refactor: 抽取 YAML field reader factory

This commit is contained in:
Codex
2026-06-14 05:24:28 +00:00
parent cd76411969
commit c10f5c2189
3 changed files with 85 additions and 175 deletions
+21 -90
View File
@@ -19,24 +19,7 @@ import {
type FrpcSecretMaterial,
} from "./platform-infra-public-service";
import {
yamlAbsolutePathField,
yamlApiPathField,
yamlArrayOfRecords,
yamlBooleanField,
yamlEnumField,
yamlEnvKeyField,
yamlHostField,
yamlHttpsUrlField,
yamlIntegerArrayField,
yamlIntegerField,
yamlKubernetesNameField,
yamlObjectField,
yamlPgIdentifierField,
yamlPortField,
yamlRecord,
yamlSourceRefField,
yamlStringArrayField,
yamlStringField,
createYamlFieldReader,
} from "./platform-infra-ops-library";
import { fingerprintSecretValues, parseEnvFile, readEnvSourceFile, readTextFile, redactRepoPath, requiredEnvValue } from "./secrets";
@@ -45,6 +28,26 @@ const configLabel = "config/platform-infra/langbot.yaml";
const serviceName = "langbot";
const pluginRuntimeServiceName = "langbot-plugin-runtime";
const fieldManager = "unidesk-platform-langbot";
const {
asRecord,
objectField,
arrayOfRecords,
stringField,
integerField,
booleanField,
stringArrayField,
numberArrayField,
enumField,
kubernetesNameField,
sourceRefField,
envKeyField,
pgIdentifierField,
hostField,
portField,
absolutePathField,
apiPathField,
httpsUrlField,
} = createYamlFieldReader(configLabel);
interface LangBotConfig {
version: number;
@@ -1461,78 +1464,6 @@ function boolField(value: Record<string, unknown> | null, key: string, fallback:
return typeof value?.[key] === "boolean" ? value[key] : fallback;
}
function asRecord(value: unknown, path: string): Record<string, unknown> {
return yamlRecord(value, path);
}
function objectField(obj: Record<string, unknown>, key: string, path: string): Record<string, unknown> {
return yamlObjectField(obj, key, configLabel, path);
}
function arrayOfRecords(value: unknown, path: string): Record<string, unknown>[] {
return yamlArrayOfRecords(value, configLabel, path);
}
function stringField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlStringField(obj, key, configLabel, path);
}
function integerField(obj: Record<string, unknown>, key: string, path: string): number {
return yamlIntegerField(obj, key, configLabel, path);
}
function booleanField(obj: Record<string, unknown>, key: string, path: string): boolean {
return yamlBooleanField(obj, key, configLabel, path);
}
function stringArrayField(obj: Record<string, unknown>, key: string, path: string): string[] {
return yamlStringArrayField(obj, key, configLabel, path);
}
function numberArrayField(obj: Record<string, unknown>, key: string, path: string): number[] {
return yamlIntegerArrayField(obj, key, configLabel, path);
}
function enumField<const T extends readonly string[]>(obj: Record<string, unknown>, key: string, path: string, values: T): T[number] {
return yamlEnumField(obj, key, configLabel, path, values);
}
function kubernetesNameField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlKubernetesNameField(obj, key, configLabel, path);
}
function sourceRefField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlSourceRefField(obj, key, configLabel, path);
}
function envKeyField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlEnvKeyField(obj, key, configLabel, path);
}
function pgIdentifierField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlPgIdentifierField(obj, key, configLabel, path);
}
function hostField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlHostField(obj, key, configLabel, path);
}
function portField(obj: Record<string, unknown>, key: string, path: string): number {
return yamlPortField(obj, key, configLabel, path);
}
function absolutePathField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlAbsolutePathField(obj, key, configLabel, path);
}
function apiPathField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlApiPathField(obj, key, configLabel, path);
}
function httpsUrlField(obj: Record<string, unknown>, key: string, path: string): string {
return yamlHttpsUrlField(obj, key, configLabel, path);
}
function pvcSpec(record: Record<string, unknown>, path: string): PvcSpec {
const name = kubernetesNameField(record, "name", path);
const size = stringField(record, "size", path);