mongodb 6.8.0-dev.20240731.sha.b26c3280 → 6.8.0-dev.20240808.sha.5565d500
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/lib/beta.d.ts +7875 -0
- package/lib/beta.js +22 -0
- package/lib/beta.js.map +1 -0
- package/lib/bson.js +4 -4
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +2 -2
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +10 -2
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +14 -3
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +24 -4
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/crypto_callbacks.js +6 -6
- package/lib/client-side-encryption/crypto_callbacks.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/client-side-encryption/providers/aws.js +1 -2
- package/lib/client-side-encryption/providers/aws.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +5 -5
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/client-side-encryption/providers/gcp.js +1 -2
- package/lib/client-side-encryption/providers/gcp.js.map +1 -1
- package/lib/client-side-encryption/providers/index.js +2 -3
- package/lib/client-side-encryption/providers/index.js.map +1 -1
- package/lib/client-side-encryption/state_machine.js +9 -4
- package/lib/client-side-encryption/state_machine.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +3 -3
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +2 -3
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +8 -6
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +3 -3
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +1 -1
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +4 -4
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/metrics.js +1 -1
- package/lib/cmap/metrics.js.map +1 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +5 -5
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/on_data.js +1 -2
- package/lib/cmap/wire_protocol/on_data.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
- package/lib/cmap/wire_protocol/responses.js +4 -4
- package/lib/cmap/wire_protocol/responses.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +2 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +10 -3
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +21 -1
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/change_stream_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +3 -3
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +1 -1
- package/lib/db.js.map +1 -1
- package/lib/deps.js +8 -8
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +9 -9
- package/lib/error.js.map +1 -1
- package/lib/explain.js.map +1 -1
- package/lib/gridfs/download.js +1 -1
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +1 -1
- package/lib/gridfs/index.js.map +1 -1
- 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 +15 -1
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_client_auth_providers.js.map +1 -1
- package/lib/mongo_logger.js +5 -5
- package/lib/mongo_logger.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +2 -2
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/execute_operation.js +1 -2
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/operation.js +2 -2
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/search_indexes/drop.js.map +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +2 -2
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_concern.js.map +1 -1
- package/lib/read_preference.js +1 -1
- 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/common.js +3 -3
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +1 -1
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +3 -3
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +5 -5
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +1 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +1 -1
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +14 -5
- package/lib/sessions.js.map +1 -1
- package/lib/sort.js +1 -2
- package/lib/sort.js.map +1 -1
- package/lib/timeout.js.map +1 -1
- package/lib/transactions.js +2 -2
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +49 -50
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +2 -2
- package/lib/write_concern.js.map +1 -1
- package/mongodb.d.ts +55 -12
- package/package.json +5 -4
- package/src/beta.ts +22 -0
- package/src/change_stream.ts +23 -4
- package/src/client-side-encryption/auto_encrypter.ts +17 -3
- package/src/client-side-encryption/client_encryption.ts +32 -6
- package/src/client-side-encryption/state_machine.ts +28 -6
- package/src/cmap/connect.ts +2 -0
- package/src/connection_string.ts +7 -0
- package/src/cursor/abstract_cursor.ts +38 -8
- package/src/index.ts +3 -0
- package/src/mongo_client.ts +25 -3
- package/src/resource_management.ts +74 -0
- package/src/sessions.ts +21 -2
package/src/mongo_client.ts
CHANGED
|
@@ -34,6 +34,7 @@ import { executeOperation } from './operations/execute_operation';
|
|
|
34
34
|
import { RunAdminCommandOperation } from './operations/run_command';
|
|
35
35
|
import type { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern';
|
|
36
36
|
import { ReadPreference, type ReadPreferenceMode } from './read_preference';
|
|
37
|
+
import { type AsyncDisposable, configureResourceManagement } from './resource_management';
|
|
37
38
|
import type { ServerMonitoringMode } from './sdam/monitor';
|
|
38
39
|
import type { TagSet } from './sdam/server_description';
|
|
39
40
|
import { readPreferenceServerSelector } from './sdam/server_selection';
|
|
@@ -104,7 +105,7 @@ export type SupportedTLSSocketOptions = Pick<
|
|
|
104
105
|
|
|
105
106
|
/** @public */
|
|
106
107
|
export type SupportedSocketOptions = Pick<
|
|
107
|
-
TcpNetConnectOpts,
|
|
108
|
+
TcpNetConnectOpts & { autoSelectFamily?: boolean; autoSelectFamilyAttemptTimeout?: number },
|
|
108
109
|
(typeof LEGAL_TCP_SOCKET_OPTIONS)[number]
|
|
109
110
|
>;
|
|
110
111
|
|
|
@@ -344,7 +345,7 @@ const kOptions = Symbol('options');
|
|
|
344
345
|
* await client.insertOne({ name: 'spot', kind: 'dog' });
|
|
345
346
|
* ```
|
|
346
347
|
*/
|
|
347
|
-
export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
348
|
+
export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements AsyncDisposable {
|
|
348
349
|
/** @internal */
|
|
349
350
|
s: MongoClientPrivate;
|
|
350
351
|
/** @internal */
|
|
@@ -404,6 +405,17 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
404
405
|
this.checkForNonGenuineHosts();
|
|
405
406
|
}
|
|
406
407
|
|
|
408
|
+
/**
|
|
409
|
+
* @beta
|
|
410
|
+
* @experimental
|
|
411
|
+
* An alias for {@link MongoClient.close|MongoClient.close()}.
|
|
412
|
+
*/
|
|
413
|
+
declare [Symbol.asyncDispose]: () => Promise<void>;
|
|
414
|
+
/** @internal */
|
|
415
|
+
async asyncDispose() {
|
|
416
|
+
await this.close();
|
|
417
|
+
}
|
|
418
|
+
|
|
407
419
|
/** @internal */
|
|
408
420
|
private checkForNonGenuineHosts() {
|
|
409
421
|
const documentDBHostnames = this[kOptions].hosts.filter((hostAddress: HostAddress) =>
|
|
@@ -570,7 +582,15 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
570
582
|
}
|
|
571
583
|
|
|
572
584
|
/**
|
|
573
|
-
*
|
|
585
|
+
* Cleans up client-side resources used by the MongoCLient and . This includes:
|
|
586
|
+
*
|
|
587
|
+
* - Closes all open, unused connections (see note).
|
|
588
|
+
* - Ends all in-use sessions with {@link ClientSession#endSession|ClientSession.endSession()}.
|
|
589
|
+
* - Ends all unused sessions server-side.
|
|
590
|
+
* - Cleans up any resources being used for auto encryption if auto encryption is enabled.
|
|
591
|
+
*
|
|
592
|
+
* @remarks Any in-progress operations are not killed and any connections used by in progress operations
|
|
593
|
+
* will be cleaned up lazily as operations finish.
|
|
574
594
|
*
|
|
575
595
|
* @param force - Force close, emitting no events
|
|
576
596
|
*/
|
|
@@ -758,6 +778,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
758
778
|
}
|
|
759
779
|
}
|
|
760
780
|
|
|
781
|
+
configureResourceManagement(MongoClient.prototype);
|
|
782
|
+
|
|
761
783
|
/**
|
|
762
784
|
* Parsed Mongo Client Options.
|
|
763
785
|
*
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export interface AsyncDisposable {
|
|
5
|
+
/**
|
|
6
|
+
* @beta
|
|
7
|
+
* @experimental
|
|
8
|
+
*/
|
|
9
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*
|
|
14
|
+
* A method that wraps disposal semantics for a given resource in the class.
|
|
15
|
+
*/
|
|
16
|
+
asyncDispose(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @internal */
|
|
20
|
+
export function configureResourceManagement(target: AsyncDisposable) {
|
|
21
|
+
Symbol.asyncDispose &&
|
|
22
|
+
Object.defineProperty(target, Symbol.asyncDispose, {
|
|
23
|
+
value: async function asyncDispose(this: AsyncDisposable) {
|
|
24
|
+
await this.asyncDispose();
|
|
25
|
+
},
|
|
26
|
+
enumerable: false,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @beta
|
|
34
|
+
* @experimental
|
|
35
|
+
*
|
|
36
|
+
* Attaches `Symbol.asyncDispose` methods to the MongoClient, Cursors, sessions and change streams
|
|
37
|
+
* if Symbol.asyncDispose is defined.
|
|
38
|
+
*
|
|
39
|
+
* It's usually not necessary to call this method - the driver attempts to attach these methods
|
|
40
|
+
* itself when its loaded. However, sometimes the driver may be loaded before `Symbol.asyncDispose`
|
|
41
|
+
* is defined, in which case it is necessary to call this method directly. This can happen if the
|
|
42
|
+
* application is polyfilling `Symbol.asyncDispose`.
|
|
43
|
+
*
|
|
44
|
+
* Example:
|
|
45
|
+
*
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { configureExplicitResourceManagement, MongoClient } from 'mongodb/lib/beta';
|
|
48
|
+
*
|
|
49
|
+
* Symbol.asyncDispose ??= Symbol('dispose');
|
|
50
|
+
* load();
|
|
51
|
+
*
|
|
52
|
+
* await using client = new MongoClient(...);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function configureExplicitResourceManagement() {
|
|
56
|
+
// We must import lazily here, because there's a circular dependency between the resource management
|
|
57
|
+
// file and each resources' file. We could move `configureResourceManagement` to a separate
|
|
58
|
+
// function, but keeping all resource-management related code together seemed preferable and I chose
|
|
59
|
+
// lazy requiring of resources instead.
|
|
60
|
+
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
62
|
+
const { MongoClient } = require('./mongo_client');
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
64
|
+
const { ClientSession } = require('./sessions');
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
66
|
+
const { AbstractCursor } = require('./cursor/abstract_cursor');
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
68
|
+
const { ChangeStream } = require('./change_stream');
|
|
69
|
+
|
|
70
|
+
configureResourceManagement(MongoClient.prototype);
|
|
71
|
+
configureResourceManagement(ClientSession.prototype);
|
|
72
|
+
configureResourceManagement(AbstractCursor.prototype);
|
|
73
|
+
configureResourceManagement(ChangeStream.prototype);
|
|
74
|
+
}
|
package/src/sessions.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { executeOperation } from './operations/execute_operation';
|
|
|
27
27
|
import { RunAdminCommandOperation } from './operations/run_command';
|
|
28
28
|
import { ReadConcernLevel } from './read_concern';
|
|
29
29
|
import { ReadPreference } from './read_preference';
|
|
30
|
+
import { type AsyncDisposable, configureResourceManagement } from './resource_management';
|
|
30
31
|
import { _advanceClusterTime, type ClusterTime, TopologyType } from './sdam/common';
|
|
31
32
|
import {
|
|
32
33
|
isTransactionCommand,
|
|
@@ -105,7 +106,10 @@ export interface EndSessionOptions {
|
|
|
105
106
|
* NOTE: not meant to be instantiated directly.
|
|
106
107
|
* @public
|
|
107
108
|
*/
|
|
108
|
-
export class ClientSession
|
|
109
|
+
export class ClientSession
|
|
110
|
+
extends TypedEventEmitter<ClientSessionEvents>
|
|
111
|
+
implements AsyncDisposable
|
|
112
|
+
{
|
|
109
113
|
/** @internal */
|
|
110
114
|
client: MongoClient;
|
|
111
115
|
/** @internal */
|
|
@@ -255,7 +259,10 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
255
259
|
}
|
|
256
260
|
|
|
257
261
|
/**
|
|
258
|
-
*
|
|
262
|
+
* Frees any client-side resources held by the current session. If a session is in a transaction,
|
|
263
|
+
* the transaction is aborted.
|
|
264
|
+
*
|
|
265
|
+
* Does not end the session on the server.
|
|
259
266
|
*
|
|
260
267
|
* @param options - Optional settings. Currently reserved for future use
|
|
261
268
|
*/
|
|
@@ -286,6 +293,16 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
286
293
|
maybeClearPinnedConnection(this, { force: true, ...options });
|
|
287
294
|
}
|
|
288
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* @beta
|
|
298
|
+
* @experimental
|
|
299
|
+
* An alias for {@link ClientSession.endSession|ClientSession.endSession()}.
|
|
300
|
+
*/
|
|
301
|
+
declare [Symbol.asyncDispose]: () => Promise<void>;
|
|
302
|
+
/** @internal */
|
|
303
|
+
async asyncDispose() {
|
|
304
|
+
await this.endSession({ force: true });
|
|
305
|
+
}
|
|
289
306
|
|
|
290
307
|
/**
|
|
291
308
|
* Advances the operationTime for a ClientSession.
|
|
@@ -484,6 +501,8 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
|
|
|
484
501
|
}
|
|
485
502
|
}
|
|
486
503
|
|
|
504
|
+
configureResourceManagement(ClientSession.prototype);
|
|
505
|
+
|
|
487
506
|
const MAX_WITH_TRANSACTION_TIMEOUT = 120000;
|
|
488
507
|
const NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = new Set([
|
|
489
508
|
'CannotSatisfyWriteConcern',
|