befly 3.16.9 → 3.16.11
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/README.md +0 -129
- package/befly.js +12769 -0
- package/befly.min.js +47 -0
- package/package.json +18 -29
- package/dist/befly.config.d.ts +0 -7
- package/dist/befly.config.js +0 -128
- package/dist/befly.js +0 -17276
- package/dist/befly.min.js +0 -23
- package/dist/checks/checkApi.d.ts +0 -1
- package/dist/checks/checkApi.js +0 -124
- package/dist/checks/checkConfig.d.ts +0 -9
- package/dist/checks/checkConfig.js +0 -255
- package/dist/checks/checkHook.d.ts +0 -1
- package/dist/checks/checkHook.js +0 -132
- package/dist/checks/checkMenu.d.ts +0 -3
- package/dist/checks/checkMenu.js +0 -106
- package/dist/checks/checkPlugin.d.ts +0 -1
- package/dist/checks/checkPlugin.js +0 -132
- package/dist/checks/checkTable.d.ts +0 -7
- package/dist/checks/checkTable.js +0 -431
- package/dist/configs/presetRegexp.d.ts +0 -145
- package/dist/configs/presetRegexp.js +0 -218
- package/dist/hooks/auth.d.ts +0 -3
- package/dist/hooks/auth.js +0 -24
- package/dist/hooks/cors.d.ts +0 -7
- package/dist/hooks/cors.js +0 -36
- package/dist/hooks/parser.d.ts +0 -10
- package/dist/hooks/parser.js +0 -76
- package/dist/hooks/permission.d.ts +0 -10
- package/dist/hooks/permission.js +0 -64
- package/dist/hooks/validator.d.ts +0 -7
- package/dist/hooks/validator.js +0 -52
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -316
- package/dist/lib/asyncContext.d.ts +0 -21
- package/dist/lib/asyncContext.js +0 -27
- package/dist/lib/cacheHelper.d.ts +0 -128
- package/dist/lib/cacheHelper.js +0 -477
- package/dist/lib/cacheKeys.d.ts +0 -27
- package/dist/lib/cacheKeys.js +0 -37
- package/dist/lib/cipher.d.ts +0 -153
- package/dist/lib/cipher.js +0 -237
- package/dist/lib/connect.d.ts +0 -95
- package/dist/lib/connect.js +0 -313
- package/dist/lib/dbHelper.d.ts +0 -229
- package/dist/lib/dbHelper.js +0 -1069
- package/dist/lib/dbUtils.d.ts +0 -91
- package/dist/lib/dbUtils.js +0 -544
- package/dist/lib/jwt.d.ts +0 -13
- package/dist/lib/jwt.js +0 -77
- package/dist/lib/logger.d.ts +0 -46
- package/dist/lib/logger.js +0 -731
- package/dist/lib/redisHelper.d.ts +0 -193
- package/dist/lib/redisHelper.js +0 -598
- package/dist/lib/sqlBuilder.d.ts +0 -160
- package/dist/lib/sqlBuilder.js +0 -837
- package/dist/lib/sqlCheck.d.ts +0 -23
- package/dist/lib/sqlCheck.js +0 -119
- package/dist/lib/validator.d.ts +0 -45
- package/dist/lib/validator.js +0 -424
- package/dist/loader/loadApis.d.ts +0 -12
- package/dist/loader/loadApis.js +0 -71
- package/dist/loader/loadHooks.d.ts +0 -7
- package/dist/loader/loadHooks.js +0 -50
- package/dist/loader/loadPlugins.d.ts +0 -8
- package/dist/loader/loadPlugins.js +0 -69
- package/dist/paths.d.ts +0 -93
- package/dist/paths.js +0 -100
- package/dist/plugins/cache.d.ts +0 -10
- package/dist/plugins/cache.js +0 -24
- package/dist/plugins/cipher.d.ts +0 -7
- package/dist/plugins/cipher.js +0 -14
- package/dist/plugins/config.d.ts +0 -3
- package/dist/plugins/config.js +0 -9
- package/dist/plugins/db.d.ts +0 -10
- package/dist/plugins/db.js +0 -48
- package/dist/plugins/jwt.d.ts +0 -6
- package/dist/plugins/jwt.js +0 -13
- package/dist/plugins/logger.d.ts +0 -10
- package/dist/plugins/logger.js +0 -21
- package/dist/plugins/redis.d.ts +0 -10
- package/dist/plugins/redis.js +0 -40
- package/dist/plugins/tool.d.ts +0 -75
- package/dist/plugins/tool.js +0 -105
- package/dist/router/api.d.ts +0 -14
- package/dist/router/api.js +0 -109
- package/dist/router/static.d.ts +0 -9
- package/dist/router/static.js +0 -56
- package/dist/scripts/ensureDist.d.ts +0 -1
- package/dist/scripts/ensureDist.js +0 -296
- package/dist/sync/syncApi.d.ts +0 -3
- package/dist/sync/syncApi.js +0 -140
- package/dist/sync/syncCache.d.ts +0 -2
- package/dist/sync/syncCache.js +0 -14
- package/dist/sync/syncDev.d.ts +0 -6
- package/dist/sync/syncDev.js +0 -166
- package/dist/sync/syncMenu.d.ts +0 -14
- package/dist/sync/syncMenu.js +0 -308
- package/dist/sync/syncTable.d.ts +0 -126
- package/dist/sync/syncTable.js +0 -1129
- package/dist/types/api.d.ts +0 -175
- package/dist/types/api.js +0 -4
- package/dist/types/befly.d.ts +0 -231
- package/dist/types/befly.js +0 -4
- package/dist/types/cache.d.ts +0 -96
- package/dist/types/cache.js +0 -4
- package/dist/types/cipher.d.ts +0 -27
- package/dist/types/cipher.js +0 -7
- package/dist/types/common.d.ts +0 -127
- package/dist/types/common.js +0 -5
- package/dist/types/context.d.ts +0 -39
- package/dist/types/context.js +0 -4
- package/dist/types/coreError.d.ts +0 -31
- package/dist/types/coreError.js +0 -38
- package/dist/types/crypto.d.ts +0 -20
- package/dist/types/crypto.js +0 -4
- package/dist/types/database.d.ts +0 -182
- package/dist/types/database.js +0 -4
- package/dist/types/hook.d.ts +0 -30
- package/dist/types/hook.js +0 -19
- package/dist/types/jwt.d.ts +0 -76
- package/dist/types/jwt.js +0 -4
- package/dist/types/logger.d.ts +0 -95
- package/dist/types/logger.js +0 -6
- package/dist/types/plugin.d.ts +0 -27
- package/dist/types/plugin.js +0 -17
- package/dist/types/redis.d.ts +0 -80
- package/dist/types/redis.js +0 -4
- package/dist/types/roleApisCache.d.ts +0 -21
- package/dist/types/roleApisCache.js +0 -8
- package/dist/types/sync.d.ts +0 -93
- package/dist/types/sync.js +0 -4
- package/dist/types/table.d.ts +0 -34
- package/dist/types/table.js +0 -4
- package/dist/types/validate.d.ts +0 -113
- package/dist/types/validate.js +0 -4
- package/dist/utils/calcPerfTime.d.ts +0 -4
- package/dist/utils/calcPerfTime.js +0 -13
- package/dist/utils/cors.d.ts +0 -8
- package/dist/utils/cors.js +0 -17
- package/dist/utils/dbFieldRules.d.ts +0 -31
- package/dist/utils/dbFieldRules.js +0 -94
- package/dist/utils/fieldClear.d.ts +0 -11
- package/dist/utils/fieldClear.js +0 -57
- package/dist/utils/formatYmdHms.d.ts +0 -1
- package/dist/utils/formatYmdHms.js +0 -20
- package/dist/utils/getClientIp.d.ts +0 -6
- package/dist/utils/getClientIp.js +0 -39
- package/dist/utils/importDefault.d.ts +0 -1
- package/dist/utils/importDefault.js +0 -53
- package/dist/utils/isDirentDirectory.d.ts +0 -3
- package/dist/utils/isDirentDirectory.js +0 -18
- package/dist/utils/loadMenuConfigs.d.ts +0 -11
- package/dist/utils/loadMenuConfigs.js +0 -130
- package/dist/utils/loggerUtils.d.ts +0 -18
- package/dist/utils/loggerUtils.js +0 -171
- package/dist/utils/mergeAndConcat.d.ts +0 -7
- package/dist/utils/mergeAndConcat.js +0 -77
- package/dist/utils/normalizeFieldDefinition.d.ts +0 -18
- package/dist/utils/normalizeFieldDefinition.js +0 -27
- package/dist/utils/processInfo.d.ts +0 -26
- package/dist/utils/processInfo.js +0 -41
- package/dist/utils/response.d.ts +0 -20
- package/dist/utils/response.js +0 -96
- package/dist/utils/scanAddons.d.ts +0 -15
- package/dist/utils/scanAddons.js +0 -35
- package/dist/utils/scanCoreBuiltins.d.ts +0 -3
- package/dist/utils/scanCoreBuiltins.js +0 -72
- package/dist/utils/scanFiles.d.ts +0 -32
- package/dist/utils/scanFiles.js +0 -124
- package/dist/utils/scanSources.d.ts +0 -10
- package/dist/utils/scanSources.js +0 -46
- package/dist/utils/sortModules.d.ts +0 -28
- package/dist/utils/sortModules.js +0 -105
- package/dist/utils/sqlUtil.d.ts +0 -33
- package/dist/utils/sqlUtil.js +0 -146
- package/dist/utils/util.d.ts +0 -172
- package/dist/utils/util.js +0 -517
package/dist/loader/loadApis.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API 加载器
|
|
3
|
-
* 负责扫描和加载所有 API 路由(组件、项目)
|
|
4
|
-
*/
|
|
5
|
-
import { Logger } from "../lib/logger";
|
|
6
|
-
import { CoreError } from "../types/coreError";
|
|
7
|
-
/**
|
|
8
|
-
* 加载所有 API 路由
|
|
9
|
-
* @param apiItems - scanSources/scanFiles 扫描到的 API 条目数组
|
|
10
|
-
* @returns API 路由映射表
|
|
11
|
-
*/
|
|
12
|
-
export async function loadApis(apis) {
|
|
13
|
-
const apisMap = new Map();
|
|
14
|
-
for (const api of apis) {
|
|
15
|
-
try {
|
|
16
|
-
// B 方案:信任启动期 checkApi 的结构校验,这里只负责把 scanFiles 的结果映射为运行时 ApiRoute。
|
|
17
|
-
if (api.type !== "api") {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
const record = api;
|
|
21
|
-
const path = record["path"];
|
|
22
|
-
const route = {
|
|
23
|
-
name: record["name"],
|
|
24
|
-
handler: record["handler"],
|
|
25
|
-
route: path
|
|
26
|
-
};
|
|
27
|
-
const method = record["method"];
|
|
28
|
-
if (typeof method === "string") {
|
|
29
|
-
const upperMethod = method.toUpperCase();
|
|
30
|
-
const normalized = upperMethod === "POST,GET" ? "GET,POST" : upperMethod;
|
|
31
|
-
route.method = ["GET", "POST", "GET,POST"].includes(normalized) ? normalized : "POST";
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
route.method = "POST";
|
|
35
|
-
}
|
|
36
|
-
const auth = record["auth"];
|
|
37
|
-
if (auth !== undefined) {
|
|
38
|
-
route.auth = auth;
|
|
39
|
-
}
|
|
40
|
-
const fields = record["fields"];
|
|
41
|
-
if (fields !== undefined) {
|
|
42
|
-
route.fields = fields;
|
|
43
|
-
}
|
|
44
|
-
const required = record["required"];
|
|
45
|
-
if (required !== undefined) {
|
|
46
|
-
route.required = required;
|
|
47
|
-
}
|
|
48
|
-
const rawBody = record["rawBody"];
|
|
49
|
-
if (rawBody !== undefined) {
|
|
50
|
-
route.rawBody = rawBody;
|
|
51
|
-
}
|
|
52
|
-
apisMap.set(path, route);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
Logger.error({ err: error, api: api.relativePath, file: api.filePath, msg: "接口加载失败" });
|
|
56
|
-
throw new CoreError({
|
|
57
|
-
kind: "runtime",
|
|
58
|
-
message: "接口加载失败",
|
|
59
|
-
logged: true,
|
|
60
|
-
cause: error,
|
|
61
|
-
meta: {
|
|
62
|
-
subsystem: "api",
|
|
63
|
-
operation: "load",
|
|
64
|
-
relativePath: api.relativePath,
|
|
65
|
-
filePath: api.filePath
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return apisMap;
|
|
71
|
-
}
|
package/dist/loader/loadHooks.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 钩子加载器
|
|
3
|
-
* 默认加载所有来源钩子(core/addon/app)
|
|
4
|
-
*/
|
|
5
|
-
import { CoreError } from "../types/coreError";
|
|
6
|
-
import { sortModules } from "../utils/sortModules";
|
|
7
|
-
export async function loadHooks(hooks) {
|
|
8
|
-
const hooksMap = [];
|
|
9
|
-
const enabledHooks = hooks.filter((item) => {
|
|
10
|
-
const moduleName = item.moduleName;
|
|
11
|
-
if (typeof moduleName !== "string" || moduleName.trim() === "") {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
// enable=false 表示禁用(替代 disableHooks 列表)。
|
|
15
|
-
// enable 仅允许 boolean;缺失 enable 的默认值应在 checkHook 阶段被补全为 true。
|
|
16
|
-
const enable = Object.hasOwn(item, "enable") ? item.enable : undefined;
|
|
17
|
-
if (enable === false) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return true;
|
|
21
|
-
});
|
|
22
|
-
const sortedHooks = sortModules(enabledHooks, { moduleLabel: "钩子" });
|
|
23
|
-
if (sortedHooks === false) {
|
|
24
|
-
// 依赖图的细节错误已由 sortModules(Logger.error) 输出。
|
|
25
|
-
// 这里抛出策略类错误即可,避免入口再打印一份重复堆栈。
|
|
26
|
-
throw new CoreError({ message: "钩子依赖关系错误", kind: "policy", logged: true });
|
|
27
|
-
}
|
|
28
|
-
for (const item of sortedHooks) {
|
|
29
|
-
const hookName = item.moduleName;
|
|
30
|
-
const depsRaw = Object.hasOwn(item, "deps") ? item.deps : undefined;
|
|
31
|
-
const deps = Array.isArray(depsRaw) ? depsRaw.filter((x) => typeof x === "string") : [];
|
|
32
|
-
const handlerRaw = Object.hasOwn(item, "handler") ? item.handler : undefined;
|
|
33
|
-
if (typeof handlerRaw !== "function") {
|
|
34
|
-
throw new CoreError({
|
|
35
|
-
kind: "validation",
|
|
36
|
-
message: `Hook '${hookName}' handler 必须是函数`,
|
|
37
|
-
noLog: true,
|
|
38
|
-
meta: { subsystem: "hook", operation: "load", hook: hookName }
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
const handler = handlerRaw;
|
|
42
|
-
hooksMap.push({
|
|
43
|
-
name: hookName,
|
|
44
|
-
enable: true,
|
|
45
|
-
deps: deps,
|
|
46
|
-
handler: handler
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return hooksMap;
|
|
50
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插件加载器
|
|
3
|
-
* 负责扫描和初始化所有插件(核心、组件、项目)
|
|
4
|
-
*/
|
|
5
|
-
import type { BeflyContext } from "../types/befly";
|
|
6
|
-
import type { Plugin } from "../types/plugin";
|
|
7
|
-
import type { ScanFileResult } from "../utils/scanFiles";
|
|
8
|
-
export declare function loadPlugins(plugins: ScanFileResult[], context: BeflyContext): Promise<Plugin[]>;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插件加载器
|
|
3
|
-
* 负责扫描和初始化所有插件(核心、组件、项目)
|
|
4
|
-
*/
|
|
5
|
-
import { Logger } from "../lib/logger";
|
|
6
|
-
import { CoreError } from "../types/coreError";
|
|
7
|
-
import { sortModules } from "../utils/sortModules";
|
|
8
|
-
export async function loadPlugins(plugins, context) {
|
|
9
|
-
const pluginsMap = [];
|
|
10
|
-
const enabledPlugins = plugins.filter((item) => {
|
|
11
|
-
const moduleName = item.moduleName;
|
|
12
|
-
if (typeof moduleName !== "string" || moduleName.trim() === "") {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
// enable=false 表示禁用(替代 disablePlugins 列表)。
|
|
16
|
-
// enable 仅允许 boolean;缺失 enable 的默认值应在 checkPlugin 阶段被补全为 true。
|
|
17
|
-
const enable = Object.hasOwn(item, "enable") ? item.enable : undefined;
|
|
18
|
-
if (enable === false) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
});
|
|
23
|
-
const sortedPlugins = sortModules(enabledPlugins, { moduleLabel: "插件" });
|
|
24
|
-
if (sortedPlugins === false) {
|
|
25
|
-
// 依赖图的细节错误已由 sortModules(Logger.error) 输出。
|
|
26
|
-
// 这里抛出策略类错误即可,避免入口再打印一份重复堆栈。
|
|
27
|
-
throw new CoreError({ message: "插件依赖关系错误", kind: "policy", logged: true });
|
|
28
|
-
}
|
|
29
|
-
for (const item of sortedPlugins) {
|
|
30
|
-
const pluginName = item.moduleName;
|
|
31
|
-
const depsRaw = Object.hasOwn(item, "deps") ? item.deps : undefined;
|
|
32
|
-
const deps = Array.isArray(depsRaw) ? depsRaw.filter((x) => typeof x === "string") : [];
|
|
33
|
-
const handlerRaw = Object.hasOwn(item, "handler") ? item.handler : undefined;
|
|
34
|
-
if (typeof handlerRaw !== "function") {
|
|
35
|
-
throw new CoreError({
|
|
36
|
-
kind: "validation",
|
|
37
|
-
message: `插件 '${pluginName}' handler 必须是函数`,
|
|
38
|
-
noLog: true,
|
|
39
|
-
meta: { subsystem: "plugin", operation: "load", plugin: pluginName }
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const handler = handlerRaw;
|
|
43
|
-
try {
|
|
44
|
-
const pluginInstance = await handler(context);
|
|
45
|
-
context[pluginName] = pluginInstance;
|
|
46
|
-
pluginsMap.push({
|
|
47
|
-
name: pluginName,
|
|
48
|
-
enable: true,
|
|
49
|
-
deps: deps,
|
|
50
|
-
handler: handler
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
Logger.error({ err: error, plugin: pluginName, msg: "插件初始化失败" });
|
|
55
|
-
throw new CoreError({
|
|
56
|
-
kind: "runtime",
|
|
57
|
-
message: `插件初始化失败: ${pluginName}`,
|
|
58
|
-
logged: true,
|
|
59
|
-
cause: error,
|
|
60
|
-
meta: {
|
|
61
|
-
subsystem: "plugin",
|
|
62
|
-
operation: "init",
|
|
63
|
-
plugin: pluginName
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return pluginsMap;
|
|
69
|
-
}
|
package/dist/paths.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Befly 框架路径配置
|
|
3
|
-
*
|
|
4
|
-
* 提供统一的路径常量,供整个框架使用
|
|
5
|
-
* 所有路径常量采用具名导出方式,避免通过对象访问
|
|
6
|
-
*
|
|
7
|
-
* 路径分类:
|
|
8
|
-
* - root* 系列:Core 框架内部路径(packages/core/*)
|
|
9
|
-
* - app* 系列:用户项目路径(process.cwd()/*)
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Core 框架根目录
|
|
14
|
-
* @description packages/core/
|
|
15
|
-
*/
|
|
16
|
-
export declare const coreDir: string;
|
|
17
|
-
/**
|
|
18
|
-
* Core 框架 dist 目录
|
|
19
|
-
* @description 源码态为 packages/core/dist;dist 运行态为 packages/core/dist
|
|
20
|
-
*/
|
|
21
|
-
export declare const coreDistDir: string;
|
|
22
|
-
/**
|
|
23
|
-
* Core 框架检查目录
|
|
24
|
-
* @description packages/core/checks/
|
|
25
|
-
* @usage 存放启动检查模块(返回 boolean 的 default 函数)
|
|
26
|
-
*/
|
|
27
|
-
export declare const coreCheckDir: string;
|
|
28
|
-
/**
|
|
29
|
-
* Core 框架插件目录
|
|
30
|
-
* @description packages/core/plugins/
|
|
31
|
-
* @usage 存放内置插件(db, logger, redis, tool 等)
|
|
32
|
-
*/
|
|
33
|
-
export declare const corePluginDir: string;
|
|
34
|
-
/**
|
|
35
|
-
* Core 框架钩子目录
|
|
36
|
-
* @description packages/core/hooks/
|
|
37
|
-
* @usage 存放内置钩子(auth, cors, parser 等)
|
|
38
|
-
*/
|
|
39
|
-
export declare const coreHookDir: string;
|
|
40
|
-
/**
|
|
41
|
-
* Core 框架 API 目录
|
|
42
|
-
* @description packages/core/apis/
|
|
43
|
-
* @usage 存放框架级别的 API 接口
|
|
44
|
-
*/
|
|
45
|
-
export declare const coreApiDir: string;
|
|
46
|
-
/**
|
|
47
|
-
* Core 框架表定义目录
|
|
48
|
-
* @description packages/core/tables/
|
|
49
|
-
* @usage 存放框架核心表定义(JSON 格式)
|
|
50
|
-
*/
|
|
51
|
-
export declare const coreTableDir: string;
|
|
52
|
-
/**
|
|
53
|
-
* 项目根目录
|
|
54
|
-
* @description process.cwd()
|
|
55
|
-
* @usage 用户项目的根目录
|
|
56
|
-
*/
|
|
57
|
-
export declare const appDir: string;
|
|
58
|
-
/**
|
|
59
|
-
* 项目检查目录
|
|
60
|
-
* @description {appDir}/checks/
|
|
61
|
-
* @usage 存放用户自定义启动检查模块
|
|
62
|
-
*/
|
|
63
|
-
export declare const appCheckDir: string;
|
|
64
|
-
/**
|
|
65
|
-
* 项目插件目录
|
|
66
|
-
* @description {appDir}/plugins/
|
|
67
|
-
* @usage 存放用户自定义插件
|
|
68
|
-
*/
|
|
69
|
-
export declare const appPluginDir: string;
|
|
70
|
-
/**
|
|
71
|
-
* 项目钩子目录
|
|
72
|
-
* @description {appDir}/hooks/
|
|
73
|
-
* @usage 存放用户自定义钩子
|
|
74
|
-
*/
|
|
75
|
-
export declare const appHookDir: string;
|
|
76
|
-
/**
|
|
77
|
-
* 项目 API 目录
|
|
78
|
-
* @description {appDir}/apis/
|
|
79
|
-
* @usage 存放用户业务 API 接口
|
|
80
|
-
*/
|
|
81
|
-
export declare const appApiDir: string;
|
|
82
|
-
/**
|
|
83
|
-
* 项目表定义目录
|
|
84
|
-
* @description {appDir}/tables/
|
|
85
|
-
* @usage 存放用户业务表定义(JSON 格式)
|
|
86
|
-
*/
|
|
87
|
-
export declare const appTableDir: string;
|
|
88
|
-
/**
|
|
89
|
-
* 项目组件目录
|
|
90
|
-
* @description {appDir}/addons/
|
|
91
|
-
* @usage 存放本地组件(优先级高于 node_modules 中的组件)
|
|
92
|
-
*/
|
|
93
|
-
export declare const appAddonsDir: string;
|
package/dist/paths.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Befly 框架路径配置
|
|
3
|
-
*
|
|
4
|
-
* 提供统一的路径常量,供整个框架使用
|
|
5
|
-
* 所有路径常量采用具名导出方式,避免通过对象访问
|
|
6
|
-
*
|
|
7
|
-
* 路径分类:
|
|
8
|
-
* - root* 系列:Core 框架内部路径(packages/core/*)
|
|
9
|
-
* - app* 系列:用户项目路径(process.cwd()/*)
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
import { fileURLToPath } from "node:url";
|
|
13
|
-
import { dirname, join, normalize } from "pathe";
|
|
14
|
-
// 当前文件的路径信息
|
|
15
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
-
const __dirname = dirname(__filename);
|
|
17
|
-
// ==================== Core 框架路径 ====================
|
|
18
|
-
/**
|
|
19
|
-
* Core 框架根目录
|
|
20
|
-
* @description packages/core/
|
|
21
|
-
*/
|
|
22
|
-
export const coreDir = __dirname;
|
|
23
|
-
/**
|
|
24
|
-
* Core 框架 dist 目录
|
|
25
|
-
* @description 源码态为 packages/core/dist;dist 运行态为 packages/core/dist
|
|
26
|
-
*/
|
|
27
|
-
export const coreDistDir = normalize(__dirname).endsWith("/dist") ? __dirname : join(__dirname, "dist");
|
|
28
|
-
/**
|
|
29
|
-
* Core 框架检查目录
|
|
30
|
-
* @description packages/core/checks/
|
|
31
|
-
* @usage 存放启动检查模块(返回 boolean 的 default 函数)
|
|
32
|
-
*/
|
|
33
|
-
export const coreCheckDir = join(__dirname, "checks");
|
|
34
|
-
/**
|
|
35
|
-
* Core 框架插件目录
|
|
36
|
-
* @description packages/core/plugins/
|
|
37
|
-
* @usage 存放内置插件(db, logger, redis, tool 等)
|
|
38
|
-
*/
|
|
39
|
-
export const corePluginDir = join(__dirname, "plugins");
|
|
40
|
-
/**
|
|
41
|
-
* Core 框架钩子目录
|
|
42
|
-
* @description packages/core/hooks/
|
|
43
|
-
* @usage 存放内置钩子(auth, cors, parser 等)
|
|
44
|
-
*/
|
|
45
|
-
export const coreHookDir = join(__dirname, "hooks");
|
|
46
|
-
/**
|
|
47
|
-
* Core 框架 API 目录
|
|
48
|
-
* @description packages/core/apis/
|
|
49
|
-
* @usage 存放框架级别的 API 接口
|
|
50
|
-
*/
|
|
51
|
-
export const coreApiDir = join(__dirname, "apis");
|
|
52
|
-
/**
|
|
53
|
-
* Core 框架表定义目录
|
|
54
|
-
* @description packages/core/tables/
|
|
55
|
-
* @usage 存放框架核心表定义(JSON 格式)
|
|
56
|
-
*/
|
|
57
|
-
export const coreTableDir = join(__dirname, "tables");
|
|
58
|
-
// ==================== 用户项目路径 ====================
|
|
59
|
-
/**
|
|
60
|
-
* 项目根目录
|
|
61
|
-
* @description process.cwd()
|
|
62
|
-
* @usage 用户项目的根目录
|
|
63
|
-
*/
|
|
64
|
-
export const appDir = process.cwd();
|
|
65
|
-
/**
|
|
66
|
-
* 项目检查目录
|
|
67
|
-
* @description {appDir}/checks/
|
|
68
|
-
* @usage 存放用户自定义启动检查模块
|
|
69
|
-
*/
|
|
70
|
-
export const appCheckDir = join(appDir, "checks");
|
|
71
|
-
/**
|
|
72
|
-
* 项目插件目录
|
|
73
|
-
* @description {appDir}/plugins/
|
|
74
|
-
* @usage 存放用户自定义插件
|
|
75
|
-
*/
|
|
76
|
-
export const appPluginDir = join(appDir, "plugins");
|
|
77
|
-
/**
|
|
78
|
-
* 项目钩子目录
|
|
79
|
-
* @description {appDir}/hooks/
|
|
80
|
-
* @usage 存放用户自定义钩子
|
|
81
|
-
*/
|
|
82
|
-
export const appHookDir = join(appDir, "hooks");
|
|
83
|
-
/**
|
|
84
|
-
* 项目 API 目录
|
|
85
|
-
* @description {appDir}/apis/
|
|
86
|
-
* @usage 存放用户业务 API 接口
|
|
87
|
-
*/
|
|
88
|
-
export const appApiDir = join(appDir, "apis");
|
|
89
|
-
/**
|
|
90
|
-
* 项目表定义目录
|
|
91
|
-
* @description {appDir}/tables/
|
|
92
|
-
* @usage 存放用户业务表定义(JSON 格式)
|
|
93
|
-
*/
|
|
94
|
-
export const appTableDir = join(appDir, "tables");
|
|
95
|
-
/**
|
|
96
|
-
* 项目组件目录
|
|
97
|
-
* @description {appDir}/addons/
|
|
98
|
-
* @usage 存放本地组件(优先级高于 node_modules 中的组件)
|
|
99
|
-
*/
|
|
100
|
-
export const appAddonsDir = join(appDir, "addons");
|
package/dist/plugins/cache.d.ts
DELETED
package/dist/plugins/cache.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 缓存插件 - TypeScript 版本
|
|
3
|
-
* 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
|
|
4
|
-
*/
|
|
5
|
-
import { CacheHelper } from "../lib/cacheHelper";
|
|
6
|
-
import { CoreError } from "../types/coreError";
|
|
7
|
-
/**
|
|
8
|
-
* 缓存插件
|
|
9
|
-
*/
|
|
10
|
-
const cachePlugin = {
|
|
11
|
-
name: "cache",
|
|
12
|
-
enable: true,
|
|
13
|
-
deps: ["logger", "redis", "db"],
|
|
14
|
-
async handler(befly) {
|
|
15
|
-
if (!befly.db) {
|
|
16
|
-
throw new CoreError({ message: "缓存初始化失败:ctx.db 未初始化", kind: "validation" });
|
|
17
|
-
}
|
|
18
|
-
if (!befly.redis) {
|
|
19
|
-
throw new CoreError({ message: "缓存初始化失败:ctx.redis 未初始化", kind: "validation" });
|
|
20
|
-
}
|
|
21
|
-
return new CacheHelper({ db: befly.db, redis: befly.redis });
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
export default cachePlugin;
|
package/dist/plugins/cipher.d.ts
DELETED
package/dist/plugins/cipher.js
DELETED
package/dist/plugins/config.d.ts
DELETED
package/dist/plugins/config.js
DELETED
package/dist/plugins/db.d.ts
DELETED
package/dist/plugins/db.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 数据库插件
|
|
3
|
-
* 初始化数据库连接和 SQL 管理器
|
|
4
|
-
*/
|
|
5
|
-
import { Connect } from "../lib/connect";
|
|
6
|
-
import { DbHelper } from "../lib/dbHelper";
|
|
7
|
-
import { Logger } from "../lib/logger";
|
|
8
|
-
import { CoreError } from "../types/coreError";
|
|
9
|
-
/**
|
|
10
|
-
* 数据库插件
|
|
11
|
-
*/
|
|
12
|
-
const dbPlugin = {
|
|
13
|
-
name: "db",
|
|
14
|
-
enable: true,
|
|
15
|
-
deps: ["logger", "redis"],
|
|
16
|
-
async handler(befly) {
|
|
17
|
-
const env = befly.config?.nodeEnv;
|
|
18
|
-
const dbName = String(befly.config?.db?.database || "");
|
|
19
|
-
if (!dbName) {
|
|
20
|
-
throw new CoreError({ message: "数据库初始化失败:befly.config.db.database 缺失", kind: "validation" });
|
|
21
|
-
}
|
|
22
|
-
if (!befly.redis) {
|
|
23
|
-
throw new CoreError({ message: "Redis 未初始化", kind: "validation" });
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const sql = Connect.getSql();
|
|
27
|
-
const idMode = befly.config?.db?.idMode;
|
|
28
|
-
const normalizedIdMode = idMode === "autoId" ? "autoId" : "timeId";
|
|
29
|
-
// 创建数据库管理器实例
|
|
30
|
-
const dbManager = new DbHelper({ redis: befly.redis, dbName: dbName, sql: sql, idMode: normalizedIdMode });
|
|
31
|
-
return dbManager;
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
Logger.error({ env: env, err: error, msg: "数据库初始化失败" });
|
|
35
|
-
throw new CoreError({
|
|
36
|
-
kind: "runtime",
|
|
37
|
-
message: "数据库初始化失败",
|
|
38
|
-
logged: true,
|
|
39
|
-
cause: error,
|
|
40
|
-
meta: {
|
|
41
|
-
subsystem: "db",
|
|
42
|
-
operation: "init"
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
export default dbPlugin;
|
package/dist/plugins/jwt.d.ts
DELETED
package/dist/plugins/jwt.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JWT 插件
|
|
3
|
-
*/
|
|
4
|
-
import { Jwt } from "../lib/jwt";
|
|
5
|
-
const jwtPlugin = {
|
|
6
|
-
name: "jwt",
|
|
7
|
-
enable: true,
|
|
8
|
-
deps: [],
|
|
9
|
-
handler: (context) => {
|
|
10
|
-
return new Jwt(context.config ? context.config.auth : undefined);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
export default jwtPlugin;
|
package/dist/plugins/logger.d.ts
DELETED
package/dist/plugins/logger.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 日志插件
|
|
3
|
-
* 提供全局日志功能
|
|
4
|
-
*/
|
|
5
|
-
import { Logger } from "../lib/logger";
|
|
6
|
-
/**
|
|
7
|
-
* 日志插件
|
|
8
|
-
*/
|
|
9
|
-
const loggerPlugin = {
|
|
10
|
-
name: "logger",
|
|
11
|
-
enable: true,
|
|
12
|
-
deps: [],
|
|
13
|
-
async handler(befly) {
|
|
14
|
-
// 配置 Logger
|
|
15
|
-
if (befly.config && befly.config.logger) {
|
|
16
|
-
Logger.configure(befly.config.logger);
|
|
17
|
-
}
|
|
18
|
-
return Logger;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export default loggerPlugin;
|
package/dist/plugins/redis.d.ts
DELETED
package/dist/plugins/redis.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Redis 插件
|
|
3
|
-
* 初始化 Redis 连接和助手工具
|
|
4
|
-
*/
|
|
5
|
-
import { Connect } from "../lib/connect";
|
|
6
|
-
import { Logger } from "../lib/logger";
|
|
7
|
-
import { RedisHelper } from "../lib/redisHelper";
|
|
8
|
-
import { CoreError } from "../types/coreError";
|
|
9
|
-
/**
|
|
10
|
-
* Redis 插件
|
|
11
|
-
*/
|
|
12
|
-
const redisPlugin = {
|
|
13
|
-
name: "redis",
|
|
14
|
-
enable: true,
|
|
15
|
-
deps: ["logger"],
|
|
16
|
-
async handler(befly) {
|
|
17
|
-
const env = befly.config?.nodeEnv;
|
|
18
|
-
const redisPrefix = befly.config?.redis?.prefix;
|
|
19
|
-
try {
|
|
20
|
-
// 启动期已建立 Redis 连接;这里仅校验连接存在
|
|
21
|
-
Connect.getRedis();
|
|
22
|
-
// 返回 RedisHelper 实例
|
|
23
|
-
return new RedisHelper(redisPrefix);
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
Logger.error({ env: env, err: error, msg: "Redis 初始化失败" });
|
|
27
|
-
throw new CoreError({
|
|
28
|
-
kind: "runtime",
|
|
29
|
-
message: "Redis 初始化失败",
|
|
30
|
-
logged: true,
|
|
31
|
-
cause: error,
|
|
32
|
-
meta: {
|
|
33
|
-
subsystem: "redis",
|
|
34
|
-
operation: "init"
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
export default redisPlugin;
|