mongodb 4.2.2 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +1 -1
  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 +3 -3
  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 +3 -3
  16. package/lib/cmap/auth/gssapi.js.map +1 -1
  17. package/lib/cmap/auth/mongo_credentials.js +16 -18
  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 +1 -1
  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 +102 -15
  36. package/lib/cmap/connect.js.map +1 -1
  37. package/lib/cmap/connection.js +27 -26
  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 +1 -1
  44. package/lib/cmap/stream_description.js.map +1 -1
  45. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  46. package/lib/cmap/wire_protocol/shared.js +4 -3
  47. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  48. package/lib/collection.js +45 -47
  49. package/lib/collection.js.map +1 -1
  50. package/lib/connection_string.js +48 -19
  51. package/lib/connection_string.js.map +1 -1
  52. package/lib/constants.js +108 -1
  53. package/lib/constants.js.map +1 -1
  54. package/lib/cursor/abstract_cursor.js +5 -5
  55. package/lib/cursor/abstract_cursor.js.map +1 -1
  56. package/lib/cursor/aggregation_cursor.js +1 -1
  57. package/lib/cursor/aggregation_cursor.js.map +1 -1
  58. package/lib/cursor/find_cursor.js +1 -1
  59. package/lib/cursor/find_cursor.js.map +1 -1
  60. package/lib/db.js +23 -13
  61. package/lib/db.js.map +1 -1
  62. package/lib/deps.js +0 -1
  63. package/lib/deps.js.map +1 -1
  64. package/lib/encrypter.js +12 -4
  65. package/lib/encrypter.js.map +1 -1
  66. package/lib/gridfs/download.js +1 -1
  67. package/lib/gridfs/download.js.map +1 -1
  68. package/lib/gridfs/index.js +3 -3
  69. package/lib/gridfs/index.js.map +1 -1
  70. package/lib/gridfs/upload.js +3 -2
  71. package/lib/gridfs/upload.js.map +1 -1
  72. package/lib/index.js +81 -81
  73. package/lib/index.js.map +1 -1
  74. package/lib/logger.js +1 -1
  75. package/lib/logger.js.map +1 -1
  76. package/lib/mongo_client.js +5 -5
  77. package/lib/mongo_client.js.map +1 -1
  78. package/lib/mongo_types.js.map +1 -1
  79. package/lib/operations/add_user.js +2 -2
  80. package/lib/operations/add_user.js.map +1 -1
  81. package/lib/operations/aggregate.js +1 -1
  82. package/lib/operations/aggregate.js.map +1 -1
  83. package/lib/operations/bulk_write.js.map +1 -1
  84. package/lib/operations/collections.js +1 -1
  85. package/lib/operations/collections.js.map +1 -1
  86. package/lib/operations/command.js +5 -6
  87. package/lib/operations/command.js.map +1 -1
  88. package/lib/operations/common_functions.js.map +1 -1
  89. package/lib/operations/connect.js +4 -13
  90. package/lib/operations/connect.js.map +1 -1
  91. package/lib/operations/count.js +1 -1
  92. package/lib/operations/count.js.map +1 -1
  93. package/lib/operations/count_documents.js.map +1 -1
  94. package/lib/operations/create_collection.js +3 -2
  95. package/lib/operations/create_collection.js.map +1 -1
  96. package/lib/operations/delete.js +3 -3
  97. package/lib/operations/delete.js.map +1 -1
  98. package/lib/operations/distinct.js +3 -3
  99. package/lib/operations/distinct.js.map +1 -1
  100. package/lib/operations/drop.js +1 -1
  101. package/lib/operations/drop.js.map +1 -1
  102. package/lib/operations/estimated_document_count.js +2 -2
  103. package/lib/operations/estimated_document_count.js.map +1 -1
  104. package/lib/operations/eval.js +2 -2
  105. package/lib/operations/eval.js.map +1 -1
  106. package/lib/operations/execute_operation.js +5 -6
  107. package/lib/operations/execute_operation.js.map +1 -1
  108. package/lib/operations/find.js +5 -5
  109. package/lib/operations/find.js.map +1 -1
  110. package/lib/operations/find_and_modify.js +2 -2
  111. package/lib/operations/find_and_modify.js.map +1 -1
  112. package/lib/operations/get_more.js.map +1 -1
  113. package/lib/operations/indexes.js +4 -4
  114. package/lib/operations/indexes.js.map +1 -1
  115. package/lib/operations/insert.js +3 -3
  116. package/lib/operations/insert.js.map +1 -1
  117. package/lib/operations/is_capped.js +1 -1
  118. package/lib/operations/is_capped.js.map +1 -1
  119. package/lib/operations/list_collections.js +3 -3
  120. package/lib/operations/list_collections.js.map +1 -1
  121. package/lib/operations/list_databases.js +1 -1
  122. package/lib/operations/list_databases.js.map +1 -1
  123. package/lib/operations/map_reduce.js +4 -3
  124. package/lib/operations/map_reduce.js.map +1 -1
  125. package/lib/operations/operation.js +1 -1
  126. package/lib/operations/operation.js.map +1 -1
  127. package/lib/operations/options_operation.js +1 -1
  128. package/lib/operations/options_operation.js.map +1 -1
  129. package/lib/operations/profiling_level.js +1 -1
  130. package/lib/operations/profiling_level.js.map +1 -1
  131. package/lib/operations/remove_user.js +1 -1
  132. package/lib/operations/remove_user.js.map +1 -1
  133. package/lib/operations/rename.js +3 -3
  134. package/lib/operations/rename.js.map +1 -1
  135. package/lib/operations/run_command.js +1 -1
  136. package/lib/operations/run_command.js.map +1 -1
  137. package/lib/operations/set_profiling_level.js +2 -2
  138. package/lib/operations/set_profiling_level.js.map +1 -1
  139. package/lib/operations/stats.js +1 -1
  140. package/lib/operations/stats.js.map +1 -1
  141. package/lib/operations/update.js +2 -2
  142. package/lib/operations/update.js.map +1 -1
  143. package/lib/operations/validate_collection.js +1 -1
  144. package/lib/operations/validate_collection.js.map +1 -1
  145. package/lib/read_preference.js +11 -4
  146. package/lib/read_preference.js.map +1 -1
  147. package/lib/sdam/monitor.js +4 -4
  148. package/lib/sdam/monitor.js.map +1 -1
  149. package/lib/sdam/server.js +24 -31
  150. package/lib/sdam/server.js.map +1 -1
  151. package/lib/sdam/server_description.js +1 -1
  152. package/lib/sdam/server_description.js.map +1 -1
  153. package/lib/sdam/server_selection.js +2 -2
  154. package/lib/sdam/server_selection.js.map +1 -1
  155. package/lib/sdam/srv_polling.js +2 -2
  156. package/lib/sdam/srv_polling.js.map +1 -1
  157. package/lib/sdam/topology.js +25 -55
  158. package/lib/sdam/topology.js.map +1 -1
  159. package/lib/sdam/topology_description.js +2 -2
  160. package/lib/sdam/topology_description.js.map +1 -1
  161. package/lib/sessions.js +12 -27
  162. package/lib/sessions.js.map +1 -1
  163. package/lib/transactions.js +1 -1
  164. package/lib/transactions.js.map +1 -1
  165. package/lib/utils.js +40 -9
  166. package/lib/utils.js.map +1 -1
  167. package/mongodb.d.ts +105 -32
  168. package/mongodb.ts34.d.ts +129 -32
  169. package/package.json +7 -3
  170. package/src/admin.ts +9 -9
  171. package/src/bson.ts +25 -17
  172. package/src/bulk/common.ts +17 -17
  173. package/src/bulk/ordered.ts +4 -4
  174. package/src/bulk/unordered.ts +5 -5
  175. package/src/change_stream.ts +25 -24
  176. package/src/cmap/auth/auth_provider.ts +3 -3
  177. package/src/cmap/auth/gssapi.ts +8 -8
  178. package/src/cmap/auth/mongo_credentials.ts +2 -6
  179. package/src/cmap/auth/mongocr.ts +3 -2
  180. package/src/cmap/auth/mongodb_aws.ts +10 -11
  181. package/src/cmap/auth/plain.ts +1 -1
  182. package/src/cmap/auth/providers.ts +21 -0
  183. package/src/cmap/auth/scram.ts +9 -9
  184. package/src/cmap/auth/x509.ts +3 -3
  185. package/src/cmap/command_monitoring_events.ts +2 -2
  186. package/src/cmap/commands.ts +22 -14
  187. package/src/cmap/connect.ts +142 -22
  188. package/src/cmap/connection.ts +72 -52
  189. package/src/cmap/connection_pool.ts +39 -39
  190. package/src/cmap/connection_pool_events.ts +1 -1
  191. package/src/cmap/message_stream.ts +9 -8
  192. package/src/cmap/stream_description.ts +2 -2
  193. package/src/cmap/wire_protocol/compression.ts +2 -2
  194. package/src/cmap/wire_protocol/shared.ts +10 -9
  195. package/src/collection.ts +94 -82
  196. package/src/connection_string.ts +66 -24
  197. package/src/constants.ts +116 -0
  198. package/src/cursor/abstract_cursor.ts +14 -13
  199. package/src/cursor/aggregation_cursor.ts +6 -6
  200. package/src/cursor/find_cursor.ts +2 -2
  201. package/src/db.ts +44 -33
  202. package/src/deps.ts +3 -1
  203. package/src/encrypter.ts +12 -3
  204. package/src/error.ts +1 -1
  205. package/src/gridfs/download.ts +10 -8
  206. package/src/gridfs/index.ts +11 -11
  207. package/src/gridfs/upload.ts +13 -10
  208. package/src/index.ts +204 -199
  209. package/src/logger.ts +2 -1
  210. package/src/mongo_client.ts +46 -32
  211. package/src/mongo_types.ts +97 -19
  212. package/src/operations/add_user.ts +6 -5
  213. package/src/operations/aggregate.ts +5 -5
  214. package/src/operations/bulk_write.ts +5 -5
  215. package/src/operations/collections.ts +2 -2
  216. package/src/operations/command.ts +15 -9
  217. package/src/operations/common_functions.ts +4 -4
  218. package/src/operations/connect.ts +4 -14
  219. package/src/operations/count.ts +4 -4
  220. package/src/operations/count_documents.ts +3 -3
  221. package/src/operations/create_collection.ts +7 -6
  222. package/src/operations/delete.ts +5 -5
  223. package/src/operations/distinct.ts +4 -4
  224. package/src/operations/drop.ts +4 -4
  225. package/src/operations/estimated_document_count.ts +5 -5
  226. package/src/operations/eval.ts +5 -5
  227. package/src/operations/execute_operation.ts +10 -11
  228. package/src/operations/find.ts +14 -14
  229. package/src/operations/find_and_modify.ts +7 -7
  230. package/src/operations/get_more.ts +2 -2
  231. package/src/operations/indexes.ts +16 -16
  232. package/src/operations/insert.ts +9 -9
  233. package/src/operations/is_capped.ts +3 -3
  234. package/src/operations/list_collections.ts +6 -6
  235. package/src/operations/list_databases.ts +4 -4
  236. package/src/operations/map_reduce.ts +10 -9
  237. package/src/operations/operation.ts +3 -3
  238. package/src/operations/options_operation.ts +3 -3
  239. package/src/operations/profiling_level.ts +4 -4
  240. package/src/operations/remove_user.ts +4 -4
  241. package/src/operations/rename.ts +6 -6
  242. package/src/operations/run_command.ts +3 -3
  243. package/src/operations/set_profiling_level.ts +6 -5
  244. package/src/operations/stats.ts +4 -4
  245. package/src/operations/update.ts +10 -10
  246. package/src/operations/validate_collection.ts +4 -4
  247. package/src/read_preference.ts +14 -6
  248. package/src/sdam/common.ts +2 -2
  249. package/src/sdam/events.ts +1 -1
  250. package/src/sdam/monitor.ts +13 -14
  251. package/src/sdam/server.ts +63 -61
  252. package/src/sdam/server_description.ts +4 -4
  253. package/src/sdam/server_selection.ts +3 -3
  254. package/src/sdam/srv_polling.ts +3 -2
  255. package/src/sdam/topology.ts +63 -81
  256. package/src/sdam/topology_description.ts +4 -4
  257. package/src/sessions.ts +30 -48
  258. package/src/transactions.ts +4 -4
  259. package/src/utils.ts +58 -22
  260. package/lib/cmap/auth/defaultAuthProviders.js +0 -30
  261. package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
  262. package/src/cmap/auth/defaultAuthProviders.ts +0 -32
