mongodb 4.0.0 → 4.1.2

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.
Files changed (246) hide show
  1. package/README.md +62 -30
  2. package/lib/bson.js +1 -0
  3. package/lib/bson.js.map +1 -1
  4. package/lib/bulk/common.js +53 -30
  5. package/lib/bulk/common.js.map +1 -1
  6. package/lib/bulk/ordered.js +3 -2
  7. package/lib/bulk/ordered.js.map +1 -1
  8. package/lib/bulk/unordered.js +3 -2
  9. package/lib/bulk/unordered.js.map +1 -1
  10. package/lib/change_stream.js +23 -13
  11. package/lib/change_stream.js.map +1 -1
  12. package/lib/cmap/auth/auth_provider.js +2 -1
  13. package/lib/cmap/auth/auth_provider.js.map +1 -1
  14. package/lib/cmap/auth/gssapi.js +5 -4
  15. package/lib/cmap/auth/gssapi.js.map +1 -1
  16. package/lib/cmap/auth/mongo_credentials.js +9 -5
  17. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  18. package/lib/cmap/auth/mongocr.js +2 -2
  19. package/lib/cmap/auth/mongocr.js.map +1 -1
  20. package/lib/cmap/auth/mongodb_aws.js +32 -32
  21. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  22. package/lib/cmap/auth/plain.js +1 -1
  23. package/lib/cmap/auth/plain.js.map +1 -1
  24. package/lib/cmap/auth/scram.js +15 -12
  25. package/lib/cmap/auth/scram.js.map +1 -1
  26. package/lib/cmap/auth/x509.js +2 -2
  27. package/lib/cmap/auth/x509.js.map +1 -1
  28. package/lib/cmap/command_monitoring_events.js +26 -10
  29. package/lib/cmap/command_monitoring_events.js.map +1 -1
  30. package/lib/cmap/commands.js +9 -5
  31. package/lib/cmap/commands.js.map +1 -1
  32. package/lib/cmap/connect.js +23 -9
  33. package/lib/cmap/connect.js.map +1 -1
  34. package/lib/cmap/connection.js +43 -46
  35. package/lib/cmap/connection.js.map +1 -1
  36. package/lib/cmap/connection_pool.js +113 -15
  37. package/lib/cmap/connection_pool.js.map +1 -1
  38. package/lib/cmap/connection_pool_events.js +3 -1
  39. package/lib/cmap/connection_pool_events.js.map +1 -1
  40. package/lib/cmap/errors.js +3 -3
  41. package/lib/cmap/errors.js.map +1 -1
  42. package/lib/cmap/message_stream.js +1 -1
  43. package/lib/cmap/message_stream.js.map +1 -1
  44. package/lib/cmap/metrics.js +62 -0
  45. package/lib/cmap/metrics.js.map +1 -0
  46. package/lib/cmap/stream_description.js +3 -1
  47. package/lib/cmap/stream_description.js.map +1 -1
  48. package/lib/cmap/wire_protocol/compression.js +22 -9
  49. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  50. package/lib/cmap/wire_protocol/shared.js +1 -1
  51. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  52. package/lib/collection.js +23 -18
  53. package/lib/collection.js.map +1 -1
  54. package/lib/connection_string.js +76 -30
  55. package/lib/connection_string.js.map +1 -1
  56. package/lib/cursor/abstract_cursor.js +75 -68
  57. package/lib/cursor/abstract_cursor.js.map +1 -1
  58. package/lib/cursor/aggregation_cursor.js +47 -9
  59. package/lib/cursor/aggregation_cursor.js.map +1 -1
  60. package/lib/cursor/find_cursor.js +53 -13
  61. package/lib/cursor/find_cursor.js.map +1 -1
  62. package/lib/db.js +21 -14
  63. package/lib/db.js.map +1 -1
  64. package/lib/deps.js +16 -5
  65. package/lib/deps.js.map +1 -1
  66. package/lib/encrypter.js +5 -8
  67. package/lib/encrypter.js.map +1 -1
  68. package/lib/error.js +230 -34
  69. package/lib/error.js.map +1 -1
  70. package/lib/explain.js +2 -2
  71. package/lib/explain.js.map +1 -1
  72. package/lib/gridfs/download.js +22 -47
  73. package/lib/gridfs/download.js.map +1 -1
  74. package/lib/gridfs/index.js +4 -3
  75. package/lib/gridfs/index.js.map +1 -1
  76. package/lib/gridfs/upload.js +13 -21
  77. package/lib/gridfs/upload.js.map +1 -1
  78. package/lib/index.js +27 -2
  79. package/lib/index.js.map +1 -1
  80. package/lib/logger.js +3 -2
  81. package/lib/logger.js.map +1 -1
  82. package/lib/mongo_client.js +5 -8
  83. package/lib/mongo_client.js.map +1 -1
  84. package/lib/mongo_types.js.map +1 -1
  85. package/lib/operations/add_user.js +2 -3
  86. package/lib/operations/add_user.js.map +1 -1
  87. package/lib/operations/aggregate.js +12 -9
  88. package/lib/operations/aggregate.js.map +1 -1
  89. package/lib/operations/command.js +5 -7
  90. package/lib/operations/command.js.map +1 -1
  91. package/lib/operations/common_functions.js +1 -1
  92. package/lib/operations/common_functions.js.map +1 -1
  93. package/lib/operations/connect.js +3 -2
  94. package/lib/operations/connect.js.map +1 -1
  95. package/lib/operations/count.js +1 -1
  96. package/lib/operations/count.js.map +1 -1
  97. package/lib/operations/count_documents.js +1 -1
  98. package/lib/operations/count_documents.js.map +1 -1
  99. package/lib/operations/delete.js +5 -5
  100. package/lib/operations/delete.js.map +1 -1
  101. package/lib/operations/distinct.js +2 -2
  102. package/lib/operations/distinct.js.map +1 -1
  103. package/lib/operations/estimated_document_count.js +5 -1
  104. package/lib/operations/estimated_document_count.js.map +1 -1
  105. package/lib/operations/eval.js.map +1 -1
  106. package/lib/operations/execute_operation.js +31 -17
  107. package/lib/operations/execute_operation.js.map +1 -1
  108. package/lib/operations/find.js +13 -9
  109. package/lib/operations/find.js.map +1 -1
  110. package/lib/operations/find_and_modify.js +9 -9
  111. package/lib/operations/find_and_modify.js.map +1 -1
  112. package/lib/operations/indexes.js +8 -3
  113. package/lib/operations/indexes.js.map +1 -1
  114. package/lib/operations/insert.js +5 -3
  115. package/lib/operations/insert.js.map +1 -1
  116. package/lib/operations/is_capped.js +2 -1
  117. package/lib/operations/is_capped.js.map +1 -1
  118. package/lib/operations/list_collections.js +6 -3
  119. package/lib/operations/list_collections.js.map +1 -1
  120. package/lib/operations/map_reduce.js +1 -1
  121. package/lib/operations/map_reduce.js.map +1 -1
  122. package/lib/operations/operation.js +3 -1
  123. package/lib/operations/operation.js.map +1 -1
  124. package/lib/operations/options_operation.js +2 -1
  125. package/lib/operations/options_operation.js.map +1 -1
  126. package/lib/operations/profiling_level.js +4 -2
  127. package/lib/operations/profiling_level.js.map +1 -1
  128. package/lib/operations/set_profiling_level.js +4 -2
  129. package/lib/operations/set_profiling_level.js.map +1 -1
  130. package/lib/operations/update.js +12 -12
  131. package/lib/operations/update.js.map +1 -1
  132. package/lib/operations/validate_collection.js +6 -5
  133. package/lib/operations/validate_collection.js.map +1 -1
  134. package/lib/promise_provider.js +1 -1
  135. package/lib/promise_provider.js.map +1 -1
  136. package/lib/read_preference.js +8 -8
  137. package/lib/read_preference.js.map +1 -1
  138. package/lib/sdam/common.js +12 -10
  139. package/lib/sdam/common.js.map +1 -1
  140. package/lib/sdam/server.js +90 -25
  141. package/lib/sdam/server.js.map +1 -1
  142. package/lib/sdam/server_description.js +9 -4
  143. package/lib/sdam/server_description.js.map +1 -1
  144. package/lib/sdam/server_selection.js +10 -4
  145. package/lib/sdam/server_selection.js.map +1 -1
  146. package/lib/sdam/srv_polling.js +1 -1
  147. package/lib/sdam/srv_polling.js.map +1 -1
  148. package/lib/sdam/topology.js +42 -21
  149. package/lib/sdam/topology.js.map +1 -1
  150. package/lib/sdam/topology_description.js +7 -3
  151. package/lib/sdam/topology_description.js.map +1 -1
  152. package/lib/sessions.js +132 -31
  153. package/lib/sessions.js.map +1 -1
  154. package/lib/sort.js +3 -3
  155. package/lib/sort.js.map +1 -1
  156. package/lib/transactions.js +15 -7
  157. package/lib/transactions.js.map +1 -1
  158. package/lib/utils.js +60 -20
  159. package/lib/utils.js.map +1 -1
  160. package/mongodb.d.ts +523 -138
  161. package/mongodb.ts34.d.ts +480 -141
  162. package/package.json +44 -48
  163. package/src/bson.ts +1 -0
  164. package/src/bulk/common.ts +83 -43
  165. package/src/bulk/ordered.ts +4 -3
  166. package/src/bulk/unordered.ts +4 -3
  167. package/src/change_stream.ts +46 -29
  168. package/src/cmap/auth/auth_provider.ts +3 -2
  169. package/src/cmap/auth/gssapi.ts +15 -5
  170. package/src/cmap/auth/mongo_credentials.ts +22 -8
  171. package/src/cmap/auth/mongocr.ts +3 -3
  172. package/src/cmap/auth/mongodb_aws.ts +52 -39
  173. package/src/cmap/auth/plain.ts +2 -2
  174. package/src/cmap/auth/scram.ts +23 -13
  175. package/src/cmap/auth/x509.ts +3 -3
  176. package/src/cmap/command_monitoring_events.ts +36 -14
  177. package/src/cmap/commands.ts +12 -6
  178. package/src/cmap/connect.ts +42 -12
  179. package/src/cmap/connection.ts +54 -62
  180. package/src/cmap/connection_pool.ts +141 -20
  181. package/src/cmap/connection_pool_events.ts +8 -1
  182. package/src/cmap/errors.ts +3 -4
  183. package/src/cmap/message_stream.ts +2 -4
  184. package/src/cmap/metrics.ts +58 -0
  185. package/src/cmap/stream_description.ts +6 -1
  186. package/src/cmap/wire_protocol/compression.ts +26 -13
  187. package/src/cmap/wire_protocol/shared.ts +4 -2
  188. package/src/collection.ts +75 -70
  189. package/src/connection_string.ts +97 -34
  190. package/src/cursor/abstract_cursor.ts +141 -104
  191. package/src/cursor/aggregation_cursor.ts +34 -20
  192. package/src/cursor/find_cursor.ts +41 -21
  193. package/src/db.ts +19 -18
  194. package/src/deps.ts +110 -22
  195. package/src/encrypter.ts +6 -12
  196. package/src/error.ts +264 -48
  197. package/src/explain.ts +3 -3
  198. package/src/gridfs/download.ts +48 -53
  199. package/src/gridfs/index.ts +5 -4
  200. package/src/gridfs/upload.ts +32 -33
  201. package/src/index.ts +42 -4
  202. package/src/logger.ts +6 -3
  203. package/src/mongo_client.ts +20 -23
  204. package/src/mongo_types.ts +19 -20
  205. package/src/operations/add_user.ts +4 -5
  206. package/src/operations/aggregate.ts +18 -17
  207. package/src/operations/command.ts +7 -10
  208. package/src/operations/common_functions.ts +2 -3
  209. package/src/operations/connect.ts +4 -3
  210. package/src/operations/count.ts +2 -2
  211. package/src/operations/count_documents.ts +2 -2
  212. package/src/operations/delete.ts +8 -6
  213. package/src/operations/distinct.ts +5 -3
  214. package/src/operations/estimated_document_count.ts +5 -1
  215. package/src/operations/eval.ts +1 -1
  216. package/src/operations/execute_operation.ts +41 -20
  217. package/src/operations/find.ts +25 -16
  218. package/src/operations/find_and_modify.ts +12 -10
  219. package/src/operations/indexes.ts +39 -8
  220. package/src/operations/insert.ts +7 -4
  221. package/src/operations/is_capped.ts +3 -2
  222. package/src/operations/list_collections.ts +9 -6
  223. package/src/operations/map_reduce.ts +4 -2
  224. package/src/operations/operation.ts +7 -2
  225. package/src/operations/options_operation.ts +3 -2
  226. package/src/operations/profiling_level.ts +5 -3
  227. package/src/operations/set_profiling_level.ts +9 -3
  228. package/src/operations/update.ts +17 -13
  229. package/src/operations/validate_collection.ts +7 -6
  230. package/src/promise_provider.ts +2 -2
  231. package/src/read_preference.ts +11 -9
  232. package/src/sdam/common.ts +11 -9
  233. package/src/sdam/server.ts +168 -69
  234. package/src/sdam/server_description.ts +16 -4
  235. package/src/sdam/server_selection.ts +15 -7
  236. package/src/sdam/srv_polling.ts +2 -2
  237. package/src/sdam/topology.ts +67 -36
  238. package/src/sdam/topology_description.ts +11 -4
  239. package/src/sessions.ts +194 -37
  240. package/src/sort.ts +6 -4
  241. package/src/transactions.ts +18 -9
  242. package/src/utils.ts +73 -20
  243. package/HISTORY.md +0 -2993
  244. package/lib/operations/find_one.js +0 -34
  245. package/lib/operations/find_one.js.map +0 -1
  246. package/src/operations/find_one.ts +0 -43
