mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-06 16:16:44 +08:00
feat(config): 添加配置验证功能
- 实现配置架构解析器,支持对象、数组和标量类型验证 - 添加 YAML 格式解析和注释提取功能 - 集成数值、布尔值、字符串等基本数据类型验证规则 - 实现日期、邮箱、UUID 等特殊格式验证逻辑 - 添加配置约束验证如最小/最大长度、数值范围等 - 支持正则表达式模式匹配验证 - 提供配置样本生成和批量编辑更新功能 - 实现多语言验证消息本地化支持 - 添加配置字段排序和可编辑性检查功能 - 支持嵌套对象和数组项的路径定位验证
This commit is contained in:
parent
7c07395825
commit
809f53e6a0
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user