Skip to content

Commit ca9f3c2

Browse files
committed
WIP
1 parent c3f4467 commit ca9f3c2

File tree

5 files changed

+21
-53
lines changed

5 files changed

+21
-53
lines changed

src/connection_string.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,13 @@ export const OPTIONS = {
13111311
* TODO: NODE-5671 - remove internal flag
13121312
*/
13131313
mongodbLogMaxDocumentLength: { type: 'uint' }
1314-
} as Record<keyof MongoClientOptions, OptionDescriptor>;
1314+
} as Record<
1315+
keyof Omit<
1316+
MongoClientOptions,
1317+
'__enableMongoLogger' | '__internalLoggerConfig' | '__skipPingOnConnect'
1318+
>,
1319+
OptionDescriptor
1320+
>;
13151321

13161322
export const DEFAULT_OPTIONS = new CaseInsensitiveMap(
13171323
Object.entries(OPTIONS)

src/mongo_client.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,6 @@ export interface MongoOptions
10101010
tlsCRLFile?: string;
10111011
tlsCertificateKeyFile?: string;
10121012

1013-
/** @internal */
1014-
[featureFlag: symbol]: any;
1015-
10161013
/**
10171014
* @internal
10181015
* TODO: NODE-5671 - remove internal flag
@@ -1024,4 +1021,10 @@ export interface MongoOptions
10241021
*/
10251022
mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable;
10261023
timeoutMS?: number;
1024+
/** @internal */
1025+
__skipPingOnConnect?: boolean;
1026+
/** @internal */
1027+
__internalLoggerConfig?: Document;
1028+
/** @internal */
1029+
__enableMongoLogger?: boolean;
10271030
}

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[__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[__skipPingOnConnect];
144+
delete client.s.options.__skipPingOnConnect;
145145
}
146146
}
147147
return client.topology;

src/sdam/topology.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */
@@ -466,7 +466,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
466466
readPreferenceServerSelector(readPreference),
467467
selectServerOptions
468468
);
469-
const skipPingOnConnect = this.s.options[__skipPingOnConnect] === true;
469+
const skipPingOnConnect = this.s.options.__skipPingOnConnect === true;
470470
if (!skipPingOnConnect && this.s.credentials) {
471471
await server.command(ns('admin.$cmd'), { ping: 1 }, { timeoutContext });
472472
stateTransition(this, STATE_CONNECTED);

test/unit/connection_string.test.ts

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
COSMOS_DB_MSG,
1313
DEFAULT_ALLOWED_HOSTS,
1414
DOCUMENT_DB_MSG,
15-
FEATURE_FLAGS,
1615
type Log,
1716
MongoAPIError,
1817
MongoClient,
@@ -748,43 +747,6 @@ describe('Connection String', function () {
748747
});
749748
});
750749

751-
describe('feature flags', () => {
752-
it('should be stored in the FEATURE_FLAGS Set', () => {
753-
expect(FEATURE_FLAGS.size).to.equal(3);
754-
expect(FEATURE_FLAGS.has(__skipPingOnConnect)).to.be.true;
755-
expect(FEATURE_FLAGS.has(__enableMongoLogger)).to.be.true;
756-
expect(FEATURE_FLAGS.has(__internalLoggerConfig)).to.be.true;
757-
// Add more flags here
758-
});
759-
760-
it('should should ignore unknown symbols', () => {
761-
const randomFlag = Symbol();
762-
const client = new MongoClient('mongodb://iLoveJavaScript', { [randomFlag]: 23n });
763-
expect(client.s.options).to.not.have.property(randomFlag);
764-
});
765-
766-
it('should be prefixed with @@mdb.', () => {
767-
for (const flag of FEATURE_FLAGS) {
768-
expect(flag).to.be.a('symbol');
769-
expect(flag).to.have.property('description');
770-
expect(flag.description).to.match(/@@mdb\..+/);
771-
}
772-
});
773-
774-
it('should only exist if specified on options', () => {
775-
const flag = Array.from(FEATURE_FLAGS)[0]; // grab a random supported flag
776-
const client = new MongoClient('mongodb://iLoveJavaScript', { [flag]: true });
777-
expect(client.s.options).to.have.property(flag, true);
778-
expect(client.options).to.have.property(flag, true);
779-
});
780-
781-
it('should support nullish values', () => {
782-
const flag = Array.from(FEATURE_FLAGS.keys())[0]; // grab a random supported flag
783-
const client = new MongoClient('mongodb://iLoveJavaScript', { [flag]: null });
784-
expect(client.s.options).to.have.property(flag, null);
785-
});
786-
});
787-
788750
describe('IPv6 host addresses', () => {
789751
it('should not allow multiple unbracketed portless localhost IPv6 addresses', () => {
790752
// Note there is no "port-full" version of this test, there's no way to distinguish when a port begins without brackets
@@ -874,8 +836,6 @@ describe('Connection String', function () {
874836
});
875837

876838
describe('when mongodbLogPath is in options', function () {
877-
const loggerFeatureFlag = __enableMongoLogger;
878-
879839
let stderrStub;
880840
let stdoutStub;
881841

@@ -891,7 +851,7 @@ describe('Connection String', function () {
891851
context('when option is `stderr`', function () {
892852
it('it is accessible through mongoLogger.logDestination', function () {
893853
const client = new MongoClient('mongodb://a/?mongodbLogPath=stderr', {
894-
[loggerFeatureFlag]: true
854+
__enableMongoLogger: true
895855
});
896856
const log: Log = { t: new Date(), c: 'ConnectionStringStdErr', s: 'error' };
897857
client.options.mongoLoggerOptions.logDestination.write(log);
@@ -903,7 +863,7 @@ describe('Connection String', function () {
903863
context('when option is `stdout`', function () {
904864
it('it is accessible through mongoLogger.logDestination', function () {
905865
const client = new MongoClient('mongodb://a/?mongodbLogPath=stdout', {
906-
[loggerFeatureFlag]: true
866+
__enableMongoLogger: true
907867
});
908868
const log: Log = { t: new Date(), c: 'ConnectionStringStdOut', s: 'error' };
909869
client.options.mongoLoggerOptions.logDestination.write(log);
@@ -916,7 +876,7 @@ describe('Connection String', function () {
916876
it('should throw error at construction', function () {
917877
expect(
918878
() =>
919-
new MongoClient('mongodb://a/?mongodbLogPath=stdnothing', { [loggerFeatureFlag]: true })
879+
new MongoClient('mongodb://a/?mongodbLogPath=stdnothing', { __enableMongoLogger: true })
920880
).to.throw(MongoAPIError);
921881
});
922882
});
@@ -931,7 +891,6 @@ describe('Connection String', function () {
931891
process.env.MONGODB_LOG_CLIENT = undefined;
932892
});
933893

934-
const loggerFeatureFlag = __enableMongoLogger;
935894
const test_cases = [
936895
['non-SRV example uri', 'mongodb://a.example.com:27017,b.example.com:27017/', ''],
937896
['non-SRV default uri', 'mongodb://a.mongodb.net:27017', ''],
@@ -960,7 +919,7 @@ describe('Connection String', function () {
960919
}
961920
};
962921
new MongoClient(uri, {
963-
[loggerFeatureFlag]: true,
922+
__enableMongoLogger: true,
964923
mongodbLogPath: stream
965924
});
966925

0 commit comments

Comments
 (0)