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.
Files changed (266) hide show
  1. package/README.md +2 -2
  2. package/lib/admin.js +3 -3
  3. package/lib/admin.js.map +1 -1
  4. package/lib/bson.js +16 -14
  5. package/lib/bson.js.map +1 -1
  6. package/lib/bulk/common.js +7 -7
  7. package/lib/bulk/common.js.map +1 -1
  8. package/lib/bulk/ordered.js +1 -1
  9. package/lib/bulk/ordered.js.map +1 -1
  10. package/lib/bulk/unordered.js +1 -1
  11. package/lib/bulk/unordered.js.map +1 -1
  12. package/lib/change_stream.js +6 -6
  13. package/lib/change_stream.js.map +1 -1
  14. package/lib/cmap/auth/auth_provider.js.map +1 -1
  15. package/lib/cmap/auth/gssapi.js +52 -10
  16. package/lib/cmap/auth/gssapi.js.map +1 -1
  17. package/lib/cmap/auth/mongo_credentials.js +36 -27
  18. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  19. package/lib/cmap/auth/mongocr.js +2 -2
  20. package/lib/cmap/auth/mongocr.js.map +1 -1
  21. package/lib/cmap/auth/mongodb_aws.js +6 -6
  22. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  23. package/lib/cmap/auth/plain.js +1 -1
  24. package/lib/cmap/auth/plain.js.map +1 -1
  25. package/lib/cmap/auth/providers.js +21 -0
  26. package/lib/cmap/auth/providers.js.map +1 -0
  27. package/lib/cmap/auth/scram.js +4 -4
  28. package/lib/cmap/auth/scram.js.map +1 -1
  29. package/lib/cmap/auth/x509.js +1 -1
  30. package/lib/cmap/auth/x509.js.map +1 -1
  31. package/lib/cmap/command_monitoring_events.js +3 -2
  32. package/lib/cmap/command_monitoring_events.js.map +1 -1
  33. package/lib/cmap/commands.js +14 -8
  34. package/lib/cmap/commands.js.map +1 -1
  35. package/lib/cmap/connect.js +119 -37
  36. package/lib/cmap/connect.js.map +1 -1
  37. package/lib/cmap/connection.js +36 -35
  38. package/lib/cmap/connection.js.map +1 -1
  39. package/lib/cmap/connection_pool.js +19 -30
  40. package/lib/cmap/connection_pool.js.map +1 -1
  41. package/lib/cmap/message_stream.js +3 -3
  42. package/lib/cmap/message_stream.js.map +1 -1
  43. package/lib/cmap/stream_description.js +4 -4
  44. package/lib/cmap/stream_description.js.map +1 -1
  45. package/lib/cmap/wire_protocol/compression.js +2 -1
  46. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  47. package/lib/cmap/wire_protocol/shared.js +4 -3
  48. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  49. package/lib/collection.js +46 -47
  50. package/lib/collection.js.map +1 -1
  51. package/lib/connection_string.js +93 -54
  52. package/lib/connection_string.js.map +1 -1
  53. package/lib/constants.js +113 -1
  54. package/lib/constants.js.map +1 -1
  55. package/lib/cursor/abstract_cursor.js +5 -5
  56. package/lib/cursor/abstract_cursor.js.map +1 -1
  57. package/lib/cursor/aggregation_cursor.js +1 -1
  58. package/lib/cursor/aggregation_cursor.js.map +1 -1
  59. package/lib/cursor/find_cursor.js +2 -1
  60. package/lib/cursor/find_cursor.js.map +1 -1
  61. package/lib/db.js +23 -13
  62. package/lib/db.js.map +1 -1
  63. package/lib/deps.js +0 -1
  64. package/lib/deps.js.map +1 -1
  65. package/lib/encrypter.js +12 -4
  66. package/lib/encrypter.js.map +1 -1
  67. package/lib/error.js +47 -24
  68. package/lib/error.js.map +1 -1
  69. package/lib/gridfs/download.js +1 -1
  70. package/lib/gridfs/download.js.map +1 -1
  71. package/lib/gridfs/index.js +3 -3
  72. package/lib/gridfs/index.js.map +1 -1
  73. package/lib/gridfs/upload.js +3 -2
  74. package/lib/gridfs/upload.js.map +1 -1
  75. package/lib/index.js +83 -81
  76. package/lib/index.js.map +1 -1
  77. package/lib/logger.js +1 -1
  78. package/lib/logger.js.map +1 -1
  79. package/lib/mongo_client.js +5 -5
  80. package/lib/mongo_client.js.map +1 -1
  81. package/lib/mongo_types.js.map +1 -1
  82. package/lib/operations/add_user.js +3 -3
  83. package/lib/operations/add_user.js.map +1 -1
  84. package/lib/operations/aggregate.js +1 -1
  85. package/lib/operations/aggregate.js.map +1 -1
  86. package/lib/operations/bulk_write.js.map +1 -1
  87. package/lib/operations/collections.js +1 -1
  88. package/lib/operations/collections.js.map +1 -1
  89. package/lib/operations/command.js +5 -6
  90. package/lib/operations/command.js.map +1 -1
  91. package/lib/operations/common_functions.js.map +1 -1
  92. package/lib/operations/connect.js +4 -13
  93. package/lib/operations/connect.js.map +1 -1
  94. package/lib/operations/count.js +1 -1
  95. package/lib/operations/count.js.map +1 -1
  96. package/lib/operations/count_documents.js.map +1 -1
  97. package/lib/operations/create_collection.js +3 -2
  98. package/lib/operations/create_collection.js.map +1 -1
  99. package/lib/operations/delete.js +3 -3
  100. package/lib/operations/delete.js.map +1 -1
  101. package/lib/operations/distinct.js +3 -3
  102. package/lib/operations/distinct.js.map +1 -1
  103. package/lib/operations/drop.js +1 -1
  104. package/lib/operations/drop.js.map +1 -1
  105. package/lib/operations/estimated_document_count.js +2 -2
  106. package/lib/operations/estimated_document_count.js.map +1 -1
  107. package/lib/operations/eval.js +2 -2
  108. package/lib/operations/eval.js.map +1 -1
  109. package/lib/operations/execute_operation.js +5 -6
  110. package/lib/operations/execute_operation.js.map +1 -1
  111. package/lib/operations/find.js +5 -5
  112. package/lib/operations/find.js.map +1 -1
  113. package/lib/operations/find_and_modify.js +2 -2
  114. package/lib/operations/find_and_modify.js.map +1 -1
  115. package/lib/operations/get_more.js.map +1 -1
  116. package/lib/operations/indexes.js +4 -4
  117. package/lib/operations/indexes.js.map +1 -1
  118. package/lib/operations/insert.js +3 -3
  119. package/lib/operations/insert.js.map +1 -1
  120. package/lib/operations/is_capped.js +1 -1
  121. package/lib/operations/is_capped.js.map +1 -1
  122. package/lib/operations/list_collections.js +3 -3
  123. package/lib/operations/list_collections.js.map +1 -1
  124. package/lib/operations/list_databases.js +1 -1
  125. package/lib/operations/list_databases.js.map +1 -1
  126. package/lib/operations/map_reduce.js +4 -3
  127. package/lib/operations/map_reduce.js.map +1 -1
  128. package/lib/operations/operation.js +1 -1
  129. package/lib/operations/operation.js.map +1 -1
  130. package/lib/operations/options_operation.js +1 -1
  131. package/lib/operations/options_operation.js.map +1 -1
  132. package/lib/operations/profiling_level.js +1 -1
  133. package/lib/operations/profiling_level.js.map +1 -1
  134. package/lib/operations/remove_user.js +1 -1
  135. package/lib/operations/remove_user.js.map +1 -1
  136. package/lib/operations/rename.js +3 -3
  137. package/lib/operations/rename.js.map +1 -1
  138. package/lib/operations/run_command.js +1 -1
  139. package/lib/operations/run_command.js.map +1 -1
  140. package/lib/operations/set_profiling_level.js +2 -2
  141. package/lib/operations/set_profiling_level.js.map +1 -1
  142. package/lib/operations/stats.js +1 -1
  143. package/lib/operations/stats.js.map +1 -1
  144. package/lib/operations/update.js +2 -2
  145. package/lib/operations/update.js.map +1 -1
  146. package/lib/operations/validate_collection.js +1 -1
  147. package/lib/operations/validate_collection.js.map +1 -1
  148. package/lib/read_preference.js +15 -5
  149. package/lib/read_preference.js.map +1 -1
  150. package/lib/sdam/events.js +4 -4
  151. package/lib/sdam/monitor.js +19 -18
  152. package/lib/sdam/monitor.js.map +1 -1
  153. package/lib/sdam/server.js +24 -31
  154. package/lib/sdam/server.js.map +1 -1
  155. package/lib/sdam/server_description.js +38 -38
  156. package/lib/sdam/server_description.js.map +1 -1
  157. package/lib/sdam/server_selection.js +2 -2
  158. package/lib/sdam/server_selection.js.map +1 -1
  159. package/lib/sdam/srv_polling.js +2 -2
  160. package/lib/sdam/srv_polling.js.map +1 -1
  161. package/lib/sdam/topology.js +32 -62
  162. package/lib/sdam/topology.js.map +1 -1
  163. package/lib/sdam/topology_description.js +3 -3
  164. package/lib/sdam/topology_description.js.map +1 -1
  165. package/lib/sessions.js +13 -28
  166. package/lib/sessions.js.map +1 -1
  167. package/lib/transactions.js +1 -1
  168. package/lib/transactions.js.map +1 -1
  169. package/lib/utils.js +46 -15
  170. package/lib/utils.js.map +1 -1
  171. package/mongodb.d.ts +205 -60
  172. package/mongodb.ts34.d.ts +230 -59
  173. package/package.json +40 -37
  174. package/src/admin.ts +9 -9
  175. package/src/bson.ts +25 -17
  176. package/src/bulk/common.ts +22 -23
  177. package/src/bulk/ordered.ts +4 -4
  178. package/src/bulk/unordered.ts +5 -5
  179. package/src/change_stream.ts +29 -28
  180. package/src/cmap/auth/auth_provider.ts +3 -3
  181. package/src/cmap/auth/gssapi.ts +65 -14
  182. package/src/cmap/auth/mongo_credentials.ts +28 -17
  183. package/src/cmap/auth/mongocr.ts +3 -2
  184. package/src/cmap/auth/mongodb_aws.ts +10 -11
  185. package/src/cmap/auth/plain.ts +1 -1
  186. package/src/cmap/auth/providers.ts +21 -0
  187. package/src/cmap/auth/scram.ts +9 -9
  188. package/src/cmap/auth/x509.ts +3 -3
  189. package/src/cmap/command_monitoring_events.ts +4 -3
  190. package/src/cmap/commands.ts +22 -14
  191. package/src/cmap/connect.ts +161 -45
  192. package/src/cmap/connection.ts +83 -63
  193. package/src/cmap/connection_pool.ts +39 -39
  194. package/src/cmap/connection_pool_events.ts +1 -1
  195. package/src/cmap/message_stream.ts +9 -8
  196. package/src/cmap/stream_description.ts +5 -5
  197. package/src/cmap/wire_protocol/compression.ts +4 -3
  198. package/src/cmap/wire_protocol/shared.ts +10 -9
  199. package/src/collection.ts +116 -93
  200. package/src/connection_string.ts +130 -59
  201. package/src/constants.ts +122 -0
  202. package/src/cursor/abstract_cursor.ts +14 -13
  203. package/src/cursor/aggregation_cursor.ts +6 -6
  204. package/src/cursor/find_cursor.ts +12 -4
  205. package/src/db.ts +44 -33
  206. package/src/deps.ts +44 -1
  207. package/src/encrypter.ts +12 -3
  208. package/src/error.ts +52 -24
  209. package/src/gridfs/download.ts +10 -8
  210. package/src/gridfs/index.ts +11 -11
  211. package/src/gridfs/upload.ts +13 -10
  212. package/src/index.ts +205 -199
  213. package/src/logger.ts +2 -1
  214. package/src/mongo_client.ts +46 -32
  215. package/src/mongo_types.ts +119 -21
  216. package/src/operations/add_user.ts +7 -6
  217. package/src/operations/aggregate.ts +5 -5
  218. package/src/operations/bulk_write.ts +5 -5
  219. package/src/operations/collections.ts +2 -2
  220. package/src/operations/command.ts +15 -9
  221. package/src/operations/common_functions.ts +4 -4
  222. package/src/operations/connect.ts +4 -14
  223. package/src/operations/count.ts +4 -4
  224. package/src/operations/count_documents.ts +3 -3
  225. package/src/operations/create_collection.ts +7 -6
  226. package/src/operations/delete.ts +5 -5
  227. package/src/operations/distinct.ts +4 -4
  228. package/src/operations/drop.ts +4 -4
  229. package/src/operations/estimated_document_count.ts +5 -5
  230. package/src/operations/eval.ts +5 -5
  231. package/src/operations/execute_operation.ts +10 -11
  232. package/src/operations/find.ts +14 -14
  233. package/src/operations/find_and_modify.ts +7 -7
  234. package/src/operations/get_more.ts +2 -2
  235. package/src/operations/indexes.ts +16 -16
  236. package/src/operations/insert.ts +9 -9
  237. package/src/operations/is_capped.ts +3 -3
  238. package/src/operations/list_collections.ts +6 -6
  239. package/src/operations/list_databases.ts +4 -4
  240. package/src/operations/map_reduce.ts +10 -9
  241. package/src/operations/operation.ts +3 -3
  242. package/src/operations/options_operation.ts +3 -3
  243. package/src/operations/profiling_level.ts +4 -4
  244. package/src/operations/remove_user.ts +4 -4
  245. package/src/operations/rename.ts +6 -6
  246. package/src/operations/run_command.ts +3 -3
  247. package/src/operations/set_profiling_level.ts +6 -5
  248. package/src/operations/stats.ts +4 -4
  249. package/src/operations/update.ts +10 -10
  250. package/src/operations/validate_collection.ts +4 -4
  251. package/src/read_preference.ts +18 -7
  252. package/src/sdam/common.ts +2 -2
  253. package/src/sdam/events.ts +5 -5
  254. package/src/sdam/monitor.ts +29 -32
  255. package/src/sdam/server.ts +64 -62
  256. package/src/sdam/server_description.ts +41 -48
  257. package/src/sdam/server_selection.ts +3 -3
  258. package/src/sdam/srv_polling.ts +3 -2
  259. package/src/sdam/topology.ts +71 -89
  260. package/src/sdam/topology_description.ts +5 -5
  261. package/src/sessions.ts +31 -48
  262. package/src/transactions.ts +4 -4
  263. package/src/utils.ts +64 -28
  264. package/lib/cmap/auth/defaultAuthProviders.js +0 -30
  265. package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
  266. package/src/cmap/auth/defaultAuthProviders.ts +0 -32
