befly 3.8.29 → 3.8.31

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 (70) hide show
  1. package/README.md +91 -6
  2. package/checks/checkApi.ts +2 -1
  3. package/checks/checkApp.ts +31 -1
  4. package/checks/checkTable.ts +3 -2
  5. package/hooks/cors.ts +3 -3
  6. package/hooks/parser.ts +8 -6
  7. package/hooks/permission.ts +12 -5
  8. package/hooks/validator.ts +1 -1
  9. package/lib/cacheHelper.ts +73 -65
  10. package/lib/cipher.ts +2 -1
  11. package/lib/connect.ts +23 -52
  12. package/lib/dbHelper.ts +14 -11
  13. package/lib/jwt.ts +58 -437
  14. package/lib/logger.ts +76 -197
  15. package/lib/redisHelper.ts +163 -1
  16. package/lib/sqlBuilder.ts +2 -1
  17. package/lib/validator.ts +150 -384
  18. package/loader/loadApis.ts +4 -7
  19. package/loader/loadHooks.ts +6 -5
  20. package/loader/loadPlugins.ts +11 -13
  21. package/main.ts +26 -53
  22. package/package.json +10 -8
  23. package/paths.ts +0 -6
  24. package/plugins/cipher.ts +1 -1
  25. package/plugins/config.ts +3 -4
  26. package/plugins/db.ts +6 -7
  27. package/plugins/jwt.ts +7 -6
  28. package/plugins/logger.ts +6 -6
  29. package/plugins/redis.ts +9 -13
  30. package/router/api.ts +2 -2
  31. package/router/static.ts +4 -8
  32. package/sync/syncAll.ts +8 -13
  33. package/sync/syncApi.ts +14 -10
  34. package/sync/syncDb/apply.ts +1 -2
  35. package/sync/syncDb.ts +12 -15
  36. package/sync/syncDev.ts +19 -56
  37. package/sync/syncMenu.ts +182 -137
  38. package/tests/cacheHelper.test.ts +327 -0
  39. package/tests/dbHelper-columns.test.ts +5 -20
  40. package/tests/dbHelper-execute.test.ts +14 -68
  41. package/tests/fields-redis-cache.test.ts +5 -3
  42. package/tests/integration.test.ts +17 -32
  43. package/tests/jwt.test.ts +36 -94
  44. package/tests/logger.test.ts +32 -34
  45. package/tests/redisHelper.test.ts +271 -2
  46. package/tests/redisKeys.test.ts +76 -0
  47. package/tests/sync-connection.test.ts +0 -6
  48. package/tests/syncDb-constants.test.ts +12 -12
  49. package/tests/util.test.ts +5 -1
  50. package/tests/validator.test.ts +611 -85
  51. package/types/befly.d.ts +9 -15
  52. package/types/cache.d.ts +73 -0
  53. package/types/common.d.ts +10 -128
  54. package/types/database.d.ts +221 -5
  55. package/types/index.ts +6 -5
  56. package/types/plugin.d.ts +1 -4
  57. package/types/redis.d.ts +37 -2
  58. package/types/table.d.ts +175 -0
  59. package/config.ts +0 -70
  60. package/hooks/_rateLimit.ts +0 -64
  61. package/lib/regexAliases.ts +0 -59
  62. package/lib/xml.ts +0 -383
  63. package/tests/validator-advanced.test.ts +0 -653
  64. package/tests/xml.test.ts +0 -101
  65. package/types/addon.d.ts +0 -50
  66. package/types/crypto.d.ts +0 -23
  67. package/types/jwt.d.ts +0 -99
  68. package/types/logger.d.ts +0 -43
  69. package/types/tool.d.ts +0 -67
  70. package/types/validator.d.ts +0 -43
package/types/befly.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  import type { Plugin } from './plugin.js';
6
6
  import type { ApiRoute, HttpMethod } from './api.js';
7
7
  import type { KeyValue } from './common.js';
8
+ import type { LoggerConfig } from './logger.js';
8
9
  import type { Logger } from '../lib/logger.js';
9
10
  import type { Jwt } from '../lib/jwt.js';
10
11
  import type { Validator } from '../lib/validator.js';
