@uni-helper/axios-adapter 1.5.3 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,359 +1,321 @@
1
- 'use strict';
2
-
3
- var axios = require('axios');
4
- var buildURL = require('axios/unsafe/helpers/buildURL');
5
- var speedometer = require('axios/unsafe/helpers/speedometer');
6
- var buildFullPath = require('axios/unsafe/core/buildFullPath');
7
- var settle = require('axios/unsafe/core/settle');
8
-
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- var buildURL__default = /*#__PURE__*/_interopDefault(buildURL);
12
- var speedometer__default = /*#__PURE__*/_interopDefault(speedometer);
13
- var buildFullPath__default = /*#__PURE__*/_interopDefault(buildFullPath);
14
- var settle__default = /*#__PURE__*/_interopDefault(settle);
15
-
16
- // src/index.ts
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_chunk = require("./chunk-CKQMccvm.cjs");
3
+ let axios = require("axios");
4
+ let axios_unsafe_core_buildFullPath = require("axios/unsafe/core/buildFullPath");
5
+ axios_unsafe_core_buildFullPath = require_chunk.__toESM(axios_unsafe_core_buildFullPath, 1);
6
+ let axios_unsafe_helpers_buildURL = require("axios/unsafe/helpers/buildURL");
7
+ axios_unsafe_helpers_buildURL = require_chunk.__toESM(axios_unsafe_helpers_buildURL, 1);
8
+ let axios_unsafe_helpers_speedometer = require("axios/unsafe/helpers/speedometer");
9
+ axios_unsafe_helpers_speedometer = require_chunk.__toESM(axios_unsafe_helpers_speedometer, 1);
10
+ let axios_unsafe_core_settle = require("axios/unsafe/core/settle");
11
+ axios_unsafe_core_settle = require_chunk.__toESM(axios_unsafe_core_settle, 1);
12
+ //#region src/utils.ts
17
13
  function getMethodType(config) {
18
- const { method: rawMethod = "GET" } = config;
19
- const method = rawMethod.toLocaleLowerCase();
20
- switch (method) {
21
- case "download":
22
- return "download";
23
- case "upload":
24
- return "upload";
25
- default:
26
- return "request";
27
- }
14
+ const { method: rawMethod = "GET" } = config;
15
+ switch (rawMethod.toLocaleLowerCase()) {
16
+ case "download": return "download";
17
+ case "upload": return "upload";
18
+ default: return "request";
19
+ }
28
20
  }
29
21
  function resolveOptions(userOptions) {
30
- return {
31
- ...userOptions
32
- };
22
+ return { ...userOptions };
33
23
  }
34
24
  function resolveUniAppRequestOptions(config, _options) {
35
- var _a, _b;
36
- const data = config.data;
37
- const responseType = config.responseType === "arraybuffer" ? "arraybuffer" : "text";
38
- const dataType = responseType === "text" ? "json" : void 0;
39
- const { headers, baseURL, ...requestConfig } = config;
40
- const requestHeaders = axios.AxiosHeaders.from(serializeObject(headers)).normalize(false);
41
- if (config.auth) {
42
- const username = config.auth.username || "";
43
- const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : "";
44
- requestHeaders.set(
45
- "Authorization",
46
- `Basic ${btoa(`${username}:${password}`)}`
47
- );
48
- }
49
- const fullPath = buildFullPath__default.default(baseURL, config.url);
50
- const method = (_b = (_a = config == null ? void 0 : config.method) == null ? void 0 : _a.toUpperCase()) != null ? _b : "GET";
51
- const url = buildURL__default.default(fullPath, config.params, config.paramsSerializer);
52
- const timeout = config.timeout || 6e4;
53
- let formData = {};
54
- if (data && typeof data === "string") {
55
- try {
56
- formData = JSON.parse(data);
57
- } catch (error) {
58
- }
59
- }
60
- const header = requestHeaders.toJSON();
61
- return {
62
- ...requestConfig,
63
- url,
64
- data,
65
- header,
66
- method,
67
- responseType,
68
- dataType,
69
- timeout,
70
- formData
71
- };
25
+ const data = config.data;
26
+ const responseType = config.responseType === "arraybuffer" ? "arraybuffer" : "text";
27
+ const dataType = responseType === "text" ? "json" : void 0;
28
+ const { headers, baseURL, ...requestConfig } = config;
29
+ const requestHeaders = axios.AxiosHeaders.from(serializeObject(headers)).normalize(false);
30
+ if (config.auth) {
31
+ const username = config.auth.username || "";
32
+ const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : "";
33
+ requestHeaders.set("Authorization", `Basic ${btoa(`${username}:${password}`)}`);
34
+ }
35
+ const fullPath = (0, axios_unsafe_core_buildFullPath.default)(baseURL, config.url);
36
+ const method = config?.method?.toUpperCase() ?? "GET";
37
+ const url = (0, axios_unsafe_helpers_buildURL.default)(fullPath, config.params, config.paramsSerializer);
38
+ const timeout = config.timeout || 6e4;
39
+ let formData = {};
40
+ if (data && typeof data === "string") try {
41
+ formData = JSON.parse(data);
42
+ } catch {}
43
+ const header = requestHeaders.toJSON();
44
+ return {
45
+ ...requestConfig,
46
+ url,
47
+ data,
48
+ header,
49
+ method,
50
+ responseType,
51
+ dataType,
52
+ timeout,
53
+ formData
54
+ };
72
55
  }