@@ -1,14 +1,14 @@
1
- import { ReadPreference } from '../read_preference';
2
- import { maxWireVersion, decorateWithCollation, hasAtomicOperators, Callback } from '../utils';
3
- import { MongoInvalidArgumentError, MongoCompatibilityError } from '../error';
4
- import { CommandOperation, CommandOperationOptions } from './command';
5
- import { defineAspects, Aspect } from './operation';
6
1
  import type { Document } from '../bson';
7
- import type { Server } from '../sdam/server';
8
2
  import type { Collection } from '../collection';
9
- import { Sort, SortForCmd, formatSort } from '../sort';
3
+ import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
4
+ import { ReadPreference } from '../read_preference';
5
+ import type { Server } from '../sdam/server';
10
6
  import type { ClientSession } from '../sessions';
7
+ import { formatSort, Sort, SortForCmd } from '../sort';
8
+ import { Callback, decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
11
9
  import type { WriteConcern, WriteConcernSettings } from '../write_concern';
10
+ import { CommandOperation, CommandOperationOptions } from './command';
11
+ import { Aspect, defineAspects } from './operation';
12
12
 
13
13
  /** @public */
14
14
  export const ReturnDocument = Object.freeze({
@@ -1,9 +1,9 @@
1
1
  import type { Document, Long } from '../bson';
2
2
  import { MongoRuntimeError } from '../error';
3
- import type { Callback, MongoDBNamespace } from '../utils';
4
3
  import type { Server } from '../sdam/server';
5
- import { Aspect, AbstractOperation, OperationOptions, defineAspects } from './operation';
6
4
  import type { ClientSession } from '../sessions';
5
+ import type { Callback, MongoDBNamespace } from '../utils';
6
+ import { AbstractOperation, Aspect, defineAspects, OperationOptions } from './operation';
7
7
 
8
8
  /**
9
9
  * @public
@@ -1,28 +1,28 @@
1
- import { indexInformation, IndexInformationOptions } from './common_functions';
2
- import { AbstractOperation, Aspect, defineAspects } from './operation';
3
- import { MONGODB_ERROR_CODES, MongoServerError, MongoCompatibilityError } from '../error';
1
+ import type { Document } from '../bson';
2
+ import type { Collection } from '../collection';
3
+ import { AbstractCursor } from '../cursor/abstract_cursor';
4
+ import type { Db } from '../db';
5
+ import { MongoCompatibilityError, MONGODB_ERROR_CODES, MongoServerError } from '../error';
6
+ import type { OneOrMore } from '../mongo_types';
7
+ import { ReadPreference } from '../read_preference';
8
+ import type { Server } from '../sdam/server';
9
+ import type { ClientSession } from '../sessions';
4
10
  import {
11
+ Callback,
12
+ getTopology,
5
13
  maxWireVersion,
6
- parseIndexOptions,
7
14
  MongoDBNamespace,
8
- Callback,
9
- getTopology
15
+ parseIndexOptions
10
16
  } from '../utils';
11
17
  import {
18
+ CollationOptions,
12
19
  CommandOperation,
13
20
  CommandOperationOptions,
14
- OperationParent,
15
- CollationOptions
21
+ OperationParent
16
22
  } from './command';
17
- import { ReadPreference } from '../read_preference';
18
- import type { Server } from '../sdam/server';
19
- import type { Document } from '../bson';
20
- import type { Collection } from '../collection';
21
- import type { Db } from '../db';
22
- import { AbstractCursor } from '../cursor/abstract_cursor';
23
- import type { ClientSession } from '../sessions';
23
+ import { indexInformation, IndexInformationOptions } from './common_functions';
24
24
  import { executeOperation, ExecutionResult } from './execute_operation';
25
- import type { OneOrMore } from '../mongo_types';
25
+ import { AbstractOperation, Aspect, defineAspects } from './operation';
26
26
 
27
27
  const LIST_INDEXES_WIRE_VERSION = 3;
28
28
  const VALID_INDEX_OPTIONS = new Set([
@@ -1,16 +1,16 @@
1
- import { MongoServerError, MongoInvalidArgumentError } from '../error';
2
- import { defineAspects, Aspect, AbstractOperation } from './operation';
3
- import { CommandOperation, CommandOperationOptions } from './command';
4
- import { prepareDocs } from './common_functions';
5
- import type { Callback, MongoDBNamespace } from '../utils';
6
- import type { Server } from '../sdam/server';
7
- import type { Collection } from '../collection';
8
1
  import type { Document } from '../bson';
9
2
  import type { BulkWriteOptions } from '../bulk/common';
10
- import { WriteConcern } from '../write_concern';
3
+ import type { Collection } from '../collection';
4
+ import { MongoInvalidArgumentError, MongoServerError } from '../error';
5
+ import type { InferIdType } from '../mongo_types';
6
+ import type { Server } from '../sdam/server';
11
7
  import type { ClientSession } from '../sessions';
8
+ import type { Callback, MongoDBNamespace } from '../utils';
9
+ import { WriteConcern } from '../write_concern';
12
10
  import { BulkWriteOperation } from './bulk_write';
13
- import type { InferIdType } from '../mongo_types';
11
+ import { CommandOperation, CommandOperationOptions } from './command';
12
+ import { prepareDocs } from './common_functions';
13
+ import { AbstractOperation, Aspect, defineAspects } from './operation';
14
14
 
15
15
  /** @internal */
16
16
  export class InsertOperation extends CommandOperation<Document> {
@@ -1,9 +1,9 @@
1
- import type { Callback } from '../utils';
2
1
  import type { Collection } from '../collection';
3
- import { OperationOptions, AbstractOperation } from './operation';
2
+ import { MongoAPIError } from '../error';
4
3
  import type { Server } from '../sdam/server';
5
4
  import type { ClientSession } from '../sessions';
6
- import { MongoAPIError } from '../error';
5
+ import type { Callback } from '../utils';
6
+ import { AbstractOperation, OperationOptions } from './operation';
7
7
 
8
8
  /** @internal */
9
9
  export class IsCappedOperation extends AbstractOperation<boolean> {
@@ -1,13 +1,13 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import { Aspect, defineAspects } from './operation';
3
- import { maxWireVersion, Callback, getTopology, MongoDBNamespace } from '../utils';
4
- import * as CONSTANTS from '../constants';
5
1
  import type { Binary, Document } from '../bson';
6
- import type { Server } from '../sdam/server';
7
- import type { Db } from '../db';
2
+ import * as CONSTANTS from '../constants';
8
3
  import { AbstractCursor } from '../cursor/abstract_cursor';
4
+ import type { Db } from '../db';
5
+ import type { Server } from '../sdam/server';
9
6
  import type { ClientSession } from '../sessions';
7
+ import { Callback, getTopology, maxWireVersion, MongoDBNamespace } from '../utils';
8
+ import { CommandOperation, CommandOperationOptions } from './command';
10
9
  import { executeOperation, ExecutionResult } from './execute_operation';
10
+ import { Aspect, defineAspects } from './operation';
11
11
 
12
12
  const LIST_COLLECTIONS_WIRE_VERSION = 3;
13
13
 
@@ -1,10 +1,10 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import { Aspect, defineAspects } from './operation';
3
- import { MongoDBNamespace, Callback } from '../utils';
4
1
  import type { Document } from '../bson';
5
- import type { Server } from '../sdam/server';
6
2
  import type { Db } from '../db';
3
+ import type { Server } from '../sdam/server';
7
4
  import type { ClientSession } from '../sessions';
5
+ import { Callback, MongoDBNamespace } from '../utils';
6
+ import { CommandOperation, CommandOperationOptions } from './command';
7
+ import { Aspect, defineAspects } from './operation';
8
8
 
9
9
  /** @public */
10
10
  export interface ListDatabasesResult {
@@ -1,22 +1,22 @@
1
+ import type { ObjectId } from '../bson';
1
2
  import { Code, Document } from '../bson';
3
+ import type { Collection } from '../collection';
4
+ import { Db } from '../db';
5
+ import { MongoCompatibilityError, MongoServerError } from '../error';
6
+ import { ReadPreference, ReadPreferenceMode } from '../read_preference';
7
+ import type { Server } from '../sdam/server';
8
+ import type { ClientSession } from '../sessions';
9
+ import type { Sort } from '../sort';
2
10
  import {
3
11
  applyWriteConcern,
12
+ Callback,
4
13
  decorateWithCollation,
5
14
  decorateWithReadConcern,
6
15
  isObject,
7
- Callback,
8
16
  maxWireVersion
9
17
  } from '../utils';
10
- import { ReadPreference, ReadPreferenceMode } from '../read_preference';
11
18
  import { CommandOperation, CommandOperationOptions } from './command';
12
- import type { Server } from '../sdam/server';
13
- import type { Collection } from '../collection';
14
- import type { Sort } from '../sort';
15
- import { MongoServerError, MongoCompatibilityError } from '../error';
16
- import type { ObjectId } from '../bson';
17
19
  import { Aspect, defineAspects } from './operation';
18
- import type { ClientSession } from '../sessions';
19
- import { Db } from '../db';
20
20
 
21
21
  const exclusionList = [
22
22
  'explain',
@@ -33,6 +33,7 @@ const exclusionList = [
33
33
  'bsonRegExp',
34
34
  'serializeFunctions',
35
35
  'ignoreUndefined',
36
+ 'enableUtf8Validation',
36
37
  'scope' // this option is reformatted thus exclude the original
37
38
  ];
38
39
 
@@ -1,8 +1,8 @@
1
+ import { BSONSerializeOptions, Document, resolveBSONOptions } from '../bson';
1
2
  import { ReadPreference, ReadPreferenceLike } from '../read_preference';
2
- import type { ClientSession } from '../sessions';
3
- import { Document, BSONSerializeOptions, resolveBSONOptions } from '../bson';
4
- import type { MongoDBNamespace, Callback } from '../utils';
5
3
  import type { Server } from '../sdam/server';
4
+ import type { ClientSession } from '../sessions';
5
+ import type { Callback, MongoDBNamespace } from '../utils';
6
6
 
7
7
  export const Aspect = {
8
8
  READ_OPERATION: Symbol('READ_OPERATION'),
@@ -1,10 +1,10 @@
1
- import { AbstractOperation, OperationOptions } from './operation';
2
- import { MongoAPIError } from '../error';
3
- import type { Callback } from '../utils';
4
1
  import type { Document } from '../bson';
5
2
  import type { Collection } from '../collection';
3
+ import { MongoAPIError } from '../error';
6
4
  import type { Server } from '../sdam/server';
7
5
  import type { ClientSession } from '../sessions';
6
+ import type { Callback } from '../utils';
7
+ import { AbstractOperation, OperationOptions } from './operation';
8
8
 
9
9
  /** @internal */
10
10
  export class OptionsOperation extends AbstractOperation<Document> {
@@ -1,9 +1,9 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import type { Callback } from '../utils';
3
- import type { Server } from '../sdam/server';
4
1
  import type { Db } from '../db';
5
- import type { ClientSession } from '../sessions';
6
2
  import { MongoRuntimeError } from '../error';
3
+ import type { Server } from '../sdam/server';
4
+ import type { ClientSession } from '../sessions';
5
+ import type { Callback } from '../utils';
6
+ import { CommandOperation, CommandOperationOptions } from './command';
7
7
 
8
8
  /** @public */
9
9
  export type ProfilingLevelOptions = CommandOperationOptions;
@@ -1,9 +1,9 @@
1
- import { Aspect, defineAspects } from './operation';
2
- import { CommandOperation, CommandOperationOptions } from './command';
3
- import type { Callback } from '../utils';
4
- import type { Server } from '../sdam/server';
5
1
  import type { Db } from '../db';
2
+ import type { Server } from '../sdam/server';
6
3
  import type { ClientSession } from '../sessions';
4
+ import type { Callback } from '../utils';
5
+ import { CommandOperation, CommandOperationOptions } from './command';
6
+ import { Aspect, defineAspects } from './operation';
7
7
 
8
8
  /** @public */
9
9
  export type RemoveUserOptions = CommandOperationOptions;
@@ -1,12 +1,12 @@
1
- import { checkCollectionName, Callback } from '../utils';
2
- import { RunAdminCommandOperation } from './run_command';
3
- import { defineAspects, Aspect } from './operation';
4
- import type { Server } from '../sdam/server';
1
+ import type { Document } from '../bson';
5
2
  import { Collection } from '../collection';
6
- import type { CommandOperationOptions } from './command';
7
3
  import { MongoServerError } from '../error';
4
+ import type { Server } from '../sdam/server';
8
5
  import type { ClientSession } from '../sessions';
9
- import type { Document } from 'bson';
6
+ import { Callback, checkCollectionName } from '../utils';
7
+ import type { CommandOperationOptions } from './command';
8
+ import { Aspect, defineAspects } from './operation';
9
+ import { RunAdminCommandOperation } from './run_command';
10
10
 
11
11
  /** @public */
12
12
  export interface RenameOptions extends CommandOperationOptions {
@@ -1,8 +1,8 @@
1
- import { CommandOperation, CommandOperationOptions, OperationParent } from './command';
2
- import { MongoDBNamespace, Callback } from '../utils';
3
- import type { Server } from '../sdam/server';
4
1
  import type { Document } from '../bson';
2
+ import type { Server } from '../sdam/server';
5
3
  import type { ClientSession } from '../sessions';
4
+ import { Callback, MongoDBNamespace } from '../utils';
5
+ import { CommandOperation, CommandOperationOptions, OperationParent } from './command';
6
6
 
7
7
  /** @public */
8
8
  export type RunCommandOptions = CommandOperationOptions;
@@ -1,10 +1,11 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import type { Callback } from '../utils';
3
- import { enumToString } from '../utils';
4
- import type { Server } from '../sdam/server';
5
1
  import type { Db } from '../db';
2
+ import { MongoInvalidArgumentError, MongoRuntimeError } from '../error';
3
+ import type { Server } from '../sdam/server';
6
4
  import type { ClientSession } from '../sessions';
7
- import { MongoRuntimeError, MongoInvalidArgumentError } from '../error';
5
+ import type { Callback } from '../utils';
6
+ import { enumToString } from '../utils';
7
+ import { CommandOperation, CommandOperationOptions } from './command';
8
+
8
9
  const levelValues = new Set(['off', 'slow_only', 'all']);
9
10
 
10
11
  /** @public */
@@ -1,11 +1,11 @@
1
- import { Aspect, defineAspects } from './operation';
2
- import { CommandOperation, CommandOperationOptions } from './command';
3
- import type { Callback } from '../utils';
4
1
  import type { Document } from '../bson';
5
- import type { Server } from '../sdam/server';
6
2
  import type { Collection } from '../collection';
7
3
  import type { Db } from '../db';
4
+ import type { Server } from '../sdam/server';
8
5
  import type { ClientSession } from '../sessions';
6
+ import type { Callback } from '../utils';
7
+ import { CommandOperation, CommandOperationOptions } from './command';
8
+ import { Aspect, defineAspects } from './operation';
9
9
 
10
10
  /** @public */
11
11
  export interface CollStatsOptions extends CommandOperationOptions {
@@ -1,17 +1,17 @@
1
- import { defineAspects, Aspect, Hint } from './operation';
1
+ import type { Document, ObjectId } from '../bson';
2
+ import type { Collection } from '../collection';
3
+ import { MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } from '../error';
4
+ import type { Server } from '../sdam/server';
5
+ import type { ClientSession } from '../sessions';
2
6
  import {
3
- hasAtomicOperators,
4
- MongoDBNamespace,
5
7
  Callback,
6
8
  collationNotSupported,
7
- maxWireVersion
9
+ hasAtomicOperators,
10
+ maxWireVersion,
11
+ MongoDBNamespace
8
12
  } from '../utils';
9
- import { CommandOperation, CommandOperationOptions, CollationOptions } from './command';
10
- import type { Server } from '../sdam/server';
11
- import type { Collection } from '../collection';
12
- import type { ObjectId, Document } from '../bson';
13
- import type { ClientSession } from '../sessions';
14
- import { MongoServerError, MongoInvalidArgumentError, MongoCompatibilityError } from '../error';
13
+ import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
14
+ import { Aspect, defineAspects, Hint } from './operation';
15
15
 
16
16
  /** @public */
17
17
  export interface UpdateOptions extends CommandOperationOptions {
@@ -1,10 +1,10 @@
1
- import { CommandOperation, CommandOperationOptions } from './command';
2
- import type { Callback } from '../utils';
1
+ import type { Admin } from '../admin';
3
2
  import type { Document } from '../bson';
3
+ import { MongoRuntimeError } from '../error';
4
4
  import type { Server } from '../sdam/server';
5
- import type { Admin } from '../admin';
6
5
  import type { ClientSession } from '../sessions';
7
- import { MongoRuntimeError } from '../error';
6
+ import type { Callback } from '../utils';
7
+ import { CommandOperation, CommandOperationOptions } from './command';
8
8
 
9
9
  /** @public */
10
10
  export interface ValidateCollectionOptions extends CommandOperationOptions {
@@ -1,7 +1,7 @@
1
- import type { TagSet } from './sdam/server_description';
2
1
  import type { Document } from './bson';
3
- import type { ClientSession } from './sessions';
4
2
  import { MongoInvalidArgumentError } from './error';
3
+ import type { TagSet } from './sdam/server_description';
4
+ import type { ClientSession } from './sessions';
5
5
 
6
6
  /** @public */
7
7
  export type ReadPreferenceLike = ReadPreference | ReadPreferenceMode;
@@ -232,19 +232,27 @@ export class ReadPreference {
232
232
  }
233
233
 
234
234
  /**
235
- * Indicates that this readPreference needs the "slaveOk" bit when sent over the wire
236
- *
235
+ * Indicates that this readPreference needs the "secondaryOk" bit when sent over the wire
236
+ * @deprecated Use secondaryOk instead
237
237
  * @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
238
238
  */
239
239
  slaveOk(): boolean {
240
- const NEEDS_SLAVEOK = new Set<string>([
240
+ return this.secondaryOk();
241
+ }
242
+
243
+ /**
244
+ * Indicates that this readPreference needs the "SecondaryOk" bit when sent over the wire
245
+ * @see https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#op-query
246
+ */
247
+ secondaryOk(): boolean {
248
+ const NEEDS_SECONDARYOK = new Set<string>([
241
249
  ReadPreference.PRIMARY_PREFERRED,
242
250
  ReadPreference.SECONDARY,
243
251
  ReadPreference.SECONDARY_PREFERRED,
244
252
  ReadPreference.NEAREST
245
253
  ]);
246
254
 
247
- return NEEDS_SLAVEOK.has(this.mode);
255
+ return NEEDS_SECONDARYOK.has(this.mode);
248
256
  }
249
257
 
250
258
  /**
@@ -1,6 +1,6 @@
1
- import type { Timestamp, Binary, Long } from '../bson';
2
- import type { Topology } from './topology';
1
+ import type { Binary, Long, Timestamp } from '../bson';
3
2
  import type { ClientSession } from '../sessions';
3
+ import type { Topology } from './topology';
4
4
 
5
5
  // shared state names
6
6
  export const STATE_CLOSING = 'closing';
@@ -1,6 +1,6 @@
1
+ import type { Document } from '../bson';
1
2
  import type { ServerDescription } from './server_description';
2
3
  import type { TopologyDescription } from './topology_description';
3
- import type { Document } from '../bson';
4
4
 
5
5
  /**
6
6
  * Emitted when server description changes, but does NOT include changes to the RTT.
@@ -1,26 +1,25 @@
1
- import { ServerType, STATE_CLOSED, STATE_CLOSING } from './common';
1
+ import { Document, Long } from '../bson';
2
+ import { connect } from '../cmap/connect';
3
+ import { Connection, ConnectionOptions } from '../cmap/connection';
4
+ import { AnyError, MongoNetworkError } from '../error';
5
+ import { CancellationToken, TypedEventEmitter } from '../mongo_types';
6
+ import type { Callback, InterruptibleAsyncInterval } from '../utils';
2
7
  import {
3
- now,
4
- makeStateMachine,
5
8
  calculateDurationInMs,
9
+ EventEmitterWithState,
6
10
  makeInterruptibleAsyncInterval,
7
- ns,
8
- EventEmitterWithState
11
+ makeStateMachine,
12
+ now,
13
+ ns
9
14
  } from '../utils';
10
- import { connect } from '../cmap/connect';
11
- import { Connection, ConnectionOptions } from '../cmap/connection';
12
- import { MongoNetworkError, AnyError } from '../error';
13
- import { Long, Document } from '../bson';
15
+ import { ServerType, STATE_CLOSED, STATE_CLOSING } from './common';
14
16
  import {
17
+ ServerHeartbeatFailedEvent,
15
18
  ServerHeartbeatStartedEvent,
16
- ServerHeartbeatSucceededEvent,
17
- ServerHeartbeatFailedEvent
19
+ ServerHeartbeatSucceededEvent
18
20
  } from './events';
19
-
20
21
  import { Server } from './server';
21
- import type { InterruptibleAsyncInterval, Callback } from '../utils';
22
22
  import type { TopologyVersion } from './server_description';
23
- import { CancellationToken, TypedEventEmitter } from '../mongo_types';
24
23
 
25
24
  /** @internal */
26
25
  const kServer = Symbol('server');
@@ -1,62 +1,72 @@
1
- import { Logger } from '../logger';
1
+ import type { Document, Long } from '../bson';
2
+ import {
3
+ CommandOptions,
4
+ Connection,
5
+ DestroyOptions,
6
+ GetMoreOptions,
7
+ QueryOptions
8
+ } from '../cmap/connection';
2
9
  import {
3
10
  ConnectionPool,
4
- ConnectionPoolOptions,
5
- CMAP_EVENTS,
6
- ConnectionPoolEvents
11
+ ConnectionPoolEvents,
12
+ ConnectionPoolOptions
7
13
  } from '../cmap/connection_pool';
8
- import { ServerDescription, compareTopologyVersion } from './server_description';
9
- import { Monitor, MonitorOptions } from './monitor';
14
+ import {
15
+ APM_EVENTS,
16
+ CLOSED,
17
+ CMAP_EVENTS,
18
+ CONNECT,
19
+ DESCRIPTION_RECEIVED,
20
+ ENDED,
21
+ HEARTBEAT_EVENTS,
22
+ SERVER_HEARTBEAT_FAILED,
23
+ SERVER_HEARTBEAT_STARTED,
24
+ SERVER_HEARTBEAT_SUCCEEDED
25
+ } from '../constants';
26
+ import type { AutoEncrypter } from '../deps';
27
+ import {
28
+ isNetworkErrorBeforeHandshake,
29
+ isNodeShuttingDownError,
30
+ isRetryableWriteError,
31
+ isSDAMUnrecoverableError,
32
+ MongoCompatibilityError,
33
+ MongoError,
34
+ MongoInvalidArgumentError,
35
+ MongoNetworkError,
36
+ MongoNetworkTimeoutError,
37
+ MongoServerClosedError
38
+ } from '../error';
39
+ import { Logger } from '../logger';
40
+ import type { ServerApi } from '../mongo_client';
41
+ import { TypedEventEmitter } from '../mongo_types';
42
+ import type { ClientSession } from '../sessions';
10
43
  import { isTransactionCommand } from '../transactions';
11
44
  import {
45
+ Callback,
46
+ CallbackWithType,
12
47
  collationNotSupported,
48
+ EventEmitterWithState,
13
49
  makeStateMachine,
14
50
  maxWireVersion,
15
- Callback,
16
- CallbackWithType,
17
51
  MongoDBNamespace,
18
- EventEmitterWithState
52
+ supportsRetryableWrites
19
53
  } from '../utils';
20
54
  import {
55
+ ClusterTime,
21
56
  STATE_CLOSED,
22
57
  STATE_CLOSING,
23
- STATE_CONNECTING,
24
58
  STATE_CONNECTED,
25
- ClusterTime,
59
+ STATE_CONNECTING,
26
60
  TopologyType
27
61
  } from './common';
28
- import {
29
- MongoError,
30
- MongoNetworkError,
31
- MongoNetworkTimeoutError,
32
- isSDAMUnrecoverableError,
33
- isRetryableWriteError,
34
- isNodeShuttingDownError,
35
- isNetworkErrorBeforeHandshake,
36
- MongoCompatibilityError,
37
- MongoInvalidArgumentError,
38
- MongoServerClosedError
39
- } from '../error';
40
- import {
41
- Connection,
42
- DestroyOptions,
43
- QueryOptions,
44
- GetMoreOptions,
45
- CommandOptions,
46
- APM_EVENTS
47
- } from '../cmap/connection';
48
- import type { Topology } from './topology';
49
62
  import type {
50
63
  ServerHeartbeatFailedEvent,
51
64
  ServerHeartbeatStartedEvent,
52
65
  ServerHeartbeatSucceededEvent
53
66
  } from './events';
54
- import type { ClientSession } from '../sessions';
55
- import type { Document, Long } from '../bson';
56
- import type { AutoEncrypter } from '../deps';
57
- import type { ServerApi } from '../mongo_client';
58
- import { TypedEventEmitter } from '../mongo_types';
59
- import { supportsRetryableWrites } from '../utils';
67
+ import { Monitor, MonitorOptions } from './monitor';
68
+ import { compareTopologyVersion, ServerDescription } from './server_description';
69
+ import type { Topology } from './topology';
60
70
 
61
71
  const stateTransition = makeStateMachine({
62
72
  [STATE_CLOSED]: [STATE_CLOSED, STATE_CONNECTING],
@@ -108,24 +118,23 @@ export class Server extends TypedEventEmitter<ServerEvents> {
108
118
  /** @internal */
109
119
  s: ServerPrivate;
110
120
  serverApi?: ServerApi;
111
- clusterTime?: ClusterTime;
112
121
  ismaster?: Document;
113
122
  [kMonitor]: Monitor;
114
123
 
115
124
  /** @event */
116
- static readonly SERVER_HEARTBEAT_STARTED = 'serverHeartbeatStarted' as const;
125
+ static readonly SERVER_HEARTBEAT_STARTED = SERVER_HEARTBEAT_STARTED;
117
126
  /** @event */
118
- static readonly SERVER_HEARTBEAT_SUCCEEDED = 'serverHeartbeatSucceeded' as const;
127
+ static readonly SERVER_HEARTBEAT_SUCCEEDED = SERVER_HEARTBEAT_SUCCEEDED;
119
128
  /** @event */
120
- static readonly SERVER_HEARTBEAT_FAILED = 'serverHeartbeatFailed' as const;
129
+ static readonly SERVER_HEARTBEAT_FAILED = SERVER_HEARTBEAT_FAILED;
121
130
  /** @event */
122
- static readonly CONNECT = 'connect' as const;
131
+ static readonly CONNECT = CONNECT;
123
132
  /** @event */
124
- static readonly DESCRIPTION_RECEIVED = 'descriptionReceived' as const;
133
+ static readonly DESCRIPTION_RECEIVED = DESCRIPTION_RECEIVED;
125
134
  /** @event */
126
- static readonly CLOSED = 'closed' as const;
135
+ static readonly CLOSED = CLOSED;
127
136
  /** @event */
128
- static readonly ENDED = 'ended' as const;
137
+ static readonly ENDED = ENDED;
129
138
 
130
139
  /**
131
140
  * Create a server
@@ -184,6 +193,14 @@ export class Server extends TypedEventEmitter<ServerEvents> {
184
193
  });
185
194
  }
186
195
 
196
+ get clusterTime(): ClusterTime | undefined {
197
+ return this.s.topology.clusterTime;
198
+ }
199
+
200
+ set clusterTime(clusterTime: ClusterTime | undefined) {
201
+ this.s.topology.clusterTime = clusterTime;
202
+ }
203
+
187
204
  get description(): ServerDescription {
188
205
  return this.s.description;
189
206
  }
@@ -453,21 +470,6 @@ export class Server extends TypedEventEmitter<ServerEvents> {
453
470
  }
454
471
  }
455
472
 
456
- export const HEARTBEAT_EVENTS = [
457
- Server.SERVER_HEARTBEAT_STARTED,
458
- Server.SERVER_HEARTBEAT_SUCCEEDED,
459
- Server.SERVER_HEARTBEAT_FAILED
460
- ];
461
-
462
- Object.defineProperty(Server.prototype, 'clusterTime', {
463
- get() {
464
- return this.s.topology.clusterTime;
465
- },
466
- set(clusterTime: ClusterTime) {
467
- this.s.topology.clusterTime = clusterTime;
468
- }
469
- });
470
-
471
473
  function calculateRoundTripTime(oldRtt: number, duration: number): number {
472
474
  if (oldRtt === -1) {
473
475
  return duration;