befly 3.14.3 → 3.15.0

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.
Files changed (60) hide show
  1. package/dist/befly.config.js +1 -1
  2. package/dist/befly.js +618 -209
  3. package/dist/befly.min.js +13 -13
  4. package/dist/checks/checkApi.d.ts +1 -1
  5. package/dist/checks/checkApi.js +64 -24
  6. package/dist/checks/checkHook.js +20 -14
  7. package/dist/checks/checkPlugin.js +20 -14
  8. package/dist/checks/checkTable.js +6 -3
  9. package/dist/hooks/permission.js +1 -1
  10. package/dist/lib/cipher.js +3 -4
  11. package/dist/lib/connect.js +2 -1
  12. package/dist/lib/dbDialect.d.ts +4 -4
  13. package/dist/lib/dbDialect.js +3 -12
  14. package/dist/lib/dbHelper.d.ts +8 -3
  15. package/dist/lib/dbHelper.js +85 -35
  16. package/dist/lib/dbUtils.js +2 -2
  17. package/dist/lib/logger.d.ts +6 -11
  18. package/dist/lib/logger.js +15 -10
  19. package/dist/lib/sqlBuilder.js +10 -2
  20. package/dist/lib/validator.d.ts +3 -3
  21. package/dist/lib/validator.js +59 -7
  22. package/dist/loader/loadApis.js +38 -6
  23. package/dist/loader/loadHooks.js +12 -5
  24. package/dist/loader/loadPlugins.js +13 -6
  25. package/dist/plugins/tool.d.ts +11 -9
  26. package/dist/plugins/tool.js +1 -1
  27. package/dist/sync/syncApi.d.ts +2 -2
  28. package/dist/sync/syncApi.js +23 -11
  29. package/dist/sync/syncDev.js +2 -2
  30. package/dist/sync/syncMenu.js +3 -2
  31. package/dist/sync/syncTable.d.ts +22 -26
  32. package/dist/sync/syncTable.js +114 -25
  33. package/dist/types/api.d.ts +11 -10
  34. package/dist/types/befly.d.ts +12 -12
  35. package/dist/types/common.d.ts +23 -6
  36. package/dist/types/context.d.ts +7 -3
  37. package/dist/types/database.d.ts +15 -15
  38. package/dist/types/jwt.d.ts +3 -2
  39. package/dist/types/logger.d.ts +24 -7
  40. package/dist/types/sync.d.ts +7 -7
  41. package/dist/types/validate.d.ts +12 -4
  42. package/dist/utils/convertBigIntFields.d.ts +2 -1
  43. package/dist/utils/convertBigIntFields.js +3 -12
  44. package/dist/utils/isDirentDirectory.d.ts +2 -1
  45. package/dist/utils/loadMenuConfigs.d.ts +1 -1
  46. package/dist/utils/loadMenuConfigs.js +11 -3
  47. package/dist/utils/mergeAndConcat.d.ts +1 -1
  48. package/dist/utils/mergeAndConcat.js +22 -17
  49. package/dist/utils/normalizeFieldDefinition.d.ts +2 -1
  50. package/dist/utils/scanCoreBuiltins.js +9 -5
  51. package/dist/utils/scanFiles.d.ts +2 -2
  52. package/dist/utils/scanFiles.js +1 -1
  53. package/dist/utils/sortModules.js +8 -1
  54. package/dist/utils/sqlParams.d.ts +10 -0
  55. package/dist/utils/sqlParams.js +78 -0
  56. package/dist/utils/sqlResult.d.ts +5 -0
  57. package/dist/utils/sqlResult.js +7 -0
  58. package/dist/utils/util.d.ts +7 -6
  59. package/dist/utils/util.js +8 -5
  60. package/package.json +2 -2
@@ -97,7 +97,7 @@ export async function scanFiles(dir, source, type, pattern) {
97
97
  customKeys: isPlainObject(content) ? Object.keys(content) : []
98
98
  };
99
99
  if (type === "table") {
100
- base["content"] = content;
100
+ base["content"] = isPlainObject(content) ? content : {};
101
101
  results.push(base);
102
102
  continue;
103
103
  }
@@ -18,7 +18,14 @@ export function sortModules(items, options = {}) {
18
18
  }