package/src/error.ts CHANGED
@@ -60,12 +60,12 @@ export const GET_MORE_RESUMABLE_CODES = new Set<number>([
60
60
  ]);
61
61
 
62
62
  /** @public */
63
- export interface ErrorDescription {
63
+ export interface ErrorDescription extends Document {
64
64
  message?: string;
65
65
  errmsg?: string;
66
66
  $err?: string;
67
67
  errorLabels?: string[];
68
- [key: string]: any;
68
+ errInfo?: Document;
69
69
  }
70
70
 
71
71
  /**
@@ -78,13 +78,17 @@ export interface ErrorDescription {
78
78
  export class MongoError extends Error {
79
79
  /** @internal */
80
80
  [kErrorLabels]: Set<string>;
81
+ /**
82
+ * This is a number in MongoServerError and a string in MongoDriverError
83
+ * @privateRemarks
84
+ * Define the type override on the subclasses when we can use the override keyword
85
+ */
81
86
  code?: number | string;
82
87
  topologyVersion?: TopologyVersion;
83
88
 
84
89
  constructor(message: string | Error) {
85
90
  if (message instanceof Error) {
86
91
  super(message.message);
87
- this.stack = message.stack;
88
92
  } else {
89
93
  super(message);
90
94
  }
@@ -133,26 +137,21 @@ export class MongoError extends Error {
133
137
  * @category Error
134
138
  */
135
139
  export class MongoServerError extends MongoError {
136
- code?: number;
137
140
  codeName?: string;
138
141
  writeConcernError?: Document;
142
+ errInfo?: Document;
143
+ ok?: number;
144
+ [key: string]: any;
139
145
 
140
- constructor(message: Error | ErrorDescription) {
141
- if (message instanceof Error) {
142
- super(message);
143
- } else {
144
- super(message.message || message.errmsg || message.$err || 'n/a');
145
- if (message.errorLabels) {
146
- this[kErrorLabels] = new Set(message.errorLabels);
147
- }
148
-
149
- for (const name in message) {
150
- if (name === 'errorLabels' || name === 'errmsg' || name === 'message') {
151
- continue;
152
- }
153
-
154
- (this as any)[name] = message[name];
155
- }
146
+ constructor(message: ErrorDescription) {
147
+ super(message.message || message.errmsg || message.$err || 'n/a');
148
+ if (message.errorLabels) {
149
+ this[kErrorLabels] = new Set(message.errorLabels);
150
+ }
151
+
152
+ for (const name in message) {
153
+ if (name !== 'errorLabels' && name !== 'errmsg' && name !== 'message')
154
+ this[name] = message[name];
156
155
  }
157
156
  }
158
157
 
@@ -168,7 +167,6 @@ export class MongoServerError extends MongoError {
168
167
  * @category Error
169
168
  */
170
169
  export class MongoDriverError extends MongoError {
171
- code?: string;
172
170
  constructor(message: string) {
173
171
  super(message);
174
172
  }
@@ -178,6 +176,26 @@ export class MongoDriverError extends MongoError {
178
176
  }
179
177
  }
180
178
 
179
+ /**
180
+ * An error generated when the driver API is used incorrectly
181
+ *
182
+ * @privateRemarks
183
+ * Should **never** be directly instantiated
184
+ *
185
+ * @public
186
+ * @category Error
187
+ */
188
+
189
+ export class MongoAPIError extends MongoDriverError {
190
+ constructor(message: string) {
191
+ super(message);
192
+ }
193
+
194
+ get name(): string {
195
+ return 'MongoAPIError';
196
+ }
197
+ }
198
+
181
199
  /**
182
200
  * An error generated when the driver encounters unexpected input
183
201
  * or reaches an unexpected/invalid internal state
@@ -189,7 +207,7 @@ export class MongoDriverError extends MongoError {
189
207
  * @category Error
190
208
  */
191
209
  export class MongoRuntimeError extends MongoDriverError {
192
- protected constructor(message: string) {
210
+ constructor(message: string) {
193
211
  super(message);
194
212
  }
195
213
 
@@ -202,17 +220,33 @@ export class MongoRuntimeError extends MongoDriverError {
202
220
  * An error generated when a batch command is reexecuted after one of the commands in the batch
203
221
  * has failed
204
222
  *
223
+ * @public
224
+ * @category Error
225
+ */
226
+ export class MongoBatchReExecutionError extends MongoAPIError {
227
+ constructor(message = 'This batch has already been executed, create new batch to execute') {
228
+ super(message);
229
+ }
230
+
231
+ get name(): string {
232
+ return 'MongoBatchReExecutionError';
233
+ }
234
+ }
235
+
236
+ /**
237
+ * An error generated when the driver fails to decompress
238
+ * data received from the server.
205
239
  *
206
240
  * @public
207
241
  * @category Error
208
242
  */
209
- export class MongoBatchReExecutionError extends MongoRuntimeError {
243
+ export class MongoDecompressionError extends MongoRuntimeError {
210
244
  constructor(message: string) {
211
245
  super(message);
212
246
  }
213
247
 
214
248
  get name(): string {
215
- return 'MongoBatchReExecutionError';
249
+ return 'MongoDecompressionError';
216
250
  }
217
251
  }
218
252
 
@@ -220,11 +254,10 @@ export class MongoBatchReExecutionError extends MongoRuntimeError {
220
254
  * An error thrown when the user attempts to operate on a database or collection through a MongoClient
221
255
  * that has not yet successfully called the "connect" method
222
256
  *
223
- *
224
257
  * @public
225
258
  * @category Error
226
259
  */
227
- export class MongoNotConnectedError extends MongoRuntimeError {
260
+ export class MongoNotConnectedError extends MongoAPIError {
228
261
  constructor(message: string) {
229
262
  super(message);
230
263
  }
@@ -235,37 +268,117 @@ export class MongoNotConnectedError extends MongoRuntimeError {
235
268
  }
236
269
 
237
270
  /**
238
- * An error thrown when the user attempts to operate on a cursor that is in a state which does not
239
- * support the attempted operation.
271
+ * An error generated when the user makes a mistake in the usage of transactions.
272
+ * (e.g. attempting to commit a transaction with a readPreference other than primary)
240
273
  *
274
+ * @public
275
+ * @category Error
276
+ */
277
+ export class MongoTransactionError extends MongoAPIError {
278
+ constructor(message: string) {
279
+ super(message);
280
+ }
281
+
282
+ get name(): string {
283
+ return 'MongoTransactionError';
284
+ }
285
+ }
286
+
287
+ /**
288
+ * An error generated when the user attempts to operate
289
+ * on a session that has expired or has been closed.
290
+ *
291
+ * @public
292
+ * @category Error
293
+ */
294
+ export class MongoExpiredSessionError extends MongoAPIError {
295
+ constructor(message = 'Cannot use a session that has ended') {
296
+ super(message);
297
+ }
298
+
299
+ get name(): string {
300
+ return 'MongoExpiredSessionError';
301
+ }
302
+ }
303
+
304
+ /**
305
+ * A error generated when the user attempts to authenticate
306
+ * via Kerberos, but fails to connect to the Kerberos client.
307
+ *
308
+ * @public
309
+ * @category Error
310
+ */
311
+ export class MongoKerberosError extends MongoRuntimeError {
312
+ constructor(message: string) {
313
+ super(message);
314
+ }
315
+
316
+ get name(): string {
317
+ return 'MongoKerberosError';
318
+ }
319
+ }
320
+
321
+ /**
322
+ * An error generated when a ChangeStream operation fails to execute.
241
323
  *
242
324
  * @public
243
325
  * @category Error
244
326
  */
245
- export class MongoCursorError extends MongoRuntimeError {
327
+ export class MongoChangeStreamError extends MongoRuntimeError {
246
328
  constructor(message: string) {
247
329
  super(message);
248
330
  }
249
331
 
250
332
  get name(): string {
251
- return 'MongoCursorError';
333
+ return 'MongoChangeStreamError';
252
334
  }
253
335
  }
254
336
 
255
337
  /**
256
338
  * An error thrown when the user calls a function or method not supported on a tailable cursor
257
339
  *
340
+ * @public
341
+ * @category Error
342
+ */
343
+ export class MongoTailableCursorError extends MongoAPIError {
344
+ constructor(message = 'Tailable cursor does not support this operation') {
345
+ super(message);
346
+ }
347
+
348
+ get name(): string {
349
+ return 'MongoTailableCursorError';
350
+ }
351
+ }
352
+
353
+ /** An error generated when a GridFSStream operation fails to execute.
258
354
  *
259
355
  * @public
260
356
  * @category Error
261
357
  */
262
- export class MongoTailableCursorError extends MongoCursorError {
358
+ export class MongoGridFSStreamError extends MongoRuntimeError {
263
359
  constructor(message: string) {
264
360
  super(message);
265
361
  }
266
362
 
267
363
  get name(): string {
268
- return 'MongoTailableCursorError';
364
+ return 'MongoGridFSStreamError';
365
+ }
366
+ }
367
+
368
+ /**
369
+ * An error generated when a malformed or invalid chunk is
370
+ * encountered when reading from a GridFSStream.
371
+ *
372
+ * @public
373
+ * @category Error
374
+ */
375
+ export class MongoGridFSChunkError extends MongoRuntimeError {
376
+ constructor(message: string) {
377
+ super(message);
378
+ }
379
+
380
+ get name(): string {
381
+ return 'MongoGridFSChunkError';
269
382
  }
270
383
  }
271
384
 
@@ -273,12 +386,11 @@ export class MongoTailableCursorError extends MongoCursorError {
273
386
  * An error thrown when the user attempts to add options to a cursor that has already been
274
387
  * initialized
275
388
  *
276
- *
277
389
  * @public
278
390
  * @category Error
279
391
  */
280
- export class MongoCursorInUseError extends MongoCursorError {
281
- constructor(message: string) {
392
+ export class MongoCursorInUseError extends MongoAPIError {
393
+ constructor(message = 'Cursor is already initialized') {
282
394
  super(message);
283
395
  }
284
396
 
@@ -287,20 +399,53 @@ export class MongoCursorInUseError extends MongoCursorError {
287
399
  }
288
400
  }
289
401
 
402
+ /**
403
+ * An error generated when an attempt is made to operate
404
+ * on a closed/closing server.
405
+ *
406
+ * @public
407
+ * @category Error
408
+ */
409
+ export class MongoServerClosedError extends MongoAPIError {
410
+ constructor(message = 'Server is closed') {
411
+ super(message);
412
+ }
413
+
414
+ get name(): string {
415
+ return 'MongoServerClosedError';
416
+ }
417
+ }
418
+
290
419
  /**
291
420
  * An error thrown when an attempt is made to read from a cursor that has been exhausted
292
421
  *
422
+ * @public
423
+ * @category Error
424
+ */
425
+ export class MongoCursorExhaustedError extends MongoAPIError {
426
+ constructor(message?: string) {
427
+ super(message || 'Cursor is exhausted');
428
+ }
429
+
430
+ get name(): string {
431
+ return 'MongoCursorExhaustedError';
432
+ }
433
+ }
434
+
435
+ /**
436
+ * An error generated when an attempt is made to operate on a
437
+ * dropped, or otherwise unavailable, database.
293
438
  *
294
439
  * @public
295
440
  * @category Error
296
441
  */
297
- export class MongoCursorExhaustedError extends MongoCursorError {
298
- constructor(message: string) {
442
+ export class MongoTopologyClosedError extends MongoAPIError {
443
+ constructor(message = 'Topology is closed') {
299
444
  super(message);
300
445
  }
301
446
 
302
447
  get name(): string {
303
- return 'MongoCursorExhaustedError';
448
+ return 'MongoTopologyClosedError';
304
449
  }
305
450
  }
306
451
 
@@ -310,6 +455,12 @@ export function isNetworkErrorBeforeHandshake(err: MongoNetworkError): boolean {
310
455
  return err[kBeforeHandshake] === true;
311
456
  }
312
457
 
458
+ /** @public */
459
+ export interface MongoNetworkErrorOptions {
460
+ /** Indicates the timeout happened before a connection handshake completed */
461
+ beforeHandshake: boolean;
462
+ }
463
+
313
464
  /**
314
465
  * An error indicating an issue with the network, including TCP errors and timeouts.
315
466
  * @public
@@ -319,7 +470,7 @@ export class MongoNetworkError extends MongoError {
319
470
  /** @internal */
320
471
  [kBeforeHandshake]?: boolean;
321
472
 
322
- constructor(message: string | Error, options?: { beforeHandshake?: boolean }) {
473
+ constructor(message: string | Error, options?: MongoNetworkErrorOptions) {
323
474
  super(message);
324
475
 
325
476
  if (options && typeof options.beforeHandshake === 'boolean') {
@@ -332,12 +483,6 @@ export class MongoNetworkError extends MongoError {
332
483
  }
333
484
  }
334
485
 
335
- /** @public */
336
- export interface MongoNetworkTimeoutErrorOptions {
337
- /** Indicates the timeout happened before a connection handshake completed */
338
- beforeHandshake: boolean;
339
- }
340
-
341
486
  /**
342
487
  * An error indicating a network timeout occurred
343
488
  * @public
@@ -347,7 +492,7 @@ export interface MongoNetworkTimeoutErrorOptions {
347
492
  * CSFLE has a dependency on this error with an instanceof check
348
493
  */
349
494
  export class MongoNetworkTimeoutError extends MongoNetworkError {
350
- constructor(message: string, options?: MongoNetworkTimeoutErrorOptions) {
495
+ constructor(message: string, options?: MongoNetworkErrorOptions) {
351
496
  super(message, options);
352
497
  }
353
498
 
@@ -371,6 +516,75 @@ export class MongoParseError extends MongoDriverError {
371
516
  }
372
517
  }
373
518
 
519
+ /**
520
+ * An error generated when the user supplies malformed or unexpected arguments
521
+ * or when a required argument or field is not provided.
522
+ *
523
+ *
524
+ * @public
525
+ * @category Error
526
+ */
527
+ export class MongoInvalidArgumentError extends MongoAPIError {
528
+ constructor(message: string) {
529
+ super(message);
530
+ }
531
+
532
+ get name(): string {
533
+ return 'MongoInvalidArgumentError';
534
+ }
535
+ }
536
+
537
+ /**
538
+ * An error generated when a feature that is not enabled or allowed for the current server
539
+ * configuration is used
540
+ *
541
+ *
542
+ * @public
543
+ * @category Error
544
+ */
545
+ export class MongoCompatibilityError extends MongoAPIError {
546
+ constructor(message: string) {
547
+ super(message);
548
+ }
549
+
550
+ get name(): string {
551
+ return 'MongoCompatibilityError';
552
+ }
553
+ }
554
+
555
+ /**
556
+ * An error generated when the user fails to provide authentication credentials before attempting
557
+ * to connect to a mongo server instance.
558
+ *
559
+ *
560
+ * @public
561
+ * @category Error
562
+ */
563
+ export class MongoMissingCredentialsError extends MongoAPIError {
564
+ constructor(message: string) {
565
+ super(message);
566
+ }
567
+
568
+ get name(): string {
569
+ return 'MongoMissingCredentialsError';
570
+ }
571
+ }
572
+
573
+ /**
574
+ * An error generated when a required module or dependency is not present in the local environment
575
+ *
576
+ * @public
577
+ * @category Error
578
+ */
579
+ export class MongoMissingDependencyError extends MongoAPIError {
580
+ constructor(message: string) {
581
+ super(message);
582
+ }
583
+
584
+ get name(): string {
585
+ return 'MongoMissingDependencyError';
586
+ }
587
+ }
374
588
  /**
375
589
  * An error signifying a general system issue
376
590
  * @public
@@ -433,13 +647,15 @@ function makeWriteConcernResultObject(input: any) {
433
647
  export class MongoWriteConcernError extends MongoServerError {
434
648
  /** The result document (provided if ok: 1) */
435
649
  result?: Document;
650
+ errInfo?: Document;
436
651
 
437
- constructor(message: ErrorDescription, result: Document) {
652
+ constructor(message: ErrorDescription, result?: Document) {
438
653
  if (result && Array.isArray(result.errorLabels)) {
439
654
  message.errorLabels = result.errorLabels;
440
655
  }
441
656
 
442
657
  super(message);
658
+ this.errInfo = message.errInfo;
443
659
 
444
660
  if (result != null) {
445
661
  this.result = makeWriteConcernResultObject(result);
@@ -582,7 +798,7 @@ export function isResumableError(error?: MongoError, wireVersion?: number): bool
582
798
  return true;
583
799
  }
584
800
 
585
- if (typeof wireVersion !== 'undefined' && wireVersion >= 9) {
801
+ if (wireVersion != null && wireVersion >= 9) {
586
802
  // DRIVERS-1308: For 4.4 drivers running against 4.4 servers, drivers will add a special case to treat the CursorNotFound error code as resumable
587
803
  if (error && error instanceof MongoError && error.code === 43) {
588
804
  return true;
package/src/explain.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MongoDriverError } from './error';
1
+ import { MongoInvalidArgumentError } from './error';
2
2
 
3
3
  /** @public */
4
4
  export const ExplainVerbosity = Object.freeze({
@@ -40,13 +40,13 @@ export class Explain {
40
40
  }
41
41
 
42
42
  static fromOptions(options?: ExplainOptions): Explain | undefined {
43
- if (options?.explain === undefined) return;
43
+ if (options?.explain == null) return;
44
44
 
45
45
  const explain = options.explain;
46
46
  if (typeof explain === 'boolean' || typeof explain === 'string') {
47
47
  return new Explain(explain);
48
48
  }
49
49
 
50
- throw new MongoDriverError('explain must be a string or a boolean');
50
+ throw new MongoInvalidArgumentError('Field "explain" must be a string or a boolean');
51
51
  }
52
52
  }