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
package/src/constants.ts CHANGED
@@ -4,3 +4,125 @@ export const SYSTEM_PROFILE_COLLECTION = 'system.profile';
4
4
  export const SYSTEM_USER_COLLECTION = 'system.users';
5
5
  export const SYSTEM_COMMAND_COLLECTION = '$cmd';
6
6
  export const SYSTEM_JS_COLLECTION = 'system.js';
7
+
8
+ // events
9
+ export const ERROR = 'error' as const;
10
+ export const TIMEOUT = 'timeout' as const;
11
+ export const CLOSE = 'close' as const;
12
+ export const OPEN = 'open' as const;
13
+ export const CONNECT = 'connect' as const;
14
+ export const CLOSED = 'closed' as const;
15
+ export const ENDED = 'ended' as const;
16
+ export const MESSAGE = 'message' as const;
17
+ export const PINNED = 'pinned' as const;
18
+ export const UNPINNED = 'unpinned' as const;
19
+ export const DESCRIPTION_RECEIVED = 'descriptionReceived';
20
+ export const SERVER_OPENING = 'serverOpening' as const;
21
+ export const SERVER_CLOSED = 'serverClosed' as const;
22
+ export const SERVER_DESCRIPTION_CHANGED = 'serverDescriptionChanged' as const;
23
+ export const TOPOLOGY_OPENING = 'topologyOpening' as const;
24
+ export const TOPOLOGY_CLOSED = 'topologyClosed' as const;
25
+ export const TOPOLOGY_DESCRIPTION_CHANGED = 'topologyDescriptionChanged' as const;
26
+ export const CONNECTION_POOL_CREATED = 'connectionPoolCreated' as const;
27
+ export const CONNECTION_POOL_CLOSED = 'connectionPoolClosed' as const;
28
+ export const CONNECTION_POOL_CLEARED = 'connectionPoolCleared' as const;
29
+ export const CONNECTION_CREATED = 'connectionCreated' as const;
30
+ export const CONNECTION_READY = 'connectionReady' as const;
31
+ export const CONNECTION_CLOSED = 'connectionClosed' as const;
32
+ export const CONNECTION_CHECK_OUT_STARTED = 'connectionCheckOutStarted' as const;
33
+ export const CONNECTION_CHECK_OUT_FAILED = 'connectionCheckOutFailed' as const;
34
+ export const CONNECTION_CHECKED_OUT = 'connectionCheckedOut' as const;
35
+ export const CONNECTION_CHECKED_IN = 'connectionCheckedIn' as const;
36
+ export const CLUSTER_TIME_RECEIVED = 'clusterTimeReceived' as const;
37
+ export const COMMAND_STARTED = 'commandStarted' as const;
38
+ export const COMMAND_SUCCEEDED = 'commandSucceeded' as const;
39
+ export const COMMAND_FAILED = 'commandFailed' as const;
40
+ export const SERVER_HEARTBEAT_STARTED = 'serverHeartbeatStarted' as const;
41
+ export const SERVER_HEARTBEAT_SUCCEEDED = 'serverHeartbeatSucceeded' as const;
42
+ export const SERVER_HEARTBEAT_FAILED = 'serverHeartbeatFailed' as const;
43
+
44
+ /** @public */
45
+ export const HEARTBEAT_EVENTS = Object.freeze([
46
+ SERVER_HEARTBEAT_STARTED,
47
+ SERVER_HEARTBEAT_SUCCEEDED,
48
+ SERVER_HEARTBEAT_FAILED
49
+ ] as const);
50
+
51
+ /** @public */
52
+ export const CMAP_EVENTS = Object.freeze([
53
+ CONNECTION_POOL_CREATED,
54
+ CONNECTION_POOL_CLOSED,
55
+ CONNECTION_CREATED,
56
+ CONNECTION_READY,
57
+ CONNECTION_CLOSED,
58
+ CONNECTION_CHECK_OUT_STARTED,
59
+ CONNECTION_CHECK_OUT_FAILED,
60
+ CONNECTION_CHECKED_OUT,
61
+ CONNECTION_CHECKED_IN,
62
+ CONNECTION_POOL_CLEARED
63
+ ] as const);
64
+
65
+ /** @public */
66
+ export const TOPOLOGY_EVENTS = Object.freeze([
67
+ SERVER_OPENING,
68
+ SERVER_CLOSED,
69
+ SERVER_DESCRIPTION_CHANGED,
70
+ TOPOLOGY_OPENING,
71
+ TOPOLOGY_CLOSED,
72
+ TOPOLOGY_DESCRIPTION_CHANGED,
73
+ ERROR,
74
+ TIMEOUT,
75
+ CLOSE
76
+ ] as const);
77
+
78
+ /** @public */
79
+ export const APM_EVENTS = Object.freeze([
80
+ COMMAND_STARTED,
81
+ COMMAND_SUCCEEDED,
82
+ COMMAND_FAILED
83
+ ] as const);
84
+
85
+ /**
86
+ * All events that we relay to the `Topology`
87
+ * @internal
88
+ */
89
+ export const SERVER_RELAY_EVENTS = Object.freeze([
90
+ SERVER_HEARTBEAT_STARTED,
91
+ SERVER_HEARTBEAT_SUCCEEDED,
92
+ SERVER_HEARTBEAT_FAILED,
93
+ COMMAND_STARTED,
94
+ COMMAND_SUCCEEDED,
95
+ COMMAND_FAILED,
96
+ ...CMAP_EVENTS
97
+ ] as const);
98
+
99
+ /**
100
+ * All events we listen to from `Server` instances, but do not forward to the client
101
+ * @internal
102
+ */
103
+ export const LOCAL_SERVER_EVENTS = Object.freeze([
104
+ CONNECT,
105
+ DESCRIPTION_RECEIVED,
106
+ CLOSED,
107
+ ENDED
108
+ ] as const);
109
+
110
+ /** @public */
111
+ export const MONGO_CLIENT_EVENTS = Object.freeze([
112
+ ...CMAP_EVENTS,
113
+ ...APM_EVENTS,
114
+ ...TOPOLOGY_EVENTS,
115
+ ...HEARTBEAT_EVENTS
116
+ ] as const);
117
+
118
+ /**
119
+ * @internal
120
+ * The legacy hello command that was deprecated in MongoDB 5.0.
121
+ */
122
+ export const LEGACY_HELLO_COMMAND = 'ismaster';
123
+
124
+ /**
125
+ * @internal
126
+ * The legacy hello command that was deprecated in MongoDB 5.0.
127
+ */
128
+ export const LEGACY_HELLO_COMMAND_CAMEL_CASE = 'isMaster';
@@ -1,23 +1,24 @@
1
- import { Callback, maybePromise, MongoDBNamespace, ns } from '../utils';
2
- import { Long, Document, BSONSerializeOptions, pluckBSONSerializeOptions } from '../bson';
3
- import { ClientSession, maybeClearPinnedConnection } from '../sessions';
1
+ import { Readable, Transform } from 'stream';
2
+
3
+ import { BSONSerializeOptions, Document, Long, pluckBSONSerializeOptions } from '../bson';
4
4
  import {
5
5
  AnyError,
6
- MongoRuntimeError,
7
- MongoNetworkError,
8
- MongoInvalidArgumentError,
9
6
  MongoCursorExhaustedError,
10
- MongoTailableCursorError,
11
- MongoCursorInUseError
7
+ MongoCursorInUseError,
8
+ MongoInvalidArgumentError,
9
+ MongoNetworkError,
10
+ MongoRuntimeError,
11
+ MongoTailableCursorError
12
12
  } from '../error';
