@maiyunnet/kebab 7.0.1 → 7.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/lib/ws.js CHANGED
@@ -24,35 +24,9 @@ const liwsServer = liws.createServer({
24
24
  'frameReceiveMode': EFrameReceiveMode.SIMPLE,
25
25
  });
26
26
  export class Socket {
27
+ /** --- 当前的 ws 对象 --- */
28
+ _ws;
27
29
  constructor(request, socket, head, options = {}) {
28
- /** --- 还未开启监听时来的数据将存在这里 --- */
29
- this._waitMsg = [];
30
- /** --- 还未开启 error 监听时产生的 error 错误对象 --- */
31
- this._error = null;
32
- /** --- 还未开启 close 监听时是不是就已经 close --- */
33
- this._close = false;
34
- /** --- 未绑定自定义监听事件的默认执行函数 --- */
35
- this._on = {
36
- /** --- 消息 --- */
37
- message: (msg) => {
38
- this._waitMsg.push(msg);
39
- },
40
- drain: () => {
41
- // --- nothing ---
42
- },
43
- error: (e) => {
44
- this._error = e;
45
- },
46
- close: () => {
47
- this._close = true;
48
- },
49
- end: () => {
50
- // --- nothing ---
51
- },
52
- timeout: () => {
53
- // --- nothing ---
54
- }
55
- };
56
30
  if (!request || !socket) {
57
31
  return;
58
32
  }
@@ -167,6 +141,34 @@ export class Socket {
167
141
  this._on.timeout();
168
142
  });
169
143
  }
144
+ /** --- 还未开启监听时来的数据将存在这里 --- */
145
+ _waitMsg = [];
146
+ /** --- 还未开启 error 监听时产生的 error 错误对象 --- */
147
+ _error = null;
148
+ /** --- 还未开启 close 监听时是不是就已经 close --- */
149
+ _close = false;
150
+ /** --- 未绑定自定义监听事件的默认执行函数 --- */
151
+ _on = {
152
+ /** --- 消息 --- */
153
+ message: (msg) => {
154
+ this._waitMsg.push(msg);
155
+ },
156
+ drain: () => {
157
+ // --- nothing ---
158
+ },
159
+ error: (e) => {
160
+ this._error = e;
161
+ },
162
+ close: () => {
163
+ this._close = true;
164
+ },
165
+ end: () => {
166
+ // --- nothing ---
167
+ },
168
+ timeout: () => {
169
+ // --- nothing ---
170
+ }
171
+ };
170
172
  on(event, cb) {
171
173
  this._on[event] = cb;
172
174
  switch (event) {
package/lib/zip.js CHANGED
@@ -5,11 +5,11 @@ import * as lText from '#kebab/lib/text.js';
5
5
  * --- 本库主要用于读取 zip,请尽量不要用来写入 zip,尤其是大文件 zip ---
6
6
  */
7
7
  export class Zip {
8
+ /** --- zip 对象 --- */
9
+ _zip;
10
+ /** --- 当前路径,以 / 开头以 / 结尾 --- */
11
+ _path = '/';
8
12
  constructor(zip) {
9
- /** --- 当前路径,以 / 开头以 / 结尾 --- */
10
- this._path = '/';
11
- /** --- 目录列表缓存 --- */
12
- this._list = {};
13
13
  this._zip = zip;
14
14
  this._refreshList();
15
15
  }
@@ -250,6 +250,8 @@ export class Zip {
250
250
  return list;
251
251
  }
252
252
  }
253
+ /** --- 目录列表缓存 --- */
254
+ _list = {};
253
255
  /**
254
256
  * --- 重建目录列表缓存 ---
255
257
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "7.0.1",
3
+ "version": "7.1.0",
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.940.0",
26
- "@aws-sdk/lib-storage": "^3.940.0",
25
+ "@aws-sdk/client-s3": "^3.943.0",
26
+ "@aws-sdk/lib-storage": "^3.943.0",
27
27
  "@litert/http-client": "^1.1.2",
28
28
  "@litert/mime": "^0.1.3",
29
29
  "@litert/redis": "^3.1.0",
@@ -45,8 +45,8 @@
45
45
  "@types/ejs": "^3.1.5",
46
46
  "@types/node": "^24.10.1",
47
47
  "@types/pg": "^8.15.6",
48
+ "@typescript/native-preview": "^7.0.0-dev.20251203.1",
48
49
  "typedoc": "^0.28.15",
49
- "typedoc-plugin-markdown": "^4.9.0",
50
- "typescript": "^5.9.3"
50
+ "typedoc-plugin-markdown": "^4.9.0"
51
51
  }
52
52
  }
package/sys/child.js CHANGED
@@ -39,6 +39,23 @@ let httpServer;
39
39
  let http2Server;
40
40
  /** --- 当前使用中的连接 --- */
41
41
  const linkCount = {};
42
+ /**
43
+ * --- 包装请求处理函数,统一管理 linkCount 计数和错误处理 ---
44
+ * @param key 连接标识
45
+ * @param handler 实际处理函数
46
+ * @param errorPrefix 错误日志前缀
47
+ */
48
+ function wrapWithLinkCount(key, handler, errorPrefix) {
49
+ linkCount[key] = (linkCount[key] ?? 0) + 1;
50
+ handler().catch((e) => {
51
+ lCore.log({}, `${errorPrefix} ${lText.stringifyJson(e.stack).slice(1, -1)}`, '-error');
52
+ }).finally(() => {
53
+ --linkCount[key];
54
+ if (!linkCount[key]) {
55
+ delete linkCount[key];
56
+ }
57
+ });
58
+ }
42
59
  /**
43
60
  * --- 最终调用执行的函数块,创建 http 服务器等 ---
44
61
  */
@@ -93,24 +110,7 @@ async function run() {
93
110
  res.end('403 Forbidden');
94
111
  return;
95
112
  }
96
- const key = host + req.url;
97
- (async function () {
98
- if (!linkCount[key]) {
99
- linkCount[key] = 0;
100
- }
101
- ++linkCount[key];
102
- await requestHandler(req, res, true);
103
- --linkCount[key];
104
- if (!linkCount[key]) {
105
- delete linkCount[key];
106
- }
107
- })().catch(function (e) {
108
- lCore.log({}, '[CHILD][http2][request] ' + lText.stringifyJson(e.stack).slice(1, -1), '-error');
109
- --linkCount[key];
110
- if (!linkCount[key]) {
111
- delete linkCount[key];
112
- }
113
- });
113
+ wrapWithLinkCount(host + req.url, () => requestHandler(req, res, true), '[CHILD][http2][request]');
114
114
  }).on('tlsClientError', (err, socket) => {
115
115
  socket.destroy();
116
116
  }).on('upgrade', function (req, socket, head) {
@@ -119,24 +119,7 @@ async function run() {
119
119
  socket.destroy();
120
120
  return;
121
121
  }
122
- const key = host + (req.url ?? '');
123
- (async function () {
124
- if (!linkCount[key]) {
125
- linkCount[key] = 0;
126
- }
127
- ++linkCount[key];
128
- await upgradeHandler(req, socket, true, head);
129
- --linkCount[key];
130
- if (!linkCount[key]) {
131
- delete linkCount[key];
132
- }
133
- })().catch(function (e) {
134
- lCore.log({}, '[CHILD][http2][upgrade] ' + lText.stringifyJson(e.stack).slice(1, -1), '-error');
135
- --linkCount[key];
136
- if (!linkCount[key]) {
137
- delete linkCount[key];
138
- }
139
- });
122
+ wrapWithLinkCount(host + (req.url ?? ''), () => upgradeHandler(req, socket, true, head), '[CHILD][http2][upgrade]');
140
123
  }).listen(lCore.globalConfig.httpsPort);
