mongodb 4.1.4 → 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 (267) hide show
  1. package/README.md +16 -15
  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 -4
  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 +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 +20 -11
  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 +4 -4
  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/constants.js +4 -4
  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 +106 -49
  52. package/lib/connection_string.js.map +1 -1
  53. package/lib/constants.js +108 -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 +2 -2
  83. package/lib/operations/add_user.js.map +1 -1
  84. package/lib/operations/aggregate.js +2 -3
  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 +9 -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 +23 -7
  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 +11 -6
  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 +4 -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/monitor.js +4 -4
  152. package/lib/sdam/monitor.js.map +1 -1
  153. package/lib/sdam/server.js +31 -31
  154. package/lib/sdam/server.js.map +1 -1
  155. package/lib/sdam/server_description.js +1 -1
  156. package/lib/sdam/server_description.js.map +1 -1
  157. package/lib/sdam/server_selection.js +38 -3
  158. package/lib/sdam/server_selection.js.map +1 -1
  159. package/lib/sdam/srv_polling.js +11 -11
  160. package/lib/sdam/srv_polling.js.map +1 -1
  161. package/lib/sdam/topology.js +40 -62
  162. package/lib/sdam/topology.js.map +1 -1
  163. package/lib/sdam/topology_description.js +36 -14
  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 +90 -23
  170. package/lib/utils.js.map +1 -1
  171. package/mongodb.d.ts +159 -65
  172. package/mongodb.ts34.d.ts +184 -65
  173. package/package.json +26 -24
  174. package/src/admin.ts +9 -9
  175. package/src/bson.ts +26 -17
  176. package/src/bulk/common.ts +26 -20
  177. package/src/bulk/ordered.ts +4 -4
  178. package/src/bulk/unordered.ts +5 -5
  179. package/src/change_stream.ts +35 -32
  180. package/src/cmap/auth/auth_provider.ts +3 -3
  181. package/src/cmap/auth/gssapi.ts +8 -8
  182. package/src/cmap/auth/mongo_credentials.ts +2 -6
  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 +2 -2
  190. package/src/cmap/commands.ts +30 -19
  191. package/src/cmap/connect.ts +142 -22
  192. package/src/cmap/connection.ts +73 -52
  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 +2 -2
  198. package/src/cmap/wire_protocol/constants.ts +4 -4
  199. package/src/cmap/wire_protocol/shared.ts +10 -9
  200. package/src/collection.ts +133 -106
  201. package/src/connection_string.ts +141 -60
  202. package/src/constants.ts +116 -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 +49 -39
  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 +58 -32
  216. package/src/mongo_types.ts +98 -20
  217. package/src/operations/add_user.ts +6 -5
  218. package/src/operations/aggregate.ts +6 -7
  219. package/src/operations/bulk_write.ts +5 -5
  220. package/src/operations/collections.ts +2 -2
  221. package/src/operations/command.ts +19 -8
  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 +8 -7
  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 +30 -11
  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 +18 -10
  240. package/src/operations/list_databases.ts +4 -4
  241. package/src/operations/map_reduce.ts +10 -9
  242. package/src/operations/operation.ts +8 -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 +1 -1
  255. package/src/sdam/monitor.ts +13 -14
  256. package/src/sdam/server.ts +71 -61
  257. package/src/sdam/server_description.ts +4 -4
  258. package/src/sdam/server_selection.ts +46 -3
  259. package/src/sdam/srv_polling.ts +15 -13
  260. package/src/sdam/topology.ts +89 -90
  261. package/src/sdam/topology_description.ts +39 -15
  262. package/src/sessions.ts +31 -48
  263. package/src/transactions.ts +6 -6
  264. package/src/utils.ts +123 -43
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "4.1.4",
3
+ "version": "4.3.0",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -32,54 +32,55 @@
32
32
  "email": "dbx-node@mongodb.com"
33
33
  },
34
34
  "dependencies": {
35
- "bson": "^4.5.4",
35
+ "bson": "^4.6.1",
36
36
  "denque": "^2.0.1",
37
- "mongodb-connection-string-url": "^2.1.0"
37
+ "mongodb-connection-string-url": "^2.3.2",
38
+ "socks": "^2.6.1"
38
39
  },