13
- import { ReadPreference, ReadPreferenceLike } from '../read_preference';
14
- import type { Server } from '../sdam/server';
15
- import type { Topology } from '../sdam/topology';
16
- import { Readable, Transform } from 'stream';
13
+ import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
17
14
  import { executeOperation, ExecutionResult } from '../operations/execute_operation';
18
15
  import { GetMoreOperation } from '../operations/get_more';
19
16
  import { ReadConcern, ReadConcernLike } from '../read_concern';
20
- import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
17
+ import { ReadPreference, ReadPreferenceLike } from '../read_preference';
18
+ import type { Server } from '../sdam/server';
19
+ import type { Topology } from '../sdam/topology';
20
+ import { ClientSession, maybeClearPinnedConnection } from '../sessions';
21
+ import { Callback, maybePromise, MongoDBNamespace, ns } from '../utils';
21
22
 
22
23
  /** @internal */
23
24
  const kId = Symbol('id');
@@ -1,14 +1,14 @@
1
+ import type { Document } from '../bson';
2
+ import type { ExplainVerbosityLike } from '../explain';
1
3
  import { AggregateOperation, AggregateOptions } from '../operations/aggregate';
2
- import { AbstractCursor, assertUninitialized } from './abstract_cursor';
3
4
  import { executeOperation, ExecutionResult } from '../operations/execute_operation';
