mongodb 4.2.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/README.md +2 -2
  2. package/lib/admin.js +3 -3
  3. package/lib/admin.js.map +1 -1
  4. package/lib/bson.js +16 -14
  5. package/lib/bson.js.map +1 -1
  6. package/lib/bulk/common.js +7 -7
  7. package/lib/bulk/common.js.map +1 -1
  8. package/lib/bulk/ordered.js +1 -1
  9. package/lib/bulk/ordered.js.map +1 -1
  10. package/lib/bulk/unordered.js +1 -1
  11. package/lib/bulk/unordered.js.map +1 -1
  12. package/lib/change_stream.js +6 -6
  13. package/lib/change_stream.js.map +1 -1
  14. package/lib/cmap/auth/auth_provider.js.map +1 -1
  15. package/lib/cmap/auth/gssapi.js +52 -10
  16. package/lib/cmap/auth/gssapi.js.map +1 -1
  17. package/lib/cmap/auth/mongo_credentials.js +36 -27
  18. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  19. package/lib/cmap/auth/mongocr.js +2 -2
  20. package/lib/cmap/auth/mongocr.js.map +1 -1
  21. package/lib/cmap/auth/mongodb_aws.js +6 -6
  22. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  23. package/lib/cmap/auth/plain.js +1 -1
  24. package/lib/cmap/auth/plain.js.map +1 -1
  25. package/lib/cmap/auth/providers.js +21 -0
  26. package/lib/cmap/auth/providers.js.map +1 -0
  27. package/lib/cmap/auth/scram.js +4 -4
  28. package/lib/cmap/auth/scram.js.map +1 -1
  29. package/lib/cmap/auth/x509.js +1 -1
  30. package/lib/cmap/auth/x509.js.map +1 -1
  31. package/lib/cmap/command_monitoring_events.js +3 -2
  32. package/lib/cmap/command_monitoring_events.js.map +1 -1
  33. package/lib/cmap/commands.js +14 -8
  34. package/lib/cmap/commands.js.map +1 -1
  35. package/lib/cmap/connect.js +119 -37
  36. package/lib/cmap/connect.js.map +1 -1
  37. package/lib/cmap/connection.js +36 -35
  38. package/lib/cmap/connection.js.map +1 -1
  39. package/lib/cmap/connection_pool.js +19 -30
  40. package/lib/cmap/connection_pool.js.map +1 -1
  41. package/lib/cmap/message_stream.js +3 -3
  42. package/lib/cmap/message_stream.js.map +1 -1
  43. package/lib/cmap/stream_description.js +4 -4
  44. package/lib/cmap/stream_description.js.map +1 -1
  45. package/lib/cmap/wire_protocol/compression.js +2 -1
  46. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  47. package/lib/cmap/wire_protocol/shared.js +4 -3
  48. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  49. package/lib/collection.js +46 -47
  50. package/lib/collection.js.map +1 -1
  51. package/lib/connection_string.js +93 -54
  52. package/lib/connection_string.js.map +1 -1
  53. package/lib/constants.js +113 -1
  54. package/lib/constants.js.map +1 -1
  55. package/lib/cursor/abstract_cursor.js +5 -5
  56. package/lib/cursor/abstract_cursor.js.map +1 -1
  57. package/lib/cursor/aggregation_cursor.js +1 -1
  58. package/lib/cursor/aggregation_cursor.js.map +1 -1
  59. package/lib/cursor/find_cursor.js +2 -1
  60. package/lib/cursor/find_cursor.js.map +1 -1
  61. package/lib/db.js +23 -13
  62. package/lib/db.js.map +1 -1
  63. package/lib/deps.js +0 -1
  64. package/lib/deps.js.map +1 -1
  65. package/lib/encrypter.js +12 -4
  66. package/lib/encrypter.js.map +1 -1
  67. package/lib/error.js +47 -24
  68. package/lib/error.js.map +1 -1
  69. package/lib/gridfs/download.js +1 -1
  70. package/lib/gridfs/download.js.map +1 -1
  71. package/lib/gridfs/index.js +3 -3
  72. package/lib/gridfs/index.js.map +1 -1
  73. package/lib/gridfs/upload.js +3 -2
  74. package/lib/gridfs/upload.js.map +1 -1
  75. package/lib/index.js +83 -81
  76. package/lib/index.js.map +1 -1
  77. package/lib/logger.js +1 -1
  78. package/lib/logger.js.map +1 -1
  79. package/lib/mongo_client.js +5 -5
  80. package/lib/mongo_client.js.map +1 -1
  81. package/lib/mongo_types.js.map +1 -1
  82. package/lib/operations/add_user.js +3 -3
  83. package/lib/operations/add_user.js.map +1 -1
  84. package/lib/operations/aggregate.js +1 -1
  85. package/lib/operations/aggregate.js.map +1 -1
  86. package/lib/operations/bulk_write.js.map +1 -1
  87. package/lib/operations/collections.js +1 -1
  88. package/lib/operations/collections.js.map +1 -1
  89. package/lib/operations/command.js +5 -6
  90. package/lib/operations/command.js.map +1 -1
  91. package/lib/operations/common_functions.js.map +1 -1
  92. package/lib/operations/connect.js +4 -13
  93. package/lib/operations/connect.js.map +1 -1
  94. package/lib/operations/count.js +1 -1
  95. package/lib/operations/count.js.map +1 -1
  96. package/lib/operations/count_documents.js.map +1 -1
  97. package/lib/operations/create_collection.js +3 -2
  98. package/lib/operations/create_collection.js.map +1 -1
  99. package/lib/operations/delete.js +3 -3
  100. package/lib/operations/delete.js.map +1 -1
  101. package/lib/operations/distinct.js +3 -3
  102. package/lib/operations/distinct.js.map +1 -1
  103. package/lib/operations/drop.js +1 -1
  104. package/lib/operations/drop.js.map +1 -1
  105. package/lib/operations/estimated_document_count.js +2 -2
  106. package/lib/operations/estimated_document_count.js.map +1 -1
  107. package/lib/operations/eval.js +2 -2
  108. package/lib/operations/eval.js.map +1 -1
  109. package/lib/operations/execute_operation.js +5 -6
  110. package/lib/operations/execute_operation.js.map +1 -1
  111. package/lib/operations/find.js +5 -5
  112. package/lib/operations/find.js.map +1 -1
  113. package/lib/operations/find_and_modify.js +2 -2
  114. package/lib/operations/find_and_modify.js.map +1 -1
  115. package/lib/operations/get_more.js.map +1 -1
  116. package/lib/operations/indexes.js +4 -4
  117. package/lib/operations/indexes.js.map +1 -1
  118. package/lib/operations/insert.js +3 -3
  119. package/lib/operations/insert.js.map +1 -1
  120. package/lib/operations/is_capped.js +1 -1
  121. package/lib/operations/is_capped.js.map +1 -1
  122. package/lib/operations/list_collections.js +3 -3
  123. package/lib/operations/list_collections.js.map +1 -1
  124. package/lib/operations/list_databases.js +1 -1
  125. package/lib/operations/list_databases.js.map +1 -1
  126. package/lib/operations/map_reduce.js +4 -3
  127. package/lib/operations/map_reduce.js.map +1 -1
  128. package/lib/operations/operation.js +1 -1
  129. package/lib/operations/operation.js.map +1 -1
  130. package/lib/operations/options_operation.js +1 -1
  131. package/lib/operations/options_operation.js.map +1 -1
  132. package/lib/operations/profiling_level.js +1 -1
  133. package/lib/operations/profiling_level.js.map +1 -1
  134. package/lib/operations/remove_user.js +1 -1
  135. package/lib/operations/remove_user.js.map +1 -1
  136. package/lib/operations/rename.js +3 -3
  137. package/lib/operations/rename.js.map +1 -1
  138. package/lib/operations/run_command.js +1 -1
  139. package/lib/operations/run_command.js.map +1 -1
  140. package/lib/operations/set_profiling_level.js +2 -2
  141. package/lib/operations/set_profiling_level.js.map +1 -1
  142. package/lib/operations/stats.js +1 -1
  143. package/lib/operations/stats.js.map +1 -1
  144. package/lib/operations/update.js +2 -2
  145. package/lib/operations/update.js.map +1 -1
  146. package/lib/operations/validate_collection.js +1 -1
  147. package/lib/operations/validate_collection.js.map +1 -1
  148. package/lib/read_preference.js +15 -5
  149. package/lib/read_preference.js.map +1 -1
  150. package/lib/sdam/events.js +4 -4
  151. package/lib/sdam/monitor.js +19 -18
  152. package/lib/sdam/monitor.js.map +1 -1
  153. package/lib/sdam/server.js +24 -31
  154. package/lib/sdam/server.js.map +1 -1
  155. package/lib/sdam/server_description.js +38 -38
  156. package/lib/sdam/server_description.js.map +1 -1
  157. package/lib/sdam/server_selection.js +2 -2
  158. package/lib/sdam/server_selection.js.map +1 -1
  159. package/lib/sdam/srv_polling.js +2 -2
  160. package/lib/sdam/srv_polling.js.map +1 -1
  161. package/lib/sdam/topology.js +32 -62
  162. package/lib/sdam/topology.js.map +1 -1
  163. package/lib/sdam/topology_description.js +3 -3
  164. package/lib/sdam/topology_description.js.map +1 -1
  165. package/lib/sessions.js +13 -28
  166. package/lib/sessions.js.map +1 -1
  167. package/lib/transactions.js +1 -1
  168. package/lib/transactions.js.map +1 -1
  169. package/lib/utils.js +46 -15
  170. package/lib/utils.js.map +1 -1
  171. package/mongodb.d.ts +205 -60
  172. package/mongodb.ts34.d.ts +230 -59
  173. package/package.json +40 -37
  174. package/src/admin.ts +9 -9
  175. package/src/bson.ts +25 -17
  176. package/src/bulk/common.ts +22 -23
  177. package/src/bulk/ordered.ts +4 -4
  178. package/src/bulk/unordered.ts +5 -5
  179. package/src/change_stream.ts +29 -28
  180. package/src/cmap/auth/auth_provider.ts +3 -3
  181. package/src/cmap/auth/gssapi.ts +65 -14
  182. package/src/cmap/auth/mongo_credentials.ts +28 -17
  183. package/src/cmap/auth/mongocr.ts +3 -2
  184. package/src/cmap/auth/mongodb_aws.ts +10 -11
  185. package/src/cmap/auth/plain.ts +1 -1
  186. package/src/cmap/auth/providers.ts +21 -0
  187. package/src/cmap/auth/scram.ts +9 -9
  188. package/src/cmap/auth/x509.ts +3 -3
  189. package/src/cmap/command_monitoring_events.ts +4 -3
  190. package/src/cmap/commands.ts +22 -14
  191. package/src/cmap/connect.ts +161 -45
  192. package/src/cmap/connection.ts +83 -63
  193. package/src/cmap/connection_pool.ts +39 -39
  194. package/src/cmap/connection_pool_events.ts +1 -1
  195. package/src/cmap/message_stream.ts +9 -8
  196. package/src/cmap/stream_description.ts +5 -5
  197. package/src/cmap/wire_protocol/compression.ts +4 -3
  198. package/src/cmap/wire_protocol/shared.ts +10 -9
  199. package/src/collection.ts +116 -93
  200. package/src/connection_string.ts +130 -59
  201. package/src/constants.ts +122 -0
  202. package/src/cursor/abstract_cursor.ts +14 -13
  203. package/src/cursor/aggregation_cursor.ts +6 -6
  204. package/src/cursor/find_cursor.ts +12 -4
  205. package/src/db.ts +44 -33
  206. package/src/deps.ts +44 -1
  207. package/src/encrypter.ts +12 -3
  208. package/src/error.ts +52 -24
  209. package/src/gridfs/download.ts +10 -8
  210. package/src/gridfs/index.ts +11 -11
  211. package/src/gridfs/upload.ts +13 -10
  212. package/src/index.ts +205 -199
  213. package/src/logger.ts +2 -1
  214. package/src/mongo_client.ts +46 -32
  215. package/src/mongo_types.ts +119 -21
  216. package/src/operations/add_user.ts +7 -6
  217. package/src/operations/aggregate.ts +5 -5
  218. package/src/operations/bulk_write.ts +5 -5
  219. package/src/operations/collections.ts +2 -2
  220. package/src/operations/command.ts +15 -9
  221. package/src/operations/common_functions.ts +4 -4
  222. package/src/operations/connect.ts +4 -14
  223. package/src/operations/count.ts +4 -4
  224. package/src/operations/count_documents.ts +3 -3
  225. package/src/operations/create_collection.ts +7 -6
  226. package/src/operations/delete.ts +5 -5
  227. package/src/operations/distinct.ts +4 -4
  228. package/src/operations/drop.ts +4 -4
  229. package/src/operations/estimated_document_count.ts +5 -5
  230. package/src/operations/eval.ts +5 -5
  231. package/src/operations/execute_operation.ts +10 -11
  232. package/src/operations/find.ts +14 -14
  233. package/src/operations/find_and_modify.ts +7 -7
  234. package/src/operations/get_more.ts +2 -2
  235. package/src/operations/indexes.ts +16 -16
  236. package/src/operations/insert.ts +9 -9
  237. package/src/operations/is_capped.ts +3 -3
  238. package/src/operations/list_collections.ts +6 -6
  239. package/src/operations/list_databases.ts +4 -4
  240. package/src/operations/map_reduce.ts +10 -9
  241. package/src/operations/operation.ts +3 -3
  242. package/src/operations/options_operation.ts +3 -3
  243. package/src/operations/profiling_level.ts +4 -4
  244. package/src/operations/remove_user.ts +4 -4
  245. package/src/operations/rename.ts +6 -6
  246. package/src/operations/run_command.ts +3 -3
  247. package/src/operations/set_profiling_level.ts +6 -5
  248. package/src/operations/stats.ts +4 -4
  249. package/src/operations/update.ts +10 -10
  250. package/src/operations/validate_collection.ts +4 -4
  251. package/src/read_preference.ts +18 -7
  252. package/src/sdam/common.ts +2 -2
  253. package/src/sdam/events.ts +5 -5
  254. package/src/sdam/monitor.ts +29 -32
  255. package/src/sdam/server.ts +64 -62
  256. package/src/sdam/server_description.ts +41 -48
  257. package/src/sdam/server_selection.ts +3 -3
  258. package/src/sdam/srv_polling.ts +3 -2
  259. package/src/sdam/topology.ts +71 -89
  260. package/src/sdam/topology_description.ts +5 -5
  261. package/src/sessions.ts +31 -48
  262. package/src/transactions.ts +4 -4
  263. package/src/utils.ts +64 -28
  264. package/lib/cmap/auth/defaultAuthProviders.js +0 -30
  265. package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
  266. package/src/cmap/auth/defaultAuthProviders.ts +0 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "4.2.1",
