forked from flow-typed/flow-typed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
axios_v1.x.x.js
245 lines (218 loc) · 6.42 KB
/
axios_v1.x.x.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
declare module 'axios' {
import type { Agent as HttpAgent } from 'http';
import type { Agent as HttpsAgent } from 'https';
declare type AxiosTransformer<T> = (
data: T,
headers?: { [key: string]: mixed, ...},
) => mixed;
declare type ProxyConfig = {|
host: string,
port: number,
auth?: {|
username: string,
password: string,
|},
protocol?: string,
|};
declare type Canceler = (message?: string) => void;
declare type CancelTokenSource = {|
token: CancelToken,
cancel: Canceler,
|};
declare class CancelToken {
constructor(executor: (cancel: Canceler) => void): void;
static source(): CancelTokenSource;
promise: Promise<Cancel<mixed>>;
reason?: Cancel<mixed>;
throwIfRequested(): void;
}
declare type Method =
| 'get'
| 'GET'
| 'delete'
| 'DELETE'
| 'head'
| 'HEAD'
| 'options'
| 'OPTIONS'
| 'post'
| 'POST'
| 'put'
| 'PUT'
| 'patch'
| 'PATCH';
declare type ResponseType =
| 'arraybuffer'
| 'blob'
| 'document'
| 'json'
| 'text'
| 'stream';
declare type AxiosAdapter = (
config: AxiosXHRConfig<mixed>
) => Promise<AxiosXHR<mixed>>;
declare type AxiosXHRConfigBase<T, R = T> = {
adapter?: AxiosAdapter,
auth?: {|
username: string,
password: string,
|},
baseURL?: string,
cancelToken?: CancelToken,
headers?: { [key: string]: mixed, ...},
httpAgent?: HttpAgent,
httpsAgent?: HttpsAgent,
maxContentLength?: number,
maxRedirects?: number,
signal?: AbortSignal,
socketPath?: string | null,
params?: { [key: string]: mixed, ...},
paramsSerializer?: (params: { [key: string]: mixed, ...}) => string,
onUploadProgress?: (progressEvent: ProgressEvent) => void,
onDownloadProgress?: (progressEvent: ProgressEvent) => void,
proxy?: ProxyConfig | false,
responseType?: ResponseType,
timeout?: number,
transformRequest?: AxiosTransformer<T> | Array<AxiosTransformer<T>>,
transformResponse?: AxiosTransformer<R> | Array<AxiosTransformer<R>>,
validateStatus?: (status: number) => boolean,
withCredentials?: boolean,
xsrfCookieName?: string,
xsrfHeaderName?: string,
...
};
declare type AxiosXHRConfig<T, R = T> = {
...$Exact<AxiosXHRConfigBase<T, R>>,
data?: T,
method?: Method,
url: string,
...
};
declare type AxiosXHRConfigShape<T, R = T> = $Shape<AxiosXHRConfig<T, R>>;
declare type AxiosXHR<T, R = T> = {|
config: AxiosXHRConfig<T, R>,
data: R,
headers: ?{[key: string]: mixed, ...},
status: number,
statusText: string,
request: http$ClientRequest<> | XMLHttpRequest | mixed,
|};
declare type AxiosInterceptorIdent = number;
declare type AxiosRequestInterceptor<T, R = T> = {|
use(
onFulfilled: ?(
response: AxiosXHRConfig<T, R>
) => Promise<AxiosXHRConfig<mixed>> | AxiosXHRConfig<mixed>,
onRejected: ?(error: mixed) => mixed
): AxiosInterceptorIdent,
eject(ident: AxiosInterceptorIdent): void,
clear(): void,
|};
declare type AxiosResponseInterceptor<T, R = T> = {|
use(
onFulfilled: ?(response: AxiosXHR<T, R>) => mixed,
onRejected: ?(error: mixed) => mixed
): AxiosInterceptorIdent,
eject(ident: AxiosInterceptorIdent): void,
clear(): void,
|};
declare type AxiosPromise<T, R = T> = Promise<AxiosXHR<T, R>>;
declare class Axios {
<T, R>(
config: AxiosXHRConfig<T, R> | string,
config?: AxiosXHRConfigShape<T, R>
): AxiosPromise<T, R>;
constructor<T, R>(config?: AxiosXHRConfigBase<T, R>): void;
request<T, R>(
config: AxiosXHRConfig<T, R> | string,
config?: AxiosXHRConfigShape<T, R>
): AxiosPromise<T, R>;
delete<R>(
url: string,
config?: AxiosXHRConfigBase<mixed, R>
): AxiosPromise<mixed, R>;
get<R>(
url: string,
config?: AxiosXHRConfigBase<mixed, R>
): AxiosPromise<mixed, R>;
head<R>(
url: string,
config?: AxiosXHRConfigBase<mixed, R>
): AxiosPromise<mixed, R>;
options<R>(
url: string,
config?: AxiosXHRConfigBase<mixed, R>
): AxiosPromise<mixed, R>;
post<T, R>(
url: string,
data?: T,
config?: AxiosXHRConfigBase<T, R>
): AxiosPromise<T, R>;
put<T, R>(
url: string,
data?: T,
config?: AxiosXHRConfigBase<T, R>
): AxiosPromise<T, R>;
patch<T, R>(
url: string,
data?: T,
config?: AxiosXHRConfigBase<T, R>
): AxiosPromise<T, R>;
interceptors: {|
request: AxiosRequestInterceptor<mixed>,
response: AxiosResponseInterceptor<mixed>,
|};
defaults: {|
...$Exact<AxiosXHRConfigBase<mixed>>,
headers: { [key: string]: mixed, ...},
|};
getUri<T, R>(config?: AxiosXHRConfig<T, R>): string;
}
declare class AxiosError<T, R = T> extends Error {
static ERR_NETWORK: string;
static ERR_BAD_OPTION_VALUE: string;
static ERR_BAD_OPTION: string;
static ECONNABORTED: string;
static ETIMEDOUT: string;
static ERR_NETWORK: string;
static ERR_FR_TOO_MANY_REDIRECTS: string;
static ERR_DEPRECATED: string;
static ERR_BAD_RESPONSE: string;
static ERR_BAD_REQUEST: string;
static ERR_CANCELED: string;
config: AxiosXHRConfig<T, R>;
request?: http$ClientRequest<> | XMLHttpRequest;
response?: AxiosXHR<T, R>;
code?: string;
isAxiosError: boolean;
status?: string;
}
declare class CanceledError<T> extends AxiosError<T> {
}
declare class Cancel<T> extends AxiosError<T> {
}
declare interface AxiosExport extends Axios {
<T, R>(
config: AxiosXHRConfig<T, R> | string,
config?: AxiosXHRConfigShape<T, R>
): AxiosPromise<T, R>;
Axios: typeof Axios;
AxiosError: typeof AxiosError;
CanceledError: typeof CanceledError;
Cancel: typeof Cancel;
CancelToken: typeof CancelToken;
isCancel(value: mixed): boolean;
create<T, R>(config?: AxiosXHRConfigBase<T, R>): Axios;
all: typeof Promise.all;
spread<T, R>(callback: (...args: T) => R): (array: T) => R;
toFormData: (
obj: { [key: string]: any, ... },
formData?: FormData,
) => FormData;
}
declare type $AxiosXHRConfigBase<T, R = T> = AxiosXHRConfigBase<T, R>;
declare type $AxiosXHRConfig<T, R = T> = AxiosXHRConfig<T, R>;
declare type $AxiosXHR<T, R = T> = AxiosXHR<T, R>;
declare type $AxiosError<T, R = T> = AxiosError<T, R>;
declare module.exports: AxiosExport;
}