@whitesev/utils 2.4.1 → 2.4.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/LICENSE +674 -0
- package/dist/index.amd.js +66 -58
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +66 -58
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +66 -58
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +66 -58
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +66 -58
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +66 -58
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +4 -4
- package/dist/types/src/types/Httpx.d.ts +7 -0
- package/package.json +1 -1
- package/src/Httpx.ts +92 -83
- package/src/Utils.ts +1 -1
- package/src/types/Httpx.d.ts +7 -0
package/dist/index.umd.js
CHANGED
|
@@ -1541,7 +1541,7 @@
|
|
|
1541
1541
|
* @param details 当前的请求配置
|
|
1542
1542
|
* @private
|
|
1543
1543
|
*/
|
|
1544
|
-
beforeRequestCallBack(details) {
|
|
1544
|
+
async beforeRequestCallBack(details) {
|
|
1545
1545
|
if (typeof details.allowInterceptConfig === "boolean") {
|
|
1546
1546
|
if (!details.allowInterceptConfig) {
|
|
1547
1547
|
// 不允许拦截
|
|
@@ -1562,7 +1562,7 @@
|
|
|
1562
1562
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1563
1563
|
let item = this.$config.configList[index];
|
|
1564
1564
|
if (typeof item.fn === "function") {
|
|
1565
|
-
let result = item.fn(details);
|
|
1565
|
+
let result = await item.fn(details);
|
|
1566
1566
|
if (result == null) {
|
|
1567
1567
|
return;
|
|
1568
1568
|
}
|
|
@@ -1619,7 +1619,7 @@
|
|
|
1619
1619
|
* @param response 响应
|
|
1620
1620
|
* @param details 请求的配置
|
|
1621
1621
|
*/
|
|
1622
|
-
successResponseCallBack(response, details) {
|
|
1622
|
+
async successResponseCallBack(response, details) {
|
|
1623
1623
|
if (typeof details.allowInterceptConfig === "boolean") {
|
|
1624
1624
|
if (!details.allowInterceptConfig) {
|
|
1625
1625
|
// 不允许拦截
|
|
@@ -1641,7 +1641,8 @@
|
|
|
1641
1641
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1642
1642
|
let item = this.$config.configList[index];
|
|
1643
1643
|
if (typeof item.successFn === "function") {
|
|
1644
|
-
|
|
1644
|
+
let result = await item.successFn(response, details);
|
|
1645
|
+
if (result == null) {
|
|
1645
1646
|
return;
|
|
1646
1647
|
}
|
|
1647
1648
|
}
|
|
@@ -1654,7 +1655,7 @@
|
|
|
1654
1655
|
* @returns
|
|
1655
1656
|
* 返回null|undefined就是拦截掉了
|
|
1656
1657
|
*/
|
|
1657
|
-
errorResponseCallBack(data) {
|
|
1658
|
+
async errorResponseCallBack(data) {
|
|
1658
1659
|
if (typeof data.details.allowInterceptConfig === "boolean") {
|
|
1659
1660
|
if (!data.details.allowInterceptConfig) {
|
|
1660
1661
|
// 不允许拦截
|
|
@@ -1676,7 +1677,8 @@
|
|
|
1676
1677
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1677
1678
|
let item = this.$config.configList[index];
|
|
1678
1679
|
if (typeof item.errorFn === "function") {
|
|
1679
|
-
|
|
1680
|
+
let result = await item.errorFn(data);
|
|
1681
|
+
if (result == null) {
|
|
1680
1682
|
return;
|
|
1681
1683
|
}
|
|
1682
1684
|
}
|
|
@@ -1716,7 +1718,7 @@
|
|
|
1716
1718
|
this.$config.configList = [];
|
|
1717
1719
|
},
|
|
1718
1720
|
};
|
|
1719
|
-
|
|
1721
|
+
HttpxRequestOption = {
|
|
1720
1722
|
context: this,
|
|
1721
1723
|
/**
|
|
1722
1724
|
* 根据传入的参数处理获取details配置
|
|
@@ -2064,7 +2066,7 @@
|
|
|
2064
2066
|
* @param reject 抛出错误
|
|
2065
2067
|
* @param argsResult 返回的参数列表
|
|
2066
2068
|
*/
|
|
2067
|
-
onAbort(details, resolve, reject, argsResult) {
|
|
2069
|
+
async onAbort(details, resolve, reject, argsResult) {
|
|
2068
2070
|
// console.log(argsResult);
|
|
2069
2071
|
if ("onabort" in details) {
|
|
2070
2072
|
details.onabort.apply(this, argsResult);
|
|
@@ -2076,12 +2078,12 @@
|
|
|
2076
2078
|
if (response.length) {
|
|
2077
2079
|
response = response[0];
|
|
2078
2080
|
}
|
|
2079
|
-
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2081
|
+
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2080
2082
|
type: "onabort",
|
|
2081
2083
|
error: new TypeError("request canceled"),
|
|
2082
2084
|
response: null,
|
|
2083
2085
|
details: details,
|
|
2084
|
-
}) == null) {
|
|
2086
|
+
})) == null) {
|
|
2085
2087
|
// reject(new TypeError("response is intercept with onabort"));
|
|
2086
2088
|
return;
|
|
2087
2089
|
}
|
|
@@ -2101,7 +2103,7 @@
|
|
|
2101
2103
|
* @param reject 抛出错误
|
|
2102
2104
|
* @param argsResult 返回的参数列表
|
|
2103
2105
|
*/
|
|
2104
|
-
onError(details, resolve, reject, argsResult) {
|
|
2106
|
+
async onError(details, resolve, reject, argsResult) {
|
|
2105
2107
|
// console.log(argsResult);
|
|
2106
2108
|
if ("onerror" in details) {
|
|
2107
2109
|
details.onerror.apply(this, argsResult);
|
|
@@ -2113,12 +2115,12 @@
|
|
|
2113
2115
|
if (response.length) {
|
|
2114
2116
|
response = response[0];
|
|
2115
2117
|
}
|
|
2116
|
-
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2118
|
+
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2117
2119
|
type: "onerror",
|
|
2118
2120
|
error: new TypeError("request error"),
|
|
2119
2121
|
response: response,
|
|
2120
2122
|
details: details,
|
|
2121
|
-
}) == null) {
|
|
2123
|
+
})) == null) {
|
|
2122
2124
|
// reject(new TypeError("response is intercept with onerror"));
|
|
2123
2125
|
return;
|
|
2124
2126
|
}
|
|
@@ -2138,7 +2140,7 @@
|
|
|
2138
2140
|
* @param reject 抛出错误
|
|
2139
2141
|
* @param argsResult 返回的参数列表
|
|
2140
2142
|
*/
|
|
2141
|
-
onTimeout(details, resolve, reject, argsResult) {
|
|
2143
|
+
async onTimeout(details, resolve, reject, argsResult) {
|
|
2142
2144
|
// console.log(argsResult);
|
|
2143
2145
|
if ("ontimeout" in details) {
|
|
2144
2146
|
details.ontimeout.apply(this, argsResult);
|
|
@@ -2150,12 +2152,12 @@
|
|
|
2150
2152
|
if (response.length) {
|
|
2151
2153
|
response = response[0];
|
|
2152
2154
|
}
|
|
2153
|
-
if (this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2155
|
+
if ((await this.context.HttpxResponseHook.errorResponseCallBack({
|
|
2154
2156
|
type: "ontimeout",
|
|
2155
2157
|
error: new TypeError("request timeout"),
|
|
2156
2158
|
response: (argsResult || [null])[0],
|
|
2157
2159
|
details: details,
|
|
2158
|
-
}) == null) {
|
|
2160
|
+
})) == null) {
|
|
2159
2161
|
// reject(new TypeError("response is intercept with ontimeout"));
|
|
2160
2162
|
return;
|
|
2161
2163
|
}
|
|
@@ -2189,7 +2191,7 @@
|
|
|
2189
2191
|
* @param reject 抛出错误
|
|
2190
2192
|
* @param argsResult 返回的参数列表
|
|
2191
2193
|
*/
|
|
2192
|
-
onLoad(details, resolve, reject, argsResult) {
|
|
2194
|
+
async onLoad(details, resolve, reject, argsResult) {
|
|
2193
2195
|
// console.log(argsResult);
|
|
2194
2196
|
/* X浏览器会因为设置了responseType导致不返回responseText */
|
|
2195
2197
|
let originResponse = argsResult[0];
|
|
@@ -2260,7 +2262,7 @@
|
|
|
2260
2262
|
}
|
|
2261
2263
|
/* 状态码2xx都是成功的 */
|
|
2262
2264
|
if (Math.floor(originResponse.status / 100) === 2) {
|
|
2263
|
-
if (this.context.HttpxResponseHook.successResponseCallBack(originResponse, details) == null) {
|
|
2265
|
+
if ((await this.context.HttpxResponseHook.successResponseCallBack(originResponse, details)) == null) {
|
|
2264
2266
|
// reject(new TypeError("response is intercept with onloada"));
|
|
2265
2267
|
return;
|
|
2266
2268
|
}
|
|
@@ -2312,20 +2314,20 @@
|
|
|
2312
2314
|
* 发送请求
|
|
2313
2315
|
* @param details
|
|
2314
2316
|
*/
|
|
2315
|
-
request(details) {
|
|
2317
|
+
async request(details) {
|
|
2316
2318
|
if (this.context.#LOG_DETAILS) {
|
|
2317
2319
|
console.log("[Httpx-HttpxRequest.request] 请求前的配置👇", details);
|
|
2318
2320
|
}
|
|
2319
2321
|
if (typeof this.context.HttpxRequestHook.beforeRequestCallBack ===
|
|
2320
2322
|
"function") {
|
|
2321
|
-
let hookResult = this.context.HttpxRequestHook.beforeRequestCallBack(details);
|
|
2323
|
+
let hookResult = await this.context.HttpxRequestHook.beforeRequestCallBack(details);
|
|
2322
2324
|
if (hookResult == null) {
|
|
2323
2325
|
return;
|
|
2324
2326
|
}
|
|
2325
2327
|
}
|
|
2326
2328
|
if (details.fetch) {
|
|
2327
2329
|
// 使用fetch请求
|
|
2328
|
-
const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.
|
|
2330
|
+
const { fetchOption: fetchOption, fetchRequestOption: fetchRequestOption, abortController, } = this.context.HttpxRequestOption.handleFetchOption(details);
|
|
2329
2331
|
return this.fetch(fetchOption, fetchRequestOption, abortController);
|
|
2330
2332
|
}
|
|
2331
2333
|
else {
|
|
@@ -2613,15 +2615,15 @@
|
|
|
2613
2615
|
* @param url 网址
|
|
2614
2616
|
* @param details 配置
|
|
2615
2617
|
*/
|
|
2616
|
-
|
|
2618
|
+
get(...args // @ts-ignore
|
|
2617
2619
|
) {
|
|
2618
|
-
let userRequestOption = this.
|
|
2620
|
+
let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
|
|
2619
2621
|
let abortFn = null;
|
|
2620
|
-
let promise = new globalThis.Promise((resolve, reject) => {
|
|
2621
|
-
let requestOption = this.
|
|
2622
|
+
let promise = new globalThis.Promise(async (resolve, reject) => {
|
|
2623
|
+
let requestOption = this.HttpxRequestOption.getRequestOption("GET", userRequestOption, resolve, reject);
|
|
2622
2624
|
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2623
|
-
this.
|
|
2624
|
-
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2625
|
+
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
2626
|
+
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
2625
2627
|
if (requestResult != null &&
|
|
2626
2628
|
typeof requestResult.abort === "function") {
|
|
2627
2629
|
abortFn = requestResult.abort;
|
|
@@ -2633,21 +2635,22 @@
|
|
|
2633
2635
|
abortFn();
|
|
2634
2636
|
}
|
|
2635
2637
|
};
|
|
2638
|
+
// @ts-ignore
|
|
2636
2639
|
return promise;
|
|
2637
2640
|
}
|
|
2638
2641
|
/**
|
|
2639
2642
|
* POST 请求
|
|
2640
2643
|
*/
|
|
2641
|
-
|
|
2644
|
+
post(...args // @ts-ignore
|
|
2642
2645
|
) {
|
|
2643
|
-
let userRequestOption = this.
|
|
2646
|
+
let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
|
|
2644
2647
|
let abortFn = null;
|
|
2645
|
-
let promise = new Promise((resolve, reject) => {
|
|
2646
|
-
let requestOption = this.
|
|
2648
|
+
let promise = new Promise(async (resolve, reject) => {
|
|
2649
|
+
let requestOption = this.HttpxRequestOption.getRequestOption("POST", userRequestOption, resolve, reject);
|
|
2647
2650
|
// @ts-ignore
|
|
2648
2651
|
requestOption =
|
|
2649
|
-
this.
|
|
2650
|
-
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2652
|
+
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
2653
|
+
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
2651
2654
|
if (requestResult != null &&
|
|
2652
2655
|
typeof requestResult.abort === "function") {
|
|
2653
2656
|
abortFn = requestResult.abort;
|
|
@@ -2659,22 +2662,23 @@
|
|
|
2659
2662
|
abortFn();
|
|
2660
2663
|
}
|
|
2661
2664
|
};
|
|
2665
|
+
// @ts-ignore
|
|
2662
2666
|
return promise;
|
|
2663
2667
|
}
|
|
2664
2668
|
/**
|
|
2665
2669
|
* HEAD 请求
|
|
2666
2670
|
*/
|
|
2667
|
-
|
|
2671
|
+
head(...args // @ts-ignore
|
|
2668
2672
|
) {
|
|
2669
|
-
let userRequestOption = this.
|
|
2673
|
+
let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
|
|
2670
2674
|
let abortFn = null;
|
|
2671
|
-
let promise = new Promise((resolve, reject) => {
|
|
2672
|
-
let requestOption = this.
|
|
2675
|
+
let promise = new Promise(async (resolve, reject) => {
|
|
2676
|
+
let requestOption = this.HttpxRequestOption.getRequestOption("HEAD", userRequestOption, resolve, reject);
|
|
2673
2677
|
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2674
2678
|
// @ts-ignore
|
|
2675
2679
|
requestOption =
|
|
2676
|
-
this.
|
|
2677
|
-
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2680
|
+
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
2681
|
+
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
2678
2682
|
if (requestResult != null &&
|
|
2679
2683
|
typeof requestResult.abort === "function") {
|
|
2680
2684
|
abortFn = requestResult.abort;
|
|
@@ -2686,22 +2690,23 @@
|
|
|
2686
2690
|
abortFn();
|
|
2687
2691
|
}
|
|
2688
2692
|
};
|
|
2693
|
+
// @ts-ignore
|
|
2689
2694
|
return promise;
|
|
2690
2695
|
}
|
|
2691
2696
|
/**
|
|
2692
2697
|
* OPTIONS 请求
|
|
2693
2698
|
*/
|
|
2694
|
-
|
|
2699
|
+
options(...args // @ts-ignore
|
|
2695
2700
|
) {
|
|
2696
|
-
let userRequestOption = this.
|
|
2701
|
+
let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
|
|
2697
2702
|
let abortFn = null;
|
|
2698
|
-
let promise = new Promise((resolve, reject) => {
|
|
2699
|
-
let requestOption = this.
|
|
2703
|
+
let promise = new Promise(async (resolve, reject) => {
|
|
2704
|
+
let requestOption = this.HttpxRequestOption.getRequestOption("OPTIONS", userRequestOption, resolve, reject);
|
|
2700
2705
|
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2701
2706
|
// @ts-ignore
|
|
2702
2707
|
requestOption =
|
|
2703
|
-
this.
|
|
2704
|
-
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2708
|
+
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
2709
|
+
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
2705
2710
|
if (requestResult != null &&
|
|
2706
2711
|
typeof requestResult.abort === "function") {
|
|
2707
2712
|
abortFn = requestResult.abort;
|
|
@@ -2713,22 +2718,23 @@
|
|
|
2713
2718
|
abortFn();
|
|
2714
2719
|
}
|
|
2715
2720
|
};
|
|
2721
|
+
// @ts-ignore
|
|
2716
2722
|
return promise;
|
|
2717
2723
|
}
|
|
2718
2724
|
/**
|
|
2719
2725
|
* DELETE 请求
|
|
2720
2726
|
*/
|
|
2721
|
-
|
|
2727
|
+
delete(...args // @ts-ignore
|
|
2722
2728
|
) {
|
|
2723
|
-
let userRequestOption = this.
|
|
2729
|
+
let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
|
|
2724
2730
|
let abortFn = null;
|
|
2725
|
-
let promise = new Promise((resolve, reject) => {
|
|
2726
|
-
let requestOption = this.
|
|
2731
|
+
let promise = new Promise(async (resolve, reject) => {
|
|
2732
|
+
let requestOption = this.HttpxRequestOption.getRequestOption("DELETE", userRequestOption, resolve, reject);
|
|
2727
2733
|
Reflect.deleteProperty(requestOption, "onprogress");
|
|
2728
2734
|
// @ts-ignore
|
|
2729
2735
|
requestOption =
|
|
2730
|
-
this.
|
|
2731
|
-
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2736
|
+
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
2737
|
+
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
2732
2738
|
if (requestResult != null &&
|
|
2733
2739
|
typeof requestResult.abort === "function") {
|
|
2734
2740
|
abortFn = requestResult.abort;
|
|
@@ -2740,21 +2746,22 @@
|
|
|
2740
2746
|
abortFn();
|
|
2741
2747
|
}
|
|
2742
2748
|
};
|
|
2749
|
+
// @ts-ignore
|
|
2743
2750
|
return promise;
|
|
2744
2751
|
}
|
|
2745
2752
|
/**
|
|
2746
2753
|
* PUT 请求
|
|
2747
2754
|
*/
|
|
2748
|
-
|
|
2755
|
+
put(...args // @ts-ignore
|
|
2749
2756
|
) {
|
|
2750
|
-
let userRequestOption = this.
|
|
2757
|
+
let userRequestOption = this.HttpxRequestOption.handleBeforeRequestOption(...args);
|
|
2751
2758
|
let abortFn = null;
|
|
2752
|
-
let promise = new Promise((resolve, reject) => {
|
|
2753
|
-
let requestOption = this.
|
|
2759
|
+
let promise = new Promise(async (resolve, reject) => {
|
|
2760
|
+
let requestOption = this.HttpxRequestOption.getRequestOption("PUT", userRequestOption, resolve, reject);
|
|
2754
2761
|
// @ts-ignore
|
|
2755
2762
|
requestOption =
|
|
2756
|
-
this.
|
|
2757
|
-
const requestResult = this.HttpxRequest.request(requestOption);
|
|
2763
|
+
this.HttpxRequestOption.removeRequestNullOption(requestOption);
|
|
2764
|
+
const requestResult = await this.HttpxRequest.request(requestOption);
|
|
2758
2765
|
if (requestResult != null &&
|
|
2759
2766
|
typeof requestResult.abort === "function") {
|
|
2760
2767
|
abortFn = requestResult.abort;
|
|
@@ -2766,6 +2773,7 @@
|
|
|
2766
2773
|
abortFn();
|
|
2767
2774
|
}
|
|
2768
2775
|
};
|
|
2776
|
+
// @ts-ignore
|
|
2769
2777
|
return promise;
|
|
2770
2778
|
}
|
|
2771
2779
|
}
|
|
@@ -4070,7 +4078,7 @@
|
|
|
4070
4078
|
this.windowApi = new WindowApi(option);
|
|
4071
4079
|
}
|
|
4072
4080
|
/** 版本号 */
|
|
4073
|
-
version = "2024.10.
|
|
4081
|
+
version = "2024.10.31";
|
|
4074
4082
|
addStyle(cssText) {
|
|
4075
4083
|
if (typeof cssText !== "string") {
|
|
4076
4084
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|