@maiyunnet/kebab 2.0.14 → 2.0.16

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 (73) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +1 -1
  3. package/lib/buffer.js +3 -9
  4. package/lib/captcha.js +2 -2
  5. package/lib/consistent.js +1 -1
  6. package/lib/core.d.ts +42 -18
  7. package/lib/core.js +147 -152
  8. package/lib/crypto.js +2 -2
  9. package/lib/db.d.ts +3 -3
  10. package/lib/db.js +32 -73
  11. package/lib/dns.d.ts +1 -1
  12. package/lib/dns.js +5 -5
  13. package/lib/fs.js +17 -9
  14. package/lib/jwt.d.ts +3 -3
  15. package/lib/jwt.js +5 -5
  16. package/lib/kv.d.ts +2 -2
  17. package/lib/kv.js +2 -2
  18. package/lib/lan.js +1 -1
  19. package/lib/net/formdata.js +2 -2
  20. package/lib/net/request.d.ts +1 -1
  21. package/lib/net/request.js +1 -1
  22. package/lib/net/response.d.ts +1 -1
  23. package/lib/net.d.ts +2 -2
  24. package/lib/net.js +4 -4
  25. package/lib/s3.d.ts +1 -1
  26. package/lib/s3.js +5 -5
  27. package/lib/scan.d.ts +3 -3
  28. package/lib/scan.js +6 -6
  29. package/lib/session.d.ts +3 -3
  30. package/lib/session.js +7 -7
  31. package/lib/sql.d.ts +3 -3
  32. package/lib/sql.js +7 -37
  33. package/lib/ssh/sftp.js +2 -2
  34. package/lib/ssh/shell.js +1 -1
  35. package/lib/text.d.ts +6 -1
  36. package/lib/text.js +9 -1
  37. package/lib/time.d.ts +1 -1
  38. package/lib/time.js +1 -1
  39. package/lib/turnstile.d.ts +1 -1
  40. package/lib/turnstile.js +2 -2
  41. package/lib/ws.d.ts +10 -2
  42. package/lib/ws.js +62 -3
  43. package/lib/zip.d.ts +1 -1
  44. package/lib/zip.js +5 -11
  45. package/lib/zlib.js +7 -21
  46. package/package.json +5 -4
  47. package/sys/child.js +43 -84
  48. package/sys/cmd.js +7 -6
  49. package/sys/ctr.d.ts +2 -2
  50. package/sys/ctr.js +2 -2
  51. package/sys/master.js +131 -9
  52. package/sys/mod.d.ts +4 -4
  53. package/sys/mod.js +24 -176
  54. package/sys/route.d.ts +1 -1
  55. package/sys/route.js +22 -20
  56. package/www/example/ctr/main.d.ts +1 -1
  57. package/www/example/ctr/main.js +1 -1
  58. package/www/example/ctr/middle.d.ts +2 -2
  59. package/www/example/ctr/middle.js +1 -1
  60. package/www/example/ctr/test.d.ts +3 -2
  61. package/www/example/ctr/test.js +83 -30
  62. package/www/example/mod/test.d.ts +2 -2
  63. package/www/example/mod/test.js +2 -2
  64. package/www/example/mod/testdata.d.ts +1 -1
  65. package/www/example/mod/testdata.js +1 -1
  66. package/www/example/ws/mproxy.d.ts +1 -1
  67. package/www/example/ws/mproxy.js +2 -2
  68. package/www/example/ws/rproxy.d.ts +1 -1
  69. package/www/example/ws/rproxy.js +2 -2
  70. package/www/example/ws/rsocket.d.ts +4 -0
  71. package/www/example/ws/rsocket.js +47 -0
  72. package/www/example/ws/test.d.ts +6 -1
  73. package/www/example/ws/test.js +10 -3
package/lib/sql.js CHANGED
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Project: Kebab, User: JianSuoQiYue
4
4
  * Date: 2019-5-27 20:18:50
