1
1
import { type Document } from '../../bson' ;
2
2
import { DocumentSequence } from '../../cmap/commands' ;
3
+ import type { Filter , OptionalId , UpdateFilter , WithoutId } from '../../mongo_types' ;
4
+ import { type CollationOptions } from '../command' ;
5
+ import { type Hint } from '../operation' ;
3
6
import type {
4
7
AnyClientBulkWriteModel ,
5
8
ClientBulkWriteOptions ,
@@ -66,9 +69,7 @@ export class ClientBulkWriteCommandBuilder {
66
69
}
67
70
}
68
71
69
- const nsInfo = Array . from ( namespaces . keys ( ) ) . map ( ns => {
70
- return { ns : ns } ;
71
- } ) ;
72
+ const nsInfo = Array . from ( namespaces . keys ( ) , ns => ( { ns } ) ) ;
72
73
73
74
// The base command.
74
75
const command : ClientBulkWriteCommand = {
@@ -83,27 +84,42 @@ export class ClientBulkWriteCommandBuilder {
83
84
command . bypassDocumentValidation = this . options . bypassDocumentValidation ;
84
85
}
85
86
// Add let if it was present in the options.
86
- if ( 'let' in this . options ) {
87
+ if ( this . options . let ) {
87
88
command . let = this . options . let ;
88
89
}
89
90
return [ command ] ;
90
91
}
91
92
}
92
93
94
+ /** @internal */
95
+ export interface InsertOperation < TSchema extends Document = Document > {
96
+ insert : number ;
97
+ document : OptionalId < TSchema > ;
98
+ }
99
+
93
100
/**
94
101
* Build the insert one operation.
95
102
* @param model - The insert one model.
96
103
* @param index - The namespace index.
97
104
* @returns the operation.
98
105
*/
99
106
export const buildInsertOneOperation = ( model : ClientInsertOneModel , index : number ) : Document => {
100
- const document : Document = {
107
+ const document : InsertOperation = {
101
108
insert : index ,
102
109
document : model . document
103
110
} ;
104
111
return document ;
105
112
} ;
106
113
114
+ /** @internal */
115
+ export interface DeleteOperation < TSchema extends Document = Document > {
116
+ delete : number ;
117
+ multi : boolean ;
118
+ filter : Filter < TSchema > ;
119
+ hint ?: Hint ;
120
+ collation ?: CollationOptions ;
121
+ }
122
+
107
123
/**
108
124
* Build the delete one operation.
109
125
* @param model - The insert many model.
@@ -131,8 +147,8 @@ function createDeleteOperation(
131
147
model : ClientDeleteOneModel | ClientDeleteManyModel ,
132
148
index : number ,
133
149
multi : boolean
134
- ) : Document {
135
- const document : Document = {
150
+ ) : DeleteOperation {
151
+ const document : DeleteOperation = {
136
152
delete : index ,
137
153
multi : multi ,
138
154
filter : model . filter
@@ -146,13 +162,27 @@ function createDeleteOperation(
146
162
return document ;
147
163
}
148
164
165
+ /** @internal */
166
+ export interface UpdateOperation < TSchema extends Document = Document > {
167
+ update : number ;
168
+ multi : boolean ;
169
+ filter : Filter < TSchema > ;
170
+ updateMods : UpdateFilter < TSchema > | Document [ ] ;
171
+ hint ?: Hint ;
172
+ upsert ?: boolean ;
173
+ arrayFilters ?: Document [ ] ;
174
+ }
175
+
149
176
/**
150
177
* Build the update one operation.
151
178
* @param model - The update one model.
152
179
* @param index - The namespace index.
153
180
* @returns the operation.
154
181
*/
155
- export const buildUpdateOneOperation = ( model : ClientUpdateOneModel , index : number ) : Document => {
182
+ export const buildUpdateOneOperation = (
183
+ model : ClientUpdateOneModel ,
184
+ index : number
185
+ ) : UpdateOperation => {
156
186
return createUpdateOperation ( model , index , false ) ;
157
187
} ;
158
188
@@ -162,7 +192,10 @@ export const buildUpdateOneOperation = (model: ClientUpdateOneModel, index: numb
162
192
* @param index - The namespace index.
163
193
* @returns the operation.
164
194
*/
165
- export const buildUpdateManyOperation = ( model : ClientUpdateManyModel , index : number ) : Document => {
195
+ export const buildUpdateManyOperation = (
196
+ model : ClientUpdateManyModel ,
197
+ index : number
198
+ ) : UpdateOperation => {
166
199
return createUpdateOperation ( model , index , true ) ;
167
200
} ;
168
201
@@ -173,8 +206,8 @@ function createUpdateOperation(
173
206
model : ClientUpdateOneModel | ClientUpdateManyModel ,
174
207
index : number ,
175
208
multi : boolean
176
- ) : Document {
177
- const document : Document = {
209
+ ) : UpdateOperation {
210
+ const document : UpdateOperation = {
178
211
update : index ,
179
212
multi : multi ,
180
213
filter : model . filter ,
@@ -192,14 +225,27 @@ function createUpdateOperation(
192
225
return document ;
193
226
}
194
227
228
+ /** @internal */
229
+ export interface ReplaceOneOperation < TSchema extends Document = Document > {
230
+ update : number ;
231
+ multi : boolean ;
232
+ filter : Filter < TSchema > ;
233
+ updateMods : WithoutId < TSchema > ;
234
+ hint ?: Hint ;
235
+ upsert ?: boolean ;
236
+ }
237
+
195
238
/**
196
239
* Build the replace one operation.
197
240
* @param model - The replace one model.
198
241
* @param index - The namespace index.
199
242
* @returns the operation.
200
243
*/
201
- export const buildReplaceOneOperation = ( model : ClientReplaceOneModel , index : number ) : Document => {
202
- const document : Document = {
244
+ export const buildReplaceOneOperation = (
245
+ model : ClientReplaceOneModel ,
246
+ index : number
247
+ ) : ReplaceOneOperation => {
248
+ const document : ReplaceOneOperation = {
203
249
update : index ,
204
250
multi : false ,
205
251
filter : model . filter ,
0 commit comments