@depup/mongodb 7.1.0-depup.0 → 7.5.0-depup.7

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 (114) hide show
  1. package/README.md +5 -5
  2. package/changes.json +18 -0
  3. package/lib/bson.js +32 -5
  4. package/lib/bson.js.map +1 -1
  5. package/lib/change_stream.js +4 -1
  6. package/lib/change_stream.js.map +1 -1
  7. package/lib/client-side-encryption/auto_encrypter.js +19 -10
  8. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  9. package/lib/client-side-encryption/client_encryption.js +5 -6
  10. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  11. package/lib/cmap/auth/aws4.js +4 -4
  12. package/lib/cmap/auth/aws4.js.map +1 -1
  13. package/lib/cmap/auth/gssapi.js +3 -6
  14. package/lib/cmap/auth/gssapi.js.map +1 -1
  15. package/lib/cmap/auth/mongodb_aws.js +3 -2
  16. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  17. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +3 -3
  18. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -1
  19. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +3 -3
  20. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -1
  21. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +3 -3
  22. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -1
  23. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +3 -3
  24. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -1
  25. package/lib/cmap/auth/mongodb_oidc.js +4 -4
  26. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  27. package/lib/cmap/auth/plain.js +1 -1
  28. package/lib/cmap/auth/plain.js.map +1 -1
  29. package/lib/cmap/auth/scram.js +58 -46
  30. package/lib/cmap/auth/scram.js.map +1 -1
  31. package/lib/cmap/commands.js +46 -39
  32. package/lib/cmap/commands.js.map +1 -1
  33. package/lib/cmap/connect.js +19 -2
  34. package/lib/cmap/connect.js.map +1 -1
  35. package/lib/cmap/connection.js +5 -2
  36. package/lib/cmap/connection.js.map +1 -1
  37. package/lib/cmap/handshake/client_metadata.js +3 -4
  38. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  39. package/lib/cmap/wire_protocol/compression.js +8 -7
  40. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  41. package/lib/cmap/wire_protocol/constants.js +2 -2
  42. package/lib/cmap/wire_protocol/on_data.js.map +1 -1
  43. package/lib/cmap/wire_protocol/on_demand/document.js +9 -9
  44. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  45. package/lib/connection_string.js +21 -5
  46. package/lib/connection_string.js.map +1 -1
  47. package/lib/cursor/abstract_cursor.js +0 -1
  48. package/lib/cursor/abstract_cursor.js.map +1 -1
  49. package/lib/cursor/find_cursor.js.map +1 -1
  50. package/lib/gridfs/download.js +2 -1
  51. package/lib/gridfs/download.js.map +1 -1
  52. package/lib/gridfs/upload.js +7 -7
  53. package/lib/gridfs/upload.js.map +1 -1
  54. package/lib/index.js.map +1 -1
  55. package/lib/mongo_client.js +0 -1
  56. package/lib/mongo_client.js.map +1 -1
  57. package/lib/operations/count.js.map +1 -1
  58. package/lib/operations/execute_operation.js +114 -41
  59. package/lib/operations/execute_operation.js.map +1 -1
  60. package/lib/operations/operation.js +1 -0
  61. package/lib/operations/operation.js.map +1 -1
  62. package/lib/runtime_adapters.js +32 -0
  63. package/lib/runtime_adapters.js.map +1 -0
  64. package/lib/sdam/srv_polling.js +1 -1
  65. package/lib/sdam/srv_polling.js.map +1 -1
  66. package/lib/sdam/topology.js +5 -3
  67. package/lib/sdam/topology.js.map +1 -1
  68. package/lib/sessions.js +125 -81
  69. package/lib/sessions.js.map +1 -1
  70. package/lib/utils.js +52 -36
  71. package/lib/utils.js.map +1 -1
  72. package/mongodb.d.ts +96 -38
  73. package/package.json +66 -53
  74. package/src/bson.ts +34 -5
  75. package/src/change_stream.ts +5 -1
  76. package/src/client-side-encryption/auto_encrypter.ts +17 -11
  77. package/src/client-side-encryption/client_encryption.ts +42 -14
  78. package/src/cmap/auth/auth_provider.ts +1 -1
  79. package/src/cmap/auth/aws4.ts +5 -5
  80. package/src/cmap/auth/gssapi.ts +9 -6
  81. package/src/cmap/auth/mongodb_aws.ts +2 -2
  82. package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +1 -1
  83. package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +1 -1
  84. package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +1 -1
  85. package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +1 -1
  86. package/src/cmap/auth/mongodb_oidc.ts +4 -4
  87. package/src/cmap/auth/plain.ts +2 -2
  88. package/src/cmap/auth/scram.ts +87 -61
  89. package/src/cmap/commands.ts +70 -51
  90. package/src/cmap/connect.ts +21 -1
  91. package/src/cmap/connection.ts +11 -4
  92. package/src/cmap/handshake/client_metadata.ts +6 -6
  93. package/src/cmap/wire_protocol/compression.ts +18 -14
  94. package/src/cmap/wire_protocol/constants.ts +2 -2
  95. package/src/cmap/wire_protocol/on_data.ts +5 -5
  96. package/src/cmap/wire_protocol/on_demand/document.ts +12 -14
  97. package/src/connection_string.ts +29 -11
  98. package/src/cursor/abstract_cursor.ts +0 -1
  99. package/src/cursor/find_cursor.ts +1 -1
  100. package/src/deps.ts +4 -4
  101. package/src/gridfs/download.ts +2 -2
  102. package/src/gridfs/upload.ts +13 -12
  103. package/src/index.ts +2 -0
  104. package/src/mongo_client.ts +28 -1
  105. package/src/operations/client_bulk_write/command_builder.ts +1 -1
  106. package/src/operations/count.ts +1 -2
  107. package/src/operations/execute_operation.ts +146 -45
  108. package/src/operations/operation.ts +8 -0
  109. package/src/runtime_adapters.ts +64 -0
  110. package/src/sdam/srv_polling.ts +1 -1
  111. package/src/sdam/topology.ts +11 -8
  112. package/src/sessions.ts +142 -99
  113. package/src/utils.ts +68 -46
  114. package/tsconfig.json +1 -1
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@depup/mongodb",
3
- "version": "7.1.0-depup.0",
4
- "description": "[DepUp] The official MongoDB driver for Node.js",
3
+ "version": "7.5.0-depup.7",
4
+ "description": "The official MongoDB driver for Node.js (with updated dependencies)",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "lib",
8
8
  "src",
