@@ -2,7 +2,7 @@ import Denque = require('denque');
2
2
import type { Readable } from 'stream' ;
3
3
import { setTimeout } from 'timers' ;
4
4
5
- import type { Document , Long , Timestamp } from './bson' ;
5
+ import type { Binary , Document , Long , Timestamp } from './bson' ;
6
6
import { Collection } from './collection' ;
7
7
import { CHANGE , CLOSE , END , ERROR , INIT , MORE , RESPONSE , RESUME_TOKEN_CHANGED } from './constants' ;
8
8
import {
@@ -52,7 +52,8 @@ const CHANGE_STREAM_OPTIONS = [
52
52
'startAfter' ,
53
53
'startAtOperationTime' ,
54
54
'fullDocument' ,
55
- 'fullDocumentBeforeChange'
55
+ 'fullDocumentBeforeChange' ,
56
+ 'showExpandedEvents'
56
57
] as const ;
57
58
58
59
const CHANGE_DOMAIN_TYPES = {
@@ -176,6 +177,19 @@ export interface ChangeStreamOptions extends AggregateOptions {
176
177
* @see https://docs.mongodb.com/manual/reference/command/aggregate
177
178
*/
178
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 ;
179
193
}
180
194
181
195
/** @public */
@@ -225,13 +239,41 @@ export interface ChangeStreamDocumentCommon {
225
239
lsid ?: ServerSessionId ;
226
240
}
227
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
+
228
269
/**
229
270
* @public
230
271
* @see https://www.mongodb.com/docs/manual/reference/change-events/#insert-event
231
272
*/
232
273
export interface ChangeStreamInsertDocument < TSchema extends Document = Document >
233
274
extends ChangeStreamDocumentCommon ,
234
- ChangeStreamDocumentKey < TSchema > {
275
+ ChangeStreamDocumentKey < TSchema > ,
276
+ ChangeStreamDocumentCollectionUUID {
235
277
/** Describes the type of operation represented in this change notification */
236
278
operationType : 'insert' ;
237
279
/** This key will contain the document being inserted */
@@ -246,7 +288,8 @@ export interface ChangeStreamInsertDocument<TSchema extends Document = Document>
246
288
*/
247
289
export interface ChangeStreamUpdateDocument < TSchema extends Document = Document >
248
290
extends ChangeStreamDocumentCommon ,
249
- ChangeStreamDocumentKey < TSchema > {
291
+ ChangeStreamDocumentKey < TSchema > ,
292
+ ChangeStreamDocumentCollectionUUID {
250
293
/** Describes the type of operation represented in this change notification */
251
294
operationType : 'update' ;
252
295
/**
@@ -299,7 +342,8 @@ export interface ChangeStreamReplaceDocument<TSchema extends Document = Document
299
342
*/
300
343
export interface ChangeStreamDeleteDocument < TSchema extends Document = Document >
301
344
extends ChangeStreamDocumentCommon ,
302
- ChangeStreamDocumentKey < TSchema > {
345
+ ChangeStreamDocumentKey < TSchema > ,
346
+ ChangeStreamDocumentCollectionUUID {
303
347
/** Describes the type of operation represented in this change notification */
304
348
operationType : 'delete' ;
305
349
/** Namespace the delete event occured on */
@@ -318,7 +362,9 @@ export interface ChangeStreamDeleteDocument<TSchema extends Document = Document>
318
362
* @public
319
363
* @see https://www.mongodb.com/docs/manual/reference/change-events/#drop-event
320
364
*/
321
- export interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
365
+ export interface ChangeStreamDropDocument
366
+ extends ChangeStreamDocumentCommon ,
367
+ ChangeStreamDocumentCollectionUUID {
322
368
/** Describes the type of operation represented in this change notification */
323
369
operationType : 'drop' ;
324
370
/** Namespace the drop event occured on */
@@ -329,7 +375,9 @@ export interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
329
375
* @public
330
376
* @see https://www.mongodb.com/docs/manual/reference/change-events/#rename-event
331
377
*/
332
- export interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon {
378
+ export interface ChangeStreamRenameDocument
379
+ extends ChangeStreamDocumentCommon ,
380
+ ChangeStreamDocumentCollectionUUID {
333
381
/** Describes the type of operation represented in this change notification */
334
382
operationType : 'rename' ;
335
383
/** The new name for the `ns.coll` collection */
@@ -358,6 +406,91 @@ export interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentComm
358
406
operationType : 'invalidate' ;
359
407
}
360
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
+
361
494
/** @public */
362
495
export type ChangeStreamDocument < TSchema extends Document = Document > =
363
496
| ChangeStreamInsertDocument < TSchema >
@@ -367,7 +500,14 @@ export type ChangeStreamDocument<TSchema extends Document = Document> =
367
500
| ChangeStreamDropDocument
368
501
| ChangeStreamRenameDocument
369
502
| ChangeStreamDropDatabaseDocument
370
- | ChangeStreamInvalidateDocument ;
503
+ | ChangeStreamInvalidateDocument
504
+ | ChangeStreamCreateIndexDocument
505
+ | ChangeStreamCreateDocument
506
+ | ChangeStreamCollModDocument
507
+ | ChangeStreamDropIndexDocument
508
+ | ChangeStreamShardCollectionDocument
509
+ | ChangeStreamReshardCollectionDocument
510
+ | ChangeStreamRefineCollectionShardKeyDocument ;
371
511
372
512
/** @public */
373
513
export interface UpdateDescription < TSchema extends Document = Document > {
0 commit comments