@maiyunnet/kebab 3.1.4 → 3.1.5
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/index.d.ts +147 -1
- package/index.js +2 -1
- package/lib/core.d.ts +5 -5
- package/lib/core.js +1 -1
- package/lib/db.d.ts +12 -12
- package/lib/db.js +0 -1
- package/lib/jwt.d.ts +8 -8
- package/lib/jwt.js +0 -1
- package/lib/kv.d.ts +41 -41
- package/lib/kv.js +0 -1
- package/lib/net/request.d.ts +5 -5
- package/lib/net/request.js +2 -2
- package/lib/net/response.d.ts +5 -5
- package/lib/net.d.ts +79 -62
- package/lib/net.js +20 -20
- package/lib/sql.d.ts +20 -20
- package/lib/sql.js +0 -5
- package/lib/text.d.ts +9 -4
- package/lib/text.js +3 -3
- package/lib/ws.d.ts +8 -7
- package/lib/ws.js +0 -1
- package/lib/zip.d.ts +55 -11
- package/package.json +5 -4
- package/sys/child.js +1 -1
- package/sys/ctr.d.ts +24 -24
- package/sys/ctr.js +15 -15
- package/sys/mod.d.ts +40 -26
- package/sys/mod.js +1 -1
- package/sys/route.d.ts +7 -7
- package/sys/route.js +1 -1
- package/www/example/ctr/main.d.ts +2 -2
- package/www/example/ctr/main.js +2 -2
- package/www/example/ctr/middle.d.ts +4 -4
- package/www/example/ctr/middle.js +2 -2
- package/www/example/ctr/test.d.ts +24 -24
- package/www/example/ctr/test.js +2 -2
- package/www/example/mod/test.d.ts +2 -2
- package/types/index.d.ts +0 -284
package/lib/net/request.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2020-4-9 20:02:39
|
|
4
|
-
* Last: 2020-4-9 20:47:58, 2022-09-10 01:35:34
|
|
4
|
+
* Last: 2020-4-9 20:47:58, 2022-09-10 01:35:34, 2025-9-23 12:41:58
|
|
5
5
|
*/
|
|
6
6
|
import * as stream from 'stream';
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
7
|
+
import * as lNet from '#lib/net.js';
|
|
8
|
+
import * as lResponse from './response.js';
|
|
9
9
|
export declare class Request {
|
|
10
10
|
/** --- get 或 post 的数据 --- */
|
|
11
11
|
private _data;
|
|
@@ -70,7 +70,7 @@ export declare class Request {
|
|
|
70
70
|
* --- 批量设置提交的 headers ---
|
|
71
71
|
* @param headers
|
|
72
72
|
*/
|
|
73
|
-
headers(headers:
|
|
73
|
+
headers(headers: lNet.THttpHeaders): this;
|
|
74
74
|
/**
|
|
75
75
|
* --- 设置单条 header ---
|
|
76
76
|
* @param name
|
|
@@ -81,5 +81,5 @@ export declare class Request {
|
|
|
81
81
|
* --- 发起请求 ---
|
|
82
82
|
* @param cookie
|
|
83
83
|
*/
|
|
84
|
-
request(cookie?: Record<string,
|
|
84
|
+
request(cookie?: Record<string, lNet.ICookie>): Promise<lResponse.Response>;
|
|
85
85
|
}
|
package/lib/net/request.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as lNet from '#lib/net.js';
|
|
2
2
|
export class Request {
|
|
3
3
|
constructor(url) {
|
|
4
4
|
/** --- get 或 post 的数据 --- */
|
|
@@ -115,6 +115,6 @@ export class Request {
|
|
|
115
115
|
*/
|
|
116
116
|
request(cookie) {
|
|
117
117
|
this._opt.cookie = cookie;
|
|
118
|
-
return
|
|
118
|
+
return lNet.request(this._url, this._data, this._opt);
|
|
119
119
|
}
|
|
120
120
|
}
|
package/lib/net/response.d.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* Last: 2020-4-12 11:12:03, 2022-09-10 12:43:23, 2022-12-25 15:12:57, 2023-9-26 14:20:41
|
|
5
5
|
*/
|
|
6
6
|
import * as hc from '@litert/http-client';
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
7
|
+
import * as stream from 'stream';
|
|
8
|
+
import * as lNet from '#lib/net.js';
|
|
9
9
|
export declare class Response {
|
|
10
10
|
/** --- httpClient 请求对象 --- */
|
|
11
11
|
private readonly _req;
|
|
12
12
|
/** --- 返回的 headers --- */
|
|
13
|
-
headers:
|
|
13
|
+
headers: lNet.THttpHeaders | null;
|
|
14
14
|
error: Error | null;
|
|
15
15
|
/** --- 用户自定义的 content 内容 --- */
|
|
16
16
|
private _content;
|
|
@@ -27,9 +27,9 @@ export declare class Response {
|
|
|
27
27
|
/**
|
|
28
28
|
* --- 获取响应读取流对象 ---
|
|
29
29
|
*/
|
|
30
|
-
getStream():
|
|
30
|
+
getStream(): stream.Readable;
|
|
31
31
|
/**
|
|
32
32
|
* --- 获取原生响应读取流对象 ---
|
|
33
33
|
*/
|
|
34
|
-
getRawStream():
|
|
34
|
+
getRawStream(): stream.Readable;
|
|
35
35
|
}
|
package/lib/net.d.ts
CHANGED
|
@@ -7,61 +7,11 @@
|
|
|
7
7
|
import * as stream from 'stream';
|
|
8
8
|
import * as http from 'http';
|
|
9
9
|
import * as http2 from 'http2';
|
|
10
|
-
import * as
|
|
11
|
-
import * as
|
|
10
|
+
import * as kebab from '#index.js';
|
|
11
|
+
import * as sCtr from '#sys/ctr.js';
|
|
12
12
|
import * as fd from './net/formdata.js';
|
|
13
13
|
import * as lRequest from './net/request.js';
|
|
14
14
|
import * as lResponse from './net/response.js';
|
|
15
|
-
/** --- 请求的传入参数选项 --- */
|
|
16
|
-
export interface IRequestOptions {
|
|
17
|
-
'method'?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
|
|
18
|
-
'type'?: 'form' | 'json';
|
|
19
|
-
/** --- 秒数 --- */
|
|
20
|
-
'timeout'?: number;
|
|
21
|
-
'follow'?: number;
|
|
22
|
-
'hosts'?: Record<string, string>;
|
|
23
|
-
'save'?: string;
|
|
24
|
-
'local'?: string;
|
|
25
|
-
'headers'?: types.THttpHeaders;
|
|
26
|
-
/** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
|
|
27
|
-
'mproxy'?: {
|
|
28
|
-
'url': string;
|
|
29
|
-
'auth': string;
|
|
30
|
-
'data'?: any;
|
|
31
|
-
};
|
|
32
|
-
/** --- 默认为 default --- */
|
|
33
|
-
'reuse'?: string;
|
|
34
|
-
/** --- cookie 托管对象 --- */
|
|
35
|
-
'cookie'?: Record<string, types.ICookie>;
|
|
36
|
-
}
|
|
37
|
-
/** --- 正向代理请求的传入参数选项 --- */
|
|
38
|
-
export interface IMproxyOptions {
|
|
39
|
-
/** --- 秒数 --- */
|
|
40
|
-
'timeout'?: number;
|
|
41
|
-
'follow'?: number;
|
|
42
|
-
'hosts'?: Record<string, string>;
|
|
43
|
-
'local'?: string;
|
|
44
|
-
'headers'?: types.THttpHeaders;
|
|
45
|
-
/** --- 默认为 default --- */
|
|
46
|
-
'reuse'?: string;
|
|
47
|
-
}
|
|
48
|
-
/** --- 反向代理请求的传入参数选项 --- */
|
|
49
|
-
export interface IRproxyOptions {
|
|
50
|
-
/** --- 秒数 --- */
|
|
51
|
-
'timeout'?: number;
|
|
52
|
-
'follow'?: number;
|
|
53
|
-
'hosts'?: Record<string, string>;
|
|
54
|
-
'local'?: string;
|
|
55
|
-
'headers'?: types.THttpHeaders;
|
|
56
|
-
/** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
|
|
57
|
-
'mproxy'?: {
|
|
58
|
-
'url': string;
|
|
59
|
-
'auth': string;
|
|
60
|
-
'data'?: any;
|
|
61
|
-
};
|
|
62
|
-
/** --- 默认为 default --- */
|
|
63
|
-
'reuse'?: string;
|
|
64
|
-
}
|
|
65
15
|
/** --- 获取 CA 证书 --- */
|
|
66
16
|
export declare function getCa(): Promise<string>;
|
|
67
17
|
/**
|
|
@@ -81,19 +31,19 @@ export declare function get(u: string, opt?: IRequestOptions): Promise<lResponse
|
|
|
81
31
|
* @param data 要发送的数据
|
|
82
32
|
* @param opt 参数
|
|
83
33
|
*/
|
|
84
|
-
export declare function post(u: string, data: Record<string,
|
|
34
|
+
export declare function post(u: string, data: Record<string, kebab.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
85
35
|
/**
|
|
86
36
|
* --- 发起 JSON 请求 ---
|
|
87
37
|
* @param u
|
|
88
38
|
* @param data
|
|
89
39
|
* @param opt
|
|
90
40
|
*/
|
|
91
|
-
export declare function postJson(u: string, data:
|
|
41
|
+
export declare function postJson(u: string, data: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
92
42
|
/**
|
|
93
43
|
* --- 发起一个请求 ---
|
|
94
44
|
* @param opt 配置项
|
|
95
45
|
*/
|
|
96
|
-
export declare function request(u: string, data?: Record<string,
|
|
46
|
+
export declare function request(u: string, data?: Record<string, kebab.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
97
47
|
/**
|
|
98
48
|
* --- 对 cookie 对象进行操作 ---
|
|
99
49
|
* @param cookie 要操作的对象
|
|
@@ -102,7 +52,7 @@ export declare function request(u: string, data?: Record<string, types.Json> | B
|
|
|
102
52
|
* @param domain 应用网址,如 .xxx.com
|
|
103
53
|
* @param opt 选项 ttl, path, ssl, httponly
|
|
104
54
|
*/
|
|
105
|
-
export declare function setCookie(cookie: Record<string,
|
|
55
|
+
export declare function setCookie(cookie: Record<string, ICookie>, name: string, value: string, domain: string, opt?: {
|
|
106
56
|
'ttl'?: number;
|
|
107
57
|
'path'?: string;
|
|
108
58
|
'ssl'?: boolean;
|
|
@@ -113,12 +63,12 @@ export declare function setCookie(cookie: Record<string, types.ICookie>, name: s
|
|
|
113
63
|
* @param cookie cookie 对象
|
|
114
64
|
* @param uri 请求的 URI 对象
|
|
115
65
|
*/
|
|
116
|
-
export declare function buildCookieQuery(cookie: Record<string,
|
|
66
|
+
export declare function buildCookieQuery(cookie: Record<string, ICookie>, uri: kebab.IUrlParse): string;
|
|
117
67
|
/**
|
|
118
68
|
* --- 模拟重启浏览器后的状态 ---
|
|
119
69
|
* @param cookie cookie 对象
|
|
120
70
|
*/
|
|
121
|
-
export declare function resetCookieSession(cookie: Record<string,
|
|
71
|
+
export declare function resetCookieSession(cookie: Record<string, ICookie>): void;
|
|
122
72
|
/**
|
|
123
73
|
* --- 创建 FormData 对象, Mutton: false, Kebab: true ---
|
|
124
74
|
*/
|
|
@@ -128,7 +78,7 @@ export declare function getFormData(): fd.FormData;
|
|
|
128
78
|
* @param headers 剔除前的 header
|
|
129
79
|
* @param res 直接设置头部而不返回,可置空
|
|
130
80
|
*/
|
|
131
|
-
export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders |
|
|
81
|
+
export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse): Record<string, string | string[]>;
|
|
132
82
|
/**
|
|
133
83
|
* --- 正向 mproxy 代理,读取 get 的 url 为实际请求地址 ---
|
|
134
84
|
* --- get: url, auth ---
|
|
@@ -136,16 +86,83 @@ export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | h
|
|
|
136
86
|
* @param auth 校验字符串,读取 get 的 auth 和本参数做比对
|
|
137
87
|
* @param opt 参数
|
|
138
88
|
*/
|
|
139
|
-
export declare function mproxy(ctr:
|
|
89
|
+
export declare function mproxy(ctr: sCtr.Ctr, auth: string, opt?: IMproxyOptions): Promise<number>;
|
|
140
90
|
/**
|
|
141
91
|
* --- 获取 mproxy 的附加数据 ---
|
|
142
92
|
* @param ctr 当前控制器
|
|
143
93
|
*/
|
|
144
|
-
export declare function mproxyData(ctr:
|
|
94
|
+
export declare function mproxyData(ctr: sCtr.Ctr): any;
|
|
145
95
|
/**
|
|
146
96
|
* --- 反向代理,将本服务器的某个路由反代到其他网址 ---
|
|
147
97
|
* @param ctr 当前控制器
|
|
148
98
|
* @param route 要反代的路由
|
|
149
99
|
* @param opt 参数
|
|
150
100
|
*/
|
|
151
|
-
export declare function rproxy(ctr:
|
|
101
|
+
export declare function rproxy(ctr: sCtr.Ctr, route: Record<string, string>, opt?: IRproxyOptions): Promise<boolean>;
|
|
102
|
+
/** --- 请求的传入参数选项 --- */
|
|
103
|
+
export interface IRequestOptions {
|
|
104
|
+
'method'?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
|
|
105
|
+
'type'?: 'form' | 'json';
|
|
106
|
+
/** --- 秒数 --- */
|
|
107
|
+
'timeout'?: number;
|
|
108
|
+
'follow'?: number;
|
|
109
|
+
'hosts'?: Record<string, string>;
|
|
110
|
+
'save'?: string;
|
|
111
|
+
'local'?: string;
|
|
112
|
+
'headers'?: THttpHeaders;
|
|
113
|
+
/** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
|
|
114
|
+
'mproxy'?: {
|
|
115
|
+
'url': string;
|
|
116
|
+
'auth': string;
|
|
117
|
+
'data'?: any;
|
|
118
|
+
};
|
|
119
|
+
/** --- 默认为 default --- */
|
|
120
|
+
'reuse'?: string;
|
|
121
|
+
/** --- cookie 托管对象 --- */
|
|
122
|
+
'cookie'?: Record<string, ICookie>;
|
|
123
|
+
}
|
|
124
|
+
/** --- 正向代理请求的传入参数选项 --- */
|
|
125
|
+
export interface IMproxyOptions {
|
|
126
|
+
/** --- 秒数 --- */
|
|
127
|
+
'timeout'?: number;
|
|
128
|
+
'follow'?: number;
|
|
129
|
+
'hosts'?: Record<string, string>;
|
|
130
|
+
'local'?: string;
|
|
131
|
+
'headers'?: THttpHeaders;
|
|
132
|
+
/** --- 默认为 default --- */
|
|
133
|
+
'reuse'?: string;
|
|
134
|
+
}
|
|
135
|
+
/** --- 反向代理请求的传入参数选项 --- */
|
|
136
|
+
export interface IRproxyOptions {
|
|
137
|
+
/** --- 秒数 --- */
|
|
138
|
+
'timeout'?: number;
|
|
139
|
+
'follow'?: number;
|
|
140
|
+
'hosts'?: Record<string, string>;
|
|
141
|
+
'local'?: string;
|
|
142
|
+
'headers'?: THttpHeaders;
|
|
143
|
+
/** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
|
|
144
|
+
'mproxy'?: {
|
|
145
|
+
'url': string;
|
|
146
|
+
'auth': string;
|
|
147
|
+
'data'?: any;
|
|
148
|
+
};
|
|
149
|
+
/** --- 默认为 default --- */
|
|
150
|
+
'reuse'?: string;
|
|
151
|
+
}
|
|
152
|
+
/** --- http headers --- */
|
|
153
|
+
export type THttpHeaders = http.IncomingHttpHeaders & {
|
|
154
|
+
'http-version'?: '1.1' | '2.0';
|
|
155
|
+
'http-code'?: number;
|
|
156
|
+
'http-url'?: string;
|
|
157
|
+
};
|
|
158
|
+
/** --- Net Cookie 对象 --- */
|
|
159
|
+
export interface ICookie {
|
|
160
|
+
'name': string;
|
|
161
|
+
'value': string;
|
|
162
|
+
/** --- 有效期秒级时间戳 --- */
|
|
163
|
+
'exp': number;
|
|
164
|
+
'path': string;
|
|
165
|
+
'domain': string;
|
|
166
|
+
'secure': boolean;
|
|
167
|
+
'httponly': boolean;
|
|
168
|
+
}
|
package/lib/net.js
CHANGED
|
@@ -8,10 +8,10 @@ import * as stream from 'stream';
|
|
|
8
8
|
// --- 第三方 ---
|
|
9
9
|
import * as hc from '@litert/http-client';
|
|
10
10
|
// --- 库和定义 ---
|
|
11
|
-
import * as fs from '#lib/fs.js';
|
|
12
|
-
import * as text from '#lib/text.js';
|
|
13
|
-
import * as time from '#lib/time.js';
|
|
14
11
|
import * as kebab from '#index.js';
|
|
12
|
+
import * as lFs from '#lib/fs.js';
|
|
13
|
+
import * as lText from '#lib/text.js';
|
|
14
|
+
import * as lTime from '#lib/time.js';
|
|
15
15
|
// --- 自己 ---
|
|
16
16
|
import * as fd from './net/formdata.js';
|
|
17
17
|
import * as lRequest from './net/request.js';
|
|
@@ -23,7 +23,7 @@ export async function getCa() {
|
|
|
23
23
|
if (ca) {
|
|
24
24
|
return ca;
|
|
25
25
|
}
|
|
26
|
-
ca = (await
|
|
26
|
+
ca = (await lFs.getContent(kebab.LIB_PATH + 'net/cacert.pem', 'utf8')) ?? '';
|
|
27
27
|
return ca;
|
|
28
28
|
}
|
|
29
29
|
/** --- 复用的 hc 对象列表 --- */
|
|
@@ -71,9 +71,9 @@ export async function postJson(u, data, opt = {}) {
|
|
|
71
71
|
* @param opt 配置项
|
|
72
72
|
*/
|
|
73
73
|
export async function request(u, data, opt = {}) {
|
|
74
|
-
const uri =
|
|
74
|
+
const uri = lText.parseUrl(u);
|
|
75
75
|
/** --- 正向代理的地址 --- */
|
|
76
|
-
const puri = opt.mproxy ?
|
|
76
|
+
const puri = opt.mproxy ? lText.parseUrl(opt.mproxy.url) : null;
|
|
77
77
|
const method = opt.method ?? 'GET';
|
|
78
78
|
const type = opt.type ?? 'form';
|
|
79
79
|
const timeout = opt.timeout ?? 10;
|
|
@@ -93,7 +93,7 @@ export async function request(u, data, opt = {}) {
|
|
|
93
93
|
if (method === 'GET') {
|
|
94
94
|
if (data && !(data instanceof stream.Readable) && !Buffer.isBuffer(data)) {
|
|
95
95
|
u += (u.includes('?') ? '&' : '?') +
|
|
96
|
-
(typeof data === 'string' ? data :
|
|
96
|
+
(typeof data === 'string' ? data : lText.queryStringify(data));
|
|
97
97
|
data = undefined;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -101,11 +101,11 @@ export async function request(u, data, opt = {}) {
|
|
|
101
101
|
// --- POST ---
|
|
102
102
|
if (data && !(data instanceof stream.Readable) && !Buffer.isBuffer(data) && typeof data !== 'string') {
|
|
103
103
|
if (type === 'form') {
|
|
104
|
-
data =
|
|
104
|
+
data = lText.queryStringify(data);
|
|
105
105
|
headers['content-type'] = 'application/x-www-form-urlencoded';
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
|
-
data =
|
|
108
|
+
data = lText.stringifyJson(data);
|
|
109
109
|
headers['content-type'] = 'application/json; charset=utf-8';
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -148,10 +148,10 @@ export async function request(u, data, opt = {}) {
|
|
|
148
148
|
reuses[reuse] = hc.createHttpClient();
|
|
149
149
|
}
|
|
150
150
|
req = await reuses[reuse].request({
|
|
151
|
-
'url': opt.mproxy ? opt.mproxy.url + (opt.mproxy.url.includes('?') ? '&' : '?') +
|
|
151
|
+
'url': opt.mproxy ? opt.mproxy.url + (opt.mproxy.url.includes('?') ? '&' : '?') + lText.queryStringify({
|
|
152
152
|
'url': u,
|
|
153
153
|
'auth': opt.mproxy.auth,
|
|
154
|
-
'data': opt.mproxy.data ?
|
|
154
|
+
'data': opt.mproxy.data ? lText.stringifyJson(opt.mproxy.data) : '{}'
|
|
155
155
|
}) : u,
|
|
156
156
|
'method': method,
|
|
157
157
|
'data': data,
|
|
@@ -181,7 +181,7 @@ export async function request(u, data, opt = {}) {
|
|
|
181
181
|
if (save && (!req.headers['location'] || follow === 0)) {
|
|
182
182
|
await new Promise(function (resolve) {
|
|
183
183
|
req.getStream().on('end', () => {
|
|
184
|
-
|
|
184
|
+
lFs.stats(save).then((stat) => {
|
|
185
185
|
total = stat?.size ?? 0;
|
|
186
186
|
resolve();
|
|
187
187
|
}).catch(() => {
|
|
@@ -189,7 +189,7 @@ export async function request(u, data, opt = {}) {
|
|
|
189
189
|
});
|
|
190
190
|
}).on('error', function () {
|
|
191
191
|
resolve();
|
|
192
|
-
}).pipe(
|
|
192
|
+
}).pipe(lFs.createWriteStream(save));
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
// --- 创建 Response 对象 ---
|
|
@@ -219,7 +219,7 @@ export async function request(u, data, opt = {}) {
|
|
|
219
219
|
}
|
|
220
220
|
// --- 哦,要追踪 ---
|
|
221
221
|
headers['referer'] = u;
|
|
222
|
-
return request(
|
|
222
|
+
return request(lText.urlResolve(u, req.headers['location']), data, {
|
|
223
223
|
'method': method,
|
|
224
224
|
'type': type,
|
|
225
225
|
'timeout': timeout,
|
|
@@ -241,7 +241,7 @@ export async function request(u, data, opt = {}) {
|
|
|
241
241
|
* @param opt 选项 ttl, path, ssl, httponly
|
|
242
242
|
*/
|
|
243
243
|
export function setCookie(cookie, name, value, domain, opt = {}) {
|
|
244
|
-
const tim =
|
|
244
|
+
const tim = lTime.stamp();
|
|
245
245
|
const ttl = opt.ttl ?? 0;
|
|
246
246
|
domain = domain.split(':')[0];
|
|
247
247
|
const domainN = domain.startsWith('.') ? domain.slice(1) : domain;
|
|
@@ -266,7 +266,7 @@ export function setCookie(cookie, name, value, domain, opt = {}) {
|
|
|
266
266
|
* @param uri 请求的 URI 对象
|
|
267
267
|
*/
|
|
268
268
|
async function buildCookieObject(cookie, setCookies, uri) {
|
|
269
|
-
const tim =
|
|
269
|
+
const tim = lTime.stamp();
|
|
270
270
|
uri.path ??= '/';
|
|
271
271
|
for (const setCookie of setCookies) {
|
|
272
272
|
const cookieTmp = {};
|
|
@@ -312,10 +312,10 @@ async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
312
312
|
// --- ok.xxx.com vs .zz.ok.xxx.com: false ---
|
|
313
313
|
if (uri.hostname !== domainN) {
|
|
314
314
|
// --- 设置的域名和当前 host 不相等,如果是 IP、无 . 域名,则直接失败 ---
|
|
315
|
-
if (!
|
|
315
|
+
if (!lText.isDomain(uri.hostname ?? '')) {
|
|
316
316
|
continue;
|
|
317
317
|
}
|
|
318
|
-
const parseDomain = await
|
|
318
|
+
const parseDomain = await lText.parseDomain(domainN);
|
|
319
319
|
if (parseDomain.tld === domainN.toLowerCase()) {
|
|
320
320
|
// --- 不能给 tld 设置 cookie ---
|
|
321
321
|
continue;
|
|
@@ -366,7 +366,7 @@ async function buildCookieObject(cookie, setCookies, uri) {
|
|
|
366
366
|
* @param uri 请求的 URI 对象
|
|
367
367
|
*/
|
|
368
368
|
export function buildCookieQuery(cookie, uri) {
|
|
369
|
-
const tim =
|
|
369
|
+
const tim = lTime.stamp();
|
|
370
370
|
let cookieStr = '';
|
|
371
371
|
for (const key in cookie) {
|
|
372
372
|
const item = cookie[key];
|
|
@@ -503,7 +503,7 @@ export function mproxyData(ctr) {
|
|
|
503
503
|
if (!get['data']) {
|
|
504
504
|
return {};
|
|
505
505
|
}
|
|
506
|
-
const data =
|
|
506
|
+
const data = lText.parseJson(get['data']);
|
|
507
507
|
if (!data) {
|
|
508
508
|
return {};
|
|
509
509
|
}
|
package/lib/sql.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Date: 2019-5-27 20:18:50
|
|
4
4
|
* 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
|
|
5
5
|
*/
|
|
6
|
+
import * as kebab from '#index.js';
|
|
6
7
|
import * as ctr from '#sys/ctr.js';
|
|
7
|
-
import * as types from '#types/index.js';
|
|
8
8
|
export declare class Sql {
|
|
9
9
|
/** --- 前置 --- */
|
|
10
10
|
private readonly _pre;
|
|
@@ -13,7 +13,7 @@ export declare class Sql {
|
|
|
13
13
|
/** --- 所有 data 数据 --- */
|
|
14
14
|
private _data;
|
|
15
15
|
constructor(pre?: string, opt?: {
|
|
16
|
-
'data'?:
|
|
16
|
+
'data'?: kebab.DbValue[];
|
|
17
17
|
'sql'?: string[];
|
|
18
18
|
});
|
|
19
19
|
/**
|
|
@@ -31,19 +31,19 @@ export declare class Sql {
|
|
|
31
31
|
* @param cs [] 数据列或字段列
|
|
32
32
|
* @param vs [] | [][] 数据
|
|
33
33
|
*/
|
|
34
|
-
values(cs: string[] | Record<string,
|
|
34
|
+
values(cs: string[] | Record<string, kebab.DbValue>, vs?: kebab.DbValue[] | kebab.DbValue[][]): this;
|
|
35
35
|
/**
|
|
36
36
|
* --- 不存在则插入,衔接在 insert 之后 ---
|
|
37
37
|
* @param table 表名
|
|
38
38
|
* @param insert {'xx': 'xx', 'xx': 'xx'}
|
|
39
39
|
* @param where [{'xx': 'xx', 'xx': 'xx'}], {'xx': 'xx'}
|
|
40
40
|
*/
|
|
41
|
-
notExists(table: string, insert: Record<string,
|
|
41
|
+
notExists(table: string, insert: Record<string, kebab.DbValue>, where: string | kebab.Json): this;
|
|
42
42
|
/**
|
|
43
43
|
* --- 当不能 insert 时,update(仅能配合 insert 方法用) ---
|
|
44
44
|
* @param s 更新数据
|
|
45
45
|
*/
|
|
46
|
-
duplicate(s:
|
|
46
|
+
duplicate(s: kebab.Json): this;
|
|
47
47
|
/**
|
|
48
48
|
* --- '*', 'xx' ---
|
|
49
49
|
* @param c 字段字符串或字段数组
|
|
@@ -55,7 +55,7 @@ export declare class Sql {
|
|
|
55
55
|
* @param f 表名
|
|
56
56
|
* @param s 设定 update 的值
|
|
57
57
|
*/
|
|
58
|
-
update(f: string, s:
|
|
58
|
+
update(f: string, s: kebab.Json): this;
|
|
59
59
|
private _updateSub;
|
|
60
60
|
/**
|
|
61
61
|
* --- 'xx' ---
|
|
@@ -81,7 +81,7 @@ export declare class Sql {
|
|
|
81
81
|
* @param suf 表后缀
|
|
82
82
|
* @param pre 表前缀,仅在 join 非默认表前缀时填写
|
|
83
83
|
*/
|
|
84
|
-
join(f: string, s?:
|
|
84
|
+
join(f: string, s?: kebab.Json, type?: string, suf?: string, pre?: string): this;
|
|
85
85
|
/**
|
|
86
86
|
* --- left join 方法 ---
|
|
87
87
|
* @param f 表名
|
|
@@ -89,7 +89,7 @@ export declare class Sql {
|
|
|
89
89
|
* @param suf 表后缀
|
|
90
90
|
* @param pre 表前缀,仅在 join 非默认表前缀时填写
|
|
91
91
|
*/
|
|
92
|
-
leftJoin(f: string, s?:
|
|
92
|
+
leftJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
|
|
93
93
|
/**
|
|
94
94
|
* --- right join 方法 ---
|
|
95
95
|
* @param f 表名
|
|
@@ -97,7 +97,7 @@ export declare class Sql {
|
|
|
97
97
|
* @param suf 表后缀
|
|
98
98
|
* @param pre 表前缀,仅在 join 非默认表前缀时填写
|
|
99
99
|
*/
|
|
100
|
-
rightJoin(f: string, s?:
|
|
100
|
+
rightJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
|
|
101
101
|
/**
|
|
102
102
|
* --- inner join 方法 ---
|
|
103
103
|
* @param f 表名
|
|
@@ -105,7 +105,7 @@ export declare class Sql {
|
|
|
105
105
|
* @param suf 表后缀
|
|
106
106
|
* @param pre 表前缀,仅在 join 非默认表前缀时填写
|
|
107
107
|
*/
|
|
108
|
-
innerJoin(f: string, s?:
|
|
108
|
+
innerJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
|
|
109
109
|
/**
|
|
110
110
|
* --- full join 方法 ---
|
|
111
111
|
* @param f 表名
|
|
@@ -113,7 +113,7 @@ export declare class Sql {
|
|
|
113
113
|
* @param suf 表后缀
|
|
114
114
|
* @param pre 表前缀,仅在 join 非默认表前缀时填写
|
|
115
115
|
*/
|
|
116
|
-
fullJoin(f: string, s?:
|
|
116
|
+
fullJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
|
|
117
117
|
/**
|
|
118
118
|
* --- cross join 方法 ---
|
|
119
119
|
* @param f 表名
|
|
@@ -121,11 +121,11 @@ export declare class Sql {
|
|
|
121
121
|
* @param suf 表后缀
|
|
122
122
|
* @param pre 表前缀,仅在 join 非默认表前缀时填写
|
|
123
123
|
*/
|
|
124
|
-
crossJoin(f: string, s?:
|
|
124
|
+
crossJoin(f: string, s?: kebab.Json, suf?: string, pre?: string): this;
|
|
125
125
|
/**
|
|
126
126
|
* --- having 后置筛选器,用法类似 where ---
|
|
127
127
|
*/
|
|
128
|
-
having(s?: string |
|
|
128
|
+
having(s?: string | kebab.Json): this;
|
|
129
129
|
/** --- where 的 data 的开始处和结束处 --- */
|
|
130
130
|
private _whereDataPosition;
|
|
131
131
|
/**
|
|
@@ -139,7 +139,7 @@ export declare class Sql {
|
|
|
139
139
|
* --- 7. ['JSON_CONTAINS(`uid`, ?)', ['hello']] ---
|
|
140
140
|
* @param s 筛选数据
|
|
141
141
|
*/
|
|
142
|
-
where(s: string |
|
|
142
|
+
where(s: string | kebab.Json): this;
|
|
143
143
|
private _whereSub;
|
|
144
144
|
/**
|
|
145
145
|
* --- ORDER BY ---
|
|
@@ -167,7 +167,7 @@ export declare class Sql {
|
|
|
167
167
|
* @param f 可为空,可设置新对象的 table 名变化
|
|
168
168
|
*/
|
|
169
169
|
copy(f?: string | string[], opt?: {
|
|
170
|
-
'where'?: string |
|
|
170
|
+
'where'?: string | kebab.Json;
|
|
171
171
|
}): Sql;
|
|
172
172
|
/**
|
|
173
173
|
* --- 获取 sql 语句 ---
|
|
@@ -176,7 +176,7 @@ export declare class Sql {
|
|
|
176
176
|
/**
|
|
177
177
|
* --- 获取全部 data ---
|
|
178
178
|
*/
|
|
179
|
-
getData():
|
|
179
|
+
getData(): kebab.DbValue[];
|
|
180
180
|
/**
|
|
181
181
|
* --- 获取定义的 pre ---
|
|
182
182
|
*/
|
|
@@ -186,7 +186,7 @@ export declare class Sql {
|
|
|
186
186
|
* @param sql
|
|
187
187
|
* @param data
|
|
188
188
|
*/
|
|
189
|
-
format(sql?: string, data?:
|
|
189
|
+
format(sql?: string, data?: kebab.DbValue[]): string;
|
|
190
190
|
/**
|
|
191
191
|
* --- 在 sql 最后追加字符串 ---
|
|
192
192
|
* @param sql
|
|
@@ -211,7 +211,7 @@ export declare class Sql {
|
|
|
211
211
|
* @param opt 参数
|
|
212
212
|
*/
|
|
213
213
|
export declare function get(ctrPre?: ctr.Ctr | string, opt?: {
|
|
214
|
-
'data'?:
|
|
214
|
+
'data'?: kebab.DbValue[];
|
|
215
215
|
'sql'?: string[];
|
|
216
216
|
}): Sql;
|
|
217
217
|
/**
|
|
@@ -219,12 +219,12 @@ export declare function get(ctrPre?: ctr.Ctr | string, opt?: {
|
|
|
219
219
|
* @param sql SQL 字符串
|
|
220
220
|
* @param data DATA 数据
|
|
221
221
|
*/
|
|
222
|
-
export declare function format(sql: string, data:
|
|
222
|
+
export declare function format(sql: string, data: kebab.DbValue[]): string;
|
|
223
223
|
/**
|
|
224
224
|
* --- 将数组兑换为组合的对象(Array/Object mix) ---
|
|
225
225
|
* @param arr 要转换的数组
|
|
226
226
|
*/
|
|
227
|
-
export declare function aoMix(arr:
|
|
227
|
+
export declare function aoMix(arr: kebab.Json): Record<string, string | number | kebab.Json>;
|
|
228
228
|
/** --- 创建字段对象 --- */
|
|
229
229
|
export declare function column(field: string): {
|
|
230
230
|
'type': 'column';
|
package/lib/sql.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
-
* Date: 2019-5-27 20:18:50
|
|
4
|
-
* 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
|
|
5
|
-
*/
|
|
6
1
|
import * as lText from '#lib/text.js';
|
|
7
2
|
import * as lCore from '#lib/core.js';
|
|
8
3
|
// --- 第三方 ---
|
package/lib/text.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Project: Kebab, User: JianSuoQiYue
|
|
3
|
+
* Date: 2019-5-15 16:49:39
|
|
4
|
+
* 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, 2025-9-23 12:51:49
|
|
5
|
+
*/
|
|
6
|
+
import * as kebab from '#index.js';
|
|
2
7
|
/**
|
|
3
8
|
* --- 将文件大小格式化为带单位的字符串 ---
|
|
4
9
|
* @param size 文件大小
|
|
@@ -9,7 +14,7 @@ export declare function sizeFormat(size: number, spliter?: string): string;
|
|
|
9
14
|
* --- 格式化一段 URL ---
|
|
10
15
|
* @param url
|
|
11
16
|
*/
|
|
12
|
-
export declare function parseUrl(url: string):
|
|
17
|
+
export declare function parseUrl(url: string): kebab.IUrlParse;
|
|
13
18
|
/**
|
|
14
19
|
* --- 将相对路径根据基准路径进行转换 ---
|
|
15
20
|
* @param from 基准路径
|
|
@@ -116,7 +121,7 @@ export declare function getFilename(path: string): string;
|
|
|
116
121
|
* --- 将普通的返回 JSON 对象序列化为字符串,Mutton 不能使用 ---
|
|
117
122
|
* @param o 返回 JSON 对象
|
|
118
123
|
*/
|
|
119
|
-
export declare function stringifyResult(rtn:
|
|
124
|
+
export declare function stringifyResult(rtn: kebab.Json): string;
|
|
120
125
|
/**
|
|
121
126
|
* --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt,Kebab true, Mutton false ---
|
|
122
127
|
* @param str 要解析的 json 字符串
|
|
@@ -127,7 +132,7 @@ export declare function parseJson(str: string): any;
|
|
|
127
132
|
* @param obj 要转换的 json 对象
|
|
128
133
|
* @param space 美化方式
|
|
129
134
|
*/
|
|
130
|
-
export declare function stringifyJson(obj:
|
|
135
|
+
export declare function stringifyJson(obj: kebab.Json, space?: string | number): string;
|
|
131
136
|
/**
|
|
132
137
|
* --- 输出文本格式的 buffer ---
|
|
133
138
|
* @param buf 原始 buffer
|
package/lib/text.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-5-15 16:49:39
|
|
4
|
-
* 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
|
|
4
|
+
* 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, 2025-9-23 12:51:49
|
|
5
5
|
*/
|
|
6
6
|
import * as kebab from '#index.js';
|
|
7
|
-
import * as
|
|
7
|
+
import * as lFs from './fs.js';
|
|
8
8
|
/**
|
|
9
9
|
* --- 将文件大小格式化为带单位的字符串 ---
|
|
10
10
|
* @param size 文件大小
|
|
@@ -253,7 +253,7 @@ export async function parseDomain(domain) {
|
|
|
253
253
|
}
|
|
254
254
|
else {
|
|
255
255
|
if (!tldList) {
|
|
256
|
-
tldList = JSON.parse(await
|
|
256
|
+
tldList = JSON.parse(await lFs.getContent(kebab.LIB_PATH + 'text/tld.json', 'utf8') ?? '[]');
|
|
257
257
|
}
|
|
258
258
|
const last2 = (arr[arr.length - 2] + '.' + arr[arr.length - 1]).toLowerCase();
|
|
259
259
|
if (tldList.includes(last2)) {
|