@@ -1,49 +1,59 @@
1
- import { MessageStream, OperationDescription } from './message_stream';
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
- uuidV4,
11
- ClientMetadata,
12
- now,
13
- calculateDurationInMs,
14
- Callback,
15
- MongoDBNamespace,
16
- maxWireVersion,
17
- HostAddress
18
- } from '../utils';
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
- Query,
46
+ KillCursor,
47
+ Msg,
35
48
  OpQueryOptions,
36
- Msg
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 kIsMaster = Symbol('ismaster');
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
- slaveOk?: boolean;
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
- lastIsMasterMS?: number;
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
- [kIsMaster]: Document;
204
+ [kHello]: Document;
186
205
  /** @internal */
187
206
  [kClusterTime]: Document;
188
207
 
189
208
  /** @event */
190
- static readonly COMMAND_STARTED = 'commandStarted' as const;
209
+ static readonly COMMAND_STARTED = COMMAND_STARTED;
191
210
  /** @event */
192
- static readonly COMMAND_SUCCEEDED = 'commandSucceeded' as const;
211
+ static readonly COMMAND_SUCCEEDED = COMMAND_SUCCEEDED;
193
212
  /** @event */
194
- static readonly COMMAND_FAILED = 'commandFailed' as const;
213
+ static readonly COMMAND_FAILED = COMMAND_FAILED;
195
214
  /** @event */
