Skip to content

Commit

Permalink
Polish & cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Levko Kravets <[email protected]>
  • Loading branch information
kravets-levko committed May 21, 2024
1 parent d178684 commit 275bdbf
Show file tree
Hide file tree
Showing 29 changed files with 598 additions and 768 deletions.
16 changes: 8 additions & 8 deletions lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I

private readonly config: ClientConfig;

protected connectionProvider?: IConnectionProvider;
private connectionProvider?: IConnectionProvider;

protected authProvider?: IAuthentication;
private authProvider?: IAuthentication;

protected client?: IThriftClient;
private client?: IThriftClient;

private readonly driver = new HiveDriver({
context: this,
});

private readonly logger: IDBSQLLogger;

protected thrift: ThriftLibrary = thrift;
private thrift: ThriftLibrary = thrift;

protected sessions = new CloseableCollection<DBSQLSession>();
private readonly sessions = new CloseableCollection<DBSQLSession>();

private static getDefaultLogger(): IDBSQLLogger {
if (!this.defaultLogger) {
Expand Down Expand Up @@ -102,7 +102,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
this.logger.log(LogLevel.info, 'Created DBSQLClient');
}

protected getConnectionOptions(options: ConnectionOptions): IConnectionOptions {
private getConnectionOptions(options: ConnectionOptions): IConnectionOptions {
return {
host: options.host,
port: options.port || 443,
Expand All @@ -116,7 +116,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
};
}

protected createAuthProvider(options: ConnectionOptions, authProvider?: IAuthentication): IAuthentication {
private createAuthProvider(options: ConnectionOptions, authProvider?: IAuthentication): IAuthentication {
if (authProvider) {
return authProvider;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient, I
}
}

protected createConnectionProvider(options: ConnectionOptions): IConnectionProvider {
private createConnectionProvider(options: ConnectionOptions): IConnectionProvider {
return new HttpConnection(this.getConnectionOptions(options), this);
}

Expand Down
18 changes: 9 additions & 9 deletions lib/DBSQLOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ async function delay(ms?: number): Promise<void> {
}

export default class DBSQLOperation implements IOperation {
protected readonly context: IClientContext;
private readonly context: IClientContext;

protected readonly operationHandle: TOperationHandle;
private readonly operationHandle: TOperationHandle;

protected readonly _data: RowSetProvider;
private readonly _data: RowSetProvider;

protected readonly closeOperation?: TCloseOperationResp;
private readonly closeOperation?: TCloseOperationResp;

protected closed: boolean = false;
private closed: boolean = false;

protected cancelled: boolean = false;
private cancelled: boolean = false;

protected metadata?: TGetResultSetMetadataResp;
private metadata?: TGetResultSetMetadataResp;

protected state: number = TOperationState.INITIALIZED_STATE;
private state: TOperationState = TOperationState.INITIALIZED_STATE;

public onClose?: () => void;

Expand Down Expand Up @@ -376,7 +376,7 @@ export default class DBSQLOperation implements IOperation {
return this.metadata;
}

protected async getResultHandler(): Promise<ResultSlicer<any>> {
private async getResultHandler(): Promise<ResultSlicer<any>> {
const metadata = await this.fetchMetadata();
const resultFormat = definedOrError(metadata.resultFormat);

Expand Down
4 changes: 2 additions & 2 deletions lib/DBSQLSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ export default class DBSQLSession implements IDBSQLSession {

private readonly sessionHandle: TSessionHandle;

protected isOpen = true;
private isOpen = true;

protected operations = new CloseableCollection<DBSQLOperation>();
private operations = new CloseableCollection<DBSQLOperation>();

public onClose?: () => void;

Expand Down
2 changes: 1 addition & 1 deletion lib/connection/auth/DatabricksOAuth/AuthorizationCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class AuthorizationCode {
throw new AuthenticationError('Failed to start server: all ports are in use');
}

protected createHttpServer(requestHandler: (req: IncomingMessage, res: ServerResponse) => void) {
private createHttpServer(requestHandler: (req: IncomingMessage, res: ServerResponse) => void) {
return http.createServer(requestHandler);
}

Expand Down
16 changes: 9 additions & 7 deletions lib/connection/auth/DatabricksOAuth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ export interface DatabricksOAuthOptions extends OAuthManagerOptions {
export default class DatabricksOAuth implements IAuthentication {
private readonly context: IClientContext;

protected readonly options: DatabricksOAuthOptions;
private readonly options: DatabricksOAuthOptions;

protected readonly manager: OAuthManager;
private manager?: OAuthManager;

private readonly defaultPersistence = new OAuthPersistenceCache();

constructor(options: DatabricksOAuthOptions) {
this.context = options.context;
this.options = options;
this.manager = this.createManager(this.options);
}

public async authenticate(): Promise<HeadersInit> {
Expand All @@ -35,10 +34,10 @@ export default class DatabricksOAuth implements IAuthentication {

let token = await persistence.read(host);
if (!token) {
token = await this.manager.getToken(scopes ?? defaultOAuthScopes);
token = await this.getManager().getToken(scopes ?? defaultOAuthScopes);
}

token = await this.manager.refreshAccessToken(token);
token = await this.getManager().refreshAccessToken(token);
await persistence.persist(host, token);

return {
Expand All @@ -47,7 +46,10 @@ export default class DatabricksOAuth implements IAuthentication {
};
}

protected createManager(options: OAuthManagerOptions): OAuthManager {
return OAuthManager.getManager(options);
private getManager(): OAuthManager {
if (!this.manager) {
this.manager = OAuthManager.getManager(this.options);
}
return this.manager;
}
}
8 changes: 4 additions & 4 deletions lib/connection/auth/PlainHttpAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ interface PlainHttpAuthenticationOptions {
}

export default class PlainHttpAuthentication implements IAuthentication {
protected readonly context: IClientContext;
private readonly context: IClientContext;

protected readonly username: string;
private readonly username: string;

protected readonly password: string;
private readonly password: string;

protected readonly headers: HeadersInit;
private readonly headers: HeadersInit;

constructor(options: PlainHttpAuthenticationOptions) {
this.context = options.context;
Expand Down
2 changes: 1 addition & 1 deletion lib/connection/connections/HttpConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class HttpConnection implements IConnectionProvider {

private readonly context: IClientContext;

protected headers: HeadersInit = {};
private headers: HeadersInit = {};

private connection?: ThriftHttpConnection;

Expand Down
6 changes: 3 additions & 3 deletions lib/connection/connections/HttpRetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ function delay(milliseconds: number): Promise<void> {
}

export default class HttpRetryPolicy implements IRetryPolicy<HttpTransactionDetails> {
protected context: IClientContext;
private context: IClientContext;

protected startTime: number; // in milliseconds
private startTime: number; // in milliseconds

protected attempt: number;
private attempt: number;

constructor(context: IClientContext) {
this.context = context;
Expand Down
4 changes: 2 additions & 2 deletions lib/result/ArrowResultConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type ArrowSchema = Schema<TypeMap>;
type ArrowSchemaField = Field<DataType<Type, TypeMap>>;

export default class ArrowResultConverter implements IResultsProvider<Array<any>> {
protected readonly context: IClientContext;
private readonly context: IClientContext;

public readonly source: IResultsProvider<ArrowBatch>;
private readonly source: IResultsProvider<ArrowBatch>;

private readonly schema: Array<TColumnDesc>;

Expand Down
6 changes: 3 additions & 3 deletions lib/result/ArrowResultHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { ArrowBatch, hiveSchemaToArrowSchema } from './utils';
import { LZ4 } from '../utils';

export default class ArrowResultHandler implements IResultsProvider<ArrowBatch> {
protected readonly context: IClientContext;
private readonly context: IClientContext;

public readonly source: IResultsProvider<TRowSet | undefined>;
private readonly source: IResultsProvider<TRowSet | undefined>;

protected readonly arrowSchema?: Buffer;
private readonly arrowSchema?: Buffer;

private readonly isLZ4Compressed: boolean;

Expand Down
8 changes: 4 additions & 4 deletions lib/result/CloudFetchResultHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { ArrowBatch } from './utils';
import { LZ4 } from '../utils';

export default class CloudFetchResultHandler implements IResultsProvider<ArrowBatch> {
protected readonly context: IClientContext;
private readonly context: IClientContext;

public readonly source: IResultsProvider<TRowSet | undefined>;
private readonly source: IResultsProvider<TRowSet | undefined>;

private readonly isLZ4Compressed: boolean;

protected pendingLinks: Array<TSparkArrowResultLink> = [];
private pendingLinks: Array<TSparkArrowResultLink> = [];

protected downloadTasks: Array<Promise<ArrowBatch>> = [];
private downloadTasks: Array<Promise<ArrowBatch>> = [];

constructor(
context: IClientContext,
Expand Down
4 changes: 2 additions & 2 deletions lib/result/JsonResultHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getSchemaColumns, convertThriftValue, getColumnValue } from './utils';
export default class JsonResultHandler implements IResultsProvider<Array<any>> {
private readonly context: IClientContext;

public readonly source: IResultsProvider<TRowSet | undefined>;
private readonly source: IResultsProvider<TRowSet | undefined>;

private readonly schema: Array<TColumnDesc>;

Expand Down Expand Up @@ -72,7 +72,7 @@ export default class JsonResultHandler implements IResultsProvider<Array<any>> {
});
}

protected isNull(nulls: Buffer, i: number): boolean {
private isNull(nulls: Buffer, i: number): boolean {
const byte = nulls[Math.floor(i / 8)];
const ofs = 2 ** (i % 8);

Expand Down
2 changes: 1 addition & 1 deletion lib/result/ResultSlicer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ResultSlicerFetchNextOptions extends ResultsProviderFetchNextOp
export default class ResultSlicer<T> implements IResultsProvider<Array<T>> {
private readonly context: IClientContext;

public readonly source: IResultsProvider<Array<T>>;
private readonly source: IResultsProvider<Array<T>>;

private remainingResults: Array<T> = [];

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/CloseableCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ICloseable {
}

export default class CloseableCollection<T extends ICloseable> {
protected items = new Set<T>();
private items = new Set<T>();

public add(item: T) {
item.onClose = () => {
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/.stubs/ClientContextStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export default class ClientContextStub implements IClientContext {
}

public getConfig(): ClientConfig {
// @ts-expect-error TS2341: Property getDefaultConfig is private and only accessible within class DBSQLClient
const defaultConfig = DBSQLClient.getDefaultConfig();
const defaultConfig = DBSQLClient['getDefaultConfig']();
return {
...defaultConfig,
...this.configOverrides,
Expand Down
Loading

0 comments on commit 275bdbf

Please sign in to comment.