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.
Files changed (178) hide show
  1. package/README.md +0 -129
  2. package/befly.js +12769 -0
  3. package/befly.min.js +47 -0
  4. package/package.json +18 -29
  5. package/dist/befly.config.d.ts +0 -7
  6. package/dist/befly.config.js +0 -128
  7. package/dist/befly.js +0 -17276
  8. package/dist/befly.min.js +0 -23
  9. package/dist/checks/checkApi.d.ts +0 -1
  10. package/dist/checks/checkApi.js +0 -124
  11. package/dist/checks/checkConfig.d.ts +0 -9
  12. package/dist/checks/checkConfig.js +0 -255
  13. package/dist/checks/checkHook.d.ts +0 -1
  14. package/dist/checks/checkHook.js +0 -132
  15. package/dist/checks/checkMenu.d.ts +0 -3
  16. package/dist/checks/checkMenu.js +0 -106
  17. package/dist/checks/checkPlugin.d.ts +0 -1
  18. package/dist/checks/checkPlugin.js +0 -132
  19. package/dist/checks/checkTable.d.ts +0 -7
  20. package/dist/checks/checkTable.js +0 -431
  21. package/dist/configs/presetRegexp.d.ts +0 -145
  22. package/dist/configs/presetRegexp.js +0 -218
  23. package/dist/hooks/auth.d.ts +0 -3
  24. package/dist/hooks/auth.js +0 -24
  25. package/dist/hooks/cors.d.ts +0 -7
  26. package/dist/hooks/cors.js +0 -36
  27. package/dist/hooks/parser.d.ts +0 -10
  28. package/dist/hooks/parser.js +0 -76
  29. package/dist/hooks/permission.d.ts +0 -10
  30. package/dist/hooks/permission.js +0 -64
  31. package/dist/hooks/validator.d.ts +0 -7
  32. package/dist/hooks/validator.js +0 -52
  33. package/dist/index.d.ts +0 -28
  34. package/dist/index.js +0 -316
  35. package/dist/lib/asyncContext.d.ts +0 -21
  36. package/dist/lib/asyncContext.js +0 -27
  37. package/dist/lib/cacheHelper.d.ts +0 -128
  38. package/dist/lib/cacheHelper.js +0 -477
  39. package/dist/lib/cacheKeys.d.ts +0 -27
  40. package/dist/lib/cacheKeys.js +0 -37
  41. package/dist/lib/cipher.d.ts +0 -153
  42. package/dist/lib/cipher.js +0 -237
  43. package/dist/lib/connect.d.ts +0 -95
  44. package/dist/lib/connect.js +0 -313
  45. package/dist/lib/dbHelper.d.ts +0 -229
  46. package/dist/lib/dbHelper.js +0 -1069
  47. package/dist/lib/dbUtils.d.ts +0 -91
  48. package/dist/lib/dbUtils.js +0 -544
  49. package/dist/lib/jwt.d.ts +0 -13
  50. package/dist/lib/jwt.js +0 -77
  51. package/dist/lib/logger.d.ts +0 -46
  52. package/dist/lib/logger.js +0 -731
  53. package/dist/lib/redisHelper.d.ts +0 -193
  54. package/dist/lib/redisHelper.js +0 -598
  55. package/dist/lib/sqlBuilder.d.ts +0 -160
  56. package/dist/lib/sqlBuilder.js +0 -837
  57. package/dist/lib/sqlCheck.d.ts +0 -23
  58. package/dist/lib/sqlCheck.js +0 -119
  59. package/dist/lib/validator.d.ts +0 -45
  60. package/dist/lib/validator.js +0 -424
  61. package/dist/loader/loadApis.d.ts +0 -12
  62. package/dist/loader/loadApis.js +0 -71
  63. package/dist/loader/loadHooks.d.ts +0 -7
  64. package/dist/loader/loadHooks.js +0 -50
  65. package/dist/loader/loadPlugins.d.ts +0 -8
  66. package/dist/loader/loadPlugins.js +0 -69
  67. package/dist/paths.d.ts +0 -93
  68. package/dist/paths.js +0 -100
  69. package/dist/plugins/cache.d.ts +0 -10
  70. package/dist/plugins/cache.js +0 -24
  71. package/dist/plugins/cipher.d.ts +0 -7
  72. package/dist/plugins/cipher.js +0 -14
  73. package/dist/plugins/config.d.ts +0 -3
  74. package/dist/plugins/config.js +0 -9
  75. package/dist/plugins/db.d.ts +0 -10
  76. package/dist/plugins/db.js +0 -48
  77. package/dist/plugins/jwt.d.ts +0 -6
  78. package/dist/plugins/jwt.js +0 -13
  79. package/dist/plugins/logger.d.ts +0 -10
  80. package/dist/plugins/logger.js +0 -21
  81. package/dist/plugins/redis.d.ts +0 -10
  82. package/dist/plugins/redis.js +0 -40
  83. package/dist/plugins/tool.d.ts +0 -75
  84. package/dist/plugins/tool.js +0 -105
  85. package/dist/router/api.d.ts +0 -14
  86. package/dist/router/api.js +0 -109
  87. package/dist/router/static.d.ts +0 -9
  88. package/dist/router/static.js +0 -56
  89. package/dist/scripts/ensureDist.d.ts +0 -1
  90. package/dist/scripts/ensureDist.js +0 -296
  91. package/dist/sync/syncApi.d.ts +0 -3
  92. package/dist/sync/syncApi.js +0 -140
  93. package/dist/sync/syncCache.d.ts +0 -2
  94. package/dist/sync/syncCache.js +0 -14
  95. package/dist/sync/syncDev.d.ts +0 -6
  96. package/dist/sync/syncDev.js +0 -166
  97. package/dist/sync/syncMenu.d.ts +0 -14
  98. package/dist/sync/syncMenu.js +0 -308
  99. package/dist/sync/syncTable.d.ts +0 -126
  100. package/dist/sync/syncTable.js +0 -1129
  101. package/dist/types/api.d.ts +0 -175
  102. package/dist/types/api.js +0 -4
  103. package/dist/types/befly.d.ts +0 -231
  104. package/dist/types/befly.js +0 -4
  105. package/dist/types/cache.d.ts +0 -96
  106. package/dist/types/cache.js +0 -4
  107. package/dist/types/cipher.d.ts +0 -27
  108. package/dist/types/cipher.js +0 -7
  109. package/dist/types/common.d.ts +0 -127
  110. package/dist/types/common.js +0 -5
  111. package/dist/types/context.d.ts +0 -39
  112. package/dist/types/context.js +0 -4
  113. package/dist/types/coreError.d.ts +0 -31
  114. package/dist/types/coreError.js +0 -38
  115. package/dist/types/crypto.d.ts +0 -20
  116. package/dist/types/crypto.js +0 -4
  117. package/dist/types/database.d.ts +0 -182
  118. package/dist/types/database.js +0 -4
  119. package/dist/types/hook.d.ts +0 -30
  120. package/dist/types/hook.js +0 -19
  121. package/dist/types/jwt.d.ts +0 -76
  122. package/dist/types/jwt.js +0 -4
  123. package/dist/types/logger.d.ts +0 -95
  124. package/dist/types/logger.js +0 -6
  125. package/dist/types/plugin.d.ts +0 -27
  126. package/dist/types/plugin.js +0 -17
  127. package/dist/types/redis.d.ts +0 -80
  128. package/dist/types/redis.js +0 -4
  129. package/dist/types/roleApisCache.d.ts +0 -21
  130. package/dist/types/roleApisCache.js +0 -8
  131. package/dist/types/sync.d.ts +0 -93
  132. package/dist/types/sync.js +0 -4
  133. package/dist/types/table.d.ts +0 -34
  134. package/dist/types/table.js +0 -4
  135. package/dist/types/validate.d.ts +0 -113
  136. package/dist/types/validate.js +0 -4
  137. package/dist/utils/calcPerfTime.d.ts +0 -4
  138. package/dist/utils/calcPerfTime.js +0 -13
  139. package/dist/utils/cors.d.ts +0 -8
  140. package/dist/utils/cors.js +0 -17
  141. package/dist/utils/dbFieldRules.d.ts +0 -31
  142. package/dist/utils/dbFieldRules.js +0 -94
  143. package/dist/utils/fieldClear.d.ts +0 -11
  144. package/dist/utils/fieldClear.js +0 -57
  145. package/dist/utils/formatYmdHms.d.ts +0 -1
  146. package/dist/utils/formatYmdHms.js +0 -20
  147. package/dist/utils/getClientIp.d.ts +0 -6
  148. package/dist/utils/getClientIp.js +0 -39
  149. package/dist/utils/importDefault.d.ts +0 -1
  150. package/dist/utils/importDefault.js +0 -53
  151. package/dist/utils/isDirentDirectory.d.ts +0 -3
  152. package/dist/utils/isDirentDirectory.js +0 -18
  153. package/dist/utils/loadMenuConfigs.d.ts +0 -11
  154. package/dist/utils/loadMenuConfigs.js +0 -130
  155. package/dist/utils/loggerUtils.d.ts +0 -18
  156. package/dist/utils/loggerUtils.js +0 -171
  157. package/dist/utils/mergeAndConcat.d.ts +0 -7
  158. package/dist/utils/mergeAndConcat.js +0 -77
  159. package/dist/utils/normalizeFieldDefinition.d.ts +0 -18
  160. package/dist/utils/normalizeFieldDefinition.js +0 -27
  161. package/dist/utils/processInfo.d.ts +0 -26
  162. package/dist/utils/processInfo.js +0 -41
  163. package/dist/utils/response.d.ts +0 -20
  164. package/dist/utils/response.js +0 -96
  165. package/dist/utils/scanAddons.d.ts +0 -15
  166. package/dist/utils/scanAddons.js +0 -35
  167. package/dist/utils/scanCoreBuiltins.d.ts +0 -3
  168. package/dist/utils/scanCoreBuiltins.js +0 -72
  169. package/dist/utils/scanFiles.d.ts +0 -32
  170. package/dist/utils/scanFiles.js +0 -124
  171. package/dist/utils/scanSources.d.ts +0 -10
  172. package/dist/utils/scanSources.js +0 -46
  173. package/dist/utils/sortModules.d.ts +0 -28
  174. package/dist/utils/sortModules.js +0 -105
  175. package/dist/utils/sqlUtil.d.ts +0 -33
  176. package/dist/utils/sqlUtil.js +0 -146
  177. package/dist/utils/util.d.ts +0 -172
  178. package/dist/utils/util.js +0 -517
