Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions lib/DBSQLOperation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringify, NIL, parse } from 'uuid';
import { stringify, NIL } from 'uuid';
import IOperation, {
FetchOptions,
FinishedOptions,
Expand Down Expand Up @@ -88,11 +88,12 @@ export default class DBSQLOperation implements IOperation {
useOnlyPrefetchedResults,
);
this.closeOperation = directResults?.closeOperation;
this.context.getLogger().log(LogLevel.debug, `Operation created with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Operation created with id: ${this.id}`);
}

public getId() {
return stringify(this.operationHandle?.operationId?.guid || parse(NIL));
public get id() {
const operationId = this.operationHandle?.operationId?.guid;
return operationId ? stringify(operationId) : NIL;
}

/**
Expand All @@ -119,7 +120,7 @@ export default class DBSQLOperation implements IOperation {
const chunk = await this.fetchChunk(fetchChunkOptions);
data.push(chunk);
} while (await this.hasMoreRows()); // eslint-disable-line no-await-in-loop
this.context.getLogger().log(LogLevel.debug, `Fetched all data from operation with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Fetched all data from operation with id: ${this.id}`);

return data.flat();
}
Expand Down Expand Up @@ -173,7 +174,7 @@ export default class DBSQLOperation implements IOperation {
.getLogger()
.log(
LogLevel.debug,
`Fetched chunk of size: ${options?.maxRows || defaultMaxRows} from operation with id: ${this.getId()}`,
`Fetched chunk of size: ${options?.maxRows || defaultMaxRows} from operation with id: ${this.id}`,
);
return result;
}
Expand All @@ -185,7 +186,7 @@ export default class DBSQLOperation implements IOperation {
*/
public async status(progress: boolean = false): Promise<TGetOperationStatusResp> {
await this.failIfClosed();
this.context.getLogger().log(LogLevel.debug, `Fetching status for operation with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Fetching status for operation with id: ${this.id}`);

if (this.operationStatus) {
return this.operationStatus;
Expand All @@ -209,7 +210,7 @@ export default class DBSQLOperation implements IOperation {
return Status.success();
}

this.context.getLogger().log(LogLevel.debug, `Cancelling operation with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Cancelling operation with id: ${this.id}`);

const driver = await this.context.getDriver();
const response = await driver.cancelOperation({
Expand All @@ -233,7 +234,7 @@ export default class DBSQLOperation implements IOperation {
return Status.success();
}

this.context.getLogger().log(LogLevel.debug, `Closing operation with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Closing operation with id: ${this.id}`);

const driver = await this.context.getDriver();
const response =
Expand Down Expand Up @@ -274,7 +275,7 @@ export default class DBSQLOperation implements IOperation {

await this.waitUntilReady(options);

this.context.getLogger().log(LogLevel.debug, `Fetching schema for operation with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Fetching schema for operation with id: ${this.id}`);
const metadata = await this.fetchMetadata();
return metadata.schema ?? null;
}
Expand Down
11 changes: 6 additions & 5 deletions lib/DBSQLSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import stream from 'node:stream';
import util from 'node:util';
import { stringify, NIL, parse } from 'uuid';
import { stringify, NIL } from 'uuid';
import fetch, { HeadersInit } from 'node-fetch';
import {
TSessionHandle,
Expand Down Expand Up @@ -140,11 +140,12 @@ export default class DBSQLSession implements IDBSQLSession {
constructor({ handle, context }: DBSQLSessionConstructorOptions) {
this.sessionHandle = handle;
this.context = context;
this.context.getLogger().log(LogLevel.debug, `Session created with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Session created with id: ${this.id}`);
}

public getId() {
return stringify(this.sessionHandle?.sessionId?.guid || parse(NIL));
public get id() {
const sessionId = this.sessionHandle?.sessionId?.guid;
return sessionId ? stringify(sessionId) : NIL;
}

/**
Expand Down Expand Up @@ -531,7 +532,7 @@ export default class DBSQLSession implements IDBSQLSession {
this.onClose?.();
this.isOpen = false;

this.context.getLogger().log(LogLevel.debug, `Session closed with id: ${this.getId()}`);
this.context.getLogger().log(LogLevel.debug, `Session closed with id: ${this.id}`);
return new Status(response.status);
}

Expand Down
5 changes: 5 additions & 0 deletions lib/contracts/IDBSQLSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export type CrossReferenceRequest = {
};

export default interface IDBSQLSession {
/**
* Session identifier
*/
readonly id: string;

/**
* Returns general information about the data source
*
Expand Down
5 changes: 5 additions & 0 deletions lib/contracts/IOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface GetSchemaOptions extends WaitUntilReadyOptions {
}

export default interface IOperation {
/**
* Operation identifier
*/
readonly id: string;

/**
* Fetch a portion of data
*/
Expand Down