@maiyunnet/kebab 5.3.0 → 6.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/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 ctr from '#kebab/sys/ctr.js';
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 const RECORD_TYPE: {
48
- A: string;
49
- NS: string;
50
- MX: string;
51
- TXT: string;
52
- CNAME: string;
53
- SRV: string;
54
- AAAA: string;
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 ERecordLine {
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: ctr.Ctr, opt: IOptions);
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'?: number;
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'?: number;
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
- * --- 创建一个第三方 Dns 对象 ---
123
+ * --- 创建一个 Dns 对象 ---
124
124
  * @param opt 选项
125
125
  */
126
- export declare function get(ctr: ctr.Ctr, opt: IOptions): Dns;
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 net from '#kebab/lib/net.js';
8
- import * as core from '#kebab/lib/core.js';
9
- import * as text from '#kebab/lib/text.js';
10
- import * as crypto from '#kebab/lib/crypto.js';
11
- import * as response from '#kebab/lib/net/response.js';
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 const RECORD_TYPE = {
26
- 'A': 'A',
27
- 'NS': 'NS',
28
- 'MX': 'MX',
29
- 'TXT': 'TXT',
30
- 'CNAME': 'CNAME',
31
- 'SRV': 'SRV',
32
- 'AAAA': 'AAAA'
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 ERecordLine;
38
- (function (ERecordLine) {
39
- ERecordLine[ERecordLine["DEFAULT"] = 0] = "DEFAULT";
40
- ERecordLine[ERecordLine["TELECOM"] = 1] = "TELECOM";
41
- ERecordLine[ERecordLine["UNICOM"] = 2] = "UNICOM";
42
- ERecordLine[ERecordLine["MOBILE"] = 3] = "MOBILE";
43
- ERecordLine[ERecordLine["EDU"] = 4] = "EDU";
44
- ERecordLine[ERecordLine["OVERSEA"] = 5] = "OVERSEA";
45
- })(ERecordLine || (ERecordLine = {}));
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
- return await net.post('https://dnsapi.cn/' + path, data); // 境外 api 会自动调度到香港服务器
91
+ // --- 境外服务器请求的话 api 会自动解析到香港服务器 ---
92
+ return lNet.post('https://dnsapi.cn/' + path, data);
91
93
  }
92
94
  // --- 阿里云 ---
93
95
  case ESERVICE.ALIBABA: {
94
- const getData = core.objectSort(Object.assign({
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': core.rand(1000000000, 9999999999)
103
+ 'SignatureNonce': lCore.rand(1000000000, 9999999999)
102
104
  }, obj));
103
- const urlRight = text.queryStringify(getData);
104
- const signature = crypto.hashHmac('sha1', `GET&${encodeURIComponent('/')}&${encodeURIComponent(urlRight)}`, (this._opt.secretKey ?? '') + '&', 'base64');
105
- return await net.get(`https://alidns.aliyuncs.com/?${urlRight}&Signature=${encodeURIComponent(signature)}`); // 境外 api 会自动调度到新加坡服务器
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 response.Response(null);
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 = text.parseJson(res.toString());
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 = text.parseJson(res.toString());
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 ?? ERecordLine.DEFAULT;
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 = text.parseJson(res.toString());
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 = text.parseJson(res.toString());
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 ?? ERecordLine.DEFAULT;
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 = text.parseJson(res.toString());
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 = text.parseJson(res.toString());
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 = text.parseJson(res.toString());
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 = text.parseJson(res.toString());
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
- * --- 创建一个第三方 Dns 对象 ---
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 f**king is a danger function, please don't use it ---
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 f**king is a danger function, please don't use it ---
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,27 @@
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
+ /**
10
+ * --- 键值存储操作类 ---
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import * as lKv from '@maiyunnet/kebab/lib/kv.js';
15
+ * const kv = lKv.get(this);
16
+ * await kv.ping();
17
+ * const v = await kv.get('test');
18
+ * const res = await kv.replace('test', 111);
19
+ * ```
20
+ */
9
21
  export declare class Kv {
10
22
  /** --- 当前的 kv 连接信息 --- */
11
23
  private readonly _etc;
12
24
  constructor(etc: kebab.IConfigKv);
25
+ /**
26
+ * --- 获取一个 pipeline 操作对象 ---
27
+ * @returns 失败则返回 false
28
+ */
29
+ pipeline(): Promise<redis.IPipelineClient | false>;
13
30
  /**
14
31
  * --- 设定一个值 ---
15
32
  * @param key
@@ -27,16 +44,15 @@ export declare class Kv {
27
44
  add(key: string, val: object | string | number, ttl?: number): Promise<boolean>;
28
45
  /**
29
46
  * --- 替换一个存在的值 ---
30
- * @param key
31
- * @param val
47
+ * @param key
48
+ * @param val
32
49
  * @param ttl 秒,0 为不限制
33
- * @param etc
34
50
  */
35
51
  replace(key: string, val: object | string | number, ttl?: number): Promise<boolean>;
36
52
  /**
37
53
  * --- 向已存在的值后追加数据 ---
38
- * @param key
39
- * @param val
54
+ * @param key
55
+ * @param val
40
56
  */
41
57
  append(key: string, val: string): Promise<boolean>;
42
58
  /**
@@ -122,7 +138,6 @@ export declare class Kv {
122
138
  flushDb(): Promise<boolean>;
123
139
  /**
124
140
  * --- 发送 ping ---
125
- * @param last 是否刷新最后使用时间(默认刷新)
126
141
  */
127
142
  ping(): Promise<false | string>;
128
143
  /**
@@ -201,7 +216,7 @@ export declare class Kv {
201
216
  }
202
217
  /**
203
218
  * --- 获取 Kv 对象 ---
204
- * @param etc 配置信息可留空
219
+ * @param ctrEtc 控制器或配置信息
205
220
  */
206
221
  export declare function get(ctrEtc: sCtr.Ctr | kebab.IConfigKv): Kv;
207
222
  /** --- 连接信息 --- */
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();
@@ -748,7 +769,7 @@ end`;
748
769
  }
749
770
  /**
750
771
  * --- 获取 Kv 对象 ---
751
- * @param etc 配置信息可留空
772
+ * @param ctrEtc 控制器或配置信息
752
773
  */
753
774
  export function get(ctrEtc) {
754
775
  const etc = ctrEtc instanceof sCtr.Ctr ? ctrEtc.getPrototype('_config').kv : ctrEtc;
@@ -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: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<lResponse.Response>;
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 url 网址
44
+ * @param u 网址
45
45
  * @param data 数据
46
- * @param init 选项
46
+ * @param opt 选项
47
47
  * @returns JSON 数据,失败时返回 null
48
48
  */
49
- export declare function postJsonResponseJson(u: string, data: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<any | null>;
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, kebab.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
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 url 网址
72
+ * @param u 网址
73
73
  * @param data 数据
74
- * @param init 选项
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
- * @patam token 必填
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
- * @patam token 必填
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();
package/lib/sql.d.ts CHANGED
@@ -22,7 +22,7 @@ export declare class Sql {
22
22
  /** --- 表别名列表 --- */
23
23
  private readonly _alias;
24
24
  /** --- PostgreSQL 占位符计数器 --- */
25
- private _placeholder;
25
+ private _placeholderCounter;
26
26
  constructor(pre?: string, opt?: {
27
27
  'data'?: kebab.DbValue[];
28
28
  'sql'?: string[];
@@ -39,6 +39,12 @@ export declare class Sql {
39
39
  * @param vs [] | [][] 数据
40
40
  */
41
41
  values(cs: string[] | Record<string, kebab.DbValue>, vs?: kebab.DbValue[] | kebab.DbValue[][]): this;
42
+ /**
43
+ * --- 如果存在则更新不存在则插入(UPSERT)---
44
+ * @param data 更新的数据
45
+ * @param conflict 冲突字段,PostgreSQL 用于指定 ON CONFLICT 字段;MySQL 时忽略,因为会对所有唯一键冲突执行更新
46
+ */
47
+ upsert(data: kebab.Json, conflict?: string | string[]): this;
42
48
  /**
43
49
  * --- '*', 'xx' ---
44
50
  * @param c 字段字符串或字段数组
@@ -59,13 +65,13 @@ export declare class Sql {
59
65
  delete(f: string): this;
60
66
  /**
61
67
  * --- 联查另一个 sql 对象 ---
62
- * @param sql sql 对象
68
+ * @param lsql sql 对象
63
69
  * @param type 类型
64
70
  */
65
71
  union(lsql: Sql, type?: string): this;
66
72
  /**
67
73
  * --- 所有联查另一个 sql 对象 ---
68
- * @param sql sql 对象
74
+ * @param lsql sql 对象
69
75
  */
70
76
  unionAll(lsql: Sql): this;
71
77
  /**
@@ -187,8 +193,6 @@ export declare class Sql {
187
193
  * @param sql
188
194
  */
189
195
  append(sql: string): this;
190
- /** --- 获取占位符 --- */
191
- placeholder(): string;
192
196
  /**
193
197
  * --- 对字段进行包裹 ---
194
198
  * @param str
@@ -201,6 +205,13 @@ export declare class Sql {
201
205
  * @param str
202
206
  */
203
207
  private _isField;
208
+ /** --- 获取占位符 --- */
209
+ private _placeholder;
210
+ /**
211
+ * --- 处理单个值,检测数据类型并返回 SQL 和 data ---
212
+ * @param v 要处理的值
213
+ */
214
+ private _processValue;
204
215
  }
205
216
  /**
206
217
  * --- 创建 sql 对象 ---