@uni-helper/axios-adapter 0.0.1 → 0.0.3
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 +32 -32
- package/README.zh-CN.md +32 -32
- package/client.d.ts +22 -22
- package/dist/index.cjs +6 -391
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -359
- package/dist/index.js.map +1 -1
- package/package.json +12 -16
package/README.md
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
# @uni-helper/axios-adapter
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
English | [简体中文](./README.zh-CN.md)
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
pnpm i @uni-helper/axios-adapter axios
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import axios from "axios";
|
|
17
|
-
import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";
|
|
18
|
-
|
|
19
|
-
const $axios = axios.create({
|
|
20
|
-
adapter: createUniAppAxiosAdapter(),
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Client Types
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
/// <reference types="@uni-helper/axios-adapter/client" />
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Configuration
|
|
31
|
-
|
|
32
|
-
see [types.ts](./src/types.ts)
|
|
1
|
+
# @uni-helper/axios-adapter
|
|
2
|
+
|
|
3
|
+
this is an Axios adapter for uni-app
|
|
4
|
+
|
|
5
|
+
English | [简体中文](./README.zh-CN.md)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pnpm i @uni-helper/axios-adapter axios
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import axios from "axios";
|
|
17
|
+
import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";
|
|
18
|
+
|
|
19
|
+
const $axios = axios.create({
|
|
20
|
+
adapter: createUniAppAxiosAdapter(),
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Client Types
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
/// <reference types="@uni-helper/axios-adapter/client" />
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
see [types.ts](./src/types.ts)
|
package/README.zh-CN.md
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
# @uni-helper/axios-adapter
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[English](./README.md) | 简体中文
|
|
6
|
-
|
|
7
|
-
## 安装
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
pnpm i @uni-helper/axios-adapter axios
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## 使用
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import axios from "axios";
|
|
17
|
-
import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";
|
|
18
|
-
|
|
19
|
-
const $axios = axios.create({
|
|
20
|
-
adapter: createUniAppAxiosAdapter(),
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## 客户端类型
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
/// <reference types="@uni-helper/axios-adapter/client" />
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## 配置
|
|
31
|
-
|
|
32
|
-
见 [types.ts](./src/types.ts)
|
|
1
|
+
# @uni-helper/axios-adapter
|
|
2
|
+
|
|
3
|
+
这是一个用于 uni-app 的 Axios 适配器
|
|
4
|
+
|
|
5
|
+
[English](./README.md) | 简体中文
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pnpm i @uni-helper/axios-adapter axios
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import axios from "axios";
|
|
17
|
+
import { createUniAppAxiosAdapter } from "@uni-helper/axios-adapter";
|
|
18
|
+
|
|
19
|
+
const $axios = axios.create({
|
|
20
|
+
adapter: createUniAppAxiosAdapter(),
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 客户端类型
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
/// <reference types="@uni-helper/axios-adapter/client" />
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 配置
|
|
31
|
+
|
|
32
|
+
见 [types.ts](./src/types.ts)
|
package/client.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
declare module "axios" {
|
|
2
|
-
export interface AxiosRequestConfig
|
|
3
|
-
extends Omit<
|
|
4
|
-
UniApp.RequestOptions,
|
|
5
|
-
"success" | "fail" | "complete" | "header"
|
|
6
|
-
>,
|
|
7
|
-
Omit<
|
|
8
|
-
UniApp.UploadFileOption,
|
|
9
|
-
"success" | "fail" | "complete" | "header" | "formData"
|
|
10
|
-
>,
|
|
11
|
-
Omit<
|
|
12
|
-
UniApp.DownloadFileOption,
|
|
13
|
-
"success" | "fail" | "complete" | "header"
|
|
14
|
-
>,
|
|
15
|
-
Partial<Pick<UniApp.RequestTask, "onHeadersReceived">> {}
|
|
16
|
-
|
|
17
|
-
export interface AxiosResponse {
|
|
18
|
-
cookies?: string[];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {};
|
|
1
|
+
declare module "axios" {
|
|
2
|
+
export interface AxiosRequestConfig
|
|
3
|
+
extends Omit<
|
|
4
|
+
UniApp.RequestOptions,
|
|
5
|
+
"success" | "fail" | "complete" | "header"
|
|
6
|
+
>,
|
|
7
|
+
Omit<
|
|
8
|
+
UniApp.UploadFileOption,
|
|
9
|
+
"success" | "fail" | "complete" | "header" | "formData"
|
|
10
|
+
>,
|
|
11
|
+
Omit<
|
|
12
|
+
UniApp.DownloadFileOption,
|
|
13
|
+
"success" | "fail" | "complete" | "header"
|
|
14
|
+
>,
|
|
15
|
+
Partial<Pick<UniApp.RequestTask, "onHeadersReceived">> {}
|
|
16
|
+
|
|
17
|
+
export interface AxiosResponse {
|
|
18
|
+
cookies?: string[];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,395 +1,10 @@
|
|
|
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
|
-
__export(src_exports, {
|
|
29
|
-
createUniAppAxiosAdapter: () => createUniAppAxiosAdapter
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
var Ae = require('form-data');
|
|
4
|
+
var axios = require('axios');
|
|
32
5
|
|
|
33
|
-
|
|
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
|
-
var getMethodType = (config) => {
|
|
38
|
-
const { method: rawMethod = "GET" } = config;
|
|
39
|
-
const method = rawMethod.toLocaleLowerCase();
|
|
40
|
-
switch (method) {
|
|
41
|
-
case "download":
|
|
42
|
-
return "download";
|
|
43
|
-
case "upload":
|
|
44
|
-
return "upload";
|
|
45
|
-
default:
|
|
46
|
-
return "request";
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var resolveOptions = (userOptions) => {
|
|
50
|
-
return {
|
|
51
|
-
...userOptions
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
var resolveUniAppRequestOptions = (config, options) => {
|
|
55
|
-
var _a;
|
|
56
|
-
const data = config.data;
|
|
57
|
-
const responseType = config.responseType === "arraybuffer" ? "arraybuffer" : "text";
|
|
58
|
-
const dataType = responseType === "text" ? "json" : void 0;
|
|
59
|
-
const requestHeaders = config.headers;
|
|
60
|
-
if (config.auth) {
|
|
61
|
-
const username = config.auth.username || "";
|
|
62
|
-
const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : "";
|
|
63
|
-
requestHeaders.set(
|
|
64
|
-
"Authorization",
|
|
65
|
-
"Basic " + btoa(username + ":" + password)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
const fullPath = (0, import_buildFullPath.default)(config.baseURL, config.url);
|
|
69
|
-
const method = ((_a = config == null ? void 0 : config.method) == null ? void 0 : _a.toUpperCase()) ?? "GET";
|
|
70
|
-
const url = (0, import_buildURL.default)(fullPath, config.params, config.paramsSerializer);
|
|
71
|
-
const timeout = config.timeout || 6e4;
|
|
72
|
-
const withCredentials = config.withCredentials ?? false;
|
|
73
|
-
const sslVerify = config.sslVerify ?? true;
|
|
74
|
-
const firstIpv4 = config.firstIpv4 ?? false;
|
|
75
|
-
let formData = {};
|
|
76
|
-
if (data && typeof data === "string") {
|
|
77
|
-
try {
|
|
78
|
-
formData = JSON.parse(data);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const header = requestHeaders.toJSON();
|
|
83
|
-
return {
|
|
84
|
-
...config,
|
|
85
|
-
url,
|
|
86
|
-
data,
|
|
87
|
-
header,
|
|
88
|
-
method,
|
|
89
|
-
responseType,
|
|
90
|
-
dataType,
|
|
91
|
-
timeout,
|
|
92
|
-
withCredentials,
|
|
93
|
-
sslVerify,
|
|
94
|
-
firstIpv4,
|
|
95
|
-
formData
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
var progressEventReducer = (listener, isDownloadStream) => {
|
|
99
|
-
let bytesNotified = 0;
|
|
100
|
-
const _speedometer = (0, import_speedometer.default)(50, 250);
|
|
101
|
-
return (result) => {
|
|
102
|
-
const loaded = result.totalBytesWritten;
|
|
103
|
-
const total = result.totalBytesExpectedToWrite;
|
|
104
|
-
const progressBytes = loaded - bytesNotified;
|
|
105
|
-
const rate = _speedometer(progressBytes);
|
|
106
|
-
const inRange = loaded <= total;
|
|
107
|
-
bytesNotified = loaded;
|
|
108
|
-
const data = {
|
|
109
|
-
loaded,
|
|
110
|
-
total,
|
|
111
|
-
progress: total ? loaded / total : void 0,
|
|
112
|
-
bytes: progressBytes,
|
|
113
|
-
rate: rate ? rate : void 0,
|
|
114
|
-
estimated: rate && total && inRange ? (total - loaded) / rate : void 0,
|
|
115
|
-
event: result
|
|
116
|
-
};
|
|
117
|
-
data[isDownloadStream ? "download" : "upload"] = true;
|
|
118
|
-
listener(data);
|
|
119
|
-
};
|
|
120
|
-
};
|
|
6
|
+
var{toString:ne}=Object.prototype,{getPrototypeOf:F}=Object,_=(e=>t=>{let n=ne.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),E=e=>(e=e.toLowerCase(),t=>_(t)===e),oe=E("URLSearchParams"),re=e=>{if(_(e)!=="object")return !1;let t=F(e);return (t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},{isArray:q}=Array,se=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;let o=e.indexOf(t,n);return o!==-1&&o===n},M=e=>t=>typeof t===e,ie=M("function"),ae=e=>e!==null&&typeof e=="object",ue=(e,t,n,o)=>{let s,a,u,y={};if(t=t||{},e==null)return t;do{for(s=Object.getOwnPropertyNames(e),a=s.length;a-- >0;)u=s[a],(!o||o(u,e,t))&&!y[u]&&(t[u]=e[u],y[u]=!0);e=n!==!1&&F(e);}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},le=E("FileList"),ce=M("undefined"),de=E("Date"),fe=E("Blob"),pe=E("ArrayBuffer"),me=(e=>t=>e&&t instanceof e)(typeof Uint8Array!="undefined"&&F(Uint8Array)),ye=e=>{if(!e)return null;if(q(e))return e;let t=e.length;if(!be(t))return null;let n=new Array(t);for(;t-- >0;)n[t]=e[t];return n};function he(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e=="undefined")return;let o,s;if(typeof e!="object"&&(e=[e]),q(e))for(o=0,s=e.length;o<s;o++)t.call(null,e[o],o,e);else {let a=n?Object.getOwnPropertyNames(e):Object.keys(e),u=a.length,y;for(o=0;o<u;o++)y=a[o],t.call(null,e[y],y,e);}}var we=M("string"),be=M("number"),l={isURLSearchParams:oe,isPlainObject:re,isArray:q,endsWith:se,isFunction:ie,isObject:ae,toFlatObject:ue,isUndefined:ce,isDate:de,isBlob:fe,isArrayBuffer:pe,isTypedArray:me,isFileList:le,toArray:ye,forEach:he,isString:we};var H=Ae;function P(e){return l.isPlainObject(e)||l.isArray(e)}function W(e){return l.endsWith(e,"[]")?e.slice(0,-2):e}function I(e,t,n){return e?e.concat(t).map(function(s,a){return s=W(s),!n&&a?"["+s+"]":s}).join(n?".":""):t}function Re(e){return l.isArray(e)&&!e.some(P)}var ge=l.toFlatObject(l,{},null,function(t){return /^is[A-Z]/.test(t)});function Te(e){return e&&l.isFunction(e.append)&&e[Symbol.toStringTag]==="FormData"&&e[Symbol.iterator]}function Ee(e,t,n){if(!l.isObject(e))throw new TypeError("target must be an object");t=t||new(H||FormData),n=l.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(i,d){return !l.isUndefined(d[i])});let o=n.metaTokens,s=n.visitor||f,a=n.dots,u=n.indexes,h=(n.Blob||typeof Blob!="undefined"&&Blob)&&Te(t);if(!l.isFunction(s))throw new TypeError("visitor must be a function");function c(r){if(r===null)return "";if(l.isDate(r))return r.toISOString();if(!h&&l.isBlob(r))throw new axios.AxiosError("Blob is not supported. Use a Buffer instead.");return l.isArrayBuffer(r)||l.isTypedArray(r)?h&&typeof Blob=="function"?new Blob([r]):Buffer.from(r):r}function f(r,i,d){let p=r;if(r&&!d&&typeof r=="object"){if(l.endsWith(i,"{}"))i=o?i:i.slice(0,-2),r=JSON.stringify(r);else if(l.isArray(r)&&Re(r)||l.isFileList(r)||l.endsWith(i,"[]")&&(p=l.toArray(r)))return i=W(i),p.forEach(function(x,S){!(l.isUndefined(x)||x===null)&&t.append(u===!0?I([i],S,a):u===null?i:i+"[]",c(x));}),!1}return P(r)?!0:(t.append(I(d,i,a),c(r)),!1)}let m=[],b=Object.assign(ge,{defaultVisitor:f,convertValue:c,isVisitable:P});function A(r,i){if(!l.isUndefined(r)){if(m.indexOf(r)!==-1)throw Error("Circular reference detected in "+i.join("."));m.push(r),l.forEach(r,function(p,w){(!(l.isUndefined(p)||p===null)&&s.call(t,p,l.isString(w)?w.trim():w,i,b))===!0&&A(p,i?i.concat(w):[w]);}),m.pop();}}if(!l.isObject(e))throw new TypeError("data must be an object");return A(e),t}var k=Ee;function z(e){let t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(o){return t[o]})}function K(e,t){this._pairs=[],e&&k(e,this,t);}var V=K.prototype;V.append=function(t){this._pairs.push([name,t]);};V.toString=function(t){let n=t?o=>t.call(this,o,z):z;return this._pairs.map(function(s){return n(s[0])+"="+n(s[1])},"").join("&")};var J=K;function Oe(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function B(e,t,n){if(!t)return e;let o=n&&n.encode||Oe,s=n&&n.serialize,a;if(s?a=s(t,n):a=l.isURLSearchParams(t)?t.toString():new J(t,n).toString(o),a){let u=e.indexOf("#");u!==-1&&(e=e.slice(0,u)),e+=(e.indexOf("?")===-1?"?":"&")+a;}return e}function L(e){return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function N(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}function v(e,t){return e&&!L(t)?N(e,t):t}function Ue(e,t){e=e||10;let n=new Array(e),o=new Array(e),s=0,a=0,u;return t=t!==void 0?t:1e3,function(h){let c=Date.now(),f=o[a];u||(u=c),n[s]=h,o[s]=c;let m=a,b=0;for(;m!==s;)b+=n[m++],m=m%e;if(s=(s+1)%e,s===a&&(a=(a+1)%e),c-u<t)return;let A=f&&c-f;return A?Math.round(b*1e3/A):void 0}}var G=Ue;var $=e=>{let{method:t="GET"}=e;switch(t.toLocaleLowerCase()){case"download":return "download";case"upload":return "upload";default:return "request"}},Q=e=>({...e}),T=(e,t)=>{var i,d,p,w,x;let n=e.data,o=e.responseType==="arraybuffer"?"arraybuffer":"text",s=o==="text"?"json":void 0,a=e.headers;if(e.auth){let S=e.auth.username||"",te=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";a.set("Authorization","Basic "+btoa(S+":"+te));}let u=v(e.baseURL,e.url),y=(d=(i=e==null?void 0:e.method)==null?void 0:i.toUpperCase())!=null?d:"GET",h=B(u,e.params,e.paramsSerializer),c=e.timeout||6e4,f=(p=e.withCredentials)!=null?p:!1,m=(w=e.sslVerify)!=null?w:!0,b=(x=e.firstIpv4)!=null?x:!1,A={};if(n&&typeof n=="string")try{A=JSON.parse(n);}catch(S){}let r=a.toJSON();return {...e,url:h,data:n,header:r,method:y,responseType:o,dataType:s,timeout:c,withCredentials:f,sslVerify:m,firstIpv4:b,formData:A}},Z=(e,t)=>{let n=0,o=G(50,250);return s=>{let a=s.totalBytesWritten,u=s.totalBytesExpectedToWrite,y=a-n,h=o(y),c=a<=u;n=a;let f={loaded:a,total:u,progress:u?a/u:void 0,bytes:y,rate:h||void 0,estimated:h&&u&&c?(u-a)/h:void 0,event:s};f[t?"download":"upload"]=!0,e(f);}};function g(e,t,n){let o=n.config.validateStatus;!n.status||!o||o(n.status)?e(n):t(new axios.AxiosError("Request failed with status code "+n.status,[axios.AxiosError.ERR_BAD_REQUEST,axios.AxiosError.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n));}var R=class{constructor(t){this.config=t;}subscribe(t,n){(this.config.cancelToken||this.config.signal)&&(this.onCanceled=o=>{!t||(n(!o||o.type?new axios.CanceledError(void 0,void 0,this.config,t):o),t.abort(),t=null);},this.config.cancelToken&&this.config.cancelToken.subscribe(this.onCanceled),this.config.signal&&this.config.signal.addEventListener&&(this.config.signal.aborted?this.onCanceled():this.config.signal.addEventListener("abort",this.onCanceled)));}unsubscribe(){this.config.cancelToken&&this.config.cancelToken.unsubscribe(this.onCanceled),this.config.signal&&this.config.signal.removeEventListener&&this.config.signal.removeEventListener("abort",this.onCanceled);}};var Se=(e,t)=>new Promise((n,o)=>{let{url:s,header:a,timeout:u,filePath:y}=T(e),h=new R(e),c=uni.downloadFile({url:s,header:a,timeout:u,filePath:y,success(f){var b;if(!c)return;let m={config:e,data:f.tempFilePath,headers:{},status:f.statusCode,statusText:(b=f.errMsg)!=null?b:"OK",request:c};g(n,o,m),c=null;},fail(f){let{errMsg:m=""}=f!=null?f:{};m&&(m==="downloadFile:fail timeout"&&o(new axios.AxiosError(m,axios.AxiosError.ETIMEDOUT,e,c)),m==="downloadFile:fail"&&o(new axios.AxiosError(m,axios.AxiosError.ERR_NETWORK,e,c))),o(new axios.AxiosError(f.errMsg,void 0,e,c)),c=null;},complete(){h.unsubscribe();}});typeof e.onDownloadProgress=="function"&&c.onProgressUpdate(Z(e.onDownloadProgress,!0)),typeof e.onHeadersReceived=="function"&&c.onHeadersReceived(e.onHeadersReceived),h.subscribe(c,o);}),X=Se;var Me=(e,t)=>new Promise((n,o)=>{let{url:s,files:a,fileType:u,file:y,filePath:h,name:c,header:f,timeout:m,formData:b}=T(e),A=new R(e),r=uni.uploadFile({url:s,files:a,fileType:u,file:y,filePath:h,name:c,header:f,timeout:m,formData:b,success(i){var p;if(!r)return;let d={config:e,data:i.data,headers:{},status:i.statusCode,statusText:(p=i.errMsg)!=null?p:"OK",request:r};g(n,o,d),r=null;},fail(i){let{errMsg:d=""}=i!=null?i:{};if(d){let p=d==="uploadFile:fail timeout",w=d==="uploadFile:fail file error";p&&o(new axios.AxiosError(d,axios.AxiosError.ETIMEDOUT,e,r)),w&&o(new axios.AxiosError(d,axios.AxiosError.ERR_NETWORK,e,r));}o(new axios.AxiosError(i.errMsg,void 0,e,r)),r=null;},complete(){A.unsubscribe();}});typeof e.onHeadersReceived=="function"&&r.onHeadersReceived(e.onHeadersReceived),A.subscribe(r,o);}),Y=Me;var Fe=(e,t)=>new Promise((n,o)=>{let{url:s,data:a,header:u,method:y,timeout:h,dataType:c,responseType:f,sslVerify:m,withCredentials:b,firstIpv4:A}=T(e),r=new R(e),i=uni.request({url:s,data:a,header:u,method:y,timeout:h,dataType:c,responseType:f,sslVerify:m,withCredentials:b,firstIpv4:A,success(d){var w;if(!i)return;let p={config:e,data:d.data,headers:d.header,status:d.statusCode,statusText:(w=d.errMsg)!=null?w:"OK",request:i,cookies:d.cookies};g(n,o,p),i=null;},fail(d){let{errMsg:p=""}=d!=null?d:{};if(p){let w=p==="request:fail timeout",x=p==="request:fail";w&&o(new axios.AxiosError(p,axios.AxiosError.ETIMEDOUT,e,i)),x&&o(new axios.AxiosError(p,axios.AxiosError.ERR_NETWORK,e,i));}o(new axios.AxiosError(d.errMsg,void 0,e,i)),i=null;},complete(){r.unsubscribe();}});typeof e.onHeadersReceived=="function"&&i.onHeadersReceived(e.onHeadersReceived),r.subscribe(i,o);}),j=Fe;var ee=e=>{switch($(e)){case"download":return X;case"upload":return Y;default:return j}};var Mt=(e={})=>{let t=Q(e);return o=>ee(o)(o,t)};
|
|
121
7
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
var import_settle = __toESM(require("axios/lib/core/settle"), 1);
|
|
125
|
-
|
|
126
|
-
// src/methods/onCanceled.ts
|
|
127
|
-
var import_axios = require("axios");
|
|
128
|
-
var OnCanceled = class {
|
|
129
|
-
constructor(config) {
|
|
130
|
-
this.config = config;
|
|
131
|
-
}
|
|
132
|
-
subscribe(task, reject) {
|
|
133
|
-
if (this.config.cancelToken || this.config.signal) {
|
|
134
|
-
this.onCanceled = (cancel) => {
|
|
135
|
-
if (!task) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
reject(
|
|
139
|
-
!cancel || cancel.type ? new import_axios.CanceledError(void 0, void 0, this.config, task) : cancel
|
|
140
|
-
);
|
|
141
|
-
task.abort();
|
|
142
|
-
task = null;
|
|
143
|
-
};
|
|
144
|
-
if (this.config.cancelToken) {
|
|
145
|
-
this.config.cancelToken.subscribe(this.onCanceled);
|
|
146
|
-
}
|
|
147
|
-
if (this.config.signal && this.config.signal.addEventListener) {
|
|
148
|
-
this.config.signal.aborted ? this.onCanceled() : this.config.signal.addEventListener("abort", this.onCanceled);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
unsubscribe() {
|
|
153
|
-
if (this.config.cancelToken) {
|
|
154
|
-
this.config.cancelToken.unsubscribe(this.onCanceled);
|
|
155
|
-
}
|
|
156
|
-
if (this.config.signal && this.config.signal.removeEventListener) {
|
|
157
|
-
this.config.signal.removeEventListener("abort", this.onCanceled);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// src/methods/download.ts
|
|
163
|
-
var download = (config, options) => {
|
|
164
|
-
return new Promise((resolve, reject) => {
|
|
165
|
-
const { url, header, timeout, filePath } = resolveUniAppRequestOptions(
|
|
166
|
-
config,
|
|
167
|
-
options
|
|
168
|
-
);
|
|
169
|
-
const onCanceled = new OnCanceled(config);
|
|
170
|
-
let task = uni.downloadFile({
|
|
171
|
-
url,
|
|
172
|
-
header,
|
|
173
|
-
timeout,
|
|
174
|
-
filePath,
|
|
175
|
-
success(result) {
|
|
176
|
-
if (!task) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const response = {
|
|
180
|
-
config,
|
|
181
|
-
data: result.tempFilePath,
|
|
182
|
-
headers: {},
|
|
183
|
-
status: result.statusCode,
|
|
184
|
-
statusText: result.errMsg ?? "OK",
|
|
185
|
-
request: task
|
|
186
|
-
};
|
|
187
|
-
(0, import_settle.default)(resolve, reject, response);
|
|
188
|
-
task = null;
|
|
189
|
-
},
|
|
190
|
-
fail(error) {
|
|
191
|
-
const { errMsg = "" } = error ?? {};
|
|
192
|
-
if (errMsg) {
|
|
193
|
-
const isTimeoutError = errMsg === "downloadFile:fail timeout";
|
|
194
|
-
if (isTimeoutError) {
|
|
195
|
-
reject(new import_axios2.AxiosError(errMsg, import_axios2.AxiosError.ETIMEDOUT, config, task));
|
|
196
|
-
}
|
|
197
|
-
const isNetworkError = errMsg === "downloadFile:fail";
|
|
198
|
-
if (isNetworkError) {
|
|
199
|
-
reject(
|
|
200
|
-
new import_axios2.AxiosError(errMsg, import_axios2.AxiosError.ERR_NETWORK, config, task)
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
reject(new import_axios2.AxiosError(error.errMsg, void 0, config, task));
|
|
205
|
-
task = null;
|
|
206
|
-
},
|
|
207
|
-
complete() {
|
|
208
|
-
onCanceled.unsubscribe();
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
if (typeof config.onDownloadProgress === "function") {
|
|
212
|
-
task.onProgressUpdate(
|
|
213
|
-
progressEventReducer(config.onDownloadProgress, true)
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
if (typeof config.onHeadersReceived === "function") {
|
|
217
|
-
task.onHeadersReceived(config.onHeadersReceived);
|
|
218
|
-
}
|
|
219
|
-
onCanceled.subscribe(task, reject);
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
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
|
-
var upload = (config, options) => {
|
|
228
|
-
return new Promise((resolve, reject) => {
|
|
229
|
-
const {
|
|
230
|
-
url,
|
|
231
|
-
files,
|
|
232
|
-
fileType,
|
|
233
|
-
file,
|
|
234
|
-
filePath,
|
|
235
|
-
name,
|
|
236
|
-
header,
|
|
237
|
-
timeout,
|
|
238
|
-
formData
|
|
239
|
-
} = resolveUniAppRequestOptions(config, options);
|
|
240
|
-
const onCanceled = new OnCanceled(config);
|
|
241
|
-
let task = uni.uploadFile({
|
|
242
|
-
url,
|
|
243
|
-
files,
|
|
244
|
-
fileType,
|
|
245
|
-
file,
|
|
246
|
-
filePath,
|
|
247
|
-
name,
|
|
248
|
-
header,
|
|
249
|
-
timeout,
|
|
250
|
-
formData,
|
|
251
|
-
success(result) {
|
|
252
|
-
if (!task) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
const response = {
|
|
256
|
-
config,
|
|
257
|
-
data: result.data,
|
|
258
|
-
headers: {},
|
|
259
|
-
status: result.statusCode,
|
|
260
|
-
statusText: result.errMsg ?? "OK",
|
|
261
|
-
request: task
|
|
262
|
-
};
|
|
263
|
-
(0, import_settle2.default)(resolve, reject, response);
|
|
264
|
-
task = null;
|
|
265
|
-
},
|
|
266
|
-
fail(error) {
|
|
267
|
-
const { errMsg = "" } = error ?? {};
|
|
268
|
-
if (errMsg) {
|
|
269
|
-
const isTimeoutError = errMsg === "uploadFile:fail timeout";
|
|
270
|
-
const isNetworkError = errMsg === "uploadFile:fail file error";
|
|
271
|
-
if (isTimeoutError) {
|
|
272
|
-
reject(new import_axios3.AxiosError(errMsg, import_axios3.AxiosError.ETIMEDOUT, config, task));
|
|
273
|
-
}
|
|
274
|
-
if (isNetworkError) {
|
|
275
|
-
reject(
|
|
276
|
-
new import_axios3.AxiosError(errMsg, import_axios3.AxiosError.ERR_NETWORK, config, task)
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
reject(new import_axios3.AxiosError(error.errMsg, void 0, config, task));
|
|
281
|
-
task = null;
|
|
282
|
-
},
|
|
283
|
-
complete() {
|
|
284
|
-
onCanceled.unsubscribe();
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
if (typeof config.onHeadersReceived === "function") {
|
|
288
|
-
task.onHeadersReceived(config.onHeadersReceived);
|
|
289
|
-
}
|
|
290
|
-
onCanceled.subscribe(task, reject);
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
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
|
-
var request = (config, options) => {
|
|
299
|
-
return new Promise((resolve, reject) => {
|
|
300
|
-
const {
|
|
301
|
-
url,
|
|
302
|
-
data,
|
|
303
|
-
header,
|
|
304
|
-
method,
|
|
305
|
-
timeout,
|
|
306
|
-
dataType,
|
|
307
|
-
responseType,
|
|
308
|
-
sslVerify,
|
|
309
|
-
withCredentials,
|
|
310
|
-
firstIpv4
|
|
311
|
-
} = resolveUniAppRequestOptions(config, options);
|
|
312
|
-
const onCanceled = new OnCanceled(config);
|
|
313
|
-
let task = uni.request({
|
|
314
|
-
url,
|
|
315
|
-
data,
|
|
316
|
-
header,
|
|
317
|
-
method,
|
|
318
|
-
timeout,
|
|
319
|
-
dataType,
|
|
320
|
-
responseType,
|
|
321
|
-
sslVerify,
|
|
322
|
-
withCredentials,
|
|
323
|
-
firstIpv4,
|
|
324
|
-
success(result) {
|
|
325
|
-
if (!task) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
const response = {
|
|
329
|
-
config,
|
|
330
|
-
data: result.data,
|
|
331
|
-
headers: result.header,
|
|
332
|
-
status: result.statusCode,
|
|
333
|
-
statusText: result.errMsg ?? "OK",
|
|
334
|
-
request: task,
|
|
335
|
-
cookies: result.cookies
|
|
336
|
-
};
|
|
337
|
-
(0, import_settle3.default)(resolve, reject, response);
|
|
338
|
-
task = null;
|
|
339
|
-
},
|
|
340
|
-
fail(error) {
|
|
341
|
-
const { errMsg = "" } = error ?? {};
|
|
342
|
-
if (errMsg) {
|
|
343
|
-
const isTimeoutError = errMsg === "request:fail timeout";
|
|
344
|
-
const isNetworkError = errMsg === "request:fail";
|
|
345
|
-
if (isTimeoutError) {
|
|
346
|
-
reject(new import_axios4.AxiosError(errMsg, import_axios4.AxiosError.ETIMEDOUT, config, task));
|
|
347
|
-
}
|
|
348
|
-
if (isNetworkError) {
|
|
349
|
-
reject(
|
|
350
|
-
new import_axios4.AxiosError(errMsg, import_axios4.AxiosError.ERR_NETWORK, config, task)
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
reject(new import_axios4.AxiosError(error.errMsg, void 0, config, task));
|
|
355
|
-
task = null;
|
|
356
|
-
},
|
|
357
|
-
complete() {
|
|
358
|
-
onCanceled.unsubscribe();
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
if (typeof config.onHeadersReceived === "function") {
|
|
362
|
-
task.onHeadersReceived(config.onHeadersReceived);
|
|
363
|
-
}
|
|
364
|
-
onCanceled.subscribe(task, reject);
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
var request_default = request;
|
|
368
|
-
|
|
369
|
-
// src/methods/index.ts
|
|
370
|
-
var getMethod = (config) => {
|
|
371
|
-
const methodType = getMethodType(config);
|
|
372
|
-
switch (methodType) {
|
|
373
|
-
case "download":
|
|
374
|
-
return download_default;
|
|
375
|
-
case "upload":
|
|
376
|
-
return upload_default;
|
|
377
|
-
default:
|
|
378
|
-
return request_default;
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// src/index.ts
|
|
383
|
-
var createUniAppAxiosAdapter = (userOptions = {}) => {
|
|
384
|
-
const options = resolveOptions(userOptions);
|
|
385
|
-
const uniappAdapter = (config) => {
|
|
386
|
-
const method = getMethod(config);
|
|
387
|
-
return method(config, options);
|
|
388
|
-
};
|
|
389
|
-
return uniappAdapter;
|
|
390
|
-
};
|
|
391
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
392
|
-
0 && (module.exports = {
|
|
393
|
-
createUniAppAxiosAdapter
|
|
394
|
-
});
|
|
8
|
+
exports.createUniAppAxiosAdapter = Mt;
|
|
9
|
+
//# sourceMappingURL=out.js.map
|
|
395
10
|
//# sourceMappingURL=index.cjs.map
|