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
+20 -85
View File
@@ -21,23 +21,7 @@ import {
type PublicServiceTarget,
} from "./platform-infra-public-service";
import {
yamlAbsolutePathField,
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 +29,25 @@ const configFile = rootPath("config", "platform-infra", "n8n.yaml");
const configLabel = "config/platform-infra/n8n.yaml";
const serviceName = "n8n";
const fieldManager = "unidesk-platform-n8n";
const {
asRecord,
objectField,
arrayOfRecords,
stringField,
integerField,
booleanField,
stringArrayField,
numberArrayField,
enumField,
kubernetesNameField,
sourceRefField,
envKeyField,
pgIdentifierField,
hostField,
portField,
absolutePathField,
httpsUrlField,
} = createYamlFieldReader(configLabel);
interface N8nConfig {
version: number;
@@ -1065,74 +1068,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 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);