73
56
  function progressEventReducer(listener, isDownloadStream) {
74
- let bytesNotified = 0;
75
- const _speedometer = speedometer__default.default(50, 250);
76
- return (result) => {
77
- const loaded = result.totalBytesWritten;
78
- const total = result.totalBytesExpectedToWrite;
79
- const progressBytes = loaded - bytesNotified;
80
- const rate = _speedometer(progressBytes);
81
- const inRange = loaded <= total;
82
- bytesNotified = loaded;
83
- const data = {
84
- loaded,
85
- total,
86
- progress: total ? loaded / total : void 0,
87
- bytes: progressBytes,
88
- rate: rate || void 0,
89
- estimated: rate && total && inRange ? (total - loaded) / rate : void 0,
90
- event: result
91
- };
92
- data[isDownloadStream ? "download" : "upload"] = true;
93
- listener(data);
94
- };
57
+ let bytesNotified = 0;
58
+ const _speedometer = (0, axios_unsafe_helpers_speedometer.default)(50, 250);
59
+ return (result) => {
60
+ const loaded = result.totalBytesWritten;
61
+ const total = result.totalBytesExpectedToWrite;
62
+ const progressBytes = loaded - bytesNotified;
63
+ const rate = _speedometer(progressBytes);
64
+ const inRange = loaded <= total;
65
+ bytesNotified = loaded;
66
+ const data = {
67
+ loaded,
68
+ total,
69
+ progress: total ? loaded / total : void 0,
70
+ bytes: progressBytes,
71
+ rate: rate || void 0,
72
+ estimated: rate && total && inRange ? (total - loaded) / rate : void 0,
73
+ event: result
74
+ };
75
+ data[isDownloadStream ? "download" : "upload"] = true;
76
+ listener(data);
77
+ };
95
78
  }
79
+ /**
80
+ * ### 对象序列化
81
+ * - 将一个对象序列化为一个纯净的、类似JSON的新对象。
82
+ * - 此过程会过滤掉值为 null、undefined 或 false 的属性。
83
+ *
84
+ * @link https://github.com/axios/axios/blob/ef36347fb559383b04c755b07f1a8d11897fab7f/lib/core/AxiosHeaders.js#L238-L246
85
+ * @param {Record<string, any> | null | undefined} sourceObj 要进行序列化的源对象。
86
+ * @param {SerializeOptions} [options] 序列化选项。
87
+ * @returns {Record<string, any>} 返回一个新的、纯净的 JavaScript 对象。
88
+ */
96
89
  function serializeObject(sourceObj, options) {
97
- const resultObj = /* @__PURE__ */ Object.create(null);
98
- if (!sourceObj)
99
- return resultObj;
100
- const { asStrings = false } = options || {};
101
- forEach(sourceObj, (value, key) => {
102
- if (value != null && value !== false) {
103
- resultObj[key] = asStrings && Array.isArray(value) ? value.join(", ") : value;
104
- }
105
- });
106
- return resultObj;
90
+ const resultObj = Object.create(null);
91
+ if (!sourceObj) return resultObj;
92
+ const { asStrings = false } = options || {};
93
+ forEach(sourceObj, (value, key) => {
94
+ if (value != null && value !== false) resultObj[key] = asStrings && Array.isArray(value) ? value.join(", ") : value;
95
+ });
96
+ return resultObj;
107
97
  }
