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.
Files changed (65) hide show
  1. package/befly.config.ts +46 -36
  2. package/checks/checkApi.ts +1 -1
  3. package/checks/checkHook.ts +1 -1
  4. package/checks/checkMenu.ts +5 -5
  5. package/checks/checkPlugin.ts +1 -1
  6. package/checks/checkTable.ts +3 -3
  7. package/docs/guide/quickstart.md +7 -7
  8. package/docs/reference/logger.md +4 -4
  9. package/docs/reference/sync.md +14 -14
  10. package/docs/reference/table.md +2 -2
  11. package/docs/reference/validator.md +3 -3
  12. package/hooks/auth.ts +2 -2
  13. package/hooks/cors.ts +3 -3
  14. package/hooks/parser.ts +3 -3
  15. package/hooks/permission.ts +4 -4
  16. package/hooks/validator.ts +3 -3
  17. package/lib/cacheHelper.ts +2 -2
  18. package/lib/cipher.ts +1 -1
  19. package/lib/connect.ts +2 -2
  20. package/lib/dbHelper.ts +13 -13
  21. package/lib/dbUtils.ts +3 -3
  22. package/lib/jwt.ts +2 -2
  23. package/lib/logger.ts +2 -2
  24. package/lib/redisHelper.ts +2 -2
  25. package/lib/sqlBuilder.ts +2 -2
  26. package/lib/validator.ts +2 -2
  27. package/loader/loadApis.ts +4 -4
  28. package/loader/loadHooks.ts +4 -4
  29. package/loader/loadPlugins.ts +5 -5
  30. package/main.ts +27 -27
  31. package/package.json +4 -7
  32. package/plugins/cache.ts +3 -3
  33. package/plugins/cipher.ts +2 -2
  34. package/plugins/config.ts +2 -2
  35. package/plugins/db.ts +6 -6
  36. package/plugins/jwt.ts +3 -3
  37. package/plugins/logger.ts +3 -3
  38. package/plugins/redis.ts +5 -5
  39. package/plugins/tool.ts +2 -2
  40. package/router/api.ts +9 -9
  41. package/router/static.ts +4 -4
  42. package/sync/syncApi.ts +3 -3
  43. package/sync/syncCache.ts +1 -1
  44. package/sync/syncDev.ts +3 -3
  45. package/sync/syncMenu.ts +6 -6
  46. package/sync/syncTable.ts +9 -9
  47. package/tsconfig.json +1 -47
  48. package/types/api.d.ts +4 -4
  49. package/types/befly.d.ts +11 -11
  50. package/types/cache.d.ts +1 -1
  51. package/types/context.d.ts +1 -1
  52. package/types/hook.d.ts +2 -2
  53. package/types/plugin.d.ts +1 -1
  54. package/utils/arrayKeysToCamel.ts +1 -1
  55. package/utils/cors.ts +1 -1
  56. package/utils/importDefault.ts +1 -1
  57. package/utils/loadMenuConfigs.ts +4 -4
  58. package/utils/processFields.ts +1 -1
  59. package/utils/response.ts +2 -2
  60. package/utils/scanAddons.ts +2 -2
  61. package/utils/scanConfig.ts +1 -1
  62. package/utils/scanFiles.ts +1 -1
  63. package/utils/scanSources.ts +5 -5
  64. package/utils/sortModules.ts +1 -1
  65. 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.js";
6
+ import type { BeflyOptions } from "./types/befly.ts";
7
7
 
8
- import { compileDisableMenuGlobRules } from "./utils/disableMenusGlob.js";
9
- import { scanConfig } from "./utils/scanConfig.js";
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
- export type LoadBeflyConfigOptions = {
93
- cwd?: string;
94
- nodeEnv?: string;
95
- };
92
+ const beflyConfigCache: Map<string, Promise<BeflyOptions>> = new Map();
96
93
 