9
9
  "etc/prepare.js",
10
10
  "mongodb.d.ts",
11
- "tsconfig.json"
11
+ "tsconfig.json",
12
+ "changes.json",
13
+ "README.md"
12
14
  ],
13
15
  "types": "mongodb.d.ts",
14
16
  "repository": {
@@ -16,10 +18,12 @@
16
18
  "url": "git@github.com:mongodb/node-mongodb-native.git"
17
19
  },
18
20
  "keywords": [
19
- "depup",
20
- "dependency-bumped",
21
- "updated-deps",
22
21
  "mongodb",
22
+ "depup",
23
+ "updated-dependencies",
24
+ "security",
25
+ "latest",
26
+ "patched",
23
27
  "driver",
24
28
  "official"
25
29
  ],
@@ -28,16 +32,16 @@
28
32
  "email": "dbx-node@mongodb.com"
29
33
  },
30
34
  "dependencies": {
31
- "@mongodb-js/saslprep": "^1.4.6",
32
- "bson": "^7.2.0",
33
- "mongodb-connection-string-url": "^7.0.1"
35
+ "@mongodb-js/saslprep": "^1.4.12",
36
+ "bson": "^7.3.1",
37
+ "mongodb-connection-string-url": "^7.0.2"
34
38
  },
35
39
  "peerDependencies": {
36
40
  "@aws-sdk/credential-providers": "^3.806.0",
37
41
  "@mongodb-js/zstd": "^7.0.0",
38
42
  "gcp-metadata": "^7.0.1",
39
43
  "kerberos": "^7.0.0",
40
- "mongodb-client-encryption": ">=7.0.0 <7.1.0",
44
+ "mongodb-client-encryption": "^7.2.0",
41
45
  "snappy": "^7.3.2",
42
46
  "socks": "^2.8.6"
43
47
  },
@@ -68,44 +72,43 @@
68
72
  "@aws-sdk/credential-providers": "^3.876.0",
69
73
  "@iarna/toml": "^2.2.5",
70
74
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
71
- "@microsoft/api-extractor": "^7.54.0",
72
- "@microsoft/tsdoc-config": "^0.17.1",
75
+ "@microsoft/api-extractor": "^7.58.7",
76
+ "@microsoft/tsdoc-config": "^0.18.1",
73
77
  "@mongodb-js/zstd": "^7.0.0",
74
- "@types/chai": "^4.3.17",
75
78
  "@types/chai-subset": "^1.3.5",
76
- "@types/express": "^5.0.5",
79
+ "@types/express": "^5.0.6",
77
80
  "@types/kerberos": "^1.1.5",
78
81
  "@types/mocha": "^10.0.9",
79
82
  "@types/node": "^22.15.3",
80
83
  "@types/saslprep": "^1.0.3",
81
84
  "@types/semver": "^7.7.0",
82
85
  "@types/sinon": "^17.0.4",
83
- "@types/sinon-chai": "^4.0.0",
84
86
  "@types/whatwg-url": "^13.0.0",
85
- "@typescript-eslint/eslint-plugin": "^8.46.3",
87
+ "@typescript-eslint/eslint-plugin": "^8.60.1",
86
88
  "@typescript-eslint/parser": "^8.31.1",
87
89
  "aws4": "^1.13.2",
88
- "chai": "^4.4.1",
90
+ "chai": "^5.3.3",
89
91
  "chai-subset": "^1.6.0",
90
92
  "chalk": "^4.1.2",
93
+ "esbuild": "^0.28.0",
91
94
  "eslint": "^9.39.1",