98
+ /**
99
+ * Iterate over an Array or an Object invoking a function for each item.
100
+ *
101
+ * If `obj` is an Array callback will be called passing
102
+ * the value, index, and complete array for each item.
103
+ *
104
+ * If 'obj' is an Object callback will be called passing
105
+ * the value, key, and complete object for each property.
106
+ *
107
+ * @link https://github.com/axios/axios/blob/v1.x/lib/utils.js#L240
108
+ *
109
+ * @param {object | Array} obj The object to iterate
110
+ * @param {Function} fn The callback to invoke for each item
111
+ * @param {object} [options]
112
+ * @param {boolean} [options.allOwnKeys]
113
+ */
108
114
  function forEach(obj, fn, { allOwnKeys = false } = {}) {
109
- if (obj === null || typeof obj === "undefined")
110
- return;
111
- if (typeof obj !== "object")
112
- obj = [obj];
113
- if (Array.isArray(obj)) {
114
- for (let i = 0, l = obj.length; i < l; i++) {
115
- fn(obj[i], i, obj);
116
- }
117
- } else {
118
- const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
119
- const len = keys.length;
120
- let key;
121
- for (let i = 0; i < len; i++) {
122
- key = keys[i];
123
- fn(obj[key], key, obj);
124
- }
125
- }
115
+ if (obj === null || typeof obj === "undefined") return;
116
+ if (typeof obj !== "object") obj = [obj];
117
+ if (Array.isArray(obj)) for (let i = 0, l = obj.length; i < l; i++) fn(obj[i], i, obj);
118
+ else {
119
+ const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
120
+ const len = keys.length;
121
+ let key;
122
+ for (let i = 0; i < len; i++) {
123
+ key = keys[i];
124
+ fn(obj[key], key, obj);
125
+ }
126
+ }
126
127
  }
128
+ //#endregion
129
+ //#region src/methods/onCanceled.ts
127
130
  var OnCanceled = class {
128
- constructor(config) {
129
- this.config = config;
130
- }
131
- subscribe(task, reject) {
132
- if (this.config.cancelToken || this.config.signal) {
133
- this.onCanceled = (cancel) => {
134
- if (!task)
135
- return;
136
- reject(
137
- !cancel || cancel.type ? new axios.CanceledError(void 0, void 0, this.config, task) : cancel
138
- );
139
- task.abort();
140
- task = null;
141
- };
142
- if (this.config.cancelToken) {
143
- this.config.cancelToken.subscribe(this.onCanceled);
144
- }
145
- if (this.config.signal && this.config.signal.addEventListener) {
146
- this.config.signal.aborted ? this.onCanceled() : this.config.signal.addEventListener("abort", this.onCanceled);
147
- }
148
- }
149
- }
150
- unsubscribe() {
151
- if (this.config.cancelToken) {
152
- this.config.cancelToken.unsubscribe(this.onCanceled);
153
- }
154
- if (this.config.signal && this.config.signal.removeEventListener)
155
- this.config.signal.removeEventListener("abort", this.onCanceled);
156
- }
131
+ config;
132
+ onCanceled;
133
+ constructor(config) {
134
+ this.config = config;
135
+ }
136
+ subscribe(task, reject) {
137
+ if (this.config.cancelToken || this.config.signal) {
138
+ this.onCanceled = (cancel) => {
139
+ if (!task) return;
140
+ reject(!cancel || cancel.type ? new axios.CanceledError(void 0, void 0, this.config, task) : cancel);
141
+ task.abort();
142
+ task = null;
143
+ };
144
+ if (this.config.cancelToken) this.config.cancelToken.subscribe(this.onCanceled);
145
+ if (this.config.signal && this.config.signal.addEventListener) this.config.signal.aborted ? this.onCanceled() : this.config.signal.addEventListener("abort", this.onCanceled);
146
+ }
147
+ }
148
+ unsubscribe() {
149
+ if (this.config.cancelToken) this.config.cancelToken.unsubscribe(this.onCanceled);
150
+ if (this.config.signal && this.config.signal.removeEventListener) this.config.signal.removeEventListener("abort", this.onCanceled);
151
+ }
157
152
  };
