mongodb 5.0.1 → 5.2.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 +25 -22
- package/lib/bson.js +3 -1
- package/lib/bson.js.map +1 -1
- package/lib/change_stream.js +3 -2
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js +21 -10
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +71 -116
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +17 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +20 -29
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +126 -140
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +28 -0
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +178 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +41 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +115 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js +3 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +62 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
- package/lib/cmap/auth/plain.js +4 -5
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +4 -1
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/auth/scram.js +45 -73
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +8 -11
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +8 -5
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +9 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +72 -86
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +68 -74
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +51 -13
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -16
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +10 -10
- package/lib/connection_string.js +47 -33
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +13 -7
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/db.js +3 -2
- package/lib/db.js.map +1 -1
- package/lib/error.js +2 -1
- package/lib/error.js.map +1 -1
- package/lib/mongo_client.js +22 -2
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +17 -1
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +4 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/create_collection.js +1 -0
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/execute_operation.js +8 -27
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +3 -2
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/indexes.js +2 -1
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/list_collections.js +2 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/read_concern.js +1 -1
- package/lib/read_preference.js +2 -2
- package/lib/sdam/monitor.js +1 -0
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +4 -2
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/topology.js +3 -26
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +2 -1
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +15 -70
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +1 -1
- package/mongodb.d.ts +137 -68
- package/package.json +30 -30
- package/src/bson.ts +3 -1
- package/src/bulk/common.ts +1 -1
- package/src/change_stream.ts +16 -8
- package/src/cmap/auth/auth_provider.ts +29 -16
- package/src/cmap/auth/gssapi.ts +102 -149
- package/src/cmap/auth/mongo_credentials.ts +47 -1
- package/src/cmap/auth/mongocr.ts +31 -36
- package/src/cmap/auth/mongodb_aws.ts +167 -189
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +26 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +259 -0
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +47 -0
- package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +166 -0
- package/src/cmap/auth/mongodb_oidc/workflow.ts +21 -0
- package/src/cmap/auth/mongodb_oidc.ts +123 -0
- package/src/cmap/auth/plain.ts +6 -6
- package/src/cmap/auth/providers.ts +5 -2
- package/src/cmap/auth/scram.ts +56 -90
- package/src/cmap/auth/x509.ts +12 -18
- package/src/cmap/command_monitoring_events.ts +5 -2
- package/src/cmap/commands.ts +11 -1
- package/src/cmap/connect.ts +90 -114
- package/src/cmap/connection.ts +92 -90
- package/src/cmap/connection_pool.ts +77 -16
- package/src/cmap/message_stream.ts +0 -2
- package/src/cmap/wire_protocol/compression.ts +1 -1
- package/src/cmap/wire_protocol/shared.ts +1 -23
- package/src/collection.ts +11 -11
- package/src/connection_string.ts +52 -35
- package/src/cursor/abstract_cursor.ts +13 -6
- package/src/cursor/change_stream_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +1 -1
- package/src/db.ts +3 -2
- package/src/deps.ts +56 -38
- package/src/error.ts +3 -2
- package/src/index.ts +7 -0
- package/src/mongo_client.ts +35 -10
- package/src/mongo_logger.ts +20 -2
- package/src/mongo_types.ts +4 -3
- package/src/operations/aggregate.ts +4 -2
- package/src/operations/create_collection.ts +2 -1
- package/src/operations/execute_operation.ts +8 -25
- package/src/operations/find.ts +13 -4
- package/src/operations/find_and_modify.ts +4 -4
- package/src/operations/indexes.ts +12 -4
- package/src/operations/list_collections.ts +11 -3
- package/src/operations/set_profiling_level.ts +1 -1
- package/src/operations/stats.ts +1 -1
- package/src/read_concern.ts +2 -2
- package/src/read_preference.ts +3 -3
- package/src/sdam/common.ts +2 -2
- package/src/sdam/monitor.ts +1 -0
- package/src/sdam/server.ts +4 -1
- package/src/sdam/topology.ts +4 -33
- package/src/sessions.ts +2 -1
- package/src/transactions.ts +1 -1
- package/src/utils.ts +24 -98
- package/src/write_concern.ts +1 -1
package/src/deps.ts
CHANGED
|
@@ -188,7 +188,7 @@ export const AutoEncryptionLoggerLevel = Object.freeze({
|
|
|
188
188
|
|
|
189
189
|
/** @public */
|
|
190
190
|
export type AutoEncryptionLoggerLevel =
|
|
191
|
-
typeof AutoEncryptionLoggerLevel[keyof typeof AutoEncryptionLoggerLevel];
|
|
191
|
+
(typeof AutoEncryptionLoggerLevel)[keyof typeof AutoEncryptionLoggerLevel];
|
|
192
192
|
|
|
193
193
|
/** @public */
|
|
194
194
|
export interface AutoEncryptionTlsOptions {
|
|
@@ -223,17 +223,19 @@ export interface AutoEncryptionOptions {
|
|
|
223
223
|
/** Configuration options that are used by specific KMS providers during key generation, encryption, and decryption. */
|
|
224
224
|
kmsProviders?: {
|
|
225
225
|
/** Configuration options for using 'aws' as your KMS provider */
|
|
226
|
-
aws?:
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
226
|
+
aws?:
|
|
227
|
+
| {
|
|
228
|
+
/** The access key used for the AWS KMS provider */
|
|
229
|
+
accessKeyId: string;
|
|
230
|
+
/** The secret access key used for the AWS KMS provider */
|
|
231
|
+
secretAccessKey: string;
|
|
232
|
+
/**
|
|
233
|
+
* An optional AWS session token that will be used as the
|
|
234
|
+
* X-Amz-Security-Token header for AWS requests.
|
|
235
|
+
*/
|
|
236
|
+
sessionToken?: string;
|
|
237
|
+
}
|
|
238
|
+
| Record<string, never>;
|
|
237
239
|
/** Configuration options for using 'local' as your KMS provider */
|
|
238
240
|
local?: {
|
|
239
241
|
/**
|
|
@@ -243,33 +245,49 @@ export interface AutoEncryptionOptions {
|
|
|
243
245
|
key: Buffer | string;
|
|
244
246
|
};
|
|
245
247
|
/** Configuration options for using 'azure' as your KMS provider */
|
|
246
|
-
azure?:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
248
|
+
azure?:
|
|
249
|
+
| {
|
|
250
|
+
/** The tenant ID identifies the organization for the account */
|
|
251
|
+
tenantId: string;
|
|
252
|
+
/** The client ID to authenticate a registered application */
|
|
253
|
+
clientId: string;
|
|
254
|
+
/** The client secret to authenticate a registered application */
|
|
255
|
+
clientSecret: string;
|
|
256
|
+
/**
|
|
257
|
+
* If present, a host with optional port. E.g. "example.com" or "example.com:443".
|
|
258
|
+
* This is optional, and only needed if customer is using a non-commercial Azure instance
|
|
259
|
+
* (e.g. a government or China account, which use different URLs).
|
|
260
|
+
* Defaults to "login.microsoftonline.com"
|
|
261
|
+
*/
|
|
262
|
+
identityPlatformEndpoint?: string | undefined;
|
|
263
|
+
}
|
|
264
|
+
| {
|
|
265
|
+
/**
|
|
266
|
+
* If present, an access token to authenticate with Azure.
|
|
267
|
+
*/
|
|
268
|
+
accessToken: string;
|
|
269
|
+
}
|
|
270
|
+
| Record<string, never>;
|
|
261
271
|
/** Configuration options for using 'gcp' as your KMS provider */
|
|
262
|
-
gcp?:
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
gcp?:
|
|
273
|
+
| {
|
|
274
|
+
/** The service account email to authenticate */
|
|
275
|
+
email: string;
|
|
276
|
+
/** A PKCS#8 encrypted key. This can either be a base64 string or a binary representation */
|
|
277
|
+
privateKey: string | Buffer;
|
|
278
|
+
/**
|
|
279
|
+
* If present, a host with optional port. E.g. "example.com" or "example.com:443".
|
|
280
|
+
* Defaults to "oauth2.googleapis.com"
|
|
281
|
+
*/
|
|
282
|
+
endpoint?: string | undefined;
|
|
283
|
+
}
|
|
284
|
+
| {
|
|
285
|
+
/**
|
|
286
|
+
* If present, an access token to authenticate with GCP.
|
|
287
|
+
*/
|
|
288
|
+
accessToken: string;
|
|
289
|
+
}
|
|
290
|
+
| Record<string, never>;
|
|
273
291
|
/**
|
|
274
292
|
* Configuration options for using 'kmip' as your KMS provider
|
|
275
293
|
*/
|
package/src/error.ts
CHANGED
|
@@ -58,7 +58,8 @@ export const MONGODB_ERROR_CODES = Object.freeze({
|
|
|
58
58
|
IllegalOperation: 20,
|
|
59
59
|
MaxTimeMSExpired: 50,
|
|
60
60
|
UnknownReplWriteConcern: 79,
|
|
61
|
-
UnsatisfiableWriteConcern: 100
|
|
61
|
+
UnsatisfiableWriteConcern: 100,
|
|
62
|
+
Reauthenticate: 391
|
|
62
63
|
} as const);
|
|
63
64
|
|
|
64
65
|
// From spec@https://github.com/mongodb/specifications/blob/f93d78191f3db2898a59013a7ed5650352ef6da8/source/change-streams/change-streams.rst#resumable-error
|
|
@@ -96,7 +97,7 @@ export const MongoErrorLabel = Object.freeze({
|
|
|
96
97
|
} as const);
|
|
97
98
|
|
|
98
99
|
/** @public */
|
|
99
|
-
export type MongoErrorLabel = typeof MongoErrorLabel[keyof typeof MongoErrorLabel];
|
|
100
|
+
export type MongoErrorLabel = (typeof MongoErrorLabel)[keyof typeof MongoErrorLabel];
|
|
100
101
|
|
|
101
102
|
/** @public */
|
|
102
103
|
export interface ErrorDescription extends Document {
|
package/src/index.ts
CHANGED
|
@@ -197,11 +197,18 @@ export type {
|
|
|
197
197
|
ResumeToken,
|
|
198
198
|
UpdateDescription
|
|
199
199
|
} from './change_stream';
|
|
200
|
+
export type { AuthContext } from './cmap/auth/auth_provider';
|
|
200
201
|
export type {
|
|
201
202
|
AuthMechanismProperties,
|
|
202
203
|
MongoCredentials,
|
|
203
204
|
MongoCredentialsOptions
|
|
204
205
|
} from './cmap/auth/mongo_credentials';
|
|
206
|
+
export type {
|
|
207
|
+
OIDCMechanismServerStep1,
|
|
208
|
+
OIDCRefreshFunction,
|
|
209
|
+
OIDCRequestFunction,
|
|
210
|
+
OIDCRequestTokenResult
|
|
211
|
+
} from './cmap/auth/mongodb_oidc';
|
|
205
212
|
export type {
|
|
206
213
|
BinMsg,
|
|
207
214
|
MessageHeader,
|
package/src/mongo_client.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const ServerApiVersion = Object.freeze({
|
|
|
33
33
|
} as const);
|
|
34
34
|
|
|
35
35
|
/** @public */
|
|
36
|
-
export type ServerApiVersion = typeof ServerApiVersion[keyof typeof ServerApiVersion];
|
|
36
|
+
export type ServerApiVersion = (typeof ServerApiVersion)[keyof typeof ServerApiVersion];
|
|
37
37
|
|
|
38
38
|
/** @public */
|
|
39
39
|
export interface ServerApi {
|
|
@@ -65,19 +65,19 @@ export interface PkFactory {
|
|
|
65
65
|
/** @public */
|
|
66
66
|
export type SupportedTLSConnectionOptions = Pick<
|
|
67
67
|
TLSConnectionOptions,
|
|
68
|
-
Extract<keyof TLSConnectionOptions, typeof LEGAL_TLS_SOCKET_OPTIONS[number]>
|
|
68
|
+
Extract<keyof TLSConnectionOptions, (typeof LEGAL_TLS_SOCKET_OPTIONS)[number]>
|
|
69
69
|
>;
|
|
70
70
|
|
|
71
71
|
/** @public */
|
|
72
72
|
export type SupportedTLSSocketOptions = Pick<
|
|
73
73
|
TLSSocketOptions,
|
|
74
|
-
Extract<keyof TLSSocketOptions, typeof LEGAL_TLS_SOCKET_OPTIONS[number]>
|
|
74
|
+
Extract<keyof TLSSocketOptions, (typeof LEGAL_TLS_SOCKET_OPTIONS)[number]>
|
|
75
75
|
>;
|
|
76
76
|
|
|
77
77
|
/** @public */
|
|
78
78
|
export type SupportedSocketOptions = Pick<
|
|
79
79
|
TcpNetConnectOpts,
|
|
80
|
-
typeof LEGAL_TCP_SOCKET_OPTIONS[number]
|
|
80
|
+
(typeof LEGAL_TCP_SOCKET_OPTIONS)[number]
|
|
81
81
|
>;
|
|
82
82
|
|
|
83
83
|
/** @public */
|
|
@@ -88,7 +88,7 @@ export type SupportedNodeConnectionOptions = SupportedTLSConnectionOptions &
|
|
|
88
88
|
/**
|
|
89
89
|
* Describes all possible URI query options for the mongo client
|
|
90
90
|
* @public
|
|
91
|
-
* @see https://
|
|
91
|
+
* @see https://www.mongodb.com/docs/manual/reference/connection-string
|
|
92
92
|
*/
|
|
93
93
|
export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeConnectionOptions {
|
|
94
94
|
/** Specifies the name of the replica set, if the mongod is a member of a replica set. */
|
|
@@ -194,7 +194,7 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
|
|
|
194
194
|
* A MongoDB WriteConcern, which describes the level of acknowledgement
|
|
195
195
|
* requested from MongoDB for write operations.
|
|
196
196
|
*
|
|
197
|
-
* @see https://
|
|
197
|
+
* @see https://www.mongodb.com/docs/manual/reference/write-concern/
|
|
198
198
|
*/
|
|
199
199
|
writeConcern?: WriteConcern | WriteConcernSettings;
|
|
200
200
|
/** Validate mongod server certificate against Certificate Authority */
|
|
@@ -230,7 +230,7 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
|
|
|
230
230
|
* Automatic encryption is an enterprise only feature that only applies to operations on a collection. Automatic encryption is not supported for operations on a database or view, and operations that are not bypassed will result in error
|
|
231
231
|
* (see [libmongocrypt: Auto Encryption Allow-List](https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.rst#libmongocrypt-auto-encryption-allow-list)). To bypass automatic encryption for all operations, set bypassAutoEncryption=true in AutoEncryptionOpts.
|
|
232
232
|
*
|
|
233
|
-
* Automatic encryption requires the authenticated user to have the [listCollections privilege action](https://
|
|
233
|
+
* Automatic encryption requires the authenticated user to have the [listCollections privilege action](https://www.mongodb.com/docs/manual/reference/command/listCollections/#dbcmd.listCollections).
|
|
234
234
|
*
|
|
235
235
|
* If a MongoClient with a limited connection pool size (i.e a non-zero maxPoolSize) is configured with AutoEncryptionOptions, a separate internal MongoClient is created if any of the following are true:
|
|
236
236
|
* - AutoEncryptionOptions.keyVaultClient is not passed.
|
|
@@ -283,7 +283,7 @@ export interface MongoClientPrivate {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
/** @public */
|
|
286
|
-
export type MongoClientEvents = Pick<TopologyEvents, typeof MONGO_CLIENT_EVENTS[number]> & {
|
|
286
|
+
export type MongoClientEvents = Pick<TopologyEvents, (typeof MONGO_CLIENT_EVENTS)[number]> & {
|
|
287
287
|
// In previous versions the open event emitted a topology, in an effort to no longer
|
|
288
288
|
// expose internals but continue to expose this useful event API, it now emits a mongoClient
|
|
289
289
|
open(mongoClient: MongoClient): void;
|
|
@@ -318,6 +318,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
318
318
|
topology?: Topology;
|
|
319
319
|
/** @internal */
|
|
320
320
|
readonly mongoLogger: MongoLogger;
|
|
321
|
+
/** @internal */
|
|
322
|
+
private connectionLock?: Promise<this>;
|
|
321
323
|
|
|
322
324
|
/**
|
|
323
325
|
* The consolidate, parsed, transformed and merged options.
|
|
@@ -405,6 +407,28 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
405
407
|
* @see docs.mongodb.org/manual/reference/connection-string/
|
|
406
408
|
*/
|
|
407
409
|
async connect(): Promise<this> {
|
|
410
|
+
if (this.connectionLock) {
|
|
411
|
+
return this.connectionLock;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
try {
|
|
415
|
+
this.connectionLock = this._connect();
|
|
416
|
+
await this.connectionLock;
|
|
417
|
+
} finally {
|
|
418
|
+
// release
|
|
419
|
+
this.connectionLock = undefined;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return this;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Create a topology to open the connection, must be locked to avoid topology leaks in concurrency scenario.
|
|
427
|
+
* Locking is enforced by the connect method.
|
|
428
|
+
*
|
|
429
|
+
* @internal
|
|
430
|
+
*/
|
|
431
|
+
private async _connect(): Promise<this> {
|
|
408
432
|
if (this.topology && this.topology.isConnected()) {
|
|
409
433
|
return this;
|
|
410
434
|
}
|
|
@@ -542,7 +566,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
542
566
|
* @remarks
|
|
543
567
|
* The programmatically provided options take precedence over the URI options.
|
|
544
568
|
*
|
|
545
|
-
* @see https://
|
|
569
|
+
* @see https://www.mongodb.com/docs/manual/reference/connection-string/
|
|
546
570
|
*/
|
|
547
571
|
static async connect(url: string, options?: MongoClientOptions): Promise<MongoClient> {
|
|
548
572
|
const client = new this(url, options);
|
|
@@ -616,7 +640,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
616
640
|
* - The first is to provide the schema that may be defined for all the data within the current cluster
|
|
617
641
|
* - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
|
|
618
642
|
*
|
|
619
|
-
* @param pipeline - An array of {@link https://
|
|
643
|
+
* @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
|
|
620
644
|
* @param options - Optional settings for the command
|
|
621
645
|
* @typeParam TSchema - Type of the data being detected by the change stream
|
|
622
646
|
* @typeParam TChange - Type of the whole change stream document emitted
|
|
@@ -676,6 +700,7 @@ export interface MongoOptions
|
|
|
676
700
|
>
|
|
677
701
|
>,
|
|
678
702
|
SupportedNodeConnectionOptions {
|
|
703
|
+
appName?: string;
|
|
679
704
|
hosts: HostAddress[];
|
|
680
705
|
srvHost?: string;
|
|
681
706
|
credentials?: MongoCredentials;
|
package/src/mongo_logger.ts
CHANGED
|
@@ -17,7 +17,25 @@ export const SeverityLevel = Object.freeze({
|
|
|
17
17
|
} as const);
|
|
18
18
|
|
|
19
19
|
/** @internal */
|
|
20
|
-
export type SeverityLevel = typeof SeverityLevel[keyof typeof SeverityLevel];
|
|
20
|
+
export type SeverityLevel = (typeof SeverityLevel)[keyof typeof SeverityLevel];
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
export const SeverityLevelMap: Map<string | number, string | number> = new Map([
|
|
24
|
+
[SeverityLevel.OFF, -Infinity],
|
|
25
|
+
[SeverityLevel.EMERGENCY, 0],
|
|
26
|
+
[SeverityLevel.ALERT, 1],
|
|
27
|
+
[SeverityLevel.CRITICAL, 2],
|
|
28
|
+
[SeverityLevel.ERROR, 3],
|
|
29
|
+
[SeverityLevel.WARNING, 4],
|
|
30
|
+
[SeverityLevel.NOTICE, 5],
|
|
31
|
+
[SeverityLevel.INFORMATIONAL, 6],
|
|
32
|
+
[SeverityLevel.DEBUG, 7],
|
|
33
|
+
[SeverityLevel.TRACE, 8]
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
for (const [level, value] of SeverityLevelMap) {
|
|
37
|
+
SeverityLevelMap.set(value, level);
|
|
38
|
+
}
|
|
21
39
|
|
|
22
40
|
/** @internal */
|
|
23
41
|
export const MongoLoggableComponent = Object.freeze({
|
|
@@ -29,7 +47,7 @@ export const MongoLoggableComponent = Object.freeze({
|
|
|
29
47
|
|
|
30
48
|
/** @internal */
|
|
31
49
|
export type MongoLoggableComponent =
|
|
32
|
-
typeof MongoLoggableComponent[keyof typeof MongoLoggableComponent];
|
|
50
|
+
(typeof MongoLoggableComponent)[keyof typeof MongoLoggableComponent];
|
|
33
51
|
|
|
34
52
|
/** @internal */
|
|
35
53
|
export interface MongoLoggerEnvOptions {
|
package/src/mongo_types.ts
CHANGED
|
@@ -176,7 +176,7 @@ export type ArrayElement<Type> = Type extends ReadonlyArray<infer Item> ? Item :
|
|
|
176
176
|
export type SchemaMember<T, V> = { [P in keyof T]?: V } | { [key: string]: V };
|
|
177
177
|
|
|
178
178
|
/** @public */
|
|
179
|
-
export type IntegerType = number | Int32 | Long;
|
|
179
|
+
export type IntegerType = number | Int32 | Long | bigint;
|
|
180
180
|
|
|
181
181
|
/** @public */
|
|
182
182
|
export type NumericType = IntegerType | Decimal128 | Double;
|
|
@@ -440,7 +440,7 @@ export type PropertyType<Type, Property extends string> = string extends Propert
|
|
|
440
440
|
/**
|
|
441
441
|
* @public
|
|
442
442
|
* returns tuple of strings (keys to be joined on '.') that represent every path into a schema
|
|
443
|
-
* https://
|
|
443
|
+
* https://www.mongodb.com/docs/manual/tutorial/query-embedded-documents/
|
|
444
444
|
*
|
|
445
445
|
* @remarks
|
|
446
446
|
* Through testing we determined that a depth of 8 is safe for the typescript compiler
|
|
@@ -454,6 +454,7 @@ export type NestedPaths<Type, Depth extends number[]> = Depth['length'] extends
|
|
|
454
454
|
: Type extends
|
|
455
455
|
| string
|
|
456
456
|
| number
|
|
457
|
+
| bigint
|
|
457
458
|
| boolean
|
|
458
459
|
| Date
|
|
459
460
|
| RegExp
|
|
@@ -490,7 +491,7 @@ export type NestedPaths<Type, Depth extends number[]> = Depth['length'] extends
|
|
|
490
491
|
/**
|
|
491
492
|
* @public
|
|
492
493
|
* returns keys (strings) for every path into a schema with a value of type
|
|
493
|
-
* https://
|
|
494
|
+
* https://www.mongodb.com/docs/manual/tutorial/query-embedded-documents/
|
|
494
495
|
*/
|
|
495
496
|
export type NestedPathsOfType<TSchema, Type> = KeysOfAType<
|
|
496
497
|
{
|
|
@@ -14,7 +14,7 @@ const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8 as const;
|
|
|
14
14
|
export interface AggregateOptions extends CommandOperationOptions {
|
|
15
15
|
/** allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 \>). */
|
|
16
16
|
allowDiskUse?: boolean;
|
|
17
|
-
/** The number of documents to return per batch. See [aggregation documentation](https://
|
|
17
|
+
/** The number of documents to return per batch. See [aggregation documentation](https://www.mongodb.com/docs/manual/reference/command/aggregate). */
|
|
18
18
|
batchSize?: number;
|
|
19
19
|
/** Allow driver to bypass schema validation in MongoDB 3.2 or higher. */
|
|
20
20
|
bypassDocumentValidation?: boolean;
|
|
@@ -44,7 +44,7 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
44
44
|
constructor(ns: MongoDBNamespace, pipeline: Document[], options?: AggregateOptions) {
|
|
45
45
|
super(undefined, { ...options, dbName: ns.db });
|
|
46
46
|
|
|
47
|
-
this.options = options
|
|
47
|
+
this.options = { ...options };
|
|
48
48
|
|
|
49
49
|
// Covers when ns.collection is null, undefined or the empty string, use DB_AGGREGATE_COLLECTION
|
|
50
50
|
this.target = ns.collection || DB_AGGREGATE_COLLECTION;
|
|
@@ -65,6 +65,8 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
65
65
|
|
|
66
66
|
if (this.hasWriteStage) {
|
|
67
67
|
this.trySecondaryWrite = true;
|
|
68
|
+
} else {
|
|
69
|
+
delete this.options.writeConcern;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
if (this.explain && this.writeConcern) {
|
|
@@ -23,6 +23,7 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
|
23
23
|
'writeConcern',
|
|
24
24
|
'raw',
|
|
25
25
|
'fieldsAsRaw',
|
|
26
|
+
'useBigInt64',
|
|
26
27
|
'promoteLongs',
|
|
27
28
|
'promoteValues',
|
|
28
29
|
'promoteBuffers',
|
|
@@ -34,7 +35,7 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
|
|
|
34
35
|
|
|
35
36
|
/** @public
|
|
36
37
|
* Configuration options for timeseries collections
|
|
37
|
-
* @see https://
|
|
38
|
+
* @see https://www.mongodb.com/docs/manual/core/timeseries-collections/
|
|
38
39
|
*/
|
|
39
40
|
export interface TimeSeriesCollectionOptions extends Document {
|
|
40
41
|
timeField: string;
|
|
@@ -106,35 +106,18 @@ async function executeOperationAsync<
|
|
|
106
106
|
throw new MongoRuntimeError('client.connect did not create a topology but also did not throw');
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
if (topology.shouldCheckForSessionSupport()) {
|
|
110
|
-
await topology.selectServerAsync(ReadPreference.primaryPreferred, {});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
109
|
// The driver sessions spec mandates that we implicitly create sessions for operations
|
|
114
110
|
// that are not explicitly provided with a session.
|
|
115
111
|
let session = operation.session;
|
|
116
112
|
let owner: symbol | undefined;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
// no session support
|
|
128
|
-
if (session && session.explicit) {
|
|
129
|
-
// If the user passed an explicit session and we are still, after server selection,
|
|
130
|
-
// trying to run against a topology that doesn't support sessions we error out.
|
|
131
|
-
throw new MongoCompatibilityError('Current topology does not support sessions');
|
|
132
|
-
} else if (session && !session.explicit) {
|
|
133
|
-
// We do not have to worry about ending the session because the server session has not been acquired yet
|
|
134
|
-
delete operation.options.session;
|
|
135
|
-
operation.clearSession();
|
|
136
|
-
session = undefined;
|
|
137
|
-
}
|
|
113
|
+
|
|
114
|
+
if (session == null) {
|
|
115
|
+
owner = Symbol();
|
|
116
|
+
session = client.startSession({ owner, explicit: false });
|
|
117
|
+
} else if (session.hasEnded) {
|
|
118
|
+
throw new MongoExpiredSessionError('Use of expired sessions is not permitted');
|
|
119
|
+
} else if (session.snapshotEnabled && !topology.capabilities.supportsSnapshotReads) {
|
|
120
|
+
throw new MongoCompatibilityError('Snapshot reads require MongoDB 5.0 or later');
|
|
138
121
|
}
|
|
139
122
|
|
|
140
123
|
const readPreference = operation.readPreference ?? ReadPreference.primary;
|
package/src/operations/find.ts
CHANGED
|
@@ -14,7 +14,8 @@ import { Aspect, defineAspects, Hint } from './operation';
|
|
|
14
14
|
* @typeParam TSchema - Unused schema definition, deprecated usage, only specify `FindOptions` with no generic
|
|
15
15
|
*/
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
-
export interface FindOptions<TSchema extends Document = Document>
|
|
17
|
+
export interface FindOptions<TSchema extends Document = Document>
|
|
18
|
+
extends Omit<CommandOperationOptions, 'writeConcern'> {
|
|
18
19
|
/** Sets the limit of documents returned in the query. */
|
|
19
20
|
limit?: number;
|
|
20
21
|
/** Set to sort the documents coming back from the query. Array of indexes, `[['a', 1]]` etc. */
|
|
@@ -66,7 +67,14 @@ export interface FindOptions<TSchema extends Document = Document> extends Comman
|
|
|
66
67
|
|
|
67
68
|
/** @internal */
|
|
68
69
|
export class FindOperation extends CommandOperation<Document> {
|
|
69
|
-
|
|
70
|
+
/**
|
|
71
|
+
* @remarks WriteConcern can still be present on the options because
|
|
72
|
+
* we inherit options from the client/db/collection. The
|
|
73
|
+
* key must be present on the options in order to delete it.
|
|
74
|
+
* This allows typescript to delete the key but will
|
|
75
|
+
* not allow a writeConcern to be assigned as a property on options.
|
|
76
|
+
*/
|
|
77
|
+
override options: FindOptions & { writeConcern?: never };
|
|
70
78
|
filter: Document;
|
|
71
79
|
|
|
72
80
|
constructor(
|
|
@@ -77,7 +85,8 @@ export class FindOperation extends CommandOperation<Document> {
|
|
|
77
85
|
) {
|
|
78
86
|
super(collection, options);
|
|
79
87
|
|
|
80
|
-
this.options = options;
|
|
88
|
+
this.options = { ...options };
|
|
89
|
+
delete this.options.writeConcern;
|
|
81
90
|
this.ns = ns;
|
|
82
91
|
|
|
83
92
|
if (typeof filter !== 'object' || Array.isArray(filter)) {
|
|
@@ -95,7 +104,7 @@ export class FindOperation extends CommandOperation<Document> {
|
|
|
95
104
|
}
|
|
96
105
|
|
|
97
106
|
// special case passing in an ObjectId as a filter
|
|
98
|
-
this.filter = filter != null && filter._bsontype === '
|
|
107
|
+
this.filter = filter != null && filter._bsontype === 'ObjectId' ? { _id: filter } : filter;
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
override execute(
|
|
@@ -17,11 +17,11 @@ export const ReturnDocument = Object.freeze({
|
|
|
17
17
|
} as const);
|
|
18
18
|
|
|
19
19
|
/** @public */
|
|
20
|
-
export type ReturnDocument = typeof ReturnDocument[keyof typeof ReturnDocument];
|
|
20
|
+
export type ReturnDocument = (typeof ReturnDocument)[keyof typeof ReturnDocument];
|
|
21
21
|
|
|
22
22
|
/** @public */
|
|
23
23
|
export interface FindOneAndDeleteOptions extends CommandOperationOptions {
|
|
24
|
-
/** An optional hint for query optimization. See the {@link https://
|
|
24
|
+
/** An optional hint for query optimization. See the {@link https://www.mongodb.com/docs/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
|
|
25
25
|
hint?: Document;
|
|
26
26
|
/** Limits the fields to return for all matching documents. */
|
|
27
27
|
projection?: Document;
|
|
@@ -35,7 +35,7 @@ export interface FindOneAndDeleteOptions extends CommandOperationOptions {
|
|
|
35
35
|
export interface FindOneAndReplaceOptions extends CommandOperationOptions {
|
|
36
36
|
/** Allow driver to bypass schema validation in MongoDB 3.2 or higher. */
|
|
37
37
|
bypassDocumentValidation?: boolean;
|
|
38
|
-
/** An optional hint for query optimization. See the {@link https://
|
|
38
|
+
/** An optional hint for query optimization. See the {@link https://www.mongodb.com/docs/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
|
|
39
39
|
hint?: Document;
|
|
40
40
|
/** Limits the fields to return for all matching documents. */
|
|
41
41
|
projection?: Document;
|
|
@@ -55,7 +55,7 @@ export interface FindOneAndUpdateOptions extends CommandOperationOptions {
|
|
|
55
55
|
arrayFilters?: Document[];
|
|
56
56
|
/** Allow driver to bypass schema validation in MongoDB 3.2 or higher. */
|
|
57
57
|
bypassDocumentValidation?: boolean;
|
|
58
|
-
/** An optional hint for query optimization. See the {@link https://
|
|
58
|
+
/** An optional hint for query optimization. See the {@link https://www.mongodb.com/docs/manual/reference/command/update/#update-command-hint|update command} reference for more information.*/
|
|
59
59
|
hint?: Document;
|
|
60
60
|
/** Limits the fields to return for all matching documents. */
|
|
61
61
|
projection?: Document;
|
|
@@ -102,7 +102,7 @@ export interface IndexDescription
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/** @public */
|
|
105
|
-
export interface CreateIndexesOptions extends CommandOperationOptions {
|
|
105
|
+
export interface CreateIndexesOptions extends Omit<CommandOperationOptions, 'writeConcern'> {
|
|
106
106
|
/** Creates the index in the background, yielding whenever possible. */
|
|
107
107
|
background?: boolean;
|
|
108
108
|
/** Creates an unique index. */
|
|
@@ -382,20 +382,28 @@ export class DropIndexesOperation extends DropIndexOperation {
|
|
|
382
382
|
}
|
|
383
383
|
|
|
384
384
|
/** @public */
|
|
385
|
-
export interface ListIndexesOptions extends CommandOperationOptions {
|
|
385
|
+
export interface ListIndexesOptions extends Omit<CommandOperationOptions, 'writeConcern'> {
|
|
386
386
|
/** The batchSize for the returned command cursor or if pre 2.8 the systems batch collection */
|
|
387
387
|
batchSize?: number;
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
/** @internal */
|
|
391
391
|
export class ListIndexesOperation extends CommandOperation<Document> {
|
|
392
|
-
|
|
392
|
+
/**
|
|
393
|
+
* @remarks WriteConcern can still be present on the options because
|
|
394
|
+
* we inherit options from the client/db/collection. The
|
|
395
|
+
* key must be present on the options in order to delete it.
|
|
396
|
+
* This allows typescript to delete the key but will
|
|
397
|
+
* not allow a writeConcern to be assigned as a property on options.
|
|
398
|
+
*/
|
|
399
|
+
override options: ListIndexesOptions & { writeConcern?: never };
|
|
393
400
|
collectionNamespace: MongoDBNamespace;
|
|
394
401
|
|
|
395
402
|
constructor(collection: Collection, options?: ListIndexesOptions) {
|
|
396
403
|
super(collection, options);
|
|
397
404
|
|
|
398
|
-
this.options = options
|
|
405
|
+
this.options = { ...options };
|
|
406
|
+
delete this.options.writeConcern;
|
|
399
407
|
this.collectionNamespace = collection.s.namespace;
|
|
400
408
|
}
|
|
401
409
|
|
|
@@ -7,7 +7,7 @@ import { CommandOperation, CommandOperationOptions } from './command';
|
|
|
7
7
|
import { Aspect, defineAspects } from './operation';
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
|
-
export interface ListCollectionsOptions extends CommandOperationOptions {
|
|
10
|
+
export interface ListCollectionsOptions extends Omit<CommandOperationOptions, 'writeConcern'> {
|
|
11
11
|
/** Since 4.0: If true, will only return the collection name in the response, and will omit additional info */
|
|
12
12
|
nameOnly?: boolean;
|
|
13
13
|
/** Since 4.0: If true and nameOnly is true, allows a user without the required privilege (i.e. listCollections action on the database) to run the command when access control is enforced. */
|
|
@@ -18,7 +18,14 @@ export interface ListCollectionsOptions extends CommandOperationOptions {
|
|
|
18
18
|
|
|
19
19
|
/** @internal */
|
|
20
20
|
export class ListCollectionsOperation extends CommandOperation<string[]> {
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @remarks WriteConcern can still be present on the options because
|
|
23
|
+
* we inherit options from the client/db/collection. The
|
|
24
|
+
* key must be present on the options in order to delete it.
|
|
25
|
+
* This allows typescript to delete the key but will
|
|
26
|
+
* not allow a writeConcern to be assigned as a property on options.
|
|
27
|
+
*/
|
|
28
|
+
override options: ListCollectionsOptions & { writeConcern?: never };
|
|
22
29
|
db: Db;
|
|
23
30
|
filter: Document;
|
|
24
31
|
nameOnly: boolean;
|
|
@@ -28,7 +35,8 @@ export class ListCollectionsOperation extends CommandOperation<string[]> {
|
|
|
28
35
|
constructor(db: Db, filter: Document, options?: ListCollectionsOptions) {
|
|
29
36
|
super(db, options);
|
|
30
37
|
|
|
31
|
-
this.options = options
|
|
38
|
+
this.options = { ...options };
|
|
39
|
+
delete this.options.writeConcern;
|
|
32
40
|
this.db = db;
|
|
33
41
|
this.filter = filter;
|
|
34
42
|
this.nameOnly = !!this.options.nameOnly;
|
|
@@ -16,7 +16,7 @@ export const ProfilingLevel = Object.freeze({
|
|
|
16
16
|
} as const);
|
|
17
17
|
|
|
18
18
|
/** @public */
|
|
19
|
-
export type ProfilingLevel = typeof ProfilingLevel[keyof typeof ProfilingLevel];
|
|
19
|
+
export type ProfilingLevel = (typeof ProfilingLevel)[keyof typeof ProfilingLevel];
|
|
20
20
|
|
|
21
21
|
/** @public */
|
|
22
22
|
export type SetProfilingLevelOptions = CommandOperationOptions;
|
package/src/operations/stats.ts
CHANGED
|
@@ -78,7 +78,7 @@ export class DbStatsOperation extends CommandOperation<Document> {
|
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* @public
|
|
81
|
-
* @see https://
|
|
81
|
+
* @see https://www.mongodb.com/docs/manual/reference/command/collStats/
|
|
82
82
|
*/
|
|
83
83
|
export interface CollStats extends Document {
|
|
84
84
|
/** Namespace */
|
package/src/read_concern.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const ReadConcernLevel = Object.freeze({
|
|
|
10
10
|
} as const);
|
|
11
11
|
|
|
12
12
|
/** @public */
|
|
13
|
-
export type ReadConcernLevel = typeof ReadConcernLevel[keyof typeof ReadConcernLevel];
|
|
13
|
+
export type ReadConcernLevel = (typeof ReadConcernLevel)[keyof typeof ReadConcernLevel];
|
|
14
14
|
|
|
15
15
|
/** @public */
|
|
16
16
|
export type ReadConcernLike = ReadConcern | { level: ReadConcernLevel } | ReadConcernLevel;
|
|
@@ -20,7 +20,7 @@ export type ReadConcernLike = ReadConcern | { level: ReadConcernLevel } | ReadCo
|
|
|
20
20
|
* of the data read from replica sets and replica set shards.
|
|
21
21
|
* @public
|
|
22
22
|
*
|
|
23
|
-
* @see https://
|
|
23
|
+
* @see https://www.mongodb.com/docs/manual/reference/read-concern/index.html
|
|
24
24
|
*/
|
|
25
25
|
export class ReadConcern {
|
|
26
26
|
level: ReadConcernLevel | string;
|