4
- import { mergeOptions } from '../utils';
5
- import type { Document } from '../bson';
6
- import type { Sort } from '../sort';
7
5
  import type { Topology } from '../sdam/topology';
8
- import type { Callback, MongoDBNamespace } from '../utils';
9
6
  import type { ClientSession } from '../sessions';
7
+ import type { Sort } from '../sort';
8
+ import type { Callback, MongoDBNamespace } from '../utils';
9
+ import { mergeOptions } from '../utils';
10
10
  import type { AbstractCursorOptions } from './abstract_cursor';
11
- import type { ExplainVerbosityLike } from '../explain';
11
+ import { AbstractCursor, assertUninitialized } from './abstract_cursor';
12
12
 
13
13
  /** @public */
14
14
  export interface AggregationCursorOptions extends AbstractCursorOptions, AggregateOptions {}
@@ -1,16 +1,15 @@
1
1
  import type { Document } from '../bson';
2
2
  import { MongoInvalidArgumentError, MongoTailableCursorError } from '../error';
3
3
  import type { ExplainVerbosityLike } from '../explain';
4
+ import type { CollationOptions } from '../operations/command';
4
5
  import { CountOperation, CountOptions } from '../operations/count';
5
6
  import { executeOperation, ExecutionResult } from '../operations/execute_operation';
6
7
  import { FindOperation, FindOptions } from '../operations/find';
7
- import { mergeOptions } from '../utils';
8
8
  import type { Hint } from '../operations/operation';
9
- import type { CollationOptions } from '../operations/command';
10
9
  import type { Topology } from '../sdam/topology';
11
10
  import type { ClientSession } from '../sessions';
12
11
  import { formatSort, Sort, SortDirection } from '../sort';
13
- import type { Callback, MongoDBNamespace } from '../utils';
12
+ import { Callback, emitWarningOnce, mergeOptions, MongoDBNamespace } from '../utils';
14
13
  import { AbstractCursor, assertUninitialized } from './abstract_cursor';
15
14
 
16
15
  /** @internal */
@@ -118,15 +117,24 @@ export class FindCursor<TSchema = Document> extends AbstractCursor<TSchema> {
118
117
  });
119
118
  }
120
119
 
121
- /** Get the count of documents for this cursor */
120
+ /**
121
+ * Get the count of documents for this cursor
122
+ * @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead
123
+ */
122
124
  count(): Promise<number>;
125
+ /** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead */
123
126
  count(callback: Callback<number>): void;
127
+ /** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead */
124
128
  count(options: CountOptions): Promise<number>;
129
+ /** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead */
125
130
  count(options: CountOptions, callback: Callback<number>): void;
