@maiyunnet/kebab 5.3.1 → 6.1.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/README.md +1 -1
- package/index.d.ts +2 -3
- package/index.js +6 -2
- package/lib/ai.d.ts +4 -3
- package/lib/ai.js +19 -11
- package/lib/buffer.d.ts +8 -4
- package/lib/buffer.js +16 -4
- package/lib/core.d.ts +24 -10
- package/lib/core.js +19 -12
- package/lib/crypto.d.ts +11 -2
- package/lib/crypto.js +6 -8
- package/lib/db/conn.js +1 -1
- package/lib/db.d.ts +5 -3
- package/lib/db.js +5 -3
- package/lib/dns.d.ts +17 -17
- package/lib/dns.js +44 -42
- package/lib/fs.d.ts +2 -2
- package/lib/fs.js +2 -2
- package/lib/kv.d.ts +49 -7
- package/lib/kv.js +69 -7
- package/lib/net/request.d.ts +1 -1
- package/lib/net.d.ts +6 -6
- package/lib/net.js +3 -3
- package/lib/scan.d.ts +3 -3
- package/lib/scan.js +3 -3
- package/lib/sql.d.ts +16 -5
- package/lib/sql.js +176 -257
- package/lib/ssh.d.ts +1 -2
- package/lib/text.d.ts +4 -4
- package/lib/text.js +2 -2
- package/lib/vector.d.ts +1 -1
- package/lib/vector.js +7 -7
- package/lib/ws.d.ts +0 -1
- package/lib/ws.js +0 -1
- package/lib/zip.d.ts +0 -1
- package/lib/zip.js +0 -1
- package/lib/zlib.d.ts +1 -2
- package/lib/zlib.js +1 -2
- package/package.json +13 -8
- package/sys/cmd.js +0 -7
- package/sys/ctr.d.ts +0 -2
- package/sys/ctr.js +0 -2
- package/sys/mod.d.ts +23 -9
- package/sys/mod.js +114 -12
- package/sys/route.js +0 -1
- package/www/example/ctr/test.d.ts +2 -2
- package/www/example/ctr/test.js +170 -93
- package/lib/jwt.d.ts +0 -73
- package/lib/jwt.js +0 -226
package/lib/dns.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-6-19
|
|
4
|
-
* Last: 2022-09-12 20:58:07, 2024-2-21 17:55:54, 2025-6-13 19:08:56
|
|
4
|
+
* Last: 2022-09-12 20:58:07, 2024-2-21 17:55:54, 2025-6-13 19:08:56, 2025-11-19 00:17:56
|
|
5
5
|
*/
|
|
6
|
-
import * as
|
|
6
|
+
import * as sCtr from '#kebab/sys/ctr.js';
|
|
7
7
|
/**
|
|
8
8
|
* 0.DNSPod:https://www.dnspod.cn/docs/index.html(腾讯云也请使用 DNSPod 的 API)
|
|
9
9
|
* 1.阿里云:https://help.aliyun.com/document_detail/29745.html
|
|
@@ -44,19 +44,19 @@ export interface IAddDomainRecord {
|
|
|
44
44
|
/**
|
|
45
45
|
* --- 记录值类型 ---
|
|
46
46
|
*/
|
|
47
|
-
export declare
|
|
48
|
-
A
|
|
49
|
-
NS
|
|
50
|
-
MX
|
|
51
|
-
TXT
|
|
52
|
-
CNAME
|
|
53
|
-
SRV
|
|
54
|
-
AAAA
|
|
55
|
-
}
|
|
47
|
+
export declare enum ERECORDTYPE {
|
|
48
|
+
'A' = 0,
|
|
49
|
+
'NS' = 1,
|
|
50
|
+
'MX' = 2,
|
|
51
|
+
'TXT' = 3,
|
|
52
|
+
'CNAME' = 4,
|
|
53
|
+
'SRV' = 5,
|
|
54
|
+
'AAAA' = 6
|
|
55
|
+
}
|
|
56
56
|
/**
|
|
57
57
|
* --- 记录值线路 ---
|
|
58
58
|
*/
|
|
59
|
-
export declare enum
|
|
59
|
+
export declare enum ERECORDLINE {
|
|
60
60
|
'DEFAULT' = 0,
|
|
61
61
|
'TELECOM' = 1,
|
|
62
62
|
'UNICOM' = 2,
|
|
@@ -67,7 +67,7 @@ export declare enum ERecordLine {
|
|
|
67
67
|
export declare class Dns {
|
|
68
68
|
/** --- 当前选项 --- */
|
|
69
69
|
private readonly _opt;
|
|
70
|
-
constructor(ctr:
|
|
70
|
+
constructor(ctr: sCtr.Ctr, opt: IOptions);
|
|
71
71
|
/**
|
|
72
72
|
* --- 最终发送 ---
|
|
73
73
|
* @param obj 要发送的信息
|
|
@@ -90,7 +90,7 @@ export declare class Dns {
|
|
|
90
90
|
'sub': string;
|
|
91
91
|
'type': string;
|
|
92
92
|
'value': string;
|
|
93
|
-
'line'?:
|
|
93
|
+
'line'?: ERECORDLINE;
|
|
94
94
|
'ttl'?: number;
|
|
95
95
|
'mx'?: number;
|
|
96
96
|
}): Promise<IAddDomainRecord | null>;
|
|
@@ -104,7 +104,7 @@ export declare class Dns {
|
|
|
104
104
|
'sub': string;
|
|
105
105
|
'type': string;
|
|
106
106
|
'value': string;
|
|
107
|
-
'line'?:
|
|
107
|
+
'line'?: ERECORDLINE;
|
|
108
108
|
'ttl'?: number;
|
|
109
109
|
'mx'?: number;
|
|
110
110
|
}): Promise<IAddDomainRecord | null>;
|
|
@@ -120,7 +120,7 @@ export declare class Dns {
|
|
|
120
120
|
} | null>;
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
|
-
* ---
|
|
123
|
+
* --- 创建一个 Dns 对象 ---
|
|
124
124
|
* @param opt 选项
|
|
125
125
|
*/
|
|
126
|
-
export declare function get(ctr:
|
|
126
|
+
export declare function get(ctr: sCtr.Ctr, opt: IOptions): Dns;
|
package/lib/dns.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-6-19
|
|
4
|
-
* Last: 2022-09-12 20:58:07, 2024-2-21 17:55:54, 2025-6-13 19:08:56
|
|
4
|
+
* Last: 2022-09-12 20:58:07, 2024-2-21 17:55:54, 2025-6-13 19:08:56, 2025-11-19 00:17:56
|
|
5
5
|
*/
|
|
6
6
|
// --- 库和定义 ---
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import * as
|
|
11
|
-
import * as
|
|
7
|
+
import * as lNet from '#kebab/lib/net.js';
|
|
8
|
+
import * as lCore from '#kebab/lib/core.js';
|
|
9
|
+
import * as lText from '#kebab/lib/text.js';
|
|
10
|
+
import * as lCrypto from '#kebab/lib/crypto.js';
|
|
11
|
+
import * as lResponse from '#kebab/lib/net/response.js';
|
|
12
12
|
/**
|
|
13
13
|
* 0.DNSPod:https://www.dnspod.cn/docs/index.html(腾讯云也请使用 DNSPod 的 API)
|
|
14
14
|
* 1.阿里云:https://help.aliyun.com/document_detail/29745.html
|
|
@@ -22,27 +22,28 @@ export var ESERVICE;
|
|
|
22
22
|
/**
|
|
23
23
|
* --- 记录值类型 ---
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
export var ERECORDTYPE;
|
|
26
|
+
(function (ERECORDTYPE) {
|
|
27
|
+
ERECORDTYPE[ERECORDTYPE["A"] = 0] = "A";
|
|
28
|
+
ERECORDTYPE[ERECORDTYPE["NS"] = 1] = "NS";
|
|
29
|
+
ERECORDTYPE[ERECORDTYPE["MX"] = 2] = "MX";
|
|
30
|
+
ERECORDTYPE[ERECORDTYPE["TXT"] = 3] = "TXT";
|
|
31
|
+
ERECORDTYPE[ERECORDTYPE["CNAME"] = 4] = "CNAME";
|
|
32
|
+
ERECORDTYPE[ERECORDTYPE["SRV"] = 5] = "SRV";
|
|
33
|
+
ERECORDTYPE[ERECORDTYPE["AAAA"] = 6] = "AAAA";
|
|
34
|
+
})(ERECORDTYPE || (ERECORDTYPE = {}));
|
|
34
35
|
/**
|
|
35
36
|
* --- 记录值线路 ---
|
|
36
37
|
*/
|
|
37
|
-
export var
|
|
38
|
-
(function (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})(
|
|
38
|
+
export var ERECORDLINE;
|
|
39
|
+
(function (ERECORDLINE) {
|
|
40
|
+
ERECORDLINE[ERECORDLINE["DEFAULT"] = 0] = "DEFAULT";
|
|
41
|
+
ERECORDLINE[ERECORDLINE["TELECOM"] = 1] = "TELECOM";
|
|
42
|
+
ERECORDLINE[ERECORDLINE["UNICOM"] = 2] = "UNICOM";
|
|
43
|
+
ERECORDLINE[ERECORDLINE["MOBILE"] = 3] = "MOBILE";
|
|
44
|
+
ERECORDLINE[ERECORDLINE["EDU"] = 4] = "EDU";
|
|
45
|
+
ERECORDLINE[ERECORDLINE["OVERSEA"] = 5] = "OVERSEA";
|
|
46
|
+
})(ERECORDLINE || (ERECORDLINE = {}));
|
|
46
47
|
const recordLine = {
|
|
47
48
|
[ESERVICE.DNSPOD]: [
|
|
48
49
|
'默认',
|
|
@@ -87,25 +88,26 @@ export class Dns {
|
|
|
87
88
|
}, obj);
|
|
88
89
|
const path = data['_path'];
|
|
89
90
|
delete data['_path'];
|
|
90
|
-
|
|
91
|
+
// --- 境外服务器请求的话 api 会自动解析到香港服务器 ---
|
|
92
|
+
return lNet.post('https://dnsapi.cn/' + path, data);
|
|
91
93
|
}
|
|
92
94
|
// --- 阿里云 ---
|
|
93
95
|
case ESERVICE.ALIBABA: {
|
|
94
|
-
const getData =
|
|
96
|
+
const getData = lCore.objectSort(Object.assign({
|
|
95
97
|
'Format': 'JSON',
|
|
96
98
|
'Version': '2015-01-09',
|
|
97
99
|
'AccessKeyId': this._opt.secretId,
|
|
98
100
|
'SignatureMethod': 'HMAC-SHA1',
|
|
99
101
|
'Timestamp': (new Date()).toISOString(),
|
|
100
102
|
'SignatureVersion': '1.0',
|
|
101
|
-
'SignatureNonce':
|
|
103
|
+
'SignatureNonce': lCore.rand(1000000000, 9999999999)
|
|
102
104
|
}, obj));
|
|
103
|
-
const urlRight =
|
|
104
|
-
const signature =
|
|
105
|
-
return
|
|
105
|
+
const urlRight = lText.queryStringify(getData);
|
|
106
|
+
const signature = lCrypto.hashHmac('sha1', `GET&${encodeURIComponent('/')}&${encodeURIComponent(urlRight)}`, (this._opt.secretKey ?? '') + '&', 'base64');
|
|
107
|
+
return lNet.get(`https://alidns.aliyuncs.com/?${urlRight}&Signature=${encodeURIComponent(signature)}`); // 境外 api 会自动调度到新加坡服务器
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
|
-
return new
|
|
110
|
+
return new lResponse.Response(null);
|
|
109
111
|
}
|
|
110
112
|
/**
|
|
111
113
|
* --- 获取域名列表 ---
|
|
@@ -124,7 +126,7 @@ export class Dns {
|
|
|
124
126
|
if (!res) {
|
|
125
127
|
return res;
|
|
126
128
|
}
|
|
127
|
-
const json =
|
|
129
|
+
const json = lText.parseJson(res.toString());
|
|
128
130
|
const r = {
|
|
129
131
|
'total': json.info.domain_total,
|
|
130
132
|
'list': []
|
|
@@ -151,7 +153,7 @@ export class Dns {
|
|
|
151
153
|
if (!res) {
|
|
152
154
|
return res;
|
|
153
155
|
}
|
|
154
|
-
const json =
|
|
156
|
+
const json = lText.parseJson(res.toString());
|
|
155
157
|
const r = {
|
|
156
158
|
'total': json.TotalCount,
|
|
157
159
|
'list': []
|
|
@@ -174,7 +176,7 @@ export class Dns {
|
|
|
174
176
|
* @param opt 参数
|
|
175
177
|
*/
|
|
176
178
|
async addDomainRecord(opt) {
|
|
177
|
-
const line = opt.line ??
|
|
179
|
+
const line = opt.line ?? ERECORDLINE.DEFAULT;
|
|
178
180
|
const ttl = opt.ttl ?? 600;
|
|
179
181
|
switch (this._opt.service) {
|
|
180
182
|
// --- DNSPod ---
|
|
@@ -193,7 +195,7 @@ export class Dns {
|
|
|
193
195
|
if (!res) {
|
|
194
196
|
return res;
|
|
195
197
|
}
|
|
196
|
-
const json =
|
|
198
|
+
const json = lText.parseJson(res.toString());
|
|
197
199
|
const r = {
|
|
198
200
|
'success': json.record?.id ? true : false,
|
|
199
201
|
'id': json.record?.id ?? ''
|
|
@@ -216,7 +218,7 @@ export class Dns {
|
|
|
216
218
|
if (!res) {
|
|
217
219
|
return res;
|
|
218
220
|
}
|
|
219
|
-
const json =
|
|
221
|
+
const json = lText.parseJson(res.toString());
|
|
220
222
|
const r = {
|
|
221
223
|
'success': json.RecordId !== undefined ? true : false,
|
|
222
224
|
'id': json.RecordId ?? ''
|
|
@@ -231,7 +233,7 @@ export class Dns {
|
|
|
231
233
|
* @param opt 参数
|
|
232
234
|
*/
|
|
233
235
|
async updateDomainRecord(opt) {
|
|
234
|
-
const line = opt.line ??
|
|
236
|
+
const line = opt.line ?? ERECORDLINE.DEFAULT;
|
|
235
237
|
const ttl = opt.ttl ?? 600;
|
|
236
238
|
switch (this._opt.service) {
|
|
237
239
|
// --- DNSPod ---
|
|
@@ -252,7 +254,7 @@ export class Dns {
|
|
|
252
254
|
if (!res) {
|
|
253
255
|
return res;
|
|
254
256
|
}
|
|
255
|
-
const json =
|
|
257
|
+
const json = lText.parseJson(res.toString());
|
|
256
258
|
const r = {
|
|
257
259
|
'success': json.record?.id ? true : false,
|
|
258
260
|
'id': json.record?.id ?? ''
|
|
@@ -275,7 +277,7 @@ export class Dns {
|
|
|
275
277
|
if (!res) {
|
|
276
278
|
return res;
|
|
277
279
|
}
|
|
278
|
-
const json =
|
|
280
|
+
const json = lText.parseJson(res.toString());
|
|
279
281
|
const r = {
|
|
280
282
|
'success': json.RecordId !== undefined ? true : false,
|
|
281
283
|
'id': json.RecordId ?? ''
|
|
@@ -302,7 +304,7 @@ export class Dns {
|
|
|
302
304
|
if (!res) {
|
|
303
305
|
return res;
|
|
304
306
|
}
|
|
305
|
-
const json =
|
|
307
|
+
const json = lText.parseJson(res.toString());
|
|
306
308
|
return {
|
|
307
309
|
'success': json.status.code === '1' ? true : false
|
|
308
310
|
};
|
|
@@ -317,7 +319,7 @@ export class Dns {
|
|
|
317
319
|
if (!res) {
|
|
318
320
|
return res;
|
|
319
321
|
}
|
|
320
|
-
const json =
|
|
322
|
+
const json = lText.parseJson(res.toString());
|
|
321
323
|
return {
|
|
322
324
|
'success': json.Code === undefined ? true : false
|
|
323
325
|
};
|
|
@@ -327,7 +329,7 @@ export class Dns {
|
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
/**
|
|
330
|
-
* ---
|
|
332
|
+
* --- 创建一个 Dns 对象 ---
|
|
331
333
|
* @param opt 选项
|
|
332
334
|
*/
|
|
333
335
|
export function get(ctr, opt) {
|
package/lib/fs.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ export declare function mkdir(path: string, mode?: number): Promise<boolean>;
|
|
|
72
72
|
export declare function rmdir(path: string): Promise<boolean>;
|
|
73
73
|
/**
|
|
74
74
|
* --- Danger 危险:危险函数,尽量不要使用 ---
|
|
75
|
-
* --- This
|
|
75
|
+
* --- This is a danger function, please don't use it ---
|
|
76
76
|
* --- 删除一个非空目录 ---
|
|
77
77
|
*/
|
|
78
78
|
export declare function rmdirDeep(path: string): Promise<boolean>;
|
|
@@ -83,7 +83,7 @@ export declare function rmdirDeep(path: string): Promise<boolean>;
|
|
|
83
83
|
*/
|
|
84
84
|
export declare function chmod(path: string, mod: string | number): Promise<boolean>;
|
|
85
85
|
/**
|
|
86
|
-
* ---
|
|
86
|
+
* --- 重命名/移动文件文件夹 ---
|
|
87
87
|
* @param oldPath 老名
|
|
88
88
|
* @param newPath 新名
|
|
89
89
|
*/
|
package/lib/fs.js
CHANGED
|
@@ -208,7 +208,7 @@ export async function rmdir(path) {
|
|
|
208
208
|
}
|
|
209
209
|
/**
|
|
210
210
|
* --- Danger 危险:危险函数,尽量不要使用 ---
|
|
211
|
-
* --- This
|
|
211
|
+
* --- This is a danger function, please don't use it ---
|
|
212
212
|
* --- 删除一个非空目录 ---
|
|
213
213
|
*/
|
|
214
214
|
export async function rmdirDeep(path) {
|
|
@@ -252,7 +252,7 @@ export async function chmod(path, mod) {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
/**
|
|
255
|
-
* ---
|
|
255
|
+
* --- 重命名/移动文件文件夹 ---
|
|
256
256
|
* @param oldPath 老名
|
|
257
257
|
* @param newPath 新名
|
|
258
258
|
*/
|
package/lib/kv.d.ts
CHANGED
|
@@ -6,10 +6,48 @@
|
|
|
6
6
|
import * as redis from '@litert/redis';
|
|
7
7
|
import * as kebab from '#kebab/index.js';
|
|
8
8
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
9
|
+
export interface IZRangeOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Range query type.
|
|
12
|
+
*
|
|
13
|
+
* - SCORE: Query by score range
|
|
14
|
+
* - LEX: Query by lexicographical range
|
|
15
|
+
*/
|
|
16
|
+
'by'?: 'SCORE' | 'LEX';
|
|
17
|
+
/**
|
|
18
|
+
* Whether to return results in reverse order.
|
|
19
|
+
*/
|
|
20
|
+
'rev'?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Pagination offset. Must be used together with count.
|
|
23
|
+
*/
|
|
24
|
+
'offset'?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Pagination count. Must be used together with offset.
|
|
27
|
+
*/
|
|
28
|
+
'count'?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* --- 键值存储操作类 ---
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import * as lKv from '@maiyunnet/kebab/lib/kv.js';
|
|
36
|
+
* const kv = lKv.get(this);
|
|
37
|
+
* await kv.ping();
|
|
38
|
+
* const v = await kv.get('test');
|
|
39
|
+
* const res = await kv.replace('test', 111);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
9
42
|
export declare class Kv {
|
|
10
43
|
/** --- 当前的 kv 连接信息 --- */
|
|
11
44
|
private readonly _etc;
|
|
12
45
|
constructor(etc: kebab.IConfigKv);
|
|
46
|
+
/**
|
|
47
|
+
* --- 获取一个 pipeline 操作对象 ---
|
|
48
|
+
* @returns 失败则返回 false
|
|
49
|
+
*/
|
|
50
|
+
pipeline(): Promise<redis.IPipelineClient | false>;
|
|
13
51
|
/**
|
|
14
52
|
* --- 设定一个值 ---
|
|
15
53
|
* @param key
|
|
@@ -27,16 +65,15 @@ export declare class Kv {
|
|
|
27
65
|
add(key: string, val: object | string | number, ttl?: number): Promise<boolean>;
|
|
28
66
|
/**
|
|
29
67
|
* --- 替换一个存在的值 ---
|
|
30
|
-
* @param key
|
|
31
|
-
* @param val
|
|
68
|
+
* @param key 键
|
|
69
|
+
* @param val 值
|
|
32
70
|
* @param ttl 秒,0 为不限制
|
|
33
|
-
* @param etc
|
|
34
71
|
*/
|
|
35
72
|
replace(key: string, val: object | string | number, ttl?: number): Promise<boolean>;
|
|
36
73
|
/**
|
|
37
74
|
* --- 向已存在的值后追加数据 ---
|
|
38
|
-
* @param key
|
|
39
|
-
* @param val
|
|
75
|
+
* @param key 键
|
|
76
|
+
* @param val 值
|
|
40
77
|
*/
|
|
41
78
|
append(key: string, val: string): Promise<boolean>;
|
|
42
79
|
/**
|
|
@@ -122,7 +159,6 @@ export declare class Kv {
|
|
|
122
159
|
flushDb(): Promise<boolean>;
|
|
123
160
|
/**
|
|
124
161
|
* --- 发送 ping ---
|
|
125
|
-
* @param last 是否刷新最后使用时间(默认刷新)
|
|
126
162
|
*/
|
|
127
163
|
ping(): Promise<false | string>;
|
|
128
164
|
/**
|
|
@@ -194,6 +230,12 @@ export declare class Kv {
|
|
|
194
230
|
bRPop(key: string | string[], timeout: number): Promise<Record<string, string> | false>;
|
|
195
231
|
lRange(key: string, start: number, stop: number): Promise<string[] | false>;
|
|
196
232
|
lLen(key: string): Promise<number | false>;
|
|
233
|
+
zAdd(key: string, score: number, member: string | Buffer): Promise<boolean>;
|
|
234
|
+
zRangeWithScores(key: string, start: number, stop: number, options?: IZRangeOptions): Promise<Array<{
|
|
235
|
+
member: string;
|
|
236
|
+
score: number;
|
|
237
|
+
}> | false>;
|
|
238
|
+
zRem(key: string, members: Array<string | Buffer>): Promise<number | false>;
|
|
197
239
|
/**
|
|
198
240
|
* --- 从连接池中获取一个符合要求的连接 ---
|
|
199
241
|
*/
|
|
@@ -201,7 +243,7 @@ export declare class Kv {
|
|
|
201
243
|
}
|
|
202
244
|
/**
|
|
203
245
|
* --- 获取 Kv 对象 ---
|
|
204
|
-
* @param
|
|
246
|
+
* @param ctrEtc 控制器或配置信息
|
|
205
247
|
*/
|
|
206
248
|
export declare function get(ctrEtc: sCtr.Ctr | kebab.IConfigKv): Kv;
|
|
207
249
|
/** --- 连接信息 --- */
|
package/lib/kv.js
CHANGED
|
@@ -10,10 +10,33 @@ import * as lCore from '#kebab/lib/core.js';
|
|
|
10
10
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
11
11
|
/** --- 连接列表(同一个 host、port、index 只有一个连接) --- */
|
|
12
12
|
const connections = [];
|
|
13
|
+
/**
|
|
14
|
+
* --- 键值存储操作类 ---
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import * as lKv from '@maiyunnet/kebab/lib/kv.js';
|
|
19
|
+
* const kv = lKv.get(this);
|
|
20
|
+
* await kv.ping();
|
|
21
|
+
* const v = await kv.get('test');
|
|
22
|
+
* const res = await kv.replace('test', 111);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
13
25
|
export class Kv {
|
|
14
26
|
constructor(etc) {
|
|
15
27
|
this._etc = etc;
|
|
16
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* --- 获取一个 pipeline 操作对象 ---
|
|
31
|
+
* @returns 失败则返回 false
|
|
32
|
+
*/
|
|
33
|
+
async pipeline() {
|
|
34
|
+
const conn = await this._getConnection();
|
|
35
|
+
if (!conn) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return conn.pipeline();
|
|
39
|
+
}
|
|
17
40
|
/**
|
|
18
41
|
* --- 设定一个值 ---
|
|
19
42
|
* @param key
|
|
@@ -57,18 +80,17 @@ export class Kv {
|
|
|
57
80
|
}
|
|
58
81
|
/**
|
|
59
82
|
* --- 替换一个存在的值 ---
|
|
60
|
-
* @param key
|
|
61
|
-
* @param val
|
|
83
|
+
* @param key 键
|
|
84
|
+
* @param val 值
|
|
62
85
|
* @param ttl 秒,0 为不限制
|
|
63
|
-
* @param etc
|
|
64
86
|
*/
|
|
65
87
|
async replace(key, val, ttl = 0) {
|
|
66
88
|
return this.set(key, val, ttl, 'xx');
|
|
67
89
|
}
|
|
68
90
|
/**
|
|
69
91
|
* --- 向已存在的值后追加数据 ---
|
|
70
|
-
* @param key
|
|
71
|
-
* @param val
|
|
92
|
+
* @param key 键
|
|
93
|
+
* @param val 值
|
|
72
94
|
*/
|
|
73
95
|
async append(key, val) {
|
|
74
96
|
const conn = await this._getConnection();
|
|
@@ -404,7 +426,6 @@ end`;
|
|
|
404
426
|
}
|
|
405
427
|
/**
|
|
406
428
|
* --- 发送 ping ---
|
|
407
|
-
* @param last 是否刷新最后使用时间(默认刷新)
|
|
408
429
|
*/
|
|
409
430
|
async ping() {
|
|
410
431
|
const conn = await this._getConnection();
|
|
@@ -707,6 +728,47 @@ end`;
|
|
|
707
728
|
return false;
|
|
708
729
|
}
|
|
709
730
|
}
|
|
731
|
+
async zAdd(key, score, member) {
|
|
732
|
+
const conn = await this._getConnection();
|
|
733
|
+
if (!conn) {
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
try {
|
|
737
|
+
return await conn.zAdd(this._etc.pre + key, score, member);
|
|
738
|
+
}
|
|
739
|
+
catch {
|
|
740
|
+
return false;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
async zRangeWithScores(key, start, stop, options) {
|
|
744
|
+
const conn = await this._getConnection();
|
|
745
|
+
if (!conn) {
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
try {
|
|
749
|
+
return await conn.zRangeWithScores(this._etc.pre + key, start, stop, {
|
|
750
|
+
'by': options?.by,
|
|
751
|
+
'reverse': options?.rev,
|
|
752
|
+
'offset': options?.offset,
|
|
753
|
+
'count': options?.count,
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
catch {
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
async zRem(key, members) {
|
|
761
|
+
const conn = await this._getConnection();
|
|
762
|
+
if (!conn) {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
try {
|
|
766
|
+
return await conn.zRem(this._etc.pre + key, members);
|
|
767
|
+
}
|
|
768
|
+
catch {
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
710
772
|
/**
|
|
711
773
|
* --- 从连接池中获取一个符合要求的连接 ---
|
|
712
774
|
*/
|
|
@@ -748,7 +810,7 @@ end`;
|
|
|
748
810
|
}
|
|
749
811
|
/**
|
|
750
812
|
* --- 获取 Kv 对象 ---
|
|
751
|
-
* @param
|
|
813
|
+
* @param ctrEtc 控制器或配置信息
|
|
752
814
|
*/
|
|
753
815
|
export function get(ctrEtc) {
|
|
754
816
|
const etc = ctrEtc instanceof sCtr.Ctr ? ctrEtc.getPrototype('_config').kv : ctrEtc;
|
package/lib/net/request.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare class Request {
|
|
|
55
55
|
* --- 设置域名 -> ip的对应键值,就像电脑里的 hosts 一样 ---
|
|
56
56
|
* @param hosts
|
|
57
57
|
*/
|
|
58
|
-
hosts(hosts: Record<string, string>): this;
|
|
58
|
+
hosts(hosts: Record<string, string> | string): this;
|
|
59
59
|
/**
|
|
60
60
|
* --- 设置后将直接保存到本地文件,不会返回,save 为本地实体路径 ---
|
|
61
61
|
* @param save
|
package/lib/net.d.ts
CHANGED
|
@@ -36,17 +36,17 @@ export declare function post(u: string, data: Record<string, kebab.Json> | Buffe
|
|
|
36
36
|
* --- 发起 JSON 请求 ---
|
|
37
37
|
* @param u 网址
|
|
38
38
|
* @param data 数据
|
|
39
|
-
* @param opt选项
|
|
39
|
+
* @param opt 选项
|
|
40
40
|
*/
|
|
41
|
-
export declare function postJson(u: string, data:
|
|
41
|
+
export declare function postJson(u: string, data: any[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
42
42
|
/**
|
|
43
43
|
* --- 发起 JSON 请求并解析 JSON 响应 ---
|
|
44
|
-
* @param
|
|
44
|
+
* @param u 网址
|
|
45
45
|
* @param data 数据
|
|
46
|
-
* @param
|
|
46
|
+
* @param opt 选项
|
|
47
47
|
* @returns JSON 数据,失败时返回 null
|
|
48
48
|
*/
|
|
49
|
-
export declare function postJsonResponseJson(u: string, data:
|
|
49
|
+
export declare function postJsonResponseJson(u: string, data: any[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<any | null>;
|
|
50
50
|
/**
|
|
51
51
|
* --- 发起一个原生 fetch 请求,增加了一些框架选项,注意:会抛出错误 ---
|
|
52
52
|
* @param input 请求的 URL 或 Request 对象
|
|
@@ -64,7 +64,7 @@ export declare function fetch(input: string | URL | Request, init?: RequestInit
|
|
|
64
64
|
* --- 发起一个请求 ---
|
|
65
65
|
* @param opt 配置项
|
|
66
66
|
*/
|
|
67
|
-
export declare function request(u: string, data?: Record<string,
|
|
67
|
+
export declare function request(u: string, data?: Record<string, any> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
68
68
|
/**
|
|
69
69
|
* --- 对 cookie 对象进行操作 ---
|
|
70
70
|
* @param cookie 要操作的对象
|
package/lib/net.js
CHANGED
|
@@ -60,7 +60,7 @@ export async function post(u, data, opt = {}) {
|
|
|
60
60
|
* --- 发起 JSON 请求 ---
|
|
61
61
|
* @param u 网址
|
|
62
62
|
* @param data 数据
|
|
63
|
-
* @param opt选项
|
|
63
|
+
* @param opt 选项
|
|
64
64
|
*/
|
|
65
65
|
export async function postJson(u, data, opt = {}) {
|
|
66
66
|
opt.method = 'POST';
|
|
@@ -69,9 +69,9 @@ export async function postJson(u, data, opt = {}) {
|
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* --- 发起 JSON 请求并解析 JSON 响应 ---
|
|
72
|
-
* @param
|
|
72
|
+
* @param u 网址
|
|
73
73
|
* @param data 数据
|
|
74
|
-
* @param
|
|
74
|
+
* @param opt 选项
|
|
75
75
|
* @returns JSON 数据,失败时返回 null
|
|
76
76
|
*/
|
|
77
77
|
export async function postJsonResponseJson(u, data, opt = {}) {
|
package/lib/scan.d.ts
CHANGED
|
@@ -68,9 +68,9 @@ export declare class Scan {
|
|
|
68
68
|
export declare function get(link: lDb.Pool | lKv.Kv, token?: string, opt?: IOptions): Promise<Scan>;
|
|
69
69
|
/**
|
|
70
70
|
* --- 对 token 执行访问操作,通常用户扫码后展示的网页所调用,代表已扫码 ---
|
|
71
|
-
* @param link
|
|
72
|
-
* @
|
|
73
|
-
* @param opt
|
|
71
|
+
* @param link Db 或 Kv
|
|
72
|
+
* @param token 必填
|
|
73
|
+
* @param opt 参数
|
|
74
74
|
*/
|
|
75
75
|
export declare function scanned(link: lDb.Pool | lKv.Kv, token: string, opt?: IStaticOptions): Promise<boolean>;
|
|
76
76
|
/**
|
package/lib/scan.js
CHANGED
|
@@ -218,9 +218,9 @@ export async function get(link, token, opt = {}) {
|
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
220
|
* --- 对 token 执行访问操作,通常用户扫码后展示的网页所调用,代表已扫码 ---
|
|
221
|
-
* @param link
|
|
222
|
-
* @
|
|
223
|
-
* @param opt
|
|
221
|
+
* @param link Db 或 Kv
|
|
222
|
+
* @param token 必填
|
|
223
|
+
* @param opt 参数
|
|
224
224
|
*/
|
|
225
225
|
export async function scanned(link, token, opt = {}) {
|
|
226
226
|
const time = lTime.stamp();
|