befly 3.15.22 → 3.15.23

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 CHANGED
@@ -10403,23 +10403,7 @@ class SyncTable {
10403
10403
  }
10404
10404
  tableTasks.push(task);
10405
10405
  }
10406
- if (incompatibleTypeChanges.length > 0) {
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
- SyncTable.assertCompatibleTypeChange(options.tableName, dbFieldName, comparison, fieldDef);
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 assertCompatibleTypeChange(tableName, dbFieldName, comparison, fieldDef) {
10823
- const typeChange = comparison.find((c) => c.type === "datatype");
10824
- if (!typeChange)
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
- throw new Error([`\u7981\u6B62\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4: ${tableName}.${dbFieldName}`, `\u5F53\u524D\u7C7B\u578B: ${typeChange.current}`, `\u76EE\u6807\u7C7B\u578B: ${typeChange.expected}`, "\u8BF4\u660E: \u4EC5\u5141\u8BB8\u5BBD\u5316\u578B\u53D8\u66F4\uFF08\u5982 INT->BIGINT, VARCHAR->TEXT\uFF09\uFF0C\u4EE5\u53CA CHAR/VARCHAR \u4E92\u8F6C\uFF1BDATETIME \u4E0E BIGINT \u4E0D\u5141\u8BB8\u4E92\u8F6C\uFF08\u9700\u8981\u624B\u52A8\u8FC1\u79FB\u6570\u636E\uFF09"].join(`
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,37 @@ class SyncTable {
10842
10846
  const typeChange = comparison.find((c) => c.type === "datatype");
10843
10847
  if (!typeChange)
10844
10848
  continue;
10845
- const currentType = String(typeChange.current || "").toLowerCase();
10846
- const expectedType = String(typeChange.expected || "").toLowerCase();
10847
- const currentBase = currentType.replace(/\s*unsigned/gi, "").replace(/\([^)]*\)/g, "").trim();
10848
- const expectedBase = expectedType.replace(/\s*unsigned/gi, "").replace(/\([^)]*\)/g, "").trim();
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: { subsystem: "syncTable", operation: "precheck" }
10878
+ });
10879
+ }
10860
10880
  static truncateForLog(input, maxLen) {
10861
10881
  const s = String(input);
10862
10882
  if (maxLen <= 0)