mongodb 4.2.0 → 4.3.1

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 (267) 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 -7
  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 +24 -26
  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 +20 -11
  34. package/lib/cmap/commands.js.map +1 -1
  35. package/lib/cmap/connect.js +119 -31
  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 +45 -47
  50. package/lib/collection.js.map +1 -1
  51. package/lib/connection_string.js +48 -23
  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 +10 -7
  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 +1 -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 +81 -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 +15 -9
  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 +28 -0
  116. package/lib/operations/get_more.js.map +1 -0
  117. package/lib/operations/indexes.js +4 -4
  118. package/lib/operations/indexes.js.map +1 -1
  119. package/lib/operations/insert.js +3 -3
  120. package/lib/operations/insert.js.map +1 -1
  121. package/lib/operations/is_capped.js +1 -1
  122. package/lib/operations/is_capped.js.map +1 -1
  123. package/lib/operations/list_collections.js +3 -3
  124. package/lib/operations/list_collections.js.map +1 -1
  125. package/lib/operations/list_databases.js +1 -1
  126. package/lib/operations/list_databases.js.map +1 -1
  127. package/lib/operations/map_reduce.js +4 -3
  128. package/lib/operations/map_reduce.js.map +1 -1
  129. package/lib/operations/operation.js +3 -2
  130. package/lib/operations/operation.js.map +1 -1
  131. package/lib/operations/options_operation.js +1 -1
  132. package/lib/operations/options_operation.js.map +1 -1
  133. package/lib/operations/profiling_level.js +1 -1
  134. package/lib/operations/profiling_level.js.map +1 -1
  135. package/lib/operations/remove_user.js +1 -1
  136. package/lib/operations/remove_user.js.map +1 -1
  137. package/lib/operations/rename.js +3 -3
  138. package/lib/operations/rename.js.map +1 -1
  139. package/lib/operations/run_command.js +1 -1
  140. package/lib/operations/run_command.js.map +1 -1
  141. package/lib/operations/set_profiling_level.js +2 -2
  142. package/lib/operations/set_profiling_level.js.map +1 -1
  143. package/lib/operations/stats.js +1 -1
  144. package/lib/operations/stats.js.map +1 -1
  145. package/lib/operations/update.js +2 -2
  146. package/lib/operations/update.js.map +1 -1
  147. package/lib/operations/validate_collection.js +1 -1
  148. package/lib/operations/validate_collection.js.map +1 -1
  149. package/lib/read_preference.js +15 -5
  150. package/lib/read_preference.js.map +1 -1
  151. package/lib/sdam/events.js +4 -4
  152. package/lib/sdam/monitor.js +19 -18
  153. package/lib/sdam/monitor.js.map +1 -1
  154. package/lib/sdam/server.js +24 -31
  155. package/lib/sdam/server.js.map +1 -1
  156. package/lib/sdam/server_description.js +38 -38
  157. package/lib/sdam/server_description.js.map +1 -1
  158. package/lib/sdam/server_selection.js +19 -3
  159. package/lib/sdam/server_selection.js.map +1 -1
  160. package/lib/sdam/srv_polling.js +2 -2
  161. package/lib/sdam/srv_polling.js.map +1 -1
  162. package/lib/sdam/topology.js +32 -62
  163. package/lib/sdam/topology.js.map +1 -1
  164. package/lib/sdam/topology_description.js +3 -3
  165. package/lib/sdam/topology_description.js.map +1 -1
  166. package/lib/sessions.js +13 -28
  167. package/lib/sessions.js.map +1 -1
  168. package/lib/transactions.js +1 -1
  169. package/lib/transactions.js.map +1 -1
  170. package/lib/utils.js +46 -15
  171. package/lib/utils.js.map +1 -1
  172. package/mongodb.d.ts +145 -61
  173. package/mongodb.ts34.d.ts +173 -60
  174. package/package.json +29 -28
  175. package/src/admin.ts +9 -9
  176. package/src/bson.ts +26 -17
  177. package/src/bulk/common.ts +22 -23
  178. package/src/bulk/ordered.ts +4 -4
  179. package/src/bulk/unordered.ts +5 -5
  180. package/src/change_stream.ts +31 -28
  181. package/src/cmap/auth/auth_provider.ts +3 -3
  182. package/src/cmap/auth/gssapi.ts +8 -8
  183. package/src/cmap/auth/mongo_credentials.ts +11 -15
  184. package/src/cmap/auth/mongocr.ts +3 -2
  185. package/src/cmap/auth/mongodb_aws.ts +10 -11
  186. package/src/cmap/auth/plain.ts +1 -1
  187. package/src/cmap/auth/providers.ts +21 -0
  188. package/src/cmap/auth/scram.ts +9 -9
  189. package/src/cmap/auth/x509.ts +3 -3
  190. package/src/cmap/command_monitoring_events.ts +4 -3
  191. package/src/cmap/commands.ts +30 -19
  192. package/src/cmap/connect.ts +161 -37
  193. package/src/cmap/connection.ts +83 -63
  194. package/src/cmap/connection_pool.ts +39 -39
  195. package/src/cmap/connection_pool_events.ts +1 -1
  196. package/src/cmap/message_stream.ts +9 -8
  197. package/src/cmap/stream_description.ts +5 -5
  198. package/src/cmap/wire_protocol/compression.ts +4 -3
  199. package/src/cmap/wire_protocol/shared.ts +10 -9
  200. package/src/collection.ts +114 -95
  201. package/src/connection_string.ts +66 -29
  202. package/src/constants.ts +122 -0
  203. package/src/cursor/abstract_cursor.ts +21 -22
  204. package/src/cursor/aggregation_cursor.ts +6 -6
  205. package/src/cursor/find_cursor.ts +2 -2
  206. package/src/db.ts +44 -33
  207. package/src/deps.ts +3 -1
  208. package/src/encrypter.ts +12 -3
  209. package/src/error.ts +52 -24
  210. package/src/gridfs/download.ts +10 -8
  211. package/src/gridfs/index.ts +11 -11
  212. package/src/gridfs/upload.ts +13 -10
  213. package/src/index.ts +204 -199
  214. package/src/logger.ts +2 -1
  215. package/src/mongo_client.ts +46 -32
  216. package/src/mongo_types.ts +119 -21
  217. package/src/operations/add_user.ts +7 -6
  218. package/src/operations/aggregate.ts +5 -5
  219. package/src/operations/bulk_write.ts +5 -5
  220. package/src/operations/collections.ts +2 -2
  221. package/src/operations/command.ts +15 -9
  222. package/src/operations/common_functions.ts +4 -4
  223. package/src/operations/connect.ts +4 -14
  224. package/src/operations/count.ts +4 -4
  225. package/src/operations/count_documents.ts +3 -3
  226. package/src/operations/create_collection.ts +7 -6
  227. package/src/operations/delete.ts +5 -5
  228. package/src/operations/distinct.ts +4 -4
  229. package/src/operations/drop.ts +4 -4
  230. package/src/operations/estimated_document_count.ts +5 -5
  231. package/src/operations/eval.ts +5 -5
  232. package/src/operations/execute_operation.ts +21 -13
  233. package/src/operations/find.ts +14 -14
  234. package/src/operations/find_and_modify.ts +7 -7
  235. package/src/operations/get_more.ts +49 -0
  236. package/src/operations/indexes.ts +16 -16
  237. package/src/operations/insert.ts +9 -9
  238. package/src/operations/is_capped.ts +3 -3
  239. package/src/operations/list_collections.ts +6 -6
  240. package/src/operations/list_databases.ts +4 -4
  241. package/src/operations/map_reduce.ts +10 -9
  242. package/src/operations/operation.ts +5 -4
  243. package/src/operations/options_operation.ts +3 -3
  244. package/src/operations/profiling_level.ts +4 -4
  245. package/src/operations/remove_user.ts +4 -4
  246. package/src/operations/rename.ts +6 -6
  247. package/src/operations/run_command.ts +3 -3
  248. package/src/operations/set_profiling_level.ts +6 -5
  249. package/src/operations/stats.ts +4 -4
  250. package/src/operations/update.ts +10 -10
  251. package/src/operations/validate_collection.ts +4 -4
  252. package/src/read_preference.ts +18 -7
  253. package/src/sdam/common.ts +2 -2
  254. package/src/sdam/events.ts +5 -5
  255. package/src/sdam/monitor.ts +29 -32
  256. package/src/sdam/server.ts +64 -62
  257. package/src/sdam/server_description.ts +41 -48
  258. package/src/sdam/server_selection.ts +21 -3
  259. package/src/sdam/srv_polling.ts +3 -2
  260. package/src/sdam/topology.ts +71 -89
  261. package/src/sdam/topology_description.ts +5 -5
  262. package/src/sessions.ts +31 -48
  263. package/src/transactions.ts +4 -4
  264. package/src/utils.ts +69 -33
  265. package/lib/cmap/auth/defaultAuthProviders.js +0 -30
  266. package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
  267. package/src/cmap/auth/defaultAuthProviders.ts +0 -32
