mongodb 4.1.1 → 4.2.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 +24 -17
- package/lib/admin.js +5 -5
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +60 -56
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +15 -13
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +1 -1
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +2 -1
- 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 +23 -28
- 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 +5 -5
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +15 -15
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +2 -2
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +15 -15
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +3 -3
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +2 -2
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +1 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +4 -4
- package/lib/collection.js +42 -41
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +94 -58
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +11 -11
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +15 -15
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +23 -23
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +20 -20
- package/lib/db.js.map +1 -1
- package/lib/deps.js +1 -1
- package/lib/deps.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +1 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +8 -2
- package/lib/index.js.map +1 -1
- package/lib/logger.js +5 -5
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +7 -7
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +3 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +3 -4
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/command.js +7 -3
- 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 +1 -1
- 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.map +1 -1
- package/lib/operations/create_collection.js +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +6 -6
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +4 -4
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +2 -2
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js +2 -2
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +17 -7
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +8 -8
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +7 -7
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/indexes.js +14 -14
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +5 -5
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/list_collections.js +12 -7
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +6 -6
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +2 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/remove_user.js +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +2 -2
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/set_profiling_level.js +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +2 -2
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +12 -12
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/monitor.js +14 -14
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +19 -12
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +3 -3
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +20 -1
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +9 -9
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +29 -21
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +34 -12
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +19 -19
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +53 -46
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +97 -50
- package/mongodb.ts34.d.ts +96 -50
- package/package.json +44 -47
- package/src/bulk/common.ts +56 -35
- package/src/change_stream.ts +8 -6
- package/src/cmap/auth/mongo_credentials.ts +14 -3
- package/src/cmap/auth/mongodb_aws.ts +32 -31
- package/src/cmap/command_monitoring_events.ts +1 -1
- package/src/cmap/connection.ts +1 -0
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/collection.ts +32 -24
- package/src/connection_string.ts +103 -52
- package/src/cursor/abstract_cursor.ts +6 -4
- package/src/cursor/aggregation_cursor.ts +3 -3
- package/src/cursor/find_cursor.ts +1 -1
- package/src/db.ts +5 -6
- package/src/deps.ts +56 -19
- package/src/gridfs/download.ts +1 -1
- package/src/gridfs/upload.ts +11 -7
- package/src/index.ts +12 -1
- package/src/mongo_client.ts +18 -11
- package/src/mongo_types.ts +10 -13
- package/src/operations/aggregate.ts +1 -2
- package/src/operations/command.ts +5 -0
- package/src/operations/count.ts +1 -1
- package/src/operations/count_documents.ts +1 -1
- package/src/operations/create_collection.ts +1 -1
- package/src/operations/eval.ts +1 -1
- package/src/operations/execute_operation.ts +13 -2
- package/src/operations/indexes.ts +2 -2
- package/src/operations/list_collections.ts +12 -4
- package/src/operations/list_databases.ts +6 -1
- package/src/operations/operation.ts +3 -0
- package/src/sdam/server.ts +8 -0
- package/src/sdam/server_selection.ts +25 -0
- package/src/sdam/srv_polling.ts +12 -11
- package/src/sdam/topology.ts +27 -10
- package/src/sdam/topology_description.ts +35 -11
- package/src/transactions.ts +2 -2
- package/src/utils.ts +67 -56
package/src/utils.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type { CommandOperationOptions, OperationParent } from './operations/comm
|
|
|
28
28
|
import { ReadPreference } from './read_preference';
|
|
29
29
|
import { URL } from 'url';
|
|
30
30
|
import { MAX_SUPPORTED_WIRE_VERSION } from './cmap/wire_protocol/constants';
|
|
31
|
+
import type { SrvRecord } from 'dns';
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* MongoDB Driver style callback
|
|
@@ -41,23 +42,6 @@ export const MAX_JS_INT = Number.MAX_SAFE_INTEGER + 1;
|
|
|
41
42
|
|
|
42
43
|
export type AnyOptions = Document;
|
|
43
44
|
|
|
44
|
-
/**
|
|
45
|
-
* Add a readonly enumerable property.
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
export function getSingleProperty(
|
|
49
|
-
obj: AnyOptions,
|
|
50
|
-
name: string | number | symbol,
|
|
51
|
-
value: unknown
|
|
52
|
-
): void {
|
|
53
|
-
Object.defineProperty(obj, name, {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
get() {
|
|
56
|
-
return value;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
45
|
/**
|
|
62
46
|
* Throws if collectionName is not a valid mongodb collection namespace.
|
|
63
47
|
* @internal
|
|
@@ -185,17 +169,6 @@ export function isObject(arg: unknown): arg is object {
|
|
|
185
169
|
return '[object Object]' === Object.prototype.toString.call(arg);
|
|
186
170
|
}
|
|
187
171
|
|
|
188
|
-
/** @internal */
|
|
189
|
-
export function decorateCommand(command: Document, options: Document, exclude: string[]): Document {
|
|
190
|
-
for (const name in options) {
|
|
191
|
-
if (!exclude.includes(name)) {
|
|
192
|
-
command[name] = options[name];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return command;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
172
|
/** @internal */
|
|
200
173
|
export function mergeOptions<T, S>(target: T, source: S): T & S {
|
|
201
174
|
return { ...target, ...source };
|
|
@@ -657,11 +630,6 @@ export function databaseNamespace(ns: string): string {
|
|
|
657
630
|
return ns.split('.')[0];
|
|
658
631
|
}
|
|
659
632
|
|
|
660
|
-
/** @internal */
|
|
661
|
-
export function collectionNamespace(ns: string): string {
|
|
662
|
-
return ns.split('.').slice(1).join('.');
|
|
663
|
-
}
|
|
664
|
-
|
|
665
633
|
/**
|
|
666
634
|
* Synchronously Generate a UUIDv4
|
|
667
635
|
* @internal
|
|
@@ -987,7 +955,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
987
955
|
): InterruptibleAsyncInterval {
|
|
988
956
|
let timerId: NodeJS.Timeout | undefined;
|
|
989
957
|
let lastCallTime: number;
|
|
990
|
-
let
|
|
958
|
+
let cannotBeExpedited = false;
|
|
991
959
|
let stopped = false;
|
|
992
960
|
|
|
993
961
|
options = options ?? {};
|
|
@@ -998,10 +966,8 @@ export function makeInterruptibleAsyncInterval(
|
|
|
998
966
|
|
|
999
967
|
function wake() {
|
|
1000
968
|
const currentTime = clock();
|
|
1001
|
-
const
|
|
1002
|
-
const
|
|
1003
|
-
const timeUntilNextCall = interval - timeSinceLastCall;
|
|
1004
|
-
lastWakeTime = currentTime;
|
|
969
|
+
const nextScheduledCallTime = lastCallTime + interval;
|
|
970
|
+
const timeUntilNextCall = nextScheduledCallTime - currentTime;
|
|
1005
971
|
|
|
1006
972
|
// For the streaming protocol: there is nothing obviously stopping this
|
|
1007
973
|
// interval from being woken up again while we are waiting "infinitely"
|
|
@@ -1009,8 +975,17 @@ export function makeInterruptibleAsyncInterval(
|
|
|
1009
975
|
// never completes, the `timeUntilNextCall` will continue to grow
|
|
1010
976
|
// negatively unbounded, so it will never trigger a reschedule here.
|
|
1011
977
|
|
|
978
|
+
// This is possible in virtualized environments like AWS Lambda where our
|
|
979
|
+
// clock is unreliable. In these cases the timer is "running" but never
|
|
980
|
+
// actually completes, so we want to execute immediately and then attempt
|
|
981
|
+
// to reschedule.
|
|
982
|
+
if (timeUntilNextCall < 0) {
|
|
983
|
+
executeAndReschedule();
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
|
|
1012
987
|
// debounce multiple calls to wake within the `minInterval`
|
|
1013
|
-
if (
|
|
988
|
+
if (cannotBeExpedited) {
|
|
1014
989
|
return;
|
|
1015
990
|
}
|
|
1016
991
|
|
|
@@ -1018,14 +993,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
1018
993
|
// faster than the `minInterval`
|
|
1019
994
|
if (timeUntilNextCall > minInterval) {
|
|
1020
995
|
reschedule(minInterval);
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
// This is possible in virtualized environments like AWS Lambda where our
|
|
1024
|
-
// clock is unreliable. In these cases the timer is "running" but never
|
|
1025
|
-
// actually completes, so we want to execute immediately and then attempt
|
|
1026
|
-
// to reschedule.
|
|
1027
|
-
if (timeUntilNextCall < 0) {
|
|
1028
|
-
executeAndReschedule();
|
|
996
|
+
cannotBeExpedited = true;
|
|
1029
997
|
}
|
|
1030
998
|
}
|
|
1031
999
|
|
|
@@ -1037,7 +1005,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
1037
1005
|
}
|
|
1038
1006
|
|
|
1039
1007
|
lastCallTime = 0;
|
|
1040
|
-
|
|
1008
|
+
cannotBeExpedited = false;
|
|
1041
1009
|
}
|
|
1042
1010
|
|
|
1043
1011
|
function reschedule(ms?: number) {
|
|
@@ -1050,7 +1018,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
1050
1018
|
}
|
|
1051
1019
|
|
|
1052
1020
|
function executeAndReschedule() {
|
|
1053
|
-
|
|
1021
|
+
cannotBeExpedited = false;
|
|
1054
1022
|
lastCallTime = clock();
|
|
1055
1023
|
|
|
1056
1024
|
fn(err => {
|
|
@@ -1128,8 +1096,9 @@ export function isSuperset(set: Set<any> | any[], subset: Set<any> | any[]): boo
|
|
|
1128
1096
|
return true;
|
|
1129
1097
|
}
|
|
1130
1098
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1099
|
+
/** Returns the items that are uniquely in setA */
|
|
1100
|
+
export function setDifference<T>(setA: Iterable<T>, setB: Iterable<T>): Set<T> {
|
|
1101
|
+
const difference = new Set<T>(setA);
|
|
1133
1102
|
for (const elem of setB) {
|
|
1134
1103
|
difference.delete(elem);
|
|
1135
1104
|
}
|
|
@@ -1352,6 +1321,14 @@ export class HostAddress {
|
|
|
1352
1321
|
Object.freeze(this);
|
|
1353
1322
|
}
|
|
1354
1323
|
|
|
1324
|
+
[Symbol.for('nodejs.util.inspect.custom')](): string {
|
|
1325
|
+
return this.inspect();
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
inspect(): string {
|
|
1329
|
+
return `new HostAddress('${this.toString(true)}')`;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1355
1332
|
/**
|
|
1356
1333
|
* @param ipv6Brackets - optionally request ipv6 bracket notation required for connection strings
|
|
1357
1334
|
*/
|
|
@@ -1368,6 +1345,10 @@ export class HostAddress {
|
|
|
1368
1345
|
static fromString(s: string): HostAddress {
|
|
1369
1346
|
return new HostAddress(s);
|
|
1370
1347
|
}
|
|
1348
|
+
|
|
1349
|
+
static fromSrvRecord({ name, port }: SrvRecord): HostAddress {
|
|
1350
|
+
return HostAddress.fromString(`${name}:${port}`);
|
|
1351
|
+
}
|
|
1371
1352
|
}
|
|
1372
1353
|
|
|
1373
1354
|
export const DEFAULT_PK_FACTORY = {
|
|
@@ -1430,11 +1411,41 @@ export function supportsRetryableWrites(server: Server): boolean {
|
|
|
1430
1411
|
);
|
|
1431
1412
|
}
|
|
1432
1413
|
|
|
1433
|
-
export function parsePackageVersion({
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
}
|
|
1414
|
+
export function parsePackageVersion({ version }: { version: string }): {
|
|
1415
|
+
major: number;
|
|
1416
|
+
minor: number;
|
|
1417
|
+
patch: number;
|
|
1418
|
+
} {
|
|
1438
1419
|
const [major, minor, patch] = version.split('.').map((n: string) => Number.parseInt(n, 10));
|
|
1439
1420
|
return { major, minor, patch };
|
|
1440
1421
|
}
|
|
1422
|
+
|
|
1423
|
+
/**
|
|
1424
|
+
* Fisher–Yates Shuffle
|
|
1425
|
+
*
|
|
1426
|
+
* Reference: https://bost.ocks.org/mike/shuffle/
|
|
1427
|
+
* @param sequence - items to be shuffled
|
|
1428
|
+
* @param limit - Defaults to `0`. If nonzero shuffle will slice the randomized array e.g, `.slice(0, limit)` otherwise will return the entire randomized array.
|
|
1429
|
+
*/
|
|
1430
|
+
export function shuffle<T>(sequence: Iterable<T>, limit = 0): Array<T> {
|
|
1431
|
+
const items = Array.from(sequence); // shallow copy in order to never shuffle the input
|
|
1432
|
+
|
|
1433
|
+
if (limit > items.length) {
|
|
1434
|
+
throw new MongoRuntimeError('Limit must be less than the number of items');
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
let remainingItemsToShuffle = items.length;
|
|
1438
|
+
const lowerBound = limit % items.length === 0 ? 1 : items.length - limit;
|
|
1439
|
+
while (remainingItemsToShuffle > lowerBound) {
|
|
1440
|
+
// Pick a remaining element
|
|
1441
|
+
const randomIndex = Math.floor(Math.random() * remainingItemsToShuffle);
|
|
1442
|
+
remainingItemsToShuffle -= 1;
|
|
1443
|
+
|
|
1444
|
+
// And swap it with the current element
|
|
1445
|
+
const swapHold = items[remainingItemsToShuffle];
|
|
1446
|
+
items[remainingItemsToShuffle] = items[randomIndex];
|
|
1447
|
+
items[randomIndex] = swapHold;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
return limit % items.length === 0 ? items : items.slice(lowerBound);
|
|
1451
|
+
}
|