@@ -14,21 +15,7 @@ import type { RedisHelper } from '../lib/redisHelper.js';
14
15
  import type { Cipher } from '../lib/cipher.js';
15
16
  import type { CacheHelper } from '../lib/cacheHelper.js';
16
17
 
17
- /**
18
- * 日志配置
19
- */
20
- export interface LoggerConfig {
21
- /** 是否开启调试模式 (0: 关闭, 1: 开启) @default 1 */
22
- debug?: number;
23
- /** 日志排除字段 (逗号分隔) @default 'password,token,secret' */
24
- excludeFields?: string;
25
- /** 日志目录 @default './logs' */
26
- dir?: string;
27
- /** 是否输出到控制台 (0: 关闭, 1: 开启) @default 1 */
28
- console?: number;
29
- /** 单个日志文件最大大小 (字节) @default 10485760 (10MB) */
30
- maxSize?: number;
31
- }
18
+ export type { LoggerConfig };
32
19
 
33
20
  /**
34
21
  * 数据库配置
@@ -137,6 +124,13 @@ export interface BeflyOptions {
137
124
  disableHooks?: string[];
138
125
  /** 禁用的插件列表 */
139
126
  disablePlugins?: string[];
127
+ /** 隐藏的菜单路径列表(不同步到数据库) */
128
+ hiddenMenus?: string[];
129
+ /**
130
+ * Addon 运行时配置
131
+ * 按 addon 名称分组,如 addons.admin.email
132
+ */
133
+ addons?: Record<string, Record<string, any>>;
140
134
  /** 其他插件配置 */
141
135
  [key: string]: any;
142
136
  }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 缓存助手类型定义
3
+ */
4
+
5
+ import type { BeflyContext } from './befly.js';
6
+
7
+ /**
8
+ * 缓存助手类
9
+ * 负责在服务器启动时缓存接口、菜单和角色权限到 Redis
10
+ */
11
+ export interface CacheHelper {
12
+ /**
13
+ * 缓存所有接口到 Redis
14
+ */
15
+ cacheApis(): Promise<void>;
16
+
17
+ /**
18
+ * 缓存所有菜单到 Redis(从数据库读取)
19
+ */
20
+ cacheMenus(): Promise<void>;
21
+
22
+ /**
23
+ * 缓存所有角色的接口权限到 Redis
24
+ * 优化:使用 Promise.all 利用 Bun Redis 自动 pipeline 特性
25
+ */
26
+ cacheRolePermissions(): Promise<void>;
27
+
28
+ /**
29
+ * 缓存所有数据(接口、菜单、角色权限)
30
+ */
31
+ cacheAll(): Promise<void>;
32
+
33
+ /**
34
+ * 获取缓存的所有接口
35
+ * @returns 接口列表
36
+ */
37
+ getApis(): Promise<any[]>;
38
+
39
+ /**
40
+ * 获取缓存的所有菜单
41
+ * @returns 菜单列表
42
+ */
43
+ getMenus(): Promise<any[]>;
44
+
45
+ /**
46
+ * 获取角色的接口权限
47
+ * @param roleCode - 角色代码
48
+ * @returns 接口路径列表
49
+ */
50
+ getRolePermissions(roleCode: string): Promise<string[]>;
51
+
52
+ /**
53
+ * 检查角色是否有指定接口权限
54
+ * @param roleCode - 角色代码
55
+ * @param apiPath - 接口路径(格式:METHOD/path)
56
+ * @returns 是否有权限
57
+ */
58
+ checkRolePermission(roleCode: string, apiPath: string): Promise<boolean>;
59
+
60
+ /**
61
+ * 删除角色的接口权限缓存
62
+ * @param roleCode - 角色代码
63
+ * @returns 是否删除成功
64
+ */
65
+ deleteRolePermissions(roleCode: string): Promise<boolean>;
66
+ }
67
+
68
+ /**
69
+ * CacheHelper 构造函数类型
70
+ */
71
+ export interface CacheHelperConstructor {
72
+ new (befly: BeflyContext): CacheHelper;
73
+ }
package/types/common.d.ts CHANGED
@@ -1,47 +1,11 @@
1
1
  /**
2
2
  * Befly 框架通用类型定义
3
+ * Core 专用类型,通用类型请直接从 befly-shared/types 导入
3
4
  */
