befly 3.16.9 → 3.16.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +0 -129
  2. package/befly.js +12769 -0
  3. package/befly.min.js +47 -0
  4. package/package.json +18 -29
  5. package/dist/befly.config.d.ts +0 -7
  6. package/dist/befly.config.js +0 -128
  7. package/dist/befly.js +0 -17276
  8. package/dist/befly.min.js +0 -23
  9. package/dist/checks/checkApi.d.ts +0 -1
  10. package/dist/checks/checkApi.js +0 -124
  11. package/dist/checks/checkConfig.d.ts +0 -9
  12. package/dist/checks/checkConfig.js +0 -255
  13. package/dist/checks/checkHook.d.ts +0 -1
  14. package/dist/checks/checkHook.js +0 -132
  15. package/dist/checks/checkMenu.d.ts +0 -3
  16. package/dist/checks/checkMenu.js +0 -106
  17. package/dist/checks/checkPlugin.d.ts +0 -1
  18. package/dist/checks/checkPlugin.js +0 -132
  19. package/dist/checks/checkTable.d.ts +0 -7
  20. package/dist/checks/checkTable.js +0 -431
  21. package/dist/configs/presetRegexp.d.ts +0 -145
  22. package/dist/configs/presetRegexp.js +0 -218
  23. package/dist/hooks/auth.d.ts +0 -3
  24. package/dist/hooks/auth.js +0 -24
  25. package/dist/hooks/cors.d.ts +0 -7
  26. package/dist/hooks/cors.js +0 -36
  27. package/dist/hooks/parser.d.ts +0 -10
  28. package/dist/hooks/parser.js +0 -76
  29. package/dist/hooks/permission.d.ts +0 -10
  30. package/dist/hooks/permission.js +0 -64
  31. package/dist/hooks/validator.d.ts +0 -7
  32. package/dist/hooks/validator.js +0 -52
  33. package/dist/index.d.ts +0 -28
  34. package/dist/index.js +0 -316
  35. package/dist/lib/asyncContext.d.ts +0 -21
  36. package/dist/lib/asyncContext.js +0 -27
  37. package/dist/lib/cacheHelper.d.ts +0 -128
  38. package/dist/lib/cacheHelper.js +0 -477
  39. package/dist/lib/cacheKeys.d.ts +0 -27
  40. package/dist/lib/cacheKeys.js +0 -37
  41. package/dist/lib/cipher.d.ts +0 -153
  42. package/dist/lib/cipher.js +0 -237
  43. package/dist/lib/connect.d.ts +0 -95
  44. package/dist/lib/connect.js +0 -313
  45. package/dist/lib/dbHelper.d.ts +0 -229
  46. package/dist/lib/dbHelper.js +0 -1069
  47. package/dist/lib/dbUtils.d.ts +0 -91
  48. package/dist/lib/dbUtils.js +0 -544
  49. package/dist/lib/jwt.d.ts +0 -13
  50. package/dist/lib/jwt.js +0 -77
  51. package/dist/lib/logger.d.ts +0 -46
  52. package/dist/lib/logger.js +0 -731
  53. package/dist/lib/redisHelper.d.ts +0 -193
  54. package/dist/lib/redisHelper.js +0 -598
  55. package/dist/lib/sqlBuilder.d.ts +0 -160
  56. package/dist/lib/sqlBuilder.js +0 -837
  57. package/dist/lib/sqlCheck.d.ts +0 -23
  58. package/dist/lib/sqlCheck.js +0 -119
  59. package/dist/lib/validator.d.ts +0 -45
  60. package/dist/lib/validator.js +0 -424
  61. package/dist/loader/loadApis.d.ts +0 -12
  62. package/dist/loader/loadApis.js +0 -71
  63. package/dist/loader/loadHooks.d.ts +0 -7
  64. package/dist/loader/loadHooks.js +0 -50
  65. package/dist/loader/loadPlugins.d.ts +0 -8
  66. package/dist/loader/loadPlugins.js +0 -69
  67. package/dist/paths.d.ts +0 -93
  68. package/dist/paths.js +0 -100
  69. package/dist/plugins/cache.d.ts +0 -10
  70. package/dist/plugins/cache.js +0 -24
  71. package/dist/plugins/cipher.d.ts +0 -7
  72. package/dist/plugins/cipher.js +0 -14
  73. package/dist/plugins/config.d.ts +0 -3
  74. package/dist/plugins/config.js +0 -9
  75. package/dist/plugins/db.d.ts +0 -10
  76. package/dist/plugins/db.js +0 -48
  77. package/dist/plugins/jwt.d.ts +0 -6
  78. package/dist/plugins/jwt.js +0 -13
  79. package/dist/plugins/logger.d.ts +0 -10
  80. package/dist/plugins/logger.js +0 -21
  81. package/dist/plugins/redis.d.ts +0 -10
  82. package/dist/plugins/redis.js +0 -40
  83. package/dist/plugins/tool.d.ts +0 -75
  84. package/dist/plugins/tool.js +0 -105
  85. package/dist/router/api.d.ts +0 -14
  86. package/dist/router/api.js +0 -109
  87. package/dist/router/static.d.ts +0 -9
  88. package/dist/router/static.js +0 -56
  89. package/dist/scripts/ensureDist.d.ts +0 -1
  90. package/dist/scripts/ensureDist.js +0 -296
  91. package/dist/sync/syncApi.d.ts +0 -3
  92. package/dist/sync/syncApi.js +0 -140
  93. package/dist/sync/syncCache.d.ts +0 -2
  94. package/dist/sync/syncCache.js +0 -14
  95. package/dist/sync/syncDev.d.ts +0 -6
  96. package/dist/sync/syncDev.js +0 -166
  97. package/dist/sync/syncMenu.d.ts +0 -14
  98. package/dist/sync/syncMenu.js +0 -308
  99. package/dist/sync/syncTable.d.ts +0 -126
  100. package/dist/sync/syncTable.js +0 -1129
  101. package/dist/types/api.d.ts +0 -175
  102. package/dist/types/api.js +0 -4
  103. package/dist/types/befly.d.ts +0 -231
  104. package/dist/types/befly.js +0 -4
  105. package/dist/types/cache.d.ts +0 -96
  106. package/dist/types/cache.js +0 -4
  107. package/dist/types/cipher.d.ts +0 -27
  108. package/dist/types/cipher.js +0 -7
  109. package/dist/types/common.d.ts +0 -127
  110. package/dist/types/common.js +0 -5
  111. package/dist/types/context.d.ts +0 -39
  112. package/dist/types/context.js +0 -4
  113. package/dist/types/coreError.d.ts +0 -31
  114. package/dist/types/coreError.js +0 -38
  115. package/dist/types/crypto.d.ts +0 -20
  116. package/dist/types/crypto.js +0 -4
  117. package/dist/types/database.d.ts +0 -182
  118. package/dist/types/database.js +0 -4
  119. package/dist/types/hook.d.ts +0 -30
  120. package/dist/types/hook.js +0 -19
  121. package/dist/types/jwt.d.ts +0 -76
  122. package/dist/types/jwt.js +0 -4
  123. package/dist/types/logger.d.ts +0 -95
  124. package/dist/types/logger.js +0 -6
  125. package/dist/types/plugin.d.ts +0 -27
  126. package/dist/types/plugin.js +0 -17
  127. package/dist/types/redis.d.ts +0 -80
  128. package/dist/types/redis.js +0 -4
  129. package/dist/types/roleApisCache.d.ts +0 -21
  130. package/dist/types/roleApisCache.js +0 -8
  131. package/dist/types/sync.d.ts +0 -93
  132. package/dist/types/sync.js +0 -4
  133. package/dist/types/table.d.ts +0 -34
  134. package/dist/types/table.js +0 -4
  135. package/dist/types/validate.d.ts +0 -113
  136. package/dist/types/validate.js +0 -4
  137. package/dist/utils/calcPerfTime.d.ts +0 -4
  138. package/dist/utils/calcPerfTime.js +0 -13
  139. package/dist/utils/cors.d.ts +0 -8
  140. package/dist/utils/cors.js +0 -17
  141. package/dist/utils/dbFieldRules.d.ts +0 -31
  142. package/dist/utils/dbFieldRules.js +0 -94
  143. package/dist/utils/fieldClear.d.ts +0 -11
  144. package/dist/utils/fieldClear.js +0 -57
  145. package/dist/utils/formatYmdHms.d.ts +0 -1
  146. package/dist/utils/formatYmdHms.js +0 -20
  147. package/dist/utils/getClientIp.d.ts +0 -6
  148. package/dist/utils/getClientIp.js +0 -39
  149. package/dist/utils/importDefault.d.ts +0 -1
  150. package/dist/utils/importDefault.js +0 -53
  151. package/dist/utils/isDirentDirectory.d.ts +0 -3
  152. package/dist/utils/isDirentDirectory.js +0 -18
  153. package/dist/utils/loadMenuConfigs.d.ts +0 -11
  154. package/dist/utils/loadMenuConfigs.js +0 -130
  155. package/dist/utils/loggerUtils.d.ts +0 -18
  156. package/dist/utils/loggerUtils.js +0 -171
  157. package/dist/utils/mergeAndConcat.d.ts +0 -7
  158. package/dist/utils/mergeAndConcat.js +0 -77
  159. package/dist/utils/normalizeFieldDefinition.d.ts +0 -18
  160. package/dist/utils/normalizeFieldDefinition.js +0 -27
  161. package/dist/utils/processInfo.d.ts +0 -26
  162. package/dist/utils/processInfo.js +0 -41
  163. package/dist/utils/response.d.ts +0 -20
  164. package/dist/utils/response.js +0 -96
  165. package/dist/utils/scanAddons.d.ts +0 -15
  166. package/dist/utils/scanAddons.js +0 -35
  167. package/dist/utils/scanCoreBuiltins.d.ts +0 -3
  168. package/dist/utils/scanCoreBuiltins.js +0 -72
  169. package/dist/utils/scanFiles.d.ts +0 -32
  170. package/dist/utils/scanFiles.js +0 -124
  171. package/dist/utils/scanSources.d.ts +0 -10
  172. package/dist/utils/scanSources.js +0 -46
  173. package/dist/utils/sortModules.d.ts +0 -28
  174. package/dist/utils/sortModules.js +0 -105
  175. package/dist/utils/sqlUtil.d.ts +0 -33
  176. package/dist/utils/sqlUtil.js +0 -146
  177. package/dist/utils/util.d.ts +0 -172
  178. package/dist/utils/util.js +0 -517
