befly 3.16.2 → 3.16.4
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 +76 -9
- package/dist/befly.min.js +20 -20
- package/dist/lib/dbHelper.js +8 -9
- package/dist/lib/dbUtils.d.ts +16 -0
- package/dist/lib/dbUtils.js +80 -0
- package/dist/utils/loadMenuConfigs.js +3 -1
- package/package.json +2 -2
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 >=
|
|
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
|
|
@@ -13972,6 +13972,9 @@ function convertBigIntFields(arr, fields = ["id", "pid", "sort"]) {
|
|
|
13972
13972
|
return arr;
|
|
13973
13973
|
}
|
|
13974
13974
|
|
|
13975
|
+
// lib/dbHelper.ts
|
|
13976
|
+
init_util();
|
|
13977
|
+
|
|
13975
13978
|
// utils/fieldClear.ts
|
|
13976
13979
|
function isObject(val) {
|
|
13977
13980
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
@@ -14022,9 +14025,6 @@ function fieldClear(data, options = {}) {
|
|
|
14022
14025
|
return data;
|
|
14023
14026
|
}
|
|
14024
14027
|
|
|
14025
|
-
// lib/dbHelper.ts
|
|
14026
|
-
init_util();
|
|
14027
|
-
|
|
14028
14028
|
// lib/dbUtils.ts
|
|
14029
14029
|
init_util();
|
|
14030
14030
|
|
|
@@ -14137,6 +14137,73 @@ class SqlCheck {
|
|
|
14137
14137
|
|
|
14138
14138
|
// lib/dbUtils.ts
|
|
14139
14139
|
class DbUtils {
|
|
14140
|
+
static clearDeep(value, options) {
|
|
14141
|
+
const arrayObjectKeys = Array.isArray(options?.arrayObjectKeys) ? options.arrayObjectKeys : ["$or", "$and"];
|
|
14142
|
+
const arrayObjectKeySet = new Set;
|
|
14143
|
+
for (const key of arrayObjectKeys) {
|
|
14144
|
+
arrayObjectKeySet.add(key);
|
|
14145
|
+
}
|
|
14146
|
+
const depthRaw = typeof options?.depth === "number" && Number.isFinite(options.depth) ? Math.floor(options.depth) : 0;
|
|
14147
|
+
const depth = depthRaw < 0 ? 0 : depthRaw;
|
|
14148
|
+
const clearInternal = (input, remainingDepth) => {
|
|
14149
|
+
if (!input || typeof input !== "object") {
|
|
14150
|
+
return input;
|
|
14151
|
+
}
|
|
14152
|
+
if (Array.isArray(input)) {
|
|
14153
|
+
return input;
|
|
14154
|
+
}
|
|
14155
|
+
const canRecurse = remainingDepth === 0 || remainingDepth > 1;
|
|
14156
|
+
const childDepth = remainingDepth === 0 ? 0 : remainingDepth - 1;
|
|
14157
|
+
const result = {};
|
|
14158
|
+
for (const [key, item] of Object.entries(input)) {
|
|
14159
|
+
if (item === undefined || item === null) {
|
|
14160
|
+
continue;
|
|
14161
|
+
}
|
|
14162
|
+
if (arrayObjectKeySet.has(key)) {
|
|
14163
|
+
if (!Array.isArray(item)) {
|
|
14164
|
+
continue;
|
|
14165
|
+
}
|
|
14166
|
+
const arrayChildDepth = remainingDepth;
|
|
14167
|
+
const outList = [];
|
|
14168
|
+
for (const child of item) {
|
|
14169
|
+
if (!child || typeof child !== "object" || Array.isArray(child)) {
|
|
14170
|
+
continue;
|
|
14171
|
+
}
|
|
14172
|
+
const cleaned = clearInternal(child, arrayChildDepth);
|
|
14173
|
+
if (!cleaned || typeof cleaned !== "object" || Array.isArray(cleaned)) {
|
|
14174
|
+
continue;
|
|
14175
|
+
}
|
|
14176
|
+
if (Object.keys(cleaned).length === 0) {
|
|
14177
|
+
continue;
|
|
14178
|
+
}
|
|
14179
|
+
outList.push(cleaned);
|
|
14180
|
+
}
|
|
14181
|
+
if (outList.length > 0) {
|
|
14182
|
+
result[key] = outList;
|
|
14183
|
+
}
|
|
14184
|
+
continue;
|
|
14185
|
+
}
|
|
14186
|
+
if (typeof item === "object" && !Array.isArray(item)) {
|
|
14187
|
+
if (!canRecurse) {
|
|
14188
|
+
result[key] = item;
|
|
14189
|
+
continue;
|
|
14190
|
+
}
|
|
14191
|
+
const cleanedObj = clearInternal(item, childDepth);
|
|
14192
|
+
if (!cleanedObj || typeof cleanedObj !== "object" || Array.isArray(cleanedObj)) {
|
|
14193
|
+
continue;
|
|
14194
|
+
}
|
|
14195
|
+
if (Object.keys(cleanedObj).length === 0) {
|
|
14196
|
+
continue;
|
|
14197
|
+
}
|
|
14198
|
+
result[key] = cleanedObj;
|
|
14199
|
+
continue;
|
|
14200
|
+
}
|
|
14201
|
+
result[key] = item;
|
|
14202
|
+
}
|
|
14203
|
+
return result;
|
|
14204
|
+
};
|
|
14205
|
+
return clearInternal(value, depth);
|
|
14206
|
+
}
|
|
14140
14207
|
static parseTableRef(tableRef) {
|
|
14141
14208
|
if (typeof tableRef !== "string") {
|
|
14142
14209
|
throw new Error(`tableRef \u5FC5\u987B\u662F\u5B57\u7B26\u4E32 (tableRef: ${String(tableRef)})`);
|
|
@@ -15313,7 +15380,7 @@ class DbHelper {
|
|
|
15313
15380
|
return columnNames;
|
|
15314
15381
|
}
|
|
15315
15382
|
async prepareQueryOptions(options) {
|
|
15316
|
-
const cleanWhere =
|
|
15383
|
+
const cleanWhere = DbUtils.clearDeep(options.where || {});
|
|
15317
15384
|
const hasJoins = options.joins && options.joins.length > 0;
|
|
15318
15385
|
if (hasJoins) {
|
|
15319
15386
|
const processedFields2 = (options.fields || []).map((f) => DbUtils.processJoinField(f));
|
|
@@ -15765,7 +15832,7 @@ class DbHelper {
|
|
|
15765
15832
|
}
|
|
15766
15833
|
async updData(options) {
|
|
15767
15834
|
const { table, data, where } = options;
|
|
15768
|
-
const cleanWhere =
|
|
15835
|
+
const cleanWhere = DbUtils.clearDeep(where);
|
|
15769
15836
|
const snakeTable = snakeCase(table);
|
|
15770
15837
|
const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
|
|
15771
15838
|
const processed = DbUtils.buildUpdateRow({ data, now: Date.now(), allowState: true });
|
|
@@ -15790,7 +15857,7 @@ class DbHelper {
|
|
|
15790
15857
|
async delForce(options) {
|
|
15791
15858
|
const { table, where } = options;
|
|
15792
15859
|
const snakeTable = snakeCase(table);
|
|
15793
|
-
const cleanWhere =
|
|
15860
|
+
const cleanWhere = DbUtils.clearDeep(where);
|
|
15794
15861
|
const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
|
|
15795
15862
|
const builder = this.createSqlBuilder().where(snakeWhere);
|
|
15796
15863
|
const { sql, params } = builder.toDeleteSql(snakeTable);
|
|
@@ -15855,7 +15922,7 @@ class DbHelper {
|
|
|
15855
15922
|
throw new Error(`exists \u4E0D\u652F\u6301 schema.table \u5199\u6CD5\uFF08table: ${rawTable}\uFF09`);
|
|
15856
15923
|
}
|
|
15857
15924
|
const snakeTable = snakeCase(rawTable);
|
|
15858
|
-
const cleanWhere =
|
|
15925
|
+
const cleanWhere = DbUtils.clearDeep(options.where || {});
|
|
15859
15926
|
const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
|
|
15860
15927
|
const whereFiltered = DbUtils.addDefaultStateFilter(snakeWhere, snakeTable, false);
|
|
15861
15928
|
const builder = this.createSqlBuilder().selectRaw("COUNT(1) as cnt").from(snakeTable).where(whereFiltered).limit(1);
|
|
@@ -15941,7 +16008,7 @@ class DbHelper {
|
|
|
15941
16008
|
if (typeof value !== "number" || isNaN(value)) {
|
|
15942
16009
|
throw new Error(`\u81EA\u589E\u503C\u5FC5\u987B\u662F\u6709\u6548\u7684\u6570\u5B57 (table: ${table}, field: ${field}, value: ${value})`);
|
|
15943
16010
|
}
|
|
15944
|
-
const cleanWhere =
|
|
16011
|
+
const cleanWhere = DbUtils.clearDeep(where);
|
|
15945
16012
|
const snakeWhere = DbUtils.whereKeysToSnake(cleanWhere);
|
|
15946
16013
|
const whereFiltered = DbUtils.addDefaultStateFilter(snakeWhere, snakeTable, false);
|
|
15947
16014
|
const builder = this.createSqlBuilder().where(whereFiltered);
|