mongodb 4.6.0 → 4.7.0

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 (98) hide show
  1. package/lib/admin.js +5 -5
  2. package/lib/admin.js.map +1 -1
  3. package/lib/bulk/common.js +4 -4
  4. package/lib/bulk/common.js.map +1 -1
  5. package/lib/change_stream.js +37 -28
  6. package/lib/change_stream.js.map +1 -1
  7. package/lib/cmap/auth/scram.js +12 -1
  8. package/lib/cmap/auth/scram.js.map +1 -1
  9. package/lib/cmap/connection.js +9 -1
  10. package/lib/cmap/connection.js.map +1 -1
  11. package/lib/cmap/connection_pool.js +70 -57
  12. package/lib/cmap/connection_pool.js.map +1 -1
  13. package/lib/cmap/connection_pool_events.js.map +1 -1
  14. package/lib/cmap/message_stream.js +39 -6
  15. package/lib/cmap/message_stream.js.map +1 -1
  16. package/lib/cmap/wire_protocol/compression.js +18 -2
  17. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  18. package/lib/cmap/wire_protocol/constants.js +2 -2
  19. package/lib/cmap/wire_protocol/shared.js +3 -0
  20. package/lib/cmap/wire_protocol/shared.js.map +1 -1
  21. package/lib/collection.js +30 -30
  22. package/lib/collection.js.map +1 -1
  23. package/lib/connection_string.js +10 -0
  24. package/lib/connection_string.js.map +1 -1
  25. package/lib/cursor/abstract_cursor.js +16 -11
  26. package/lib/cursor/abstract_cursor.js.map +1 -1
  27. package/lib/cursor/aggregation_cursor.js +5 -5
  28. package/lib/cursor/aggregation_cursor.js.map +1 -1
  29. package/lib/cursor/find_cursor.js +6 -6
  30. package/lib/cursor/find_cursor.js.map +1 -1
  31. package/lib/db.js +14 -14
  32. package/lib/db.js.map +1 -1
  33. package/lib/deps.js +6 -1
  34. package/lib/deps.js.map +1 -1
  35. package/lib/encrypter.js +9 -2
  36. package/lib/encrypter.js.map +1 -1
  37. package/lib/mongo_client.js +11 -0
  38. package/lib/mongo_client.js.map +1 -1
  39. package/lib/operations/connect.js +1 -0
  40. package/lib/operations/connect.js.map +1 -1
  41. package/lib/operations/create_collection.js +8 -3
  42. package/lib/operations/create_collection.js.map +1 -1
  43. package/lib/operations/drop.js +1 -20
  44. package/lib/operations/drop.js.map +1 -1
  45. package/lib/operations/estimated_document_count.js +1 -20
  46. package/lib/operations/estimated_document_count.js.map +1 -1
  47. package/lib/operations/execute_operation.js +15 -9
  48. package/lib/operations/execute_operation.js.map +1 -1
  49. package/lib/operations/indexes.js +2 -2
  50. package/lib/operations/indexes.js.map +1 -1
  51. package/lib/operations/list_collections.js +2 -2
  52. package/lib/operations/list_collections.js.map +1 -1
  53. package/lib/sdam/monitor.js +10 -3
  54. package/lib/sdam/monitor.js.map +1 -1
  55. package/lib/sdam/srv_polling.js +2 -1
  56. package/lib/sdam/srv_polling.js.map +1 -1
  57. package/lib/sdam/topology.js +3 -2
  58. package/lib/sdam/topology.js.map +1 -1
  59. package/lib/sessions.js +29 -17
  60. package/lib/sessions.js.map +1 -1
  61. package/lib/utils.js +3 -2
  62. package/lib/utils.js.map +1 -1
  63. package/mongodb.d.ts +229 -37
  64. package/package.json +10 -9
  65. package/src/admin.ts +9 -5
  66. package/src/bulk/common.ts +4 -4
  67. package/src/change_stream.ts +250 -47
  68. package/src/cmap/auth/scram.ts +11 -1
  69. package/src/cmap/connection.ts +11 -0
  70. package/src/cmap/connection_pool.ts +90 -74
  71. package/src/cmap/connection_pool_events.ts +1 -1
  72. package/src/cmap/message_stream.ts +41 -7
  73. package/src/cmap/wire_protocol/compression.ts +27 -3
  74. package/src/cmap/wire_protocol/constants.ts +2 -2
  75. package/src/cmap/wire_protocol/shared.ts +5 -1
  76. package/src/collection.ts +38 -31
  77. package/src/connection_string.ts +10 -0
  78. package/src/cursor/abstract_cursor.ts +16 -13
  79. package/src/cursor/aggregation_cursor.ts +6 -6
  80. package/src/cursor/find_cursor.ts +7 -7
  81. package/src/db.ts +18 -14
  82. package/src/deps.ts +41 -12
  83. package/src/encrypter.ts +8 -2
  84. package/src/index.ts +9 -0
  85. package/src/mongo_client.ts +18 -1
  86. package/src/operations/connect.ts +1 -0
  87. package/src/operations/create_collection.ts +13 -3
  88. package/src/operations/drop.ts +1 -23
  89. package/src/operations/estimated_document_count.ts +2 -29
  90. package/src/operations/execute_operation.ts +25 -26
  91. package/src/operations/indexes.ts +3 -9
  92. package/src/operations/list_collections.ts +3 -3
  93. package/src/sdam/monitor.ts +10 -0
  94. package/src/sdam/srv_polling.ts +1 -0
  95. package/src/sdam/topology.ts +6 -2
  96. package/src/sessions.ts +31 -20
  97. package/src/transactions.ts +1 -1
  98. package/src/utils.ts +2 -1
