@@ -7,10 +7,7 @@ import {
77 type ConnectionPoolOptions
88} from '../cmap/connection_pool' ;
99import { PoolClearedError } from '../cmap/errors' ;
10- import {
11- type MongoDBResponse ,
12- type MongoDBResponseConstructor
13- } from '../cmap/wire_protocol/responses' ;
10+ import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses' ;
1411import {
1512 APM_EVENTS ,
1613 CLOSED ,
@@ -41,7 +38,7 @@ import {
4138import type { ServerApi } from '../mongo_client' ;
4239import { type Abortable , TypedEventEmitter } from '../mongo_types' ;
4340import type { GetMoreOptions } from '../operations/get_more' ;
44- import { type ModernOperation } from '../operations/operation' ;
41+ import { type ModernizedOperation } from '../operations/operation' ;
4542import type { ClientSession } from '../sessions' ;
4643import { type TimeoutContext } from '../timeout' ;
4744import { isTransactionCommand } from '../transactions' ;
@@ -281,14 +278,10 @@ export class Server extends TypedEventEmitter<ServerEvents> {
281278 }
282279 }
283280
284- public async modernCommand < TResponse extends typeof MongoDBResponse | undefined , TResult > (
285- operation : ModernOperation < TResponse , TResult > ,
281+ public async modernCommand < TResult > (
282+ operation : ModernizedOperation < TResult > ,
286283 timeoutContext : TimeoutContext
287- ) : Promise <
288- typeof operation . RESPONSE_TYPE extends typeof MongoDBResponse
289- ? InstanceType < TResponse >
290- : Document
291- > {
284+ ) : Promise < InstanceType < typeof operation . SERVER_COMMAND_RESPONSE_TYPE > > {
292285 if ( this . s . state === STATE_CLOSING || this . s . state === STATE_CLOSED ) {
293286 throw new MongoServerClosedError ( ) ;
294287 }
@@ -333,12 +326,9 @@ export class Server extends TypedEventEmitter<ServerEvents> {
333326
334327 try {
335328 try {
336- const res = await conn . command ( ns , cmd , options , operation . RESPONSE_TYPE ) ;
329+ const res = await conn . command ( ns , cmd , options , operation . SERVER_COMMAND_RESPONSE_TYPE ) ;
337330 throwIfWriteConcernError ( res ) ;
338- // TODO: figure out why casting is necessary
339- return res as typeof operation . RESPONSE_TYPE extends typeof MongoDBResponse
340- ? InstanceType < TResponse >
341- : Document ;
331+ return res ;
342332 } catch ( commandError ) {
343333 throw this . decorateCommandError ( conn , cmd , options , commandError ) ;
344334 }
@@ -357,12 +347,9 @@ export class Server extends TypedEventEmitter<ServerEvents> {
357347 reauthPromise = null ; // only reachable if reauth succeeds
358348
359349 try {
360- const res = await conn . command ( ns , cmd , options ) ;
350+ const res = await conn . command ( ns , cmd , options , operation . SERVER_COMMAND_RESPONSE_TYPE ) ;
361351 throwIfWriteConcernError ( res ) ;
362- // TODO: figure out why casting is necessary
363- return res as typeof operation . RESPONSE_TYPE extends typeof MongoDBResponse
364- ? InstanceType < TResponse >
365- : Document ;
352+ return res ;
366353 } catch ( commandError ) {
367354 throw this . decorateCommandError ( conn , cmd , options , commandError ) ;
368355 }
0 commit comments