158
-
159
- // src/methods/download.ts
160
- var download = (config, options) => {
161
- return new Promise((resolve, reject) => {
162
- const requestOptions = resolveUniAppRequestOptions(
163
- config);
164
- const responseConfig = config;
165
- responseConfig.headers = new axios.AxiosHeaders(requestOptions.header);
166
- const onCanceled = new OnCanceled(config);
167
- let task = uni.downloadFile({
168
- ...requestOptions,
169
- success(result) {
170
- var _a;
171
- if (!task)
172
- return;
173
- const response = {
174
- config: responseConfig,
175
- data: result.tempFilePath,
176
- headers: {},
177
- status: result.statusCode,
178
- statusText: (_a = result.errMsg) != null ? _a : "OK",
179
- request: task
180
- };
181
- settle__default.default(resolve, reject, response);
182
- task = null;
183
- },
184
- fail(error) {
185
- const { errMsg = "" } = error != null ? error : {};
186
- if (errMsg) {
187
- const isTimeoutError = errMsg === "downloadFile:fail timeout";
188
- if (isTimeoutError)
189
- reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, responseConfig, task));
190
- const isNetworkError = errMsg === "downloadFile:fail";
191
- if (isNetworkError) {
192
- reject(
193
- new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, responseConfig, task)
194
- );
195
- }
196
- }
197
- reject(new axios.AxiosError(error.errMsg, void 0, responseConfig, task));
198
- task = null;
199
- },
200
- complete() {
201
- onCanceled.unsubscribe();
202
- }
203
- });
204
- if (typeof config.onDownloadProgress === "function") {
205
- task.onProgressUpdate(
206
- progressEventReducer(config.onDownloadProgress, true)
207
- );
208
- }
209
- if (typeof config.onHeadersReceived === "function")
210
- task.onHeadersReceived(config.onHeadersReceived);
211
- onCanceled.subscribe(task, reject);
212
- });
153
+ //#endregion
154
+ //#region src/methods/download.ts
155
+ const download = (config, options) => {
156
+ return new Promise((resolve, reject) => {
157
+ const requestOptions = resolveUniAppRequestOptions(config, options);
158
+ const responseConfig = config;
159
+ responseConfig.headers = new axios.AxiosHeaders(requestOptions.header);
160
+ const onCanceled = new OnCanceled(config);
161
+ let task = uni.downloadFile({
162
+ ...requestOptions,
163
+ success(result) {
164
+ if (!task) return;
165
+ (0, axios_unsafe_core_settle.default)(resolve, reject, {
166
+ config: responseConfig,
167
+ data: result.tempFilePath,
168
+ headers: {},
169
+ status: result.statusCode,
170
+ statusText: result.errMsg ?? "OK",
171
+ request: task
172
+ });
173
+ task = null;
174
+ },
175
+ fail(error) {
176
+ const { errMsg = "" } = error ?? {};
177
+ if (errMsg) {
178
+ if (errMsg === "downloadFile:fail timeout") reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, responseConfig, task));
179
+ if (errMsg === "downloadFile:fail") reject(new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, responseConfig, task));
180
+ }
181
+ reject(new axios.AxiosError(error.errMsg, void 0, responseConfig, task));
182
+ task = null;
183
+ },
184
+ complete() {
185
+ onCanceled.unsubscribe();
186
+ }
187
+ });
188
+ if (typeof config.onDownloadProgress === "function") task.onProgressUpdate(progressEventReducer(config.onDownloadProgress, true));
189
+ if (typeof config.onHeadersReceived === "function") task.onHeadersReceived(config.onHeadersReceived);
190
+ onCanceled.subscribe(task, reject);
191
+ });
213
192
  };
