mongodb 6.8.2 → 6.9.0-dev.20240917.sha.20396e1b
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 +14 -1
- package/lib/beta.d.ts +7940 -0
- package/lib/beta.js +21 -0
- package/lib/beta.js.map +1 -0
- package/lib/bson.js +5 -5
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +16 -21
- 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 -8
- 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 +25 -7
- 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 +9 -5
- 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 +4 -4
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +2 -7
- package/lib/cmap/auth/mongo_credentials.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 +0 -2
- 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 +0 -2
- 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 +62 -5
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +10 -7
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +3 -5
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +11 -9
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +7 -3
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +5 -5
- 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/constants.js +4 -4
- 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 +12 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +21 -6
- 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 +2 -2
- package/lib/db.js.map +1 -1
- package/lib/deps.js +16 -8
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +19 -14
- package/lib/error.js.map +1 -1
- package/lib/explain.js +6 -6
- package/lib/explain.js.map +1 -1
- package/lib/gridfs/download.js +1 -4
- 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 +0 -4
- 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 +6 -2
- package/lib/mongo_client_auth_providers.js.map +1 -1
- package/lib/mongo_logger.js +8 -8
- package/lib/mongo_logger.js.map +1 -1
- package/lib/mongo_types.js +1 -0
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/aggregate.js +1 -0
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/client_bulk_write/command_builder.js +198 -0
- package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
- package/lib/operations/client_bulk_write/common.js +3 -0
- package/lib/operations/client_bulk_write/common.js.map +1 -0
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js +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 +111 -109
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +2 -8
- 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 +5 -5
- 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 +1 -5
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +2 -2
- 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 +2 -3
- 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 +221 -218
- package/lib/sessions.js.map +1 -1
- package/lib/sort.js +2 -3
- package/lib/sort.js.map +1 -1
- package/lib/timeout.js +0 -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 +54 -54
- 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 +191 -148
- package/package.json +27 -28
- package/src/beta.ts +22 -0
- package/src/bson.ts +1 -2
- package/src/bulk/common.ts +18 -18
- package/src/change_stream.ts +33 -15
- package/src/client-side-encryption/auto_encrypter.ts +18 -82
- package/src/client-side-encryption/client_encryption.ts +51 -54
- package/src/client-side-encryption/mongocryptd_manager.ts +10 -6
- package/src/client-side-encryption/state_machine.ts +28 -6
- package/src/cmap/auth/gssapi.ts +1 -1
- package/src/cmap/auth/mongo_credentials.ts +2 -8
- package/src/cmap/auth/mongodb_aws.ts +2 -2
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +2 -2
- package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +2 -2
- package/src/cmap/commands.ts +70 -5
- package/src/cmap/connect.ts +4 -1
- package/src/cmap/connection.ts +2 -2
- package/src/cmap/connection_pool.ts +17 -9
- package/src/cmap/connection_pool_events.ts +34 -2
- package/src/cmap/handshake/client_metadata.ts +1 -1
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/cmap/wire_protocol/shared.ts +1 -2
- package/src/collection.ts +16 -15
- package/src/connection_string.ts +10 -3
- package/src/constants.ts +1 -0
- package/src/cursor/abstract_cursor.ts +38 -13
- package/src/cursor/aggregation_cursor.ts +8 -6
- package/src/cursor/find_cursor.ts +2 -2
- package/src/db.ts +1 -1
- package/src/deps.ts +8 -1
- package/src/error.ts +33 -14
- package/src/explain.ts +47 -11
- package/src/gridfs/download.ts +28 -4
- package/src/gridfs/upload.ts +1 -6
- package/src/index.ts +11 -2
- package/src/mongo_client.ts +29 -5
- package/src/mongo_client_auth_providers.ts +8 -2
- package/src/mongo_logger.ts +5 -3
- package/src/mongo_types.ts +69 -68
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/bulk_write.ts +2 -2
- package/src/operations/client_bulk_write/command_builder.ts +283 -0
- package/src/operations/client_bulk_write/common.ts +146 -0
- package/src/operations/command.ts +1 -1
- package/src/operations/execute_operation.ts +137 -131
- package/src/operations/find_and_modify.ts +2 -7
- package/src/operations/insert.ts +3 -4
- package/src/operations/operation.ts +7 -10
- package/src/operations/search_indexes/drop.ts +4 -1
- package/src/resource_management.ts +74 -0
- package/src/sdam/monitor.ts +3 -5
- package/src/sdam/server.ts +1 -1
- package/src/sdam/server_description.ts +5 -6
- package/src/sdam/srv_polling.ts +1 -2
- package/src/sessions.ts +291 -277
- package/src/sort.ts +1 -1
- package/src/timeout.ts +0 -1
- package/src/transactions.ts +1 -2
- package/src/utils.ts +25 -9
- package/src/write_concern.ts +2 -2
- package/tsconfig.json +2 -1
- package/lib/cmap/auth/mongocr.js +0 -35
- package/lib/cmap/auth/mongocr.js.map +0 -1
- package/src/cmap/auth/mongocr.ts +0 -38
package/src/gridfs/download.ts
CHANGED
|
@@ -56,15 +56,41 @@ export interface GridFSFile {
|
|
|
56
56
|
|
|
57
57
|
/** @internal */
|
|
58
58
|
export interface GridFSBucketReadStreamPrivate {
|
|
59
|
+
/**
|
|
60
|
+
* The running total number of bytes read from the chunks collection.
|
|
61
|
+
*/
|
|
59
62
|
bytesRead: number;
|
|
63
|
+
/**
|
|
64
|
+
* The number of bytes to remove from the last chunk read in the file. This is non-zero
|
|
65
|
+
* if `end` is not equal to the length of the document and `end` is not a multiple
|
|
66
|
+
* of the chunkSize.
|
|
67
|
+
*/
|
|
60
68
|
bytesToTrim: number;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The number of bytes to remove from the first chunk read in the file. This is non-zero
|
|
72
|
+
* if `start` is not equal to the 0 and `start` is not a multiple
|
|
73
|
+
* of the chunkSize.
|
|
74
|
+
*/
|
|
61
75
|
bytesToSkip: number;
|
|
76
|
+
|
|
77
|
+
files: Collection<GridFSFile>;
|
|
62
78
|
chunks: Collection<GridFSChunk>;
|
|
63
79
|
cursor?: FindCursor<GridFSChunk>;
|
|
80
|
+
|
|
81
|
+
/** The running total number of chunks read from the chunks collection. */
|
|
64
82
|
expected: number;
|
|
65
|
-
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The filter used to search in the _files_ collection (i.e., `{ _id: <> }`)
|
|
86
|
+
* This is not the same filter used when reading chunks from the chunks collection.
|
|
87
|
+
*/
|
|
66
88
|
filter: Document;
|
|
89
|
+
|
|
90
|
+
/** Indicates whether or not download has started. */
|
|
67
91
|
init: boolean;
|
|
92
|
+
|
|
93
|
+
/** The expected number of chunks to read, calculated from start, end, chunkSize and file length. */
|
|
68
94
|
expectedEnd: number;
|
|
69
95
|
file?: GridFSFile;
|
|
70
96
|
options: {
|
|
@@ -190,7 +216,7 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
190
216
|
|
|
191
217
|
if (!doc) {
|
|
192
218
|
stream.push(null);
|
|
193
|
-
|
|
219
|
+
|
|
194
220
|
stream.s.cursor?.close().then(undefined, error => stream.destroy(error));
|
|
195
221
|
return;
|
|
196
222
|
}
|
|
@@ -262,7 +288,6 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
262
288
|
return;
|
|
263
289
|
};
|
|
264
290
|
|
|
265
|
-
// eslint-disable-next-line github/no-then
|
|
266
291
|
stream.s.cursor.next().then(handleReadResult, error => {
|
|
267
292
|
if (stream.destroyed) return;
|
|
268
293
|
stream.destroy(error);
|
|
@@ -346,7 +371,6 @@ function init(stream: GridFSBucketReadStream): void {
|
|
|
346
371
|
return;
|
|
347
372
|
};
|
|
348
373
|
|
|
349
|
-
// eslint-disable-next-line github/no-then
|
|
350
374
|
stream.s.files.findOne(stream.s.filter, findOneOptions).then(handleReadResult, error => {
|
|
351
375
|
if (stream.destroyed) return;
|
|
352
376
|
stream.destroy(error);
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Writable } from 'stream';
|
|
2
2
|
|
|
3
|
-
import type
|
|
4
|
-
import { ObjectId } from '../bson';
|
|
3
|
+
import { type Document, ObjectId } from '../bson';
|
|
5
4
|
import type { Collection } from '../collection';
|
|
6
5
|
import { MongoAPIError, MONGODB_ERROR_CODES, MongoError } from '../error';
|
|
7
6
|
import { type Callback, squashError } from '../utils';
|
|
@@ -135,7 +134,6 @@ export class GridFSBucketWriteStream extends Writable {
|
|
|
135
134
|
if (!this.bucket.s.calledOpenUploadStream) {
|
|
136
135
|
this.bucket.s.calledOpenUploadStream = true;
|
|
137
136
|
|
|
138
|
-
// eslint-disable-next-line github/no-then
|
|
139
137
|
checkIndexes(this).then(() => {
|
|
140
138
|
this.bucket.s.checkedIndexes = true;
|
|
141
139
|
this.bucket.emit('index');
|
|
@@ -272,7 +270,6 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
|
|
|
272
270
|
return;
|
|
273
271
|
}
|
|
274
272
|
|
|
275
|
-
// eslint-disable-next-line github/no-then
|
|
276
273
|
stream.files.insertOne(gridFSFile, { writeConcern: stream.writeConcern }).then(
|
|
277
274
|
() => {
|
|
278
275
|
stream.gridFSFile = gridFSFile;
|
|
@@ -396,7 +393,6 @@ function doWrite(
|
|
|
396
393
|
return;
|
|
397
394
|
}
|
|
398
395
|
|
|
399
|
-
// eslint-disable-next-line github/no-then
|
|
400
396
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
401
397
|
() => {
|
|
402
398
|
--stream.state.outstandingRequests;
|
|
@@ -437,7 +433,6 @@ function writeRemnant(stream: GridFSBucketWriteStream, callback: Callback): void
|
|
|
437
433
|
return;
|
|
438
434
|
}
|
|
439
435
|
|
|
440
|
-
// eslint-disable-next-line github/no-then
|
|
441
436
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
442
437
|
() => {
|
|
443
438
|
--stream.state.outstandingRequests;
|
package/src/index.ts
CHANGED
|
@@ -73,8 +73,10 @@ export {
|
|
|
73
73
|
MongoTopologyClosedError,
|
|
74
74
|
MongoTransactionError,
|
|
75
75
|
MongoUnexpectedServerResponseError,
|
|
76
|
-
MongoWriteConcernError
|
|
76
|
+
MongoWriteConcernError,
|
|
77
|
+
WriteConcernErrorResult
|
|
77
78
|
} from './error';
|
|
79
|
+
export { configureExplicitResourceManagement } from './resource_management';
|
|
78
80
|
export {
|
|
79
81
|
AbstractCursor,
|
|
80
82
|
// Actual driver classes exported
|
|
@@ -247,6 +249,7 @@ export type {
|
|
|
247
249
|
LocalKMSProviderConfiguration
|
|
248
250
|
} from './client-side-encryption/providers/index';
|
|
249
251
|
export type {
|
|
252
|
+
ClientEncryptionSocketOptions,
|
|
250
253
|
ClientEncryptionTlsOptions,
|
|
251
254
|
CSFLEKMSTlsOptions,
|
|
252
255
|
StateMachineExecutable
|
|
@@ -365,7 +368,12 @@ export type { RunCursorCommandOptions } from './cursor/run_command_cursor';
|
|
|
365
368
|
export type { DbOptions, DbPrivate } from './db';
|
|
366
369
|
export type { Encrypter, EncrypterOptions } from './encrypter';
|
|
367
370
|
export type { AnyError, ErrorDescription, MongoNetworkErrorOptions } from './error';
|
|
368
|
-
export type {
|
|
371
|
+
export type {
|
|
372
|
+
Explain,
|
|
373
|
+
ExplainCommandOptions,
|
|
374
|
+
ExplainOptions,
|
|
375
|
+
ExplainVerbosityLike
|
|
376
|
+
} from './explain';
|
|
369
377
|
export type {
|
|
370
378
|
GridFSBucketReadStreamOptions,
|
|
371
379
|
GridFSBucketReadStreamOptionsWithRevision,
|
|
@@ -524,6 +532,7 @@ export type {
|
|
|
524
532
|
ReadPreferenceLikeOptions,
|
|
525
533
|
ReadPreferenceOptions
|
|
526
534
|
} from './read_preference';
|
|
535
|
+
export type { AsyncDisposable } from './resource_management';
|
|
527
536
|
export type { ClusterTime, TimerQueue } from './sdam/common';
|
|
528
537
|
export type {
|
|
529
538
|
Monitor,
|
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';
|
|
@@ -92,8 +93,10 @@ export interface PkFactory {
|
|
|
92
93
|
|
|
93
94
|
/** @public */
|
|
94
95
|
export type SupportedTLSConnectionOptions = Pick<
|
|
95
|
-
TLSConnectionOptions
|
|
96
|
-
|
|
96
|
+
TLSConnectionOptions & {
|
|
97
|
+
allowPartialTrustChain?: boolean;
|
|
98
|
+
},
|
|
99
|
+
(typeof LEGAL_TLS_SOCKET_OPTIONS)[number]
|
|
97
100
|
>;
|
|
98
101
|
|
|
99
102
|
/** @public */
|
|
@@ -104,7 +107,7 @@ export type SupportedTLSSocketOptions = Pick<
|
|
|
104
107
|
|
|
105
108
|
/** @public */
|
|
106
109
|
export type SupportedSocketOptions = Pick<
|
|
107
|
-
TcpNetConnectOpts,
|
|
110
|
+
TcpNetConnectOpts & { autoSelectFamily?: boolean; autoSelectFamilyAttemptTimeout?: number },
|
|
108
111
|
(typeof LEGAL_TCP_SOCKET_OPTIONS)[number]
|
|
109
112
|
>;
|
|
110
113
|
|
|
@@ -344,7 +347,7 @@ const kOptions = Symbol('options');
|
|
|
344
347
|
* await client.insertOne({ name: 'spot', kind: 'dog' });
|
|
345
348
|
* ```
|
|
346
349
|
*/
|
|
347
|
-
export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
350
|
+
export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements AsyncDisposable {
|
|
348
351
|
/** @internal */
|
|
349
352
|
s: MongoClientPrivate;
|
|
350
353
|
/** @internal */
|
|
@@ -404,6 +407,17 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
404
407
|
this.checkForNonGenuineHosts();
|
|
405
408
|
}
|
|
406
409
|
|
|
410
|
+
/**
|
|
411
|
+
* @beta
|
|
412
|
+
* @experimental
|
|
413
|
+
* An alias for {@link MongoClient.close|MongoClient.close()}.
|
|
414
|
+
*/
|
|
415
|
+
declare [Symbol.asyncDispose]: () => Promise<void>;
|
|
416
|
+
/** @internal */
|
|
417
|
+
async asyncDispose() {
|
|
418
|
+
await this.close();
|
|
419
|
+
}
|
|
420
|
+
|
|
407
421
|
/** @internal */
|
|
408
422
|
private checkForNonGenuineHosts() {
|
|
409
423
|
const documentDBHostnames = this[kOptions].hosts.filter((hostAddress: HostAddress) =>
|
|
@@ -570,7 +584,15 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
570
584
|
}
|
|
571
585
|
|
|
572
586
|
/**
|
|
573
|
-
*
|
|
587
|
+
* Cleans up client-side resources used by the MongoCLient and . This includes:
|
|
588
|
+
*
|
|
589
|
+
* - Closes all open, unused connections (see note).
|
|
590
|
+
* - Ends all in-use sessions with {@link ClientSession#endSession|ClientSession.endSession()}.
|
|
591
|
+
* - Ends all unused sessions server-side.
|
|
592
|
+
* - Cleans up any resources being used for auto encryption if auto encryption is enabled.
|
|
593
|
+
*
|
|
594
|
+
* @remarks Any in-progress operations are not killed and any connections used by in progress operations
|
|
595
|
+
* will be cleaned up lazily as operations finish.
|
|
574
596
|
*
|
|
575
597
|
* @param force - Force close, emitting no events
|
|
576
598
|
*/
|
|
@@ -758,6 +780,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
758
780
|
}
|
|
759
781
|
}
|
|
760
782
|
|
|
783
|
+
configureResourceManagement(MongoClient.prototype);
|
|
784
|
+
|
|
761
785
|
/**
|
|
762
786
|
* Parsed Mongo Client Options.
|
|
763
787
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type AuthProvider } from './cmap/auth/auth_provider';
|
|
2
2
|
import { GSSAPI } from './cmap/auth/gssapi';
|
|
3
3
|
import { type AuthMechanismProperties } from './cmap/auth/mongo_credentials';
|
|
4
|
-
import { MongoCR } from './cmap/auth/mongocr';
|
|
5
4
|
import { MongoDBAWS } from './cmap/auth/mongodb_aws';
|
|
6
5
|
import { MongoDBOIDC, OIDC_WORKFLOWS, type Workflow } from './cmap/auth/mongodb_oidc';
|
|
7
6
|
import { AutomatedCallbackWorkflow } from './cmap/auth/mongodb_oidc/automated_callback_workflow';
|
|
@@ -16,7 +15,14 @@ import { MongoInvalidArgumentError } from './error';
|
|
|
16
15
|
/** @internal */
|
|
17
16
|
const AUTH_PROVIDERS = new Map<AuthMechanism | string, (workflow?: Workflow) => AuthProvider>([
|
|
18
17
|
[AuthMechanism.MONGODB_AWS, () => new MongoDBAWS()],
|
|
19
|
-
[
|
|
18
|
+
[
|
|
19
|
+
AuthMechanism.MONGODB_CR,
|
|
20
|
+
() => {
|
|
21
|
+
throw new MongoInvalidArgumentError(
|
|
22
|
+
'MONGODB-CR is no longer a supported auth mechanism in MongoDB 4.0+'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
],
|
|
20
26
|
[AuthMechanism.MONGODB_GSSAPI, () => new GSSAPI()],
|
|
21
27
|
[AuthMechanism.MONGODB_OIDC, (workflow?: Workflow) => new MongoDBOIDC(workflow)],
|
|
22
28
|
[AuthMechanism.MONGODB_PLAIN, () => new Plain()],
|
package/src/mongo_logger.ts
CHANGED
|
@@ -604,6 +604,7 @@ export function defaultLogTransform(
|
|
|
604
604
|
log = attachConnectionFields(log, logObject);
|
|
605
605
|
log.message = 'Connection ready';
|
|
606
606
|
log.driverConnectionId = logObject.connectionId;
|
|
607
|
+
log.durationMS = logObject.durationMS;
|
|
607
608
|
return log;
|
|
608
609
|
case CONNECTION_CLOSED:
|
|
609
610
|
log = attachConnectionFields(log, logObject);
|
|
@@ -653,11 +654,13 @@ export function defaultLogTransform(
|
|
|
653
654
|
default:
|
|
654
655
|
log.reason = `Unknown close reason: ${logObject.reason}`;
|
|
655
656
|
}
|
|
657
|
+
log.durationMS = logObject.durationMS;
|
|
656
658
|
return log;
|
|
657
659
|
case CONNECTION_CHECKED_OUT:
|
|
658
660
|
log = attachConnectionFields(log, logObject);
|
|
659
661
|
log.message = 'Connection checked out';
|
|
660
662
|
log.driverConnectionId = logObject.connectionId;
|
|
663
|
+
log.durationMS = logObject.durationMS;
|
|
661
664
|
return log;
|
|
662
665
|
case CONNECTION_CHECKED_IN:
|
|
663
666
|
log = attachConnectionFields(log, logObject);
|
|
@@ -836,9 +839,9 @@ export class MongoLogger {
|
|
|
836
839
|
|
|
837
840
|
if (isPromiseLike(this.pendingLog)) {
|
|
838
841
|
this.pendingLog = this.pendingLog
|
|
839
|
-
|
|
842
|
+
|
|
840
843
|
.then(() => this.logDestination.write(logMessage))
|
|
841
|
-
|
|
844
|
+
|
|
842
845
|
.then(this.clearPendingLog.bind(this), this.logWriteFailureHandler.bind(this));
|
|
843
846
|
return;
|
|
844
847
|
}
|
|
@@ -846,7 +849,6 @@ export class MongoLogger {
|
|
|
846
849
|
try {
|
|
847
850
|
const logResult = this.logDestination.write(logMessage);
|
|
848
851
|
if (isPromiseLike(logResult)) {
|
|
849
|
-
// eslint-disable-next-line github/no-then
|
|
850
852
|
this.pendingLog = logResult.then(
|
|
851
853
|
this.clearPendingLog.bind(this),
|
|
852
854
|
this.logWriteFailureHandler.bind(this)
|
package/src/mongo_types.ts
CHANGED
|
@@ -34,11 +34,11 @@ export type InferIdType<TSchema> = TSchema extends { _id: infer IdType }
|
|
|
34
34
|
? never // explicitly forbid empty objects as the type of _id
|
|
35
35
|
: IdType
|
|
36
36
|
: TSchema extends { _id?: infer IdType }
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
? // optional _id defined - return ObjectId | IdType
|
|
38
|
+
unknown extends IdType
|
|
39
|
+
? ObjectId // infer the _id type as ObjectId if the type of _id is unknown
|
|
40
|
+
: IdType
|
|
41
|
+
: ObjectId; // user has not defined _id on schema
|
|
42
42
|
|
|
43
43
|
/** Add an _id field to an object shaped type @public */
|
|
44
44
|
export type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id: InferIdType<TSchema> };
|
|
@@ -68,8 +68,8 @@ export type OptionalUnlessRequiredId<TSchema> = TSchema extends { _id: any }
|
|
|
68
68
|
export type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion
|
|
69
69
|
? TRecordOrUnion // TRecordOrUnion has indexed type e.g. { _id: string; [k: string]: any; } or it is "any"
|
|
70
70
|
: TRecordOrUnion extends any
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> // discriminated unions
|
|
72
|
+
: never;
|
|
73
73
|
|
|
74
74
|
/** Remove the _id field from an object shaped type @public */
|
|
75
75
|
export type WithoutId<TSchema> = Omit<TSchema, '_id'>;
|
|
@@ -88,9 +88,8 @@ export type Condition<T> = AlternativeType<T> | FilterOperators<AlternativeType<
|
|
|
88
88
|
* array types can be searched using their element type
|
|
89
89
|
* @public
|
|
90
90
|
*/
|
|
91
|
-
export type AlternativeType<T> =
|
|
92
|
-
? T | RegExpOrString<U>
|
|
93
|
-
: RegExpOrString<T>;
|
|
91
|
+
export type AlternativeType<T> =
|
|
92
|
+
T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>;
|
|
94
93
|
|
|
95
94
|
/** @public */
|
|
96
95
|
export type RegExpOrString<T> = T extends string ? BSONRegExp | RegExp | T : T;
|
|
@@ -192,9 +191,10 @@ export type IntegerType = number | Int32 | Long | bigint;
|
|
|
192
191
|
export type NumericType = IntegerType | Decimal128 | Double;
|
|
193
192
|
|
|
194
193
|
/** @public */
|
|
195
|
-
export type FilterOperations<T> =
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
export type FilterOperations<T> =
|
|
195
|
+
T extends Record<string, any>
|
|
196
|
+
? { [key in keyof T]?: FilterOperators<T[key]> }
|
|
197
|
+
: FilterOperators<T>;
|
|
198
198
|
|
|
199
199
|
/** @public */
|
|
200
200
|
export type KeysOfAType<TSchema, Type> = {
|
|
@@ -412,6 +412,7 @@ export declare interface TypedEventEmitter<Events extends EventsDescription> ext
|
|
|
412
412
|
* @public
|
|
413
413
|
*/
|
|
414
414
|
|
|
415
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
415
416
|
export class TypedEventEmitter<Events extends EventsDescription> extends EventEmitter {
|
|
416
417
|
/** @internal */
|
|
417
418
|
protected mongoLogger?: MongoLogger;
|
|
@@ -480,31 +481,31 @@ export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {}
|
|
|
480
481
|
export type Join<T extends unknown[], D extends string> = T extends []
|
|
481
482
|
? ''
|
|
482
483
|
: T extends [string | number]
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
484
|
+
? `${T[0]}`
|
|
485
|
+
: T extends [string | number, ...infer R]
|
|
486
|
+
? `${T[0]}${D}${Join<R, D>}`
|
|
487
|
+
: string;
|
|
487
488
|
|
|
488
489
|
/** @public */
|
|
489
490
|
export type PropertyType<Type, Property extends string> = string extends Property
|
|
490
491
|
? unknown
|
|
491
492
|
: Property extends keyof Type
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
493
|
+
? Type[Property]
|
|
494
|
+
: Property extends `${number}`
|
|
495
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
496
|
+
? ArrayType
|
|
497
|
+
: unknown
|
|
498
|
+
: Property extends `${infer Key}.${infer Rest}`
|
|
499
|
+
? Key extends `${number}`
|
|
500
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
501
|
+
? PropertyType<ArrayType, Rest>
|
|
502
|
+
: unknown
|
|
503
|
+
: Key extends keyof Type
|
|
504
|
+
? Type[Key] extends Map<string, infer MapType>
|
|
505
|
+
? MapType
|
|
506
|
+
: PropertyType<Type[Key], Rest>
|
|
507
|
+
: unknown
|
|
508
|
+
: unknown;
|
|
508
509
|
|
|
509
510
|
/**
|
|
510
511
|
* @public
|
|
@@ -521,41 +522,41 @@ export type PropertyType<Type, Property extends string> = string extends Propert
|
|
|
521
522
|
export type NestedPaths<Type, Depth extends number[]> = Depth['length'] extends 8
|
|
522
523
|
? []
|
|
523
524
|
: Type extends
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
525
|
+
| string
|
|
526
|
+
| number
|
|
527
|
+
| bigint
|
|
528
|
+
| boolean
|
|
529
|
+
| Date
|
|
530
|
+
| RegExp
|
|
531
|
+
| Buffer
|
|
532
|
+
| Uint8Array
|
|
533
|
+
| ((...args: any[]) => any)
|
|
534
|
+
| { _bsontype: string }
|
|
535
|
+
? []
|
|
536
|
+
: Type extends ReadonlyArray<infer ArrayType>
|
|
537
|
+
? [] | [number, ...NestedPaths<ArrayType, [...Depth, 1]>]
|
|
538
|
+
: Type extends Map<string, any>
|
|
539
|
+
? [string]
|
|
540
|
+
: Type extends object
|
|
541
|
+
? {
|
|
542
|
+
[Key in Extract<keyof Type, string>]: Type[Key] extends Type // type of value extends the parent
|
|
543
|
+
? [Key]
|
|
544
|
+
: // for a recursive union type, the child will never extend the parent type.
|
|
545
|
+
// but the parent will still extend the child
|
|
546
|
+
Type extends Type[Key]
|
|
547
|
+
? [Key]
|
|
548
|
+
: Type[Key] extends ReadonlyArray<infer ArrayType> // handling recursive types with arrays
|
|
549
|
+
? Type extends ArrayType // is the type of the parent the same as the type of the array?
|
|
550
|
+
? [Key] // yes, it's a recursive array type
|
|
551
|
+
: // for unions, the child type extends the parent
|
|
552
|
+
ArrayType extends Type
|
|
553
|
+
? [Key] // we have a recursive array union
|
|
554
|
+
: // child is an array, but it's not a recursive array
|
|
555
|
+
[Key, ...NestedPaths<Type[Key], [...Depth, 1]>]
|
|
556
|
+
: // child is not structured the same as the parent
|
|
557
|
+
[Key, ...NestedPaths<Type[Key], [...Depth, 1]>] | [Key];
|
|
558
|
+
}[Extract<keyof Type, string>]
|
|
559
|
+
: [];
|
|
559
560
|
|
|
560
561
|
/**
|
|
561
562
|
* @public
|
|
@@ -9,8 +9,9 @@ import { type CollationOptions, CommandOperation, type CommandOperationOptions }
|
|
|
9
9
|
import { Aspect, defineAspects, type Hint } from './operation';
|
|
10
10
|
|
|
11
11
|
/** @internal */
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
12
13
|
export const DB_AGGREGATE_COLLECTION = 1 as const;
|
|
13
|
-
const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8
|
|
14
|
+
const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;
|
|
14
15
|
|
|
15
16
|
/** @public */
|
|
16
17
|
export interface AggregateOptions extends CommandOperationOptions {
|
|
@@ -13,11 +13,11 @@ import { AbstractOperation, Aspect, defineAspects } from './operation';
|
|
|
13
13
|
export class BulkWriteOperation extends AbstractOperation<BulkWriteResult> {
|
|
14
14
|
override options: BulkWriteOptions;
|
|
15
15
|
collection: Collection;
|
|
16
|
-
operations: AnyBulkWriteOperation
|
|
16
|
+
operations: ReadonlyArray<AnyBulkWriteOperation>;
|
|
17
17
|
|
|
18
18
|
constructor(
|
|
19
19
|
collection: Collection,
|
|
20
|
-
operations: AnyBulkWriteOperation
|
|
20
|
+
operations: ReadonlyArray<AnyBulkWriteOperation>,
|
|
21
21
|
options: BulkWriteOptions
|
|
22
22
|
) {
|
|
23
23
|
super(options);
|