refactor: add yaml subfield label helper (#365)

Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
Lyon
2026-06-14 13:04:53 +08:00
committed by GitHub
parent c525bed7f8
commit 2b80832add
2 changed files with 7 additions and 7 deletions
@@ -185,6 +185,10 @@ export function yamlFieldLabel(configLabel: string, path: string, key: string):
return `${configLabel}.${prefix}${key}`;
}
export function yamlSubFieldLabel(label: string, key: string): string {
return label.endsWith(".") ? `${label}${key}` : `${label}.${key}`;
}
export function yamlRecord(value: unknown, label: string): Record<string, unknown> {
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} must be a YAML object`);
return value as Record<string, unknown>;
+3 -7
View File
@@ -7,7 +7,7 @@ import { startJob } from "./jobs";
import type { RenderedCliResult } from "./output";
import { pk01CaddyMergeManagedBlocksPython, renderCaddyManagedBlock, renderSimpleReverseProxyCaddySiteBlock } from "./pk01-caddy";
import { capture, compactCapture, parseJsonOutput, prepareFrpcSecret, shQuote } from "./platform-infra-public-service";
import { yamlBooleanField, yamlIntegerField } from "./platform-infra-ops-library";
import { yamlBooleanField, yamlIntegerField, yamlSubFieldLabel } from "./platform-infra-ops-library";
import { fingerprintSecretValues, parseEnvFile, readEnvSourceFile, readTextFile, redactRepoPath, requiredEnvValue } from "./secrets";
const serviceName = "sub2api";
@@ -785,7 +785,7 @@ function objectField(obj: Record<string, unknown>, key: string, path: string): R
}
function booleanField(obj: Record<string, unknown>, key: string, path: string): boolean {
return yamlBooleanField(obj, key, yamlConfigLabel(path), path);
return yamlBooleanField(obj, key, yamlSubFieldLabel(configPath, path), "");
}
function stringArrayField(obj: Record<string, unknown>, key: string, path: string): string[] {
@@ -803,7 +803,7 @@ function enumField<const T extends readonly string[]>(obj: Record<string, unknow
}
function integerField(obj: Record<string, unknown>, key: string, path: string): number {
return yamlIntegerField(obj, key, yamlConfigLabel(path), path);
return yamlIntegerField(obj, key, yamlSubFieldLabel(configPath, path), "");
}
function integerArrayField(obj: Record<string, unknown>, key: string, path: string): number[] {
@@ -814,10 +814,6 @@ function integerArrayField(obj: Record<string, unknown>, key: string, path: stri
return value;
}
function yamlConfigLabel(path: string): string {
return path.length === 0 ? `${configPath}.` : configPath;
}
function isKubernetesName(value: string): boolean {
return /^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/u.test(value);
}