befly 3.74.0 → 3.74.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configs/constConfig.js +1 -1
- package/lib/validator.js +3 -1
- package/package.json +1 -1
package/configs/constConfig.js
CHANGED
|
@@ -35,7 +35,7 @@ export const RUN_MODE_VALUES = ["development", "production"];
|
|
|
35
35
|
// ==========================
|
|
36
36
|
|
|
37
37
|
// 字段 input 可选值(统一用于 validator / checkTable / checkApi)
|
|
38
|
-
export const FIELD_RULE_INPUT_TYPES = ["number", "integer", "string", "char", "array", "arrayNumber", "arrayInteger", "json", "jsonNumber", "jsonInteger", "regexp", "enum", "enumNumber", "enumInteger"];
|
|
38
|
+
export const FIELD_RULE_INPUT_TYPES = ["number", "integer", "string", "char", "array", "arrayNumber", "arrayInteger", "arrayObject", "json", "jsonNumber", "jsonInteger", "regexp", "enum", "enumNumber", "enumInteger"];
|
|
39
39
|
|
|
40
40
|
// 字段 min/max 缺省值
|
|
41
41
|
export const FIELD_RULE_DEFAULT_MIN = 0;
|
package/lib/validator.js
CHANGED
|
@@ -90,6 +90,8 @@ function checkFieldValue(value, rule) {
|
|
|
90
90
|
if (!isScalarArray(value)) return "必须是仅包含基础值的一层数组";
|
|
91
91
|
if (input === "arrayNumber" && !value.every(isFiniteNumber)) return "数组元素必须是数字";
|
|
92
92
|
if (input === "arrayInteger" && !value.every(isIntegerNumber)) return "数组元素必须是整数";
|
|
93
|
+
} else if (input === "arrayObject") {
|
|
94
|
+
if (!Array.isArray(value) || !value.every((item) => isPlainObject(item) && isFlatJson(item))) return "必须是对象成员仅包含基础值的一层数组";
|
|
93
95
|
} else if (input === "json" || input === "jsonNumber" || input === "jsonInteger") {
|
|
94
96
|
const kind = input === "json" ? "any" : input === "jsonNumber" ? "number" : "integer";
|
|
95
97
|
if (!isFlatJson(value, kind)) return kind === "any" ? "必须是一层JSON对象或数组,成员只能是基础值" : `JSON值必须是${kind === "number" ? "数字" : "整数"}`;
|
|
@@ -128,7 +130,7 @@ function checkFieldValue(value, rule) {
|
|
|
128
130
|
if (!values.includes(converted)) return "值不在枚举范围内";
|
|
129
131
|
}
|
|
130
132
|
|
|
131
|
-
if (input === "array" || input === "arrayNumber" || input === "arrayInteger") {
|
|
133
|
+
if (input === "array" || input === "arrayNumber" || input === "arrayInteger" || input === "arrayObject") {
|
|
132
134
|
if (value.length < min) return `至少需要${min}个元素`;
|
|
133
135
|
if (value.length > max) return `最多只能有${max}个元素`;
|
|
134
136
|
}
|