This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
interfaces.ts
89 lines (78 loc) · 2.2 KB
/
interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
export interface IData {
[key: string]: any;
}
export interface IHeaderData {
[key: string]: any;
}
export type Data = string | IData | FormData;
export type TransformRequest = (data: Data, headers?: IHeaderData) => Data;
export type TransformResponse = (data: Data) => Data;
export interface IConfig {
headers?: IHeaderData;
params?: {
[key: string]: string | number | boolean;
};
timeout?: number;
withCredentials?: boolean;
auth?: {
username: string;
password: string;
};
validateStatus?: Function;
paramsSerializer?: Function;
transformRequest?: Array<TransformRequest>;
transformResponse?: Array<TransformResponse>;
redirect?: RequestRedirect;
responseType?: ResponseType;
}
export interface IRequest extends IConfig {
url?: string;
baseURL?: string;
method?:
| string
| 'get'
| 'post'
| 'put'
| 'delete'
| 'options'
| 'head'
| 'connect'
| 'trace'
| 'patch';
data?: Data;
}
export interface IAxiodResponse<T = any> {
status: number;
statusText: string;
data: T;
headers: Headers;
config: IRequest;
}
export interface IAxiodError<T = unknown> {
response: {
status: number;
statusText: string;
data: T;
headers: Headers;
};
config: IRequest;
}
export type IAxiodRequestInterceptor = (config: IRequest) => IRequest | Promise<IRequest>;
export type IAxiodRequestErrorInterceptor = (error: IAxiodError) => Promise<never>;
export type IAxiodResponseInterceptor<T = any> = (response: IAxiodResponse<T>) => IAxiodResponse<T>;
export type IAxiodResponseErrorInterceptor = (error: IAxiodError) => Promise<never>;
export interface IAxiodInterceptor<Fullfill = any, Rejected = any> {
list: Array<
{
fulfilled?: Fullfill | null;
rejected?: Rejected | null;
} | null
>;
use: (fulfilled?: Fullfill | null | undefined, rejected?: Rejected | null | undefined) => number;
eject: (index: number) => void;
}
export interface IAxiodInterceptors {
request: IAxiodInterceptor<IAxiodRequestInterceptor, IAxiodRequestErrorInterceptor>;
response: IAxiodInterceptor<IAxiodResponseInterceptor, IAxiodResponseErrorInterceptor>;
}
export type ResponseType = 'arraybuffer' | 'blob' | 'json' | 'text' | 'stream';