Skip to content

Commit 80c4d74

Browse files
W-A-Jamesnbbeeken
andauthored
refactor(NODE-6610): replace feature flag symbols with internal properties (#4354)
Co-authored-by: Neal Beeken <neal.beeken@mongodb.com>
1 parent e972bb8 commit 80c4d74

File tree

14 files changed

+232
-284
lines changed

14 files changed

+232
-284
lines changed

src/connection_string.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,6 @@ export function parseOptions(
249249

250250
const mongoOptions = Object.create(null);
251251

252-
// Feature flags
253-
for (const flag of Object.getOwnPropertySymbols(options)) {
254-
if (FEATURE_FLAGS.has(flag)) {
255-
mongoOptions[flag] = options[flag];
256-
}
257-
}
258-
259252
mongoOptions.hosts = isSRV ? [] : hosts.map(HostAddress.fromString);
260253

261254
const urlOptions = new CaseInsensitiveMap<unknown[]>();
@@ -515,12 +508,11 @@ export function parseOptions(
515508
);
516509
}
517510

518-
const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger');
519-
mongoOptions[loggerFeatureFlag] = mongoOptions[loggerFeatureFlag] ?? false;
511+
mongoOptions.__enableMongoLogger = mongoOptions.__enableMongoLogger ?? false;
520512

521513
let loggerEnvOptions: MongoLoggerEnvOptions = {};
522514
let loggerClientOptions: MongoLoggerMongoClientOptions = {};
523-
if (mongoOptions[loggerFeatureFlag]) {
515+
if (mongoOptions.__enableMongoLogger) {
524516
loggerEnvOptions = {
525517
MONGODB_LOG_COMMAND: process.env.MONGODB_LOG_COMMAND,
526518
MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY,
@@ -530,7 +522,7 @@ export function parseOptions(
530522
MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL,
531523
MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH,
532524
MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH,
533-
...mongoOptions[Symbol.for('@@mdb.internalLoggerConfig')]
525+
...mongoOptions.__internalLoggerConfig
534526
};
535527
loggerClientOptions = {
536528
mongodbLogPath: mongoOptions.mongodbLogPath,
@@ -1317,21 +1309,14 @@ export const OPTIONS = {
13171309
* @internal
13181310
* TODO: NODE-5671 - remove internal flag
13191311
*/
1320-
mongodbLogMaxDocumentLength: { type: 'uint' }
1312+
mongodbLogMaxDocumentLength: { type: 'uint' },
1313+
__enableMongoLogger: { type: 'boolean' },
1314+
__skipPingOnConnect: { type: 'boolean' },
1315+
__internalLoggerConfig: { type: 'record' }
13211316
} as Record<keyof MongoClientOptions, OptionDescriptor>;
13221317

13231318
export const DEFAULT_OPTIONS = new CaseInsensitiveMap(
13241319
Object.entries(OPTIONS)
13251320
.filter(([, descriptor]) => descriptor.default != null)
13261321
.map(([k, d]) => [k, d.default])
13271322
);
1328-
1329-
/**
1330-
* Set of permitted feature flags
1331-
* @internal
1332-
*/
1333-
export const FEATURE_FLAGS = new Set([
1334-
Symbol.for('@@mdb.skipPingOnConnect'),
1335-
Symbol.for('@@mdb.enableMongoLogger'),
1336-
Symbol.for('@@mdb.internalLoggerConfig')
1337-
]);

src/mongo_client.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
type LogComponentSeveritiesClientOptions,
2727
type MongoDBLogWritable,
2828
MongoLogger,
29+
type MongoLoggerEnvOptions,
2930
type MongoLoggerOptions,
3031
SeverityLevel
3132
} from './mongo_logger';
@@ -299,7 +300,11 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
299300
mongodbLogMaxDocumentLength?: number;
300301

301302
/** @internal */
302-
[featureFlag: symbol]: any;
303+
__skipPingOnConnect?: boolean;
304+
/** @internal */
305+
__internalLoggerConfig?: MongoLoggerEnvOptions;
306+
/** @internal */
307+
__enableMongoLogger?: boolean;
303308
}
304309

305310
/** @public */
@@ -1006,9 +1011,6 @@ export interface MongoOptions
10061011
tlsCRLFile?: string;
10071012
tlsCertificateKeyFile?: string;
10081013

1009-
/** @internal */
1010-
[featureFlag: symbol]: any;
1011-
10121014
/**
10131015
* @internal
10141016
* TODO: NODE-5671 - remove internal flag
@@ -1020,4 +1022,10 @@ export interface MongoOptions
10201022
*/
10211023
mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable;
10221024
timeoutMS?: number;
1025+
/** @internal */
1026+
__skipPingOnConnect?: boolean;
1027+
/** @internal */
1028+
__internalLoggerConfig?: Document;
1029+
/** @internal */
1030+
__enableMongoLogger?: boolean;
10231031
}

src/operations/execute_operation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async function autoConnect(client: MongoClient): Promise<Topology> {
131131
if (client.s.hasBeenClosed) {
132132
throw new MongoNotConnectedError('Client must be connected before running operations');
133133
}
134-
client.s.options[Symbol.for('@@mdb.skipPingOnConnect')] = true;
134+
client.s.options.__skipPingOnConnect = true;
135135
try {
136136
await client.connect();
137137
if (client.topology == null) {
@@ -141,7 +141,7 @@ async function autoConnect(client: MongoClient): Promise<Topology> {
141141
}
142142
return client.topology;
143143
} finally {
144-
delete client.s.options[Symbol.for('@@mdb.skipPingOnConnect')];
144+
delete client.s.options.__skipPingOnConnect;
145145
}
146146
}
147147
return client.topology;

src/sdam/topology.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
33
import type { ConnectionEvents } from '../cmap/connection';
44
import type { ConnectionPoolEvents } from '../cmap/connection_pool';
55
import type { ClientMetadata } from '../cmap/handshake/client_metadata';
6-
import { DEFAULT_OPTIONS, FEATURE_FLAGS } from '../connection_string';
6+
import { DEFAULT_OPTIONS } from '../connection_string';
77
import {
88
CLOSE,
99
CONNECT,
@@ -153,7 +153,7 @@ export interface TopologyOptions extends BSONSerializeOptions, ServerOptions {
153153
serverMonitoringMode: ServerMonitoringMode;
154154
/** MongoDB server API version */
155155
serverApi?: ServerApi;
156-
[featureFlag: symbol]: any;
156+
__skipPingOnConnect?: boolean;
157157
}
158158

159159
/** @public */
@@ -251,8 +251,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
251251
// Options should only be undefined in tests, MongoClient will always have defined options
252252
options = options ?? {
253253
hosts: [HostAddress.fromString('localhost:27017')],
254-
...Object.fromEntries(DEFAULT_OPTIONS.entries()),
255-
...Object.fromEntries(FEATURE_FLAGS.entries())
254+
...Object.fromEntries(DEFAULT_OPTIONS.entries())
256255
};
257256

258257
if (typeof seeds === 'string') {
@@ -466,7 +465,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
466465
readPreferenceServerSelector(readPreference),
467466
selectServerOptions
468467
);
469-
const skipPingOnConnect = this.s.options[Symbol.for('@@mdb.skipPingOnConnect')] === true;
468+
const skipPingOnConnect = this.s.options.__skipPingOnConnect === true;
470469
if (!skipPingOnConnect && this.s.credentials) {
471470
await server.command(ns('admin.$cmd'), { ping: 1 }, { timeoutContext });
472471
stateTransition(this, STATE_CONNECTED);

test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CapturingMongoClient extends MongoClient {
3434
commandStartedEvents: Array<CommandStartedEvent> = [];
3535
clientsCreated = 0;
3636
constructor(url: string, options: MongoClientOptions = {}) {
37-
options = { ...options, monitorCommands: true, [Symbol.for('@@mdb.skipPingOnConnect')]: true };
37+
options = { ...options, monitorCommands: true, __skipPingOnConnect: true };
3838
if (process.env.MONGODB_API_VERSION) {
3939
options.serverApi = process.env.MONGODB_API_VERSION as MongoClientOptions['serverApi'];
4040
}

test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { expect } from 'chai';
33
import { DEFAULT_MAX_DOCUMENT_LENGTH, type Document } from '../../mongodb';
44

55
describe('Command Logging and Monitoring Prose Tests', function () {
6-
const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger');
76
const ELLIPSES_LENGTH = 3;
87
let client;
98
let writable;
@@ -40,7 +39,7 @@ describe('Command Logging and Monitoring Prose Tests', function () {
4039
client = this.configuration.newClient(
4140
{},
4241
{
43-
[loggerFeatureFlag]: true,
42+
__enableMongoLogger: true,
4443
mongodbLogPath: writable,
4544
mongodbLogComponentSeverities: {
4645
command: 'debug'
@@ -124,7 +123,7 @@ describe('Command Logging and Monitoring Prose Tests', function () {
124123
client = this.configuration.newClient(
125124
{},
126125
{
127-
[loggerFeatureFlag]: true,
126+
__enableMongoLogger: true,
128127
mongodbLogPath: writable,
129128
mongodbLogComponentSeverities: {
130129
command: 'debug'
@@ -181,7 +180,7 @@ describe('Command Logging and Monitoring Prose Tests', function () {
181180
client = this.configuration.newClient(
182181
{},
183182
{
184-
[loggerFeatureFlag]: true,
183+
__enableMongoLogger: true,
185184
mongodbLogPath: writable,
186185
mongodbLogComponentSeverities: {
187186
command: 'debug'

test/integration/node-specific/feature_flags.test.ts

Lines changed: 0 additions & 168 deletions
This file was deleted.

test/integration/node-specific/ipv6.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('IPv6 Addresses', () => {
3131

3232
ipv6Hosts = this.configuration.options.hostAddresses.map(({ port }) => `[::1]:${port}`);
3333
client = this.configuration.newClient(`mongodb://${ipv6Hosts.join(',')}/test`, {
34-
[Symbol.for('@@mdb.skipPingOnConnect')]: true,
34+
__skipPingOnConnect: true,
3535
maxPoolSize: 1
3636
});
3737
});

0 commit comments

Comments
 (0)