@maiyunnet/kebab 3.2.35 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "3.2.35";
8
+ export declare const VER = "4.0.0";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '3.2.35';
9
+ export const VER = '4.0.0';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/core.d.ts CHANGED
@@ -193,7 +193,7 @@ export declare function log(opt: sCtr.Ctr | ILogOptions, msg: string, fend?: str
193
193
  * @param opt 参数
194
194
  */
195
195
  export declare function getLog(opt: {
196
- /** --- 127.0.0.1 --- */
196
+ /** --- 要查询的头,如 127.0.0.1、system、www.maiyun.net --- */
197
197
  'hostname': string;
198
198
  /** --- 如 2024/08/01/22 --- */
199
199
  'path': string;
package/lib/core.js CHANGED
@@ -681,11 +681,15 @@ export async function getLog(opt) {
681
681
  });
682
682
  const content = await res.getContent();
683
683
  if (!content) {
684
+ // --- 连接失败,系统错误 ---
685
+ debug('[CORE][getLog] rpc server error');
684
686
  return false;
685
687
  }
686
688
  const str = content.toString();
687
689
  const j = lText.parseJson(str);
688
690
  if (!j) {
691
+ // --- 解析失败,系统错误 ---
692
+ debug('[CORE][getLog] rpc server content error');
689
693
  return false;
690
694
  }
691
695
  return j.data;
@@ -782,7 +786,7 @@ export function debug(message, ...optionalParams) {
782
786
  return;
783
787
  }
784
788
  // eslint-disable-next-line no-console
785
- console.debug(message, ...optionalParams);
789
+ console.debug(`KE-DEBUG ${lTime.format(null, 'Y-m-d H:i:s')}`, message, ...optionalParams);
786
790
  }
787
791
  /**
788
792
  * --- 向控制台直接显示内容,一般情况下禁止使用 ---
package/lib/db.js CHANGED
@@ -186,8 +186,8 @@ export class Pool {
186
186
  break;
187
187
  }
188
188
  catch (err) {
189
- if (err.message === 'ETIMEOUT') {
190
- lCore.debug('[DB][_getConnection][ETIMEOUT]', err);
189
+ if (err.message === 'ETIMEOUT' || err.message === 'EHOSTUNREACH') {
190
+ lCore.debug('[DB][_getConnection][TIMEOUT|HOSTUNREACH]', err);
191
191
  await lCore.sleep(300);
192
192
  continue;
193
193
  }
package/lib/jwt.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2023-1-31 20:34:47
4
- * Last: 2023-1-31 20:34:47, 2023-12-8 13:55:09
4
+ * Last: 2023-1-31 20:34:47, 2023-12-8 13:55:09, 2025-11-6 16:22:06
5
5
  */
6
6
  import * as kebab from '#kebab/index.js';
7
7
  import * as lKv from '#kebab/lib/kv.js';
@@ -35,7 +35,7 @@ export declare class Jwt {
35
35
  * @param auth 设为 true 则优先从头 Authorization 或 post _auth 值读取 token
36
36
  * @param opt 选项
37
37
  */
38
- init(ctr: sCtr.Ctr, opt?: IOptions, link?: lKv.Pool): Promise<boolean>;
38
+ init(ctr: sCtr.Ctr, opt?: IOptions, link?: lKv.Kv): Promise<boolean>;
39
39
  /**
40
40
  * --- 将 _jwt 数据封装并返回(创建新的或者续期老的 token),默认会同时设置一个 cookie(data 值会自动设置 token、exp) ---
41
41
  */
@@ -60,14 +60,14 @@ export declare function getOrigin(ctr: sCtr.Ctr, name?: string, auth?: boolean):
60
60
  * --- decode ---
61
61
  * 不传入 link 的话,将不做 block 有效校验,只做本身的 exp 有效校验
62
62
  */
63
- export declare function decode(ctr: sCtr.Ctr, val: string, link?: lKv.Pool, name?: string, secret?: string): Promise<Record<string, kebab.DbValue> | false>;
63
+ export declare function decode(ctr: sCtr.Ctr, val: string, link?: lKv.Kv, name?: string, secret?: string): Promise<Record<string, kebab.DbValue> | false>;
64
64
  /**
65
65
  * --- 仅往 redis 写禁止相关 token 的数据,一般用于异步通知时在异处的服务器来调用的 ---
66
66
  */
67
- export declare function block(ctr: sCtr.Ctr, token: string, exp: number, link: lKv.Pool, name?: string): Promise<boolean>;
67
+ export declare function block(ctr: sCtr.Ctr, token: string, exp: number, link: lKv.Kv, name?: string): Promise<boolean>;
68
68
  /**
69
69
  * @param ctr 模型实例
70
70
  * @param opt name, ttl, ssl, secret, auth: false, true 则优先从头 Authorization 或 post _auth 值读取 token
71
71
  * @param link 实例
72
72
  */
73
- export declare function get(ctr: sCtr.Ctr, opt?: IOptions, link?: lKv.Pool): Promise<Jwt>;
73
+ export declare function get(ctr: sCtr.Ctr, opt?: IOptions, link?: lKv.Kv): Promise<Jwt>;
package/lib/jwt.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2023-1-31 20:34:47
4
- * Last: 2023-1-31 20:34:47, 2023-12-8 13:55:09
4
+ * Last: 2023-1-31 20:34:47, 2023-12-8 13:55:09, 2025-11-6 16:22:06
5
5
  */
6
6
  import * as lCore from '#kebab/lib/core.js';
7
7
  import * as lTime from '#kebab/lib/time.js';
package/lib/kv.d.ts CHANGED
@@ -1,24 +1,22 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2019-5-30 19:25:22
4
- * Last: 2020-3-28 18:54:04, 2022-09-12 23:24:45, 2022-09-22 01:06:22, 2024-2-21 13:32:56, 2024-8-21 16:59:57
4
+ * Last: 2020-3-28 18:54:04, 2022-09-12 23:24:45, 2022-09-22 01:06:22, 2024-2-21 13:32:56, 2024-8-21 16:59:57, 2025-11-6 14:56:45
5
5
  */
6
6
  import * as redis from '@litert/redis';
7
- import * as kebab from '#kebab/index.js';
8
7
  import * as sCtr from '#kebab/sys/ctr.js';
9
- /** --- 连接信息 --- */
10
- export interface IConnectionInfo {
11
- 'id': number;
12
- 'last': number;
13
- 'host': string;
14
- 'port': number;
15
- 'index': number;
16
- 'lost': boolean;
17
- }
18
- export declare class Pool {
19
- /** --- 当前 Pool 对象的 kv 连接信息 --- */
20
- private readonly _etc;
8
+ export declare class Kv {
9
+ /** --- pre --- */
10
+ private readonly _pre;
11
+ /** --- 当前连接的 db index --- */
12
+ private readonly _index;
13
+ /** --- kv 连接对象 --- */
14
+ private readonly _link;
15
+ /** --- 获取之时是新 redis 链接还是老链接 --- */
16
+ private readonly _new;
21
17
  constructor(ctr: sCtr.Ctr, etc?: IOptions);
18
+ /** --- 初始化连接 --- */
19
+ init(ctr: sCtr.Ctr, etc?: IOptions): Promise<boolean>;
22
20
  /**
23
21
  * --- 设定一个值 ---
24
22
  * @param key
@@ -39,6 +37,7 @@ export declare class Pool {
39
37
  * @param key
40
38
  * @param val
41
39
  * @param ttl 秒,0 为不限制
40
+ * @param etc
42
41
  */
43
42
  replace(key: string, val: object | string | number, ttl?: number): Promise<boolean>;
44
43
  /**
@@ -55,12 +54,13 @@ export declare class Pool {
55
54
  prepend(key: string, val: string): Promise<boolean>;
56
55
  /**
57
56
  * --- 检测 key 是否存在 ---
58
- * @param keys
57
+ * @param keys 单个或序列
59
58
  */
60
59
  exists(keys: string | string[]): Promise<number>;
61
60
  /**
62
61
  * --- 获取字符串 ---
63
62
  * @param key
63
+ * @returns 字符串 / false / null(即使存入时是 number,这个方法也只会返回字符串)
64
64
  */
65
65
  get(key: string): Promise<string | false | null>;
66
66
  /**
@@ -77,16 +77,17 @@ export declare class Pool {
77
77
  * --- 批量获取值 ---
78
78
  * @param keys key 序列
79
79
  */
80
- mSet(rows: Record<string, string | Buffer>): Promise<boolean>;
80
+ mGet(keys: string[]): Promise<Record<string, string | null>>;
81
81
  /**
82
- * --- 批量获取值 ---
83
- * @param keys key 序列
82
+ * --- 批量设置哈希值 ---
83
+ * @param key key
84
+ * @param rows key / val 数组
85
+ * @param etc
84
86
  */
85
- mGet(keys: string[]): Promise<Record<string, string | null>>;
87
+ mSet(rows: Record<string, string | Buffer>): Promise<boolean>;
86
88
  /**
87
89
  * --- 获取 json 对象 ---
88
90
  * @param key
89
- * @returns false 表示系统错误, null 表示不存在, 其他值为 json 对象
90
91
  */
91
92
  getJson(key: string): Promise<any | false | null>;
92
93
  /**
@@ -130,8 +131,9 @@ export declare class Pool {
130
131
  flushDb(): Promise<boolean>;
131
132
  /**
132
133
  * --- 发送 ping ---
134
+ * @param last 是否刷新最后使用时间(默认刷新)
133
135
  */
134
- ping(): Promise<string | false>;
136
+ ping(): Promise<false | string>;
135
137
  /**
136
138
  * --- 设置哈希表值 ---
137
139
  * @param key key 名
@@ -201,279 +203,19 @@ export declare class Pool {
201
203
  bRPop(key: string | string[], timeout: number): Promise<Record<string, string>>;
202
204
  lRange(key: string, start: number, stop: number): Promise<string[]>;
203
205
  lLen(key: string): Promise<number>;
204
- /**
205
- * --- 从连接池获取一个连接,会被自动设置为使用中,需要在执行命令后解除占用 ---
206
- */
207
- private _getConnection;
208
- }
209
- export declare class Connection {
210
- /** --- 本连接最后一次使用时间 --- */
211
- private _last;
212
- /** --- kv 缓存连接对象 --- */
213
- private readonly _link;
214
- /** --- 当前连接是否正在被独占使用 --- */
215
- private _using;
216
- /** --- 当发生断开,则需从连接池移除连接 --- */
217
- private _lost;
218
- /** --- 当前的连接配置信息 --- */
219
- private readonly _etc;
220
- constructor(etc: kebab.IConfigKv, link: redis.ICommandClient);
221
- /**
222
- * --- 获取连接 etc 信息 ---
223
- */
224
- getEtc(): kebab.IConfigKv;
225
- /**
226
- * --- 获取最后一次获取连接的时间 ---
227
- */
228
- getLast(): number;
229
- /**
230
- * --- 将本条连接设置为不可用 ---
231
- */
232
- setLost(): void;
233
- /**
234
- * --- 是否已经丢失 ---
235
- */
236
- isLost(): boolean;
237
- /**
238
- * --- 将本条连接设置占用中 ---
239
- */
240
- setUsing(): void;
241
- /**
242
- * --- 获取当前状态是否正在被使用中 ---
243
- */
244
- isUsing(): boolean;
245
- /**
246
- * --- 取消占用 ---
247
- */
248
- used(): void;
249
- /**
250
- * --- 设定最后使用时间 ---
251
- */
252
- refreshLast(): void;
253
- /**
254
- * --- 断开此连接,一般情况下不使用 ---
255
- */
256
- end(): Promise<void>;
257
- /**
258
- * --- 设定一个值 ---
259
- * @param key
260
- * @param val
261
- * @param ttl 秒,0 为不限制
262
- * @param mod 设置模式: 空,nx(key不存在才建立),xx(key存在才修改)
263
- * @param etc 配置项,主要用 etc.pre
264
- */
265
- set(key: string, val: object | string | number, ttl: number, mod: '' | 'nx' | 'xx', etc: kebab.IConfigKv): Promise<boolean>;
266
- /**
267
- * --- 添加一个值,存在则不变 ---
268
- * @param key
269
- * @param val
270
- * @param ttl 秒,0 为不限制
271
- * @param etc
272
- */
273
- add(key: string, val: object | string | number, ttl: number, etc: kebab.IConfigKv): Promise<boolean>;
274
- /**
275
- * --- 替换一个存在的值 ---
276
- * @param key
277
- * @param val
278
- * @param ttl 秒,0 为不限制
279
- * @param etc
280
- */
281
- replace(key: string, val: object | string | number, ttl: number, etc: kebab.IConfigKv): Promise<boolean>;
282
- /**
283
- * --- 向已存在的值后追加数据 ---
284
- * @param key
285
- * @param val
286
- * @param etc
287
- */
288
- append(key: string, val: string, etc: kebab.IConfigKv): Promise<boolean>;
289
- /**
290
- * --- 向已存在的值之前追加数据 ---
291
- * @param key
292
- * @param val
293
- */
294
- prepend(key: string, val: string, etc: kebab.IConfigKv): Promise<boolean>;
295
- /**
296
- * --- 检测 key 是否存在 ---
297
- * @param keys 单个或序列
298
- * @param etc
299
- */
300
- exists(keys: string | string[], etc: kebab.IConfigKv): Promise<number>;
301
- /**
302
- * --- 获取字符串 ---
303
- * @param key
304
- * @param etc
305
- * @returns 字符串 / false / null(即使存入时是 number,这个方法也只会返回字符串)
306
- */
307
- get(key: string, etc: kebab.IConfigKv): Promise<string | false | null>;
308
- /**
309
- * --- 获取相应的剩余有效期秒数 ---
310
- * @param key
311
- * @param etc
312
- */
313
- ttl(key: string, etc: kebab.IConfigKv): Promise<number | null>;
314
- /**
315
- * --- 获取相应的剩余有效期毫秒数 ---
316
- * @param key
317
- * @param etc
318
- */
319
- pttl(key: string, etc: kebab.IConfigKv): Promise<number | null>;
320
- /**
321
- * --- 批量获取值 ---
322
- * @param keys key 序列
323
- * @param etc 顺序数组
324
- */
325
- mGet(keys: string[], etc: kebab.IConfigKv): Promise<Record<string, string | null>>;
326
- /**
327
- * --- 批量设置哈希值 ---
328
- * @param key key 名
329
- * @param rows key / val 数组
330
- * @param etc
331
- */
332
- mSet(rows: Record<string, string | Buffer>, etc: kebab.IConfigKv): Promise<boolean>;
333
- /**
334
- * --- 获取 json 对象 ---
335
- * @param key
336
- * @param etc
337
- */
338
- getJson(key: string, etc: kebab.IConfigKv): Promise<any | false | null>;
339
- /**
340
- * --- 删除已存在的值 ---
341
- * @param keys
342
- * @param etc
343
- */
344
- del(keys: string | string[], etc: kebab.IConfigKv): Promise<boolean>;
345
- /**
346
- * --- 自增 ---
347
- * @param key
348
- * @param num 整数或浮点正数
349
- * @param etc
350
- */
351
- incr(key: string, num: number, etc: kebab.IConfigKv): Promise<number | false>;
352
- /**
353
- * --- 自减 ---
354
- * @param key
355
- * @param num 整数或浮点正数
356
- * @param etc
357
- */
358
- decr(key: string, num: number, etc: kebab.IConfigKv): Promise<number | false>;
359
- /**
360
- * --- 仅修改过期时间不修改值 ---
361
- * @param key
362
- * @param ttl
363
- * @param etc
364
- */
365
- expire(key: string, ttl: number, etc: kebab.IConfigKv): Promise<boolean>;
366
- /**
367
- * --- 获取服务器上的所有 key 列表 ---
368
- * @param pattern
369
- */
370
- keys(pattern: string, etc: kebab.IConfigKv): Promise<string[] | false>;
371
- /**
372
- * --- 根据条件获取服务器上的 keys ---
373
- * @param cursor
374
- * @param pattern 例如 *
375
- * @param count 获取的条数
376
- * @param etc
377
- */
378
- scan(cursor: number, pattern: string, count: number, etc: kebab.IConfigKv): Promise<redis.IScanResult<string> | false>;
379
- /**
380
- * --- 清除当前所选数据库的所有内容 ---
381
- */
382
- flushDb(): Promise<boolean>;
383
- /**
384
- * --- 发送 ping ---
385
- * @param last 是否刷新最后使用时间(默认刷新)
386
- */
387
- ping(last?: boolean): Promise<false | string>;
388
- /**
389
- * --- 设置哈希表值 ---
390
- * @param key key 名
391
- * @param field 字段名
392
- * @param val 值
393
- * @param mod 空,nx(key不存在才建立)
394
- * @param etc
395
- */
396
- hSet(key: string, field: string, val: object | string | number, mod: '' | 'nx', etc: kebab.IConfigKv): Promise<boolean>;
397
- /**
398
- * --- 批量设置哈希值 ---
399
- * @param key key 名
400
- * @param rows key / val 数组
401
- * @param etc
402
- */
403
- hMSet(key: string, rows: Record<string, object | string | number>, etc: kebab.IConfigKv): Promise<boolean>;
404
- /**
405
- * --- 获取哈希值 ---
406
- * @param key
407
- * @param field
408
- * @param etc
409
- */
410
- hGet(key: string, field: string, etc: kebab.IConfigKv): Promise<string | null>;
411
- /**
412
- * --- 获取哈希 json 对象 ---
413
- * @param key
414
- * @param field
415
- * @param etc
416
- */
417
- hGetJson(key: string, field: string, etc: kebab.IConfigKv): Promise<any | null>;
418
- /**
419
- * --- 批量获取哈希值 ---
420
- * @param key
421
- * @param fields
422
- * @param etc
423
- */
424
- hMGet(key: string, fields: string[], etc: kebab.IConfigKv): Promise<Record<string, string | null>>;
425
- /**
426
- * --- 批量获取哈希键值对 ---
427
- * @param key
428
- * @param etc
429
- */
430
- hGetAll(key: string, etc: kebab.IConfigKv): Promise<Record<string, string | null> | null>;
431
- /**
432
- * --- 删除哈希键 ---
433
- * @param key
434
- * @param fields 值序列
435
- * @param etc
436
- */
437
- hDel(key: string, fields: string | string[], etc: kebab.IConfigKv): Promise<number>;
438
- /**
439
- * --- 判断哈希字段是否存在 ---
440
- * @param key
441
- * @param field
442
- * @param etc
443
- */
444
- hExists(key: string, field: string, etc: kebab.IConfigKv): Promise<boolean>;
445
- /**
446
- * --- 设置哈希自增自减 ---
447
- * @param key key
448
- * @param field 字段
449
- * @param increment 正数或负数,整数或浮点
450
- * @param etc
451
- */
452
- hIncr(key: string, field: string, increment: number, etc: kebab.IConfigKv): Promise<number>;
453
- /**
454
- * --- 获取哈希所有字段 ---
455
- * @param key
456
- * @param etc
457
- */
458
- hKeys(key: string, etc: kebab.IConfigKv): Promise<string[]>;
459
- lPush(key: string, values: Array<string | Buffer>, etc: kebab.IConfigKv): Promise<number>;
460
- rPush(key: string, values: Array<string | Buffer>, etc: kebab.IConfigKv): Promise<number>;
461
- bLMove(sourceKey: string, destKey: string, soo: 'LEFT' | 'RIGHT', deo: 'LEFT' | 'RIGHT', timeout: number, etc: kebab.IConfigKv): Promise<string | null>;
462
- lPop(key: string, etc: kebab.IConfigKv): Promise<string | null>;
463
- rPop(key: string, etc: kebab.IConfigKv): Promise<string | null>;
464
- bRPop(key: string | string[], timeout: number, etc: kebab.IConfigKv): Promise<Record<string, string>>;
465
- lRange(key: string, start: number, stop: number, etc: kebab.IConfigKv): Promise<string[]>;
466
- lLen(key: string, etc: kebab.IConfigKv): Promise<number>;
467
206
  }
468
207
  /**
469
- * --- 获取 Kv Pool 对象 ---
208
+ * --- 获取 Kv 对象 ---
470
209
  * @param etc 配置信息可留空
471
210
  */
472
- export declare function get(ctr: sCtr.Ctr, etc?: IOptions): Pool;
473
- /**
474
- * --- 获取当前连接池中所有连接的信息 ---
475
- */
476
- export declare function getConnectionList(): IConnectionInfo[];
211
+ export declare function get(ctr: sCtr.Ctr, etc?: IOptions): Promise<Kv | false>;
212
+ /** --- 连接信息 --- */
213
+ export interface IConnectionInfo {
214
+ 'host': string;
215
+ 'port': number;
216
+ 'index': number;
217
+ 'link': redis.ICommandClient;
218
+ }
477
219
  /** --- 选项 --- */
478
220
  export interface IOptions {
479
221
  'host'?: string;