mongodb 4.2.2 → 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 +1 -1
- 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 -3
- 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 -6
- 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 +14 -8
- 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 +1 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +4 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +45 -47
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +48 -19
- 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 +5 -5
- 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/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 +1 -1
- 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 +5 -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 +5 -6
- 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.map +1 -1
- 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 +3 -3
- 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 +1 -1
- 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 +11 -4
- 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 +24 -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 +2 -2
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -2
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +25 -55
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +2 -2
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +12 -27
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +40 -9
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +105 -32
- package/mongodb.ts34.d.ts +129 -32
- package/package.json +7 -3
- package/src/admin.ts +9 -9
- package/src/bson.ts +25 -17
- package/src/bulk/common.ts +17 -17
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +25 -24
- 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 +22 -14
- package/src/cmap/connect.ts +142 -22
- package/src/cmap/connection.ts +72 -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 +2 -2
- package/src/cmap/wire_protocol/compression.ts +2 -2
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +94 -82
- package/src/connection_string.ts +66 -24
- package/src/constants.ts +116 -0
- package/src/cursor/abstract_cursor.ts +14 -13
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +2 -2
- package/src/db.ts +44 -33
- package/src/deps.ts +3 -1
- package/src/encrypter.ts +12 -3
- package/src/error.ts +1 -1
- 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 +46 -32
- package/src/mongo_types.ts +97 -19
- package/src/operations/add_user.ts +6 -5
- package/src/operations/aggregate.ts +5 -5
- package/src/operations/bulk_write.ts +5 -5
- package/src/operations/collections.ts +2 -2
- package/src/operations/command.ts +15 -9
- 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 +7 -6
- 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 +10 -11
- package/src/operations/find.ts +14 -14
- package/src/operations/find_and_modify.ts +7 -7
- package/src/operations/get_more.ts +2 -2
- 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 +6 -6
- package/src/operations/list_databases.ts +4 -4
- package/src/operations/map_reduce.ts +10 -9
- package/src/operations/operation.ts +3 -3
- 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 +14 -6
- 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 +63 -61
- package/src/sdam/server_description.ts +4 -4
- package/src/sdam/server_selection.ts +3 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +63 -81
- package/src/sdam/topology_description.ts +4 -4
- package/src/sessions.ts +30 -48
- package/src/transactions.ts +4 -4
- package/src/utils.ts +58 -22
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ServerType } from './common';
|
|
3
|
-
import { ObjectId, Long, Document } from '../bson';
|
|
4
|
-
import type { ClusterTime } from './common';
|
|
1
|
+
import { Document, Long, ObjectId } from '../bson';
|
|
5
2
|
import type { MongoError } from '../error';
|
|
3
|
+
import { arrayStrictEqual, errorStrictEqual, HostAddress, now } from '../utils';
|
|
4
|
+
import type { ClusterTime } from './common';
|
|
5
|
+
import { ServerType } from './common';
|
|
6
6
|
|
|
7
7
|
const WRITABLE_SERVER_TYPES = new Set<ServerType>([
|
|
8
8
|
ServerType.RSPrimary,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ServerType, TopologyType } from './common';
|
|
2
|
-
import { ReadPreference } from '../read_preference';
|
|
3
1
|
import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
|
|
4
|
-
import
|
|
2
|
+
import { ReadPreference } from '../read_preference';
|
|
3
|
+
import { ServerType, TopologyType } from './common';
|
|
5
4
|
import type { ServerDescription, TagSet } from './server_description';
|
|
5
|
+
import type { TopologyDescription } from './topology_description';
|
|
6
6
|
|
|
7
7
|
// max staleness constants
|
|
8
8
|
const IDLE_WRITE_PERIOD = 10000;
|
package/src/sdam/srv_polling.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as dns from 'dns';
|
|
2
|
+
|
|
3
|
+
import { MongoRuntimeError } from '../error';
|
|
2
4
|
import { Logger, LoggerOptions } from '../logger';
|
|
3
|
-
import { HostAddress } from '../utils';
|
|
4
5
|
import { TypedEventEmitter } from '../mongo_types';
|
|
5
|
-
import {
|
|
6
|
+
import { HostAddress } from '../utils';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Determines whether a provided address matches the provided parent domain in order
|
package/src/sdam/topology.ts
CHANGED
|
@@ -1,88 +1,83 @@
|
|
|
1
1
|
import Denque = require('denque');
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import type { BSONSerializeOptions, Document } from '../bson';
|
|
3
|
+
import { deserialize, serialize } from '../bson';
|
|
4
|
+
import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
|
|
5
|
+
import type { ConnectionEvents, DestroyOptions } from '../cmap/connection';
|
|
6
|
+
import type { CloseOptions, ConnectionPoolEvents } from '../cmap/connection_pool';
|
|
7
|
+
import { DEFAULT_OPTIONS } from '../connection_string';
|
|
6
8
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
CLOSE,
|
|
10
|
+
CONNECT,
|
|
11
|
+
ERROR,
|
|
12
|
+
LOCAL_SERVER_EVENTS,
|
|
13
|
+
OPEN,
|
|
14
|
+
SERVER_CLOSED,
|
|
15
|
+
SERVER_DESCRIPTION_CHANGED,
|
|
16
|
+
SERVER_OPENING,
|
|
17
|
+
SERVER_RELAY_EVENTS,
|
|
18
|
+
TIMEOUT,
|
|
19
|
+
TOPOLOGY_CLOSED,
|
|
20
|
+
TOPOLOGY_DESCRIPTION_CHANGED,
|
|
21
|
+
TOPOLOGY_OPENING
|
|
22
|
+
} from '../constants';
|
|
14
23
|
import {
|
|
15
|
-
MongoServerSelectionError,
|
|
16
24
|
MongoCompatibilityError,
|
|
17
25
|
MongoDriverError,
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
MongoRuntimeError,
|
|
27
|
+
MongoServerSelectionError,
|
|
28
|
+
MongoTopologyClosedError
|
|
20
29
|
} from '../error';
|
|
21
|
-
import {
|
|
30
|
+
import type { MongoOptions, ServerApi } from '../mongo_client';
|
|
31
|
+
import { TypedEventEmitter } from '../mongo_types';
|
|
32
|
+
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
|
|
33
|
+
import {
|
|
34
|
+
ClientSession,
|
|
35
|
+
ClientSessionOptions,
|
|
36
|
+
ServerSessionId,
|
|
37
|
+
ServerSessionPool
|
|
38
|
+
} from '../sessions';
|
|
39
|
+
import type { Transaction } from '../transactions';
|
|
22
40
|
import {
|
|
23
|
-
makeStateMachine,
|
|
24
|
-
eachAsync,
|
|
25
|
-
ClientMetadata,
|
|
26
41
|
Callback,
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
ClientMetadata,
|
|
43
|
+
eachAsync,
|
|
29
44
|
emitWarning,
|
|
30
45
|
EventEmitterWithState,
|
|
46
|
+
HostAddress,
|
|
47
|
+
makeStateMachine,
|
|
48
|
+
ns,
|
|
31
49
|
shuffle
|
|
32
50
|
} from '../utils';
|
|
33
51
|
import {
|
|
34
|
-
TopologyType,
|
|
35
|
-
ServerType,
|
|
36
|
-
ClusterTime,
|
|
37
|
-
TimerQueue,
|
|
38
52
|
_advanceClusterTime,
|
|
39
|
-
drainTimerQueue,
|
|
40
53
|
clearAndRemoveTimerFrom,
|
|
54
|
+
ClusterTime,
|
|
55
|
+
drainTimerQueue,
|
|
56
|
+
ServerType,
|
|
41
57
|
STATE_CLOSED,
|
|
42
58
|
STATE_CLOSING,
|
|
59
|
+
STATE_CONNECTED,
|
|
43
60
|
STATE_CONNECTING,
|
|
44
|
-
|
|
61
|
+
TimerQueue,
|
|
62
|
+
TopologyType
|
|
45
63
|
} from './common';
|
|
46
64
|
import {
|
|
47
|
-
ServerOpeningEvent,
|
|
48
65
|
ServerClosedEvent,
|
|
49
66
|
ServerDescriptionChangedEvent,
|
|
50
|
-
|
|
67
|
+
ServerOpeningEvent,
|
|
51
68
|
TopologyClosedEvent,
|
|
52
|
-
TopologyDescriptionChangedEvent
|
|
69
|
+
TopologyDescriptionChangedEvent,
|
|
70
|
+
TopologyOpeningEvent
|
|
53
71
|
} from './events';
|
|
54
|
-
import
|
|
55
|
-
import
|
|
56
|
-
import
|
|
57
|
-
import
|
|
58
|
-
import {
|
|
59
|
-
import type { MongoOptions, ServerApi } from '../mongo_client';
|
|
60
|
-
import { DEFAULT_OPTIONS } from '../connection_string';
|
|
61
|
-
import { serialize, deserialize } from '../bson';
|
|
62
|
-
import { TypedEventEmitter } from '../mongo_types';
|
|
72
|
+
import { Server, ServerEvents, ServerOptions } from './server';
|
|
73
|
+
import { compareTopologyVersion, ServerDescription } from './server_description';
|
|
74
|
+
import { readPreferenceServerSelector, ServerSelector } from './server_selection';
|
|
75
|
+
import { SrvPoller, SrvPollingEvent } from './srv_polling';
|
|
76
|
+
import { TopologyDescription } from './topology_description';
|
|
63
77
|
|
|
64
78
|
// Global state
|
|
65
79
|
let globalTopologyCounter = 0;
|
|
66
80
|
|
|
67
|
-
// events that we relay to the `Topology`
|
|
68
|
-
const SERVER_RELAY_EVENTS = [
|
|
69
|
-
Server.SERVER_HEARTBEAT_STARTED,
|
|
70
|
-
Server.SERVER_HEARTBEAT_SUCCEEDED,
|
|
71
|
-
Server.SERVER_HEARTBEAT_FAILED,
|
|
72
|
-
Connection.COMMAND_STARTED,
|
|
73
|
-
Connection.COMMAND_SUCCEEDED,
|
|
74
|
-
Connection.COMMAND_FAILED,
|
|
75
|
-
...CMAP_EVENTS
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
// all events we listen to from `Server` instances
|
|
79
|
-
const LOCAL_SERVER_EVENTS = [
|
|
80
|
-
Server.CONNECT,
|
|
81
|
-
Server.DESCRIPTION_RECEIVED,
|
|
82
|
-
Server.CLOSED,
|
|
83
|
-
Server.ENDED
|
|
84
|
-
];
|
|
85
|
-
|
|
86
81
|
const stateTransition = makeStateMachine({
|
|
87
82
|
[STATE_CLOSED]: [STATE_CLOSED, STATE_CONNECTING],
|
|
88
83
|
[STATE_CONNECTING]: [STATE_CONNECTING, STATE_CLOSING, STATE_CONNECTED, STATE_CLOSED],
|
|
@@ -208,27 +203,27 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
208
203
|
_type?: string;
|
|
209
204
|
|
|
210
205
|
/** @event */
|
|
211
|
-
static readonly SERVER_OPENING =
|
|
206
|
+
static readonly SERVER_OPENING = SERVER_OPENING;
|
|
212
207
|
/** @event */
|
|
213
|
-
static readonly SERVER_CLOSED =
|
|
208
|
+
static readonly SERVER_CLOSED = SERVER_CLOSED;
|
|
214
209
|
/** @event */
|
|
215
|
-
static readonly SERVER_DESCRIPTION_CHANGED =
|
|
210
|
+
static readonly SERVER_DESCRIPTION_CHANGED = SERVER_DESCRIPTION_CHANGED;
|
|
216
211
|
/** @event */
|
|
217
|
-
static readonly TOPOLOGY_OPENING =
|
|
212
|
+
static readonly TOPOLOGY_OPENING = TOPOLOGY_OPENING;
|
|
218
213
|
/** @event */
|
|
219
|
-
static readonly TOPOLOGY_CLOSED =
|
|
214
|
+
static readonly TOPOLOGY_CLOSED = TOPOLOGY_CLOSED;
|
|
220
215
|
/** @event */
|
|
221
|
-
static readonly TOPOLOGY_DESCRIPTION_CHANGED =
|
|
216
|
+
static readonly TOPOLOGY_DESCRIPTION_CHANGED = TOPOLOGY_DESCRIPTION_CHANGED;
|
|
222
217
|
/** @event */
|
|
223
|
-
static readonly ERROR =
|
|
218
|
+
static readonly ERROR = ERROR;
|
|
224
219
|
/** @event */
|
|
225
|
-
static readonly OPEN =
|
|
220
|
+
static readonly OPEN = OPEN;
|
|
226
221
|
/** @event */
|
|
227
|
-
static readonly CONNECT =
|
|
222
|
+
static readonly CONNECT = CONNECT;
|
|
228
223
|
/** @event */
|
|
229
|
-
static readonly CLOSE =
|
|
224
|
+
static readonly CLOSE = CLOSE;
|
|
230
225
|
/** @event */
|
|
231
|
-
static readonly TIMEOUT =
|
|
226
|
+
static readonly TIMEOUT = TIMEOUT;
|
|
232
227
|
|
|
233
228
|
/**
|
|
234
229
|
* @internal
|
|
@@ -827,19 +822,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
|
|
|
827
822
|
}
|
|
828
823
|
}
|
|
829
824
|
|
|
830
|
-
/** @public */
|
|
831
|
-
export const TOPOLOGY_EVENTS = [
|
|
832
|
-
Topology.SERVER_OPENING,
|
|
833
|
-
Topology.SERVER_CLOSED,
|
|
834
|
-
Topology.SERVER_DESCRIPTION_CHANGED,
|
|
835
|
-
Topology.TOPOLOGY_OPENING,
|
|
836
|
-
Topology.TOPOLOGY_CLOSED,
|
|
837
|
-
Topology.TOPOLOGY_DESCRIPTION_CHANGED,
|
|
838
|
-
Topology.ERROR,
|
|
839
|
-
Topology.TIMEOUT,
|
|
840
|
-
Topology.CLOSE
|
|
841
|
-
];
|
|
842
|
-
|
|
843
825
|
/** Destroys a server, and removes all event listeners from the instance */
|
|
844
826
|
function destroyServer(
|
|
845
827
|
server: Server,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Document, ObjectId } from '../bson';
|
|
2
2
|
import * as WIRE_CONSTANTS from '../cmap/wire_protocol/constants';
|
|
3
|
-
import { TopologyType, ServerType } from './common';
|
|
4
|
-
import type { ObjectId, Document } from '../bson';
|
|
5
|
-
import type { SrvPollingEvent } from './srv_polling';
|
|
6
3
|
import { MongoError, MongoRuntimeError } from '../error';
|
|
7
4
|
import { shuffle } from '../utils';
|
|
5
|
+
import { ServerType, TopologyType } from './common';
|
|
6
|
+
import { ServerDescription } from './server_description';
|
|
7
|
+
import type { SrvPollingEvent } from './srv_polling';
|
|
8
8
|
|
|
9
9
|
// constants related to compatibility checks
|
|
10
10
|
const MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION;
|
package/src/sessions.ts
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { isTransactionCommand, TxnState, Transaction, TransactionOptions } from './transactions';
|
|
5
|
-
import { _advanceClusterTime, ClusterTime, TopologyType } from './sdam/common';
|
|
1
|
+
import { Binary, Document, Long, Timestamp } from './bson';
|
|
2
|
+
import type { CommandOptions, Connection } from './cmap/connection';
|
|
3
|
+
import { ConnectionPoolMetrics } from './cmap/metrics';
|
|
6
4
|
import { isSharded } from './cmap/wire_protocol/shared';
|
|
5
|
+
import { PINNED, UNPINNED } from './constants';
|
|
6
|
+
import type { AbstractCursor } from './cursor/abstract_cursor';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
MongoInvalidArgumentError,
|
|
10
|
-
isRetryableError,
|
|
8
|
+
AnyError,
|
|
11
9
|
isRetryableEndTransactionError,
|
|
10
|
+
isRetryableError,
|
|
11
|
+
MongoAPIError,
|
|
12
12
|
MongoCompatibilityError,
|
|
13
|
-
MongoNetworkError,
|
|
14
|
-
MongoWriteConcernError,
|
|
15
13
|
MONGODB_ERROR_CODES,
|
|
16
|
-
MongoServerError,
|
|
17
14
|
MongoDriverError,
|
|
18
|
-
|
|
19
|
-
AnyError,
|
|
15
|
+
MongoError,
|
|
20
16
|
MongoExpiredSessionError,
|
|
17
|
+
MongoInvalidArgumentError,
|
|
18
|
+
MongoNetworkError,
|
|
19
|
+
MongoRuntimeError,
|
|
20
|
+
MongoServerError,
|
|
21
21
|
MongoTransactionError,
|
|
22
|
-
|
|
22
|
+
MongoWriteConcernError
|
|
23
23
|
} from './error';
|
|
24
|
+
import type { MongoOptions } from './mongo_client';
|
|
25
|
+
import { TypedEventEmitter } from './mongo_types';
|
|
26
|
+
import { executeOperation } from './operations/execute_operation';
|
|
27
|
+
import { RunAdminCommandOperation } from './operations/run_command';
|
|
28
|
+
import { PromiseProvider } from './promise_provider';
|
|
29
|
+
import { ReadConcernLevel } from './read_concern';
|
|
30
|
+
import { ReadPreference } from './read_preference';
|
|
31
|
+
import { _advanceClusterTime, ClusterTime, TopologyType } from './sdam/common';
|
|
32
|
+
import type { Topology } from './sdam/topology';
|
|
33
|
+
import { isTransactionCommand, Transaction, TransactionOptions, TxnState } from './transactions';
|
|
24
34
|
import {
|
|
25
|
-
now,
|
|
26
35
|
calculateDurationInMs,
|
|
27
36
|
Callback,
|
|
37
|
+
commandSupportsReadConcern,
|
|
28
38
|
isPromiseLike,
|
|
29
|
-
uuidV4,
|
|
30
39
|
maxWireVersion,
|
|
31
|
-
maybePromise
|
|
40
|
+
maybePromise,
|
|
41
|
+
now,
|
|
42
|
+
uuidV4
|
|
32
43
|
} from './utils';
|
|
33
|
-
import type { Topology } from './sdam/topology';
|
|
34
|
-
import type { MongoOptions } from './mongo_client';
|
|
35
|
-
import { executeOperation } from './operations/execute_operation';
|
|
36
|
-
import { RunAdminCommandOperation } from './operations/run_command';
|
|
37
|
-
import type { AbstractCursor } from './cursor/abstract_cursor';
|
|
38
|
-
import type { CommandOptions } from './cmap/connection';
|
|
39
|
-
import { Connection } from './cmap/connection';
|
|
40
|
-
import { ConnectionPoolMetrics } from './cmap/metrics';
|
|
41
44
|
import type { WriteConcern } from './write_concern';
|
|
42
|
-
import { TypedEventEmitter } from './mongo_types';
|
|
43
|
-
import { ReadConcernLevel } from './read_concern';
|
|
44
45
|
|
|
45
46
|
const minWireVersionForShardedTransactions = 8;
|
|
46
47
|
|
|
@@ -225,7 +226,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
225
226
|
|
|
226
227
|
this[kPinnedConnection] = conn;
|
|
227
228
|
conn.emit(
|
|
228
|
-
|
|
229
|
+
PINNED,
|
|
229
230
|
this.inTransaction() ? ConnectionPoolMetrics.TXN : ConnectionPoolMetrics.CURSOR
|
|
230
231
|
);
|
|
231
232
|
}
|
|
@@ -520,7 +521,7 @@ export function maybeClearPinnedConnection(
|
|
|
520
521
|
if (options?.error == null || options?.force) {
|
|
521
522
|
loadBalancer.s.pool.checkIn(conn);
|
|
522
523
|
conn.emit(
|
|
523
|
-
|
|
524
|
+
UNPINNED,
|
|
524
525
|
session.transaction.state !== TxnState.NO_TRANSACTION
|
|
525
526
|
? ConnectionPoolMetrics.TXN
|
|
526
527
|
: ConnectionPoolMetrics.CURSOR
|
|
@@ -929,25 +930,6 @@ export class ServerSessionPool {
|
|
|
929
930
|
}
|
|
930
931
|
}
|
|
931
932
|
|
|
932
|
-
// TODO: this should be codified in command construction
|
|
933
|
-
// @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#read-concern
|
|
934
|
-
export function commandSupportsReadConcern(command: Document, options?: Document): boolean {
|
|
935
|
-
if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
|
|
936
|
-
return true;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
if (
|
|
940
|
-
command.mapReduce &&
|
|
941
|
-
options &&
|
|
942
|
-
options.out &&
|
|
943
|
-
(options.out.inline === 1 || options.out === 'inline')
|
|
944
|
-
) {
|
|
945
|
-
return true;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
return false;
|
|
949
|
-
}
|
|
950
|
-
|
|
951
933
|
/**
|
|
952
934
|
* Optionally decorate a command with sessions specific keys
|
|
953
935
|
*
|
package/src/transactions.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Document } from './bson';
|
|
2
2
|
import { MongoRuntimeError, MongoTransactionError } from './error';
|
|
3
|
+
import type { CommandOperationOptions } from './operations/command';
|
|
3
4
|
import { ReadConcern, ReadConcernLike } from './read_concern';
|
|
4
|
-
import {
|
|
5
|
+
import { ReadPreference } from './read_preference';
|
|
5
6
|
import type { Server } from './sdam/server';
|
|
6
|
-
import
|
|
7
|
-
import type { Document } from './bson';
|
|
7
|
+
import { WriteConcern } from './write_concern';
|
|
8
8
|
|
|
9
9
|
/** @internal */
|
|
10
10
|
export const TxnState = Object.freeze({
|
package/src/utils.ts
CHANGED
|
@@ -1,34 +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 {
|
|
31
|
-
import type {
|
|
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';
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* MongoDB Driver style callback
|
|
@@ -1096,6 +1098,14 @@ export function isSuperset(set: Set<any> | any[], subset: Set<any> | any[]): boo
|
|
|
1096
1098
|
return true;
|
|
1097
1099
|
}
|
|
1098
1100
|
|
|
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
|
+
|
|
1099
1109
|
/** Returns the items that are uniquely in setA */
|
|
1100
1110
|
export function setDifference<T>(setA: Iterable<T>, setB: Iterable<T>): Set<T> {
|
|
1101
1111
|
const difference = new Set<T>(setA);
|
|
@@ -1346,8 +1356,15 @@ export class HostAddress {
|
|
|
1346
1356
|
return new HostAddress(s);
|
|
1347
1357
|
}
|
|
1348
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
|
+
|
|
1349
1366
|
static fromSrvRecord({ name, port }: SrvRecord): HostAddress {
|
|
1350
|
-
return HostAddress.
|
|
1367
|
+
return HostAddress.fromHostPort(name, port);
|
|
1351
1368
|
}
|
|
1352
1369
|
}
|
|
1353
1370
|
|
|
@@ -1449,3 +1466,22 @@ export function shuffle<T>(sequence: Iterable<T>, limit = 0): Array<T> {
|
|
|
1449
1466
|
|
|
1450
1467
|
return limit % items.length === 0 ? items : items.slice(lowerBound);
|
|
1451
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
|
-
]);
|