mongodb 4.2.1 → 4.4.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 +2 -2
- 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 +7 -7
- 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 +52 -10
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +36 -27
- 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 +3 -2
- 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 +119 -37
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +36 -35
- 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 +2 -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 +46 -47
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +93 -54
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +113 -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 +2 -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 +83 -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 +3 -3
- 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 +15 -5
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/events.js +4 -4
- package/lib/sdam/monitor.js +19 -18
- 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 +38 -38
- 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 +32 -62
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +3 -3
- 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 +46 -15
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +205 -60
- package/mongodb.ts34.d.ts +230 -59
- package/package.json +40 -37
- package/src/admin.ts +9 -9
- package/src/bson.ts +25 -17
- package/src/bulk/common.ts +22 -23
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +29 -28
- package/src/cmap/auth/auth_provider.ts +3 -3
- package/src/cmap/auth/gssapi.ts +65 -14
- package/src/cmap/auth/mongo_credentials.ts +28 -17
- 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 +4 -3
- package/src/cmap/commands.ts +22 -14
- package/src/cmap/connect.ts +161 -45
- package/src/cmap/connection.ts +83 -63
- 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 +4 -3
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +116 -93
- package/src/connection_string.ts +130 -59
- package/src/constants.ts +122 -0
- package/src/cursor/abstract_cursor.ts +14 -13
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +12 -4
- package/src/db.ts +44 -33
- package/src/deps.ts +44 -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 +205 -199
- package/src/logger.ts +2 -1
- package/src/mongo_client.ts +46 -32
- package/src/mongo_types.ts +119 -21
- package/src/operations/add_user.ts +7 -6
- 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 +18 -7
- package/src/sdam/common.ts +2 -2
- package/src/sdam/events.ts +5 -5
- package/src/sdam/monitor.ts +29 -32
- package/src/sdam/server.ts +64 -62
- package/src/sdam/server_description.ts +41 -48
- package/src/sdam/server_selection.ts +3 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +71 -89
- package/src/sdam/topology_description.ts +5 -5
- package/src/sessions.ts +31 -48
- package/src/transactions.ts +4 -4
- package/src/utils.ts +64 -28
- 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/cmap/connection.ts
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StreamDescription, StreamDescriptionOptions } from './stream_description';
|
|
3
|
-
import {
|
|
4
|
-
CommandStartedEvent,
|
|
5
|
-
CommandFailedEvent,
|
|
6
|
-
CommandSucceededEvent
|
|
7
|
-
} from './command_monitoring_events';
|
|
8
|
-
import { applySession, ClientSession, updateSessionFromResponse } from '../sessions';
|
|
1
|
+
import { BSONSerializeOptions, Document, Long, ObjectId, pluckBSONSerializeOptions } from '../bson';
|
|
9
2
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from '../
|
|
3
|
+
CLOSE,
|
|
4
|
+
CLUSTER_TIME_RECEIVED,
|
|
5
|
+
COMMAND_FAILED,
|
|
6
|
+
COMMAND_STARTED,
|
|
7
|
+
COMMAND_SUCCEEDED,
|
|
8
|
+
MESSAGE,
|
|
9
|
+
PINNED,
|
|
10
|
+
UNPINNED
|
|
11
|
+
} from '../constants';
|
|
12
|
+
import type { AutoEncrypter } from '../deps';
|
|
19
13
|
import {
|
|
20
|
-
MongoRuntimeError,
|
|
21
|
-
MongoMissingDependencyError,
|
|
22
14
|
MongoCompatibilityError,
|
|
15
|
+
MongoMissingDependencyError,
|
|
23
16
|
MongoNetworkError,
|
|
24
17
|
MongoNetworkTimeoutError,
|
|
18
|
+
MongoRuntimeError,
|
|
25
19
|
MongoServerError,
|
|
26
20
|
MongoWriteConcernError
|
|
27
21
|
} from '../error';
|
|
22
|
+
import type { ServerApi, SupportedNodeConnectionOptions } from '../mongo_client';
|
|
23
|
+
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
24
|
+
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
|
|
25
|
+
import { applySession, ClientSession, updateSessionFromResponse } from '../sessions';
|
|
26
|
+
import {
|
|
27
|
+
calculateDurationInMs,
|
|
28
|
+
Callback,
|
|
29
|
+
ClientMetadata,
|
|
30
|
+
HostAddress,
|
|
31
|
+
maxWireVersion,
|
|
32
|
+
MongoDBNamespace,
|
|
33
|
+
now,
|
|
34
|
+
uuidV4
|
|
35
|
+
} from '../utils';
|
|
36
|
+
import type { W, WriteConcern, WriteConcernOptions } from '../write_concern';
|
|
37
|
+
import type { MongoCredentials } from './auth/mongo_credentials';
|
|
38
|
+
import {
|
|
39
|
+
CommandFailedEvent,
|
|
40
|
+
CommandStartedEvent,
|
|
41
|
+
CommandSucceededEvent
|
|
42
|
+
} from './command_monitoring_events';
|
|
28
43
|
import {
|
|
29
44
|
BinMsg,
|
|
30
|
-
WriteProtocolMessageType,
|
|
31
|
-
Response,
|
|
32
|
-
KillCursor,
|
|
33
45
|
GetMore,
|
|
34
|
-
|
|
46
|
+
KillCursor,
|
|
47
|
+
Msg,
|
|
35
48
|
OpQueryOptions,
|
|
36
|
-
|
|
49
|
+
Query,
|
|
50
|
+
Response,
|
|
51
|
+
WriteProtocolMessageType
|
|
37
52
|
} from './commands';
|
|
38
|
-
import { BSONSerializeOptions, Document, Long, pluckBSONSerializeOptions, ObjectId } from '../bson';
|
|
39
|
-
import type { AutoEncrypter } from '../deps';
|
|
40
|
-
import type { MongoCredentials } from './auth/mongo_credentials';
|
|
41
53
|
import type { Stream } from './connect';
|
|
54
|
+
import { MessageStream, OperationDescription } from './message_stream';
|
|
55
|
+
import { StreamDescription, StreamDescriptionOptions } from './stream_description';
|
|
42
56
|
import { applyCommonQueryOptions, getReadPreference, isSharded } from './wire_protocol/shared';
|
|
43
|
-
import { ReadPreference, ReadPreferenceLike } from '../read_preference';
|
|
44
|
-
import type { W, WriteConcern, WriteConcernOptions } from '../write_concern';
|
|
45
|
-
import type { ServerApi, SupportedNodeConnectionOptions } from '../mongo_client';
|
|
46
|
-
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
47
57
|
|
|
48
58
|
/** @internal */
|
|
49
59
|
const kStream = Symbol('stream');
|
|
@@ -60,7 +70,7 @@ const kClusterTime = Symbol('clusterTime');
|
|
|
60
70
|
/** @internal */
|
|
61
71
|
const kDescription = Symbol('description');
|
|
62
72
|
/** @internal */
|
|
63
|
-
const
|
|
73
|
+
const kHello = Symbol('hello');
|
|
64
74
|
/** @internal */
|
|
65
75
|
const kAutoEncrypter = Symbol('autoEncrypter');
|
|
66
76
|
/** @internal */
|
|
@@ -86,7 +96,7 @@ export interface QueryOptions extends BSONSerializeOptions {
|
|
|
86
96
|
/** @internal */
|
|
87
97
|
export interface CommandOptions extends BSONSerializeOptions {
|
|
88
98
|
command?: boolean;
|
|
89
|
-
|
|
99
|
+
secondaryOk?: boolean;
|
|
90
100
|
/** Specify read preference if command supports it */
|
|
91
101
|
readPreference?: ReadPreferenceLike;
|
|
92
102
|
raw?: boolean;
|
|
@@ -114,10 +124,19 @@ export interface GetMoreOptions extends CommandOptions {
|
|
|
114
124
|
comment?: Document | string;
|
|
115
125
|
}
|
|
116
126
|
|
|
127
|
+
/** @public */
|
|
128
|
+
export interface ProxyOptions {
|
|
129
|
+
proxyHost?: string;
|
|
130
|
+
proxyPort?: number;
|
|
131
|
+
proxyUsername?: string;
|
|
132
|
+
proxyPassword?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
117
135
|
/** @public */
|
|
118
136
|
export interface ConnectionOptions
|
|
119
137
|
extends SupportedNodeConnectionOptions,
|
|
120
|
-
StreamDescriptionOptions
|
|
138
|
+
StreamDescriptionOptions,
|
|
139
|
+
ProxyOptions {
|
|
121
140
|
// Internal creation info
|
|
122
141
|
id: number | '<monitor>';
|
|
123
142
|
generation: number;
|
|
@@ -166,7 +185,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
166
185
|
monitorCommands: boolean;
|
|
167
186
|
closed: boolean;
|
|
168
187
|
destroyed: boolean;
|
|
169
|
-
|
|
188
|
+
lastHelloMS?: number;
|
|
170
189
|
serverApi?: ServerApi;
|
|
171
190
|
helloOk?: boolean;
|
|
172
191
|
/** @internal */
|
|
@@ -182,31 +201,31 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
182
201
|
/** @internal */
|
|
183
202
|
[kStream]: Stream;
|
|
184
203
|
/** @internal */
|
|
185
|
-
[
|
|
204
|
+
[kHello]: Document;
|
|
186
205
|
/** @internal */
|
|
187
206
|
[kClusterTime]: Document;
|
|
188
207
|
|
|
189
208
|
/** @event */
|
|
190
|
-
static readonly COMMAND_STARTED =
|
|
209
|
+
static readonly COMMAND_STARTED = COMMAND_STARTED;
|
|
191
210
|
/** @event */
|
|
192
|
-
static readonly COMMAND_SUCCEEDED =
|
|
211
|
+
static readonly COMMAND_SUCCEEDED = COMMAND_SUCCEEDED;
|
|
193
212
|
/** @event */
|
|
194
|
-
static readonly COMMAND_FAILED =
|
|
213
|
+
static readonly COMMAND_FAILED = COMMAND_FAILED;
|
|
195
214
|
/** @event */
|
|
196
|
-
static readonly CLUSTER_TIME_RECEIVED =
|
|
215
|
+
static readonly CLUSTER_TIME_RECEIVED = CLUSTER_TIME_RECEIVED;
|
|
197
216
|
/** @event */
|
|
198
|
-
static readonly CLOSE =
|
|
217
|
+
static readonly CLOSE = CLOSE;
|
|
199
218
|
/** @event */
|
|
200
|
-
static readonly MESSAGE =
|
|
219
|
+
static readonly MESSAGE = MESSAGE;
|
|
201
220
|
/** @event */
|
|
202
|
-
static readonly PINNED =
|
|
221
|
+
static readonly PINNED = PINNED;
|
|
203
222
|
/** @event */
|
|
204
|
-
static readonly UNPINNED =
|
|
223
|
+
static readonly UNPINNED = UNPINNED;
|
|
205
224
|
|
|
206
225
|
constructor(stream: Stream, options: ConnectionOptions) {
|
|
207
226
|
super();
|
|
208
227
|
this.id = options.id;
|
|
209
|
-
this.address = streamIdentifier(stream);
|
|
228
|
+
this.address = streamIdentifier(stream, options);
|
|
210
229
|
this.socketTimeoutMS = options.socketTimeoutMS ?? 0;
|
|
211
230
|
this.monitorCommands = options.monitorCommands;
|
|
212
231
|
this.serverApi = options.serverApi;
|
|
@@ -221,7 +240,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
221
240
|
this[kQueue] = new Map();
|
|
222
241
|
this[kMessageStream] = new MessageStream({
|
|
223
242
|
...options,
|
|
224
|
-
maxBsonMessageSize: this.
|
|
243
|
+
maxBsonMessageSize: this.hello?.maxBsonMessageSize
|
|
225
244
|
});
|
|
226
245
|
this[kMessageStream].on('message', messageHandler(this));
|
|
227
246
|
this[kStream] = stream;
|
|
@@ -242,21 +261,21 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
242
261
|
return this[kDescription];
|
|
243
262
|
}
|
|
244
263
|
|
|
245
|
-
get
|
|
246
|
-
return this[
|
|
264
|
+
get hello(): Document {
|
|
265
|
+
return this[kHello];
|
|
247
266
|
}
|
|
248
267
|
|
|
249
|
-
// the `connect` method stores the result of the handshake
|
|
250
|
-
set
|
|
268
|
+
// the `connect` method stores the result of the handshake hello on the connection
|
|
269
|
+
set hello(response: Document) {
|
|
251
270
|
this[kDescription].receiveResponse(response);
|
|
252
271
|
this[kDescription] = Object.freeze(this[kDescription]);
|
|
253
272
|
|
|
254
273
|
// TODO: remove this, and only use the `StreamDescription` in the future
|
|
255
|
-
this[
|
|
274
|
+
this[kHello] = response;
|
|
256
275
|
}
|
|
257
276
|
|
|
258
277
|
get serviceId(): ObjectId | undefined {
|
|
259
|
-
return this.
|
|
278
|
+
return this.hello?.serviceId;
|
|
260
279
|
}
|
|
261
280
|
|
|
262
281
|
get loadBalanced(): boolean {
|
|
@@ -302,7 +321,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
302
321
|
if (issue.isTimeout) {
|
|
303
322
|
op.cb(
|
|
304
323
|
new MongoNetworkTimeoutError(`connection ${this.id} to ${this.address} timed out`, {
|
|
305
|
-
beforeHandshake: this.
|
|
324
|
+
beforeHandshake: this.hello == null
|
|
306
325
|
})
|
|
307
326
|
);
|
|
308
327
|
} else if (issue.isClose) {
|
|
@@ -417,7 +436,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
417
436
|
numberToReturn: -1,
|
|
418
437
|
checkKeys: false,
|
|
419
438
|
// This value is not overridable
|
|
420
|
-
|
|
439
|
+
secondaryOk: readPreference.secondaryOk()
|
|
421
440
|
},
|
|
422
441
|
options
|
|
423
442
|
);
|
|
@@ -462,7 +481,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
462
481
|
numberToReturn,
|
|
463
482
|
pre32Limit: typeof limit === 'number' ? limit : undefined,
|
|
464
483
|
checkKeys: false,
|
|
465
|
-
|
|
484
|
+
secondaryOk: readPreference.secondaryOk()
|
|
466
485
|
};
|
|
467
486
|
|
|
468
487
|
if (options.projection) {
|
|
@@ -616,13 +635,6 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
616
635
|
}
|
|
617
636
|
}
|
|
618
637
|
|
|
619
|
-
/** @public */
|
|
620
|
-
export const APM_EVENTS = [
|
|
621
|
-
Connection.COMMAND_STARTED,
|
|
622
|
-
Connection.COMMAND_SUCCEEDED,
|
|
623
|
-
Connection.COMMAND_FAILED
|
|
624
|
-
];
|
|
625
|
-
|
|
626
638
|
/** @internal */
|
|
627
639
|
export class CryptoConnection extends Connection {
|
|
628
640
|
/** @internal */
|
|
@@ -754,7 +766,13 @@ function messageHandler(conn: Connection) {
|
|
|
754
766
|
};
|
|
755
767
|
}
|
|
756
768
|
|
|
757
|
-
function streamIdentifier(stream: Stream) {
|
|
769
|
+
function streamIdentifier(stream: Stream, options: ConnectionOptions): string {
|
|
770
|
+
if (options.proxyHost) {
|
|
771
|
+
// If proxy options are specified, the properties of `stream` itself
|
|
772
|
+
// will not accurately reflect what endpoint this is connected to.
|
|
773
|
+
return options.hostAddress.toString();
|
|
774
|
+
}
|
|
775
|
+
|
|
758
776
|
if (typeof stream.address === 'function') {
|
|
759
777
|
return `${stream.remoteAddress}:${stream.remotePort}`;
|
|
760
778
|
}
|
|
@@ -787,6 +805,8 @@ function write(
|
|
|
787
805
|
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
|
|
788
806
|
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
|
|
789
807
|
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
|
|
808
|
+
enableUtf8Validation:
|
|
809
|
+
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true,
|
|
790
810
|
raw: typeof options.raw === 'boolean' ? options.raw : false,
|
|
791
811
|
started: 0
|
|
792
812
|
};
|
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
import Denque = require('denque');
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import type { ObjectId } from '../bson';
|
|
3
|
+
import {
|
|
4
|
+
APM_EVENTS,
|
|
5
|
+
CONNECTION_CHECK_OUT_FAILED,
|
|
6
|
+
CONNECTION_CHECK_OUT_STARTED,
|
|
7
|
+
CONNECTION_CHECKED_IN,
|
|
8
|
+
CONNECTION_CHECKED_OUT,
|
|
9
|
+
CONNECTION_CLOSED,
|
|
10
|
+
CONNECTION_CREATED,
|
|
11
|
+
CONNECTION_POOL_CLEARED,
|
|
12
|
+
CONNECTION_POOL_CLOSED,
|
|
13
|
+
CONNECTION_POOL_CREATED,
|
|
14
|
+
CONNECTION_READY
|
|
15
|
+
} from '../constants';
|
|
16
|
+
import { MongoError, MongoInvalidArgumentError, MongoRuntimeError } from '../error';
|
|
4
17
|
import { Logger } from '../logger';
|
|
5
|
-
import {
|
|
18
|
+
import { CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
19
|
+
import { Callback, eachAsync, makeCounter } from '../utils';
|
|
6
20
|
import { connect } from './connect';
|
|
7
|
-
import {
|
|
8
|
-
import { MongoError, MongoInvalidArgumentError, MongoRuntimeError } from '../error';
|
|
9
|
-
import { PoolClosedError, WaitQueueTimeoutError } from './errors';
|
|
21
|
+
import { Connection, ConnectionEvents, ConnectionOptions } from './connection';
|
|
10
22
|
import {
|
|
11
|
-
ConnectionPoolCreatedEvent,
|
|
12
|
-
ConnectionPoolClosedEvent,
|
|
13
|
-
ConnectionCreatedEvent,
|
|
14
|
-
ConnectionReadyEvent,
|
|
15
|
-
ConnectionClosedEvent,
|
|
16
|
-
ConnectionCheckOutStartedEvent,
|
|
17
|
-
ConnectionCheckOutFailedEvent,
|
|
18
|
-
ConnectionCheckedOutEvent,
|
|
19
23
|
ConnectionCheckedInEvent,
|
|
20
|
-
|
|
24
|
+
ConnectionCheckedOutEvent,
|
|
25
|
+
ConnectionCheckOutFailedEvent,
|
|
26
|
+
ConnectionCheckOutStartedEvent,
|
|
27
|
+
ConnectionClosedEvent,
|
|
28
|
+
ConnectionCreatedEvent,
|
|
29
|
+
ConnectionPoolClearedEvent,
|
|
30
|
+
ConnectionPoolClosedEvent,
|
|
31
|
+
ConnectionPoolCreatedEvent,
|
|
32
|
+
ConnectionReadyEvent
|
|
21
33
|
} from './connection_pool_events';
|
|
22
|
-
import {
|
|
34
|
+
import { PoolClosedError, WaitQueueTimeoutError } from './errors';
|
|
35
|
+
import { ConnectionPoolMetrics } from './metrics';
|
|
23
36
|
|
|
24
37
|
/** @internal */
|
|
25
38
|
const kLogger = Symbol('logger');
|
|
@@ -132,52 +145,52 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
|
|
|
132
145
|
* Emitted when the connection pool is created.
|
|
133
146
|
* @event
|
|
134
147
|
*/
|
|
135
|
-
static readonly CONNECTION_POOL_CREATED =
|
|
148
|
+
static readonly CONNECTION_POOL_CREATED = CONNECTION_POOL_CREATED;
|
|
136
149
|
/**
|
|
137
150
|
* Emitted once when the connection pool is closed
|
|
138
151
|
* @event
|
|
139
152
|
*/
|
|
140
|
-
static readonly CONNECTION_POOL_CLOSED =
|
|
153
|
+
static readonly CONNECTION_POOL_CLOSED = CONNECTION_POOL_CLOSED;
|
|
141
154
|
/**
|
|
142
155
|
* Emitted each time the connection pool is cleared and it's generation incremented
|
|
143
156
|
* @event
|
|
144
157
|
*/
|
|
145
|
-
static readonly CONNECTION_POOL_CLEARED =
|
|
158
|
+
static readonly CONNECTION_POOL_CLEARED = CONNECTION_POOL_CLEARED;
|
|
146
159
|
/**
|
|
147
160
|
* Emitted when a connection is created.
|
|
148
161
|
* @event
|
|
149
162
|
*/
|
|
150
|
-
static readonly CONNECTION_CREATED =
|
|
163
|
+
static readonly CONNECTION_CREATED = CONNECTION_CREATED;
|
|
151
164
|
/**
|
|
152
165
|
* Emitted when a connection becomes established, and is ready to use
|
|
153
166
|
* @event
|
|
154
167
|
*/
|
|
155
|
-
static readonly CONNECTION_READY =
|
|
168
|
+
static readonly CONNECTION_READY = CONNECTION_READY;
|
|
156
169
|
/**
|
|
157
170
|
* Emitted when a connection is closed
|
|
158
171
|
* @event
|
|
159
172
|
*/
|
|
160
|
-
static readonly CONNECTION_CLOSED =
|
|
173
|
+
static readonly CONNECTION_CLOSED = CONNECTION_CLOSED;
|
|
161
174
|
/**
|
|
162
175
|
* Emitted when an attempt to check out a connection begins
|
|
163
176
|
* @event
|
|
164
177
|
*/
|
|
165
|
-
static readonly CONNECTION_CHECK_OUT_STARTED =
|
|
178
|
+
static readonly CONNECTION_CHECK_OUT_STARTED = CONNECTION_CHECK_OUT_STARTED;
|
|
166
179
|
/**
|
|
167
180
|
* Emitted when an attempt to check out a connection fails
|
|
168
181
|
* @event
|
|
169
182
|
*/
|
|
170
|
-
static readonly CONNECTION_CHECK_OUT_FAILED =
|
|
183
|
+
static readonly CONNECTION_CHECK_OUT_FAILED = CONNECTION_CHECK_OUT_FAILED;
|
|
171
184
|
/**
|
|
172
185
|
* Emitted each time a connection is successfully checked out of the connection pool
|
|
173
186
|
* @event
|
|
174
187
|
*/
|
|
175
|
-
static readonly CONNECTION_CHECKED_OUT =
|
|
188
|
+
static readonly CONNECTION_CHECKED_OUT = CONNECTION_CHECKED_OUT;
|
|
176
189
|
/**
|
|
177
190
|
* Emitted each time a connection is successfully checked into the connection pool
|
|
178
191
|
* @event
|
|
179
192
|
*/
|
|
180
|
-
static readonly CONNECTION_CHECKED_IN =
|
|
193
|
+
static readonly CONNECTION_CHECKED_IN = CONNECTION_CHECKED_IN;
|
|
181
194
|
|
|
182
195
|
/** @internal */
|
|
183
196
|
constructor(options: ConnectionPoolOptions) {
|
|
@@ -664,19 +677,6 @@ function processWaitQueue(pool: ConnectionPool) {
|
|
|
664
677
|
}
|
|
665
678
|
}
|
|
666
679
|
|
|
667
|
-
export const CMAP_EVENTS = [
|
|
668
|
-
ConnectionPool.CONNECTION_POOL_CREATED,
|
|
669
|
-
ConnectionPool.CONNECTION_POOL_CLOSED,
|
|
670
|
-
ConnectionPool.CONNECTION_CREATED,
|
|
671
|
-
ConnectionPool.CONNECTION_READY,
|
|
672
|
-
ConnectionPool.CONNECTION_CLOSED,
|
|
673
|
-
ConnectionPool.CONNECTION_CHECK_OUT_STARTED,
|
|
674
|
-
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
|
|
675
|
-
ConnectionPool.CONNECTION_CHECKED_OUT,
|
|
676
|
-
ConnectionPool.CONNECTION_CHECKED_IN,
|
|
677
|
-
ConnectionPool.CONNECTION_POOL_CLEARED
|
|
678
|
-
] as const;
|
|
679
|
-
|
|
680
680
|
/**
|
|
681
681
|
* A callback provided to `withConnection`
|
|
682
682
|
* @internal
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ObjectId } from '../bson';
|
|
2
|
+
import type { AnyError } from '../error';
|
|
2
3
|
import type { Connection } from './connection';
|
|
3
4
|
import type { ConnectionPool, ConnectionPoolOptions } from './connection_pool';
|
|
4
|
-
import type { AnyError } from '../error';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The base export class for all monitoring events published from the connection pool
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { Duplex, DuplexOptions } from 'stream';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import type { BSONSerializeOptions, Document } from '../bson';
|
|
3
4
|
import { MongoDecompressionError, MongoParseError } from '../error';
|
|
4
|
-
import {
|
|
5
|
+
import type { ClientSession } from '../sessions';
|
|
6
|
+
import { BufferPool, Callback } from '../utils';
|
|
7
|
+
import { BinMsg, MessageHeader, Msg, Query, Response, WriteProtocolMessageType } from './commands';
|
|
5
8
|
import {
|
|
6
9
|
compress,
|
|
7
|
-
decompress,
|
|
8
|
-
uncompressibleCommands,
|
|
9
10
|
Compressor,
|
|
10
|
-
CompressorName
|
|
11
|
+
CompressorName,
|
|
12
|
+
decompress,
|
|
13
|
+
uncompressibleCommands
|
|
11
14
|
} from './wire_protocol/compression';
|
|
12
|
-
import
|
|
13
|
-
import { BufferPool, Callback } from '../utils';
|
|
14
|
-
import type { ClientSession } from '../sessions';
|
|
15
|
+
import { OP_COMPRESSED, OP_MSG } from './wire_protocol/constants';
|
|
15
16
|
|
|
16
17
|
const MESSAGE_HEADER_SIZE = 16;
|
|
17
18
|
const COMPRESSION_DETAILS_SIZE = 9; // originalOpcode + uncompressedSize, compressorID
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { parseServerType } from '../sdam/server_description';
|
|
2
1
|
import type { Document } from '../bson';
|
|
3
|
-
import type { CompressorName } from './wire_protocol/compression';
|
|
4
2
|
import { ServerType } from '../sdam/common';
|
|
3
|
+
import { parseServerType } from '../sdam/server_description';
|
|
4
|
+
import type { CompressorName } from './wire_protocol/compression';
|
|
5
5
|
|
|
6
6
|
const RESPONSE_FIELDS = [
|
|
7
7
|
'minWireVersion',
|
|
@@ -55,8 +55,8 @@ export class StreamDescription {
|
|
|
55
55
|
|
|
56
56
|
receiveResponse(response: Document): void {
|
|
57
57
|
this.type = parseServerType(response);
|
|
58
|
-
|
|
59
|
-
if (
|
|
58
|
+
for (const field of RESPONSE_FIELDS) {
|
|
59
|
+
if (response[field] != null) {
|
|
60
60
|
this[field] = response[field];
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ export class StreamDescription {
|
|
|
64
64
|
if ('__nodejs_mock_server__' in response) {
|
|
65
65
|
this.__nodejs_mock_server__ = response['__nodejs_mock_server__'];
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|
|
68
68
|
|
|
69
69
|
if (response.compression) {
|
|
70
70
|
this.compressor = this.compressors.filter(c => response.compression?.includes(c))[0];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as zlib from 'zlib';
|
|
2
|
-
import type { Callback } from '../../utils';
|
|
3
|
-
import type { OperationDescription } from '../message_stream';
|
|
4
2
|
|
|
3
|
+
import { LEGACY_HELLO_COMMAND } from '../../constants';
|
|
5
4
|
import { PKG_VERSION, Snappy } from '../../deps';
|
|
6
5
|
import { MongoDecompressionError, MongoInvalidArgumentError } from '../../error';
|
|
6
|
+
import type { Callback } from '../../utils';
|
|
7
|
+
import type { OperationDescription } from '../message_stream';
|
|
7
8
|
|
|
8
9
|
/** @public */
|
|
9
10
|
export const Compressor = Object.freeze({
|
|
@@ -19,7 +20,7 @@ export type Compressor = typeof Compressor[CompressorName];
|
|
|
19
20
|
export type CompressorName = keyof typeof Compressor;
|
|
20
21
|
|
|
21
22
|
export const uncompressibleCommands = new Set([
|
|
22
|
-
|
|
23
|
+
LEGACY_HELLO_COMMAND,
|
|
23
24
|
'saslStart',
|
|
24
25
|
'saslContinue',
|
|
25
26
|
'getnonce',
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TopologyDescription } from '../../sdam/topology_description';
|
|
1
|
+
import type { Document } from '../../bson';
|
|
3
2
|
import { MongoInvalidArgumentError } from '../../error';
|
|
3
|
+
import type { ReadPreferenceLike } from '../../read_preference';
|
|
4
4
|
import { ReadPreference } from '../../read_preference';
|
|
5
|
-
import
|
|
6
|
-
import type { OpQueryOptions } from '../commands';
|
|
7
|
-
import type { Topology } from '../../sdam/topology';
|
|
5
|
+
import { ServerType } from '../../sdam/common';
|
|
8
6
|
import type { Server } from '../../sdam/server';
|
|
9
7
|
import type { ServerDescription } from '../../sdam/server_description';
|
|
10
|
-
import type {
|
|
11
|
-
import
|
|
12
|
-
import type {
|
|
8
|
+
import type { Topology } from '../../sdam/topology';
|
|
9
|
+
import { TopologyDescription } from '../../sdam/topology_description';
|
|
10
|
+
import type { OpQueryOptions } from '../commands';
|
|
11
|
+
import type { CommandOptions, Connection } from '../connection';
|
|
13
12
|
|
|
14
13
|
export interface ReadPreferenceOption {
|
|
15
14
|
readPreference?: ReadPreferenceLike;
|
|
@@ -45,7 +44,9 @@ export function applyCommonQueryOptions(
|
|
|
45
44
|
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
|
|
46
45
|
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
|
|
47
46
|
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
|
|
48
|
-
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false
|
|
47
|
+
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
|
|
48
|
+
enableUtf8Validation:
|
|
49
|
+
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
if (options.session) {
|