92
95
  "eslint-config-prettier": "^10.1.8",
93
96
  "eslint-plugin-mocha": "^10.4.1",
94
- "eslint-plugin-prettier": "^5.5.4",
97
+ "eslint-plugin-prettier": "^5.5.6",
95
98
  "eslint-plugin-simple-import-sort": "^12.1.1",
96
- "eslint-plugin-tsdoc": "^0.4.0",
97
- "eslint-plugin-unused-imports": "^4.2.0",
98
- "express": "^5.1.0",
99
+ "eslint-plugin-tsdoc": "^0.5.2",
100
+ "eslint-plugin-unused-imports": "^4.4.1",
101
+ "express": "^5.2.1",
99
102
  "gcp-metadata": "^7.0.1",
100
- "js-yaml": "^4.1.0",
101
- "mocha": "^11.7.5",
103
+ "js-yaml": "^4.2.0",
104
+ "mocha": "^11.7.6",
102
105
  "mocha-sinon": "^2.1.2",
103
- "mongodb-client-encryption": "^7.0.0",
106
+ "mongodb-client-encryption": "^7.2.0",
104
107
  "nyc": "^17.1.0",
105
108
  "prettier": "^3.6.2",
106
109
  "semver": "^7.7.2",
107
110
  "sinon": "^18.0.1",
108
- "sinon-chai": "^3.7.0",
111
+ "sinon-chai": "^4.0.1",
109
112
  "snappy": "^7.3.2",
110
113
  "socks": "^2.8.7",
111
114
  "source-map-support": "^0.5.21",
@@ -134,32 +137,42 @@
134
137
  "check:bench": "npm --prefix test/benchmarks/driver_bench start",
135
138
  "check:coverage": "nyc npm run test:all",
136
139
  "check:integration-coverage": "nyc npm run check:test",
137
- "check:lambda": "nyc mocha --config test/mocha_lambda.js test/integration/node-specific/examples/handler.test.js",
138
- "check:lambda:aws": "nyc mocha --config test/mocha_lambda.js test/integration/node-specific/examples/aws_handler.test.js",
140
+ "check:lambda": "npm run build:bundle && nyc mocha --config test/mocha_lambda.js test/integration/node-specific/examples/handler.test.js",
141
+ "check:lambda:aws": "npm run build:bundle && nyc mocha --config test/mocha_lambda.js test/integration/node-specific/examples/aws_handler.test.js",
139
142
  "check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
140
143
  "check:eslint": "npm run build:dts && ESLINT_USE_FLAT_CONFIG=false eslint -v && ESLINT_USE_FLAT_CONFIG=false eslint --max-warnings=0 --ext '.js,.ts' src test",
141
144
  "check:tsd": "tsd --version && tsd",
142
- "check:dependencies": "mocha test/action/dependency.test.ts",
143
- "check:dts": "node ./node_modules/typescript/bin/tsc --target es2023 --module commonjs --noEmit mongodb.d.ts && tsd",
144
- "check:search-indexes": "nyc mocha --config test/mocha_mongodb.js test/manual/search-index-management.prose.test.ts",
145
- "check:test": "mocha --config test/mocha_mongodb.js test/integration",
146
- "check:unit": "nyc mocha test/unit",
145
+ "check:dependencies": "npm run build:bundle && mocha test/action/dependency.test.ts",
146
+ "check:dts": "npm run build:bundle && node ./node_modules/typescript/bin/tsc --target es2023 --module commonjs --noEmit mongodb.d.ts && tsd",
147
+ "check:search-indexes": "npm run build:bundle && nyc mocha --config test/mocha_mongodb.js test/manual/search-index-management.prose.test.ts",
148
+ "check:test": "npm run build:bundle && nyc mocha --config test/mocha_mongodb.js test/integration",
149
+ "check:test:debug": "npm run mocha:debug -- --config test/mocha_mongodb.js test/integration",
150
+ "check:test-bundled": "MONGODB_BUNDLED=true npm run check:test",
151
+ "check:unit": "npm run build:bundle && nyc mocha test/unit",
152
+ "check:unit:debug": "npm run mocha:debug -- test/unit",
153
+ "check:unit-bundled": "MONGODB_BUNDLED=true npm run check:unit",
147
154
  "check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
