befly 3.16.2 → 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
@@ -1405,7 +1405,7 @@ function normalizeViewDirMeta(input) {
1405
1405
  return null;
1406
1406
  }
1407
1407
  const orderRaw = record["order"];
1408
- const order = typeof orderRaw === "number" && Number.isFinite(orderRaw) && Number.isInteger(orderRaw) && orderRaw >= 0 ? orderRaw : undefined;
1408
+ const order = typeof orderRaw === "number" && Number.isFinite(orderRaw) && Number.isInteger(orderRaw) && orderRaw >= 1 ? orderRaw : undefined;
1409
1409
  if (order === undefined) {
1410
1410
  return {
1411
1411
  title
@@ -13921,56 +13921,8 @@ 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
- }
13924
+ // lib/dbHelper.ts
13925
+ init_util();
13974
13926
 
13975
13927
  // utils/fieldClear.ts
13976
13928
  function isObject(val) {
@@ -14022,9 +13974,6 @@ function fieldClear(data, options = {}) {
14022
13974
  return data;
14023
13975
  }
14024
13976
 
14025
- // lib/dbHelper.ts
14026
- init_util();
14027
-
14028
13977
  // lib/dbUtils.ts
14029
13978
  init_util();
14030
13979
 
@@ -14137,6 +14086,73 @@ class SqlCheck {
14137
14086
 
14138
14087
  // lib/dbUtils.ts
14139
14088
  class DbUtils {
14089
+ static clearDeep(value, options) {
14090
+ const arrayObjectKeys = Array.isArray(options?.arrayObjectKeys) ? options.arrayObjectKeys : ["$or", "$and"];
14091
+ const arrayObjectKeySet = new Set;
14092
+ for (const key of arrayObjectKeys) {
14093
+ arrayObjectKeySet.add(key);
14094
+ }
14095
+ const depthRaw = typeof options?.depth === "number" && Number.isFinite(options.depth) ? Math.floor(options.depth) : 0;
14096
+ const depth = depthRaw < 0 ? 0 : depthRaw;
14097
+ const clearInternal = (input, remainingDepth) => {
14098
+ if (!input || typeof input !== "object") {
14099
+ return input;
14100
+ }
14101
+ if (Array.isArray(input)) {
14102
+ return input;
14103
+ }
14104
+ const canRecurse = remainingDepth === 0 || remainingDepth > 1;
14105
+ const childDepth = remainingDepth === 0 ? 0 : remainingDepth - 1;
14106
+ const result = {};
14107
+ for (const [key, item] of Object.entries(input)) {
14108
+ if (item === undefined || item === null) {
14109
+ continue;
14110
+ }
14111
+ if (arrayObjectKeySet.has(key)) {
14112
+ if (!Array.isArray(item)) {
14113
+ continue;
14114
+ }
14115
+ const arrayChildDepth = remainingDepth;
14116
+ const outList = [];
14117
+ for (const child of item) {
14118
+ if (!child || typeof child !== "object" || Array.isArray(child)) {
14119
+ continue;
14120
+ }
14121
+ const cleaned = clearInternal(child, arrayChildDepth);
14122
+ if (!cleaned || typeof cleaned !== "object" || Array.isArray(cleaned)) {
14123
+ continue;
14124
+ }
14125
+ if (Object.keys(cleaned).length === 0) {
14126
+ continue;
14127
+ }
14128
+ outList.push(cleaned);
14129
+ }
14130
+ if (outList.length > 0) {
14131
+ result[key] = outList;
14132
+ }
14133
+ continue;
14134
+ }
14135
+ if (typeof item === "object" && !Array.isArray(item)) {
14136
+ if (!canRecurse) {
14137
+ result[key] = item;
14138
+ continue;
14139
+ }
14140
+ const cleanedObj = clearInternal(item, childDepth);
14141
+ if (!cleanedObj || typeof cleanedObj !== "object" || Array.isArray(cleanedObj)) {
14142
+ continue;
14143
+ }
14144
+ if (Object.keys(cleanedObj).length === 0) {
14145
+ continue;
14146
+ }
14147
+ result[key] = cleanedObj;
14148
+ continue;
14149
+ }
14150
+ result[key] = item;
14151
+ }
14152
+ return result;
14153
+ };
14154
+ return clearInternal(value, depth);
14155
+ }
14140
14156
  static parseTableRef(tableRef) {
14141
14157
  if (typeof tableRef !== "string") {
14142
14158
  throw new Error(`tableRef \u5FC5\u987B\u662F\u5B57\u7B26\u4E32 (tableRef: ${String(tableRef)})`);
@@ -15283,6 +15299,72 @@ class DbHelper {
15283
15299
  sql = null;
15284
15300
  isTransaction = false;
15285
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
+ }
15286
15368
  constructor(options) {
15287
15369
  this.redis = options.redis;
15288
15370
  if (typeof options.dbName !== "string" || options.dbName.trim() === "") {
@@ -15313,7 +15395,7 @@ class DbHelper {
15313
15395
  return columnNames;
15314
15396
  }
15315
15397
  async prepareQueryOptions(options) {
15316
- const cleanWhere = fieldClear(options.where || {}, { excludeValues: [null, undefined] });
15398
+ const cleanWhere = DbUtils.clearDeep(options.where || {});
15317
15399
  const hasJoins = options.joins && options.joins.length > 0;
15318
15400
  if (hasJoins) {
15319
15401
  const processedFields2 = (options.fields || []).map((f) => DbUtils.processJoinField(f));
@@ -15457,7 +15539,7 @@ class DbHelper {
15457
15539
  sql: execRes.sql
15458
15540
  };
15459
15541
  }
15460
- const convertedList = convertBigIntFields([deserialized]);
15542
+ const convertedList = DbHelper.convertBigIntFields([deserialized], options.bigint);
15461
15543
  const data = convertedList[0] ?? deserialized;
15462
15544
  return {
15463
15545
  data,
@@ -15508,7 +15590,7 @@ class DbHelper {
15508
15590
  const deserializedList = camelList.map((item) => DbUtils.deserializeArrayFields(item)).filter((item) => item !== null);
15509
15591
  return {
15510
15592
  data: {
15511
- lists: convertBigIntFields(deserializedList),
15593
+ lists: DbHelper.convertBigIntFields(deserializedList, options.bigint),
15512
15594
  total,
15513
15595
  page: prepared.page,
15514
15596
  limit: prepared.limit,
@@ -15530,6 +15612,8 @@ class DbHelper {
15530
15612
  };
15531
15613
  if (options.fields !== undefined)
15532
15614
  prepareOptions.fields = options.fields;
15615
+ if (options.bigint !== undefined)
15616
+ prepareOptions.bigint = options.bigint;
15533
15617
  if (options.where !== undefined)
15534
15618
  prepareOptions.where = options.where;
15535
15619
  if (options.joins !== undefined)
@@ -15570,7 +15654,7 @@ class DbHelper {
15570
15654
  }
15571
15655
  const camelResult = arrayKeysToCamel(result);
15572
15656
  const deserializedList = camelResult.map((item) => DbUtils.deserializeArrayFields(item)).filter((item) => item !== null);
15573
- const lists = convertBigIntFields(deserializedList);
15657
+ const lists = DbHelper.convertBigIntFields(deserializedList, options.bigint);
15574
15658
  return {
15575
15659
  data: {
15576
15660
  lists,
@@ -15765,7 +15849,7 @@ class DbHelper {
15765
15849
  }
15766
15850
  async updData(options) {
15767
15851
  const { table, data, where } = options;
15768
- const cleanWhere = fieldClear(where, { excludeValues: [null, undefined] });
15852
+ const cleanWhere = DbUtils.clearDeep(where);
15769
15853
  const snakeTable = snakeCase(table);
15770
15854
  const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
15771
15855
  const processed = DbUtils.buildUpdateRow({ data, now: Date.now(), allowState: true });
@@ -15790,7 +15874,7 @@ class DbHelper {
15790
15874
  async delForce(options) {
15791
15875
  const { table, where } = options;
15792
15876
  const snakeTable = snakeCase(table);
15793
- const cleanWhere = fieldClear(where, { excludeValues: [null, undefined] });
15877
+ const cleanWhere = DbUtils.clearDeep(where);
15794
15878
  const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
15795
15879
  const builder = this.createSqlBuilder().where(snakeWhere);
15796
15880
  const { sql, params } = builder.toDeleteSql(snakeTable);
@@ -15855,7 +15939,7 @@ class DbHelper {
15855
15939
  throw new Error(`exists \u4E0D\u652F\u6301 schema.table \u5199\u6CD5\uFF08table: ${rawTable}\uFF09`);
15856
15940
  }
15857
15941
  const snakeTable = snakeCase(rawTable);
15858
- const cleanWhere = fieldClear(options.where || {}, { excludeValues: [null, undefined] });
15942
+ const cleanWhere = DbUtils.clearDeep(options.where || {});
15859
15943
  const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
15860
15944
  const whereFiltered = DbUtils.addDefaultStateFilter(snakeWhere, snakeTable, false);
15861
15945
  const builder = this.createSqlBuilder().selectRaw("COUNT(1) as cnt").from(snakeTable).where(whereFiltered).limit(1);
@@ -15941,7 +16025,7 @@ class DbHelper {
15941
16025
  if (typeof value !== "number" || isNaN(value)) {
15942
16026
  throw new Error(`\u81EA\u589E\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684\u6570\u5B57 (table: ${table}, field: ${field}, value: ${value})`);
15943
16027
  }
15944
- const cleanWhere = fieldClear(where, { excludeValues: [null, undefined] });
16028
+ const cleanWhere = DbUtils.clearDeep(where);
15945
16029
  const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
15946
16030
  const whereFiltered = DbUtils.addDefaultStateFilter(snakeWhere, snakeTable, false);
15947
16031
  const builder = this.createSqlBuilder().where(whereFiltered);