befly 3.10.18 → 3.11.1

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 (223) hide show
  1. package/README.md +83 -307
  2. package/dist/befly.config.d.ts +7 -0
  3. package/{befly.config.ts → dist/befly.config.js} +11 -36
  4. package/dist/befly.js +15621 -0
  5. package/dist/befly.min.js +21 -0
  6. package/dist/checks/checkApi.d.ts +1 -0
  7. package/{checks/checkApi.ts → dist/checks/checkApi.js} +12 -30
  8. package/dist/checks/checkHook.d.ts +1 -0
  9. package/dist/checks/checkHook.js +86 -0
  10. package/dist/checks/checkMenu.d.ts +7 -0
  11. package/{checks/checkMenu.ts → dist/checks/checkMenu.js} +18 -53
  12. package/dist/checks/checkPlugin.d.ts +1 -0
  13. package/dist/checks/checkPlugin.js +86 -0
  14. package/dist/checks/checkTable.d.ts +6 -0
  15. package/{checks/checkTable.ts → dist/checks/checkTable.js} +17 -41
  16. package/dist/configs/presetFields.d.ts +4 -0
  17. package/{configs/presetFields.ts → dist/configs/presetFields.js} +1 -1
  18. package/dist/configs/presetRegexp.d.ts +145 -0
  19. package/{utils/regex.ts → dist/configs/presetRegexp.js} +8 -31
  20. package/dist/hooks/auth.d.ts +7 -0
  21. package/{hooks/auth.ts → dist/hooks/auth.js} +8 -10
  22. package/dist/hooks/cors.d.ts +11 -0
  23. package/{hooks/cors.ts → dist/hooks/cors.js} +5 -13
  24. package/dist/hooks/parser.d.ts +14 -0
  25. package/{hooks/parser.ts → dist/hooks/parser.js} +31 -45
  26. package/dist/hooks/permission.d.ts +14 -0
  27. package/{hooks/permission.ts → dist/hooks/permission.js} +16 -25
  28. package/dist/hooks/validator.d.ts +11 -0
  29. package/{hooks/validator.ts → dist/hooks/validator.js} +9 -14
  30. package/dist/index.d.ts +26 -0
  31. package/{main.ts → dist/index.js} +61 -100
  32. package/dist/lib/asyncContext.d.ts +21 -0
  33. package/dist/lib/asyncContext.js +27 -0
  34. package/dist/lib/cacheHelper.d.ts +95 -0
  35. package/{lib/cacheHelper.ts → dist/lib/cacheHelper.js} +45 -105
  36. package/dist/lib/cacheKeys.d.ts +23 -0
  37. package/{lib/cacheKeys.ts → dist/lib/cacheKeys.js} +5 -10
  38. package/dist/lib/cipher.d.ts +153 -0
  39. package/{lib/cipher.ts → dist/lib/cipher.js} +23 -44
  40. package/dist/lib/connect.d.ts +91 -0
  41. package/{lib/connect.ts → dist/lib/connect.js} +47 -88
  42. package/dist/lib/dbDialect.d.ts +87 -0
  43. package/{lib/dbDialect.ts → dist/lib/dbDialect.js} +32 -112
  44. package/dist/lib/dbHelper.d.ts +204 -0
  45. package/{lib/dbHelper.ts → dist/lib/dbHelper.js} +82 -241
  46. package/dist/lib/dbUtils.d.ts +68 -0
  47. package/{lib/dbUtils.ts → dist/lib/dbUtils.js} +51 -126
  48. package/dist/lib/jwt.d.ts +13 -0
  49. package/{lib/jwt.ts → dist/lib/jwt.js} +11 -32
  50. package/dist/lib/logger.d.ts +42 -0
  51. package/dist/lib/logger.js +1144 -0
  52. package/dist/lib/redisHelper.d.ts +185 -0
  53. package/{lib/redisHelper.ts → dist/lib/redisHelper.js} +97 -141
  54. package/dist/lib/sqlBuilder.d.ts +160 -0
  55. package/{lib/sqlBuilder.ts → dist/lib/sqlBuilder.js} +132 -278
  56. package/dist/lib/sqlCheck.d.ts +23 -0
  57. package/{lib/sqlCheck.ts → dist/lib/sqlCheck.js} +24 -41
  58. package/dist/lib/validator.d.ts +45 -0
  59. package/{lib/validator.ts → dist/lib/validator.js} +44 -61
  60. package/dist/loader/loadApis.d.ts +12 -0
  61. package/{loader/loadApis.ts → dist/loader/loadApis.js} +10 -20
  62. package/dist/loader/loadHooks.d.ts +7 -0
  63. package/dist/loader/loadHooks.js +35 -0
  64. package/dist/loader/loadPlugins.d.ts +8 -0
  65. package/{loader/loadPlugins.ts → dist/loader/loadPlugins.js} +14 -26
  66. package/dist/paths.d.ts +93 -0
  67. package/{paths.ts → dist/paths.js} +6 -19
  68. package/dist/plugins/cache.d.ts +16 -0
  69. package/{plugins/cache.ts → dist/plugins/cache.js} +7 -12
  70. package/dist/plugins/cipher.d.ts +12 -0
  71. package/{plugins/cipher.ts → dist/plugins/cipher.js} +4 -6
  72. package/dist/plugins/config.d.ts +12 -0
  73. package/dist/plugins/config.js +8 -0
  74. package/dist/plugins/db.d.ts +16 -0
  75. package/{plugins/db.ts → dist/plugins/db.js} +11 -17
  76. package/dist/plugins/jwt.d.ts +12 -0
  77. package/dist/plugins/jwt.js +12 -0
  78. package/dist/plugins/logger.d.ts +32 -0
  79. package/{plugins/logger.ts → dist/plugins/logger.js} +5 -8
  80. package/dist/plugins/redis.d.ts +16 -0
  81. package/{plugins/redis.ts → dist/plugins/redis.js} +9 -12
  82. package/dist/plugins/tool.d.ts +81 -0
  83. package/{plugins/tool.ts → dist/plugins/tool.js} +9 -30
  84. package/dist/router/api.d.ts +14 -0
  85. package/dist/router/api.js +107 -0
  86. package/dist/router/static.d.ts +9 -0
  87. package/{router/static.ts → dist/router/static.js} +20 -34
  88. package/dist/scripts/ensureDist.d.ts +1 -0
  89. package/dist/scripts/ensureDist.js +296 -0
  90. package/dist/sync/syncApi.d.ts +3 -0
  91. package/{sync/syncApi.ts → dist/sync/syncApi.js} +35 -55
  92. package/dist/sync/syncCache.d.ts +2 -0
  93. package/{sync/syncCache.ts → dist/sync/syncCache.js} +1 -6
  94. package/dist/sync/syncDev.d.ts +6 -0
  95. package/{sync/syncDev.ts → dist/sync/syncDev.js} +29 -62
  96. package/dist/sync/syncMenu.d.ts +14 -0
  97. package/{sync/syncMenu.ts → dist/sync/syncMenu.js} +65 -125
  98. package/dist/sync/syncTable.d.ts +151 -0
  99. package/{sync/syncTable.ts → dist/sync/syncTable.js} +172 -379
  100. package/{types → dist/types}/api.d.ts +12 -51
  101. package/dist/types/api.js +4 -0
  102. package/{types → dist/types}/befly.d.ts +32 -227
  103. package/dist/types/befly.js +4 -0
  104. package/{types → dist/types}/cache.d.ts +7 -15
  105. package/dist/types/cache.js +4 -0
  106. package/dist/types/cipher.d.ts +27 -0
  107. package/dist/types/cipher.js +7 -0
  108. package/{types → dist/types}/common.d.ts +8 -33
  109. package/dist/types/common.js +5 -0
  110. package/{types → dist/types}/context.d.ts +3 -5
  111. package/dist/types/context.js +4 -0
  112. package/{types → dist/types}/crypto.d.ts +0 -3
  113. package/dist/types/crypto.js +4 -0
  114. package/dist/types/database.d.ts +138 -0
  115. package/dist/types/database.js +4 -0
  116. package/dist/types/hook.d.ts +17 -0
  117. package/dist/types/hook.js +6 -0
  118. package/dist/types/jwt.d.ts +75 -0
  119. package/dist/types/jwt.js +4 -0
  120. package/dist/types/logger.d.ts +59 -0
  121. package/dist/types/logger.js +6 -0
  122. package/dist/types/plugin.d.ts +16 -0
  123. package/dist/types/plugin.js +6 -0
  124. package/dist/types/redis.d.ts +71 -0
  125. package/dist/types/redis.js +4 -0
  126. package/{types/roleApisCache.ts → dist/types/roleApisCache.d.ts} +0 -2
  127. package/dist/types/roleApisCache.js +8 -0
  128. package/dist/types/sync.d.ts +92 -0
  129. package/dist/types/sync.js +4 -0
  130. package/dist/types/table.d.ts +34 -0
  131. package/dist/types/table.js +4 -0
  132. package/dist/types/validate.d.ts +67 -0
  133. package/dist/types/validate.js +4 -0
  134. package/dist/utils/calcPerfTime.d.ts +4 -0
  135. package/{utils/calcPerfTime.ts → dist/utils/calcPerfTime.js} +3 -3
  136. package/dist/utils/convertBigIntFields.d.ts +11 -0
  137. package/{utils/convertBigIntFields.ts → dist/utils/convertBigIntFields.js} +5 -9
  138. package/dist/utils/cors.d.ts +8 -0
  139. package/{utils/cors.ts → dist/utils/cors.js} +1 -3
  140. package/dist/utils/disableMenusGlob.d.ts +13 -0
  141. package/{utils/disableMenusGlob.ts → dist/utils/disableMenusGlob.js} +9 -29
  142. package/dist/utils/fieldClear.d.ts +11 -0
  143. package/{utils/fieldClear.ts → dist/utils/fieldClear.js} +15 -33
  144. package/dist/utils/getClientIp.d.ts +6 -0
  145. package/{utils/getClientIp.ts → dist/utils/getClientIp.js} +1 -7
  146. package/dist/utils/importDefault.d.ts +1 -0
  147. package/dist/utils/importDefault.js +29 -0
  148. package/dist/utils/isDirentDirectory.d.ts +2 -0
  149. package/{utils/isDirentDirectory.ts → dist/utils/isDirentDirectory.js} +3 -8
  150. package/dist/utils/loadMenuConfigs.d.ts +29 -0
  151. package/{utils/loadMenuConfigs.ts → dist/utils/loadMenuConfigs.js} +66 -52
  152. package/dist/utils/mergeAndConcat.d.ts +7 -0
  153. package/dist/utils/mergeAndConcat.js +72 -0
  154. package/dist/utils/processAtSymbol.d.ts +4 -0
  155. package/{utils/processFields.ts → dist/utils/processAtSymbol.js} +5 -9
  156. package/dist/utils/processInfo.d.ts +24 -0
  157. package/{utils/process.ts → dist/utils/processInfo.js} +2 -18
  158. package/dist/utils/response.d.ts +20 -0
  159. package/{utils/response.ts → dist/utils/response.js} +28 -49
  160. package/dist/utils/scanAddons.d.ts +17 -0
  161. package/{utils/scanAddons.ts → dist/utils/scanAddons.js} +7 -41
  162. package/dist/utils/scanConfig.d.ts +26 -0
  163. package/{utils/scanConfig.ts → dist/utils/scanConfig.js} +28 -66
  164. package/dist/utils/scanCoreBuiltins.d.ts +3 -0
  165. package/dist/utils/scanCoreBuiltins.js +65 -0
  166. package/dist/utils/scanFiles.d.ts +30 -0
  167. package/{utils/scanFiles.ts → dist/utils/scanFiles.js} +44 -71
  168. package/dist/utils/scanSources.d.ts +10 -0
  169. package/dist/utils/scanSources.js +46 -0
  170. package/dist/utils/sortModules.d.ts +28 -0
  171. package/{utils/sortModules.ts → dist/utils/sortModules.js} +26 -66
  172. package/dist/utils/util.d.ts +84 -0
  173. package/dist/utils/util.js +262 -0
  174. package/package.json +26 -34
  175. package/.gitignore +0 -0
  176. package/bunfig.toml +0 -3
  177. package/checks/checkHook.ts +0 -48
  178. package/checks/checkPlugin.ts +0 -48
  179. package/configs/presetRegexp.ts +0 -225
  180. package/docs/README.md +0 -98
  181. package/docs/api/api.md +0 -1921
  182. package/docs/guide/examples.md +0 -926
  183. package/docs/guide/quickstart.md +0 -354
  184. package/docs/hooks/auth.md +0 -38
  185. package/docs/hooks/cors.md +0 -28
  186. package/docs/hooks/hook.md +0 -838
  187. package/docs/hooks/parser.md +0 -19
  188. package/docs/hooks/rateLimit.md +0 -47
  189. package/docs/infra/redis.md +0 -628
  190. package/docs/plugins/cipher.md +0 -61
  191. package/docs/plugins/database.md +0 -189
  192. package/docs/plugins/plugin.md +0 -986
  193. package/docs/reference/addon.md +0 -510
  194. package/docs/reference/config.md +0 -573
  195. package/docs/reference/logger.md +0 -495
  196. package/docs/reference/sync.md +0 -478
  197. package/docs/reference/table.md +0 -763
  198. package/docs/reference/validator.md +0 -620
  199. package/lib/asyncContext.ts +0 -43
  200. package/lib/logger.ts +0 -811
  201. package/loader/loadHooks.ts +0 -51
  202. package/plugins/config.ts +0 -13
  203. package/plugins/jwt.ts +0 -15
  204. package/router/api.ts +0 -130
  205. package/tsconfig.json +0 -8
  206. package/types/database.d.ts +0 -541
  207. package/types/hook.d.ts +0 -25
  208. package/types/jwt.d.ts +0 -118
  209. package/types/logger.d.ts +0 -65
  210. package/types/plugin.d.ts +0 -19
  211. package/types/redis.d.ts +0 -83
  212. package/types/sync.d.ts +0 -398
  213. package/types/table.d.ts +0 -216
  214. package/types/validate.d.ts +0 -69
  215. package/utils/arrayKeysToCamel.ts +0 -18
  216. package/utils/configTypes.ts +0 -3
  217. package/utils/genShortId.ts +0 -12
  218. package/utils/importDefault.ts +0 -21
  219. package/utils/keysToCamel.ts +0 -22
  220. package/utils/keysToSnake.ts +0 -22
  221. package/utils/pickFields.ts +0 -19
  222. package/utils/scanSources.ts +0 -64
  223. package/utils/sqlLog.ts +0 -37