5
- * Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28
5
+ * Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18
6
6
  */
7
7
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
8
  if (k2 === undefined) k2 = k;
@@ -43,12 +43,12 @@ exports.get = get;
43
43
  exports.format = format;
44
44
  exports.aoMix = aoMix;
45
45
  exports.column = column;
46
- const lText = __importStar(require("../lib/text"));
47
- const lCore = __importStar(require("../lib/core"));
46
+ const lText = __importStar(require("~/lib/text"));
47
+ const lCore = __importStar(require("~/lib/core"));
48
48
  // --- 第三方 ---
49
49
  const mysql2 = __importStar(require("mysql2/promise"));
50
50
  // --- 库和定义 ---
51
- const ctr = __importStar(require("../sys/ctr"));
51
+ const ctr = __importStar(require("~/sys/ctr"));
52
52
  /** --- filed 用 token --- */
53
53
  let columnToken = '';
54
54
  class Sql {
@@ -116,17 +116,7 @@ class Sql {
116
116
  // --- v1 是项目值,如 {'x': 1, 'y': 2}, 'string', 0 ---
117
117
  if (v1 === undefined || Number.isNaN(v1)) {
118
118
  // --- 异常情况 ---
119
- lCore.log({
120
- 'path': '',
121
- 'urlFull': '',
122
- 'hostname': '',
123
- 'req': null,
124
- 'get': {},
125
- 'cookie': {},
126
- 'headers': {}
127
- }, '(sql.values) value error', '-error').catch(() => {
128
- //
129
- });
119
+ lCore.log({}, '[SQL][values] value error', '-error');
130
120
  sql += `'', `;
131
121
  }
132
122
  else if (v1 === null) {
@@ -200,17 +190,7 @@ class Sql {
200
190
  sql += this.field(k) + ', ';
201
191
  if (v === undefined || Number.isNaN(v)) {
202
192
  // --- 异常情况 ---
203
- lCore.log({
204
- 'path': '',
205
- 'urlFull': '',
206
- 'hostname': '',
207
- 'req': null,
208
- 'get': {},
209
- 'cookie': {},
210
- 'headers': {}
211
- }, '(sql.values) value error', '-error').catch(() => {
212
- //
213
- });
193
+ lCore.log({}, '[SQL][values] value error', '-error');
214
194
  values += `'', `;
215
195
  }
216
196
  else if (v === null) {
@@ -413,17 +393,7 @@ class Sql {
413
393
  sql += this.field(k) + ' = ';
414
394
  if (v === undefined || Number.isNaN(v)) {
415
395
  // --- 异常情况 ---
416
- lCore.log({
417
- 'path': '',
418
- 'urlFull': '',
419
- 'hostname': '',
420
- 'req': null,
421
- 'get': {},
422
- 'cookie': {},
423
- 'headers': {}
424
- }, '(sql._updateSub) value error, key: ' + k, '-error').catch(() => {
425
- //
426
- });
396
+ lCore.log({}, '[SQL][_updateSub] value error, key: ' + k, '-error');
427
397
  sql += '"", ';
428
398
  }
429
399
  else if (v === null) {
package/lib/ssh/sftp.js CHANGED
@@ -35,8 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Connection = void 0;
37
37
  // --- 库和定义 ---
38
- const core = __importStar(require("../../lib/core"));
39
- const text = __importStar(require("../../lib/text"));
38
+ const core = __importStar(require("~/lib/core"));
39
+ const text = __importStar(require("~/lib/text"));
40
40
  class Connection {
41
41
  constructor(sftp, path) {
42
42
  this._client = sftp;
package/lib/ssh/shell.js CHANGED
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Connection = void 0;
37
- const lCore = __importStar(require("../../lib/core"));
37
+ const lCore = __importStar(require("~/lib/core"));
38
38
  class Connection {
39
39
  constructor(stream) {
40
40
  this._client = stream;
package/lib/text.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as types from '../types';
1
+ import * as types from '~/types';
2
2
  /**
3
3
  * --- 将文件大小格式化为带单位的字符串 ---
4
4
  * @param size 文件大小
@@ -139,6 +139,11 @@ type TFalsy = false | '' | 0 | null | undefined | typeof NaN;
139
139
  * @param val 要判断的值
140
140
  */
141
141
  export declare function isFalsy(val: any): val is TFalsy;
142
+ /**
143
+ * --- 判断一个值是否是真实的(不为 null/undefined/空字符串/false/0) ---
144
+ * @param val 要判断的值
145
+ */
146
+ export declare function isTruthy(val: any): val is Exclude<typeof val, TFalsy>;
142
147
  /**
143
148
  * --- 类似 || 运算符的效果 ---
144
149
  * @param v1 比对值
package/lib/text.js CHANGED
@@ -58,6 +58,7 @@ exports.parseJson = parseJson;
58
58
  exports.stringifyJson = stringifyJson;
59
59
  exports.stringifyBuffer = stringifyBuffer;
60
60
  exports.isFalsy = isFalsy;
61
+ exports.isTruthy = isTruthy;
61
62
  exports.logicalOr = logicalOr;
62
63
  exports.str2int = str2int;
63
64
  exports.int2str = int2str;
@@ -66,7 +67,7 @@ exports.int2str = int2str;
66
67
  * Date: 2019-5-15 16:49:39
67
68
  * Last: 2020-04-06 20:51:06, 2022-9-29 15:18:16, 2022-12-29 00:01:30, 2024-3-6 17:53:14, 2024-5-31 17:29:52, 2025-6-13 15:47:02
68
69
  */
69
- const kebab = __importStar(require("../index"));
70
+ const kebab = __importStar(require("~/index"));
70
71
  const fs = __importStar(require("./fs"));
71
72
  /**
72
73
  * --- 将文件大小格式化为带单位的字符串 ---
@@ -587,6 +588,13 @@ function stringifyBuffer(buf) {
587
588
  function isFalsy(val) {
588
589
  return (val === null) || (val === undefined) || (val === '') || (val === false) || (val === 0);
589
590
  }
591
+ /**
592
+ * --- 判断一个值是否是真实的(不为 null/undefined/空字符串/false/0) ---
593
+ * @param val 要判断的值
594
+ */
595
+ function isTruthy(val) {
596
+ return !isFalsy(val);
597
+ }
590
598
  /**
591
599
  * --- 类似 || 运算符的效果 ---
592
600
  * @param v1 比对值
package/lib/time.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Date: 2019-6-6 12:04:15
4
4
  * Last: 2020-3-29 23:41:21, 2024-1-18 17:16:50, 2024-8-5 10:55:21
5
5
  */
6
- import * as sCtr from '../sys/ctr';
6
+ import * as sCtr from '~/sys/ctr';
7
7
  export interface IOptions {
8
8
  /** --- 时区 --- */
9
9
  'zone'?: number;
package/lib/time.js CHANGED
@@ -43,7 +43,7 @@ exports.format = format;
43
43
  * Date: 2019-6-6 12:04:15
44
44
  * Last: 2020-3-29 23:41:21, 2024-1-18 17:16:50, 2024-8-5 10:55:21
45
45
  */
46
- const sCtr = __importStar(require("../sys/ctr"));
46
+ const sCtr = __importStar(require("~/sys/ctr"));
47
47
  /** --- 一小时的秒数 --- */
48
48
  exports.HOUR = 3600;
49
49
  /** --- 一天的秒数 --- */
@@ -1,4 +1,4 @@
1
- import * as sCtr from '../sys/ctr';
1
+ import * as sCtr from '~/sys/ctr';
2
2
  /**
3
3
  * 0. CloudFlare:https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
4
4
  * 1. 腾讯云:https://cloud.tencent.com/document/product/1110/36926
package/lib/turnstile.js CHANGED
@@ -42,8 +42,8 @@ exports.verify = verify;
42
42
  */
43
43
  const tc = __importStar(require("tencentcloud-sdk-nodejs"));
44
44
  // --- 库和定义 ---
45
- const lNet = __importStar(require("../lib/net"));
46
- const lText = __importStar(require("../lib/text"));
45
+ const lNet = __importStar(require("~/lib/net"));
46
+ const lText = __importStar(require("~/lib/text"));
47
47
  /**
48
48
  * 0. CloudFlare:https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
49
49
  * 1. 腾讯云:https://cloud.tencent.com/document/product/1110/36926
package/lib/ws.d.ts CHANGED
@@ -5,8 +5,8 @@
5
5
  */
6
6
  import * as http from 'http';
7
7
  import * as net from 'net';
8
- import * as types from '../types';
9
- import * as sCtr from '../sys/ctr';
8
+ import * as types from '~/types';
9
+ import * as sCtr from '~/sys/ctr';
10
10
  /** --- 一般用 SIMPLE --- */
11
11
  export declare enum EFrameReceiveMode {
12
12
  STANDARD = 0,
@@ -153,3 +153,11 @@ export declare function mproxy(ctr: sCtr.Ctr, auth: string, opt?: IMproxyOptions
153
153
  * @param opt 参数
154
154
  */
155
155
  export declare function rproxy(ctr: sCtr.Ctr, url: string, opt?: IRproxyOptions): Promise<boolean>;
156
+ /**
157
+ * --- 反向代理,将本 websocket 连接反代到其他真正的 socket,在 ws 的 onLoad 事件中使用 ---
158
+ * @param ctr 当前控制器
159
+ * @param host 反代真实请求地址
160
+ * @param port 反代真实请求端口
161
+ * @param opt 参数
162
+ */
163
+ export declare function rsocket(ctr: sCtr.Ctr, host: string, port: number): Promise<boolean>;
package/lib/ws.js CHANGED
@@ -38,11 +38,13 @@ exports.connect = connect;
38
38
  exports.createServer = createServer;
39
39
  exports.mproxy = mproxy;
40
40
  exports.rproxy = rproxy;
41
+ exports.rsocket = rsocket;
42
+ const net = __importStar(require("net"));
41
43
  // --- 第三方 ---
42
44
  const liws = __importStar(require("@litert/websocket"));
43
45
  // --- 库 ---
44
- const lText = __importStar(require("../lib/text"));
45
- const lNet = __importStar(require("../lib/net"));
46
+ const lText = __importStar(require("~/lib/text"));
47
+ const lNet = __importStar(require("~/lib/net"));
46
48
  /** --- 一般用 SIMPLE --- */
47
49
  var EFrameReceiveMode;
48
50
  (function (EFrameReceiveMode) {
@@ -95,7 +97,7 @@ class Socket {
95
97
  'request': request,
96
98
  'socket': socket,
97
99
  'headers': options.headers,
98
- 'timeout': options.timeout
100
+ 'timeout': options.timeout,
99
101
  });
100
102
  this._bindEvent();
101
103
  }
@@ -358,6 +360,7 @@ function bindPipe(s1, s2) {
358
360
  }
359
361
  }
360
362
  }).on('close', () => {
363
+ s2.end();
361
364
  resolve();
362
365
  });
363
366
  // --- 监听远程端的 ---
@@ -390,6 +393,7 @@ function bindPipe(s1, s2) {
390
393
  }
391
394
  }
392
395
  }).on('close', () => {
396
+ s1.end();
393
397
  resolve();
394
398
  });
395
399
  });
@@ -445,3 +449,58 @@ async function rproxy(ctr, url, opt = {}) {
445
449
  await bindPipe(socket, rsocket);
446
450
  return true;
447
451
  }
452
+ /**
453
+ * --- 反向代理,将本 websocket 连接反代到其他真正的 socket,在 ws 的 onLoad 事件中使用 ---
454
+ * @param ctr 当前控制器
455
+ * @param host 反代真实请求地址
456
+ * @param port 反代真实请求端口
457
+ * @param opt 参数
458
+ */
459
+ async function rsocket(ctr, host, port) {
460
+ return new Promise(resolve => {
461
+ /** --- 请求端产生的双向 ws --- */
462
+ const ws = ctr.getPrototype('_socket');
463
+ /** --- 对端真实 tcp socket --- */
464
+ const socket = new net.Socket();
465
+ socket.connect(port, host, () => {
466
+ // --- 连接成功 ---
467
+ // --- 监听发送端的 ---
468
+ ws.on('message', msg => {
469
+ switch (msg.opcode) {
470
+ case EOpcode.TEXT:
471
+ case EOpcode.BINARY: {
472
+ socket.write(msg.data);
473
+ break;
474
+ }
475
+ case EOpcode.CLOSE: {
476
+ socket.end();
477
+ resolve(true);
478
+ break;
479
+ }
480
+ case EOpcode.PING: {
481
+ ws.pong();
482
+ break;
483
+ }
484
+ case EOpcode.PONG: {
485
+ break;
486
+ }
487
+ default: {
488
+ // --- EOpcode.CONTINUATION ---
489
+ }
490
+ }
491
+ }).on('close', () => {
492
+ socket.end();
493
+ resolve(true);
494
+ });
495
+ // --- 监听远程端的 ---
496
+ socket.on('data', data => {
497
+ ws.writeBinary(data);
498
+ }).on('close', () => {
499
+ ws.end();
500
+ resolve(true);
501
+ });
502
+ }).on('error', () => {
503
+ resolve(false);
504
+ });
505
+ });
506
+ }
package/lib/zip.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import jszip from 'jszip';
2
- import * as types from '../types';
2
+ import * as types from '~/types';
3
3
  /**
4
4
  * --- 本库主要用于读取 zip,请尽量不要用来写入 zip,尤其是大文件 zip ---
5
5
  */
package/lib/zip.js CHANGED
@@ -40,7 +40,7 @@ exports.Zip = void 0;
40
40
  exports.get = get;
41
41
  const jszip_1 = __importDefault(require("jszip"));
42
42
  const mime = __importStar(require("@litert/mime"));
43
- const lText = __importStar(require("../lib/text"));
43
+ const lText = __importStar(require("~/lib/text"));
44
44
  /**
45
45
  * --- 本库主要用于读取 zip,请尽量不要用来写入 zip,尤其是大文件 zip ---
46
46
  */
@@ -182,15 +182,9 @@ class Zip {
182
182
  * @param opt 选项
183
183
  */
184
184
  readDir(path, opt = {}) {
185
- if (opt.hasChildren === undefined) {
186
- opt.hasChildren = false;
187
- }
188
- if (opt.hasDir === undefined) {
189
- opt.hasDir = true;
190
- }
191
- if (opt.pathAsKey === undefined) {
192
- opt.pathAsKey = false;
193
- }
185
+ opt.hasChildren ??= false;
186
+ opt.hasDir ??= true;
187
+ opt.pathAsKey ??= false;
194
188
  if (!path) {
195
189
  path = this._path;
196
190
  }
@@ -302,7 +296,7 @@ class Zip {
302
296
  */
303
297
  _refreshList() {
304
298
  const list = {};
305
- // eslint-disable-next-line @litert/rules/disable-for-each-method
299
+ // eslint-disable-next-line @litert/disable-for-each-method
306
300
  this._zip.forEach(function (relativePath, item) {
307
301
  if (relativePath.startsWith('/')) {
308
302
  relativePath = relativePath.slice(1);
package/lib/zlib.js CHANGED
@@ -60,9 +60,7 @@ const zlib = __importStar(require("zlib"));
60
60
  * @param options 选项
61
61
  */
62
62
  function createGzip(options = {}) {
63
- if (!options.level) {
64
- options.level = 7;
65
- }
63
+ options.level ??= 7;
66
64
  return zlib.createGzip(options);
67
65
  }
68
66
  /**
@@ -76,9 +74,7 @@ function createGunzip() {
76
74
  * @param options 选项
77
75
  */
78
76
  function createDeflate(options = {}) {
79
- if (!options.level) {
80
- options.level = 7;
81
- }
77
+ options.level ??= 7;
82
78
  return zlib.createDeflate(options);
83
79
  }
84
80
  /**
@@ -92,9 +88,7 @@ function createInflate() {
92
88
  * @param options 选项
93
89
  */
94
90
  function createBrotliCompress(options = {}) {
95
- if (!options.level) {
96
- options.level = 7;
97
- }
91
+ options.level ??= 7;
98
92
  return zlib.createBrotliCompress(options);
99
93
  }
100
94
  /**
@@ -109,9 +103,7 @@ function createBrotliDecompress() {
109
103
  * @param options 选项
110
104
  */
111
105
  function createCompress(types, options = {}) {
112
- if (!options.level) {
113
- options.level = 7;
114
- }
106
+ options.level ??= 7;
115
107
  const type = getTypeByTypes(types);
116
108
  if (!type) {
117
109
  return null;
@@ -176,9 +168,7 @@ function createDecompress(types) {
176
168
  * @param options 选项
177
169
  */
178
170
  function gzip(buffer, options = {}) {
179
- if (!options.level) {
180
- options.level = 7;
181
- }
171
+ options.level ??= 7;
182
172
  return new Promise(function (resolve) {
183
173
  zlib.gzip(buffer, options, function (error, result) {
184
174
  if (error) {
@@ -212,9 +202,7 @@ function gunzip(buffer) {
212
202
  * @param options 选项
213
203
  */
214
204
  function deflate(buffer, options = {}) {
215
- if (!options.level) {
216
- options.level = 7;
217
- }
205
+ options.level ??= 7;
218
206
  return new Promise(function (resolve) {
219
207
  zlib.deflate(buffer, options, function (error, result) {
220
208
  if (error) {
@@ -248,9 +236,7 @@ function inflate(buffer) {
248
236
  * @param options 选项
249
237
  */
250
238
  function brotliCompress(buffer, options = {}) {
251
- if (!options.level) {
252
- options.level = 7;
253
- }
239
+ options.level ??= 7;
254
240
  return new Promise(function (resolve) {
255
241
  zlib.brotliCompress(buffer, options, function (error, result) {
256
242
  if (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "keywords": [
6
6
  "kebab",
@@ -14,8 +14,8 @@
14
14
  "kebab": "./bin/kebab.js"
15
15
  },
16
16
  "dependencies": {
17
- "@aws-sdk/client-s3": "^3.826.0",
18
- "@aws-sdk/lib-storage": "^3.826.0",
17
+ "@aws-sdk/client-s3": "^3.844.0",
18
+ "@aws-sdk/lib-storage": "^3.844.0",
19
19
  "@litert/http-client": "^1.1.2",
20
20
  "@litert/mime": "^0.1.3",
21
21
  "@litert/redis": "^3.0.5",
@@ -26,12 +26,13 @@
26
26
  "mysql2": "^3.14.1",
27
27
  "ssh2": "^1.16.0",
28
28
  "svg-captcha": "^1.4.0",
29
+ "tencentcloud-sdk-nodejs": "^4.1.74",
29
30
  "ts-alias-loader": "^0.1.5"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@litert/eslint-plugin-rules": "^0.3.1",
33
34
  "@types/ejs": "^3.1.5",
34
- "@types/node": "^24.0.0",
35
+ "@types/node": "^24.0.12",
35
36
  "tsc-alias": "^1.8.16",
36
37
  "typescript": "^5.8.3"
37
38
  }