mongodb 6.12.0 → 6.13.0-dev.20250201.sha.35c703e3
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 +176 -108
- package/lib/bulk/common.js +5 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +16 -26
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/auto_encrypter.js +4 -2
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
- package/lib/client-side-encryption/client_encryption.js +4 -4
- package/lib/client-side-encryption/client_encryption.js.map +1 -1
- package/lib/client-side-encryption/state_machine.js +56 -30
- package/lib/client-side-encryption/state_machine.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +1 -1
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc.js +1 -1
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +9 -50
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/connection.js +28 -22
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +88 -117
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/wire_protocol/on_data.js +6 -1
- package/lib/cmap/wire_protocol/on_data.js.map +1 -1
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +68 -86
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +47 -18
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +2 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +2 -1
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/cursor/list_collections_cursor.js +2 -1
- package/lib/cursor/list_collections_cursor.js.map +1 -1
- package/lib/db.js +2 -1
- package/lib/db.js.map +1 -1
- package/lib/encrypter.js +5 -9
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +10 -18
- package/lib/error.js.map +1 -1
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +46 -26
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +102 -3
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/execute_operation.js +9 -5
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/operation.js +4 -5
- package/lib/operations/operation.js.map +1 -1
- package/lib/sdam/monitor.js +25 -31
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +27 -17
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/topology.js +20 -19
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +24 -48
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +64 -44
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +176 -108
- package/package.json +2 -2
- package/src/bulk/common.ts +6 -9
- package/src/change_stream.ts +21 -33
- package/src/client-side-encryption/auto_encrypter.ts +12 -8
- package/src/client-side-encryption/client_encryption.ts +6 -4
- package/src/client-side-encryption/state_machine.ts +80 -36
- package/src/cmap/auth/mongodb_aws.ts +1 -1
- package/src/cmap/auth/mongodb_oidc.ts +1 -1
- package/src/cmap/command_monitoring_events.ts +10 -55
- package/src/cmap/connection.ts +37 -29
- package/src/cmap/connection_pool.ts +121 -145
- package/src/cmap/wire_protocol/on_data.ts +9 -2
- package/src/collection.ts +15 -8
- package/src/connection_string.ts +74 -99
- package/src/cursor/abstract_cursor.ts +71 -23
- package/src/cursor/aggregation_cursor.ts +5 -3
- package/src/cursor/find_cursor.ts +5 -3
- package/src/cursor/list_collections_cursor.ts +5 -3
- package/src/db.ts +11 -7
- package/src/encrypter.ts +6 -11
- package/src/error.ts +11 -23
- package/src/index.ts +3 -3
- package/src/mongo_client.ts +78 -47
- package/src/mongo_logger.ts +158 -11
- package/src/mongo_types.ts +38 -0
- package/src/operations/execute_operation.ts +11 -6
- package/src/operations/list_collections.ts +4 -1
- package/src/operations/operation.ts +8 -9
- package/src/sdam/monitor.ts +30 -38
- package/src/sdam/server.ts +33 -20
- package/src/sdam/topology.ts +29 -26
- package/src/sessions.ts +37 -58
- package/src/utils.ts +79 -43
package/src/utils.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
MongoRuntimeError
|
|
28
28
|
} from './error';
|
|
29
29
|
import type { MongoClient } from './mongo_client';
|
|
30
|
+
import { type Abortable } from './mongo_types';
|
|
30
31
|
import type { CommandOperationOptions, OperationParent } from './operations/command';
|
|
31
32
|
import type { Hint, OperationOptions } from './operations/operation';
|
|
32
33
|
import { ReadConcern } from './read_concern';
|
|
@@ -620,43 +621,6 @@ export function isRecord(
|
|
|
620
621
|
return true;
|
|
621
622
|
}
|
|
622
623
|
|
|
623
|
-
/**
|
|
624
|
-
* Make a deep copy of an object
|
|
625
|
-
*
|
|
626
|
-
* NOTE: This is not meant to be the perfect implementation of a deep copy,
|
|
627
|
-
* but instead something that is good enough for the purposes of
|
|
628
|
-
* command monitoring.
|
|
629
|
-
*/
|
|
630
|
-
export function deepCopy<T>(value: T): T {
|
|
631
|
-
if (value == null) {
|
|
632
|
-
return value;
|
|
633
|
-
} else if (Array.isArray(value)) {
|
|
634
|
-
return value.map(item => deepCopy(item)) as unknown as T;
|
|
635
|
-
} else if (isRecord(value)) {
|
|
636
|
-
const res = {} as any;
|
|
637
|
-
for (const key in value) {
|
|
638
|
-
res[key] = deepCopy(value[key]);
|
|
639
|
-
}
|
|
640
|
-
return res;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
const ctor = (value as any).constructor;
|
|
644
|
-
if (ctor) {
|
|
645
|
-
switch (ctor.name.toLowerCase()) {
|
|
646
|
-
case 'date':
|
|
647
|
-
return new ctor(Number(value));
|
|
648
|
-
case 'map':
|
|
649
|
-
return new Map(value as any) as unknown as T;
|
|
650
|
-
case 'set':
|
|
651
|
-
return new Set(value as any) as unknown as T;
|
|
652
|
-
case 'buffer':
|
|
653
|
-
return Buffer.from(value as unknown as Buffer) as unknown as T;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
return value;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
624
|
type ListNode<T> = {
|
|
661
625
|
value: T;
|
|
662
626
|
next: ListNode<T> | HeadNode<T>;
|
|
@@ -1349,19 +1313,24 @@ export const randomBytes = promisify(crypto.randomBytes);
|
|
|
1349
1313
|
* @param ee - An event emitter that may emit `ev`
|
|
1350
1314
|
* @param name - An event name to wait for
|
|
1351
1315
|
*/
|
|
1352
|
-
export async function once<T>(ee: EventEmitter, name: string): Promise<T> {
|
|
1316
|
+
export async function once<T>(ee: EventEmitter, name: string, options?: Abortable): Promise<T> {
|
|
1317
|
+
options?.signal?.throwIfAborted();
|
|
1318
|
+
|
|
1353
1319
|
const { promise, resolve, reject } = promiseWithResolvers<T>();
|
|
1354
1320
|
const onEvent = (data: T) => resolve(data);
|
|
1355
1321
|
const onError = (error: Error) => reject(error);
|
|
1322
|
+
const abortListener = addAbortListener(options?.signal, function () {
|
|
1323
|
+
reject(this.reason);
|
|
1324
|
+
});
|
|
1356
1325
|
|
|
1357
1326
|
ee.once(name, onEvent).once('error', onError);
|
|
1327
|
+
|
|
1358
1328
|
try {
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
return res;
|
|
1362
|
-
} catch (error) {
|
|
1329
|
+
return await promise;
|
|
1330
|
+
} finally {
|
|
1363
1331
|
ee.off(name, onEvent);
|
|
1364
|
-
|
|
1332
|
+
ee.off('error', onError);
|
|
1333
|
+
abortListener?.[kDispose]();
|
|
1365
1334
|
}
|
|
1366
1335
|
}
|
|
1367
1336
|
|
|
@@ -1468,3 +1437,70 @@ export function decorateDecryptionResult(
|
|
|
1468
1437
|
decorateDecryptionResult(decrypted[k], originalValue, false);
|
|
1469
1438
|
}
|
|
1470
1439
|
}
|
|
1440
|
+
|
|
1441
|
+
/** @internal */
|
|
1442
|
+
export const kDispose: unique symbol = (Symbol.dispose as any) ?? Symbol('dispose');
|
|
1443
|
+
|
|
1444
|
+
/** @internal */
|
|
1445
|
+
export interface Disposable {
|
|
1446
|
+
[kDispose](): void;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
/**
|
|
1450
|
+
* A utility that helps with writing listener code idiomatically
|
|
1451
|
+
*
|
|
1452
|
+
* @example
|
|
1453
|
+
* ```js
|
|
1454
|
+
* using listener = addAbortListener(signal, function () {
|
|
1455
|
+
* console.log('aborted', this.reason);
|
|
1456
|
+
* });
|
|
1457
|
+
* ```
|
|
1458
|
+
*
|
|
1459
|
+
* @param signal - if exists adds an abort listener
|
|
1460
|
+
* @param listener - the listener to be added to signal
|
|
1461
|
+
* @returns A disposable that will remove the abort listener
|
|
1462
|
+
*/
|
|
1463
|
+
export function addAbortListener(
|
|
1464
|
+
signal: AbortSignal | undefined | null,
|
|
1465
|
+
listener: (this: AbortSignal, event: Event) => void
|
|
1466
|
+
): Disposable | undefined {
|
|
1467
|
+
if (signal == null) return;
|
|
1468
|
+
signal.addEventListener('abort', listener, { once: true });
|
|
1469
|
+
return { [kDispose]: () => signal.removeEventListener('abort', listener) };
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* Takes a promise and races it with a promise wrapping the abort event of the optionally provided signal.
|
|
1474
|
+
* The given promise is _always_ ordered before the signal's abort promise.
|
|
1475
|
+
* When given an already rejected promise and an already aborted signal, the promise's rejection takes precedence.
|
|
1476
|
+
*
|
|
1477
|
+
* Any asynchronous processing in `promise` will continue even after the abort signal has fired,
|
|
1478
|
+
* but control will be returned to the caller
|
|
1479
|
+
*
|
|
1480
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race
|
|
1481
|
+
*
|
|
1482
|
+
* @param promise - A promise to discard if the signal aborts
|
|
1483
|
+
* @param options - An options object carrying an optional signal
|
|
1484
|
+
*/
|
|
1485
|
+
export async function abortable<T>(
|
|
1486
|
+
promise: Promise<T>,
|
|
1487
|
+
{ signal }: { signal?: AbortSignal }
|
|
1488
|
+
): Promise<T> {
|
|
1489
|
+
if (signal == null) {
|
|
1490
|
+
return await promise;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
const { promise: aborted, reject } = promiseWithResolvers<never>();
|
|
1494
|
+
|
|
1495
|
+
const abortListener = signal.aborted
|
|
1496
|
+
? reject(signal.reason)
|
|
1497
|
+
: addAbortListener(signal, function () {
|
|
1498
|
+
reject(this.reason);
|
|
1499
|
+
});
|
|
1500
|
+
|
|
1501
|
+
try {
|
|
1502
|
+
return await Promise.race([promise, aborted]);
|
|
1503
|
+
} finally {
|
|
1504
|
+
abortListener?.[kDispose]();
|
|
1505
|
+
}
|
|
1506
|
+
}
|