@@ -2,7 +2,7 @@ import Denque = require('denque');
22import type { Readable } from 'stream' ;
33import { setTimeout } from 'timers' ;
44
5- import type { Document , Long , Timestamp } from './bson' ;
5+ import type { Binary , Document , Long , Timestamp } from './bson' ;
66import { Collection } from './collection' ;
77import { CHANGE , CLOSE , END , ERROR , INIT , MORE , RESPONSE , RESUME_TOKEN_CHANGED } from './constants' ;
88import {
@@ -52,7 +52,8 @@ const CHANGE_STREAM_OPTIONS = [
5252 'startAfter' ,
5353 'startAtOperationTime' ,
5454 'fullDocument' ,
55- 'fullDocumentBeforeChange'
55+ 'fullDocumentBeforeChange' ,
56+ 'showExpandedEvents'
5657] as const ;
5758
5859const CHANGE_DOMAIN_TYPES = {
@@ -176,6 +177,19 @@ export interface ChangeStreamOptions extends AggregateOptions {
176177 * @see https://docs.mongodb.com/manual/reference/command/aggregate
177178 */
178179 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 ;
179193}
180194
181195/** @public */
@@ -225,13 +239,41 @@ export interface ChangeStreamDocumentCommon {
225239 lsid ?: ServerSessionId ;
226240}
227241
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+
228269/**
229270 * @public
230271 * @see https://www.mongodb.com/docs/manual/reference/change-events/#insert-event
231272 */
232273export interface ChangeStreamInsertDocument < TSchema extends Document = Document >
233274 extends ChangeStreamDocumentCommon ,
234- ChangeStreamDocumentKey < TSchema > {
275+ ChangeStreamDocumentKey < TSchema > ,
276+ ChangeStreamDocumentCollectionUUID {
235277 /** Describes the type of operation represented in this change notification */
236278 operationType : 'insert' ;
237279 /** This key will contain the document being inserted */
@@ -246,7 +288,8 @@ export interface ChangeStreamInsertDocument<TSchema extends Document = Document>
246288 */
247289export interface ChangeStreamUpdateDocument < TSchema extends Document = Document >
248290 extends ChangeStreamDocumentCommon ,
249- ChangeStreamDocumentKey < TSchema > {
291+ ChangeStreamDocumentKey < TSchema > ,
292+ ChangeStreamDocumentCollectionUUID {
250293 /** Describes the type of operation represented in this change notification */
251294 operationType : 'update' ;
252295 /**
@@ -299,7 +342,8 @@ export interface ChangeStreamReplaceDocument<TSchema extends Document = Document
299342 */
300343export interface ChangeStreamDeleteDocument < TSchema extends Document = Document >
301344 extends ChangeStreamDocumentCommon ,
302- ChangeStreamDocumentKey < TSchema > {
345+ ChangeStreamDocumentKey < TSchema > ,
346+ ChangeStreamDocumentCollectionUUID {
303347 /** Describes the type of operation represented in this change notification */
304348 operationType : 'delete' ;
305349 /** Namespace the delete event occured on */
@@ -318,7 +362,9 @@ export interface ChangeStreamDeleteDocument<TSchema extends Document = Document>
318362 * @public
319363 * @see https://www.mongodb.com/docs/manual/reference/change-events/#drop-event
320364 */
321- export interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
365+ export interface ChangeStreamDropDocument
366+ extends ChangeStreamDocumentCommon ,
367+ ChangeStreamDocumentCollectionUUID {
322368 /** Describes the type of operation represented in this change notification */
323369 operationType : 'drop' ;
324370 /** Namespace the drop event occured on */
@@ -329,7 +375,9 @@ export interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
329375 * @public
330376 * @see https://www.mongodb.com/docs/manual/reference/change-events/#rename-event
331377 */
332- export interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon {
378+ export interface ChangeStreamRenameDocument
379+ extends ChangeStreamDocumentCommon ,
380+ ChangeStreamDocumentCollectionUUID {
333381 /** Describes the type of operation represented in this change notification */
334382 operationType : 'rename' ;
335383 /** The new name for the `ns.coll` collection */
@@ -358,6 +406,91 @@ export interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentComm
358406 operationType : 'invalidate' ;
359407}
360408
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+
361494/** @public */
362495export type ChangeStreamDocument < TSchema extends Document = Document > =
363496 | ChangeStreamInsertDocument < TSchema >
@@ -367,7 +500,14 @@ export type ChangeStreamDocument<TSchema extends Document = Document> =
367500 | ChangeStreamDropDocument
368501 | ChangeStreamRenameDocument
369502 | ChangeStreamDropDatabaseDocument
370- | ChangeStreamInvalidateDocument ;
503+ | ChangeStreamInvalidateDocument
504+ | ChangeStreamCreateIndexDocument
505+ | ChangeStreamCreateDocument
506+ | ChangeStreamCollModDocument
507+ | ChangeStreamDropIndexDocument
508+ | ChangeStreamShardCollectionDocument
509+ | ChangeStreamReshardCollectionDocument
510+ | ChangeStreamRefineCollectionShardKeyDocument ;
371511
372512/** @public */
373513export interface UpdateDescription < TSchema extends Document = Document > {
0 commit comments