@@ -1,541 +0,0 @@
1
- /**
2
- * 数据库相关类型定义
3
- */
4
-
5
- import type { SqlValue } from "./common";
6
- import type { JoinOption } from "./common";
7
- import type { DatabaseTables, TableName, TableType, TableInsertType, TableUpdateType, TypedWhereConditions } from "./table";
8
-
9
- // 重新导出表类型工具
10
- export type { DatabaseTables, TableName, TableType, TableInsertType, TableUpdateType, SystemFields, BaseTable, InsertType, UpdateType, SelectType, TypedWhereConditions } from "./table";
11
-
12
- // ============================================
13
- // SQL 查询相关类型
14
- // ============================================
15
-
16
- /**
17
- * WHERE 条件操作符
18
- */
19
- export type WhereOperator = "$eq" | "$ne" | "$not" | "$gt" | "$gte" | "$lt" | "$lte" | "$like" | "$notLike" | "$in" | "$notIn" | "$nin" | "$isNull" | "$isNotNull" | "$null" | "$notNull" | "$between" | "$notBetween";
20
-
21
- /**
22
- * WHERE 条件类型
23
- */
24
- export type WhereConditions = Record<string, any>;
25
-
26
- /**
27
- * 排序方向
28
- */
29
- export type OrderDirection = "ASC" | "DESC";
30
-
31
- /**
32
- * 排序字段
33
- */
34
- export type OrderByField = string | { field: string; direction: OrderDirection };
35
-
36
- // ============================================
37
- // 泛型查询选项(类型安全版本)
38
- // ============================================
39
-
40
- /**
41
- * 泛型查询选项 - 支持类型推断
42
- * @template K - 表名类型
43
- */
44
- export interface TypedQueryOptions<K extends TableName> {
45
- /** 表名 */
46
- table: K;
47
- /** 查询字段(表字段的子集) */
48
- fields?: (keyof TableType<K>)[] | string[];
49
- /** WHERE 条件(类型安全) */
50
- where?: TypedWhereConditions<TableType<K>> | WhereConditions;
51
- /** 排序(格式:["字段#ASC", "字段#DESC"]) */
52
- orderBy?: string[];
53
- /** 页码(从 1 开始) */
54
- page?: number;
55
- /** 每页数量 */
56
- limit?: number;
57
- }
58
-
59
- /**
60
- * 泛型插入选项 - 支持类型推断
61
- * @template K - 表名类型
62
- */
63
- export interface TypedInsertOptions<K extends TableName> {
64
- /** 表名 */
65
- table: K;
66
- /** 插入数据(ID、时间戳、state 会自动生成) */
67
- data: TableInsertType<K> | Record<string, any>;
68
- }
69
-
70
- /**
71
- * 泛型更新选项 - 支持类型推断
72
- * @template K - 表名类型
73
- */
74
- export interface TypedUpdateOptions<K extends TableName> {
75
- /** 表名 */
76
- table: K;
77
- /** 更新数据(updated_at 会自动更新) */
78
- data: TableUpdateType<K> | Record<string, any>;
79
- /** WHERE 条件 */
80
- where: TypedWhereConditions<TableType<K>> | WhereConditions;
81
- }
82
-
83
- /**
84
- * 泛型删除选项 - 支持类型推断
85
- * @template K - 表名类型
86
- */
87
- export interface TypedDeleteOptions<K extends TableName> {
88
- /** 表名 */
89
- table: K;
90
- /** WHERE 条件 */
91
- where: TypedWhereConditions<TableType<K>> | WhereConditions;
92
- }
93
-
94
- // ============================================
95
- // 兼容旧版查询选项(非类型安全版本)
96
- // ============================================
97
-
98
- /**
99
- * 查询选项(兼容旧版,不进行类型检查)
100
- */
101
- export interface QueryOptions {
102
- /** 表名(可带别名,如 'order o') */
103
- table: string;
104
- /** 查询字段(联查时需带表别名,如 'o.id', 'u.username') */
105
- fields?: string[];
106
- /** WHERE 条件(联查时字段需带表别名,如 { 'o.state': 1 }) */
107
- where?: WhereConditions;
108
- /** 多表联查选项 */
109
- joins?: JoinOption[];
110
- /** 排序(格式:["字段#ASC", "字段#DESC"]) */
111
- orderBy?: string[];
112
- /** 页码(从 1 开始) */
113
- page?: number;
114
- /** 每页数量 */
115
- limit?: number;
116
- }
117
-
118
- /**
119
- * 插入选项(兼容旧版)
120
- */
121
- export interface InsertOptions {
122
- /** 表名 */
123
- table: string;
124
- /** 插入数据(ID、时间戳、state 会自动生成) */
125
- data: Record<string, any>;
126
- }
127
-
128
- /**
129
- * 更新选项(兼容旧版)
130
- */
131
- export interface UpdateOptions {
132
- /** 表名 */
133
- table: string;
134
- /** 更新数据(updated_at 会自动更新) */
135
- data: Record<string, any>;
136
- /** WHERE 条件 */
137
- where: WhereConditions;
138
- }
139
-
140
- /**
141
- * 删除选项(兼容旧版)
142
- */
143
- export interface DeleteOptions {
144
- /** 表名 */
145
- table: string;
146
- /** WHERE 条件 */
147
- where: WhereConditions;
148
- }
149
-
150
- /**
151
- * 列表查询结果
152
- */
153
- export interface ListResult<T = any> {
154
- /** 数据列表 */
155
- lists: T[];
156
- /** 总条数 */
157
- total: number;
158
- /** 当前页码 */
159
- page: number;
160
- /** 每页数量 */
161
- limit: number;
162
- /** 总页数 */
163
- pages: number;
164
- }
165
-
166
- /**
167
- * 全部查询结果
168
- */
169
- export interface AllResult<T = any> {
170
- /** 数据列表 */
171
- lists: T[];
172
- /** 总条数 */
173
- total: number;
174
- }
175
-
176
- /**
177
- * 事务回调函数
178
- */
179
- export type TransactionCallback<T = any> = (trans: DbHelper) => Promise<T>;
180
-
181
- /**
182
- * SQL 查询结果
183
- */
184
- export interface SqlQuery {
185
- sql: string;
186
- params: SqlValue[];
187
- }
188
-
189
- /**
190
- * SQL 信息(用于 DbHelper 统一返回结构)
191
- */
192
- export interface SqlInfo extends SqlQuery {
193
- /** 执行耗时(毫秒) */
194
- duration: number;
195
- }
196
-
197
- /**
198
- * 列表/全量查询常见的两段 SQL 调试信息
199
- * - count: 计数 SQL
200
- * - data: 数据 SQL(在 total=0 等情况下可能不会执行)
201
- */
202
- export interface ListSql {
203
- count: SqlInfo;
204
- data?: SqlInfo;
205
- }
206
-
207
- /**
208
- * DbHelper 统一返回结构:全部用 data 承载原返回值,并附带 sql
209
- */
210
- export interface DbResult<TData = any, TSql = SqlInfo> {
211
- data: TData;
212
- sql: TSql;
213
- }
214
-
215
- /**
216
- * 插入数据类型
217
- */
218
- export type InsertData = Record<string, SqlValue> | Record<string, SqlValue>[];
219
-
220
- /**
221
- * 更新数据类型
222
- */
223
- export type UpdateData = Record<string, SqlValue>;
224
-
225
- /**
226
- * 数据库类型
227
- */
228
- export type DbType = "mysql" | "postgresql" | "sqlite";
229
-
230
- /**
231
- * 列信息
232
- */
233
- export interface ColumnInfo {
234
- /** 列名 */
235
- name: string;
236
- /** 数据类型 */
237
- type: string;
238
- /** 是否可空 */
239
- nullable: boolean;
240
- /** 默认值 */
241
- default: any;
242
- /** 长度 */
243
- length?: number;
244
- }
245
-
246
- /**
247
- * 索引信息
248
- */
249
- export interface IndexInfo {
250
- /** 索引名 */
251
- name: string;
252
- /** 列名 */
253
- column: string;
254
- /** 是否唯一 */
255
- unique: boolean;
256
- }
257
-
258
- /**
259
- * 同步统计
260
- */
261
- export interface SyncStats {
262
- /** 创建的表数 */
263
- created: number;
264
- /** 修改的表数 */
265
- modified: number;
266
- /** 创建的索引数 */
267
- indexesCreated: number;
268
- /** 删除的索引数 */
269
- indexesDropped: number;
270
- }
271
-
272
- /**
273
- * DbHelper 接口(前向声明)
274
- * 支持两种使用方式:
275
- * 1. 类型安全模式:使用 TypedQueryOptions 等泛型接口,获得完整类型推断
276
- * 2. 兼容模式:使用 QueryOptions 等非泛型接口,行为与之前一致
277
- */
278
- export interface DbHelper {
279
- // ============================================
280
- // 类型安全方法(推荐)
281
- // ============================================
282
-
283
- /**
284
- * 查询记录数(类型安全版本)
285
- * @template K - 表名类型
286
- */
287
- getCount<K extends TableName>(options: Omit<TypedQueryOptions<K>, "fields" | "page" | "limit" | "orderBy">): Promise<DbResult<number>>;
288
-
289
- /**
290
- * 查询单条数据(类型安全版本)
291
- * @template K - 表名类型
292
- * @returns 返回类型自动推断为对应表的记录类型
293
- */
294
- getOne<K extends TableName>(options: TypedQueryOptions<K>): Promise<DbResult<TableType<K> | null>>;
295
-
296
- /**
297
- * 查询列表(类型安全版本)
298
- * @template K - 表名类型
299
- * @returns 返回类型自动推断为对应表的记录列表
300
- */
301
- getList<K extends TableName>(options: TypedQueryOptions<K>): Promise<DbResult<ListResult<TableType<K>>, ListSql>>;
302
-
303
- /**
304
- * 查询所有数据(类型安全版本)
305
- * @template K - 表名类型
306
- * @returns 返回类型自动推断为对应表的记录数组
307
- */
308
- getAll<K extends TableName>(options: Omit<TypedQueryOptions<K>, "page" | "limit">): Promise<DbResult<AllResult<TableType<K>>, ListSql>>;
309
-
310
- /**
311
- * 插入数据(类型安全版本)
312
- * @template K - 表名类型
313
- */
314
- insData<K extends TableName>(options: TypedInsertOptions<K>): Promise<DbResult<number>>;
315
-
316
- /**
317
- * 更新数据(类型安全版本)
318
- * @template K - 表名类型
319
- */
320
- updData<K extends TableName>(options: TypedUpdateOptions<K>): Promise<DbResult<number>>;
321
-
322
- /**
323
- * 删除数据(类型安全版本)
324
- * @template K - 表名类型
325
- */
326
- delData<K extends TableName>(options: TypedDeleteOptions<K>): Promise<DbResult<number>>;
327
-
328
- // ============================================
329
- // 兼容旧版方法(手动指定返回类型)
330
- // ============================================
331
-
332
- /**
333
- * 查询记录数(兼容版本)
334
- */
335
- getCount(options: Omit<QueryOptions, "fields" | "page" | "limit" | "orderBy">): Promise<DbResult<number>>;
336
-
337
- /**
338
- * 查询单条数据(兼容版本,需手动指定泛型)
339
- * @template T - 返回类型
340
- */
341
- getOne<T = any>(options: QueryOptions): Promise<DbResult<T | null>>;
342
-
343
- /**
344
- * 查询列表(兼容版本,需手动指定泛型)
345
- * @template T - 列表项类型
346
- */
347
- getList<T = any>(options: QueryOptions): Promise<DbResult<ListResult<T>, ListSql>>;
348
-
349
- /**
350
- * 查询所有数据(兼容版本,需手动指定泛型)
351
- * @template T - 返回类型
352
- */
353
- getAll<T = any>(options: Omit<QueryOptions, "page" | "limit">): Promise<DbResult<AllResult<T>, ListSql>>;
354
-
355
- /**
356
- * 插入数据(兼容版本)
357
- */
358
- insData(options: InsertOptions): Promise<DbResult<number>>;
359
-
360
- /**
361
- * 更新数据(兼容版本)
362
- */
363
- updData(options: UpdateOptions): Promise<DbResult<number>>;
364
-
365
- /**
366
- * 删除数据(兼容版本)
367
- */
368
- delData(options: DeleteOptions): Promise<DbResult<number>>;
369
-
370
- // ============================================
371
- // 通用方法
372
- // ============================================
373
-
374
- /**
375
- * 执行事务
376
- * @template T - 事务返回类型
377
- */
378
- trans<T = any>(callback: TransactionCallback<T>): Promise<T>;
379
-
380
- /**
381
- * 执行原始 SQL
382
- */
383
- query(sql: string, params?: any[]): Promise<DbResult<any>>;
384
-
385
- /**
386
- * 检查数据是否存在
387
- */
388
- exists(options: Omit<QueryOptions, "fields" | "orderBy" | "page" | "limit">): Promise<DbResult<boolean>>;
389
-
390
- /**
391
- * 检查表是否存在
392
- */
393
- tableExists(tableName: string): Promise<DbResult<boolean>>;
394
-
395
- /**
396
- * 批量插入数据
397
- */
398
- insBatch(table: string, dataList: Record<string, any>[]): Promise<DbResult<number[]>>;
399
-
400
- /**
401
- * 禁用数据(设置 state=2)
402
- */
403
- disableData(options: Omit<DeleteOptions, "hard">): Promise<DbResult<number>>;
404
-
405
- /**
406
- * 启用数据(设置 state=1)
407
- */
408
- enableData(options: Omit<DeleteOptions, "hard">): Promise<DbResult<number>>;
409
-
410
- /**
411
- * 硬删除数据(物理删除)
412
- */
413
- delForce(options: Omit<DeleteOptions, "hard">): Promise<DbResult<number>>;
414
-
415
- /**
416
- * 自增字段
417
- */
418
- increment(table: string, field: string, where: WhereConditions, value?: number): Promise<DbResult<number>>;
419
-
420
- /**
421
- * 自减字段
422
- */
423
- decrement(table: string, field: string, where: WhereConditions, value?: number): Promise<DbResult<number>>;
424
-
425
- /**
426
- * 查询单个字段值
427
- */
428
- getFieldValue<T = any>(options: Omit<QueryOptions, "fields"> & { field: string }): Promise<DbResult<T | null>>;
429
- }
430
-
431
- /**
432
- * SQL 客户端选项
433
- */
434
- export interface SqlClientOptions {
435
- /** 最大连接数 */
436
- max?: number;
437
- /** 是否使用 BigInt */
438
- bigint?: boolean;
439
- /** 连接超时时间(毫秒),默认 30000ms */
440
- connectionTimeout?: number;
441
- /** 其他自定义选项 */
442
- [key: string]: any;
443
- }
444
-
445
- // ========== 数据库同步相关类型 ==========
446
-
447
- /**
448
- * 列信息接口(用于数据库同步)
449
- */
450
- export interface ColumnInfo {
451
- /** 字段类型(如 string, number 等) */
452
- type: string;
453
- /** 数据库列类型(如 VARCHAR, INT 等) */
454
- columnType: string;
455
- /** 字段长度 */
456
- length: number | null;
457
- /** 是否可空 */
458
- nullable: boolean;
459
- /** 默认值 */
460
- defaultValue: any;
461
- /** 字段注释 */
462
- comment: string | null;
463
- }
464
-
465
- /**
466
- * 索引信息接口
467
- */
468
- export interface IndexInfo {
469
- /** 索引名称到字段数组的映射 */
470
- [indexName: string]: string[];
471
- }
472
-
473
- /**
474
- * 字段变更类型
475
- */
476
- export interface FieldChange {
477
- /** 变更类型 */
478
- type: "length" | "comment" | "datatype" | "default";
479
- /** 当前值 */
480
- current: any;
481
- /** 新值 */
482
- new: any;
483
- }
484
-
485
- /**
486
- * 索引操作接口
487
- */
488
- export interface IndexAction {
489
- /** 操作类型:create(创建)或 drop(删除) */
490
- action: "create" | "drop";
491
- /** 索引名称 */
492
- indexName: string;
493
- /** 字段名称 */
494
- fieldName: string;
495
- }
496
-
497
- /**
498
- * 表同步计划接口
499
- */
500
- export interface TablePlan {
501
- /** 是否有变更 */
502
- changed: boolean;
503
- /** 添加字段的 SQL 子句 */
504
- addClauses: string[];
505
- /** 修改字段的 SQL 子句 */
506
- modifyClauses: string[];
507
- /** 默认值变更的 SQL 子句 */
508
- defaultClauses: string[];
509
- /** 索引操作列表 */
510
- indexActions: IndexAction[];
511
- /** 注释变更的 SQL 子句(可选) */
512
- commentActions?: string[];
513
- }
514
-
515
- /**
516
- * 全局统计计数接口
517
- */
518
- export interface GlobalCount {
519
- /** 已处理表数量 */
520
- processedTables: number;
521
- /** 创建表数量 */
522
- createdTables: number;
523
- /** 修改表数量 */
524
- modifiedTables: number;
525
- /** 新增字段数量 */
526
- addFields: number;
527
- /** 类型变更数量 */
528
- typeChanges: number;
529
- /** 最大值变更数量 */
530
- maxChanges: number;
531
- /** 最小值变更数量 */
532
- minChanges: number;
533
- /** 默认值变更数量 */
534
- defaultChanges: number;
535
- /** 名称变更数量 */
536
- nameChanges: number;
537
- /** 索引创建数量 */
538
- indexCreate: number;
539
- /** 索引删除数量 */
540
- indexDrop: number;
541
- }
package/types/hook.d.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * Befly 钩子系统类型定义
3
- */
4
-
5
- import type { BeflyContext } from "./befly.ts";
6
- import type { RequestContext } from "./context.ts";
7
-
8
- /**
9
- * 钩子处理函数类型(串联模式,无 next 参数)
10
- */
11
- export type HookHandler = (befly: BeflyContext, ctx: RequestContext) => Promise<void> | void;
12
-
13
- /**
14
- * 钩子配置类型
15
- */
16
- export interface Hook {
17
- /** 钩子名称(运行时动态添加,由文件名生成) */
18
- name?: string;
19
-
20
- /** 依赖的钩子列表(在这些钩子之后执行) */
21
- deps: string[];
22
-
23
- /** 钩子处理函数 */
24
- handler: HookHandler;
25
- }
package/types/jwt.d.ts DELETED
@@ -1,118 +0,0 @@
1
- /**
2
- * JWT 相关类型定义
3
- */
4
-
5
- /**
6
- * JWT 算法类型
7
- */
8
- export type JwtAlgorithm = "HS256" | "HS384" | "HS512";
9
-
10
- /**
11
- * JWT Header 接口
12
- */
13
- export interface JwtHeader {
14
- alg: JwtAlgorithm;
15
- typ: "JWT";
16
- }
17
-
18
- /**
19
- * JWT 载荷
20
- */
21
- export interface JwtPayload {
22
- /**
23
- * 注意:JWT payload 的业务字段来自 `befly.jwt.sign(payload)` 的入参。
24
- * 也就是说:你在 sign 时放了什么字段,verify/decode 时就能取到什么字段。
25
- *
26
- * 另外,JWT 标准 claim(如 iat/exp/nbf/iss/aud/sub/jti)可能由 signer 注入。
27
- */
28
-
29
- /** 用户 ID(历史字段:部分代码用 userId) */
30
- userId?: string | number;
31
-
32
- /** 用户 ID(推荐字段:部分项目使用 id) */
33
- id?: string | number;
34
-
35
- /** 角色编码 */
36
- roleCode?: string;
37
-
38
- /** 昵称 */
39
- nickname?: string;
40
-
41
- /** 角色类型 */
42
- roleType?: string;
43
-
44
- /** 签发时间(秒级或毫秒级取决于实现,当前由底层库决定) */
45
- iat?: number;
46
-
47
- /** 过期时间(秒级或毫秒级取决于实现,当前由底层库决定) */
48
- exp?: number;
49
-
50
- /** 生效时间 */
51
- nbf?: number;
52
-
53
- /** 签发者 */
54
- iss?: string;
55
-
56
- /** 受众 */
57
- aud?: string | string[];
58
-
59
- /** 主题 */
60
- sub?: string;
61
-
62
- /** JWT ID */
63
- jti?: string;
64
-
65
- /** 其他自定义字段(由 sign 入参决定) */
66
- [key: string]: unknown;
67
- }
68
-
69
- /**
70
- * JWT 完整解码结果
71
- */
72
- export interface JwtDecoded {
73
- header: JwtHeader;
74
- payload: JwtPayload;
75
- signature: string;
76
- }
77
-
78
- /**
79
- * JWT 签名选项
80
- */
81
- export interface JwtSignOptions {
82
- /** 密钥 */
83
- secret?: string;
84
- /** 算法 */
85
- algorithm?: JwtAlgorithm;
86
- /** 过期时间 */
87
- expiresIn?: string | number;
88
- /** 签发者 */
89
- issuer?: string;
90
- /** 受众 */
91
- audience?: string;
92
- /** 主题 */
93
- subject?: string;
94
- /** 生效时间 */
95
- notBefore?: string | number;
96
- /** JWT ID */
97
- jwtId?: string;
98
- }
99
-
100
- /**
101
- * JWT 验证选项
102
- */
103
- export interface JwtVerifyOptions {
104
- /** 密钥 */
105
- secret?: string;
106
- /** 算法列表 */
107
- algorithms?: JwtAlgorithm[];
108
- /** 签发者 */
109
- issuer?: string;
110
- /** 受众 */
111
- audience?: string;
112
- /** 主题 */
113
- subject?: string;
114
- /** 是否忽略过期 */
115
- ignoreExpiration?: boolean;
116
- /** 是否忽略生效时间 */
117
- ignoreNotBefore?: boolean;
118
- }