Skip to content

Commit f56f772

Browse files
authored
chore: get default user config from schema (#710)
1 parent 1c49353 commit f56f772

File tree

14 files changed

+392
-395
lines changed

14 files changed

+392
-395
lines changed

eslint-rules/enforce-zod-v4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from "path";
33

44
// The file that is allowed to import from zod/v4
55
const configFilePath = path.resolve(import.meta.dirname, "../src/common/config.ts");
6+
const schemasFilePath = path.resolve(import.meta.dirname, "../src/common/schemas.ts");
67

78
// Ref: https://eslint.org/docs/latest/extend/custom-rules
89
export default {

scripts/generateArguments.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import { readFileSync, writeFileSync } from "fs";
1212
import { join, dirname } from "path";
1313
import { fileURLToPath } from "url";
14-
import { OPTIONS, UserConfigSchema, defaultUserConfig, configRegistry } from "../src/common/config.js";
14+
import { UserConfigSchema, configRegistry } from "../src/common/config.js";
1515
import assert from "assert";
1616
import { execSync } from "child_process";
17+
import { OPTIONS } from "../src/common/argsParserOptions.js";
1718

1819
const __filename = fileURLToPath(import.meta.url);
1920
const __dirname = dirname(__filename);
@@ -68,7 +69,8 @@ function extractZodDescriptions(): Record<string, ConfigMetadata> {
6869
let description = schema.description || `Configuration option: ${key}`;
6970

7071
if ("innerType" in schema.def) {
71-
if (schema.def.innerType.def.type === "array") {
72+
// "pipe" is used for our comma-separated arrays
73+
if (schema.def.innerType.def.type === "pipe") {
7274
assert(
7375
description.startsWith("An array of"),
7476
`Field description for field "${key}" with array type does not start with 'An array of'`
@@ -255,9 +257,7 @@ function generateReadmeConfigTable(argumentInfos: ArgumentInfo[]): string {
255257
const cliOption = `\`${argumentInfo.configKey}\``;
256258
const envVarName = `\`${argumentInfo.name}\``;
257259

258-
// Get default value from Zod schema or fallback to defaultUserConfig
259-
const config = defaultUserConfig as unknown as Record<string, unknown>;
260-
const defaultValue = argumentInfo.defaultValue ?? config[argumentInfo.configKey];
260+
const defaultValue = argumentInfo.defaultValue;
261261

262262
let defaultValueString = argumentInfo.defaultValueDescription ?? "`<not set>`";
263263
if (!argumentInfo.defaultValueDescription && defaultValue !== undefined && defaultValue !== null) {

src/common/argsParserOptions.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
type ArgsParserOptions = {
2+
string: string[];
3+
number: string[];
4+
boolean: string[];
5+
array: string[];
6+
alias: Record<string, string>;
7+
configuration: Record<string, boolean>;
8+
};
9+
10+
// TODO: Export this from arg-parser or find a better way to do this
11+
// From: https://github.com/mongodb-js/mongosh/blob/main/packages/cli-repl/src/arg-parser.ts
12+
export const OPTIONS = {
13+
number: ["maxDocumentsPerQuery", "maxBytesPerQuery"],
14+
string: [
15+
"apiBaseUrl",
16+
"apiClientId",
17+
"apiClientSecret",
18+
"connectionString",
19+
"httpHost",
20+
"httpPort",
21+
"idleTimeoutMs",
22+
"logPath",
23+
"notificationTimeoutMs",
24+
"telemetry",
25+
"transport",
26+
"apiVersion",
27+
"authenticationDatabase",
28+
"authenticationMechanism",
29+
"browser",
30+
"db",
31+
"gssapiHostName",
32+
"gssapiServiceName",
33+
"host",
34+
"oidcFlows",
35+
"oidcRedirectUri",
36+
"password",
37+
"port",
38+
"sslCAFile",
39+
"sslCRLFile",
40+
"sslCertificateSelector",
41+
"sslDisabledProtocols",
42+
"sslPEMKeyFile",
43+
"sslPEMKeyPassword",
44+
"sspiHostnameCanonicalization",
45+
"sspiRealmOverride",
46+
"tlsCAFile",
47+
"tlsCRLFile",
48+
"tlsCertificateKeyFile",
49+
"tlsCertificateKeyFilePassword",
50+
"tlsCertificateSelector",
51+
"tlsDisabledProtocols",
52+
"username",
53+
"atlasTemporaryDatabaseUserLifetimeMs",
54+
"exportsPath",
55+
"exportTimeoutMs",
56+
"exportCleanupIntervalMs",
57+
"voyageApiKey",
58+
],
59+
boolean: [
60+
"apiDeprecationErrors",
61+
"apiStrict",
62+
"disableEmbeddingsValidation",
63+
"help",
64+
"indexCheck",
65+
"ipv6",
66+
"nodb",
67+
"oidcIdTokenAsAccessToken",
68+
"oidcNoNonce",
69+
"oidcTrustedEndpoint",
70+
"readOnly",
71+
"retryWrites",
72+
"ssl",
73+
"sslAllowInvalidCertificates",
74+
"sslAllowInvalidHostnames",
75+
"sslFIPSMode",
76+
"tls",
77+
"tlsAllowInvalidCertificates",
78+
"tlsAllowInvalidHostnames",
79+
"tlsFIPSMode",
80+
"version",
81+
],
82+
array: ["disabledTools", "loggers", "confirmationRequiredTools", "previewFeatures"],
83+
alias: {
84+
h: "help",
85+
p: "password",
86+
u: "username",
87+
"build-info": "buildInfo",
88+
browser: "browser",
89+
oidcDumpTokens: "oidcDumpTokens",
90+
oidcRedirectUrl: "oidcRedirectUri",
91+
oidcIDTokenAsAccessToken: "oidcIdTokenAsAccessToken",
92+
},
93+
configuration: {
94+
"camel-case-expansion": false,
95+
"unknown-options-as-args": true,
96+
"parse-positional-numbers": false,
97+
"parse-numbers": false,
98+
"greedy-arrays": true,
99+
"short-option-groups": false,
100+
},
101+
} as Readonly<ArgsParserOptions>;
102+
103+
export const ALL_CONFIG_KEYS = new Set(
104+
(OPTIONS.string as readonly string[])
105+
.concat(OPTIONS.number)
106+
.concat(OPTIONS.array)
107+
.concat(OPTIONS.boolean)
108+
.concat(Object.keys(OPTIONS.alias))
109+
);

0 commit comments

Comments
 (0)