@uni-helper/axios-adapter 0.0.1 → 0.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/README.md +8 -1
- package/README.zh-CN.md +7 -0
- package/dist/index.cjs +42 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -45
- package/dist/index.js.map +1 -1
- package/package.json +12 -14
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @uni-helper/axios-adapter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
this is an Axios adapter for uni-app
|
|
4
4
|
|
|
5
5
|
English | [简体中文](./README.zh-CN.md)
|
|
6
6
|
|
|
@@ -30,3 +30,10 @@ const $axios = axios.create({
|
|
|
30
30
|
## Configuration
|
|
31
31
|
|
|
32
32
|
see [types.ts](./src/types.ts)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Notes
|
|
36
|
+
|
|
37
|
+
Axios-adapter uses the built-in utility functions of Axios, but Axios does not export `"./lib/*": "./lib/*"`, so you need to use a tool like `pnpm patch` to export it.
|
|
38
|
+
|
|
39
|
+
Here's an example: [axios@1.2.1.patch](./patches/axios%401.2.1.patch)
|
package/README.zh-CN.md
CHANGED
|
@@ -30,3 +30,10 @@ const $axios = axios.create({
|
|
|
30
30
|
## 配置
|
|
31
31
|
|
|
32
32
|
见 [types.ts](./src/types.ts)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## 注意事项
|
|
36
|
+
|
|
37
|
+
`axios-adapter` 使用了 `axios` 内置的工具库函数,但是 axios 未导出 `"./lib/*": "./lib/*"`,因此您需要使用类似 `pnpm patch` 的工具导出。
|
|
38
|
+
|
|
39
|
+
这里有一个例子: [axios@1.2.1.patch](./patches/axios%401.2.1.patch)
|
package/dist/index.cjs
CHANGED
|
@@ -1,39 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
25
2
|
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
var buildURL = require('axios/lib/helpers/buildURL.js');
|
|
4
|
+
var buildFullPath = require('axios/lib/core/buildFullPath.js');
|
|
5
|
+
var speedometer = require('axios/lib/helpers/speedometer.js');
|
|
6
|
+
var axios = require('axios');
|
|
7
|
+
var settle = require('axios/lib/core/settle.js');
|
|
32
8
|
|
|
33
9
|
// src/utils.ts
|
|
34
|
-
var import_buildURL = __toESM(require("axios/lib/helpers/buildURL.js"), 1);
|
|
35
|
-
var import_buildFullPath = __toESM(require("axios/lib/core/buildFullPath.js"), 1);
|
|
36
|
-
var import_speedometer = __toESM(require("axios/lib/helpers/speedometer.js"), 1);
|
|
37
10
|
var getMethodType = (config) => {
|
|
38
11
|
const { method: rawMethod = "GET" } = config;
|
|
39
12
|
const method = rawMethod.toLocaleLowerCase();
|
|
@@ -52,7 +25,7 @@ var resolveOptions = (userOptions) => {
|
|
|
52
25
|
};
|
|
53
26
|
};
|
|
54
27
|
var resolveUniAppRequestOptions = (config, options) => {
|
|
55
|
-
var _a;
|
|
28
|
+
var _a, _b, _c, _d, _e;
|
|
56
29
|
const data = config.data;
|
|
57
30
|
const responseType = config.responseType === "arraybuffer" ? "arraybuffer" : "text";
|
|
58
31
|
const dataType = responseType === "text" ? "json" : void 0;
|
|
@@ -65,13 +38,13 @@ var resolveUniAppRequestOptions = (config, options) => {
|
|
|
65
38
|
"Basic " + btoa(username + ":" + password)
|
|
66
39
|
);
|
|
67
40
|
}
|
|
68
|
-
const fullPath = (
|
|
69
|
-
const method = ((_a = config == null ? void 0 : config.method) == null ? void 0 : _a.toUpperCase())
|
|
70
|
-
const url = (
|
|
41
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
42
|
+
const method = (_b = (_a = config == null ? void 0 : config.method) == null ? void 0 : _a.toUpperCase()) != null ? _b : "GET";
|
|
43
|
+
const url = buildURL(fullPath, config.params, config.paramsSerializer);
|
|
71
44
|
const timeout = config.timeout || 6e4;
|
|
72
|
-
const withCredentials = config.withCredentials
|
|
73
|
-
const sslVerify = config.sslVerify
|
|
74
|
-
const firstIpv4 = config.firstIpv4
|
|
45
|
+
const withCredentials = (_c = config.withCredentials) != null ? _c : false;
|
|
46
|
+
const sslVerify = (_d = config.sslVerify) != null ? _d : true;
|
|
47
|
+
const firstIpv4 = (_e = config.firstIpv4) != null ? _e : false;
|
|
75
48
|
let formData = {};
|
|
76
49
|
if (data && typeof data === "string") {
|
|
77
50
|
try {
|
|
@@ -97,7 +70,7 @@ var resolveUniAppRequestOptions = (config, options) => {
|
|
|
97
70
|
};
|
|
98
71
|
var progressEventReducer = (listener, isDownloadStream) => {
|
|
99
72
|
let bytesNotified = 0;
|
|
100
|
-
const _speedometer = (
|
|
73
|
+
const _speedometer = speedometer(50, 250);
|
|
101
74
|
return (result) => {
|
|
102
75
|
const loaded = result.totalBytesWritten;
|
|
103
76
|
const total = result.totalBytesExpectedToWrite;
|
|
@@ -118,13 +91,6 @@ var progressEventReducer = (listener, isDownloadStream) => {
|
|
|
118
91
|
listener(data);
|
|
119
92
|
};
|
|
120
93
|
};
|
|
121
|
-
|
|
122
|
-
// src/methods/download.ts
|
|
123
|
-
var import_axios2 = require("axios");
|
|
124
|
-
var import_settle = __toESM(require("axios/lib/core/settle"), 1);
|
|
125
|
-
|
|
126
|
-
// src/methods/onCanceled.ts
|
|
127
|
-
var import_axios = require("axios");
|
|
128
94
|
var OnCanceled = class {
|
|
129
95
|
constructor(config) {
|
|
130
96
|
this.config = config;
|
|
@@ -136,7 +102,7 @@ var OnCanceled = class {
|
|
|
136
102
|
return;
|
|
137
103
|
}
|
|
138
104
|
reject(
|
|
139
|
-
!cancel || cancel.type ? new
|
|
105
|
+
!cancel || cancel.type ? new axios.CanceledError(void 0, void 0, this.config, task) : cancel
|
|
140
106
|
);
|
|
141
107
|
task.abort();
|
|
142
108
|
task = null;
|
|
@@ -163,9 +129,7 @@ var OnCanceled = class {
|
|
|
163
129
|
var download = (config, options) => {
|
|
164
130
|
return new Promise((resolve, reject) => {
|
|
165
131
|
const { url, header, timeout, filePath } = resolveUniAppRequestOptions(
|
|
166
|
-
config
|
|
167
|
-
options
|
|
168
|
-
);
|
|
132
|
+
config);
|
|
169
133
|
const onCanceled = new OnCanceled(config);
|
|
170
134
|
let task = uni.downloadFile({
|
|
171
135
|
url,
|
|
@@ -173,6 +137,7 @@ var download = (config, options) => {
|
|
|
173
137
|
timeout,
|
|
174
138
|
filePath,
|
|
175
139
|
success(result) {
|
|
140
|
+
var _a;
|
|
176
141
|
if (!task) {
|
|
177
142
|
return;
|
|
178
143
|
}
|
|
@@ -181,27 +146,27 @@ var download = (config, options) => {
|
|
|
181
146
|
data: result.tempFilePath,
|
|
182
147
|
headers: {},
|
|
183
148
|
status: result.statusCode,
|
|
184
|
-
statusText: result.errMsg
|
|
149
|
+
statusText: (_a = result.errMsg) != null ? _a : "OK",
|
|
185
150
|
request: task
|
|
186
151
|
};
|
|
187
|
-
(
|
|
152
|
+
settle(resolve, reject, response);
|
|
188
153
|
task = null;
|
|
189
154
|
},
|
|
190
155
|
fail(error) {
|
|
191
|
-
const { errMsg = "" } = error
|
|
156
|
+
const { errMsg = "" } = error != null ? error : {};
|
|
192
157
|
if (errMsg) {
|
|
193
158
|
const isTimeoutError = errMsg === "downloadFile:fail timeout";
|
|
194
159
|
if (isTimeoutError) {
|
|
195
|
-
reject(new
|
|
160
|
+
reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, config, task));
|
|
196
161
|
}
|
|
197
162
|
const isNetworkError = errMsg === "downloadFile:fail";
|
|
198
163
|
if (isNetworkError) {
|
|
199
164
|
reject(
|
|
200
|
-
new
|
|
165
|
+
new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, config, task)
|
|
201
166
|
);
|
|
202
167
|
}
|
|
203
168
|
}
|
|
204
|
-
reject(new
|
|
169
|
+
reject(new axios.AxiosError(error.errMsg, void 0, config, task));
|
|
205
170
|
task = null;
|
|
206
171
|
},
|
|
207
172
|
complete() {
|
|
@@ -220,10 +185,6 @@ var download = (config, options) => {
|
|
|
220
185
|
});
|
|
221
186
|
};
|
|
222
187
|
var download_default = download;
|
|
223
|
-
|
|
224
|
-
// src/methods/upload.ts
|
|
225
|
-
var import_settle2 = __toESM(require("axios/lib/core/settle"), 1);
|
|
226
|
-
var import_axios3 = require("axios");
|
|
227
188
|
var upload = (config, options) => {
|
|
228
189
|
return new Promise((resolve, reject) => {
|
|
229
190
|
const {
|
|
@@ -236,7 +197,7 @@ var upload = (config, options) => {
|
|
|
236
197
|
header,
|
|
237
198
|
timeout,
|
|
238
199
|
formData
|
|
239
|
-
} = resolveUniAppRequestOptions(config
|
|
200
|
+
} = resolveUniAppRequestOptions(config);
|
|
240
201
|
const onCanceled = new OnCanceled(config);
|
|
241
202
|
let task = uni.uploadFile({
|
|
242
203
|
url,
|
|
@@ -249,6 +210,7 @@ var upload = (config, options) => {
|
|
|
249
210
|
timeout,
|
|
250
211
|
formData,
|
|
251
212
|
success(result) {
|
|
213
|
+
var _a;
|
|
252
214
|
if (!task) {
|
|
253
215
|
return;
|
|
254
216
|
}
|
|
@@ -257,27 +219,27 @@ var upload = (config, options) => {
|
|
|
257
219
|
data: result.data,
|
|
258
220
|
headers: {},
|
|
259
221
|
status: result.statusCode,
|
|
260
|
-
statusText: result.errMsg
|
|
222
|
+
statusText: (_a = result.errMsg) != null ? _a : "OK",
|
|
261
223
|
request: task
|
|
262
224
|
};
|
|
263
|
-
(
|
|
225
|
+
settle(resolve, reject, response);
|
|
264
226
|
task = null;
|
|
265
227
|
},
|
|
266
228
|
fail(error) {
|
|
267
|
-
const { errMsg = "" } = error
|
|
229
|
+
const { errMsg = "" } = error != null ? error : {};
|
|
268
230
|
if (errMsg) {
|
|
269
231
|
const isTimeoutError = errMsg === "uploadFile:fail timeout";
|
|
270
232
|
const isNetworkError = errMsg === "uploadFile:fail file error";
|
|
271
233
|
if (isTimeoutError) {
|
|
272
|
-
reject(new
|
|
234
|
+
reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, config, task));
|
|
273
235
|
}
|
|
274
236
|
if (isNetworkError) {
|
|
275
237
|
reject(
|
|
276
|
-
new
|
|
238
|
+
new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, config, task)
|
|
277
239
|
);
|
|
278
240
|
}
|
|
279
241
|
}
|
|
280
|
-
reject(new
|
|
242
|
+
reject(new axios.AxiosError(error.errMsg, void 0, config, task));
|
|
281
243
|
task = null;
|
|
282
244
|
},
|
|
283
245
|
complete() {
|
|
@@ -291,10 +253,6 @@ var upload = (config, options) => {
|
|
|
291
253
|
});
|
|
292
254
|
};
|
|
293
255
|
var upload_default = upload;
|
|
294
|
-
|
|
295
|
-
// src/methods/request.ts
|
|
296
|
-
var import_axios4 = require("axios");
|
|
297
|
-
var import_settle3 = __toESM(require("axios/lib/core/settle"), 1);
|
|
298
256
|
var request = (config, options) => {
|
|
299
257
|
return new Promise((resolve, reject) => {
|
|
300
258
|
const {
|
|
@@ -308,7 +266,7 @@ var request = (config, options) => {
|
|
|
308
266
|
sslVerify,
|
|
309
267
|
withCredentials,
|
|
310
268
|
firstIpv4
|
|
311
|
-
} = resolveUniAppRequestOptions(config
|
|
269
|
+
} = resolveUniAppRequestOptions(config);
|
|
312
270
|
const onCanceled = new OnCanceled(config);
|
|
313
271
|
let task = uni.request({
|
|
314
272
|
url,
|
|
@@ -322,6 +280,7 @@ var request = (config, options) => {
|
|
|
322
280
|
withCredentials,
|
|
323
281
|
firstIpv4,
|
|
324
282
|
success(result) {
|
|
283
|
+
var _a;
|
|
325
284
|
if (!task) {
|
|
326
285
|
return;
|
|
327
286
|
}
|
|
@@ -330,28 +289,28 @@ var request = (config, options) => {
|
|
|
330
289
|
data: result.data,
|
|
331
290
|
headers: result.header,
|
|
332
291
|
status: result.statusCode,
|
|
333
|
-
statusText: result.errMsg
|
|
292
|
+
statusText: (_a = result.errMsg) != null ? _a : "OK",
|
|
334
293
|
request: task,
|
|
335
294
|
cookies: result.cookies
|
|
336
295
|
};
|
|
337
|
-
(
|
|
296
|
+
settle(resolve, reject, response);
|
|
338
297
|
task = null;
|
|
339
298
|
},
|
|
340
299
|
fail(error) {
|
|
341
|
-
const { errMsg = "" } = error
|
|
300
|
+
const { errMsg = "" } = error != null ? error : {};
|
|
342
301
|
if (errMsg) {
|
|
343
302
|
const isTimeoutError = errMsg === "request:fail timeout";
|
|
344
303
|
const isNetworkError = errMsg === "request:fail";
|
|
345
304
|
if (isTimeoutError) {
|
|
346
|
-
reject(new
|
|
305
|
+
reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, config, task));
|
|
347
306
|
}
|
|
348
307
|
if (isNetworkError) {
|
|
349
308
|
reject(
|
|
350
|
-
new
|
|
309
|
+
new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, config, task)
|
|
351
310
|
);
|
|
352
311
|
}
|
|
353
312
|
}
|
|
354
|
-
reject(new
|
|
313
|
+
reject(new axios.AxiosError(error.errMsg, void 0, config, task));
|
|
355
314
|
task = null;
|
|
356
315
|
},
|
|
357
316
|
complete() {
|
|
@@ -388,8 +347,7 @@ var createUniAppAxiosAdapter = (userOptions = {}) => {
|
|
|
388
347
|
};
|
|
389
348
|
return uniappAdapter;
|
|
390
349
|
};
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
});
|
|
350
|
+
|
|
351
|
+
exports.createUniAppAxiosAdapter = createUniAppAxiosAdapter;
|
|
352
|
+
//# sourceMappingURL=out.js.map
|
|
395
353
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/methods/download.ts","../src/methods/onCanceled.ts","../src/methods/upload.ts","../src/methods/request.ts","../src/methods/index.ts"],"sourcesContent":["import { AxiosAdapter, AxiosRequestConfig } from \"axios\";\nimport { getMethod } from \"./methods\";\nimport { UserOptions } from \"./types\";\nimport { resolveOptions } from \"./utils\";\n\nexport const createUniAppAxiosAdapter = (\n userOptions: UserOptions = {}\n): AxiosAdapter => {\n const options = resolveOptions(userOptions);\n const uniappAdapter: AxiosAdapter = (config: AxiosRequestConfig) => {\n const method = getMethod(config);\n return method(config, options);\n };\n return uniappAdapter;\n};\n","// @ts-ignore\nimport utils from \"axios/lib/utils.js\";\n// @ts-ignore\nimport buildURL from \"axios/lib/helpers/buildURL.js\";\n// @ts-ignore\nimport buildFullPath from \"axios/lib/core/buildFullPath.js\";\n// @ts-ignore\nimport speedometer from \"axios/lib/helpers/speedometer.js\";\n\nimport {\n ResolvedOptions,\n MethodType,\n UserOptions,\n UniNetworkRequestWithoutCallback,\n} from \"./types\";\nimport axios, {\n AxiosRequestConfig,\n AxiosHeaders as AxiosHeadersType,\n} from \"axios\";\n\nexport const getMethodType = <T>(config: AxiosRequestConfig<T>): MethodType => {\n const { method: rawMethod = \"GET\" } = config;\n const method = rawMethod.toLocaleLowerCase();\n switch (method) {\n case \"download\":\n return \"download\";\n case \"upload\":\n return \"upload\";\n default:\n return \"request\";\n }\n};\n\nexport const resolveOptions = (userOptions: UserOptions): ResolvedOptions => {\n return {\n ...userOptions,\n };\n};\n\nexport const resolveUniAppRequestOptions = (\n config: AxiosRequestConfig,\n options: ResolvedOptions\n): UniNetworkRequestWithoutCallback => {\n const data = config.data;\n const responseType =\n config.responseType === \"arraybuffer\" ? \"arraybuffer\" : \"text\";\n const dataType = responseType === \"text\" ? \"json\" : undefined;\n // @ts-ignore\n const requestHeaders: AxiosHeadersType = config.headers;\n\n if (config.auth) {\n const username = config.auth.username || \"\";\n const password = config.auth.password\n ? unescape(encodeURIComponent(config.auth.password))\n : \"\";\n requestHeaders.set(\n \"Authorization\",\n \"Basic \" + btoa(username + \":\" + password)\n );\n }\n\n const fullPath = buildFullPath(config.baseURL, config.url);\n const method = (config?.method?.toUpperCase() ?? \"GET\") as unknown as any;\n const url = buildURL(fullPath, config.params, config.paramsSerializer);\n\n // set uni-app default value\n // request\n const timeout = config.timeout || 60000;\n const withCredentials = config.withCredentials ?? false;\n const sslVerify = config.sslVerify ?? true;\n const firstIpv4 = config.firstIpv4 ?? false;\n // upload\n let formData = {};\n if (data && typeof data === \"string\") {\n try {\n formData = JSON.parse(data);\n } catch (error) {}\n }\n\n const header = requestHeaders.toJSON();\n\n return {\n ...config,\n url,\n data,\n header,\n method,\n responseType,\n dataType,\n timeout,\n withCredentials,\n sslVerify,\n firstIpv4,\n formData,\n };\n};\n\nexport const progressEventReducer = (\n listener: any,\n isDownloadStream: boolean\n) => {\n let bytesNotified = 0;\n const _speedometer = speedometer(50, 250);\n\n return (result: UniApp.OnProgressDownloadResult) => {\n const loaded = result.totalBytesWritten;\n const total = result.totalBytesExpectedToWrite;\n const progressBytes = loaded - bytesNotified;\n const rate = _speedometer(progressBytes);\n const inRange = loaded <= total;\n\n bytesNotified = loaded;\n\n const data: any = {\n loaded,\n total,\n progress: total ? loaded / total : undefined,\n bytes: progressBytes,\n rate: rate ? rate : undefined,\n estimated: rate && total && inRange ? (total - loaded) / rate : undefined,\n event: result,\n };\n data[isDownloadStream ? \"download\" : \"upload\"] = true;\n listener(data);\n };\n};\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { progressEventReducer, resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle\";\nimport OnCanceled from \"./onCanceled\";\n\nconst download: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const { url, header, timeout, filePath } = resolveUniAppRequestOptions(\n config,\n options\n );\n const onCanceled = new OnCanceled(config);\n let task: UniApp.DownloadTask | null = uni.downloadFile({\n url,\n header,\n timeout,\n // @ts-ignore\n filePath,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.tempFilePath,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"downloadFile:fail timeout\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n const isNetworkError = errMsg === \"downloadFile:fail\";\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onDownloadProgress === \"function\") {\n task.onProgressUpdate(\n progressEventReducer(config.onDownloadProgress, true)\n );\n }\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default download;\n","import { AxiosRequestConfig, CanceledError } from \"axios\";\n\nexport default class OnCanceled<T> {\n config: AxiosRequestConfig<T>;\n private onCanceled?: (cancel?: any) => void;\n constructor(config: AxiosRequestConfig<T>) {\n this.config = config;\n }\n\n subscribe(task: any, reject: any) {\n if (this.config.cancelToken || this.config.signal) {\n this.onCanceled = (cancel?: any) => {\n if (!task) {\n return;\n }\n reject(\n !cancel || cancel.type\n ? new CanceledError(undefined, undefined, this.config, task)\n : cancel\n );\n task.abort();\n task = null;\n };\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.subscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.addEventListener) {\n this.config.signal.aborted\n ? this.onCanceled()\n : this.config.signal.addEventListener(\"abort\", this.onCanceled);\n }\n }\n }\n\n unsubscribe() {\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.unsubscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.removeEventListener) {\n this.config.signal.removeEventListener(\"abort\", this.onCanceled);\n }\n }\n}\n","import { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\nimport OnCanceled from \"./onCanceled\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle\";\nimport { AxiosError, AxiosResponse } from \"axios\";\n\nconst upload: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n\n let task: UniApp.UploadTask | null = uni.uploadFile({\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"uploadFile:fail timeout\";\n const isNetworkError = errMsg === \"uploadFile:fail file error\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default upload;\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle\";\nimport OnCanceled from \"./onCanceled\";\n\nconst request: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n let task: UniApp.RequestTask | null = uni.request({\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: result.header,\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n cookies: result.cookies,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"request:fail timeout\";\n const isNetworkError = errMsg === \"request:fail\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default request;\n","import { AxiosRequestConfig } from \"axios\";\nimport { Method } from \"../types\";\nimport { getMethodType } from \"../utils\";\nimport download from \"./download\";\nimport upload from \"./upload\";\nimport request from \"./request\";\n\nexport const getMethod = (config: AxiosRequestConfig): Method => {\n const methodType = getMethodType(config);\n switch (methodType) {\n case \"download\":\n return download;\n case \"upload\":\n return upload;\n default:\n return request;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,sBAAqB;AAErB,2BAA0B;AAE1B,yBAAwB;AAajB,IAAM,gBAAgB,CAAI,WAA8C;AAC7E,QAAM,EAAE,QAAQ,YAAY,MAAM,IAAI;AACtC,QAAM,SAAS,UAAU,kBAAkB;AAC3C,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,IAAM,iBAAiB,CAAC,gBAA8C;AAC3E,SAAO;AAAA,IACL,GAAG;AAAA,EACL;AACF;AAEO,IAAM,8BAA8B,CACzC,QACA,YACqC;AA1CvC;AA2CE,QAAM,OAAO,OAAO;AACpB,QAAM,eACJ,OAAO,iBAAiB,gBAAgB,gBAAgB;AAC1D,QAAM,WAAW,iBAAiB,SAAS,SAAS;AAEpD,QAAM,iBAAmC,OAAO;AAEhD,MAAI,OAAO,MAAM;AACf,UAAM,WAAW,OAAO,K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AAa,QAAQ,IAAI;AAAA,YAC7D;AAAA,UACF;AAAA,QACF;AACA,eAAO,IAAI,yBAAW,MAAM,QAAQ,QAAW,QAAQ,IAAI,CAAC;AAC5D,eAAO;AAAA,MACT;AAAA,MACA,WAAW;AACT,mBAAW,YAAY;AAAA,MACzB;AAAA,IACF,CAAC;AAED,QAAI,OAAO,OAAO,sBAAsB,YAAY;AAClD,WAAK,kBAAkB,OAAO,iBAAiB;AAAA,IACjD;AAEA,eAAW,UAAU,MAAM,MAAM;AAAA,EACnC,CAAC;AACH;AAEA,IAAO,kBAAQ;;;ACzER,IAAM,YAAY,CAAC,WAAuC;AAC/D,QAAM,aAAa,cAAc,MAAM;AACvC,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;;;ANZO,IAAM,2BAA2B,CACtC,cAA2B,CAAC,MACX;AACjB,QAAM,UAAU,eAAe,WAAW;AAC1C,QAAM,gBAA8B,CAAC,WAA+B;AAClE,UAAM,SAAS,UAAU,MAAM;AAC/B,WAAO,OAAO,QAAQ,OAAO;AAAA,EAC/B;AACA,SAAO;AACT;","names":["buildFullPath","buildURL","speedometer","import_axios","settle","import_settle","import_axios","settle","import_axios","import_settle","settle"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/methods/download.ts","../src/methods/onCanceled.ts","../src/methods/upload.ts","../src/methods/request.ts","../src/methods/index.ts","../src/index.ts"],"names":["settle","AxiosError"],"mappings":";AACA,OAAO,cAAc;AAErB,OAAO,mBAAmB;AAE1B,OAAO,iBAAiB;AAajB,IAAM,gBAAgB,CAAI,WAA8C;AAC7E,QAAM,EAAE,QAAQ,YAAY,MAAM,IAAI;AACtC,QAAM,SAAS,UAAU,kBAAkB;AAC3C,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAC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;AAAA,QAClB;AACA,QAAAA,QAAO,SAAS,QAAQ,QAAQ;AAChC,eAAO;AAAA,MACT;AAAA,MACA,KAAK,OAAO;AACV,cAAM,EAAE,SAAS,GAAG,IAAI,wBAAS,CAAC;AAClC,YAAI,QAAQ;AACV,gBAAM,iBAAiB,WAAW;AAClC,gBAAM,iBAAiB,WAAW;AAClC,cAAI,gBAAgB;AAClB,mBAAO,IAAIC,YAAW,QAAQA,YAAW,WAAW,QAAQ,IAAI,CAAC;AAAA,UACnE;AACA,cAAI,gBAAgB;AAClB;AAAA,cACE,IAAIA,YAAW,QAAQA,YAAW,aAAa,QAAQ,IAAI;AAAA,YAC7D;AAAA,UACF;AAAA,QACF;AACA,eAAO,IAAIA,YAAW,MAAM,QAAQ,QAAW,QAAQ,IAAI,CAAC;AAC5D,eAAO;AAAA,MACT;AAAA,MACA,WAAW;AACT,mBAAW,YAAY;AAAA,MACzB;AAAA,IACF,CAAC;AAED,QAAI,OAAO,OAAO,sBAAsB,YAAY;AAClD,WAAK,kBAAkB,OAAO,iBAAiB;AAAA,IACjD;AAEA,eAAW,UAAU,MAAM,MAAM;AAAA,EACnC,CAAC;AACH;AAEA,IAAO,kBAAQ;;;ACzER,IAAM,YAAY,CAAC,WAAuC;AAC/D,QAAM,aAAa,cAAc,MAAM;AACvC,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;;;ACZO,IAAM,2BAA2B,CACtC,cAA2B,CAAC,MACX;AACjB,QAAM,UAAU,eAAe,WAAW;AAC1C,QAAM,gBAA8B,CAAC,WAA+B;AAClE,UAAM,SAAS,UAAU,MAAM;AAC/B,WAAO,OAAO,QAAQ,OAAO;AAAA,EAC/B;AACA,SAAO;AACT","sourcesContent":["// @ts-ignore\nimport buildURL from \"axios/lib/helpers/buildURL.js\";\n// @ts-ignore\nimport buildFullPath from \"axios/lib/core/buildFullPath.js\";\n// @ts-ignore\nimport speedometer from \"axios/lib/helpers/speedometer.js\";\n\nimport {\n ResolvedOptions,\n MethodType,\n UserOptions,\n UniNetworkRequestWithoutCallback,\n} from \"./types\";\nimport axios, {\n AxiosRequestConfig,\n AxiosHeaders as AxiosHeadersType,\n} from \"axios\";\n\nexport const getMethodType = <T>(config: AxiosRequestConfig<T>): MethodType => {\n const { method: rawMethod = \"GET\" } = config;\n const method = rawMethod.toLocaleLowerCase();\n switch (method) {\n case \"download\":\n return \"download\";\n case \"upload\":\n return \"upload\";\n default:\n return \"request\";\n }\n};\n\nexport const resolveOptions = (userOptions: UserOptions): ResolvedOptions => {\n return {\n ...userOptions,\n };\n};\n\nexport const resolveUniAppRequestOptions = (\n config: AxiosRequestConfig,\n options: ResolvedOptions\n): UniNetworkRequestWithoutCallback => {\n const data = config.data;\n const responseType =\n config.responseType === \"arraybuffer\" ? \"arraybuffer\" : \"text\";\n const dataType = responseType === \"text\" ? \"json\" : undefined;\n // @ts-ignore\n const requestHeaders: AxiosHeadersType = config.headers;\n\n if (config.auth) {\n const username = config.auth.username || \"\";\n const password = config.auth.password\n ? unescape(encodeURIComponent(config.auth.password))\n : \"\";\n requestHeaders.set(\n \"Authorization\",\n \"Basic \" + btoa(username + \":\" + password)\n );\n }\n\n const fullPath = buildFullPath(config.baseURL, config.url);\n const method = (config?.method?.toUpperCase() ?? \"GET\") as unknown as any;\n const url = buildURL(fullPath, config.params, config.paramsSerializer);\n\n // set uni-app default value\n // request\n const timeout = config.timeout || 60000;\n const withCredentials = config.withCredentials ?? false;\n const sslVerify = config.sslVerify ?? true;\n const firstIpv4 = config.firstIpv4 ?? false;\n // upload\n let formData = {};\n if (data && typeof data === \"string\") {\n try {\n formData = JSON.parse(data);\n } catch (error) {}\n }\n\n const header = requestHeaders.toJSON();\n\n return {\n ...config,\n url,\n data,\n header,\n method,\n responseType,\n dataType,\n timeout,\n withCredentials,\n sslVerify,\n firstIpv4,\n formData,\n };\n};\n\nexport const progressEventReducer = (\n listener: any,\n isDownloadStream: boolean\n) => {\n let bytesNotified = 0;\n const _speedometer = speedometer(50, 250);\n\n return (result: UniApp.OnProgressDownloadResult) => {\n const loaded = result.totalBytesWritten;\n const total = result.totalBytesExpectedToWrite;\n const progressBytes = loaded - bytesNotified;\n const rate = _speedometer(progressBytes);\n const inRange = loaded <= total;\n\n bytesNotified = loaded;\n\n const data: any = {\n loaded,\n total,\n progress: total ? loaded / total : undefined,\n bytes: progressBytes,\n rate: rate ? rate : undefined,\n estimated: rate && total && inRange ? (total - loaded) / rate : undefined,\n event: result,\n };\n data[isDownloadStream ? \"download\" : \"upload\"] = true;\n listener(data);\n };\n};\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { progressEventReducer, resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle.js\";\nimport OnCanceled from \"./onCanceled\";\n\nconst download: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const { url, header, timeout, filePath } = resolveUniAppRequestOptions(\n config,\n options\n );\n const onCanceled = new OnCanceled(config);\n let task: UniApp.DownloadTask | null = uni.downloadFile({\n url,\n header,\n timeout,\n // @ts-ignore\n filePath,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.tempFilePath,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"downloadFile:fail timeout\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n const isNetworkError = errMsg === \"downloadFile:fail\";\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onDownloadProgress === \"function\") {\n task.onProgressUpdate(\n progressEventReducer(config.onDownloadProgress, true)\n );\n }\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default download;\n","import { AxiosRequestConfig, CanceledError } from \"axios\";\n\nexport default class OnCanceled<T> {\n config: AxiosRequestConfig<T>;\n private onCanceled?: (cancel?: any) => void;\n constructor(config: AxiosRequestConfig<T>) {\n this.config = config;\n }\n\n subscribe(task: any, reject: any) {\n if (this.config.cancelToken || this.config.signal) {\n this.onCanceled = (cancel?: any) => {\n if (!task) {\n return;\n }\n reject(\n !cancel || cancel.type\n ? new CanceledError(undefined, undefined, this.config, task)\n : cancel\n );\n task.abort();\n task = null;\n };\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.subscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.addEventListener) {\n this.config.signal.aborted\n ? this.onCanceled()\n : this.config.signal.addEventListener(\"abort\", this.onCanceled);\n }\n }\n }\n\n unsubscribe() {\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.unsubscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.removeEventListener) {\n this.config.signal.removeEventListener(\"abort\", this.onCanceled);\n }\n }\n}\n","import { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\nimport OnCanceled from \"./onCanceled\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle.js\";\nimport { AxiosError, AxiosResponse } from \"axios\";\n\nconst upload: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n\n let task: UniApp.UploadTask | null = uni.uploadFile({\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"uploadFile:fail timeout\";\n const isNetworkError = errMsg === \"uploadFile:fail file error\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default upload;\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle.js\";\nimport OnCanceled from \"./onCanceled\";\n\nconst request: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n let task: UniApp.RequestTask | null = uni.request({\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: result.header,\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n cookies: result.cookies,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"request:fail timeout\";\n const isNetworkError = errMsg === \"request:fail\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default request;\n","import { AxiosRequestConfig } from \"axios\";\nimport { Method } from \"../types\";\nimport { getMethodType } from \"../utils\";\nimport download from \"./download\";\nimport upload from \"./upload\";\nimport request from \"./request\";\n\nexport const getMethod = (config: AxiosRequestConfig): Method => {\n const methodType = getMethodType(config);\n switch (methodType) {\n case \"download\":\n return download;\n case \"upload\":\n return upload;\n default:\n return request;\n }\n};\n","import type { AxiosAdapter, AxiosRequestConfig } from \"axios\";\nimport { getMethod } from \"./methods\";\nimport { UserOptions } from \"./types\";\nimport { resolveOptions } from \"./utils\";\n\nexport const createUniAppAxiosAdapter = (\n userOptions: UserOptions = {}\n): AxiosAdapter => {\n const options = resolveOptions(userOptions);\n const uniappAdapter: AxiosAdapter = (config: AxiosRequestConfig) => {\n const method = getMethod(config);\n return method(config, options);\n };\n return uniappAdapter;\n};\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import buildURL from 'axios/lib/helpers/buildURL.js';
|
|
2
|
+
import buildFullPath from 'axios/lib/core/buildFullPath.js';
|
|
3
|
+
import speedometer from 'axios/lib/helpers/speedometer.js';
|
|
4
|
+
import { AxiosError, CanceledError } from 'axios';
|
|
5
|
+
import settle from 'axios/lib/core/settle.js';
|
|
6
|
+
|
|
1
7
|
// src/utils.ts
|
|
2
|
-
import buildURL from "axios/lib/helpers/buildURL.js";
|
|
3
|
-
import buildFullPath from "axios/lib/core/buildFullPath.js";
|
|
4
|
-
import speedometer from "axios/lib/helpers/speedometer.js";
|
|
5
8
|
var getMethodType = (config) => {
|
|
6
9
|
const { method: rawMethod = "GET" } = config;
|
|
7
10
|
const method = rawMethod.toLocaleLowerCase();
|
|
@@ -20,7 +23,7 @@ var resolveOptions = (userOptions) => {
|
|
|
20
23
|
};
|
|
21
24
|
};
|
|
22
25
|
var resolveUniAppRequestOptions = (config, options) => {
|
|
23
|
-
var _a;
|
|
26
|
+
var _a, _b, _c, _d, _e;
|
|
24
27
|
const data = config.data;
|
|
25
28
|
const responseType = config.responseType === "arraybuffer" ? "arraybuffer" : "text";
|
|
26
29
|
const dataType = responseType === "text" ? "json" : void 0;
|
|
@@ -34,12 +37,12 @@ var resolveUniAppRequestOptions = (config, options) => {
|
|
|
34
37
|
);
|
|
35
38
|
}
|
|
36
39
|
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
37
|
-
const method = ((_a = config == null ? void 0 : config.method) == null ? void 0 : _a.toUpperCase())
|
|
40
|
+
const method = (_b = (_a = config == null ? void 0 : config.method) == null ? void 0 : _a.toUpperCase()) != null ? _b : "GET";
|
|
38
41
|
const url = buildURL(fullPath, config.params, config.paramsSerializer);
|
|
39
42
|
const timeout = config.timeout || 6e4;
|
|
40
|
-
const withCredentials = config.withCredentials
|
|
41
|
-
const sslVerify = config.sslVerify
|
|
42
|
-
const firstIpv4 = config.firstIpv4
|
|
43
|
+
const withCredentials = (_c = config.withCredentials) != null ? _c : false;
|
|
44
|
+
const sslVerify = (_d = config.sslVerify) != null ? _d : true;
|
|
45
|
+
const firstIpv4 = (_e = config.firstIpv4) != null ? _e : false;
|
|
43
46
|
let formData = {};
|
|
44
47
|
if (data && typeof data === "string") {
|
|
45
48
|
try {
|
|
@@ -86,13 +89,6 @@ var progressEventReducer = (listener, isDownloadStream) => {
|
|
|
86
89
|
listener(data);
|
|
87
90
|
};
|
|
88
91
|
};
|
|
89
|
-
|
|
90
|
-
// src/methods/download.ts
|
|
91
|
-
import { AxiosError } from "axios";
|
|
92
|
-
import settle from "axios/lib/core/settle";
|
|
93
|
-
|
|
94
|
-
// src/methods/onCanceled.ts
|
|
95
|
-
import { CanceledError } from "axios";
|
|
96
92
|
var OnCanceled = class {
|
|
97
93
|
constructor(config) {
|
|
98
94
|
this.config = config;
|
|
@@ -131,9 +127,7 @@ var OnCanceled = class {
|
|
|
131
127
|
var download = (config, options) => {
|
|
132
128
|
return new Promise((resolve, reject) => {
|
|
133
129
|
const { url, header, timeout, filePath } = resolveUniAppRequestOptions(
|
|
134
|
-
config
|
|
135
|
-
options
|
|
136
|
-
);
|
|
130
|
+
config);
|
|
137
131
|
const onCanceled = new OnCanceled(config);
|
|
138
132
|
let task = uni.downloadFile({
|
|
139
133
|
url,
|
|
@@ -141,6 +135,7 @@ var download = (config, options) => {
|
|
|
141
135
|
timeout,
|
|
142
136
|
filePath,
|
|
143
137
|
success(result) {
|
|
138
|
+
var _a;
|
|
144
139
|
if (!task) {
|
|
145
140
|
return;
|
|
146
141
|
}
|
|
@@ -149,14 +144,14 @@ var download = (config, options) => {
|
|
|
149
144
|
data: result.tempFilePath,
|
|
150
145
|
headers: {},
|
|
151
146
|
status: result.statusCode,
|
|
152
|
-
statusText: result.errMsg
|
|
147
|
+
statusText: (_a = result.errMsg) != null ? _a : "OK",
|
|
153
148
|
request: task
|
|
154
149
|
};
|
|
155
150
|
settle(resolve, reject, response);
|
|
156
151
|
task = null;
|
|
157
152
|
},
|
|
158
153
|
fail(error) {
|
|
159
|
-
const { errMsg = "" } = error
|
|
154
|
+
const { errMsg = "" } = error != null ? error : {};
|
|
160
155
|
if (errMsg) {
|
|
161
156
|
const isTimeoutError = errMsg === "downloadFile:fail timeout";
|
|
162
157
|
if (isTimeoutError) {
|
|
@@ -188,10 +183,6 @@ var download = (config, options) => {
|
|
|
188
183
|
});
|
|
189
184
|
};
|
|
190
185
|
var download_default = download;
|
|
191
|
-
|
|
192
|
-
// src/methods/upload.ts
|
|
193
|
-
import settle2 from "axios/lib/core/settle";
|
|
194
|
-
import { AxiosError as AxiosError2 } from "axios";
|
|
195
186
|
var upload = (config, options) => {
|
|
196
187
|
return new Promise((resolve, reject) => {
|
|
197
188
|
const {
|
|
@@ -204,7 +195,7 @@ var upload = (config, options) => {
|
|
|
204
195
|
header,
|
|
205
196
|
timeout,
|
|
206
197
|
formData
|
|
207
|
-
} = resolveUniAppRequestOptions(config
|
|
198
|
+
} = resolveUniAppRequestOptions(config);
|
|
208
199
|
const onCanceled = new OnCanceled(config);
|
|
209
200
|
let task = uni.uploadFile({
|
|
210
201
|
url,
|
|
@@ -217,6 +208,7 @@ var upload = (config, options) => {
|
|
|
217
208
|
timeout,
|
|
218
209
|
formData,
|
|
219
210
|
success(result) {
|
|
211
|
+
var _a;
|
|
220
212
|
if (!task) {
|
|
221
213
|
return;
|
|
222
214
|
}
|
|
@@ -225,27 +217,27 @@ var upload = (config, options) => {
|
|
|
225
217
|
data: result.data,
|
|
226
218
|
headers: {},
|
|
227
219
|
status: result.statusCode,
|
|
228
|
-
statusText: result.errMsg
|
|
220
|
+
statusText: (_a = result.errMsg) != null ? _a : "OK",
|
|
229
221
|
request: task
|
|
230
222
|
};
|
|
231
|
-
|
|
223
|
+
settle(resolve, reject, response);
|
|
232
224
|
task = null;
|
|
233
225
|
},
|
|
234
226
|
fail(error) {
|
|
235
|
-
const { errMsg = "" } = error
|
|
227
|
+
const { errMsg = "" } = error != null ? error : {};
|
|
236
228
|
if (errMsg) {
|
|
237
229
|
const isTimeoutError = errMsg === "uploadFile:fail timeout";
|
|
238
230
|
const isNetworkError = errMsg === "uploadFile:fail file error";
|
|
239
231
|
if (isTimeoutError) {
|
|
240
|
-
reject(new
|
|
232
|
+
reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));
|
|
241
233
|
}
|
|
242
234
|
if (isNetworkError) {
|
|
243
235
|
reject(
|
|
244
|
-
new
|
|
236
|
+
new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)
|
|
245
237
|
);
|
|
246
238
|
}
|
|
247
239
|
}
|
|
248
|
-
reject(new
|
|
240
|
+
reject(new AxiosError(error.errMsg, void 0, config, task));
|
|
249
241
|
task = null;
|
|
250
242
|
},
|
|
251
243
|
complete() {
|
|
@@ -259,10 +251,6 @@ var upload = (config, options) => {
|
|
|
259
251
|
});
|
|
260
252
|
};
|
|
261
253
|
var upload_default = upload;
|
|
262
|
-
|
|
263
|
-
// src/methods/request.ts
|
|
264
|
-
import { AxiosError as AxiosError3 } from "axios";
|
|
265
|
-
import settle3 from "axios/lib/core/settle";
|
|
266
254
|
var request = (config, options) => {
|
|
267
255
|
return new Promise((resolve, reject) => {
|
|
268
256
|
const {
|
|
@@ -276,7 +264,7 @@ var request = (config, options) => {
|
|
|
276
264
|
sslVerify,
|
|
277
265
|
withCredentials,
|
|
278
266
|
firstIpv4
|
|
279
|
-
} = resolveUniAppRequestOptions(config
|
|
267
|
+
} = resolveUniAppRequestOptions(config);
|
|
280
268
|
const onCanceled = new OnCanceled(config);
|
|
281
269
|
let task = uni.request({
|
|
282
270
|
url,
|
|
@@ -290,6 +278,7 @@ var request = (config, options) => {
|
|
|
290
278
|
withCredentials,
|
|
291
279
|
firstIpv4,
|
|
292
280
|
success(result) {
|
|
281
|
+
var _a;
|
|
293
282
|
if (!task) {
|
|
294
283
|
return;
|
|
295
284
|
}
|
|
@@ -298,28 +287,28 @@ var request = (config, options) => {
|
|
|
298
287
|
data: result.data,
|
|
299
288
|
headers: result.header,
|
|
300
289
|
status: result.statusCode,
|
|
301
|
-
statusText: result.errMsg
|
|
290
|
+
statusText: (_a = result.errMsg) != null ? _a : "OK",
|
|
302
291
|
request: task,
|
|
303
292
|
cookies: result.cookies
|
|
304
293
|
};
|
|
305
|
-
|
|
294
|
+
settle(resolve, reject, response);
|
|
306
295
|
task = null;
|
|
307
296
|
},
|
|
308
297
|
fail(error) {
|
|
309
|
-
const { errMsg = "" } = error
|
|
298
|
+
const { errMsg = "" } = error != null ? error : {};
|
|
310
299
|
if (errMsg) {
|
|
311
300
|
const isTimeoutError = errMsg === "request:fail timeout";
|
|
312
301
|
const isNetworkError = errMsg === "request:fail";
|
|
313
302
|
if (isTimeoutError) {
|
|
314
|
-
reject(new
|
|
303
|
+
reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));
|
|
315
304
|
}
|
|
316
305
|
if (isNetworkError) {
|
|
317
306
|
reject(
|
|
318
|
-
new
|
|
307
|
+
new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)
|
|
319
308
|
);
|
|
320
309
|
}
|
|
321
310
|
}
|
|
322
|
-
reject(new
|
|
311
|
+
reject(new AxiosError(error.errMsg, void 0, config, task));
|
|
323
312
|
task = null;
|
|
324
313
|
},
|
|
325
314
|
complete() {
|
|
@@ -356,7 +345,7 @@ var createUniAppAxiosAdapter = (userOptions = {}) => {
|
|
|
356
345
|
};
|
|
357
346
|
return uniappAdapter;
|
|
358
347
|
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
348
|
+
|
|
349
|
+
export { createUniAppAxiosAdapter };
|
|
350
|
+
//# sourceMappingURL=out.js.map
|
|
362
351
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/methods/download.ts","../src/methods/onCanceled.ts","../src/methods/upload.ts","../src/methods/request.ts","../src/methods/index.ts","../src/index.ts"],"sourcesContent":["// @ts-ignore\nimport utils from \"axios/lib/utils.js\";\n// @ts-ignore\nimport buildURL from \"axios/lib/helpers/buildURL.js\";\n// @ts-ignore\nimport buildFullPath from \"axios/lib/core/buildFullPath.js\";\n// @ts-ignore\nimport speedometer from \"axios/lib/helpers/speedometer.js\";\n\nimport {\n ResolvedOptions,\n MethodType,\n UserOptions,\n UniNetworkRequestWithoutCallback,\n} from \"./types\";\nimport axios, {\n AxiosRequestConfig,\n AxiosHeaders as AxiosHeadersType,\n} from \"axios\";\n\nexport const getMethodType = <T>(config: AxiosRequestConfig<T>): MethodType => {\n const { method: rawMethod = \"GET\" } = config;\n const method = rawMethod.toLocaleLowerCase();\n switch (method) {\n case \"download\":\n return \"download\";\n case \"upload\":\n return \"upload\";\n default:\n return \"request\";\n }\n};\n\nexport const resolveOptions = (userOptions: UserOptions): ResolvedOptions => {\n return {\n ...userOptions,\n };\n};\n\nexport const resolveUniAppRequestOptions = (\n config: AxiosRequestConfig,\n options: ResolvedOptions\n): UniNetworkRequestWithoutCallback => {\n const data = config.data;\n const responseType =\n config.responseType === \"arraybuffer\" ? \"arraybuffer\" : \"text\";\n const dataType = responseType === \"text\" ? \"json\" : undefined;\n // @ts-ignore\n const requestHeaders: AxiosHeadersType = config.headers;\n\n if (config.auth) {\n const username = config.auth.username || \"\";\n const password = config.auth.password\n ? unescape(encodeURIComponent(config.auth.password))\n : \"\";\n requestHeaders.set(\n \"Authorization\",\n \"Basic \" + btoa(username + \":\" + password)\n );\n }\n\n const fullPath = buildFullPath(config.baseURL, config.url);\n const method = (config?.method?.toUpperCase() ?? \"GET\") as unknown as any;\n const url = buildURL(fullPath, config.params, config.paramsSerializer);\n\n // set uni-app default value\n // request\n const timeout = config.timeout || 60000;\n const withCredentials = config.withCredentials ?? false;\n const sslVerify = config.sslVerify ?? true;\n const firstIpv4 = config.firstIpv4 ?? false;\n // upload\n let formData = {};\n if (data && typeof data === \"string\") {\n try {\n formData = JSON.parse(data);\n } catch (error) {}\n }\n\n const header = requestHeaders.toJSON();\n\n return {\n ...config,\n url,\n data,\n header,\n method,\n responseType,\n dataType,\n timeout,\n withCredentials,\n sslVerify,\n firstIpv4,\n formData,\n };\n};\n\nexport const progressEventReducer = (\n listener: any,\n isDownloadStream: boolean\n) => {\n let bytesNotified = 0;\n const _speedometer = speedometer(50, 250);\n\n return (result: UniApp.OnProgressDownloadResult) => {\n const loaded = result.totalBytesWritten;\n const total = result.totalBytesExpectedToWrite;\n const progressBytes = loaded - bytesNotified;\n const rate = _speedometer(progressBytes);\n const inRange = loaded <= total;\n\n bytesNotified = loaded;\n\n const data: any = {\n loaded,\n total,\n progress: total ? loaded / total : undefined,\n bytes: progressBytes,\n rate: rate ? rate : undefined,\n estimated: rate && total && inRange ? (total - loaded) / rate : undefined,\n event: result,\n };\n data[isDownloadStream ? \"download\" : \"upload\"] = true;\n listener(data);\n };\n};\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { progressEventReducer, resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle\";\nimport OnCanceled from \"./onCanceled\";\n\nconst download: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const { url, header, timeout, filePath } = resolveUniAppRequestOptions(\n config,\n options\n );\n const onCanceled = new OnCanceled(config);\n let task: UniApp.DownloadTask | null = uni.downloadFile({\n url,\n header,\n timeout,\n // @ts-ignore\n filePath,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.tempFilePath,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"downloadFile:fail timeout\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n const isNetworkError = errMsg === \"downloadFile:fail\";\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onDownloadProgress === \"function\") {\n task.onProgressUpdate(\n progressEventReducer(config.onDownloadProgress, true)\n );\n }\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default download;\n","import { AxiosRequestConfig, CanceledError } from \"axios\";\n\nexport default class OnCanceled<T> {\n config: AxiosRequestConfig<T>;\n private onCanceled?: (cancel?: any) => void;\n constructor(config: AxiosRequestConfig<T>) {\n this.config = config;\n }\n\n subscribe(task: any, reject: any) {\n if (this.config.cancelToken || this.config.signal) {\n this.onCanceled = (cancel?: any) => {\n if (!task) {\n return;\n }\n reject(\n !cancel || cancel.type\n ? new CanceledError(undefined, undefined, this.config, task)\n : cancel\n );\n task.abort();\n task = null;\n };\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.subscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.addEventListener) {\n this.config.signal.aborted\n ? this.onCanceled()\n : this.config.signal.addEventListener(\"abort\", this.onCanceled);\n }\n }\n }\n\n unsubscribe() {\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.unsubscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.removeEventListener) {\n this.config.signal.removeEventListener(\"abort\", this.onCanceled);\n }\n }\n}\n","import { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\nimport OnCanceled from \"./onCanceled\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle\";\nimport { AxiosError, AxiosResponse } from \"axios\";\n\nconst upload: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n\n let task: UniApp.UploadTask | null = uni.uploadFile({\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"uploadFile:fail timeout\";\n const isNetworkError = errMsg === \"uploadFile:fail file error\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default upload;\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle\";\nimport OnCanceled from \"./onCanceled\";\n\nconst request: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n let task: UniApp.RequestTask | null = uni.request({\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: result.header,\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n cookies: result.cookies,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"request:fail timeout\";\n const isNetworkError = errMsg === \"request:fail\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default request;\n","import { AxiosRequestConfig } from \"axios\";\nimport { Method } from \"../types\";\nimport { getMethodType } from \"../utils\";\nimport download from \"./download\";\nimport upload from \"./upload\";\nimport request from \"./request\";\n\nexport const getMethod = (config: AxiosRequestConfig): Method => {\n const methodType = getMethodType(config);\n switch (methodType) {\n case \"download\":\n return download;\n case \"upload\":\n return upload;\n default:\n return request;\n }\n};\n","import { AxiosAdapter, AxiosRequestConfig } from \"axios\";\nimport { getMethod } from \"./methods\";\nimport { UserOptions } from \"./types\";\nimport { resolveOptions } from \"./utils\";\n\nexport const createUniAppAxiosAdapter = (\n userOptions: UserOptions = {}\n): AxiosAdapter => {\n const options = resolveOptions(userOptions);\n const uniappAdapter: AxiosAdapter = (config: AxiosRequestConfig) => {\n const method = getMethod(config);\n return method(config, options);\n };\n return uniappAdapter;\n};\n"],"mappings":";AAGA,OAAO,cAAc;AAErB,OAAO,mBAAmB;AAE1B,OAAO,iBAAiB;AAajB,IAAM,gBAAgB,CAAI,WAA8C;AAC7E,QAAM,EAAE,QAAQ,YAAY,MAAM,IAAI;AACtC,QAAM,SAAS,UAAU,kBAAkB;AAC3C,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,IAAM,iBAAiB,CAAC,gBAA8C;AAC3E,SAAO;AAAA,IACL,GAAG;AAAA,EACL;AACF;AAEO,IAAM,8BAA8B,CACzC,QACA,YACqC;AA1CvC;AA2CE,QAAM,OAAO,OAAO;AACpB,QAAM,eACJ,OAAO,iBAAiB,gBAAgB,gBAAgB;AAC1D,QAAM,WAAW,iBAAiB,SAAS,SAAS;AAEpD,QAAM,iBAAmC,OAAO;AA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QAAQA,YAAW,aAAa,QAAQ,IAAI;AAAA,YAC7D;AAAA,UACF;AAAA,QACF;AACA,eAAO,IAAIA,YAAW,MAAM,QAAQ,QAAW,QAAQ,IAAI,CAAC;AAC5D,eAAO;AAAA,MACT;AAAA,MACA,WAAW;AACT,mBAAW,YAAY;AAAA,MACzB;AAAA,IACF,CAAC;AAED,QAAI,OAAO,OAAO,sBAAsB,YAAY;AAClD,WAAK,kBAAkB,OAAO,iBAAiB;AAAA,IACjD;AAEA,eAAW,UAAU,MAAM,MAAM;AAAA,EACnC,CAAC;AACH;AAEA,IAAO,kBAAQ;;;ACzER,IAAM,YAAY,CAAC,WAAuC;AAC/D,QAAM,aAAa,cAAc,MAAM;AACvC,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;;;ACZO,IAAM,2BAA2B,CACtC,cAA2B,CAAC,MACX;AACjB,QAAM,UAAU,eAAe,WAAW;AAC1C,QAAM,gBAA8B,CAAC,WAA+B;AAClE,UAAM,SAAS,UAAU,MAAM;AAC/B,WAAO,OAAO,QAAQ,OAAO;AAAA,EAC/B;AACA,SAAO;AACT;","names":["settle","AxiosError","AxiosError","settle","settle","AxiosError"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/methods/download.ts","../src/methods/onCanceled.ts","../src/methods/upload.ts","../src/methods/request.ts","../src/methods/index.ts","../src/index.ts"],"names":["settle","AxiosError"],"mappings":";AACA,OAAO,cAAc;AAErB,OAAO,mBAAmB;AAE1B,OAAO,iBAAiB;AAajB,IAAM,gBAAgB,CAAI,WAA8C;AAC7E,QAAM,EAAE,QAAQ,YAAY,MAAM,IAAI;AACtC,QAAM,SAAS,UAAU,kBAAkB;AAC3C,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEO,I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ACA,QAAAA,QAAO,SAAS,QAAQ,QAAQ;AAChC,eAAO;AAAA,MACT;AAAA,MACA,KAAK,OAAO;AACV,cAAM,EAAE,SAAS,GAAG,IAAI,wBAAS,CAAC;AAClC,YAAI,QAAQ;AACV,gBAAM,iBAAiB,WAAW;AAClC,gBAAM,iBAAiB,WAAW;AAClC,cAAI,gBAAgB;AAClB,mBAAO,IAAIC,YAAW,QAAQA,YAAW,WAAW,QAAQ,IAAI,CAAC;AAAA,UACnE;AACA,cAAI,gBAAgB;AAClB;AAAA,cACE,IAAIA,YAAW,QAAQA,YAAW,aAAa,QAAQ,IAAI;AAAA,YAC7D;AAAA,UACF;AAAA,QACF;AACA,eAAO,IAAIA,YAAW,MAAM,QAAQ,QAAW,QAAQ,IAAI,CAAC;AAC5D,eAAO;AAAA,MACT;AAAA,MACA,WAAW;AACT,mBAAW,YAAY;AAAA,MACzB;AAAA,IACF,CAAC;AAED,QAAI,OAAO,OAAO,sBAAsB,YAAY;AAClD,WAAK,kBAAkB,OAAO,iBAAiB;AAAA,IACjD;AAEA,eAAW,UAAU,MAAM,MAAM;AAAA,EACnC,CAAC;AACH;AAEA,IAAO,kBAAQ;;;ACzER,IAAM,YAAY,CAAC,WAAuC;AAC/D,QAAM,aAAa,cAAc,MAAM;AACvC,UAAQ,YAAY;AAAA,IAClB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;;;ACZO,IAAM,2BAA2B,CACtC,cAA2B,CAAC,MACX;AACjB,QAAM,UAAU,eAAe,WAAW;AAC1C,QAAM,gBAA8B,CAAC,WAA+B;AAClE,UAAM,SAAS,UAAU,MAAM;AAC/B,WAAO,OAAO,QAAQ,OAAO;AAAA,EAC/B;AACA,SAAO;AACT","sourcesContent":["// @ts-ignore\nimport buildURL from \"axios/lib/helpers/buildURL.js\";\n// @ts-ignore\nimport buildFullPath from \"axios/lib/core/buildFullPath.js\";\n// @ts-ignore\nimport speedometer from \"axios/lib/helpers/speedometer.js\";\n\nimport {\n ResolvedOptions,\n MethodType,\n UserOptions,\n UniNetworkRequestWithoutCallback,\n} from \"./types\";\nimport axios, {\n AxiosRequestConfig,\n AxiosHeaders as AxiosHeadersType,\n} from \"axios\";\n\nexport const getMethodType = <T>(config: AxiosRequestConfig<T>): MethodType => {\n const { method: rawMethod = \"GET\" } = config;\n const method = rawMethod.toLocaleLowerCase();\n switch (method) {\n case \"download\":\n return \"download\";\n case \"upload\":\n return \"upload\";\n default:\n return \"request\";\n }\n};\n\nexport const resolveOptions = (userOptions: UserOptions): ResolvedOptions => {\n return {\n ...userOptions,\n };\n};\n\nexport const resolveUniAppRequestOptions = (\n config: AxiosRequestConfig,\n options: ResolvedOptions\n): UniNetworkRequestWithoutCallback => {\n const data = config.data;\n const responseType =\n config.responseType === \"arraybuffer\" ? \"arraybuffer\" : \"text\";\n const dataType = responseType === \"text\" ? \"json\" : undefined;\n // @ts-ignore\n const requestHeaders: AxiosHeadersType = config.headers;\n\n if (config.auth) {\n const username = config.auth.username || \"\";\n const password = config.auth.password\n ? unescape(encodeURIComponent(config.auth.password))\n : \"\";\n requestHeaders.set(\n \"Authorization\",\n \"Basic \" + btoa(username + \":\" + password)\n );\n }\n\n const fullPath = buildFullPath(config.baseURL, config.url);\n const method = (config?.method?.toUpperCase() ?? \"GET\") as unknown as any;\n const url = buildURL(fullPath, config.params, config.paramsSerializer);\n\n // set uni-app default value\n // request\n const timeout = config.timeout || 60000;\n const withCredentials = config.withCredentials ?? false;\n const sslVerify = config.sslVerify ?? true;\n const firstIpv4 = config.firstIpv4 ?? false;\n // upload\n let formData = {};\n if (data && typeof data === \"string\") {\n try {\n formData = JSON.parse(data);\n } catch (error) {}\n }\n\n const header = requestHeaders.toJSON();\n\n return {\n ...config,\n url,\n data,\n header,\n method,\n responseType,\n dataType,\n timeout,\n withCredentials,\n sslVerify,\n firstIpv4,\n formData,\n };\n};\n\nexport const progressEventReducer = (\n listener: any,\n isDownloadStream: boolean\n) => {\n let bytesNotified = 0;\n const _speedometer = speedometer(50, 250);\n\n return (result: UniApp.OnProgressDownloadResult) => {\n const loaded = result.totalBytesWritten;\n const total = result.totalBytesExpectedToWrite;\n const progressBytes = loaded - bytesNotified;\n const rate = _speedometer(progressBytes);\n const inRange = loaded <= total;\n\n bytesNotified = loaded;\n\n const data: any = {\n loaded,\n total,\n progress: total ? loaded / total : undefined,\n bytes: progressBytes,\n rate: rate ? rate : undefined,\n estimated: rate && total && inRange ? (total - loaded) / rate : undefined,\n event: result,\n };\n data[isDownloadStream ? \"download\" : \"upload\"] = true;\n listener(data);\n };\n};\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { progressEventReducer, resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle.js\";\nimport OnCanceled from \"./onCanceled\";\n\nconst download: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const { url, header, timeout, filePath } = resolveUniAppRequestOptions(\n config,\n options\n );\n const onCanceled = new OnCanceled(config);\n let task: UniApp.DownloadTask | null = uni.downloadFile({\n url,\n header,\n timeout,\n // @ts-ignore\n filePath,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.tempFilePath,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"downloadFile:fail timeout\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n const isNetworkError = errMsg === \"downloadFile:fail\";\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onDownloadProgress === \"function\") {\n task.onProgressUpdate(\n progressEventReducer(config.onDownloadProgress, true)\n );\n }\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default download;\n","import { AxiosRequestConfig, CanceledError } from \"axios\";\n\nexport default class OnCanceled<T> {\n config: AxiosRequestConfig<T>;\n private onCanceled?: (cancel?: any) => void;\n constructor(config: AxiosRequestConfig<T>) {\n this.config = config;\n }\n\n subscribe(task: any, reject: any) {\n if (this.config.cancelToken || this.config.signal) {\n this.onCanceled = (cancel?: any) => {\n if (!task) {\n return;\n }\n reject(\n !cancel || cancel.type\n ? new CanceledError(undefined, undefined, this.config, task)\n : cancel\n );\n task.abort();\n task = null;\n };\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.subscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.addEventListener) {\n this.config.signal.aborted\n ? this.onCanceled()\n : this.config.signal.addEventListener(\"abort\", this.onCanceled);\n }\n }\n }\n\n unsubscribe() {\n if (this.config.cancelToken) {\n // @ts-ignore\n this.config.cancelToken.unsubscribe(this.onCanceled);\n }\n\n if (this.config.signal && this.config.signal.removeEventListener) {\n this.config.signal.removeEventListener(\"abort\", this.onCanceled);\n }\n }\n}\n","import { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\nimport OnCanceled from \"./onCanceled\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle.js\";\nimport { AxiosError, AxiosResponse } from \"axios\";\n\nconst upload: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n\n let task: UniApp.UploadTask | null = uni.uploadFile({\n url,\n files,\n fileType,\n file,\n filePath,\n name,\n header,\n timeout,\n formData,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: {},\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"uploadFile:fail timeout\";\n const isNetworkError = errMsg === \"uploadFile:fail file error\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default upload;\n","import { AxiosError, AxiosResponse } from \"axios\";\nimport { Method } from \"../types\";\nimport { resolveUniAppRequestOptions } from \"../utils\";\n// @ts-ignore\nimport settle from \"axios/lib/core/settle.js\";\nimport OnCanceled from \"./onCanceled\";\n\nconst request: Method = (config, options) => {\n return new Promise((resolve, reject) => {\n const {\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n } = resolveUniAppRequestOptions(config, options);\n const onCanceled = new OnCanceled(config);\n let task: UniApp.RequestTask | null = uni.request({\n url,\n data,\n header,\n method,\n timeout,\n dataType,\n responseType,\n sslVerify,\n withCredentials,\n firstIpv4,\n success(result) {\n if (!task) {\n return;\n }\n const response: AxiosResponse = {\n config,\n data: result.data,\n headers: result.header,\n status: result.statusCode,\n // @ts-ignore\n statusText: result.errMsg ?? \"OK\",\n request: task,\n cookies: result.cookies,\n };\n settle(resolve, reject, response);\n task = null;\n },\n fail(error) {\n const { errMsg = \"\" } = error ?? {};\n if (errMsg) {\n const isTimeoutError = errMsg === \"request:fail timeout\";\n const isNetworkError = errMsg === \"request:fail\";\n if (isTimeoutError) {\n reject(new AxiosError(errMsg, AxiosError.ETIMEDOUT, config, task));\n }\n if (isNetworkError) {\n reject(\n new AxiosError(errMsg, AxiosError.ERR_NETWORK, config, task)\n );\n }\n }\n reject(new AxiosError(error.errMsg, undefined, config, task));\n task = null;\n },\n complete() {\n onCanceled.unsubscribe();\n },\n });\n\n if (typeof config.onHeadersReceived === \"function\") {\n task.onHeadersReceived(config.onHeadersReceived);\n }\n\n onCanceled.subscribe(task, reject);\n });\n};\n\nexport default request;\n","import { AxiosRequestConfig } from \"axios\";\nimport { Method } from \"../types\";\nimport { getMethodType } from \"../utils\";\nimport download from \"./download\";\nimport upload from \"./upload\";\nimport request from \"./request\";\n\nexport const getMethod = (config: AxiosRequestConfig): Method => {\n const methodType = getMethodType(config);\n switch (methodType) {\n case \"download\":\n return download;\n case \"upload\":\n return upload;\n default:\n return request;\n }\n};\n","import type { AxiosAdapter, AxiosRequestConfig } from \"axios\";\nimport { getMethod } from \"./methods\";\nimport { UserOptions } from \"./types\";\nimport { resolveOptions } from \"./utils\";\n\nexport const createUniAppAxiosAdapter = (\n userOptions: UserOptions = {}\n): AxiosAdapter => {\n const options = resolveOptions(userOptions);\n const uniappAdapter: AxiosAdapter = (config: AxiosRequestConfig) => {\n const method = getMethod(config);\n return method(config, options);\n };\n return uniappAdapter;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uni-helper/axios-adapter",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"packageManager": "pnpm@7.12.0",
|
|
7
7
|
"description": "The Axios adapter for uniapp",
|
|
@@ -39,30 +39,28 @@
|
|
|
39
39
|
"dev": "tsup --watch",
|
|
40
40
|
"play": "nr -C playground dev:h5",
|
|
41
41
|
"prepublishOnly": "nr build",
|
|
42
|
-
"release": "bumpp && npm publish",
|
|
42
|
+
"release": "bumpp && npm publish --access public",
|
|
43
43
|
"test": "vitest",
|
|
44
44
|
"typecheck": "tsc --noEmit"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"axios": "
|
|
47
|
+
"axios": "1.2.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@dcloudio/types": "^3.
|
|
51
|
-
"@types/node": "^18.11.
|
|
50
|
+
"@dcloudio/types": "^3.2.2",
|
|
51
|
+
"@types/node": "^18.11.12",
|
|
52
|
+
"axios": "^1.2.1",
|
|
52
53
|
"bumpp": "^8.2.1",
|
|
53
|
-
"eslint": "^8.
|
|
54
|
-
"pnpm": "^7.
|
|
54
|
+
"eslint": "^8.29.0",
|
|
55
|
+
"pnpm": "^7.18.1",
|
|
55
56
|
"rimraf": "^3.0.2",
|
|
56
|
-
"tsup": "^6.
|
|
57
|
-
"typescript": "^4.
|
|
58
|
-
"vite": "^
|
|
59
|
-
},
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"axios": "^1.1.3"
|
|
57
|
+
"tsup": "^6.5.0",
|
|
58
|
+
"typescript": "^4.9.4",
|
|
59
|
+
"vite": "^4.0.0"
|
|
62
60
|
},
|
|
63
61
|
"pnpm": {
|
|
64
62
|
"patchedDependencies": {
|
|
65
|
-
"axios@1.1
|
|
63
|
+
"axios@1.2.1": "patches/axios@1.2.1.patch"
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
}
|