@seayoo-web/request 3.5.2 → 4.0.1
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/README.md +58 -56
- package/dist/index.js +136 -122
- package/dist/node.js +58 -58
- package/dist/request.fetch-U2PiTmEn.js +54 -0
- package/dist/retry-b0Etywu_.js +645 -0
- package/dist/wx.js +58 -49
- package/package.json +1 -1
- package/types/inc/cache.d.ts +2 -2
- package/types/inc/config.d.ts +5 -5
- package/types/inc/guard.d.ts +3 -3
- package/types/inc/jsonp.d.ts +3 -2
- package/types/inc/main.d.ts +51 -34
- package/types/inc/option.d.ts +6 -7
- package/types/inc/request.xhr.d.ts +4 -4
- package/types/inc/response.d.ts +8 -3
- package/types/inc/retry.d.ts +3 -3
- package/types/inc/rule.d.ts +5 -5
- package/types/inc/sentry.d.ts +4 -4
- package/types/inc/type.d.ts +55 -50
- package/types/inc/utils.d.ts +7 -2
- package/types/index.d.ts +37 -25
- package/types/node.d.ts +26 -24
- package/types/wx.d.ts +22 -20
- package/dist/request.fetch-Jj3A4PnG.js +0 -48
- package/dist/retry-Cxkf8ke1.js +0 -624
package/types/inc/type.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GlobalConfigHelper } from "./config";
|
|
2
2
|
import type { MaybePromise, TypeGuard, TypeGuardFn } from "@seayoo-web/utils";
|
|
3
|
-
export type
|
|
3
|
+
export type BaseRequestBody = Blob | ArrayBuffer | FormData | URLSearchParams | string;
|
|
4
4
|
export declare const RequestInternalError: {
|
|
5
5
|
/** 响应数据校验失败 */
|
|
6
6
|
readonly UnexpectResponse: "UnexpectResponse";
|
|
@@ -14,27 +14,33 @@ export declare const RequestInternalError: {
|
|
|
14
14
|
readonly Timeout: "Timeout";
|
|
15
15
|
/** 请求方法不被支持,在微信小程序环境下有效 */
|
|
16
16
|
readonly NotSupport: "NotSupport";
|
|
17
|
-
/** url 格式错误 */
|
|
18
|
-
readonly URLFormatError: "URLFormatError";
|
|
19
17
|
};
|
|
20
18
|
export type RequestInternalError = (typeof RequestInternalError)[keyof typeof RequestInternalError];
|
|
19
|
+
export type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
|
|
20
|
+
export type RequestQueryParams = Record<string, string | number | boolean | null | undefined>;
|
|
21
21
|
/** 通用网络请求工具的基本配置 */
|
|
22
|
-
export interface
|
|
22
|
+
export interface BaseRequestOptions {
|
|
23
23
|
/** 网络请求方法,默认 GET */
|
|
24
|
-
method?:
|
|
24
|
+
method?: RequestMethod;
|
|
25
25
|
/** 自定义 header 头 */
|
|
26
26
|
headers?: Record<string, string>;
|
|
27
27
|
/** url 参数 */
|
|
28
|
-
params?:
|
|
28
|
+
params?: RequestQueryParams;
|
|
29
29
|
/** 发送的 body 内容,method 为 GET / HEAD / DELETE 时无效 */
|
|
30
|
-
body?:
|
|
30
|
+
body?: BaseRequestBody | object | unknown[];
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* 是否将请求响应为 ArrayBuffer
|
|
33
|
+
*
|
|
34
|
+
* 设置为 `true` 后将忽略 response body 解析,直接返回响应内容
|
|
35
|
+
*/
|
|
36
|
+
asBuffer?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* 是否携带用户认证信息(cookie, basic http auth 等),默认 "same-origin"
|
|
33
39
|
*
|
|
34
40
|
* 使用 xhRequest 时,omit 无效,nodejs 环境无效
|
|
35
41
|
*/
|
|
36
42
|
credentials?: "omit" | "same-origin" | "include";
|
|
37
|
-
/** 请求超时设置,单位 ms */
|
|
43
|
+
/** 请求超时设置,单位 ms,默认 10000 */
|
|
38
44
|
timeout?: number;
|
|
39
45
|
/**
|
|
40
46
|
* 中断控制信号,仅仅浏览器环境支持
|
|
@@ -44,7 +50,7 @@ export interface IBaseRequestOptions {
|
|
|
44
50
|
abort?: AbortSignal;
|
|
45
51
|
}
|
|
46
52
|
/** 重试请求的配置参数,暂不支持全局配置 */
|
|
47
|
-
export interface
|
|
53
|
+
export interface RetryRequestOptions {
|
|
48
54
|
/** 错误时重试的次数,不能超过 10 次,默认不重试 */
|
|
49
55
|
maxRetry?: number;
|
|
50
56
|
/**
|
|
@@ -54,7 +60,7 @@ export interface IRetryRequestOptions {
|
|
|
54
60
|
*
|
|
55
61
|
* `network` 仅仅网络错误时重试,但忽略 aborted / timeout 状态;
|
|
56
62
|
*/
|
|
57
|
-
retryResolve?:
|
|
63
|
+
retryResolve?: RetryResolve;
|
|
58
64
|
/**
|
|
59
65
|
* 两次重试的间隔,如果设置时间,则单位 ms,或者设置函数返回等待的时间(单位ms),默认 100,最小 100,函数参数 retryIndex 从 1 开始
|
|
60
66
|
*
|
|
@@ -70,7 +76,7 @@ export interface IRetryRequestOptions {
|
|
|
70
76
|
}
|
|
71
77
|
/** 计算请求缓冲key的函数 */
|
|
72
78
|
export type RequestCacheResolve = () => string | false;
|
|
73
|
-
export interface
|
|
79
|
+
export interface OtherRequestOptions {
|
|
74
80
|
/**
|
|
75
81
|
* 如果设置为 false 则关闭通用提示
|
|
76
82
|
*
|
|
@@ -82,11 +88,11 @@ export interface IOtherRequestOptions {
|
|
|
82
88
|
*
|
|
83
89
|
* 💡类型守卫校验不通过则会强制提示,即类型守卫校验提示不受此配置影响
|
|
84
90
|
*/
|
|
85
|
-
message?: false | ((result:
|
|
91
|
+
message?: false | ((result: ResponseResult, method: string, url: string, defaultMessage: string) => string | false | Error | {
|
|
86
92
|
message: string;
|
|
87
93
|
});
|
|
88
94
|
/** 自定义 ajax response 解析策略 */
|
|
89
|
-
responseRule?:
|
|
95
|
+
responseRule?: ResponseRule;
|
|
90
96
|
/**
|
|
91
97
|
* 用于设置请求的缓冲时长,单位 ms,建议不小于 100,默认 500。设置为 0 则不缓冲
|
|
92
98
|
*/
|
|
@@ -99,11 +105,11 @@ export interface IOtherRequestOptions {
|
|
|
99
105
|
cacheResolve?: RequestCacheResolve;
|
|
100
106
|
}
|
|
101
107
|
/** 对外工具接口的请求配置 */
|
|
102
|
-
export type
|
|
108
|
+
export type RequestOptions = BaseRequestOptions & RetryRequestOptions & OtherRequestOptions;
|
|
103
109
|
/** 请求的原始错误信息 */
|
|
104
110
|
export type ERequestRawError = Error | ProgressEvent;
|
|
105
111
|
/** 全局默认配置 */
|
|
106
|
-
export type
|
|
112
|
+
export type RequestGlobalConfig = {
|
|
107
113
|
/**
|
|
108
114
|
* 设置全局 url 基础路径,必须要以 / 开头 或者完整的 api 地址,比如 /api 或 https://api.server.com/path
|
|
109
115
|
*/
|
|
@@ -121,9 +127,9 @@ export type IRequestGlobalConfig = {
|
|
|
121
127
|
headers: Record<string, string>;
|
|
122
128
|
params: Record<string, string>;
|
|
123
129
|
method: string;
|
|
124
|
-
/**
|
|
130
|
+
/** 即将要请求的 url 地址,不包含 params 参数 */
|
|
125
131
|
url: string;
|
|
126
|
-
body?:
|
|
132
|
+
body?: BaseRequestBody;
|
|
127
133
|
}) => MaybePromise<void | string>);
|
|
128
134
|
/** 全局错误处理函数,仅在 statusCode 错误时触发 */
|
|
129
135
|
errorHandler?: null | ((data: {
|
|
@@ -134,22 +140,21 @@ export type IRequestGlobalConfig = {
|
|
|
134
140
|
url: string;
|
|
135
141
|
headers: Record<string, string>;
|
|
136
142
|
rawError?: ERequestRawError;
|
|
137
|
-
responseBody: string;
|
|
138
143
|
sentryError: Error;
|
|
139
144
|
sentryTags: Record<string, string | number>;
|
|
140
145
|
sentryExtra: Record<string, unknown>;
|
|
141
146
|
}) => void);
|
|
142
147
|
/** 全局响应处理函数,任意状态都会触发 */
|
|
143
|
-
responseHandler?: null | ((result:
|
|
148
|
+
responseHandler?: null | ((result: ResponseResult, method: string, url: string) => void);
|
|
144
149
|
/** 全局消息提示函数 */
|
|
145
150
|
messageHandler?: null | ((isError: boolean, message: string, code: string, status: number) => void);
|
|
146
151
|
/** 全局日志打印函数 */
|
|
147
|
-
logHandler?: null | ((log:
|
|
148
|
-
} & Pick<
|
|
152
|
+
logHandler?: null | ((log: RequestLog) => void);
|
|
153
|
+
} & Pick<BaseRequestOptions, "credentials" | "timeout"> & RetryRequestOptions & OtherRequestOptions;
|
|
149
154
|
/**
|
|
150
155
|
* 自定义重试检测方法
|
|
151
156
|
*/
|
|
152
|
-
export type
|
|
157
|
+
export type RetryResolveFunc = (response: RequestBaseResponse, count: number) => boolean;
|
|
153
158
|
/**
|
|
154
159
|
* 失败重试策略:
|
|
155
160
|
*
|
|
@@ -157,17 +162,17 @@ export type IRetryResolveFunc = (response: IRequestBaseResponse, count: number)
|
|
|
157
162
|
*
|
|
158
163
|
* `network` 仅仅网络错误时重试,但忽略 aborted / timeout 状态;
|
|
159
164
|
*/
|
|
160
|
-
export type
|
|
165
|
+
export type RetryResolve = "default" | "network" | number[] | RetryResolveFunc;
|
|
161
166
|
/** 响应内容转化器 */
|
|
162
|
-
export type
|
|
167
|
+
export type ResponseBodyConverter = (body: unknown) => unknown;
|
|
163
168
|
/** 响应内容解析规则配置 */
|
|
164
|
-
export interface
|
|
169
|
+
export interface ResponseRule {
|
|
165
170
|
/** http失败时 (status <200 || status >= 400) 解析策略 */
|
|
166
171
|
failed: {
|
|
167
172
|
/** 解析方式,如果解析方式为 json,则可以进一步指定错误消息字段 */
|
|
168
173
|
resolve: "json" | "body";
|
|
169
|
-
/**
|
|
170
|
-
converter?:
|
|
174
|
+
/** 将响应内容进行转化 */
|
|
175
|
+
converter?: ResponseBodyConverter;
|
|
171
176
|
/** 解析错误消息的状态字段,比如 error 或 code,仅在 resolve 为 json 时有效,有值的话会替换 response 的 code */
|
|
172
177
|
statusField?: string;
|
|
173
178
|
/** 解析错误消息的字段,仅在 resolve 为 json 时有效 */
|
|
@@ -178,17 +183,13 @@ export interface IResponseRule {
|
|
|
178
183
|
/**
|
|
179
184
|
* http成功响应时,响应内容解析策略
|
|
180
185
|
*
|
|
181
|
-
* - json
|
|
182
|
-
*
|
|
183
|
-
* 此时 response body 被格式化为 json,并根据后续配置进一步读取自定义状态和数据字段等信息
|
|
184
|
-
*
|
|
185
|
-
* - body
|
|
186
|
+
* - `json` 此时 response body 被格式化为 json,并根据后续配置进一步读取自定义状态和数据字段等信息
|
|
186
187
|
*
|
|
187
|
-
* 此时 response body 被格式化为 json 并作为接口返回的数据使用,如果格式化失败,则返回 body 本身的字符串
|
|
188
|
+
* - `body` 此时 response body 被格式化为 json 并作为接口返回的数据使用,如果格式化失败,则返回 body 本身的字符串
|
|
188
189
|
*/
|
|
189
190
|
resolve: "json" | "body";
|
|
190
|
-
/**
|
|
191
|
-
converter?:
|
|
191
|
+
/** 将响应内容进行转化 */
|
|
192
|
+
converter?: ResponseBodyConverter;
|
|
192
193
|
/** 表示自定义状态的字段名 */
|
|
193
194
|
statusField?: string;
|
|
194
195
|
/** 自定义状态成功时的取值 */
|
|
@@ -201,8 +202,10 @@ export interface IResponseRule {
|
|
|
201
202
|
ignoreMessage?: string | string[];
|
|
202
203
|
};
|
|
203
204
|
}
|
|
205
|
+
/** 请求响应体 */
|
|
206
|
+
export type ResponseBody = string | null | ArrayBuffer | Buffer;
|
|
204
207
|
/** 通用网络请求工具返回的内容 */
|
|
205
|
-
export interface
|
|
208
|
+
export interface RequestBaseResponse {
|
|
206
209
|
/** 最终发送请求的方法 */
|
|
207
210
|
method: string;
|
|
208
211
|
/** 最终发送请求的 url(带有params) */
|
|
@@ -211,15 +214,17 @@ export interface IRequestBaseResponse {
|
|
|
211
214
|
status: number;
|
|
212
215
|
/** 状态描述信息 */
|
|
213
216
|
statusText: string;
|
|
217
|
+
/** 请求如果失败,则返回 RequestInternalError 错误 */
|
|
218
|
+
error?: RequestInternalError;
|
|
214
219
|
/** 响应头,如果网络错误,则返回空对象 */
|
|
215
220
|
headers?: Record<string, string | undefined>;
|
|
216
|
-
/** 响应体,如果网络错误或 204
|
|
217
|
-
body:
|
|
221
|
+
/** 响应体,如果网络错误或 204,则返回空或错误信息 */
|
|
222
|
+
body: ResponseBody;
|
|
218
223
|
/** 原始的请求错误信息,仅当请求失败时有值,用以进行错误上报用 */
|
|
219
224
|
rawError?: ERequestRawError;
|
|
220
225
|
}
|
|
221
226
|
/** 对外工具接口的返回内容 */
|
|
222
|
-
export interface
|
|
227
|
+
export interface ResponseResult<T = unknown> {
|
|
223
228
|
/** 标记响应是否成功,包括检测 http statusCode 以及 自定义 Response rule 中的规则 */
|
|
224
229
|
ok: boolean;
|
|
225
230
|
/** 响应的 http 状态码,异常情况返回负数(仅代表异常,具体数值无含义) */
|
|
@@ -235,13 +240,13 @@ export interface IResponseResult<T = unknown> {
|
|
|
235
240
|
*/
|
|
236
241
|
data: T;
|
|
237
242
|
}
|
|
238
|
-
export type ResponseWithType<T> = Promise<
|
|
239
|
-
export type ResponseWithoutType = Promise<
|
|
243
|
+
export type ResponseWithType<T> = Promise<ResponseResult<T | null>>;
|
|
244
|
+
export type ResponseWithoutType = Promise<ResponseResult>;
|
|
240
245
|
export interface NetRequestCoreFn {
|
|
241
|
-
(url: string, config:
|
|
246
|
+
(url: string, config: GlobalConfigHelper, options?: BaseRequestOptions): Promise<RequestBaseResponse>;
|
|
242
247
|
}
|
|
243
248
|
export interface NetRequestAgent {
|
|
244
|
-
(url: string, config:
|
|
249
|
+
(url: string, config: GlobalConfigHelper, options?: RequestOptions): Promise<ResponseResult>;
|
|
245
250
|
}
|
|
246
251
|
interface LogBase {
|
|
247
252
|
method: string;
|
|
@@ -255,7 +260,7 @@ interface RetryCount extends LogBase {
|
|
|
255
260
|
interface LogPrepare extends RetryCount {
|
|
256
261
|
type: "prepare";
|
|
257
262
|
/** 请求的参数 */
|
|
258
|
-
options?:
|
|
263
|
+
options?: RequestOptions;
|
|
259
264
|
/** 自定义追加的请求 header 头 */
|
|
260
265
|
headers?: Record<string, string>;
|
|
261
266
|
}
|
|
@@ -264,7 +269,7 @@ interface LogReady extends LogBase {
|
|
|
264
269
|
/** 实际发送的请求 header 头 */
|
|
265
270
|
headers: Record<string, string>;
|
|
266
271
|
/** 实际发送的数据 */
|
|
267
|
-
body?:
|
|
272
|
+
body?: BaseRequestBody;
|
|
268
273
|
/** 实际发送设定的 timeout */
|
|
269
274
|
timeout?: number;
|
|
270
275
|
}
|
|
@@ -273,10 +278,10 @@ interface LogFinished extends RetryCount {
|
|
|
273
278
|
/** 请求消耗的时间,单位 ms */
|
|
274
279
|
cost: number;
|
|
275
280
|
/** 请求响应的内容 */
|
|
276
|
-
response:
|
|
281
|
+
response: RequestBaseResponse;
|
|
277
282
|
/** 请求响应的 header */
|
|
278
283
|
headers?: Record<string, string | undefined>;
|
|
279
284
|
}
|
|
280
|
-
export type
|
|
281
|
-
export type
|
|
285
|
+
export type RequestLog = LogPrepare | LogReady | LogFinished;
|
|
286
|
+
export type DataGuard<T> = TypeGuard<T> | TypeGuardFn<T>;
|
|
282
287
|
export {};
|
package/types/inc/utils.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RetryResolve, RetryResolveFunc, RequestQueryParams } from "./type";
|
|
2
2
|
/** 简版 Object.fromEntries 以处理某些低版本浏览器和 webview 的问题 */
|
|
3
3
|
export declare function fromEntries(kv: [string, string | undefined][]): Record<string, string>;
|
|
4
|
+
export declare function convertParams(params?: RequestQueryParams): Record<string, string>;
|
|
5
|
+
export declare function toString(data: unknown): string;
|
|
6
|
+
export declare function convertError(e: unknown): Error;
|
|
7
|
+
export declare function convertStringToArrayBuffer(content: string): Promise<ArrayBuffer>;
|
|
8
|
+
export declare function addParamsToUrl(url: string, params: Record<string, string>): string;
|
|
4
9
|
/**
|
|
5
10
|
* 根据配置返回重试策略函数
|
|
6
11
|
*/
|
|
7
|
-
export declare function getRetryCheckFn(retryResolve:
|
|
12
|
+
export declare function getRetryCheckFn(retryResolve: RetryResolve): RetryResolveFunc;
|
package/types/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { NetRequestHandler } from "./inc/main";
|
|
2
2
|
import { xhrUpload } from "./inc/request.xhr";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RequestGlobalConfig } from "./inc/type";
|
|
4
4
|
export { jsonp, jsonx } from "./inc/jsonp";
|
|
5
5
|
export { getResponseRulesDescription } from "./inc/rule";
|
|
6
6
|
export { RequestInternalError } from "./inc/type";
|
|
7
|
-
export type { NetRequestHandler } from "./inc/main";
|
|
8
|
-
export type {
|
|
7
|
+
export type { NetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
8
|
+
export type { RequestOptions, RequestGlobalConfig, ResponseRule, ResponseResult, RequestLog, RequestMethod, RequestQueryParams, } from "./inc/type";
|
|
9
9
|
/**
|
|
10
10
|
* 基于 xhr 模块的上传工具,支持上传进度
|
|
11
11
|
*/
|
|
@@ -15,59 +15,71 @@ export type NetRequestFactory = typeof NetRequest;
|
|
|
15
15
|
/**
|
|
16
16
|
* 创建新的实例空间,配置和缓存跟全局默认实例是隔离的,仅支持在浏览器环境使用
|
|
17
17
|
*/
|
|
18
|
-
export declare function NetRequest(config?:
|
|
18
|
+
export declare function NetRequest(config?: RequestGlobalConfig): NetRequestHandler;
|
|
19
19
|
/**
|
|
20
20
|
* 设置全局默认的 Request Config
|
|
21
21
|
*/
|
|
22
|
-
export declare const setGlobalConfig: (config:
|
|
22
|
+
export declare const setGlobalConfig: (config: RequestGlobalConfig) => void;
|
|
23
23
|
/**
|
|
24
24
|
* 发送一个网络请求
|
|
25
25
|
*/
|
|
26
|
-
export declare const request:
|
|
26
|
+
export declare const request: {
|
|
27
|
+
(op: {
|
|
28
|
+
url: string;
|
|
29
|
+
options?: import("./inc/type").RequestOptions;
|
|
30
|
+
}): Promise<import("./inc/type").ResponseResult<unknown>>;
|
|
31
|
+
<T>(op: {
|
|
32
|
+
url: string;
|
|
33
|
+
options?: import("./inc/type").RequestOptions;
|
|
34
|
+
guard: import("./inc/type").DataGuard<T>;
|
|
35
|
+
}): Promise<import("./inc/type").ResponseResult<T>>;
|
|
36
|
+
};
|
|
27
37
|
/**
|
|
28
38
|
* 发送一个 HEAD 请求
|
|
29
39
|
*/
|
|
30
|
-
export declare const head: (url: string, options?: import("./inc/type").
|
|
40
|
+
export declare const head: (url: string, params?: import("./inc/type").RequestQueryParams | null, options?: Omit<import("./inc/type").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
|
|
31
41
|
/**
|
|
32
42
|
* 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景,可选 typeGuard 用于检查数据类型
|
|
33
43
|
*/
|
|
34
44
|
export declare const get: {
|
|
35
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
36
|
-
(url: string,
|
|
37
|
-
|
|
45
|
+
(url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
|
|
46
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
47
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
48
|
+
<T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
38
49
|
};
|
|
39
50
|
/**
|
|
40
51
|
* 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
|
|
41
52
|
*/
|
|
42
53
|
export declare const post: {
|
|
43
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
44
|
-
(url:
|
|
45
|
-
(url:
|
|
46
|
-
<T>(url:
|
|
54
|
+
(url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
55
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
56
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
57
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
47
58
|
};
|
|
48
59
|
/**
|
|
49
60
|
* 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
|
|
50
61
|
*/
|
|
51
62
|
export declare const del: {
|
|
52
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
53
|
-
(url: string,
|
|
54
|
-
|
|
63
|
+
(url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
|
|
64
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
65
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
66
|
+
<T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
55
67
|
};
|
|
56
68
|
/**
|
|
57
69
|
* 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
|
|
58
70
|
*/
|
|
59
71
|
export declare const put: {
|
|
60
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
61
|
-
(url:
|
|
62
|
-
(url:
|
|
63
|
-
<T>(url:
|
|
72
|
+
(url: import("./inc/main").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
73
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
74
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
75
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
64
76
|
};
|
|
65
77
|
/**
|
|
66
78
|
* 发送一个 PATCH 请求,可选 typeGuard 用于检查数据类型
|
|
67
79
|
*/
|
|
68
80
|
export declare const patch: {
|
|
69
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
70
|
-
(url:
|
|
71
|
-
(url:
|
|
72
|
-
<T>(url:
|
|
81
|
+
(url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
82
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
83
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
84
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
73
85
|
};
|
package/types/node.d.ts
CHANGED
|
@@ -1,61 +1,63 @@
|
|
|
1
1
|
import { NetRequestHandler } from "./inc/main";
|
|
2
|
-
import type {
|
|
2
|
+
import type { RequestGlobalConfig } from "./inc/type";
|
|
3
3
|
export { getResponseRulesDescription } from "./inc/rule";
|
|
4
4
|
export { RequestInternalError } from "./inc/type";
|
|
5
|
-
export type { NetRequestHandler } from "./inc/main";
|
|
6
|
-
export type {
|
|
5
|
+
export type { NetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
6
|
+
export type { RequestOptions, RequestGlobalConfig, ResponseRule, ResponseResult, RequestLog, RequestMethod, RequestQueryParams, } from "./inc/type";
|
|
7
7
|
/**
|
|
8
8
|
* 创建新的实例空间,配置和缓存跟全局默认实例是隔离的
|
|
9
9
|
*/
|
|
10
|
-
export declare function NetRequest(config?:
|
|
10
|
+
export declare function NetRequest(config?: RequestGlobalConfig): NetRequestHandler;
|
|
11
11
|
/**
|
|
12
12
|
* 设置全局默认的 Request Config
|
|
13
13
|
*/
|
|
14
|
-
export declare const setGlobalConfig: (config:
|
|
14
|
+
export declare const setGlobalConfig: (config: RequestGlobalConfig) => void;
|
|
15
15
|
/**
|
|
16
16
|
* 发送一个 HEAD 请求
|
|
17
17
|
*/
|
|
18
|
-
export declare const head: (url: string, options?: import("./inc/type").
|
|
18
|
+
export declare const head: (url: string, params?: import("./inc/type").RequestQueryParams | null, options?: Omit<import("./inc/type").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
|
|
19
19
|
/**
|
|
20
20
|
* 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景,可选 typeGuard 用于检查数据类型
|
|
21
21
|
*/
|
|
22
22
|
export declare const get: {
|
|
23
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
24
|
-
(url: string,
|
|
25
|
-
|
|
23
|
+
(url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
|
|
24
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
25
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
26
|
+
<T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
26
27
|
};
|
|
27
28
|
/**
|
|
28
29
|
* 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
|
|
29
30
|
*/
|
|
30
31
|
export declare const post: {
|
|
31
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
32
|
-
(url:
|
|
33
|
-
(url:
|
|
34
|
-
<T>(url:
|
|
32
|
+
(url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
33
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
34
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
35
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
35
36
|
};
|
|
36
37
|
/**
|
|
37
38
|
* 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
|
|
38
39
|
*/
|
|
39
40
|
export declare const del: {
|
|
40
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
41
|
-
(url: string,
|
|
42
|
-
|
|
41
|
+
(url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
|
|
42
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
43
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
44
|
+
<T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
43
45
|
};
|
|
44
46
|
/**
|
|
45
47
|
* 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
|
|
46
48
|
*/
|
|
47
49
|
export declare const put: {
|
|
48
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
49
|
-
(url:
|
|
50
|
-
(url:
|
|
51
|
-
<T>(url:
|
|
50
|
+
(url: import("./inc/main").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
51
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
52
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
53
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
52
54
|
};
|
|
53
55
|
/**
|
|
54
56
|
* 发送一个 PATCH 请求,可选 typeGuard 用于检查数据类型
|
|
55
57
|
*/
|
|
56
58
|
export declare const patch: {
|
|
57
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
58
|
-
(url:
|
|
59
|
-
(url:
|
|
60
|
-
<T>(url:
|
|
59
|
+
(url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
60
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
61
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
62
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
61
63
|
};
|
package/types/wx.d.ts
CHANGED
|
@@ -1,52 +1,54 @@
|
|
|
1
1
|
import { NetRequestHandler } from "./inc/main";
|
|
2
|
-
import type {
|
|
2
|
+
import type { RequestGlobalConfig } from "./inc/type";
|
|
3
3
|
export { getResponseRulesDescription } from "./inc/rule";
|
|
4
4
|
export { RequestInternalError } from "./inc/type";
|
|
5
|
-
export type { NetRequestHandler } from "./inc/main";
|
|
6
|
-
export type {
|
|
5
|
+
export type { NetRequestHandler, URLPlus, BufferRequestOptions } from "./inc/main";
|
|
6
|
+
export type { RequestOptions, RequestGlobalConfig, ResponseRule, ResponseResult, RequestLog, RequestMethod, RequestQueryParams, } from "./inc/type";
|
|
7
7
|
/**
|
|
8
8
|
* 创建新的实例空间,配置和缓存跟全局默认实例是隔离的
|
|
9
9
|
*/
|
|
10
|
-
export declare function NetRequest(config?:
|
|
10
|
+
export declare function NetRequest(config?: RequestGlobalConfig): NetRequestHandler;
|
|
11
11
|
/**
|
|
12
12
|
* 设置全局默认的 Request Config
|
|
13
13
|
*/
|
|
14
|
-
export declare const setGlobalConfig: (config:
|
|
14
|
+
export declare const setGlobalConfig: (config: RequestGlobalConfig) => void;
|
|
15
15
|
/**
|
|
16
16
|
* 发送一个 HEAD 请求
|
|
17
17
|
*/
|
|
18
|
-
export declare const head: (url: string, options?: import("./inc/type").
|
|
18
|
+
export declare const head: (url: string, params?: import("./inc/type").RequestQueryParams | null, options?: Omit<import("./inc/type").RequestOptions, "asBuffer">) => import("./inc/type").ResponseWithoutType;
|
|
19
19
|
/**
|
|
20
20
|
* 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景,可选 typeGuard 用于检查数据类型
|
|
21
21
|
*/
|
|
22
22
|
export declare const get: {
|
|
23
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
24
|
-
(url: string,
|
|
25
|
-
|
|
23
|
+
(url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
|
|
24
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
25
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
26
|
+
<T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
26
27
|
};
|
|
27
28
|
/**
|
|
28
29
|
* 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
|
|
29
30
|
*/
|
|
30
31
|
export declare const post: {
|
|
31
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
32
|
-
(url:
|
|
33
|
-
(url:
|
|
34
|
-
<T>(url:
|
|
32
|
+
(url: import("./inc/main").URLPlus, data?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
33
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
34
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
35
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
35
36
|
};
|
|
36
37
|
/**
|
|
37
38
|
* 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
|
|
38
39
|
*/
|
|
39
40
|
export declare const del: {
|
|
40
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
41
|
-
(url: string,
|
|
42
|
-
|
|
41
|
+
(url: string, params?: import("./inc/type").RequestQueryParams): import("./inc/type").ResponseWithoutType;
|
|
42
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
43
|
+
(url: string, params: import("./inc/type").RequestQueryParams | null, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
44
|
+
<T>(url: string, params: import("./inc/type").RequestQueryParams | null, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
43
45
|
};
|
|
44
46
|
/**
|
|
45
47
|
* 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
|
|
46
48
|
*/
|
|
47
49
|
export declare const put: {
|
|
48
|
-
(url: string): import("./inc/type").ResponseWithoutType;
|
|
49
|
-
(url:
|
|
50
|
-
(url:
|
|
51
|
-
<T>(url:
|
|
50
|
+
(url: import("./inc/main").URLPlus, body?: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams): import("./inc/type").ResponseWithoutType;
|
|
51
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options: import("./inc/main").BufferRequestOptions): import("./inc/type").ResponseWithType<ArrayBuffer>;
|
|
52
|
+
(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: null, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithoutType;
|
|
53
|
+
<T>(url: import("./inc/main").URLPlus, body: string | object | unknown[] | ArrayBuffer | Blob | FormData | URLSearchParams, guard: import("./inc/type").DataGuard<T>, options?: import("./inc/type").RequestOptions): import("./inc/type").ResponseWithType<T>;
|
|
52
54
|
};
|