@@ -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
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * 钩子加载器
3
- * 默认加载所有来源钩子(core/addon/app)
4
- */
5
- import type { Hook } from "../types/hook";
6
- import type { ScanFileResult } from "../utils/scanFiles";
7
- export declare function loadHooks(hooks: ScanFileResult[]): Promise<Hook[]>;
@@ -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");
@@ -1,10 +0,0 @@
1
- /**
2
- * 缓存插件 - TypeScript 版本
3
- * 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
4
- */
5
- import type { Plugin } from "../types/plugin";
6
- /**
7
- * 缓存插件
8
- */
9
- declare const cachePlugin: Plugin;
10
- export default cachePlugin;
@@ -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;
@@ -1,7 +0,0 @@
1
- /**
2
- * Cipher 插件
3
- * 提供加密解密功能
4
- */
5
- import type { Plugin } from "../types/plugin";
6
- declare const cipherPlugin: Plugin;
7
- export default cipherPlugin;
@@ -1,14 +0,0 @@
1
- /**
2
- * Cipher 插件
3
- * 提供加密解密功能
4
- */
5
- import { Cipher } from "../lib/cipher";
6
- const cipherPlugin = {
7
- name: "cipher",
8
- enable: true,
9
- deps: [],
10
- handler: () => {
11
- return Cipher;
12
- }
13
- };
14
- export default cipherPlugin;
@@ -1,3 +0,0 @@
1
- import type { Plugin } from "../types/plugin";
2
- declare const configPlugin: Plugin;
3
- export default configPlugin;
@@ -1,9 +0,0 @@
1
- const configPlugin = {
2
- name: "config",
3
- enable: true,
4
- deps: [],
5
- handler: (befly) => {
6
- return befly.config;
7
- }
8
- };
9
- export default configPlugin;
@@ -1,10 +0,0 @@
1
- /**
2
- * 数据库插件
3
- * 初始化数据库连接和 SQL 管理器
4
- */
5
- import type { Plugin } from "../types/plugin";
6
- /**
7
- * 数据库插件
8
- */
9
- declare const dbPlugin: Plugin;
10
- export default dbPlugin;
@@ -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;
@@ -1,6 +0,0 @@
1
- /**
2
- * JWT 插件
3
- */
4
- import type { Plugin } from "../types/plugin";
5
- declare const jwtPlugin: Plugin;
6
- export default jwtPlugin;
@@ -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;
@@ -1,10 +0,0 @@
1
- /**
2
- * 日志插件
3
- * 提供全局日志功能
4
- */
5
- import type { Plugin } from "../types/plugin";
6
- /**
7
- * 日志插件
8
- */
9
- declare const loggerPlugin: Plugin;
10
- export default loggerPlugin;
@@ -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;
@@ -1,10 +0,0 @@
1
- /**
2
- * Redis 插件
3
- * 初始化 Redis 连接和助手工具
4
- */
5
- import type { Plugin } from "../types/plugin";
6
- /**
7
- * Redis 插件
8
- */
9
- declare const redisPlugin: Plugin;
10
- export default redisPlugin;
@@ -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;