Skip to content

Commit c10b98e

Browse files
committed
feat(NODE-4059): ChangeStreamDocument not fully typed to specification
1 parent 5e465b7 commit c10b98e

File tree

8 files changed

+664
-180
lines changed

8 files changed

+664
-180
lines changed

src/change_stream.ts

+226-98
Large diffs are not rendered by default.

src/collection.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
22
import type { AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult } from './bulk/common';
33
import { OrderedBulkOperation } from './bulk/ordered';
44
import { UnorderedBulkOperation } from './bulk/unordered';
5-
import { ChangeStream, ChangeStreamOptions } from './change_stream';
5+
import { ChangeStream, ChangeStreamDocument, ChangeStreamOptions } from './change_stream';
66
import { AggregationCursor } from './cursor/aggregation_cursor';
77
import { FindCursor } from './cursor/find_cursor';
88
import type { Db } from './db';
@@ -1422,17 +1422,17 @@ export class Collection<TSchema extends Document = Document> {
14221422
* @param pipeline - An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
14231423
* @param options - Optional settings for the command
14241424
*/
1425-
watch<TLocal extends Document = TSchema>(
1426-
pipeline: Document[] = [],
1427-
options: ChangeStreamOptions = {}
1428-
): ChangeStream<TLocal> {
1425+
watch<
1426+
TLocal extends Document = TSchema,
1427+
TChange extends ChangeStreamDocument<TLocal> = ChangeStreamDocument<TLocal>
1428+
>(pipeline: Document[] = [], options: ChangeStreamOptions = {}): ChangeStream<TLocal, TChange> {
14291429
// Allow optionally not specifying a pipeline
14301430
if (!Array.isArray(pipeline)) {
14311431
options = pipeline;
14321432
pipeline = [];
14331433
}
14341434

1435-
return new ChangeStream<TLocal>(this, pipeline, resolveOptions(this, options));
1435+
return new ChangeStream<TLocal, TChange>(this, pipeline, resolveOptions(this, options));
14361436
}
14371437

14381438
/**

src/db.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Admin } from './admin';
22
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
3-
import { ChangeStream, ChangeStreamOptions } from './change_stream';
3+
import { ChangeStream, ChangeStreamDocument, ChangeStreamOptions } from './change_stream';
44
import { Collection, CollectionOptions } from './collection';
55
import * as CONSTANTS from './constants';
66
import { AggregationCursor } from './cursor/aggregation_cursor';
@@ -722,17 +722,17 @@ export class Db {
722722
* @param pipeline - An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
723723
* @param options - Optional settings for the command
724724
*/
725-
watch<TSchema extends Document = Document>(
726-
pipeline: Document[] = [],
727-
options: ChangeStreamOptions = {}
728-
): ChangeStream<TSchema> {
725+
watch<
726+
TSchema extends Document = Document,
727+
TChange extends ChangeStreamDocument<TSchema> = ChangeStreamDocument<TSchema>
728+
>(pipeline: Document[] = [], options: ChangeStreamOptions = {}): ChangeStream<TSchema, TChange> {
729729
// Allow optionally not specifying a pipeline
730730
if (!Array.isArray(pipeline)) {
731731
options = pipeline;
732732
pipeline = [];
733733
}
734734

735-
return new ChangeStream<TSchema>(this, pipeline, resolveOptions(this, options));
735+
return new ChangeStream<TSchema, TChange>(this, pipeline, resolveOptions(this, options));
736736
}
737737

738738
/** Return the db logger */

src/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,20 @@ export type {
172172
ChangeStreamAggregateRawResult,
173173
ChangeStreamCursor,
174174
ChangeStreamCursorOptions,
175+
ChangeStreamDeleteDocument,
175176
ChangeStreamDocument,
177+
ChangeStreamDocumentCommon,
178+
ChangeStreamDocumentKey,
179+
ChangeStreamDropDatabaseDocument,
180+
ChangeStreamDropDocument,
176181
ChangeStreamEvents,
182+
ChangeStreamInsertDocument,
183+
ChangeStreamInvalidateDocument,
184+
ChangeStreamNameSpace,
177185
ChangeStreamOptions,
186+
ChangeStreamRenameDocument,
187+
ChangeStreamReplaceDocument,
188+
ChangeStreamUpdateDocument,
178189
OperationTime,
179190
PipeOptions,
180191
ResumeOptions,

src/mongo_client.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { TcpNetConnectOpts } from 'net';
22
import type { ConnectionOptions as TLSConnectionOptions, TLSSocketOptions } from 'tls';
33

44
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
5-
import { ChangeStream, ChangeStreamOptions } from './change_stream';
5+
import { ChangeStream, ChangeStreamDocument, ChangeStreamOptions } from './change_stream';
66
import type { AuthMechanismProperties, MongoCredentials } from './cmap/auth/mongo_credentials';
77
import type { AuthMechanism } from './cmap/auth/providers';
88
import type { LEGAL_TCP_SOCKET_OPTIONS, LEGAL_TLS_SOCKET_OPTIONS } from './cmap/connect';
@@ -593,17 +593,17 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
593593
* @param pipeline - An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
594594
* @param options - Optional settings for the command
595595
*/
596-
watch<TSchema extends Document = Document>(
597-
pipeline: Document[] = [],
598-
options: ChangeStreamOptions = {}
599-
): ChangeStream<TSchema> {
596+
watch<
597+
TSchema extends Document = Document,
598+
TChange extends ChangeStreamDocument<TSchema> = ChangeStreamDocument<TSchema>
599+
>(pipeline: Document[] = [], options: ChangeStreamOptions = {}): ChangeStream<TSchema, TChange> {
600600
// Allow optionally not specifying a pipeline
601601
if (!Array.isArray(pipeline)) {
602602
options = pipeline;
603603
pipeline = [];
604604
}
605605

606-
return new ChangeStream<TSchema>(this, pipeline, resolveOptions(this, options));
606+
return new ChangeStream<TSchema, TChange>(this, pipeline, resolveOptions(this, options));
607607
}
608608

609609
/** Return the mongo client logger */

0 commit comments

Comments
 (0)