@maiyunnet/kebab 7.10.0 → 7.10.2
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/doc/kebab-rag.md +9 -3
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/session.d.ts +4 -4
- package/lib/session.js +21 -21
- package/lib/text.d.ts +1 -1
- package/package.json +12 -8
package/doc/kebab-rag.md
CHANGED
|
@@ -1385,7 +1385,7 @@ index/variables/VER.md
|
|
|
1385
1385
|
|
|
1386
1386
|
# Variable: VER
|
|
1387
1387
|
|
|
1388
|
-
> `const` **VER**: `"7.10.
|
|
1388
|
+
> `const` **VER**: `"7.10.2"` = `'7.10.2'`
|
|
1389
1389
|
|
|
1390
1390
|
Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
|
|
1391
1391
|
|
|
@@ -15528,12 +15528,18 @@ lib/text/functions/parseJson.md
|
|
|
15528
15528
|
|
|
15529
15529
|
# Function: parseJson()
|
|
15530
15530
|
|
|
15531
|
-
> **parseJson
|
|
15531
|
+
> **parseJson**\<`T`\>(`str`): `false` \| `T`
|
|
15532
15532
|
|
|
15533
15533
|
Defined in: [lib/text.ts:550](https://github.com/maiyunnet/kebab/blob/master/lib/text.ts#L550)
|
|
15534
15534
|
|
|
15535
15535
|
将字符串解析为对象,返回 false 代表解析失败,支持 BigInt
|
|
15536
15536
|
|
|
15537
|
+
## Type Parameters
|
|
15538
|
+
|
|
15539
|
+
### T
|
|
15540
|
+
|
|
15541
|
+
`T`
|
|
15542
|
+
|
|
15537
15543
|
## Parameters
|
|
15538
15544
|
|
|
15539
15545
|
### str
|
|
@@ -15544,7 +15550,7 @@ Defined in: [lib/text.ts:550](https://github.com/maiyunnet/kebab/blob/master/lib
|
|
|
15544
15550
|
|
|
15545
15551
|
## Returns
|
|
15546
15552
|
|
|
15547
|
-
`
|
|
15553
|
+
`false` \| `T`
|
|
15548
15554
|
|
|
15549
15555
|
lib/text/functions/parseUrl.md
|
|
15550
15556
|
---
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '7.10.
|
|
9
|
+
export const VER = '7.10.1';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/session.d.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Date: 2019-6-5 22:01:40
|
|
4
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
|
-
import * as
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
6
|
+
import * as lDb from '#kebab/lib/db.js';
|
|
7
|
+
import * as lKv from '#kebab/lib/kv.js';
|
|
8
|
+
import * as sCtr from '#kebab/sys/ctr.js';
|
|
9
9
|
export interface IOptions {
|
|
10
10
|
'name'?: string;
|
|
11
11
|
'ttl'?: number;
|
|
@@ -33,7 +33,7 @@ export declare class Session {
|
|
|
33
33
|
* @param opt 选项
|
|
34
34
|
* @returns false 表示系统错误
|
|
35
35
|
*/
|
|
36
|
-
init(ctr:
|
|
36
|
+
init(ctr: sCtr.Ctr, link: lDb.Pool | lKv.Kv, auth?: boolean, opt?: IOptions): Promise<boolean>;
|
|
37
37
|
/**
|
|
38
38
|
* --- 获取当前的 token 值 ---
|
|
39
39
|
*/
|
package/lib/session.js
CHANGED
|
@@ -17,12 +17,12 @@ CREATE TABLE `session` (
|
|
|
17
17
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
|
18
18
|
*/
|
|
19
19
|
// --- 库和定义 ---
|
|
20
|
-
import * as
|
|
21
|
-
import * as
|
|
22
|
-
import * as
|
|
23
|
-
import * as
|
|
24
|
-
import * as
|
|
25
|
-
import * as
|
|
20
|
+
import * as lCore from '#kebab/lib/core.js';
|
|
21
|
+
import * as lTime from '#kebab/lib/time.js';
|
|
22
|
+
import * as lDb from '#kebab/lib/db.js';
|
|
23
|
+
import * as lKv from '#kebab/lib/kv.js';
|
|
24
|
+
import * as lSql from '#kebab/lib/sql.js';
|
|
25
|
+
import * as lText from '#kebab/lib/text.js';
|
|
26
26
|
export class Session {
|
|
27
27
|
/** --- 数据库操作对象 --- */
|
|
28
28
|
_link;
|
|
@@ -49,7 +49,7 @@ export class Session {
|
|
|
49
49
|
const ssl = opt.ssl ?? config.session.ssl ?? false;
|
|
50
50
|
this._name = opt.name ?? config.session.name;
|
|
51
51
|
this._ttl = opt.ttl ?? config.session.ttl ?? 172800;
|
|
52
|
-
const tim =
|
|
52
|
+
const tim = lTime.stamp();
|
|
53
53
|
this._ctr = ctr;
|
|
54
54
|
if (auth) {
|
|
55
55
|
const a = ctr.getAuthorization();
|
|
@@ -62,8 +62,8 @@ export class Session {
|
|
|
62
62
|
this._token = cookie[this._name];
|
|
63
63
|
}
|
|
64
64
|
this._link = link;
|
|
65
|
-
if (link instanceof
|
|
66
|
-
this._sql =
|
|
65
|
+
if (link instanceof lDb.Pool) {
|
|
66
|
+
this._sql = lSql.get({
|
|
67
67
|
'service': link.getService(),
|
|
68
68
|
'ctr': ctr,
|
|
69
69
|
'pre': opt.sqlPre,
|
|
@@ -76,7 +76,7 @@ export class Session {
|
|
|
76
76
|
// --- 有 token 则查看 token 的信息是否存在
|
|
77
77
|
if (this._token !== '') {
|
|
78
78
|
// --- 如果启用了内存加速则在内存找 ---
|
|
79
|
-
if (this._link instanceof
|
|
79
|
+
if (this._link instanceof lKv.Kv) {
|
|
80
80
|
// --- Kv ---
|
|
81
81
|
const data = await this._link.getJson(this._name + '_' + this._token);
|
|
82
82
|
if (data === null) {
|
|
@@ -97,7 +97,7 @@ export class Session {
|
|
|
97
97
|
]);
|
|
98
98
|
const data = await this._link.query(this._sql.getSql(), this._sql.getData());
|
|
99
99
|
if (data.rows?.[0]) {
|
|
100
|
-
session =
|
|
100
|
+
session = lText.parseJson(data.rows[0].data);
|
|
101
101
|
}
|
|
102
102
|
else if (data.result === -500) {
|
|
103
103
|
return false;
|
|
@@ -117,13 +117,13 @@ export class Session {
|
|
|
117
117
|
// --- 数据库的 Session 已经过期加新 Session ---
|
|
118
118
|
// --- 如果不存在不允许加新则返回错误 ---
|
|
119
119
|
if (needInsert) {
|
|
120
|
-
if (this._link instanceof
|
|
120
|
+
if (this._link instanceof lKv.Kv) {
|
|
121
121
|
let count = 0;
|
|
122
122
|
do {
|
|
123
123
|
if (count === 5) {
|
|
124
124
|
return false;
|
|
125
125
|
}
|
|
126
|
-
this._token =
|
|
126
|
+
this._token = lCore.random(16, lCore.RANDOM_LUN);
|
|
127
127
|
++count;
|
|
128
128
|
} while (!await this._link.set(this._name + '_' + this._token, [], this._ttl, 'nx'));
|
|
129
129
|
}
|
|
@@ -133,7 +133,7 @@ export class Session {
|
|
|
133
133
|
if (count === 5) {
|
|
134
134
|
return false;
|
|
135
135
|
}
|
|
136
|
-
this._token =
|
|
136
|
+
this._token = lCore.random(16, lCore.RANDOM_LUN);
|
|
137
137
|
this._sql.insert('session').values({
|
|
138
138
|
'token': this._token,
|
|
139
139
|
'data': '{}',
|
|
@@ -153,7 +153,7 @@ export class Session {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
|
|
156
|
+
lCore.setCookie(ctr, this._name, this._token, {
|
|
157
157
|
'ttl': this._ttl,
|
|
158
158
|
'ssl': ssl
|
|
159
159
|
});
|
|
@@ -175,13 +175,13 @@ export class Session {
|
|
|
175
175
|
* --- 页面整体结束时,要写入到 Kv 或 数据库 ---
|
|
176
176
|
*/
|
|
177
177
|
async update() {
|
|
178
|
-
if (this._link instanceof
|
|
178
|
+
if (this._link instanceof lKv.Kv) {
|
|
179
179
|
await this._link.set(this._name + '_' + this._token, this._ctr.getPrototype('_session'), this._ttl);
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
182
|
this._sql.update('session', [{
|
|
183
|
-
'data':
|
|
184
|
-
'time_update':
|
|
183
|
+
'data': lText.stringifyJson(this._ctr.getPrototype('_session')),
|
|
184
|
+
'time_update': lTime.stamp(),
|
|
185
185
|
}]).where([{
|
|
186
186
|
'token': this._token
|
|
187
187
|
}]);
|
|
@@ -193,14 +193,14 @@ export class Session {
|
|
|
193
193
|
* --- 仅能在 Db 模式执行,非 Db 模式则等于没运行 ---
|
|
194
194
|
*/
|
|
195
195
|
async _gc() {
|
|
196
|
-
if (!(this._link instanceof
|
|
196
|
+
if (!(this._link instanceof lDb.Pool)) {
|
|
197
197
|
return;
|
|
198
198
|
}
|
|
199
|
-
if (
|
|
199
|
+
if (lCore.rand(0, 20) !== 10) {
|
|
200
200
|
return;
|
|
201
201
|
}
|
|
202
202
|
this._sql.delete('session').where([
|
|
203
|
-
['time_update', '<',
|
|
203
|
+
['time_update', '<', lTime.stamp() - this._ttl]
|
|
204
204
|
]);
|
|
205
205
|
await this._link.execute(this._sql.getSql(), this._sql.getData());
|
|
206
206
|
}
|
package/lib/text.d.ts
CHANGED
|
@@ -147,7 +147,7 @@ export declare function stringifyResult(rtn: kebab.Json): string;
|
|
|
147
147
|
* --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt ---
|
|
148
148
|
* @param str 要解析的 json 字符串
|
|
149
149
|
*/
|
|
150
|
-
export declare function parseJson(str: string):
|
|
150
|
+
export declare function parseJson<T>(str: string): T | false;
|
|
151
151
|
/**
|
|
152
152
|
* --- 将对象转换为 json 字符串,返回 false 代表解析失败,支持 BigInt ---
|
|
153
153
|
* @param obj 要转换的 json 对象
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiyunnet/kebab",
|
|
3
|
-
"version": "7.10.
|
|
3
|
+
"version": "7.10.2",
|
|
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": [
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"#kebab/*": "./*"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@aws-sdk/client-s3": "^3.
|
|
26
|
-
"@aws-sdk/lib-storage": "^3.
|
|
25
|
+
"@aws-sdk/client-s3": "^3.980.0",
|
|
26
|
+
"@aws-sdk/lib-storage": "^3.980.0",
|
|
27
27
|
"@litert/http-client": "^1.1.2",
|
|
28
28
|
"@litert/mime": "^0.1.3",
|
|
29
29
|
"@litert/redis": "^3.1.0",
|
|
@@ -32,21 +32,25 @@
|
|
|
32
32
|
"@zilliz/milvus2-sdk-node": "^2.6.9",
|
|
33
33
|
"ejs": "^4.0.1",
|
|
34
34
|
"jszip": "^3.10.1",
|
|
35
|
-
"mysql2": "^3.16.
|
|
35
|
+
"mysql2": "^3.16.2",
|
|
36
36
|
"node-cron": "^4.2.1",
|
|
37
|
-
"openai": "^6.
|
|
38
|
-
"pg": "^8.
|
|
37
|
+
"openai": "^6.17.0",
|
|
38
|
+
"pg": "^8.18.0",
|
|
39
39
|
"ssh2": "^1.17.0",
|
|
40
40
|
"svg-captcha": "^1.4.0",
|
|
41
|
-
"tencentcloud-sdk-nodejs": "^4.1.
|
|
41
|
+
"tencentcloud-sdk-nodejs": "^4.1.180"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@litert/eslint-plugin-rules": "^0.3.1",
|
|
45
45
|
"@types/ejs": "^3.1.5",
|
|
46
|
-
"@types/node": "^25.0
|
|
46
|
+
"@types/node": "^25.1.0",
|
|
47
47
|
"@types/pg": "^8.16.0",
|
|
48
48
|
"typedoc": "^0.28.16",
|
|
49
49
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
50
50
|
"typescript": "^5.9.3"
|
|
51
|
+
},
|
|
52
|
+
"overrides": {
|
|
53
|
+
"fast-xml-parser": "^5.3.4",
|
|
54
|
+
"@grpc/grpc-js": "^1.14.3"
|
|
51
55
|
}
|
|
52
56
|
}
|