1
1
import 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' ;
3
4
import { type Db } from '../db' ;
4
- import { type TODO_NODE_3286 } from '../mongo_types' ;
5
5
import type { ReadPreferenceLike } from '../read_preference' ;
6
- import type { Server } from '../sdam/server' ;
6
+ import type { ServerCommandOptions } from '../sdam/server' ;
7
7
import type { ClientSession } from '../sessions' ;
8
8
import { type TimeoutContext } from '../timeout' ;
9
9
import { MongoDBNamespace } from '../utils' ;
10
- import { AbstractOperation } from './operation' ;
10
+ import { ModernizedOperation } from './operation' ;
11
11
12
12
/** @public */
13
13
export type RunCommandOptions = {
@@ -25,7 +25,8 @@ export type RunCommandOptions = {
25
25
} & BSONSerializeOptions ;
26
26
27
27
/** @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 ;
29
30
command : Document ;
30
31
override options : RunCommandOptions & { responseType ?: MongoDBResponseConstructor } ;
31
32
@@ -44,29 +45,17 @@ export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
44
45
return 'runCommand' as const ;
45
46
}
46
47
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
+ }
64
51
65
- return res ;
52
+ override buildOptions ( timeoutContext : TimeoutContext ) : ServerCommandOptions {
53
+ return { session : this . session , timeoutContext } ;
66
54
}
67
55
}
68
56
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 ;
70
59
command : Document ;
71
60
override options : RunCommandOptions & {
72
61
noResponse ?: boolean ;
@@ -90,18 +79,11 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
90
79
return 'runCommand' as const ;
91
80
}
92
81
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 } ;
106
88
}
107
89
}
0 commit comments