mongodb 4.3.1 → 4.5.0
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 +7 -6
- package/lib/admin.js +5 -6
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +31 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +29 -20
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +49 -7
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +12 -1
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js +1 -0
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +0 -6
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +111 -86
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +3 -0
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/collection.js +29 -28
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +53 -40
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +64 -42
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +2 -2
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +4 -3
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +13 -13
- package/lib/db.js.map +1 -1
- package/lib/encrypter.js +17 -9
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +99 -48
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +2 -0
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +42 -51
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +9 -2
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +14 -27
- package/lib/mongo_client.js.map +1 -1
- package/lib/operations/add_user.js +8 -1
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +5 -0
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js +8 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +5 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js.map +1 -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 +70 -79
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +3 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +5 -0
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +5 -0
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +8 -9
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +10 -42
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +5 -0
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +1 -2
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +1 -3
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +1 -1
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +5 -0
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_concern.js +1 -0
- package/lib/read_concern.js.map +1 -1
- package/lib/sdam/common.js +1 -7
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/events.js +1 -1
- package/lib/sdam/events.js.map +1 -1
- package/lib/sdam/monitor.js +1 -2
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +79 -57
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/topology.js +16 -33
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +1 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +93 -68
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +21 -97
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +188 -29
- package/package.json +46 -46
- package/src/admin.ts +6 -10
- package/src/bulk/common.ts +42 -14
- package/src/bulk/unordered.ts +1 -1
- package/src/change_stream.ts +58 -42
- package/src/cmap/auth/gssapi.ts +58 -7
- package/src/cmap/auth/mongo_credentials.ts +17 -2
- package/src/cmap/auth/mongocr.ts +1 -1
- package/src/cmap/auth/mongodb_aws.ts +1 -1
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/scram.ts +3 -2
- package/src/cmap/auth/x509.ts +6 -2
- package/src/cmap/commands.ts +3 -0
- package/src/cmap/connect.ts +2 -20
- package/src/cmap/connection.ts +162 -111
- package/src/cmap/errors.ts +2 -2
- package/src/cmap/message_stream.ts +2 -2
- package/src/cmap/stream_description.ts +4 -1
- package/src/collection.ts +37 -33
- package/src/connection_string.ts +77 -45
- package/src/cursor/abstract_cursor.ts +85 -56
- package/src/cursor/aggregation_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +19 -11
- package/src/db.ts +15 -19
- package/src/deps.ts +52 -0
- package/src/encrypter.ts +18 -10
- package/src/error.ts +145 -76
- package/src/gridfs/download.ts +3 -1
- package/src/gridfs/index.ts +51 -68
- package/src/gridfs/upload.ts +12 -12
- package/src/index.ts +10 -1
- package/src/mongo_client.ts +19 -41
- package/src/operations/add_user.ts +14 -3
- package/src/operations/aggregate.ts +15 -5
- package/src/operations/bulk_write.ts +6 -2
- package/src/operations/collections.ts +6 -2
- package/src/operations/command.ts +23 -8
- package/src/operations/common_functions.ts +8 -1
- package/src/operations/count.ts +6 -2
- package/src/operations/count_documents.ts +5 -1
- package/src/operations/create_collection.ts +6 -2
- package/src/operations/delete.ts +19 -13
- package/src/operations/distinct.ts +6 -2
- package/src/operations/drop.ts +12 -4
- package/src/operations/estimated_document_count.ts +11 -3
- package/src/operations/eval.ts +6 -2
- package/src/operations/execute_operation.ts +102 -101
- package/src/operations/find.ts +9 -5
- package/src/operations/find_and_modify.ts +21 -2
- package/src/operations/get_more.ts +20 -6
- package/src/operations/indexes.ts +54 -36
- package/src/operations/insert.ts +20 -6
- package/src/operations/is_capped.ts +6 -2
- package/src/operations/list_collections.ts +24 -59
- package/src/operations/list_databases.ts +13 -3
- package/src/operations/map_reduce.ts +7 -6
- package/src/operations/operation.ts +10 -9
- package/src/operations/options_operation.ts +6 -2
- package/src/operations/profiling_level.ts +6 -2
- package/src/operations/remove_user.ts +6 -2
- package/src/operations/rename.ts +7 -3
- package/src/operations/run_command.ts +6 -2
- package/src/operations/set_profiling_level.ts +6 -2
- package/src/operations/stats.ts +12 -4
- package/src/operations/update.ts +21 -9
- package/src/operations/validate_collection.ts +6 -2
- package/src/read_concern.ts +1 -0
- package/src/sdam/common.ts +0 -6
- package/src/sdam/events.ts +2 -2
- package/src/sdam/monitor.ts +4 -5
- package/src/sdam/server.ts +95 -90
- package/src/sdam/topology.ts +9 -53
- package/src/sdam/topology_description.ts +1 -3
- package/src/sessions.ts +108 -78
- package/src/utils.ts +38 -118
- package/tsconfig.json +40 -0
- package/mongodb.ts34.d.ts +0 -5649
package/src/utils.ts
CHANGED
|
@@ -8,11 +8,12 @@ import type { Connection } from './cmap/connection';
|
|
|
8
8
|
import { MAX_SUPPORTED_WIRE_VERSION } from './cmap/wire_protocol/constants';
|
|
9
9
|
import type { Collection } from './collection';
|
|
10
10
|
import { LEGACY_HELLO_COMMAND } from './constants';
|
|
11
|
+
import type { AbstractCursor } from './cursor/abstract_cursor';
|
|
12
|
+
import type { FindCursor } from './cursor/find_cursor';
|
|
11
13
|
import type { Db } from './db';
|
|
12
14
|
import {
|
|
13
15
|
AnyError,
|
|
14
16
|
MongoCompatibilityError,
|
|
15
|
-
MongoExpiredSessionError,
|
|
16
17
|
MongoInvalidArgumentError,
|
|
17
18
|
MongoNotConnectedError,
|
|
18
19
|
MongoParseError,
|
|
@@ -37,8 +38,6 @@ import { W, WriteConcern, WriteConcernOptions } from './write_concern';
|
|
|
37
38
|
* @public
|
|
38
39
|
*/
|
|
39
40
|
export type Callback<T = any> = (error?: AnyError, result?: T) => void;
|
|
40
|
-
/** @public */
|
|
41
|
-
export type CallbackWithType<E = AnyError, T0 = any> = (error?: E, result?: T0) => void;
|
|
42
41
|
|
|
43
42
|
export const MAX_JS_INT = Number.MAX_SAFE_INTEGER + 1;
|
|
44
43
|
|
|
@@ -190,110 +189,6 @@ export function filterOptions(options: AnyOptions, names: string[]): AnyOptions
|
|
|
190
189
|
return filterOptions;
|
|
191
190
|
}
|
|
192
191
|
|
|
193
|
-
/**
|
|
194
|
-
* Executes the given operation with provided arguments.
|
|
195
|
-
*
|
|
196
|
-
* @remarks
|
|
197
|
-
* This method reduces large amounts of duplication in the entire codebase by providing
|
|
198
|
-
* a single point for determining whether callbacks or promises should be used. Additionally
|
|
199
|
-
* it allows for a single point of entry to provide features such as implicit sessions, which
|
|
200
|
-
* are required by the Driver Sessions specification in the event that a ClientSession is
|
|
201
|
-
* not provided
|
|
202
|
-
*
|
|
203
|
-
* @internal
|
|
204
|
-
*
|
|
205
|
-
* @param topology - The topology to execute this operation on
|
|
206
|
-
* @param operation - The operation to execute
|
|
207
|
-
* @param args - Arguments to apply the provided operation
|
|
208
|
-
* @param options - Options that modify the behavior of the method
|
|
209
|
-
*/
|
|
210
|
-
export function executeLegacyOperation(
|
|
211
|
-
topology: Topology,
|
|
212
|
-
operation: (...args: any[]) => void | Promise<Document>,
|
|
213
|
-
args: any[],
|
|
214
|
-
options?: AnyOptions
|
|
215
|
-
): void | Promise<any> {
|
|
216
|
-
const Promise = PromiseProvider.get();
|
|
217
|
-
|
|
218
|
-
if (!Array.isArray(args)) {
|
|
219
|
-
// TODO(NODE-3483)
|
|
220
|
-
throw new MongoRuntimeError('This method requires an array of arguments to apply');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
options = options ?? {};
|
|
224
|
-
|
|
225
|
-
let callback = args[args.length - 1];
|
|
226
|
-
|
|
227
|
-
// The driver sessions spec mandates that we implicitly create sessions for operations
|
|
228
|
-
// that are not explicitly provided with a session.
|
|
229
|
-
let session: ClientSession;
|
|
230
|
-
let opOptions: any;
|
|
231
|
-
let owner: any;
|
|
232
|
-
if (!options.skipSessions && topology.hasSessionSupport()) {
|
|
233
|
-
opOptions = args[args.length - 2];
|
|
234
|
-
if (opOptions == null || opOptions.session == null) {
|
|
235
|
-
owner = Symbol();
|
|
236
|
-
session = topology.startSession({ owner });
|
|
237
|
-
const optionsIndex = args.length - 2;
|
|
238
|
-
args[optionsIndex] = Object.assign({}, args[optionsIndex], { session: session });
|
|
239
|
-
} else if (opOptions.session && opOptions.session.hasEnded) {
|
|
240
|
-
throw new MongoExpiredSessionError();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function makeExecuteCallback(
|
|
245
|
-
resolve: (value?: Document) => void,
|
|
246
|
-
reject: (reason?: AnyError) => void
|
|
247
|
-
) {
|
|
248
|
-
return function (err?: AnyError, result?: any) {
|
|
249
|
-
if (session && session.owner === owner && !options?.returnsCursor) {
|
|
250
|
-
session.endSession(() => {
|
|
251
|
-
delete opOptions.session;
|
|
252
|
-
if (err) return reject(err);
|
|
253
|
-
resolve(result);
|
|
254
|
-
});
|
|
255
|
-
} else {
|
|
256
|
-
if (err) return reject(err);
|
|
257
|
-
resolve(result);
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// Execute using callback
|
|
263
|
-
if (typeof callback === 'function') {
|
|
264
|
-
callback = args.pop();
|
|
265
|
-
const handler = makeExecuteCallback(
|
|
266
|
-
result => callback(undefined, result),
|
|
267
|
-
err => callback(err, null)
|
|
268
|
-
);
|
|
269
|
-
args.push(handler);
|
|
270
|
-
|
|
271
|
-
try {
|
|
272
|
-
return operation(...args);
|
|
273
|
-
} catch (e) {
|
|
274
|
-
handler(e);
|
|
275
|
-
throw e;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Return a Promise
|
|
280
|
-
if (args[args.length - 1] != null) {
|
|
281
|
-
// TODO(NODE-3483)
|
|
282
|
-
throw new MongoRuntimeError('Final argument to `executeLegacyOperation` must be a callback');
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return new Promise<any>((resolve, reject) => {
|
|
286
|
-
const handler = makeExecuteCallback(resolve, reject);
|
|
287
|
-
args[args.length - 1] = handler;
|
|
288
|
-
|
|
289
|
-
try {
|
|
290
|
-
return operation(...args);
|
|
291
|
-
} catch (e) {
|
|
292
|
-
handler(e);
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
192
|
interface HasRetryableWrites {
|
|
298
193
|
retryWrites?: boolean;
|
|
299
194
|
}
|
|
@@ -434,17 +329,30 @@ export function decorateWithExplain(command: Document, explain: Explain): Docume
|
|
|
434
329
|
return { explain: command, verbosity: explain.verbosity };
|
|
435
330
|
}
|
|
436
331
|
|
|
332
|
+
/**
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
export type TopologyProvider =
|
|
336
|
+
| MongoClient
|
|
337
|
+
| ClientSession
|
|
338
|
+
| FindCursor
|
|
339
|
+
| AbstractCursor
|
|
340
|
+
| Collection<any>
|
|
341
|
+
| Db;
|
|
342
|
+
|
|
437
343
|
/**
|
|
438
344
|
* A helper function to get the topology from a given provider. Throws
|
|
439
345
|
* if the topology cannot be found.
|
|
346
|
+
* @throws MongoNotConnectedError
|
|
440
347
|
* @internal
|
|
441
348
|
*/
|
|
442
|
-
export function getTopology
|
|
349
|
+
export function getTopology(provider: TopologyProvider): Topology {
|
|
350
|
+
// MongoClient or ClientSession or AbstractCursor
|
|
443
351
|
if (`topology` in provider && provider.topology) {
|
|
444
352
|
return provider.topology;
|
|
445
|
-
} else if ('client' in provider.s && provider.s.client.topology) {
|
|
353
|
+
} else if ('s' in provider && 'client' in provider.s && provider.s.client.topology) {
|
|
446
354
|
return provider.s.client.topology;
|
|
447
|
-
} else if ('db' in provider.s && provider.s.db.s.client.topology) {
|
|
355
|
+
} else if ('s' in provider && 'db' in provider.s && provider.s.db.s.client.topology) {
|
|
448
356
|
return provider.s.db.s.client.topology;
|
|
449
357
|
}
|
|
450
358
|
|
|
@@ -1181,7 +1089,7 @@ export function deepCopy<T>(value: T): T {
|
|
|
1181
1089
|
case 'set':
|
|
1182
1090
|
return new Set(value as any) as unknown as T;
|
|
1183
1091
|
case 'buffer':
|
|
1184
|
-
return Buffer.from(value as Buffer) as unknown as T;
|
|
1092
|
+
return Buffer.from(value as unknown as Buffer) as unknown as T;
|
|
1185
1093
|
}
|
|
1186
1094
|
}
|
|
1187
1095
|
|
|
@@ -1419,13 +1327,25 @@ export function enumToString(en: Record<string, unknown>): string {
|
|
|
1419
1327
|
*
|
|
1420
1328
|
* @internal
|
|
1421
1329
|
*/
|
|
1422
|
-
export function supportsRetryableWrites(server
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1330
|
+
export function supportsRetryableWrites(server?: Server): boolean {
|
|
1331
|
+
if (!server) {
|
|
1332
|
+
return false;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
if (server.loadBalanced) {
|
|
1336
|
+
// Loadbalanced topologies will always support retry writes
|
|
1337
|
+
return true;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
if (server.description.logicalSessionTimeoutMinutes != null) {
|
|
1341
|
+
// that supports sessions
|
|
1342
|
+
if (server.description.type !== ServerType.Standalone) {
|
|
1343
|
+
// and that is not a standalone
|
|
1344
|
+
return true;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
return false;
|
|
1429
1349
|
}
|
|
1430
1350
|
|
|
1431
1351
|
export function parsePackageVersion({ version }: { version: string }): {
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": false,
|
|
4
|
+
"checkJs": false,
|
|
5
|
+
"strict": true,
|
|
6
|
+
"alwaysStrict": true,
|
|
7
|
+
"target": "ES2019",
|
|
8
|
+
"module": "commonJS",
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"lib": ["es2020"],
|
|
12
|
+
// We don't make use of tslib helpers, all syntax used is supported by target engine
|
|
13
|
+
"importHelpers": false,
|
|
14
|
+
"noEmitHelpers": true,
|
|
15
|
+
// Never emit error filled code
|
|
16
|
+
"noEmitOnError": true,
|
|
17
|
+
"outDir": "lib",
|
|
18
|
+
"importsNotUsedAsValues": "error",
|
|
19
|
+
// We want the sourcemaps in a separate file
|
|
20
|
+
"inlineSourceMap": false,
|
|
21
|
+
"sourceMap": true,
|
|
22
|
+
// API-Extractor uses declaration maps to report problems in source, no need to distribute
|
|
23
|
+
"declaration": true,
|
|
24
|
+
"declarationMap": true,
|
|
25
|
+
// we include sources in the release
|
|
26
|
+
"inlineSources": false,
|
|
27
|
+
// Prevents web types from being suggested by vscode.
|
|
28
|
+
"types": ["node"],
|
|
29
|
+
"forceConsistentCasingInFileNames": true,
|
|
30
|
+
"noImplicitOverride": true,
|
|
31
|
+
"noImplicitReturns": true,
|
|
32
|
+
// TODO(NODE-3659): Enable useUnknownInCatchVariables and add type assertions or remove unnecessary catch blocks
|
|
33
|
+
"useUnknownInCatchVariables": false
|
|
34
|
+
},
|
|
35
|
+
"ts-node": {
|
|
36
|
+
"transpileOnly": true,
|
|
37
|
+
"compiler": "typescript-cached-transpile"
|
|
38
|
+
},
|
|
39
|
+
"include": ["src/**/*"]
|
|
40
|
+
}
|