4
5
 
5
- /**
6
- * 响应结果类型
7
- */
8
- export interface ResponseResult<T = any> {
9
- code: number;
10
- msg: string;
11
- data?: T;
12
- error?: any;
13
- }
14
-
15
- /**
16
- * 验证结果类型
17
- */
18
- export interface ValidationResult {
19
- code: 0 | 1;
20
- fields: Record<string, any>;
21
- }
22
-
23
- /**
24
- * 字段定义类型(对象格式)
25
- */
26
- export interface FieldDefinition {
27
- name: string; // 字段标签/描述
28
- detail: string; // 字段详细说明
29
- type: 'string' | 'number' | 'text' | 'array_string' | 'array_text';
30
- min: number | null; // 最小值/最小长度
31
- max: number | null; // 最大值/最大长度
32
- default: any; // 默认值
33
- index: boolean; // 是否创建索引
34
- unique: boolean; // 是否唯一
35
- comment: string; // 字段注释
36
- nullable: boolean; // 是否允许为空
37
- unsigned: boolean; // 是否无符号(仅number类型)
38
- regexp: string | null; // 正则验证
39
- }
40
-
41
- /**
42
- * 表定义类型(对象格式)
43
- */
44
- export type TableDefinition = Record<string, FieldDefinition>;
6
+ // ============================================
7
+ // Core 专用类型(不适合放在 shared 中的类型)
8
+ // ============================================
45
9
 
46
10
  /**
47
11
  * 字段规则字符串(已废弃,保留用于兼容)
@@ -60,26 +24,15 @@ export type FieldRule = string;
60
24
  * @deprecated 请使用 FieldDefinition 对象格式
61
25
  */
62
26
  export interface ParsedFieldRule {
63
- name: string; // 字段名称
27
+ name: string;
64
28
  type: 'string' | 'number' | 'text' | 'array_string' | 'array_text';
65
- min: number | null; // 最小值
66
- max: number | null; // 最大值
67
- default: any; // 默认值
68
- index: 0 | 1; // 是否索引
69
- regex: string | null; // 正则约束
29
+ min: number | null;
30
+ max: number | null;
31
+ default: any;
32
+ index: 0 | 1;
33
+ regex: string | null;
70
34
  }
71
35
 
72
- /**
73
- * SQL 查询参数类型
74
- */
75
- export type SqlValue = string | number | boolean | null | Date;
76
- export type SqlParams = SqlValue[];
77
-
78
- /**
79
- * 排序方向
80
- */
81
- export type OrderDirection = 'ASC' | 'DESC' | 'asc' | 'desc';
82
-
83
36
  /**
84
37
  * 比较运算符
85
38
  */
@@ -90,44 +43,6 @@ export type ComparisonOperator = '=' | '>' | '<' | '>=' | '<=' | '!=' | '<>' | '
90
43
  */
91
44
  export type JoinType = 'INNER' | 'LEFT' | 'RIGHT' | 'FULL';
92
45
 
93
- /**
94
- * 数据库配置类型
95
- */
96
- export interface DatabaseConfig {
97
- host: string;
98
- port: number;
99
- user: string;
100
- password: string;
101
- database: string;
102
- connectionLimit?: number;
103
- }
104
-
105
- /**
106
- * Redis 配置类型
107
- */
108
- export interface RedisConfig {
109
- host: string;
110
- port: number;
111
- password?: string;
112
- db?: number;
113
- }
114
-
115
- /**
116
- * 日志级别
117
- */
118
- export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
119
-
120
- /**
121
- * 日志配置
122
- */
123
- export interface LoggerConfig {
124
- level?: LogLevel;
125
- transport?: {
126
- target: string;
127
- options?: Record<string, any>;
128
- };
129
- }
130
-
131
46
  /**
132
47
  * 工具函数返回类型
133
48
  */
@@ -137,29 +52,6 @@ export interface ToolResponse<T = any> {
137
52
  error?: string;
138
53
  }
139
54
 
