@maiyunnet/kebab 2.0.6 → 2.0.8

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.
Files changed (83) hide show
  1. package/index.d.ts +11 -1
  2. package/index.js +13 -1
  3. package/lib/buffer.d.ts +25 -0
  4. package/lib/buffer.js +30 -5
  5. package/lib/captcha.d.ts +15 -0
  6. package/lib/captcha.js +20 -0
  7. package/lib/consistent.d.ts +51 -0
  8. package/lib/consistent.js +59 -0
  9. package/lib/core.d.ts +134 -0
  10. package/lib/core.js +176 -0
  11. package/lib/crypto.d.ts +75 -6
  12. package/lib/crypto.js +206 -38
  13. package/lib/db.d.ts +104 -0
  14. package/lib/db.js +126 -0
  15. package/lib/dns.d.ts +51 -0
  16. package/lib/dns.js +54 -2
  17. package/lib/fs.d.ts +100 -0
  18. package/lib/fs.js +118 -0
  19. package/lib/jwt.d.ts +43 -0
  20. package/lib/jwt.js +45 -0
  21. package/lib/kv.d.ts +362 -0
  22. package/lib/kv.js +377 -0
  23. package/lib/lan.d.ts +6 -0
  24. package/lib/lan.js +7 -0
  25. package/lib/net/formdata.d.ts +38 -0
  26. package/lib/net/formdata.js +43 -0
  27. package/lib/net/request.d.ts +62 -0
  28. package/lib/net/request.js +57 -0
  29. package/lib/net/response.d.ts +21 -0
  30. package/lib/net/response.js +16 -0
  31. package/lib/net.d.ts +86 -0
  32. package/lib/net.js +140 -0
  33. package/lib/s3.d.ts +52 -0
  34. package/lib/s3.js +51 -0
  35. package/lib/scan.d.ts +52 -0
  36. package/lib/scan.js +84 -0
  37. package/lib/session.d.ts +31 -0
  38. package/lib/session.js +52 -1
  39. package/lib/sql.d.ts +176 -0
  40. package/lib/sql.js +287 -2
  41. package/lib/ssh/sftp.d.ts +106 -0
  42. package/lib/ssh/sftp.js +106 -0
  43. package/lib/ssh/shell.d.ts +37 -0
  44. package/lib/ssh/shell.js +31 -0
  45. package/lib/ssh.d.ts +32 -0
  46. package/lib/ssh.js +32 -0
  47. package/lib/text.d.ts +131 -0
  48. package/lib/text.js +188 -0
  49. package/lib/time.d.ts +53 -0
  50. package/lib/time.js +55 -0
  51. package/lib/ws.d.ts +68 -0
  52. package/lib/ws.js +74 -0
  53. package/lib/zip.d.ts +53 -0
  54. package/lib/zip.js +73 -0
  55. package/lib/zlib.d.ts +76 -0
  56. package/lib/zlib.js +78 -0
  57. package/main.d.ts +6 -1
  58. package/main.js +11 -1
  59. package/package.json +2 -2
  60. package/sys/child.js +104 -0
  61. package/sys/cmd.js +28 -0
  62. package/sys/ctr.d.ts +166 -0
  63. package/sys/ctr.js +177 -0
  64. package/sys/master.js +63 -0
  65. package/sys/mod.d.ts +266 -0
  66. package/sys/mod.js +335 -0
  67. package/sys/route.d.ts +34 -0
  68. package/sys/route.js +164 -0
  69. package/www/example/ctr/test.d.ts +3 -0
  70. package/www/example/ctr/test.js +63 -1
  71. package/www/example/mod/test.js +14 -0
  72. package/www/example/mod/testdata.js +9 -0
  73. package/www/example/ws/test.js +1 -0
  74. package/.VSCodeCounter/2025-02-14_14-46-44/details.md +0 -82
  75. package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +0 -15
  76. package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +0 -2
  77. package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +0 -19
  78. package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +0 -22
  79. package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +0 -69
  80. package/.VSCodeCounter/2025-02-14_14-46-44/results.json +0 -1
  81. package/.VSCodeCounter/2025-02-14_14-46-44/results.md +0 -48
  82. package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +0 -118
  83. package/.vscode/tasks.json +0 -15
