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,88 +1,83 @@
1
1
  import Denque = require('denque');
2
- import { ReadPreference, ReadPreferenceLike } from '../read_preference';
3
- import { compareTopologyVersion, ServerDescription } from './server_description';
4
- import { TopologyDescription } from './topology_description';
5
- import { Server, ServerEvents, ServerOptions } from './server';
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
- ClientSession,
8
- ServerSessionPool,
9
- ServerSessionId,
10
- ClientSessionOptions
11
- } from '../sessions';
12
- import { SrvPoller, SrvPollingEvent } from './srv_polling';
13
- import { CMAP_EVENTS, ConnectionPoolEvents } from '../cmap/connection_pool';
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
- MongoTopologyClosedError,
19
- MongoRuntimeError
26
+ MongoRuntimeError,
27
+ MongoServerSelectionError,
28
+ MongoTopologyClosedError
20
29
  } from '../error';
21
- import { readPreferenceServerSelector, ServerSelector } from './server_selection';
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
- HostAddress,
28
- ns,
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
- STATE_CONNECTED
61
+ TimerQueue,
62
+ TopologyType
45
63
  } from './common';
46
64
  import {
47
- ServerOpeningEvent,
48
65
  ServerClosedEvent,
49
66
  ServerDescriptionChangedEvent,
50
- TopologyOpeningEvent,
67
+ ServerOpeningEvent,
51
68
  TopologyClosedEvent,
52
- TopologyDescriptionChangedEvent
69
+ TopologyDescriptionChangedEvent,
70
+ TopologyOpeningEvent
53
71
  } from './events';
54
- import type { Document, BSONSerializeOptions } from '../bson';
55
- import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
56
- import type { Transaction } from '../transactions';
57
- import type { CloseOptions } from '../cmap/connection_pool';
58
- import { DestroyOptions, Connection, ConnectionEvents } from '../cmap/connection';
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],
@@ -203,32 +198,32 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
203
198
  /** @internal */
204
199
  [kWaitQueue]: Denque<ServerSelectionRequest>;
205
200
  /** @internal */
206
- ismaster?: Document;
201
+ hello?: Document;
207
202
  /** @internal */
208
203
  _type?: string;
209
204
 
210
205
  /** @event */
211
- static readonly SERVER_OPENING = 'serverOpening' as const;
206
+ static readonly SERVER_OPENING = SERVER_OPENING;
212
207
  /** @event */
213
- static readonly SERVER_CLOSED = 'serverClosed' as const;
208
+ static readonly SERVER_CLOSED = SERVER_CLOSED;
214
209
  /** @event */
215
- static readonly SERVER_DESCRIPTION_CHANGED = 'serverDescriptionChanged' as const;
210
+ static readonly SERVER_DESCRIPTION_CHANGED = SERVER_DESCRIPTION_CHANGED;
216
211
  /** @event */
217
- static readonly TOPOLOGY_OPENING = 'topologyOpening' as const;
212
+ static readonly TOPOLOGY_OPENING = TOPOLOGY_OPENING;
218
213
  /** @event */
219
- static readonly TOPOLOGY_CLOSED = 'topologyClosed' as const;
214
+ static readonly TOPOLOGY_CLOSED = TOPOLOGY_CLOSED;
220
215
  /** @event */
221
- static readonly TOPOLOGY_DESCRIPTION_CHANGED = 'topologyDescriptionChanged' as const;
216
+ static readonly TOPOLOGY_DESCRIPTION_CHANGED = TOPOLOGY_DESCRIPTION_CHANGED;
222
217
  /** @event */
223
- static readonly ERROR = 'error' as const;
218
+ static readonly ERROR = ERROR;
224
219
  /** @event */
225
- static readonly OPEN = 'open' as const;
220
+ static readonly OPEN = OPEN;
226
221
  /** @event */
227
- static readonly CONNECT = 'connect' as const;
222
+ static readonly CONNECT = CONNECT;
228
223
  /** @event */
229
- static readonly CLOSE = 'close' as const;
224
+ static readonly CLOSE = CLOSE;
230
225
  /** @event */
231
- static readonly TIMEOUT = 'timeout' as const;
226
+ static readonly TIMEOUT = TIMEOUT;
232
227
 