214
- var download_default = download;
215
- var upload = (config, options) => {
216
- return new Promise((resolve, reject) => {
217
- const requestOptions = resolveUniAppRequestOptions(config);
218
- const responseConfig = config;
219
- responseConfig.headers = new axios.AxiosHeaders(requestOptions.header);
220
- const onCanceled = new OnCanceled(config);
221
- let task = uni.uploadFile({
222
- ...requestOptions,
223
- success(result) {
224
- var _a;
225
- if (!task)
226
- return;
227
- const response = {
228
- config: responseConfig,
229
- data: result.data,
230
- headers: {},
231
- status: result.statusCode,
232
- statusText: (_a = result.errMsg) != null ? _a : "OK",
233
- request: task
234
- };
235
- settle__default.default(resolve, reject, response);
236
- task = null;
237
- },
238
- fail(error) {
239
- const { errMsg = "" } = error != null ? error : {};
240
- if (errMsg) {
241
- const isTimeoutError = errMsg === "uploadFile:fail timeout";
242
- const isNetworkError = errMsg === "uploadFile:fail file error";
243
- if (isTimeoutError)
244
- reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, responseConfig, task));
245
- if (isNetworkError) {
246
- reject(
247
- new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, responseConfig, task)
248
- );
249
- }
250
- }
251
- reject(new axios.AxiosError(error.errMsg, void 0, responseConfig, task));
252
- task = null;
253
- },
254
- complete() {
255
- onCanceled.unsubscribe();
256
- }
257
- });
258
- if (typeof config.onHeadersReceived === "function")
259
- task.onHeadersReceived(config.onHeadersReceived);
260
- onCanceled.subscribe(task, reject);
261
- });
193
+ //#endregion
194
+ //#region src/methods/request.ts
195
+ const request = (config, options) => {
196
+ return new Promise((resolve, reject) => {
197
+ const requestOptions = resolveUniAppRequestOptions(config, options);
198
+ const responseConfig = config;
199
+ responseConfig.headers = new axios.AxiosHeaders(requestOptions.header);
200
+ const onCanceled = new OnCanceled(config);
201
+ let task = uni.request({
202
+ ...requestOptions,
203
+ success(result) {
204
+ if (!task) return;
205
+ if (Array.isArray(result.header)) {
206
+ const dingHeader = {};
207
+ result.header.forEach((h) => Object.assign(dingHeader, h));
208
+ result.header = dingHeader;
209
+ }
210
+ const headers = new axios.AxiosHeaders(result.header);
211
+ (0, axios_unsafe_core_settle.default)(resolve, reject, {
212
+ config: responseConfig,
213
+ data: result.data,
214
+ headers,
215
+ status: result.statusCode,
216
+ statusText: result.errMsg ?? "OK",
217
+ request: task,
218
+ cookies: result.cookies
219
+ });
220
+ task = null;
221
+ },
222
+ fail(error) {
223
+ const { errMsg = "" } = error ?? {};
224
+ if (errMsg) {
225
+ const isStatusError = errMsg === "request:fail http status error";
226
+ const isTimeoutError = errMsg === "request:fail timeout";
227
+ const isNetworkError = errMsg === "request:fail";
228
+ if (isTimeoutError) reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, responseConfig, task));
229
+ if (isNetworkError) reject(new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, responseConfig, task));
230
+ if (isStatusError) {
231
+ const response = error ?? {};
232
+ reject(new axios.AxiosError(errMsg, response.statusCode, responseConfig, task, response));
233
+ }
234
+ }
235
+ reject(new axios.AxiosError(error.errMsg, void 0, responseConfig, task));
236
+ task = null;
237
+ },
238
+ complete() {
239
+ onCanceled.unsubscribe();
240
+ }
241
+ });
242
+ if (typeof config.onHeadersReceived === "function") task.onHeadersReceived(config.onHeadersReceived);
243
+ onCanceled.subscribe(task, reject);
244
+ });
262
245
  };
