@whitesev/utils 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +7 -6
- package/package.json +1 -1
- package/src/Httpx.ts +11 -7
package/dist/src/Httpx.d.ts
CHANGED
|
@@ -1105,6 +1105,11 @@ export declare interface HttpxAsyncResult<T = HttpxDetails> {
|
|
|
1105
1105
|
*/
|
|
1106
1106
|
type: HttpxResponseCallBackType;
|
|
1107
1107
|
}
|
|
1108
|
+
export declare interface HttpxHookErrorData {
|
|
1109
|
+
type: "onerror" | "ontimeout" | "onabort";
|
|
1110
|
+
error: Error;
|
|
1111
|
+
response: any;
|
|
1112
|
+
}
|
|
1108
1113
|
declare class Httpx {
|
|
1109
1114
|
#private;
|
|
1110
1115
|
private GM_Api;
|
|
@@ -1134,7 +1139,7 @@ declare class Httpx {
|
|
|
1134
1139
|
* 添加拦截器
|
|
1135
1140
|
* @param fn 设置的请求前回调函数,如果返回配置,则使用返回的配置,如果返回null|undefined,则阻止请求
|
|
1136
1141
|
*/
|
|
1137
|
-
use(fn: (details:
|
|
1142
|
+
use(fn: <T extends Required<HttpxDetails>>(details: T) => void | T): string | undefined;
|
|
1138
1143
|
/**
|
|
1139
1144
|
* 移除拦截器
|
|
1140
1145
|
* @param id 通过use返回的id
|
|
@@ -1157,11 +1162,7 @@ declare class Httpx {
|
|
|
1157
1162
|
* @param errorFn 设置的响应后回调函数,如果返回响应,则使用返回的响应,如果返回null|undefined,则阻止响应
|
|
1158
1163
|
* + 超出 2xx 范围的状态码都会触发该函数
|
|
1159
1164
|
*/
|
|
1160
|
-
use(successFn?: (response: HttpxAsyncResultData) => void, errorFn?: (data:
|
|
1161
|
-
type: "onerror" | "ontimeout" | "onabort";
|
|
1162
|
-
error: Error;
|
|
1163
|
-
response: any;
|
|
1164
|
-
}) => void): string | undefined;
|
|
1165
|
+
use(successFn?: (<T_1 extends HttpxAsyncResultData<HttpxDetails>>(response: HttpxAsyncResultData) => void | T_1) | undefined, errorFn?: (<T_2 extends HttpxHookErrorData>(data: T_2) => void | T_2) | undefined): string | undefined;
|
|
1165
1166
|
/**
|
|
1166
1167
|
* 移除拦截器
|
|
1167
1168
|
* @param id 通过use返回的id
|
package/package.json
CHANGED
package/src/Httpx.ts
CHANGED
|
@@ -1202,6 +1202,12 @@ export declare interface HttpxAsyncResult<T = HttpxDetails> {
|
|
|
1202
1202
|
type: HttpxResponseCallBackType;
|
|
1203
1203
|
}
|
|
1204
1204
|
|
|
1205
|
+
export declare interface HttpxHookErrorData {
|
|
1206
|
+
type: "onerror" | "ontimeout" | "onabort";
|
|
1207
|
+
error: Error;
|
|
1208
|
+
response: any;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1205
1211
|
const GenerateUUID = () => {
|
|
1206
1212
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
1207
1213
|
var r = (Math.random() * 16) | 0,
|
|
@@ -2076,7 +2082,7 @@ class Httpx {
|
|
|
2076
2082
|
* 添加拦截器
|
|
2077
2083
|
* @param fn 设置的请求前回调函数,如果返回配置,则使用返回的配置,如果返回null|undefined,则阻止请求
|
|
2078
2084
|
*/
|
|
2079
|
-
use(fn: (details:
|
|
2085
|
+
use(fn: <T extends Required<HttpxDetails>>(details: T) => void | T) {
|
|
2080
2086
|
if (typeof fn !== "function") {
|
|
2081
2087
|
console.warn("[Httpx-interceptors-request] 请传入拦截器函数");
|
|
2082
2088
|
return;
|
|
@@ -2110,12 +2116,10 @@ class Httpx {
|
|
|
2110
2116
|
* + 超出 2xx 范围的状态码都会触发该函数
|
|
2111
2117
|
*/
|
|
2112
2118
|
use(
|
|
2113
|
-
successFn?:
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
response: any;
|
|
2118
|
-
}) => void
|
|
2119
|
+
successFn?: <T extends HttpxAsyncResultData>(
|
|
2120
|
+
response: HttpxAsyncResultData
|
|
2121
|
+
) => void | T,
|
|
2122
|
+
errorFn?: <T extends HttpxHookErrorData>(data: T) => void | T
|
|
2119
2123
|
) {
|
|
2120
2124
|
if (typeof successFn !== "function" && typeof errorFn !== "function") {
|
|
2121
2125
|
console.warn("[Httpx-interceptors-response] 必须传入一个拦截器函数");
|