befly 3.16.4 → 3.16.5

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
@@ -13921,57 +13921,6 @@ var configPlugin = {
13921
13921
  };
13922
13922
  var config_default = configPlugin;
13923
13923
 
13924
- // utils/convertBigIntFields.ts
13925
- function convertBigIntFields(arr, fields = ["id", "pid", "sort"]) {
13926
- if (arr === null || arr === undefined) {
13927
- return arr;
13928
- }
13929
- const MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
13930
- const MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
13931
- const convertRecord = (source) => {
13932
- const converted = {};
13933
- for (const [key, value] of Object.entries(source)) {
13934
- converted[key] = value;
13935
- }
13936
- for (const [key, value] of Object.entries(converted)) {
13937
- if (value === undefined || value === null) {
13938
- continue;
13939
- }
13940
- const shouldConvert = fields.includes(key) || key.endsWith("Id") || key.endsWith("_id") || key.endsWith("At") || key.endsWith("_at");
13941
- if (!shouldConvert) {
13942
- continue;
13943
- }
13944
- let bigintValue = null;
13945
- if (typeof value === "bigint") {
13946
- bigintValue = value;
13947
- } else if (typeof value === "string") {
13948
- if (!/^-?\d+$/.test(value)) {
13949
- continue;
13950
- }
13951
- try {
13952
- bigintValue = BigInt(value);
13953
- } catch {
13954
- continue;
13955
- }
13956
- } else {
13957
- continue;
13958
- }
13959
- if (bigintValue > MAX_SAFE_INTEGER_BIGINT || bigintValue < MIN_SAFE_INTEGER_BIGINT) {
13960
- throw new Error(`BIGINT \u5B57\u6BB5\u8D85\u51FA JS \u5B89\u5168\u6574\u6570\u8303\u56F4\uFF0C\u8BF7\u6539\u7528 bigint/string \u6216\u8C03\u6574\u5B57\u6BB5\u8BBE\u8BA1 (field: ${key}, value: ${String(value)})`);
13961
- }
13962
- converted[key] = Number(bigintValue);
13963
- }
13964
- return converted;
13965
- };
13966
- if (Array.isArray(arr)) {
13967
- return arr.map((item) => convertRecord(item));
13968
- }
13969
- if (typeof arr === "object") {
13970
- return convertRecord(arr);
13971
- }
13972
- return arr;
13973
- }
13974
-
13975
13924
  // lib/dbHelper.ts
13976
13925
  init_util();
13977
13926
 
@@ -15350,6 +15299,72 @@ class DbHelper {
15350
15299
  sql = null;
15351
15300
  isTransaction = false;
15352
15301
  idMode;
15302
+ static convertBigIntFields(arr, fields) {
15303
+ if (arr === null || arr === undefined) {
15304
+ return arr;
15305
+ }
15306
+ const defaultFields = ["id", "pid", "sort"];
15307
+ const buildFields = (userFields) => {
15308
+ if (!userFields || userFields.length === 0) {
15309
+ return defaultFields;
15310
+ }
15311
+ const merged = ["id", "pid", "sort"];
15312
+ for (const f of userFields) {
15313
+ if (typeof f !== "string") {
15314
+ continue;
15315
+ }
15316
+ const trimmed = f.trim();
15317
+ if (trimmed.length === 0) {
15318
+ continue;
15319
+ }
15320
+ if (!merged.includes(trimmed)) {
15321
+ merged.push(trimmed);
15322
+ }
15323
+ }
15324
+ return merged;
15325
+ };
15326
+ const effectiveFields = buildFields(fields);
15327
+ const fieldSet = new Set(effectiveFields);
15328
+ const MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
15329
+ const MIN_SAFE_INTEGER_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
15330
+ const convertRecord = (source) => {
15331
+ const converted = {};
15332
+ for (const [key, value] of Object.entries(source)) {
15333
+ let nextValue = value;
15334
+ if (value !== undefined && value !== null) {
15335
+ const shouldConvert = fieldSet.has(key) || key.endsWith("Id") || key.endsWith("_id") || key.endsWith("At") || key.endsWith("_at");
15336
+ if (shouldConvert) {
15337
+ let bigintValue = null;
15338
+ if (typeof value === "bigint") {
15339
+ bigintValue = value;
15340
+ } else if (typeof value === "string") {
15341
+ if (/^-?\d+$/.test(value)) {
15342
+ try {
15343
+ bigintValue = BigInt(value);
15344
+ } catch {
15345
+ bigintValue = null;
15346
+ }
15347
+ }
15348
+ }
15349
+ if (bigintValue !== null) {
15350
+ if (bigintValue <= MAX_SAFE_INTEGER_BIGINT && bigintValue >= MIN_SAFE_INTEGER_BIGINT) {
15351
+ nextValue = Number(bigintValue);
15352
+ }
15353
+ }
15354
+ }
15355
+ }
15356
+ converted[key] = nextValue;
15357
+ }
15358
+ return converted;
15359
+ };
15360
+ if (Array.isArray(arr)) {
15361
+ return arr.map((item) => convertRecord(item));
15362
+ }
15363
+ if (typeof arr === "object") {
15364
+ return convertRecord(arr);
15365
+ }
15366
+ return arr;
15367
+ }
15353
15368
  constructor(options) {
15354
15369
  this.redis = options.redis;
15355
15370
  if (typeof options.dbName !== "string" || options.dbName.trim() === "") {
@@ -15524,7 +15539,7 @@ class DbHelper {
15524
15539
  sql: execRes.sql
15525
15540
  };
15526
15541
  }
15527
- const convertedList = convertBigIntFields([deserialized]);
15542
+ const convertedList = DbHelper.convertBigIntFields([deserialized], options.bigint);
15528
15543
  const data = convertedList[0] ?? deserialized;
15529
15544
  return {
15530
15545
  data,
@@ -15575,7 +15590,7 @@ class DbHelper {
15575
15590
  const deserializedList = camelList.map((item) => DbUtils.deserializeArrayFields(item)).filter((item) => item !== null);
15576
15591
  return {
15577
15592
  data: {
15578
- lists: convertBigIntFields(deserializedList),
15593
+ lists: DbHelper.convertBigIntFields(deserializedList, options.bigint),
15579
15594
  total,
15580
15595
  page: prepared.page,
15581
15596
  limit: prepared.limit,
@@ -15597,6 +15612,8 @@ class DbHelper {
15597
15612
  };
15598
15613
  if (options.fields !== undefined)
15599
15614
  prepareOptions.fields = options.fields;
15615
+ if (options.bigint !== undefined)
15616
+ prepareOptions.bigint = options.bigint;
15600
15617
  if (options.where !== undefined)
15601
15618
  prepareOptions.where = options.where;
15602
15619
  if (options.joins !== undefined)
@@ -15637,7 +15654,7 @@ class DbHelper {
15637
15654
  }
15638
15655
  const camelResult = arrayKeysToCamel(result);
15639
15656
  const deserializedList = camelResult.map((item) => DbUtils.deserializeArrayFields(item)).filter((item) => item !== null);
15640
- const lists = convertBigIntFields(deserializedList);
15657
+ const lists = DbHelper.convertBigIntFields(deserializedList, options.bigint);
15641
15658
  return {
15642
15659
  data: {
15643
15660
  lists,