11import type { Document } from '../bson' ;
2+ import { type Connection } from '../cmap/connection' ;
3+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
24import type { Collection } from '../collection' ;
35import { MongoCompatibilityError , MongoServerError } from '../error' ;
46import { type TODO_NODE_3286 } from '../mongo_types' ;
@@ -7,7 +9,11 @@ import type { ClientSession } from '../sessions';
79import { type TimeoutContext } from '../timeout' ;
810import { type MongoDBNamespace } from '../utils' ;
911import { type WriteConcernOptions } from '../write_concern' ;
10- import { type CollationOptions , CommandOperation , type CommandOperationOptions } from './command' ;
12+ import {
13+ type CollationOptions ,
14+ type CommandOperationOptions ,
15+ ModernizedCommandOperation
16+ } from './command' ;
1117import { Aspect , defineAspects , type Hint } from './operation' ;
1218
1319/** @public */
@@ -43,7 +49,8 @@ export interface DeleteStatement {
4349}
4450
4551/** @internal */
46- export class DeleteOperation extends CommandOperation < DeleteResult > {
52+ export class DeleteOperation extends ModernizedCommandOperation < Document > {
53+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
4754 override options : DeleteOptions ;
4855 statements : DeleteStatement [ ] ;
4956
@@ -66,12 +73,9 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
6673 return this . statements . every ( op => ( op . limit != null ? op . limit > 0 : true ) ) ;
6774 }
6875
69- override async execute (
70- server : Server ,
71- session : ClientSession | undefined ,
72- timeoutContext : TimeoutContext
73- ) : Promise < DeleteResult > {
74- const options = this . options ?? { } ;
76+ override buildCommandDocument ( _connection : Connection , _session ?: ClientSession ) : Document {
77+ const options = this . options ;
78+
7579 const ordered = typeof options . ordered === 'boolean' ? options . ordered : true ;
7680 const command : Document = {
7781 delete : this . ns . collection ,
@@ -97,13 +101,7 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
97101 }
98102 }
99103
100- const res : TODO_NODE_3286 = await super . executeCommand (
101- server ,
102- session ,
103- command ,
104- timeoutContext
105- ) ;
106- return res ;
104+ return command ;
107105 }
108106}
109107
@@ -112,13 +110,14 @@ export class DeleteOneOperation extends DeleteOperation {
112110 super ( collection . s . namespace , [ makeDeleteStatement ( filter , { ...options , limit : 1 } ) ] , options ) ;
113111 }
114112
115- override async execute (
116- server : Server ,
117- session : ClientSession | undefined ,
118- timeoutContext : TimeoutContext
119- ) : Promise < DeleteResult > {
120- const res : TODO_NODE_3286 = await super . execute ( server , session , timeoutContext ) ;
113+ override handleOk (
114+ response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
115+ ) : DeleteResult {
116+ const res = super . handleOk ( response ) ;
117+
118+ // @ts -expect-error Explain commands have broken TS
121119 if ( this . explain ) return res ;
120+
122121 if ( res . code ) throw new MongoServerError ( res ) ;
123122 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
124123
@@ -133,13 +132,14 @@ export class DeleteManyOperation extends DeleteOperation {
133132 super ( collection . s . namespace , [ makeDeleteStatement ( filter , options ) ] , options ) ;
134133 }
135134
136- override async execute (
137- server : Server ,
138- session : ClientSession | undefined ,
139- timeoutContext : TimeoutContext
140- ) : Promise < DeleteResult > {
141- const res : TODO_NODE_3286 = await super . execute ( server , session , timeoutContext ) ;
135+ override handleOk (
136+ response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
137+ ) : DeleteResult {
138+ const res = super . handleOk ( response ) ;
139+
140+ // @ts -expect-error Explain commands have broken TS
142141 if ( this . explain ) return res ;
142+
143143 if ( res . code ) throw new MongoServerError ( res ) ;
144144 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
145145
0 commit comments