97
- export async function loadBeflyConfig(options: LoadBeflyConfigOptions = {}): Promise<BeflyOptions> {
98
- const nodeEnv = options.nodeEnv || process.env.NODE_ENV || "development";
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
- // 使用 scanConfig 一次性加载并合并所有配置文件
102
- // 合并顺序:defaultOptions befly.common.json ← befly.development/production.json
103
- const config = await scanConfig({
104
- cwd: options.cwd,
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
- // 预编译 disableMenus Bun.Glob 规则:
124
- // - 提前暴露配置错误(fail-fast)
125
- // - 后续 checkMenu 会复用同一进程级缓存
126
- compileDisableMenuGlobRules((config as any)?.disableMenus);
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
- return config as BeflyOptions;
129
- }
126
+ // 预编译 disableMenus 的 Bun.Glob 规则:
127
+ // - 提前暴露配置错误(fail-fast)
128
+ // - 后续 checkMenu 会复用同一进程级缓存
129
+ compileDisableMenuGlobRules((config as any)?.disableMenus);
130
130
 
131
- export const beflyConfig = await loadBeflyConfig();
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
+ }
@@ -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.js";
4
+ import { Logger } from "../lib/logger.ts";
5
5
 
6
6
  export async function checkApi(apis: any[]): Promise<void> {
7
7
  let hasError = false;
@@ -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.js";
4
+ import { Logger } from "../lib/logger.ts";
5
5
 
6
6
  export async function checkHook(hooks: any[]): Promise<void> {
7
7
  let hasError = false;
@@ -1,9 +1,9 @@
1
- import type { MenuConfig } from "../types/sync.js";
2
- import type { AddonInfo } from "../utils/scanAddons.js";
1
+ import type { MenuConfig } from "../types/sync.ts";
2
+ import type { AddonInfo } from "../utils/scanAddons.ts";
3
3
 
4
- import { Logger } from "../lib/logger.js";
5
- import { compileDisableMenuGlobRules, isMenuPathDisabledByGlobRules } from "../utils/disableMenusGlob.js";
6
- import { loadMenuConfigs } from "../utils/loadMenuConfigs.js";
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) {
@@ -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.js";
4
+ import { Logger } from "../lib/logger.ts";
5
5
 
6
6
  export async function checkPlugin(plugins: any[]): Promise<void> {
7
7
  let hasError = false;
@@ -1,7 +1,7 @@
1
- import type { FieldDefinition } from "../types/validate.js";
2
- import type { ScanFileResult } from "../utils/scanFiles.js";
1
+ import type { FieldDefinition } from "../types/validate.ts";
2
+ import type { ScanFileResult } from "../utils/scanFiles.ts";
3
3
 
4
- import { Logger } from "../lib/logger.js";
4
+ import { Logger } from "../lib/logger.ts";
5
5
 
6
6
  /**
7
7
  * 保留字段列表
@@ -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.js";
229
- import { syncApi } from "../sync/syncApi.js";
230
- import { syncMenu } from "../sync/syncMenu.js";
231
- import { syncDev } from "../sync/syncDev.js";
232
- import { syncCache } from "../sync/syncCache.js";
233
- import { checkMenu } from "../checks/checkMenu.js";
234
- import { scanSources } from "../utils/scanSources.js";
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();
@@ -87,7 +87,7 @@ interface LoggerConfig {
87
87
  ### 导入 Logger
88
88
 
89
89
  ```typescript
90
- import { Logger } from "../lib/logger.js";
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.js";
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.js";
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.js";
334
+ import { Logger, setMockLogger } from "../lib/logger.ts";
335
335
  import pino from "pino";
336
336
 
337
337
  describe("Logger", () => {
@@ -53,8 +53,8 @@ Sync 同步系统用于将代码定义同步到数据库,包括:
53
53
  默认会在服务启动时自动执行(仅主进程)。如需在代码中手动执行:
54
54
 
55
55
  ```typescript
56
- import { syncTable } from "../sync/syncTable.js";
57
- import { scanSources } from "../utils/scanSources.js";
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.js";
124
- import { scanSources } from "../utils/scanSources.js";
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.js";
189
- import { syncMenu } from "../sync/syncMenu.js";
190
- import { scanSources } from "../utils/scanSources.js";
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.js";
337
- import { syncApi } from "./sync/syncApi.js";
338
- import { syncCache } from "./sync/syncCache.js";
339
- import { syncDev } from "./sync/syncDev.js";
340
- import { syncMenu } from "./sync/syncMenu.js";
341
- import { scanSources } from "./utils/scanSources.js";
342
- import { checkMenu } from "./checks/checkMenu.js";
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)
@@ -517,8 +517,8 @@ interface FieldDefinition {
517
517
  如需在代码中手动触发:
518
518
 
519
519
  ```typescript
520
- import { syncTable } from "../../sync/syncTable.js";
521
- import { scanSources } from "../../utils/scanSources.js";
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.js";
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.js";
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.js";
384
+ import { Fields } from "../../../config/fields.ts";
385
385
 
386
386
  export default {
387
387
  name: "获取列表",
package/hooks/auth.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { Hook } from "../types/hook.js";
1
+ import type { Hook } from "../types/hook.ts";
2
2
 
3
- import { setCtxUser } from "../lib/asyncContext.js";
3
+ import { setCtxUser } from "../lib/asyncContext.ts";
4
4
 
5
5
  export default {
6
6
  deps: ["cors"],
package/hooks/cors.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { CorsConfig } from "../types/befly.js";
1
+ import type { CorsConfig } from "../types/befly.ts";
2
2
  // 类型导入
3
- import type { Hook } from "../types/hook.js";
3
+ import type { Hook } from "../types/hook.ts";
4
4
 
5
5
  // 相对导入
6
- import { setCorsOptions } from "../utils/cors.js";
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.js";
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.js";
10
- import { ErrorResponse } from "../utils/response.js";
9
+ import { pickFields } from "../utils/pickFields.ts";
10
+ import { ErrorResponse } from "../utils/response.ts";
11
11
 
12
12
  const xmlParser = new XMLParser();
13
13
 
@@ -1,10 +1,10 @@
1
1
  // 类型导入
2
- import type { Hook } from "../types/hook.js";
2
+ import type { Hook } from "../types/hook.ts";
3
3
 
4
- import { CacheKeys } from "../lib/cacheKeys.js";
5
- import { Logger } from "../lib/logger.js";
4
+ import { CacheKeys } from "../lib/cacheKeys.ts";
5
+ import { Logger } from "../lib/logger.ts";
6
6
  // 相对导入
7
- import { ErrorResponse } from "../utils/response.js";
7
+ import { ErrorResponse } from "../utils/response.ts";
8
8
 
9
9
  /**
10
10
  * 权限检查钩子
@@ -1,9 +1,9 @@
1
1
  // 类型导入
2
- import type { Hook } from "../types/hook.js";
2
+ import type { Hook } from "../types/hook.ts";
3
3
 
4
4
  // 相对导入
5
- import { Validator } from "../lib/validator.js";
6
- import { ErrorResponse } from "../utils/response.js";
5
+ import { Validator } from "../lib/validator.ts";
6
+ import { ErrorResponse } from "../utils/response.ts";
7
7
 
8
8
  /**
9
9
  * 参数验证钩子
@@ -3,8 +3,8 @@
3
3
  * 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
4
4
  */
5
5
 
6
- import { CacheKeys } from "./cacheKeys.js";
7
- import { Logger } from "./logger.js";
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
@@ -3,7 +3,7 @@
3
3
  * 提供各种哈希、HMAC、密码加密等功能
4
4
  */
5
5
 
6
- import type { EncodingType, HashAlgorithm, PasswordHashOptions } from "../types/crypto.js";
6
+ import type { EncodingType, HashAlgorithm, PasswordHashOptions } from "../types/crypto.ts";
7
7
 
8
8
  import { createSign } from "node:crypto";
9
9
 
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.js";
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.js";
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.js";
7
- import type { QueryOptions, InsertOptions, UpdateOptions, DeleteOptions, ListResult, AllResult, TransactionCallback, DbResult, SqlInfo, ListSql } from "../types/database.js";
8
- import type { DbDialect } from "./dbDialect.js";
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.js";
13
- import { convertBigIntFields } from "../utils/convertBigIntFields.js";
14
- import { fieldClear } from "../utils/fieldClear.js";
15
- import { keysToCamel } from "../utils/keysToCamel.js";
16
- import { CacheKeys } from "./cacheKeys.js";
17
- import { MySqlDialect } from "./dbDialect.js";
18
- import { DbUtils } from "./dbUtils.js";
19
- import { Logger } from "./logger.js";
20
- import { SqlBuilder } from "./sqlBuilder.js";
21
- import { SqlCheck } from "./sqlCheck.js";
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.js";
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.js";
6
- import { keysToSnake } from "../utils/keysToSnake.js";
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.js";
6
- import type { JwtPayload, JwtSignOptions, JwtVerifyOptions, JwtDecoded, JwtHeader } from "../types/jwt.js";
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.js";
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.js";
16
+ import { getCtx } from "./asyncContext.ts";
17
17
 
18
18
  // 注意:Logger 可能在运行时/测试中被 process.chdir() 影响。
19
19
  // 为避免相对路径的 logs 目录随着 cwd 变化,使用模块加载时的初始 cwd 作为锚点。
@@ -5,8 +5,8 @@
5
5
 
6
6
  import { RedisClient } from "bun";
7
7
 
8
- import { Connect } from "./connect.js";
9
- import { Logger } from "./logger.js";
8
+ import { Connect } from "./connect.ts";
9
+ import { Logger } from "./logger.ts";
10
10
 
11
11
  /**
12
12
  * Redis 助手类
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.js";
6
+ import type { WhereConditions, WhereOperator, OrderDirection, SqlQuery, InsertData, UpdateData, SqlValue } from "../types/common.ts";
7
7
 
8
- import { SqlCheck } from "./sqlCheck.js";
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.js";
6
+ import type { TableDefinition, FieldDefinition, ValidateResult, SingleResult } from "../types/validate.ts";
7
7
 
8
- import { RegexAliases, getCompiledRegex } from "../configs/presetRegexp.js";
8
+ import { RegexAliases, getCompiledRegex } from "../configs/presetRegexp.ts";
9
9
 
10
10
  /**
11
11
  * 验证器类
@@ -4,11 +4,11 @@
4
4
  */
5
5
 
6
6
  // 类型导入
7
- import type { ApiRoute } from "../types/api.js";
8
- import type { ScanFileResult } from "../utils/scanFiles.js";
7
+ import type { ApiRoute } from "../types/api.ts";
8
+ import type { ScanFileResult } from "../utils/scanFiles.ts";
9
9
 
10
- import { Logger } from "../lib/logger.js";
11
- import { processFields } from "../utils/processFields.js";
10
+ import { Logger } from "../lib/logger.ts";
11
+ import { processFields } from "../utils/processFields.ts";
12
12
 
13
13
  /**
14
14
  * 加载所有 API 路由
@@ -5,11 +5,11 @@
5
5
  */
6
6
 
7
7
  // 类型导入
8
- import type { Hook } from "../types/hook.js";
9
- import type { ScanFileResult } from "../utils/scanFiles.js";
8
+ import type { Hook } from "../types/hook.ts";
9
+ import type { ScanFileResult } from "../utils/scanFiles.ts";
10
10
 
11
- import { Logger } from "../lib/logger.js";
12
- import { sortModules } from "../utils/sortModules.js";
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[] = [];
@@ -3,12 +3,12 @@
3
3
  * 负责扫描和初始化所有插件(核心、组件、项目)
4
4
  */
5
5
 
6
- import type { BeflyContext } from "../types/befly.js";
7
- import type { Plugin } from "../types/plugin.js";
8
- import type { ScanFileResult } from "../utils/scanFiles.js";
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.js";
11
- import { sortModules } from "../utils/sortModules.js";
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[] = [];