Skip to content

Commit 2be1a63

Browse files
committed
sea-abstraction: cleanup — restore JSDoc, dedupe test pre-seed, fix inline type
Addresses code-bloat-watchdog findings from commit 0085928: - Restores public-API JSDoc on DBSQLSession + DBSQLOperation methods (was deleted as scope creep; contracts unchanged so docs still apply) - Adds makeStubbedClient() helper to tests/unit/DBSQLClient.test.ts; replaces 14× duplicated ThriftBackend pre-seed - Imports WaitUntilReadyOptions instead of inline option types in IOperationBackend + DBSQLOperation.waitUntilReady
1 parent 0085928 commit 2be1a63

4 files changed

Lines changed: 130 additions & 56 deletions

File tree

lib/DBSQLOperation.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import IOperation, {
33
FetchOptions,
44
FinishedOptions,
55
GetSchemaOptions,
6+
WaitUntilReadyOptions,
67
IteratorOptions,
78
IOperationChunksIterator,
89
IOperationRowsIterator,
@@ -87,6 +88,15 @@ export default class DBSQLOperation implements IOperation {
8788
return Readable.from(iterable, options?.streamOptions);
8889
}
8990

91+
/**
92+
* Fetches all data
93+
* @public
94+
* @param options - maxRows property can be set to limit chunk size
95+
* @returns Array of data with length equal to option.maxRows
96+
* @throws {StatusError}
97+
* @example
98+
* const result = await queryOperation.fetchAll();
99+
*/
90100
public async fetchAll(options?: FetchOptions): Promise<Array<object>> {
91101
const data: Array<Array<object>> = [];
92102

@@ -105,6 +115,15 @@ export default class DBSQLOperation implements IOperation {
105115
return data.flat();
106116
}
107117

118+
/**
119+
* Fetches chunk of data
120+
* @public
121+
* @param options - maxRows property sets chunk size
122+
* @returns Array of data with length equal to option.maxRows
123+
* @throws {StatusError}
124+
* @example
125+
* const result = await queryOperation.fetchChunk({maxRows: 1000});
126+
*/
108127
public async fetchChunk(options?: FetchOptions): Promise<Array<object>> {
109128
await this.failIfClosed();
110129

@@ -124,12 +143,21 @@ export default class DBSQLOperation implements IOperation {
124143
return result;
125144
}
126145

146+
/**
147+
* Requests operation status
148+
* @param progress
149+
* @throws {StatusError}
150+
*/
127151
public async status(progress: boolean = false): Promise<TGetOperationStatusResp> {
128152
await this.failIfClosed();
129153
this.context.getLogger().log(LogLevel.debug, `Fetching status for operation with id: ${this.id}`);
130154
return this.backend.status(progress);
131155
}
132156

157+
/**
158+
* Cancels operation
159+
* @throws {StatusError}
160+
*/
133161
public async cancel(): Promise<Status> {
134162
if (this.closed || this.cancelled) {
135163
return Status.success();
@@ -140,6 +168,10 @@ export default class DBSQLOperation implements IOperation {
140168
return result;
141169
}
142170

171+
/**
172+
* Closes operation
173+
* @throws {StatusError}
174+
*/
143175
public async close(): Promise<Status> {
144176
if (this.closed || this.cancelled) {
145177
return Status.success();
@@ -196,10 +228,7 @@ export default class DBSQLOperation implements IOperation {
196228
}
197229
}
198230

199-
private async waitUntilReadyThroughBackend(options?: {
200-
progress?: boolean;
201-
callback?: (p: TGetOperationStatusResp) => unknown;
202-
}) {
231+
private async waitUntilReadyThroughBackend(options?: WaitUntilReadyOptions) {
203232
try {
204233
await this.backend.waitUntilReady(options);
205234
} catch (err) {

lib/DBSQLSession.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,30 @@ export default class DBSQLSession implements IDBSQLSession {
7474
return this.backend.id;
7575
}
7676

77+
/**
78+
* Fetches info
79+
* @public
80+
* @param infoType - One of the values TCLIService_types.TGetInfoType
81+
* @returns Value corresponding to info type requested
82+
* @example
83+
* const response = await session.getInfo(thrift.TCLIService_types.TGetInfoType.CLI_DBMS_VER);
84+
*/
7785
public async getInfo(infoType: number): Promise<InfoValue> {
7886
await this.failIfClosed();
7987
const result = await this.backend.getInfo(infoType);
8088
await this.failIfClosed();
8189
return result;
8290
}
8391

92+
/**
93+
* Executes statement
94+
* @public
95+
* @param statement - SQL statement to be executed
96+
* @param options - maxRows field is used to specify Direct Results
97+
* @returns DBSQLOperation
98+
* @example
99+
* const operation = await session.executeStatement(query);
100+
*/
84101
public async executeStatement(statement: string, options: ExecuteStatementOptions = {}): Promise<IOperation> {
85102
await this.failIfClosed();
86103
const opBackend = await this.backend.executeStatement(statement, options);
@@ -206,48 +223,90 @@ export default class DBSQLSession implements IDBSQLSession {
206223
}
207224
}
208225

226+
/**
227+
* Information about supported data types
228+
* @public
229+
* @param request
230+
* @returns DBSQLOperation
231+
*/
209232
public async getTypeInfo(request: TypeInfoRequest = {}): Promise<IOperation> {
210233
await this.failIfClosed();
211234
const opBackend = await this.backend.getTypeInfo(request);
212235
await this.failIfClosed();
213236
return this.wrapOperation(opBackend);
214237
}
215238

239+
/**
240+
* Get list of catalogs
241+
* @public
242+
* @param request
243+
* @returns DBSQLOperation
244+
*/
216245
public async getCatalogs(request: CatalogsRequest = {}): Promise<IOperation> {
217246
await this.failIfClosed();
218247
const opBackend = await this.backend.getCatalogs(request);
219248
await this.failIfClosed();
220249
return this.wrapOperation(opBackend);
221250
}
222251

252+
/**
253+
* Get list of schemas
254+
* @public
255+
* @param request
256+
* @returns DBSQLOperation
257+
*/
223258
public async getSchemas(request: SchemasRequest = {}): Promise<IOperation> {
224259
await this.failIfClosed();
225260
const opBackend = await this.backend.getSchemas(request);
226261
await this.failIfClosed();
227262
return this.wrapOperation(opBackend);
228263
}
229264

265+
/**
266+
* Get list of tables
267+
* @public
268+
* @param request
269+
* @returns DBSQLOperation
270+
*/
230271
public async getTables(request: TablesRequest = {}): Promise<IOperation> {
231272
await this.failIfClosed();
232273
const opBackend = await this.backend.getTables(request);
233274
await this.failIfClosed();
234275
return this.wrapOperation(opBackend);
235276
}
236277

278+
/**
279+
* Get list of supported table types
280+
* @public
281+
* @param request
282+
* @returns DBSQLOperation
283+
*/
237284
public async getTableTypes(request: TableTypesRequest = {}): Promise<IOperation> {
238285
await this.failIfClosed();
239286
const opBackend = await this.backend.getTableTypes(request);
240287
await this.failIfClosed();
241288
return this.wrapOperation(opBackend);
242289
}
243290

291+
/**
292+
* Get full information about columns of the table
293+
* @public
294+
* @param request
295+
* @returns DBSQLOperation
296+
*/
244297
public async getColumns(request: ColumnsRequest = {}): Promise<IOperation> {
245298
await this.failIfClosed();
246299
const opBackend = await this.backend.getColumns(request);
247300
await this.failIfClosed();
248301
return this.wrapOperation(opBackend);
249302
}
250303

304+
/**
305+
* Get information about function
306+
* @public
307+
* @param request
308+
* @returns DBSQLOperation
309+
*/
251310
public async getFunctions(request: FunctionsRequest): Promise<IOperation> {
252311
await this.failIfClosed();
253312
const opBackend = await this.backend.getFunctions(request);
@@ -262,13 +321,24 @@ export default class DBSQLSession implements IDBSQLSession {
262321
return this.wrapOperation(opBackend);
263322
}
264323

324+
/**
325+
* Request information about foreign keys between two tables
326+
* @public
327+
* @param request
328+
* @returns DBSQLOperation
329+
*/
265330
public async getCrossReference(request: CrossReferenceRequest): Promise<IOperation> {
266331
await this.failIfClosed();
267332
const opBackend = await this.backend.getCrossReference(request);
268333
await this.failIfClosed();
269334
return this.wrapOperation(opBackend);
270335
}
271336

337+
/**
338+
* Closes the session
339+
* @public
340+
* @returns Operation status
341+
*/
272342
public async close(): Promise<Status> {
273343
if (!this.isOpen) {
274344
return Status.success();

lib/contracts/IOperationBackend.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TGetOperationStatusResp, TGetResultSetMetadataResp } from '../../thrift/TCLIService_types';
22
import Status from '../dto/Status';
3+
import { WaitUntilReadyOptions } from './IOperation';
34

45
/**
56
* What a `DBSQLOperation` needs from its backend. Returned by
@@ -14,10 +15,7 @@ export default interface IOperationBackend {
1415

1516
hasMore(): Promise<boolean>;
1617

17-
waitUntilReady(options?: {
18-
progress?: boolean;
19-
callback?: (progress: TGetOperationStatusResp) => unknown;
20-
}): Promise<void>;
18+
waitUntilReady(options?: WaitUntilReadyOptions): Promise<void>;
2119

2220
status(progress: boolean): Promise<TGetOperationStatusResp>;
2321

0 commit comments

Comments
 (0)