From 2b80832addad1e68ff2d0951f3966b7a845db469 Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Sun, 14 Jun 2026 13:04:53 +0800 Subject: [PATCH] refactor: add yaml subfield label helper (#365) Co-authored-by: Codex --- scripts/src/platform-infra-ops-library.ts | 4 ++++ scripts/src/platform-infra.ts | 10 +++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/src/platform-infra-ops-library.ts b/scripts/src/platform-infra-ops-library.ts index c720e64d..07871a32 100644 --- a/scripts/src/platform-infra-ops-library.ts +++ b/scripts/src/platform-infra-ops-library.ts @@ -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 { if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`${label} must be a YAML object`); return value as Record; diff --git a/scripts/src/platform-infra.ts b/scripts/src/platform-infra.ts index 988d08f9..8a3c55dd 100644 --- a/scripts/src/platform-infra.ts +++ b/scripts/src/platform-infra.ts @@ -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, key: string, path: string): R } function booleanField(obj: Record, key: string, path: string): boolean { - return yamlBooleanField(obj, key, yamlConfigLabel(path), path); + return yamlBooleanField(obj, key, yamlSubFieldLabel(configPath, path), ""); } function stringArrayField(obj: Record, key: string, path: string): string[] { @@ -803,7 +803,7 @@ function enumField(obj: Record, key: string, path: string): number { - return yamlIntegerField(obj, key, yamlConfigLabel(path), path); + return yamlIntegerField(obj, key, yamlSubFieldLabel(configPath, path), ""); } function integerArrayField(obj: Record, key: string, path: string): number[] { @@ -814,10 +814,6 @@ function integerArrayField(obj: Record, 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); }