mongodb 6.5.0 → 6.6.0-dev.20240504.sha.2609953
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 +9 -9
- package/lib/admin.js +9 -9
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +33 -22
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +13 -12
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +28 -18
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +2 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +6 -6
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/providers/aws.js +13 -10
- package/lib/client-side-encryption/providers/aws.js.map +1 -1
- package/lib/client-side-encryption/providers/azure.js +6 -3
- package/lib/client-side-encryption/providers/azure.js.map +1 -1
- package/lib/cmap/auth/aws_temporary_credentials.js +140 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +7 -6
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +8 -101
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
- package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
- package/lib/cmap/auth/scram.js +2 -2
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/commands.js +24 -111
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +4 -4
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +61 -36
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +22 -13
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +2 -2
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +8 -8
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/on_demand/document.js +218 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +184 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/collection.js +42 -38
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +4 -6
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +76 -43
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +16 -33
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +36 -18
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +3 -2
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +15 -19
- package/lib/db.js.map +1 -1
- package/lib/deps.js +31 -26
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +14 -5
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +4 -3
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +19 -14
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +6 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +11 -7
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +3 -0
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/aggregate.js +2 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/create_collection.js +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +4 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/execute_operation.js +23 -8
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +4 -4
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/get_more.js +2 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +29 -121
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/kill_cursors.js +3 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/run_command.js +4 -2
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/search_indexes/create.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/monitor.js +139 -42
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +5 -15
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -0
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +1 -1
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +2 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +67 -54
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +10 -0
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +133 -93
- package/lib/sessions.js.map +1 -1
- package/lib/timeout.js +77 -0
- package/lib/timeout.js.map +1 -0
- package/lib/utils.js +61 -28
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +150 -38
- package/package.json +17 -14
- package/src/admin.ts +9 -9
- package/src/bson.ts +14 -0
- package/src/bulk/common.ts +3 -2
- package/src/change_stream.ts +39 -30
- package/src/client-side-encryption/auto_encrypter.ts +2 -2
- package/src/client-side-encryption/client_encryption.ts +6 -6
- package/src/client-side-encryption/providers/aws.ts +17 -10
- package/src/client-side-encryption/providers/azure.ts +5 -3
- package/src/cmap/auth/aws_temporary_credentials.ts +169 -0
- package/src/cmap/auth/gssapi.ts +9 -11
- package/src/cmap/auth/mongodb_aws.ts +19 -126
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
- package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
- package/src/cmap/auth/scram.ts +2 -2
- package/src/cmap/commands.ts +28 -132
- package/src/cmap/connect.ts +4 -4
- package/src/cmap/connection.ts +107 -43
- package/src/cmap/connection_pool.ts +32 -29
- package/src/cmap/handshake/client_metadata.ts +2 -5
- package/src/cmap/wire_protocol/compression.ts +11 -13
- package/src/cmap/wire_protocol/on_demand/document.ts +338 -0
- package/src/cmap/wire_protocol/responses.ts +237 -0
- package/src/collection.ts +87 -58
- package/src/connection_string.ts +9 -7
- package/src/cursor/abstract_cursor.ts +102 -38
- package/src/cursor/aggregation_cursor.ts +32 -34
- package/src/cursor/find_cursor.ts +33 -21
- package/src/cursor/list_search_indexes_cursor.ts +1 -1
- package/src/cursor/run_command_cursor.ts +3 -2
- package/src/db.ts +42 -21
- package/src/deps.ts +52 -40
- package/src/encrypter.ts +14 -5
- package/src/error.ts +9 -3
- package/src/gridfs/download.ts +19 -31
- package/src/gridfs/index.ts +2 -0
- package/src/gridfs/upload.ts +11 -8
- package/src/index.ts +13 -5
- package/src/mongo_client.ts +21 -15
- package/src/mongo_logger.ts +3 -0
- package/src/mongo_types.ts +1 -1
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/command.ts +1 -1
- package/src/operations/create_collection.ts +7 -2
- package/src/operations/delete.ts +4 -3
- package/src/operations/drop.ts +1 -1
- package/src/operations/execute_operation.ts +29 -10
- package/src/operations/find.ts +13 -14
- package/src/operations/get_more.ts +9 -1
- package/src/operations/indexes.ts +103 -176
- package/src/operations/insert.ts +2 -2
- package/src/operations/kill_cursors.ts +3 -2
- package/src/operations/list_collections.ts +5 -1
- package/src/operations/list_databases.ts +1 -1
- package/src/operations/operation.ts +3 -0
- package/src/operations/run_command.ts +6 -4
- package/src/operations/search_indexes/create.ts +4 -1
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +7 -7
- package/src/sdam/common.ts +8 -2
- package/src/sdam/monitor.ts +178 -61
- package/src/sdam/server.ts +27 -20
- package/src/sdam/server_description.ts +8 -3
- package/src/sdam/server_selection.ts +2 -3
- package/src/sdam/srv_polling.ts +3 -2
- package/src/sdam/topology.ts +114 -117
- package/src/sdam/topology_description.ts +14 -4
- package/src/sessions.ts +168 -148
- package/src/timeout.ts +96 -0
- package/src/utils.ts +85 -32
- package/lib/operations/common_functions.js +0 -38
- package/lib/operations/common_functions.js.map +0 -1
- package/src/operations/common_functions.ts +0 -79
package/src/db.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type { MongoClient, PkFactory } from './mongo_client';
|
|
|
11
11
|
import type { TODO_NODE_3286 } from './mongo_types';
|
|
12
12
|
import type { AggregateOptions } from './operations/aggregate';
|
|
13
13
|
import { CollectionsOperation } from './operations/collections';
|
|
14
|
-
import type { IndexInformationOptions } from './operations/common_functions';
|
|
15
14
|
import {
|
|
16
15
|
CreateCollectionOperation,
|
|
17
16
|
type CreateCollectionOptions
|
|
@@ -24,9 +23,11 @@ import {
|
|
|
24
23
|
} from './operations/drop';
|
|
25
24
|
import { executeOperation } from './operations/execute_operation';
|
|
26
25
|
import {
|
|
26
|
+
CreateIndexesOperation,
|
|
27
27
|
type CreateIndexesOptions,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
type IndexDescriptionCompact,
|
|
29
|
+
type IndexDescriptionInfo,
|
|
30
|
+
type IndexInformationOptions,
|
|
30
31
|
type IndexSpecification
|
|
31
32
|
} from './operations/indexes';
|
|
32
33
|
import type { CollectionInfo, ListCollectionsOptions } from './operations/list_collections';
|
|
@@ -67,7 +68,8 @@ const DB_OPTIONS_ALLOW_LIST = [
|
|
|
67
68
|
'enableUtf8Validation',
|
|
68
69
|
'promoteValues',
|
|
69
70
|
'compression',
|
|
70
|
-
'retryWrites'
|
|
71
|
+
'retryWrites',
|
|
72
|
+
'timeoutMS'
|
|
71
73
|
];
|
|
72
74
|
|
|
73
75
|
/** @internal */
|
|
@@ -95,6 +97,8 @@ export interface DbOptions extends BSONSerializeOptions, WriteConcernOptions {
|
|
|
95
97
|
readConcern?: ReadConcern;
|
|
96
98
|
/** Should retry failed writes */
|
|
97
99
|
retryWrites?: boolean;
|
|
100
|
+
/** @internal TODO(NODE-5688): make this public */
|
|
101
|
+
timeoutMS?: number;
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
/**
|
|
@@ -231,7 +235,7 @@ export class Db {
|
|
|
231
235
|
name: string,
|
|
232
236
|
options?: CreateCollectionOptions
|
|
233
237
|
): Promise<Collection<TSchema>> {
|
|
234
|
-
return executeOperation(
|
|
238
|
+
return await executeOperation(
|
|
235
239
|
this.client,
|
|
236
240
|
new CreateCollectionOperation(this, name, resolveOptions(this, options)) as TODO_NODE_3286
|
|
237
241
|
);
|
|
@@ -264,7 +268,7 @@ export class Db {
|
|
|
264
268
|
*/
|
|
265
269
|
async command(command: Document, options?: RunCommandOptions): Promise<Document> {
|
|
266
270
|
// Intentionally, we do not inherit options from parent for this operation.
|
|
267
|
-
return executeOperation(
|
|
271
|
+
return await executeOperation(
|
|
268
272
|
this.client,
|
|
269
273
|
new RunCommandOperation(this, command, {
|
|
270
274
|
...resolveBSONOptions(options),
|
|
@@ -321,7 +325,10 @@ export class Db {
|
|
|
321
325
|
* @param options - Optional settings for the command
|
|
322
326
|
*/
|
|
323
327
|
async stats(options?: DbStatsOptions): Promise<Document> {
|
|
324
|
-
return executeOperation(
|
|
328
|
+
return await executeOperation(
|
|
329
|
+
this.client,
|
|
330
|
+
new DbStatsOperation(this, resolveOptions(this, options))
|
|
331
|
+
);
|
|
325
332
|
}
|
|
326
333
|
|
|
327
334
|
/**
|
|
@@ -367,7 +374,7 @@ export class Db {
|
|
|
367
374
|
options?: RenameOptions
|
|
368
375
|
): Promise<Collection<TSchema>> {
|
|
369
376
|
// Intentionally, we do not inherit options from parent for this operation.
|
|
370
|
-
return executeOperation(
|
|
377
|
+
return await executeOperation(
|
|
371
378
|
this.client,
|
|
372
379
|
new RenameOperation(
|
|
373
380
|
this.collection<TSchema>(fromCollection) as TODO_NODE_3286,
|
|
@@ -384,7 +391,7 @@ export class Db {
|
|
|
384
391
|
* @param options - Optional settings for the command
|
|
385
392
|
*/
|
|
386
393
|
async dropCollection(name: string, options?: DropCollectionOptions): Promise<boolean> {
|
|
387
|
-
return executeOperation(
|
|
394
|
+
return await executeOperation(
|
|
388
395
|
this.client,
|
|
389
396
|
new DropCollectionOperation(this, name, resolveOptions(this, options))
|
|
390
397
|
);
|
|
@@ -396,7 +403,7 @@ export class Db {
|
|
|
396
403
|
* @param options - Optional settings for the command
|
|
397
404
|
*/
|
|
398
405
|
async dropDatabase(options?: DropDatabaseOptions): Promise<boolean> {
|
|
399
|
-
return executeOperation(
|
|
406
|
+
return await executeOperation(
|
|
400
407
|
this.client,
|
|
401
408
|
new DropDatabaseOperation(this, resolveOptions(this, options))
|
|
402
409
|
);
|
|
@@ -408,7 +415,7 @@ export class Db {
|
|
|
408
415
|
* @param options - Optional settings for the command
|
|
409
416
|
*/
|
|
410
417
|
async collections(options?: ListCollectionsOptions): Promise<Collection[]> {
|
|
411
|
-
return executeOperation(
|
|
418
|
+
return await executeOperation(
|
|
412
419
|
this.client,
|
|
413
420
|
new CollectionsOperation(this, resolveOptions(this, options))
|
|
414
421
|
);
|
|
@@ -426,10 +433,11 @@ export class Db {
|
|
|
426
433
|
indexSpec: IndexSpecification,
|
|
427
434
|
options?: CreateIndexesOptions
|
|
428
435
|
): Promise<string> {
|
|
429
|
-
|
|
436
|
+
const indexes = await executeOperation(
|
|
430
437
|
this.client,
|
|
431
|
-
|
|
438
|
+
CreateIndexesOperation.fromIndexSpecification(this, name, indexSpec, options)
|
|
432
439
|
);
|
|
440
|
+
return indexes[0];
|
|
433
441
|
}
|
|
434
442
|
|
|
435
443
|
/**
|
|
@@ -439,7 +447,7 @@ export class Db {
|
|
|
439
447
|
* @param options - Optional settings for the command
|
|
440
448
|
*/
|
|
441
449
|
async removeUser(username: string, options?: RemoveUserOptions): Promise<boolean> {
|
|
442
|
-
return executeOperation(
|
|
450
|
+
return await executeOperation(
|
|
443
451
|
this.client,
|
|
444
452
|
new RemoveUserOperation(this, username, resolveOptions(this, options))
|
|
445
453
|
);
|
|
@@ -455,7 +463,7 @@ export class Db {
|
|
|
455
463
|
level: ProfilingLevel,
|
|
456
464
|
options?: SetProfilingLevelOptions
|
|
457
465
|
): Promise<ProfilingLevel> {
|
|
458
|
-
return executeOperation(
|
|
466
|
+
return await executeOperation(
|
|
459
467
|
this.client,
|
|
460
468
|
new SetProfilingLevelOperation(this, level, resolveOptions(this, options))
|
|
461
469
|
);
|
|
@@ -467,7 +475,7 @@ export class Db {
|
|
|
467
475
|
* @param options - Optional settings for the command
|
|
468
476
|
*/
|
|
469
477
|
async profilingLevel(options?: ProfilingLevelOptions): Promise<string> {
|
|
470
|
-
return executeOperation(
|
|
478
|
+
return await executeOperation(
|
|
471
479
|
this.client,
|
|
472
480
|
new ProfilingLevelOperation(this, resolveOptions(this, options))
|
|
473
481
|
);
|
|
@@ -479,11 +487,24 @@ export class Db {
|
|
|
479
487
|
* @param name - The name of the collection.
|
|
480
488
|
* @param options - Optional settings for the command
|
|
481
489
|
*/
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
490
|
+
indexInformation(
|
|
491
|
+
name: string,
|
|
492
|
+
options: IndexInformationOptions & { full: true }
|
|
493
|
+
): Promise<IndexDescriptionInfo[]>;
|
|
494
|
+
indexInformation(
|
|
495
|
+
name: string,
|
|
496
|
+
options: IndexInformationOptions & { full?: false }
|
|
497
|
+
): Promise<IndexDescriptionCompact>;
|
|
498
|
+
indexInformation(
|
|
499
|
+
name: string,
|
|
500
|
+
options: IndexInformationOptions
|
|
501
|
+
): Promise<IndexDescriptionCompact | IndexDescriptionInfo[]>;
|
|
502
|
+
indexInformation(name: string): Promise<IndexDescriptionCompact>;
|
|
503
|
+
async indexInformation(
|
|
504
|
+
name: string,
|
|
505
|
+
options?: IndexInformationOptions
|
|
506
|
+
): Promise<IndexDescriptionCompact | IndexDescriptionInfo[]> {
|
|
507
|
+
return await this.collection(name).indexInformation(resolveOptions(this, options));
|
|
487
508
|
}
|
|
488
509
|
|
|
489
510
|
/**
|
package/src/deps.ts
CHANGED
|
@@ -18,21 +18,22 @@ function makeErrorModule(error: any) {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export
|
|
22
|
-
makeErrorModule(
|
|
23
|
-
new MongoMissingDependencyError(
|
|
24
|
-
'Optional module `kerberos` not found. Please install it to enable kerberos authentication'
|
|
25
|
-
)
|
|
26
|
-
);
|
|
21
|
+
export type Kerberos = typeof import('kerberos') | { kModuleError: MongoMissingDependencyError };
|
|
27
22
|
|
|
28
|
-
export function getKerberos():
|
|
23
|
+
export function getKerberos(): Kerberos {
|
|
24
|
+
let kerberos: Kerberos;
|
|
29
25
|
try {
|
|
30
26
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
kerberos = require('kerberos');
|
|
28
|
+
} catch (error) {
|
|
29
|
+
kerberos = makeErrorModule(
|
|
30
|
+
new MongoMissingDependencyError(
|
|
31
|
+
'Optional module `kerberos` not found. Please install it to enable kerberos authentication',
|
|
32
|
+
{ cause: error, dependencyName: 'kerberos' }
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
35
|
}
|
|
36
|
+
return kerberos;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export interface KerberosClient {
|
|
@@ -57,20 +58,22 @@ type ZStandardLib = {
|
|
|
57
58
|
decompress(buf: Buffer): Promise<Buffer>;
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
export
|
|
61
|
-
makeErrorModule(
|
|
62
|
-
new MongoMissingDependencyError(
|
|
63
|
-
'Optional module `@mongodb-js/zstd` not found. Please install it to enable zstd compression'
|
|
64
|
-
)
|
|
65
|
-
);
|
|
61
|
+
export type ZStandard = ZStandardLib | { kModuleError: MongoMissingDependencyError };
|
|
66
62
|
|
|
67
|
-
export function getZstdLibrary():
|
|
63
|
+
export function getZstdLibrary(): ZStandardLib | { kModuleError: MongoMissingDependencyError } {
|
|
64
|
+
let ZStandard: ZStandardLib | { kModuleError: MongoMissingDependencyError };
|
|
68
65
|
try {
|
|
69
66
|
ZStandard = require('@mongodb-js/zstd');
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
} catch (error) {
|
|
68
|
+
ZStandard = makeErrorModule(
|
|
69
|
+
new MongoMissingDependencyError(
|
|
70
|
+
'Optional module `@mongodb-js/zstd` not found. Please install it to enable zstd compression',
|
|
71
|
+
{ cause: error, dependencyName: 'zstd' }
|
|
72
|
+
)
|
|
73
|
+
);
|
|
73
74
|
}
|
|
75
|
+
|
|
76
|
+
return ZStandard;
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
/**
|
|
@@ -100,11 +103,12 @@ export function getAwsCredentialProvider():
|
|
|
100
103
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
101
104
|
const credentialProvider = require('@aws-sdk/credential-providers');
|
|
102
105
|
return credentialProvider;
|
|
103
|
-
} catch {
|
|
106
|
+
} catch (error) {
|
|
104
107
|
return makeErrorModule(
|
|
105
108
|
new MongoMissingDependencyError(
|
|
106
109
|
'Optional module `@aws-sdk/credential-providers` not found.' +
|
|
107
|
-
' Please install it to enable getting aws credentials via the official sdk.'
|
|
110
|
+
' Please install it to enable getting aws credentials via the official sdk.',
|
|
111
|
+
{ cause: error, dependencyName: '@aws-sdk/credential-providers' }
|
|
108
112
|
)
|
|
109
113
|
);
|
|
110
114
|
}
|
|
@@ -120,11 +124,12 @@ export function getGcpMetadata(): GcpMetadata {
|
|
|
120
124
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
121
125
|
const credentialProvider = require('gcp-metadata');
|
|
122
126
|
return credentialProvider;
|
|
123
|
-
} catch {
|
|
127
|
+
} catch (error) {
|
|
124
128
|
return makeErrorModule(
|
|
125
129
|
new MongoMissingDependencyError(
|
|
126
130
|
'Optional module `gcp-metadata` not found.' +
|
|
127
|
-
' Please install it to enable getting gcp credentials via the official sdk.'
|
|
131
|
+
' Please install it to enable getting gcp credentials via the official sdk.',
|
|
132
|
+
{ cause: error, dependencyName: 'gcp-metadata' }
|
|
128
133
|
)
|
|
129
134
|
);
|
|
130
135
|
}
|
|
@@ -150,10 +155,10 @@ export function getSnappy(): SnappyLib | { kModuleError: MongoMissingDependencyE
|
|
|
150
155
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
151
156
|
const value = require('snappy');
|
|
152
157
|
return value;
|
|
153
|
-
} catch (
|
|
158
|
+
} catch (error) {
|
|
154
159
|
const kModuleError = new MongoMissingDependencyError(
|
|
155
160
|
'Optional module `snappy` not found. Please install it to enable snappy compression',
|
|
156
|
-
{ cause }
|
|
161
|
+
{ cause: error, dependencyName: 'snappy' }
|
|
157
162
|
);
|
|
158
163
|
return { kModuleError };
|
|
159
164
|
}
|
|
@@ -184,10 +189,10 @@ export function getSocks(): SocksLib | { kModuleError: MongoMissingDependencyErr
|
|
|
184
189
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
185
190
|
const value = require('socks');
|
|
186
191
|
return value;
|
|
187
|
-
} catch (
|
|
192
|
+
} catch (error) {
|
|
188
193
|
const kModuleError = new MongoMissingDependencyError(
|
|
189
194
|
'Optional module `socks` not found. Please install it to connections over a SOCKS5 proxy',
|
|
190
|
-
{ cause }
|
|
195
|
+
{ cause: error, dependencyName: 'socks' }
|
|
191
196
|
);
|
|
192
197
|
return { kModuleError };
|
|
193
198
|
}
|
|
@@ -234,16 +239,23 @@ interface AWS4 {
|
|
|
234
239
|
};
|
|
235
240
|
}
|
|
236
241
|
|
|
237
|
-
export
|
|
238
|
-
new MongoMissingDependencyError(
|
|
239
|
-
'Optional module `aws4` not found. Please install it to enable AWS authentication'
|
|
240
|
-
)
|
|
241
|
-
);
|
|
242
|
+
export const aws4: AWS4 | { kModuleError: MongoMissingDependencyError } = loadAws4();
|
|
242
243
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
function loadAws4() {
|
|
245
|
+
let aws4: AWS4 | { kModuleError: MongoMissingDependencyError };
|
|
246
|
+
try {
|
|
247
|
+
aws4 = require('aws4');
|
|
248
|
+
} catch (error) {
|
|
249
|
+
aws4 = makeErrorModule(
|
|
250
|
+
new MongoMissingDependencyError(
|
|
251
|
+
'Optional module `aws4` not found. Please install it to enable AWS authentication',
|
|
252
|
+
{ cause: error, dependencyName: 'aws4' }
|
|
253
|
+
)
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return aws4;
|
|
258
|
+
}
|
|
247
259
|
|
|
248
260
|
/** A utility function to get the instance of mongodb-client-encryption, if it exists. */
|
|
249
261
|
export function getMongoDBClientEncryption():
|
|
@@ -256,10 +268,10 @@ export function getMongoDBClientEncryption():
|
|
|
256
268
|
// Cannot be moved to helper utility function, bundlers search and replace the actual require call
|
|
257
269
|
// in a way that makes this line throw at bundle time, not runtime, catching here will make bundling succeed
|
|
258
270
|
mongodbClientEncryption = require('mongodb-client-encryption');
|
|
259
|
-
} catch (
|
|
271
|
+
} catch (error) {
|
|
260
272
|
const kModuleError = new MongoMissingDependencyError(
|
|
261
273
|
'Optional module `mongodb-client-encryption` not found. Please install it to use auto encryption or ClientEncryption.',
|
|
262
|
-
{ cause }
|
|
274
|
+
{ cause: error, dependencyName: 'mongodb-client-encryption' }
|
|
263
275
|
);
|
|
264
276
|
return { kModuleError };
|
|
265
277
|
}
|
package/src/encrypter.ts
CHANGED
|
@@ -108,13 +108,18 @@ export class Encrypter {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
async close(client: MongoClient, force: boolean): Promise<void> {
|
|
111
|
-
|
|
111
|
+
let error;
|
|
112
|
+
try {
|
|
113
|
+
await this.autoEncrypter.teardown(force);
|
|
114
|
+
} catch (autoEncrypterError) {
|
|
115
|
+
error = autoEncrypterError;
|
|
116
|
+
}
|
|
112
117
|
const internalClient = this[kInternalClient];
|
|
113
118
|
if (internalClient != null && client !== internalClient) {
|
|
114
|
-
return internalClient.close(force);
|
|
119
|
+
return await internalClient.close(force);
|
|
115
120
|
}
|
|
116
|
-
if (
|
|
117
|
-
throw
|
|
121
|
+
if (error != null) {
|
|
122
|
+
throw error;
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
125
|
|
|
@@ -123,7 +128,11 @@ export class Encrypter {
|
|
|
123
128
|
if ('kModuleError' in mongodbClientEncryption) {
|
|
124
129
|
throw new MongoMissingDependencyError(
|
|
125
130
|
'Auto-encryption requested, but the module is not installed. ' +
|
|
126
|
-
'Please add `mongodb-client-encryption` as a dependency of your project'
|
|
131
|
+
'Please add `mongodb-client-encryption` as a dependency of your project',
|
|
132
|
+
{
|
|
133
|
+
cause: mongodbClientEncryption['kModuleError'],
|
|
134
|
+
dependencyName: 'mongodb-client-encryption'
|
|
135
|
+
}
|
|
127
136
|
);
|
|
128
137
|
}
|
|
129
138
|
}
|
package/src/error.ts
CHANGED
|
@@ -520,8 +520,8 @@ export class MongoAWSError extends MongoRuntimeError {
|
|
|
520
520
|
*
|
|
521
521
|
* @public
|
|
522
522
|
**/
|
|
523
|
-
constructor(message: string) {
|
|
524
|
-
super(message);
|
|
523
|
+
constructor(message: string, options?: { cause?: Error }) {
|
|
524
|
+
super(message, options);
|
|
525
525
|
}
|
|
526
526
|
|
|
527
527
|
override get name(): string {
|
|
@@ -1008,6 +1008,11 @@ export class MongoMissingCredentialsError extends MongoAPIError {
|
|
|
1008
1008
|
* @category Error
|
|
1009
1009
|
*/
|
|
1010
1010
|
export class MongoMissingDependencyError extends MongoAPIError {
|
|
1011
|
+
dependencyName: string;
|
|
1012
|
+
|
|
1013
|
+
/** @remarks This property is assigned in the `Error` constructor. */
|
|
1014
|
+
declare cause: Error;
|
|
1015
|
+
|
|
1011
1016
|
/**
|
|
1012
1017
|
* **Do not use this constructor!**
|
|
1013
1018
|
*
|
|
@@ -1019,8 +1024,9 @@ export class MongoMissingDependencyError extends MongoAPIError {
|
|
|
1019
1024
|
*
|
|
1020
1025
|
* @public
|
|
1021
1026
|
**/
|
|
1022
|
-
constructor(message: string, options: { cause
|
|
1027
|
+
constructor(message: string, options: { cause: Error; dependencyName: string }) {
|
|
1023
1028
|
super(message, options);
|
|
1029
|
+
this.dependencyName = options.dependencyName;
|
|
1024
1030
|
}
|
|
1025
1031
|
|
|
1026
1032
|
override get name(): string {
|
package/src/gridfs/download.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface GridFSBucketReadStreamOptions {
|
|
|
28
28
|
* to be returned by the stream. `end` is non-inclusive
|
|
29
29
|
*/
|
|
30
30
|
end?: number;
|
|
31
|
+
/** @internal TODO(NODE-5688): make this public */
|
|
32
|
+
timeoutMS?: number;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/** @public */
|
|
@@ -183,24 +185,13 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
183
185
|
if (!stream.s.cursor) return;
|
|
184
186
|
if (!stream.s.file) return;
|
|
185
187
|
|
|
186
|
-
const handleReadResult = ({
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}: { error: Error; doc: null } | { error: null; doc: any }) => {
|
|
190
|
-
if (stream.destroyed) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (error) {
|
|
194
|
-
stream.destroy(error);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
188
|
+
const handleReadResult = (doc: Document | null) => {
|
|
189
|
+
if (stream.destroyed) return;
|
|
190
|
+
|
|
197
191
|
if (!doc) {
|
|
198
192
|
stream.push(null);
|
|
199
|
-
|
|
200
|
-
stream.s.cursor?.close().then(
|
|
201
|
-
() => null,
|
|
202
|
-
error => stream.destroy(error)
|
|
203
|
-
);
|
|
193
|
+
// eslint-disable-next-line github/no-then
|
|
194
|
+
stream.s.cursor?.close().then(undefined, error => stream.destroy(error));
|
|
204
195
|
return;
|
|
205
196
|
}
|
|
206
197
|
|
|
@@ -271,10 +262,11 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
271
262
|
return;
|
|
272
263
|
};
|
|
273
264
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
265
|
+
// eslint-disable-next-line github/no-then
|
|
266
|
+
stream.s.cursor.next().then(handleReadResult, error => {
|
|
267
|
+
if (stream.destroyed) return;
|
|
268
|
+
stream.destroy(error);
|
|
269
|
+
});
|
|
278
270
|
}
|
|
279
271
|
|
|
280
272
|
function init(stream: GridFSBucketReadStream): void {
|
|
@@ -289,13 +281,8 @@ function init(stream: GridFSBucketReadStream): void {
|
|
|
289
281
|
findOneOptions.skip = stream.s.options.skip;
|
|
290
282
|
}
|
|
291
283
|
|
|
292
|
-
const handleReadResult = ({
|
|
293
|
-
|
|
294
|
-
doc
|
|
295
|
-
}: { error: Error; doc: null } | { error: null; doc: any }) => {
|
|
296
|
-
if (error) {
|
|
297
|
-
return stream.destroy(error);
|
|
298
|
-
}
|
|
284
|
+
const handleReadResult = (doc: Document | null) => {
|
|
285
|
+
if (stream.destroyed) return;
|
|
299
286
|
|
|
300
287
|
if (!doc) {
|
|
301
288
|
const identifier = stream.s.filter._id
|
|
@@ -359,10 +346,11 @@ function init(stream: GridFSBucketReadStream): void {
|
|
|
359
346
|
return;
|
|
360
347
|
};
|
|
361
348
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
349
|
+
// eslint-disable-next-line github/no-then
|
|
350
|
+
stream.s.files.findOne(stream.s.filter, findOneOptions).then(handleReadResult, error => {
|
|
351
|
+
if (stream.destroyed) return;
|
|
352
|
+
stream.destroy(error);
|
|
353
|
+
});
|
|
366
354
|
}
|
|
367
355
|
|
|
368
356
|
function waitForFile(stream: GridFSBucketReadStream, callback: Callback): void {
|
package/src/gridfs/index.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface GridFSBucketOptions extends WriteConcernOptions {
|
|
|
36
36
|
chunkSizeBytes?: number;
|
|
37
37
|
/** Read preference to be passed to read operations */
|
|
38
38
|
readPreference?: ReadPreference;
|
|
39
|
+
/** @internal TODO(NODE-5688): make this public */
|
|
40
|
+
timeoutMS?: number;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/** @internal */
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Document } from '../bson';
|
|
|
4
4
|
import { ObjectId } from '../bson';
|
|
5
5
|
import type { Collection } from '../collection';
|
|
6
6
|
import { MongoAPIError, MONGODB_ERROR_CODES, MongoError } from '../error';
|
|
7
|
-
import type
|
|
7
|
+
import { type Callback, squashError } from '../utils';
|
|
8
8
|
import type { WriteConcernOptions } from '../write_concern';
|
|
9
9
|
import { WriteConcern } from './../write_concern';
|
|
10
10
|
import type { GridFSFile } from './download';
|
|
@@ -36,6 +36,8 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
|
|
|
36
36
|
* @deprecated Will be removed in the next major version. Add an aliases field to the metadata document instead.
|
|
37
37
|
*/
|
|
38
38
|
aliases?: string[];
|
|
39
|
+
/** @internal TODO(NODE-5688): make this public */
|
|
40
|
+
timeoutMS?: number;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/**
|
|
@@ -133,13 +135,11 @@ export class GridFSBucketWriteStream extends Writable {
|
|
|
133
135
|
if (!this.bucket.s.calledOpenUploadStream) {
|
|
134
136
|
this.bucket.s.calledOpenUploadStream = true;
|
|
135
137
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
() => null
|
|
142
|
-
);
|
|
138
|
+
// eslint-disable-next-line github/no-then
|
|
139
|
+
checkIndexes(this).then(() => {
|
|
140
|
+
this.bucket.s.checkedIndexes = true;
|
|
141
|
+
this.bucket.emit('index');
|
|
142
|
+
}, squashError);
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -272,6 +272,7 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
|
|
|
272
272
|
return;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
// eslint-disable-next-line github/no-then
|
|
275
276
|
stream.files.insertOne(gridFSFile, { writeConcern: stream.writeConcern }).then(
|
|
276
277
|
() => {
|
|
277
278
|
stream.gridFSFile = gridFSFile;
|
|
@@ -395,6 +396,7 @@ function doWrite(
|
|
|
395
396
|
return;
|
|
396
397
|
}
|
|
397
398
|
|
|
399
|
+
// eslint-disable-next-line github/no-then
|
|
398
400
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
399
401
|
() => {
|
|
400
402
|
--stream.state.outstandingRequests;
|
|
@@ -435,6 +437,7 @@ function writeRemnant(stream: GridFSBucketWriteStream, callback: Callback): void
|
|
|
435
437
|
return;
|
|
436
438
|
}
|
|
437
439
|
|
|
440
|
+
// eslint-disable-next-line github/no-then
|
|
438
441
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
439
442
|
() => {
|
|
440
443
|
--stream.state.outstandingRequests;
|
package/src/index.ts
CHANGED
|
@@ -264,8 +264,7 @@ export type {
|
|
|
264
264
|
OpMsgResponse,
|
|
265
265
|
OpQueryOptions,
|
|
266
266
|
OpQueryRequest,
|
|
267
|
-
|
|
268
|
-
OpResponseOptions,
|
|
267
|
+
OpReply,
|
|
269
268
|
WriteProtocolMessageType
|
|
270
269
|
} from './cmap/commands';
|
|
271
270
|
export type { HandshakeDocument } from './cmap/connect';
|
|
@@ -290,6 +289,12 @@ export type { ClientMetadata, ClientMetadataOptions } from './cmap/handshake/cli
|
|
|
290
289
|
export type { ConnectionPoolMetrics } from './cmap/metrics';
|
|
291
290
|
export type { StreamDescription, StreamDescriptionOptions } from './cmap/stream_description';
|
|
292
291
|
export type { CompressorName } from './cmap/wire_protocol/compression';
|
|
292
|
+
export type { JSTypeOf, OnDemandDocument } from './cmap/wire_protocol/on_demand/document';
|
|
293
|
+
export type {
|
|
294
|
+
CursorResponse,
|
|
295
|
+
MongoDBResponse,
|
|
296
|
+
MongoDBResponseConstructor
|
|
297
|
+
} from './cmap/wire_protocol/responses';
|
|
293
298
|
export type { CollectionOptions, CollectionPrivate, ModifyResult } from './collection';
|
|
294
299
|
export type {
|
|
295
300
|
COMMAND_FAILED,
|
|
@@ -447,7 +452,6 @@ export type {
|
|
|
447
452
|
CommandOperationOptions,
|
|
448
453
|
OperationParent
|
|
449
454
|
} from './operations/command';
|
|
450
|
-
export type { IndexInformationOptions } from './operations/common_functions';
|
|
451
455
|
export type { CountOptions } from './operations/count';
|
|
452
456
|
export type { CountDocumentsOptions } from './operations/count_documents';
|
|
453
457
|
export type {
|
|
@@ -466,10 +470,13 @@ export type {
|
|
|
466
470
|
FindOneAndReplaceOptions,
|
|
467
471
|
FindOneAndUpdateOptions
|
|
468
472
|
} from './operations/find_and_modify';
|
|
473
|
+
export type { IndexInformationOptions } from './operations/indexes';
|
|
469
474
|
export type {
|
|
470
475
|
CreateIndexesOptions,
|
|
471
476
|
DropIndexesOptions,
|
|
472
477
|
IndexDescription,
|
|
478
|
+
IndexDescriptionCompact,
|
|
479
|
+
IndexDescriptionInfo,
|
|
473
480
|
IndexDirection,
|
|
474
481
|
IndexSpecification,
|
|
475
482
|
ListIndexesOptions
|
|
@@ -510,6 +517,7 @@ export type {
|
|
|
510
517
|
MonitorPrivate,
|
|
511
518
|
RTTPinger,
|
|
512
519
|
RTTPingerOptions,
|
|
520
|
+
RTTSampler,
|
|
513
521
|
ServerMonitoringMode
|
|
514
522
|
} from './sdam/monitor';
|
|
515
523
|
export type { Server, ServerEvents, ServerOptions, ServerPrivate } from './sdam/server';
|
|
@@ -543,6 +551,7 @@ export type {
|
|
|
543
551
|
WithTransactionCallback
|
|
544
552
|
} from './sessions';
|
|
545
553
|
export type { Sort, SortDirection, SortDirectionForCmd, SortForCmd } from './sort';
|
|
554
|
+
export type { Timeout } from './timeout';
|
|
546
555
|
export type { Transaction, TransactionOptions, TxnState } from './transactions';
|
|
547
556
|
export type {
|
|
548
557
|
BufferPool,
|
|
@@ -551,7 +560,6 @@ export type {
|
|
|
551
560
|
HostAddress,
|
|
552
561
|
List,
|
|
553
562
|
MongoDBCollectionNamespace,
|
|
554
|
-
MongoDBNamespace
|
|
555
|
-
TimeoutController
|
|
563
|
+
MongoDBNamespace
|
|
556
564
|
} from './utils';
|
|
557
565
|
export type { W, WriteConcernOptions, WriteConcernSettings } from './write_concern';
|