@@ -1,39 +0,0 @@
1
- /**
2
- * 请求上下文类型定义
3
- */
4
- import type { ApiRoute } from "./api";
5
- import type { JsonValue } from "./common";
6
- import type { JwtPayload } from "./jwt";
7
- export type RequestUser = Partial<JwtPayload>;
8
- export type RequestResult = Response | JsonValue;
9
- /**
10
- * 请求上下文接口
11
- */
12
- export interface RequestContext<TBody = Record<string, JsonValue>> {
13
- /** 请求方法 (GET/POST) */
14
- method: string;
15
- /** 请求体参数 */
16
- body: TBody;
17
- /** 用户信息 */
18
- user: RequestUser;
19
- /** 原始请求对象 */
20
- req: Request;
21
- /** 请求开始时间(毫秒) */
22
- now: number;
23
- /** 客户端 IP 地址 */
24
- ip: string;
25
- /** 请求头 */
26
- headers: Headers;
27
- /** API 路由路径(url.pathname,例如 /api/user/login;与 method 无关) */
28
- route: string;
29
- /** 请求唯一 ID */
30
- requestId: string;
31
- /** CORS 响应头 */
32
- corsHeaders: Record<string, string>;
33
- /** 当前请求的 API 路由对象 */
34
- api?: ApiRoute;
35
- /** 响应对象(如果设置了此属性,将直接返回该响应) */
36
- response?: Response;
37
- /** 原始处理结果(未转换为 Response 对象前) */
38
- result?: RequestResult;
39
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * 请求上下文类型定义
3
- */
4
- export {};
@@ -1,31 +0,0 @@
1
- export type CoreErrorKind = "validation" | "policy" | "runtime";
2
- export type CoreErrorOptions = {
3
- message: string;
4
- kind: CoreErrorKind;
5
- code?: string;
6
- meta?: Record<string, unknown>;
7
- noLog?: boolean;
8
- logged?: boolean;
9
- /** 若为 true:入口可选择把 message 原样按行输出到控制台(更适合肉眼阅读)。 */
10
- multiline?: boolean;
11
- cause?: unknown;
12
- };
13
- /**
14
- * CoreError:用于 core 内部统一传递“错误类型/策略/元信息”。
15
- *
16
- * 设计目标:
17
- * - 让入口(index.ts)能稳定决策:是否打印、打印多详细、是否避免重复日志。
18
- * - 不强制所有模块都必须使用(可渐进迁移)。
19
- */
20
- export declare class CoreError extends Error {
21
- kind: CoreErrorKind;
22
- code: string | null;
23
- meta: Record<string, unknown> | null;
24
- noLog: boolean;
25
- logged: boolean;
26
- /** 若为 true:入口可选择把 message 原样按行输出到控制台(更适合肉眼阅读)。 */
27
- multiline: boolean;
28
- cause: unknown;
29
- constructor(options: CoreErrorOptions);
30
- }
31
- export declare function isCoreError(error: unknown): error is CoreError;
@@ -1,38 +0,0 @@
1
- /**
2
- * CoreError:用于 core 内部统一传递“错误类型/策略/元信息”。
3
- *
4
- * 设计目标:
5
- * - 让入口(index.ts)能稳定决策:是否打印、打印多详细、是否避免重复日志。
6
- * - 不强制所有模块都必须使用(可渐进迁移)。
7
- */
8
- export class CoreError extends Error {
9
- kind;
10
- code;
11
- meta;
12
- noLog;
13
- logged;
14
- /** 若为 true:入口可选择把 message 原样按行输出到控制台(更适合肉眼阅读)。 */
15
- multiline;
16
- cause;
17
- constructor(options) {
18
- super(options.message);
19
- this.name = "CoreError";
20
- this.kind = options.kind;
21
- this.code = typeof options.code === "string" && options.code.length > 0 ? options.code : null;
22
- this.meta = options.meta ? options.meta : null;
23
- this.noLog = options.noLog === true;
24
- this.logged = options.logged === true;
25
- this.multiline = options.multiline === true;
26
- this.cause = options.cause;
27
- }
28
- }
29
- export function isCoreError(error) {
30
- if (typeof error !== "object" || error === null)
31
- return false;
32
- const anyErr = error;
33
- if (anyErr.name !== "CoreError")
34
- return false;
35
- if (typeof anyErr.kind !== "string")
36
- return false;
37
- return true;
38
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * 加密相关类型定义
3
- */
4
- /**
5
- * 编码类型
6
- */
7
- export type EncodingType = "hex" | "base64" | "base64url";
8
- /**
9
- * 哈希算法类型
10
- */
11
- export type HashAlgorithm = "md5" | "sha1" | "sha256" | "sha512" | "sha384" | "sha224";
12
- /**
13
- * 密码哈希选项
14
- */
15
- export interface PasswordHashOptions {
16
- algorithm?: "argon2" | "bcrypt";
17
- memoryCost?: number;
18
- timeCost?: number;
19
- [key: string]: any;
20
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * 加密相关类型定义
3
- */
4
- export {};
@@ -1,182 +0,0 @@
1
- /**
2
- * 数据库操作相关类型定义
3
- */
4
- import type { JoinOption, SqlValue, WhereConditions } from "./common";
5
- /**
6
- * 表名到行类型的映射(项目侧可通过 declaration merging 扩展)。
7
- *
8
- * 用法(项目侧):
9
- * declare module "befly/types/database" {
10
- * interface DbRowMap {
11
- * user: { id: number; nickname?: string };
12
- * }
13
- * }
14
- */
15
- export interface DbRowMap {
16
- }
17
- export type DbTableName = keyof DbRowMap & string;
18
- /**
19
- * 数据库类型
20
- */
21
- export type DatabaseType = "mysql";
22
- /**
23
- * 查询选项
24
- */
25
- export interface QueryOptions {
26
- /** 表名 */
27
- table: string;
28
- /** 查询字段 */
29
- fields?: string[];
30
- /**
31
- * BIGINT 字段白名单:在查询结果反序列化后,会将这些字段传入 convertBigIntFields 做 bigint/string → number 的安全转换。
32
- *
33
- * 说明:该白名单会与内置默认(id/pid/sort)合并。
34
- */
35
- bigint?: readonly string[];
36
- /** 查询条件 */
37
- where?: WhereConditions;
38
- /** 多表联查选项 */
39
- joins?: JoinOption[];
40
- /** 排序 */
41
- orderBy?: string[];
42
- /** 页码(从 1 开始) */
43
- page?: number;
44
- /** 每页数量 */
45
- limit?: number;
46
- }
47
- /**
48
- * 插入选项
49
- */
50
- export interface InsertOptions {
51
- /** 表名 */
52
- table: string;
53
- /** 插入数据 */
54
- data: Record<string, SqlValue>;
55
- /** 是否返回插入 ID */
56
- returnId?: boolean;
57
- }
58
- /**
59
- * 更新选项
60
- */
61
- export interface UpdateOptions {
62
- /** 表名 */
63
- table: string;
64
- /** 更新数据 */
65
- data: Record<string, SqlValue>;
66
- /** 更新条件 */
67
- where: WhereConditions;
68
- }
69
- /**
70
- * 删除选项
71
- */
72
- export interface DeleteOptions {
73
- /** 表名 */
74
- table: string;
75
- /** 删除条件 */
76
- where: WhereConditions;
77
- /** 是否物理删除(默认逻辑删除) */
78
- hard?: boolean;
79
- }
80
- /**
81
- * SQL 执行信息
82
- */
83
- export interface SqlInfo {
84
- sql: string;
85
- params: SqlValue[];
86
- duration: number;
87
- }
88
- /**
89
- * getList/getAll 的 SQL 信息(count/data 两段)
90
- */
91
- export interface ListSql {
92
- count: SqlInfo;
93
- data?: SqlInfo;
94
- }
95
- /**
96
- * 统一返回结构
97
- */
98
- export type DbUnknownRow = Record<string, SqlValue>;
99
- export type DbResult<TData = DbUnknownRow, TSql = SqlInfo> = {
100
- data: TData;
101
- sql: TSql;
102
- };
103
- /**
104
- * 分页结果
105
- */
106
- export interface DbPageResult<TItem = DbUnknownRow> {
107
- lists: TItem[];
108
- total: number;
109
- page: number;
110
- limit: number;
111
- pages: number;
112
- }
113
- /**
114
- * 不分页结果(带 total)
115
- */
116
- export interface DbListResult<TItem = DbUnknownRow> {
117
- lists: TItem[];
118
- total: number;
119
- }
120
- /**
121
- * 事务回调
122
- */
123
- export type TransactionCallback<TResult = void, TDb = DbHelper> = (db: TDb) => Promise<TResult>;
124
- /**
125
- * DbHelper 公开接口(类型层)。
126
- *
127
- * 说明:runtime 的实现位于 core 内部(dist/lib),但对外类型应只从 `befly/types/*` 获取。
128
- * 这里提供一个与实际实现对齐的接口,用于 BeflyContext.db 的类型标注。
129
- */
130
- export interface DbHelper {
131
- tableExists(tableName: string): Promise<DbResult<boolean>>;
132
- getCount<TTable extends DbTableName>(options: Omit<QueryOptions, "fields" | "page" | "limit" | "orderBy" | "table"> & {
133
- table: TTable;
134
- }): Promise<DbResult<number>>;
135
- getCount(options: Omit<QueryOptions, "fields" | "page" | "limit" | "orderBy">): Promise<DbResult<number>>;
136
- getOne<TTable extends DbTableName>(options: Omit<QueryOptions, "table"> & {
137
- table: TTable;
138
- }): Promise<DbResult<DbRowMap[TTable]>>;
139
- getOne<TItem = DbUnknownRow>(options: QueryOptions): Promise<DbResult<TItem>>;
140
- getDetail<TTable extends DbTableName>(options: Omit<QueryOptions, "table"> & {
141
- table: TTable;
142
- }): Promise<DbResult<DbRowMap[TTable]>>;
143
- getDetail<TItem = DbUnknownRow>(options: QueryOptions): Promise<DbResult<TItem>>;
144
- getList<TTable extends DbTableName>(options: Omit<QueryOptions, "table"> & {
145
- table: TTable;
146
- }): Promise<DbResult<DbPageResult<DbRowMap[TTable]>, ListSql>>;
147
- getList<TItem = DbUnknownRow>(options: QueryOptions): Promise<DbResult<DbPageResult<TItem>, ListSql>>;
148
- getAll<TTable extends DbTableName>(options: Omit<QueryOptions, "table" | "page" | "limit"> & {
149
- table: TTable;
150
- }): Promise<DbResult<DbListResult<DbRowMap[TTable]>, ListSql>>;
151
- getAll<TItem = DbUnknownRow>(options: Omit<QueryOptions, "page" | "limit">): Promise<DbResult<DbListResult<TItem>, ListSql>>;
152
- exists<TTable extends DbTableName>(options: Omit<QueryOptions, "fields" | "orderBy" | "page" | "limit" | "table"> & {
153
- table: TTable;
154
- }): Promise<DbResult<boolean>>;
155
- exists(options: Omit<QueryOptions, "fields" | "orderBy" | "page" | "limit">): Promise<DbResult<boolean>>;
156
- getFieldValue<TTable extends DbTableName, TField extends keyof DbRowMap[TTable] & string>(options: Omit<QueryOptions, "fields" | "table"> & {
157
- table: TTable;
158
- field: TField;
159
- }): Promise<DbResult<DbRowMap[TTable][TField] | null>>;
160
- getFieldValue<TValue = SqlValue>(options: Omit<QueryOptions, "fields"> & {
161
- field: string;
162
- }): Promise<DbResult<TValue | null>>;
163
- insData<TInsert extends Record<string, SqlValue> = Record<string, SqlValue>>(options: Omit<InsertOptions, "data"> & {
164
- data: TInsert;
165
- }): Promise<DbResult<number>>;
166
- insBatch<TInsert extends Record<string, SqlValue> = Record<string, SqlValue>>(table: string, dataList: TInsert[]): Promise<DbResult<number[]>>;
167
- updData(options: UpdateOptions): Promise<DbResult<number>>;
168
- updBatch(table: string, dataList: Array<{
169
- id: number;
170
- data: Record<string, SqlValue>;
171
- }>): Promise<DbResult<number>>;
172
- delData(options: DeleteOptions): Promise<DbResult<number>>;
173
- delForce(options: Omit<DeleteOptions, "hard">): Promise<DbResult<number>>;
174
- delForceBatch(table: string, ids: number[]): Promise<DbResult<number>>;
175
- enableData(options: Omit<DeleteOptions, "hard">): Promise<DbResult<number>>;
176
- disableData(options: Omit<DeleteOptions, "hard">): Promise<DbResult<number>>;
177
- query<TResult = DbUnknownRow[]>(sql: string, params?: SqlValue[]): Promise<DbResult<TResult>>;
178
- unsafe<TResult = DbUnknownRow[]>(sqlStr: string, params?: SqlValue[]): Promise<DbResult<TResult>>;
179
- trans<TResult = void>(callback: TransactionCallback<TResult, DbHelper>): Promise<TResult>;
180
- increment(table: string, field: string, where: WhereConditions, value?: number): Promise<DbResult<number>>;
181
- decrement(table: string, field: string, where: WhereConditions, value?: number): Promise<DbResult<number>>;
182
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * 数据库操作相关类型定义
3
- */
4
- export {};
@@ -1,30 +0,0 @@
1
- /**
2
- * Hook 类型定义
3
- *
4
- * 说明:当前 core 的 hook 执行模型是“顺序执行 handler(befly, ctx)”,无 next / 洋葱链。
5
- *
6
- * 说明:当前 core hook 推荐的默认导出写法(避免声明文件深推导导致的类型问题):
7
- *
8
- * const xxxHook: Hook = {
9
- * name: "xxx",
10
- * enable: true,
11
- * deps: [],
12
- * handler: async (befly, ctx) => {
13
- * // ...
14
- * }
15
- * };
16
- *
17
- * export default xxxHook;
18
- */
19
- import type { BeflyContext } from "./befly";
20
- import type { RequestContext } from "./context";
21
- export interface Hook {
22
- /** 运行时由 loader 注入(默认导出对象中通常不需要写) */
23
- name?: string;
24
- /** 是否启用该 Hook;必填(true/false) */
25
- enable: boolean;
26
- /** 依赖的 hook(按文件名推导的 hookName),用于排序 */
27
- deps?: string[];
28
- /** hook 处理函数 */
29
- handler: (befly: BeflyContext, ctx: RequestContext) => Promise<void> | void;
30
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Hook 类型定义
3
- *
4
- * 说明:当前 core 的 hook 执行模型是“顺序执行 handler(befly, ctx)”,无 next / 洋葱链。
5
- *
6
- * 说明:当前 core hook 推荐的默认导出写法(避免声明文件深推导导致的类型问题):
7
- *
8
- * const xxxHook: Hook = {
9
- * name: "xxx",
10
- * enable: true,
11
- * deps: [],
12
- * handler: async (befly, ctx) => {
13
- * // ...
14
- * }
15
- * };
16
- *
17
- * export default xxxHook;
18
- */
19
- export {};
@@ -1,76 +0,0 @@
1
- /**
2
- * JWT 相关类型定义
3
- */
4
- import type { JsonValue } from "./common";
5
- /**
6
- * JWT Payload 类型
7
- */
8
- export interface JwtPayload {
9
- /** 用户 ID */
10
- id: number;
11
- /** 角色代码 */
12
- roleCode: string;
13
- /** 角色类型 */
14
- roleType: string;
15
- /** 用户昵称 */
16
- nickname: string;
17
- /** 过期时间戳 */
18
- exp?: number;
19
- /** 签发时间 */
20
- iat?: number;
21
- /** 其他字段 */
22
- [key: string]: JsonValue | undefined;
23
- }
24
- /**
25
- * JWT header(最常用字段)
26
- */
27
- export interface JwtHeader {
28
- alg?: string;
29
- typ?: string;
30
- kid?: string;
31
- [key: string]: JsonValue | undefined;
32
- }
33
- /**
34
- * sign() 选项(映射 fast-jwt 的 signer 参数)
35
- */
36
- export interface JwtSignOptions {
37
- secret?: string;
38
- expiresIn?: string | number;
39
- algorithm?: string;
40
- issuer?: string;
41
- audience?: string | string[];
42
- subject?: string;
43
- jwtId?: string;
44
- notBefore?: number | string;
45
- }
46
- /**
47
- * verify() 选项(映射 fast-jwt 的 verifier 参数)
48
- */
49
- export interface JwtVerifyOptions {
50
- secret?: string;
51
- algorithms?: string[];
52
- issuer?: string | string[];
53
- audience?: string | string[];
54
- subject?: string | string[];
55
- ignoreExpiration?: boolean;
56
- ignoreNotBefore?: boolean;
57
- }
58
- /**
59
- * decode(complete=true) 返回
60
- */
61
- export interface JwtDecoded {
62
- header: JwtHeader;
63
- payload: JwtPayload;
64
- signature: string;
65
- }
66
- /**
67
- * Jwt 实例接口(类型层)。
68
- *
69
- * runtime 实现位于 core 内部,但对外类型应从 `befly/types/*` 获取。
70
- */
71
- export interface Jwt {
72
- sign(payload: JwtPayload, options?: JwtSignOptions): string;
73
- verify<T = JwtPayload>(token: string, options?: JwtVerifyOptions): T;
74
- decode(token: string, complete?: false): JwtPayload;
75
- decode(token: string, complete: true): JwtDecoded;
76
- }
package/dist/types/jwt.js DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * JWT 相关类型定义
3
- */
4
- export {};
@@ -1,95 +0,0 @@
1
- /**
2
- * 日志相关类型定义
3
- *
4
- * 说明:这里的类型需要与 core/runtime 的 logger 实现保持一致(大量配置项以 0/1 表示开关)。
5
- */
6
- import type { JsonValue } from "./common";
7
- export type LoggerFlag = 0 | 1;
8
- export type LoggerWriteOptions = {
9
- truncate?: boolean;
10
- /** 是否输出到控制台;默认遵循 LoggerConfig.console。 */
11
- console?: boolean;
12
- };
13
- /**
14
- * Logger 插件配置
15
- */
16
- export interface LoggerConfig {
17
- /** 是否开启 debug 输出(0/1) */
18
- debug?: LoggerFlag;
19
- /** 日志目录(相对路径会以初始化 cwd 为锚点解析) */
20
- dir?: string;
21
- /** 是否输出到控制台(0/1) */
22
- console?: LoggerFlag;
23
- /** 单文件最大大小(MB),例如 10 表示 10MB;默认 20MB */
24
- maxSize?: number;
25
- /** 日志清洗深度限制(1..10) */
26
- sanitizeDepth?: number;
27
- /** 日志清洗节点数限制(50..20000) */
28
- sanitizeNodes?: number;
29
- /** 日志对象 key 数量限制(10..5000) */
30
- sanitizeObjectKeys?: number;
31
- /** 单条字符串最大长度(20..200000) */
32
- maxStringLen?: number;
33
- /** 数组最大展开元素数(10..5000) */
34
- maxArrayItems?: number;
35
- /**
36
- * 自定义脱敏字段匹配(支持通配,如 *password*)
37
- */
38
- excludeFields?: string[];
39
- }
40
- export type LogLevelName = "debug" | "info" | "warn" | "error";
41
- /**
42
- * LoggerRecord 允许出现的值类型。
43
- * - JsonValue:可序列化数据
44
- * - Error:允许直接传入错误对象(运行时会清洗成可序列化结构)
45
- * - object:允许传入非 plain object(如 Date/Map/Set/自定义 class 实例),由运行时做安全预览/截断
46
- */
47
- export type LoggerRecordValue = JsonValue | Error | object;
48
- export type LoggerRecord = {
49
- /** 文本消息(推荐直接放在 record 里) */
50
- msg?: string;
51
- /** 错误对象(会在运行时被清洗为可序列化结构) */
52
- err?: Error | JsonValue;
53
- /** 其他自定义字段 */
54
- [key: string]: LoggerRecordValue | undefined;
55
- };
56
- /**
57
- * Logger 的可替换 sink(用于测试 mock)。
58
- */
59
- export interface LoggerSink {
60
- info(record: LoggerRecord): void;
61
- warn(record: LoggerRecord): void;
62
- error(record: LoggerRecord): void;
63
- debug(record: LoggerRecord): void;
64
- }
65
- /**
66
- * Logger 接口(类型层)。
67
- *
68
- * 说明:core/runtime 内部使用的是 Bun 环境的自定义 Logger 实现(异步批量写入)。
69
- * 对外只承诺常用的 `info/warn/error/debug` 等调用形式(不再兼容 pino 的多签名调用)。
70
- */
71
- export interface Logger {
72
- /**
73
- * 只接受一个参数(任意类型):
74
- * - plain object({})会作为 record 写入
75
- * - 其他任何类型会被包装成对象后写入(例如 { msg: "..." } 或 { value: ... })
76
- */
77
- info(input: unknown, options?: LoggerWriteOptions): void;
78
- warn(input: unknown, options?: LoggerWriteOptions): void;
79
- error(input: unknown, options?: LoggerWriteOptions): void;
80
- debug(input: unknown, options?: LoggerWriteOptions): void;
81
- configure(cfg: LoggerConfig): void;
82
- setMock(mock: LoggerSink | null): void;
83
- /**
84
- * 将当前 buffer 尽快刷入 sink(不会关闭文件句柄)。
85
- *
86
- * 说明:主要用于测试或进程即将退出前的“尽快落盘”。
87
- */
88
- flush(): Promise<void>;
89
- /**
90
- * 刷新并关闭 sink(会关闭文件句柄)。
91
- *
92
- * 说明:主要用于测试(避免 Windows 句柄占用导致的删除/轮转失败)。
93
- */
94
- shutdown(): Promise<void>;
95
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * 日志相关类型定义
3
- *
4
- * 说明:这里的类型需要与 core/runtime 的 logger 实现保持一致(大量配置项以 0/1 表示开关)。
5
- */
6
- export {};
@@ -1,27 +0,0 @@
1
- /**
2
- * 插件类型定义
3
- *
4
- * 说明:当前 core 插件推荐的默认导出写法(避免声明文件深推导导致的类型问题):
5
- *
6
- * const xxxPlugin: Plugin = {
7
- * name: "xxx",
8
- * enable: true,
9
- * deps: [],
10
- * handler: (context) => {
11
- * return any;
12
- * }
13
- * };
14
- *
15
- * export default xxxPlugin;
16
- */
17
- import type { BeflyContext } from "./befly";
18
- export interface Plugin {
19
- /** 运行时由 loader 注入(默认导出对象中通常不需要写) */
20
- name?: string;
21
- /** 是否启用该插件;必填(true/false) */
22
- enable: boolean;
23
- /** 依赖的插件名(由文件名推导出的插件名),用于排序 */
24
- deps?: string[];
25
- /** 插件初始化函数(返回会被挂到 befly 上) */
26
- handler: (context: BeflyContext) => Promise<any> | any;
27
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * 插件类型定义
3
- *
4
- * 说明:当前 core 插件推荐的默认导出写法(避免声明文件深推导导致的类型问题):
5
- *
6
- * const xxxPlugin: Plugin = {
7
- * name: "xxx",
8
- * enable: true,
9
- * deps: [],
10
- * handler: (context) => {
11
- * return any;
12
- * }
13
- * };
14
- *
15
- * export default xxxPlugin;
16
- */
17
- export {};