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.
Files changed (95) hide show
  1. package/lib/beta.d.ts +176 -108
  2. package/lib/bulk/common.js +5 -7
  3. package/lib/bulk/common.js.map +1 -1
  4. package/lib/change_stream.js +16 -26
  5. package/lib/change_stream.js.map +1 -1
  6. package/lib/client-side-encryption/auto_encrypter.js +4 -2
  7. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  8. package/lib/client-side-encryption/client_encryption.js +4 -4
  9. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  10. package/lib/client-side-encryption/state_machine.js +56 -30
  11. package/lib/client-side-encryption/state_machine.js.map +1 -1
  12. package/lib/cmap/auth/mongodb_aws.js +1 -1
  13. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  14. package/lib/cmap/auth/mongodb_oidc.js +1 -1
  15. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  16. package/lib/cmap/command_monitoring_events.js +9 -50
  17. package/lib/cmap/command_monitoring_events.js.map +1 -1
  18. package/lib/cmap/connection.js +28 -22
  19. package/lib/cmap/connection.js.map +1 -1
  20. package/lib/cmap/connection_pool.js +88 -117
  21. package/lib/cmap/connection_pool.js.map +1 -1
  22. package/lib/cmap/wire_protocol/on_data.js +6 -1
  23. package/lib/cmap/wire_protocol/on_data.js.map +1 -1
  24. package/lib/collection.js.map +1 -1
  25. package/lib/connection_string.js +68 -86
  26. package/lib/connection_string.js.map +1 -1
  27. package/lib/cursor/abstract_cursor.js +47 -18
  28. package/lib/cursor/abstract_cursor.js.map +1 -1
  29. package/lib/cursor/aggregation_cursor.js +2 -1
  30. package/lib/cursor/aggregation_cursor.js.map +1 -1
  31. package/lib/cursor/find_cursor.js +2 -1
  32. package/lib/cursor/find_cursor.js.map +1 -1
  33. package/lib/cursor/list_collections_cursor.js +2 -1
  34. package/lib/cursor/list_collections_cursor.js.map +1 -1
  35. package/lib/db.js +2 -1
  36. package/lib/db.js.map +1 -1
  37. package/lib/encrypter.js +5 -9
  38. package/lib/encrypter.js.map +1 -1
  39. package/lib/error.js +10 -18
  40. package/lib/error.js.map +1 -1
  41. package/lib/index.js +5 -2
  42. package/lib/index.js.map +1 -1
  43. package/lib/mongo_client.js +46 -26
  44. package/lib/mongo_client.js.map +1 -1
  45. package/lib/mongo_logger.js +102 -3
  46. package/lib/mongo_logger.js.map +1 -1
  47. package/lib/operations/execute_operation.js +9 -5
  48. package/lib/operations/execute_operation.js.map +1 -1
  49. package/lib/operations/list_collections.js.map +1 -1
  50. package/lib/operations/operation.js +4 -5
  51. package/lib/operations/operation.js.map +1 -1
  52. package/lib/sdam/monitor.js +25 -31
  53. package/lib/sdam/monitor.js.map +1 -1
  54. package/lib/sdam/server.js +27 -17
  55. package/lib/sdam/server.js.map +1 -1
  56. package/lib/sdam/topology.js +20 -19
  57. package/lib/sdam/topology.js.map +1 -1
  58. package/lib/sessions.js +24 -48
  59. package/lib/sessions.js.map +1 -1
  60. package/lib/utils.js +64 -44
  61. package/lib/utils.js.map +1 -1
  62. package/mongodb.d.ts +176 -108
  63. package/package.json +2 -2
  64. package/src/bulk/common.ts +6 -9
  65. package/src/change_stream.ts +21 -33
  66. package/src/client-side-encryption/auto_encrypter.ts +12 -8
  67. package/src/client-side-encryption/client_encryption.ts +6 -4
  68. package/src/client-side-encryption/state_machine.ts +80 -36
  69. package/src/cmap/auth/mongodb_aws.ts +1 -1
  70. package/src/cmap/auth/mongodb_oidc.ts +1 -1
  71. package/src/cmap/command_monitoring_events.ts +10 -55
  72. package/src/cmap/connection.ts +37 -29
  73. package/src/cmap/connection_pool.ts +121 -145
  74. package/src/cmap/wire_protocol/on_data.ts +9 -2
  75. package/src/collection.ts +15 -8
  76. package/src/connection_string.ts +74 -99
  77. package/src/cursor/abstract_cursor.ts +71 -23
  78. package/src/cursor/aggregation_cursor.ts +5 -3
  79. package/src/cursor/find_cursor.ts +5 -3
  80. package/src/cursor/list_collections_cursor.ts +5 -3
  81. package/src/db.ts +11 -7
  82. package/src/encrypter.ts +6 -11
  83. package/src/error.ts +11 -23
  84. package/src/index.ts +3 -3
  85. package/src/mongo_client.ts +78 -47
  86. package/src/mongo_logger.ts +158 -11
  87. package/src/mongo_types.ts +38 -0
  88. package/src/operations/execute_operation.ts +11 -6
  89. package/src/operations/list_collections.ts +4 -1
  90. package/src/operations/operation.ts +8 -9
  91. package/src/sdam/monitor.ts +30 -38
  92. package/src/sdam/server.ts +33 -20
  93. package/src/sdam/topology.ts +29 -26
  94. package/src/sessions.ts +37 -58
  95. package/src/utils.ts +79 -43
@@ -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({ timeoutContext: options.timeoutContext })) {
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
- if (timeout) {
707
- try {
708
- return await Promise.race([drainEvent, timeout]);
709
- } catch (error) {
710
- let err = error;
711
- if (TimeoutError.is(error)) {
712
- err = new MongoOperationTimeoutError('Timed out at socket write');
713
- this.cleanup(err);
714
- }
715
- throw error;
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(options: {
733
- timeoutContext?: TimeoutContext;
734
- }): AsyncGenerator<OpMsgResponse | OpReply> {
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 error = new MongoOperationTimeoutError(
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(error);
755
- throw error;
760
+ this.onError(timeoutError);
761
+ throw timeoutError;
762
+ } else if (readError === options.signal?.reason) {
763
+ this.onError(readError);
756
764
  }
757
- throw err;
765
+ throw readError;
758
766
  } finally {
759
767
  this.dataEvents = null;
760
768
  this.messageStream.pause();