141
124
  httpServer = http.createServer(function (req, res) {
142
125
  const host = (req.headers['host'] ?? '');
@@ -146,24 +129,7 @@ async function run() {
146
129
  res.end();
147
130
  return;
148
131
  }
149
- const key = host + (req.url ?? '');
150
- (async function () {
151
- if (!linkCount[key]) {
152
- linkCount[key] = 0;
153
- }
154
- ++linkCount[key];
155
- await requestHandler(req, res, false);
156
- --linkCount[key];
157
- if (!linkCount[key]) {
158
- delete linkCount[key];
159
- }
160
- })().catch(function (e) {
161
- lCore.log({}, '[CHILD][http][request] ' + lText.stringifyJson(e.stack).slice(1, -1), '-error');
162
- --linkCount[key];
163
- if (!linkCount[key]) {
164
- delete linkCount[key];
165
- }
166
- });
132
+ wrapWithLinkCount(host + (req.url ?? ''), () => requestHandler(req, res, false), '[CHILD][http][request]');
167
133
  }).on('clientError', (err, socket) => {
168
134
  socket.destroy();
169
135
  }).on('upgrade', function (req, socket, head) {
@@ -172,24 +138,7 @@ async function run() {
172
138
  socket.destroy();
173
139
  return;
174
140
  }
175
- const key = host + (req.url ?? '');
176
- (async function () {
177
- if (!linkCount[key]) {
178
- linkCount[key] = 0;
179
- }
180
- ++linkCount[key];
181
- await upgradeHandler(req, socket, false, head);
182
- --linkCount[key];
183
- if (!linkCount[key]) {
184
- delete linkCount[key];
185
- }
186
- })().catch(function (e) {
187
- lCore.log({}, '[CHILD][http][upgrade] ' + lText.stringifyJson(e.stack).slice(1, -1), '-error');
188
- --linkCount[key];
189
- if (!linkCount[key]) {
190
- delete linkCount[key];
191
- }
192
- });
141
+ wrapWithLinkCount(host + (req.url ?? ''), () => upgradeHandler(req, socket, false, head), '[CHILD][http][upgrade]');
193
142
  }).listen(lCore.globalConfig.httpPort);
194
143
  }
195
144
  /**
package/sys/ctr.d.ts CHANGED
@@ -150,6 +150,13 @@ export declare class Ctr {
150
150
  * @param data
151
151
  */
152
152
  protected _loadView(path: string, data?: kebab.Json): Promise<string>;
153
+ /**
154
+ * --- 设置校验错误返回值 ---
155
+ * @param rtn 返回值数组
156
+ * @param lastVal 规则最后一项
157
+ * @param msgSuffix 可选的消息后缀
158
+ */
159
+ private _setCheckError;
153
160
  /**
154
161
  * --- 检测提交的数据类型 ---
155
162
  * @param input 要校验的输入项