feat(config): 添加配置验证功能

- 实现配置架构解析器,支持对象、数组和标量类型验证
- 添加 YAML 格式解析和注释提取功能
- 集成数值、布尔值、字符串等基本数据类型验证规则
- 实现日期、邮箱、UUID 等特殊格式验证逻辑
- 添加配置约束验证如最小/最大长度、数值范围等
- 支持正则表达式模式匹配验证
- 提供配置样本生成和批量编辑更新功能
- 实现多语言验证消息本地化支持
- 添加配置字段排序和可编辑性检查功能
- 支持嵌套对象和数组项的路径定位验证
This commit is contained in:
GeWuYou 2026-04-11 15:04:22 +08:00
parent 7c07395825
commit 809f53e6a0
2 changed files with 15 additions and 7 deletions

View File

@ -719,11 +719,13 @@ function isValidCalendarDate(year, month, day) {
return false;
}
if (month < 1 || month > 12 || day < 1) {
if (year < 1 || year > 9999 || month < 1 || month > 12 || day < 1) {
return false;
}
const lastDay = new Date(Date.UTC(year, month, 0)).getUTCDate();
const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
const monthDays = [31, isLeapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
const lastDay = monthDays[month - 1];
return day <= lastDay;
}

View File

@ -667,6 +667,10 @@ test("validateParsedConfig should enforce supported string formats", () => {
"type": "string",
"format": "date"
},
"ancientReleaseDate": {
"type": "string",
"format": "date"
},
"publishedAt": {
"type": "string",
"format": "date-time"
@ -688,6 +692,7 @@ test("validateParsedConfig should enforce supported string formats", () => {
`);
const yaml = parseTopLevelYaml(`
releaseDate: 2026-02-30
ancientReleaseDate: 0000-01-01
publishedAt: 2026-04-11T08:30:00
contactEmail: boss.example.com
catalogUri: /loot-table
@ -696,12 +701,13 @@ configId: 123e4567e89b12d3a456426614174000
const diagnostics = validateParsedConfig(schema, yaml);
assert.equal(diagnostics.length, 5);
assert.equal(diagnostics.length, 6);
assert.match(diagnostics[0].message, /format 'date'|字符串格式“date”/u);
assert.match(diagnostics[1].message, /format 'date-time'|字符串格式“date-time”/u);
assert.match(diagnostics[2].message, /format 'email'|字符串格式“email”/u);
assert.match(diagnostics[3].message, /format 'uri'|字符串格式“uri”/u);
assert.match(diagnostics[4].message, /format 'uuid'|字符串格式“uuid”/u);
assert.match(diagnostics[1].message, /format 'date'|字符串格式“date”/u);
assert.match(diagnostics[2].message, /format 'date-time'|字符串格式“date-time”/u);
assert.match(diagnostics[3].message, /format 'email'|字符串格式“email”/u);
assert.match(diagnostics[4].message, /format 'uri'|字符串格式“uri”/u);
assert.match(diagnostics[5].message, /format 'uuid'|字符串格式“uuid”/u);
});
test("validateParsedConfig should accept supported string formats", () => {