package/src/bson.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import type {
2
- serialize as serializeFn,
2
+ calculateObjectSize as calculateObjectSizeFn,
3
3
  deserialize as deserializeFn,
4
- calculateObjectSize as calculateObjectSizeFn
4
+ DeserializeOptions,
5
+ serialize as serializeFn,
6
+ SerializeOptions
5
7
  } from 'bson';
6
8
 
7
9
  // eslint-disable-next-line @typescript-eslint/no-var-requires
8
10
  let BSON = require('bson');
11
+
9
12
  try {
10
13
  // Ensure you always wrap an optional require in the try block NODE-3199
11
14
  BSON = require('bson-ext');
@@ -19,25 +22,23 @@ export const serialize = BSON.serialize as typeof serializeFn;
19
22
  export const calculateObjectSize = BSON.calculateObjectSize as typeof calculateObjectSizeFn;
20
23
 
21
24
  export {
22
- Long,
23
25
  Binary,
24
- ObjectId,
25
- Timestamp,
26
+ BSONRegExp,
27
+ BSONSymbol,
26
28
  Code,
27
- MinKey,
28
- MaxKey,
29
+ DBRef,
29
30
  Decimal128,
30
- Int32,
31
+ Document,
31
32
  Double,
32
- DBRef,
33
- BSONRegExp,
34
- BSONSymbol,
33
+ Int32,
34
+ Long,
35
35
  Map,
36
- Document
36
+ MaxKey,
37
+ MinKey,
38
+ ObjectId,
39
+ Timestamp
37
40
  } from 'bson';
38
41
 
39
- import type { DeserializeOptions, SerializeOptions } from 'bson';
40
-
41
42
  /**
42
43
  * BSON Serialization options.
43
44
  * @public
@@ -51,9 +52,13 @@ export interface BSONSerializeOptions
51
52
  | 'cacheFunctionsCrc32'
52
53
  | 'allowObjectSmallerThanBufferSize'
53
54
  | 'index'
55
+ | 'validation'
54
56
  > {
55
57
  /** Return BSON filled buffers from operations */
56
58
  raw?: boolean;
59
+
60
+ /** Enable utf8 validation when deserializing BSON documents. Defaults to true. */
61
+ enableUtf8Validation?: boolean;
57
62
  }
