Skip to content

Commit f6d7868

Browse files
authored
refactor(NODE-4144): remove all symbol properties (#4351)
1 parent 2f9ad4d commit f6d7868

20 files changed

+316
-477
lines changed

src/bulk/common.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ import {
3030
} from '../utils';
3131
import { WriteConcern } from '../write_concern';
3232

33-
/** @internal */
34-
const kServerError = Symbol('serverError');
35-
3633
/** @public */
3734
export const BatchType = Object.freeze({
3835
INSERT: 1,
@@ -315,29 +312,29 @@ export interface WriteConcernErrorData {
315312
*/
316313
export class WriteConcernError {
317314
/** @internal */
318-
[kServerError]: WriteConcernErrorData;
315+
private serverError: WriteConcernErrorData;
319316

320317
constructor(error: WriteConcernErrorData) {
321-
this[kServerError] = error;
318+
this.serverError = error;
322319
}
323320

324321
/** Write concern error code. */
325322
get code(): number | undefined {
326-
return this[kServerError].code;
323+
return this.serverError.code;
327324
}
328325

329326
/** Write concern error message. */
330327
get errmsg(): string | undefined {
331-
return this[kServerError].errmsg;
328+
return this.serverError.errmsg;
332329
}
333330

334331
/** Write concern error info. */
335332
get errInfo(): Document | undefined {
336-
return this[kServerError].errInfo;
333+
return this.serverError.errInfo;
337334
}
338335

339336
toJSON(): WriteConcernErrorData {
340-
return this[kServerError];
337+
return this.serverError;
341338
}
342339

343340
toString(): string {

src/change_stream.ts

+21-33
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ import type { ServerSessionId } from './sessions';
2424
import { CSOTTimeoutContext, type TimeoutContext } from './timeout';
2525
import { filterOptions, getTopology, type MongoDBNamespace, squashError } from './utils';
2626

27-
/** @internal */
28-
const kCursorStream = Symbol('cursorStream');
29-
/** @internal */
30-
const kClosed = Symbol('closed');
31-
/** @internal */
32-
const kMode = Symbol('mode');
33-
3427
const CHANGE_STREAM_OPTIONS = [
3528
'resumeAfter',
3629
'startAfter',
@@ -584,14 +577,14 @@ export class ChangeStream<
584577
namespace: MongoDBNamespace;
585578
type: symbol;
586579
/** @internal */
587-
cursor: ChangeStreamCursor<TSchema, TChange>;
580+
private cursor: ChangeStreamCursor<TSchema, TChange>;
588581
streamOptions?: CursorStreamOptions;
589582
/** @internal */
590-
[kCursorStream]?: Readable & AsyncIterable<TChange>;
583+
private cursorStream?: Readable & AsyncIterable<TChange>;
591584
/** @internal */
592-
[kClosed]: boolean;
585+
private isClosed: boolean;
593586
/** @internal */
594-
[kMode]: false | 'iterator' | 'emitter';
587+
private mode: false | 'iterator' | 'emitter';
595588

596589
/** @event */
597590
static readonly RESPONSE = RESPONSE;
@@ -668,8 +661,8 @@ export class ChangeStream<
668661
// Create contained Change Stream cursor
669662
this.cursor = this._createChangeStreamCursor(options);
670663

671-
this[kClosed] = false;
672-
this[kMode] = false;
664+
this.isClosed = false;
665+
this.mode = false;
673666

674667
// Listen for any `change` listeners being added to ChangeStream
675668
this.on('newListener', eventName => {
@@ -680,7 +673,7 @@ export class ChangeStream<
680673

681674
this.on('removeListener', eventName => {
682675
if (eventName === 'change' && this.listenerCount('change') === 0 && this.cursor) {
683-
this[kCursorStream]?.removeAllListeners('data');
676+
this.cursorStream?.removeAllListeners('data');
684677
}
685678
});
686679

@@ -692,11 +685,6 @@ export class ChangeStream<
692685
}
693686
}
694687

695-
/** @internal */
696-
get cursorStream(): (Readable & AsyncIterable<TChange>) | undefined {
697-
return this[kCursorStream];
698-
}
699-
700688
/** The cached resume token that is used to resume after the most recently returned change. */
701689
get resumeToken(): ResumeToken {
702690
return this.cursor?.resumeToken;
@@ -826,8 +814,8 @@ export class ChangeStream<
826814
}
827815

828816
/** Is the cursor closed */
829-
get closed(): boolean {
830-
return this[kClosed] || this.cursor.closed;
817+
public get closed(): boolean {
818+
return this.isClosed || this.cursor.closed;
831819
}
832820

833821
/**
@@ -836,7 +824,7 @@ export class ChangeStream<
836824
async close(): Promise<void> {
837825
this.timeoutContext?.clear();
838826
this.timeoutContext = undefined;
839-
this[kClosed] = true;
827+
this.isClosed = true;
840828

841829
const cursor = this.cursor;
842830
try {
@@ -865,24 +853,24 @@ export class ChangeStream<
865853

866854
/** @internal */
867855
private _setIsEmitter(): void {
868-
if (this[kMode] === 'iterator') {
856+
if (this.mode === 'iterator') {
869857
// TODO(NODE-3485): Replace with MongoChangeStreamModeError
870858
throw new MongoAPIError(
871859
'ChangeStream cannot be used as an EventEmitter after being used as an iterator'
872860
);
873861
}
874-
this[kMode] = 'emitter';
862+
this.mode = 'emitter';
875863
}
876864

877865
/** @internal */
878866
private _setIsIterator(): void {
879-
if (this[kMode] === 'emitter') {
867+
if (this.mode === 'emitter') {
880868
// TODO(NODE-3485): Replace with MongoChangeStreamModeError
881869
throw new MongoAPIError(
882870
'ChangeStream cannot be used as an iterator after being used as an EventEmitter'
883871
);
884872
}
885-
this[kMode] = 'iterator';
873+
this.mode = 'iterator';
886874
}
887875

888876
/**
@@ -947,8 +935,8 @@ export class ChangeStream<
947935
/** @internal */
948936
private _streamEvents(cursor: ChangeStreamCursor<TSchema, TChange>): void {
949937
this._setIsEmitter();
950-
const stream = this[kCursorStream] ?? cursor.stream();
951-
this[kCursorStream] = stream;
938+
const stream = this.cursorStream ?? cursor.stream();
939+
this.cursorStream = stream;
952940
stream.on('data', change => {
953941
try {
954942
const processedChange = this._processChange(change);
@@ -963,18 +951,18 @@ export class ChangeStream<
963951

964952
/** @internal */
965953
private _endStream(): void {
966-
const cursorStream = this[kCursorStream];
954+
const cursorStream = this.cursorStream;
967955
if (cursorStream) {
968956
['data', 'close', 'end', 'error'].forEach(event => cursorStream.removeAllListeners(event));
969957
cursorStream.destroy();
970958
}
971959

972-
this[kCursorStream] = undefined;
960+
this.cursorStream = undefined;
973961
}
974962

975963
/** @internal */
976964
private _processChange(change: TChange | null): TChange {
977-
if (this[kClosed]) {
965+
if (this.isClosed) {
978966
// TODO(NODE-3485): Replace with MongoChangeStreamClosedError
979967
throw new MongoAPIError(CHANGESTREAM_CLOSED_ERROR);
980968
}
@@ -1002,7 +990,7 @@ export class ChangeStream<
1002990
/** @internal */
1003991
private _processErrorStreamMode(changeStreamError: AnyError, cursorInitialized: boolean) {
1004992
// If the change stream has been closed explicitly, do not process error.
1005-
if (this[kClosed]) return;
993+
if (this.isClosed) return;
1006994

1007995
if (
1008996
cursorInitialized &&
@@ -1034,7 +1022,7 @@ export class ChangeStream<
10341022

10351023
/** @internal */
10361024
private async _processErrorIteratorMode(changeStreamError: AnyError, cursorInitialized: boolean) {
1037-
if (this[kClosed]) {
1025+
if (this.isClosed) {
10381026
// TODO(NODE-3485): Replace with MongoChangeStreamClosedError
10391027
throw new MongoAPIError(CHANGESTREAM_CLOSED_ERROR);
10401028
}

0 commit comments

Comments
 (0)