befly 3.15.25 → 3.15.26

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
@@ -499,6 +499,20 @@ import { createWriteStream, existsSync, mkdirSync } from "fs";
499
499
  import { stat } from "fs/promises";
500
500
  import { hostname as osHostname } from "os";
501
501
  import { isAbsolute as nodePathIsAbsolute, join as nodePathJoin, resolve as nodePathResolve } from "path";
502
+ function buildSanitizeOptionsForWrite(writeOptions) {
503
+ if (!writeOptions)
504
+ return sanitizeOptions;
505
+ if (writeOptions.truncate !== false)
506
+ return sanitizeOptions;
507
+ return {
508
+ maxStringLen: 200000,
509
+ maxArrayItems: 5000,
510
+ sanitizeDepth: sanitizeOptions.sanitizeDepth,
511
+ sanitizeNodes: sanitizeOptions.sanitizeNodes,
512
+ sanitizeObjectKeys: sanitizeOptions.sanitizeObjectKeys,
513
+ sensitiveKeyMatcher: sanitizeOptions.sensitiveKeyMatcher
514
+ };
515
+ }
502
516
  function safeWriteStderr(msg) {
503
517
  try {
504
518
  process.stderr.write(`${msg}
@@ -964,7 +978,16 @@ function createSinkLogger(options) {
964
978
  if (level === "debug" && config.debug !== 1)
965
979
  return;
966
980
  const input = isPlainObject(record) ? record : { value: record };
967
- const sanitizedRecord = sanitizeLogObject(input, sanitizeOptions);
981
+ let writeOptions = null;
982
+ if (input && isPlainObject(input)) {
983
+ const raw = input["__loggerWriteOptions"];
984
+ if (raw && isPlainObject(raw)) {
985
+ writeOptions = raw;
986
+ delete input["__loggerWriteOptions"];
987
+ }
988
+ }
989
+ const effectiveSanitizeOptions = buildSanitizeOptionsForWrite(writeOptions);
990
+ const sanitizedRecord = sanitizeLogObject(input, effectiveSanitizeOptions);
968
991
  const line = buildLogLine(level, sanitizedRecord);
969
992
  fileSink.enqueue(line);
970
993
  if (consoleSink)
@@ -1046,34 +1069,47 @@ function withRequestMetaRecord(record) {
1046
1069
  }
1047
1070
 
1048
1071
  class LoggerFacade {
1049
- maybeSanitizeForMock(record) {
1072
+ maybeSanitizeForMock(record, options) {
1050
1073
  if (!mockInstance)
1051
1074
  return record;
1052
- return sanitizeLogObject(record, sanitizeOptions);
1075
+ const effective = buildSanitizeOptionsForWrite(options ? options : null);
1076
+ return sanitizeLogObject(record, effective);
1053
1077
  }
1054
- info(input) {
1078
+ info(input, options) {
1055
1079
  const record0 = withRequestMetaRecord(toRecord(input));
1056
- const record = this.maybeSanitizeForMock(record0);
1080
+ if (!mockInstance && options && isPlainObject(options)) {
1081
+ record0["__loggerWriteOptions"] = options;
1082
+ }
1083
+ const record = this.maybeSanitizeForMock(record0, options);
1057
1084
  getSink("app").info(record);
1058
1085
  }
1059
- warn(input) {
1086
+ warn(input, options) {
1060
1087
  const record0 = withRequestMetaRecord(toRecord(input));
1061
- const record = this.maybeSanitizeForMock(record0);
1088
+ if (!mockInstance && options && isPlainObject(options)) {
1089
+ record0["__loggerWriteOptions"] = options;
1090
+ }
1091
+ const record = this.maybeSanitizeForMock(record0, options);
1062
1092
  getSink("app").warn(record);
1063
1093
  }
1064
- error(input) {
1094
+ error(input, options) {
1065
1095
  const record0 = withRequestMetaRecord(toRecord(input));
1066
- const record = this.maybeSanitizeForMock(record0);
1096
+ if (!mockInstance && options && isPlainObject(options)) {
1097
+ record0["__loggerWriteOptions"] = options;
1098
+ }
1099
+ const record = this.maybeSanitizeForMock(record0, options);
1067
1100
  getSink("app").error(record);
1068
1101
  if (mockInstance)
1069
1102
  return;
1070
1103
  getSink("error").error(record);
1071
1104
  }
1072
- debug(input) {
1105
+ debug(input, options) {
1073
1106
  if (config.debug !== 1)
1074
1107
  return;
1075
1108
  const record0 = withRequestMetaRecord(toRecord(input));
1076
- const record = this.maybeSanitizeForMock(record0);
1109
+ if (!mockInstance && options && isPlainObject(options)) {
1110
+ record0["__loggerWriteOptions"] = options;
1111
+ }
1112
+ const record = this.maybeSanitizeForMock(record0, options);
1077
1113
  getSink("app").debug(record);
1078
1114
  }
1079
1115
  async flush() {
@@ -10876,9 +10912,7 @@ class SyncTable {
10876
10912
  noLog: true,
10877
10913
  meta: {
10878
10914
  subsystem: "syncTable",
10879
- operation: "precheck",
10880
- incompatibleTypeChangeCount: incompatibleTypeChanges.length,
10881
- incompatibleTypeChanges
10915
+ operation: "precheck"
10882
10916
  }
10883
10917
  });
10884
10918
  }
@@ -16562,17 +16596,11 @@ class Befly {
16562
16596
  let kind = "runtime";
16563
16597
  let alreadyLogged = false;
16564
16598
  let noLog = false;
16565
- let incompatibleTypeChanges = null;
16566
- let incompatibleTypeChangeCount = null;
16567
- let incompatibleTypeChangeLines = null;
16599
+ const incompatibleTypeChangeLines = [];
16568
16600
  if (isCoreError(error)) {
16569
16601
  kind = error.kind;
16570
16602
  alreadyLogged = error.logged === true;
16571
16603
  noLog = error.noLog === true;
16572
- if (error.meta && typeof error.meta === "object") {
16573
- incompatibleTypeChanges = error.meta["incompatibleTypeChanges"] ?? null;
16574
- incompatibleTypeChangeCount = error.meta["incompatibleTypeChangeCount"] ?? null;
16575
- }
16576
16604
  } else {
16577
16605
  const anyErr = error;
16578
16606
  if (anyErr && anyErr.__syncTableLogged === true) {
@@ -16589,57 +16617,49 @@ class Befly {
16589
16617
  }
16590
16618
  }
16591
16619
  {
16592
- const lines = [];
16593
- if (Array.isArray(incompatibleTypeChanges)) {
16594
- for (const item of incompatibleTypeChanges) {
16595
- if (!item || typeof item !== "object")
16596
- continue;
16597
- const rec = item;
16598
- const tableName = rec["tableName"];
16599
- const dbFieldName = rec["dbFieldName"];
16600
- const currentType = rec["currentType"];
16601
- const expectedType = rec["expectedType"];
16602
- if (typeof tableName !== "string" || tableName.length === 0)
16603
- continue;
16604
- if (typeof dbFieldName !== "string" || dbFieldName.length === 0)
16605
- continue;
16606
- if (typeof currentType !== "string" || currentType.length === 0)
16607
- continue;
16608
- if (typeof expectedType !== "string" || expectedType.length === 0)
16609
- continue;
16610
- lines.push(`- ${tableName}.${dbFieldName}: ${currentType} -> ${expectedType}`);
16620
+ const text = String(errMessage || "");
16621
+ const parts = text.split(`
16622
+ `);
16623
+ for (const p of parts) {
16624
+ const line = String(p || "").trim();
16625
+ if (line.startsWith("- ")) {
16626
+ incompatibleTypeChangeLines.push(line);
16611
16627
  }
16612
16628
  }
16613
- if (lines.length > 0) {
16614
- incompatibleTypeChangeLines = lines;
16615
- }
16616
16629
  }
16630
+ const errorMessageFirstLine = String(errMessage || "").split(`
16631
+ `)[0] || "";
16617
16632
  if (alreadyLogged) {
16618
16633
  Logger.error({
16619
16634
  msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25\uFF08\u4E0B\u5C42\u5DF2\u8BB0\u5F55\uFF09",
16620
16635
  errorKind: kind,
16621
- errorMessage: errMessage,
16622
- incompatibleTypeChangeCount,
16623
- incompatibleTypeChangeLines
16636
+ errorMessage: errorMessageFirstLine,
16637
+ incompatibleTypeChangeCount: incompatibleTypeChangeLines.length
16624
16638
  });
16625
16639
  } else if (noLog) {
16626
16640
  Logger.error({
16627
16641
  msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25",
16628
16642
  errorKind: kind,
16629
- errorMessage: errMessage,
16630
- incompatibleTypeChangeCount,
16631
- incompatibleTypeChangeLines
16643
+ errorMessage: errorMessageFirstLine,
16644
+ incompatibleTypeChangeCount: incompatibleTypeChangeLines.length
16632
16645
  });
16633
16646
  } else {
16634
16647
  Logger.error({
16635
16648
  msg: "\u9879\u76EE\u542F\u52A8\u5931\u8D25",
16636
16649
  errorKind: kind,
16637
- errorMessage: errMessage,
16650
+ errorMessage: errorMessageFirstLine,
16638
16651
  err: error,
16639
- incompatibleTypeChangeCount,
16640
- incompatibleTypeChangeLines
16652
+ incompatibleTypeChangeCount: incompatibleTypeChangeLines.length
16641
16653
  });
16642
16654
  }
16655
+ if (!alreadyLogged && incompatibleTypeChangeLines.length > 0) {
16656
+ for (const line of incompatibleTypeChangeLines) {
16657
+ Logger.error({
16658
+ msg: "\u4E0D\u517C\u5BB9\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4",
16659
+ incompatibleTypeChangeLine: line
16660
+ }, { truncate: false });
16661
+ }
16662
+ }
16643
16663
  try {
16644
16664
  await Logger.flush();
16645
16665
  } catch {}