Skip to content

Commit 6aec144

Browse files
initial commit - working NODE POC
add tests for new flags added with dropCollection add tests for new change stream events and refactor existing tests update change stream type changes to reflect new events clean up change stream, export new types and add type tests fix rename test to always drop the target collection add change stream test for shardCollection clean up spec tests update spec tests initial commit - working NODE POC add tests for new change stream events and refactor existing tests update change stream type changes to reflect new events clean up change stream, export new types and add type tests
1 parent 55a2e45 commit 6aec144

File tree

9 files changed

+1009
-5
lines changed

9 files changed

+1009
-5
lines changed

src/change_stream.ts

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { UUID } from 'bson';
12
import Denque = require('denque');
23
import type { Readable } from 'stream';
34

@@ -50,7 +51,8 @@ const CHANGE_STREAM_OPTIONS = [
5051
'resumeAfter',
5152
'startAfter',
5253
'startAtOperationTime',
53-
'fullDocument'
54+
'fullDocument',
55+
'showExpandedEvents'
5456
] as const;
5557

5658
const CURSOR_OPTIONS = [
@@ -155,6 +157,20 @@ export interface ChangeStreamOptions extends AggregateOptions {
155157
* @see https://docs.mongodb.com/manual/reference/command/aggregate
156158
*/
157159
batchSize?: number;
160+
161+
/**
162+
* When enabled, configures the change stream to include extra change events.
163+
*
164+
* - createIndex
165+
* - dropIndex
166+
* - collMod
167+
* - create
168+
* - shardCollection
169+
* - reshardCollection
170+
* - refineCollectionShardKey
171+
* - chunkMigrated
172+
*/
173+
showExpandedEvents?: boolean;
158174
}
159175

160176
/** @public */
@@ -291,6 +307,25 @@ export interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon {
291307
to: { db: string; coll: string };
292308
/** The "from" namespace that the rename occured on */
293309
ns: ChangeStreamNameSpace;
310+
/**
311+
* An operation description representing the changes in a `rename` event.
312+
*
313+
* Only present when the `showExpandedEvents` flag is enabled.
314+
*
315+
* @since 6.0.0
316+
*/
317+
operationDescription?: {
318+
/**
319+
* Contains two fields: "db" and "coll" containing the database and
320+
* collection name in which the change happened.
321+
*/
322+
to?: { db: string; coll: string };
323+
324+
/**
325+
* The uuid of the target collection that was dropped.
326+
*/
327+
dropTarget?: UUID; // TODO - confirm that this value is optional
328+
};
294329
}
295330

296331
/**
@@ -313,6 +348,45 @@ export interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentComm
313348
operationType: 'invalidate';
314349
}
315350

351+
/**
352+
* Only present when the `showExpandedEvents` flag is enabled.
353+
* @public
354+
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
355+
*/
356+
export interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon {
357+
/** Describes the type of operation represented in this change notification */
358+
operationType: 'createIndexes';
359+
}
360+
361+
/**
362+
* Only present when the `showExpandedEvents` flag is enabled.
363+
* @public
364+
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
365+
*/
366+
export interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon {
367+
/** Describes the type of operation represented in this change notification */
368+
operationType: 'dropIndexes';
369+
}
370+
371+
/**
372+
* Only present when the `showExpandedEvents` flag is enabled.
373+
* @public
374+
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
375+
*/
376+
export interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon {
377+
/** Describes the type of operation represented in this change notification */
378+
operationType: 'modify';
379+
}
380+
381+
/**
382+
* @public
383+
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
384+
*/
385+
export interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon {
386+
/** Describes the type of operation represented in this change notification */
387+
operationType: 'create';
388+
}
389+
316390
/** @public */
317391
export type ChangeStreamDocument<TSchema extends Document = Document> =
318392
| ChangeStreamInsertDocument<TSchema>
@@ -322,7 +396,11 @@ export type ChangeStreamDocument<TSchema extends Document = Document> =
322396
| ChangeStreamDropDocument
323397
| ChangeStreamRenameDocument
324398
| ChangeStreamDropDatabaseDocument
325-
| ChangeStreamInvalidateDocument;
399+
| ChangeStreamInvalidateDocument
400+
| ChangeStreamCreateIndexDocument
401+
| ChangeStreamCreateDocument
402+
| ChangeStreamCollModDocument
403+
| ChangeStreamDropIndexDocument;
326404

327405
/** @public */
328406
export interface UpdateDescription<TSchema extends Document = Document> {

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ export type { UnorderedBulkOperation } from './bulk/unordered';
171171
export type {
172172
ChangeStream,
173173
ChangeStreamAggregateRawResult,
174+
ChangeStreamCollModDocument,
175+
ChangeStreamCreateDocument,
176+
ChangeStreamCreateIndexDocument,
174177
ChangeStreamCursor,
175178
ChangeStreamCursorOptions,
176179
ChangeStreamDeleteDocument,
@@ -179,6 +182,7 @@ export type {
179182
ChangeStreamDocumentKey,
180183
ChangeStreamDropDatabaseDocument,
181184
ChangeStreamDropDocument,
185+
ChangeStreamDropIndexDocument,
182186
ChangeStreamEvents,
183187
ChangeStreamInsertDocument,
184188
ChangeStreamInvalidateDocument,

0 commit comments

Comments
 (0)