11import { type Connection } from '..' ;
22import type { BSONSerializeOptions , Document } from '../bson' ;
3- import { type MongoDBResponseConstructor } from '../cmap/wire_protocol/responses' ;
43import { MongoInvalidArgumentError } from '../error' ;
54import {
65 decorateWithExplain ,
@@ -10,13 +9,13 @@ import {
109} from '../explain' ;
1110import { ReadConcern } from '../read_concern' ;
1211import type { ReadPreference } from '../read_preference' ;
13- import type { Server , ServerCommandOptions } from '../sdam/server' ;
12+ import type { ServerCommandOptions } from '../sdam/server' ;
1413import type { ClientSession } from '../sessions' ;
1514import { type TimeoutContext } from '../timeout' ;
1615import { commandSupportsReadConcern , MongoDBNamespace } from '../utils' ;
1716import { WriteConcern , type WriteConcernOptions } from '../write_concern' ;
1817import type { ReadConcernLike } from './../read_concern' ;
19- import { AbstractOperation , Aspect , ModernizedOperation , type OperationOptions } from './operation' ;
18+ import { AbstractOperation , Aspect , type OperationOptions } from './operation' ;
2019
2120/** @public */
2221export interface CollationOptions {
@@ -117,109 +116,6 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
117116 return super . canRetryWrite ;
118117 }
119118
120- public async executeCommand < T extends MongoDBResponseConstructor > (
121- server : Server ,
122- session : ClientSession | undefined ,
123- cmd : Document ,
124- timeoutContext : TimeoutContext ,
125- responseType : T | undefined
126- ) : Promise < typeof responseType extends undefined ? Document : InstanceType < T > > ;
127-
128- public async executeCommand (
129- server : Server ,
130- session : ClientSession | undefined ,
131- cmd : Document ,
132- timeoutContext : TimeoutContext
133- ) : Promise < Document > ;
134-
135- async executeCommand (
136- server : Server ,
137- session : ClientSession | undefined ,
138- cmd : Document ,
139- timeoutContext : TimeoutContext ,
140- responseType ?: MongoDBResponseConstructor
141- ) : Promise < Document > {
142- this . server = server ;
143-
144- const options = {
145- ...this . options ,
146- ...this . bsonOptions ,
147- timeoutContext,
148- readPreference : this . readPreference ,
149- session
150- } ;
151-
152- const inTransaction = this . session && this . session . inTransaction ( ) ;
153-
154- if ( this . readConcern && commandSupportsReadConcern ( cmd ) && ! inTransaction ) {
155- Object . assign ( cmd , { readConcern : this . readConcern } ) ;
156- }
157-
158- if ( this . writeConcern && this . hasAspect ( Aspect . WRITE_OPERATION ) && ! inTransaction ) {
159- WriteConcern . apply ( cmd , this . writeConcern ) ;
160- }
161-
162- if (
163- options . collation &&
164- typeof options . collation === 'object' &&
165- ! this . hasAspect ( Aspect . SKIP_COLLATION )
166- ) {
167- Object . assign ( cmd , { collation : options . collation } ) ;
168- }
169-
170- if ( typeof options . maxTimeMS === 'number' ) {
171- cmd . maxTimeMS = options . maxTimeMS ;
172- }
173-
174- if ( this . hasAspect ( Aspect . EXPLAINABLE ) && this . explain ) {
175- cmd = decorateWithExplain ( cmd , this . explain ) ;
176- }
177-
178- return await server . command ( this . ns , cmd , options , responseType ) ;
179- }
180- }
181-
182- /** @internal */
183- export abstract class ModernizedCommandOperation < T > extends ModernizedOperation < T > {
184- override options : CommandOperationOptions ;
185- readConcern ?: ReadConcern ;
186- writeConcern ?: WriteConcern ;
187- explain ?: Explain ;
188-
189- constructor ( parent ?: OperationParent , options ?: CommandOperationOptions ) {
190- super ( options ) ;
191- this . options = options ?? { } ;
192-
193- // NOTE: this was explicitly added for the add/remove user operations, it's likely
194- // something we'd want to reconsider. Perhaps those commands can use `Admin`
195- // as a parent?
196- const dbNameOverride = options ?. dbName || options ?. authdb ;
197- if ( dbNameOverride ) {
198- this . ns = new MongoDBNamespace ( dbNameOverride , '$cmd' ) ;
199- } else {
200- this . ns = parent
201- ? parent . s . namespace . withCollection ( '$cmd' )
202- : new MongoDBNamespace ( 'admin' , '$cmd' ) ;
203- }
204-
205- this . readConcern = ReadConcern . fromOptions ( options ) ;
206- this . writeConcern = WriteConcern . fromOptions ( options ) ;
207-
208- if ( this . hasAspect ( Aspect . EXPLAINABLE ) ) {
209- this . explain = Explain . fromOptions ( options ) ;
210- if ( this . explain ) validateExplainTimeoutOptions ( this . options , this . explain ) ;
211- } else if ( options ?. explain != null ) {
212- throw new MongoInvalidArgumentError ( `Option "explain" is not supported on this command` ) ;
213- }
214- }
215-
216- override get canRetryWrite ( ) : boolean {
217- if ( this . hasAspect ( Aspect . EXPLAINABLE ) ) {
218- return this . explain == null ;
219- }
220- return super . canRetryWrite ;
221- }
222-
223119 abstract buildCommandDocument ( connection : Connection , session ?: ClientSession ) : Document ;
224120
225121 override buildOptions ( timeoutContext : TimeoutContext ) : ServerCommandOptions {
0 commit comments