148
- "check:atlas": "nyc mocha --config test/manual/mocharc.js test/manual/atlas_connectivity.test.ts",
149
- "check:drivers-atlas-testing": "nyc mocha --config test/mocha_mongodb.js test/atlas/drivers_atlas_testing.test.ts",
150
- "check:aws": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_aws.test.ts test/integration/auth/mongodb_aws.prose.test.ts",
151
- "check:oidc-auth": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/auth.spec.test.ts",
152
- "check:oidc-test": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_oidc.prose.test.ts",
153
- "check:kerberos": "nyc mocha --config test/manual/mocharc.js test/manual/kerberos.test.ts",
154
- "check:tls": "nyc mocha --config test/manual/mocharc.js test/manual/tls_support.test.ts",
155
- "check:ldap": "nyc mocha --config test/manual/mocharc.js test/manual/ldap.test.ts",
156
- "check:socks5": "nyc mocha --config test/manual/mocharc.js test/manual/socks5.test.ts",
157
- "check:csfle": "nyc mocha --config test/mocha_mongodb.js test/integration/client-side-encryption",
158
- "check:snappy": "nyc mocha test/unit/assorted/snappy.test.js",
159
- "check:x509": "nyc mocha test/manual/x509_auth.test.ts",
155
+ "check:atlas": "npm run build:bundle && nyc mocha --config test/manual/mocharc.js test/manual/atlas_connectivity.test.ts",
156
+ "check:drivers-atlas-testing": "npm run build:bundle && nyc mocha --config test/mocha_mongodb.js test/atlas/drivers_atlas_testing.test.ts",
157
+ "check:aws": "npm run build:bundle && nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_aws.test.ts test/integration/auth/mongodb_aws.prose.test.ts",
158
+ "check:oidc-auth": "npm run build:bundle && nyc mocha --config test/mocha_mongodb.js test/integration/auth/auth.spec.test.ts",
159
+ "check:oidc-test": "npm run build:bundle && nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_oidc.prose.test.ts",
160
+ "check:kerberos": "npm run build:bundle && nyc mocha --config test/manual/mocharc.js test/manual/kerberos.test.ts",
161
+ "check:tls": "npm run build:bundle && nyc mocha --config test/manual/mocharc.js test/manual/tls_support.test.ts",
162
+ "check:ldap": "npm run build:bundle && nyc mocha --config test/manual/mocharc.js test/manual/ldap.test.ts",
163
+ "check:socks5": "npm run build:bundle && nyc mocha --config test/manual/mocharc.js test/manual/socks5.test.ts",
164
+ "check:csfle": "npm run build:bundle && nyc mocha --config test/mocha_mongodb.js test/integration/client-side-encryption",
165
+ "check:snappy": "npm run build:bundle && nyc mocha test/unit/assorted/snappy.test.js",
166
+ "check:x509": "npm run build:bundle && nyc mocha test/manual/x509_auth.test.ts",
167
+ "mocha:debug": "npm run build:bundle && node --inspect --enable-source-maps --no-experimental-strip-types ./node_modules/mocha/bin/mocha.js",
168
+ "build:bundle": "npm run bundle:driver && npm run bundle:types && npm run build:runtime-barrel",
169
+ "build:runtime-barrel": "node etc/build-runtime-barrel.mjs",
170
+ "bundle:driver": "node etc/bundle-driver.mjs",
171
+ "bundle:types": "npx tsc --project ./tsconfig.json --declaration --emitDeclarationOnly --declarationDir test/tools/runner/bundle/types",
160
172
  "fix:eslint": "npm run check:eslint -- --fix",
161
- "prepare": "node etc/prepare.js",
162
173
  "preview:docs": "ts-node etc/docs/preview.ts",
174
+ "switch:to-bundled": "MONGODB_BUNDLED=true npm run build:runtime-barrel",
175
+ "switch:to-unbundled": "MONGODB_BUNDLED=false npm run build:runtime-barrel",
163
176
  "test": "npm run check:lint && npm run test:all",
164
177
  "test:all": "npm run check:unit && npm run check:test",
165
178
  "update:docs": "npm run build:docs -- --yes"
@@ -176,22 +189,22 @@
176
189
  "depup": {
177
190
  "changes": {
178
191
  "@mongodb-js/saslprep": {
179
- "from": "^1.3.0",
180
- "to": "^1.4.6"
192
+ "from": "^1.4.11",
193
+ "to": "^1.4.12"
181
194
  },
182
195
  "bson": {
183
- "from": "^7.1.1",
184
- "to": "^7.2.0"
196
+ "from": "^7.2.0",
197
+ "to": "^7.3.1"
185
198
  },
186
199
  "mongodb-connection-string-url": {
187
- "from": "^7.0.0",
188
- "to": "^7.0.1"
200
+ "from": "^7.0.1",
201
+ "to": "^7.0.2"
189
202
  }
190
203
  },
191
204
  "depsUpdated": 3,
192
205
  "originalPackage": "mongodb",
193
- "originalVersion": "7.1.0",
194
- "processedAt": "2026-03-09T04:58:47.350Z",
206
+ "originalVersion": "7.5.0",
207
+ "processedAt": "2026-07-21T16:17:48.439Z",
195
208
  "smokeTest": "passed"
196
209
  }
197
210
  }
package/src/bson.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-restricted-imports */
2
- import { BSON, type DeserializeOptions, type SerializeOptions } from 'bson';
2
+ import { BSON, type DeserializeOptions, NumberUtils, type SerializeOptions } from 'bson';
3
3
 
