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 , MongoInvalidArgumentError , MongoServerError } from '../error' ;
4- import type { InferIdType , TODO_NODE_3286 } from '../mongo_types' ;
5- import type { Server } from '../sdam/server' ;
6+ import type { InferIdType } from '../mongo_types' ;
67import type { ClientSession } from '../sessions' ;
78import { formatSort , type Sort , type SortForCmd } from '../sort' ;
8- import { type TimeoutContext } from '../timeout' ;
99import { hasAtomicOperators , type MongoDBNamespace } from '../utils' ;
10- import { type CollationOptions , CommandOperation , type CommandOperationOptions } from './command' ;
10+ import {
11+ type CollationOptions ,
12+ type CommandOperationOptions ,
13+ ModernizedCommandOperation
14+ } from './command' ;
1115import { Aspect , defineAspects , type Hint } from './operation' ;
1216
1317/** @public */
@@ -67,7 +71,8 @@ export interface UpdateStatement {
6771 * @internal
6872 * UpdateOperation is used in bulk write, while UpdateOneOperation and UpdateManyOperation are only used in the collections API
6973 */
70- export class UpdateOperation extends CommandOperation < Document > {
74+ export class UpdateOperation extends ModernizedCommandOperation < Document > {
75+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse ;
7176 override options : UpdateOptions & { ordered ?: boolean } ;
7277 statements : UpdateStatement [ ] ;
7378
@@ -95,12 +100,9 @@ export class UpdateOperation extends CommandOperation<Document> {
95100 return this . statements . every ( op => op . multi == null || op . multi === false ) ;
96101 }
97102
98- override async execute (
99- server : Server ,
100- session : ClientSession | undefined ,
101- timeoutContext : TimeoutContext
102- ) : Promise < Document > {
103+ override buildCommandDocument ( _connection : Connection , _session ?: ClientSession ) : Document {
103104 const options = this . options ?? { } ;
105+
104106 const ordered = typeof options . ordered === 'boolean' ? options . ordered : true ;
105107 const command : Document = {
106108 update : this . ns . collection ,
@@ -130,8 +132,7 @@ export class UpdateOperation extends CommandOperation<Document> {
130132 }
131133 }
132134
133- const res = await super . executeCommand ( server , session , command , timeoutContext ) ;
134- return res ;
135+ return command ;
135136 }
136137}
137138
@@ -149,12 +150,9 @@ export class UpdateOneOperation extends UpdateOperation {
149150 }
150151 }
151152
152- override async execute (
153- server : Server ,
154- session : ClientSession | undefined ,
155- timeoutContext : TimeoutContext
156- ) : Promise < UpdateResult > {
157- const res : TODO_NODE_3286 = await super . execute ( server , session , timeoutContext ) ;
153+ override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
154+ const res = super . handleOk ( response ) ;
155+
158156 if ( this . explain != null ) return res ;
159157 if ( res . code ) throw new MongoServerError ( res ) ;
160158 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
@@ -184,12 +182,9 @@ export class UpdateManyOperation extends UpdateOperation {
184182 }
185183 }
186184
187- override async execute (
188- server : Server ,
189- session : ClientSession | undefined ,
190- timeoutContext : TimeoutContext
191- ) : Promise < UpdateResult > {
192- const res : TODO_NODE_3286 = await super . execute ( server , session , timeoutContext ) ;
185+ override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
186+ const res = super . handleOk ( response ) ;
187+
193188 if ( this . explain != null ) return res ;
194189 if ( res . code ) throw new MongoServerError ( res ) ;
195190 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
@@ -240,13 +235,11 @@ export class ReplaceOneOperation extends UpdateOperation {
240235 }
241236 }
242237
243- override async execute (
244- server : Server ,
245- session : ClientSession | undefined ,
246- timeoutContext : TimeoutContext
247- ) : Promise < UpdateResult > {
248- const res : TODO_NODE_3286 = await super . execute ( server , session , timeoutContext ) ;
238+ override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
239+ const res = super . handleOk ( response ) ;
240+
249241 if ( this . explain != null ) return res ;
242+
250243 if ( res . code ) throw new MongoServerError ( res ) ;
251244 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
252245
0 commit comments