@varlet/axle 1.0.0 → 1.0.2
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/dist/api.d.mts +27 -0
- package/dist/api.mjs +46 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.mjs +324 -0
- package/dist/instance-ar9qY3vp.d.mts +64 -0
- package/dist/use.d.mts +85 -0
- package/dist/use.mjs +229 -0
- package/package.json +34 -34
- package/lib/api.cjs +0 -89
- package/lib/api.d.cts +0 -28
- package/lib/api.d.ts +0 -28
- package/lib/api.js +0 -41
- package/lib/chunk-G2ADBYYC.js +0 -37
- package/lib/index.cjs +0 -490
- package/lib/index.d.cts +0 -85
- package/lib/index.d.ts +0 -85
- package/lib/index.js +0 -427
- package/lib/instance-857fe07c.d.ts +0 -64
- package/lib/use.cjs +0 -351
- package/lib/use.d.cts +0 -85
- package/lib/use.d.ts +0 -85
- package/lib/use.js +0 -314
package/lib/index.js
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__spreadProps,
|
|
3
|
-
__spreadValues
|
|
4
|
-
} from "./chunk-G2ADBYYC.js";
|
|
5
|
-
|
|
6
|
-
// src/instance.ts
|
|
7
|
-
import axios from "axios";
|
|
8
|
-
import qs from "qs";
|
|
9
|
-
|
|
10
|
-
// src/utils/index.ts
|
|
11
|
-
function isFormData(value) {
|
|
12
|
-
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
13
|
-
}
|
|
14
|
-
function formDataToObject(formData) {
|
|
15
|
-
const normalizedData = {};
|
|
16
|
-
formData.forEach((value, key) => {
|
|
17
|
-
normalizedData[key] = value;
|
|
18
|
-
});
|
|
19
|
-
return normalizedData;
|
|
20
|
-
}
|
|
21
|
-
function objectToFormData(object) {
|
|
22
|
-
const formData = new FormData();
|
|
23
|
-
Object.keys(object).forEach((key) => formData.append(key, object[key]));
|
|
24
|
-
return formData;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/instance.ts
|
|
28
|
-
import { AxiosError, isAxiosError } from "axios";
|
|
29
|
-
function createFetchRunner(service, method, responseType) {
|
|
30
|
-
return function(url, params, config) {
|
|
31
|
-
return service[method](url, __spreadValues({
|
|
32
|
-
params,
|
|
33
|
-
responseType
|
|
34
|
-
}, config));
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function createModifyRunner(service, method, contentType) {
|
|
38
|
-
return function(url, params, config) {
|
|
39
|
-
let normalizedParams = params != null ? params : {};
|
|
40
|
-
if (contentType === "application/x-www-form-urlencoded") {
|
|
41
|
-
normalizedParams = qs.stringify(normalizedParams);
|
|
42
|
-
}
|
|
43
|
-
if (contentType === "multipart/form-data") {
|
|
44
|
-
normalizedParams = objectToFormData(normalizedParams);
|
|
45
|
-
}
|
|
46
|
-
return service[method](url, normalizedParams, __spreadValues({
|
|
47
|
-
headers: {
|
|
48
|
-
"Content-Type": contentType
|
|
49
|
-
}
|
|
50
|
-
}, config));
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function createAxle(config = {}) {
|
|
54
|
-
const service = axios.create(config);
|
|
55
|
-
function getHeaders() {
|
|
56
|
-
return service.defaults.headers.common;
|
|
57
|
-
}
|
|
58
|
-
function setHeader(key, value) {
|
|
59
|
-
;
|
|
60
|
-
service.defaults.headers.common[key] = value;
|
|
61
|
-
}
|
|
62
|
-
function removeHeader(key) {
|
|
63
|
-
if (typeof key === "string") {
|
|
64
|
-
Reflect.deleteProperty(service.defaults.headers.common, key);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
key.forEach((k) => Reflect.deleteProperty(service.defaults.headers.common, k));
|
|
68
|
-
}
|
|
69
|
-
function useRequestInterceptor(...interceptors) {
|
|
70
|
-
interceptors.forEach((interceptor) => {
|
|
71
|
-
service.interceptors.request.use(interceptor.onFulfilled, interceptor.onRejected, interceptor.options);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function useResponseInterceptor(...interceptors) {
|
|
75
|
-
interceptors.forEach((interceptor) => {
|
|
76
|
-
service.interceptors.response.use(interceptor.onFulfilled, interceptor.onRejected, interceptor.options);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
get: createFetchRunner(service, "get", "json"),
|
|
81
|
-
getBlob: createFetchRunner(service, "get", "blob"),
|
|
82
|
-
getDocument: createFetchRunner(service, "get", "document"),
|
|
83
|
-
getArrayBuffer: createFetchRunner(service, "get", "arraybuffer"),
|
|
84
|
-
getText: createFetchRunner(service, "get", "text"),
|
|
85
|
-
getStream: createFetchRunner(service, "get", "stream"),
|
|
86
|
-
head: createFetchRunner(service, "head", "json"),
|
|
87
|
-
headBlob: createFetchRunner(service, "head", "blob"),
|
|
88
|
-
headDocument: createFetchRunner(service, "head", "document"),
|
|
89
|
-
headArrayBuffer: createFetchRunner(service, "head", "arraybuffer"),
|
|
90
|
-
headText: createFetchRunner(service, "head", "text"),
|
|
91
|
-
headStream: createFetchRunner(service, "head", "stream"),
|
|
92
|
-
options: createFetchRunner(service, "options", "json"),
|
|
93
|
-
optionsBlob: createFetchRunner(service, "options", "blob"),
|
|
94
|
-
optionsDocument: createFetchRunner(service, "options", "document"),
|
|
95
|
-
optionsArrayBuffer: createFetchRunner(service, "options", "arraybuffer"),
|
|
96
|
-
optionsText: createFetchRunner(service, "options", "text"),
|
|
97
|
-
optionsStream: createFetchRunner(service, "options", "stream"),
|
|
98
|
-
delete: createFetchRunner(service, "delete", "json"),
|
|
99
|
-
deleteBlob: createFetchRunner(service, "delete", "blob"),
|
|
100
|
-
deleteDocument: createFetchRunner(service, "delete", "document"),
|
|
101
|
-
deleteArrayBuffer: createFetchRunner(service, "delete", "arraybuffer"),
|
|
102
|
-
deleteText: createFetchRunner(service, "delete", "text"),
|
|
103
|
-
deleteStream: createFetchRunner(service, "delete", "stream"),
|
|
104
|
-
post: createModifyRunner(service, "post", "application/json"),
|
|
105
|
-
postUrlEncode: createModifyRunner(service, "post", "application/x-www-form-urlencoded"),
|
|
106
|
-
postMultipart: createModifyRunner(service, "post", "multipart/form-data"),
|
|
107
|
-
put: createModifyRunner(service, "put", "application/json"),
|
|
108
|
-
putUrlEncode: createModifyRunner(service, "put", "application/x-www-form-urlencoded"),
|
|
109
|
-
putMultipart: createModifyRunner(service, "put", "multipart/form-data"),
|
|
110
|
-
patch: createModifyRunner(service, "patch", "application/json"),
|
|
111
|
-
patchUrlEncode: createModifyRunner(service, "patch", "application/x-www-form-urlencoded"),
|
|
112
|
-
patchMultipart: createModifyRunner(service, "patch", "multipart/form-data"),
|
|
113
|
-
getHeaders,
|
|
114
|
-
setHeader,
|
|
115
|
-
removeHeader,
|
|
116
|
-
useRequestInterceptor,
|
|
117
|
-
useResponseInterceptor,
|
|
118
|
-
axios: service
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// src/matcher.ts
|
|
123
|
-
import { isFunction } from "rattail";
|
|
124
|
-
function matchPattern(pattern, method, url, status) {
|
|
125
|
-
if (isFunction(pattern)) {
|
|
126
|
-
return pattern({ url, method, status });
|
|
127
|
-
}
|
|
128
|
-
if (pattern.startsWith("status:")) {
|
|
129
|
-
return pattern.replace("status:", "").trim() === String(status);
|
|
130
|
-
}
|
|
131
|
-
return pattern.startsWith("method:") ? pattern.replace("method:", "").trim() === method : url === pattern;
|
|
132
|
-
}
|
|
133
|
-
function createMatcher(include, exclude) {
|
|
134
|
-
function matcher(method, url, status) {
|
|
135
|
-
if (!include && !exclude) {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
const isExclude = (exclude != null ? exclude : []).some((pattern) => matchPattern(pattern, method, url, status));
|
|
139
|
-
if (isExclude) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (!include) {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
const isInclude = (include != null ? include : []).some((pattern) => matchPattern(pattern, method, url, status));
|
|
146
|
-
return isInclude;
|
|
147
|
-
}
|
|
148
|
-
return matcher;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// src/helper.ts
|
|
152
|
-
import { isAxiosError as isAxiosError2 } from "axios";
|
|
153
|
-
import { inBrowser } from "rattail";
|
|
154
|
-
function withResponse(promise) {
|
|
155
|
-
return new Promise((resolve, reject) => {
|
|
156
|
-
promise.then((response) => {
|
|
157
|
-
resolve({
|
|
158
|
-
response,
|
|
159
|
-
errorResponse: void 0
|
|
160
|
-
});
|
|
161
|
-
}).catch((error) => {
|
|
162
|
-
if (isAxiosError2(error)) {
|
|
163
|
-
resolve({
|
|
164
|
-
response: void 0,
|
|
165
|
-
errorResponse: error.response
|
|
166
|
-
});
|
|
167
|
-
} else {
|
|
168
|
-
reject(error);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
function download(url, filename) {
|
|
174
|
-
if (!inBrowser()) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const a = document.createElement("a");
|
|
178
|
-
a.download = filename;
|
|
179
|
-
a.style.display = "none";
|
|
180
|
-
a.href = typeof url === "string" ? url : URL.createObjectURL(url);
|
|
181
|
-
document.body.appendChild(a);
|
|
182
|
-
a.click();
|
|
183
|
-
URL.revokeObjectURL(a.href);
|
|
184
|
-
document.body.removeChild(a);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// src/interceptors/requestHeadersInterceptor.ts
|
|
188
|
-
import { isFunction as isFunction2 } from "rattail";
|
|
189
|
-
function requestHeadersInterceptor(options = {}) {
|
|
190
|
-
const { headers: headersOrGetter } = options;
|
|
191
|
-
return {
|
|
192
|
-
onFulfilled(config) {
|
|
193
|
-
var _a, _b, _c;
|
|
194
|
-
const matcher = createMatcher(options.include, options.exclude);
|
|
195
|
-
if (!matcher((_a = config.method) != null ? _a : "", (_b = config.url) != null ? _b : "")) {
|
|
196
|
-
return config;
|
|
197
|
-
}
|
|
198
|
-
const headers = (_c = isFunction2(headersOrGetter) ? headersOrGetter() : headersOrGetter) != null ? _c : {};
|
|
199
|
-
Object.entries(headers).forEach(([key, value]) => {
|
|
200
|
-
config.headers[key] = value;
|
|
201
|
-
});
|
|
202
|
-
return config;
|
|
203
|
-
},
|
|
204
|
-
onRejected: (error) => Promise.reject(error),
|
|
205
|
-
options: options.axiosInterceptorOptions
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// src/interceptors/requestMockInterceptor.ts
|
|
210
|
-
import { AxiosError as AxiosError2 } from "axios";
|
|
211
|
-
import { isFunction as isFunction3 } from "rattail";
|
|
212
|
-
function settle(response, resolve, reject, delay = 0) {
|
|
213
|
-
if (delay > 0) {
|
|
214
|
-
setTimeout(() => {
|
|
215
|
-
settle(response, resolve, reject);
|
|
216
|
-
}, delay);
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (!response.config.validateStatus || response.config.validateStatus(response.status)) {
|
|
220
|
-
resolve(response);
|
|
221
|
-
} else {
|
|
222
|
-
reject(new AxiosError2(`Request failed with status code ${response.status}`, void 0, response.config, response));
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function requestMockInterceptor(options = {}) {
|
|
226
|
-
return {
|
|
227
|
-
onFulfilled(config) {
|
|
228
|
-
var _a, _b;
|
|
229
|
-
const matcher = createMatcher(options.include, options.exclude);
|
|
230
|
-
if (!matcher((_a = config.method) != null ? _a : "", (_b = config.url) != null ? _b : "")) {
|
|
231
|
-
return config;
|
|
232
|
-
}
|
|
233
|
-
const findMapping = () => {
|
|
234
|
-
var _a2;
|
|
235
|
-
return ((_a2 = options.mappings) != null ? _a2 : []).find((mapping2) => {
|
|
236
|
-
var _a3, _b2;
|
|
237
|
-
const isMatchUrl = isFunction3(mapping2.url) ? mapping2.url((_a3 = config.url) != null ? _a3 : "") : mapping2.url === ((_b2 = config.url) != null ? _b2 : "");
|
|
238
|
-
const isMatchMethod = mapping2.method != null ? config.method === mapping2.method : true;
|
|
239
|
-
return isMatchUrl && isMatchMethod;
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
const mapping = findMapping();
|
|
243
|
-
if (!mapping) {
|
|
244
|
-
return config;
|
|
245
|
-
}
|
|
246
|
-
config.adapter = () => {
|
|
247
|
-
var _a2, _b2;
|
|
248
|
-
const partialResponse = mapping.handler(config);
|
|
249
|
-
const response = __spreadProps(__spreadValues({}, partialResponse), {
|
|
250
|
-
headers: config.headers,
|
|
251
|
-
config,
|
|
252
|
-
request: {},
|
|
253
|
-
data: partialResponse.data,
|
|
254
|
-
status: (_a2 = partialResponse.status) != null ? _a2 : 200,
|
|
255
|
-
statusText: (_b2 = partialResponse.statusText) != null ? _b2 : "OK"
|
|
256
|
-
});
|
|
257
|
-
return new Promise((resolve, reject) => {
|
|
258
|
-
settle(response, resolve, reject, mapping.delay);
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
return config;
|
|
262
|
-
},
|
|
263
|
-
onRejected: (error) => Promise.reject(error),
|
|
264
|
-
options: options.axiosInterceptorOptions
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// src/interceptors/responseBlobInterceptor.ts
|
|
269
|
-
function responseBlobInterceptor(options = {}) {
|
|
270
|
-
return {
|
|
271
|
-
onFulfilled(response) {
|
|
272
|
-
var _a, _b, _c, _d;
|
|
273
|
-
const matcher = createMatcher(options.include, options.exclude);
|
|
274
|
-
if (!matcher((_a = response.config.method) != null ? _a : "", (_b = response.config.url) != null ? _b : "", response.status)) {
|
|
275
|
-
return response;
|
|
276
|
-
}
|
|
277
|
-
if (response.request.responseType === "blob") {
|
|
278
|
-
return (_d = (_c = options.onResponse) == null ? void 0 : _c.call(options, response)) != null ? _d : response;
|
|
279
|
-
}
|
|
280
|
-
return response;
|
|
281
|
-
},
|
|
282
|
-
onRejected: (error) => Promise.reject(error),
|
|
283
|
-
options: options.axiosInterceptorOptions
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// src/interceptors/responseRetryInterceptor.ts
|
|
288
|
-
import axios2, { isCancel } from "axios";
|
|
289
|
-
function responseRetryInterceptor(options) {
|
|
290
|
-
return {
|
|
291
|
-
onFulfilled: (response) => response,
|
|
292
|
-
onRejected(error) {
|
|
293
|
-
var _a, _b, _c;
|
|
294
|
-
const matcher = createMatcher(options.include, options.exclude);
|
|
295
|
-
if (!matcher((_a = error.config.method) != null ? _a : "", (_b = error.config.url) != null ? _b : "", (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.status) || isCancel(error)) {
|
|
296
|
-
return Promise.reject(error);
|
|
297
|
-
}
|
|
298
|
-
const { count = 1 } = options;
|
|
299
|
-
let retryCount = 0;
|
|
300
|
-
async function retry() {
|
|
301
|
-
try {
|
|
302
|
-
retryCount++;
|
|
303
|
-
return await axios2.create()(error.config);
|
|
304
|
-
} catch (error2) {
|
|
305
|
-
if (retryCount === count) {
|
|
306
|
-
return Promise.reject(error2);
|
|
307
|
-
}
|
|
308
|
-
return retry();
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return retry();
|
|
312
|
-
},
|
|
313
|
-
options: options.axiosInterceptorOptions
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// src/interceptors/responseStatusInterceptor.ts
|
|
318
|
-
function responseStatusInterceptor(options) {
|
|
319
|
-
return {
|
|
320
|
-
onFulfilled: (response) => {
|
|
321
|
-
var _a, _b, _c;
|
|
322
|
-
const matcher = createMatcher(options.include, options.exclude);
|
|
323
|
-
if (!matcher((_a = response.config.method) != null ? _a : "", (_b = response.config.url) != null ? _b : "", response.status)) {
|
|
324
|
-
return response;
|
|
325
|
-
}
|
|
326
|
-
const handler = ((_c = options.validStatusHandler) != null ? _c : {})[response.status];
|
|
327
|
-
if (!handler) {
|
|
328
|
-
return response;
|
|
329
|
-
}
|
|
330
|
-
const handlerResponse = handler(response);
|
|
331
|
-
return handlerResponse != null ? handlerResponse : response;
|
|
332
|
-
},
|
|
333
|
-
onRejected: (error) => {
|
|
334
|
-
var _a, _b, _c, _d;
|
|
335
|
-
const matcher = createMatcher(options.include, options.exclude);
|
|
336
|
-
if (!matcher((_a = error.config.method) != null ? _a : "", (_b = error.config.url) != null ? _b : "", (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.status)) {
|
|
337
|
-
return Promise.reject(error);
|
|
338
|
-
}
|
|
339
|
-
const handler = ((_d = options.invalidStatusHandler) != null ? _d : {})[error.response.status];
|
|
340
|
-
if (!handler) {
|
|
341
|
-
return Promise.reject(error);
|
|
342
|
-
}
|
|
343
|
-
const handlerError = handler(error);
|
|
344
|
-
return handlerError != null ? handlerError : Promise.reject(error);
|
|
345
|
-
},
|
|
346
|
-
options: options.axiosInterceptorOptions
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// src/interceptors/requestMd5Interceptor.ts
|
|
351
|
-
import md5 from "crypto-js/md5.js";
|
|
352
|
-
import get from "lodash/get.js";
|
|
353
|
-
import set from "lodash/set.js";
|
|
354
|
-
import qs2 from "qs";
|
|
355
|
-
import { isFunction as isFunction4, isString } from "rattail";
|
|
356
|
-
function withCtxMd5(ctx, mapping) {
|
|
357
|
-
mapping.path.forEach((path) => {
|
|
358
|
-
const targetValue = get(ctx, path);
|
|
359
|
-
if (targetValue != null) {
|
|
360
|
-
set(ctx, path, md5(String(targetValue)).toString());
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
function withMd5(config, mapping) {
|
|
365
|
-
const { data = {}, params = {}, headers = {} } = config;
|
|
366
|
-
const ctx = {
|
|
367
|
-
data: isFormData(data) ? data : JSON.parse(JSON.stringify(data)),
|
|
368
|
-
params: JSON.parse(JSON.stringify(params)),
|
|
369
|
-
headers: JSON.parse(JSON.stringify(headers))
|
|
370
|
-
};
|
|
371
|
-
if (isString(ctx.data) && ctx.data.length > 0 && ctx.headers["Content-Type"] === "application/x-www-form-urlencoded") {
|
|
372
|
-
ctx.data = qs2.parse(ctx.data);
|
|
373
|
-
withCtxMd5(ctx, mapping);
|
|
374
|
-
ctx.data = qs2.stringify(ctx.data);
|
|
375
|
-
} else if (isFormData(ctx.data)) {
|
|
376
|
-
ctx.data = formDataToObject(ctx.data);
|
|
377
|
-
withCtxMd5(ctx, mapping);
|
|
378
|
-
ctx.data = objectToFormData(ctx.data);
|
|
379
|
-
} else {
|
|
380
|
-
withCtxMd5(ctx, mapping);
|
|
381
|
-
}
|
|
382
|
-
return __spreadValues(__spreadValues({}, config), ctx);
|
|
383
|
-
}
|
|
384
|
-
function requestMd5Interceptor(options = {}) {
|
|
385
|
-
return {
|
|
386
|
-
onFulfilled(config) {
|
|
387
|
-
var _a, _b;
|
|
388
|
-
const matcher = createMatcher(options.include, options.exclude);
|
|
389
|
-
if (!matcher((_a = config.method) != null ? _a : "", (_b = config.url) != null ? _b : "")) {
|
|
390
|
-
return config;
|
|
391
|
-
}
|
|
392
|
-
const findMapping = () => {
|
|
393
|
-
var _a2;
|
|
394
|
-
return ((_a2 = options.mappings) != null ? _a2 : []).find((mapping2) => {
|
|
395
|
-
var _a3, _b2;
|
|
396
|
-
const isMatchUrl = isFunction4(mapping2.url) ? mapping2.url((_a3 = config.url) != null ? _a3 : "") : mapping2.url === ((_b2 = config.url) != null ? _b2 : "");
|
|
397
|
-
const isMatchMethod = mapping2.method != null ? config.method === mapping2.method : true;
|
|
398
|
-
return isMatchUrl && isMatchMethod;
|
|
399
|
-
});
|
|
400
|
-
};
|
|
401
|
-
const mapping = findMapping();
|
|
402
|
-
if (!mapping) {
|
|
403
|
-
return config;
|
|
404
|
-
}
|
|
405
|
-
return withMd5(config, mapping);
|
|
406
|
-
},
|
|
407
|
-
onRejected: (error) => Promise.reject(error),
|
|
408
|
-
options: options.axiosInterceptorOptions
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
export {
|
|
412
|
-
AxiosError,
|
|
413
|
-
createAxle,
|
|
414
|
-
createFetchRunner,
|
|
415
|
-
createMatcher,
|
|
416
|
-
createModifyRunner,
|
|
417
|
-
download,
|
|
418
|
-
isAxiosError,
|
|
419
|
-
matchPattern,
|
|
420
|
-
requestHeadersInterceptor,
|
|
421
|
-
requestMd5Interceptor,
|
|
422
|
-
requestMockInterceptor,
|
|
423
|
-
responseBlobInterceptor,
|
|
424
|
-
responseRetryInterceptor,
|
|
425
|
-
responseStatusInterceptor,
|
|
426
|
-
withResponse
|
|
427
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse, AxiosInterceptorOptions, InternalAxiosRequestConfig, HeadersDefaults, AxiosInstance, ResponseType } from 'axios';
|
|
2
|
-
|
|
3
|
-
interface AxleRequestConfig<D = any, E = Record<string, any>> extends AxiosRequestConfig<D> {
|
|
4
|
-
extra?: E;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type FetchRunner = <R = AxiosResponse, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P, config?: AxleRequestConfig<D>) => Promise<R>;
|
|
8
|
-
type ModifyRunner = <R = AxiosResponse, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P, config?: AxleRequestConfig<D>) => Promise<R>;
|
|
9
|
-
type FetchMethod = 'get' | 'delete' | 'options' | 'head';
|
|
10
|
-
type ModifyMethod = 'post' | 'put' | 'patch';
|
|
11
|
-
type RunnerMethod = keyof Omit<AxleInstance, 'axios' | 'getHeaders' | 'setHeader' | 'removeHeader' | 'useRequestInterceptor' | 'useResponseInterceptor'>;
|
|
12
|
-
interface Interceptor<V> {
|
|
13
|
-
onFulfilled?: ((value: V) => any) | null;
|
|
14
|
-
onRejected?: ((error: any) => any) | null;
|
|
15
|
-
options?: AxiosInterceptorOptions;
|
|
16
|
-
}
|
|
17
|
-
type RequestInterceptor = Interceptor<InternalAxiosRequestConfig>;
|
|
18
|
-
type ResponseInterceptor<V = AxiosResponse<any, any>> = Interceptor<V>;
|
|
19
|
-
type AxleInstance = {
|
|
20
|
-
get: FetchRunner;
|
|
21
|
-
getBlob: FetchRunner;
|
|
22
|
-
getDocument: FetchRunner;
|
|
23
|
-
getText: FetchRunner;
|
|
24
|
-
getArrayBuffer: FetchRunner;
|
|
25
|
-
getStream: FetchRunner;
|
|
26
|
-
head: FetchRunner;
|
|
27
|
-
headBlob: FetchRunner;
|
|
28
|
-
headDocument: FetchRunner;
|
|
29
|
-
headText: FetchRunner;
|
|
30
|
-
headArrayBuffer: FetchRunner;
|
|
31
|
-
headStream: FetchRunner;
|
|
32
|
-
options: FetchRunner;
|
|
33
|
-
optionsBlob: FetchRunner;
|
|
34
|
-
optionsDocument: FetchRunner;
|
|
35
|
-
optionsText: FetchRunner;
|
|
36
|
-
optionsArrayBuffer: FetchRunner;
|
|
37
|
-
optionsStream: FetchRunner;
|
|
38
|
-
delete: FetchRunner;
|
|
39
|
-
deleteBlob: FetchRunner;
|
|
40
|
-
deleteDocument: FetchRunner;
|
|
41
|
-
deleteText: FetchRunner;
|
|
42
|
-
deleteArrayBuffer: FetchRunner;
|
|
43
|
-
deleteStream: FetchRunner;
|
|
44
|
-
post: ModifyRunner;
|
|
45
|
-
postUrlEncode: ModifyRunner;
|
|
46
|
-
postMultipart: ModifyRunner;
|
|
47
|
-
put: ModifyRunner;
|
|
48
|
-
putUrlEncode: ModifyRunner;
|
|
49
|
-
putMultipart: ModifyRunner;
|
|
50
|
-
patch: ModifyRunner;
|
|
51
|
-
patchUrlEncode: ModifyRunner;
|
|
52
|
-
patchMultipart: ModifyRunner;
|
|
53
|
-
getHeaders(): HeadersDefaults['common'];
|
|
54
|
-
setHeader(key: string, value: string): void;
|
|
55
|
-
removeHeader(key: string | string[]): void;
|
|
56
|
-
useRequestInterceptor(...interceptors: RequestInterceptor[]): void;
|
|
57
|
-
useResponseInterceptor(...interceptors: ResponseInterceptor[]): void;
|
|
58
|
-
axios: AxiosInstance;
|
|
59
|
-
};
|
|
60
|
-
declare function createFetchRunner(service: AxiosInstance, method: FetchMethod, responseType: ResponseType): <R = AxiosResponse<any, any>, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P | undefined, config?: AxleRequestConfig<D, Record<string, any>> | undefined) => Promise<R>;
|
|
61
|
-
declare function createModifyRunner(service: AxiosInstance, method: ModifyMethod, contentType: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded'): <R = AxiosResponse<any, any>, P = Record<string, any>, D = Record<string, any>>(url: string, params?: P | undefined, config?: AxleRequestConfig<D, Record<string, any>> | undefined) => Promise<R>;
|
|
62
|
-
declare function createAxle(config?: AxleRequestConfig): AxleInstance;
|
|
63
|
-
|
|
64
|
-
export { AxleRequestConfig as A, FetchRunner as F, Interceptor as I, ModifyRunner as M, RequestInterceptor as R, ResponseInterceptor as a, FetchMethod as b, ModifyMethod as c, RunnerMethod as d, AxleInstance as e, createFetchRunner as f, createModifyRunner as g, createAxle as h };
|