package/lib/db.d.ts CHANGED
@@ -1,6 +1,12 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2019-4-15 13:40
4
+ * Last: 2020-4-13 15:34:45, 2022-09-12 13:10:34, 2023-5-24 18:29:38, 2024-7-11 14:37:54, 2024-8-25 00:32:53, 2024-9-22 17:30:47
5
+ */
1
6
  import * as mysql2 from 'mysql2/promise';
2
7
  import * as ctr from '../sys/ctr';
3
8
  import * as types from '../types';
9
+ /** --- query 返回的数据 --- */
4
10
  export interface IData {
5
11
  'rows': any[] | null;
6
12
  'fields': mysql2.FieldPacket[];
@@ -10,6 +16,7 @@ export interface IData {
10
16
  [key: string]: any;
11
17
  } | null;
12
18
  }
19
+ /** --- exec 返回对象 --- */
13
20
  export interface IPacket {
14
21
  'packet': mysql2.ResultSetHeader | null;
15
22
  'fields': mysql2.FieldPacket[];
@@ -19,6 +26,7 @@ export interface IPacket {
19
26
  [key: string]: any;
20
27
  } | null;
21
28
  }
29
+ /** --- 连接信息 --- */
22
30
  export interface IConnectionInfo {
23
31
  'id': number;
24
32
  'last': number;
@@ -30,18 +38,43 @@ export interface IConnectionInfo {
30
38
  'using': boolean;
31
39
  'transaction': boolean;
32
40
  }
41
+ /** --- 数据库连接池对象 --- */
33
42
  export declare class Pool {
43
+ /** --- SQL 执行次数 --- */
34
44
  private _queries;
45
+ /** --- 当前 Pool 对象的数据库连接信息 --- */
35
46
  private readonly _etc;
36
47
  constructor(etc: types.IConfigDb);
48
+ /**
49
+ * --- 执行一条 SQL,无视顺序和相同连接,随用随取 ---
50
+ * @param sql 执行的 SQL 字符串
51
+ * @param values 要替换的 data 数据
52
+ */
37
53
  query(sql: string, values?: types.DbValue[]): Promise<IData>;
54
+ /**
55
+ * --- 执行一条 SQL 并获得影响行数对象 packet,连接失败抛出错误 ---
56
+ * @param sql 执行的 SQL 字符串
57
+ * @param values 要替换的 data 数据
58
+ */
38
59
  execute(sql: string, values?: types.DbValue[]): Promise<IPacket>;
60
+ /**
61
+ * --- 开启事务,返回事务对象并锁定连接,别人任何人不可用,有 ctr 的话必传 this,独立执行时可传 null ---
62
+ */
39
63
  beginTransaction(ctr: ctr.Ctr | null): Promise<Transaction | null>;
64
+ /**
65
+ * --- 获取一个连接,自动变为 using 状态,;连接失败会返回 null ---
66
+ */
40
67
  private _getConnection;
68
+ /**
69
+ * --- 获取 SQL 执行次数 ---
70
+ */
41
71
  getQueries(): number;
42
72
  }
73
+ /** --- 事务连接对象,commit 和 rollback 后将无法使用 --- */
43
74
  export declare class Transaction {
75
+ /** --- SQL 执行次数 --- */
44
76
  private _queries;
77
+ /** --- 连接对象 --- */
45
78
  private _conn;
46
79
  private readonly _ctr;
47
80
  private readonly _timer;
@@ -49,40 +82,111 @@ export declare class Transaction {
49
82
  'warning'?: number;
50
83
  'danger'?: number;
51
84
  });
85
+ /**
86
+ * --- 在事务连接中执行一条 SQL ---
87
+ * @param sql 执行的 SQL 字符串
88
+ * @param values 要替换的 data 数据
89
+ */
52
90
  query(sql: string, values?: types.DbValue[]): Promise<IData>;
91
+ /**
92
+ * --- 执行一条 SQL 并获得影响行数对象 packet,连接失败抛出错误 ---
93
+ * @param sql 执行的 SQL 字符串
94
+ * @param values 要替换的 data 数据
95
+ */
53
96
  execute(sql: string, values?: types.DbValue[]): Promise<IPacket>;
54
97
  commit(): Promise<boolean>;
55
98
  rollback(): Promise<boolean>;
56
99
  }
