Skip to content

Commit f759ff7

Browse files
committed
chore: poc blacklist
1 parent c18106a commit f759ff7

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

src/change_stream.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { AggregateOptions } from './operations/aggregate';
2020
import type { OperationParent } from './operations/command';
2121
import type { ServerSessionId } from './sessions';
2222
import { CSOTTimeoutContext, type TimeoutContext } from './timeout';
23-
import { getTopology, type MongoDBNamespace, squashError } from './utils';
23+
import { type AnyOptions, getTopology, type MongoDBNamespace, squashError } from './utils';
2424

2525
const CHANGE_DOMAIN_TYPES = {
2626
COLLECTION: Symbol('Collection'),
@@ -34,6 +34,34 @@ const NO_RESUME_TOKEN_ERROR =
3434
'A change stream document has been received that lacks a resume token (_id).';
3535
const CHANGESTREAM_CLOSED_ERROR = 'ChangeStream is closed';
3636

37+
const INVALID_STAGE_OPTIONS = [
38+
'raw',
39+
'useBigInt64',
40+
'promoteLongs',
41+
'promoteValues',
42+
'promoteBuffers',
43+
'ignoreUndefined',
44+
'bsonRegExp',
45+
'serializeFunctions',
46+
'fieldsAsRaw',
47+
'enableUtf8Validation',
48+
'timeoutMS',
49+
'readPreference'
50+
];
51+
52+
export function filterOutOptions(options: AnyOptions, names: ReadonlyArray<string>): AnyOptions {
53+
const filterOptions: AnyOptions = {};
54+
55+
for (const name in options) {
56+
if (!names.includes(name)) {
57+
filterOptions[name] = options[name];
58+
}
59+
}
60+
61+
// Filtered options
62+
return filterOptions;
63+
}
64+
3765
/**
3866
* Represents the logical starting point for a new ChangeStream or resuming a ChangeStream on the server.
3967
* @see https://www.mongodb.com/docs/manual/changeStreams/#std-label-change-stream-resume
@@ -891,7 +919,7 @@ export class ChangeStream<
891919
private _createChangeStreamCursor(
892920
options: ChangeStreamOptions | ChangeStreamCursorOptions
893921
): ChangeStreamCursor<TSchema, TChange> {
894-
const changeStreamStageOptions: Document = { ...options };
922+
const changeStreamStageOptions: Document = filterOutOptions(options, INVALID_STAGE_OPTIONS);
895923
if (this.type === CHANGE_DOMAIN_TYPES.CLUSTER) {
896924
changeStreamStageOptions.allChangesForCluster = true;
897925
}

0 commit comments

Comments
 (0)