@@ -169,6 +169,8 @@ export class ExecuteScanQuerySettings {
169169 }
170170}
171171
172+ export type DescribeTableParams = Omit < Ydb . Table . IDescribeTableRequest , 'sessionId' | 'path' > ;
173+
172174export class Session extends EventEmitter implements ICreateSessionResult {
173175 private beingDeleted = false ;
174176 private free = true ;
@@ -258,14 +260,38 @@ export class Session extends EventEmitter implements ICreateSessionResult {
258260 ensureOperationSucceeded ( await this . api . dropTable ( request ) , [ SchemeError . status ] ) ;
259261 }
260262
263+ public async describeTable ( tablePath : string , operationParams ?: IOperationParams ) : Promise < DescribeTableResult > ;
264+ public async describeTable ( tablePath : string , operationParams ?: DescribeTableParams ) : Promise < DescribeTableResult > ;
265+
261266 @retryable ( )
262267 @pessimizable
263- public async describeTable ( tablePath : string , operationParams ?: IOperationParams ) : Promise < DescribeTableResult > {
264- const request : Ydb . Table . IDescribeTableRequest = {
265- sessionId : this . sessionId ,
266- path : `${ this . endpoint . database } /${ tablePath } ` ,
267- operationParams,
268- } ;
268+ public async describeTable ( tablePath : string , operationParams ?: IOperationParams | DescribeTableParams ) : Promise < DescribeTableResult > {
269+
270+ // type narrowing
271+ // because IOperationParams don't have any persistent member - it needs to check all members one by one
272+ function isIOperationParams ( op ?: IOperationParams | DescribeTableParams ) : op is IOperationParams {
273+ if ( ! op ) return false ;
274+ return (
275+ 'operationMode' in op ||
276+ 'operationTimeout' in op ||
277+ 'cancelAfter' in op ||
278+ 'labels' in op ||
279+ 'reportCostInfo' in op ) ;
280+ }
281+
282+ let request : Ydb . Table . IDescribeTableRequest = { } ;
283+
284+ if ( operationParams ) {
285+ if ( isIOperationParams ( operationParams ) ) {
286+ request . operationParams = operationParams
287+ } else {
288+ request = operationParams ;
289+ } ;
290+ }
291+
292+ request . sessionId = this . sessionId ;
293+ request . path = `${ this . endpoint . database } /${ tablePath } ` ;
294+
269295 const response = await this . api . describeTable ( request ) ;
270296 const payload = getOperationPayload ( response ) ;
271297 return DescribeTableResult . decode ( payload ) ;
0 commit comments