58
63
 
59
64
  export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSerializeOptions {
@@ -65,7 +70,8 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
65
70
  serializeFunctions,
66
71
  ignoreUndefined,
67
72
  bsonRegExp,
68
- raw
73
+ raw,
74
+ enableUtf8Validation
69
75
  } = options;
70
76
  return {
71
77
  fieldsAsRaw,
@@ -75,7 +81,8 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
75
81
  serializeFunctions,
76
82
  ignoreUndefined,
77
83
  bsonRegExp,
78
- raw
84
+ raw,
85
+ enableUtf8Validation
79
86
  };
80
87
  }
81
88
 
@@ -98,6 +105,8 @@ export function resolveBSONOptions(
98
105
  ignoreUndefined: options?.ignoreUndefined ?? parentOptions?.ignoreUndefined ?? false,
99
106
  bsonRegExp: options?.bsonRegExp ?? parentOptions?.bsonRegExp ?? false,
100
107
  serializeFunctions: options?.serializeFunctions ?? parentOptions?.serializeFunctions ?? false,
101
- fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {}
108
+ fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {},
109
+ enableUtf8Validation:
110
+ options?.enableUtf8Validation ?? parentOptions?.enableUtf8Validation ?? true
102
111
  };
103
112
  }
@@ -1,39 +1,39 @@
1
- import { PromiseProvider } from '../promise_provider';
2
1
  import {
2
+ BSONSerializeOptions,
3
+ Document,
3
4
  Long,
4
5
  ObjectId,
5
- Document,
6
- BSONSerializeOptions,
7
6
  resolveBSONOptions,
8
7
  Timestamp
9
8
  } from '../bson';
9
+ import type { Collection } from '../collection';
10
10
  import {
11
- MongoWriteConcernError,
12
11
  AnyError,
12
+ MongoBatchReExecutionError,
13
13
  MONGODB_ERROR_CODES,
14
- MongoServerError,
15
14
  MongoInvalidArgumentError,
16
- MongoBatchReExecutionError
15
+ MongoServerError,
16
+ MongoWriteConcernError
17
17
  } from '../error';