19
19
  return camelCase(item.fileName);
20
20
  });
21
- const getDeps = options.getDeps || ((item) => item.deps);
21
+ const getDeps = options.getDeps ||
22
+ ((item) => {
23
+ const deps = item.deps;
24
+ if (!Array.isArray(deps)) {
25
+ return [];
26
+ }
27
+ return deps.filter((x) => typeof x === "string");
28
+ });
22
29
  const result = [];
23
30
  const visited = new Set();
24
31
  const visiting = new Set();
@@ -0,0 +1,10 @@
1
+ import type { SqlValue } from "../types/common";
2
+ export declare function isSqlValue(value: unknown): value is SqlValue;
3
+ /**
4
+ * 将外部输入参数(unknown[])转换为 DbHelper/sqlInfo 可接受的 SqlValue[]。
5
+ *
6
+ * 规则:
7
+ * - bigint -> string
8
+ * - 其他不可序列化值 -> String(value)
9
+ */
10
+ export declare function toSqlParams(params: unknown[] | undefined): SqlValue[];
@@ -0,0 +1,78 @@
1
+ function isJsonPrimitive(value) {
2
+ if (value === null)
3
+ return true;
4
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
5
+ }
6
+ function isJsonObject(value) {
7
+ if (!value || typeof value !== "object")
8
+ return false;
9
+ if (value instanceof Date)
10
+ return false;
11
+ if (Array.isArray(value))
12
+ return false;
13
+ return true;
14
+ }
15
+ function isJsonValue(value) {
16
+ if (isJsonPrimitive(value))
17
+ return true;
18
+ if (Array.isArray(value)) {
19
+ for (const item of value) {
20
+ if (!isJsonValue(item))
21
+ return false;
22
+ }
23
+ return true;
24
+ }
25
+ if (isJsonObject(value)) {
26
+ for (const v of Object.values(value)) {
27
+ if (v === undefined)
28
+ continue;
29
+ if (!isJsonValue(v))
30
+ return false;
31
+ }
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+ export function isSqlValue(value) {
37
+ if (value instanceof Date)
38
+ return true;
39
+ return isJsonValue(value);
40
+ }
41
+ /**
42
+ * 将外部输入参数(unknown[])转换为 DbHelper/sqlInfo 可接受的 SqlValue[]。
43
+ *
44
+ * 规则:
45
+ * - bigint -> string
46
+ * - 其他不可序列化值 -> String(value)
47
+ */
48
+ export function toSqlParams(params) {
49
+ if (!Array.isArray(params)) {
50
+ return [];
51
+ }
52
+ const out = [];
53
+ for (const value of params) {
54
+ if (value === null) {
55
+ out.push(null);
56
+ continue;
57
+ }
58
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
59
+ out.push(value);
60
+ continue;
61
+ }
62
+ if (typeof value === "bigint") {
63
+ out.push(String(value));
64
+ continue;
65
+ }
66
+ if (value instanceof Date) {
67
+ out.push(value);
68
+ continue;
69
+ }
70
+ if (isJsonValue(value)) {
71
+ // JsonObject / JsonValue[] 都属于 SqlValue 允许的范围
72
+ out.push(value);
73
+ continue;
74
+ }
75
+ out.push(String(value));
76
+ }
77
+ return out;
78
+ }
@@ -0,0 +1,5 @@
1
+ export type SqlRunResult = {
2
+ changes?: number | bigint;
3
+ lastInsertRowid?: number | bigint;
4
+ };
5
+ export declare function toNumberFromSql(value: unknown): number;
@@ -0,0 +1,7 @@
1
+ export function toNumberFromSql(value) {
2
+ if (typeof value === "number")
3
+ return value;
4
+ if (typeof value === "bigint")
5
+ return Number(value);
6
+ return 0;
7
+ }
@@ -3,11 +3,11 @@
3
3
  * - 按项目规范:避免零散小文件噪音;实现集中在本文件,而不是做 re-export 聚合。
4
4
  * - 仅在 packages/core 内部使用;core 对外不承诺这些路径导出。
5
5
  */
6
- export declare function isPlainObject(value: unknown): value is Record<string, any>;
6
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
7
7
  export type ValueTypeTag = "undefined" | "null" | "string" | "number" | "boolean" | "bigint" | "symbol" | "function" | "array" | "object";
8
8
  export declare function getTypeTag(value: unknown): ValueTypeTag;
9
9
  export declare function escapeRegExp(input: string): string;
10
- export declare function normalizePositiveInt(value: any, fallback: number, min: number, max: number): number;
10
+ export declare function normalizePositiveInt(value: unknown, fallback: number, min: number, max: number): number;
11
11
  /**
12
12
  * 激进空值判断(项目约定):
13
13
  * - null/undefined => empty
@@ -20,7 +20,7 @@ export declare function normalizePositiveInt(value: any, fallback: number, min:
20
20
  * - 其他类型 => false
21
21
  */
22
22
  export declare function isEmpty(value: unknown): boolean;
23
- export declare function forOwn(obj: unknown, iteratee: (value: any, key: string) => void): void;
23
+ export declare function forOwn(obj: unknown, iteratee: (value: unknown, key: string) => void): void;
24
24
  /**
25
25
  * 把字符串转为小驼峰。
26
26
  * - 主要用于文件名/目录名(例如 my_plugin / my-plugin / my plugin)。
@@ -65,17 +65,18 @@ export declare const keysToSnake: <T = any>(obj: Record<string, any>) => T;
65
65
  */
66
66
  export declare const arrayKeysToCamel: <T = any>(arr: Record<string, any>[]) => T[];
67
67
  export declare function getByPath(obj: unknown, path: string): unknown;
68
- export declare function setByPath(target: Record<string, any>, path: string, value: unknown): void;
68
+ export declare function setByPath(target: Record<string, unknown>, path: string, value: unknown): void;
69
69
  /**
70
70
  * 返回一个移除指定 key 的浅拷贝。
71
71
  * - 仅处理 plain object;其他类型返回空对象,避免日志场景抛错。
72
72
  */
73
- export declare function omit<T extends Record<string, any>>(obj: unknown, keys: string[]): Partial<T>;
73
+ export declare function omit<T extends Record<string, unknown>>(obj: unknown, keys: string[]): Partial<T>;
74
74
  /**
75
75
  * 挑选指定字段
76
76
  */
77
- export declare const pickFields: <T extends Record<string, any>>(obj: T, keys: string[]) => Partial<T>;
77
+ export declare const pickFields: (obj: unknown, keys: readonly string[]) => Record<string, unknown>;
78
78
  export declare function keyBy<T>(items: T[], getKey: (item: T) => string): Record<string, T>;
79
+ export declare function keyBy(items: unknown, getKey: unknown): Record<string, unknown>;
79
80
  /**
80
81
  * 生成短 ID
81
82
  * 由时间戳(base36)+ 随机字符组成,约 13 位
@@ -90,8 +90,9 @@ export function forOwn(obj, iteratee) {
90
90
  if (!isPlainObject(obj)) {
91
91
  return;
92
92
  }
93
- for (const key of Object.keys(obj)) {
94
- iteratee(obj[key], key);
93
+ const record = obj;
94
+ for (const key of Object.keys(record)) {
95
+ iteratee(record[key], key);
95
96
  }
96
97
  }
97
98
  function toWordParts(input) {
@@ -216,7 +217,8 @@ export function getByPath(obj, path) {
216
217
  if (typeof cur !== "object") {
217
218
  return undefined;
218
219
  }
219
- cur = cur[part];
220
+ const record = cur;
221
+ cur = record[part];
220
222
  }
221
223
  return cur;
222
224
  }
@@ -271,10 +273,11 @@ export const pickFields = (obj, keys) => {
271
273
  if (!obj || (!isPlainObject(obj) && !Array.isArray(obj))) {
272
274
  return {};
273
275
  }
276
+ const record = obj;
274
277
  const result = {};
275
278
  for (const key of keys) {
276
- if (key in obj) {
277
- result[key] = obj[key];
279
+ if (key in record) {
280
+ result[key] = record[key];
278
281
  }
279
282
  }
280
283
  return result;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.14.3",
4
- "gitHead": "5a041666725189792d66b994d4d35a28822637ad",
3
+ "version": "3.15.0",
4
+ "gitHead": "3a9dc64d2eb69e646f4fd6eebd5d8dbe6516cb69",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
7
7
  "keywords": [