@maiyunnet/kebab 3.1.3 → 3.1.4
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 +1 -1
- package/index.js +1 -1
- package/lib/net.d.ts +5 -5
- package/lib/net.js +6 -6
- package/package.json +1 -1
- package/tsconfig.json +26 -0
- package/types/index.d.ts +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* ------------------------
|
|
9
9
|
*/
|
|
10
10
|
/** --- 当前系统版本号 --- */
|
|
11
|
-
export const VER = '3.1.
|
|
11
|
+
export const VER = '3.1.4';
|
|
12
12
|
// --- 服务端用的路径 ---
|
|
13
13
|
const imu = import.meta.url.replace('file://', '').replace(/^\/(\w:)/, '$1').replace(/\\/g, '/');
|
|
14
14
|
/** --- /xxx/xxx --- */
|
package/lib/net.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import * as ctr from '#sys/ctr.js';
|
|
|
11
11
|
import * as types from '#types/index.js';
|
|
12
12
|
import * as fd from './net/formdata.js';
|
|
13
13
|
import * as lRequest from './net/request.js';
|
|
14
|
-
import * as
|
|
14
|
+
import * as lResponse from './net/response.js';
|
|
15
15
|
/** --- 请求的传入参数选项 --- */
|
|
16
16
|
export interface IRequestOptions {
|
|
17
17
|
'method'?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
|
|
@@ -74,26 +74,26 @@ export declare function open(u: string): lRequest.Request;
|
|
|
74
74
|
* @param u 请求的 URL
|
|
75
75
|
* @param opt 参数
|
|
76
76
|
*/
|
|
77
|
-
export declare function get(u: string, opt?: IRequestOptions): Promise<
|
|
77
|
+
export declare function get(u: string, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
78
78
|
/**
|
|
79
79
|
* --- 发起一个 post 请求 ---
|
|
80
80
|
* @param u 请求的 URL
|
|
81
81
|
* @param data 要发送的数据
|
|
82
82
|
* @param opt 参数
|
|
83
83
|
*/
|
|
84
|
-
export declare function post(u: string, data: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<
|
|
84
|
+
export declare function post(u: string, data: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
85
85
|
/**
|
|
86
86
|
* --- 发起 JSON 请求 ---
|
|
87
87
|
* @param u
|
|
88
88
|
* @param data
|
|
89
89
|
* @param opt
|
|
90
90
|
*/
|
|
91
|
-
export declare function postJson(u: string, data: types.Json[] | Record<string, types.Json>, opt?: IRequestOptions): Promise<
|
|
91
|
+
export declare function postJson(u: string, data: types.Json[] | Record<string, types.Json>, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
92
92
|
/**
|
|
93
93
|
* --- 发起一个请求 ---
|
|
94
94
|
* @param opt 配置项
|
|
95
95
|
*/
|
|
96
|
-
export declare function request(u: string, data?: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<
|
|
96
|
+
export declare function request(u: string, data?: Record<string, types.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
97
97
|
/**
|
|
98
98
|
* --- 对 cookie 对象进行操作 ---
|
|
99
99
|
* @param cookie 要操作的对象
|
package/lib/net.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as kebab from '#index.js';
|
|
|
15
15
|
// --- 自己 ---
|
|
16
16
|
import * as fd from './net/formdata.js';
|
|
17
17
|
import * as lRequest from './net/request.js';
|
|
18
|
-
import * as
|
|
18
|
+
import * as lResponse from './net/response.js';
|
|
19
19
|
/** --- ca 根证书内容 --- */
|
|
20
20
|
let ca = '';
|
|
21
21
|
/** --- 获取 CA 证书 --- */
|
|
@@ -28,7 +28,7 @@ export async function getCa() {
|
|
|
28
28
|
}
|
|
29
29
|
/** --- 复用的 hc 对象列表 --- */
|
|
30
30
|
const reuses = {
|
|
31
|
-
'default': hc.createHttpClient()
|
|
31
|
+
'default': hc.createHttpClient(),
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
34
|
* --- 创建一个请求对象 ---
|
|
@@ -129,7 +129,7 @@ export async function request(u, data, opt = {}) {
|
|
|
129
129
|
// --- 重定义 IP ---
|
|
130
130
|
const host = (puri ? puri.hostname : uri.hostname) ?? '';
|
|
131
131
|
if (!host) {
|
|
132
|
-
const res = new
|
|
132
|
+
const res = new lResponse.Response(null);
|
|
133
133
|
res.error = {
|
|
134
134
|
'name': 'Possible mProxy error',
|
|
135
135
|
'message': 'host not found'
|
|
@@ -137,7 +137,7 @@ export async function request(u, data, opt = {}) {
|
|
|
137
137
|
return res;
|
|
138
138
|
}
|
|
139
139
|
if (hosts[host] !== undefined && !hosts[host]) {
|
|
140
|
-
const res = new
|
|
140
|
+
const res = new lResponse.Response(null);
|
|
141
141
|
res.error = {
|
|
142
142
|
'name': 'hosts error',
|
|
143
143
|
'message': 'hosts param error'
|
|
@@ -165,7 +165,7 @@ export async function request(u, data, opt = {}) {
|
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
catch (err) {
|
|
168
|
-
const res = new
|
|
168
|
+
const res = new lResponse.Response(null);
|
|
169
169
|
res.error = err;
|
|
170
170
|
return res;
|
|
171
171
|
}
|
|
@@ -193,7 +193,7 @@ export async function request(u, data, opt = {}) {
|
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
// --- 创建 Response 对象 ---
|
|
196
|
-
const res = new
|
|
196
|
+
const res = new lResponse.Response(req);
|
|
197
197
|
if (total) {
|
|
198
198
|
res.setContent(total.toString());
|
|
199
199
|
}
|
package/package.json
CHANGED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"removeComments": false,
|
|
5
|
+
"preserveConstEnums": true, // 保留 const 和 enum 声明
|
|
6
|
+
"outDir": "./",
|
|
7
|
+
"sourceMap": false,
|
|
8
|
+
"target": "ES2021",
|
|
9
|
+
"strict": true, // 严格模式
|
|
10
|
+
"declaration": true, // d.ts
|
|
11
|
+
"declarationMap": false, // d.ts 的 map
|
|
12
|
+
"newLine": "LF",
|
|
13
|
+
"paths": {
|
|
14
|
+
"#*": ["./*"]
|
|
15
|
+
},
|
|
16
|
+
"moduleResolution": "node",
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"esModuleInterop": true
|
|
19
|
+
},
|
|
20
|
+
"include": [
|
|
21
|
+
"./**/*.ts"
|
|
22
|
+
],
|
|
23
|
+
"exclude": [
|
|
24
|
+
"node_modules"
|
|
25
|
+
]
|
|
26
|
+
}
|