@@ -1,7 +1,8 @@
1
1
  import Denque = require('denque');
2
2
  import type { Readable } from 'stream';
3
+ import { setTimeout } from 'timers';
3
4
 
4
- import type { Document, Long, Timestamp } from './bson';
5
+ import type { Binary, Document, Long, Timestamp } from './bson';
5
6
  import { Collection } from './collection';
6
7
  import { CHANGE, CLOSE, END, ERROR, INIT, MORE, RESPONSE, RESUME_TOKEN_CHANGED } from './constants';
7
8
  import {
@@ -50,16 +51,9 @@ const CHANGE_STREAM_OPTIONS = [
50
51
  'resumeAfter',
51
52
  'startAfter',
52
53
  'startAtOperationTime',
53
- 'fullDocument'
54
- ] as const;
55
-
56
- const CURSOR_OPTIONS = [
57
- 'batchSize',
58
- 'maxAwaitTimeMS',
59
- 'collation',
60
- 'readPreference',
61
- 'comment',
62
- ...CHANGE_STREAM_OPTIONS
54
+ 'fullDocument',
55
+ 'fullDocumentBeforeChange',
56
+ 'showExpandedEvents'
63
57
  ] as const;
64
58
 
65
59
  const CHANGE_DOMAIN_TYPES = {
@@ -83,7 +77,10 @@ const NO_RESUME_TOKEN_ERROR =
83
77
  const NO_CURSOR_ERROR = 'ChangeStream has no cursor';
84
78
  const CHANGESTREAM_CLOSED_ERROR = 'ChangeStream is closed';
85
79
 
86
- /** @public */
80
+ /**
81
+ * @public
82
+ * @deprecated Please use the ChangeStreamCursorOptions type instead.
83
+ */
87
84
  export interface ResumeOptions {
88
85
  startAtOperationTime?: Timestamp;
89
86
  batchSize?: number;
@@ -92,6 +89,7 @@ export interface ResumeOptions {
92
89
  readPreference?: ReadPreference;
93
90
  resumeAfter?: ResumeToken;
94
91
  startAfter?: ResumeToken;
92
+ fullDocument?: string;
95
93
  }
96
94
 
97
95
  /**
@@ -131,11 +129,35 @@ export type ChangeStreamAggregateRawResult<TChange> = {
131
129
  */
132
130
  export interface ChangeStreamOptions extends AggregateOptions {
133
131
  /**
134
- * Allowed values: 'updateLookup'. When set to 'updateLookup',
135
- * the change stream will include both a delta describing the changes to the document,
136
- * as well as a copy of the entire document that was changed from some time after the change occurred.
132
+ * Allowed values: 'updateLookup', 'whenAvailable', 'required'.
133
+ *
134
+ * When set to 'updateLookup', the change notification for partial updates
135
+ * will include both a delta describing the changes to the document as well
136
+ * as a copy of the entire document that was changed from some time after
137
+ * the change occurred.
138
+ *
139
+ * When set to 'whenAvailable', configures the change stream to return the
140
+ * post-image of the modified document for replace and update change events
141
+ * if the post-image for this event is available.
142
+ *
143
+ * When set to 'required', the same behavior as 'whenAvailable' except that
144
+ * an error is raised if the post-image is not available.
137
145
  */
138
146
  fullDocument?: string;
147
+
148
+ /**
149
+ * Allowed values: 'whenAvailable', 'required', 'off'.
150
+ *
151
+ * The default is to not send a value, which is equivalent to 'off'.
152
+ *
153
+ * When set to 'whenAvailable', configures the change stream to return the
154
+ * pre-image of the modified document for replace, update, and delete change
155
+ * events if it is available.
156
+ *
157
+ * When set to 'required', the same behavior as 'whenAvailable' except that
158
+ * an error is raised if the pre-image is not available.
159
+ */
160
+ fullDocumentBeforeChange?: string;
139
161
  /** The maximum amount of time for the server to wait on new documents to satisfy a change stream query. */
140
162
  maxAwaitTimeMS?: number;
141
163
  /**
@@ -155,6 +177,19 @@ export interface ChangeStreamOptions extends AggregateOptions {
155
177
  * @see https://docs.mongodb.com/manual/reference/command/aggregate
156
178
  */
157
179
  batchSize?: number;
180
+
181
+ /**
182
+ * When enabled, configures the change stream to include extra change events.
183
+ *
184
+ * - createIndexes
185
+ * - dropIndexes
186
+ * - modify
187
+ * - create
188
+ * - shardCollection
189
+ * - reshardCollection
190
+ * - refineCollectionShardKey
191
+ */
192
+ showExpandedEvents?: boolean;
158
193
  }
159
194
 
160
195
  /** @public */
@@ -204,13 +239,41 @@ export interface ChangeStreamDocumentCommon {
204
239
  lsid?: ServerSessionId;
205
240
  }
206
241
 
242
+ /** @public */
243
+ export interface ChangeStreamDocumentCollectionUUID {
244
+ /**
245
+ * The UUID (Binary subtype 4) of the collection that the operation was performed on.
246
+ *
247
+ * Only present when the `showExpandedEvents` flag is enabled.
248
+ *
249
+ * **NOTE:** collectionUUID will be converted to a NodeJS Buffer if the promoteBuffers
250
+ * flag is enabled.
251
+ *
252
+ * @since 6.1.0
253
+ */
254
+ collectionUUID: Binary;
255
+ }
256
+
257
+ /** @public */
258
+ export interface ChangeStreamDocumentOperationDescription {
259
+ /**
260
+ * An description of the operation.
261
+ *
262
+ * Only present when the `showExpandedEvents` flag is enabled.
263
+ *
264
+ * @since 6.1.0
265
+ */
266
+ operationDescription?: Document;
267
+ }
268
+
207
269
  /**
208
270
  * @public
209
271
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#insert-event
210
272
  */
211
273
  export interface ChangeStreamInsertDocument<TSchema extends Document = Document>
212
274
  extends ChangeStreamDocumentCommon,
213
- ChangeStreamDocumentKey<TSchema> {
275
+ ChangeStreamDocumentKey<TSchema>,
276
+ ChangeStreamDocumentCollectionUUID {
214
277
  /** Describes the type of operation represented in this change notification */
215
278
  operationType: 'insert';
216
279
  /** This key will contain the document being inserted */
@@ -225,20 +288,29 @@ export interface ChangeStreamInsertDocument<TSchema extends Document = Document>
225
288
  */
226
289
  export interface ChangeStreamUpdateDocument<TSchema extends Document = Document>
227
290
  extends ChangeStreamDocumentCommon,
228
- ChangeStreamDocumentKey<TSchema> {
291
+ ChangeStreamDocumentKey<TSchema>,
292
+ ChangeStreamDocumentCollectionUUID {
229
293
  /** Describes the type of operation represented in this change notification */
230
294
  operationType: 'update';
231
295
  /**
232
296
  * This is only set if `fullDocument` is set to `'updateLookup'`
233
- * The fullDocument document represents the most current majority-committed version of the updated document.
234
- * The fullDocument document may vary from the document at the time of the update operation depending on the
235
- * number of interleaving majority-committed operations that occur between the update operation and the document lookup.
297
+ * Contains the point-in-time post-image of the modified document if the
298
+ * post-image is available and either 'required' or 'whenAvailable' was
299
+ * specified for the 'fullDocument' option when creating the change stream.
236
300
  */
237
301
  fullDocument?: TSchema;
238
302
  /** Contains a description of updated and removed fields in this operation */
239
303
  updateDescription: UpdateDescription<TSchema>;
240
304
  /** Namespace the update event occured on */
241
305
  ns: ChangeStreamNameSpace;
306
+ /**
307
+ * Contains the pre-image of the modified or deleted document if the
308
+ * pre-image is available for the change event and either 'required' or
309
+ * 'whenAvailable' was specified for the 'fullDocumentBeforeChange' option
310
+ * when creating the change stream. If 'whenAvailable' was specified but the
311
+ * pre-image is unavailable, this will be explicitly set to null.
312
+ */
313
+ fullDocumentBeforeChange?: TSchema;
242
314
  }
243
315
 
244
316
  /**
@@ -254,6 +326,14 @@ export interface ChangeStreamReplaceDocument<TSchema extends Document = Document
254
326
  fullDocument: TSchema;
255
327
  /** Namespace the replace event occured on */
256
328
  ns: ChangeStreamNameSpace;
329
+ /**
330
+ * Contains the pre-image of the modified or deleted document if the
331
+ * pre-image is available for the change event and either 'required' or
332
+ * 'whenAvailable' was specified for the 'fullDocumentBeforeChange' option
333
+ * when creating the change stream. If 'whenAvailable' was specified but the
334
+ * pre-image is unavailable, this will be explicitly set to null.
335
+ */
336
+ fullDocumentBeforeChange?: TSchema;
257
337
  }
258
338
 
259
339
  /**
@@ -262,18 +342,29 @@ export interface ChangeStreamReplaceDocument<TSchema extends Document = Document
262
342
  */
263
343
  export interface ChangeStreamDeleteDocument<TSchema extends Document = Document>
264
344
  extends ChangeStreamDocumentCommon,
265
- ChangeStreamDocumentKey<TSchema> {
345
+ ChangeStreamDocumentKey<TSchema>,
346
+ ChangeStreamDocumentCollectionUUID {
266
347
  /** Describes the type of operation represented in this change notification */
267
348
  operationType: 'delete';
268
349
  /** Namespace the delete event occured on */
269
350
  ns: ChangeStreamNameSpace;
351
+ /**
352
+ * Contains the pre-image of the modified or deleted document if the
353
+ * pre-image is available for the change event and either 'required' or
354
+ * 'whenAvailable' was specified for the 'fullDocumentBeforeChange' option
355
+ * when creating the change stream. If 'whenAvailable' was specified but the
356
+ * pre-image is unavailable, this will be explicitly set to null.
357
+ */
358
+ fullDocumentBeforeChange?: TSchema;
270
359
  }
271
360
 
272
361
  /**
273
362
  * @public
274
363
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#drop-event
275
364
  */
276
- export interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
365
+ export interface ChangeStreamDropDocument
366
+ extends ChangeStreamDocumentCommon,
367
+ ChangeStreamDocumentCollectionUUID {
277
368
  /** Describes the type of operation represented in this change notification */
278
369
  operationType: 'drop';
279
370
  /** Namespace the drop event occured on */
@@ -284,7 +375,9 @@ export interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
284
375
  * @public
285
376
  * @see https://www.mongodb.com/docs/manual/reference/change-events/#rename-event
286
377
  */
287
- export interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon {
378
+ export interface ChangeStreamRenameDocument
379
+ extends ChangeStreamDocumentCommon,
380
+ ChangeStreamDocumentCollectionUUID {
288
381
  /** Describes the type of operation represented in this change notification */
289
382
  operationType: 'rename';
290
383
  /** The new name for the `ns.coll` collection */
@@ -313,6 +406,91 @@ export interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentComm
313
406
  operationType: 'invalidate';
314
407
  }
315
408
 
409
+ /**
410
+ * Only present when the `showExpandedEvents` flag is enabled.
411
+ * @public
412
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/
413
+ */
414
+ export interface ChangeStreamCreateIndexDocument
415
+ extends ChangeStreamDocumentCommon,
416
+ ChangeStreamDocumentCollectionUUID,
417
+ ChangeStreamDocumentOperationDescription {
418
+ /** Describes the type of operation represented in this change notification */
419
+ operationType: 'createIndexes';
420
+ }
421
+
422
+ /**
423
+ * Only present when the `showExpandedEvents` flag is enabled.
424
+ * @public
425
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/
426
+ */
427
+ export interface ChangeStreamDropIndexDocument
428
+ extends ChangeStreamDocumentCommon,
429
+ ChangeStreamDocumentCollectionUUID,
430
+ ChangeStreamDocumentOperationDescription {
431
+ /** Describes the type of operation represented in this change notification */
432
+ operationType: 'dropIndexes';
433
+ }
434
+
435
+ /**
436
+ * Only present when the `showExpandedEvents` flag is enabled.
437
+ * @public
438
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/
439
+ */
440
+ export interface ChangeStreamCollModDocument
441
+ extends ChangeStreamDocumentCommon,
442
+ ChangeStreamDocumentCollectionUUID {
443
+ /** Describes the type of operation represented in this change notification */
444
+ operationType: 'modify';
445
+ }
446
+
447
+ /**
448
+ * @public
449
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/
450
+ */
451
+ export interface ChangeStreamCreateDocument
452
+ extends ChangeStreamDocumentCommon,
453
+ ChangeStreamDocumentCollectionUUID {
454
+ /** Describes the type of operation represented in this change notification */
455
+ operationType: 'create';
456
+ }
457
+
458
+ /**
459
+ * @public
460
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/
461
+ */
462
+ export interface ChangeStreamShardCollectionDocument
463
+ extends ChangeStreamDocumentCommon,
464
+ ChangeStreamDocumentCollectionUUID,
465
+ ChangeStreamDocumentOperationDescription {
466
+ /** Describes the type of operation represented in this change notification */
467
+ operationType: 'shardCollection';
468
+ }
469
+
470
+ /**
471
+ * @public
472
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/
473
+ */
474
+ export interface ChangeStreamReshardCollectionDocument
475
+ extends ChangeStreamDocumentCommon,
476
+ ChangeStreamDocumentCollectionUUID,
477
+ ChangeStreamDocumentOperationDescription {
478
+ /** Describes the type of operation represented in this change notification */
479
+ operationType: 'reshardCollection';
480
+ }
481
+
482
+ /**
483
+ * @public
484
+ * @see https://www.mongodb.com/docs/manual/reference/change-events/
485
+ */
486
+ export interface ChangeStreamRefineCollectionShardKeyDocument
487
+ extends ChangeStreamDocumentCommon,
488
+ ChangeStreamDocumentCollectionUUID,
489
+ ChangeStreamDocumentOperationDescription {
490
+ /** Describes the type of operation represented in this change notification */
491
+ operationType: 'refineCollectionShardKey';
492
+ }
493
+
316
494
  /** @public */
317
495
  export type ChangeStreamDocument<TSchema extends Document = Document> =
318
496
  | ChangeStreamInsertDocument<TSchema>
@@ -322,7 +500,14 @@ export type ChangeStreamDocument<TSchema extends Document = Document> =
322
500
  | ChangeStreamDropDocument
323
501
  | ChangeStreamRenameDocument
324
502
  | ChangeStreamDropDatabaseDocument
325
- | ChangeStreamInvalidateDocument;
503
+ | ChangeStreamInvalidateDocument
504
+ | ChangeStreamCreateIndexDocument
505
+ | ChangeStreamCreateDocument
506
+ | ChangeStreamCollModDocument
507
+ | ChangeStreamDropIndexDocument
508
+ | ChangeStreamShardCollectionDocument
509
+ | ChangeStreamReshardCollectionDocument
510
+ | ChangeStreamRefineCollectionShardKeyDocument;
326
511
 
327
512
  /** @public */
328
513
  export interface UpdateDescription<TSchema extends Document = Document> {
@@ -590,7 +775,7 @@ export class ChangeStream<
590
775
  * @internal
591
776
  */
592
777
  private _createChangeStreamCursor(
593
- options: ChangeStreamOptions | ResumeOptions
778
+ options: ChangeStreamOptions | ChangeStreamCursorOptions
594
779
  ): ChangeStreamCursor<TSchema, TChange> {
595
780
  const changeStreamStageOptions = filterOptions(options, CHANGE_STREAM_OPTIONS);
596
781
  if (this.type === CHANGE_DOMAIN_TYPES.CLUSTER) {
@@ -598,13 +783,27 @@ export class ChangeStream<
598
783
  }
599
784
  const pipeline = [{ $changeStream: changeStreamStageOptions }, ...this.pipeline];
600
785
 
601
- const cursorOptions: ChangeStreamCursorOptions = filterOptions(options, CURSOR_OPTIONS);
786
+ const client: MongoClient | null =
787
+ this.type === CHANGE_DOMAIN_TYPES.CLUSTER
788
+ ? (this.parent as MongoClient)
789
+ : this.type === CHANGE_DOMAIN_TYPES.DATABASE
790
+ ? (this.parent as Db).s.client
791
+ : this.type === CHANGE_DOMAIN_TYPES.COLLECTION
792
+ ? (this.parent as Collection).s.db.s.client
793
+ : null;
794
+
795
+ if (client == null) {
796
+ // This should never happen because of the assertion in the constructor
797
+ throw new MongoRuntimeError(
798
+ `Changestream type should only be one of cluster, database, collection. Found ${this.type.toString()}`
799
+ );
800
+ }
602
801
 
603
802
  const changeStreamCursor = new ChangeStreamCursor<TSchema, TChange>(
604
- getTopology(this.parent),
803
+ client,
605
804
  this.namespace,
606
805
  pipeline,
607
- cursorOptions
806
+ options
608
807
  );
609
808
 
610
809
  for (const event of CHANGE_STREAM_EVENTS) {
@@ -789,7 +988,7 @@ export class ChangeStream<
789
988
  * Drain the resume queue when a new has become available
790
989
  * @internal
791
990
  *
792
- * @param err - error getting a new cursor
991
+ * @param error - error getting a new cursor
793
992
  */
794
993
  private _processResumeQueue(error?: Error) {
795
994
  while (this[kResumeQueue].length) {
@@ -817,6 +1016,9 @@ export interface ChangeStreamCursorOptions extends AbstractCursorOptions {
817
1016
  startAtOperationTime?: OperationTime;
818
1017
  resumeAfter?: ResumeToken;
819
1018
  startAfter?: ResumeToken;
1019
+ maxAwaitTimeMS?: number;
1020
+ collation?: CollationOptions;
1021
+ fullDocument?: string;
820
1022
  }
821
1023
 
822
1024
  /** @internal */
@@ -835,12 +1037,12 @@ export class ChangeStreamCursor<
835
1037
  pipeline: Document[];
836
1038
 
837
1039
  constructor(
838
- topology: Topology,
1040
+ client: MongoClient,
839
1041
  namespace: MongoDBNamespace,
840
1042
  pipeline: Document[] = [],
841
1043
  options: ChangeStreamCursorOptions = {}
842
1044
  ) {
843
- super(topology, namespace, options);
1045
+ super(client, namespace, options);
844
1046
 
845
1047
  this.pipeline = pipeline;
846
1048
  this.options = options;
@@ -863,25 +1065,26 @@ export class ChangeStreamCursor<
863
1065
  return this._resumeToken;
864
1066
  }
865
1067
 
866
- get resumeOptions(): ResumeOptions {
867
- const result: ResumeOptions = filterOptions(this.options, CURSOR_OPTIONS);
868
-
869
- if (this.resumeToken || this.startAtOperationTime) {
870
- for (const key of ['resumeAfter', 'startAfter', 'startAtOperationTime']) {
871
- Reflect.deleteProperty(result, key);
872
- }
1068
+ get resumeOptions(): ChangeStreamCursorOptions {
1069
+ const options: ChangeStreamCursorOptions = {
1070
+ ...this.options
1071
+ };
873
1072
 
874
- if (this.resumeToken) {
875
- const resumeKey =
876
- this.options.startAfter && !this.hasReceived ? 'startAfter' : 'resumeAfter';
1073
+ for (const key of ['resumeAfter', 'startAfter', 'startAtOperationTime'] as const) {
1074
+ delete options[key];
1075
+ }
877
1076
 
878
- result[resumeKey] = this.resumeToken;
879
- } else if (this.startAtOperationTime && maxWireVersion(this.server) >= 7) {
880
- result.startAtOperationTime = this.startAtOperationTime;
1077
+ if (this.resumeToken != null) {
1078
+ if (this.options.startAfter && !this.hasReceived) {
1079
+ options.startAfter = this.resumeToken;
1080
+ } else {
1081
+ options.resumeAfter = this.resumeToken;
881
1082
  }
1083
+ } else if (this.startAtOperationTime != null && maxWireVersion(this.server) >= 7) {
1084
+ options.startAtOperationTime = this.startAtOperationTime;
882
1085
  }
883
1086
 
884
- return result;
1087
+ return options;
885
1088
  }
886
1089
 
887
1090
  cacheResumeToken(resumeToken: ResumeToken): void {
@@ -907,7 +1110,7 @@ export class ChangeStreamCursor<
907
1110
  }
908
1111
 
909
1112
  clone(): AbstractCursor<TChange> {
910
- return new ChangeStreamCursor(this.topology, this.namespace, this.pipeline, {
1113
+ return new ChangeStreamCursor(this.client, this.namespace, this.pipeline, {
911
1114
  ...this.cursorOptions
912
1115
  });
913
1116
  }
@@ -920,7 +1123,7 @@ export class ChangeStreamCursor<
920
1123
  });
921
1124
 
922
1125
  executeOperation<TODO_NODE_3286, ChangeStreamAggregateRawResult<TChange>>(
923
- session,
1126
+ session.client,
924
1127
  aggregateOperation,
925
1128
  (err, response) => {
926
1129
  if (err || response == null) {
@@ -261,7 +261,17 @@ function passwordDigest(username: string, password: string) {
261
261
  throw new MongoInvalidArgumentError('Password cannot be empty');
262
262
  }
263
263
 
264
- const md5 = crypto.createHash('md5');
264
+ let md5: crypto.Hash;
265
+ try {
266
+ md5 = crypto.createHash('md5');
267
+ } catch (err) {
268
+ if (crypto.getFips()) {
269
+ // This error is (slightly) more helpful than what comes from OpenSSL directly, e.g.
270
+ // 'Error: error:060800C8:digital envelope routines:EVP_DigestInit_ex:disabled for FIPS'
271
+ throw new Error('Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode');
272
+ }
273
+ throw err;
274
+ }
265
275
  md5.update(`${username}:mongo:${password}`, 'utf8');
266
276
  return md5.digest('hex');
267
277
  }
@@ -1,3 +1,5 @@
1
+ import { setTimeout } from 'timers';
2
+
1
3
  import { BSONSerializeOptions, Document, Long, ObjectId, pluckBSONSerializeOptions } from '../bson';
2
4
  import {
3
5
  CLOSE,
@@ -293,6 +295,15 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
293
295
  this[kHello] = response;
294
296
  }
295
297
 
298
+ // Set the whether the message stream is for a monitoring connection.
299
+ set isMonitoringConnection(value: boolean) {
300
+ this[kMessageStream].isMonitoringConnection = value;
301
+ }
302
+
303
+ get isMonitoringConnection(): boolean {
304
+ return this[kMessageStream].isMonitoringConnection;
305
+ }
306
+
296
307
  get serviceId(): ObjectId | undefined {
297
308
  return this.hello?.serviceId;
298
309
  }