18
+ import type { Filter, OneOrMore, OptionalId, UpdateFilter, WithoutId } from '../mongo_types';
19
+ import type { CollationOptions, CommandOperationOptions } from '../operations/command';
20
+ import { DeleteOperation, DeleteStatement, makeDeleteStatement } from '../operations/delete';
21
+ import { executeOperation } from '../operations/execute_operation';
22
+ import { InsertOperation } from '../operations/insert';
23
+ import type { Hint } from '../operations/operation';
24
+ import { makeUpdateStatement, UpdateOperation, UpdateStatement } from '../operations/update';
25
+ import { PromiseProvider } from '../promise_provider';
26
+ import type { Topology } from '../sdam/topology';
18
27
  import {
19
28
  applyRetryableWrites,
29
+ Callback,
20
30
  executeLegacyOperation,
31
+ getTopology,
21
32
  hasAtomicOperators,
22
- Callback,
23
33
  MongoDBNamespace,
24
- getTopology,
25
34
  resolveOptions
26
35
  } from '../utils';
27
- import { executeOperation } from '../operations/execute_operation';
28
- import { InsertOperation } from '../operations/insert';
29
- import { UpdateOperation, UpdateStatement, makeUpdateStatement } from '../operations/update';
30
- import { DeleteOperation, DeleteStatement, makeDeleteStatement } from '../operations/delete';
31
36
  import { WriteConcern } from '../write_concern';
32
- import type { Collection } from '../collection';
33
- import type { Topology } from '../sdam/topology';
34
- import type { CommandOperationOptions, CollationOptions } from '../operations/command';
35
- import type { Hint } from '../operations/operation';
36
- import type { Filter, OneOrMore, OptionalId, UpdateFilter } from '../mongo_types';
37
37
 
38
38
  /** @internal */
39
39
  const kServerError = Symbol('serverError');
