1
1
import type { Document } from '../bson' ;
2
+ import { type Connection } from '../cmap/connection' ;
3
+ import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
2
4
import type { Collection } from '../collection' ;
3
5
import { MongoCompatibilityError , MongoServerError } from '../error' ;
4
6
import { type TODO_NODE_3286 } from '../mongo_types' ;
@@ -7,7 +9,11 @@ import type { ClientSession } from '../sessions';
7
9
import { type TimeoutContext } from '../timeout' ;
8
10
import { type MongoDBNamespace } from '../utils' ;
9
11
import { 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' ;
11
17
import { Aspect , defineAspects , type Hint } from './operation' ;
12
18
13
19
/** @public */
@@ -43,7 +49,8 @@ export interface DeleteStatement {
43
49
}
44
50
45
51
/** @internal */
46
- export class DeleteOperation extends CommandOperation < DeleteResult > {
52
+ export class DeleteOperation extends ModernizedCommandOperation < Document > {
53
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
47
54
override options : DeleteOptions ;
48
55
statements : DeleteStatement [ ] ;
49
56
@@ -66,12 +73,9 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
66
73
return this . statements . every ( op => ( op . limit != null ? op . limit > 0 : true ) ) ;
67
74
}
68
75
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
+
75
79
const ordered = typeof options . ordered === 'boolean' ? options . ordered : true ;
76
80
const command : Document = {
77
81
delete : this . ns . collection ,
@@ -97,13 +101,7 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
97
101
}
98
102
}
99
103
100
- const res : TODO_NODE_3286 = await super . executeCommand (
101
- server ,
102
- session ,
103
- command ,
104
- timeoutContext
105
- ) ;
106
- return res ;
104
+ return command ;
107
105
}
108
106
}
109
107
@@ -112,13 +110,14 @@ export class DeleteOneOperation extends DeleteOperation {
112
110
super ( collection . s . namespace , [ makeDeleteStatement ( filter , { ...options , limit : 1 } ) ] , options ) ;
113
111
}
114
112
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
121
119
if ( this . explain ) return res ;
120
+
122
121
if ( res . code ) throw new MongoServerError ( res ) ;
123
122
if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
124
123
@@ -133,13 +132,14 @@ export class DeleteManyOperation extends DeleteOperation {
133
132
super ( collection . s . namespace , [ makeDeleteStatement ( filter , options ) ] , options ) ;
134
133
}
135
134
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
142
141
if ( this . explain ) return res ;
142
+
143
143
if ( res . code ) throw new MongoServerError ( res ) ;
144
144
if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
145
145
0 commit comments