@chzky/reqwest 0.0.1 → 0.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/README.md +314 -0
- package/esm/_dnt.polyfills.d.ts +11 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -10
- package/esm/_dnt.polyfills.js +24 -66
- package/esm/_dnt.shims.d.ts +1 -13
- package/esm/_dnt.shims.d.ts.map +1 -1
- package/esm/_dnt.shims.js +57 -1
- package/esm/lib/mod.d.ts +1 -1
- package/esm/lib/mod.d.ts.map +1 -1
- package/esm/lib/mod.js +1 -1
- package/esm/lib/reqwest/class.d.ts +116 -78
- package/esm/lib/reqwest/class.d.ts.map +1 -1
- package/esm/lib/reqwest/class.js +175 -1
- package/esm/lib/reqwest/core.d.ts +5 -0
- package/esm/lib/reqwest/core.d.ts.map +1 -1
- package/esm/lib/reqwest/core.js +154 -244
- package/esm/lib/reqwest/factor.d.ts +2 -2
- package/esm/lib/reqwest/factor.d.ts.map +1 -1
- package/esm/lib/reqwest/factor.js +32 -1
- package/esm/lib/reqwest/interface.d.ts +166 -42
- package/esm/lib/reqwest/interface.d.ts.map +1 -1
- package/esm/lib/reqwest/interface.js +1 -1
- package/esm/lib/reqwest/mod.d.ts +1 -1
- package/esm/lib/reqwest/mod.d.ts.map +1 -1
- package/esm/lib/reqwest/mod.js +2 -2
- package/esm/lib/{helper → utils}/mod.d.ts +1 -0
- package/esm/lib/utils/mod.d.ts.map +1 -0
- package/esm/lib/{helper → utils}/mod.js +1 -0
- package/esm/lib/utils/other/mod.d.ts +2 -0
- package/esm/lib/utils/other/mod.d.ts.map +1 -0
- package/esm/lib/utils/other/mod.js +1 -0
- package/esm/lib/utils/other/sseParse.d.ts +34 -0
- package/esm/lib/utils/other/sseParse.d.ts.map +1 -0
- package/esm/lib/utils/other/sseParse.js +42 -0
- package/{script/lib/helper → esm/lib/utils}/request/RESTful.d.ts +43 -11
- package/esm/lib/utils/request/RESTful.d.ts.map +1 -0
- package/esm/lib/utils/request/RESTful.js +129 -0
- package/esm/lib/utils/request/baseConf.d.ts +22 -0
- package/esm/lib/utils/request/baseConf.d.ts.map +1 -0
- package/esm/lib/utils/request/baseConf.js +37 -0
- package/esm/lib/utils/request/factors.d.ts +30 -0
- package/esm/lib/utils/request/factors.d.ts.map +1 -0
- package/esm/lib/utils/request/factors.js +39 -0
- package/esm/lib/{helper → utils}/request/input.d.ts +4 -3
- package/esm/lib/utils/request/input.d.ts.map +1 -0
- package/esm/lib/utils/request/input.js +24 -0
- package/esm/lib/utils/request/mod.d.ts +7 -0
- package/esm/lib/utils/request/mod.d.ts.map +1 -0
- package/esm/lib/utils/request/mod.js +6 -0
- package/esm/lib/utils/request/process.d.ts +16 -0
- package/esm/lib/utils/request/process.d.ts.map +1 -0
- package/esm/lib/utils/request/process.js +37 -0
- package/esm/lib/utils/request/wait.d.ts +10 -0
- package/esm/lib/utils/request/wait.d.ts.map +1 -0
- package/esm/lib/utils/request/wait.js +14 -0
- package/esm/lib/utils/response/blobToUrl.d.ts +10 -0
- package/esm/lib/utils/response/blobToUrl.d.ts.map +1 -0
- package/esm/lib/utils/response/blobToUrl.js +21 -0
- package/esm/lib/utils/response/mod.d.ts +5 -0
- package/esm/lib/utils/response/mod.d.ts.map +1 -0
- package/esm/lib/utils/response/mod.js +4 -0
- package/esm/lib/utils/response/openLink.d.ts +7 -0
- package/esm/lib/utils/response/openLink.d.ts.map +1 -0
- package/esm/lib/utils/response/openLink.js +20 -0
- package/esm/lib/utils/response/output.d.ts +16 -0
- package/esm/lib/utils/response/output.d.ts.map +1 -0
- package/esm/lib/utils/response/output.js +24 -0
- package/esm/lib/utils/response/pick.d.ts +23 -0
- package/esm/lib/utils/response/pick.d.ts.map +1 -0
- package/esm/lib/utils/response/pick.js +25 -0
- package/esm/lib/utils/use/mod.d.ts.map +1 -0
- package/esm/lib/utils/use/mod.js +2 -0
- package/esm/lib/utils/use/useCancel.d.ts +33 -0
- package/esm/lib/utils/use/useCancel.d.ts.map +1 -0
- package/esm/lib/utils/use/useCancel.js +41 -0
- package/esm/lib/utils/use/useLoading.d.ts +34 -0
- package/esm/lib/utils/use/useLoading.d.ts.map +1 -0
- package/esm/lib/utils/use/useLoading.js +57 -0
- package/package.json +4 -11
- package/script/_dnt.polyfills.d.ts +11 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +15 -0
- package/script/_dnt.shims.d.ts +1 -13
- package/script/_dnt.shims.d.ts.map +1 -1
- package/script/_dnt.shims.js +2 -21
- package/script/lib/mod.d.ts +1 -1
- package/script/lib/mod.d.ts.map +1 -1
- package/script/lib/mod.js +1 -1
- package/script/lib/reqwest/class.d.ts +116 -78
- package/script/lib/reqwest/class.d.ts.map +1 -1
- package/script/lib/reqwest/class.js +135 -25
- package/script/lib/reqwest/core.d.ts +5 -0
- package/script/lib/reqwest/core.d.ts.map +1 -1
- package/script/lib/reqwest/core.js +119 -23
- package/script/lib/reqwest/factor.d.ts +2 -2
- package/script/lib/reqwest/factor.d.ts.map +1 -1
- package/script/lib/reqwest/factor.js +2 -2
- package/script/lib/reqwest/interface.d.ts +160 -11
- package/script/lib/reqwest/interface.d.ts.map +1 -1
- package/script/lib/reqwest/mod.d.ts +1 -1
- package/script/lib/reqwest/mod.d.ts.map +1 -1
- package/script/lib/{helper → utils}/mod.d.ts +1 -0
- package/script/lib/utils/mod.d.ts.map +1 -0
- package/script/lib/{helper → utils}/mod.js +1 -0
- package/script/lib/utils/other/mod.d.ts +2 -0
- package/script/lib/utils/other/mod.d.ts.map +1 -0
- package/script/lib/{helper/response → utils/other}/mod.js +1 -2
- package/script/lib/utils/other/sseParse.d.ts +34 -0
- package/script/lib/utils/other/sseParse.d.ts.map +1 -0
- package/script/lib/utils/other/sseParse.js +45 -0
- package/{esm/lib/helper → script/lib/utils}/request/RESTful.d.ts +43 -11
- package/script/lib/utils/request/RESTful.d.ts.map +1 -0
- package/script/lib/utils/request/RESTful.js +140 -0
- package/script/lib/utils/request/baseConf.d.ts +22 -0
- package/script/lib/utils/request/baseConf.d.ts.map +1 -0
- package/script/lib/utils/request/baseConf.js +42 -0
- package/script/lib/utils/request/factors.d.ts +30 -0
- package/script/lib/utils/request/factors.d.ts.map +1 -0
- package/script/lib/utils/request/factors.js +42 -0
- package/script/lib/{helper → utils}/request/input.d.ts +4 -3
- package/script/lib/utils/request/input.d.ts.map +1 -0
- package/script/lib/{helper → utils}/request/input.js +10 -10
- package/script/lib/utils/request/mod.d.ts +7 -0
- package/script/lib/utils/request/mod.d.ts.map +1 -0
- package/script/lib/utils/request/mod.js +22 -0
- package/script/lib/utils/request/process.d.ts +16 -0
- package/script/lib/utils/request/process.d.ts.map +1 -0
- package/script/lib/utils/request/process.js +41 -0
- package/script/lib/utils/request/wait.d.ts +10 -0
- package/script/lib/utils/request/wait.d.ts.map +1 -0
- package/script/lib/utils/request/wait.js +17 -0
- package/script/lib/utils/response/blobToUrl.d.ts +10 -0
- package/script/lib/utils/response/blobToUrl.d.ts.map +1 -0
- package/script/lib/utils/response/blobToUrl.js +24 -0
- package/script/lib/utils/response/mod.d.ts +5 -0
- package/script/lib/utils/response/mod.d.ts.map +1 -0
- package/script/lib/{helper/request → utils/response}/mod.js +4 -3
- package/script/lib/utils/response/openLink.d.ts +7 -0
- package/script/lib/utils/response/openLink.d.ts.map +1 -0
- package/script/lib/{helper/use/useLoading.js → utils/response/openLink.js} +17 -22
- package/script/lib/utils/response/output.d.ts +16 -0
- package/script/lib/utils/response/output.d.ts.map +1 -0
- package/script/lib/utils/response/output.js +28 -0
- package/script/lib/utils/response/pick.d.ts +23 -0
- package/script/lib/utils/response/pick.d.ts.map +1 -0
- package/script/lib/utils/response/pick.js +28 -0
- package/script/lib/utils/use/mod.d.ts.map +1 -0
- package/script/lib/{helper → utils}/use/mod.js +2 -2
- package/script/lib/utils/use/useCancel.d.ts +33 -0
- package/script/lib/utils/use/useCancel.d.ts.map +1 -0
- package/script/lib/utils/use/useCancel.js +44 -0
- package/script/lib/utils/use/useLoading.d.ts +34 -0
- package/script/lib/utils/use/useLoading.d.ts.map +1 -0
- package/script/lib/utils/use/useLoading.js +60 -0
- package/esm/lib/helper/mod.d.ts.map +0 -1
- package/esm/lib/helper/request/RESTful.d.ts.map +0 -1
- package/esm/lib/helper/request/RESTful.js +0 -1
- package/esm/lib/helper/request/baseConf.d.ts +0 -15
- package/esm/lib/helper/request/baseConf.d.ts.map +0 -1
- package/esm/lib/helper/request/baseConf.js +0 -1
- package/esm/lib/helper/request/input.d.ts.map +0 -1
- package/esm/lib/helper/request/input.js +0 -1
- package/esm/lib/helper/request/mod.d.ts +0 -4
- package/esm/lib/helper/request/mod.d.ts.map +0 -1
- package/esm/lib/helper/request/mod.js +0 -3
- package/esm/lib/helper/response/mod.d.ts +0 -3
- package/esm/lib/helper/response/mod.d.ts.map +0 -1
- package/esm/lib/helper/response/mod.js +0 -2
- package/esm/lib/helper/response/output.d.ts +0 -5
- package/esm/lib/helper/response/output.d.ts.map +0 -1
- package/esm/lib/helper/response/output.js +0 -1
- package/esm/lib/helper/response/pick.d.ts +0 -7
- package/esm/lib/helper/response/pick.d.ts.map +0 -1
- package/esm/lib/helper/response/pick.js +0 -1
- package/esm/lib/helper/use/mod.d.ts.map +0 -1
- package/esm/lib/helper/use/mod.js +0 -2
- package/esm/lib/helper/use/useCancel.d.ts +0 -4
- package/esm/lib/helper/use/useCancel.d.ts.map +0 -1
- package/esm/lib/helper/use/useCancel.js +0 -1
- package/esm/lib/helper/use/useLoading.d.ts +0 -15
- package/esm/lib/helper/use/useLoading.d.ts.map +0 -1
- package/esm/lib/helper/use/useLoading.js +0 -1
- package/script/lib/helper/mod.d.ts.map +0 -1
- package/script/lib/helper/request/RESTful.d.ts.map +0 -1
- package/script/lib/helper/request/RESTful.js +0 -86
- package/script/lib/helper/request/baseConf.d.ts +0 -15
- package/script/lib/helper/request/baseConf.d.ts.map +0 -1
- package/script/lib/helper/request/baseConf.js +0 -27
- package/script/lib/helper/request/input.d.ts.map +0 -1
- package/script/lib/helper/request/mod.d.ts +0 -4
- package/script/lib/helper/request/mod.d.ts.map +0 -1
- package/script/lib/helper/response/mod.d.ts +0 -3
- package/script/lib/helper/response/mod.d.ts.map +0 -1
- package/script/lib/helper/response/output.d.ts +0 -5
- package/script/lib/helper/response/output.d.ts.map +0 -1
- package/script/lib/helper/response/output.js +0 -15
- package/script/lib/helper/response/pick.d.ts +0 -7
- package/script/lib/helper/response/pick.d.ts.map +0 -1
- package/script/lib/helper/response/pick.js +0 -12
- package/script/lib/helper/use/mod.d.ts.map +0 -1
- package/script/lib/helper/use/useCancel.d.ts +0 -4
- package/script/lib/helper/use/useCancel.d.ts.map +0 -1
- package/script/lib/helper/use/useCancel.js +0 -15
- package/script/lib/helper/use/useLoading.d.ts +0 -15
- package/script/lib/helper/use/useLoading.d.ts.map +0 -1
- /package/esm/lib/{helper → utils}/use/mod.d.ts +0 -0
- /package/script/lib/{helper → utils}/use/mod.d.ts +0 -0
|
@@ -1,48 +1,172 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { AsyncResult, Copy, Fn, PromiseOr, Result, rjx_ws, UnexpectedError, zod } from '@chzky/core';
|
|
2
|
+
import type { AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from 'axios';
|
|
3
|
+
type WebSocketMessage = string | ArrayBuffer | Blob | ArrayBufferView;
|
|
4
|
+
/** ### `ReqwestWsConfig` : WebSocket连接配置 */
|
|
5
|
+
export type ReqwestWsConfig<A, B> = {
|
|
6
|
+
/** WebSocket连接地址 */
|
|
7
|
+
url: string;
|
|
8
|
+
/** 终止控制器 */
|
|
9
|
+
abort?: AbortController | AbortSignal;
|
|
10
|
+
/** 反序列化函数 , 将获取的数据反序列化为`B`类型
|
|
11
|
+
@default `(data)=>JSON.parse(data.data)` */
|
|
12
|
+
deserialize?: Fn<MessageEvent, B>;
|
|
13
|
+
/** 序列化函数 , 将发送的数据序列化为`WebSocketMessage`类型
|
|
14
|
+
@default `(data)=>JSON.stringify(data)` */
|
|
15
|
+
serialize?: Fn<A, WebSocketMessage>;
|
|
16
|
+
};
|
|
17
|
+
export type ExtendWebSocketSubject<A, B> = {
|
|
18
|
+
next: (data: A) => void;
|
|
19
|
+
subscribe: Fn<Fn<B, void>, void>;
|
|
20
|
+
} & {
|
|
21
|
+
complete?: Fn<void, void>;
|
|
22
|
+
error?: Fn<Fn<unknown, void>, void>;
|
|
23
|
+
next?: Fn<Fn<B, void>, void>;
|
|
24
|
+
} & rjx_ws.WebSocketSubject<unknown>;
|
|
25
|
+
/** ### `ReqwestSSEConfig` : SSE连接配置 */
|
|
26
|
+
export type ReqwestSSEConfig = {
|
|
27
|
+
/** SSE连接地址 */
|
|
28
|
+
url: string;
|
|
29
|
+
/** 终止控制器 */
|
|
30
|
+
abort?: AbortController | AbortSignal;
|
|
31
|
+
/** SSE连接方法 : 默认`get` */
|
|
32
|
+
method?: 'GET' | 'POST';
|
|
33
|
+
/** 解码器 : 默认不使用,直接返回`Uint8Array` */
|
|
34
|
+
decode?: {
|
|
35
|
+
decode: (input: Uint8Array<ArrayBuffer>) => string;
|
|
36
|
+
};
|
|
37
|
+
/** 数据校验器,用于校验解码后的数据 : 默认不使用,直接返回解码后的数据 */
|
|
38
|
+
validator?: zod.ZodSchema<unknown>;
|
|
39
|
+
};
|
|
4
40
|
/** ### `RequestInterceptor` : 请求拦截器 | 返回`Ok()` or `Err(E)`
|
|
5
|
-
+ Ok()
|
|
6
|
-
+ Err(E)
|
|
41
|
+
+ `Ok()`表示通过拦截器 , 会运行下一个拦截器
|
|
42
|
+
+ `Err(E)`表示拦截器拦截 , 会直接短路返回`Err(E)`
|
|
7
43
|
*/
|
|
8
|
-
export type RequestInterceptor<E = never> = (
|
|
9
|
-
conf: InternalAxiosRequestConfig<unknown>
|
|
10
|
-
) => PromiseOr<Result<void, E>>
|
|
44
|
+
export type RequestInterceptor<E = never> = (conf: InternalAxiosRequestConfig<unknown>) => PromiseOr<Result<void, E>>;
|
|
11
45
|
/** ### `ResponseInterceptor` : 响应拦截器 | 返回`Ok(O)` or `Err(E)`
|
|
12
|
-
+ Ok(O) 表示通过拦截器 , 会自动解包并将值传递给下一个拦截器
|
|
13
|
-
+ Err(E)
|
|
46
|
+
+ `Ok(O)` 表示通过拦截器 , 会自动解包并将值传递给下一个拦截器
|
|
47
|
+
+ `Err(E)`表示拦截器拦截 , 会直接短路返回`Err(E)`
|
|
14
48
|
*/
|
|
15
|
-
export type ResponseInterceptor<
|
|
16
|
-
|
|
17
|
-
OO = AxiosResponse<unknown, unknown>,
|
|
18
|
-
EE = never
|
|
19
|
-
> = (response: O) => PromiseOr<Result<OO, EE>>
|
|
20
|
-
/** ### `ReqwestInterceptor` : 拦截器 | 分成响应拦截和请求拦截 */
|
|
49
|
+
export type ResponseInterceptor<O = AxiosResponse<unknown, unknown>, OO = AxiosResponse<unknown, unknown>, EE = never> = (response: O) => PromiseOr<Result<OO, EE>>;
|
|
50
|
+
/** ### `ReqwestInterceptor` : `请求-响应拦截器` | 分成响应拦截和请求拦截 */
|
|
21
51
|
export interface ReqwestInterceptor<O, E, OO = O, EE = never> {
|
|
22
|
-
|
|
23
|
-
|
|
52
|
+
request: RequestInterceptor<E>;
|
|
53
|
+
response: ResponseInterceptor<O, OO, EE>;
|
|
24
54
|
}
|
|
25
|
-
export type MergeErrors<T extends
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
export type MergeErrors<T extends unknown[]> = T extends [
|
|
56
|
+
RequestInterceptor<infer E>,
|
|
57
|
+
...infer Rest
|
|
58
|
+
] ? E | MergeErrors<Rest> : never;
|
|
59
|
+
type FinalResult<Interceptors extends ResponseInterceptor<unknown, unknown, unknown>[], CurrentOutput = AxiosResponse<unknown>, CurrentError = UnexpectedError> = Interceptors extends [
|
|
60
|
+
infer First,
|
|
61
|
+
...infer Rest extends ResponseInterceptor<unknown, unknown, unknown>[]
|
|
62
|
+
] ? First extends ResponseInterceptor<CurrentOutput, infer NextOutput, infer NextError> ? FinalResult<Rest, NextOutput, NextError | CurrentError> : never : Result<CurrentOutput, CurrentError>;
|
|
63
|
+
export type ResponseResult<O, E, ER, Interceptors extends ResponseInterceptor<unknown, unknown, unknown>[]> = ReqwestInterface<FinalResult<Interceptors, O, ER> extends Result<infer O, unknown> ? O : never, E, FinalResult<Interceptors, O, ER> extends Result<unknown, infer E> ? E : never>;
|
|
64
|
+
export interface ReqwestInterface<O = AxiosResponse<unknown, unknown>, E = never, ER = UnexpectedError> extends Copy {
|
|
65
|
+
/** ### `conf` : 更新配置
|
|
66
|
+
@example Usage
|
|
67
|
+
```ts
|
|
68
|
+
const conf = { baseURL: 'https://jsonplaceholder.typicode.com/todos/' }
|
|
69
|
+
const mock_reqwest = Reqwest.new().conf(conf)
|
|
70
|
+
mock_reqwest.dispatch() // curl https://jsonplaceholder.typicode.com/todos/
|
|
71
|
+
```
|
|
72
|
+
*/
|
|
73
|
+
conf(conf: CreateAxiosDefaults): ReqwestInterface<O, E, ER>;
|
|
74
|
+
/** ### `dispatch` : 发送请求,获取请求结果
|
|
75
|
+
@example Usage
|
|
76
|
+
```ts
|
|
77
|
+
const conf = { baseURL: 'https://jsonplaceholder.typicode.com/todos/' }
|
|
78
|
+
const mock_reqwest = Reqwest.new().conf(conf)
|
|
79
|
+
mock_reqwest.dispatch() // dispatch to get https://jsonplaceholder.typicode.com/todos/
|
|
80
|
+
```
|
|
81
|
+
*/
|
|
82
|
+
dispatch(): AsyncResult<O, E | ER>;
|
|
83
|
+
/** ### `request` : 增加请求拦截器,拦截器会按顺序执行
|
|
84
|
+
+ 该方法会返回一个新的`Reqwest`,并且与原`Reqwest`保持独立 */
|
|
85
|
+
request<I extends RequestInterceptor<unknown>[]>(...interceptors: I): ReqwestInterface<O, MergeErrors<I> | E, ER>;
|
|
86
|
+
/** ### `response` : 增加响应拦截器,拦截器会按顺序执行
|
|
87
|
+
+ 该方法会返回一个新的`Reqwest`,并且与原`Reqwest`保持独立 */
|
|
88
|
+
response<OO, EE>(interceptor: ResponseInterceptor<O, OO, EE>): ReqwestInterface<OO, E, EE | ER>;
|
|
89
|
+
response<OO, EE, O2, E2>(...interceptor: [ResponseInterceptor<O, OO, EE>, ResponseInterceptor<OO, O2, E2>]): ReqwestInterface<O2, E, E2 | EE | ER>;
|
|
90
|
+
response<OO, EE, O2, E2, O3, E3>(...interceptor: [
|
|
91
|
+
ResponseInterceptor<O, OO, EE>,
|
|
92
|
+
ResponseInterceptor<OO, O2, E2>,
|
|
93
|
+
ResponseInterceptor<O2, O3, E3>
|
|
94
|
+
]): ReqwestInterface<O3, E, E3 | E2 | EE | ER>;
|
|
95
|
+
response<OO, EE, O2, E2, O3, E3, O4, E4>(...interceptor: [
|
|
96
|
+
ResponseInterceptor<O, OO, EE>,
|
|
97
|
+
ResponseInterceptor<OO, O2, E2>,
|
|
98
|
+
ResponseInterceptor<O2, O3, E3>,
|
|
99
|
+
ResponseInterceptor<O3, O4, E4>
|
|
100
|
+
]): ReqwestInterface<O4, E, E4 | E3 | E2 | EE | ER>;
|
|
101
|
+
response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5>(...interceptor: [
|
|
102
|
+
ResponseInterceptor<O, OO, EE>,
|
|
103
|
+
ResponseInterceptor<OO, O2, E2>,
|
|
104
|
+
ResponseInterceptor<O2, O3, E3>,
|
|
105
|
+
ResponseInterceptor<O3, O4, E4>
|
|
106
|
+
]): ReqwestInterface<O5, E, E5 | E4 | E3 | E2 | EE | ER>;
|
|
107
|
+
response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6>(...interceptor: [
|
|
108
|
+
ResponseInterceptor<O, OO, EE>,
|
|
109
|
+
ResponseInterceptor<OO, O2, E2>,
|
|
110
|
+
ResponseInterceptor<O2, O3, E3>,
|
|
111
|
+
ResponseInterceptor<O3, O4, E4>,
|
|
112
|
+
ResponseInterceptor<O4, O5, E5>,
|
|
113
|
+
ResponseInterceptor<O5, O6, E6>
|
|
114
|
+
]): ReqwestInterface<O6, E, E6 | E5 | E4 | E3 | E2 | EE | ER>;
|
|
115
|
+
response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6, O7, E7>(...interceptor: [
|
|
116
|
+
ResponseInterceptor<O, OO, EE>,
|
|
117
|
+
ResponseInterceptor<OO, O2, E2>,
|
|
118
|
+
ResponseInterceptor<O2, O3, E3>,
|
|
119
|
+
ResponseInterceptor<O3, O4, E4>,
|
|
120
|
+
ResponseInterceptor<O4, O5, E5>,
|
|
121
|
+
ResponseInterceptor<O5, O6, E6>,
|
|
122
|
+
ResponseInterceptor<O6, O7, E7>
|
|
123
|
+
]): ReqwestInterface<O7, E, E7 | E6 | E5 | E4 | E3 | E2 | EE | ER>;
|
|
124
|
+
response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6, O7, E7, O8, E8>(...interceptor: [
|
|
125
|
+
ResponseInterceptor<O, OO, EE>,
|
|
126
|
+
ResponseInterceptor<OO, O2, E2>,
|
|
127
|
+
ResponseInterceptor<O2, O3, E3>,
|
|
128
|
+
ResponseInterceptor<O3, O4, E4>,
|
|
129
|
+
ResponseInterceptor<O4, O5, E5>,
|
|
130
|
+
ResponseInterceptor<O5, O6, E6>,
|
|
131
|
+
ResponseInterceptor<O6, O7, E7>,
|
|
132
|
+
ResponseInterceptor<O7, O8, E8>
|
|
133
|
+
]): ReqwestInterface<O8, E, E8 | E7 | E6 | E5 | E4 | E3 | E2 | EE | ER>;
|
|
134
|
+
response<OO, EE, O2, E2, O3, E3, O4, E4, O5, E5, O6, E6, O7, E7, O8, E8, O9, E9>(...interceptor: [
|
|
135
|
+
ResponseInterceptor<O, OO, EE>,
|
|
136
|
+
ResponseInterceptor<OO, O2, E2>,
|
|
137
|
+
ResponseInterceptor<O2, O3, E3>,
|
|
138
|
+
ResponseInterceptor<O3, O4, E4>,
|
|
139
|
+
ResponseInterceptor<O4, O5, E5>,
|
|
140
|
+
ResponseInterceptor<O5, O6, E6>,
|
|
141
|
+
ResponseInterceptor<O6, O7, E7>,
|
|
142
|
+
ResponseInterceptor<O7, O8, E8>,
|
|
143
|
+
ResponseInterceptor<O8, O9, E9>
|
|
144
|
+
]): ReqwestInterface<O9, E, E9 | E8 | E7 | E6 | E5 | E4 | E3 | E2 | EE | ER>;
|
|
145
|
+
/** ### `use` : 增加`请求-响应拦截器`,拦截器会按顺序执行
|
|
146
|
+
+ 该方法会返回一个新的`Reqwest`,并且与原`Reqwest`保持独立
|
|
147
|
+
@example Usage - cancel
|
|
148
|
+
```ts
|
|
149
|
+
const conf = { baseURL: 'https://jsonplaceholder.typicode.com/todos/' }
|
|
150
|
+
const mock_reqwest = Reqwest.new().conf(conf)
|
|
151
|
+
|
|
152
|
+
const [abort_controler, interceptor] = cancel() // 可取消的请求
|
|
153
|
+
|
|
154
|
+
const reqwest = mock_reqwest.clone().request(wait(2000), get('/1')).use(interceptor)
|
|
155
|
+
|
|
156
|
+
const mock_cause = 'mock abort'
|
|
157
|
+
abort_controler.abort(mock_cause)
|
|
158
|
+
|
|
159
|
+
const result = await reqwest.dispatch()
|
|
160
|
+
|
|
161
|
+
const error = result.unwrap_err()
|
|
162
|
+
assert(error.instance_of(AbortedError))
|
|
163
|
+
assert.equal(error.cause, mock_cause)
|
|
164
|
+
```
|
|
165
|
+
*/
|
|
166
|
+
use<OO, EC, EE>(interceptor: ReqwestInterceptor<O, EC, OO, EE>): ReqwestInterface<OO, EC | E, EE | ER>;
|
|
167
|
+
/** ### `clone`
|
|
168
|
+
+ 实现{@link Copy}接口 : 生成一个全新的`Reqwest` */
|
|
169
|
+
clone(): ReqwestInterface<O, E, ER>;
|
|
170
|
+
}
|
|
171
|
+
export {};
|
|
172
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/lib/reqwest/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/lib/reqwest/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EACX,IAAI,EACJ,EAAE,EACF,SAAS,EACT,MAAM,EACN,MAAM,EACN,eAAe,EACf,GAAG,EACH,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAA;AAE3F,KAAK,gBAAgB,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI,GAAG,eAAe,CAAA;AAErE,4CAA4C;AAC5C,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI;IACnC,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,YAAY;IACZ,KAAK,CAAC,EAAE,eAAe,GAAG,WAAW,CAAA;IACrC;+CAC2C;IAC3C,WAAW,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA;IACjC;8CAC0C;IAC1C,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAA;CACnC,CAAA;AAGD,MAAM,MAAM,sBAAsB,CAAC,CAAC,EAAE,CAAC,IAAI;IAC1C,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IACvB,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;CAChC,GAAG;IACH,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,I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4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export type { RequestInterceptor, ReqwestInterceptor, ResponseInterceptor, } from './interface.js';
|
|
2
2
|
export * from './class.js';
|
|
3
3
|
export * from './factor.js';
|
|
4
4
|
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/lib/reqwest/mod.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/lib/reqwest/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,GACnB,MAAM,gBAAgB,CAAA;AAEvB,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
|
package/esm/lib/reqwest/mod.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './class.js'
|
|
2
|
-
export * from './factor.js'
|
|
1
|
+
export * from './class.js';
|
|
2
|
+
export * from './factor.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/mod.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/other/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sseParse.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** `SSEMessageEvent` : 经典的SSE事件名
|
|
2
|
+
+ `message` : 默认事件(不写 event: 时就是它)
|
|
3
|
+
+ `open` : 连接建立后服务器推送的第一条欢迎消息
|
|
4
|
+
+ `ping` : 服务端保活
|
|
5
|
+
+ `update` : 数据增量更新
|
|
6
|
+
+ `error` : 服务端主动通知前端“出错了”
|
|
7
|
+
+ `close` : 服务端优雅关闭连接
|
|
8
|
+
*/
|
|
9
|
+
export type SSEMessageEvent = 'message' | 'open' | 'ping' | 'update' | 'error' | 'close';
|
|
10
|
+
export interface SSEMessage {
|
|
11
|
+
/** 数据 */
|
|
12
|
+
data: string;
|
|
13
|
+
/** 事件类型 */
|
|
14
|
+
event?: SSEMessageEvent | string;
|
|
15
|
+
/** 消息ID */
|
|
16
|
+
id?: string;
|
|
17
|
+
/** 重连时间(毫秒) */
|
|
18
|
+
retry?: number;
|
|
19
|
+
}
|
|
20
|
+
/** ## `parse_sse_data` : 解析[标准SSE格式](https://developer.mozilla.org/zh-CN/docs/Web/API/Server-sent_events/Using_server-sent_events)的数据
|
|
21
|
+
@example Usage
|
|
22
|
+
```ts
|
|
23
|
+
const generator = Reqwest.sse({
|
|
24
|
+
url: 'http://localhost:7788/api/ping/sse',
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
for await (const item of generator) {
|
|
28
|
+
const { data } = parse_sse_data(item)
|
|
29
|
+
assert(typeof data === 'string')
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
*/
|
|
33
|
+
export declare function parse_sse_data(data: string | Uint8Array): SSEMessage;
|
|
34
|
+
//# sourceMappingURL=sseParse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sseParse.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/other/sseParse.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAA;AAExF,MAAM,WAAW,UAAU;IAC1B,SAAS;IACT,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW;IACX,KAAK,CAAC,EAAE,eAAe,GAAG,MAAM,CAAA;IAChC,WAAW;IACX,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,eAAe;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;;;;;;GAYG;AAEH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAGpE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** ## `parse_sse_data` : 解析[标准SSE格式](https://developer.mozilla.org/zh-CN/docs/Web/API/Server-sent_events/Using_server-sent_events)的数据
|
|
2
|
+
@example Usage
|
|
3
|
+
```ts
|
|
4
|
+
const generator = Reqwest.sse({
|
|
5
|
+
url: 'http://localhost:7788/api/ping/sse',
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
for await (const item of generator) {
|
|
9
|
+
const { data } = parse_sse_data(item)
|
|
10
|
+
assert(typeof data === 'string')
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
*/
|
|
14
|
+
export function parse_sse_data(data) {
|
|
15
|
+
if (typeof data === 'string')
|
|
16
|
+
return parse_core(data);
|
|
17
|
+
return parse_core(new TextDecoder().decode(data));
|
|
18
|
+
}
|
|
19
|
+
const MSG_SPLIT = '\n';
|
|
20
|
+
const EVENT_LINE = 'event: ';
|
|
21
|
+
const ID_LINE = 'id: ';
|
|
22
|
+
const RETRY_LINE = 'retry: ';
|
|
23
|
+
const DATA_LINE = 'data: ';
|
|
24
|
+
function parse_core(str) {
|
|
25
|
+
const result = { data: '' };
|
|
26
|
+
const lines = str.split(MSG_SPLIT);
|
|
27
|
+
for (const line of lines) {
|
|
28
|
+
if (line.startsWith(DATA_LINE)) {
|
|
29
|
+
if (result.data.length === 0)
|
|
30
|
+
result.data += line.slice(DATA_LINE.length);
|
|
31
|
+
else
|
|
32
|
+
result.data += `\n${line.slice(DATA_LINE.length)}`;
|
|
33
|
+
}
|
|
34
|
+
if (line.startsWith(ID_LINE))
|
|
35
|
+
result.id = line.slice(ID_LINE.length);
|
|
36
|
+
if (line.startsWith(EVENT_LINE))
|
|
37
|
+
result.event = line.slice(EVENT_LINE.length);
|
|
38
|
+
if (line.startsWith(RETRY_LINE))
|
|
39
|
+
result.retry = Number(line.slice(RETRY_LINE.length));
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
@@ -1,40 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { JsonXObject } from '@chzky/core';
|
|
2
2
|
import type { RequestInterceptor } from '../../../mod.js';
|
|
3
3
|
/** ### `post` : post请求
|
|
4
|
-
@param
|
|
4
|
+
@param `string` - 请求地址
|
|
5
5
|
@param [data={}] `unknown` - 请求数据
|
|
6
6
|
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
7
|
-
@
|
|
8
|
-
@category `Request`
|
|
7
|
+
@category `RequestInterceptor`
|
|
9
8
|
*/
|
|
10
9
|
export declare function post(url: string, data?: unknown, query?: JsonXObject): RequestInterceptor<never>;
|
|
11
10
|
/** ### `get` : get请求
|
|
12
11
|
@param url `string` - 请求地址
|
|
13
12
|
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
14
|
-
@
|
|
15
|
-
@category `Request`
|
|
13
|
+
@category `RequestInterceptor`
|
|
16
14
|
*/
|
|
17
15
|
export declare function get(url: string, query?: JsonXObject): RequestInterceptor<never>;
|
|
18
16
|
/** ### `put` : put请求
|
|
19
17
|
@param url `string` - 请求地址
|
|
20
18
|
@param [data={}] `unknown` - 请求数据
|
|
21
19
|
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
22
|
-
@
|
|
23
|
-
@category `Request`
|
|
20
|
+
@category `RequestInterceptor`
|
|
24
21
|
*/
|
|
25
22
|
export declare function put(url: string, data?: unknown, query?: JsonXObject): RequestInterceptor<never>;
|
|
26
23
|
/** ### `del` : delete请求
|
|
27
24
|
@param url `string` - 请求地址
|
|
28
25
|
@param [query={}] `Record<string, unknown>` - query形式的请求参数
|
|
29
|
-
@
|
|
30
|
-
@category `Request`
|
|
26
|
+
@category `RequestInterceptor`
|
|
31
27
|
*/
|
|
32
28
|
export declare function del(url: string, query?: JsonXObject): RequestInterceptor<never>;
|
|
33
29
|
/** ### `form` : FormData形式请求
|
|
34
30
|
@param url `string` - 请求地址
|
|
35
31
|
@param data `Record<string, string | Blob>` - 请求数据
|
|
36
|
-
@type `Interceptor` - `Request`
|
|
37
32
|
@category `Request`
|
|
38
33
|
*/
|
|
39
34
|
export declare function form(url: string, data: Record<string | number, string | Blob>): RequestInterceptor<never>;
|
|
35
|
+
/** ### `set_body` : 覆盖Body参数
|
|
36
|
+
该方法会覆盖请求的Body参数
|
|
37
|
+
@example Usage
|
|
38
|
+
```ts
|
|
39
|
+
const request = post('/api')
|
|
40
|
+
request.use(set_body({ foo: 'bar' })) // Will override request body
|
|
41
|
+
```
|
|
42
|
+
@param data `unknown` - 请求数据
|
|
43
|
+
@category `RequestInterceptor`
|
|
44
|
+
*/
|
|
45
|
+
export declare function set_body(data: unknown): RequestInterceptor<never>;
|
|
46
|
+
/** ### `set_params` : 覆盖URL参数
|
|
47
|
+
该方法会覆盖请求的URL参数
|
|
48
|
+
@example Usage
|
|
49
|
+
```ts
|
|
50
|
+
const request = get('/api')
|
|
51
|
+
request.use(set_params({ foo: 'bar' })) // Will override request params
|
|
52
|
+
```
|
|
53
|
+
@param params `Record<string, unknown>` - URL形式的请求参数
|
|
54
|
+
@type `Interceptor` - `Request`
|
|
55
|
+
@category `RequestInterceptor`
|
|
56
|
+
*/
|
|
57
|
+
export declare function set_params(params: JsonXObject): RequestInterceptor<never>;
|
|
58
|
+
/** ### `append_url` : URL
|
|
59
|
+
该方法会将url添加到请求地址的后面;如果没有url,则直接添加
|
|
60
|
+
@param url `string` - 请求地址
|
|
61
|
+
@type `Interceptor` - `Request`
|
|
62
|
+
@category `RequestInterceptor`
|
|
63
|
+
*/
|
|
64
|
+
export declare function append_url(url: string): RequestInterceptor<never>;
|
|
65
|
+
/** ## `RESTful` : `RESTful`请求 */
|
|
66
|
+
export declare const RESTful: {
|
|
67
|
+
readonly Get: typeof get;
|
|
68
|
+
readonly Post: typeof post;
|
|
69
|
+
readonly Put: typeof put;
|
|
70
|
+
readonly Del: typeof del;
|
|
71
|
+
};
|
|
40
72
|
//# sourceMappingURL=RESTful.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RESTful.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/RESTful.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAIzD;;;;;EAKE;AACF,wBAAgB,IAAI,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,OAAY,EAClB,KAAK,GAAE,WAAgB,GACrB,kBAAkB,CAAC,KAAK,CAAC,CAQ3B;AAED;;;;EAIE;AACF,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAOnF;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAClB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,OAAY,EAClB,KAAK,GAAE,WAAgB,GACrB,kBAAkB,CAAC,KAAK,CAAC,CAQ3B;AAED;;;;EAIE;AACF,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAOnF;AAED;;;;EAIE;AACF,wBAAgB,IAAI,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,GAC1C,kBAAkB,CAAC,KAAK,CAAC,CAW3B;AAED;;;;;;;;;EASE;AACF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAKjE;AAED;;;;;;;;;;EAUE;AACF,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAKzE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAMjE;AAED,kCAAkC;AAClC,eAAO,MAAM,OAAO;;;;;CAKV,CAAA"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Ok } from '@chzky/core';
|
|
2
|
+
/** ### `post` : post请求
|
|
3
|
+
@param `string` - 请求地址
|
|
4
|
+
@param [data={}] `unknown` - 请求数据
|
|
5
|
+
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
6
|
+
@category `RequestInterceptor`
|
|
7
|
+
*/
|
|
8
|
+
export function post(url, data = {}, query = {}) {
|
|
9
|
+
return conf => {
|
|
10
|
+
conf.method = 'post';
|
|
11
|
+
conf.url = url;
|
|
12
|
+
conf.data = data;
|
|
13
|
+
conf.params = query;
|
|
14
|
+
return Ok();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** ### `get` : get请求
|
|
18
|
+
@param url `string` - 请求地址
|
|
19
|
+
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
20
|
+
@category `RequestInterceptor`
|
|
21
|
+
*/
|
|
22
|
+
export function get(url, query = {}) {
|
|
23
|
+
return conf => {
|
|
24
|
+
conf.method = 'get';
|
|
25
|
+
conf.url = url;
|
|
26
|
+
conf.params = query;
|
|
27
|
+
return Ok();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** ### `put` : put请求
|
|
31
|
+
@param url `string` - 请求地址
|
|
32
|
+
@param [data={}] `unknown` - 请求数据
|
|
33
|
+
@param [query={}] `Record<string, unknown>` - URL形式的请求参数
|
|
34
|
+
@category `RequestInterceptor`
|
|
35
|
+
*/
|
|
36
|
+
export function put(url, data = {}, query = {}) {
|
|
37
|
+
return conf => {
|
|
38
|
+
conf.method = 'put';
|
|
39
|
+
conf.url = url;
|
|
40
|
+
conf.data = data;
|
|
41
|
+
conf.params = query;
|
|
42
|
+
return Ok();
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** ### `del` : delete请求
|
|
46
|
+
@param url `string` - 请求地址
|
|
47
|
+
@param [query={}] `Record<string, unknown>` - query形式的请求参数
|
|
48
|
+
@category `RequestInterceptor`
|
|
49
|
+
*/
|
|
50
|
+
export function del(url, query = {}) {
|
|
51
|
+
return conf => {
|
|
52
|
+
conf.method = 'delete';
|
|
53
|
+
conf.url = url;
|
|
54
|
+
conf.params = query;
|
|
55
|
+
return Ok();
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** ### `form` : FormData形式请求
|
|
59
|
+
@param url `string` - 请求地址
|
|
60
|
+
@param data `Record<string, string | Blob>` - 请求数据
|
|
61
|
+
@category `Request`
|
|
62
|
+
*/
|
|
63
|
+
export function form(url, data) {
|
|
64
|
+
return conf => {
|
|
65
|
+
conf.method = 'post';
|
|
66
|
+
conf.url = url;
|
|
67
|
+
const fdata = new FormData();
|
|
68
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
69
|
+
fdata.append(key, value);
|
|
70
|
+
});
|
|
71
|
+
conf.data = fdata;
|
|
72
|
+
return Ok();
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** ### `set_body` : 覆盖Body参数
|
|
76
|
+
该方法会覆盖请求的Body参数
|
|
77
|
+
@example Usage
|
|
78
|
+
```ts
|
|
79
|
+
const request = post('/api')
|
|
80
|
+
request.use(set_body({ foo: 'bar' })) // Will override request body
|
|
81
|
+
```
|
|
82
|
+
@param data `unknown` - 请求数据
|
|
83
|
+
@category `RequestInterceptor`
|
|
84
|
+
*/
|
|
85
|
+
export function set_body(data) {
|
|
86
|
+
return conf => {
|
|
87
|
+
conf.data = data;
|
|
88
|
+
return Ok();
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** ### `set_params` : 覆盖URL参数
|
|
92
|
+
该方法会覆盖请求的URL参数
|
|
93
|
+
@example Usage
|
|
94
|
+
```ts
|
|
95
|
+
const request = get('/api')
|
|
96
|
+
request.use(set_params({ foo: 'bar' })) // Will override request params
|
|
97
|
+
```
|
|
98
|
+
@param params `Record<string, unknown>` - URL形式的请求参数
|
|
99
|
+
@type `Interceptor` - `Request`
|
|
100
|
+
@category `RequestInterceptor`
|
|
101
|
+
*/
|
|
102
|
+
export function set_params(params) {
|
|
103
|
+
return conf => {
|
|
104
|
+
conf.params = params;
|
|
105
|
+
return Ok();
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** ### `append_url` : URL
|
|
109
|
+
该方法会将url添加到请求地址的后面;如果没有url,则直接添加
|
|
110
|
+
@param url `string` - 请求地址
|
|
111
|
+
@type `Interceptor` - `Request`
|
|
112
|
+
@category `RequestInterceptor`
|
|
113
|
+
*/
|
|
114
|
+
export function append_url(url) {
|
|
115
|
+
return conf => {
|
|
116
|
+
if (!conf.url)
|
|
117
|
+
conf.url = url;
|
|
118
|
+
else
|
|
119
|
+
conf.url = `${url}/${conf.url}`.replace(/\/{2,}/g, '/');
|
|
120
|
+
return Ok();
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** ## `RESTful` : `RESTful`请求 */
|
|
124
|
+
export const RESTful = {
|
|
125
|
+
Get: get,
|
|
126
|
+
Post: post,
|
|
127
|
+
Put: put,
|
|
128
|
+
Del: del,
|
|
129
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PositiveInteger } from '@chzky/core';
|
|
2
|
+
import type { RequestInterceptor } from '../../../mod.js';
|
|
3
|
+
import type { AxiosRequestHeaders, ResponseType } from 'axios';
|
|
4
|
+
/** ## `header` : 修改请求头数据
|
|
5
|
+
@param head `AxiosRequestHeaders` - 请求头数据
|
|
6
|
+
@type `Interceptor` - `Request`
|
|
7
|
+
@category `Request`
|
|
8
|
+
*/
|
|
9
|
+
export declare function header(head: AxiosRequestHeaders): RequestInterceptor<never>;
|
|
10
|
+
/** ## `response_type` : 修改响应数据类型
|
|
11
|
+
@param type `ResponseType` - 响应数据类型
|
|
12
|
+
@type `Interceptor` - `Request`
|
|
13
|
+
@category `Request`
|
|
14
|
+
*/
|
|
15
|
+
export declare function response_type(type: ResponseType): RequestInterceptor<never>;
|
|
16
|
+
/** ## `timeout` : 修改请求超时时间
|
|
17
|
+
@param time `PositiveInteger<N>` - 请求超时时间
|
|
18
|
+
@type `Interceptor` - `Request`
|
|
19
|
+
@category `Request`
|
|
20
|
+
*/
|
|
21
|
+
export declare function timeout<N extends number>(time: PositiveInteger<N>): RequestInterceptor<never>;
|
|
22
|
+
//# sourceMappingURL=baseConf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseConf.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/request/baseConf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAI9D;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAO3E;AAED;;;;EAIE;AACF,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK3E;AAED;;;;EAIE;AACF,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAK7F"}
|