11import type { Document } from '../bson' ;
22import { type Connection } from '../cmap/connection' ;
33import { MongoDBResponse } from '../cmap/wire_protocol/responses' ;
4- import type { Collection } from '../collection' ;
54import { MongoCompatibilityError , MongoInvalidArgumentError , MongoServerError } from '../error' ;
65import type { InferIdType } from '../mongo_types' ;
76import type { ClientSession } from '../sessions' ;
87import { formatSort , type Sort , type SortForCmd } from '../sort' ;
9- import { hasAtomicOperators , type MongoDBNamespace } from '../utils' ;
8+ import {
9+ hasAtomicOperators ,
10+ type MongoDBCollectionNamespace ,
11+ type MongoDBNamespace
12+ } from '../utils' ;
1013import {
1114 type CollationOptions ,
1215 type CommandOperationOptions ,
@@ -136,21 +139,27 @@ export class UpdateOperation extends ModernizedCommandOperation<Document> {
136139
137140/** @internal */
138141export class UpdateOneOperation extends UpdateOperation {
139- constructor ( collection : Collection , filter : Document , update : Document , options : UpdateOptions ) {
140- super (
141- collection . s . namespace ,
142- [ makeUpdateStatement ( filter , update , { ...options , multi : false } ) ] ,
143- options
144- ) ;
142+ constructor (
143+ ns : MongoDBCollectionNamespace ,
144+ filter : Document ,
145+ update : Document ,
146+ options : UpdateOptions
147+ ) {
148+ super ( ns , [ makeUpdateStatement ( filter , update , { ...options , multi : false } ) ] , options ) ;
145149
146150 if ( ! hasAtomicOperators ( update , options ) ) {
147151 throw new MongoInvalidArgumentError ( 'Update document requires atomic operators' ) ;
148152 }
149153 }
150154
151- override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
155+ override handleOk (
156+ response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
157+ ) : UpdateResult {
152158 const res = super . handleOk ( response ) ;
159+
160+ // @ts -expect-error Explain typing is broken
153161 if ( this . explain != null ) return res ;
162+
154163 if ( res . code ) throw new MongoServerError ( res ) ;
155164 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
156165
@@ -167,20 +176,25 @@ export class UpdateOneOperation extends UpdateOperation {
167176
168177/** @internal */
169178export class UpdateManyOperation extends UpdateOperation {
170- constructor ( collection : Collection , filter : Document , update : Document , options : UpdateOptions ) {
171- super (
172- collection . s . namespace ,
173- [ makeUpdateStatement ( filter , update , { ...options , multi : true } ) ] ,
174- options
175- ) ;
179+ constructor (
180+ ns : MongoDBCollectionNamespace ,
181+ filter : Document ,
182+ update : Document ,
183+ options : UpdateOptions
184+ ) {
185+ super ( ns , [ makeUpdateStatement ( filter , update , { ...options , multi : true } ) ] , options ) ;
176186
177187 if ( ! hasAtomicOperators ( update , options ) ) {
178188 throw new MongoInvalidArgumentError ( 'Update document requires atomic operators' ) ;
179189 }
180190 }
181191
182- override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
192+ override handleOk (
193+ response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
194+ ) : UpdateResult {
183195 const res = super . handleOk ( response ) ;
196+
197+ // @ts -expect-error Explain typing is broken
184198 if ( this . explain != null ) return res ;
185199 if ( res . code ) throw new MongoServerError ( res ) ;
186200 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
@@ -215,24 +229,24 @@ export interface ReplaceOptions extends CommandOperationOptions {
215229/** @internal */
216230export class ReplaceOneOperation extends UpdateOperation {
217231 constructor (
218- collection : Collection ,
232+ ns : MongoDBCollectionNamespace ,
219233 filter : Document ,
220234 replacement : Document ,
221235 options : ReplaceOptions
222236 ) {
223- super (
224- collection . s . namespace ,
225- [ makeUpdateStatement ( filter , replacement , { ...options , multi : false } ) ] ,
226- options
227- ) ;
237+ super ( ns , [ makeUpdateStatement ( filter , replacement , { ...options , multi : false } ) ] , options ) ;
228238
229239 if ( hasAtomicOperators ( replacement ) ) {
230240 throw new MongoInvalidArgumentError ( 'Replacement document must not contain atomic operators' ) ;
231241 }
232242 }
233243
234- override handleOk ( response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE > ) : Document {
244+ override handleOk (
245+ response : InstanceType < typeof this . SERVER_COMMAND_RESPONSE_TYPE >
246+ ) : UpdateResult {
235247 const res = super . handleOk ( response ) ;
248+
249+ // @ts -expect-error Explain typing is broken
236250 if ( this . explain != null ) return res ;
237251 if ( res . code ) throw new MongoServerError ( res ) ;
238252 if ( res . writeErrors ) throw new MongoServerError ( res . writeErrors [ 0 ] ) ;
0 commit comments