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/cmap/connection.ts
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
import type { ServerApi, SupportedNodeConnectionOptions } from '../mongo_client';
|
|
34
34
|
import { type MongoClientAuthProviders } from '../mongo_client_auth_providers';
|
|
35
35
|
import { MongoLoggableComponent, type MongoLogger, SeverityLevel } from '../mongo_logger';
|
|
36
|
-
import { type CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
36
|
+
import { type Abortable, type CancellationToken, TypedEventEmitter } from '../mongo_types';
|
|
37
37
|
import { ReadPreference, type ReadPreferenceLike } from '../read_preference';
|
|
38
38
|
import { ServerType } from '../sdam/common';
|
|
39
39
|
import { applySession, type ClientSession, updateSessionFromResponse } from '../sessions';
|
|
@@ -438,7 +438,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
438
438
|
|
|
439
439
|
private async *sendWire(
|
|
440
440
|
message: WriteProtocolMessageType,
|
|
441
|
-
options: CommandOptions,
|
|
441
|
+
options: CommandOptions & Abortable,
|
|
442
442
|
responseType?: MongoDBResponseConstructor
|
|
443
443
|
): AsyncGenerator<MongoDBResponse> {
|
|
444
444
|
this.throwIfAborted();
|
|
@@ -453,7 +453,8 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
453
453
|
await this.writeCommand(message, {
|
|
454
454
|
agreedCompressor: this.description.compressor ?? 'none',
|
|
455
455
|
zlibCompressionLevel: this.description.zlibCompressionLevel,
|
|
456
|
-
timeoutContext: options.timeoutContext
|
|
456
|
+
timeoutContext: options.timeoutContext,
|
|
457
|
+
signal: options.signal
|
|
457
458
|
});
|
|
458
459
|
|
|
459
460
|
if (options.noResponse || message.moreToCome) {
|
|
@@ -473,7 +474,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
473
474
|
);
|
|
474
475
|
}
|
|
475
476
|
|
|
476
|
-
for await (const response of this.readMany(
|
|
477
|
+
for await (const response of this.readMany(options)) {
|
|
477
478
|
this.socket.setTimeout(0);
|
|
478
479
|
const bson = response.parse();
|
|
479
480
|
|
|
@@ -492,9 +493,11 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
492
493
|
private async *sendCommand(
|
|
493
494
|
ns: MongoDBNamespace,
|
|
494
495
|
command: Document,
|
|
495
|
-
options: CommandOptions,
|
|
496
|
+
options: CommandOptions & Abortable,
|
|
496
497
|
responseType?: MongoDBResponseConstructor
|
|
497
498
|
) {
|
|
499
|
+
options?.signal?.throwIfAborted();
|
|
500
|
+
|
|
498
501
|
const message = this.prepareCommand(ns.db, command, options);
|
|
499
502
|
let started = 0;
|
|
500
503
|
if (this.shouldEmitAndLogCommand) {
|
|
@@ -610,10 +613,12 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
610
613
|
public async command(
|
|
611
614
|
ns: MongoDBNamespace,
|
|
612
615
|
command: Document,
|
|
613
|
-
options: CommandOptions = {},
|
|
616
|
+
options: CommandOptions & Abortable = {},
|
|
614
617
|
responseType?: MongoDBResponseConstructor
|
|
615
618
|
): Promise<Document> {
|
|
616
619
|
this.throwIfAborted();
|
|
620
|
+
options.signal?.throwIfAborted();
|
|
621
|
+
|
|
617
622
|
for await (const document of this.sendCommand(ns, command, options, responseType)) {
|
|
618
623
|
if (options.timeoutContext?.csotEnabled()) {
|
|
619
624
|
if (MongoDBResponse.is(document)) {
|
|
@@ -676,7 +681,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
676
681
|
agreedCompressor?: CompressorName;
|
|
677
682
|
zlibCompressionLevel?: number;
|
|
678
683
|
timeoutContext?: TimeoutContext;
|
|
679
|
-
}
|
|
684
|
+
} & Abortable
|
|
680
685
|
): Promise<void> {
|
|
681
686
|
const finalCommand =
|
|
682
687
|
options.agreedCompressor === 'none' || !OpCompressedRequest.canCompress(command)
|
|
@@ -701,23 +706,23 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
701
706
|
|
|
702
707
|
if (this.socket.write(buffer)) return;
|
|
703
708
|
|
|
704
|
-
const drainEvent = once<void>(this.socket, 'drain');
|
|
709
|
+
const drainEvent = once<void>(this.socket, 'drain', options);
|
|
705
710
|
const timeout = options?.timeoutContext?.timeoutForSocketWrite;
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
} finally {
|
|
717
|
-
timeout.clear();
|
|
711
|
+
const drained = timeout ? Promise.race([drainEvent, timeout]) : drainEvent;
|
|
712
|
+
try {
|
|
713
|
+
return await drained;
|
|
714
|
+
} catch (writeError) {
|
|
715
|
+
if (TimeoutError.is(writeError)) {
|
|
716
|
+
const timeoutError = new MongoOperationTimeoutError('Timed out at socket write');
|
|
717
|
+
this.onError(timeoutError);
|
|
718
|
+
throw timeoutError;
|
|
719
|
+
} else if (writeError === options.signal?.reason) {
|
|
720
|
+
this.onError(writeError);
|
|
718
721
|
}
|
|
722
|
+
throw writeError;
|
|
723
|
+
} finally {
|
|
724
|
+
timeout?.clear();
|
|
719
725
|
}
|
|
720
|
-
return await drainEvent;
|
|
721
726
|
}
|
|
722
727
|
|
|
723
728
|
/**
|
|
@@ -729,9 +734,11 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
729
734
|
*
|
|
730
735
|
* Note that `for-await` loops call `return` automatically when the loop is exited.
|
|
731
736
|
*/
|
|
732
|
-
private async *readMany(
|
|
733
|
-
|
|
734
|
-
|
|
737
|
+
private async *readMany(
|
|
738
|
+
options: {
|
|
739
|
+
timeoutContext?: TimeoutContext;
|
|
740
|
+
} & Abortable
|
|
741
|
+
): AsyncGenerator<OpMsgResponse | OpReply> {
|
|
735
742
|
try {
|
|
736
743
|
this.dataEvents = onData(this.messageStream, options);
|
|
737
744
|
this.messageStream.resume();
|
|
@@ -745,16 +752,17 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
|
|
|
745
752
|
}
|
|
746
753
|
}
|
|
747
754
|
} catch (readError) {
|
|
748
|
-
const err = readError;
|
|
749
755
|
if (TimeoutError.is(readError)) {
|
|
750
|
-
const
|
|
756
|
+
const timeoutError = new MongoOperationTimeoutError(
|
|
751
757
|
`Timed out during socket read (${readError.duration}ms)`
|
|
752
758
|
);
|
|
753
759
|
this.dataEvents = null;
|
|
754
|
-
this.onError(
|
|
755
|
-
throw
|
|
760
|
+
this.onError(timeoutError);
|
|
761
|
+
throw timeoutError;
|
|
762
|
+
} else if (readError === options.signal?.reason) {
|
|
763
|
+
this.onError(readError);
|
|
756
764
|
}
|
|
757
|
-
throw
|
|
765
|
+
throw readError;
|
|
758
766
|
} finally {
|
|
759
767
|
this.dataEvents = null;
|
|
760
768
|
this.messageStream.pause();
|