befly 3.15.18 → 3.15.19
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 +22 -5
- package/dist/befly.min.js +11 -11
- package/dist/checks/checkTable.js +12 -2
- package/dist/sync/syncTable.d.ts +1 -0
- package/dist/sync/syncTable.js +11 -3
- package/dist/types/validate.d.ts +1 -1
- package/dist/utils/normalizeFieldDefinition.js +2 -0
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -8294,7 +8294,7 @@ init_logger();
|
|
|
8294
8294
|
init_util();
|
|
8295
8295
|
var RESERVED_FIELDS = ["id", "created_at", "updated_at", "deleted_at", "state"];
|
|
8296
8296
|
var RESERVED_FIELD_SET = new Set(RESERVED_FIELDS);
|
|
8297
|
-
var FIELD_TYPES = ["tinyint", "smallint", "mediumint", "int", "bigint", "decimal", "char", "varchar", "tinytext", "text", "mediumtext", "longtext", "datetime", "json"];
|
|
8297
|
+
var FIELD_TYPES = ["tinyint", "smallint", "mediumint", "int", "bigint", "decimal", "float", "double", "char", "varchar", "tinytext", "text", "mediumtext", "longtext", "datetime", "json"];
|
|
8298
8298
|
var FIELD_TYPE_SET = new Set(FIELD_TYPES);
|
|
8299
8299
|
var INPUT_TYPES = ["number", "integer", "string", "char", "array", "array_number", "array_integer", "json", "json_number", "json_integer"];
|
|
8300
8300
|
var INPUT_TYPE_SET = new Set(INPUT_TYPES);
|
|
@@ -8307,6 +8307,8 @@ function inferInputByType(dbType) {
|
|
|
8307
8307
|
case "bigint":
|
|
8308
8308
|
return "integer";
|
|
8309
8309
|
case "decimal":
|
|
8310
|
+
case "float":
|
|
8311
|
+
case "double":
|
|
8310
8312
|
return "number";
|
|
8311
8313
|
case "char":
|
|
8312
8314
|
case "varchar":
|
|
@@ -8461,8 +8463,9 @@ async function checkTable(tables, config2) {
|
|
|
8461
8463
|
const isTextDbType = ["tinytext", "text", "mediumtext", "longtext"].includes(effectiveType);
|
|
8462
8464
|
const isIntDbType = ["tinyint", "smallint", "mediumint", "int", "bigint"].includes(effectiveType);
|
|
8463
8465
|
const isDecimalDbType = effectiveType === "decimal";
|
|
8466
|
+
const isFloatDbType = effectiveType === "float" || effectiveType === "double";
|
|
8464
8467
|
const isJsonDbType = effectiveType === "json";
|
|
8465
|
-
const isNumericDbType = isIntDbType || isDecimalDbType;
|
|
8468
|
+
const isNumericDbType = isIntDbType || isDecimalDbType || isFloatDbType;
|
|
8466
8469
|
if (isRegexInput(normalizedInput) || isEnumInput(normalizedInput) || isAliasInput(normalizedInput)) {
|
|
8467
8470
|
if (!isStringDbType) {
|
|
8468
8471
|
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u5B57\u6BB5 input \u4F7F\u7528\u6B63\u5219/\u679A\u4E3E/\u6B63\u5219\u522B\u540D\uFF0C\u4EC5\u5141\u8BB8\u5B57\u7B26\u4E32\u7C7B\u5B57\u6BB5\uFF08char/varchar/text\uFF09`);
|
|
@@ -8598,6 +8601,11 @@ async function checkTable(tables, config2) {
|
|
|
8598
8601
|
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A ${effectiveType} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A\u6570\u5B57\u6216 null` + `\uFF08typeof=${typeof field.default}\uFF0Cvalue=${formatValuePreview(field.default)}\uFF09`);
|
|
8599
8602
|
hasError = true;
|
|
8600
8603
|
}
|
|
8604
|
+
} else if (isFloatDbType) {
|
|
8605
|
+
if (field.default !== undefined && field.default !== null && typeof field.default !== "number") {
|
|
8606
|
+
Logger.warn(`${tablePrefix}${fileName} \u6587\u4EF6 ${colKey} \u4E3A ${effectiveType} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A\u6570\u5B57\u6216 null` + `\uFF08typeof=${typeof field.default}\uFF0Cvalue=${formatValuePreview(field.default)}\uFF09`);
|
|
8607
|
+
hasError = true;
|
|
8608
|
+
}
|
|
8601
8609
|
}
|
|
8602
8610
|
}
|
|
8603
8611
|
} catch (error) {
|
|
@@ -9987,6 +9995,8 @@ function inferInputByType2(dbType) {
|
|
|
9987
9995
|
case "bigint":
|
|
9988
9996
|
return "integer";
|
|
9989
9997
|
case "decimal":
|
|
9998
|
+
case "float":
|
|
9999
|
+
case "double":
|
|
9990
10000
|
return "number";
|
|
9991
10001
|
case "char":
|
|
9992
10002
|
case "varchar":
|
|
@@ -10184,6 +10194,8 @@ class SyncTable {
|
|
|
10184
10194
|
int: "INT",
|
|
10185
10195
|
bigint: "BIGINT",
|
|
10186
10196
|
decimal: "DECIMAL",
|
|
10197
|
+
float: "FLOAT",
|
|
10198
|
+
double: "DOUBLE",
|
|
10187
10199
|
char: "CHAR",
|
|
10188
10200
|
varchar: "VARCHAR",
|
|
10189
10201
|
datetime: "DATETIME",
|
|
@@ -10196,6 +10208,7 @@ class SyncTable {
|
|
|
10196
10208
|
static TEXT_FAMILY = new Set(["tinytext", "text", "mediumtext", "longtext"]);
|
|
10197
10209
|
static INT_TYPES = new Set(["tinyint", "smallint", "mediumint", "int", "bigint"]);
|
|
10198
10210
|
static DECIMAL_TYPES = new Set(["decimal"]);
|
|
10211
|
+
static FLOAT_TYPES = new Set(["float", "double"]);
|
|
10199
10212
|
db;
|
|
10200
10213
|
dbName;
|
|
10201
10214
|
constructor(ctx) {
|
|
@@ -10318,7 +10331,7 @@ class SyncTable {
|
|
|
10318
10331
|
return unsigned ? `${base} UNSIGNED` : base;
|
|
10319
10332
|
}
|
|
10320
10333
|
const baseType = typeMapping[normalizedType] || "TEXT";
|
|
10321
|
-
if (SyncTable.INT_TYPES.has(normalizedType) && unsigned) {
|
|
10334
|
+
if ((SyncTable.INT_TYPES.has(normalizedType) || SyncTable.FLOAT_TYPES.has(normalizedType)) && unsigned) {
|
|
10322
10335
|
return `${baseType} UNSIGNED`;
|
|
10323
10336
|
}
|
|
10324
10337
|
return baseType;
|
|
@@ -10335,6 +10348,8 @@ class SyncTable {
|
|
|
10335
10348
|
case "int":
|
|
10336
10349
|
case "bigint":
|
|
10337
10350
|
case "decimal":
|
|
10351
|
+
case "float":
|
|
10352
|
+
case "double":
|
|
10338
10353
|
return 0;
|
|
10339
10354
|
case "char":
|
|
10340
10355
|
case "varchar":
|
|
@@ -10356,7 +10371,7 @@ class SyncTable {
|
|
|
10356
10371
|
if (SyncTable.TEXT_FAMILY.has(normalizedType) || normalizedType === "json" || actualDefault === "null") {
|
|
10357
10372
|
return "";
|
|
10358
10373
|
}
|
|
10359
|
-
if (SyncTable.INT_TYPES.has(normalizedType) || SyncTable.DECIMAL_TYPES.has(normalizedType) || SyncTable.isStringOrArrayType(normalizedType)) {
|
|
10374
|
+
if (SyncTable.INT_TYPES.has(normalizedType) || SyncTable.DECIMAL_TYPES.has(normalizedType) || SyncTable.FLOAT_TYPES.has(normalizedType) || SyncTable.isStringOrArrayType(normalizedType)) {
|
|
10360
10375
|
if (typeof actualDefault === "number" && !Number.isNaN(actualDefault)) {
|
|
10361
10376
|
return ` DEFAULT ${actualDefault}`;
|
|
10362
10377
|
} else {
|
|
@@ -10383,7 +10398,7 @@ class SyncTable {
|
|
|
10383
10398
|
return "null";
|
|
10384
10399
|
const normalizedType = String(fieldType || "").toLowerCase();
|
|
10385
10400
|
const raw = String(value).trim();
|
|
10386
|
-
if (SyncTable.INT_TYPES.has(normalizedType) || SyncTable.DECIMAL_TYPES.has(normalizedType)) {
|
|
10401
|
+
if (SyncTable.INT_TYPES.has(normalizedType) || SyncTable.DECIMAL_TYPES.has(normalizedType) || SyncTable.FLOAT_TYPES.has(normalizedType)) {
|
|
10387
10402
|
if (/^[+-]?\d+(?:\.\d+)?$/.test(raw)) {
|
|
10388
10403
|
let sign = "";
|
|
10389
10404
|
let body = raw;
|
|
@@ -10683,6 +10698,8 @@ SQL: ${sqlLine}
|
|
|
10683
10698
|
if (nIntIdx > cIntIdx)
|
|
10684
10699
|
return true;
|
|
10685
10700
|
}
|
|
10701
|
+
if (cBase === "float" && nBase === "double")
|
|
10702
|
+
return true;
|
|
10686
10703
|
if (cBase === "varchar" && (nBase === "text" || nBase === "mediumtext" || nBase === "longtext"))
|
|
10687
10704
|
return true;
|
|
10688
10705
|
if (cBase === "char" && nBase === "varchar" || cBase === "varchar" && nBase === "char") {
|