263
- var upload_default = upload;
264
- var request = (config, options) => {
265
- return new Promise((resolve, reject) => {
266
- const requestOptions = resolveUniAppRequestOptions(config);
267
- const responseConfig = config;
268
- responseConfig.headers = new axios.AxiosHeaders(requestOptions.header);
269
- const onCanceled = new OnCanceled(config);
270
- let task = uni.request({
271
- ...requestOptions,
272
- success(result) {
273
- var _a;
274
- if (!task)
275
- return;
276
- if (Array.isArray(result.header)) {
277
- const dingHeader = {};
278
- result.header.forEach((h) => Object.assign(dingHeader, h));
279
- result.header = dingHeader;
280
- }
281
- const headers = new axios.AxiosHeaders(result.header);
282
- const response = {
283
- config: responseConfig,
284
- data: result.data,
285
- headers,
286
- status: result.statusCode,
287
- statusText: (_a = result.errMsg) != null ? _a : "OK",
288
- request: task,
289
- cookies: result.cookies
290
- };
291
- settle__default.default(resolve, reject, response);
292
- task = null;
293
- },
294
- fail(error) {
295
- const { errMsg = "" } = error != null ? error : {};
296
- if (errMsg) {
297
- const isTimeoutError = errMsg === "request:fail timeout";
298
- const isNetworkError = errMsg === "request:fail";
299
- if (isTimeoutError)
300
- reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, responseConfig, task));
301
- if (isNetworkError) {
302
- reject(
303
- new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, responseConfig, task)
304
- );
305
- }
306
- }
307
- reject(new axios.AxiosError(error.errMsg, void 0, responseConfig, task));
308
- task = null;
309
- },
310
- complete() {
311
- onCanceled.unsubscribe();
312
- }
313
- });
314
- if (typeof config.onHeadersReceived === "function")
315
- task.onHeadersReceived(config.onHeadersReceived);
316
- onCanceled.subscribe(task, reject);
317
- });
246
+ //#endregion
247
+ //#region src/methods/upload.ts
248
+ const upload = (config, options) => {
249
+ return new Promise((resolve, reject) => {
250
+ const requestOptions = resolveUniAppRequestOptions(config, options);
251
+ const responseConfig = config;
252
+ responseConfig.headers = new axios.AxiosHeaders(requestOptions.header);
253
+ const onCanceled = new OnCanceled(config);
254
+ let task = uni.uploadFile({
255
+ ...requestOptions,
256
+ success(result) {
257
+ if (!task) return;
258
+ (0, axios_unsafe_core_settle.default)(resolve, reject, {
259
+ config: responseConfig,
260
+ data: result.data,
261
+ headers: {},
262
+ status: result.statusCode,
263
+ statusText: result.errMsg ?? "OK",
264
+ request: task
265
+ });
266
+ task = null;
267
+ },
268
+ fail(error) {
269
+ const { errMsg = "" } = error ?? {};
270
+ if (errMsg) {
271
+ const isTimeoutError = errMsg === "uploadFile:fail timeout";
272
+ const isNetworkError = errMsg === "uploadFile:fail file error";
273
+ if (isTimeoutError) reject(new axios.AxiosError(errMsg, axios.AxiosError.ETIMEDOUT, responseConfig, task));
274
+ if (isNetworkError) reject(new axios.AxiosError(errMsg, axios.AxiosError.ERR_NETWORK, responseConfig, task));
275
+ }
276
+ reject(new axios.AxiosError(error.errMsg, void 0, responseConfig, task));
277
+ task = null;
278
+ },
279
+ complete() {
280
+ onCanceled.unsubscribe();
281
+ }
282
+ });
283
+ if (typeof config.onHeadersReceived === "function") task.onHeadersReceived(config.onHeadersReceived);
284
+ onCanceled.subscribe(task, reject);
285
+ });
318
286
  };
319
- var request_default = request;
320
-
321
- // src/methods/index.ts
287
+ //#endregion
288
+ //#region src/methods/index.ts
322
289
  function getMethod(config) {
323
- const methodType = getMethodType(config);
324
- switch (methodType) {
325
- case "download":
326
- return download_default;
327
- case "upload":
328
- return upload_default;
329
- default:
330
- return request_default;
331
- }
290
+ switch (getMethodType(config)) {
291
+ case "download": return download;
292
+ case "upload": return upload;
293
+ default: return request;
294
+ }
332
295
  }
333
-
334
- // src/index.ts
296
+ //#endregion
297
+ //#region src/index.ts
335
298
  function createUniAppAxiosAdapter(userOptions = {}) {
336
- const options = resolveOptions(userOptions);
337
- axios.Axios.prototype.download = function(url, config) {
338
- return this.request({
339
- url,
340
- method: "download",
341
- ...config
342
- });
343
- };
344
- axios.Axios.prototype.upload = function(url, data, config) {
345
- return this.request({
346
- url,
347
- method: "upload",
348
- data,
349
- ...config
350
- });
351
- };
352
- const uniappAdapter = (config) => {
353
- const method = getMethod(config);
354
- return method(config, options);
355
- };
356
- return uniappAdapter;
299
+ const options = resolveOptions(userOptions);
300
+ axios.Axios.prototype.download = function(url, config) {
301
+ return this.request({
302
+ url,
303
+ method: "download",
304
+ ...config
305
+ });
306
+ };
307
+ axios.Axios.prototype.upload = function(url, data, config) {
308
+ return this.request({
309
+ url,
310
+ method: "upload",
311
+ data,
312
+ ...config
313
+ });
314
+ };
315
+ const uniappAdapter = (config) => {
316
+ return getMethod(config)(config, options);
317
+ };
318
+ return uniappAdapter;
357
319
  }
358
-
320
+ //#endregion
359
321
  exports.createUniAppAxiosAdapter = createUniAppAxiosAdapter;