@toa.io/storages.mongodb 1.0.0-alpha.34 → 1.0.0-alpha.341

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,443 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.341](https://github.com/toa-io/toa/compare/v1.0.0-alpha.340...v1.0.0-alpha.341) (2026-10-28)
7
+
8
+ **Note:** Version bump only for package @toa.io/storages.mongodb
9
+
10
+
11
+
12
+
13
+
14
+ # [1.0.0-alpha.340](https://github.com/toa-io/toa/compare/v1.0.0-alpha.339...v1.0.0-alpha.340) (2026-10-28)
15
+
16
+ **Note:** Version bump only for package @toa.io/storages.mongodb
17
+
18
+
19
+
20
+
21
+
22
+ # [1.0.0-alpha.339](https://github.com/toa-io/toa/compare/v1.0.0-alpha.338...v1.0.0-alpha.339) (2026-10-28)
23
+
24
+ **Note:** Version bump only for package @toa.io/storages.mongodb
25
+
26
+
27
+
28
+
29
+
30
+ # [1.0.0-alpha.338](https://github.com/toa-io/toa/compare/v1.0.0-alpha.337...v1.0.0-alpha.338) (2026-10-28)
31
+
32
+ **Note:** Version bump only for package @toa.io/storages.mongodb
33
+
34
+
35
+
36
+
37
+
38
+ # [1.0.0-alpha.337](https://github.com/toa-io/toa/compare/v1.0.0-alpha.336...v1.0.0-alpha.337) (2026-10-28)
39
+
40
+ **Note:** Version bump only for package @toa.io/storages.mongodb
41
+
42
+
43
+
44
+
45
+
46
+ # [1.0.0-alpha.336](https://github.com/toa-io/toa/compare/v1.0.0-alpha.335...v1.0.0-alpha.336) (2026-10-26)
47
+
48
+ **Note:** Version bump only for package @toa.io/storages.mongodb
49
+
50
+
51
+
52
+
53
+
54
+ # [1.0.0-alpha.335](https://github.com/toa-io/toa/compare/v1.0.0-alpha.334...v1.0.0-alpha.335) (2026-10-26)
55
+
56
+ **Note:** Version bump only for package @toa.io/storages.mongodb
57
+
58
+
59
+
60
+
61
+
62
+ # [1.0.0-alpha.334](https://github.com/toa-io/toa/compare/v1.0.0-alpha.333...v1.0.0-alpha.334) (2026-10-26)
63
+
64
+ **Note:** Version bump only for package @toa.io/storages.mongodb
65
+
66
+
67
+
68
+
69
+
70
+ # [1.0.0-alpha.333](https://github.com/toa-io/toa/compare/v1.0.0-alpha.332...v1.0.0-alpha.333) (2026-10-26)
71
+
72
+ ### Bug Fixes
73
+
74
+ * **storages.mongodb:** run a set again where it met a commit in flight ([2e293fe](https://github.com/toa-io/toa/commit/2e293fe1b72c3eac65f659f0061e312945829b6e))
75
+
76
+
77
+ # [1.0.0-alpha.332](https://github.com/toa-io/toa/compare/v1.0.0-alpha.331...v1.0.0-alpha.332) (2026-10-23)
78
+
79
+ ### Bug Fixes
80
+
81
+ * **storages.mongodb:** commit a set where the URL sets timeoutMS ([0b51f02](https://github.com/toa-io/toa/commit/0b51f0281de218dbcb677b75d6dd58685c4e2958))
82
+
83
+
84
+ # [1.0.0-alpha.331](https://github.com/toa-io/toa/compare/v1.0.0-alpha.330...v1.0.0-alpha.331) (2026-10-16)
85
+
86
+ **Note:** Version bump only for package @toa.io/storages.mongodb
87
+
88
+
89
+
90
+
91
+
92
+ # [1.0.0-alpha.330](https://github.com/toa-io/toa/compare/v1.0.0-alpha.329...v1.0.0-alpha.330) (2026-10-15)
93
+
94
+ **Note:** Version bump only for package @toa.io/storages.mongodb
95
+
96
+
97
+
98
+
99
+
100
+ # [1.0.0-alpha.329](https://github.com/toa-io/toa/compare/v1.0.0-alpha.328...v1.0.0-alpha.329) (2026-10-11)
101
+
102
+ **Note:** Version bump only for package @toa.io/storages.mongodb
103
+
104
+
105
+
106
+
107
+
108
+ # [1.0.0-alpha.328](https://github.com/toa-io/toa/compare/v1.0.0-alpha.327...v1.0.0-alpha.328) (2026-10-10)
109
+
110
+ **Note:** Version bump only for package @toa.io/storages.mongodb
111
+
112
+
113
+
114
+
115
+
116
+ # [1.0.0-alpha.327](https://github.com/toa-io/toa/compare/v1.0.0-alpha.326...v1.0.0-alpha.327) (2026-10-10)
117
+
118
+ ### Bug Fixes
119
+
120
+ * **storages.mongodb:** pass a deleted record by when an effect gets or creates ([0cea640](https://github.com/toa-io/toa/commit/0cea6405021c8230e9b68a0f3086ff610332b34d))
121
+
122
+
123
+ # [1.0.0-alpha.326](https://github.com/toa-io/toa/compare/v1.0.0-alpha.325...v1.0.0-alpha.326) (2026-10-06)
124
+
125
+ ### Features
126
+
127
+ * **core:** parse criteria with [@toa](https://github.com/toa).io/rsql ([c4dc9f4](https://github.com/toa-io/toa/commit/c4dc9f41ca2719ac66607c5b14e9ead678baa740))
128
+
129
+
130
+ # [1.0.0-alpha.325](https://github.com/toa-io/toa/compare/v1.0.0-alpha.324...v1.0.0-alpha.325) (2026-10-02)
131
+
132
+ ### Bug Fixes
133
+
134
+ * **storages.mongodb:** kill the cursor of a stream's position whatever type its id comes as ([71c799e](https://github.com/toa-io/toa/commit/71c799ec3694a41cc32890d9e21bb42573b96395))
135
+
136
+
137
+ # [1.0.0-alpha.324](https://github.com/toa-io/toa/compare/v1.0.0-alpha.323...v1.0.0-alpha.324) (2026-10-02)
138
+
139
+ **Note:** Version bump only for package @toa.io/storages.mongodb
140
+
141
+
142
+
143
+
144
+
145
+ # [1.0.0-alpha.323](https://github.com/toa-io/toa/compare/v1.0.0-alpha.322...v1.0.0-alpha.323) (2026-10-01)
146
+
147
+ ### Bug Fixes
148
+
149
+ * **storages.mongodb:** store the moments an assignment sets as dates ([240102d](https://github.com/toa-io/toa/commit/240102db5b218e0b0a3a7b097c77852e749e76ef))
150
+
151
+
152
+ # [1.0.0-alpha.322](https://github.com/toa-io/toa/compare/v1.0.0-alpha.321...v1.0.0-alpha.322) (2026-09-29)
153
+
154
+ **Note:** Version bump only for package @toa.io/storages.mongodb
155
+
156
+
157
+
158
+
159
+
160
+ # [1.0.0-alpha.321](https://github.com/toa-io/toa/compare/v1.0.0-alpha.320...v1.0.0-alpha.321) (2026-09-28)
161
+
162
+ ### Bug Fixes
163
+
164
+ * **storages.mongodb:** commit a set of entries all or nothing ([dafecf0](https://github.com/toa-io/toa/commit/dafecf096bac99c4aca5b697a0d7d9f6f6d82daf))
165
+
166
+
167
+ # [1.0.0-alpha.320](https://github.com/toa-io/toa/compare/v1.0.0-alpha.319...v1.0.0-alpha.320) (2026-09-28)
168
+
169
+ ### Features
170
+
171
+ * page a stream by CREATED, and stop it after its first page ([038dc52](https://github.com/toa-io/toa/commit/038dc52f2db1a4dd58c6ec58a00de8914b3d38a3))
172
+
173
+
174
+ # [1.0.0-alpha.319](https://github.com/toa-io/toa/compare/v1.0.0-alpha.318...v1.0.0-alpha.319) (2026-09-27)
175
+
176
+ ### Features
177
+
178
+ * **storages.mongodb:** read a set and its changes from a token ([d0a8955](https://github.com/toa-io/toa/commit/d0a8955683b7566e704f7e9cde69f67272c7be1b))
179
+
180
+
181
+ # [1.0.0-alpha.318](https://github.com/toa-io/toa/compare/v1.0.0-alpha.317...v1.0.0-alpha.318) (2026-09-23)
182
+
183
+ **Note:** Version bump only for package @toa.io/storages.mongodb
184
+
185
+
186
+
187
+
188
+
189
+ # [1.0.0-alpha.317](https://github.com/toa-io/toa/compare/v1.0.0-alpha.316...v1.0.0-alpha.317) (2026-09-23)
190
+
191
+ **Note:** Version bump only for package @toa.io/storages.mongodb
192
+
193
+
194
+
195
+
196
+
197
+ # [1.0.0-alpha.316](https://github.com/toa-io/toa/compare/v1.0.0-alpha.315...v1.0.0-alpha.316) (2026-09-23)
198
+
199
+ **Note:** Version bump only for package @toa.io/storages.mongodb
200
+
201
+
202
+
203
+
204
+
205
+ # [1.0.0-alpha.315](https://github.com/toa-io/toa/compare/v1.0.0-alpha.314...v1.0.0-alpha.315) (2026-09-23)
206
+
207
+ **Note:** Version bump only for package @toa.io/storages.mongodb
208
+
209
+
210
+
211
+
212
+
213
+ # [1.0.0-alpha.314](https://github.com/toa-io/toa/compare/v1.0.0-alpha.313...v1.0.0-alpha.314) (2026-09-19)
214
+
215
+ * feat(core)!: let an operation state how long its calls are remembered ([af177c2](https://github.com/toa-io/toa/commit/af177c2ab3d00d475840b5ef9e612f04e82b72bd))
216
+
217
+ ### BREAKING CHANGES
218
+
219
+ * `inbox.retention` under 600 is refused. See
220
+ migrations/313.md.
221
+
222
+
223
+ # [1.0.0-alpha.313](https://github.com/toa-io/toa/compare/v1.0.0-alpha.312...v1.0.0-alpha.313) (2026-09-18)
224
+
225
+ **Note:** Version bump only for package @toa.io/storages.mongodb
226
+
227
+
228
+
229
+
230
+
231
+ # [1.0.0-alpha.312](https://github.com/toa-io/toa/compare/v1.0.0-alpha.311...v1.0.0-alpha.312) (2026-09-18)
232
+
233
+ **Note:** Version bump only for package @toa.io/storages.mongodb
234
+
235
+
236
+
237
+
238
+
239
+ # [1.0.0-alpha.311](https://github.com/toa-io/toa/compare/v1.0.0-alpha.310...v1.0.0-alpha.311) (2026-09-17)
240
+
241
+ ### Features
242
+
243
+ * name the database after the scope ([4d7203f](https://github.com/toa-io/toa/commit/4d7203fd18828895272a9dae76e351d92b49277f))
244
+
245
+
246
+ # [1.0.0-alpha.310](https://github.com/toa-io/toa/compare/v1.0.0-alpha.309...v1.0.0-alpha.310) (2026-09-16)
247
+
248
+ **Note:** Version bump only for package @toa.io/storages.mongodb
249
+
250
+
251
+
252
+
253
+
254
+ # [1.0.0-alpha.309](https://github.com/toa-io/toa/compare/v1.0.0-alpha.308...v1.0.0-alpha.309) (2026-09-16)
255
+
256
+ **Note:** Version bump only for package @toa.io/storages.mongodb
257
+
258
+
259
+
260
+
261
+
262
+ # [1.0.0-alpha.308](https://github.com/toa-io/toa/compare/v1.0.0-alpha.307...v1.0.0-alpha.308) (2026-09-15)
263
+
264
+ **Note:** Version bump only for package @toa.io/storages.mongodb
265
+
266
+
267
+
268
+
269
+
270
+ # [1.0.0-alpha.307](https://github.com/toa-io/toa/compare/v1.0.0-alpha.306...v1.0.0-alpha.307) (2026-09-15)
271
+
272
+ **Note:** Version bump only for package @toa.io/storages.mongodb
273
+
274
+
275
+
276
+
277
+
278
+ # [1.0.0-alpha.306](https://github.com/toa-io/toa/compare/v1.0.0-alpha.305...v1.0.0-alpha.306) (2026-09-14)
279
+
280
+ **Note:** Version bump only for package @toa.io/storages.mongodb
281
+
282
+
283
+
284
+
285
+
286
+ # [1.0.0-alpha.305](https://github.com/toa-io/toa/compare/v1.0.0-alpha.304...v1.0.0-alpha.305) (2026-09-13)
287
+
288
+ **Note:** Version bump only for package @toa.io/storages.mongodb
289
+
290
+
291
+
292
+
293
+
294
+ # [1.0.0-alpha.304](https://github.com/toa-io/toa/compare/v1.0.0-alpha.303...v1.0.0-alpha.304) (2026-09-13)
295
+
296
+ **Note:** Version bump only for package @toa.io/storages.mongodb
297
+
298
+
299
+
300
+
301
+
302
+ # [1.0.0-alpha.303](https://github.com/toa-io/toa/compare/v1.0.0-alpha.302...v1.0.0-alpha.303) (2026-09-12)
303
+
304
+ ### Features
305
+
306
+ * **metrics:** measure storage, stash, blob storages and fetch ([252298b](https://github.com/toa-io/toa/commit/252298bb9f34421694da4ee89742d62b47c39dfb))
307
+
308
+ ### Performance Improvements
309
+
310
+ * **storages.mongodb:** rename a record's _id to id in place ([4aeb2a1](https://github.com/toa-io/toa/commit/4aeb2a1d61f7f2b0ddab203b5887152e8917ef7f))
311
+
312
+
313
+ # [1.0.0-alpha.302](https://github.com/toa-io/toa/compare/v1.0.0-alpha.301...v1.0.0-alpha.302) (2026-09-11)
314
+
315
+ **Note:** Version bump only for package @toa.io/storages.mongodb
316
+
317
+
318
+
319
+
320
+
321
+ # [1.0.0-alpha.301](https://github.com/toa-io/toa/compare/v1.0.0-alpha.300...v1.0.0-alpha.301) (2026-09-11)
322
+
323
+ **Note:** Version bump only for package @toa.io/storages.mongodb
324
+
325
+
326
+
327
+
328
+
329
+ # [1.0.0-alpha.300](https://github.com/toa-io/toa/compare/v1.0.0-alpha.299...v1.0.0-alpha.300) (2026-09-11)
330
+
331
+ * feat(core)!: an operation may ask to run once ([dca616c](https://github.com/toa-io/toa/commit/dca616cb380a7a389e277875d3bd5ca55a6e4d45))
332
+
333
+ ### Bug Fixes
334
+
335
+ * **extensions:** what a factory remembers does not outlive the tree it was made for ([dd36631](https://github.com/toa-io/toa/commit/dd3663160f500eadfb701bf840ef3741a2d075f0))
336
+
337
+ ### Features
338
+
339
+ * **core:** an assignment may ask to run once as well ([10fbcbd](https://github.com/toa-io/toa/commit/10fbcbd86a5e82960e65f62c09d0a465ae8d0353))
340
+
341
+ ### BREAKING CHANGES
342
+
343
+ * `Storage.store`, `.upsert` and `.ensure` take one more
344
+ argument, and `Storage` has two more members. A connector that ignores them
345
+ works exactly as it did; a component that asks it for `once` is refused at
346
+ boot. See migrations/299.md.
347
+
348
+
349
+ # [1.0.0-alpha.299](https://github.com/toa-io/toa/compare/v1.0.0-alpha.298...v1.0.0-alpha.299) (2026-09-10)
350
+
351
+ ### Features
352
+
353
+ * **core:** a record carries the region that wrote it ([13ed187](https://github.com/toa-io/toa/commit/13ed187604f06dec66feec2e26ccf9dae30bb048))
354
+ * **core:** an outbox row is published to destinations ([cfb77b4](https://github.com/toa-io/toa/commit/cfb77b4826ff0f9560769a0996981e143d6525af))
355
+
356
+
357
+ # [1.0.0-alpha.298](https://github.com/toa-io/toa/compare/v1.0.0-alpha.297...v1.0.0-alpha.298) (2026-09-08)
358
+
359
+ **Note:** Version bump only for package @toa.io/storages.mongodb
360
+
361
+
362
+
363
+
364
+
365
+ # [1.0.0-alpha.297](https://github.com/toa-io/toa/compare/v1.0.0-alpha.296...v1.0.0-alpha.297) (2026-09-08)
366
+
367
+ **Note:** Version bump only for package @toa.io/storages.mongodb
368
+
369
+
370
+
371
+
372
+
373
+ # [1.0.0-alpha.296](https://github.com/toa-io/toa/compare/v1.0.0-alpha.295...v1.0.0-alpha.296) (2026-09-08)
374
+
375
+ **Note:** Version bump only for package @toa.io/storages.mongodb
376
+
377
+
378
+
379
+
380
+
381
+ # [1.0.0-alpha.295](https://github.com/toa-io/toa/compare/v1.0.0-alpha.294...v1.0.0-alpha.295) (2026-09-07)
382
+
383
+ **Note:** Version bump only for package @toa.io/storages.mongodb
384
+
385
+
386
+
387
+
388
+
389
+ # [1.0.0-alpha.294](https://github.com/toa-io/toa/compare/v1.0.0-alpha.293...v1.0.0-alpha.294) (2026-09-07)
390
+
391
+ **Note:** Version bump only for package @toa.io/storages.mongodb
392
+
393
+
394
+
395
+
396
+
397
+ # [1.0.0-alpha.293](https://github.com/toa-io/toa/compare/v1.0.0-alpha.292...v1.0.0-alpha.293) (2026-09-07)
398
+
399
+ **Note:** Version bump only for package @toa.io/storages.mongodb
400
+
401
+
402
+
403
+
404
+
405
+ # [1.0.0-alpha.292](https://github.com/toa-io/toa/compare/v1.0.0-alpha.291...v1.0.0-alpha.292) (2026-09-07)
406
+
407
+ ### Features
408
+
409
+ * **definitions:** what a package declares is read from one package ([7052341](https://github.com/toa-io/toa/commit/70523411b5d9e2b204c999aa02365173f3bb518d))
410
+
411
+
412
+ # [1.0.0-alpha.291](https://github.com/toa-io/toa/compare/v1.0.0-alpha.290...v1.0.0-alpha.291) (2026-09-07)
413
+
414
+ **Note:** Version bump only for package @toa.io/storages.mongodb
415
+
416
+
417
+
418
+
419
+
420
+ # [1.0.0-alpha.289](https://github.com/toa-io/toa/compare/v1.0.0-alpha.288...v1.0.0-alpha.289) (2026-09-07)
421
+
422
+ * A deploy moves only what changed, and a component sees none of the runtime's environment (#1073) ([f38e3db](https://github.com/toa-io/toa/commit/f38e3db533f24db866c57bfa1ef294eff1eaf499)), closes [#1073](https://github.com/toa-io/toa/issues/1073) [#1064](https://github.com/toa-io/toa/issues/1064) [#1066](https://github.com/toa-io/toa/issues/1066) [#1067](https://github.com/toa-io/toa/issues/1067) [#1068](https://github.com/toa-io/toa/issues/1068) [#1069](https://github.com/toa-io/toa/issues/1069) [#1071](https://github.com/toa-io/toa/issues/1071) [#1070](https://github.com/toa-io/toa/issues/1070) [#1072](https://github.com/toa-io/toa/issues/1072)
423
+
424
+ ### BREAKING CHANGES
425
+
426
+ * a component that read `process.env.TOA_*` reads `context` instead;
427
+ `echo(input)` no longer substitutes from the environment; a bash operation sees no
428
+ `TOA_*`; images no longer set `USER node` — see migrations/289.md.
429
+
430
+
431
+ # [1.0.0-alpha.288](https://github.com/toa-io/toa/compare/v1.0.0-alpha.287...v1.0.0-alpha.288) (2026-09-06)
432
+
433
+ **Note:** Version bump only for package @toa.io/storages.mongodb
434
+
435
+
436
+
437
+
438
+
439
+ # [1.0.0-alpha.287](https://github.com/toa-io/toa/compare/v1.0.0-alpha.286...v1.0.0-alpha.287) (2026-09-06)
440
+
441
+ ### Features
442
+
443
+ * **mongodb:** a migration says what it is doing ([a917a81](https://github.com/toa-io/toa/commit/a917a81fdc94eb23fd73182c0edf891e6b2df843))
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@toa.io/storages.mongodb",
3
- "version": "1.0.0-alpha.34",
3
+ "version": "1.0.0-alpha.341",
4
+ "type": "module",
4
5
  "description": "Toa MongoDB Storage Connector",
5
6
  "author": "temich <tema.gurtovoy@gmail.com>",
6
7
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -19,13 +20,13 @@
19
20
  "test": "echo \"Error: run tests from root\" && exit 1"
20
21
  },
21
22
  "dependencies": {
22
- "@toa.io/console": "1.0.0-alpha.34",
23
- "@toa.io/conveyor": "1.0.0-alpha.34",
24
- "@toa.io/core": "1.0.0-alpha.34",
25
- "@toa.io/generic": "1.0.0-alpha.34",
26
- "@toa.io/pointer": "1.0.0-alpha.34",
27
- "mongodb": "6.3.0",
28
- "saslprep": "1.0.3"
23
+ "@toa.io/conveyor": "1.0.0-alpha.332",
24
+ "@toa.io/core": "1.0.0-alpha.333",
25
+ "@toa.io/definitions": "1.0.0-alpha.341",
26
+ "@toa.io/generic": "1.0.0-alpha.332",
27
+ "@toa.io/pointer": "1.0.0-alpha.332",
28
+ "mongodb": "7.7.0",
29
+ "openspan": "1.0.0-alpha.330"
29
30
  },
30
- "gitHead": "caf71c04ebd589ff54a25f533b975484aaf9a254"
31
+ "gitHead": "ffad087737a8416703887d311058dd9f32ac3c69"
31
32
  }
package/readme.md ADDED
@@ -0,0 +1,43 @@
1
+ # MongoDB Storage
2
+
3
+ ## Server
4
+
5
+ MongoDB 8.0 or later. An earlier server refuses a `transition` of scope `entries`
6
+ ([Operations](/documentation/component/declaration.md#operations)).
7
+
8
+ ## Tracing
9
+
10
+ Commands are recorded as `client` spans within the trace of the current invocation.
11
+
12
+ Spans are named `{command} {collection}` and carry `db.*` attributes following the
13
+ [OpenTelemetry semantic conventions](https://opentelemetry.io/docs/specs/semconv/database/mongodb/):
14
+ `db.system`, `db.namespace`, `db.collection.name`, `db.operation.name`.
15
+
16
+ Commands executed outside of a sampled trace context (e.g. index management on startup)
17
+ and internal driver commands (`hello`, `ping`, authentication) are not recorded.
18
+
19
+ Monitoring is client-side only and does not affect the MongoDB server. Span recording
20
+ adds no waiting to the query path: exporting is buffered and happens in the background.
21
+
22
+ ## Stream tokens
23
+
24
+ A [stream](/documentation/collections.md) ends with a token of changes where two things hold:
25
+
26
+ - **MongoDB runs as a replica set**, which it does wherever there is an outbox.
27
+ - **The collection keeps images** of what a record was before each change, which is how a change
28
+ that takes an entry out of the collection is told from a change outside it. They cost a copy of every
29
+ changed record for as long as the oplog holds it, so a collection keeps them only by a
30
+ [migration](/documentation/component/declaration.md#migrations):
31
+
32
+ ```yaml
33
+ # migrations/0003-images.yaml
34
+ - images: true
35
+ ```
36
+
37
+ `- images: false` stops keeping them, and a token issued before is then refused with `410`.
38
+
39
+ A token lasts as long as the oplog of the replica set holds the point it names — its window, which
40
+ the size of the oplog and the rate of writes decide.
41
+
42
+ A read from a token scans the oplog from the point it names: it costs what the whole replica set
43
+ wrote since, whatever of it concerns the collection.
package/src/bulk.js ADDED
@@ -0,0 +1,26 @@
1
+ import { MongoClientBulkWriteError, MongoServerError } from 'mongodb'
2
+
3
+ /**
4
+ * The client's bulk write, where a command the server refused is thrown as the server sent it.
5
+ *
6
+ * The driver wraps that refusal in an error that carries none of its labels, and a transaction
7
+ * runs again only what is labelled as worth running again: a write conflict with a commit in
8
+ * flight would end the transaction as a failure of its own. A write the server refused one by
9
+ * one is left as it is, read off `writeErrors`.
10
+ *
11
+ * @param {import('mongodb').MongoClient} client
12
+ * @param {import('mongodb').AnyClientBulkWriteModel[]} operations
13
+ * @param {import('mongodb').ClientBulkWriteOptions} options
14
+ */
15
+ export async function bulkWrite(client, operations, options) {
16
+ try {
17
+ return await client.bulkWrite(operations, options)
18
+ } catch (error) {
19
+ if (
20
+ error instanceof MongoClientBulkWriteError &&
21
+ error.cause instanceof MongoServerError
22
+ )
23
+ throw error.cause
24
+ else throw error
25
+ }
26
+ }