befly 3.10.16 → 3.10.18
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/befly.config.ts +46 -36
- package/checks/checkApi.ts +1 -1
- package/checks/checkHook.ts +1 -1
- package/checks/checkMenu.ts +5 -5
- package/checks/checkPlugin.ts +1 -1
- package/checks/checkTable.ts +3 -3
- package/docs/guide/quickstart.md +7 -7
- package/docs/reference/logger.md +4 -4
- package/docs/reference/sync.md +14 -14
- package/docs/reference/table.md +2 -2
- package/docs/reference/validator.md +3 -3
- package/hooks/auth.ts +2 -2
- package/hooks/cors.ts +3 -3
- package/hooks/parser.ts +3 -3
- package/hooks/permission.ts +4 -4
- package/hooks/validator.ts +3 -3
- package/lib/cacheHelper.ts +2 -2
- package/lib/cipher.ts +1 -1
- package/lib/connect.ts +2 -2
- package/lib/dbHelper.ts +13 -13
- package/lib/dbUtils.ts +3 -3
- package/lib/jwt.ts +2 -2
- package/lib/logger.ts +2 -2
- package/lib/redisHelper.ts +2 -2
- package/lib/sqlBuilder.ts +2 -2
- package/lib/validator.ts +2 -2
- package/loader/loadApis.ts +4 -4
- package/loader/loadHooks.ts +4 -4
- package/loader/loadPlugins.ts +5 -5
- package/main.ts +27 -27
- package/package.json +4 -7
- package/plugins/cache.ts +3 -3
- package/plugins/cipher.ts +2 -2
- package/plugins/config.ts +2 -2
- package/plugins/db.ts +6 -6
- package/plugins/jwt.ts +3 -3
- package/plugins/logger.ts +3 -3
- package/plugins/redis.ts +5 -5
- package/plugins/tool.ts +2 -2
- package/router/api.ts +9 -9
- package/router/static.ts +4 -4
- package/sync/syncApi.ts +3 -3
- package/sync/syncCache.ts +1 -1
- package/sync/syncDev.ts +3 -3
- package/sync/syncMenu.ts +6 -6
- package/sync/syncTable.ts +9 -9
- package/tsconfig.json +1 -47
- package/types/api.d.ts +4 -4
- package/types/befly.d.ts +11 -11
- package/types/cache.d.ts +1 -1
- package/types/context.d.ts +1 -1
- package/types/hook.d.ts +2 -2
- package/types/plugin.d.ts +1 -1
- package/utils/arrayKeysToCamel.ts +1 -1
- package/utils/cors.ts +1 -1
- package/utils/importDefault.ts +1 -1
- package/utils/loadMenuConfigs.ts +4 -4
- package/utils/processFields.ts +1 -1
- package/utils/response.ts +2 -2
- package/utils/scanAddons.ts +2 -2
- package/utils/scanConfig.ts +1 -1
- package/utils/scanFiles.ts +1 -1
- package/utils/scanSources.ts +5 -5
- package/utils/sortModules.ts +1 -1
- package/utils/sqlLog.ts +1 -1
package/befly.config.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* 自动加载 configs 目录下的配置文件并与默认配置合并
|
|
4
4
|
* 支持环境分离:befly.common.json + befly.development/production.json
|
|
5
5
|
*/
|
|
6
|
-
import type { BeflyOptions } from "./types/befly.
|
|
6
|
+
import type { BeflyOptions } from "./types/befly.ts";
|
|
7
7
|
|
|
8
|
-
import { compileDisableMenuGlobRules } from "./utils/disableMenusGlob.
|
|
9
|
-
import { scanConfig } from "./utils/scanConfig.
|
|
8
|
+
import { compileDisableMenuGlobRules } from "./utils/disableMenusGlob.ts";
|
|
9
|
+
import { scanConfig } from "./utils/scanConfig.ts";
|
|
10
10
|
|
|
11
11
|
/** 默认配置 */
|
|
12
12
|
const defaultOptions: BeflyOptions = {
|
|
@@ -89,43 +89,53 @@ const defaultOptions: BeflyOptions = {
|
|
|
89
89
|
addons: {}
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
cwd?: string;
|
|
94
|
-
nodeEnv?: string;
|
|
95
|
-
};
|
|
92
|
+
const beflyConfigCache: Map<string, Promise<BeflyOptions>> = new Map();
|
|
96
93
|
|
|
97
|
-
export async function loadBeflyConfig(
|
|
98
|
-
const nodeEnv =
|
|
94
|
+
export async function loadBeflyConfig(): Promise<BeflyOptions> {
|
|
95
|
+
const nodeEnv = process.env.NODE_ENV || defaultOptions.nodeEnv || "development";
|
|
99
96
|
const envSuffix = nodeEnv === "production" ? "production" : "development";
|
|
100
97
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
dirs: ["configs"],
|
|
106
|
-
files: ["befly.common", `befly.${envSuffix}`],
|
|
107
|
-
extensions: [".json"],
|
|
108
|
-
mode: "merge",
|
|
109
|
-
defaults: defaultOptions
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// 配置校验:redis.prefix 作为 key 前缀,由 RedisHelper 统一拼接 ":"。
|
|
113
|
-
// 因此 prefix 本身不允许包含 ":",否则会导致 key 结构出现空段或多段分隔(例如 "prefix::key"),
|
|
114
|
-
// 在 RedisInsight 等工具里可能显示 [NO NAME] 空分组,且容易造成 key 管理混乱。
|
|
115
|
-
const redisPrefix = (config as any)?.redis?.prefix;
|
|
116
|
-
if (typeof redisPrefix === "string") {
|
|
117
|
-
const trimmedPrefix = redisPrefix.trim();
|
|
118
|
-
if (trimmedPrefix.includes(":")) {
|
|
119
|
-
throw new Error(`配置错误:redis.prefix 不允许包含 ':'(RedisHelper 会自动拼接分隔符 ':'),请改为不带冒号的前缀,例如 'befly_demo',当前值=${redisPrefix}`);
|
|
120
|
-
}
|
|
98
|
+
const cacheKey = nodeEnv;
|
|
99
|
+
const cached = beflyConfigCache.get(cacheKey);
|
|
100
|
+
if (cached) {
|
|
101
|
+
return await cached;
|
|
121
102
|
}
|
|
122
103
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
104
|
+
const promise = (async () => {
|
|
105
|
+
// 使用 scanConfig 一次性加载并合并所有配置文件
|
|
106
|
+
// 合并顺序:defaultOptions ← befly.common.json ← befly.development/production.json
|
|
107
|
+
const config = await scanConfig({
|
|
108
|
+
dirs: ["configs"],
|
|
109
|
+
files: ["befly.common", `befly.${envSuffix}`],
|
|
110
|
+
extensions: [".json"],
|
|
111
|
+
mode: "merge",
|
|
112
|
+
defaults: defaultOptions
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// 配置校验:redis.prefix 作为 key 前缀,由 RedisHelper 统一拼接 ":"。
|
|
116
|
+
// 因此 prefix 本身不允许包含 ":",否则会导致 key 结构出现空段或多段分隔(例如 "prefix::key"),
|
|
117
|
+
// 在 RedisInsight 等工具里可能显示 [NO NAME] 空分组,且容易造成 key 管理混乱。
|
|
118
|
+
const redisPrefix = (config as any)?.redis?.prefix;
|
|
119
|
+
if (typeof redisPrefix === "string") {
|
|
120
|
+
const trimmedPrefix = redisPrefix.trim();
|
|
121
|
+
if (trimmedPrefix.includes(":")) {
|
|
122
|
+
throw new Error(`配置错误:redis.prefix 不允许包含 ':'(RedisHelper 会自动拼接分隔符 ':'),请改为不带冒号的前缀,例如 'befly_demo',当前值=${redisPrefix}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
127
125
|
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
// 预编译 disableMenus 的 Bun.Glob 规则:
|
|
127
|
+
// - 提前暴露配置错误(fail-fast)
|
|
128
|
+
// - 后续 checkMenu 会复用同一进程级缓存
|
|
129
|
+
compileDisableMenuGlobRules((config as any)?.disableMenus);
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
return config as BeflyOptions;
|
|
132
|
+
})();
|
|
133
|
+
|
|
134
|
+
beflyConfigCache.set(cacheKey, promise);
|
|
135
|
+
try {
|
|
136
|
+
return await promise;
|
|
137
|
+
} catch (error: any) {
|
|
138
|
+
beflyConfigCache.delete(cacheKey);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
package/checks/checkApi.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isPlainObject } from "es-toolkit/compat";
|
|
2
2
|
import { omit } from "es-toolkit/object";
|
|
3
3
|
|
|
4
|
-
import { Logger } from "../lib/logger.
|
|
4
|
+
import { Logger } from "../lib/logger.ts";
|
|
5
5
|
|
|
6
6
|
export async function checkApi(apis: any[]): Promise<void> {
|
|
7
7
|
let hasError = false;
|
package/checks/checkHook.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isPlainObject } from "es-toolkit/compat";
|
|
2
2
|
import { omit } from "es-toolkit/object";
|
|
3
3
|
|
|
4
|
-
import { Logger } from "../lib/logger.
|
|
4
|
+
import { Logger } from "../lib/logger.ts";
|
|
5
5
|
|
|
6
6
|
export async function checkHook(hooks: any[]): Promise<void> {
|
|
7
7
|
let hasError = false;
|
package/checks/checkMenu.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { MenuConfig } from "../types/sync.
|
|
2
|
-
import type { AddonInfo } from "../utils/scanAddons.
|
|
1
|
+
import type { MenuConfig } from "../types/sync.ts";
|
|
2
|
+
import type { AddonInfo } from "../utils/scanAddons.ts";
|
|
3
3
|
|
|
4
|
-
import { Logger } from "../lib/logger.
|
|
5
|
-
import { compileDisableMenuGlobRules, isMenuPathDisabledByGlobRules } from "../utils/disableMenusGlob.
|
|
6
|
-
import { loadMenuConfigs } from "../utils/loadMenuConfigs.
|
|
4
|
+
import { Logger } from "../lib/logger.ts";
|
|
5
|
+
import { compileDisableMenuGlobRules, isMenuPathDisabledByGlobRules } from "../utils/disableMenusGlob.ts";
|
|
6
|
+
import { loadMenuConfigs } from "../utils/loadMenuConfigs.ts";
|
|
7
7
|
|
|
8
8
|
function isValidMenuPath(path: string): { ok: boolean; reason: string } {
|
|
9
9
|
if (!path) {
|
package/checks/checkPlugin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isPlainObject } from "es-toolkit/compat";
|
|
2
2
|
import { omit } from "es-toolkit/object";
|
|
3
3
|
|
|
4
|
-
import { Logger } from "../lib/logger.
|
|
4
|
+
import { Logger } from "../lib/logger.ts";
|
|
5
5
|
|
|
6
6
|
export async function checkPlugin(plugins: any[]): Promise<void> {
|
|
7
7
|
let hasError = false;
|
package/checks/checkTable.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { FieldDefinition } from "../types/validate.
|
|
2
|
-
import type { ScanFileResult } from "../utils/scanFiles.
|
|
1
|
+
import type { FieldDefinition } from "../types/validate.ts";
|
|
2
|
+
import type { ScanFileResult } from "../utils/scanFiles.ts";
|
|
3
3
|
|
|
4
|
-
import { Logger } from "../lib/logger.
|
|
4
|
+
import { Logger } from "../lib/logger.ts";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 保留字段列表
|
package/docs/guide/quickstart.md
CHANGED
|
@@ -225,13 +225,13 @@ CREATE DATABASE my_api CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
225
225
|
如需手动触发,可在代码中调用(一般不建议在请求路径中调用):
|
|
226
226
|
|
|
227
227
|
```typescript
|
|
228
|
-
import { syncTable } from "../sync/syncTable.
|
|
229
|
-
import { syncApi } from "../sync/syncApi.
|
|
230
|
-
import { syncMenu } from "../sync/syncMenu.
|
|
231
|
-
import { syncDev } from "../sync/syncDev.
|
|
232
|
-
import { syncCache } from "../sync/syncCache.
|
|
233
|
-
import { checkMenu } from "../checks/checkMenu.
|
|
234
|
-
import { scanSources } from "../utils/scanSources.
|
|
228
|
+
import { syncTable } from "../sync/syncTable.ts";
|
|
229
|
+
import { syncApi } from "../sync/syncApi.ts";
|
|
230
|
+
import { syncMenu } from "../sync/syncMenu.ts";
|
|
231
|
+
import { syncDev } from "../sync/syncDev.ts";
|
|
232
|
+
import { syncCache } from "../sync/syncCache.ts";
|
|
233
|
+
import { checkMenu } from "../checks/checkMenu.ts";
|
|
234
|
+
import { scanSources } from "../utils/scanSources.ts";
|
|
235
235
|
|
|
236
236
|
// ctx:BeflyContext(需已具备 ctx.db / ctx.redis / ctx.cache / ctx.config)
|
|
237
237
|
const sources = await scanSources();
|
package/docs/reference/logger.md
CHANGED
|
@@ -87,7 +87,7 @@ interface LoggerConfig {
|
|
|
87
87
|
### 导入 Logger
|
|
88
88
|
|
|
89
89
|
```typescript
|
|
90
|
-
import { Logger } from "../lib/logger.
|
|
90
|
+
import { Logger } from "../lib/logger.ts";
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
### 日志方法
|
|
@@ -297,7 +297,7 @@ export default {
|
|
|
297
297
|
|
|
298
298
|
```typescript
|
|
299
299
|
// 直接导入使用
|
|
300
|
-
import { Logger } from "../lib/logger.
|
|
300
|
+
import { Logger } from "../lib/logger.ts";
|
|
301
301
|
|
|
302
302
|
Logger.info("直接使用");
|
|
303
303
|
```
|
|
@@ -311,7 +311,7 @@ Logger.info("直接使用");
|
|
|
311
311
|
测试时可以设置 Mock 实例:
|
|
312
312
|
|
|
313
313
|
```typescript
|
|
314
|
-
import { Logger, setMockLogger } from "../lib/logger.
|
|
314
|
+
import { Logger, setMockLogger } from "../lib/logger.ts";
|
|
315
315
|
import pino from "pino";
|
|
316
316
|
|
|
317
317
|
// 创建 mock logger
|
|
@@ -331,7 +331,7 @@ setMockLogger(null);
|
|
|
331
331
|
|
|
332
332
|
```typescript
|
|
333
333
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
334
|
-
import { Logger, setMockLogger } from "../lib/logger.
|
|
334
|
+
import { Logger, setMockLogger } from "../lib/logger.ts";
|
|
335
335
|
import pino from "pino";
|
|
336
336
|
|
|
337
337
|
describe("Logger", () => {
|
package/docs/reference/sync.md
CHANGED
|
@@ -53,8 +53,8 @@ Sync 同步系统用于将代码定义同步到数据库,包括:
|
|
|
53
53
|
默认会在服务启动时自动执行(仅主进程)。如需在代码中手动执行:
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
|
-
import { syncTable } from "../sync/syncTable.
|
|
57
|
-
import { scanSources } from "../utils/scanSources.
|
|
56
|
+
import { syncTable } from "../sync/syncTable.ts";
|
|
57
|
+
import { scanSources } from "../utils/scanSources.ts";
|
|
58
58
|
|
|
59
59
|
// ctx:BeflyContext(需已具备 ctx.db / ctx.redis / ctx.cache / ctx.config)
|
|
60
60
|
const sources = await scanSources();
|
|
@@ -120,8 +120,8 @@ await syncTable(ctx, sources.tables);
|
|
|
120
120
|
如需在代码中手动调用:
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
|
-
import { syncApi } from "../sync/syncApi.
|
|
124
|
-
import { scanSources } from "../utils/scanSources.
|
|
123
|
+
import { syncApi } from "../sync/syncApi.ts";
|
|
124
|
+
import { scanSources } from "../utils/scanSources.ts";
|
|
125
125
|
|
|
126
126
|
const sources = await scanSources();
|
|
127
127
|
await syncApi(ctx, sources.apis as any);
|
|
@@ -185,9 +185,9 @@ interface SyncApiStats {
|
|
|
185
185
|
如需手动调用,需要先对菜单配置做校验/过滤(例如 disableMenus):
|
|
186
186
|
|
|
187
187
|
```typescript
|
|
188
|
-
import { checkMenu } from "../checks/checkMenu.
|
|
189
|
-
import { syncMenu } from "../sync/syncMenu.
|
|
190
|
-
import { scanSources } from "../utils/scanSources.
|
|
188
|
+
import { checkMenu } from "../checks/checkMenu.ts";
|
|
189
|
+
import { syncMenu } from "../sync/syncMenu.ts";
|
|
190
|
+
import { scanSources } from "../utils/scanSources.ts";
|
|
191
191
|
|
|
192
192
|
const sources = await scanSources();
|
|
193
193
|
const checkedMenus = await checkMenu(sources.addons, { disableMenus: ctx.config.disableMenus || [] });
|
|
@@ -333,13 +333,13 @@ interface SyncMenuStats {
|
|
|
333
333
|
## 代码调用
|
|
334
334
|
|
|
335
335
|
```typescript
|
|
336
|
-
import { syncTable } from "./sync/syncTable.
|
|
337
|
-
import { syncApi } from "./sync/syncApi.
|
|
338
|
-
import { syncCache } from "./sync/syncCache.
|
|
339
|
-
import { syncDev } from "./sync/syncDev.
|
|
340
|
-
import { syncMenu } from "./sync/syncMenu.
|
|
341
|
-
import { scanSources } from "./utils/scanSources.
|
|
342
|
-
import { checkMenu } from "./checks/checkMenu.
|
|
336
|
+
import { syncTable } from "./sync/syncTable.ts";
|
|
337
|
+
import { syncApi } from "./sync/syncApi.ts";
|
|
338
|
+
import { syncCache } from "./sync/syncCache.ts";
|
|
339
|
+
import { syncDev } from "./sync/syncDev.ts";
|
|
340
|
+
import { syncMenu } from "./sync/syncMenu.ts";
|
|
341
|
+
import { scanSources } from "./utils/scanSources.ts";
|
|
342
|
+
import { checkMenu } from "./checks/checkMenu.ts";
|
|
343
343
|
|
|
344
344
|
// 启动前/启动中手动触发同步
|
|
345
345
|
// ctx:BeflyContext(需已具备 ctx.db / ctx.redis / ctx.cache / ctx.config)
|
package/docs/reference/table.md
CHANGED
|
@@ -517,8 +517,8 @@ interface FieldDefinition {
|
|
|
517
517
|
如需在代码中手动触发:
|
|
518
518
|
|
|
519
519
|
```typescript
|
|
520
|
-
import { syncTable } from "../../sync/syncTable.
|
|
521
|
-
import { scanSources } from "../../utils/scanSources.
|
|
520
|
+
import { syncTable } from "../../sync/syncTable.ts";
|
|
521
|
+
import { scanSources } from "../../utils/scanSources.ts";
|
|
522
522
|
|
|
523
523
|
// ctx:BeflyContext(需已具备 ctx.db / ctx.redis / ctx.config)
|
|
524
524
|
const sources = await scanSources();
|
|
@@ -33,7 +33,7 @@ Validator 是 Befly 的参数验证系统,提供:
|
|
|
33
33
|
### 基本结构
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
|
-
import { Validator } from "../lib/validator.
|
|
36
|
+
import { Validator } from "../lib/validator.ts";
|
|
37
37
|
|
|
38
38
|
class Validator {
|
|
39
39
|
// 验证数据对象
|
|
@@ -362,7 +362,7 @@ export default {
|
|
|
362
362
|
可以引用表定义中的字段:
|
|
363
363
|
|
|
364
364
|
```typescript
|
|
365
|
-
import { adminTable } from "../../../tables/admin.
|
|
365
|
+
import { adminTable } from "../../../tables/admin.ts";
|
|
366
366
|
|
|
367
367
|
export default {
|
|
368
368
|
name: "创建管理员",
|
|
@@ -381,7 +381,7 @@ export default {
|
|
|
381
381
|
### 使用公共字段
|
|
382
382
|
|
|
383
383
|
```typescript
|
|
384
|
-
import { Fields } from "../../../config/fields.
|
|
384
|
+
import { Fields } from "../../../config/fields.ts";
|
|
385
385
|
|
|
386
386
|
export default {
|
|
387
387
|
name: "获取列表",
|
package/hooks/auth.ts
CHANGED
package/hooks/cors.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { CorsConfig } from "../types/befly.
|
|
1
|
+
import type { CorsConfig } from "../types/befly.ts";
|
|
2
2
|
// 类型导入
|
|
3
|
-
import type { Hook } from "../types/hook.
|
|
3
|
+
import type { Hook } from "../types/hook.ts";
|
|
4
4
|
|
|
5
5
|
// 相对导入
|
|
6
|
-
import { setCorsOptions } from "../utils/cors.
|
|
6
|
+
import { setCorsOptions } from "../utils/cors.ts";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* CORS 跨域处理钩子
|
package/hooks/parser.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// 类型导入
|
|
2
|
-
import type { Hook } from "../types/hook.
|
|
2
|
+
import type { Hook } from "../types/hook.ts";
|
|
3
3
|
|
|
4
4
|
// 外部依赖
|
|
5
5
|
import { isPlainObject, isEmpty } from "es-toolkit/compat";
|
|
6
6
|
import { XMLParser } from "fast-xml-parser";
|
|
7
7
|
|
|
8
8
|
// 相对导入
|
|
9
|
-
import { pickFields } from "../utils/pickFields.
|
|
10
|
-
import { ErrorResponse } from "../utils/response.
|
|
9
|
+
import { pickFields } from "../utils/pickFields.ts";
|
|
10
|
+
import { ErrorResponse } from "../utils/response.ts";
|
|
11
11
|
|
|
12
12
|
const xmlParser = new XMLParser();
|
|
13
13
|
|
package/hooks/permission.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// 类型导入
|
|
2
|
-
import type { Hook } from "../types/hook.
|
|
2
|
+
import type { Hook } from "../types/hook.ts";
|
|
3
3
|
|
|
4
|
-
import { CacheKeys } from "../lib/cacheKeys.
|
|
5
|
-
import { Logger } from "../lib/logger.
|
|
4
|
+
import { CacheKeys } from "../lib/cacheKeys.ts";
|
|
5
|
+
import { Logger } from "../lib/logger.ts";
|
|
6
6
|
// 相对导入
|
|
7
|
-
import { ErrorResponse } from "../utils/response.
|
|
7
|
+
import { ErrorResponse } from "../utils/response.ts";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* 权限检查钩子
|
package/hooks/validator.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// 类型导入
|
|
2
|
-
import type { Hook } from "../types/hook.
|
|
2
|
+
import type { Hook } from "../types/hook.ts";
|
|
3
3
|
|
|
4
4
|
// 相对导入
|
|
5
|
-
import { Validator } from "../lib/validator.
|
|
6
|
-
import { ErrorResponse } from "../utils/response.
|
|
5
|
+
import { Validator } from "../lib/validator.ts";
|
|
6
|
+
import { ErrorResponse } from "../utils/response.ts";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 参数验证钩子
|
package/lib/cacheHelper.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { CacheKeys } from "./cacheKeys.
|
|
7
|
-
import { Logger } from "./logger.
|
|
6
|
+
import { CacheKeys } from "./cacheKeys.ts";
|
|
7
|
+
import { Logger } from "./logger.ts";
|
|
8
8
|
|
|
9
9
|
type CacheHelperDb = {
|
|
10
10
|
tableExists(table: string): Promise<{ data: boolean }>;
|
package/lib/cipher.ts
CHANGED
package/lib/connect.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* 统一管理 SQL 和 Redis 连接
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { DatabaseConfig, RedisConfig } from "../types/befly.
|
|
6
|
+
import type { DatabaseConfig, RedisConfig } from "../types/befly.ts";
|
|
7
7
|
|
|
8
8
|
import { SQL, RedisClient } from "bun";
|
|
9
9
|
|
|
10
|
-
import { Logger } from "./logger.
|
|
10
|
+
import { Logger } from "./logger.ts";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* 数据库连接管理器
|
package/lib/dbHelper.ts
CHANGED
|
@@ -3,22 +3,22 @@
|
|
|
3
3
|
* 提供数据库 CRUD 操作的封装
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { WhereConditions, JoinOption } from "../types/common.
|
|
7
|
-
import type { QueryOptions, InsertOptions, UpdateOptions, DeleteOptions, ListResult, AllResult, TransactionCallback, DbResult, SqlInfo, ListSql } from "../types/database.
|
|
8
|
-
import type { DbDialect } from "./dbDialect.
|
|
6
|
+
import type { WhereConditions, JoinOption } from "../types/common.ts";
|
|
7
|
+
import type { QueryOptions, InsertOptions, UpdateOptions, DeleteOptions, ListResult, AllResult, TransactionCallback, DbResult, SqlInfo, ListSql } from "../types/database.ts";
|
|
8
|
+
import type { DbDialect } from "./dbDialect.ts";
|
|
9
9
|
|
|
10
10
|
import { snakeCase } from "es-toolkit/string";
|
|
11
11
|
|
|
12
|
-
import { arrayKeysToCamel } from "../utils/arrayKeysToCamel.
|
|
13
|
-
import { convertBigIntFields } from "../utils/convertBigIntFields.
|
|
14
|
-
import { fieldClear } from "../utils/fieldClear.
|
|
15
|
-
import { keysToCamel } from "../utils/keysToCamel.
|
|
16
|
-
import { CacheKeys } from "./cacheKeys.
|
|
17
|
-
import { MySqlDialect } from "./dbDialect.
|
|
18
|
-
import { DbUtils } from "./dbUtils.
|
|
19
|
-
import { Logger } from "./logger.
|
|
20
|
-
import { SqlBuilder } from "./sqlBuilder.
|
|
21
|
-
import { SqlCheck } from "./sqlCheck.
|
|
12
|
+
import { arrayKeysToCamel } from "../utils/arrayKeysToCamel.ts";
|
|
13
|
+
import { convertBigIntFields } from "../utils/convertBigIntFields.ts";
|
|
14
|
+
import { fieldClear } from "../utils/fieldClear.ts";
|
|
15
|
+
import { keysToCamel } from "../utils/keysToCamel.ts";
|
|
16
|
+
import { CacheKeys } from "./cacheKeys.ts";
|
|
17
|
+
import { MySqlDialect } from "./dbDialect.ts";
|
|
18
|
+
import { DbUtils } from "./dbUtils.ts";
|
|
19
|
+
import { Logger } from "./logger.ts";
|
|
20
|
+
import { SqlBuilder } from "./sqlBuilder.ts";
|
|
21
|
+
import { SqlCheck } from "./sqlCheck.ts";
|
|
22
22
|
|
|
23
23
|
const TABLE_COLUMNS_CACHE_TTL_SECONDS = 3600;
|
|
24
24
|
|
package/lib/dbUtils.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { WhereConditions } from "../types/common.
|
|
1
|
+
import type { WhereConditions } from "../types/common.ts";
|
|
2
2
|
|
|
3
3
|
import { snakeCase } from "es-toolkit/string";
|
|
4
4
|
|
|
5
|
-
import { fieldClear } from "../utils/fieldClear.
|
|
6
|
-
import { keysToSnake } from "../utils/keysToSnake.
|
|
5
|
+
import { fieldClear } from "../utils/fieldClear.ts";
|
|
6
|
+
import { keysToSnake } from "../utils/keysToSnake.ts";
|
|
7
7
|
|
|
8
8
|
export class DbUtils {
|
|
9
9
|
static parseTableRef(tableRef: string): { schema: string | null; table: string; alias: string | null } {
|
package/lib/jwt.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* JWT 工具类 - 基于 fast-jwt 实现
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { AuthConfig } from "../types/befly.
|
|
6
|
-
import type { JwtPayload, JwtSignOptions, JwtVerifyOptions, JwtDecoded, JwtHeader } from "../types/jwt.
|
|
5
|
+
import type { AuthConfig } from "../types/befly.ts";
|
|
6
|
+
import type { JwtPayload, JwtSignOptions, JwtVerifyOptions, JwtDecoded, JwtHeader } from "../types/jwt.ts";
|
|
7
7
|
import type { Algorithm as FastJwtAlgorithm } from "fast-jwt";
|
|
8
8
|
|
|
9
9
|
import { createSigner, createVerifier, createDecoder } from "fast-jwt";
|
package/lib/logger.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 日志系统 - 基于 pino 实现
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { LoggerConfig } from "../types/logger.
|
|
5
|
+
import type { LoggerConfig } from "../types/logger.ts";
|
|
6
6
|
|
|
7
7
|
import { existsSync, mkdirSync } from "node:fs";
|
|
8
8
|
import { readdir, stat, unlink } from "node:fs/promises";
|
|
@@ -13,7 +13,7 @@ import { escapeRegExp } from "es-toolkit/string";
|
|
|
13
13
|
import { join } from "pathe";
|
|
14
14
|
import pino from "pino";
|
|
15
15
|
|
|
16
|
-
import { getCtx } from "./asyncContext.
|
|
16
|
+
import { getCtx } from "./asyncContext.ts";
|
|
17
17
|
|
|
18
18
|
// 注意:Logger 可能在运行时/测试中被 process.chdir() 影响。
|
|
19
19
|
// 为避免相对路径的 logs 目录随着 cwd 变化,使用模块加载时的初始 cwd 作为锚点。
|
package/lib/redisHelper.ts
CHANGED
package/lib/sqlBuilder.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* 提供链式 API 构建 SQL 查询
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { WhereConditions, WhereOperator, OrderDirection, SqlQuery, InsertData, UpdateData, SqlValue } from "../types/common.
|
|
6
|
+
import type { WhereConditions, WhereOperator, OrderDirection, SqlQuery, InsertData, UpdateData, SqlValue } from "../types/common.ts";
|
|
7
7
|
|
|
8
|
-
import { SqlCheck } from "./sqlCheck.
|
|
8
|
+
import { SqlCheck } from "./sqlCheck.ts";
|
|
9
9
|
|
|
10
10
|
const SqlBuilderError = {
|
|
11
11
|
QUOTE_IDENT_NEED_STRING: (identifier: unknown) => `quoteIdent 需要字符串类型标识符 (identifier: ${String(identifier)})`,
|
package/lib/validator.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* 纯静态类设计,简洁易用
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { TableDefinition, FieldDefinition, ValidateResult, SingleResult } from "../types/validate.
|
|
6
|
+
import type { TableDefinition, FieldDefinition, ValidateResult, SingleResult } from "../types/validate.ts";
|
|
7
7
|
|
|
8
|
-
import { RegexAliases, getCompiledRegex } from "../configs/presetRegexp.
|
|
8
|
+
import { RegexAliases, getCompiledRegex } from "../configs/presetRegexp.ts";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* 验证器类
|
package/loader/loadApis.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// 类型导入
|
|
7
|
-
import type { ApiRoute } from "../types/api.
|
|
8
|
-
import type { ScanFileResult } from "../utils/scanFiles.
|
|
7
|
+
import type { ApiRoute } from "../types/api.ts";
|
|
8
|
+
import type { ScanFileResult } from "../utils/scanFiles.ts";
|
|
9
9
|
|
|
10
|
-
import { Logger } from "../lib/logger.
|
|
11
|
-
import { processFields } from "../utils/processFields.
|
|
10
|
+
import { Logger } from "../lib/logger.ts";
|
|
11
|
+
import { processFields } from "../utils/processFields.ts";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 加载所有 API 路由
|
package/loader/loadHooks.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// 类型导入
|
|
8
|
-
import type { Hook } from "../types/hook.
|
|
9
|
-
import type { ScanFileResult } from "../utils/scanFiles.
|
|
8
|
+
import type { Hook } from "../types/hook.ts";
|
|
9
|
+
import type { ScanFileResult } from "../utils/scanFiles.ts";
|
|
10
10
|
|
|
11
|
-
import { Logger } from "../lib/logger.
|
|
12
|
-
import { sortModules } from "../utils/sortModules.
|
|
11
|
+
import { Logger } from "../lib/logger.ts";
|
|
12
|
+
import { sortModules } from "../utils/sortModules.ts";
|
|
13
13
|
|
|
14
14
|
export async function loadHooks(hooks: ScanFileResult[], disableHooks: string[] = []): Promise<Hook[]> {
|
|
15
15
|
const hooksMap: Hook[] = [];
|
package/loader/loadPlugins.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* 负责扫描和初始化所有插件(核心、组件、项目)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { BeflyContext } from "../types/befly.
|
|
7
|
-
import type { Plugin } from "../types/plugin.
|
|
8
|
-
import type { ScanFileResult } from "../utils/scanFiles.
|
|
6
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
7
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
8
|
+
import type { ScanFileResult } from "../utils/scanFiles.ts";
|
|
9
9
|
|
|
10
|
-
import { Logger } from "../lib/logger.
|
|
11
|
-
import { sortModules } from "../utils/sortModules.
|
|
10
|
+
import { Logger } from "../lib/logger.ts";
|
|
11
|
+
import { sortModules } from "../utils/sortModules.ts";
|
|
12
12
|
|
|
13
13
|
export async function loadPlugins(plugins: ScanFileResult[], context: BeflyContext, disablePlugins: string[] = []): Promise<Plugin[]> {
|
|
14
14
|
const pluginsMap: Plugin[] = [];
|