befly 3.16.0 → 3.16.1
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/dist/befly.js +20 -13
- package/dist/befly.min.js +9 -9
- package/dist/checks/checkTable.js +7 -7
- package/dist/lib/validator.js +10 -6
- package/dist/sync/syncTable.js +6 -2
- package/dist/types/validate.d.ts +1 -1
- package/dist/utils/dbFieldRules.js +1 -1
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -8600,7 +8600,7 @@ function inferInputByDbType(dbType) {
|
|
|
8600
8600
|
if (DECIMAL_DB_TYPES.has(normalized) || FLOAT_DB_TYPES.has(normalized)) {
|
|
8601
8601
|
return "number";
|
|
8602
8602
|
}
|
|
8603
|
-
if (STRING_DB_TYPES.has(normalized) || normalized === "datetime") {
|
|
8603
|
+
if (STRING_DB_TYPES.has(normalized) || normalized === "datetime" || normalized === "timestamp") {
|
|
8604
8604
|
return "string";
|
|
8605
8605
|
}
|
|
8606
8606
|
if (normalized === "json") {
|
|
@@ -8635,7 +8635,7 @@ function parseEnumRuleValues(enumInput) {
|
|
|
8635
8635
|
init_util();
|
|
8636
8636
|
var RESERVED_FIELDS = ["id", "created_at", "updated_at", "deleted_at", "state"];
|
|
8637
8637
|
var RESERVED_FIELD_SET = new Set(RESERVED_FIELDS);
|
|
8638
|
-
var FIELD_TYPES = ["tinyint", "smallint", "mediumint", "int", "bigint", "decimal", "float", "double", "char", "varchar", "enum", "tinytext", "text", "mediumtext", "longtext", "datetime", "json"];
|
|
8638
|
+
var FIELD_TYPES = ["tinyint", "smallint", "mediumint", "int", "bigint", "decimal", "float", "double", "char", "varchar", "enum", "tinytext", "text", "mediumtext", "longtext", "datetime", "timestamp", "json"];
|
|
8639
8639
|
var FIELD_TYPE_SET = new Set(FIELD_TYPES);
|
|
8640
8640
|
var INPUT_TYPES = ["number", "integer", "string", "char", "array", "array_number", "array_integer", "json", "json_number", "json_integer"];
|
|
8641
8641
|
var INPUT_TYPE_SET = new Set(INPUT_TYPES);
|
|
@@ -8845,21 +8845,21 @@ async function checkTable(tables, config2) {
|
|
|
8845
8845
|
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A ${effectiveType} \u7C7B\u578B\uFF0C\u4E0D\u652F\u6301\u552F\u4E00\u7EA6\u675F\uFF08unique=true \u65E0\u6548\uFF09`);
|
|
8846
8846
|
hasError = true;
|
|
8847
8847
|
}
|
|
8848
|
-
} else if (effectiveType === "datetime") {
|
|
8848
|
+
} else if (effectiveType === "datetime" || effectiveType === "timestamp") {
|
|
8849
8849
|
if (field.min !== undefined && field.min !== null) {
|
|
8850
|
-
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A
|
|
8850
|
+
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A ${effectiveType} \u7C7B\u578B\uFF0Cmin \u5FC5\u987B\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${field.min}"`);
|
|
8851
8851
|
hasError = true;
|
|
8852
8852
|
}
|
|
8853
8853
|
if (field.max !== undefined && field.max !== null) {
|
|
8854
|
-
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A
|
|
8854
|
+
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A ${effectiveType} \u7C7B\u578B\uFF0Cmax \u5FC5\u987B\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${field.max}"`);
|
|
8855
8855
|
hasError = true;
|
|
8856
8856
|
}
|
|
8857
8857
|
if (field.default !== undefined && field.default !== null) {
|
|
8858
|
-
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A
|
|
8858
|
+
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A ${effectiveType} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A null\uFF08\u5982\u9700\u5F53\u524D\u65F6\u95F4\uFF0C\u8BF7\u5728\u4E1A\u52A1\u5199\u5165\u65F6\u8D4B\u503C\uFF09\u3002\u5F53\u524D\u4E3A ${formatValuePreview(field.default)}`);
|
|
8859
8859
|
hasError = true;
|
|
8860
8860
|
}
|
|
8861
8861
|
if (field.unsigned !== undefined) {
|
|
8862
|
-
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A
|
|
8862
|
+
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A ${effectiveType} \u7C7B\u578B\uFF0C\u4E0D\u5141\u8BB8\u8BBE\u7F6E unsigned`);
|
|
8863
8863
|
hasError = true;
|
|
8864
8864
|
}
|
|
8865
8865
|
} else if (effectiveType === "enum") {
|
|
@@ -10606,6 +10606,7 @@ class SyncTable {
|
|
|
10606
10606
|
varchar: "VARCHAR",
|
|
10607
10607
|
enum: "ENUM",
|
|
10608
10608
|
datetime: "DATETIME",
|
|
10609
|
+
timestamp: "TIMESTAMP",
|
|
10609
10610
|
tinytext: "TINYTEXT",
|
|
10610
10611
|
text: "MEDIUMTEXT",
|
|
10611
10612
|
mediumtext: "MEDIUMTEXT",
|
|
@@ -10879,6 +10880,8 @@ class SyncTable {
|
|
|
10879
10880
|
return "null";
|
|
10880
10881
|
case "datetime":
|
|
10881
10882
|
return "null";
|
|
10883
|
+
case "timestamp":
|
|
10884
|
+
return "null";
|
|
10882
10885
|
case "tinytext":
|
|
10883
10886
|
case "text":
|
|
10884
10887
|
case "mediumtext":
|
|
@@ -10906,7 +10909,7 @@ class SyncTable {
|
|
|
10906
10909
|
return ` DEFAULT '${escaped}'`;
|
|
10907
10910
|
}
|
|
10908
10911
|
}
|
|
10909
|
-
if (normalizedType === "datetime") {
|
|
10912
|
+
if (normalizedType === "datetime" || normalizedType === "timestamp") {
|
|
10910
10913
|
if (typeof actualDefault === "string") {
|
|
10911
10914
|
const trimmed = actualDefault.trim();
|
|
10912
10915
|
if (/^current_timestamp(\(\s*\d+\s*\)|\(\s*\))?$/i.test(trimmed)) {
|
|
@@ -13447,13 +13450,15 @@ class Validator {
|
|
|
13447
13450
|
}
|
|
13448
13451
|
case "string": {
|
|
13449
13452
|
if (typeof value === "string") {
|
|
13450
|
-
|
|
13453
|
+
const dbTypeNormalized2 = String(dbType || "").toLowerCase();
|
|
13454
|
+
if (dbTypeNormalized2 === "datetime" || dbTypeNormalized2 === "timestamp") {
|
|
13451
13455
|
const trimmed = value.trim();
|
|
13452
13456
|
return { value: trimmed, error: null };
|
|
13453
13457
|
}
|
|
13454
13458
|
return { value, error: null };
|
|
13455
13459
|
}
|
|
13456
|
-
|
|
13460
|
+
const dbTypeNormalized = String(dbType || "").toLowerCase();
|
|
13461
|
+
if (dbTypeNormalized === "datetime" || dbTypeNormalized === "timestamp") {
|
|
13457
13462
|
return { value: null, error: "\u5FC5\u987B\u662F\u65F6\u95F4\u5B57\u7B26\u4E32" };
|
|
13458
13463
|
}
|
|
13459
13464
|
return { value: null, error: "\u5FC5\u987B\u662F\u5B57\u7B26\u4E32" };
|
|
@@ -13495,7 +13500,8 @@ class Validator {
|
|
|
13495
13500
|
return { value: null, error: "\u5FC5\u987B\u662FJSON\u5BF9\u8C61\u6216\u6570\u7EC4" };
|
|
13496
13501
|
return checkJsonLeaves(value, "integer") ? { value, error: null } : { value: null, error: "JSON\u503C\u5FC5\u987B\u662F\u6574\u6570" };
|
|
13497
13502
|
default: {
|
|
13498
|
-
|
|
13503
|
+
const dbTypeNormalized = String(dbType || "").toLowerCase();
|
|
13504
|
+
if (dbTypeNormalized === "datetime" || dbTypeNormalized === "timestamp") {
|
|
13499
13505
|
if (typeof value !== "string")
|
|
13500
13506
|
return { value: null, error: "\u5FC5\u987B\u662F\u65F6\u95F4\u5B57\u7B26\u4E32" };
|
|
13501
13507
|
const trimmed = value.trim();
|
|
@@ -13552,7 +13558,8 @@ class Validator {
|
|
|
13552
13558
|
if (!isJsonStructure(value))
|
|
13553
13559
|
return "\u5FC5\u987B\u662FJSON\u5BF9\u8C61\u6216\u6570\u7EC4";
|
|
13554
13560
|
}
|
|
13555
|
-
|
|
13561
|
+
const normalizedTypeForDb = String(type || "").toLowerCase();
|
|
13562
|
+
if (normalizedTypeForDb === "datetime" || normalizedTypeForDb === "timestamp") {
|
|
13556
13563
|
if (typeof value !== "string")
|
|
13557
13564
|
return "\u5FC5\u987B\u662F\u65F6\u95F4\u5B57\u7B26\u4E32";
|
|
13558
13565
|
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(value))
|
|
@@ -13621,7 +13628,7 @@ class Validator {
|
|
|
13621
13628
|
return defaultValue;
|
|
13622
13629
|
}
|
|
13623
13630
|
const normalizedType = String(type || "").toLowerCase();
|
|
13624
|
-
if (normalizedType === "datetime" || normalizedType === "json" || normalizedType === "enum") {
|
|
13631
|
+
if (normalizedType === "datetime" || normalizedType === "timestamp" || normalizedType === "json" || normalizedType === "enum") {
|
|
13625
13632
|
return null;
|
|
13626
13633
|
}
|
|
13627
13634
|
const normalizedInput = String(input || "").toLowerCase();
|