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.
- package/README.md +62 -30
- package/lib/bson.js +1 -0
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +53 -30
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +3 -2
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +3 -2
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +23 -13
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js +2 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +5 -4
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +9 -5
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +2 -2
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +32 -32
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js +15 -12
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +2 -2
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +26 -10
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +9 -5
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +23 -9
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +43 -46
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +113 -15
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +3 -1
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/errors.js +3 -3
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/message_stream.js +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +3 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +22 -9
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -1
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +23 -18
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +76 -30
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +75 -68
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +47 -9
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +53 -13
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +21 -14
- package/lib/db.js.map +1 -1
- package/lib/deps.js +16 -5
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +5 -8
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +230 -34
- package/lib/error.js.map +1 -1
- package/lib/explain.js +2 -2
- package/lib/explain.js.map +1 -1
- package/lib/gridfs/download.js +22 -47
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +4 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +13 -21
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +27 -2
- package/lib/index.js.map +1 -1
- package/lib/logger.js +3 -2
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -8
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +2 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +12 -9
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +5 -7
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +3 -2
- package/lib/operations/connect.js.map +1 -1
- package/lib/operations/count.js +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/delete.js +5 -5
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +2 -2
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/estimated_document_count.js +5 -1
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +31 -17
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +13 -9
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +9 -9
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/indexes.js +8 -3
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +5 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js +2 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +6 -3
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/map_reduce.js +1 -1
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +3 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +2 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +4 -2
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/set_profiling_level.js +4 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/update.js +12 -12
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +6 -5
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/promise_provider.js +1 -1
- package/lib/promise_provider.js.map +1 -1
- package/lib/read_preference.js +8 -8
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/common.js +12 -10
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/server.js +90 -25
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +9 -4
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +10 -4
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +1 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +42 -21
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +7 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +132 -31
- package/lib/sessions.js.map +1 -1
- package/lib/sort.js +3 -3
- package/lib/sort.js.map +1 -1
- package/lib/transactions.js +15 -7
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +60 -20
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +523 -138
- package/mongodb.ts34.d.ts +480 -141
- package/package.json +44 -48
- package/src/bson.ts +1 -0
- package/src/bulk/common.ts +83 -43
- package/src/bulk/ordered.ts +4 -3
- package/src/bulk/unordered.ts +4 -3
- package/src/change_stream.ts +46 -29
- package/src/cmap/auth/auth_provider.ts +3 -2
- package/src/cmap/auth/gssapi.ts +15 -5
- package/src/cmap/auth/mongo_credentials.ts +22 -8
- package/src/cmap/auth/mongocr.ts +3 -3
- package/src/cmap/auth/mongodb_aws.ts +52 -39
- package/src/cmap/auth/plain.ts +2 -2
- package/src/cmap/auth/scram.ts +23 -13
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +36 -14
- package/src/cmap/commands.ts +12 -6
- package/src/cmap/connect.ts +42 -12
- package/src/cmap/connection.ts +54 -62
- package/src/cmap/connection_pool.ts +141 -20
- package/src/cmap/connection_pool_events.ts +8 -1
- package/src/cmap/errors.ts +3 -4
- package/src/cmap/message_stream.ts +2 -4
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +6 -1
- package/src/cmap/wire_protocol/compression.ts +26 -13
- package/src/cmap/wire_protocol/shared.ts +4 -2
- package/src/collection.ts +75 -70
- package/src/connection_string.ts +97 -34
- package/src/cursor/abstract_cursor.ts +141 -104
- package/src/cursor/aggregation_cursor.ts +34 -20
- package/src/cursor/find_cursor.ts +41 -21
- package/src/db.ts +19 -18
- package/src/deps.ts +110 -22
- package/src/encrypter.ts +6 -12
- package/src/error.ts +264 -48
- package/src/explain.ts +3 -3
- package/src/gridfs/download.ts +48 -53
- package/src/gridfs/index.ts +5 -4
- package/src/gridfs/upload.ts +32 -33
- package/src/index.ts +42 -4
- package/src/logger.ts +6 -3
- package/src/mongo_client.ts +20 -23
- package/src/mongo_types.ts +19 -20
- package/src/operations/add_user.ts +4 -5
- package/src/operations/aggregate.ts +18 -17
- package/src/operations/command.ts +7 -10
- package/src/operations/common_functions.ts +2 -3
- package/src/operations/connect.ts +4 -3
- package/src/operations/count.ts +2 -2
- package/src/operations/count_documents.ts +2 -2
- package/src/operations/delete.ts +8 -6
- package/src/operations/distinct.ts +5 -3
- package/src/operations/estimated_document_count.ts +5 -1
- package/src/operations/eval.ts +1 -1
- package/src/operations/execute_operation.ts +41 -20
- package/src/operations/find.ts +25 -16
- package/src/operations/find_and_modify.ts +12 -10
- package/src/operations/indexes.ts +39 -8
- package/src/operations/insert.ts +7 -4
- package/src/operations/is_capped.ts +3 -2
- package/src/operations/list_collections.ts +9 -6
- package/src/operations/map_reduce.ts +4 -2
- package/src/operations/operation.ts +7 -2
- package/src/operations/options_operation.ts +3 -2
- package/src/operations/profiling_level.ts +5 -3
- package/src/operations/set_profiling_level.ts +9 -3
- package/src/operations/update.ts +17 -13
- package/src/operations/validate_collection.ts +7 -6
- package/src/promise_provider.ts +2 -2
- package/src/read_preference.ts +11 -9
- package/src/sdam/common.ts +11 -9
- package/src/sdam/server.ts +168 -69
- package/src/sdam/server_description.ts +16 -4
- package/src/sdam/server_selection.ts +15 -7
- package/src/sdam/srv_polling.ts +2 -2
- package/src/sdam/topology.ts +67 -36
- package/src/sdam/topology_description.ts +11 -4
- package/src/sessions.ts +194 -37
- package/src/sort.ts +6 -4
- package/src/transactions.ts +18 -9
- package/src/utils.ts +73 -20
- package/HISTORY.md +0 -2993
- package/lib/operations/find_one.js +0 -34
- package/lib/operations/find_one.js.map +0 -1
- 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
|
-
|
|
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:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
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
|
|
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 '
|
|
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
|
|
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
|
|
239
|
-
*
|
|
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
|
|
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 '
|
|
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
|
|
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 '
|
|
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
|
|
281
|
-
constructor(message
|
|
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
|
|
298
|
-
constructor(message
|
|
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 '
|
|
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?:
|
|
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?:
|
|
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
|
|
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 (
|
|
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 {
|
|
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
|
|
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
|
|
50
|
+
throw new MongoInvalidArgumentError('Field "explain" must be a string or a boolean');
|
|
51
51
|
}
|
|
52
52
|
}
|