39
40
  "devDependencies": {
40
- "@istanbuljs/nyc-config-typescript": "^1.0.1",
41
- "@microsoft/api-extractor": "^7.18.14",
41
+ "@istanbuljs/nyc-config-typescript": "^1.0.2",
42
+ "@microsoft/api-extractor": "^7.18.21",
42
43
  "@microsoft/tsdoc-config": "^0.15.2",
43
- "@types/chai": "^4.2.22",
44
+ "@types/chai": "^4.3.0",
44
45
  "@types/chai-subset": "^1.3.3",
45
46
  "@types/kerberos": "^1.1.1",
46
47
  "@types/mocha": "^9.0.0",
47
- "@types/node": "^16.10.3",
48
+ "@types/node": "^16.11.12",
48
49
  "@types/saslprep": "^1.0.1",
49
- "@types/semver": "^7.3.8",
50
+ "@types/semver": "^7.3.9",
51
+ "@types/sinon": "^10.0.6",
50
52
  "@types/whatwg-url": "^8.2.1",
51
- "@typescript-eslint/eslint-plugin": "^4.33.0",
52
- "@typescript-eslint/parser": "^4.33.0",
53
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
54
+ "@typescript-eslint/parser": "^5.6.0",
53
55
  "bluebird": "^3.7.2",
54
56
  "chai": "^4.3.4",
55
57
  "chai-subset": "^1.6.0",
56
58
  "chalk": "^4.1.2",
57
- "co": "4.6.0",
58
59
  "downlevel-dts": "^0.7.0",
59
- "eslint": "^7.32.0",
60
+ "eslint": "^8.4.1",
60
61
  "eslint-config-prettier": "^8.3.0",
62
+ "eslint-plugin-import": "^2.25.3",
61
63
  "eslint-plugin-prettier": "^4.0.0",
64
+ "eslint-plugin-simple-import-sort": "^7.0.0",
62
65
  "eslint-plugin-tsdoc": "^0.2.14",
63
66
  "js-yaml": "^4.1.0",
64
67
  "lodash.camelcase": "^4.3.0",
65
- "mocha": "^9.1.2",
68
+ "mocha": "^9.1.3",
66
69
  "mocha-sinon": "^2.1.2",
67
- "mongodb-mock-server": "^2.0.1",
68
70
  "nyc": "^15.1.0",
69
- "prettier": "^2.4.1",
71
+ "prettier": "^2.5.1",
70
72
  "rimraf": "^3.0.2",
71
73
  "semver": "^7.3.5",
72
- "sinon": "^11.1.2",
74
+ "sinon": "^12.0.1",
73
75
  "sinon-chai": "^3.7.0",
74
- "source-map-support": "^0.5.20",
75
- "standard-version": "^9.3.1",
76
- "ts-node": "^10.2.1",
77
- "tsd": "^0.17.0",
78
- "typedoc": "^0.22.5",
79
- "typescript": "4.4.3",
76
+ "source-map-support": "^0.5.21",
77
+ "standard-version": "^9.3.2",
78
+ "ts-node": "^10.4.0",
79
+ "tsd": "^0.19.0",
80
+ "typescript": "^4.5.2",
80
81
  "typescript-cached-transpile": "^0.0.6",
81
82
  "xml2js": "^0.4.23",
82
- "yargs": "^17.2.1"
83
+ "yargs": "^17.3.0"
83
84
  },
84
85
  "license": "Apache-2.0",