233
228
  /**
234
229
  * @internal
@@ -408,7 +403,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
408
403
  }
409
404
 
410
405
  get capabilities(): ServerCapabilities {
411
- return new ServerCapabilities(this.lastIsMaster());
406
+ return new ServerCapabilities(this.lastHello());
412
407
  }
413
408
 
414
409
  /** Initiate server connect */
@@ -796,10 +791,10 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
796
791
  emitWarning('`unref` is a noop and will be removed in the next major version');
797
792
  }
798
793
 
799
- // NOTE: There are many places in code where we explicitly check the last isMaster
794
+ // NOTE: There are many places in code where we explicitly check the last hello
800
795
  // to do feature support detection. This should be done any other way, but for
801
- // now we will just return the first isMaster seen, which should suffice.
802
- lastIsMaster(): Document {
796
+ // now we will just return the first hello seen, which should suffice.
797
+ lastHello(): Document {
803
798
  const serverDescriptions = Array.from(this.description.servers.values());
804
799
  if (serverDescriptions.length === 0) return {};
805
800
  const sd = serverDescriptions.filter(
@@ -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,
@@ -1084,9 +1066,9 @@ export class ServerCapabilities {
1084
1066
  maxWireVersion: number;
1085
1067
  minWireVersion: number;
1086
1068
 
1087
- constructor(ismaster: Document) {
1088
- this.minWireVersion = ismaster.minWireVersion || 0;
1089
- this.maxWireVersion = ismaster.maxWireVersion || 0;
1069
+ constructor(hello: Document) {
1070
+ this.minWireVersion = hello.minWireVersion || 0;
1071
+ this.maxWireVersion = hello.maxWireVersion || 0;
1090
1072
  }
1091
1073
 
1092
1074
  get hasAggregationCursor(): boolean {
@@ -1,10 +1,10 @@
1
- import { ServerDescription } from './server_description';
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;
@@ -106,7 +106,7 @@ export class TopologyDescription {
106
106
  }
107
107
  }
108
108
 
109
- // Whenever a client updates the TopologyDescription from an ismaster response, it MUST set
109
+ // Whenever a client updates the TopologyDescription from a hello response, it MUST set
110
110
  // TopologyDescription.logicalSessionTimeoutMinutes to the smallest logicalSessionTimeoutMinutes
111
111
  // value among ServerDescriptions of all data-bearing server types. If any have a null
112
112
  // logicalSessionTimeoutMinutes, then TopologyDescription.logicalSessionTimeoutMinutes MUST be
package/src/sessions.ts CHANGED
@@ -1,45 +1,47 @@
1
- import { PromiseProvider } from './promise_provider';
2
- import { Binary, Long, Timestamp, Document } from './bson';
3
- import { ReadPreference } from './read_preference';
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
- MongoError,
9
- MongoInvalidArgumentError,
8
+ AnyError,
9
+ isRetryableEndTransactionError,
10
10
  isRetryableError,
11
+ MongoAPIError,
11
12
  MongoCompatibilityError,
12
- MongoNetworkError,
13
- MongoWriteConcernError,
14
13
  MONGODB_ERROR_CODES,
15
- MongoServerError,
16
14
  MongoDriverError,
17
- MongoAPIError,
18
- AnyError,
15
+ MongoError,
19
16
  MongoExpiredSessionError,
17
+ MongoInvalidArgumentError,
18
+ MongoNetworkError,
19
+ MongoRuntimeError,
20
+ MongoServerError,
20
21
  MongoTransactionError,
21
- MongoRuntimeError
22
+ MongoWriteConcernError
22
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';
23
34
  import {
24
- now,
25
35
  calculateDurationInMs,
26
36
  Callback,
37
+ commandSupportsReadConcern,
27
38
  isPromiseLike,
28
- uuidV4,
29
39
  maxWireVersion,
30
- maybePromise
40
+ maybePromise,
41
+ now,
42
+ uuidV4
31
43
  } from './utils';
32
- import type { Topology } from './sdam/topology';
33
- import type { MongoOptions } from './mongo_client';
34
- import { executeOperation } from './operations/execute_operation';
35
- import { RunAdminCommandOperation } from './operations/run_command';
36
- import type { AbstractCursor } from './cursor/abstract_cursor';
37
- import type { CommandOptions } from './cmap/connection';
38
- import { Connection } from './cmap/connection';
39
- import { ConnectionPoolMetrics } from './cmap/metrics';
40
44
  import type { WriteConcern } from './write_concern';
41
- import { TypedEventEmitter } from './mongo_types';
42
- import { ReadConcernLevel } from './read_concern';
43
45
 
44
46
  const minWireVersionForShardedTransactions = 8;
45
47
 
@@ -224,7 +226,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
224
226
 
225
227
  this[kPinnedConnection] = conn;
226
228
  conn.emit(
227
- Connection.PINNED,
229
+ PINNED,
228
230
  this.inTransaction() ? ConnectionPoolMetrics.TXN : ConnectionPoolMetrics.CURSOR
229
231
  );
230
232
  }
@@ -519,7 +521,7 @@ export function maybeClearPinnedConnection(
519
521
  if (options?.error == null || options?.force) {
520
522
  loadBalancer.s.pool.checkIn(conn);
521
523
  conn.emit(
522
- Connection.UNPINNED,
524
+ UNPINNED,
523
525
  session.transaction.state !== TxnState.NO_TRANSACTION
524
526
  ? ConnectionPoolMetrics.TXN
525
527
  : ConnectionPoolMetrics.CURSOR
@@ -767,7 +769,7 @@ function endTransaction(session: ClientSession, commandName: string, callback: C
767
769
  session.unpin();
768
770
  }
769
771
 
770
- if (err && isRetryableError(err as MongoError)) {
772
+ if (err && isRetryableEndTransactionError(err as MongoError)) {
771
773
  // SPEC-1185: apply majority write concern when retrying commitTransaction
772
774
  if (command.commitTransaction) {
773
775
  // per txns spec, must unpin session in this case
@@ -928,25 +930,6 @@ export class ServerSessionPool {
928
930
  }
929
931
  }
930
932
 
931
- // TODO: this should be codified in command construction
932
- // @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.rst#read-concern
933
- export function commandSupportsReadConcern(command: Document, options?: Document): boolean {
934
- if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
935
- return true;
936
- }
937
-
938
- if (
939
- command.mapReduce &&
940
- options &&
941
- options.out &&
942
- (options.out.inline === 1 || options.out === 'inline')
943
- ) {
944
- return true;
945
- }
946
-
947
- return false;
948
- }
949
-
950
933
  /**
951
934
  * Optionally decorate a command with sessions specific keys
952
935
  *
@@ -1,10 +1,10 @@
1
- import { ReadPreference } from './read_preference';
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 { WriteConcern } from './write_concern';
5
+ import { ReadPreference } from './read_preference';
5
6
  import type { Server } from './sdam/server';
6
- import type { CommandOperationOptions } from './operations/command';
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 { PromiseProvider } from './promise_provider';
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
- MongoNotConnectedError,
15
+ MongoExpiredSessionError,
10
16
  MongoInvalidArgumentError,
11
- MongoExpiredSessionError
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 { URL } from 'url';
30
- import { MAX_SUPPORTED_WIRE_VERSION } from './cmap/wire_protocol/constants';
31
- import type { SrvRecord } from 'dns';
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
@@ -654,14 +656,14 @@ export function maxWireVersion(topologyOrServer?: Connection | Topology | Server
654
656
  // application that a feature is avaiable that is actually not.
655
657
  return MAX_SUPPORTED_WIRE_VERSION;
656
658
  }
657
- if (topologyOrServer.ismaster) {
658
- return topologyOrServer.ismaster.maxWireVersion;
659
+ if (topologyOrServer.hello) {
660
+ return topologyOrServer.hello.maxWireVersion;
659
661
  }
660
662
 
661
- if ('lastIsMaster' in topologyOrServer && typeof topologyOrServer.lastIsMaster === 'function') {
662
- const lastIsMaster = topologyOrServer.lastIsMaster();
663
- if (lastIsMaster) {
664
- return lastIsMaster.maxWireVersion;
663
+ if ('lastHello' in topologyOrServer && typeof topologyOrServer.lastHello === 'function') {
664
+ const lastHello = topologyOrServer.lastHello();
665
+ if (lastHello) {
666
+ return lastHello.maxWireVersion;
665
667
  }
666
668
  }
667
669
 
@@ -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.fromString(`${name}:${port}`);
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
- ]);