@maiyunnet/kebab 2.0.7 → 2.0.9

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 +5 -0
  58. package/main.js +12 -0
  59. package/package.json +3 -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/sys/ctr.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Project: Kebab, User: JianSuoQiYue
3
+ * Date: 2020-3-14 17:24:38
4
+ * Last: 2020-3-30 15:31:40, 2022-07-22 16:59:00, 2022-09-12 23:51:56, 2022-09-23 15:53:58, 2022-12-29 01:18:08, 2023-2-28 20:07:57, 2023-12-27 18:39:35, 2024-3-1 19:38:53, 2024-4-9 16:03:58, 2025-2-12 18:55:44, 2025-6-12 16:56:08
5
+ */
1
6
  import * as http from 'http';
2
7
  import * as http2 from 'http2';
3
8
  import * as session from '../lib/session';
@@ -5,41 +10,75 @@ import * as db from '../lib/db';
5
10
  import * as kv from '../lib/kv';
6
11
  import * as lWs from '../lib/ws';
7
12
  import * as types from '../types';
13
+ /**
14
+ * --- 清除已经加载的 data 与语言包文件缓存 ---
15
+ */
8
16
  export declare function clearLocaleData(): void;
9
17
  export declare class Ctr {
18
+ /** --- 路由参数序列数组 --- */
10
19
  protected _param: string[];
20
+ /** --- 当前的 action 名 --- */
11
21
  protected _action: string;
22
+ /** --- 请求的 header 列表,key 均为小写 --- */
12
23
  protected _headers: http.IncomingHttpHeaders;
24
+ /** --- GET 数据 --- */
13
25
  protected _get: Record<string, string>;
26
+ /** --- 原始 POST 数据 --- */
14
27
  protected _rawPost: Record<string, types.Json>;
28
+ /** --- POST 数据 --- */
15
29
  protected _post: Record<string, types.Json>;
30
+ /** --- 原始 input 字符串 */
16
31
  protected _input: string;
32
+ /** --- 上传的文件列表 --- */
17
33
  protected _files: Record<string, types.IPostFile | types.IPostFile[]>;
34
+ /** --- Cookie 数组 --- */
18
35
  protected _cookie: Record<string, string>;
36
+ /** --- Jwt 数组 --- */
19
37
  protected _jwt: Record<string, types.Json>;
38
+ /** --- Session 数组 --- */
20
39
  protected _session: Record<string, types.Json>;
40
+ /** --- Session --- 对象 */
21
41
  protected _sess: session.Session | null;
42
+ /** --- 页面浏览器客户端缓存 --- */
22
43
  protected _cacheTTL: number;
44
+ /** --- XSRF TOKEN 值 --- */
23
45
  protected _xsrf: string;
46
+ /** --- 自定义 http code --- */
24
47
  protected _httpCode: number;
48
+ /** --- 当前语言名 --- */
25
49
  protected _locale: string;
50
+ /** --- vhost 的 kebab.json 以及全局常量 --- */
26
51
  protected readonly _config: types.IConfig;
27
52
  protected readonly _req: http2.Http2ServerRequest | http.IncomingMessage;
28
53
  protected readonly _res: http2.Http2ServerResponse | http.ServerResponse;
29
54
  protected readonly _socket: lWs.Socket;
55
+ /** --- 本 ctr 已加载的语言文件列表 --- */
30
56
  protected _localeFiles: string[];
57
+ /** --- 本 ctr 的 locale data --- */
31
58
  protected _localeData: Record<string, Record<string, string>>;
32
59
  constructor(config: types.IConfig, req: http2.Http2ServerRequest | http.IncomingMessage, res?: http2.Http2ServerResponse | http.ServerResponse);
60
+ /** --- 当前用户连接是否还在连接中 --- */
33
61
  get isAvail(): boolean;
62
+ /** --- timeout 的 timer --- */
34
63
  protected _timer?: {
35
64
  'timer': NodeJS.Timeout;
36
65
  'timeout': number;
37
66
  'callback': () => void;
38
67
  };
68
+ /** --- 获取当前过期时间 --- */
39
69
  get timeout(): number;
70
+ /**
71
+ * --- 设置当前过期时间 ---
72
+ */
40
73
  set timeout(num: number);
74
+ /** --- 一些需要等待的事项的记录(异步任务、事务) --- */
41
75
  private readonly _waitInfo;
76
+ /**
77
+ * --- 执行一段跳出堆栈的异步代码,代码执行完成前,热更新不会杀死当面进程 且 ftmp 临时文件不会被清除 ---
78
+ * @param func 异步代码
79
+ */
42
80
  protected _asyncTask(func: () => void | Promise<void>): void;
81
+ /** --- 获取类内部的 prototype --- */
43
82
  getPrototype(name: '_config'): types.IConfig;
44
83
  getPrototype(name: '_sess'): session.Session | null;
45
84
  getPrototype(name: '_headers'): http.IncomingHttpHeaders;
@@ -49,45 +88,172 @@ export declare class Ctr {
49
88
  getPrototype(name: '_rawPost' | '_post' | '_get' | '_session'): Record<string, types.Json>;
50
89
  getPrototype(name: '_input'): string;
51
90
  getPrototype(name: string): types.Json;
91
+ /** --- 设置类内部的 prototype --- */
52
92
  setPrototype(name: string, val: string | string[] | http.IncomingHttpHeaders | Record<string, types.Json> | session.Session | lWs.Socket | null): void;
93
+ /**
94
+ * --- 实例化后会执行的方法,可重写此方法 ---
95
+ */
53
96
  onLoad(): boolean | string | types.DbValue[] | Promise<boolean | string | types.DbValue[]>;
97
+ /**
98
+ * --- 整个结束前会执行本方法,可重写此方法对输出结果再处理一次(Websocket 模式无效) ---
99
+ * @param rtn 之前用户的输出结果
100
+ */
54
101
  onUnload(rtn: boolean | string | types.DbValue[]): boolean | string | types.DbValue[] | Promise<boolean | string | types.DbValue[]>;
102
+ /**
103
+ * --- WebSocket 下在建立 Server 连接之前可对 WebSocket 的信息进行配置 ---
104
+ */
55
105
  onUpgrade(): {
56
106
  'headers'?: http.OutgoingHttpHeaders;
57
107
  'timeout'?: number;
58
108
  };
109
+ /**
110
+ * --- WebSocket 下当收到数据时会自动被调用的事件,即只文本和二进制数据,返回内容会被发送给 socket,但返回 false 连接会被中断 ---
111
+ */
59
112
  onData(data: Buffer | string, opcode: lWs.EOpcode): types.Json;
113
+ /**
114
+ * --- 包含所有 opcode 的消息,若要发送数据需自行调用 write 方法,返回 false 则不会执行默认方法 ---
115
+ * @param data 数据
116
+ * @param opcode opcode
117
+ */
60
118
  onMessage(data: Buffer | string, opcode: lWs.EOpcode): undefined | boolean | Promise<undefined | boolean>;
119
+ /**
120
+ * --- WebSocket 下连接恢复可写入状态后会调用此事件,可重写此方法 ---
121
+ */
61
122
  onDrain(): void | Promise<void>;
123
+ /**
124
+ * --- WebSocket 下连接被终止后会自动被调用的事件,可重写此方法 ---
125
+ */
62
126
  onClose(): void | Promise<void>;
127
+ /**
128
+ * --- 获取截止当前时间的总运行时间 ---
129
+ * @param ms 为 true 为毫秒,否则为秒
130
+ */
63
131
  protected _getRunTime(ms?: boolean): number;
132
+ /**
133
+ * --- 获取截止当前内存的使用情况 ---
134
+ */
64
135
  protected _getMemoryUsage(): number;
136
+ /**
137
+ * --- 加载视图 ---
138
+ * @param path
139
+ * @param data
140
+ */
65
141
  protected _loadView(path: string, data?: types.Json): Promise<string>;
142
+ /**
143
+ * --- 检测提交的数据类型 ---
144
+ * @param input 要校验的输入项
145
+ * @param rule 规则
146
+ * @param rtn 返回值
147
+ */
66
148
  protected _checkInput(input: Record<string, types.Json>, rule: Record<string, types.Json[]>, rtn: types.Json[]): boolean;
149
+ /**
150
+ * --- 检测提交的数据类型(会检测 XSRF) ---
151
+ * @param input 要校验的输入项
152
+ * @param rule 规则
153
+ * @param rtn 返回值
154
+ */
67
155
  protected _checkXInput(input: Record<string, types.Json>, rule: Record<string, types.Json[]>, rtn: types.Json[]): boolean;
156
+ /**
157
+ * --- 当前页面开启 XSRF 支持(主要检测 cookie 是否存在) ---
158
+ * --- 如果当前页面有 CDN,请不要使用 ---
159
+ */
68
160
  protected _enabledXsrf(): void;
161
+ /**
162
+ * --- 获取 Auth 字符串,用于客户端提交 ---
163
+ * @param user 用户名
164
+ * @param pwd 密码
165
+ */
69
166
  protected _getBasicAuth(user: string, pwd: string): string;
167
+ /**
168
+ * --- 根据用户 ua 获取当前用户的设备类型 ---
169
+ */
70
170
  protected _device(): 'android' | 'windows' | 'linux' | 'macintosh' | 'ipad' | 'unknown';
171
+ /** --- auth 对象,user, pwd --- */
71
172
  private _authorization;
173
+ /**
174
+ * --- 通过 header 或 _auth 获取鉴权信息或 JWT 信息(不解析) ---
175
+ */
72
176
  getAuthorization(): {
73
177
  'user': string;
74
178
  'pwd': string;
75
179
  } | false | string;
180
+ /**
181
+ * --- 获取 data 数据 ---
182
+ * @param path 文件路径(不含扩展名)
183
+ */
76
184
  protected _loadData(path: string): Promise<Record<string, string> | null>;
185
+ /**
186
+ * --- 跳转(302临时跳转),支持相对本项目根路径的路径或绝对路径 ---
187
+ * @param location 相对或绝对网址
188
+ */
77
189
  protected _location(location: string): false;
190
+ /**
191
+ * --- 开启 Session ---
192
+ * @param link Kv 或 Db 实例
193
+ * @param auth 设为 true 则从头 Authorization 或 post _auth 值读取 token
194
+ * @param opt name, ttl, ssl, sqlPre
195
+ */
78
196
  protected _startSession(link: db.Pool | kv.Pool, auth?: boolean, opt?: session.IOptions): Promise<void>;
197
+ /**
198
+ * --- 设定语言并加载语言包 ---
199
+ * @param loc 要加载的目标语言
200
+ * @param pkg 包名,为空自动填充为 default
201
+ */
79
202
  protected _loadLocale(loc: string, pkg?: string): Promise<boolean>;
80
203
  private _loadLocaleDeep;
204
+ /**
205
+ * --- 根据当前后台语言包设置情况获取 JSON 字符串传输到前台 ---
206
+ * @return string
207
+ */
81
208
  protected _getLocaleJsonString(): string;
209
+ /**
210
+ * --- 获取当前语言名 ---
211
+ */
82
212
  protected _getLocale(): string;
213
+ /**
214
+ * --- 开启跨域请求 ---
215
+ * 返回 true 接续执行,返回 false 需要中断用户本次访问(options请求)
216
+ */
83
217
  protected _cross(): boolean;
218
+ /**
219
+ * --- 获取语言包值 ---
220
+ * @param key
221
+ * @param data 要替换的数据
222
+ */
84
223
  _l(key: string, data?: string[]): string;
224
+ /**
225
+ * --- 发送 socket 文本 ---
226
+ * @param data 要发送的信息
227
+ */
85
228
  protected _writeText(data: string): boolean;
229
+ /**
230
+ * --- 发送结果对象文本 ---
231
+ * @param data 要发送的结果对象,如 [0, 'Failed.']
232
+ */
86
233
  protected _writeResult(data: types.Json): boolean;
234
+ /**
235
+ * --- 发送 socket 二进制 ---
236
+ * @param data 要发送的信息
237
+ */
87
238
  protected _writeBinary(data: Buffer | string | Array<Buffer | string>): boolean;
239
+ /**
240
+ * --- 发送 socket ping ---
241
+ * @param data 要发送的信息
242
+ */
88
243
  protected _ping(): boolean;
244
+ /**
245
+ * --- 发送 socket pong ---
246
+ * @param data 要发送的信息
247
+ */
89
248
  protected _pong(): boolean;
249
+ /**
250
+ * --- 主动关闭当前 socket 连接 ---
251
+ */
90
252
  protected _end(): void;
253
+ /**
254
+ * --- 获取 formdata 的信息 ---
255
+ * @param events 文件处理情况
256
+ */
91
257
  protected _handleFormData(events?: {
92
258
  onfilestart?: (name: string) => boolean | undefined;
93
259
  onfiledata?: (chunk: Buffer) => void;