85
86
  "engines": {
@@ -113,7 +114,8 @@
113
114
  "check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
114
115
  "check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
115
116
  "check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
116
- "check:csfle": "mocha --file test/tools/runner test/functional/client_side_encryption",
117
+ "check:socks5": "mocha --config \"test/manual/mocharc.json\" test/manual/socks5.test.ts",
118
+ "check:csfle": "mocha --file test/tools/runner test/integration/client-side-encryption",
117
119
  "check:snappy": "mocha --file test/tools/runner test/functional/unit_snappy.test.js",
118
120
  "prepare": "node etc/prepare.js",
119
121
  "release": "standard-version -i HISTORY.md",
package/src/admin.ts CHANGED
@@ -1,20 +1,20 @@
1
+ import type { Document } from './bson';
2
+ import type { Db } from './db';
1
3
  import { AddUserOperation, AddUserOptions } from './operations/add_user';
2
- import { RemoveUserOperation, RemoveUserOptions } from './operations/remove_user';
3
- import {
4
- ValidateCollectionOperation,
5
- ValidateCollectionOptions
6
- } from './operations/validate_collection';
4
+ import type { CommandOperationOptions } from './operations/command';
5
+ import { executeOperation } from './operations/execute_operation';
7
6
  import {
8
7
  ListDatabasesOperation,
9
8
  ListDatabasesOptions,
10
9
  ListDatabasesResult
11
10
  } from './operations/list_databases';
12
- import { executeOperation } from './operations/execute_operation';
11
+ import { RemoveUserOperation, RemoveUserOptions } from './operations/remove_user';
13
12
  import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
13
+ import {
14
+ ValidateCollectionOperation,
15
+ ValidateCollectionOptions
16
+ } from './operations/validate_collection';
14
17
  import { Callback, getTopology } from './utils';
15
- import type { Document } from './bson';
16
- import type { CommandOperationOptions } from './operations/command';
17
- import type { Db } from './db';
18
18
 
19
19
  /** @internal */
20
20
  export interface AdminPrivate {
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. */
@@ -1216,9 +1216,15 @@ export abstract class BulkOperationBase {
1216
1216
  return batches;
1217
1217
  }
1218
1218
 
1219
- /** An internal helper method. Do not invoke directly. Will be going away in the future */
1219
+ execute(options?: BulkWriteOptions): Promise<BulkWriteResult>;
1220
+ execute(callback: Callback<BulkWriteResult>): void;
1221
+ execute(options: BulkWriteOptions | undefined, callback: Callback<BulkWriteResult>): void;
1222
+ execute(
1223
+ options?: BulkWriteOptions | Callback<BulkWriteResult>,
1224
+ callback?: Callback<BulkWriteResult>
1225
+ ): Promise<BulkWriteResult> | void;
1220
1226
  execute(
1221
- options?: BulkWriteOptions,
1227
+ options?: BulkWriteOptions | Callback<BulkWriteResult>,
1222
1228
  callback?: Callback<BulkWriteResult>
1223
1229
  ): Promise<BulkWriteResult> | void {
1224
1230
  if (typeof options === 'function') (callback = options), (options = {});
@@ -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');
@@ -184,23 +185,23 @@ export interface UpdateDescription<TSchema extends Document = Document> {
184
185
  }
185
186
 
186
187
  /** @public */
187
- export type ChangeStreamEvents = {
188
+ export type ChangeStreamEvents<TSchema extends Document = Document> = {
188
189
  resumeTokenChanged(token: ResumeToken): void;
189
- init(response: Document): void;
190
- more(response?: Document | undefined): void;
190
+ init(response: TSchema): void;
191
+ more(response?: TSchema | undefined): void;
191
192
  response(): void;
192
193
  end(): void;
193
194
  error(error: Error): void;
194
- change(change: ChangeStreamDocument): void;
195
+ change(change: ChangeStreamDocument<TSchema>): void;
195
196
  } & AbstractCursorEvents;
196
197
 
197
198
  /**
198
199
  * Creates a new Change Stream instance. Normally created using {@link Collection#watch|Collection.watch()}.
199
200
  * @public
200
201
  */
201
- export class ChangeStream<
202
- TSchema extends Document = Document
203
- > extends TypedEventEmitter<ChangeStreamEvents> {
202
+ export class ChangeStream<TSchema extends Document = Document> extends TypedEventEmitter<
203
+ ChangeStreamEvents<TSchema>
204
+ > {
204
205
  pipeline: Document[];
205
206
  options: ChangeStreamOptions;
206
207
  parent: MongoClient | Db | Collection;
@@ -310,7 +311,9 @@ export class ChangeStream<
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,7 +2,7 @@
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
8
  function getDefaultAuthMechanism(ismaster?: Document): AuthMechanism {
@@ -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,7 @@
1
- import { GetMore, KillCursor, Msg, WriteProtocolMessageType } from './commands';
1
+ import type { Document, ObjectId } from '../bson';
2
2
  import { calculateDurationInMs, deepCopy } from '../utils';
3
+ import { GetMore, KillCursor, Msg, WriteProtocolMessageType } from './commands';
3
4
  import type { Connection } from './connection';
4
- import type { Document, ObjectId } from '../bson';
5
5
 
6
6
  /**
7
7
  * An event indicating the start of a given