3
+ "version": "4.4.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.6.0",
35
+ "bson": "^4.6.1",
36
36
  "denque": "^2.0.1",
37
- "mongodb-connection-string-url": "^2.2.0"
37
+ "mongodb-connection-string-url": "^2.4.1",
38
+ "socks": "^2.6.1"
38
39
  },
39
40
  "devDependencies": {
40
- "@istanbuljs/nyc-config-typescript": "^1.0.1",
41
- "@microsoft/api-extractor": "^7.18.19",
41
+ "@istanbuljs/nyc-config-typescript": "^1.0.2",
42
+ "@microsoft/api-extractor": "^7.19.4",
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
- "@types/mocha": "^9.0.0",
47
- "@types/node": "^16.11.8",
47
+ "@types/mocha": "^9.1.0",
48
+ "@types/node": "^17.0.13",
48
49
  "@types/saslprep": "^1.0.1",
49
50
  "@types/semver": "^7.3.9",
50
- "@types/sinon": "^10.0.6",
51
+ "@types/sinon": "^10.0.9",
51
52
  "@types/whatwg-url": "^8.2.1",
52
- "@typescript-eslint/eslint-plugin": "^5.4.0",
53
- "@typescript-eslint/parser": "^5.4.0",
53
+ "@typescript-eslint/eslint-plugin": "^5.10.1",
54
+ "@typescript-eslint/parser": "^5.10.1",
54
55
  "bluebird": "^3.7.2",
55
- "chai": "^4.3.4",
56
+ "chai": "^4.3.6",
56
57
  "chai-subset": "^1.6.0",
57
58
  "chalk": "^4.1.2",
58
- "co": "4.6.0",
59
- "downlevel-dts": "^0.7.0",
60
- "eslint": "^8.2.0",
59
+ "downlevel-dts": "^0.8.0",
60
+ "eslint": "^8.8.0",
61
61
  "eslint-config-prettier": "^8.3.0",
62
+ "eslint-plugin-import": "^2.25.4",
62
63
  "eslint-plugin-prettier": "^4.0.0",
64
+ "eslint-plugin-simple-import-sort": "^7.0.0",
63
65
  "eslint-plugin-tsdoc": "^0.2.14",
64
66
  "js-yaml": "^4.1.0",
65
67
  "lodash.camelcase": "^4.3.0",
66
- "mocha": "^9.1.3",
68
+ "mocha": "^9.2.0",
67
69
  "mocha-sinon": "^2.1.2",
68
- "mongodb-mock-server": "^2.0.1",
69
70
  "nyc": "^15.1.0",
70
- "prettier": "^2.4.1",
71
+ "prettier": "^2.5.1",
71
72
  "rimraf": "^3.0.2",
72
73
  "semver": "^7.3.5",
73
- "sinon": "^12.0.1",
74
+ "sinon": "^13.0.0",
74
75
  "sinon-chai": "^3.7.0",
75
- "source-map-support": "^0.5.20",
76
+ "source-map-support": "^0.5.21",
76
77
  "standard-version": "^9.3.2",
77
78
  "ts-node": "^10.4.0",
78
- "tsd": "^0.19.0",
79
- "typescript": "^4.5.2",
79
+ "tsd": "^0.19.1",
80
+ "typescript": "^4.5.5",
80
81
  "typescript-cached-transpile": "^0.0.6",
81
82
  "xml2js": "^0.4.23",
82
- "yargs": "^17.2.1"
83
+ "yargs": "^17.3.1"
83
84
  },