@@ -79,7 +79,7 @@ export interface ReplaceOneModel<TSchema extends Document = Document> {
79
79
  /** The filter to limit the replaced document. */
80
80
  filter: Filter<TSchema>;
81
81
  /** The document with which to replace the matched document. */
82
- replacement: TSchema;
82
+ replacement: WithoutId<TSchema>;
83
83
  /** Specifies a collation. */
84
84
  collation?: CollationOptions;
85
85
  /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
@@ -940,7 +940,7 @@ export abstract class BulkOperationBase {
940
940
 
941
941
  const topology = getTopology(collection);
942
942
  options = options == null ? {} : options;
943
- // TODO Bring from driver information in isMaster
943
+ // TODO Bring from driver information in hello
944
944
  // Get the namespace for the write operations
945
945
  const namespace = collection.s.namespace;
946
946
  // Used to mark operation as executed
@@ -950,16 +950,15 @@ export abstract class BulkOperationBase {
950
950
  const currentOp = undefined;
951
951
 
952
952
  // Set max byte size
953
- const isMaster = topology.lastIsMaster();
953
+ const hello = topology.lastHello();
954
954
 
955
955
  // If we have autoEncryption on, batch-splitting must be done on 2mb chunks, but single documents
956
956
  // over 2mb are still allowed
957
957
  const usingAutoEncryption = !!(topology.s.options && topology.s.options.autoEncrypter);
958
958
  const maxBsonObjectSize =
959
- isMaster && isMaster.maxBsonObjectSize ? isMaster.maxBsonObjectSize : 1024 * 1024 * 16;
959
+ hello && hello.maxBsonObjectSize ? hello.maxBsonObjectSize : 1024 * 1024 * 16;
960
960
  const maxBatchSizeBytes = usingAutoEncryption ? 1024 * 1024 * 2 : maxBsonObjectSize;
961
- const maxWriteBatchSize =
962
- isMaster && isMaster.maxWriteBatchSize ? isMaster.maxWriteBatchSize : 1000;
961
+ const maxWriteBatchSize = hello && hello.maxWriteBatchSize ? hello.maxWriteBatchSize : 1000;
963
962
 
964
963
  // Calculates the largest possible size of an Array key, represented as a BSON string
965
964
  // element. This calculation:
@@ -1,10 +1,10 @@
1
- import * as BSON from '../bson';
2
- import { BulkOperationBase, Batch, BatchType, BulkWriteOptions } from './common';
3
1
  import type { Document } from '../bson';
2
+ import * as BSON from '../bson';
4
3
  import type { Collection } from '../collection';
5
- import type { UpdateStatement } from '../operations/update';
6
- import type { DeleteStatement } from '../operations/delete';
7
4
  import { MongoInvalidArgumentError } from '../error';
5
+ import type { DeleteStatement } from '../operations/delete';
6
+ import type { UpdateStatement } from '../operations/update';
7
+ import { Batch, BatchType, BulkOperationBase, BulkWriteOptions } from './common';
8
8
 
9
9
  /** @public */
10
10
  export class OrderedBulkOperation extends BulkOperationBase {
@@ -1,11 +1,11 @@
1
- import * as BSON from '../bson';
2
- import { BulkOperationBase, Batch, BatchType, BulkWriteOptions, BulkWriteResult } from './common';
3
- import type { Callback } from '../utils';
4
1
  import type { Document } from '../bson';
2
+ import * as BSON from '../bson';
5
3
  import type { Collection } from '../collection';
6
- import type { UpdateStatement } from '../operations/update';
7
- import type { DeleteStatement } from '../operations/delete';
8
4
  import { MongoInvalidArgumentError } from '../error';
5
+ import type { DeleteStatement } from '../operations/delete';
6
+ import type { UpdateStatement } from '../operations/update';
7
+ import type { Callback } from '../utils';
8
+ import { Batch, BatchType, BulkOperationBase, BulkWriteOptions, BulkWriteResult } from './common';
9
9
 
10
10
  /** @public */
11
11
  export class UnorderedBulkOperation extends BulkOperationBase {
@@ -1,39 +1,40 @@
1
1
  import Denque = require('denque');
2
+ import type { Readable } from 'stream';
3
+
4
+ import type { Document, Timestamp } from './bson';
5
+ import { Collection } from './collection';
6
+ import {
7
+ AbstractCursor,
8
+ AbstractCursorEvents,
9
+ AbstractCursorOptions,
10
+ CursorStreamOptions
11
+ } from './cursor/abstract_cursor';
12
+ import { Db } from './db';
2
13
  import {
3
- MongoError,
4
14
  AnyError,
5
15
  isResumableError,
6
- MongoRuntimeError,
7
16
  MongoAPIError,
8
- MongoChangeStreamError
17
+ MongoChangeStreamError,
18
+ MongoError,
19
+ MongoRuntimeError
9
20
  } from './error';
21
+ import { MongoClient } from './mongo_client';
22
+ import { InferIdType, Nullable, TypedEventEmitter } from './mongo_types';
10
23
  import { AggregateOperation, AggregateOptions } from './operations/aggregate';
24
+ import type { CollationOptions, OperationParent } from './operations/command';
25
+ import { executeOperation, ExecutionResult } from './operations/execute_operation';
26
+ import type { ReadPreference } from './read_preference';
27
+ import type { Topology } from './sdam/topology';
28
+ import type { ClientSession } from './sessions';
11
29
  import {
12
- maxWireVersion,
13
30
  calculateDurationInMs,
14
- now,
31
+ Callback,
32
+ getTopology,
33
+ maxWireVersion,
15
34
  maybePromise,
16
35
  MongoDBNamespace,
17
- Callback,
18
- getTopology
36
+ now
19
37
  } from './utils';
20
- import type { ReadPreference } from './read_preference';
21
- import type { Timestamp, Document } from './bson';
22
- import type { Topology } from './sdam/topology';
23
- import type { OperationParent, CollationOptions } from './operations/command';
24
- import { MongoClient } from './mongo_client';
25
- import { Db } from './db';
26
- import { Collection } from './collection';
27
- import type { Readable } from 'stream';
28
- import {
29
- AbstractCursor,
30
- AbstractCursorEvents,
31
- AbstractCursorOptions,
32
- CursorStreamOptions
33
- } from './cursor/abstract_cursor';
34
- import type { ClientSession } from './sessions';
35
- import { executeOperation, ExecutionResult } from './operations/execute_operation';
36
- import { InferIdType, Nullable, TypedEventEmitter } from './mongo_types';
37
38
 
38
39
  /** @internal */
39
40
  const kResumeQueue = Symbol('resumeQueue');
@@ -70,7 +71,7 @@ export interface ResumeOptions {
70
71
  }
71
72
 
72
73
  /**
73
- * Represents the logical starting point for a new or resuming {@link https://docs.mongodb.com/master/changeStreams/#change-stream-resume-token| Change Stream} on the server.
74
+ * Represents the logical starting point for a new or resuming {@link https://docs.mongodb.com/manual/changeStreams/#std-label-change-stream-resume| Change Stream} on the server.
74
75
  * @public
75
76
  */
76
77
  export type ResumeToken = unknown;
@@ -97,9 +98,9 @@ export interface ChangeStreamOptions extends AggregateOptions {
97
98
  fullDocument?: string;
98
99
  /** The maximum amount of time for the server to wait on new documents to satisfy a change stream query. */
99
100
  maxAwaitTimeMS?: number;
100
- /** Allows you to start a changeStream after a specified event. See {@link https://docs.mongodb.com/master/changeStreams/#resumeafter-for-change-streams|ChangeStream documentation}. */
101
+ /** Allows you to start a changeStream after a specified event. See {@link https://docs.mongodb.com/manual/changeStreams/#resumeafter-for-change-streams|ChangeStream documentation}. */
101
102
  resumeAfter?: ResumeToken;
102
- /** Similar to resumeAfter, but will allow you to start after an invalidated event. See {@link https://docs.mongodb.com/master/changeStreams/#startafter-for-change-streams|ChangeStream documentation}. */
103
+ /** Similar to resumeAfter, but will allow you to start after an invalidated event. See {@link https://docs.mongodb.com/manual/changeStreams/#startafter-for-change-streams|ChangeStream documentation}. */
103
104
  startAfter?: ResumeToken;
104
105
  /** Will start the changeStream after the specified operationTime. */
105
106
  startAtOperationTime?: OperationTime;
@@ -310,7 +311,9 @@ export class ChangeStream<TSchema extends Document = Document> extends TypedEven
310
311
  }
311
312
 
312
313
  /** Check if there is any document still available in the Change Stream */
313
- hasNext(callback?: Callback): Promise<void> | void {
314
+ hasNext(): Promise<boolean>;
315
+ hasNext(callback: Callback<boolean>): void;
316
+ hasNext(callback?: Callback): Promise<boolean> | void {
314
317
  setIsIterator(this);
315
318
  return maybePromise(callback, cb => {
316
319
  getCursor(this, (err, cursor) => {
@@ -1,9 +1,9 @@
1
1
  import type { Document } from '../../bson';
2
+ import { MongoRuntimeError } from '../../error';
3
+ import type { Callback, ClientMetadataOptions } from '../../utils';
4
+ import type { HandshakeDocument } from '../connect';
2
5
  import type { Connection, ConnectionOptions } from '../connection';
3
6
  import type { MongoCredentials } from './mongo_credentials';
4
- import type { HandshakeDocument } from '../connect';
5
- import type { ClientMetadataOptions, Callback } from '../../utils';
6
- import { MongoRuntimeError } from '../../error';
7
7
 
8
8
  export type AuthContextOptions = ConnectionOptions & ClientMetadataOptions;
9
9
 
@@ -1,14 +1,16 @@
1
- import { AuthProvider, AuthContext } from './auth_provider';
1
+ import * as dns from 'dns';
2
+
3
+ import type { Document } from '../../bson';
4
+ import { Kerberos, KerberosClient } from '../../deps';
2
5
  import {
3
- MongoRuntimeError,
6
+ MongoError,
4
7
  MongoInvalidArgumentError,
5
8
  MongoMissingCredentialsError,
6
- MongoError,
7
- MongoMissingDependencyError
9
+ MongoMissingDependencyError,
10
+ MongoRuntimeError
8
11
  } from '../../error';
9
- import { Kerberos, KerberosClient } from '../../deps';
10
12
  import { Callback, ns } from '../../utils';
11
- import type { Document } from '../../bson';
13
+ import { AuthContext, AuthProvider } from './auth_provider';
12
14
 
13
15
  type MechanismProperties = {
14
16
  gssapiCanonicalizeHostName?: boolean;
@@ -16,8 +18,6 @@ type MechanismProperties = {
16
18
  SERVICE_REALM?: string;
17
19
  };
18
20
 
19
- import * as dns from 'dns';
20
-
21
21
  export class GSSAPI extends AuthProvider {
22
22
  auth(authContext: AuthContext, callback: Callback): void {
23
23
  const { connection, credentials } = authContext;
@@ -2,21 +2,21 @@
2
2
 
3
3
  import type { Document } from '../../bson';
4
4
  import { MongoAPIError, MongoMissingCredentialsError } from '../../error';
5
- import { AuthMechanism } from './defaultAuthProviders';
5
+ import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './providers';
6
6
 
7
7
  // https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst
8
- function getDefaultAuthMechanism(ismaster?: Document): AuthMechanism {
9
- if (ismaster) {
10
- // If ismaster contains saslSupportedMechs, use scram-sha-256
8
+ function getDefaultAuthMechanism(hello?: Document): AuthMechanism {
9
+ if (hello) {
10
+ // If hello contains saslSupportedMechs, use scram-sha-256
11
11
  // if it is available, else scram-sha-1
12
- if (Array.isArray(ismaster.saslSupportedMechs)) {
13
- return ismaster.saslSupportedMechs.includes(AuthMechanism.MONGODB_SCRAM_SHA256)
12
+ if (Array.isArray(hello.saslSupportedMechs)) {
13
+ return hello.saslSupportedMechs.includes(AuthMechanism.MONGODB_SCRAM_SHA256)
14
14
  ? AuthMechanism.MONGODB_SCRAM_SHA256
15
15
  : AuthMechanism.MONGODB_SCRAM_SHA1;
16
16
  }
17
17
 
18
18
  // Fallback to legacy selection method. If wire version >= 3, use scram-sha-1
19
- if (ismaster.maxWireVersion >= 3) {
19
+ if (hello.maxWireVersion >= 3) {
20
20
  return AuthMechanism.MONGODB_SCRAM_SHA1;
21
21
  }
22
22
  }
@@ -107,16 +107,16 @@ export class MongoCredentials {
107
107
  * If the authentication mechanism is set to "default", resolves the authMechanism
108
108
  * based on the server version and server supported sasl mechanisms.
109
109
  *
110
- * @param ismaster - An ismaster response from the server
110
+ * @param hello - A hello response from the server
111
111
  */
112
- resolveAuthMechanism(ismaster?: Document): MongoCredentials {
112
+ resolveAuthMechanism(hello?: Document): MongoCredentials {
113
113
  // If the mechanism is not "default", then it does not need to be resolved
114
114
  if (this.mechanism.match(/DEFAULT/i)) {
115
115
  return new MongoCredentials({
116
116
  username: this.username,
117
117
  password: this.password,
118
118
  source: this.source,
119
- mechanism: getDefaultAuthMechanism(ismaster),
119
+ mechanism: getDefaultAuthMechanism(hello),
120
120
  mechanismProperties: this.mechanismProperties
121
121
  });
122
122
  }
@@ -136,11 +136,7 @@ export class MongoCredentials {
136
136
  throw new MongoMissingCredentialsError(`Username required for mechanism '${this.mechanism}'`);
137
137
  }
138
138
 
139
- if (
140
- this.mechanism === AuthMechanism.MONGODB_GSSAPI ||
141
- this.mechanism === AuthMechanism.MONGODB_AWS ||
142
- this.mechanism === AuthMechanism.MONGODB_X509
143
- ) {
139
+ if (AUTH_MECHS_AUTH_SRC_EXTERNAL.has(this.mechanism)) {
144
140
  if (this.source != null && this.source !== '$external') {
145
141
  // TODO(NODE-3485): Replace this with a MongoAuthValidationError
146
142
  throw new MongoAPIError(
@@ -1,7 +1,8 @@
1
1
  import * as crypto from 'crypto';
2
- import { AuthProvider, AuthContext } from './auth_provider';
3
- import { Callback, ns } from '../../utils';
2
+
4
3
  import { MongoMissingCredentialsError } from '../../error';
4
+ import { Callback, ns } from '../../utils';
5
+ import { AuthContext, AuthProvider } from './auth_provider';
5
6
 
6
7
  export class MongoCR extends AuthProvider {
7
8
  auth(authContext: AuthContext, callback: Callback): void {
@@ -1,20 +1,19 @@
1
- import * as http from 'http';
2
1
  import * as crypto from 'crypto';
2
+ import * as http from 'http';
3
3
  import * as url from 'url';
4
+
5
+ import type { Binary, BSONSerializeOptions } from '../../bson';
4
6
  import * as BSON from '../../bson';
5
- import { AuthProvider, AuthContext } from './auth_provider';
6
- import { MongoCredentials } from './mongo_credentials';
7
+ import { aws4 } from '../../deps';
7
8
  import {
8
- MongoRuntimeError,
9
+ MongoCompatibilityError,
9
10
  MongoMissingCredentialsError,
10
- MongoCompatibilityError
11
+ MongoRuntimeError
11
12
  } from '../../error';
12
- import { maxWireVersion, Callback, ns } from '../../utils';
13
- import type { BSONSerializeOptions } from '../../bson';
14
-
15
- import { aws4 } from '../../deps';
16
- import { AuthMechanism } from './defaultAuthProviders';
17
- import type { Binary } from 'bson';
13
+ import { Callback, maxWireVersion, ns } from '../../utils';
14
+ import { AuthContext, AuthProvider } from './auth_provider';
15
+ import { MongoCredentials } from './mongo_credentials';
16
+ import { AuthMechanism } from './providers';
18
17
 
19
18
  const ASCII_N = 110;
20
19
  const AWS_RELATIVE_URI = 'http://169.254.170.2';
@@ -1,7 +1,7 @@
1
1
  import { Binary } from '../../bson';
2
- import { AuthProvider, AuthContext } from './auth_provider';
3
2
  import { MongoMissingCredentialsError } from '../../error';
4
3
  import { Callback, ns } from '../../utils';
4
+ import { AuthContext, AuthProvider } from './auth_provider';
5
5
 
6
6
  export class Plain extends AuthProvider {
7
7
  auth(authContext: AuthContext, callback: Callback): void {
@@ -0,0 +1,21 @@
1
+ /** @public */
2
+ export const AuthMechanism = Object.freeze({
3
+ MONGODB_AWS: 'MONGODB-AWS',
4
+ MONGODB_CR: 'MONGODB-CR',
5
+ MONGODB_DEFAULT: 'DEFAULT',
6
+ MONGODB_GSSAPI: 'GSSAPI',
7
+ MONGODB_PLAIN: 'PLAIN',
8
+ MONGODB_SCRAM_SHA1: 'SCRAM-SHA-1',
9
+ MONGODB_SCRAM_SHA256: 'SCRAM-SHA-256',
10
+ MONGODB_X509: 'MONGODB-X509'
11
+ } as const);
12
+
13
+ /** @public */
14
+ export type AuthMechanism = typeof AuthMechanism[keyof typeof AuthMechanism];
15
+
16
+ /** @internal */
17
+ export const AUTH_MECHS_AUTH_SRC_EXTERNAL = new Set<AuthMechanism>([
18
+ AuthMechanism.MONGODB_GSSAPI,
19
+ AuthMechanism.MONGODB_AWS,
20
+ AuthMechanism.MONGODB_X509
21
+ ]);
@@ -1,19 +1,19 @@
1
1
  import * as crypto from 'crypto';
2
+
2
3
  import { Binary, Document } from '../../bson';
4
+ import { saslprep } from '../../deps';
3
5
  import {
4
6
  AnyError,
5
- MongoRuntimeError,
6
- MongoServerError,
7
7
  MongoInvalidArgumentError,
8
- MongoMissingCredentialsError
8
+ MongoMissingCredentialsError,
9
+ MongoRuntimeError,
10
+ MongoServerError
9
11
  } from '../../error';
10
- import { AuthProvider, AuthContext } from './auth_provider';
11
- import { Callback, ns, emitWarning } from '../../utils';
12
- import type { MongoCredentials } from './mongo_credentials';
12
+ import { Callback, emitWarning, ns } from '../../utils';
13
13
  import type { HandshakeDocument } from '../connect';
14
-
15
- import { saslprep } from '../../deps';
16
- import { AuthMechanism } from './defaultAuthProviders';
14
+ import { AuthContext, AuthProvider } from './auth_provider';
15
+ import type { MongoCredentials } from './mongo_credentials';
16
+ import { AuthMechanism } from './providers';
17
17
 
18
18
  type CryptoMethod = 'sha1' | 'sha256';
19
19
 
@@ -1,9 +1,9 @@
1
- import { AuthProvider, AuthContext } from './auth_provider';
2
- import { MongoMissingCredentialsError } from '../../error';
3
1
  import type { Document } from '../../bson';
2
+ import { MongoMissingCredentialsError } from '../../error';
4
3
  import { Callback, ns } from '../../utils';
5
- import type { MongoCredentials } from './mongo_credentials';
6
4
  import type { HandshakeDocument } from '../connect';
5
+ import { AuthContext, AuthProvider } from './auth_provider';
6
+ import type { MongoCredentials } from './mongo_credentials';
7
7
 
8
8
  export class X509 extends AuthProvider {
9
9
  prepare(handshakeDoc: HandshakeDocument, authContext: AuthContext, callback: Callback): void {
@@ -1,7 +1,8 @@
1
- import { GetMore, KillCursor, Msg, WriteProtocolMessageType } from './commands';
1
+ import type { Document, ObjectId } from '../bson';
2
+ import { LEGACY_HELLO_COMMAND, LEGACY_HELLO_COMMAND_CAMEL_CASE } from '../constants';
2
3
  import { calculateDurationInMs, deepCopy } from '../utils';
4
+ import { GetMore, KillCursor, Msg, WriteProtocolMessageType } from './commands';
3
5
  import type { Connection } from './connection';
4
- import type { Document, ObjectId } from '../bson';
5
6
 
6
7
  /**
7
8
  * An event indicating the start of a given
@@ -161,7 +162,7 @@ const SENSITIVE_COMMANDS = new Set([
161
162
  'copydb'
162
163
  ]);
163
164
 
164
- const HELLO_COMMANDS = new Set(['hello', 'ismaster', 'isMaster']);
165
+ const HELLO_COMMANDS = new Set(['hello', LEGACY_HELLO_COMMAND, LEGACY_HELLO_COMMAND_CAMEL_CASE]);
165
166
 
166
167
  // helper methods
167
168
  const extractCommandName = (commandDoc: Document) => Object.keys(commandDoc)[0];