4
4
  export {
5
5
  Binary,
@@ -8,6 +8,7 @@ export {
8
8
  BSONRegExp,
9
9
  BSONSymbol,
10
10
  BSONType,
11
+ ByteUtils,
11
12
  calculateObjectSize,
12
13
  Code,
13
14
  DBRef,
@@ -38,10 +39,38 @@ export function parseToElementsToArray(bytes: Uint8Array, offset?: number): BSON
38
39
  return Array.isArray(res) ? res : [...res];
39
40
  }
40
41
 
41
- export const getInt32LE = BSON.onDemand.NumberUtils.getInt32LE;
42
- export const getFloat64LE = BSON.onDemand.NumberUtils.getFloat64LE;
43
- export const getBigInt64LE = BSON.onDemand.NumberUtils.getBigInt64LE;
44
- export const toUTF8 = BSON.onDemand.ByteUtils.toUTF8;
42
+ // validates buffer inputs, used for read operations
43
+ const validateBufferInputs = (buffer: Uint8Array, offset: number, length: number) => {
44
+ if (offset < 0 || offset + length > buffer.length) {
45
+ throw new RangeError(
46
+ `Attempt to access memory outside buffer bounds: buffer length: ${buffer.length}, offset: ${offset}, length: ${length}`
47
+ );
48
+ }
49
+ };
50
+
51
+ // readInt32LE, reads a 32-bit integer from buffer at given offset
52
+ // throws if offset is out of bounds
53
+ export const readInt32LE = (buffer: Uint8Array, offset: number): number => {
54
+ validateBufferInputs(buffer, offset, 4);
55
+ return NumberUtils.getInt32LE(buffer, offset);
56
+ };
57
+
58
+ // readUint8, reads a single unsigned byte from buffer at given offset
59
+ export const readUint8 = (buffer: Uint8Array, offset: number): number => {
60
+ validateBufferInputs(buffer, offset, 1);
61
+ return buffer[offset];
62
+ };
63
+
64
+ export const setUint32LE = (destination: Uint8Array, offset: number, value: number): 4 => {
65
+ destination[offset] = value;
66
+ value >>>= 8;
67
+ destination[offset + 1] = value;
68
+ value >>>= 8;
69
+ destination[offset + 2] = value;
70
+ value >>>= 8;
71
+ destination[offset + 3] = value;
72
+ return 4;
73
+ };
45
74
 
46
75
  /**
47
76
  * BSON Serialization options.
@@ -573,7 +573,6 @@ export class ChangeStream<
573
573
  implements AsyncDisposable
574
574
  {
575
575
  /**
576
- * @experimental
577
576
  * An alias for {@link ChangeStream.close|ChangeStream.close()}.
578
577
  */
579
578
  async [Symbol.asyncDispose]() {
@@ -705,6 +704,11 @@ export class ChangeStream<
705
704
  return this.cursor?.resumeToken;
706
705
  }
707
706
 
707
+ /** Returns the currently buffered documents length of the underlying cursor. */
708
+ bufferedCount(): number {
709
+ return this.cursor?.bufferedCount() ?? 0;
710
+ }
711
+
708
712
  /** Check if there is any document still available in the Change Stream */
709
713
  async hasNext(): Promise<boolean> {
710
714
  this._setIsIterator();
@@ -1,7 +1,7 @@
1
1
  import { type MongoCrypt, type MongoCryptOptions } from 'mongodb-client-encryption';
2
2
  import * as net from 'net';
3
3
 
4
- import { deserialize, type Document, serialize } from '../bson';
4
+ import { ByteUtils, deserialize, type Document, serialize } from '../bson';
5
5
  import { type CommandOptions, type ProxyOptions } from '../cmap/connection';
6
6
  import { kDecorateResult } from '../constants';
7
7
  import { getMongoDBClientEncryption } from '../deps';
@@ -256,20 +256,26 @@ export class AutoEncrypter {
256
256
  errorWrapper: defaultErrorWrapper
257
257
  };
258
258
  if (options.schemaMap) {
259
- mongoCryptOptions.schemaMap = Buffer.isBuffer(options.schemaMap)
260
- ? options.schemaMap
261
- : (serialize(options.schemaMap) as Buffer);
259
+ if (ByteUtils.isUint8Array(options.schemaMap)) {
260
+ mongoCryptOptions.schemaMap = options.schemaMap;
261
+ } else {
262
+ mongoCryptOptions.schemaMap = serialize(options.schemaMap);
263
+ }
262
264
  }
263
265
 
264
266
  if (options.encryptedFieldsMap) {
265
- mongoCryptOptions.encryptedFieldsMap = Buffer.isBuffer(options.encryptedFieldsMap)
266
- ? options.encryptedFieldsMap
267
- : (serialize(options.encryptedFieldsMap) as Buffer);
267
+ if (ByteUtils.isUint8Array(options.encryptedFieldsMap)) {
268
+ mongoCryptOptions.encryptedFieldsMap = options.encryptedFieldsMap;
269
+ } else {
270
+ mongoCryptOptions.encryptedFieldsMap = serialize(options.encryptedFieldsMap);
271
+ }
268
272
  }
269
273
 
270
- mongoCryptOptions.kmsProviders = !Buffer.isBuffer(this._kmsProviders)
271
- ? (serialize(this._kmsProviders) as Buffer)
272
- : this._kmsProviders;
274
+ if (ByteUtils.isUint8Array(this._kmsProviders)) {
275
+ mongoCryptOptions.kmsProviders = this._kmsProviders;
276
+ } else {
277
+ mongoCryptOptions.kmsProviders = serialize(this._kmsProviders);
278
+ }
273
279
 
274
280
  if (options.options?.logger) {
275
281
  mongoCryptOptions.logger = options.options.logger;
@@ -396,7 +402,7 @@ export class AutoEncrypter {
396
402
  return cmd;
397
403
  }
398
404
 
399
- const commandBuffer = Buffer.isBuffer(cmd) ? cmd : serialize(cmd, options);
405
+ const commandBuffer: Uint8Array = serialize(cmd, options);
400
406
  const context = this._mongocrypt.makeEncryptionContext(
401
407
  MongoDBCollectionNamespace.fromString(ns).db,
402
408
  commandBuffer
@@ -143,9 +143,7 @@ export class ClientEncryption {
143
143
 
144
144
  const mongoCryptOptions: MongoCryptOptions = {
145
145
  ...options,
146
- kmsProviders: !Buffer.isBuffer(this._kmsProviders)
147
- ? (serialize(this._kmsProviders) as Buffer)
148
- : this._kmsProviders,
146
+ kmsProviders: serialize(this._kmsProviders),
149
147
  errorWrapper: defaultErrorWrapper
150
148
  };
151
149
 
@@ -748,8 +746,16 @@ export class ClientEncryption {
748
746
  expressionMode: boolean,
749
747
  options: ClientEncryptionEncryptOptions
750
748
  ): Promise<Binary> {
751
- const { algorithm, keyId, keyAltName, contentionFactor, queryType, rangeOptions, textOptions } =
752
- options;
749
+ const {
750
+ algorithm,
751
+ keyId,
752
+ keyAltName,
753
+ contentionFactor,
754
+ queryType,
755
+ rangeOptions,
756
+ stringOptions,
757
+ textOptions
758
+ } = options;
753
759
  const contextOptions: ExplicitEncryptionContextOptions = {
754
760
  expressionMode,
755
761
  algorithm
@@ -782,8 +788,9 @@ export class ClientEncryption {
782
788
  contextOptions.rangeOptions = serialize(rangeOptions);
783
789
  }
784
790
 
785
- if (typeof textOptions === 'object') {
786
- contextOptions.textOptions = serialize(textOptions);
791
+ const resolvedStringOptions = stringOptions ?? textOptions;
792
+ if (typeof resolvedStringOptions === 'object') {
793
+ contextOptions.textOptions = serialize(resolvedStringOptions);
787
794
  }
788
795
 
789
796
  const valueBuffer = serialize({ v: value });
@@ -817,6 +824,8 @@ export interface ClientEncryptionEncryptOptions {
817
824
  | 'Indexed'
818
825
  | 'Unindexed'
819
826
  | 'Range'
827
+ | 'String'
828
+ /** @deprecated Use `'String'` instead. */
820
829
  | 'TextPreview';
821
830
 
822
831
  /**
@@ -835,26 +844,39 @@ export interface ClientEncryptionEncryptOptions {
835
844
  /**
836
845
  * The query type.
837
846
  */
838
- queryType?: 'equality' | 'range' | 'prefixPreview' | 'suffixPreview' | 'substringPreview';
847
+ queryType?:
848
+ | 'equality'
849
+ | 'range'
850
+ | 'prefix'
851
+ | 'suffix'
852
+ | 'substring'
853
+ /** @deprecated Use `'prefix'` instead. */
854
+ | 'prefixPreview'
855
+ /** @deprecated Use `'suffix'` instead. */
856
+ | 'suffixPreview'
857
+ /** @deprecated Use `'substring'` instead. */
858
+ | 'substringPreview';
839
859
 
840
860
  /** The index options for a Queryable Encryption field supporting "range" queries.*/
841
861
  rangeOptions?: RangeOptions;
842
862
 
863
+ /** Options for a Queryable Encryption field supporting string queries. Only valid when `algorithm` is `'String'` or the deprecated `'TextPreview'`. */
864
+ stringOptions?: StringQueryOptions;
865
+
843
866
  /**
844
- * Options for a Queryable Encryption field supporting text queries. Only valid when `algorithm` is `TextPreview`.
867
+ * Options for a Queryable Encryption field supporting text queries. Only valid when `algorithm` is `'String'` or the deprecated `'TextPreview'`.
845
868
  *
846
- * @experimental Public Technical Preview: `textPreview` is an experimental feature and may break at any time.
869
+ * @deprecated Use `stringOptions` instead.
847
870
  */
848
- textOptions?: TextQueryOptions;
871
+ textOptions?: StringQueryOptions;
849
872
  }
850
873
 
851
874
  /**
852
- * Options for a Queryable Encryption field supporting text queries.
875
+ * Options for a Queryable Encryption field supporting string queries.
853
876
  *
854
877
  * @public
855
- * @experimental Public Technical Preview: `textPreview` is an experimental feature and may break at any time.
856
878
  */
857
- export interface TextQueryOptions {
879
+ export interface StringQueryOptions {
858
880
  /** Indicates that text indexes for this field are case sensitive */
859
881
  caseSensitive: boolean;
860
882
  /** Indicates that text indexes for this field are diacritic sensitive. */
@@ -884,6 +906,12 @@ export interface TextQueryOptions {
884
906
  };
885
907
  }
886
908
 
909
+ /**
910
+ * @public
911
+ * @deprecated Use {@link StringQueryOptions} instead.
912
+ */
913
+ export type TextQueryOptions = StringQueryOptions;
914
+
887
915
  /**
888
916
  * @public
889
917
  * @experimental
@@ -21,7 +21,7 @@ export class AuthContext {
21
21
  /** A response from an initial auth attempt, only some mechanisms use this (e.g, SCRAM) */
22
22
  response?: Document;
23
23
  /** A random nonce generated for use in an authentication conversation */
24
- nonce?: Buffer;
24
+ nonce?: Uint8Array;
25
25
 
26
26
  constructor(
27
27
  connection: Connection,
@@ -1,4 +1,4 @@
1
- import { BSON } from '../../bson';
1
+ import { ByteUtils } from '../../bson';
2
2
  import { type AWSCredentials } from '../../deps';
3
3
 
4
4
  export type AwsSigv4Options = {
@@ -31,7 +31,7 @@ export type SignedHeaders = {
31
31
  const getHexSha256 = async (str: string): Promise<string> => {
32
32
  const data = stringToBuffer(str);
33
33
  const hashBuffer = await crypto.subtle.digest('SHA-256', data);
34
- const hashHex = BSON.onDemand.ByteUtils.toHex(new Uint8Array(hashBuffer));
34
+ const hashHex = ByteUtils.toHex(new Uint8Array(hashBuffer));
35
35
  return hashHex;
36
36
  };
37
37
 
@@ -81,8 +81,8 @@ const convertHeaderValue = (value: string | number) => {
81
81
  * @returns Uint8Array containing the UTF-8 encoded string.
82
82
  */
83
83
  function stringToBuffer(str: string): Uint8Array {
84
- const data = new Uint8Array(BSON.onDemand.ByteUtils.utf8ByteLength(str));
85
- BSON.onDemand.ByteUtils.encodeUTF8Into(data, str, 0);
84
+ const data = new Uint8Array(ByteUtils.utf8ByteLength(str));
85
+ ByteUtils.encodeUTF8Into(data, str, 0);
86
86
  return data;
87
87
  }
88
88
 
@@ -189,7 +189,7 @@ export async function aws4Sign(
189
189
 
190
190
  // 5. Calculate the signature
191
191
  const signatureBuffer = await getHmacSha256(signingKey, stringToSign);
192
- const signature = BSON.onDemand.ByteUtils.toHex(signatureBuffer);
192
+ const signature = ByteUtils.toHex(signatureBuffer);
193
193
 
194
194
  // 6. Add the signature to the request
195
195
  // Calculate the Authorization header
@@ -1,5 +1,4 @@
1
1
  import * as dns from 'dns';
2
- import * as os from 'os';
3
2
 
4
3
  import { getKerberos, type Kerberos, type KerberosClient } from '../../deps';
5
4
  import { MongoInvalidArgumentError, MongoMissingCredentialsError } from '../../error';
@@ -69,9 +68,13 @@ export class GSSAPI extends AuthProvider {
69
68
  }
70
69
  }
71
70
 
72
- async function makeKerberosClient(authContext: AuthContext): Promise<KerberosClient> {
73
- const { hostAddress } = authContext.options;
74
- const { credentials } = authContext;
71
+ async function makeKerberosClient({
72
+ options: {
73
+ hostAddress,
74
+ runtime: { os }
75
+ },
76
+ credentials
77
+ }: AuthContext): Promise<KerberosClient> {
75
78
  if (!hostAddress || typeof hostAddress.host !== 'string' || !credentials) {
76
79
  throw new MongoInvalidArgumentError(
77
80
  'Connection must have host and port and credentials defined.'
@@ -166,7 +169,7 @@ export async function performGSSAPICanonicalizeHostName(
166
169
 
167
170
  try {
168
171
  // Perform a reverse ptr lookup on the ip address.
169
- const results = await dns.promises.resolvePtr(address);
172
+ const results = await dns.promises.resolve(address, 'PTR');
170
173
  // If the ptr did not error but had no results, return the host.
171
174
  return results.length > 0 ? results[0] : host;
172
175
  } catch {
@@ -185,7 +188,7 @@ export async function performGSSAPICanonicalizeHostName(
185
188
  export async function resolveCname(host: string): Promise<string> {
186
189
  // Attempt to resolve the host name
187
190
  try {
188
- const results = await dns.promises.resolveCname(host);
191
+ const results = await dns.promises.resolve(host, 'CNAME');
189
192
  // Get the first resolved host id
190
193
  return results.length > 0 ? results[0] : host;
191
194
  } catch {
@@ -1,11 +1,11 @@
1
- import type { Binary, BSONSerializeOptions } from '../../bson';
1
+ import { type Binary, type BSONSerializeOptions, ByteUtils } from '../../bson';
2
2
  import * as BSON from '../../bson';
3
3
  import {
4
4
  MongoCompatibilityError,
5
5
  MongoMissingCredentialsError,
6
6
  MongoRuntimeError
7
7
  } from '../../error';
8
- import { ByteUtils, maxWireVersion, ns, randomBytes } from '../../utils';
8
+ import { maxWireVersion, ns, randomBytes } from '../../utils';
9
9
  import { type AuthContext, AuthProvider } from './auth_provider';
10
10
  import {
11
11
  type AWSCredentialProvider,
@@ -19,7 +19,7 @@ const TOKEN_RESOURCE_MISSING_ERROR =
19
19
  * @param params - The OIDC callback parameters.
20
20
  * @returns The OIDC response.
21
21
  */
22
- export const callback: OIDCCallbackFunction = async (
22
+ export const azureCallback: OIDCCallbackFunction = async (
23
23
  params: OIDCCallbackParams
24
24
  ): Promise<OIDCResponse> => {
25
25
  const tokenAudience = params.tokenAudience;
@@ -18,7 +18,7 @@ const TOKEN_RESOURCE_MISSING_ERROR =
18
18
  * @param params - The OIDC callback parameters.
19
19
  * @returns The OIDC response.
20
20
  */
21
- export const callback: OIDCCallbackFunction = async (
21
+ export const gcpCallback: OIDCCallbackFunction = async (
22
22
  params: OIDCCallbackParams
23
23
  ): Promise<OIDCResponse> => {
24
24
  const tokenAudience = params.tokenAudience;
@@ -17,7 +17,7 @@ const AWS_FILENAME = 'AWS_WEB_IDENTITY_TOKEN_FILE';
17
17
  * @param params - The OIDC callback parameters.
18
18
  * @returns The OIDC response.
19
19
  */
20
- export const callback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
20
+ export const k8sCallback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
21
21
  let filename: string;
22
22
  if (process.env[AZURE_FILENAME]) {
23
23
  filename = process.env[AZURE_FILENAME];
@@ -12,7 +12,7 @@ const TOKEN_MISSING_ERROR = 'OIDC_TOKEN_FILE must be set in the environment.';
12
12
  * @param params - The OIDC callback parameters.
13
13
  * @returns The OIDC response.
14
14
  */
15
- export const callback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
15
+ export const tokenMachineCallback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
16
16
  const tokenFile = process.env.OIDC_TOKEN_FILE;
17
17
  if (!tokenFile) {
18
18
  throw new MongoAWSError(TOKEN_MISSING_ERROR);
@@ -5,11 +5,11 @@ import type { Connection } from '../connection';
5
5
  import { type AuthContext, AuthProvider } from './auth_provider';
6
6
  import type { MongoCredentials } from './mongo_credentials';
7
7
  import { AutomatedCallbackWorkflow } from './mongodb_oidc/automated_callback_workflow';
8
- import { callback as azureCallback } from './mongodb_oidc/azure_machine_workflow';
9
- import { callback as gcpCallback } from './mongodb_oidc/gcp_machine_workflow';
10
- import { callback as k8sCallback } from './mongodb_oidc/k8s_machine_workflow';
8
+ import { azureCallback } from './mongodb_oidc/azure_machine_workflow';
9
+ import { gcpCallback } from './mongodb_oidc/gcp_machine_workflow';
10
+ import { k8sCallback } from './mongodb_oidc/k8s_machine_workflow';
11
11
  import { TokenCache } from './mongodb_oidc/token_cache';
12
- import { callback as testCallback } from './mongodb_oidc/token_machine_workflow';
12
+ import { tokenMachineCallback as testCallback } from './mongodb_oidc/token_machine_workflow';
13
13
 
14
14
  /** Error when credentials are missing. */
15
15
  const MISSING_CREDENTIALS_ERROR = 'AuthContext must provide credentials.';
@@ -1,4 +1,4 @@
1
- import { Binary } from '../../bson';
1
+ import { Binary, ByteUtils } from '../../bson';
2
2
  import { MongoMissingCredentialsError } from '../../error';
3
3
  import { ns } from '../../utils';
4
4
  import { type AuthContext, AuthProvider } from './auth_provider';
@@ -12,7 +12,7 @@ export class Plain extends AuthProvider {
12
12
 
13
13
  const { username, password } = credentials;
14
14
 
15
- const payload = new Binary(Buffer.from(`\x00${username}\x00${password}`));
15
+ const payload = new Binary(ByteUtils.fromUTF8(`\x00${username}\x00${password}`));
16
16
  const command = {
17
17
  saslStart: 1,
18
18
  mechanism: 'PLAIN',