84
85
  "license": "Apache-2.0",
85
86
  "engines": {
@@ -94,27 +95,29 @@
94
95
  },
95
96
  "scripts": {
96
97
  "build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
97
- "build:ts": "rimraf lib && ./node_modules/typescript/bin/tsc",
98
+ "build:ts": "rimraf lib && node ./node_modules/typescript/bin/tsc",
98
99
  "build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*' && downlevel-dts mongodb.d.ts mongodb.ts34.d.ts",
99
100
  "build:docs": "typedoc",
100
101
  "check:bench": "node test/benchmarks/driverBench",
101
102
  "check:coverage": "nyc npm run test:all",
103
+ "check:integration-coverage": "nyc npm run check:test",
102
104
  "check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
103
105
  "check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
104
106
  "check:tsd": "tsd --version && tsd",
105
- "check:dts": "./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
106
- "check:test": "mocha --file test/tools/runner --recursive test/functional test/integration",
107
- "check:unit": "mocha --recursive test/unit/",
108
- "check:ts": "./node_modules/typescript/bin/tsc -v && ./node_modules/typescript/bin/tsc --noEmit",
109
- "check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
110
- "check:adl": "mocha --file test/tools/runner test/manual/data_lake.test.js",
111
- "check:aws": "mocha --file test/tools/runner test/functional/mongodb_aws.test.js",
112
- "check:ocsp": "mocha --config \"test/manual/mocharc.json\" test/manual/ocsp_support.test.js",
113
- "check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
114
- "check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
115
- "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:snappy": "mocha --file test/tools/runner test/functional/unit_snappy.test.js",
107
+ "check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
108
+ "check:test": "mocha --config test/mocha_mongodb.json test/integration",
109
+ "check:unit": "mocha test/unit",
110
+ "check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
111
+ "check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
112
+ "check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
113
+ "check:aws": "mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.js",
114
+ "check:ocsp": "mocha --config test/manual/mocharc.json test/manual/ocsp_support.test.js",
115
+ "check:kerberos": "mocha --config test/manual/mocharc.json test/manual/kerberos.test.js",
116
+ "check:tls": "mocha --config test/manual/mocharc.json test/manual/tls_support.test.js",
117
+ "check:ldap": "mocha --config test/manual/mocharc.json test/manual/ldap.test.js",
118
+ "check:socks5": "mocha --config test/manual/mocharc.json test/manual/socks5.test.ts",
119
+ "check:csfle": "mocha --config test/mocha_mongodb.json test/integration/client-side-encryption",
120
+ "check:snappy": "mocha test/unit/assorted/snappy.test.js",
118
121
  "prepare": "node etc/prepare.js",
119
122
  "release": "standard-version -i HISTORY.md",
120
123
  "test": "npm run check:lint && npm run test:all",
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
@@ -55,6 +56,9 @@ export interface BSONSerializeOptions
55
56
  > {
56
57
  /** Return BSON filled buffers from operations */
57
58
  raw?: boolean;
59
+
60
+ /** Enable utf8 validation when deserializing BSON documents. Defaults to true. */
61
+ enableUtf8Validation?: boolean;
58
62
  }
59
63
 
60
64
  export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSerializeOptions {
@@ -66,7 +70,8 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
66
70
  serializeFunctions,
67
71
  ignoreUndefined,
68
72
  bsonRegExp,
69
- raw
73
+ raw,
74
+ enableUtf8Validation
70
75
  } = options;
71
76
  return {
72
77
  fieldsAsRaw,
@@ -76,7 +81,8 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
76
81
  serializeFunctions,
77
82
  ignoreUndefined,
78
83
  bsonRegExp,
79
- raw
84
+ raw,
85
+ enableUtf8Validation
80
86
  };
81
87
  }
