Skip to content

Commit a945d02

Browse files
add 3 missing new change stream types
1 parent 1f03496 commit a945d02

File tree

3 files changed

+207
-20
lines changed

3 files changed

+207
-20
lines changed

src/change_stream.ts

Lines changed: 178 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ export interface ChangeStreamInsertDocument<TSchema extends Document = Document>
258258
fullDocument: TSchema;
259259
/** Namespace the insert event occured on */
260260
ns: ChangeStreamNameSpace;
261+
262+
/**
263+
* The UUID of the collection that the operation was performed on.
264+
*
265+
* Only present when the `showExpandedEvents` flag is enabled.
266+
*
267+
* @since 6.1.0
268+
*/
269+
collectionUUID: UUID;
261270
}
262271

263272
/**
@@ -288,6 +297,15 @@ export interface ChangeStreamUpdateDocument<TSchema extends Document = Document>
288297
* pre-image is unavailable, this will be explicitly set to null.
289298
*/
290299
fullDocumentBeforeChange?: TSchema;
300+
301+
/**
302+
* The UUID of the collection that the operation was performed on.
303+
*
304+
* Only present when the `showExpandedEvents` flag is enabled.
305+
*
306+
* @since 6.1.0
307+
*/
308+
collectionUUID: UUID;
291309
}
292310

293311
/**
@@ -332,6 +350,15 @@ export interface ChangeStreamDeleteDocument<TSchema extends Document = Document>
332350
* pre-image is unavailable, this will be explicitly set to null.
333351
*/
334352
fullDocumentBeforeChange?: TSchema;
353+
354+
/**
355+
* The UUID of the collection that the operation was performed on.
356+
*
357+
* Only present when the `showExpandedEvents` flag is enabled.
358+
*
359+
* @since 6.1.0
360+
*/
361+
collectionUUID: UUID;
335362
}
336363

337364
/**
@@ -343,6 +370,15 @@ export interface ChangeStreamDropDocument extends ChangeStreamDocumentCommon {
343370
operationType: 'drop';
344371
/** Namespace the drop event occured on */
345372
ns: ChangeStreamNameSpace;
373+
374+
/**
375+
* The UUID of the collection that the operation was performed on.
376+
*
377+
* Only present when the `showExpandedEvents` flag is enabled.
378+
*
379+
* @since 6.1.0
380+
*/
381+
collectionUUID: UUID;
346382
}
347383

348384
/**
@@ -357,24 +393,13 @@ export interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon {
357393
/** The "from" namespace that the rename occured on */
358394
ns: ChangeStreamNameSpace;
359395
/**
360-
* An operation description representing the changes in a `rename` event.
396+
* An description of the operation.
361397
*
362398
* Only present when the `showExpandedEvents` flag is enabled.
363399
*
364-
* @since 6.0.0
400+
* @since 6.1.0
365401
*/
366-
operationDescription?: {
367-
/**
368-
* Contains two fields: "db" and "coll" containing the database and
369-
* collection name in which the change happened.
370-
*/
371-
to?: { db: string; coll: string };
372-
373-
/**
374-
* The uuid of the target collection that was dropped.
375-
*/
376-
dropTarget?: UUID; // TODO - confirm that this value is optional
377-
};
402+
operationDescription?: Document;
378403
}
379404

380405
/**
@@ -405,6 +430,24 @@ export interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentComm
405430
export interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon {
406431
/** Describes the type of operation represented in this change notification */
407432
operationType: 'createIndexes';
433+
434+
/**
435+
* The UUID of the collection that the operation was performed on.
436+
*
437+
* Only present when the `showExpandedEvents` flag is enabled.
438+
*
439+
* @since 6.1.0
440+
*/
441+
collectionUUID: UUID;
442+
443+
/**
444+
* An description of the operation.
445+
*
446+
* Only present when the `showExpandedEvents` flag is enabled.
447+
*
448+
* @since 6.1.0
449+
*/
450+
operationDescription?: Document;
408451
}
409452

