mongodb 6.20.0 → 7.0.0-dev.20251111.sha.b183de39
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 +17 -18
- package/lib/bulk/common.js +7 -9
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +84 -38
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -4
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +2 -3
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/errors.js +3 -1
- 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 +10 -58
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +0 -15
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +2 -7
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/providers.js +0 -1
- 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 +28 -27
- 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 +7 -5
- 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 +3 -1
- package/lib/cmap/wire_protocol/constants.js.map +1 -1
- package/lib/cmap/wire_protocol/on_data.js +0 -1
- 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 +8 -10
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +17 -34
- 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 +37 -26
- 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 +2 -8
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +58 -67
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_client_auth_providers.js +0 -6
- package/lib/mongo_client_auth_providers.js.map +1 -1
- package/lib/mongo_logger.js.map +1 -1
- package/lib/mongo_types.js +1 -2
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/aggregate.js +0 -3
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/create_collection.js +0 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/drop.js +8 -9
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/end_sessions.js +34 -0
- package/lib/operations/end_sessions.js.map +1 -0
- package/lib/operations/execute_operation.js +3 -1
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/read_preference.js +10 -14
- package/lib/read_preference.js.map +1 -1
- 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 +24 -68
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +5 -4
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +2 -13
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +0 -14
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +72 -239
- package/package.json +17 -20
- package/src/bulk/common.ts +9 -11
- package/src/change_stream.ts +85 -37
- package/src/client-side-encryption/auto_encrypter.ts +6 -12
- package/src/client-side-encryption/client_encryption.ts +5 -6
- package/src/client-side-encryption/errors.ts +3 -0
- package/src/cmap/auth/aws_temporary_credentials.ts +12 -70
- package/src/cmap/auth/mongo_credentials.ts +1 -20
- package/src/cmap/auth/mongodb_aws.ts +8 -17
- package/src/cmap/auth/providers.ts +0 -1
- package/src/cmap/connect.ts +1 -1
- package/src/cmap/connection.ts +14 -16
- package/src/cmap/connection_pool.ts +4 -13
- package/src/cmap/errors.ts +1 -1
- package/src/cmap/handshake/client_metadata.ts +18 -26
- package/src/cmap/wire_protocol/constants.ts +2 -0
- package/src/cmap/wire_protocol/on_data.ts +1 -2
- package/src/collection.ts +1 -1
- package/src/connection_string.ts +13 -20
- package/src/cursor/abstract_cursor.ts +12 -49
- package/src/cursor/change_stream_cursor.ts +2 -2
- package/src/cursor/find_cursor.ts +40 -27
- package/src/cursor/run_command_cursor.ts +1 -1
- package/src/error.ts +2 -2
- package/src/gridfs/download.ts +0 -4
- package/src/gridfs/upload.ts +0 -22
- package/src/index.ts +2 -8
- package/src/mongo_client.ts +68 -100
- package/src/mongo_client_auth_providers.ts +0 -8
- package/src/mongo_logger.ts +1 -1
- package/src/mongo_types.ts +1 -2
- package/src/operations/aggregate.ts +0 -6
- package/src/operations/command.ts +0 -12
- package/src/operations/create_collection.ts +0 -3
- package/src/operations/drop.ts +9 -11
- package/src/operations/end_sessions.ts +44 -0
- package/src/operations/execute_operation.ts +6 -2
- package/src/operations/find.ts +2 -11
- package/src/read_preference.ts +0 -9
- package/src/sdam/topology.ts +2 -60
- package/src/sessions.ts +2 -8
- package/src/transactions.ts +2 -17
- package/src/utils.ts +0 -18
- package/tsconfig.json +5 -7
- package/lib/beta.d.ts +0 -9224
- package/lib/beta.js +0 -21
- package/lib/beta.js.map +0 -1
- package/lib/client-side-encryption/crypto_callbacks.js +0 -81
- package/lib/client-side-encryption/crypto_callbacks.js.map +0 -1
- package/lib/resource_management.js +0 -58
- package/lib/resource_management.js.map +0 -1
- package/src/beta.ts +0 -22
- package/src/client-side-encryption/crypto_callbacks.ts +0 -87
- package/src/resource_management.ts +0 -74
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-dev.20251111.sha.b183de39",
|
|
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": "^7.0.0",
|
|
30
|
+
"mongodb-connection-string-url": "^7.0.0"
|
|
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.806.0",
|
|
34
|
+
"@mongodb-js/zstd": "^7.0.0",
|
|
35
|
+
"gcp-metadata": "^7.0.1",
|
|
36
|
+
"kerberos": "^7.0.0",
|
|
37
|
+
"mongodb-client-encryption": ">=7.0.0 <7.1.0",
|
|
38
38
|
"snappy": "^7.3.2",
|
|
39
|
-
"socks": "^2.
|
|
39
|
+
"socks": "^2.8.6"
|
|
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": "^7.0.0",
|
|
71
71
|
"@types/chai": "^4.3.17",
|
|
72
72
|
"@types/chai-subset": "^1.3.5",
|
|
73
73
|
"@types/express": "^5.0.3",
|
|
@@ -92,12 +92,11 @@
|
|
|
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": "^7.0.1",
|
|
96
96
|
"js-yaml": "^4.1.0",
|
|
97
97
|
"mocha": "^11.7.1",
|
|
98
98
|
"mocha-sinon": "^2.1.2",
|
|
99
|
-
"mongodb-client-encryption": "^
|
|
100
|
-
"mongodb-legacy": "^6.1.3",
|
|
99
|
+
"mongodb-client-encryption": "^7.0.0",
|
|
101
100
|
"nyc": "^15.1.0",
|
|
102
101
|
"prettier": "^3.6.2",
|
|
103
102
|
"semver": "^7.7.2",
|
|
@@ -115,7 +114,7 @@
|
|
|
115
114
|
},
|
|
116
115
|
"license": "Apache-2.0",
|
|
117
116
|
"engines": {
|
|
118
|
-
"node": ">=
|
|
117
|
+
"node": ">=20.19.0"
|
|
119
118
|
},
|
|
120
119
|
"bugs": {
|
|
121
120
|
"url": "https://jira.mongodb.org/projects/NODE/issues/"
|
|
@@ -124,7 +123,7 @@
|
|
|
124
123
|
"scripts": {
|
|
125
124
|
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
|
|
126
125
|
"build:ts": "node ./node_modules/typescript/bin/tsc",
|
|
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
|
|
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",
|
|
128
127
|
"build:docs": "./etc/docs/build.ts",
|
|
129
128
|
"build:typedoc": "typedoc",
|
|
130
129
|
"build:nightly": "node ./.github/scripts/nightly.mjs",
|
|
@@ -137,16 +136,14 @@
|
|
|
137
136
|
"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",
|
|
138
137
|
"check:tsd": "tsd --version && tsd",
|
|
139
138
|
"check:dependencies": "mocha test/action/dependency.test.ts",
|
|
140
|
-
"check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
|
|
139
|
+
"check:dts": "node ./node_modules/typescript/bin/tsc --target es2023 --module commonjs --noEmit mongodb.d.ts && tsd",
|
|
141
140
|
"check:search-indexes": "nyc mocha --config test/mocha_mongodb.js test/manual/search-index-management.prose.test.ts",
|
|
142
141
|
"check:test": "mocha --config test/mocha_mongodb.js test/integration",
|
|
143
142
|
"check:unit": "nyc mocha test/unit",
|
|
144
143
|
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
|
|
145
144
|
"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",
|
|
147
145
|
"check:drivers-atlas-testing": "nyc mocha --config test/mocha_mongodb.js test/atlas/drivers_atlas_testing.test.ts",
|
|
148
|
-
"check:
|
|
149
|
-
"check:aws": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_aws.test.ts",
|
|
146
|
+
"check:aws": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_aws.test.ts test/integration/auth/mongodb_aws.prose.test.ts",
|
|
150
147
|
"check:oidc-auth": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/auth.spec.test.ts",
|
|
151
148
|
"check:oidc-test": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_oidc.prose.test.ts",
|
|
152
149
|
"check:oidc-azure": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_oidc_azure.prose.05.test.ts",
|
|
@@ -175,4 +172,4 @@
|
|
|
175
172
|
"moduleResolution": "node"
|
|
176
173
|
}
|
|
177
174
|
}
|
|
178
|
-
}
|
|
175
|
+
}
|
package/src/bulk/common.ts
CHANGED
|
@@ -20,7 +20,6 @@ import type { Topology } from '../sdam/topology';
|
|
|
20
20
|
import { type Sort } from '../sort';
|
|
21
21
|
import { TimeoutContext } from '../timeout';
|
|
22
22
|
import {
|
|
23
|
-
applyRetryableWrites,
|
|
24
23
|
getTopology,
|
|
25
24
|
hasAtomicOperators,
|
|
26
25
|
maybeAddIdToDocuments,
|
|
@@ -527,15 +526,15 @@ async function executeCommands(
|
|
|
527
526
|
finalOptions.checkKeys = false;
|
|
528
527
|
}
|
|
529
528
|
|
|
530
|
-
if (
|
|
529
|
+
if (bulkOperation.retryWrites) {
|
|
531
530
|
if (isUpdateBatch(batch)) {
|
|
532
|
-
|
|
533
|
-
|
|
531
|
+
bulkOperation.retryWrites =
|
|
532
|
+
bulkOperation.retryWrites && !batch.operations.some(op => op.multi);
|
|
534
533
|
}
|
|
535
534
|
|
|
536
535
|
if (isDeleteBatch(batch)) {
|
|
537
|
-
|
|
538
|
-
|
|
536
|
+
bulkOperation.retryWrites =
|
|
537
|
+
bulkOperation.retryWrites && !batch.operations.some(op => op.limit === 0);
|
|
539
538
|
}
|
|
540
539
|
}
|
|
541
540
|
|
|
@@ -859,6 +858,8 @@ export abstract class BulkOperationBase {
|
|
|
859
858
|
s: BulkOperationPrivate;
|
|
860
859
|
operationId?: number;
|
|
861
860
|
private collection: Collection;
|
|
861
|
+
/** @internal */
|
|
862
|
+
retryWrites?: boolean;
|
|
862
863
|
|
|
863
864
|
/**
|
|
864
865
|
* Create a new OrderedBulkOperation or UnorderedBulkOperation instance
|
|
@@ -866,6 +867,7 @@ export abstract class BulkOperationBase {
|
|
|
866
867
|
*/
|
|
867
868
|
constructor(collection: Collection, options: BulkWriteOptions, isOrdered: boolean) {
|
|
868
869
|
this.collection = collection;
|
|
870
|
+
this.retryWrites = collection.db.options?.retryWrites;
|
|
869
871
|
// determine whether bulkOperation is ordered or unordered
|
|
870
872
|
this.isOrdered = isOrdered;
|
|
871
873
|
|
|
@@ -898,10 +900,6 @@ export abstract class BulkOperationBase {
|
|
|
898
900
|
// + 1 bytes for null terminator
|
|
899
901
|
const maxKeySize = (maxWriteBatchSize - 1).toString(10).length + 2;
|
|
900
902
|
|
|
901
|
-
// Final options for retryable writes
|
|
902
|
-
let finalOptions = Object.assign({}, options);
|
|
903
|
-
finalOptions = applyRetryableWrites(finalOptions, collection.db);
|
|
904
|
-
|
|
905
903
|
// Final results
|
|
906
904
|
const bulkResult: BulkResult = {
|
|
907
905
|
ok: 1,
|
|
@@ -943,7 +941,7 @@ export abstract class BulkOperationBase {
|
|
|
943
941
|
// Topology
|
|
944
942
|
topology,
|
|
945
943
|
// Options
|
|
946
|
-
options:
|
|
944
|
+
options: options,
|
|
947
945
|
// BSON options
|
|
948
946
|
bsonOptions: resolveBSONOptions(options),
|
|
949
947
|
// 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 {
|
|
6
|
+
import { 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,21 +17,10 @@ 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 {
|
|
21
|
-
import type { ReadPreference } from './read_preference';
|
|
22
|
-
import { type AsyncDisposable, configureResourceManagement } from './resource_management';
|
|
20
|
+
import type { OperationParent } from './operations/command';
|
|
23
21
|
import type { ServerSessionId } from './sessions';
|
|
24
22
|
import { CSOTTimeoutContext, type TimeoutContext } from './timeout';
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
const CHANGE_STREAM_OPTIONS = [
|
|
28
|
-
'resumeAfter',
|
|
29
|
-
'startAfter',
|
|
30
|
-
'startAtOperationTime',
|
|
31
|
-
'fullDocument',
|
|
32
|
-
'fullDocumentBeforeChange',
|
|
33
|
-
'showExpandedEvents'
|
|
34
|
-
] as const;
|
|
23
|
+
import { type AnyOptions, getTopology, type MongoDBNamespace, squashError } from './utils';
|
|
35
24
|
|
|
36
25
|
const CHANGE_DOMAIN_TYPES = {
|
|
37
26
|
COLLECTION: Symbol('Collection'),
|
|
@@ -45,19 +34,12 @@ const NO_RESUME_TOKEN_ERROR =
|
|
|
45
34
|
'A change stream document has been received that lacks a resume token (_id).';
|
|
46
35
|
const CHANGESTREAM_CLOSED_ERROR = 'ChangeStream is closed';
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
batchSize?: number;
|
|
55
|
-
maxAwaitTimeMS?: number;
|
|
56
|
-
collation?: CollationOptions;
|
|
57
|
-
readPreference?: ReadPreference;
|
|
58
|
-
resumeAfter?: ResumeToken;
|
|
59
|
-
startAfter?: ResumeToken;
|
|
60
|
-
fullDocument?: string;
|
|
37
|
+
const INVALID_STAGE_OPTIONS = buildDisallowedChangeStreamOptions();
|
|
38
|
+
|
|
39
|
+
export function filterOutOptions(options: AnyOptions): AnyOptions {
|
|
40
|
+
return Object.fromEntries(
|
|
41
|
+
Object.entries(options).filter(([k, _]) => !INVALID_STAGE_OPTIONS.has(k))
|
|
42
|
+
);
|
|
61
43
|
}
|
|
62
44
|
|
|
63
45
|
/**
|
|
@@ -590,13 +572,10 @@ export class ChangeStream<
|
|
|
590
572
|
implements AsyncDisposable
|
|
591
573
|
{
|
|
592
574
|
/**
|
|
593
|
-
* @beta
|
|
594
575
|
* @experimental
|
|
595
576
|
* An alias for {@link ChangeStream.close|ChangeStream.close()}.
|
|
596
577
|
*/
|
|
597
|
-
|
|
598
|
-
/** @internal */
|
|
599
|
-
async asyncDispose() {
|
|
578
|
+
async [Symbol.asyncDispose]() {
|
|
600
579
|
await this.close();
|
|
601
580
|
}
|
|
602
581
|
|
|
@@ -614,7 +593,6 @@ export class ChangeStream<
|
|
|
614
593
|
type: symbol;
|
|
615
594
|
/** @internal */
|
|
616
595
|
private cursor: ChangeStreamCursor<TSchema, TChange>;
|
|
617
|
-
streamOptions?: CursorStreamOptions;
|
|
618
596
|
/** @internal */
|
|
619
597
|
private cursorStream?: Readable & AsyncIterable<TChange>;
|
|
620
598
|
/** @internal */
|
|
@@ -882,13 +860,12 @@ export class ChangeStream<
|
|
|
882
860
|
*
|
|
883
861
|
* @throws MongoChangeStreamError if the underlying cursor or the change stream is closed
|
|
884
862
|
*/
|
|
885
|
-
stream(
|
|
863
|
+
stream(): Readable & AsyncIterable<TChange> {
|
|
886
864
|
if (this.closed) {
|
|
887
865
|
throw new MongoChangeStreamError(CHANGESTREAM_CLOSED_ERROR);
|
|
888
866
|
}
|
|
889
867
|
|
|
890
|
-
this.
|
|
891
|
-
return this.cursor.stream(options);
|
|
868
|
+
return this.cursor.stream();
|
|
892
869
|
}
|
|
893
870
|
|
|
894
871
|
/** @internal */
|
|
@@ -920,7 +897,7 @@ export class ChangeStream<
|
|
|
920
897
|
private _createChangeStreamCursor(
|
|
921
898
|
options: ChangeStreamOptions | ChangeStreamCursorOptions
|
|
922
899
|
): ChangeStreamCursor<TSchema, TChange> {
|
|
923
|
-
const changeStreamStageOptions =
|
|
900
|
+
const changeStreamStageOptions: Document = filterOutOptions(options);
|
|
924
901
|
if (this.type === CHANGE_DOMAIN_TYPES.CLUSTER) {
|
|
925
902
|
changeStreamStageOptions.allChangesForCluster = true;
|
|
926
903
|
}
|
|
@@ -1107,4 +1084,75 @@ export class ChangeStream<
|
|
|
1107
1084
|
}
|
|
1108
1085
|
}
|
|
1109
1086
|
|
|
1110
|
-
|
|
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
|
+
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type MongoCrypt,
|
|
3
|
-
type MongoCryptConstructor,
|
|
4
|
-
type MongoCryptOptions
|
|
5
|
-
} from 'mongodb-client-encryption';
|
|
1
|
+
import { type MongoCrypt, type MongoCryptOptions } from 'mongodb-client-encryption';
|
|
6
2
|
import * as net from 'net';
|
|
7
3
|
|
|
8
4
|
import { deserialize, type Document, serialize } from '../bson';
|
|
@@ -14,8 +10,7 @@ import { MongoClient, type MongoClientOptions } from '../mongo_client';
|
|
|
14
10
|
import { type Abortable } from '../mongo_types';
|
|
15
11
|
import { MongoDBCollectionNamespace } from '../utils';
|
|
16
12
|
import { autoSelectSocketOptions } from './client_encryption';
|
|
17
|
-
import
|
|
18
|
-
import { MongoCryptInvalidArgumentError } from './errors';
|
|
13
|
+
import { defaultErrorWrapper, MongoCryptInvalidArgumentError } from './errors';
|
|
19
14
|
import { MongocryptdManager } from './mongocryptd_manager';
|
|
20
15
|
import {
|
|
21
16
|
type CredentialProviders,
|
|
@@ -69,7 +64,7 @@ export interface AutoEncryptionOptions {
|
|
|
69
64
|
/** If true, autoEncryption will not attempt to spawn a mongocryptd before connecting */
|
|
70
65
|
mongocryptdBypassSpawn?: boolean;
|
|
71
66
|
/** The path to the mongocryptd executable on the system */
|
|
72
|
-
mongocryptdSpawnPath?: string
|
|
67
|
+
mongocryptdSpawnPath?: `${string}mongocryptd${'.exe' | ''}`;
|
|
73
68
|
/** Command line arguments to use when auto-spawning a mongocryptd */
|
|
74
69
|
mongocryptdSpawnArgs?: string[];
|
|
75
70
|
/**
|
|
@@ -95,7 +90,7 @@ export interface AutoEncryptionOptions {
|
|
|
95
90
|
*
|
|
96
91
|
* Requires the MongoDB Crypt shared library, available in MongoDB 6.0 or higher.
|
|
97
92
|
*/
|
|
98
|
-
cryptSharedLibPath?: string
|
|
93
|
+
cryptSharedLibPath?: `${string}mongo_crypt_v${number}.${'so' | 'dll' | 'dylib'}`;
|
|
99
94
|
/**
|
|
100
95
|
* If specified, never use mongocryptd and instead fail when the MongoDB Crypt
|
|
101
96
|
* shared library could not be loaded.
|
|
@@ -183,7 +178,7 @@ export class AutoEncrypter {
|
|
|
183
178
|
[kDecorateResult] = false;
|
|
184
179
|
|
|
185
180
|
/** @internal */
|
|
186
|
-
static getMongoCrypt():
|
|
181
|
+
static getMongoCrypt(): typeof MongoCrypt {
|
|
187
182
|
const encryption = getMongoDBClientEncryption();
|
|
188
183
|
if ('kModuleError' in encryption) {
|
|
189
184
|
throw encryption.kModuleError;
|
|
@@ -258,8 +253,7 @@ export class AutoEncrypter {
|
|
|
258
253
|
}
|
|
259
254
|
|
|
260
255
|
const mongoCryptOptions: MongoCryptOptions = {
|
|
261
|
-
|
|
262
|
-
cryptoCallbacks
|
|
256
|
+
errorWrapper: defaultErrorWrapper
|
|
263
257
|
};
|
|
264
258
|
if (options.schemaMap) {
|
|
265
259
|
mongoCryptOptions.schemaMap = Buffer.isBuffer(options.schemaMap)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ExplicitEncryptionContextOptions,
|
|
3
3
|
MongoCrypt,
|
|
4
|
-
MongoCryptConstructor,
|
|
5
4
|
MongoCryptOptions
|
|
6
5
|
} from 'mongodb-client-encryption';
|
|
7
6
|
|
|
@@ -26,8 +25,8 @@ import { type CreateCollectionOptions } from '../operations/create_collection';
|
|
|
26
25
|
import { type DeleteResult } from '../operations/delete';
|
|
27
26
|
import { type CSOTTimeoutContext, TimeoutContext } from '../timeout';
|
|
28
27
|
import { MongoDBCollectionNamespace, resolveTimeoutOptions } from '../utils';
|
|
29
|
-
import * as cryptoCallbacks from './crypto_callbacks';
|
|
30
28
|
import {
|
|
29
|
+
defaultErrorWrapper,
|
|
31
30
|
MongoCryptCreateDataKeyError,
|
|
32
31
|
MongoCryptCreateEncryptedCollectionError,
|
|
33
32
|
MongoCryptInvalidArgumentError
|
|
@@ -87,7 +86,7 @@ export class ClientEncryption {
|
|
|
87
86
|
_credentialProviders?: CredentialProviders;
|
|
88
87
|
|
|
89
88
|
/** @internal */
|
|
90
|
-
static getMongoCrypt():
|
|
89
|
+
static getMongoCrypt(): typeof MongoCrypt {
|
|
91
90
|
const encryption = getMongoDBClientEncryption();
|
|
92
91
|
if ('kModuleError' in encryption) {
|
|
93
92
|
throw encryption.kModuleError;
|
|
@@ -144,10 +143,10 @@ export class ClientEncryption {
|
|
|
144
143
|
|
|
145
144
|
const mongoCryptOptions: MongoCryptOptions = {
|
|
146
145
|
...options,
|
|
147
|
-
cryptoCallbacks,
|
|
148
146
|
kmsProviders: !Buffer.isBuffer(this._kmsProviders)
|
|
149
147
|
? (serialize(this._kmsProviders) as Buffer)
|
|
150
|
-
: this._kmsProviders
|
|
148
|
+
: this._kmsProviders,
|
|
149
|
+
errorWrapper: defaultErrorWrapper
|
|
151
150
|
};
|
|
152
151
|
|
|
153
152
|
this._keyVaultNamespace = options.keyVaultNamespace;
|
|
@@ -286,7 +285,7 @@ export class ClientEncryption {
|
|
|
286
285
|
*/
|
|
287
286
|
async rewrapManyDataKey(
|
|
288
287
|
filter: Filter<DataKey>,
|
|
289
|
-
options
|
|
288
|
+
options?: ClientEncryptionRewrapManyDataKeyProviderOptions
|
|
290
289
|
): Promise<{ bulkWriteResult?: BulkWriteResult }> {
|
|
291
290
|
let keyEncryptionKeyBson = undefined;
|
|
292
291
|
if (options) {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { type AWSCredentials, getAwsCredentialProvider } from '../../deps';
|
|
2
2
|
import { MongoAWSError } from '../../error';
|
|
3
|
-
import { request } from '../../utils';
|
|
4
|
-
|
|
5
|
-
const AWS_RELATIVE_URI = 'http://169.254.170.2';
|
|
6
|
-
const AWS_EC2_URI = 'http://169.254.169.254';
|
|
7
|
-
const AWS_EC2_PATH = '/latest/meta-data/iam/security-credentials';
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* @internal
|
|
@@ -24,26 +19,9 @@ export interface AWSTempCredentials {
|
|
|
24
19
|
/** @public **/
|
|
25
20
|
export type AWSCredentialProvider = () => Promise<AWSCredentials>;
|
|
26
21
|
|
|
27
|
-
/**
|
|
28
|
-
* @internal
|
|
29
|
-
*
|
|
30
|
-
* Fetches temporary AWS credentials.
|
|
31
|
-
*/
|
|
32
|
-
export abstract class AWSTemporaryCredentialProvider {
|
|
33
|
-
abstract getCredentials(): Promise<AWSTempCredentials>;
|
|
34
|
-
private static _awsSDK: ReturnType<typeof getAwsCredentialProvider>;
|
|
35
|
-
protected static get awsSDK() {
|
|
36
|
-
AWSTemporaryCredentialProvider._awsSDK ??= getAwsCredentialProvider();
|
|
37
|
-
return AWSTemporaryCredentialProvider._awsSDK;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static get isAWSSDKInstalled(): boolean {
|
|
41
|
-
return !('kModuleError' in AWSTemporaryCredentialProvider.awsSDK);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
22
|
/** @internal */
|
|
46
|
-
export class AWSSDKCredentialProvider
|
|
23
|
+
export class AWSSDKCredentialProvider {
|
|
24
|
+
private static _awsSDK: ReturnType<typeof getAwsCredentialProvider>;
|
|
47
25
|
private _provider?: AWSCredentialProvider;
|
|
48
26
|
|
|
49
27
|
/**
|
|
@@ -51,20 +29,23 @@ export class AWSSDKCredentialProvider extends AWSTemporaryCredentialProvider {
|
|
|
51
29
|
* @param credentialsProvider - The credentials provider.
|
|
52
30
|
*/
|
|
53
31
|
constructor(credentialsProvider?: AWSCredentialProvider) {
|
|
54
|
-
super();
|
|
55
|
-
|
|
56
32
|
if (credentialsProvider) {
|
|
57
33
|
this._provider = credentialsProvider;
|
|
58
34
|
}
|
|
59
35
|
}
|
|
60
36
|
|
|
37
|
+
static get awsSDK() {
|
|
38
|
+
AWSSDKCredentialProvider._awsSDK ??= getAwsCredentialProvider();
|
|
39
|
+
return AWSSDKCredentialProvider._awsSDK;
|
|
40
|
+
}
|
|
41
|
+
|
|
61
42
|
/**
|
|
62
43
|
* The AWS SDK caches credentials automatically and handles refresh when the credentials have expired.
|
|
63
44
|
* To ensure this occurs, we need to cache the `provider` returned by the AWS sdk and re-use it when fetching credentials.
|
|
64
45
|
*/
|
|
65
46
|
private get provider(): () => Promise<AWSCredentials> {
|
|
66
|
-
if ('kModuleError' in
|
|
67
|
-
throw
|
|
47
|
+
if ('kModuleError' in AWSSDKCredentialProvider.awsSDK) {
|
|
48
|
+
throw AWSSDKCredentialProvider.awsSDK.kModuleError;
|
|
68
49
|
}
|
|
69
50
|
if (this._provider) {
|
|
70
51
|
return this._provider;
|
|
@@ -112,15 +93,15 @@ export class AWSSDKCredentialProvider extends AWSTemporaryCredentialProvider {
|
|
|
112
93
|
|
|
113
94
|
this._provider =
|
|
114
95
|
awsRegionSettingsExist && useRegionalSts
|
|
115
|
-
?
|
|
96
|
+
? AWSSDKCredentialProvider.awsSDK.fromNodeProviderChain({
|
|
116
97
|
clientConfig: { region: AWS_REGION }
|
|
117
98
|
})
|
|
118
|
-
:
|
|
99
|
+
: AWSSDKCredentialProvider.awsSDK.fromNodeProviderChain();
|
|
119
100
|
|
|
120
101
|
return this._provider;
|
|
121
102
|
}
|
|
122
103
|
|
|
123
|
-
|
|
104
|
+
async getCredentials(): Promise<AWSTempCredentials> {
|
|
124
105
|
/*
|
|
125
106
|
* Creates a credential provider that will attempt to find credentials from the
|
|
126
107
|
* following sources (listed in order of precedence):
|
|
@@ -144,42 +125,3 @@ export class AWSSDKCredentialProvider extends AWSTemporaryCredentialProvider {
|
|
|
144
125
|
}
|
|
145
126
|
}
|
|
146
127
|
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @internal
|
|
150
|
-
* Fetches credentials manually (without the AWS SDK), as outlined in the [Obtaining Credentials](https://github.com/mongodb/specifications/blob/master/source/auth/auth.md#obtaining-credentials)
|
|
151
|
-
* section of the Auth spec.
|
|
152
|
-
*/
|
|
153
|
-
export class LegacyAWSTemporaryCredentialProvider extends AWSTemporaryCredentialProvider {
|
|
154
|
-
override async getCredentials(): Promise<AWSTempCredentials> {
|
|
155
|
-
// If the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
|
|
156
|
-
// is set then drivers MUST assume that it was set by an AWS ECS agent
|
|
157
|
-
if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
|
|
158
|
-
return await request(
|
|
159
|
-
`${AWS_RELATIVE_URI}${process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Otherwise assume we are on an EC2 instance
|
|
164
|
-
|
|
165
|
-
// get a token
|
|
166
|
-
const token = await request(`${AWS_EC2_URI}/latest/api/token`, {
|
|
167
|
-
method: 'PUT',
|
|
168
|
-
json: false,
|
|
169
|
-
headers: { 'X-aws-ec2-metadata-token-ttl-seconds': 30 }
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
// get role name
|
|
173
|
-
const roleName = await request(`${AWS_EC2_URI}/${AWS_EC2_PATH}`, {
|
|
174
|
-
json: false,
|
|
175
|
-
headers: { 'X-aws-ec2-metadata-token': token }
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// get temp credentials
|
|
179
|
-
const creds = await request(`${AWS_EC2_URI}/${AWS_EC2_PATH}/${roleName}`, {
|
|
180
|
-
headers: { 'X-aws-ec2-metadata-token': token }
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
return creds;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
@@ -58,6 +58,7 @@ export interface AuthMechanismProperties extends Document {
|
|
|
58
58
|
SERVICE_NAME?: string;
|
|
59
59
|
SERVICE_REALM?: string;
|
|
60
60
|
CANONICALIZE_HOST_NAME?: GSSAPICanonicalizationValue;
|
|
61
|
+
/** @internal */
|
|
61
62
|
AWS_SESSION_TOKEN?: string;
|
|
62
63
|
/** A user provided OIDC machine callback function. */
|
|
63
64
|
OIDC_CALLBACK?: OIDCCallbackFunction;
|
|
@@ -134,26 +135,6 @@ export class MongoCredentials {
|
|
|
134
135
|
this.mechanism = options.mechanism || AuthMechanism.MONGODB_DEFAULT;
|
|
135
136
|
this.mechanismProperties = options.mechanismProperties || {};
|
|
136
137
|
|
|
137
|
-
if (this.mechanism.match(/MONGODB-AWS/i)) {
|
|
138
|
-
if (!this.username && process.env.AWS_ACCESS_KEY_ID) {
|
|
139
|
-
this.username = process.env.AWS_ACCESS_KEY_ID;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!this.password && process.env.AWS_SECRET_ACCESS_KEY) {
|
|
143
|
-
this.password = process.env.AWS_SECRET_ACCESS_KEY;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
this.mechanismProperties.AWS_SESSION_TOKEN == null &&
|
|
148
|
-
process.env.AWS_SESSION_TOKEN != null
|
|
149
|
-
) {
|
|
150
|
-
this.mechanismProperties = {
|
|
151
|
-
...this.mechanismProperties,
|
|
152
|
-
AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
138
|
if (this.mechanism === AuthMechanism.MONGODB_OIDC && !this.mechanismProperties.ALLOWED_HOSTS) {
|
|
158
139
|
this.mechanismProperties = {
|
|
159
140
|
...this.mechanismProperties,
|