82
88
 
@@ -99,6 +105,8 @@ export function resolveBSONOptions(
99
105
  ignoreUndefined: options?.ignoreUndefined ?? parentOptions?.ignoreUndefined ?? false,
100
106
  bsonRegExp: options?.bsonRegExp ?? parentOptions?.bsonRegExp ?? false,
101
107
  serializeFunctions: options?.serializeFunctions ?? parentOptions?.serializeFunctions ?? false,
102
- fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {}
108
+ fieldsAsRaw: options?.fieldsAsRaw ?? parentOptions?.fieldsAsRaw ?? {},
109
+ enableUtf8Validation:
110
+ options?.enableUtf8Validation ?? parentOptions?.enableUtf8Validation ?? true
103
111
  };
104
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;
@@ -143,7 +144,7 @@ export interface ChangeStreamDocument<TSchema extends Document = Document> {
143
144
  * this will contain all the components of the shard key in order,
144
145
  * followed by the _id if the _id isn’t part of the shard key.
145
146
  */
146
- documentKey?: InferIdType<TSchema>;
147
+ documentKey?: { _id: InferIdType<TSchema> };
147
148
 
148
149
  /**
149
150
  * Only present for ops of type ‘update’.
@@ -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,23 +1,39 @@
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';
14
+
15
+ /** @public */
16
+ export const GSSAPICanonicalizationValue = Object.freeze({
17
+ on: true,
18
+ off: false,
19
+ none: 'none',
20
+ forward: 'forward',
21
+ forwardAndReverse: 'forwardAndReverse'
22
+ } as const);
23
+
24
+ /** @public */
25
+ export type GSSAPICanonicalizationValue =
26
+ typeof GSSAPICanonicalizationValue[keyof typeof GSSAPICanonicalizationValue];
12
27
 
13
28
  type MechanismProperties = {
29
+ /** @deprecated use `CANONICALIZE_HOST_NAME` instead */
14
30
  gssapiCanonicalizeHostName?: boolean;
31
+ CANONICALIZE_HOST_NAME?: GSSAPICanonicalizationValue;
32
+ SERVICE_HOST?: string;
15
33
  SERVICE_NAME?: string;
16
34
  SERVICE_REALM?: string;
17
35
  };
18
36
 
19
- import * as dns from 'dns';
20
-
21
37
  export class GSSAPI extends AuthProvider {
22
38
  auth(authContext: AuthContext, callback: Callback): void {
23
39
  const { connection, credentials } = authContext;
@@ -70,6 +86,7 @@ export class GSSAPI extends AuthProvider {
70
86
  });
71
87
  }
72
88
  }