100
+ /** --- 数据库连接对象 --- */
57
101
  export declare class Connection {
102
+ /** --- 本连接最后一次使用时间 --- */
58
103
  private _last;
104
+ /** --- 最后两次执行的 sql 完整串 --- */
59
105
  private readonly _lastSql;
106
+ /** --- 数据库连接对象 --- */
60
107
  private readonly _link;
108
+ /** --- 当前连接是否正在被独占使用 --- */
61
109
  private _using;
110
+ /** --- 当发生断开,则需从连接池移除连接 --- */
62
111
  private _lost;
112
+ /** --- 当前正在处理事务 --- */
63
113
  private _transaction;
114
+ /** --- 当前的连接配置信息 --- */
64
115
  private readonly _etc;
65
116
  constructor(etc: types.IConfigDb, link: mysql2.Connection);
117
+ /**
118
+ * --- 获取连接 etc 信息 ---
119
+ */
66
120
  getEtc(): types.IConfigDb;
121
+ /**
122
+ * --- 获取最后一次获取连接的时间 ---
123
+ */
67
124
  getLast(): number;
125
+ /**
126
+ * --- 获取最后两次执行的 sql 字符串 ---
127
+ */
68
128
  getLastSql(): Array<{
69
129
  'sql': string;
70
130
  'values'?: types.DbValue[];
71
131
  }>;
132
+ /**
133
+ * --- 将本条连接设置为不可用 ---
134
+ */
72
135
  setLost(): void;
136
+ /**
137
+ * --- 是否已经丢失 ---
138
+ */
73
139
  isLost(): boolean;
140
+ /**
141
+ * --- 是否是开启事务状态 ---
142
+ */
74
143
  isTransaction(): boolean;
144
+ /**
145
+ * --- 获取当前状态是否正在被使用中 ---
146
+ */
75
147
  isUsing(): boolean;
148
+ /**
149
+ * --- 判断是否可用(丢失的也算不可用),返回 true 代表获取成功并自动刷新最后时间 ---
150
+ */
76
151
  using(): boolean;
152
+ /**
153
+ * --- 取消占用 ---
154
+ */
77
155
  used(): void;
156
+ /**
157
+ * --- 设定最后使用时间 ---
158
+ */
78
159
  refreshLast(): void;
160
+ /**
161
+ * --- 通过执行一条语句判断当前连接是否可用 ---
162
+ */
79
163
  isAvailable(): Promise<boolean>;
164
+ /**
165
+ * --- 执行一条 SQL 并获得返回数据 ---
166
+ * @param sql 执行的 SQL 字符串
167
+ * @param values 要替换的 data 数据
168
+ */
80
169
  query(sql: string, values?: types.DbValue[]): Promise<IData>;
170
+ /**
171
+ * --- 执行一条 SQL 并获得影响行数对象 packet ---
172
+ * @param sql 执行的 SQL 字符串
173
+ * @param values 要替换的 data 数据
174
+ */
81
175
  execute(sql: string, values?: types.DbValue[]): Promise<IPacket>;
176
+ /**
177
+ * --- 关闭连接,一般情况下不使用 ---
178
+ */
82
179
  end(): Promise<boolean>;
83
180
  beginTransaction(): Promise<boolean>;
84
181
  commit(): Promise<boolean>;
85
182
  rollback(): Promise<boolean>;
86
183
  }