140
- /**
141
- * 分页参数
142
- */
143
- export interface PaginationParams {
144
- page: number;
145
- limit: number;
146
- }
147
-
148
- /**
149
- * 分页结果
150
- */
151
- export interface PaginatedResult<T = any> {
152
- total: number;
153
- page: number;
154
- limit: number;
155
- data: T[];
156
- }
157
-
158
- /**
159
- * 通用键值对
160
- */
161
- export type KeyValue<T = any> = Record<string, T>;
162
-
163
55
  /**
164
56
  * 可选字段
165
57
  */
@@ -170,16 +62,6 @@ export type Optional<T> = T | null | undefined;
170
62
  */
171
63
  export type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
172
64
 
173
- /**
174
- * 保留字段(系统自动管理)
175
- */
176
- export type ReservedFields = 'id' | 'created_at' | 'updated_at' | 'deleted_at' | 'state';
177
-
178
- /**
179
- * 排除保留字段
180
- */
181
- export type ExcludeReserved<T> = Omit<T, ReservedFields>;
182
-
183
65
  /**
184
66
  * 数据库记录基础类型
185
67
  */
@@ -2,13 +2,80 @@
2
2
  * 数据库相关类型定义
3
3
  */
4
4
 
5
- import type { SqlValue, WhereConditions } from './common';
5
+ import type { SqlValue } from 'befly-shared/types';
6
+ import type { WhereConditions } from './common';
7
+ import type { DatabaseTables, TableName, TableType, TableInsertType, TableUpdateType, TypedWhereConditions } from './table';
6
8
 
7
9
  // 重新导出 WhereOperator 和 WhereConditions,供其他模块使用
8
10
  export type { WhereOperator, WhereConditions } from './index';
9
11
 
12
+ // 重新导出表类型工具
13
+ export type { DatabaseTables, TableName, TableType, TableInsertType, TableUpdateType, SystemFields, BaseTable, InsertType, UpdateType, SelectType, TypedWhereConditions } from './table';
14
+
15
+ // ============================================
16
+ // 泛型查询选项(类型安全版本)
17
+ // ============================================
18
+
19
+ /**
20
+ * 泛型查询选项 - 支持类型推断
21
+ * @template K - 表名类型
22
+ */
23
+ export interface TypedQueryOptions<K extends TableName> {
24
+ /** 表名 */
25
+ table: K;
26
+ /** 查询字段(表字段的子集) */
27
+ fields?: (keyof TableType<K>)[] | string[];
28
+ /** WHERE 条件(类型安全) */
29
+ where?: TypedWhereConditions<TableType<K>> | WhereConditions;
30
+ /** 排序(格式:["字段#ASC", "字段#DESC"]) */
31
+ orderBy?: string[];
32
+ /** 页码(从 1 开始) */
33
+ page?: number;
34
+ /** 每页数量 */
35
+ limit?: number;
36
+ }
37
+
10
38
  /**
11
- * 查询选项
39
+ * 泛型插入选项 - 支持类型推断
40
+ * @template K - 表名类型
41
+ */
42
+ export interface TypedInsertOptions<K extends TableName> {
43
+ /** 表名 */
44
+ table: K;
45
+ /** 插入数据(ID、时间戳、state 会自动生成) */
46
+ data: TableInsertType<K> | Record<string, any>;
47
+ }
48
+
49
+ /**
50
+ * 泛型更新选项 - 支持类型推断
51
+ * @template K - 表名类型
52
+ */
53
+ export interface TypedUpdateOptions<K extends TableName> {
54
+ /** 表名 */
55
+ table: K;
56
+ /** 更新数据(updated_at 会自动更新) */
57
+ data: TableUpdateType<K> | Record<string, any>;
58
+ /** WHERE 条件 */
59
+ where: TypedWhereConditions<TableType<K>> | WhereConditions;
60
+ }
61
+
62
+ /**
63
+ * 泛型删除选项 - 支持类型推断
64
+ * @template K - 表名类型
65
+ */
66
+ export interface TypedDeleteOptions<K extends TableName> {
67
+ /** 表名 */
68
+ table: K;
69
+ /** WHERE 条件 */
70
+ where: TypedWhereConditions<TableType<K>> | WhereConditions;
71
+ }
72
+
73
+ // ============================================
74
+ // 兼容旧版查询选项(非类型安全版本)
75
+ // ============================================
76
+
77
+ /**
78
+ * 查询选项(兼容旧版,不进行类型检查)
12
79
  */
