GeWuYou 3c52c8c1ea feat(config): 添加配置验证和YAML解析功能
- 实现了配置模式解析器,支持递归对象/数组/标量树结构
- 添加了可编辑字段收集功能,支持标量和数组类型的批量编辑
- 集成了YAML解析器,支持嵌套对象、数组和注释提取
- 实现了配置验证诊断,支持中英文本地化错误消息
- 添加了表单更新应用功能,支持安全的嵌套对象编辑
- 实现了示例配置生成功能,包含模式描述作为YAML注释
- 提供了批量数组值解析和枚举值标准化工具函数
- 集成了多语言支持,包含中英文验证消息本地化
2026-04-02 22:22:46 +08:00

65 lines
1.7 KiB
JavaScript

/**
* Join one object property onto a logical config path.
*
* @param {string} parentPath Parent logical path.
* @param {string} propertyName Property name.
* @returns {string} Combined logical path.
*/
function joinPropertyPath(parentPath, propertyName) {
return parentPath ? `${parentPath}.${propertyName}` : propertyName;
}
/**
* Join one indexed array item onto a logical config path.
*
* @param {string} arrayPath Array logical path.
* @param {number} itemIndex Zero-based item index.
* @returns {string} Indexed logical path.
*/
function joinArrayIndexPath(arrayPath, itemIndex) {
return `${arrayPath}[${itemIndex}]`;
}
/**
* Join one array-item template marker onto a logical config path.
*
* @param {string} arrayPath Array logical path.
* @returns {string} Template logical path.
*/
function joinArrayTemplatePath(arrayPath) {
return `${arrayPath}[]`;
}
/**
* Check whether a logical path still contains one template array marker.
*
* @param {string} path Logical path.
* @returns {boolean} True when the path contains a template array segment.
*/
function isTemplatePath(path) {
return String(path).includes("[]");
}
/**
* Split one logical object path into individual property segments.
* The current form model only supports dotted object paths here and keeps
* array indexing as part of other dedicated helpers.
*
* @param {string} path Logical path.
* @returns {string[]} Property segments.
*/
function splitObjectPath(path) {
return String(path)
.split(".")
.map((segment) => segment.trim())
.filter((segment) => segment.length > 0);
}
module.exports = {
isTemplatePath,
joinArrayIndexPath,
joinArrayTemplatePath,
joinPropertyPath,
splitObjectPath
};