184
+ /**
185
+ * --- 获取 Db Pool 对象 ---
186
+ * @param etc 配置信息可留空
187
+ */
87
188
  export declare function get(ctrEtc: ctr.Ctr | types.IConfigDb): Pool;
189
+ /**
190
+ * --- 获取当前连接池中所有连接的信息 ---
191
+ */
88
192
  export declare function getConnectionList(): IConnectionInfo[];
package/lib/db.js CHANGED
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Project: Kebab, User: JianSuoQiYue
4
+ * Date: 2019-4-15 13:40
5
+ * Last: 2020-4-13 15:34:45, 2022-09-12 13:10:34, 2023-5-24 18:29:38, 2024-7-11 14:37:54, 2024-8-25 00:32:53, 2024-9-22 17:30:47
6
+ */
2
7
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
8
  if (k2 === undefined) k2 = k;
4
9
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -36,25 +41,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
41
  exports.Connection = exports.Transaction = exports.Pool = void 0;
37
42
  exports.get = get;
38
43
  exports.getConnectionList = getConnectionList;
44
+ // --- Pool 是使用时必须要一个用户创建一份的,Connection 是池子里获取的 ---
45
+ // --- 第三方 ---
39
46
  const mysql2 = __importStar(require("mysql2/promise"));
47
+ // --- 库和定义 ---
40
48
  const time = __importStar(require("../lib/time"));
41
49
  const lSql = __importStar(require("../lib/sql"));
42
50
  const core = __importStar(require("../lib/core"));
43
51
  const text = __importStar(require("../lib/text"));
44
52
  const ctr = __importStar(require("../sys/ctr"));
53
+ /** --- 连接列表池 --- */
45
54
  const connections = [];