13
80
  export interface QueryOptions {
14
81
  /** 表名 */
@@ -26,7 +93,7 @@ export interface QueryOptions {
26
93
  }
27
94
 
28
95
  /**
29
- * 插入选项
96
+ * 插入选项(兼容旧版)
30
97
  */
31
98
  export interface InsertOptions {
32
99
  /** 表名 */
@@ -36,7 +103,7 @@ export interface InsertOptions {
36
103
  }
37
104
 
38
105
  /**
39
- * 更新选项
106
+ * 更新选项(兼容旧版)
40
107
  */
41
108
  export interface UpdateOptions {
42
109
  /** 表名 */
@@ -48,7 +115,7 @@ export interface UpdateOptions {
48
115
  }
49
116
 
50
117
  /**
51
- * 删除选项
118
+ * 删除选项(兼容旧版)
52
119
  */
53
120
  export interface DeleteOptions {
54
121
  /** 表名 */
@@ -147,17 +214,166 @@ export interface SyncStats {
147
214
 
148
215
  /**
149
216
  * DbHelper 接口(前向声明)
217
+ * 支持两种使用方式:
218
+ * 1. 类型安全模式:使用 TypedQueryOptions 等泛型接口,获得完整类型推断
219
+ * 2. 兼容模式:使用 QueryOptions 等非泛型接口,行为与之前一致
150
220
  */
151
221
  export interface DbHelper {
222
+ // ============================================
223
+ // 类型安全方法(推荐)
224
+ // ============================================
225
+
226
+ /**
227
+ * 查询记录数(类型安全版本)
228
+ * @template K - 表名类型
229
+ */
230
+ getCount<K extends TableName>(options: Omit<TypedQueryOptions<K>, 'fields' | 'page' | 'limit' | 'orderBy'>): Promise<number>;
231
+
232
+ /**
233
+ * 查询单条数据(类型安全版本)
234
+ * @template K - 表名类型
235
+ * @returns 返回类型自动推断为对应表的记录类型
236
+ */
237
+ getOne<K extends TableName>(options: TypedQueryOptions<K>): Promise<TableType<K> | null>;
238
+
239
+ /**
240
+ * 查询列表(类型安全版本)
241
+ * @template K - 表名类型
242
+ * @returns 返回类型自动推断为对应表的记录列表
243
+ */
244
+ getList<K extends TableName>(options: TypedQueryOptions<K>): Promise<ListResult<TableType<K>>>;
245
+
246
+ /**
247
+ * 查询所有数据(类型安全版本)
248
+ * @template K - 表名类型
249
+ * @returns 返回类型自动推断为对应表的记录数组
250
+ */
251
+ getAll<K extends TableName>(options: Omit<TypedQueryOptions<K>, 'page' | 'limit'>): Promise<TableType<K>[]>;
252
+
253
+ /**
254
+ * 插入数据(类型安全版本)
255
+ * @template K - 表名类型
256
+ */
257
+ insData<K extends TableName>(options: TypedInsertOptions<K>): Promise<number>;
258
+
259
+ /**
260
+ * 更新数据(类型安全版本)
261
+ * @template K - 表名类型
262
+ */
263
+ updData<K extends TableName>(options: TypedUpdateOptions<K>): Promise<number>;
264
+
265
+ /**
266
+ * 删除数据(类型安全版本)
267
+ * @template K - 表名类型
268
+ */
269
+ delData<K extends TableName>(options: TypedDeleteOptions<K>): Promise<number>;
270
+
271
+ // ============================================
272
+ // 兼容旧版方法(手动指定返回类型)
273
+ // ============================================
274
+
275
+ /**
276
+ * 查询记录数(兼容版本)
277
+ */
152
278
  getCount(options: Omit<QueryOptions, 'fields' | 'page' | 'limit' | 'orderBy'>): Promise<number>;
279
+
280
+ /**
281
+ * 查询单条数据(兼容版本,需手动指定泛型)
282
+ * @template T - 返回类型
283
+ */
153
284
  getOne<T = any>(options: QueryOptions): Promise<T | null>;
285
+
286
+ /**
287
+ * 查询列表(兼容版本,需手动指定泛型)
288
+ * @template T - 列表项类型
289
+ */
154
290
  getList<T = any>(options: QueryOptions): Promise<ListResult<T>>;
291
+
292
+ /**
293
+ * 查询所有数据(兼容版本,需手动指定泛型)
294
+ * @template T - 返回类型
295
+ */
155
296
  getAll<T = any>(options: Omit<QueryOptions, 'page' | 'limit'>): Promise<T[]>;
297
+
298
+ /**
299
+ * 插入数据(兼容版本)
300
+ */
156
301
  insData(options: InsertOptions): Promise<number>;
302
+
303
+ /**
304
+ * 更新数据(兼容版本)
305
+ */
157
306
  updData(options: UpdateOptions): Promise<number>;
307
+
308
+ /**
309
+ * 删除数据(兼容版本)
310
+ */
158
311
  delData(options: DeleteOptions): Promise<number>;
312
+
313
+ // ============================================
314
+ // 通用方法
315
+ // ============================================
316
+
317
+ /**
318
+ * 执行事务
319
+ * @template T - 事务返回类型
320
+ */
159
321
  trans<T = any>(callback: TransactionCallback<T>): Promise<T>;
322
+
323
+ /**
324
+ * 执行原始 SQL
325
+ */
160
326
  query(sql: string, params?: any[]): Promise<any>;
327
+
328
+ /**
329
+ * 检查数据是否存在
330
+ */
331
+ exists(options: Omit<QueryOptions, 'fields' | 'orderBy' | 'page' | 'limit'>): Promise<boolean>;
332
+
333
+ /**
334
+ * 检查表是否存在
335
+ */
336
+ tableExists(tableName: string): Promise<boolean>;
337
+
338
+ /**
339
+ * 批量插入数据
340
+ */
341
+ insBatch(table: string, dataList: Record<string, any>[]): Promise<number[]>;
342
+
343
+ /**
344
+ * 禁用数据(设置 state=2)
345
+ */
346
+ disableData(options: Omit<DeleteOptions, 'hard'>): Promise<number>;
347
+
348
+ /**
349
+ * 启用数据(设置 state=1)
350
+ */
351
+ enableData(options: Omit<DeleteOptions, 'hard'>): Promise<number>;
352
+
353
+ /**
354
+ * 硬删除数据(物理删除)
355
+ */
356
+ delForce(options: Omit<DeleteOptions, 'hard'>): Promise<number>;
357
+
358
+ /**
359
+ * 自增字段
360
+ */
361
+ increment(table: string, field: string, where: WhereConditions, value?: number): Promise<number>;
362
+
363
+ /**
364
+ * 自减字段
365
+ */
366
+ decrement(table: string, field: string, where: WhereConditions, value?: number): Promise<number>;
367
+
368
+ /**
369
+ * 查询单个字段值
370
+ */
371
+ getFieldValue<T = any>(options: Omit<QueryOptions, 'fields'> & { field: string }): Promise<T | null>;
372
+
373
+ /**
374
+ * 清理数据或 where 条件(默认排除 null 和 undefined)
375
+ */
376
+ cleanFields<T extends Record<string, any>>(data: T, excludeValues?: any[], keepValues?: Record<string, any>): Partial<T>;
161
377
  }
162
378
 
163
379
  /**
package/types/index.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  /**
2
2
  * 类型定义导出
3
+ *
4
+ * 注意:通用类型已迁移到 befly-shared/types
5
+ * - addon, crypto, jwt, logger, tool 等类型请从 befly-shared/types 导入
3
6
  */
4
7
 
5
- export * from './addon.js';
6
8
  export * from './api.js';
7
9
  export * from './befly.js';
10
+ export * from './cache.js';
8
11
  export * from './common.js';
9
12
  export * from './context.js';
10
- export * from './crypto.js';
11
13
  export * from './database.js';
12
- export * from './jwt.js';
13
- export * from './logger.js';
14
+ export * from './hook.js';
14
15
  export * from './plugin.js';
15
16
  export * from './redis.js';
16
- export * from './tool.js';
17
+ export * from './table.js';
17
18
  export * from './validator.js';
18
19
  export * from './sync.js';
package/types/plugin.d.ts CHANGED
@@ -28,14 +28,11 @@ export interface Plugin {
28
28
  after?: string[];
29
29
 
30
30
  /** 插件初始化函数 */
31
- handler?: (context: BeflyContext, config?: Record<string, any>) => any | Promise<any>;
31
+ handler?: (context: BeflyContext) => any | Promise<any>;
32
32
 
33
33
  /** @deprecated use handler instead */
34
34
  onInit?: PluginInitFunction;
35
35
 
36
- /** 插件配置 */
37
- config?: Record<string, any>;
38
-
39
36
  /** 插件描述 */
40
37
  description?: string;
41
38
 
package/types/redis.d.ts CHANGED
@@ -23,14 +23,13 @@ export type RedisTTL = number | null;
23
23
  * Redis 助手接口
24
24
  */
25
25
  export interface RedisHelper {
26
+ // ==================== 基础操作 ====================
26
27
  /** 设置对象到 Redis */
27
28
  setObject<T = any>(key: string, obj: T, ttl?: RedisTTL): Promise<string | null>;
28
29
  /** 从 Redis 获取对象 */
29
30
  getObject<T = any>(key: string): Promise<T | null>;
30
31
  /** 从 Redis 删除对象 */
31
32
  delObject(key: string): Promise<void>;
32
- /** 生成基于时间的唯一 ID */
33
- genTimeID(): Promise<number>;
34
33
  /** 设置字符串值 */
35
34
  setString(key: string, value: string, ttl?: RedisTTL): Promise<string | null>;
36
35
  /** 获取字符串值 */
@@ -41,6 +40,42 @@ export interface RedisHelper {
41
40
  expire(key: string, seconds: number): Promise<number>;
42
41
  /** 获取剩余过期时间 */
43
42
  ttl(key: string): Promise<number>;
43
+ /** 删除键 */
44
+ del(key: string): Promise<number>;
44
45
  /** 测试 Redis 连接 */
45
46
  ping(): Promise<string>;
47
+
48
+ // ==================== ID 生成 ====================
49
+ /** 生成基于时间的唯一 ID (14位纯数字) */
50
+ genTimeID(): Promise<number>;
51
+ /** 批量生成基于时间的唯一 ID */
52
+ genTimeIDBatch(count: number): Promise<number[]>;
53
+
54
+ // ==================== Set 操作 ====================
55
+ /** 向 Set 中添加一个或多个成员 */
56
+ sadd(key: string, members: string[]): Promise<number>;
57
+ /** 判断成员是否在 Set 中 */
58
+ sismember(key: string, member: string): Promise<number>;
59
+ /** 获取 Set 的成员数量 */
60
+ scard(key: string): Promise<number>;
61
+ /** 获取 Set 的所有成员 */
62
+ smembers(key: string): Promise<string[]>;
63
+
64
+ // ==================== 批量操作 ====================
65
+ /** 批量设置对象 */
66
+ setBatch<T = any>(items: Array<{ key: string; value: T; ttl?: number | null }>): Promise<number>;
67
+ /** 批量获取对象 */
68
+ getBatch<T = any>(keys: string[]): Promise<Array<T | null>>;
69
+ /** 批量删除键 */
70
+ delBatch(keys: string[]): Promise<number>;
71
+ /** 批量检查键是否存在 */
72
+ existsBatch(keys: string[]): Promise<boolean[]>;
73
+ /** 批量设置过期时间 */
74
+ expireBatch(items: Array<{ key: string; seconds: number }>): Promise<number>;
75
+ /** 批量获取剩余过期时间 */
76
+ ttlBatch(keys: string[]): Promise<number[]>;
77
+ /** 批量向多个 Set 添加成员 */
78
+ saddBatch(items: Array<{ key: string; members: string[] }>): Promise<number>;
79
+ /** 批量检查成员是否在 Set 中 */
80
+ sismemberBatch(items: Array<{ key: string; member: string }>): Promise<boolean[]>;
46
81
  }