Skip to content

Commit

Permalink
initial commit - working NODE POC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
baileympearson committed May 18, 2022
1 parent 55a2e45 commit 6aec144
Show file tree
Hide file tree
Showing 9 changed files with 1,009 additions and 5 deletions.
82 changes: 80 additions & 2 deletions src/change_stream.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { UUID } from 'bson';
import Denque = require('denque');
import type { Readable } from 'stream';

Expand Down Expand Up @@ -50,7 +51,8 @@ const CHANGE_STREAM_OPTIONS = [
'resumeAfter',
'startAfter',
'startAtOperationTime',
'fullDocument'
'fullDocument',
'showExpandedEvents'
] as const;

const CURSOR_OPTIONS = [
Expand Down Expand Up @@ -155,6 +157,20 @@ export interface ChangeStreamOptions extends AggregateOptions {
* @see https://docs.mongodb.com/manual/reference/command/aggregate
*/
batchSize?: number;

/**
* When enabled, configures the change stream to include extra change events.
*
* - createIndex
* - dropIndex
* - collMod
* - create
* - shardCollection
* - reshardCollection
* - refineCollectionShardKey
* - chunkMigrated
*/
showExpandedEvents?: boolean;
}

/** @public */
Expand Down Expand Up @@ -291,6 +307,25 @@ export interface ChangeStreamRenameDocument extends ChangeStreamDocumentCommon {
to: { db: string; coll: string };
/** The "from" namespace that the rename occured on */
ns: ChangeStreamNameSpace;
/**
* An operation description representing the changes in a `rename` event.
*
* Only present when the `showExpandedEvents` flag is enabled.
*
* @since 6.0.0
*/
operationDescription?: {
/**
* Contains two fields: "db" and "coll" containing the database and
* collection name in which the change happened.
*/
to?: { db: string; coll: string };

/**
* The uuid of the target collection that was dropped.
*/
dropTarget?: UUID; // TODO - confirm that this value is optional
};
}

/**
Expand All @@ -313,6 +348,45 @@ export interface ChangeStreamInvalidateDocument extends ChangeStreamDocumentComm
operationType: 'invalidate';
}

/**
* Only present when the `showExpandedEvents` flag is enabled.
* @public
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
*/
export interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCommon {
/** Describes the type of operation represented in this change notification */
operationType: 'createIndexes';
}

/**
* Only present when the `showExpandedEvents` flag is enabled.
* @public
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
*/
export interface ChangeStreamDropIndexDocument extends ChangeStreamDocumentCommon {
/** Describes the type of operation represented in this change notification */
operationType: 'dropIndexes';
}

/**
* Only present when the `showExpandedEvents` flag is enabled.
* @public
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
*/
export interface ChangeStreamCollModDocument extends ChangeStreamDocumentCommon {
/** Describes the type of operation represented in this change notification */
operationType: 'modify';
}

/**
* @public
* @see https://www.mongodb.com/docs/manual/reference/change-events/#invalidate-event
*/
export interface ChangeStreamCreateDocument extends ChangeStreamDocumentCommon {
/** Describes the type of operation represented in this change notification */
operationType: 'create';
}

/** @public */
export type ChangeStreamDocument<TSchema extends Document = Document> =
| ChangeStreamInsertDocument<TSchema>
Expand All @@ -322,7 +396,11 @@ export type ChangeStreamDocument<TSchema extends Document = Document> =
| ChangeStreamDropDocument
| ChangeStreamRenameDocument
| ChangeStreamDropDatabaseDocument
| ChangeStreamInvalidateDocument;
| ChangeStreamInvalidateDocument
| ChangeStreamCreateIndexDocument
| ChangeStreamCreateDocument
| ChangeStreamCollModDocument
| ChangeStreamDropIndexDocument;

/** @public */
export interface UpdateDescription<TSchema extends Document = Document> {
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export type { UnorderedBulkOperation } from './bulk/unordered';
export type {
ChangeStream,
ChangeStreamAggregateRawResult,
ChangeStreamCollModDocument,
ChangeStreamCreateDocument,
ChangeStreamCreateIndexDocument,
ChangeStreamCursor,
ChangeStreamCursorOptions,
ChangeStreamDeleteDocument,
Expand All @@ -179,6 +182,7 @@ export type {
ChangeStreamDocumentKey,
ChangeStreamDropDatabaseDocument,
ChangeStreamDropDocument,
ChangeStreamDropIndexDocument,
ChangeStreamEvents,
ChangeStreamInsertDocument,
ChangeStreamInvalidateDocument,
Expand Down

0 comments on commit 6aec144

Please sign in to comment.