55
+ /**
56
+ * --- 计划任务 30 秒一次,关闭超过 3 分钟不活动的连接,回滚独占时间过长的连接 ---
57
+ */
46
58
  async function checkConnection() {
47
59
  const now = time.stamp();
48
60
  for (let i = 0; i < connections.length; ++i) {
49
61
  const connection = connections[i];
50
62
  if (connection.isLost()) {
63
+ // --- 连接已经丢失,移除 ---
51
64
  await connection.end();
52
65
  connections.splice(i, 1);
53
66
  --i;
54
67
  continue;
55
68
  }
56
69
  if (connection.isUsing()) {
70
+ // --- 连接正在被使用,看看是否空闲了超过 1 分钟,超过则不是正常状态 ---
57
71
  if (connection.getLast() <= now - 60) {
72
+ // --- 1 分钟之前开始的 ---
58
73
  const ls = connection.getLastSql();
59
74
  const sql = ls[1] ?? ls[0];
60
75
  console.log(`[child] [db] [error] There is a transactional connection[${i}] that is not closed, last sql: ${sql?.sql ?? 'undefined'}.`);
@@ -77,9 +92,12 @@ async function checkConnection() {
77
92
  }
78
93
  continue;
79
94
  }
95
+ // --- 目前未被使用中的连接 ---
80
96
  if (connection.getLast() > now - 180) {
97
+ // --- 3 分钟内使用过,不管 ---
81
98
  continue;
82
99
  }
100
+ // --- 超 3 分钟未被使用,则关闭 ---
83
101
  await connection.end();
84
102
  connections.splice(i, 1);
85
103
  --i;
@@ -91,13 +109,21 @@ async function checkConnection() {
91
109
  setTimeout(function () {
92
110
  checkConnection().catch(e => { console.log('[DB]', e); });
93
111
  }, 30000);
112
+ /** --- 数据库连接池对象 --- */
94
113
  class Pool {
95
114
  constructor(etc) {
115
+ /** --- SQL 执行次数 --- */
96
116
  this._queries = 0;
97
117
  this._etc = etc;
98
118
  }
119
+ /**
120
+ * --- 执行一条 SQL,无视顺序和相同连接,随用随取 ---
121
+ * @param sql 执行的 SQL 字符串
122
+ * @param values 要替换的 data 数据
123
+ */
99
124
  async query(sql, values) {
100
125
  ++this._queries;
126
+ // --- 获取并自动 using ---
101
127
  const conn = await this._getConnection();
102
128
  if (!conn) {
103
129
  return {
@@ -109,8 +135,14 @@ class Pool {
109
135
  }
110
136
  };
111
137
  }
138
+ // --- 执行一次后自动解除 using ---
112
139
  return conn.query(sql, values);
113
140
  }
141
+ /**
142
+ * --- 执行一条 SQL 并获得影响行数对象 packet,连接失败抛出错误 ---
143
+ * @param sql 执行的 SQL 字符串
144
+ * @param values 要替换的 data 数据
145
+ */
114
146
  async execute(sql, values) {
115
147
  ++this._queries;
116
148
  const conn = await this._getConnection();
@@ -126,6 +158,9 @@ class Pool {
126
158
  }
127
159
  return conn.execute(sql, values);
128
160
  }
161
+ /**
162
+ * --- 开启事务,返回事务对象并锁定连接,别人任何人不可用,有 ctr 的话必传 this,独立执行时可传 null ---
163
+ */
129
164
  async beginTransaction(ctr) {
130
165
  const conn = await this._getConnection();
131
166
  if (!conn) {
@@ -136,6 +171,9 @@ class Pool {
136
171
  }
137
172
  return new Transaction(ctr, conn);
138
173
  }
174
+ /**
175
+ * --- 获取一个连接,自动变为 using 状态,;连接失败会返回 null ---
176
+ */
139
177
  async _getConnection() {
140
178
  let conn = null;
141
179
  for (const connection of connections) {
@@ -144,15 +182,19 @@ class Pool {
144
182
  (etc.port !== this._etc.port) ||
145
183
  (etc.name !== this._etc.name) ||
146
184
  (etc.user !== this._etc.user)) {
185
+ // --- 配置项连接项不匹配 ---
147
186
  continue;
148
187
  }
149
188
  if (!connection.using()) {
189
+ // --- 正在被使用,或者已经 lost ---
150
190
  continue;
151
191
  }
192
+ // --- 匹配且可用 ---
152
193
  conn = connection;
153
194
  break;
154
195
  }
155
196
  if (!conn) {
197
+ // --- 没有找到合适的连接,创建一个 ---
156
198
  try {
157
199
  const link = await mysql2.createConnection({
158
200
  'host': this._etc.host,
@@ -190,23 +232,31 @@ class Pool {
190
232
  }
191
233
  return conn;
192
234
  }
235
+ /**
236
+ * --- 获取 SQL 执行次数 ---
237
+ */
193
238
  getQueries() {
194
239
  return this._queries;
195
240
  }
196
241
  }
197
242
  exports.Pool = Pool;
243
+ /** --- 事务连接对象,commit 和 rollback 后将无法使用 --- */
198
244
  class Transaction {
199
245
  constructor(ctr, conn, opts = {}) {
246
+ /** --- SQL 执行次数 --- */
200
247
  this._queries = 0;
248
+ // --- 事务时长监听 timer ---
201
249
  this._timer = {
202
250
  'warning': undefined,
203
251
  'danger': undefined
204
252
  };
253
+ // --- 进来的连接对象直接是事务独占模式 ---
205
254
  this._ctr = ctr;
206
255
  if (ctr) {
207
256
  ++ctr.getPrototype('_waitInfo').transaction;
208
257
  }
209
258
  this._conn = conn;
259
+ // --- 事务时长监听 ---
210
260
  const warning = opts.warning ?? 1_500;
211
261
  this._timer.warning = setTimeout(() => {
212
262
  this._timer.warning = undefined;
@@ -218,8 +268,14 @@ class Transaction {
218
268
  console.log('[DANGER][DB][Transaction] time too long, ms:', danger, this._ctr?.getPrototype('_config').const.path ?? 'no ctr');
219
269
  }, danger);
220
270
  }
271
+ /**
272
+ * --- 在事务连接中执行一条 SQL ---
273
+ * @param sql 执行的 SQL 字符串
274
+ * @param values 要替换的 data 数据
275
+ */
221
276
  async query(sql, values) {
222
277
  if (!this._conn) {
278
+ // --- 当前连接已不可用 ---
223
279
  console.log('[ERROR][DB][Transaction.query] has been closed.', this._ctr?.getPrototype('_config').const.path ?? 'no ctr', sql);
224
280
  await core.log({
225
281
  'path': '',
@@ -242,8 +298,14 @@ class Transaction {
242
298
  ++this._queries;
243
299
  return this._conn.query(sql, values);
244
300
  }
301
+ /**
302
+ * --- 执行一条 SQL 并获得影响行数对象 packet,连接失败抛出错误 ---
303
+ * @param sql 执行的 SQL 字符串
304
+ * @param values 要替换的 data 数据
305
+ */
245
306
  async execute(sql, values) {
246
307
  if (!this._conn) {
308
+ // --- 当前连接已不可用 ---
247
309
  console.log('[ERROR][DB][Transaction.execute] has been closed.', this._ctr?.getPrototype('_config').const.path ?? 'no ctr', sql);
248
310
  await core.log({
249
311
  'path': '',
@@ -268,6 +330,7 @@ class Transaction {
268
330
  }
269
331
  async commit() {
270
332
  if (!this._conn) {
333
+ // --- 当前连接已不可用 ---
271
334
  console.log('[ERROR][DB][Transaction.commit] has been closed.', this._ctr?.getPrototype('_config').const.path ?? 'no ctr');
272
335
  await core.log({
273
336
  'path': '',
@@ -296,6 +359,7 @@ class Transaction {
296
359
  }
297
360
  async rollback() {
298
361
  if (!this._conn) {
362
+ // --- 当前连接已不可用 ---
299
363
  console.log('[ERROR][DB][Transaction.rollback] has been closed.', this._ctr?.getPrototype('_config').const.path ?? 'no ctr');
300
364
  await core.log({
301
365
  'path': '',
@@ -324,38 +388,68 @@ class Transaction {
324
388
  }
325
389
  }
326
390
  exports.Transaction = Transaction;
391
+ /** --- 数据库连接对象 --- */
327
392
  class Connection {
328
393
  constructor(etc, link) {
394
+ /** --- 本连接最后一次使用时间 --- */
329
395
  this._last = 0;
396
+ /** --- 最后两次执行的 sql 完整串 --- */
330
397
  this._lastSql = [];
398
+ /** --- 当前连接是否正在被独占使用 --- */
331
399
  this._using = false;
400
+ /** --- 当发生断开,则需从连接池移除连接 --- */
332
401
  this._lost = false;
402
+ /** --- 当前正在处理事务 --- */
333
403
  this._transaction = false;
334
404
  this._etc = etc;
335
405
  this._link = link;
336
406
  this.refreshLast();
337
407
  }
408
+ /**
409
+ * --- 获取连接 etc 信息 ---
410
+ */
338
411
  getEtc() {
339
412
  return this._etc;
340
413
  }
414
+ /**
415
+ * --- 获取最后一次获取连接的时间 ---
416
+ */
341
417
  getLast() {
342
418
  return this._last;
343
419
  }
420
+ /**
421
+ * --- 获取最后两次执行的 sql 字符串 ---
422
+ */
344
423
  getLastSql() {
345
424
  return this._lastSql;
346
425
  }
426
+ /**
427
+ * --- 将本条连接设置为不可用 ---
428
+ */
347
429
  setLost() {
348
430
  this._lost = true;
349
431
  }
432
+ /**
433
+ * --- 是否已经丢失 ---
434
+ */
350
435
  isLost() {
351
436
  return this._lost;
352
437
  }
438
+ /**
439
+ * --- 是否是开启事务状态 ---
440
+ */
353
441
  isTransaction() {
354
442
  return this._transaction;
355
443
  }
444
+ /**
445
+ * --- 获取当前状态是否正在被使用中 ---
446
+ */
356
447
  isUsing() {
357
448
  return this._using;
358
449
  }
450
+ /**
451
+ * --- 判断是否可用(丢失的也算不可用),返回 true 代表获取成功并自动刷新最后时间 ---
452
+ */
359
453
  using() {
360
454
  if (this._lost || this._using) {
361
455
  return false;
@@ -366,12 +460,21 @@ class Connection {
366
460
  return true;
367
461
  }
368
462
  }
463
+ /**
464
+ * --- 取消占用 ---
465
+ */
369
466
  used() {
370
467
  this._using = false;
371
468
  }
469
+ /**
470
+ * --- 设定最后使用时间 ---
471
+ */
372
472
  refreshLast() {
373
473
  this._last = time.stamp();
374
474
  }
475
+ /**
476
+ * --- 通过执行一条语句判断当前连接是否可用 ---
477
+ */
375
478
  async isAvailable() {
376
479
  this.refreshLast();
377
480
  try {
@@ -382,6 +485,11 @@ class Connection {
382
485
  return false;
383
486
  }
384
487
  }
488
+ /**
489
+ * --- 执行一条 SQL 并获得返回数据 ---
490
+ * @param sql 执行的 SQL 字符串
491
+ * @param values 要替换的 data 数据
492
+ */
385
493
  async query(sql, values) {
386
494
  let res;
387
495
  try {
@@ -408,12 +516,18 @@ class Connection {
408
516
  if (!this._transaction) {
409
517
  this._using = false;
410
518
  }
519
+ // --- 返回数据 ---
411
520
  return {
412
521
  'rows': res[0],
413
522
  'fields': res[1],
414
523
  'error': null
415
524
  };
416
525
  }
526
+ /**
527
+ * --- 执行一条 SQL 并获得影响行数对象 packet ---
528
+ * @param sql 执行的 SQL 字符串
529
+ * @param values 要替换的 data 数据
530
+ */
417
531
  async execute(sql, values) {
418
532
  let res;
419
533
  try {
@@ -431,6 +545,7 @@ class Connection {
431
545
  if (!this._transaction) {
432
546
  this._using = false;
433
547
  }
548
+ // --- e.errno 可能为 1062 ---
434
549
  return {
435
550
  'packet': null,
436
551
  'fields': [],
@@ -446,6 +561,9 @@ class Connection {
446
561
  'error': null
447
562
  };
448
563
  }
564
+ /**
565
+ * --- 关闭连接,一般情况下不使用 ---
566
+ */
449
567
  async end() {
450
568
  try {
451
569
  await this._link.end();
@@ -455,6 +573,7 @@ class Connection {
455
573
  return false;
456
574
  }
457
575
  }
576
+ // --- 事务,只能在独占连接中使用,pool 创建事务返回独占连接,commit 或 rollback 释放连接回池 ---
458
577
  async beginTransaction() {
459
578
  if (this._using) {
460
579
  try {
@@ -496,10 +615,17 @@ class Connection {
496
615
  }
497
616
  }
498
617
  exports.Connection = Connection;
618
+ /**
619
+ * --- 获取 Db Pool 对象 ---
620
+ * @param etc 配置信息可留空
621
+ */
499
622
  function get(ctrEtc) {
500
623
  const etc = ctrEtc instanceof ctr.Ctr ? ctrEtc.getPrototype('_config').db : ctrEtc;
501
624
  return new Pool(etc);
502
625
  }
626
+ /**
627
+ * --- 获取当前连接池中所有连接的信息 ---
628
+ */
503
629
  function getConnectionList() {
504
630
  const list = [];
505
631
  for (let i = 0; i < connections.length; ++i) {
package/lib/dns.d.ts CHANGED
@@ -1,13 +1,30 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
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
5
+ */
1
6
  import * as ctr from '../sys/ctr';
7
+ /**
8
+ * 0.DNSPod:https://www.dnspod.cn/docs/index.html(腾讯云也请使用 DNSPod 的 API)
9
+ * 1.阿里云:https://help.aliyun.com/document_detail/29745.html
10
+ */
11
+ /** --- 服务商定义 --- */
2
12
  export declare enum ESERVICE {
3
13
  'DNSPOD' = 0,
4
14
  'ALIBABA' = 1
5
15
  }
16
+ /** --- 选项 --- */
6
17
  export interface IOptions {
18
+ /** --- 服务商 ---- */
7
19
  'service': ESERVICE;
20
+ /** --- 密钥键 --- */
8
21
  'secretId'?: string;
22
+ /** --- 密钥值 --- */
9
23
  'secretKey'?: string;
10
24
  }
25
+ /**
26
+ * --- 获取域名列表的返回对象 ---
27
+ */
11
28
  export interface IDomainList {
12
29
  'total': number;
13
30
  'list': Array<{
@@ -17,10 +34,16 @@ export interface IDomainList {
17
34
  'punyCode': string;
18
35
  }>;
19
36
  }
37
+ /**
38
+ * --- 添加记录的返回对象 ---
39
+ */
20
40
  export interface IAddDomainRecord {
21
41
  'success': boolean;
22
42
  'id': string;
23
43
  }
44
+ /**
45
+ * --- 记录值类型 ---
46
+ */
24
47
  export declare const RECORD_TYPE: {
25
48
  A: string;
26
49
  NS: string;
@@ -30,6 +53,9 @@ export declare const RECORD_TYPE: {
30
53
  SRV: string;
31
54
  AAAA: string;
32
55
  };
56
+ /**
57
+ * --- 记录值线路 ---
58
+ */
33
59
  export declare enum ERecordLine {
34
60
  'DEFAULT' = 0,
35
61
  'TELECOM' = 1,
@@ -39,13 +65,26 @@ export declare enum ERecordLine {
39
65
  'OVERSEA' = 5
40
66
  }
41
67
  export declare class Dns {
68
+ /** --- 当前选项 --- */
42
69
  private readonly _opt;
43
70
  constructor(ctr: ctr.Ctr, opt: IOptions);
71
+ /**
72
+ * --- 最终发送 ---
73
+ * @param obj 要发送的信息
74
+ */
44
75
  private _send;
76
+ /**
77
+ * --- 获取域名列表 ---
78
+ * @param opt 参数
79
+ */
45
80
  getDomainList(opt: {
46
81
  'offset'?: number;
47
82
  'length'?: number;
48
83
  }): Promise<IDomainList | null>;
84
+ /**
85
+ * --- 添加记录 ---
86
+ * @param opt 参数
87
+ */
49
88
  addDomainRecord(opt: {
50
89
  'domain': string;
51
90
  'sub': string;
@@ -55,6 +94,10 @@ export declare class Dns {
55
94
  'ttl'?: number;
56
95
  'mx'?: number;
57
96
  }): Promise<IAddDomainRecord | null>;
97
+ /**
98
+ * --- 修改记录 ---
99
+ * @param opt 参数
100
+ */
58
101
  updateDomainRecord(opt: {
59
102
  'domain': string;
60
103
  'record': string;
@@ -65,6 +108,10 @@ export declare class Dns {
65
108
  'ttl'?: number;
66
109
  'mx'?: number;
67
110
  }): Promise<IAddDomainRecord | null>;
111
+ /**
112
+ * --- 删除记录 ---
113
+ * @param opt 参数
114
+ */
68
115
  deleteDomainRecord(opt: {
69
116
  'domain': string;
70
117
  'id': string;
@@ -72,4 +119,8 @@ export declare class Dns {
72
119
  'success': boolean;
73
120
  } | null>;
74
121
  }
122
+ /**
123
+ * --- 创建一个第三方 Dns 对象 ---
124
+ * @param opt 选项
125
+ */
75
126
  export declare function get(ctr: ctr.Ctr, opt: IOptions): Dns;