Skip to content

Commit fb3bc3f

Browse files
clean up logic when flattening options object
1 parent 0a89c73 commit fb3bc3f

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/connection_string.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ function getUint(name: string, value: unknown): number {
204204
return parsedValue;
205205
}
206206

207+
208+
function toArray<T>(value: T): T[];
209+
function toArray<T>(value: T[]): T[];
210+
function toArray<T>(value: T | T[]): T[] {
211+
return Array.isArray(value) ? value : [value];
212+
}
213+
207214
function toRecord(value: string): Record<string, any> {
208215
const record = Object.create(null);
209216
const keyValuePairs = value.split(',');
@@ -324,23 +331,11 @@ export function parseOptions(
324331
]);
325332

326333
for (const key of allKeys) {
327-
const values = [];
328-
if (objectOptions.has(key)) {
329-
const options = Array.isArray(objectOptions.get(key))
330-
? objectOptions.get(key)
331-
: [objectOptions.get(key)];
332-
values.push(...options);
333-
}
334-
if (urlOptions.has(key)) {
335-
const options = urlOptions.get(key) ?? [];
336-
values.push(...options);
337-
}
338-
if (DEFAULT_OPTIONS.has(key)) {
339-
const options = Array.isArray(DEFAULT_OPTIONS.get(key))
340-
? DEFAULT_OPTIONS.get(key)
341-
: [DEFAULT_OPTIONS.get(key)];
342-
values.push(...options);
343-
}
334+
const values = [objectOptions, urlOptions, DEFAULT_OPTIONS].flatMap(optionsObject => {
335+
const options = optionsObject.get(key) ?? [];
336+
return toArray(options);
337+
});
338+
344339
allOptions.set(key, values);
345340
}
346341

test/unit/assorted/uri_options.spec.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ describe('URI option spec tests', function () {
2828
'tlsDisableCertificateRevocationCheck can be set to true',
2929
'tlsDisableCertificateRevocationCheck can be set to false',
3030
'tlsDisableOCSPEndpointCheck can be set to true',
31-
'tlsDisableOCSPEndpointCheck can be set to false',
32-
33-
// TODO(NODE-3813): read preference tag issue: parsing rack:1 as rack:true
34-
'Valid read preference options are parsed correctly'
31+
'tlsDisableOCSPEndpointCheck can be set to false'
3532
];
3633

3734
const testsThatDoNotThrowOnWarn = [
@@ -60,6 +57,7 @@ describe('URI option spec tests', function () {
6057

6158
for (const test of suite.tests) {
6259
it(`${test.description}`, function () {
60+
console.error(test);
6361
if (skipTests.includes(test.description)) {
6462
return this.skip();
6563
}

0 commit comments

Comments
 (0)