410453
/**
@@ -415,6 +458,24 @@ export interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCom
415458
export interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon {
416459
/** Describes the type of operation represented in this change notification */
417460
operationType: 'dropIndexes';
461+
462+
/**
463+
* The UUID of the collection that the operation was performed on.
464+
*
465+
* Only present when the `showExpandedEvents` flag is enabled.
466+
*
467+
* @since 6.1.0
468+
*/
469+
collectionUUID: UUID;
470+
471+
/**
472+
* An description of the operation.
473+
*
474+
* Only present when the `showExpandedEvents` flag is enabled.
475+
*
476+
* @since 6.1.0
477+
*/
478+
operationDescription?: Document;
418479
}
419480

420481
/**
@@ -425,6 +486,15 @@ export interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommo
425486
export interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon {
426487
/** Describes the type of operation represented in this change notification */
427488
operationType: 'modify';
489+
490+
/**
491+
* The UUID of the collection that the operation was performed on.
492+
*
493+
* Only present when the `showExpandedEvents` flag is enabled.
494+
*
495+
* @since 6.1.0
496+
*/
497+
collectionUUID: UUID;
428498
}
429499

430500
/**
@@ -434,6 +504,96 @@ export interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon
434504
export interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon {
435505
/** Describes the type of operation represented in this change notification */
436506
operationType: 'create';
507+
508+
/**
509+
* The UUID of the collection that the operation was performed on.
510+
*
511+
* Only present when the `showExpandedEvents` flag is enabled.
512+
*
513+
* @since 6.1.0
514+
*/
515+
collectionUUID: UUID;
516+
}
517+
518+
/**
519+
* @public
520+
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
521+
*/
522+
export interface ChangeStreamShardCollectionDocument extends ChangeStreamDocumentCommon {
523+
/** Describes the type of operation represented in this change notification */
524+
operationType: 'shardCollection';
525+
526+
/**
527+
* The UUID of the collection that the operation was performed on.
528+
*
529+
* Only present when the `showExpandedEvents` flag is enabled.
530+
*
531+
* @since 6.1.0
532+
*/
533+
collectionUUID: UUID;
534+
535+
/**
536+
* An description of the operation.
537+
*
538+
* Only present when the `showExpandedEvents` flag is enabled.
539+
*
540+
* @since 6.1.0
541+
*/
542+
operationDescription?: Document;
543+
}
544+
545+
/**
546+
* @public
547+
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
548+
*/
549+
export interface ChangeStreamReshardCollectionDocument extends ChangeStreamDocumentCommon {
550+
/** Describes the type of operation represented in this change notification */
551+
operationType: 'reshardCollection';
552+
553+
/**
554+
* The UUID of the collection that the operation was performed on.
555+
*
556+
* Only present when the `showExpandedEvents` flag is enabled.
557+
*
558+
* @since 6.1.0
559+
*/
560+
collectionUUID: UUID;
561+
562+
/**
563+
* An description of the operation.
564+
*
565+
* Only present when the `showExpandedEvents` flag is enabled.
566+
*
567+
* @since 6.1.0
568+
*/
569+
operationDescription?: Document;
570+
}
571+
572+
/**
573+
* @public
574+
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
575+
*/
576+
export interface ChangeStreamRefineCollectionShardKeyDocument extends ChangeStreamDocumentCommon {
577+
/** Describes the type of operation represented in this change notification */
578+
operationType: 'refineCollectionShardKey';
579+
580+
/**
581+
* The UUID of the collection that the operation was performed on.
582+
*
583+
* Only present when the `showExpandedEvents` flag is enabled.
584+
*
585+
* @since 6.1.0
586+
*/
587+
collectionUUID?: UUID;
588+
589+
/**
590+
* An description of the operation.
591+
*
592+
* Only present when the `showExpandedEvents` flag is enabled.
593+
*
594+
* @since 6.1.0
595+
*/
596+
operationDescription?: Document;
437597
}
438598

