gewuyou ff553977e3 chore(license): 补齐 Apache-2.0 文件头治理
- 新增许可证文件头检查与修复脚本

- 补充维护者手动修复 PR 工作流和 CI 校验

- 更新贡献指南中的文件头说明

- 补齐仓库维护源码和配置文件的许可证声明
2026-05-03 19:39:49 +08:00

79 lines
2.8 KiB
JavaScript

// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0
/**
* Build a compact contains-schema summary for array field hints.
* The summary reuses existing localized hint strings so Chinese UI surfaces
* do not fall back to mixed English tokens such as const/enum/pattern/ref.
*
* @param {{type?: string, enumValues?: string[], constValue?: string, constDisplayValue?: string, pattern?: string, refTable?: string}} containsSchema Parsed contains schema metadata.
* @param {{t: (key: string, params?: Record<string, string | number>) => string}} localizer Runtime localizer.
* @returns {string} Human-facing summary.
*/
function describeContainsSchema(containsSchema, localizer) {
const parts = [];
if (containsSchema.type) {
parts.push(containsSchema.type);
}
if (containsSchema.constValue !== undefined) {
parts.push(localizer.t("webview.hint.const", {
value: containsSchema.constDisplayValue ?? containsSchema.constValue
}));
} else if (Array.isArray(containsSchema.enumValues) && containsSchema.enumValues.length > 0) {
parts.push(localizer.t("webview.hint.allowed", {
values: containsSchema.enumValues.join(", ")
}));
} else if (containsSchema.pattern) {
parts.push(localizer.t("webview.hint.pattern", {
value: containsSchema.pattern
}));
}
if (containsSchema.refTable) {
parts.push(localizer.t("webview.hint.refTable", {
refTable: containsSchema.refTable
}));
}
return parts.join(", ") || localizer.t("webview.objectArray.item");
}
/**
* Build localized contains-related hint lines for array fields.
*
* @param {{contains?: {type?: string, enumValues?: string[], constValue?: string, constDisplayValue?: string, pattern?: string, refTable?: string}, minContains?: number, maxContains?: number}} propertySchema Array property schema metadata.
* @param {{t: (key: string, params?: Record<string, string | number>) => string}} localizer Runtime localizer.
* @returns {string[]} Localized contains hint lines.
*/
function buildContainsHintLines(propertySchema, localizer) {
if (!propertySchema.contains) {
return [];
}
const effectiveMinContains = typeof propertySchema.minContains === "number"
? propertySchema.minContains
: 1;
const lines = [
localizer.t("webview.hint.contains", {
summary: describeContainsSchema(propertySchema.contains, localizer)
}),
localizer.t("webview.hint.minContains", {
value: effectiveMinContains
})
];
if (typeof propertySchema.maxContains === "number") {
lines.push(localizer.t("webview.hint.maxContains", {
value: propertySchema.maxContains
}));
}
return lines;
}
module.exports = {
describeContainsSchema,
buildContainsHintLines
};