befly 3.10.18 → 3.11.1
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 +83 -307
- package/dist/befly.config.d.ts +7 -0
- package/{befly.config.ts → dist/befly.config.js} +11 -36
- package/dist/befly.js +15621 -0
- package/dist/befly.min.js +21 -0
- package/dist/checks/checkApi.d.ts +1 -0
- package/{checks/checkApi.ts → dist/checks/checkApi.js} +12 -30
- package/dist/checks/checkHook.d.ts +1 -0
- package/dist/checks/checkHook.js +86 -0
- package/dist/checks/checkMenu.d.ts +7 -0
- package/{checks/checkMenu.ts → dist/checks/checkMenu.js} +18 -53
- package/dist/checks/checkPlugin.d.ts +1 -0
- package/dist/checks/checkPlugin.js +86 -0
- package/dist/checks/checkTable.d.ts +6 -0
- package/{checks/checkTable.ts → dist/checks/checkTable.js} +17 -41
- package/dist/configs/presetFields.d.ts +4 -0
- package/{configs/presetFields.ts → dist/configs/presetFields.js} +1 -1
- package/dist/configs/presetRegexp.d.ts +145 -0
- package/{utils/regex.ts → dist/configs/presetRegexp.js} +8 -31
- package/dist/hooks/auth.d.ts +7 -0
- package/{hooks/auth.ts → dist/hooks/auth.js} +8 -10
- package/dist/hooks/cors.d.ts +11 -0
- package/{hooks/cors.ts → dist/hooks/cors.js} +5 -13
- package/dist/hooks/parser.d.ts +14 -0
- package/{hooks/parser.ts → dist/hooks/parser.js} +31 -45
- package/dist/hooks/permission.d.ts +14 -0
- package/{hooks/permission.ts → dist/hooks/permission.js} +16 -25
- package/dist/hooks/validator.d.ts +11 -0
- package/{hooks/validator.ts → dist/hooks/validator.js} +9 -14
- package/dist/index.d.ts +26 -0
- package/{main.ts → dist/index.js} +61 -100
- package/dist/lib/asyncContext.d.ts +21 -0
- package/dist/lib/asyncContext.js +27 -0
- package/dist/lib/cacheHelper.d.ts +95 -0
- package/{lib/cacheHelper.ts → dist/lib/cacheHelper.js} +45 -105
- package/dist/lib/cacheKeys.d.ts +23 -0
- package/{lib/cacheKeys.ts → dist/lib/cacheKeys.js} +5 -10
- package/dist/lib/cipher.d.ts +153 -0
- package/{lib/cipher.ts → dist/lib/cipher.js} +23 -44
- package/dist/lib/connect.d.ts +91 -0
- package/{lib/connect.ts → dist/lib/connect.js} +47 -88
- package/dist/lib/dbDialect.d.ts +87 -0
- package/{lib/dbDialect.ts → dist/lib/dbDialect.js} +32 -112
- package/dist/lib/dbHelper.d.ts +204 -0
- package/{lib/dbHelper.ts → dist/lib/dbHelper.js} +82 -241
- package/dist/lib/dbUtils.d.ts +68 -0
- package/{lib/dbUtils.ts → dist/lib/dbUtils.js} +51 -126
- package/dist/lib/jwt.d.ts +13 -0
- package/{lib/jwt.ts → dist/lib/jwt.js} +11 -32
- package/dist/lib/logger.d.ts +42 -0
- package/dist/lib/logger.js +1144 -0
- package/dist/lib/redisHelper.d.ts +185 -0
- package/{lib/redisHelper.ts → dist/lib/redisHelper.js} +97 -141
- package/dist/lib/sqlBuilder.d.ts +160 -0
- package/{lib/sqlBuilder.ts → dist/lib/sqlBuilder.js} +132 -278
- package/dist/lib/sqlCheck.d.ts +23 -0
- package/{lib/sqlCheck.ts → dist/lib/sqlCheck.js} +24 -41
- package/dist/lib/validator.d.ts +45 -0
- package/{lib/validator.ts → dist/lib/validator.js} +44 -61
- package/dist/loader/loadApis.d.ts +12 -0
- package/{loader/loadApis.ts → dist/loader/loadApis.js} +10 -20
- package/dist/loader/loadHooks.d.ts +7 -0
- package/dist/loader/loadHooks.js +35 -0
- package/dist/loader/loadPlugins.d.ts +8 -0
- package/{loader/loadPlugins.ts → dist/loader/loadPlugins.js} +14 -26
- package/dist/paths.d.ts +93 -0
- package/{paths.ts → dist/paths.js} +6 -19
- package/dist/plugins/cache.d.ts +16 -0
- package/{plugins/cache.ts → dist/plugins/cache.js} +7 -12
- package/dist/plugins/cipher.d.ts +12 -0
- package/{plugins/cipher.ts → dist/plugins/cipher.js} +4 -6
- package/dist/plugins/config.d.ts +12 -0
- package/dist/plugins/config.js +8 -0
- package/dist/plugins/db.d.ts +16 -0
- package/{plugins/db.ts → dist/plugins/db.js} +11 -17
- package/dist/plugins/jwt.d.ts +12 -0
- package/dist/plugins/jwt.js +12 -0
- package/dist/plugins/logger.d.ts +32 -0
- package/{plugins/logger.ts → dist/plugins/logger.js} +5 -8
- package/dist/plugins/redis.d.ts +16 -0
- package/{plugins/redis.ts → dist/plugins/redis.js} +9 -12
- package/dist/plugins/tool.d.ts +81 -0
- package/{plugins/tool.ts → dist/plugins/tool.js} +9 -30
- package/dist/router/api.d.ts +14 -0
- package/dist/router/api.js +107 -0
- package/dist/router/static.d.ts +9 -0
- package/{router/static.ts → dist/router/static.js} +20 -34
- package/dist/scripts/ensureDist.d.ts +1 -0
- package/dist/scripts/ensureDist.js +296 -0
- package/dist/sync/syncApi.d.ts +3 -0
- package/{sync/syncApi.ts → dist/sync/syncApi.js} +35 -55
- package/dist/sync/syncCache.d.ts +2 -0
- package/{sync/syncCache.ts → dist/sync/syncCache.js} +1 -6
- package/dist/sync/syncDev.d.ts +6 -0
- package/{sync/syncDev.ts → dist/sync/syncDev.js} +29 -62
- package/dist/sync/syncMenu.d.ts +14 -0
- package/{sync/syncMenu.ts → dist/sync/syncMenu.js} +65 -125
- package/dist/sync/syncTable.d.ts +151 -0
- package/{sync/syncTable.ts → dist/sync/syncTable.js} +172 -379
- package/{types → dist/types}/api.d.ts +12 -51
- package/dist/types/api.js +4 -0
- package/{types → dist/types}/befly.d.ts +32 -227
- package/dist/types/befly.js +4 -0
- package/{types → dist/types}/cache.d.ts +7 -15
- package/dist/types/cache.js +4 -0
- package/dist/types/cipher.d.ts +27 -0
- package/dist/types/cipher.js +7 -0
- package/{types → dist/types}/common.d.ts +8 -33
- package/dist/types/common.js +5 -0
- package/{types → dist/types}/context.d.ts +3 -5
- package/dist/types/context.js +4 -0
- package/{types → dist/types}/crypto.d.ts +0 -3
- package/dist/types/crypto.js +4 -0
- package/dist/types/database.d.ts +138 -0
- package/dist/types/database.js +4 -0
- package/dist/types/hook.d.ts +17 -0
- package/dist/types/hook.js +6 -0
- package/dist/types/jwt.d.ts +75 -0
- package/dist/types/jwt.js +4 -0
- package/dist/types/logger.d.ts +59 -0
- package/dist/types/logger.js +6 -0
- package/dist/types/plugin.d.ts +16 -0
- package/dist/types/plugin.js +6 -0
- package/dist/types/redis.d.ts +71 -0
- package/dist/types/redis.js +4 -0
- package/{types/roleApisCache.ts → dist/types/roleApisCache.d.ts} +0 -2
- package/dist/types/roleApisCache.js +8 -0
- package/dist/types/sync.d.ts +92 -0
- package/dist/types/sync.js +4 -0
- package/dist/types/table.d.ts +34 -0
- package/dist/types/table.js +4 -0
- package/dist/types/validate.d.ts +67 -0
- package/dist/types/validate.js +4 -0
- package/dist/utils/calcPerfTime.d.ts +4 -0
- package/{utils/calcPerfTime.ts → dist/utils/calcPerfTime.js} +3 -3
- package/dist/utils/convertBigIntFields.d.ts +11 -0
- package/{utils/convertBigIntFields.ts → dist/utils/convertBigIntFields.js} +5 -9
- package/dist/utils/cors.d.ts +8 -0
- package/{utils/cors.ts → dist/utils/cors.js} +1 -3
- package/dist/utils/disableMenusGlob.d.ts +13 -0
- package/{utils/disableMenusGlob.ts → dist/utils/disableMenusGlob.js} +9 -29
- package/dist/utils/fieldClear.d.ts +11 -0
- package/{utils/fieldClear.ts → dist/utils/fieldClear.js} +15 -33
- package/dist/utils/getClientIp.d.ts +6 -0
- package/{utils/getClientIp.ts → dist/utils/getClientIp.js} +1 -7
- package/dist/utils/importDefault.d.ts +1 -0
- package/dist/utils/importDefault.js +29 -0
- package/dist/utils/isDirentDirectory.d.ts +2 -0
- package/{utils/isDirentDirectory.ts → dist/utils/isDirentDirectory.js} +3 -8
- package/dist/utils/loadMenuConfigs.d.ts +29 -0
- package/{utils/loadMenuConfigs.ts → dist/utils/loadMenuConfigs.js} +66 -52
- package/dist/utils/mergeAndConcat.d.ts +7 -0
- package/dist/utils/mergeAndConcat.js +72 -0
- package/dist/utils/processAtSymbol.d.ts +4 -0
- package/{utils/processFields.ts → dist/utils/processAtSymbol.js} +5 -9
- package/dist/utils/processInfo.d.ts +24 -0
- package/{utils/process.ts → dist/utils/processInfo.js} +2 -18
- package/dist/utils/response.d.ts +20 -0
- package/{utils/response.ts → dist/utils/response.js} +28 -49
- package/dist/utils/scanAddons.d.ts +17 -0
- package/{utils/scanAddons.ts → dist/utils/scanAddons.js} +7 -41
- package/dist/utils/scanConfig.d.ts +26 -0
- package/{utils/scanConfig.ts → dist/utils/scanConfig.js} +28 -66
- package/dist/utils/scanCoreBuiltins.d.ts +3 -0
- package/dist/utils/scanCoreBuiltins.js +65 -0
- package/dist/utils/scanFiles.d.ts +30 -0
- package/{utils/scanFiles.ts → dist/utils/scanFiles.js} +44 -71
- package/dist/utils/scanSources.d.ts +10 -0
- package/dist/utils/scanSources.js +46 -0
- package/dist/utils/sortModules.d.ts +28 -0
- package/{utils/sortModules.ts → dist/utils/sortModules.js} +26 -66
- package/dist/utils/util.d.ts +84 -0
- package/dist/utils/util.js +262 -0
- package/package.json +26 -34
- package/.gitignore +0 -0
- package/bunfig.toml +0 -3
- package/checks/checkHook.ts +0 -48
- package/checks/checkPlugin.ts +0 -48
- package/configs/presetRegexp.ts +0 -225
- package/docs/README.md +0 -98
- package/docs/api/api.md +0 -1921
- package/docs/guide/examples.md +0 -926
- package/docs/guide/quickstart.md +0 -354
- package/docs/hooks/auth.md +0 -38
- package/docs/hooks/cors.md +0 -28
- package/docs/hooks/hook.md +0 -838
- package/docs/hooks/parser.md +0 -19
- package/docs/hooks/rateLimit.md +0 -47
- package/docs/infra/redis.md +0 -628
- package/docs/plugins/cipher.md +0 -61
- package/docs/plugins/database.md +0 -189
- package/docs/plugins/plugin.md +0 -986
- package/docs/reference/addon.md +0 -510
- package/docs/reference/config.md +0 -573
- package/docs/reference/logger.md +0 -495
- package/docs/reference/sync.md +0 -478
- package/docs/reference/table.md +0 -763
- package/docs/reference/validator.md +0 -620
- package/lib/asyncContext.ts +0 -43
- package/lib/logger.ts +0 -811
- package/loader/loadHooks.ts +0 -51
- package/plugins/config.ts +0 -13
- package/plugins/jwt.ts +0 -15
- package/router/api.ts +0 -130
- package/tsconfig.json +0 -8
- package/types/database.d.ts +0 -541
- package/types/hook.d.ts +0 -25
- package/types/jwt.d.ts +0 -118
- package/types/logger.d.ts +0 -65
- package/types/plugin.d.ts +0 -19
- package/types/redis.d.ts +0 -83
- package/types/sync.d.ts +0 -398
- package/types/table.d.ts +0 -216
- package/types/validate.d.ts +0 -69
- package/utils/arrayKeysToCamel.ts +0 -18
- package/utils/configTypes.ts +0 -3
- package/utils/genShortId.ts +0 -12
- package/utils/importDefault.ts +0 -21
- package/utils/keysToCamel.ts +0 -22
- package/utils/keysToSnake.ts +0 -22
- package/utils/pickFields.ts +0 -19
- package/utils/scanSources.ts +0 -64
- package/utils/sqlLog.ts +0 -37
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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;
|
|
@@ -9,102 +9,89 @@
|
|
|
9
9
|
* - app* 系列:用户项目路径(process.cwd()/*)
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
import { fileURLToPath } from "node:url";
|
|
14
|
-
|
|
15
|
-
import { dirname, join } from "pathe";
|
|
16
|
-
|
|
13
|
+
import { dirname, join, normalize } from "pathe";
|
|
17
14
|
// 当前文件的路径信息
|
|
18
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
19
16
|
const __dirname = dirname(__filename);
|
|
20
|
-
|
|
21
17
|
// ==================== Core 框架路径 ====================
|
|
22
|
-
|
|
23
18
|
/**
|
|
24
19
|
* Core 框架根目录
|
|
25
20
|
* @description packages/core/
|
|
26
21
|
*/
|
|
27
22
|
export const coreDir = __dirname;
|
|
28
|
-
|
|
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");
|
|
29
28
|
/**
|
|
30
29
|
* Core 框架检查目录
|
|
31
30
|
* @description packages/core/checks/
|
|
32
31
|
* @usage 存放启动检查模块(返回 boolean 的 default 函数)
|
|
33
32
|
*/
|
|
34
33
|
export const coreCheckDir = join(__dirname, "checks");
|
|
35
|
-
|
|
36
34
|
/**
|
|
37
35
|
* Core 框架插件目录
|
|
38
36
|
* @description packages/core/plugins/
|
|
39
37
|
* @usage 存放内置插件(db, logger, redis, tool 等)
|
|
40
38
|
*/
|
|
41
39
|
export const corePluginDir = join(__dirname, "plugins");
|
|
42
|
-
|
|
43
40
|
/**
|
|
44
41
|
* Core 框架钩子目录
|
|
45
42
|
* @description packages/core/hooks/
|
|
46
43
|
* @usage 存放内置钩子(auth, cors, parser 等)
|
|
47
44
|
*/
|
|
48
45
|
export const coreHookDir = join(__dirname, "hooks");
|
|
49
|
-
|
|
50
46
|
/**
|
|
51
47
|
* Core 框架 API 目录
|
|
52
48
|
* @description packages/core/apis/
|
|
53
49
|
* @usage 存放框架级别的 API 接口
|
|
54
50
|
*/
|
|
55
51
|
export const coreApiDir = join(__dirname, "apis");
|
|
56
|
-
|
|
57
52
|
/**
|
|
58
53
|
* Core 框架表定义目录
|
|
59
54
|
* @description packages/core/tables/
|
|
60
55
|
* @usage 存放框架核心表定义(JSON 格式)
|
|
61
56
|
*/
|
|
62
57
|
export const coreTableDir = join(__dirname, "tables");
|
|
63
|
-
|
|
64
58
|
// ==================== 用户项目路径 ====================
|
|
65
|
-
|
|
66
59
|
/**
|
|
67
60
|
* 项目根目录
|
|
68
61
|
* @description process.cwd()
|
|
69
62
|
* @usage 用户项目的根目录
|
|
70
63
|
*/
|
|
71
64
|
export const appDir = process.cwd();
|
|
72
|
-
|
|
73
65
|
/**
|
|
74
66
|
* 项目检查目录
|
|
75
67
|
* @description {appDir}/checks/
|
|
76
68
|
* @usage 存放用户自定义启动检查模块
|
|
77
69
|
*/
|
|
78
70
|
export const appCheckDir = join(appDir, "checks");
|
|
79
|
-
|
|
80
71
|
/**
|
|
81
72
|
* 项目插件目录
|
|
82
73
|
* @description {appDir}/plugins/
|
|
83
74
|
* @usage 存放用户自定义插件
|
|
84
75
|
*/
|
|
85
76
|
export const appPluginDir = join(appDir, "plugins");
|
|
86
|
-
|
|
87
77
|
/**
|
|
88
78
|
* 项目钩子目录
|
|
89
79
|
* @description {appDir}/hooks/
|
|
90
80
|
* @usage 存放用户自定义钩子
|
|
91
81
|
*/
|
|
92
82
|
export const appHookDir = join(appDir, "hooks");
|
|
93
|
-
|
|
94
83
|
/**
|
|
95
84
|
* 项目 API 目录
|
|
96
85
|
* @description {appDir}/apis/
|
|
97
86
|
* @usage 存放用户业务 API 接口
|
|
98
87
|
*/
|
|
99
88
|
export const appApiDir = join(appDir, "apis");
|
|
100
|
-
|
|
101
89
|
/**
|
|
102
90
|
* 项目表定义目录
|
|
103
91
|
* @description {appDir}/tables/
|
|
104
92
|
* @usage 存放用户业务表定义(JSON 格式)
|
|
105
93
|
*/
|
|
106
94
|
export const appTableDir = join(appDir, "tables");
|
|
107
|
-
|
|
108
95
|
/**
|
|
109
96
|
* 项目组件目录
|
|
110
97
|
* @description {appDir}/addons/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 缓存插件 - TypeScript 版本
|
|
3
|
+
* 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
|
|
4
|
+
*/
|
|
5
|
+
import type { BeflyContext } from "../types/befly";
|
|
6
|
+
import { CacheHelper } from "../lib/cacheHelper";
|
|
7
|
+
/**
|
|
8
|
+
* 缓存插件
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: {
|
|
11
|
+
name: string;
|
|
12
|
+
enable: true;
|
|
13
|
+
deps: string[];
|
|
14
|
+
handler(befly: BeflyContext): Promise<CacheHelper>;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
@@ -2,26 +2,21 @@
|
|
|
2
2
|
* 缓存插件 - TypeScript 版本
|
|
3
3
|
* 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import type { BeflyContext } from "../types/befly.ts";
|
|
7
|
-
import type { Plugin } from "../types/plugin.ts";
|
|
8
|
-
|
|
9
|
-
import { CacheHelper } from "../lib/cacheHelper.ts";
|
|
10
|
-
|
|
5
|
+
import { CacheHelper } from "../lib/cacheHelper";
|
|
11
6
|
/**
|
|
12
7
|
* 缓存插件
|
|
13
8
|
*/
|
|
14
9
|
export default {
|
|
10
|
+
name: "cache",
|
|
11
|
+
enable: true,
|
|
15
12
|
deps: ["logger", "redis", "db"],
|
|
16
|
-
async handler(befly
|
|
17
|
-
if (!
|
|
13
|
+
async handler(befly) {
|
|
14
|
+
if (!befly.db) {
|
|
18
15
|
throw new Error("缓存初始化失败:ctx.db 未初始化(Db 插件未加载或注入失败)");
|
|
19
16
|
}
|
|
20
|
-
|
|
21
|
-
if (!(befly as any).redis) {
|
|
17
|
+
if (!befly.redis) {
|
|
22
18
|
throw new Error("缓存初始化失败:ctx.redis 未初始化(Redis 插件未加载或注入失败)");
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
return new CacheHelper({ db: befly.db, redis: befly.redis });
|
|
26
21
|
}
|
|
27
|
-
}
|
|
22
|
+
};
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
* Cipher 插件
|
|
3
3
|
* 提供加密解密功能
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import type { Plugin } from "../types/plugin.ts";
|
|
7
|
-
|
|
8
|
-
import { Cipher } from "../lib/cipher.ts";
|
|
9
|
-
|
|
5
|
+
import { Cipher } from "../lib/cipher";
|
|
10
6
|
export default {
|
|
7
|
+
name: "cipher",
|
|
8
|
+
enable: true,
|
|
11
9
|
deps: [],
|
|
12
10
|
handler: () => {
|
|
13
11
|
return Cipher;
|
|
14
12
|
}
|
|
15
|
-
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置插件
|
|
3
|
+
* 提供访问项目配置的能力
|
|
4
|
+
*/
|
|
5
|
+
import type { BeflyContext } from "../types/befly";
|
|
6
|
+
declare const _default: {
|
|
7
|
+
name: string;
|
|
8
|
+
enable: true;
|
|
9
|
+
deps: never[];
|
|
10
|
+
handler: (context: BeflyContext) => import("../types/befly").BeflyOptions;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据库插件
|
|
3
|
+
* 初始化数据库连接和 SQL 管理器
|
|
4
|
+
*/
|
|
5
|
+
import type { BeflyContext } from "../types/befly";
|
|
6
|
+
import { DbHelper } from "../lib/dbHelper";
|
|
7
|
+
/**
|
|
8
|
+
* 数据库插件
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: {
|
|
11
|
+
name: string;
|
|
12
|
+
enable: true;
|
|
13
|
+
deps: string[];
|
|
14
|
+
handler(befly: BeflyContext): Promise<DbHelper>;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
@@ -2,39 +2,33 @@
|
|
|
2
2
|
* 数据库插件
|
|
3
3
|
* 初始化数据库连接和 SQL 管理器
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import { Connect } from "../lib/connect.ts";
|
|
10
|
-
import { getDialectByName } from "../lib/dbDialect.ts";
|
|
11
|
-
import { DbHelper } from "../lib/dbHelper.ts";
|
|
12
|
-
import { Logger } from "../lib/logger.ts";
|
|
13
|
-
|
|
5
|
+
import { Connect } from "../lib/connect";
|
|
6
|
+
import { getDialectByName } from "../lib/dbDialect";
|
|
7
|
+
import { DbHelper } from "../lib/dbHelper";
|
|
8
|
+
import { Logger } from "../lib/logger";
|
|
14
9
|
/**
|
|
15
10
|
* 数据库插件
|
|
16
11
|
*/
|
|
17
12
|
export default {
|
|
13
|
+
name: "db",
|
|
14
|
+
enable: true,
|
|
18
15
|
deps: ["logger", "redis"],
|
|
19
|
-
async handler(befly
|
|
20
|
-
if (!
|
|
16
|
+
async handler(befly) {
|
|
17
|
+
if (!befly.redis) {
|
|
21
18
|
throw new Error("数据库初始化失败:ctx.redis 未初始化(Redis 插件未加载或注入失败)");
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
try {
|
|
25
21
|
const sql = Connect.getSql();
|
|
26
|
-
|
|
27
22
|
const rawDbType = befly.config && befly.config.db ? befly.config.db.type : undefined;
|
|
28
23
|
const resolvedDbType = rawDbType === "postgres" ? "postgresql" : rawDbType;
|
|
29
24
|
const dialect = getDialectByName(resolvedDbType === "postgresql" || resolvedDbType === "sqlite" ? resolvedDbType : "mysql");
|
|
30
|
-
|
|
31
25
|
// 创建数据库管理器实例
|
|
32
26
|
const dbManager = new DbHelper({ redis: befly.redis, sql: sql, dialect: dialect });
|
|
33
|
-
|
|
34
27
|
return dbManager;
|
|
35
|
-
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
36
30
|
Logger.error({ err: error }, "数据库初始化失败");
|
|
37
31
|
throw error;
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
|
-
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT 插件
|
|
3
|
+
*/
|
|
4
|
+
import type { BeflyContext } from "../types/befly";
|
|
5
|
+
import { Jwt } from "../lib/jwt";
|
|
6
|
+
declare const _default: {
|
|
7
|
+
name: string;
|
|
8
|
+
enable: true;
|
|
9
|
+
deps: never[];
|
|
10
|
+
handler: (context: BeflyContext) => Jwt;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日志插件
|
|
3
|
+
* 提供全局日志功能
|
|
4
|
+
*/
|
|
5
|
+
import type { BeflyContext } from "../types/befly";
|
|
6
|
+
/**
|
|
7
|
+
* 日志插件
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: {
|
|
10
|
+
name: string;
|
|
11
|
+
enable: true;
|
|
12
|
+
deps: never[];
|
|
13
|
+
handler(context: BeflyContext): Promise<{
|
|
14
|
+
info(...args: [] | [msg: string, ...args: unknown[]] | [msg: string, err: Error, ...args: unknown[]] | [err: Error, msg?: string | undefined, ...args: unknown[]] | [obj: {
|
|
15
|
+
[x: string]: any;
|
|
16
|
+
}, msg?: string | undefined, ...args: unknown[]]): any;
|
|
17
|
+
warn(...args: [] | [msg: string, ...args: unknown[]] | [msg: string, err: Error, ...args: unknown[]] | [err: Error, msg?: string | undefined, ...args: unknown[]] | [obj: {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
}, msg?: string | undefined, ...args: unknown[]]): any;
|
|
20
|
+
error(...args: [] | [msg: string, ...args: unknown[]] | [msg: string, err: Error, ...args: unknown[]] | [err: Error, msg?: string | undefined, ...args: unknown[]] | [obj: {
|
|
21
|
+
[x: string]: any;
|
|
22
|
+
}, msg?: string | undefined, ...args: unknown[]]): any;
|
|
23
|
+
debug(...args: [] | [msg: string, ...args: unknown[]] | [msg: string, err: Error, ...args: unknown[]] | [err: Error, msg?: string | undefined, ...args: unknown[]] | [obj: {
|
|
24
|
+
[x: string]: any;
|
|
25
|
+
}, msg?: string | undefined, ...args: unknown[]]): any;
|
|
26
|
+
flush(): Promise<void>;
|
|
27
|
+
configure: typeof import("../lib/logger").configure;
|
|
28
|
+
setMock: typeof import("../lib/logger").setMockLogger;
|
|
29
|
+
shutdown: typeof import("../lib/logger").shutdown;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
export default _default;
|
|
@@ -2,22 +2,19 @@
|
|
|
2
2
|
* 日志插件
|
|
3
3
|
* 提供全局日志功能
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import type { BeflyContext } from "../types/befly.ts";
|
|
7
|
-
import type { Plugin } from "../types/plugin.ts";
|
|
8
|
-
|
|
9
|
-
import { Logger } from "../lib/logger.ts";
|
|
10
|
-
|
|
5
|
+
import { Logger } from "../lib/logger";
|
|
11
6
|
/**
|
|
12
7
|
* 日志插件
|
|
13
8
|
*/
|
|
14
9
|
export default {
|
|
10
|
+
name: "logger",
|
|
11
|
+
enable: true,
|
|
15
12
|
deps: [],
|
|
16
|
-
async handler(context
|
|
13
|
+
async handler(context) {
|
|
17
14
|
// 配置 Logger
|
|
18
15
|
if (context.config && context.config.logger) {
|
|
19
16
|
Logger.configure(context.config.logger);
|
|
20
17
|
}
|
|
21
18
|
return Logger;
|
|
22
19
|
}
|
|
23
|
-
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redis 插件
|
|
3
|
+
* 初始化 Redis 连接和助手工具
|
|
4
|
+
*/
|
|
5
|
+
import type { BeflyContext } from "../types/befly";
|
|
6
|
+
import { RedisHelper } from "../lib/redisHelper";
|
|
7
|
+
/**
|
|
8
|
+
* Redis 插件
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: {
|
|
11
|
+
name: string;
|
|
12
|
+
enable: true;
|
|
13
|
+
deps: string[];
|
|
14
|
+
handler(context: BeflyContext): Promise<Record<string, never> | RedisHelper>;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
@@ -2,30 +2,27 @@
|
|
|
2
2
|
* Redis 插件
|
|
3
3
|
* 初始化 Redis 连接和助手工具
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import { Connect } from "../lib/connect.ts";
|
|
10
|
-
import { Logger } from "../lib/logger.ts";
|
|
11
|
-
import { RedisHelper } from "../lib/redisHelper.ts";
|
|
12
|
-
|
|
5
|
+
import { Connect } from "../lib/connect";
|
|
6
|
+
import { Logger } from "../lib/logger";
|
|
7
|
+
import { RedisHelper } from "../lib/redisHelper";
|
|
13
8
|
/**
|
|
14
9
|
* Redis 插件
|
|
15
10
|
*/
|
|
16
11
|
export default {
|
|
12
|
+
name: "redis",
|
|
13
|
+
enable: true,
|
|
17
14
|
deps: ["logger"],
|
|
18
|
-
async handler(context
|
|
15
|
+
async handler(context) {
|
|
19
16
|
const redisConfig = context.config && context.config.redis ? context.config.redis : {};
|
|
20
17
|
try {
|
|
21
18
|
// 启动期已建立 Redis 连接;这里仅校验连接存在
|
|
22
19
|
Connect.getRedis();
|
|
23
|
-
|
|
24
20
|
// 返回 RedisHelper 实例
|
|
25
21
|
return new RedisHelper(redisConfig.prefix);
|
|
26
|
-
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
27
24
|
Logger.error({ err: error }, "Redis 初始化失败");
|
|
28
25
|
throw error;
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
}
|
|
28
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具插件
|
|
3
|
+
* 提供常用的工具函数
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestContext } from "../types/context";
|
|
6
|
+
/**
|
|
7
|
+
* 成功响应
|
|
8
|
+
* @param msg - 消息
|
|
9
|
+
* @param data - 数据(可选)
|
|
10
|
+
* @param other - 其他字段(可选)
|
|
11
|
+
* @returns 成功响应对象
|
|
12
|
+
*/
|
|
13
|
+
export declare function Yes(msg: string, data?: any, other?: Record<string, any>): {
|
|
14
|
+
code: number;
|
|
15
|
+
msg: string;
|
|
16
|
+
data: any;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 失败响应
|
|
20
|
+
* @param msg - 消息
|
|
21
|
+
* @param data - 数据(可选)
|
|
22
|
+
* @param other - 其他字段(可选)
|
|
23
|
+
* @returns 失败响应对象
|
|
24
|
+
*/
|
|
25
|
+
export declare function No(msg: string, data?: any, other?: Record<string, any>): {
|
|
26
|
+
code: number;
|
|
27
|
+
msg: string;
|
|
28
|
+
data: any;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 响应选项
|
|
32
|
+
*/
|
|
33
|
+
interface ResponseOptions {
|
|
34
|
+
/** HTTP 状态码,默认 200 */
|
|
35
|
+
status?: number;
|
|
36
|
+
/** Content-Type,默认根据 data 类型自动判断 */
|
|
37
|
+
contentType?: string;
|
|
38
|
+
/** 额外的响应头 */
|
|
39
|
+
headers?: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 统一响应函数
|
|
43
|
+
*
|
|
44
|
+
* 自动识别数据类型并设置正确的 Content-Type:
|
|
45
|
+
* - 对象 → application/json
|
|
46
|
+
* - 字符串 → text/plain
|
|
47
|
+
* - 可通过 options.contentType 手动指定
|
|
48
|
+
*
|
|
49
|
+
* @param ctx 请求上下文
|
|
50
|
+
* @param data 响应数据(对象或字符串)
|
|
51
|
+
* @param options 响应选项
|
|
52
|
+
* @returns Response 对象
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // JSON 响应(自动)
|
|
56
|
+
* return Raw(ctx, { code: 'SUCCESS', message: '成功' });
|
|
57
|
+
*
|
|
58
|
+
* // 纯文本响应(自动)
|
|
59
|
+
* return Raw(ctx, 'success');
|
|
60
|
+
*
|
|
61
|
+
* // XML 响应(手动指定)
|
|
62
|
+
* return Raw(ctx, xmlString, { contentType: 'application/xml' });
|
|
63
|
+
*
|
|
64
|
+
* // 自定义状态码和额外头
|
|
65
|
+
* return Raw(ctx, { error: 'Not Found' }, {
|
|
66
|
+
* status: 404,
|
|
67
|
+
* headers: { 'X-Custom': 'value' }
|
|
68
|
+
* });
|
|
69
|
+
*/
|
|
70
|
+
export declare function Raw(ctx: RequestContext, data: Record<string, any> | string, options?: ResponseOptions): Response;
|
|
71
|
+
declare const _default: {
|
|
72
|
+
name: string;
|
|
73
|
+
enable: true;
|
|
74
|
+
deps: never[];
|
|
75
|
+
handler: () => {
|
|
76
|
+
Yes: typeof Yes;
|
|
77
|
+
No: typeof No;
|
|
78
|
+
Raw: typeof Raw;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export default _default;
|