@@ -77,110 +77,7 @@ export interface OperationParent {
7777}
7878
7979/** @internal */
80- export abstract class CommandOperation < T > extends AbstractOperation < T > {
81- override options : CommandOperationOptions ;
82- readConcern ?: ReadConcern ;
83- writeConcern ?: WriteConcern ;
84- explain ?: Explain ;
85-
86- constructor ( parent ?: OperationParent , options ?: CommandOperationOptions ) {
87- super ( options ) ;
88- this . options = options ?? { } ;
89-
90- // NOTE: this was explicitly added for the add/remove user operations, it's likely
91- // something we'd want to reconsider. Perhaps those commands can use `Admin`
92- // as a parent?
93- const dbNameOverride = options ?. dbName || options ?. authdb ;
94- if ( dbNameOverride ) {
95- this . ns = new MongoDBNamespace ( dbNameOverride , '$cmd' ) ;
96- } else {
97- this . ns = parent
98- ? parent . s . namespace . withCollection ( '$cmd' )
99- : new MongoDBNamespace ( 'admin' , '$cmd' ) ;
100- }
101-
102- this . readConcern = ReadConcern . fromOptions ( options ) ;
103- this . writeConcern = WriteConcern . fromOptions ( options ) ;
104-
105- if ( this . hasAspect ( Aspect . EXPLAINABLE ) ) {
106- this . explain = Explain . fromOptions ( options ) ;
107- if ( this . explain ) validateExplainTimeoutOptions ( this . options , this . explain ) ;
108- } else if ( options ?. explain != null ) {
109- throw new MongoInvalidArgumentError ( `Option "explain" is not supported on this command` ) ;
110- }
111- }
112-
113- override get canRetryWrite ( ) : boolean {
114- if ( this . hasAspect ( Aspect . EXPLAINABLE ) ) {
115- return this . explain == null ;
116- }
117- return super . canRetryWrite ;
118- }
119-
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 > {
80+ export abstract class CommandOperation < T > extends ModernizedOperation < T > {
18481 override options : CommandOperationOptions ;
18582 readConcern ?: ReadConcern ;
18683 writeConcern ?: WriteConcern ;
0 commit comments