import { Readable, ReadableOptions } from 'node:stream'; import { TGetOperationStatusResp, TTableSchema } from '../../thrift/TCLIService_types'; import Status from '../dto/Status'; export type OperationStatusCallback = (progress: TGetOperationStatusResp) => unknown; export interface WaitUntilReadyOptions { progress?: boolean; callback?: OperationStatusCallback; } export interface FinishedOptions extends WaitUntilReadyOptions { // no other options } export interface FetchOptions extends WaitUntilReadyOptions { maxRows?: number; // Disables internal buffer used to ensure a consistent chunks size. // When set to `true`, returned chunks size may vary (and may differ from `maxRows`) disableBuffering?: boolean; } export interface GetSchemaOptions extends WaitUntilReadyOptions { // no other options } export interface IteratorOptions extends FetchOptions { autoClose?: boolean; // defaults to `false` } export interface IOperationChunksIterator extends AsyncIterableIterator> { readonly operation: IOperation; } export interface IOperationRowsIterator extends AsyncIterableIterator { readonly operation: IOperation; } export interface NodeStreamOptions { mode?: 'chunks' | 'rows'; // defaults to 'chunks' iteratorOptions?: IteratorOptions; streamOptions?: ReadableOptions; } export default interface IOperation { /** * Operation identifier */ readonly id: string; /** * Fetch a portion of data */ fetchChunk(options?: FetchOptions): Promise>; /** * Fetch all the data */ fetchAll(options?: FetchOptions): Promise>; /** * Request status of operation * * @param progress */ status(progress?: boolean): Promise; /** * Cancel operation */ cancel(): Promise; /** * Close operation */ close(): Promise; /** * Waits until operation is finished */ finished(options?: FinishedOptions): Promise; /** * Check if operation hasMoreRows */ hasMoreRows(): Promise; /** * Fetch schema */ getSchema(options?: GetSchemaOptions): Promise; iterateChunks(options?: IteratorOptions): IOperationChunksIterator; iterateRows(options?: IteratorOptions): IOperationRowsIterator; toNodeStream(options?: NodeStreamOptions): Readable; }