mongodb 6.20.0-dev.20251106.sha.696664cb → 6.21.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.
- package/README.md +11 -11
- package/lib/beta.d.ts +9229 -0
- package/lib/beta.js +21 -0
- package/lib/beta.js.map +1 -0
- package/lib/bulk/common.js +9 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +38 -84
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +4 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +3 -2
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/crypto_callbacks.js +81 -0
- package/lib/client-side-encryption/crypto_callbacks.js.map +1 -0
- package/lib/client-side-encryption/errors.js +1 -3
- package/lib/client-side-encryption/errors.js.map +1 -1
- package/lib/client-side-encryption/mongocryptd_manager.js +1 -1
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +58 -10
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +15 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +7 -2
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/providers.js +1 -0
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/connect.js +1 -1
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +27 -28
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +59 -59
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/errors.js +1 -1
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +5 -7
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/metrics.js +3 -3
- package/lib/cmap/metrics.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +1 -3
- package/lib/cmap/wire_protocol/constants.js.map +1 -1
- package/lib/cmap/wire_protocol/on_data.js +1 -0
- package/lib/cmap/wire_protocol/on_data.js.map +1 -1
- package/lib/cmap/wire_protocol/responses.js +2 -2
- package/lib/cmap/wire_protocol/responses.js.map +1 -1
- package/lib/collection.js +1 -1
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +10 -8
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +34 -17
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/change_stream_cursor.js +2 -2
- package/lib/cursor/change_stream_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +26 -37
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +1 -1
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +6 -6
- package/lib/db.js.map +1 -1
- package/lib/error.js +2 -2
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +5 -5
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +9 -9
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +8 -2
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +67 -58
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_client_auth_providers.js +6 -0
- package/lib/mongo_client_auth_providers.js.map +1 -1
- package/lib/mongo_logger.js.map +1 -1
- package/lib/mongo_types.js +2 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/aggregate.js +3 -0
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/create_collection.js +1 -0
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/drop.js +9 -8
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/execute_operation.js +1 -3
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/read_preference.js +14 -10
- package/lib/read_preference.js.map +1 -1
- package/lib/resource_management.js +58 -0
- package/lib/resource_management.js.map +1 -0
- package/lib/sdam/server.js +14 -14
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -2
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +68 -24
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +4 -5
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +13 -2
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +14 -0
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +244 -72
- package/package.json +20 -17
- package/src/beta.ts +22 -0
- package/src/bulk/common.ts +11 -9
- package/src/change_stream.ts +37 -85
- package/src/client-side-encryption/auto_encrypter.ts +12 -6
- package/src/client-side-encryption/client_encryption.ts +6 -5
- package/src/client-side-encryption/crypto_callbacks.ts +87 -0
- package/src/client-side-encryption/errors.ts +0 -3
- package/src/cmap/auth/aws_temporary_credentials.ts +70 -12
- package/src/cmap/auth/mongo_credentials.ts +21 -1
- package/src/cmap/auth/mongodb_aws.ts +17 -8
- package/src/cmap/auth/providers.ts +1 -0
- package/src/cmap/connect.ts +1 -1
- package/src/cmap/connection.ts +18 -14
- package/src/cmap/connection_pool.ts +13 -4
- package/src/cmap/errors.ts +1 -1
- package/src/cmap/handshake/client_metadata.ts +26 -18
- package/src/cmap/wire_protocol/constants.ts +0 -2
- package/src/cmap/wire_protocol/on_data.ts +2 -1
- package/src/collection.ts +1 -1
- package/src/connection_string.ts +20 -13
- package/src/cursor/abstract_cursor.ts +52 -12
- package/src/cursor/change_stream_cursor.ts +2 -2
- package/src/cursor/find_cursor.ts +27 -40
- package/src/cursor/run_command_cursor.ts +1 -1
- package/src/error.ts +2 -2
- package/src/gridfs/download.ts +4 -0
- package/src/gridfs/upload.ts +22 -0
- package/src/index.ts +8 -2
- package/src/mongo_client.ts +100 -68
- package/src/mongo_client_auth_providers.ts +8 -0
- package/src/mongo_logger.ts +1 -1
- package/src/mongo_types.ts +2 -1
- package/src/operations/aggregate.ts +6 -0
- package/src/operations/command.ts +12 -0
- package/src/operations/create_collection.ts +3 -0
- package/src/operations/drop.ts +11 -9
- package/src/operations/execute_operation.ts +2 -6
- package/src/operations/find.ts +11 -2
- package/src/read_preference.ts +9 -0
- package/src/resource_management.ts +74 -0
- package/src/sdam/topology.ts +60 -2
- package/src/sessions.ts +8 -2
- package/src/transactions.ts +17 -2
- package/src/utils.ts +18 -0
- package/tsconfig.json +7 -5
- package/lib/operations/end_sessions.js +0 -34
- package/lib/operations/end_sessions.js.map +0 -1
- package/src/operations/end_sessions.ts +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.21.0",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@mongodb-js/saslprep": "^1.3.0",
|
|
29
|
-
"bson": "^
|
|
30
|
-
"mongodb-connection-string-url": "^
|
|
29
|
+
"bson": "^6.10.4",
|
|
30
|
+
"mongodb-connection-string-url": "^3.0.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@aws-sdk/credential-providers": "^3.
|
|
34
|
-
"@mongodb-js/zstd": "^
|
|
35
|
-
"gcp-metadata": "^
|
|
36
|
-
"kerberos": "^
|
|
37
|
-
"mongodb-client-encryption": ">=
|
|
33
|
+
"@aws-sdk/credential-providers": "^3.188.0",
|
|
34
|
+
"@mongodb-js/zstd": "^1.1.0 || ^2.0.0",
|
|
35
|
+
"gcp-metadata": "^5.2.0",
|
|
36
|
+
"kerberos": "^2.0.1",
|
|
37
|
+
"mongodb-client-encryption": ">=6.0.0 <7",
|
|
38
38
|
"snappy": "^7.3.2",
|
|
39
|
-
"socks": "^2.
|
|
39
|
+
"socks": "^2.7.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@aws-sdk/credential-providers": {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
68
68
|
"@microsoft/api-extractor": "^7.52.11",
|
|
69
69
|
"@microsoft/tsdoc-config": "^0.17.1",
|
|
70
|
-
"@mongodb-js/zstd": "^
|
|
70
|
+
"@mongodb-js/zstd": "^2.0.1",
|
|
71
71
|
"@types/chai": "^4.3.17",
|
|
72
72
|
"@types/chai-subset": "^1.3.5",
|
|
73
73
|
"@types/express": "^5.0.3",
|
|
@@ -92,11 +92,12 @@
|
|
|
92
92
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
93
93
|
"eslint-plugin-unused-imports": "^4.2.0",
|
|
94
94
|
"express": "^5.1.0",
|
|
95
|
-
"gcp-metadata": "^
|
|
95
|
+
"gcp-metadata": "^5.3.0",
|
|
96
96
|
"js-yaml": "^4.1.0",
|
|
97
97
|
"mocha": "^11.7.1",
|
|
98
98
|
"mocha-sinon": "^2.1.2",
|
|
99
|
-
"mongodb-client-encryption": "^
|
|
99
|
+
"mongodb-client-encryption": "^6.5.0",
|
|
100
|
+
"mongodb-legacy": "^6.1.3",
|
|
100
101
|
"nyc": "^15.1.0",
|
|
101
102
|
"prettier": "^3.6.2",
|
|
102
103
|
"semver": "^7.7.2",
|
|
@@ -114,7 +115,7 @@
|
|
|
114
115
|
},
|
|
115
116
|
"license": "Apache-2.0",
|
|
116
117
|
"engines": {
|
|
117
|
-
"node": ">=20.
|
|
118
|
+
"node": ">=16.20.1"
|
|
118
119
|
},
|
|
119
120
|
"bugs": {
|
|
120
121
|
"url": "https://jira.mongodb.org/projects/NODE/issues/"
|
|
@@ -123,7 +124,7 @@
|
|
|
123
124
|
"scripts": {
|
|
124
125
|
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
|
|
125
126
|
"build:ts": "node ./node_modules/typescript/bin/tsc",
|
|
126
|
-
"build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs && ESLINT_USE_FLAT_CONFIG=false eslint --no-ignore --fix mongodb.d.ts",
|
|
127
|
+
"build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs && ESLINT_USE_FLAT_CONFIG=false eslint --no-ignore --fix mongodb.d.ts lib/beta.d.ts",
|
|
127
128
|
"build:docs": "./etc/docs/build.ts",
|
|
128
129
|
"build:typedoc": "typedoc",
|
|
129
130
|
"build:nightly": "node ./.github/scripts/nightly.mjs",
|
|
@@ -136,14 +137,16 @@
|
|
|
136
137
|
"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",
|
|
137
138
|
"check:tsd": "tsd --version && tsd",
|
|
138
139
|
"check:dependencies": "mocha test/action/dependency.test.ts",
|
|
139
|
-
"check:dts": "node ./node_modules/typescript/bin/tsc --
|
|
140
|
+
"check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
|
|
140
141
|
"check:search-indexes": "nyc mocha --config test/mocha_mongodb.js test/manual/search-index-management.prose.test.ts",
|
|
141
142
|
"check:test": "mocha --config test/mocha_mongodb.js test/integration",
|
|
142
143
|
"check:unit": "nyc mocha test/unit",
|
|
143
144
|
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
|
|
144
145
|
"check:atlas": "nyc mocha --config test/manual/mocharc.js test/manual/atlas_connectivity.test.ts",
|
|
146
|
+
"check:resource-management": "nyc mocha --config test/manual/mocharc.js test/manual/resource_management.test.ts",
|
|
145
147
|
"check:drivers-atlas-testing": "nyc mocha --config test/mocha_mongodb.js test/atlas/drivers_atlas_testing.test.ts",
|
|
146
|
-
"check:
|
|
148
|
+
"check:adl": "nyc mocha --config test/mocha_mongodb.js test/manual/atlas-data-lake-testing",
|
|
149
|
+
"check:aws": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_aws.test.ts",
|
|
147
150
|
"check:oidc-auth": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/auth.spec.test.ts",
|
|
148
151
|
"check:oidc-test": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_oidc.prose.test.ts",
|
|
149
152
|
"check:oidc-azure": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_oidc_azure.prose.05.test.ts",
|
|
@@ -172,4 +175,4 @@
|
|
|
172
175
|
"moduleResolution": "node"
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
|
-
}
|
|
178
|
+
}
|
package/src/beta.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Document } from './bson';
|
|
2
|
+
|
|
3
|
+
export * from './index';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*
|
|
8
|
+
* Since we don't bundle tslib helpers, we need to polyfill this method.
|
|
9
|
+
*
|
|
10
|
+
* This is used in the generated JS. Adapted from https://github.com/microsoft/TypeScript/blob/aafdfe5b3f76f5c41abeec412ce73c86da94c75f/src/compiler/factory/emitHelpers.ts#L1202.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function __exportStar(mod: Document) {
|
|
14
|
+
for (const key of Object.keys(mod)) {
|
|
15
|
+
Object.defineProperty(exports, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () {
|
|
18
|
+
return mod[key];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/bulk/common.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type { Topology } from '../sdam/topology';
|
|
|
20
20
|
import { type Sort } from '../sort';
|
|
21
21
|
import { TimeoutContext } from '../timeout';
|
|
22
22
|
import {
|
|
23
|
+
applyRetryableWrites,
|
|
23
24
|
getTopology,
|
|
24
25
|
hasAtomicOperators,
|
|
25
26
|
maybeAddIdToDocuments,
|
|
@@ -526,15 +527,15 @@ async function executeCommands(
|
|
|
526
527
|
finalOptions.checkKeys = false;
|
|
527
528
|
}
|
|
528
529
|
|
|
529
|
-
if (
|
|
530
|
+
if (finalOptions.retryWrites) {
|
|
530
531
|
if (isUpdateBatch(batch)) {
|
|
531
|
-
|
|
532
|
-
|
|
532
|
+
finalOptions.retryWrites =
|
|
533
|
+
finalOptions.retryWrites && !batch.operations.some(op => op.multi);
|
|
533
534
|
}
|
|
534
535
|
|
|
535
536
|
if (isDeleteBatch(batch)) {
|
|
536
|
-
|
|
537
|
-
|
|
537
|
+
finalOptions.retryWrites =
|
|
538
|
+
finalOptions.retryWrites && !batch.operations.some(op => op.limit === 0);
|
|
538
539
|
}
|
|
539
540
|
}
|
|
540
541
|
|
|
@@ -858,8 +859,6 @@ export abstract class BulkOperationBase {
|
|
|
858
859
|
s: BulkOperationPrivate;
|
|
859
860
|
operationId?: number;
|
|
860
861
|
private collection: Collection;
|
|
861
|
-
/** @internal */
|
|
862
|
-
retryWrites?: boolean;
|
|
863
862
|
|
|
864
863
|
/**
|
|
865
864
|
* Create a new OrderedBulkOperation or UnorderedBulkOperation instance
|
|
@@ -867,7 +866,6 @@ export abstract class BulkOperationBase {
|
|
|
867
866
|
*/
|
|
868
867
|
constructor(collection: Collection, options: BulkWriteOptions, isOrdered: boolean) {
|
|
869
868
|
this.collection = collection;
|
|
870
|
-
this.retryWrites = collection.db.options?.retryWrites;
|
|
871
869
|
// determine whether bulkOperation is ordered or unordered
|
|
872
870
|
this.isOrdered = isOrdered;
|
|
873
871
|
|
|
@@ -900,6 +898,10 @@ export abstract class BulkOperationBase {
|
|
|
900
898
|
// + 1 bytes for null terminator
|
|
901
899
|
const maxKeySize = (maxWriteBatchSize - 1).toString(10).length + 2;
|
|
902
900
|
|
|
901
|
+
// Final options for retryable writes
|
|
902
|
+
let finalOptions = Object.assign({}, options);
|
|
903
|
+
finalOptions = applyRetryableWrites(finalOptions, collection.db);
|
|
904
|
+
|
|
903
905
|
// Final results
|
|
904
906
|
const bulkResult: BulkResult = {
|
|
905
907
|
ok: 1,
|
|
@@ -941,7 +943,7 @@ export abstract class BulkOperationBase {
|
|
|
941
943
|
// Topology
|
|
942
944
|
topology,
|
|
943
945
|
// Options
|
|
944
|
-
options:
|
|
946
|
+
options: finalOptions,
|
|
945
947
|
// BSON options
|
|
946
948
|
bsonOptions: resolveBSONOptions(options),
|
|
947
949
|
// Current operation
|
package/src/change_stream.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Readable } from 'stream';
|
|
|
3
3
|
import type { Binary, Document, Timestamp } from './bson';
|
|
4
4
|
import { Collection } from './collection';
|
|
5
5
|
import { CHANGE, CLOSE, END, ERROR, INIT, MORE, RESPONSE, RESUME_TOKEN_CHANGED } from './constants';
|
|
6
|
-
import { CursorTimeoutContext } from './cursor/abstract_cursor';
|
|
6
|
+
import { type CursorStreamOptions, CursorTimeoutContext } from './cursor/abstract_cursor';
|
|
7
7
|
import { ChangeStreamCursor, type ChangeStreamCursorOptions } from './cursor/change_stream_cursor';
|
|
8
8
|
import { Db } from './db';
|
|
9
9
|
import {
|
|
@@ -17,10 +17,21 @@ import {
|
|
|
17
17
|
import { MongoClient } from './mongo_client';
|
|
18
18
|
import { type InferIdType, TypedEventEmitter } from './mongo_types';
|
|
19
19
|
import type { AggregateOptions } from './operations/aggregate';
|
|
20
|
-
import type { OperationParent } from './operations/command';
|
|
20
|
+
import type { CollationOptions, OperationParent } from './operations/command';
|
|
21
|
+
import type { ReadPreference } from './read_preference';
|
|
22
|
+
import { type AsyncDisposable, configureResourceManagement } from './resource_management';
|
|
21
23
|
import type { ServerSessionId } from './sessions';
|
|
22
24
|
import { CSOTTimeoutContext, type TimeoutContext } from './timeout';
|
|
23
|
-
import {
|
|
25
|
+
import { filterOptions, getTopology, type MongoDBNamespace, squashError } from './utils';
|
|
26
|
+
|
|
27
|
+
const CHANGE_STREAM_OPTIONS = [
|
|
28
|
+
'resumeAfter',
|
|
29
|
+
'startAfter',
|
|
30
|
+
'startAtOperationTime',
|
|
31
|
+
'fullDocument',
|
|
32
|
+
'fullDocumentBeforeChange',
|
|
33
|
+
'showExpandedEvents'
|
|
34
|
+
] as const;
|
|
24
35
|
|
|
25
36
|
const CHANGE_DOMAIN_TYPES = {
|
|
26
37
|
COLLECTION: Symbol('Collection'),
|
|
@@ -34,12 +45,19 @@ const NO_RESUME_TOKEN_ERROR =
|
|
|
34
45
|
'A change stream document has been received that lacks a resume token (_id).';
|
|
35
46
|
const CHANGESTREAM_CLOSED_ERROR = 'ChangeStream is closed';
|
|
36
47
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
* @deprecated Please use the ChangeStreamCursorOptions type instead.
|
|
51
|
+
*/
|
|
52
|
+
export interface ResumeOptions {
|
|
53
|
+
startAtOperationTime?: Timestamp;
|
|
54
|
+
batchSize?: number;
|
|
55
|
+
maxAwaitTimeMS?: number;
|
|
56
|
+
collation?: CollationOptions;
|
|
57
|
+
readPreference?: ReadPreference;
|
|
58
|
+
resumeAfter?: ResumeToken;
|
|
59
|
+
startAfter?: ResumeToken;
|
|
60
|
+
fullDocument?: string;
|
|
43
61
|
}
|
|
44
62
|
|
|
45
63
|
/**
|
|
@@ -572,10 +590,13 @@ export class ChangeStream<
|
|
|
572
590
|
implements AsyncDisposable
|
|
573
591
|
{
|
|
574
592
|
/**
|
|
593
|
+
* @beta
|
|
575
594
|
* @experimental
|
|
576
595
|
* An alias for {@link ChangeStream.close|ChangeStream.close()}.
|
|
577
596
|
*/
|
|
578
|
-
|
|
597
|
+
declare [Symbol.asyncDispose]: () => Promise<void>;
|
|
598
|
+
/** @internal */
|
|
599
|
+
async asyncDispose() {
|
|
579
600
|
await this.close();
|
|
580
601
|
}
|
|
581
602
|
|
|
@@ -593,6 +614,7 @@ export class ChangeStream<
|
|
|
593
614
|
type: symbol;
|
|
594
615
|
/** @internal */
|
|
595
616
|
private cursor: ChangeStreamCursor<TSchema, TChange>;
|
|
617
|
+
streamOptions?: CursorStreamOptions;
|
|
596
618
|
/** @internal */
|
|
597
619
|
private cursorStream?: Readable & AsyncIterable<TChange>;
|
|
598
620
|
/** @internal */
|
|
@@ -860,12 +882,13 @@ export class ChangeStream<
|
|
|
860
882
|
*
|
|
861
883
|
* @throws MongoChangeStreamError if the underlying cursor or the change stream is closed
|
|
862
884
|
*/
|
|
863
|
-
stream(): Readable & AsyncIterable<TChange> {
|
|
885
|
+
stream(options?: CursorStreamOptions): Readable & AsyncIterable<TChange> {
|
|
864
886
|
if (this.closed) {
|
|
865
887
|
throw new MongoChangeStreamError(CHANGESTREAM_CLOSED_ERROR);
|
|
866
888
|
}
|
|
867
889
|
|
|
868
|
-
|
|
890
|
+
this.streamOptions = options;
|
|
891
|
+
return this.cursor.stream(options);
|
|
869
892
|
}
|
|
870
893
|
|
|
871
894
|
/** @internal */
|
|
@@ -897,7 +920,7 @@ export class ChangeStream<
|
|
|
897
920
|
private _createChangeStreamCursor(
|
|
898
921
|
options: ChangeStreamOptions | ChangeStreamCursorOptions
|
|
899
922
|
): ChangeStreamCursor<TSchema, TChange> {
|
|
900
|
-
const changeStreamStageOptions
|
|
923
|
+
const changeStreamStageOptions = filterOptions(options, CHANGE_STREAM_OPTIONS);
|
|
901
924
|
if (this.type === CHANGE_DOMAIN_TYPES.CLUSTER) {
|
|
902
925
|
changeStreamStageOptions.allChangesForCluster = true;
|
|
903
926
|
}
|
|
@@ -1084,75 +1107,4 @@ export class ChangeStream<
|
|
|
1084
1107
|
}
|
|
1085
1108
|
}
|
|
1086
1109
|
|
|
1087
|
-
|
|
1088
|
-
* This function returns a list of options that are *not* supported by the $changeStream
|
|
1089
|
-
* aggregation stage. This is best-effort - it uses the options "officially supported" by the driver
|
|
1090
|
-
* to derive a list of known, unsupported options for the $changeStream stage.
|
|
1091
|
-
*
|
|
1092
|
-
* Notably, at runtime, users can still provide options unknown to the driver and the driver will
|
|
1093
|
-
* *not* filter them out of the options object (see NODE-5510).
|
|
1094
|
-
*/
|
|
1095
|
-
function buildDisallowedChangeStreamOptions(): Set<string> {
|
|
1096
|
-
/** hard-coded list of allowed ChangeStream options */
|
|
1097
|
-
type CSOptions =
|
|
1098
|
-
| 'resumeAfter'
|
|
1099
|
-
| 'startAfter'
|
|
1100
|
-
| 'startAtOperationTime'
|
|
1101
|
-
| 'fullDocument'
|
|
1102
|
-
| 'fullDocumentBeforeChange'
|
|
1103
|
-
| 'showExpandedEvents';
|
|
1104
|
-
|
|
1105
|
-
/**
|
|
1106
|
-
* a type representing all known options that the driver supports that are *not* change stream stage options.
|
|
1107
|
-
*
|
|
1108
|
-
* each known key is mapped to a non-optional string, so that if new driver-specific options are added, the
|
|
1109
|
-
* instantiation of `denyList` below results in a TS error.
|
|
1110
|
-
*/
|
|
1111
|
-
type DisallowedOptions = {
|
|
1112
|
-
[k in Exclude<
|
|
1113
|
-
keyof ChangeStreamOptions & { timeoutContext: TimeoutContext },
|
|
1114
|
-
CSOptions
|
|
1115
|
-
>]: string;
|
|
1116
|
-
};
|
|
1117
|
-
|
|
1118
|
-
const denyList: DisallowedOptions = {
|
|
1119
|
-
allowDiskUse: '',
|
|
1120
|
-
authdb: '',
|
|
1121
|
-
batchSize: '',
|
|
1122
|
-
bsonRegExp: '',
|
|
1123
|
-
bypassDocumentValidation: '',
|
|
1124
|
-
bypassPinningCheck: '',
|
|
1125
|
-
checkKeys: '',
|
|
1126
|
-
collation: '',
|
|
1127
|
-
comment: '',
|
|
1128
|
-
cursor: '',
|
|
1129
|
-
dbName: '',
|
|
1130
|
-
enableUtf8Validation: '',
|
|
1131
|
-
explain: '',
|
|
1132
|
-
fieldsAsRaw: '',
|
|
1133
|
-
hint: '',
|
|
1134
|
-
ignoreUndefined: '',
|
|
1135
|
-
let: '',
|
|
1136
|
-
maxAwaitTimeMS: '',
|
|
1137
|
-
maxTimeMS: '',
|
|
1138
|
-
omitMaxTimeMS: '',
|
|
1139
|
-
out: '',
|
|
1140
|
-
promoteBuffers: '',
|
|
1141
|
-
promoteLongs: '',
|
|
1142
|
-
promoteValues: '',
|
|
1143
|
-
raw: '',
|
|
1144
|
-
rawData: '',
|
|
1145
|
-
readConcern: '',
|
|
1146
|
-
readPreference: '',
|
|
1147
|
-
serializeFunctions: '',
|
|
1148
|
-
session: '',
|
|
1149
|
-
timeoutContext: '',
|
|
1150
|
-
timeoutMS: '',
|
|
1151
|
-
timeoutMode: '',
|
|
1152
|
-
useBigInt64: '',
|
|
1153
|
-
willRetryWrite: '',
|
|
1154
|
-
writeConcern: ''
|
|
1155
|
-
};
|
|
1156
|
-
|
|
1157
|
-
return new Set(Object.keys(denyList));
|
|
1158
|
-
}
|
|
1110
|
+
configureResourceManagement(ChangeStream.prototype);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type MongoCrypt,
|
|
3
|
+
type MongoCryptConstructor,
|
|
4
|
+
type MongoCryptOptions
|
|
5
|
+
} from 'mongodb-client-encryption';
|
|
2
6
|
import * as net from 'net';
|
|
3
7
|
|
|
4
8
|
import { deserialize, type Document, serialize } from '../bson';
|
|
@@ -10,7 +14,8 @@ import { MongoClient, type MongoClientOptions } from '../mongo_client';
|
|
|
10
14
|
import { type Abortable } from '../mongo_types';
|
|
11
15
|
import { MongoDBCollectionNamespace } from '../utils';
|
|
12
16
|
import { autoSelectSocketOptions } from './client_encryption';
|
|
13
|
-
import
|
|
17
|
+
import * as cryptoCallbacks from './crypto_callbacks';
|
|
18
|
+
import { MongoCryptInvalidArgumentError } from './errors';
|
|
14
19
|
import { MongocryptdManager } from './mongocryptd_manager';
|
|
15
20
|
import {
|
|
16
21
|
type CredentialProviders,
|
|
@@ -64,7 +69,7 @@ export interface AutoEncryptionOptions {
|
|
|
64
69
|
/** If true, autoEncryption will not attempt to spawn a mongocryptd before connecting */
|
|
65
70
|
mongocryptdBypassSpawn?: boolean;
|
|
66
71
|
/** The path to the mongocryptd executable on the system */
|
|
67
|
-
mongocryptdSpawnPath?:
|
|
72
|
+
mongocryptdSpawnPath?: string;
|
|
68
73
|
/** Command line arguments to use when auto-spawning a mongocryptd */
|
|
69
74
|
mongocryptdSpawnArgs?: string[];
|
|
70
75
|
/**
|
|
@@ -90,7 +95,7 @@ export interface AutoEncryptionOptions {
|
|
|
90
95
|
*
|
|
91
96
|
* Requires the MongoDB Crypt shared library, available in MongoDB 6.0 or higher.
|
|
92
97
|
*/
|
|
93
|
-
cryptSharedLibPath?:
|
|
98
|
+
cryptSharedLibPath?: string;
|
|
94
99
|
/**
|
|
95
100
|
* If specified, never use mongocryptd and instead fail when the MongoDB Crypt
|
|
96
101
|
* shared library could not be loaded.
|
|
@@ -178,7 +183,7 @@ export class AutoEncrypter {
|
|
|
178
183
|
[kDecorateResult] = false;
|
|
179
184
|
|
|
180
185
|
/** @internal */
|
|
181
|
-
static getMongoCrypt():
|
|
186
|
+
static getMongoCrypt(): MongoCryptConstructor {
|
|
182
187
|
const encryption = getMongoDBClientEncryption();
|
|
183
188
|
if ('kModuleError' in encryption) {
|
|
184
189
|
throw encryption.kModuleError;
|
|
@@ -253,7 +258,8 @@ export class AutoEncrypter {
|
|
|
253
258
|
}
|
|
254
259
|
|
|
255
260
|
const mongoCryptOptions: MongoCryptOptions = {
|
|
256
|
-
|
|
261
|
+
enableMultipleCollinfo: true,
|
|
262
|
+
cryptoCallbacks
|
|
257
263
|
};
|
|
258
264
|
if (options.schemaMap) {
|
|
259
265
|
mongoCryptOptions.schemaMap = Buffer.isBuffer(options.schemaMap)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ExplicitEncryptionContextOptions,
|
|
3
3
|
MongoCrypt,
|
|
4
|
+
MongoCryptConstructor,
|
|
4
5
|
MongoCryptOptions
|
|
5
6
|
} from 'mongodb-client-encryption';
|
|
6
7
|
|
|
@@ -25,8 +26,8 @@ import { type CreateCollectionOptions } from '../operations/create_collection';
|
|
|
25
26
|
import { type DeleteResult } from '../operations/delete';
|
|
26
27
|
import { type CSOTTimeoutContext, TimeoutContext } from '../timeout';
|
|
27
28
|
import { MongoDBCollectionNamespace, resolveTimeoutOptions } from '../utils';
|
|
29
|
+
import * as cryptoCallbacks from './crypto_callbacks';
|
|
28
30
|
import {
|
|
29
|
-
defaultErrorWrapper,
|
|
30
31
|
MongoCryptCreateDataKeyError,
|
|
31
32
|
MongoCryptCreateEncryptedCollectionError,
|
|
32
33
|
MongoCryptInvalidArgumentError
|
|
@@ -86,7 +87,7 @@ export class ClientEncryption {
|
|
|
86
87
|
_credentialProviders?: CredentialProviders;
|
|
87
88
|
|
|
88
89
|
/** @internal */
|
|
89
|
-
static getMongoCrypt():
|
|
90
|
+
static getMongoCrypt(): MongoCryptConstructor {
|
|
90
91
|
const encryption = getMongoDBClientEncryption();
|
|
91
92
|
if ('kModuleError' in encryption) {
|
|
92
93
|
throw encryption.kModuleError;
|
|
@@ -143,10 +144,10 @@ export class ClientEncryption {
|
|
|
143
144
|
|
|
144
145
|
const mongoCryptOptions: MongoCryptOptions = {
|
|
145
146
|
...options,
|
|
147
|
+
cryptoCallbacks,
|
|
146
148
|
kmsProviders: !Buffer.isBuffer(this._kmsProviders)
|
|
147
149
|
? (serialize(this._kmsProviders) as Buffer)
|
|
148
|
-
: this._kmsProviders
|
|
149
|
-
errorWrapper: defaultErrorWrapper
|
|
150
|
+
: this._kmsProviders
|
|
150
151
|
};
|
|
151
152
|
|
|
152
153
|
this._keyVaultNamespace = options.keyVaultNamespace;
|
|
@@ -285,7 +286,7 @@ export class ClientEncryption {
|
|
|
285
286
|
*/
|
|
286
287
|
async rewrapManyDataKey(
|
|
287
288
|
filter: Filter<DataKey>,
|
|
288
|
-
options
|
|
289
|
+
options: ClientEncryptionRewrapManyDataKeyProviderOptions
|
|
289
290
|
): Promise<{ bulkWriteResult?: BulkWriteResult }> {
|
|
290
291
|
let keyEncryptionKeyBson = undefined;
|
|
291
292
|
if (options) {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
type AES256Callback = (key: Buffer, iv: Buffer, input: Buffer, output: Buffer) => number | Error;
|
|
4
|
+
|
|
5
|
+
export function makeAES256Hook(
|
|
6
|
+
method: 'createCipheriv' | 'createDecipheriv',
|
|
7
|
+
mode: 'aes-256-cbc' | 'aes-256-ctr'
|
|
8
|
+
): AES256Callback {
|
|
9
|
+
return function (key: Buffer, iv: Buffer, input: Buffer, output: Buffer): number | Error {
|
|
10
|
+
let result;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const cipher = crypto[method](mode, key, iv);
|
|
14
|
+
cipher.setAutoPadding(false);
|
|
15
|
+
result = cipher.update(input);
|
|
16
|
+
const final = cipher.final();
|
|
17
|
+
if (final.length > 0) {
|
|
18
|
+
result = Buffer.concat([result, final]);
|
|
19
|
+
}
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return e;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
result.copy(output);
|
|
25
|
+
return result.length;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function randomHook(buffer: Buffer, count: number): number | Error {
|
|
30
|
+
try {
|
|
31
|
+
crypto.randomFillSync(buffer, 0, count);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return e;
|
|
34
|
+
}
|
|
35
|
+
return count;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function sha256Hook(input: Buffer, output: Buffer): number | Error {
|
|
39
|
+
let result;
|
|
40
|
+
try {
|
|
41
|
+
result = crypto.createHash('sha256').update(input).digest();
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return e;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
result.copy(output);
|
|
47
|
+
return result.length;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type HMACHook = (key: Buffer, input: Buffer, output: Buffer) => number | Error;
|
|
51
|
+
export function makeHmacHook(algorithm: 'sha512' | 'sha256'): HMACHook {
|
|
52
|
+
return (key: Buffer, input: Buffer, output: Buffer): number | Error => {
|
|
53
|
+
let result;
|
|
54
|
+
try {
|
|
55
|
+
result = crypto.createHmac(algorithm, key).update(input).digest();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return e;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
result.copy(output);
|
|
61
|
+
return result.length;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function signRsaSha256Hook(key: Buffer, input: Buffer, output: Buffer): number | Error {
|
|
66
|
+
let result;
|
|
67
|
+
try {
|
|
68
|
+
const signer = crypto.createSign('sha256WithRSAEncryption');
|
|
69
|
+
const privateKey = Buffer.from(
|
|
70
|
+
`-----BEGIN PRIVATE KEY-----\n${key.toString('base64')}\n-----END PRIVATE KEY-----\n`
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
result = signer.update(input).end().sign(privateKey);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return e;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
result.copy(output);
|
|
79
|
+
return result.length;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const aes256CbcEncryptHook = makeAES256Hook('createCipheriv', 'aes-256-cbc');
|
|
83
|
+
export const aes256CbcDecryptHook = makeAES256Hook('createDecipheriv', 'aes-256-cbc');
|
|
84
|
+
export const aes256CtrEncryptHook = makeAES256Hook('createCipheriv', 'aes-256-ctr');
|
|
85
|
+
export const aes256CtrDecryptHook = makeAES256Hook('createDecipheriv', 'aes-256-ctr');
|
|
86
|
+
export const hmacSha512Hook = makeHmacHook('sha512');
|
|
87
|
+
export const hmacSha256Hook = makeHmacHook('sha256');
|