@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/lib/scan.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2022-09-24 15:23:25
4
- * Last: 2022-09-24 15:23:25, 2022-9-26 12:37:01, 2022-12-29 00:11:16
4
+ * Last: 2022-09-24 15:23:25, 2022-9-26 12:37:01, 2022-12-29 00:11:16, 2025-11-6 16:32:05
5
5
  */
6
6
  import * as lDb from '#kebab/lib/db.js';
7
7
  import * as lKv from '#kebab/lib/kv.js';
@@ -25,7 +25,7 @@ export declare class Scan {
25
25
  private _token;
26
26
  /** --- 有效期,默认 5 分钟 --- */
27
27
  private _ttl;
28
- constructor(link: lDb.Pool | lKv.Pool, token?: string, opt?: IOptions);
28
+ constructor(link: lDb.Pool | lKv.Kv, token?: string, opt?: IOptions);
29
29
  /** --- 二维码剩余有效时间 --- */
30
30
  private _timeLeft;
31
31
  /**
@@ -65,14 +65,14 @@ export declare class Scan {
65
65
  * @param token Token
66
66
  * @param opt
67
67
  */
68
- export declare function get(link: lDb.Pool | lKv.Pool, token?: string, opt?: IOptions): Promise<Scan>;
68
+ export declare function get(link: lDb.Pool | lKv.Kv, token?: string, opt?: IOptions): Promise<Scan>;
69
69
  /**
70
70
  * --- 对 token 执行访问操作,通常用户扫码后展示的网页所调用,代表已扫码 ---
71
71
  * @param link
72
72
  * @patam token 必填
73
73
  * @param opt
74
74
  */
75
- export declare function scanned(link: lDb.Pool | lKv.Pool, token: string, opt?: IStaticOptions): Promise<boolean>;
75
+ export declare function scanned(link: lDb.Pool | lKv.Kv, token: string, opt?: IStaticOptions): Promise<boolean>;
76
76
  /**
77
77
  * --- 将数据写入 token,通常在客户的逻辑下去写,服务器会 poll 到 ---
78
78
  * @param link
@@ -80,4 +80,4 @@ export declare function scanned(link: lDb.Pool | lKv.Pool, token: string, opt?:
80
80
  * @param data
81
81
  * @param opt
82
82
  */
83
- export declare function setData(link: lDb.Pool | lKv.Pool, token: string, data: Record<string, any> | string | number, opt?: IStaticOptions): Promise<boolean>;
83
+ export declare function setData(link: lDb.Pool | lKv.Kv, token: string, data: Record<string, any> | string | number, opt?: IStaticOptions): Promise<boolean>;
package/lib/scan.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2022-09-24 15:23:25
4
- * Last: 2022-09-24 15:23:25, 2022-9-26 12:37:01, 2022-12-29 00:11:16
4
+ * Last: 2022-09-24 15:23:25, 2022-9-26 12:37:01, 2022-12-29 00:11:16, 2025-11-6 16:32:05
5
5
  */
6
6
  /*
7
7
  CREATE TABLE IF NOT EXISTS `scan` (
@@ -191,7 +191,7 @@ export class Scan {
191
191
  * --- 根据情况清空 Db 状态下的 scan 表垃圾数据 ---
192
192
  */
193
193
  async _gc() {
194
- if (this._link instanceof lKv.Pool) {
194
+ if (this._link instanceof lKv.Kv) {
195
195
  return;
196
196
  }
197
197
  if (lCore.rand(0, 10) !== 5) {
package/lib/session.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2019-6-5 22:01:40
4
- * Last: 2020-3-30 00:11:15, 2022-12-29 00:10:28, 2023-5-24 18:59:27
4
+ * Last: 2020-3-30 00:11:15, 2022-12-29 00:10:28, 2023-5-24 18:59:27, 2025-11-6 16:32:11
5
5
  */
6
6
  import * as db from '#kebab/lib/db.js';
7
7
  import * as kv from '#kebab/lib/kv.js';
@@ -33,7 +33,7 @@ export declare class Session {
33
33
  * @param opt 选项
34
34
  * @returns false 表示系统错误
35
35
  */
36
- init(ctr: ctr.Ctr, link: db.Pool | kv.Pool, auth?: boolean, opt?: IOptions): Promise<boolean>;
36
+ init(ctr: ctr.Ctr, link: db.Pool | kv.Kv, auth?: boolean, opt?: IOptions): Promise<boolean>;
37
37
  /**
38
38
  * --- 获取当前的 token 值 ---
39
39
  */
package/lib/session.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2019-6-5 22:01:40
4
- * Last: 2020-3-30 00:11:15, 2022-12-29 00:10:28, 2023-5-24 18:59:27
4
+ * Last: 2020-3-30 00:11:15, 2022-12-29 00:10:28, 2023-5-24 18:59:27, 2025-11-6 16:32:11
5
5
  */
6
6
  /*
7
7
  * --- Mysql ---
@@ -67,7 +67,7 @@ export class Session {
67
67
  // --- 有 token 则查看 token 的信息是否存在
68
68
  if (this._token !== '') {
69
69
  // --- 如果启用了内存加速则在内存找 ---
70
- if (this._link instanceof kv.Pool) {
70
+ if (this._link instanceof kv.Kv) {
71
71
  // --- Kv ---
72
72
  const data = await this._link.getJson(this._name + '_' + this._token);
73
73
  if (data === null) {
@@ -108,7 +108,7 @@ export class Session {
108
108
  // --- 数据库的 Session 已经过期加新 Session ---
109
109
  // --- 如果不存在不允许加新则返回错误 ---
110
110
  if (needInsert) {
111
- if (this._link instanceof kv.Pool) {
111
+ if (this._link instanceof kv.Kv) {
112
112
  let count = 0;
113
113
  do {
114
114
  if (count === 5) {
@@ -166,7 +166,7 @@ export class Session {
166
166
  * --- 页面整体结束时,要写入到 Kv 或 数据库 ---
167
167
  */
168
168
  async update() {
169
- if (this._link instanceof kv.Pool) {
169
+ if (this._link instanceof kv.Kv) {
170
170
  await this._link.set(this._name + '_' + this._token, this._ctr.getPrototype('_session'), this._ttl);
171
171
  }
172
172
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "3.2.35",
3
+ "version": "4.0.0",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
package/sys/ctr.d.ts CHANGED
@@ -206,7 +206,7 @@ export declare class Ctr {
206
206
  * @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
207
207
  * @param opt name, ttl, ssl, sqlPre
208
208
  */
209
- protected _startSession(link: lDb.Pool | lKv.Pool, auth?: boolean, opt?: lSession.IOptions): Promise<boolean>;
209
+ protected _startSession(link: lDb.Pool | lKv.Kv, auth?: boolean, opt?: lSession.IOptions): Promise<boolean>;
210
210
  /**
211
211
  * --- 设定语言并加载语言包 ---
212
212
  * @param loc 要加载的目标语言
package/sys/master.js CHANGED
@@ -233,7 +233,7 @@ function createRpcListener() {
233
233
  if (!await lFs.isFile(path)) {
234
234
  res.end(lText.stringifyJson({
235
235
  'result': 1,
236
- 'data': false,
236
+ 'data': null,
237
237
  }));
238
238
  return;
239
239
  }
@@ -241,7 +241,7 @@ function createRpcListener() {
241
241
  let limit = msg.limit ?? 100;
242
242
  /** --- 剩余 offset --- */
243
243
  let offset = msg.offset ?? 0;
244
- const rtn = await new Promise((resolve) => {
244
+ const rtn = await new Promise(resolve => {
245
245
  const list = [];
246
246
  /** --- 当前行号 --- */
247
247
  let line = 0;
@@ -1357,14 +1357,14 @@ exec: ${JSON.stringify(exec)}<br><br>`);
1357
1357
  return echo.join('') + '<br>' + this._getEnd();
1358
1358
  }
1359
1359
  async kv() {
1360
- const kv = lKv.get(this);
1361
- if (!await kv.ping()) {
1360
+ const kv = await lKv.get(this);
1361
+ if (!kv) {
1362
1362
  return [0, 'Failed.'];
1363
1363
  }
1364
1364
  const value = this._get['value'] ?? '';
1365
1365
  const ac = this._get['ac'] ?? '';
1366
- const echo = [`<pre>const kv = lKv.get(this);
1367
- if (!await kv.ping()) {
1366
+ const echo = [`<pre>const kv = await lKv.get(this);
1367
+ if (!kv) {
1368
1368
  return [0, 'Failed.'];
1369
1369
  }
1370
1370
  JSON.stringify(await kv.ping());</pre>${JSON.stringify(await kv.ping())}`];
@@ -2103,8 +2103,8 @@ function confirm() {
2103
2103
  link = db;
2104
2104
  }
2105
2105
  else {
2106
- const kv = lKv.get(this);
2107
- if (!await kv.ping()) {
2106
+ const kv = await lKv.get(this);
2107
+ if (!kv) {
2108
2108
  return false;
2109
2109
  }
2110
2110
  link = kv;
@@ -2127,11 +2127,11 @@ function confirm() {
2127
2127
  echo.push('link = lDb.get(this);\n');
2128
2128
  }
2129
2129
  else {
2130
- link = lKv.get(this);
2131
- if (!await link.ping()) {
2130
+ link = await lKv.get(this);
2131
+ if (!link) {
2132
2132
  return [0, 'Failed, Redis can not be connected.'];
2133
2133
  }
2134
- echo.push('link = lKv.get(this);\n');
2134
+ echo.push('link = await lKv.get(this);\n');
2135
2135
  }
2136
2136
  if (this._get['auth'] === '') {
2137
2137
  const r = await this._startSession(link, false, { 'ttl': 60 });
@@ -2181,8 +2181,11 @@ Result:<pre id="result">Nothing.</pre>`);
2181
2181
  const echo = ['<pre>'];
2182
2182
  let link = undefined;
2183
2183
  if (this._get['type'] === 'kv') {
2184
- link = lKv.get(this);
2185
- echo.push('link = lKv.get(this);\n');
2184
+ link = await lKv.get(this);
2185
+ if (!link) {
2186
+ return [0, 'Failed, Redis can not be connected.'];
2187
+ }
2188
+ echo.push('link = await lKv.get(this);\n');
2186
2189
  }
2187
2190
  const origin = lJwt.getOrigin(this);
2188
2191
  echo.push(`const origin = lJwt.getOrigin(this);