befly 3.10.17 → 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 +3 -3
- 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 +26 -26
- 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 = {
|
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[] = [];
|
package/main.ts
CHANGED
|
@@ -4,37 +4,37 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// ========== 类型导入 ==========
|
|
7
|
-
import type { ApiRoute } from "./types/api.
|
|
8
|
-
import type { BeflyContext, BeflyOptions } from "./types/befly.
|
|
9
|
-
import type { Hook } from "./types/hook.
|
|
10
|
-
import type { Plugin } from "./types/plugin.
|
|
11
|
-
|
|
12
|
-
import { checkApi } from "./checks/checkApi.
|
|
13
|
-
import { checkHook } from "./checks/checkHook.
|
|
14
|
-
import { checkMenu } from "./checks/checkMenu.
|
|
15
|
-
import { checkPlugin } from "./checks/checkPlugin.
|
|
16
|
-
import { checkTable } from "./checks/checkTable.
|
|
7
|
+
import type { ApiRoute } from "./types/api.ts";
|
|
8
|
+
import type { BeflyContext, BeflyOptions } from "./types/befly.ts";
|
|
9
|
+
import type { Hook } from "./types/hook.ts";
|
|
10
|
+
import type { Plugin } from "./types/plugin.ts";
|
|
11
|
+
|
|
12
|
+
import { checkApi } from "./checks/checkApi.ts";
|
|
13
|
+
import { checkHook } from "./checks/checkHook.ts";
|
|
14
|
+
import { checkMenu } from "./checks/checkMenu.ts";
|
|
15
|
+
import { checkPlugin } from "./checks/checkPlugin.ts";
|
|
16
|
+
import { checkTable } from "./checks/checkTable.ts";
|
|
17
17
|
// ========== 相对导入(项目内部文件) ==========
|
|
18
18
|
// 基础设施
|
|
19
|
-
import { Connect } from "./lib/connect.
|
|
20
|
-
import { Logger } from "./lib/logger.
|
|
19
|
+
import { Connect } from "./lib/connect.ts";
|
|
20
|
+
import { Logger } from "./lib/logger.ts";
|
|
21
21
|
// 加载器
|
|
22
|
-
import { loadApis } from "./loader/loadApis.
|
|
23
|
-
import { loadHooks } from "./loader/loadHooks.
|
|
24
|
-
import { loadPlugins } from "./loader/loadPlugins.
|
|
22
|
+
import { loadApis } from "./loader/loadApis.ts";
|
|
23
|
+
import { loadHooks } from "./loader/loadHooks.ts";
|
|
24
|
+
import { loadPlugins } from "./loader/loadPlugins.ts";
|
|
25
25
|
// 路由处理
|
|
26
|
-
import { apiHandler } from "./router/api.
|
|
27
|
-
import { staticHandler } from "./router/static.
|
|
26
|
+
import { apiHandler } from "./router/api.ts";
|
|
27
|
+
import { staticHandler } from "./router/static.ts";
|
|
28
28
|
// 同步
|
|
29
|
-
import { syncApi } from "./sync/syncApi.
|
|
30
|
-
import { syncCache } from "./sync/syncCache.
|
|
31
|
-
import { syncDev } from "./sync/syncDev.
|
|
32
|
-
import { syncMenu } from "./sync/syncMenu.
|
|
33
|
-
import { syncTable } from "./sync/syncTable.
|
|
29
|
+
import { syncApi } from "./sync/syncApi.ts";
|
|
30
|
+
import { syncCache } from "./sync/syncCache.ts";
|
|
31
|
+
import { syncDev } from "./sync/syncDev.ts";
|
|
32
|
+
import { syncMenu } from "./sync/syncMenu.ts";
|
|
33
|
+
import { syncTable } from "./sync/syncTable.ts";
|
|
34
34
|
// 工具
|
|
35
|
-
import { calcPerfTime } from "./utils/calcPerfTime.
|
|
36
|
-
import { getProcessRole } from "./utils/process.
|
|
37
|
-
import { scanSources } from "./utils/scanSources.
|
|
35
|
+
import { calcPerfTime } from "./utils/calcPerfTime.ts";
|
|
36
|
+
import { getProcessRole } from "./utils/process.ts";
|
|
37
|
+
import { scanSources } from "./utils/scanSources.ts";
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Befly 框架核心类
|
|
@@ -65,7 +65,7 @@ export class Befly {
|
|
|
65
65
|
const serverStartTime = Bun.nanoseconds();
|
|
66
66
|
|
|
67
67
|
// 0. 延迟加载配置(避免循环依赖)
|
|
68
|
-
const { loadBeflyConfig } = await import("./befly.config.
|
|
68
|
+
const { loadBeflyConfig } = await import("./befly.config.ts");
|
|
69
69
|
this.config = await loadBeflyConfig();
|
|
70
70
|
|
|
71
71
|
// 将配置注入到 ctx,供插件/Hook/sync 等按需读取
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.10.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.10.18",
|
|
4
|
+
"gitHead": "1fb1ccce3a69fb6a57f42a1e269c307ed159ae9a",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"test": "bun test",
|
|
62
|
-
"typecheck": "
|
|
62
|
+
"typecheck": "bunx tsgo -p tsconfig.json --noEmit"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"befly-shared": "^1.3.
|
|
65
|
+
"befly-shared": "^1.3.10",
|
|
66
66
|
"chalk": "^5.6.2",
|
|
67
67
|
"es-toolkit": "^1.43.0",
|
|
68
68
|
"fast-jwt": "^6.1.0",
|
|
@@ -72,9 +72,6 @@
|
|
|
72
72
|
"pino": "^10.1.0",
|
|
73
73
|
"pino-roll": "^4.0.0"
|
|
74
74
|
},
|
|
75
|
-
"devDependencies": {
|
|
76
|
-
"typescript": "^5.9.3"
|
|
77
|
-
},
|
|
78
75
|
"engines": {
|
|
79
76
|
"bun": ">=1.3.0"
|
|
80
77
|
}
|
package/plugins/cache.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { BeflyContext } from "../types/befly.
|
|
7
|
-
import type { Plugin } from "../types/plugin.
|
|
6
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
7
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
8
8
|
|
|
9
|
-
import { CacheHelper } from "../lib/cacheHelper.
|
|
9
|
+
import { CacheHelper } from "../lib/cacheHelper.ts";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* 缓存插件
|
package/plugins/cipher.ts
CHANGED
package/plugins/config.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* 配置插件
|
|
3
3
|
* 提供访问项目配置的能力
|
|
4
4
|
*/
|
|
5
|
-
import type { BeflyContext } from "../types/befly.
|
|
6
|
-
import type { Plugin } from "../types/plugin.
|
|
5
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
6
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
9
|
deps: [],
|
package/plugins/db.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* 初始化数据库连接和 SQL 管理器
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { BeflyContext } from "../types/befly.
|
|
7
|
-
import type { Plugin } from "../types/plugin.
|
|
6
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
7
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
8
8
|
|
|
9
|
-
import { Connect } from "../lib/connect.
|
|
10
|
-
import { getDialectByName } from "../lib/dbDialect.
|
|
11
|
-
import { DbHelper } from "../lib/dbHelper.
|
|
12
|
-
import { Logger } from "../lib/logger.
|
|
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
13
|
|
|
14
14
|
/**
|
|
15
15
|
* 数据库插件
|
package/plugins/jwt.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* JWT 插件
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { BeflyContext } from "../types/befly.
|
|
6
|
-
import type { Plugin } from "../types/plugin.
|
|
5
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
6
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
7
7
|
|
|
8
|
-
import { Jwt } from "../lib/jwt.
|
|
8
|
+
import { Jwt } from "../lib/jwt.ts";
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
deps: [],
|
package/plugins/logger.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* 提供全局日志功能
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { BeflyContext } from "../types/befly.
|
|
7
|
-
import type { Plugin } from "../types/plugin.
|
|
6
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
7
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
8
8
|
|
|
9
|
-
import { Logger } from "../lib/logger.
|
|
9
|
+
import { Logger } from "../lib/logger.ts";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* 日志插件
|
package/plugins/redis.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* 初始化 Redis 连接和助手工具
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { BeflyContext } from "../types/befly.
|
|
7
|
-
import type { Plugin } from "../types/plugin.
|
|
6
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
7
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
8
8
|
|
|
9
|
-
import { Connect } from "../lib/connect.
|
|
10
|
-
import { Logger } from "../lib/logger.
|
|
11
|
-
import { RedisHelper } from "../lib/redisHelper.
|
|
9
|
+
import { Connect } from "../lib/connect.ts";
|
|
10
|
+
import { Logger } from "../lib/logger.ts";
|
|
11
|
+
import { RedisHelper } from "../lib/redisHelper.ts";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Redis 插件
|
package/plugins/tool.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* 提供常用的工具函数
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { RequestContext } from "../types/context.
|
|
6
|
+
import type { RequestContext } from "../types/context.ts";
|
|
7
7
|
// 类型导入
|
|
8
|
-
import type { Plugin } from "../types/plugin.
|
|
8
|
+
import type { Plugin } from "../types/plugin.ts";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* 成功响应
|
package/router/api.ts
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
* 处理 /api/* 路径的请求
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { ApiRoute } from "../types/api.
|
|
7
|
-
import type { BeflyContext } from "../types/befly.
|
|
6
|
+
import type { ApiRoute } from "../types/api.ts";
|
|
7
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
8
8
|
// 类型导入
|
|
9
|
-
import type { RequestContext } from "../types/context.
|
|
10
|
-
import type { Hook } from "../types/hook.
|
|
9
|
+
import type { RequestContext } from "../types/context.ts";
|
|
10
|
+
import type { Hook } from "../types/hook.ts";
|
|
11
11
|
|
|
12
|
-
import { withCtx } from "../lib/asyncContext.
|
|
13
|
-
import { Logger } from "../lib/logger.
|
|
12
|
+
import { withCtx } from "../lib/asyncContext.ts";
|
|
13
|
+
import { Logger } from "../lib/logger.ts";
|
|
14
14
|
// 相对导入
|
|
15
|
-
import { genShortId } from "../utils/genShortId.
|
|
16
|
-
import { getClientIp } from "../utils/getClientIp.
|
|
17
|
-
import { FinalResponse } from "../utils/response.
|
|
15
|
+
import { genShortId } from "../utils/genShortId.ts";
|
|
16
|
+
import { getClientIp } from "../utils/getClientIp.ts";
|
|
17
|
+
import { FinalResponse } from "../utils/response.ts";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* API处理器工厂函数
|
package/router/static.ts
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// 类型导入
|
|
7
|
-
import type { CorsConfig } from "../types/befly.
|
|
7
|
+
import type { CorsConfig } from "../types/befly.ts";
|
|
8
8
|
|
|
9
9
|
// 外部依赖
|
|
10
10
|
import { join } from "pathe";
|
|
11
11
|
|
|
12
|
-
import { Logger } from "../lib/logger.
|
|
12
|
+
import { Logger } from "../lib/logger.ts";
|
|
13
13
|
// 相对导入
|
|
14
|
-
import { appDir } from "../paths.
|
|
15
|
-
import { setCorsOptions } from "../utils/cors.
|
|
14
|
+
import { appDir } from "../paths.ts";
|
|
15
|
+
import { setCorsOptions } from "../utils/cors.ts";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* 静态文件处理器工厂
|
package/sync/syncApi.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { BeflyContext } from "../types/befly.
|
|
2
|
-
import type { SyncApiItem } from "../types/sync.
|
|
1
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
2
|
+
import type { SyncApiItem } from "../types/sync.ts";
|
|
3
3
|
|
|
4
4
|
import { keyBy } from "es-toolkit/array";
|
|
5
5
|
|
|
6
|
-
import { Logger } from "../lib/logger.
|
|
6
|
+
import { Logger } from "../lib/logger.ts";
|
|
7
7
|
|
|
8
8
|
export async function syncApi(ctx: Pick<BeflyContext, "db" | "cache">, apis: SyncApiItem[]): Promise<void> {
|
|
9
9
|
const tableName = "addon_admin_api";
|
package/sync/syncCache.ts
CHANGED
package/sync/syncDev.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { BeflyContext } from "../types/befly.
|
|
1
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
2
2
|
|
|
3
|
-
import { Cipher } from "../lib/cipher.
|
|
4
|
-
import { Logger } from "../lib/logger.
|
|
3
|
+
import { Cipher } from "../lib/cipher.ts";
|
|
4
|
+
import { Logger } from "../lib/logger.ts";
|
|
5
5
|
|
|
6
6
|
export type SyncDevConfig = {
|
|
7
7
|
devEmail?: string;
|
package/sync/syncMenu.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { BeflyContext } from "../types/befly.
|
|
2
|
-
import type { MenuConfig } from "../types/sync.
|
|
1
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
2
|
+
import type { MenuConfig } from "../types/sync.ts";
|
|
3
3
|
|
|
4
|
-
import { Logger } from "../lib/logger.
|
|
5
|
-
import { compileDisableMenuGlobRules, isMenuPathDisabledByGlobRules } from "../utils/disableMenusGlob.
|
|
6
|
-
import { getParentPath } from "../utils/loadMenuConfigs.
|
|
4
|
+
import { Logger } from "../lib/logger.ts";
|
|
5
|
+
import { compileDisableMenuGlobRules, isMenuPathDisabledByGlobRules } from "../utils/disableMenusGlob.ts";
|
|
6
|
+
import { getParentPath } from "../utils/loadMenuConfigs.ts";
|
|
7
7
|
|
|
8
8
|
type MenuDef = {
|
|
9
9
|
path: string;
|
|
@@ -298,7 +298,7 @@ export async function syncMenu(ctx: BeflyContext, mergedMenus: MenuConfig[]): Pr
|
|
|
298
298
|
// 仅测试用(避免将内部扫描逻辑变成稳定 API)
|
|
299
299
|
export const __test__ = {
|
|
300
300
|
scanViewsDir: async (viewsDir: string, prefix: string, parentPath: string = "") => {
|
|
301
|
-
const mod = await import("../utils/loadMenuConfigs.
|
|
301
|
+
const mod = await import("../utils/loadMenuConfigs.ts");
|
|
302
302
|
return await mod.scanViewsDirToMenuConfigs(viewsDir, prefix, parentPath);
|
|
303
303
|
},
|
|
304
304
|
flattenMenusToDefMap: (mergedMenus: MenuConfig[]) => {
|
package/sync/syncTable.ts
CHANGED
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
* - 现在按项目要求,将所有实现合并到本文件(目录 packages/core/sync/syncTable/ 已删除)
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { DbDialectName } from "../lib/dbDialect.
|
|
10
|
-
import type { BeflyContext } from "../types/befly.
|
|
11
|
-
import type { DbResult, SqlInfo } from "../types/database.
|
|
12
|
-
import type { ColumnInfo, FieldChange, IndexInfo, TablePlan } from "../types/sync.
|
|
13
|
-
import type { FieldDefinition } from "../types/validate.
|
|
14
|
-
import type { ScanFileResult } from "../utils/scanFiles.
|
|
9
|
+
import type { DbDialectName } from "../lib/dbDialect.ts";
|
|
10
|
+
import type { BeflyContext } from "../types/befly.ts";
|
|
11
|
+
import type { DbResult, SqlInfo } from "../types/database.ts";
|
|
12
|
+
import type { ColumnInfo, FieldChange, IndexInfo, TablePlan } from "../types/sync.ts";
|
|
13
|
+
import type { FieldDefinition } from "../types/validate.ts";
|
|
14
|
+
import type { ScanFileResult } from "../utils/scanFiles.ts";
|
|
15
15
|
|
|
16
16
|
import { snakeCase } from "es-toolkit/string";
|
|
17
17
|
|
|
18
|
-
import { CacheKeys } from "../lib/cacheKeys.
|
|
19
|
-
import { getDialectByName, getSyncTableColumnsInfoQuery, getSyncTableIndexesQuery } from "../lib/dbDialect.
|
|
20
|
-
import { Logger } from "../lib/logger.
|
|
18
|
+
import { CacheKeys } from "../lib/cacheKeys.ts";
|
|
19
|
+
import { getDialectByName, getSyncTableColumnsInfoQuery, getSyncTableIndexesQuery } from "../lib/dbDialect.ts";
|
|
20
|
+
import { Logger } from "../lib/logger.ts";
|
|
21
21
|
|
|
22
22
|
type SqlExecutor = {
|
|
23
23
|
unsafe<T = any>(sqlStr: string, params?: unknown[]): Promise<DbResult<T, SqlInfo>>;
|
package/tsconfig.json
CHANGED
|
@@ -1,53 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.base.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"lib": ["ESNext"],
|
|
8
|
-
"moduleResolution": "bundler",
|
|
9
|
-
|
|
10
|
-
// 类型检查
|
|
11
|
-
"strict": true,
|
|
12
|
-
"noImplicitAny": true,
|
|
13
|
-
"strictNullChecks": true,
|
|
14
|
-
"strictFunctionTypes": true,
|
|
15
|
-
"strictBindCallApply": true,
|
|
16
|
-
"strictPropertyInitialization": true,
|
|
17
|
-
"noImplicitThis": true,
|
|
18
|
-
"alwaysStrict": true,
|
|
19
|
-
|
|
20
|
-
// 额外检查
|
|
21
|
-
"noUnusedLocals": false,
|
|
22
|
-
"noUnusedParameters": false,
|
|
23
|
-
"noImplicitReturns": true,
|
|
24
|
-
"noFallthroughCasesInSwitch": true,
|
|
25
|
-
"noUncheckedIndexedAccess": false,
|
|
26
|
-
"noImplicitOverride": true,
|
|
27
|
-
"noPropertyAccessFromIndexSignature": false,
|
|
28
|
-
|
|
29
|
-
// 模块
|
|
30
|
-
"esModuleInterop": true,
|
|
31
|
-
"allowSyntheticDefaultImports": true,
|
|
32
|
-
"forceConsistentCasingInFileNames": true,
|
|
33
|
-
"resolveJsonModule": true,
|
|
34
|
-
"isolatedModules": true,
|
|
35
|
-
|
|
36
|
-
// 输出
|
|
37
|
-
"noEmit": true,
|
|
38
|
-
"removeComments": false,
|
|
39
|
-
"importHelpers": false,
|
|
40
|
-
|
|
41
|
-
// 高级
|
|
42
|
-
"skipLibCheck": true,
|
|
43
|
-
"allowJs": false,
|
|
44
|
-
// Bun 特定
|
|
45
|
-
"types": ["bun"],
|
|
46
|
-
|
|
47
|
-
// 路径
|
|
48
|
-
"paths": {
|
|
49
|
-
"@/*": ["./*"]
|
|
50
|
-
}
|
|
4
|
+
"types": ["bun"]
|
|
51
5
|
},
|
|
52
6
|
"include": ["**/*.ts"],
|
|
53
7
|
"exclude": ["node_modules", "dist", "logs", "temp", "tests"]
|
package/types/api.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Befly API 类型定义
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { BeflyContext } from "./befly.
|
|
6
|
-
import type { KeyValue } from "./common.
|
|
7
|
-
import type { RequestContext } from "./context.
|
|
8
|
-
import type { TableDefinition } from "./validate.
|
|
5
|
+
import type { BeflyContext } from "./befly.ts";
|
|
6
|
+
import type { KeyValue } from "./common.ts";
|
|
7
|
+
import type { RequestContext } from "./context.ts";
|
|
8
|
+
import type { TableDefinition } from "./validate.ts";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* HTTP 方法类型
|
package/types/befly.d.ts
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Befly 核心框架类型定义
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { CacheHelper } from "../lib/cacheHelper.
|
|
6
|
-
import type { Cipher } from "../lib/cipher.
|
|
7
|
-
import type { DbHelper } from "../lib/dbHelper.
|
|
8
|
-
import type { Jwt } from "../lib/jwt.
|
|
9
|
-
import type { Logger } from "../lib/logger.
|
|
10
|
-
import type { RedisHelper } from "../lib/redisHelper.
|
|
11
|
-
import type { Validator } from "../lib/validator.
|
|
12
|
-
import type { ApiRoute, HttpMethod } from "./api.
|
|
13
|
-
import type { KeyValue } from "./common.
|
|
14
|
-
import type { LoggerConfig } from "./logger.
|
|
15
|
-
import type { Plugin } from "./plugin.
|
|
5
|
+
import type { CacheHelper } from "../lib/cacheHelper.ts";
|
|
6
|
+
import type { Cipher } from "../lib/cipher.ts";
|
|
7
|
+
import type { DbHelper } from "../lib/dbHelper.ts";
|
|
8
|
+
import type { Jwt } from "../lib/jwt.ts";
|
|
9
|
+
import type { Logger } from "../lib/logger.ts";
|
|
10
|
+
import type { RedisHelper } from "../lib/redisHelper.ts";
|
|
11
|
+
import type { Validator } from "../lib/validator.ts";
|
|
12
|
+
import type { ApiRoute, HttpMethod } from "./api.ts";
|
|
13
|
+
import type { KeyValue } from "./common.ts";
|
|
14
|
+
import type { LoggerConfig } from "./logger.ts";
|
|
15
|
+
import type { Plugin } from "./plugin.ts";
|
|
16
16
|
import type { Database } from "bun:sqlite";
|
|
17
17
|
|
|
18
18
|
export type { LoggerConfig };
|
package/types/cache.d.ts
CHANGED
package/types/context.d.ts
CHANGED
package/types/hook.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Befly 钩子系统类型定义
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { BeflyContext } from "./befly.
|
|
6
|
-
import type { RequestContext } from "./context.
|
|
5
|
+
import type { BeflyContext } from "./befly.ts";
|
|
6
|
+
import type { RequestContext } from "./context.ts";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 钩子处理函数类型(串联模式,无 next 参数)
|
package/types/plugin.d.ts
CHANGED
package/utils/cors.ts
CHANGED
package/utils/importDefault.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* - import() 报错:返回 defaultValue
|
|
5
5
|
* - default 导出为 null/undefined:返回 defaultValue
|
|
6
6
|
*/
|
|
7
|
-
import { Logger } from "../lib/logger.
|
|
7
|
+
import { Logger } from "../lib/logger.ts";
|
|
8
8
|
|
|
9
9
|
export async function importDefault<T>(file: string, defaultValue: T): Promise<T> {
|
|
10
10
|
try {
|
package/utils/loadMenuConfigs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MenuConfig } from "../types/sync.
|
|
2
|
-
import type { AddonInfo } from "./scanAddons.
|
|
1
|
+
import type { MenuConfig } from "../types/sync.ts";
|
|
2
|
+
import type { AddonInfo } from "./scanAddons.ts";
|
|
3
3
|
import type { ViewDirMeta } from "befly-shared/utils/scanViewsDir";
|
|
4
4
|
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
@@ -8,8 +8,8 @@ import { readdir, readFile } from "node:fs/promises";
|
|
|
8
8
|
import { cleanDirName, extractDefinePageMetaFromScriptSetup, extractScriptSetupBlock } from "befly-shared/utils/scanViewsDir";
|
|
9
9
|
import { join } from "pathe";
|
|
10
10
|
|
|
11
|
-
import { Logger } from "../lib/logger.
|
|
12
|
-
import { isDirentDirectory } from "./isDirentDirectory.
|
|
11
|
+
import { Logger } from "../lib/logger.ts";
|
|
12
|
+
import { isDirentDirectory } from "./isDirentDirectory.ts";
|
|
13
13
|
|
|
14
14
|
export async function scanViewsDirToMenuConfigs(viewsDir: string, prefix: string, parentPath: string = ""): Promise<MenuConfig[]> {
|
|
15
15
|
if (!existsSync(viewsDir)) {
|
package/utils/processFields.ts
CHANGED
package/utils/response.ts
CHANGED
package/utils/scanAddons.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { existsSync, readdirSync } from "node:fs";
|
|
|
3
3
|
import { camelCase } from "es-toolkit/string";
|
|
4
4
|
import { join, resolve } from "pathe";
|
|
5
5
|
|
|
6
|
-
import { appAddonsDir, appDir } from "../paths.
|
|
7
|
-
import { isDirentDirectory } from "./isDirentDirectory.
|
|
6
|
+
import { appAddonsDir, appDir } from "../paths.ts";
|
|
7
|
+
import { isDirentDirectory } from "./isDirentDirectory.ts";
|
|
8
8
|
|
|
9
9
|
export type AddonSource = "addon" | "app";
|
|
10
10
|
|
package/utils/scanConfig.ts
CHANGED
package/utils/scanFiles.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { forOwn } from "es-toolkit/compat";
|
|
|
4
4
|
import { camelCase } from "es-toolkit/string";
|
|
5
5
|
import { relative, normalize, parse, join } from "pathe";
|
|
6
6
|
|
|
7
|
-
import { importDefault } from "./importDefault.
|
|
7
|
+
import { importDefault } from "./importDefault.ts";
|
|
8
8
|
|
|
9
9
|
export type ScanFileSource = "app" | "addon" | "core";
|
|
10
10
|
|
package/utils/scanSources.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AddonInfo } from "./scanAddons.
|
|
2
|
-
import type { ScanFileResult } from "./scanFiles.
|
|
1
|
+
import type { AddonInfo } from "./scanAddons.ts";
|
|
2
|
+
import type { ScanFileResult } from "./scanFiles.ts";
|
|
3
3
|
|
|
4
4
|
import { join } from "pathe";
|
|
5
5
|
|
|
6
|
-
import { coreDir, appDir } from "../paths.
|
|
7
|
-
import { scanAddons } from "./scanAddons.
|
|
8
|
-
import { scanFiles } from "./scanFiles.
|
|
6
|
+
import { coreDir, appDir } from "../paths.ts";
|
|
7
|
+
import { scanAddons } from "./scanAddons.ts";
|
|
8
|
+
import { scanFiles } from "./scanFiles.ts";
|
|
9
9
|
|
|
10
10
|
export type ScanSourcesResult = {
|
|
11
11
|
hooks: ScanFileResult[];
|
package/utils/sortModules.ts
CHANGED
package/utils/sqlLog.ts
CHANGED