befly 3.15.22 → 3.15.24
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 +90 -53
- package/dist/befly.min.js +9 -10
- package/dist/index.js +15 -3
- package/dist/lib/logger.js +10 -10
- package/dist/sync/syncTable.d.ts +2 -1
- package/dist/sync/syncTable.js +71 -45
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -863,11 +863,11 @@ function configure(cfg) {
|
|
|
863
863
|
errorFileSink = null;
|
|
864
864
|
appConsoleSink = null;
|
|
865
865
|
sanitizeOptions = {
|
|
866
|
-
maxStringLen: normalizePositiveInt(config.maxStringLen,
|
|
867
|
-
maxArrayItems: normalizePositiveInt(config.maxArrayItems,
|
|
868
|
-
sanitizeDepth: normalizePositiveInt(config.sanitizeDepth,
|
|
869
|
-
sanitizeNodes: normalizePositiveInt(config.sanitizeNodes,
|
|
870
|
-
sanitizeObjectKeys: normalizePositiveInt(config.sanitizeObjectKeys,
|
|
866
|
+
maxStringLen: normalizePositiveInt(config.maxStringLen, 200, 20, 200000),
|
|
867
|
+
maxArrayItems: normalizePositiveInt(config.maxArrayItems, 500, 10, 5000),
|
|
868
|
+
sanitizeDepth: normalizePositiveInt(config.sanitizeDepth, 5, 1, 10),
|
|
869
|
+
sanitizeNodes: normalizePositiveInt(config.sanitizeNodes, 5000, 50, 20000),
|
|
870
|
+
sanitizeObjectKeys: normalizePositiveInt(config.sanitizeObjectKeys, 500, 10, 5000),
|
|
871
871
|
sensitiveKeyMatcher: buildSensitiveKeyMatcher({ builtinPatterns: BUILTIN_SENSITIVE_KEYS, userPatterns: config.excludeFields })
|
|
872
872
|
};
|
|
873
873
|
}
|
|
@@ -1097,11 +1097,11 @@ var init_logger = __esm(() => {
|
|
|
1097
1097
|
INITIAL_CWD = process.cwd();
|
|
1098
1098
|
BUILTIN_SENSITIVE_KEYS = ["*password*", "pass", "pwd", "*token*", "access_token", "refresh_token", "accessToken", "refreshToken", "authorization", "cookie", "set-cookie", "*secret*", "apiKey", "api_key", "privateKey", "private_key"];
|
|
1099
1099
|
sanitizeOptions = {
|
|
1100
|
-
maxStringLen:
|
|
1101
|
-
maxArrayItems:
|
|
1102
|
-
sanitizeDepth:
|
|
1103
|
-
sanitizeNodes:
|
|
1104
|
-
sanitizeObjectKeys:
|
|
1100
|
+
maxStringLen: 200,
|
|
1101
|
+
maxArrayItems: 500,
|
|
1102
|
+
sanitizeDepth: 5,
|
|
1103
|
+
sanitizeNodes: 5000,
|
|
1104
|
+
sanitizeObjectKeys: 500,
|
|
1105
1105
|
sensitiveKeyMatcher: buildSensitiveKeyMatcher({ builtinPatterns: BUILTIN_SENSITIVE_KEYS, userPatterns: [] })
|
|
1106
1106
|
};
|
|
1107
1107
|
HOSTNAME = (() => {
|
|
@@ -10403,23 +10403,7 @@ class SyncTable {
|
|
|
10403
10403
|
}
|
|
10404
10404
|
tableTasks.push(task);
|
|
10405
10405
|
}
|
|
10406
|
-
|
|
10407
|
-
const lines = [];
|
|
10408
|
-
for (const change of incompatibleTypeChanges) {
|
|
10409
|
-
lines.push(`- ${change.tableName}.${change.dbFieldName}: ${change.currentType} -> ${change.expectedType}`);
|
|
10410
|
-
}
|
|
10411
|
-
const msgLines = [];
|
|
10412
|
-
msgLines.push("\u7981\u6B62\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4\uFF08\u68C0\u6D4B\u5230\u4E0D\u517C\u5BB9/\u6536\u7F29\u53D8\u66F4\uFF09:");
|
|
10413
|
-
for (const line of lines) {
|
|
10414
|
-
msgLines.push(line);
|
|
10415
|
-
}
|
|
10416
|
-
msgLines.push("\u8BF4\u660E: \u4EC5\u5141\u8BB8\u540C\u7C7B\u578B\u7684\u5BBD\u5316\u53D8\u66F4\uFF08\u5982 TINYINT->SMALLINT->INT->BIGINT\uFF09\uFF0C\u4EE5\u53CA\u90E8\u5206\u517C\u5BB9\u53D8\u66F4\uFF08\u5982 VARCHAR->TEXT\u3001CHAR/VARCHAR \u4E92\u8F6C\u3001float->double\uFF09\u3002");
|
|
10417
|
-
msgLines.push("\u63D0\u793A: \u82E5\u786E\u9700\u6536\u7F29\uFF0C\u8BF7\u5148\u624B\u5DE5\u8FC1\u79FB/\u6E05\u6D17\u6570\u636E\u540E\u518D\u6267\u884C\u540C\u6B65\u3002");
|
|
10418
|
-
const err = new Error(msgLines.join(`
|
|
10419
|
-
`));
|
|
10420
|
-
err.__syncTableNoLog = true;
|
|
10421
|
-
throw err;
|
|
10422
|
-
}
|
|
10406
|
+
SyncTable.throwIfIncompatibleTypeChanges(incompatibleTypeChanges);
|
|
10423
10407
|
for (const task of tableTasks) {
|
|
10424
10408
|
if (!task.existsTable) {
|
|
10425
10409
|
continue;
|
|
@@ -10436,7 +10420,11 @@ class SyncTable {
|
|
|
10436
10420
|
task.plan = built.plan;
|
|
10437
10421
|
task.planSummary = built.summary;
|
|
10438
10422
|
task.planDetails = built.details;
|
|
10423
|
+
for (const change of built.incompatibleTypeChanges) {
|
|
10424
|
+
incompatibleTypeChanges.push(change);
|
|
10425
|
+
}
|
|
10439
10426
|
}
|
|
10427
|
+
SyncTable.throwIfIncompatibleTypeChanges(incompatibleTypeChanges);
|
|
10440
10428
|
for (const task of tableTasks) {
|
|
10441
10429
|
const item = task.item;
|
|
10442
10430
|
const tableName = task.tableName;
|
|
@@ -10502,6 +10490,9 @@ class SyncTable {
|
|
|
10502
10490
|
if (error?.__syncTableLogged === true) {
|
|
10503
10491
|
throw error;
|
|
10504
10492
|
}
|
|
10493
|
+
if (isCoreError(error) && error.noLog === true) {
|
|
10494
|
+
throw error;
|
|
10495
|
+
}
|
|
10505
10496
|
if (error?.__syncTableNoLog === true) {
|
|
10506
10497
|
throw error;
|
|
10507
10498
|
}
|
|
@@ -10744,6 +10735,7 @@ class SyncTable {
|
|
|
10744
10735
|
const addedBusiness = fieldPlan.addedBusiness;
|
|
10745
10736
|
const modified = fieldPlan.modified;
|
|
10746
10737
|
const addedSystem = systemPlan.addedSystem;
|
|
10738
|
+
const incompatibleTypeChanges = fieldPlan.incompatibleTypeChanges;
|
|
10747
10739
|
const plan = {
|
|
10748
10740
|
changed: alterClauses.length > 0 || indexActions.length > 0,
|
|
10749
10741
|
alterClauses,
|
|
@@ -10760,7 +10752,8 @@ class SyncTable {
|
|
|
10760
10752
|
details: {
|
|
10761
10753
|
fieldChanges: fieldPlan.changeDetails,
|
|
10762
10754
|
indexChanges: indexPlan.indexActions
|
|
10763
|
-
}
|
|
10755
|
+
},
|
|
10756
|
+
incompatibleTypeChanges
|
|
10764
10757
|
};
|
|
10765
10758
|
}
|
|
10766
10759
|
static buildFieldPlan(options) {
|
|
@@ -10768,6 +10761,7 @@ class SyncTable {
|
|
|
10768
10761
|
let addedBusiness = 0;
|
|
10769
10762
|
let modified = 0;
|
|
10770
10763
|
const changeDetails = [];
|
|
10764
|
+
const incompatibleTypeChanges = [];
|
|
10771
10765
|
for (const [fieldKey, fieldDef] of Object.entries(options.fields)) {
|
|
10772
10766
|
const dbFieldName = snakeCase(fieldKey);
|
|
10773
10767
|
if (options.existingColumns[dbFieldName]) {
|
|
@@ -10775,7 +10769,14 @@ class SyncTable {
|
|
|
10775
10769
|
if (comparison.length > 0) {
|
|
10776
10770
|
modified = modified + 1;
|
|
10777
10771
|
changeDetails.push({ fieldKey, dbFieldName, changes: comparison });
|
|
10778
|
-
|
|
10772
|
+
const typeChange = comparison.find((c) => c.type === "datatype");
|
|
10773
|
+
if (typeChange) {
|
|
10774
|
+
const expectedType = SyncTable.getSqlType(fieldDef.type, fieldDef.max ?? null, fieldDef.unsigned ?? false, fieldDef.precision ?? null, fieldDef.scale ?? null);
|
|
10775
|
+
const incompatible = SyncTable.getIncompatibleTypeChange(options.tableName, dbFieldName, String(typeChange.current ?? ""), expectedType);
|
|
10776
|
+
if (incompatible) {
|
|
10777
|
+
incompatibleTypeChanges.push(incompatible);
|
|
10778
|
+
}
|
|
10779
|
+
}
|
|
10779
10780
|
alterClauses.push(SyncTable.generateDDLClause(fieldKey, fieldDef, false));
|
|
10780
10781
|
}
|
|
10781
10782
|
} else {
|
|
@@ -10783,7 +10784,7 @@ class SyncTable {
|
|
|
10783
10784
|
alterClauses.push(SyncTable.generateDDLClause(fieldKey, fieldDef, true));
|
|
10784
10785
|
}
|
|
10785
10786
|
}
|
|
10786
|
-
return { alterClauses, addedBusiness, modified, changeDetails };
|
|
10787
|
+
return { alterClauses, addedBusiness, modified, changeDetails, incompatibleTypeChanges };
|
|
10787
10788
|
}
|
|
10788
10789
|
static buildSystemFieldPlan(options) {
|
|
10789
10790
|
const alterClauses = [];
|
|
@@ -10819,17 +10820,20 @@ class SyncTable {
|
|
|
10819
10820
|
];
|
|
10820
10821
|
return { indexActions };
|
|
10821
10822
|
}
|
|
10822
|
-
static
|
|
10823
|
-
const
|
|
10824
|
-
|
|
10825
|
-
return;
|
|
10826
|
-
const currentType = String(typeChange.current || "").toLowerCase();
|
|
10827
|
-
const expectedType = SyncTable.getSqlType(fieldDef.type, fieldDef.max ?? null, fieldDef.unsigned ?? false, fieldDef.precision ?? null, fieldDef.scale ?? null).toLowerCase();
|
|
10823
|
+
static getIncompatibleTypeChange(tableName, dbFieldName, currentTypeRaw, expectedTypeRaw) {
|
|
10824
|
+
const currentType = String(currentTypeRaw || "").toLowerCase();
|
|
10825
|
+
const expectedType = String(expectedTypeRaw || "").toLowerCase();
|
|
10828
10826
|
const currentBase = currentType.replace(/\s*unsigned/gi, "").replace(/\([^)]*\)/g, "").trim();
|
|
10829
10827
|
const expectedBase = expectedType.replace(/\s*unsigned/gi, "").replace(/\([^)]*\)/g, "").trim();
|
|
10830
|
-
if (currentBase !== expectedBase && !SyncTable.isCompatibleTypeChange(currentType, expectedType))
|
|
10831
|
-
|
|
10832
|
-
|
|
10828
|
+
if (currentBase !== expectedBase && !SyncTable.isCompatibleTypeChange(currentType, expectedType)) {
|
|
10829
|
+
return {
|
|
10830
|
+
tableName,
|
|
10831
|
+
dbFieldName,
|
|
10832
|
+
currentType: String(currentTypeRaw ?? ""),
|
|
10833
|
+
expectedType: String(expectedTypeRaw ?? "")
|
|
10834
|
+
};
|
|
10835
|
+
}
|
|
10836
|
+
return null;
|
|
10833
10837
|
}
|
|
10834
10838
|
static collectIncompatibleTypeChanges(tableName, existingColumns, fields) {
|
|
10835
10839
|
const out = [];
|
|
@@ -10842,21 +10846,42 @@ class SyncTable {
|
|
|
10842
10846
|
const typeChange = comparison.find((c) => c.type === "datatype");
|
|
10843
10847
|
if (!typeChange)
|
|
10844
10848
|
continue;
|
|
10845
|
-
const
|
|
10846
|
-
const
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
if (currentBase !== expectedBase && !SyncTable.isCompatibleTypeChange(currentType, expectedType)) {
|
|
10850
|
-
out.push({
|
|
10851
|
-
tableName,
|
|
10852
|
-
dbFieldName,
|
|
10853
|
-
currentType: String(typeChange.current ?? ""),
|
|
10854
|
-
expectedType: String(typeChange.expected ?? "")
|
|
10855
|
-
});
|
|
10849
|
+
const expectedType = SyncTable.getSqlType(fieldDef.type, fieldDef.max ?? null, fieldDef.unsigned ?? false, fieldDef.precision ?? null, fieldDef.scale ?? null);
|
|
10850
|
+
const incompatible = SyncTable.getIncompatibleTypeChange(tableName, dbFieldName, String(typeChange.current ?? ""), expectedType);
|
|
10851
|
+
if (incompatible) {
|
|
10852
|
+
out.push(incompatible);
|
|
10856
10853
|
}
|
|
10857
10854
|
}
|
|
10858
10855
|
return out;
|
|
10859
10856
|
}
|
|
10857
|
+
static throwIfIncompatibleTypeChanges(incompatibleTypeChanges) {
|
|
10858
|
+
if (incompatibleTypeChanges.length === 0) {
|
|
10859
|
+
return;
|
|
10860
|
+
}
|
|
10861
|
+
const lines = [];
|
|
10862
|
+
for (const change of incompatibleTypeChanges) {
|
|
10863
|
+
lines.push(`- ${change.tableName}.${change.dbFieldName}: ${change.currentType} -> ${change.expectedType}`);
|
|
10864
|
+
}
|
|
10865
|
+
const msgLines = [];
|
|
10866
|
+
msgLines.push("\u7981\u6B62\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4\uFF08\u68C0\u6D4B\u5230\u4E0D\u517C\u5BB9/\u6536\u7F29\u53D8\u66F4\uFF09:");
|
|
10867
|
+
for (const line of lines) {
|
|
10868
|
+
msgLines.push(line);
|
|
10869
|
+
}
|
|
10870
|
+
msgLines.push("\u8BF4\u660E: \u4EC5\u5141\u8BB8\u540C\u7C7B\u578B\u7684\u5BBD\u5316\u53D8\u66F4\uFF08\u5982 TINYINT->SMALLINT->INT->BIGINT\uFF09\uFF0C\u4EE5\u53CA\u90E8\u5206\u517C\u5BB9\u53D8\u66F4\uFF08\u5982 VARCHAR->TEXT\u3001CHAR/VARCHAR \u4E92\u8F6C\u3001float->double\uFF09\u3002");
|
|
10871
|
+
msgLines.push("\u63D0\u793A: \u82E5\u786E\u9700\u6536\u7F29\uFF0C\u8BF7\u5148\u624B\u5DE5\u8FC1\u79FB/\u6E05\u6D17\u6570\u636E\u540E\u518D\u6267\u884C\u540C\u6B65\u3002");
|
|
10872
|
+
throw new CoreError({
|
|
10873
|
+
kind: "policy",
|
|
10874
|
+
message: msgLines.join(`
|
|
10875
|
+
`),
|
|
10876
|
+
noLog: true,
|
|
10877
|
+
meta: {
|
|
10878
|
+
subsystem: "syncTable",
|
|
10879
|
+
operation: "precheck",
|
|
10880
|
+
incompatibleTypeChangeCount: incompatibleTypeChanges.length,
|
|
10881
|
+
incompatibleTypeChanges
|
|
10882
|
+
}
|
|
10883
|
+
});
|
|
10884
|
+
}
|
|
10860
10885
|
static truncateForLog(input, maxLen) {
|
|
10861
10886
|
const s = String(input);
|
|
10862
10887
|
if (maxLen <= 0)
|
|
@@ -16537,10 +16562,16 @@ class Befly {
|
|
|
16537
16562
|
let kind = "runtime";
|
|
16538
16563
|
let alreadyLogged = false;
|
|
16539
16564
|
let noLog = false;
|
|
16565
|
+
let incompatibleTypeChanges = null;
|
|
16566
|
+
let incompatibleTypeChangeCount = null;
|
|
16540
16567
|
if (isCoreError(error)) {
|
|
16541
16568
|
kind = error.kind;
|
|
16542
16569
|
alreadyLogged = error.logged === true;
|
|
16543
16570
|
noLog = error.noLog === true;
|
|
16571
|
+
if (error.meta && typeof error.meta === "object") {
|
|
16572
|
+
incompatibleTypeChanges = error.meta["incompatibleTypeChanges"] ?? null;
|
|
16573
|
+
incompatibleTypeChangeCount = error.meta["incompatibleTypeChangeCount"] ?? null;
|
|
16574
|
+
}
|
|
16544
16575
|
} else {
|
|
16545
16576
|
const anyErr = error;
|
|
16546
16577
|
if (anyErr && anyErr.__syncTableLogged === true) {
|
|
@@ -16560,20 +16591,26 @@ class Befly {
|
|
|
16560
16591
|
Logger.error({
|
|
16561
16592
|
msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25\uFF08\u4E0B\u5C42\u5DF2\u8BB0\u5F55\uFF09",
|
|
16562
16593
|
errorKind: kind,
|
|
16563
|
-
errorMessage: errMessage
|
|
16594
|
+
errorMessage: errMessage,
|
|
16595
|
+
incompatibleTypeChangeCount,
|
|
16596
|
+
incompatibleTypeChanges
|
|
16564
16597
|
});
|
|
16565
16598
|
} else if (noLog) {
|
|
16566
16599
|
Logger.error({
|
|
16567
16600
|
msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25",
|
|
16568
16601
|
errorKind: kind,
|
|
16569
|
-
errorMessage: errMessage
|
|
16602
|
+
errorMessage: errMessage,
|
|
16603
|
+
incompatibleTypeChangeCount,
|
|
16604
|
+
incompatibleTypeChanges
|
|
16570
16605
|
});
|
|
16571
16606
|
} else {
|
|
16572
16607
|
Logger.error({
|
|
16573
16608
|
msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25",
|
|
16574
16609
|
errorKind: kind,
|
|
16575
16610
|
errorMessage: errMessage,
|
|
16576
|
-
err: error
|
|
16611
|
+
err: error,
|
|
16612
|
+
incompatibleTypeChangeCount,
|
|
16613
|
+
incompatibleTypeChanges
|
|
16577
16614
|
});
|
|
16578
16615
|
}
|
|
16579
16616
|
try {
|