89
+
73
90
  function makeKerberosClient(authContext: AuthContext, callback: Callback<KerberosClient>): void {
74
91
  const { hostAddress } = authContext.options;
75
92
  const { credentials } = authContext;
@@ -89,7 +106,7 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
89
106
 
90
107
  const serviceName = mechanismProperties.SERVICE_NAME ?? 'mongodb';
91
108
 
92
- performGssapiCanonicalizeHostName(
109
+ performGSSAPICanonicalizeHostName(
93
110
  hostAddress.host,
94
111
  mechanismProperties,
95
112
  (err?: Error | MongoError, host?: string) => {
@@ -100,7 +117,8 @@ function makeKerberosClient(authContext: AuthContext, callback: Callback<Kerbero
100
117
  Object.assign(initOptions, { user: username, password: password });
101
118
  }
102
119
 
103
- let spn = `${serviceName}${process.platform === 'win32' ? '/' : '@'}${host}`;
120
+ const spnHost = mechanismProperties.SERVICE_HOST ?? host;
121
+ let spn = `${serviceName}${process.platform === 'win32' ? '/' : '@'}${spnHost}`;
104
122
  if ('SERVICE_REALM' in mechanismProperties) {
105
123
  spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
106
124
  }
@@ -169,19 +187,52 @@ function finalize(
169
187
  });
170
188
  }
171
189
 
172
- function performGssapiCanonicalizeHostName(
190
+ export function performGSSAPICanonicalizeHostName(
173
191
  host: string,
174
192
  mechanismProperties: MechanismProperties,
175
193
  callback: Callback<string>
176
194
  ): void {
177
- if (!mechanismProperties.gssapiCanonicalizeHostName) return callback(undefined, host);
195
+ const mode = mechanismProperties.CANONICALIZE_HOST_NAME;
196
+ if (!mode || mode === GSSAPICanonicalizationValue.none) {
197
+ return callback(undefined, host);
198
+ }
199
+
200
+ // If forward and reverse or true
201
+ if (
202
+ mode === GSSAPICanonicalizationValue.on ||
203
+ mode === GSSAPICanonicalizationValue.forwardAndReverse
204
+ ) {
205
+ // Perform the lookup of the ip address.
206
+ dns.lookup(host, (error, address) => {
207
+ // No ip found, return the error.
208
+ if (error) return callback(error);
209
+
210
+ // Perform a reverse ptr lookup on the ip address.
211
+ dns.resolvePtr(address, (err, results) => {
212
+ // This can error as ptr records may not exist for all ips. In this case
213
+ // fallback to a cname lookup as dns.lookup() does not return the
214
+ // cname.
215
+ if (err) {
216
+ return resolveCname(host, callback);
217
+ }
218
+ // If the ptr did not error but had no results, return the host.
219
+ callback(undefined, results.length > 0 ? results[0] : host);
220
+ });
221
+ });
222
+ } else {
223
+ // The case for forward is just to resolve the cname as dns.lookup()
224
+ // will not return it.
225
+ resolveCname(host, callback);
226
+ }
227
+ }
178
228
 
229
+ export function resolveCname(host: string, callback: Callback<string>): void {
179
230
  // Attempt to resolve the host name
180
231
  dns.resolveCname(host, (err, r) => {
181
- if (err) return callback(err);
232
+ if (err) return callback(undefined, host);
182
233
 
183
234
  // Get the first resolve host id
184
- if (Array.isArray(r) && r.length > 0) {
235
+ if (r.length > 0) {
185
236
  return callback(undefined, r[0]);
186
237
  }
187
238