77 type ConnectionPoolOptions
88} from '../cmap/connection_pool' ;
99import { PoolClearedError } from '../cmap/errors' ;
10- import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses' ;
1110import {
1211 APM_EVENTS ,
1312 CLOSED ,
@@ -27,7 +26,6 @@ import {
2726 MONGODB_ERROR_CODES ,
2827 MongoError ,
2928 MongoErrorLabel ,
30- MongoInvalidArgumentError ,
3129 MongoNetworkError ,
3230 MongoNetworkTimeoutError ,
3331 MongoRuntimeError ,
@@ -48,7 +46,6 @@ import {
4846 type EventEmitterWithState ,
4947 makeStateMachine ,
5048 maxWireVersion ,
51- type MongoDBNamespace ,
5249 noop ,
5350 squashError ,
5451 supportsRetryableWrites
@@ -281,7 +278,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
281278 }
282279 }
283280
284- public async modernCommand < TResult > (
281+ public async command < TResult > (
285282 operation : AbstractOperation < TResult > ,
286283 timeoutContext : TimeoutContext
287284 ) : Promise < InstanceType < typeof operation . SERVER_COMMAND_RESPONSE_TYPE > > {
@@ -295,7 +292,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
295292 this . incrementOperationCount ( ) ;
296293 if ( conn == null ) {
297294 try {
298- conn = await this . pool . checkOut ( { timeoutContext } ) ;
295+ conn = await this . pool . checkOut ( { timeoutContext, signal : operation . options . signal } ) ;
299296 } catch ( checkoutError ) {
300297 this . decrementOperationCount ( ) ;
301298 if ( ! ( checkoutError instanceof PoolClearedError ) ) this . handleError ( checkoutError ) ;
@@ -385,106 +382,6 @@ export class Server extends TypedEventEmitter<ServerEvents> {
385382 }
386383 }
387384
388- public async command < T extends MongoDBResponseConstructor > (
389- ns : MongoDBNamespace ,
390- command : Document ,
391- options : ServerCommandOptions ,
392- responseType : T | undefined
393- ) : Promise < typeof responseType extends undefined ? Document : InstanceType < T > > ;
394-
395- public async command (
396- ns : MongoDBNamespace ,
397- command : Document ,
398- options : ServerCommandOptions
399- ) : Promise < Document > ;
400-
401- public async command (
402- ns : MongoDBNamespace ,
403- cmd : Document ,
404- { ...options } : ServerCommandOptions ,
405- responseType ?: MongoDBResponseConstructor
406- ) : Promise < Document > {
407- if ( ns . db == null || typeof ns === 'string' ) {
408- throw new MongoInvalidArgumentError ( 'Namespace must not be a string' ) ;
409- }
410-
411- if ( this . s . state === STATE_CLOSING || this . s . state === STATE_CLOSED ) {
412- throw new MongoServerClosedError ( ) ;
413- }
414-
415- options . directConnection = this . topology . s . options . directConnection ;
416-
417- if ( this . description . iscryptd ) {
418- options . omitMaxTimeMS = true ;
419- }
420-
421- const session = options . session ;
422- let conn = session ?. pinnedConnection ;
423-
424- this . incrementOperationCount ( ) ;
425- if ( conn == null ) {
426- try {
427- conn = await this . pool . checkOut ( options ) ;
428- if ( this . loadBalanced && isPinnableCommand ( cmd , session ) ) {
429- session ?. pin ( conn ) ;
430- }
431- } catch ( checkoutError ) {
432- this . decrementOperationCount ( ) ;
433- if ( ! ( checkoutError instanceof PoolClearedError ) ) this . handleError ( checkoutError ) ;
434- throw checkoutError ;
435- }
436- }
437-
438- let reauthPromise : Promise < void > | null = null ;
439-
440- try {
441- try {
442- const res = await conn . command ( ns , cmd , options , responseType ) ;
443- throwIfWriteConcernError ( res ) ;
444- return res ;
445- } catch ( commandError ) {
446- throw this . decorateCommandError ( conn , cmd , options , commandError ) ;
447- }
448- } catch ( operationError ) {
449- if (
450- operationError instanceof MongoError &&
451- operationError . code === MONGODB_ERROR_CODES . Reauthenticate
452- ) {
453- reauthPromise = this . pool . reauthenticate ( conn ) ;
454- reauthPromise . then ( undefined , error => {
455- reauthPromise = null ;
456- squashError ( error ) ;
457- } ) ;
458-
459- await abortable ( reauthPromise , options ) ;
460- reauthPromise = null ; // only reachable if reauth succeeds
461-
462- try {
463- const res = await conn . command ( ns , cmd , options , responseType ) ;
464- throwIfWriteConcernError ( res ) ;
465- return res ;
466- } catch ( commandError ) {
467- throw this . decorateCommandError ( conn , cmd , options , commandError ) ;
468- }
469- } else {
470- throw operationError ;
471- }
472- } finally {
473- this . decrementOperationCount ( ) ;
474- if ( session ?. pinnedConnection !== conn ) {
475- if ( reauthPromise != null ) {
476- // The reauth promise only exists if it hasn't thrown.
477- const checkBackIn = ( ) => {
478- this . pool . checkIn ( conn ) ;
479- } ;
480- void reauthPromise . then ( checkBackIn , checkBackIn ) ;
481- } else {
482- this . pool . checkIn ( conn ) ;
483- }
484- }
485- }
486- }
487-
488385 /**
489386 * Handle SDAM error
490387 * @internal
0 commit comments