439599
/** @public */
@@ -449,7 +609,10 @@ export type ChangeStreamDocument<TSchema extends Document = Document> =
449609
| ChangeStreamCreateIndexDocument
450610
| ChangeStreamCreateDocument
451611
| ChangeStreamCollModDocument
452-
| ChangeStreamDropIndexDocument;
612+
| ChangeStreamDropIndexDocument
613+
| ChangeStreamShardCollectionDocument
614+
| ChangeStreamReshardCollectionDocument
615+
| ChangeStreamRefineCollectionShardKeyDocument;
453616

454617
/** @public */
455618
export interface UpdateDescription<TSchema extends Document = Document> {

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ export type {
188188
ChangeStreamInvalidateDocument,
189189
ChangeStreamNameSpace,
190190
ChangeStreamOptions,
191+
ChangeStreamRefineCollectionShardKeyDocument,
191192
ChangeStreamRenameDocument,
192193
ChangeStreamReplaceDocument,
194+
ChangeStreamReshardCollectionDocument,
195+
ChangeStreamShardCollectionDocument,
193196
ChangeStreamUpdateDocument,
194197
OperationTime,
195198
PipeOptions,

test/types/change_stream.test-d.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { expectError, expectType } from 'tsd';
22

33
import type {
4+
ChangeStreamCollModDocument,
5+
ChangeStreamCreateDocument,
6+
ChangeStreamCreateIndexDocument,
47
ChangeStreamDeleteDocument,
58
ChangeStreamDocument,
69
ChangeStreamDocumentCommon,
710
ChangeStreamDocumentKey,
811
ChangeStreamDropDatabaseDocument,
912
ChangeStreamDropDocument,
13+
ChangeStreamDropIndexDocument,
1014
ChangeStreamInsertDocument,
1115
ChangeStreamInvalidateDocument,
1216
ChangeStreamNameSpace,
@@ -22,10 +26,9 @@ import type {
2226
UpdateDescription
2327
} from '../../src';
2428
import type {
25-
ChangeStreamCollModDocument,
26-
ChangeStreamCreateDocument,
27-
ChangeStreamCreateIndexDocument,
28-
ChangeStreamDropIndexDocument
29+
ChangeStreamRefineCollectionShardKeyDocument,
30+
ChangeStreamReshardCollectionDocument,
31+
ChangeStreamShardCollectionDocument
2932
} from '../../src/change_stream';
3033

3134
declare const changeStreamOptions: ChangeStreamOptions;
@@ -41,7 +44,10 @@ type ChangeStreamOperationType =
4144
| 'create'
4245
| 'modify'
4346
| 'createIndexes'
44-
| 'dropIndexes';
47+
| 'dropIndexes'
48+
| 'shardCollection'
49+
| 'reshardCollection'
50+
| 'refineCollectionShardKey';
4551

4652
// The change stream spec says that we cannot throw an error for invalid values to `fullDocument`
4753
// for future compatibility. This means we must leave `fullDocument` as type string.
@@ -152,6 +158,21 @@ switch (change.operationType) {
152158
expectType<'dropIndexes'>(change.operationType);
153159
break;
154160
}
161+
case 'shardCollection': {
162+
expectType<ChangeStreamShardCollectionDocument>(change);
163+
expectType<'shardCollection'>(change.operationType);
164+
break;
165+
}
166+
case 'reshardCollection': {
167+
expectType<ChangeStreamReshardCollectionDocument>(change);
168+
expectType<'reshardCollection'>(change.operationType);
169+
break;
170+
}
171+
case 'refineCollectionShardKey': {
172+
expectType<ChangeStreamRefineCollectionShardKeyDocument>(change);
173+
expectType<'refineCollectionShardKey'>(change.operationType);
174+
break;
175+
}
155176
default: {
156177
expectType<never>(change);
157178
}

0 commit comments

Comments
 (0)