11import type { BSONSerializeOptions , Document } from '../bson' ;
2- import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses' ;
2+ import { type Connection } from '../cmap/connection' ;
3+ import { MongoDBResponse , type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses' ;
34import { type Db } from '../db' ;
4- import { type TODO_NODE_3286 } from '../mongo_types' ;
55import type { ReadPreferenceLike } from '../read_preference' ;
6- import type { Server } from '../sdam/server' ;
6+ import type { ServerCommandOptions } from '../sdam/server' ;
77import type { ClientSession } from '../sessions' ;
88import { type TimeoutContext } from '../timeout' ;
99import { MongoDBNamespace } from '../utils' ;
10- import { AbstractOperation } from './operation' ;
10+ import { ModernizedOperation } from './operation' ;
1111
1212/** @public */
1313export type RunCommandOptions = {
@@ -25,7 +25,8 @@ export type RunCommandOptions = {
2525} & BSONSerializeOptions ;
2626
2727/** @internal */
28- export class RunCommandOperation < T = Document > extends AbstractOperation < T > {
28+ export class RunCommandOperation < T = Document > extends ModernizedOperation < T > {
29+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
2930 command : Document ;
3031 override options : RunCommandOptions & { responseType ?: MongoDBResponseConstructor } ;
3132
@@ -44,29 +45,17 @@ export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
4445 return 'runCommand' as const ;
4546 }
4647
47- override async execute (
48- server : Server ,
49- session : ClientSession | undefined ,
50- timeoutContext : TimeoutContext
51- ) : Promise < T > {
52- this . server = server ;
53- const res : TODO_NODE_3286 = await server . command (
54- this . ns ,
55- this . command ,
56- {
57- ...this . options ,
58- readPreference : this . readPreference ,
59- session,
60- timeoutContext
61- } ,
62- this . options . responseType
63- ) ;
48+ override buildCommand ( _connection : Connection , _session ?: ClientSession ) : Document {
49+ return this . command ;
50+ }
6451
65- return res ;
52+ override buildOptions ( timeoutContext : TimeoutContext ) : ServerCommandOptions {
53+ return { session : this . session , timeoutContext } ;
6654 }
6755}
6856
69- export class RunAdminCommandOperation < T = Document > extends AbstractOperation < T > {
57+ export class RunAdminCommandOperation < T = Document > extends ModernizedOperation < T > {
58+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
7059 command : Document ;
7160 override options : RunCommandOptions & {
7261 noResponse ?: boolean ;
@@ -90,18 +79,11 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
9079 return 'runCommand' as const ;
9180 }
9281
93- override async execute (
94- server : Server ,
95- session : ClientSession | undefined ,
96- timeoutContext : TimeoutContext
97- ) : Promise < T > {
98- this . server = server ;
99- const res : TODO_NODE_3286 = await server . command ( this . ns , this . command , {
100- ...this . options ,
101- readPreference : this . readPreference ,
102- session,
103- timeoutContext
104- } ) ;
105- return res ;
82+ override buildCommand ( _connection : Connection , _session ?: ClientSession ) : Document {
83+ return this . command ;
84+ }
85+
86+ override buildOptions ( timeoutContext : TimeoutContext ) : ServerCommandOptions {
87+ return { session : this . session , timeoutContext } ;
10688 }
10789}
0 commit comments