126
131
  count(
127
132
  options?: CountOptions | Callback<number>,
128
133
  callback?: Callback<number>
129
134
  ): Promise<number> | void {
135
+ emitWarningOnce(
136
+ 'cursor.count is deprecated and will be removed in the next major version, please use `collection.estimatedDocumentCount` or `collection.countDocuments` instead '
137
+ );
130
138
  if (typeof options === 'boolean') {
131
139
  throw new MongoInvalidArgumentError('Invalid first parameter to count');
132
140
  }
package/src/db.ts CHANGED
@@ -1,39 +1,31 @@
1
- import {
2
- Callback,
3
- resolveOptions,
4
- filterOptions,
5
- MongoDBNamespace,
6
- getTopology,
7
- DEFAULT_PK_FACTORY
8
- } from './utils';
9
- import { AggregationCursor } from './cursor/aggregation_cursor';
10
- import { Document, BSONSerializeOptions, resolveBSONOptions } from './bson';
11
- import { ReadPreference, ReadPreferenceLike } from './read_preference';
12
- import { MongoAPIError, MongoInvalidArgumentError } from './error';
13
- import { Collection, CollectionOptions } from './collection';
1
+ import { Admin } from './admin';
2
+ import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
14
3
  import { ChangeStream, ChangeStreamOptions } from './change_stream';
4
+ import { Collection, CollectionOptions } from './collection';
15
5
  import * as CONSTANTS from './constants';
16
- import { WriteConcern, WriteConcernOptions } from './write_concern';
17
- import { ReadConcern } from './read_concern';
6
+ import { AggregationCursor } from './cursor/aggregation_cursor';
7
+ import { MongoAPIError, MongoInvalidArgumentError } from './error';
18
8
  import { Logger, LoggerOptions } from './logger';
19
- import type { AggregateOptions } from './operations/aggregate';
9
+ import type { MongoClient, PkFactory } from './mongo_client';
10
+ import type { TODO_NODE_3286 } from './mongo_types';
20
11
  import { AddUserOperation, AddUserOptions } from './operations/add_user';
12
+ import type { AggregateOptions } from './operations/aggregate';
21
13
  import { CollectionsOperation } from './operations/collections';
22
- import { DbStatsOperation, DbStatsOptions } from './operations/stats';
23
- import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
14
+ import type { IndexInformationOptions } from './operations/common_functions';
24
15
  import { CreateCollectionOperation, CreateCollectionOptions } from './operations/create_collection';
25
16
  import {
17
+ DropCollectionOperation,
18
+ DropCollectionOptions,
19
+ DropDatabaseOperation,
20
+ DropDatabaseOptions
21
+ } from './operations/drop';
22
+ import { executeOperation } from './operations/execute_operation';
23
+ import {
24
+ CreateIndexesOptions,
26
25
  CreateIndexOperation,
27
26
  IndexInformationOperation,
28
- CreateIndexesOptions,
29
27
  IndexSpecification
30
28
  } from './operations/indexes';
31
- import {
32
- DropCollectionOperation,
33
- DropDatabaseOperation,
34
- DropDatabaseOptions,
35
- DropCollectionOptions
36
- } from './operations/drop';
37
29
  import {
38
30
  CollectionInfo,
39
31
  ListCollectionsCursor,
@@ -42,16 +34,24 @@ import {
42
34
  import { ProfilingLevelOperation, ProfilingLevelOptions } from './operations/profiling_level';
43
35
  import { RemoveUserOperation, RemoveUserOptions } from './operations/remove_user';
44
36
  import { RenameOperation, RenameOptions } from './operations/rename';
37
+ import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
45
38
  import {
39
+ ProfilingLevel,
46
40
  SetProfilingLevelOperation,
47
- SetProfilingLevelOptions,
48
- ProfilingLevel
41
+ SetProfilingLevelOptions
49
42
  } from './operations/set_profiling_level';
50
- import { executeOperation } from './operations/execute_operation';
51
- import type { IndexInformationOptions } from './operations/common_functions';
52
- import type { MongoClient, PkFactory } from './mongo_client';
53
- import { Admin } from './admin';
54
- import type { TODO_NODE_3286 } from './mongo_types';
43
+ import { DbStatsOperation, DbStatsOptions } from './operations/stats';
44
+ import { ReadConcern } from './read_concern';
45
+ import { ReadPreference, ReadPreferenceLike } from './read_preference';
46
+ import {
47
+ Callback,
48
+ DEFAULT_PK_FACTORY,
49
+ filterOptions,
50
+ getTopology,
51
+ MongoDBNamespace,
52
+ resolveOptions
53
+ } from './utils';
54
+ import { WriteConcern, WriteConcernOptions } from './write_concern';
55
55
 
56
56
  // Allowed parameters
57
57
  const DB_OPTIONS_ALLOW_LIST = [
@@ -73,6 +73,7 @@ const DB_OPTIONS_ALLOW_LIST = [
73
73
  'promoteBuffers',
74
74
  'promoteLongs',
75
75
  'bsonRegExp',
76
+ 'enableUtf8Validation',
76
77
  'promoteValues',
77
78
  'compression',
78
79
  'retryWrites'
@@ -184,8 +185,18 @@ export class Db {
184
185
  return this.s.options;
185
186
  }
186
187
 
187
- // slaveOk specified
188
+ /**
189
+ * slaveOk specified
190
+ * @deprecated Use secondaryOk instead
191
+ */
188
192
  get slaveOk(): boolean {
193
+ return this.secondaryOk;
194
+ }
195
+
196
+ /**
197
+ * Check if a secondary can be used (because the read preference is *not* set to primary)
198
+ */
199
+ get secondaryOk(): boolean {
189
200
  return this.s.readPreference?.preference !== 'primary' || false;
190
201
  }
191
202
 
package/src/deps.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
+ import type { deserialize, Document, serialize } from './bson';
3
+ import type { ProxyOptions } from './cmap/connection';
2
4
  import { MongoMissingDependencyError } from './error';
3
5
  import type { MongoClient } from './mongo_client';
4
- import type { deserialize, Document, serialize } from './bson';
5
6
  import { Callback, parsePackageVersion } from './utils';
6
7
 
7
8
  export const PKG_VERSION = Symbol('kPkgVersion');
@@ -173,6 +174,28 @@ export const AutoEncryptionLoggerLevel = Object.freeze({
173
174
  export type AutoEncryptionLoggerLevel =
174
175
  typeof AutoEncryptionLoggerLevel[keyof typeof AutoEncryptionLoggerLevel];
175
176
 
177
+ /** @public */
178
+ export interface AutoEncryptionTlsOptions {
179
+ /**
180
+ * Specifies the location of a local .pem file that contains
181
+ * either the client's TLS/SSL certificate and key or only the
182
+ * client's TLS/SSL key when tlsCertificateFile is used to
183
+ * provide the certificate.
184
+ */
185
+ tlsCertificateKeyFile?: string;
186
+ /**
187
+ * Specifies the password to de-crypt the tlsCertificateKeyFile.
188
+ */
189
+ tlsCertificateKeyFilePassword?: string;
190
+ /**
191
+ * Specifies the location of a local .pem file that contains the
192
+ * root certificate chain from the Certificate Authority.
193
+ * This file is used to validate the certificate presented by the
194
+ * KMS provider.
195
+ */
196
+ tlsCAFile?: string;
197
+ }
198
+
176
199
  /** @public */
177
200
  export interface AutoEncryptionOptions {
178
201
  /** @internal */
@@ -233,6 +256,17 @@ export interface AutoEncryptionOptions {
233
256
  */
234
257
  endpoint?: string | undefined;
235
258
  };
259
+ /**
260
+ * Configuration options for using 'kmip' as your KMS provider
261
+ */
262
+ kmip?: {
263
+ /**
264
+ * The output endpoint string.
265
+ * The endpoint consists of a hostname and port separated by a colon.
266
+ * E.g. "example.com:123". A port is always present.
267
+ */
268
+ endpoint?: string;
269
+ };
236
270
  };
237
271
  /**
238
272
  * A map of namespaces to a local JSON schema for encryption
@@ -262,6 +296,15 @@ export interface AutoEncryptionOptions {
262
296
  /** Command line arguments to use when auto-spawning a mongocryptd */
263
297
  mongocryptdSpawnArgs?: string[];
264
298
  };
299
+ proxyOptions?: ProxyOptions;
300
+ /** The TLS options to use connecting to the KMS provider */
301
+ tlsOptions?: {
302
+ aws?: AutoEncryptionTlsOptions;
303
+ local?: AutoEncryptionTlsOptions;
304
+ azure?: AutoEncryptionTlsOptions;
305
+ gcp?: AutoEncryptionTlsOptions;
306
+ kmip?: AutoEncryptionTlsOptions;
307
+ };
265
308
  }
266
309
 
267
310
  /** @public */
package/src/encrypter.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
- import { MongoClient, MongoClientOptions } from './mongo_client';
2
+ import { deserialize, serialize } from './bson';
3
+ import { MONGO_CLIENT_EVENTS } from './constants';
3
4
  import type { AutoEncrypter, AutoEncryptionOptions } from './deps';
4
5
  import { MongoInvalidArgumentError, MongoMissingDependencyError } from './error';
5
- import { deserialize, serialize } from './bson';
6
+ import { MongoClient, MongoClientOptions } from './mongo_client';
6
7
  import type { Callback } from './utils';
7
- import { MONGO_CLIENT_EVENTS } from './operations/connect';
8
8
 
9
9
  let AutoEncrypterClass: AutoEncrypter;
10
10
 
@@ -46,6 +46,15 @@ export class Encrypter {
46
46
  options.autoEncryption.metadataClient = this.getInternalClient(client, uri, options);
47
47
  }
48
48
 
49
+ if (options.proxyHost) {
50
+ options.autoEncryption.proxyOptions = {
51
+ proxyHost: options.proxyHost,
52
+ proxyPort: options.proxyPort,
53
+ proxyUsername: options.proxyUsername,
54
+ proxyPassword: options.proxyPassword
55
+ };
56
+ }
57
+
49
58
  options.autoEncryption.bson = Object.create(null);
50
59
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
60
  options.autoEncryption.bson!.serialize = serialize;
package/src/error.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { TopologyVersion } from './sdam/server_description';
2
1
  import type { Document } from './bson';
2
+ import type { TopologyVersion } from './sdam/server_description';
3
3
  import type { TopologyDescription } from './sdam/topology_description';
4
4
 
5
5
  /** @public */
@@ -8,6 +8,27 @@ export type AnyError = MongoError | Error;
8
8
  /** @internal */
9
9
  const kErrorLabels = Symbol('errorLabels');
10
10
 
11
+ /**
12
+ * @internal
13
+ * The legacy error message from the server that indicates the node is not a writable primary
14
+ * https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
15
+ */
16
+ export const LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = 'not master';
17
+
18
+ /**
19
+ * @internal
20
+ * The legacy error message from the server that indicates the node is not a primary or secondary
21
+ * https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
22
+ */
23
+ export const LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = 'not master or secondary';
24
+
25
+ /**
26
+ * @internal
27
+ * The error message from the server that indicates the node is recovering
28
+ * https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
29
+ */
30
+ export const NODE_IS_RECOVERING_ERROR_MESSAGE = 'node is recovering';
31
+
11
32
  /** @internal MongoDB Error Codes */
12
33
  export const MONGODB_ERROR_CODES = Object.freeze({
13
34
  HostUnreachable: 6,
@@ -17,11 +38,11 @@ export const MONGODB_ERROR_CODES = Object.freeze({
17
38
  PrimarySteppedDown: 189,
18
39
  ExceededTimeLimit: 262,
19
40
  SocketException: 9001,
20
- NotMaster: 10107,
41
+ NotWritablePrimary: 10107,
21
42
  InterruptedAtShutdown: 11600,
22
43
  InterruptedDueToReplStateChange: 11602,
23
- NotMasterNoSlaveOk: 13435,
24
- NotMasterOrSecondary: 13436,
44
+ NotPrimaryNoSecondaryOk: 13435,
45
+ NotPrimaryOrSecondary: 13436,
25
46
  StaleShardVersion: 63,
26
47
  StaleEpoch: 150,
27
48
  StaleConfig: 13388,
@@ -46,11 +67,11 @@ export const GET_MORE_RESUMABLE_CODES = new Set<number>([
46
67
  MONGODB_ERROR_CODES.PrimarySteppedDown,
47
68
  MONGODB_ERROR_CODES.ExceededTimeLimit,
48
69
  MONGODB_ERROR_CODES.SocketException,
49
- MONGODB_ERROR_CODES.NotMaster,
70
+ MONGODB_ERROR_CODES.NotWritablePrimary,
50
71
  MONGODB_ERROR_CODES.InterruptedAtShutdown,
51
72
  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
52
- MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
53
- MONGODB_ERROR_CODES.NotMasterOrSecondary,
73
+ MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
74
+ MONGODB_ERROR_CODES.NotPrimaryOrSecondary,
54
75
  MONGODB_ERROR_CODES.StaleShardVersion,
55
76
  MONGODB_ERROR_CODES.StaleEpoch,
56
77
  MONGODB_ERROR_CODES.StaleConfig,
@@ -675,19 +696,19 @@ const RETRYABLE_ERROR_CODES = new Set<number>([
675
696
  MONGODB_ERROR_CODES.ShutdownInProgress,
676
697
  MONGODB_ERROR_CODES.PrimarySteppedDown,
677
698
  MONGODB_ERROR_CODES.SocketException,
678
- MONGODB_ERROR_CODES.NotMaster,
699
+ MONGODB_ERROR_CODES.NotWritablePrimary,
679
700
  MONGODB_ERROR_CODES.InterruptedAtShutdown,
680
701
  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
681
- MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
682
- MONGODB_ERROR_CODES.NotMasterOrSecondary
702
+ MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
703
+ MONGODB_ERROR_CODES.NotPrimaryOrSecondary
683
704
  ]);
684
705
 
685
706
  const RETRYABLE_WRITE_ERROR_CODES = new Set<number>([
686
707
  MONGODB_ERROR_CODES.InterruptedAtShutdown,
687
708
  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
688
- MONGODB_ERROR_CODES.NotMaster,
689
- MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
690
- MONGODB_ERROR_CODES.NotMasterOrSecondary,
709
+ MONGODB_ERROR_CODES.NotWritablePrimary,
710
+ MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
711
+ MONGODB_ERROR_CODES.NotPrimaryOrSecondary,
691
712
  MONGODB_ERROR_CODES.PrimarySteppedDown,
692
713
  MONGODB_ERROR_CODES.ShutdownInProgress,
693
714
  MONGODB_ERROR_CODES.HostNotFound,
@@ -697,6 +718,10 @@ const RETRYABLE_WRITE_ERROR_CODES = new Set<number>([
697
718
  MONGODB_ERROR_CODES.ExceededTimeLimit
698
719
  ]);
699
720
 
721
+ export function isRetryableEndTransactionError(error: MongoError): boolean {
722
+ return error.hasErrorLabel('RetryableWriteError');
723
+ }
724
+
700
725
  export function isRetryableWriteError(error: MongoError): boolean {
701
726
  if (error instanceof MongoWriteConcernError) {
702
727
  return RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? error.code ?? 0);
@@ -710,8 +735,8 @@ export function isRetryableError(error: MongoError): boolean {
710
735
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
711
736
  (typeof error.code === 'number' && RETRYABLE_ERROR_CODES.has(error.code!)) ||
712
737
  error instanceof MongoNetworkError ||
713
- !!error.message.match(/not master/) ||
714
- !!error.message.match(/node is recovering/)
738
+ !!error.message.match(new RegExp(LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE)) ||
739
+ !!error.message.match(new RegExp(NODE_IS_RECOVERING_ERROR_MESSAGE))
715
740
  );
716
741
  }
717
742
 
@@ -720,12 +745,12 @@ const SDAM_RECOVERING_CODES = new Set<number>([
720
745
  MONGODB_ERROR_CODES.PrimarySteppedDown,
721
746
  MONGODB_ERROR_CODES.InterruptedAtShutdown,
722
747
  MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
723
- MONGODB_ERROR_CODES.NotMasterOrSecondary
748
+ MONGODB_ERROR_CODES.NotPrimaryOrSecondary
724
749
  ]);
725
750
 
726
- const SDAM_NOTMASTER_CODES = new Set<number>([
727
- MONGODB_ERROR_CODES.NotMaster,
728
- MONGODB_ERROR_CODES.NotMasterNoSlaveOk,
751
+ const SDAM_NOTPRIMARY_CODES = new Set<number>([
752
+ MONGODB_ERROR_CODES.NotWritablePrimary,
753
+ MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
729
754
  MONGODB_ERROR_CODES.LegacyNotPrimary
730
755
  ]);
731
756
 
@@ -740,20 +765,23 @@ function isRecoveringError(err: MongoError) {
740
765
  return SDAM_RECOVERING_CODES.has(err.code);
741
766
  }
742
767
 
743
- return /not master or secondary/.test(err.message) || /node is recovering/.test(err.message);
768
+ return (
769
+ new RegExp(LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE).test(err.message) ||
770
+ new RegExp(NODE_IS_RECOVERING_ERROR_MESSAGE).test(err.message)
771
+ );
744
772
  }
745
773
 
746
- function isNotMasterError(err: MongoError) {
774
+ function isNotWritablePrimaryError(err: MongoError) {
747
775
  if (typeof err.code === 'number') {
748
776
  // If any error code exists, we ignore the error.message
749
- return SDAM_NOTMASTER_CODES.has(err.code);
777
+ return SDAM_NOTPRIMARY_CODES.has(err.code);
750
778
  }
751
779
 
752
780
  if (isRecoveringError(err)) {
753
781
  return false;
754
782
  }
755
783
 
756
- return /not master/.test(err.message);
784
+ return new RegExp(LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE).test(err.message);
757
785
  }
758
786
 
759
787
  export function isNodeShuttingDownError(err: MongoError): boolean {
@@ -774,7 +802,7 @@ export function isSDAMUnrecoverableError(error: MongoError): boolean {
774
802
  return true;
775
803
  }
776
804
 
777
- return isRecoveringError(error) || isNotMasterError(error);
805
+ return isRecoveringError(error) || isNotWritablePrimaryError(error);
778
806
  }
779
807
 
780
808
  export function isNetworkTimeoutError(err: MongoError): err is MongoNetworkError {
@@ -1,19 +1,19 @@
1
1
  import { Readable } from 'stream';
2
+
3
+ import type { Document, ObjectId } from '../bson';
4
+ import type { Collection } from '../collection';
5
+ import type { FindCursor } from '../cursor/find_cursor';
2
6
  import {
3
- MongoRuntimeError,
4
7
  MongoGridFSChunkError,
5
8
  MongoGridFSStreamError,
6
- MongoInvalidArgumentError
9
+ MongoInvalidArgumentError,
10
+ MongoRuntimeError
7
11
  } from '../error';
8
- import type { Document } from '../bson';
9
12
  import type { FindOptions } from '../operations/find';
13
+ import type { ReadPreference } from '../read_preference';
10
14
  import type { Sort } from '../sort';
11
15
  import type { Callback } from '../utils';
12
- import type { Collection } from '../collection';
13
- import type { ReadPreference } from '../read_preference';
14
16
  import type { GridFSChunk } from './upload';
15
- import type { FindCursor } from '../cursor/find_cursor';
16
- import type { ObjectId } from 'bson';
17
17
 
18
18
  /** @public */
19
19
  export interface GridFSBucketReadStreamOptions {
@@ -262,7 +262,9 @@ function doRead(stream: GridFSBucketReadStream): void {
262
262
  if (bytesRemaining <= 0) {
263
263
  return stream.emit(
264
264
  GridFSBucketReadStream.ERROR,
265
- new MongoGridFSChunkError(`ExtraChunk: Got unexpected n: ${doc.n}`)
265
+ new MongoGridFSChunkError(
266
+ `ExtraChunk: Got unexpected n: ${doc.n}, expected file length ${stream.s.file.length} bytes but already read ${stream.s.bytesRead} bytes`
267
+ )
266
268
  );
267
269
  }
268
270