mongodb 4.1.4 → 4.3.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 +16 -15
- package/lib/admin.js +3 -3
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +16 -14
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +3 -4
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +1 -1
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +6 -7
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +3 -3
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +16 -18
- 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 +6 -6
- 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/providers.js +21 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +4 -4
- 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 +1 -1
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +20 -11
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +102 -15
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +27 -26
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +19 -30
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +3 -3
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +4 -4
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +4 -4
- package/lib/cmap/wire_protocol/shared.js +4 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +46 -47
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +106 -49
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +108 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +10 -7
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +23 -13
- package/lib/db.js.map +1 -1
- package/lib/deps.js +0 -1
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +12 -4
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +47 -24
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +1 -1
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +3 -2
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +81 -81
- package/lib/index.js.map +1 -1
- package/lib/logger.js +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -5
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +2 -2
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +2 -3
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js +9 -6
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +4 -13
- 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 +3 -2
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +3 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +3 -3
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- 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 +2 -2
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +23 -7
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +5 -5
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +2 -2
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +28 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +4 -4
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +11 -6
- 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 +4 -3
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +4 -2
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +1 -1
- package/lib/operations/profiling_level.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 +3 -3
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js +2 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +2 -2
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_preference.js +15 -5
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/monitor.js +4 -4
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +31 -31
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -1
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +38 -3
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +11 -11
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +40 -62
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +36 -14
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +13 -28
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +90 -23
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +159 -65
- package/mongodb.ts34.d.ts +184 -65
- package/package.json +26 -24
- package/src/admin.ts +9 -9
- package/src/bson.ts +26 -17
- package/src/bulk/common.ts +26 -20
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +35 -32
- package/src/cmap/auth/auth_provider.ts +3 -3
- package/src/cmap/auth/gssapi.ts +8 -8
- package/src/cmap/auth/mongo_credentials.ts +2 -6
- package/src/cmap/auth/mongocr.ts +3 -2
- package/src/cmap/auth/mongodb_aws.ts +10 -11
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/providers.ts +21 -0
- package/src/cmap/auth/scram.ts +9 -9
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +2 -2
- package/src/cmap/commands.ts +30 -19
- package/src/cmap/connect.ts +142 -22
- package/src/cmap/connection.ts +73 -52
- package/src/cmap/connection_pool.ts +39 -39
- package/src/cmap/connection_pool_events.ts +1 -1
- package/src/cmap/message_stream.ts +9 -8
- package/src/cmap/stream_description.ts +5 -5
- package/src/cmap/wire_protocol/compression.ts +2 -2
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +133 -106
- package/src/connection_string.ts +141 -60
- package/src/constants.ts +116 -0
- package/src/cursor/abstract_cursor.ts +21 -22
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +2 -2
- package/src/db.ts +49 -39
- package/src/deps.ts +3 -1
- package/src/encrypter.ts +12 -3
- package/src/error.ts +52 -24
- package/src/gridfs/download.ts +10 -8
- package/src/gridfs/index.ts +11 -11
- package/src/gridfs/upload.ts +13 -10
- package/src/index.ts +204 -199
- package/src/logger.ts +2 -1
- package/src/mongo_client.ts +58 -32
- package/src/mongo_types.ts +98 -20
- package/src/operations/add_user.ts +6 -5
- package/src/operations/aggregate.ts +6 -7
- package/src/operations/bulk_write.ts +5 -5
- package/src/operations/collections.ts +2 -2
- package/src/operations/command.ts +19 -8
- package/src/operations/common_functions.ts +4 -4
- package/src/operations/connect.ts +4 -14
- package/src/operations/count.ts +4 -4
- package/src/operations/count_documents.ts +3 -3
- package/src/operations/create_collection.ts +8 -7
- package/src/operations/delete.ts +5 -5
- package/src/operations/distinct.ts +4 -4
- package/src/operations/drop.ts +4 -4
- package/src/operations/estimated_document_count.ts +5 -5
- package/src/operations/eval.ts +5 -5
- package/src/operations/execute_operation.ts +30 -11
- package/src/operations/find.ts +14 -14
- package/src/operations/find_and_modify.ts +7 -7
- package/src/operations/get_more.ts +49 -0
- package/src/operations/indexes.ts +16 -16
- package/src/operations/insert.ts +9 -9
- package/src/operations/is_capped.ts +3 -3
- package/src/operations/list_collections.ts +18 -10
- package/src/operations/list_databases.ts +4 -4
- package/src/operations/map_reduce.ts +10 -9
- package/src/operations/operation.ts +8 -4
- package/src/operations/options_operation.ts +3 -3
- package/src/operations/profiling_level.ts +4 -4
- package/src/operations/remove_user.ts +4 -4
- package/src/operations/rename.ts +6 -6
- package/src/operations/run_command.ts +3 -3
- package/src/operations/set_profiling_level.ts +6 -5
- package/src/operations/stats.ts +4 -4
- package/src/operations/update.ts +10 -10
- package/src/operations/validate_collection.ts +4 -4
- package/src/read_preference.ts +18 -7
- package/src/sdam/common.ts +2 -2
- package/src/sdam/events.ts +1 -1
- package/src/sdam/monitor.ts +13 -14
- package/src/sdam/server.ts +71 -61
- package/src/sdam/server_description.ts +4 -4
- package/src/sdam/server_selection.ts +46 -3
- package/src/sdam/srv_polling.ts +15 -13
- package/src/sdam/topology.ts +89 -90
- package/src/sdam/topology_description.ts +39 -15
- package/src/sessions.ts +31 -48
- package/src/transactions.ts +6 -6
- package/src/utils.ts +123 -43
- package/lib/cmap/auth/defaultAuthProviders.js +0 -30
- package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
- package/src/cmap/auth/defaultAuthProviders.ts +0 -32
package/src/utils.ts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import * as os from 'os';
|
|
2
1
|
import * as crypto from 'crypto';
|
|
3
|
-
import {
|
|
2
|
+
import type { SrvRecord } from 'dns';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import { URL } from 'url';
|
|
5
|
+
|
|
6
|
+
import { Document, ObjectId, resolveBSONOptions } from './bson';
|
|
7
|
+
import type { Connection } from './cmap/connection';
|
|
8
|
+
import { MAX_SUPPORTED_WIRE_VERSION } from './cmap/wire_protocol/constants';
|
|
9
|
+
import type { Collection } from './collection';
|
|
10
|
+
import { LEGACY_HELLO_COMMAND } from './constants';
|
|
11
|
+
import type { Db } from './db';
|
|
4
12
|
import {
|
|
5
13
|
AnyError,
|
|
6
|
-
MongoParseError,
|
|
7
|
-
MongoRuntimeError,
|
|
8
14
|
MongoCompatibilityError,
|
|
9
|
-
|
|
15
|
+
MongoExpiredSessionError,
|
|
10
16
|
MongoInvalidArgumentError,
|
|
11
|
-
|
|
17
|
+
MongoNotConnectedError,
|
|
18
|
+
MongoParseError,
|
|
19
|
+
MongoRuntimeError
|
|
12
20
|
} from './error';
|
|
13
|
-
import { WriteConcern, WriteConcernOptions, W } from './write_concern';
|
|
14
|
-
import type { Server } from './sdam/server';
|
|
15
|
-
import type { Topology } from './sdam/topology';
|
|
16
|
-
import { ServerType } from './sdam/common';
|
|
17
|
-
import type { Db } from './db';
|
|
18
|
-
import type { Collection } from './collection';
|
|
19
|
-
import type { OperationOptions, Hint } from './operations/operation';
|
|
20
|
-
import type { ClientSession } from './sessions';
|
|
21
|
-
import { ReadConcern } from './read_concern';
|
|
22
|
-
import type { Connection } from './cmap/connection';
|
|
23
|
-
import { Document, ObjectId, resolveBSONOptions } from './bson';
|
|
24
|
-
import type { IndexSpecification, IndexDirection } from './operations/indexes';
|
|
25
21
|
import type { Explain } from './explain';
|
|
26
22
|
import type { MongoClient } from './mongo_client';
|
|
27
23
|
import type { CommandOperationOptions, OperationParent } from './operations/command';
|
|
24
|
+
import type { IndexDirection, IndexSpecification } from './operations/indexes';
|
|
25
|
+
import type { Hint, OperationOptions } from './operations/operation';
|
|
26
|
+
import { PromiseProvider } from './promise_provider';
|
|
27
|
+
import { ReadConcern } from './read_concern';
|
|
28
28
|
import { ReadPreference } from './read_preference';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
29
|
+
import { ServerType } from './sdam/common';
|
|
30
|
+
import type { Server } from './sdam/server';
|
|
31
|
+
import type { Topology } from './sdam/topology';
|
|
32
|
+
import type { ClientSession } from './sessions';
|
|
33
|
+
import { W, WriteConcern, WriteConcernOptions } from './write_concern';
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* MongoDB Driver style callback
|
|
@@ -954,7 +957,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
954
957
|
): InterruptibleAsyncInterval {
|
|
955
958
|
let timerId: NodeJS.Timeout | undefined;
|
|
956
959
|
let lastCallTime: number;
|
|
957
|
-
let
|
|
960
|
+
let cannotBeExpedited = false;
|
|
958
961
|
let stopped = false;
|
|
959
962
|
|
|
960
963
|
options = options ?? {};
|
|
@@ -965,10 +968,8 @@ export function makeInterruptibleAsyncInterval(
|
|
|
965
968
|
|
|
966
969
|
function wake() {
|
|
967
970
|
const currentTime = clock();
|
|
968
|
-
const
|
|
969
|
-
const
|
|
970
|
-
const timeUntilNextCall = interval - timeSinceLastCall;
|
|
971
|
-
lastWakeTime = currentTime;
|
|
971
|
+
const nextScheduledCallTime = lastCallTime + interval;
|
|
972
|
+
const timeUntilNextCall = nextScheduledCallTime - currentTime;
|
|
972
973
|
|
|
973
974
|
// For the streaming protocol: there is nothing obviously stopping this
|
|
974
975
|
// interval from being woken up again while we are waiting "infinitely"
|
|
@@ -976,8 +977,17 @@ export function makeInterruptibleAsyncInterval(
|
|
|
976
977
|
// never completes, the `timeUntilNextCall` will continue to grow
|
|
977
978
|
// negatively unbounded, so it will never trigger a reschedule here.
|
|
978
979
|
|
|
980
|
+
// This is possible in virtualized environments like AWS Lambda where our
|
|
981
|
+
// clock is unreliable. In these cases the timer is "running" but never
|
|
982
|
+
// actually completes, so we want to execute immediately and then attempt
|
|
983
|
+
// to reschedule.
|
|
984
|
+
if (timeUntilNextCall < 0) {
|
|
985
|
+
executeAndReschedule();
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
|
|
979
989
|
// debounce multiple calls to wake within the `minInterval`
|
|
980
|
-
if (
|
|
990
|
+
if (cannotBeExpedited) {
|
|
981
991
|
return;
|
|
982
992
|
}
|
|
983
993
|
|
|
@@ -985,14 +995,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
985
995
|
// faster than the `minInterval`
|
|
986
996
|
if (timeUntilNextCall > minInterval) {
|
|
987
997
|
reschedule(minInterval);
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
// This is possible in virtualized environments like AWS Lambda where our
|
|
991
|
-
// clock is unreliable. In these cases the timer is "running" but never
|
|
992
|
-
// actually completes, so we want to execute immediately and then attempt
|
|
993
|
-
// to reschedule.
|
|
994
|
-
if (timeUntilNextCall < 0) {
|
|
995
|
-
executeAndReschedule();
|
|
998
|
+
cannotBeExpedited = true;
|
|
996
999
|
}
|
|
997
1000
|
}
|
|
998
1001
|
|
|
@@ -1004,7 +1007,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
1004
1007
|
}
|
|
1005
1008
|
|
|
1006
1009
|
lastCallTime = 0;
|
|
1007
|
-
|
|
1010
|
+
cannotBeExpedited = false;
|
|
1008
1011
|
}
|
|
1009
1012
|
|
|
1010
1013
|
function reschedule(ms?: number) {
|
|
@@ -1017,7 +1020,7 @@ export function makeInterruptibleAsyncInterval(
|
|
|
1017
1020
|
}
|
|
1018
1021
|
|
|
1019
1022
|
function executeAndReschedule() {
|
|
1020
|
-
|
|
1023
|
+
cannotBeExpedited = false;
|
|
1021
1024
|
lastCallTime = clock();
|
|
1022
1025
|
|
|
1023
1026
|
fn(err => {
|
|
@@ -1095,8 +1098,17 @@ export function isSuperset(set: Set<any> | any[], subset: Set<any> | any[]): boo
|
|
|
1095
1098
|
return true;
|
|
1096
1099
|
}
|
|
1097
1100
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1101
|
+
/**
|
|
1102
|
+
* Checks if the document is a Hello request
|
|
1103
|
+
* @internal
|
|
1104
|
+
*/
|
|
1105
|
+
export function isHello(doc: Document): boolean {
|
|
1106
|
+
return doc[LEGACY_HELLO_COMMAND] || doc.hello ? true : false;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/** Returns the items that are uniquely in setA */
|
|
1110
|
+
export function setDifference<T>(setA: Iterable<T>, setB: Iterable<T>): Set<T> {
|
|
1111
|
+
const difference = new Set<T>(setA);
|
|
1100
1112
|
for (const elem of setB) {
|
|
1101
1113
|
difference.delete(elem);
|
|
1102
1114
|
}
|
|
@@ -1146,11 +1158,11 @@ export function isRecord(
|
|
|
1146
1158
|
* but instead something that is good enough for the purposes of
|
|
1147
1159
|
* command monitoring.
|
|
1148
1160
|
*/
|
|
1149
|
-
export function deepCopy<T
|
|
1161
|
+
export function deepCopy<T>(value: T): T {
|
|
1150
1162
|
if (value == null) {
|
|
1151
1163
|
return value;
|
|
1152
1164
|
} else if (Array.isArray(value)) {
|
|
1153
|
-
return value.map(item => deepCopy(item)) as T;
|
|
1165
|
+
return value.map(item => deepCopy(item)) as unknown as T;
|
|
1154
1166
|
} else if (isRecord(value)) {
|
|
1155
1167
|
const res = {} as any;
|
|
1156
1168
|
for (const key in value) {
|
|
@@ -1165,11 +1177,11 @@ export function deepCopy<T extends any>(value: T): T {
|
|
|
1165
1177
|
case 'date':
|
|
1166
1178
|
return new ctor(Number(value));
|
|
1167
1179
|
case 'map':
|
|
1168
|
-
return new Map(value as any) as T;
|
|
1180
|
+
return new Map(value as any) as unknown as T;
|
|
1169
1181
|
case 'set':
|
|
1170
|
-
return new Set(value as any) as T;
|
|
1182
|
+
return new Set(value as any) as unknown as T;
|
|
1171
1183
|
case 'buffer':
|
|
1172
|
-
return Buffer.from(value as Buffer) as T;
|
|
1184
|
+
return Buffer.from(value as Buffer) as unknown as T;
|
|
1173
1185
|
}
|
|
1174
1186
|
}
|
|
1175
1187
|
|
|
@@ -1319,6 +1331,14 @@ export class HostAddress {
|
|
|
1319
1331
|
Object.freeze(this);
|
|
1320
1332
|
}
|
|
1321
1333
|
|
|
1334
|
+
[Symbol.for('nodejs.util.inspect.custom')](): string {
|
|
1335
|
+
return this.inspect();
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
inspect(): string {
|
|
1339
|
+
return `new HostAddress('${this.toString(true)}')`;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1322
1342
|
/**
|
|
1323
1343
|
* @param ipv6Brackets - optionally request ipv6 bracket notation required for connection strings
|
|
1324
1344
|
*/
|
|
@@ -1335,6 +1355,17 @@ export class HostAddress {
|
|
|
1335
1355
|
static fromString(s: string): HostAddress {
|
|
1336
1356
|
return new HostAddress(s);
|
|
1337
1357
|
}
|
|
1358
|
+
|
|
1359
|
+
static fromHostPort(host: string, port: number): HostAddress {
|
|
1360
|
+
if (host.includes(':')) {
|
|
1361
|
+
host = `[${host}]`; // IPv6 address
|
|
1362
|
+
}
|
|
1363
|
+
return HostAddress.fromString(`${host}:${port}`);
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
static fromSrvRecord({ name, port }: SrvRecord): HostAddress {
|
|
1367
|
+
return HostAddress.fromHostPort(name, port);
|
|
1368
|
+
}
|
|
1338
1369
|
}
|
|
1339
1370
|
|
|
1340
1371
|
export const DEFAULT_PK_FACTORY = {
|
|
@@ -1405,3 +1436,52 @@ export function parsePackageVersion({ version }: { version: string }): {
|
|
|
1405
1436
|
const [major, minor, patch] = version.split('.').map((n: string) => Number.parseInt(n, 10));
|
|
1406
1437
|
return { major, minor, patch };
|
|
1407
1438
|
}
|
|
1439
|
+
|
|
1440
|
+
/**
|
|
1441
|
+
* Fisher–Yates Shuffle
|
|
1442
|
+
*
|
|
1443
|
+
* Reference: https://bost.ocks.org/mike/shuffle/
|
|
1444
|
+
* @param sequence - items to be shuffled
|
|
1445
|
+
* @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.
|
|
1446
|
+
*/
|
|
1447
|
+
export function shuffle<T>(sequence: Iterable<T>, limit = 0): Array<T> {
|
|
1448
|
+
const items = Array.from(sequence); // shallow copy in order to never shuffle the input
|
|
1449
|
+
|
|
1450
|
+
if (limit > items.length) {
|
|
1451
|
+
throw new MongoRuntimeError('Limit must be less than the number of items');
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
let remainingItemsToShuffle = items.length;
|
|
1455
|
+
const lowerBound = limit % items.length === 0 ? 1 : items.length - limit;
|
|
1456
|
+
while (remainingItemsToShuffle > lowerBound) {
|
|
1457
|
+
// Pick a remaining element
|
|
1458
|
+
const randomIndex = Math.floor(Math.random() * remainingItemsToShuffle);
|
|
1459
|
+
remainingItemsToShuffle -= 1;
|
|
1460
|
+
|
|
1461
|
+
// And swap it with the current element
|
|
1462
|
+
const swapHold = items[remainingItemsToShuffle];
|
|
1463
|
+
items[remainingItemsToShuffle] = items[randomIndex];
|
|
1464
|
+
items[randomIndex] = swapHold;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
return limit % items.length === 0 ? items : items.slice(lowerBound);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// TODO: this should be codified in command construction
|
|
1471
|
+
// @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#read-concern
|
|
1472
|
+
export function commandSupportsReadConcern(command: Document, options?: Document): boolean {
|
|
1473
|
+
if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
|
|
1474
|
+
return true;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
if (
|
|
1478
|
+
command.mapReduce &&
|
|
1479
|
+
options &&
|
|
1480
|
+
options.out &&
|
|
1481
|
+
(options.out.inline === 1 || options.out === 'inline')
|
|
1482
|
+
) {
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
return false;
|
|
1487
|
+
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AUTH_PROVIDERS = exports.AuthMechanism = void 0;
|
|
4
|
-
const mongocr_1 = require("./mongocr");
|
|
5
|
-
const x509_1 = require("./x509");
|
|
6
|
-
const plain_1 = require("./plain");
|
|
7
|
-
const gssapi_1 = require("./gssapi");
|
|
8
|
-
const scram_1 = require("./scram");
|
|
9
|
-
const mongodb_aws_1 = require("./mongodb_aws");
|
|
10
|
-
/** @public */
|
|
11
|
-
exports.AuthMechanism = Object.freeze({
|
|
12
|
-
MONGODB_AWS: 'MONGODB-AWS',
|
|
13
|
-
MONGODB_CR: 'MONGODB-CR',
|
|
14
|
-
MONGODB_DEFAULT: 'DEFAULT',
|
|
15
|
-
MONGODB_GSSAPI: 'GSSAPI',
|
|
16
|
-
MONGODB_PLAIN: 'PLAIN',
|
|
17
|
-
MONGODB_SCRAM_SHA1: 'SCRAM-SHA-1',
|
|
18
|
-
MONGODB_SCRAM_SHA256: 'SCRAM-SHA-256',
|
|
19
|
-
MONGODB_X509: 'MONGODB-X509'
|
|
20
|
-
});
|
|
21
|
-
exports.AUTH_PROVIDERS = new Map([
|
|
22
|
-
[exports.AuthMechanism.MONGODB_AWS, new mongodb_aws_1.MongoDBAWS()],
|
|
23
|
-
[exports.AuthMechanism.MONGODB_CR, new mongocr_1.MongoCR()],
|
|
24
|
-
[exports.AuthMechanism.MONGODB_GSSAPI, new gssapi_1.GSSAPI()],
|
|
25
|
-
[exports.AuthMechanism.MONGODB_PLAIN, new plain_1.Plain()],
|
|
26
|
-
[exports.AuthMechanism.MONGODB_SCRAM_SHA1, new scram_1.ScramSHA1()],
|
|
27
|
-
[exports.AuthMechanism.MONGODB_SCRAM_SHA256, new scram_1.ScramSHA256()],
|
|
28
|
-
[exports.AuthMechanism.MONGODB_X509, new x509_1.X509()]
|
|
29
|
-
]);
|
|
30
|
-
//# sourceMappingURL=defaultAuthProviders.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultAuthProviders.js","sourceRoot":"","sources":["../../../src/cmap/auth/defaultAuthProviders.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,iCAA8B;AAC9B,mCAAgC;AAChC,qCAAkC;AAClC,mCAAiD;AACjD,+CAA2C;AAG3C,cAAc;AACD,QAAA,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,eAAe,EAAE,SAAS;IAC1B,cAAc,EAAE,QAAQ;IACxB,aAAa,EAAE,OAAO;IACtB,kBAAkB,EAAE,aAAa;IACjC,oBAAoB,EAAE,eAAe;IACrC,YAAY,EAAE,cAAc;CACpB,CAAC,CAAC;AAKC,QAAA,cAAc,GAAG,IAAI,GAAG,CAAuC;IAC1E,CAAC,qBAAa,CAAC,WAAW,EAAE,IAAI,wBAAU,EAAE,CAAC;IAC7C,CAAC,qBAAa,CAAC,UAAU,EAAE,IAAI,iBAAO,EAAE,CAAC;IACzC,CAAC,qBAAa,CAAC,cAAc,EAAE,IAAI,eAAM,EAAE,CAAC;IAC5C,CAAC,qBAAa,CAAC,aAAa,EAAE,IAAI,aAAK,EAAE,CAAC;IAC1C,CAAC,qBAAa,CAAC,kBAAkB,EAAE,IAAI,iBAAS,EAAE,CAAC;IACnD,CAAC,qBAAa,CAAC,oBAAoB,EAAE,IAAI,mBAAW,EAAE,CAAC;IACvD,CAAC,qBAAa,CAAC,YAAY,EAAE,IAAI,WAAI,EAAE,CAAC;CACzC,CAAC,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { MongoCR } from './mongocr';
|
|
2
|
-
import { X509 } from './x509';
|
|
3
|
-
import { Plain } from './plain';
|
|
4
|
-
import { GSSAPI } from './gssapi';
|
|
5
|
-
import { ScramSHA1, ScramSHA256 } from './scram';
|
|
6
|
-
import { MongoDBAWS } from './mongodb_aws';
|
|
7
|
-
import type { AuthProvider } from './auth_provider';
|
|
8
|
-
|
|
9
|
-
/** @public */
|
|
10
|
-
export const AuthMechanism = Object.freeze({
|
|
11
|
-
MONGODB_AWS: 'MONGODB-AWS',
|
|
12
|
-
MONGODB_CR: 'MONGODB-CR',
|
|
13
|
-
MONGODB_DEFAULT: 'DEFAULT',
|
|
14
|
-
MONGODB_GSSAPI: 'GSSAPI',
|
|
15
|
-
MONGODB_PLAIN: 'PLAIN',
|
|
16
|
-
MONGODB_SCRAM_SHA1: 'SCRAM-SHA-1',
|
|
17
|
-
MONGODB_SCRAM_SHA256: 'SCRAM-SHA-256',
|
|
18
|
-
MONGODB_X509: 'MONGODB-X509'
|
|
19
|
-
} as const);
|
|
20
|
-
|
|
21
|
-
/** @public */
|
|
22
|
-
export type AuthMechanism = typeof AuthMechanism[keyof typeof AuthMechanism];
|
|
23
|
-
|
|
24
|
-
export const AUTH_PROVIDERS = new Map<AuthMechanism | string, AuthProvider>([
|
|
25
|
-
[AuthMechanism.MONGODB_AWS, new MongoDBAWS()],
|
|
26
|
-
[AuthMechanism.MONGODB_CR, new MongoCR()],
|
|
27
|
-
[AuthMechanism.MONGODB_GSSAPI, new GSSAPI()],
|
|
28
|
-
[AuthMechanism.MONGODB_PLAIN, new Plain()],
|
|
29
|
-
[AuthMechanism.MONGODB_SCRAM_SHA1, new ScramSHA1()],
|
|
30
|
-
[AuthMechanism.MONGODB_SCRAM_SHA256, new ScramSHA256()],
|
|
31
|
-
[AuthMechanism.MONGODB_X509, new X509()]
|
|
32
|
-
]);
|