befly 3.14.2 → 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.
- package/dist/befly.config.js +1 -1
- package/dist/befly.js +618 -209
- package/dist/befly.min.js +13 -13
- package/dist/checks/checkApi.d.ts +1 -1
- package/dist/checks/checkApi.js +64 -24
- package/dist/checks/checkHook.js +20 -14
- package/dist/checks/checkPlugin.js +20 -14
- package/dist/checks/checkTable.js +6 -3
- package/dist/hooks/permission.js +1 -1
- package/dist/lib/cipher.js +3 -4
- package/dist/lib/connect.js +2 -1
- package/dist/lib/dbDialect.d.ts +4 -4
- package/dist/lib/dbDialect.js +3 -12
- package/dist/lib/dbHelper.d.ts +8 -3
- package/dist/lib/dbHelper.js +85 -35
- package/dist/lib/dbUtils.js +2 -2
- package/dist/lib/logger.d.ts +6 -11
- package/dist/lib/logger.js +15 -10
- package/dist/lib/sqlBuilder.js +10 -2
- package/dist/lib/validator.d.ts +3 -3
- package/dist/lib/validator.js +59 -7
- package/dist/loader/loadApis.js +38 -6
- package/dist/loader/loadHooks.js +12 -5
- package/dist/loader/loadPlugins.js +13 -6
- package/dist/plugins/tool.d.ts +11 -9
- package/dist/plugins/tool.js +1 -1
- package/dist/sync/syncApi.d.ts +2 -2
- package/dist/sync/syncApi.js +23 -11
- package/dist/sync/syncDev.js +2 -2
- package/dist/sync/syncMenu.js +3 -2
- package/dist/sync/syncTable.d.ts +22 -26
- package/dist/sync/syncTable.js +114 -25
- package/dist/types/api.d.ts +11 -10
- package/dist/types/befly.d.ts +17 -11
- package/dist/types/common.d.ts +23 -6
- package/dist/types/context.d.ts +7 -3
- package/dist/types/database.d.ts +50 -15
- package/dist/types/jwt.d.ts +3 -2
- package/dist/types/logger.d.ts +24 -7
- package/dist/types/sync.d.ts +7 -7
- package/dist/types/validate.d.ts +12 -4
- package/dist/utils/convertBigIntFields.d.ts +2 -1
- package/dist/utils/convertBigIntFields.js +3 -12
- package/dist/utils/isDirentDirectory.d.ts +2 -1
- package/dist/utils/loadMenuConfigs.d.ts +1 -1
- package/dist/utils/loadMenuConfigs.js +11 -3
- package/dist/utils/mergeAndConcat.d.ts +1 -1
- package/dist/utils/mergeAndConcat.js +22 -17
- package/dist/utils/normalizeFieldDefinition.d.ts +2 -1
- package/dist/utils/scanCoreBuiltins.js +9 -5
- package/dist/utils/scanFiles.d.ts +2 -2
- package/dist/utils/scanFiles.js +1 -1
- package/dist/utils/sortModules.js +8 -1
- package/dist/utils/sqlParams.d.ts +10 -0
- package/dist/utils/sqlParams.js +78 -0
- package/dist/utils/sqlResult.d.ts +5 -0
- package/dist/utils/sqlResult.js +7 -0
- package/dist/utils/util.d.ts +7 -6
- package/dist/utils/util.js +8 -5
- package/package.json +2 -2
|
@@ -13,9 +13,12 @@ import corePluginRedis from "../plugins/redis";
|
|
|
13
13
|
import corePluginTool from "../plugins/tool";
|
|
14
14
|
import { isPlainObject } from "./util";
|
|
15
15
|
function toCoreBuiltinScanFileResult(type, item) {
|
|
16
|
-
const
|
|
16
|
+
const record = (isPlainObject(item) ? item : {});
|
|
17
|
+
const name = typeof record["name"] === "string" ? String(record["name"]) : "";
|
|
17
18
|
const customKeys = isPlainObject(item) ? Object.keys(item) : [];
|
|
18
|
-
|
|
19
|
+
const depsRaw = record["deps"];
|
|
20
|
+
const deps = Array.isArray(depsRaw) ? depsRaw.filter((x) => typeof x === "string") : [];
|
|
21
|
+
const out = {
|
|
19
22
|
source: "core",
|
|
20
23
|
type: type,
|
|
21
24
|
sourceName: "核心",
|
|
@@ -27,11 +30,12 @@ function toCoreBuiltinScanFileResult(type, item) {
|
|
|
27
30
|
fileBaseName: name,
|
|
28
31
|
fileDir: "(builtin)",
|
|
29
32
|
name: name,
|
|
30
|
-
enable:
|
|
31
|
-
deps:
|
|
32
|
-
handler:
|
|
33
|
+
enable: record["enable"],
|
|
34
|
+
deps: deps,
|
|
35
|
+
handler: record["handler"] ?? null,
|
|
33
36
|
customKeys: customKeys
|
|
34
37
|
};
|
|
38
|
+
return out;
|
|
35
39
|
}
|
|
36
40
|
export function scanCoreBuiltinPlugins() {
|
|
37
41
|
const plugins = [];
|
|
@@ -18,10 +18,10 @@ export interface ScanFileResultBase {
|
|
|
18
18
|
}
|
|
19
19
|
export type ScanFileResult = (ScanFileResultBase & {
|
|
20
20
|
type: "table";
|
|
21
|
-
content:
|
|
21
|
+
content: Record<string, unknown>;
|
|
22
22
|
}) | (ScanFileResultBase & {
|
|
23
23
|
type: Exclude<ScanFileType, "table">;
|
|
24
|
-
} & Record<string,
|
|
24
|
+
} & Record<string, unknown>);
|
|
25
25
|
/**
|
|
26
26
|
* 扫描指定目录下的文件
|
|
27
27
|
* @param dir 目录路径
|
package/dist/utils/scanFiles.js
CHANGED
|
@@ -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 ||
|
|
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
|
+
}
|
package/dist/utils/util.d.ts
CHANGED
|
@@ -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,
|
|
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:
|
|
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:
|
|
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,
|
|
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,
|
|
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:
|
|
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 位
|
package/dist/utils/util.js
CHANGED
|
@@ -90,8 +90,9 @@ export function forOwn(obj, iteratee) {
|
|
|
90
90
|
if (!isPlainObject(obj)) {
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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
|
|
277
|
-
result[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.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.15.0",
|
|
4
|
+
"gitHead": "3a9dc64d2eb69e646f4fd6eebd5d8dbe6516cb69",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|