196
- static readonly CLUSTER_TIME_RECEIVED = 'clusterTimeReceived' as const;
215
+ static readonly CLUSTER_TIME_RECEIVED = CLUSTER_TIME_RECEIVED;
197
216
  /** @event */
198
- static readonly CLOSE = 'close' as const;
217
+ static readonly CLOSE = CLOSE;
199
218
  /** @event */
200
- static readonly MESSAGE = 'message' as const;
219
+ static readonly MESSAGE = MESSAGE;
201
220
  /** @event */
202
- static readonly PINNED = 'pinned' as const;
221
+ static readonly PINNED = PINNED;
203
222
  /** @event */
204
- static readonly UNPINNED = 'unpinned' as const;
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.ismaster?.maxBsonMessageSize
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 ismaster(): Document {
246
- return this[kIsMaster];
264
+ get hello(): Document {
265
+ return this[kHello];
247
266
  }
248
267
 
249
- // the `connect` method stores the result of the handshake ismaster on the connection
250
- set ismaster(response: Document) {
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[kIsMaster] = response;
274
+ this[kHello] = response;
256
275
  }
257
276
 
258
277
  get serviceId(): ObjectId | undefined {
259
- return this.ismaster?.serviceId;
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.ismaster == null
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
- slaveOk: readPreference.slaveOk()
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
- slaveOk: readPreference.slaveOk()
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 { APM_EVENTS, Connection, ConnectionEvents, ConnectionOptions } from './connection';
3
- import type { ObjectId } from 'bson';
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 { ConnectionPoolMetrics } from './metrics';
18
+ import { CancellationToken, TypedEventEmitter } from '../mongo_types';
19
+ import { Callback, eachAsync, makeCounter } from '../utils';
6
20
  import { connect } from './connect';
7
- import { eachAsync, makeCounter, Callback } from '../utils';
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
- ConnectionPoolClearedEvent
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 { CancellationToken, TypedEventEmitter } from '../mongo_types';
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 = 'connectionPoolCreated' as const;
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 = 'connectionPoolClosed' as const;
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 = 'connectionPoolCleared' as const;
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 = 'connectionCreated' as const;
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 = 'connectionReady' as const;
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 = 'connectionClosed' as const;
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 = 'connectionCheckOutStarted' as const;
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 = 'connectionCheckOutFailed' as const;
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 = 'connectionCheckedOut' as const;
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 = 'connectionCheckedIn' as const;
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
- import { Response, Msg, BinMsg, Query, WriteProtocolMessageType, MessageHeader } from './commands';
2
+
3
+ import type { BSONSerializeOptions, Document } from '../bson';
3
4
  import { MongoDecompressionError, MongoParseError } from '../error';
4
- import { OP_COMPRESSED, OP_MSG } from './wire_protocol/constants';
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 type { Document, BSONSerializeOptions } from '../bson';
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
- RESPONSE_FIELDS.forEach(field => {
59
- if (typeof response[field] != null) {
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
- 'ismaster',
23
+ LEGACY_HELLO_COMMAND,
23
24
  'saslStart',
24
25
  'saslContinue',
25
26
  'getnonce',
@@ -1,15 +1,14 @@
1
- import { ServerType } from '../../sdam/common';
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 type { Document } from '../../bson';
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 { ReadPreferenceLike } from '../../read_preference';
11
- import type { CommandOptions } from '../connection';
12
- import type { Connection } from '../connection';
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) {