@seayoo-web/request 3.1.5 → 3.2.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/README.md +9 -10
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/node.cjs +1 -1
- package/dist/node.js +3 -3
- package/dist/{request.fetch-hlpQxV81.cjs → request.fetch-Clr0F0uQ.cjs} +1 -1
- package/dist/{request.fetch-1poQOlEV.js → request.fetch-D8zNsNGx.js} +1 -1
- package/dist/retry-CsPcCrZK.cjs +3 -0
- package/dist/{retry-_AqXIa5P.js → retry-DQlh3z7q.js} +194 -223
- package/dist/wx.cjs +1 -1
- package/dist/wx.js +2 -2
- package/package.json +2 -2
- package/types/inc/type.d.ts +3 -3
- package/dist/retry-8pExkGke.cjs +0 -3
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var v = (e, t, s) =>
|
|
4
|
-
var
|
|
1
|
+
var rt = Object.defineProperty;
|
|
2
|
+
var nt = (e, t, s) => t in e ? rt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
3
|
+
var v = (e, t, s) => nt(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
var it = Object.defineProperty, ot = (e, t, s) => t in e ? it(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, o = (e, t, s) => ot(e, typeof t != "symbol" ? t + "" : t, s);
|
|
5
5
|
const u = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), j = {
|
|
6
|
-
wx: "wx" in u && x(u.wx) && "getSystemInfo" in u.wx &&
|
|
7
|
-
fetch: "fetch" in u &&
|
|
6
|
+
wx: "wx" in u && x(u.wx) && "getSystemInfo" in u.wx && m(u.wx.getSystemInfo),
|
|
7
|
+
fetch: "fetch" in u && m(u.fetch),
|
|
8
8
|
window: "window" in u && x(u.window),
|
|
9
|
-
requestAnimationFrame: "requestAnimationFrame" in u &&
|
|
10
|
-
localStorage: "localStorage" in u && x(u.localStorage) && "getItem" in u.localStorage &&
|
|
11
|
-
sessionStorage: "sessionStorage" in u && x(u.sessionStorage) && "getItem" in u.sessionStorage &&
|
|
12
|
-
File: "File" in u &&
|
|
13
|
-
Blob: "Blob" in u &&
|
|
14
|
-
Proxy: "Proxy" in u &&
|
|
15
|
-
Request: "Request" in u &&
|
|
16
|
-
FormData: "FormData" in u &&
|
|
17
|
-
TextDecoder: "TextDecoder" in u &&
|
|
18
|
-
ResizeObserver: "ResizeObserver" in u &&
|
|
19
|
-
AbortController: "AbortController" in u &&
|
|
20
|
-
URLSearchParams: "URLSearchParams" in u &&
|
|
9
|
+
requestAnimationFrame: "requestAnimationFrame" in u && m(u.requestAnimationFrame),
|
|
10
|
+
localStorage: "localStorage" in u && x(u.localStorage) && "getItem" in u.localStorage && m(u.localStorage.getItem),
|
|
11
|
+
sessionStorage: "sessionStorage" in u && x(u.sessionStorage) && "getItem" in u.sessionStorage && m(u.sessionStorage.getItem),
|
|
12
|
+
File: "File" in u && m(u.File),
|
|
13
|
+
Blob: "Blob" in u && m(u.Blob),
|
|
14
|
+
Proxy: "Proxy" in u && m(u.Proxy),
|
|
15
|
+
Request: "Request" in u && m(u.Request),
|
|
16
|
+
FormData: "FormData" in u && m(u.FormData),
|
|
17
|
+
TextDecoder: "TextDecoder" in u && m(u.TextDecoder),
|
|
18
|
+
ResizeObserver: "ResizeObserver" in u && m(u.ResizeObserver),
|
|
19
|
+
AbortController: "AbortController" in u && m(u.AbortController),
|
|
20
|
+
URLSearchParams: "URLSearchParams" in u && m(u.URLSearchParams)
|
|
21
21
|
};
|
|
22
|
-
function
|
|
22
|
+
function m(e) {
|
|
23
23
|
return typeof e == "function";
|
|
24
24
|
}
|
|
25
25
|
function x(e) {
|
|
26
26
|
return typeof e == "object" && e !== null;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function at(e) {
|
|
29
29
|
return new Promise((t) => setTimeout(t, Math.max(0, e)));
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function X() {
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function Q(e, t) {
|
|
34
34
|
const s = {
|
|
35
35
|
log: console.log.bind(console),
|
|
36
36
|
error: console.error.bind(console),
|
|
@@ -43,7 +43,7 @@ function rt(e, t) {
|
|
|
43
43
|
};
|
|
44
44
|
}), s;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function lt(e) {
|
|
47
47
|
const t = e || "CustomError";
|
|
48
48
|
return class extends Error {
|
|
49
49
|
constructor(s) {
|
|
@@ -55,28 +55,28 @@ function mt(e) {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
const
|
|
59
|
-
function
|
|
58
|
+
const ut = /^(?:https?:)?\/\/.+$/i, ht = /^https?:\/\/.+$/i, ct = /^\{[\d\D]*\}$/, ft = /^\[[\d\D]*\]$/;
|
|
59
|
+
function dt(e) {
|
|
60
60
|
return typeof e == "string";
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
return t ?
|
|
62
|
+
function P(e, t = !1) {
|
|
63
|
+
return t ? ut.test(e) : ht.test(e);
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function mt(e) {
|
|
66
66
|
return e == null;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function Y(e, ...t) {
|
|
69
69
|
return e !== null && typeof e == "object" && !(e instanceof Map) && !(e instanceof Set) && !(e instanceof WeakMap) && !(e instanceof WeakSet) && !Array.isArray(e) && t.every((s) => s in e);
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function k(e, ...t) {
|
|
72
72
|
if (!e || typeof e != "object") return !1;
|
|
73
73
|
const s = Object.getPrototypeOf(e);
|
|
74
74
|
return s !== Object.prototype && s !== null ? !1 : t.every((r) => r in e);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function I(e, t) {
|
|
77
77
|
return Array.isArray(e) && e.every((s) => t(s));
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function F(e) {
|
|
80
80
|
if (typeof e != "number" || Number.isNaN(e) || !Number.isFinite(e) || Number.isInteger(e) && !Number.isSafeInteger(e))
|
|
81
81
|
return !1;
|
|
82
82
|
if (e === 0)
|
|
@@ -84,25 +84,14 @@ function U(e) {
|
|
|
84
84
|
const t = Math.abs(e);
|
|
85
85
|
return t >= Number.EPSILON && t <= Number.MAX_SAFE_INTEGER;
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
87
|
+
function tt(e) {
|
|
88
|
+
return ct.test(e) || ft.test(e);
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function _t(e, t = 20) {
|
|
91
91
|
const s = Math.max(t, 10), r = [...e];
|
|
92
92
|
return r.length <= s ? e : r.slice(0, s - 3).join("") + "...";
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
return e ? e[0].toLowerCase() + e.slice(1) : "";
|
|
96
|
-
}
|
|
97
|
-
const ot = /_\w*/, at = /-\w*/;
|
|
98
|
-
function Z(e) {
|
|
99
|
-
const t = ot.test(e) ? e.replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (s, r) => r.toUpperCase()) : at.test(e) ? e.replace(/(?:^-*|-*$)/g, "").replace(/-+(\w)/g, (s, r) => r.toUpperCase()) : e;
|
|
100
|
-
return O(t);
|
|
101
|
-
}
|
|
102
|
-
function X(e) {
|
|
103
|
-
return ot.test(e) ? O(e).replace(/(?:^_*|_*$)/g, "").replace(/_+([^_])/g, (t, s) => "_" + s.toLowerCase()) : at.test(e) ? O(e.replace(/(?:^-*|-*$)/g, "")).replace(/-+(\w)/g, (t, s) => "_" + s.toLowerCase()) : O(e).replace(/[A-Z]/g, (t) => `_${t.toLowerCase()}`);
|
|
104
|
-
}
|
|
105
|
-
function M(e, t) {
|
|
94
|
+
function S(e, t) {
|
|
106
95
|
try {
|
|
107
96
|
const s = JSON.parse(e);
|
|
108
97
|
return t ? t(s) ? s : null : s;
|
|
@@ -111,26 +100,8 @@ function M(e, t) {
|
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
102
|
"" + Math.random().toString(32).slice(2);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(s, r) => {
|
|
117
|
-
const n = Z(String(r)), i = n.charAt(0).toLowerCase() + n.slice(1);
|
|
118
|
-
return s[i] = t ? e[r] : A(e[r]), s;
|
|
119
|
-
},
|
|
120
|
-
{}
|
|
121
|
-
) : e;
|
|
122
|
-
}
|
|
123
|
-
function F(e, t = !1) {
|
|
124
|
-
return typeof e == "string" ? X(e) : Array.isArray(e) ? e.map((s) => !t || typeof s == "string" ? F(s) : typeof s == "object" && s ? F(s, t) : s) : b(e) ? Object.keys(e).reduce(
|
|
125
|
-
(s, r) => {
|
|
126
|
-
const n = X(String(r));
|
|
127
|
-
return s[n] = t ? e[r] : F(e[r]), s;
|
|
128
|
-
},
|
|
129
|
-
{}
|
|
130
|
-
) : e;
|
|
131
|
-
}
|
|
132
|
-
rt("LoadUtils");
|
|
133
|
-
async function Vt(e) {
|
|
103
|
+
Q("LoadUtils");
|
|
104
|
+
async function Bt(e) {
|
|
134
105
|
return await new Promise(function(t) {
|
|
135
106
|
const s = document.getElementsByTagName("head")[0], r = document.createElement("script");
|
|
136
107
|
r.setAttribute("type", "text/javascript"), r.setAttribute("charset", "utf-8"), r.onload = function() {
|
|
@@ -140,25 +111,25 @@ async function Vt(e) {
|
|
|
140
111
|
}, r.setAttribute("src", e), s.appendChild(r);
|
|
141
112
|
});
|
|
142
113
|
}
|
|
143
|
-
function
|
|
114
|
+
function W(e) {
|
|
144
115
|
return Object.getOwnPropertyNames(e).forEach(function(t) {
|
|
145
116
|
delete e[t];
|
|
146
117
|
}), e;
|
|
147
118
|
}
|
|
148
|
-
const g =
|
|
119
|
+
const g = Q("Validator");
|
|
149
120
|
function E(e) {
|
|
150
|
-
return e ? `"${
|
|
121
|
+
return e ? `"${_t(e).replace(/"/g, '\\"')}"` : "empty string";
|
|
151
122
|
}
|
|
152
|
-
function
|
|
123
|
+
function U(e) {
|
|
153
124
|
return typeof e == "object" && e && "constructor" in e && typeof e.constructor == "function" ? e.constructor.name || "ClassInstance" : Object.prototype.toString.call(e).replace(/(?:.+ |]$)/g, "");
|
|
154
125
|
}
|
|
155
|
-
function
|
|
126
|
+
function A(e) {
|
|
156
127
|
return typeof e == "bigint";
|
|
157
128
|
}
|
|
158
129
|
function l(e) {
|
|
159
130
|
return new Error(`${e ? `${e}()` : "method"} is not allowed after locked`);
|
|
160
131
|
}
|
|
161
|
-
class
|
|
132
|
+
class L {
|
|
162
133
|
constructor() {
|
|
163
134
|
o(this, "_ps", {}), o(this, "_allow", []), o(this, "_reject", []), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
|
|
164
135
|
}
|
|
@@ -186,7 +157,7 @@ class q {
|
|
|
186
157
|
enum(...t) {
|
|
187
158
|
if (this._locked) throw l("enum");
|
|
188
159
|
const s = t[0];
|
|
189
|
-
return
|
|
160
|
+
return I(t, dt) ? (this._allow = t, W(this._ps)) : k(s) && (this._allow = Object.values(s).map((r) => `${r}`), W(this._ps)), this;
|
|
190
161
|
}
|
|
191
162
|
disallow(...t) {
|
|
192
163
|
return this._reject.push(...t), this;
|
|
@@ -203,7 +174,7 @@ class q {
|
|
|
203
174
|
return this._locked = !0, this;
|
|
204
175
|
}
|
|
205
176
|
clone() {
|
|
206
|
-
const t = new
|
|
177
|
+
const t = new L();
|
|
207
178
|
return t._ps = { ...this._ps }, t._allow = [...this._allow], t._reject = [...this._reject], t._locked = !1, t;
|
|
208
179
|
}
|
|
209
180
|
validate(t, s = g.warn) {
|
|
@@ -224,7 +195,7 @@ class q {
|
|
|
224
195
|
}) ? (s(`${E(t)} is not match pattern ${r.join(" | ")}`), !1) : !0;
|
|
225
196
|
}
|
|
226
197
|
}
|
|
227
|
-
class
|
|
198
|
+
class C {
|
|
228
199
|
constructor() {
|
|
229
200
|
o(this, "_int", !1), o(this, "_min", -1 / 0), o(this, "_max", 1 / 0), o(this, "_allow", []), o(this, "_reject", []), o(this, "_infinite", !1), o(this, "_unsafe", !1), o(this, "_nan", !1), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
|
|
230
201
|
}
|
|
@@ -258,7 +229,7 @@ class B {
|
|
|
258
229
|
enum(...t) {
|
|
259
230
|
if (this._locked) throw l("enum");
|
|
260
231
|
const s = t[0];
|
|
261
|
-
return
|
|
232
|
+
return I(t, F) ? (this._allow = t, this._reject = []) : k(s) && (this._allow = Object.values(s).map((r) => F(r) ? r : null).filter((r) => r !== null), this._reject = []), this;
|
|
262
233
|
}
|
|
263
234
|
disallow(...t) {
|
|
264
235
|
if (this._locked) throw l("disallow");
|
|
@@ -276,14 +247,14 @@ class B {
|
|
|
276
247
|
return this._locked = !0, this;
|
|
277
248
|
}
|
|
278
249
|
clone() {
|
|
279
|
-
const t = new
|
|
250
|
+
const t = new C();
|
|
280
251
|
return t._int = this._int, t._min = this._min, t._max = this._max, t._allow = [...this._allow], t._reject = [...this._reject], t._infinite = this._infinite, t._unsafe = this._unsafe, t._nan = this._nan, t._locked = !1, t;
|
|
281
252
|
}
|
|
282
253
|
validate(t, s = g.warn) {
|
|
283
|
-
return t === void 0 ? this._opt || (s("should be a number, but got undefined"), !1) : t === null ? this._null || (s("should be a number, but got null"), !1) : typeof t != "number" ? (s(`should be a number, but got ${typeof t}`), !1) : Number.isNaN(t) ? this._nan || (s("should be a number, but got NaN"), !1) : !Number.isFinite(t) && !this._infinite ? (s("should be a number, but got Infinity"), !1) : this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : this._int && Math.ceil(t) !== t ? (s(`${t} is not an integer`), !1) : !
|
|
254
|
+
return t === void 0 ? this._opt || (s("should be a number, but got undefined"), !1) : t === null ? this._null || (s("should be a number, but got null"), !1) : typeof t != "number" ? (s(`should be a number, but got ${typeof t}`), !1) : Number.isNaN(t) ? this._nan || (s("should be a number, but got NaN"), !1) : !Number.isFinite(t) && !this._infinite ? (s("should be a number, but got Infinity"), !1) : this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : this._int && Math.ceil(t) !== t ? (s(`${t} is not an integer`), !1) : !F(t) && !this._unsafe ? (s(`${t} is not a safe number`), !1) : t >= this._min && t <= this._max || (s(`${t} is not in range [${this._min}, ${this._max}]`), !1);
|
|
284
255
|
}
|
|
285
256
|
}
|
|
286
|
-
class
|
|
257
|
+
class D {
|
|
287
258
|
constructor() {
|
|
288
259
|
o(this, "_min", null), o(this, "_max", null), o(this, "_allow", []), o(this, "_reject", []), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
|
|
289
260
|
}
|
|
@@ -298,7 +269,7 @@ class H {
|
|
|
298
269
|
enum(...t) {
|
|
299
270
|
if (this._locked) throw l("enum");
|
|
300
271
|
const s = t[0];
|
|
301
|
-
return
|
|
272
|
+
return I(t, A) ? (this._allow = t, this._reject = []) : k(s) && (this._allow = Object.values(s).map((r) => A(r) ? r : null).filter((r) => r !== null), this._reject = []), this;
|
|
302
273
|
}
|
|
303
274
|
disallow(...t) {
|
|
304
275
|
if (this._locked) throw l("disallow");
|
|
@@ -316,16 +287,16 @@ class H {
|
|
|
316
287
|
return this._locked = !0, this;
|
|
317
288
|
}
|
|
318
289
|
clone() {
|
|
319
|
-
const t = new
|
|
290
|
+
const t = new D();
|
|
320
291
|
return t._min = this._min, t._max = this._max, t._allow = [...this._allow], t._reject = [...this._reject], t._locked = !1, t;
|
|
321
292
|
}
|
|
322
293
|
validate(t, s = g.warn) {
|
|
323
|
-
return t === void 0 ? this._opt || (s("should be a bigint, but got undefined"), !1) : t === null ? this._null || (s("should be a bigint, but got null"), !1) :
|
|
294
|
+
return t === void 0 ? this._opt || (s("should be a bigint, but got undefined"), !1) : t === null ? this._null || (s("should be a bigint, but got null"), !1) : A(t) ? this._allow.length > 0 ? this._allow.includes(t) || (s(`${t} is not allowed, just support ${this._allow.join(", ")}`), !1) : this._reject.length > 0 && this._reject.includes(t) ? (s(`${t} is not allowed`), !1) : (this._min !== null ? t >= this._min : !0) && (this._max !== null ? t <= this._max : !0) || (s(
|
|
324
295
|
`${t} is not in range [${this._min === null ? -1 / 0 : this._min}, ${this._max === null ? 1 / 0 : this._max}]`
|
|
325
296
|
), !1) : (s(`should be a bigint, but got ${typeof t}`), !1);
|
|
326
297
|
}
|
|
327
298
|
}
|
|
328
|
-
class
|
|
299
|
+
class q {
|
|
329
300
|
constructor() {
|
|
330
301
|
o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1);
|
|
331
302
|
}
|
|
@@ -341,7 +312,7 @@ class z {
|
|
|
341
312
|
return this._locked = !0, this;
|
|
342
313
|
}
|
|
343
314
|
clone() {
|
|
344
|
-
return new
|
|
315
|
+
return new q();
|
|
345
316
|
}
|
|
346
317
|
validate(t, s = g.warn) {
|
|
347
318
|
return t === void 0 ? this._opt || (s("should be a boolean, but got undefined"), !1) : t === null ? this._null || (s("should be a boolean, but got null"), !1) : typeof t != "boolean" ? (s(`should be a boolean, but got ${typeof t}`), !1) : !0;
|
|
@@ -380,15 +351,15 @@ class R {
|
|
|
380
351
|
* 检查指定的 field / value 是否可以通过校验
|
|
381
352
|
*/
|
|
382
353
|
match(t, s) {
|
|
383
|
-
return t in this._shape ? this._shape[t].validate(s,
|
|
354
|
+
return t in this._shape ? this._shape[t].validate(s, X) : !1;
|
|
384
355
|
}
|
|
385
356
|
validate(t, s = g.warn) {
|
|
386
|
-
return t === void 0 ? this._opt || (s("should be a object, but got undefined"), !1) : t === null ? this._null || (s("should be a object, but got null"), !1) :
|
|
357
|
+
return t === void 0 ? this._opt || (s("should be a object, but got undefined"), !1) : t === null ? this._null || (s("should be a object, but got null"), !1) : Y(t) ? this._plain && !k(t) ? (s(`should be a plain object, but got ${U(t)}`), !1) : Object.keys(this._shape).every((r) => this._shape[r].validate(t[r], (...n) => {
|
|
387
358
|
s(`[.${String(r)}]`, ...n);
|
|
388
|
-
})) : (s(`should be a object, but got ${
|
|
359
|
+
})) : (s(`should be a object, but got ${U(t)}`), !1);
|
|
389
360
|
}
|
|
390
361
|
}
|
|
391
|
-
class
|
|
362
|
+
class B {
|
|
392
363
|
constructor(t) {
|
|
393
364
|
o(this, "_val"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._val = t;
|
|
394
365
|
}
|
|
@@ -404,17 +375,17 @@ class G {
|
|
|
404
375
|
return this._locked = !0, this;
|
|
405
376
|
}
|
|
406
377
|
clone() {
|
|
407
|
-
return new
|
|
378
|
+
return new B(this._val);
|
|
408
379
|
}
|
|
409
380
|
validate(t, s = g.warn) {
|
|
410
|
-
return t === void 0 ? this._opt || (s("should be a record, but got undefined"), !1) : t === null ? this._null || (s("should be a record, but got null"), !1) :
|
|
381
|
+
return t === void 0 ? this._opt || (s("should be a record, but got undefined"), !1) : t === null ? this._null || (s("should be a record, but got null"), !1) : k(t) ? Object.keys(t).every(
|
|
411
382
|
(r) => this._val.validate(t[r], (...n) => {
|
|
412
383
|
s(`[:${r}]`, ...n);
|
|
413
384
|
})
|
|
414
|
-
) : (s(`should be a record, but got ${
|
|
385
|
+
) : (s(`should be a record, but got ${U(t)}`), !1);
|
|
415
386
|
}
|
|
416
387
|
}
|
|
417
|
-
class
|
|
388
|
+
class H {
|
|
418
389
|
constructor(t) {
|
|
419
390
|
o(this, "_val"), o(this, "_min", 0), o(this, "_max", 1 / 0), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._val = t;
|
|
420
391
|
}
|
|
@@ -438,7 +409,7 @@ class K {
|
|
|
438
409
|
return this._locked = !0, this;
|
|
439
410
|
}
|
|
440
411
|
clone() {
|
|
441
|
-
const t = new
|
|
412
|
+
const t = new H(this._val);
|
|
442
413
|
return t._min = this._min, t._max = this._max, t._locked = !1, t;
|
|
443
414
|
}
|
|
444
415
|
validate(t, s = g.warn) {
|
|
@@ -449,7 +420,7 @@ class K {
|
|
|
449
420
|
) : (s(`should be a array, but got ${typeof t}`), !1);
|
|
450
421
|
}
|
|
451
422
|
}
|
|
452
|
-
class
|
|
423
|
+
class z {
|
|
453
424
|
constructor(...t) {
|
|
454
425
|
o(this, "_vs"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._vs = t;
|
|
455
426
|
}
|
|
@@ -465,7 +436,7 @@ class W {
|
|
|
465
436
|
return this._locked = !0, this;
|
|
466
437
|
}
|
|
467
438
|
clone() {
|
|
468
|
-
return new
|
|
439
|
+
return new z(...this._vs);
|
|
469
440
|
}
|
|
470
441
|
validate(t, s = g.warn) {
|
|
471
442
|
return t === void 0 ? this._opt || (s("should be a tuple, but got undefined"), !1) : t === null ? this._null || (s("should be a tuple, but got null"), !1) : Array.isArray(t) ? t.length !== this._vs.length ? (s(`should be a tuple with length ${this._vs.length}, but got ${t.length}`), !1) : this._vs.every(
|
|
@@ -475,7 +446,7 @@ class W {
|
|
|
475
446
|
) : (s(`should be a tuple, but got ${typeof t}`), !1);
|
|
476
447
|
}
|
|
477
448
|
}
|
|
478
|
-
class
|
|
449
|
+
class K {
|
|
479
450
|
constructor(...t) {
|
|
480
451
|
o(this, "_vs"), o(this, "_key", ""), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._vs = t;
|
|
481
452
|
}
|
|
@@ -506,7 +477,7 @@ class J {
|
|
|
506
477
|
return [...this._vs];
|
|
507
478
|
}
|
|
508
479
|
clone() {
|
|
509
|
-
const t = new
|
|
480
|
+
const t = new K(...this._vs);
|
|
510
481
|
return t._key = this._key, t._locked = !1, t;
|
|
511
482
|
}
|
|
512
483
|
validate(t, s = g.warn) {
|
|
@@ -514,7 +485,7 @@ class J {
|
|
|
514
485
|
return this._opt || (s("should be a union, but got undefined"), !1);
|
|
515
486
|
if (t === null)
|
|
516
487
|
return this._null || (s("should be a union, but got null"), !1);
|
|
517
|
-
if (this._key &&
|
|
488
|
+
if (this._key && Y(t) && t) {
|
|
518
489
|
const n = t[this._key];
|
|
519
490
|
if (n === void 0)
|
|
520
491
|
return s(`key field "${this._key}" is not found`, t), !1;
|
|
@@ -523,11 +494,11 @@ class J {
|
|
|
523
494
|
);
|
|
524
495
|
return i ? i.validate(t, s) : (s(`key field "${this._key}" value is match union definition`, n), !1);
|
|
525
496
|
}
|
|
526
|
-
const r = this._vs.some((n) => n.validate(t,
|
|
497
|
+
const r = this._vs.some((n) => n.validate(t, X));
|
|
527
498
|
return r || s("value is not match union definition", t), r;
|
|
528
499
|
}
|
|
529
500
|
}
|
|
530
|
-
class
|
|
501
|
+
class O {
|
|
531
502
|
constructor(t, s) {
|
|
532
503
|
o(this, "_name", ""), o(this, "_guard"), o(this, "_locked", !1), o(this, "_opt", !1), o(this, "_null", !1), this._name = t, this._guard = s;
|
|
533
504
|
}
|
|
@@ -543,22 +514,22 @@ class S {
|
|
|
543
514
|
return this._locked = !0, this;
|
|
544
515
|
}
|
|
545
516
|
clone() {
|
|
546
|
-
return new
|
|
517
|
+
return new O(this._name, this._guard);
|
|
547
518
|
}
|
|
548
519
|
validate(t, s = g.warn) {
|
|
549
520
|
const r = this._name || "custom type";
|
|
550
521
|
return t === void 0 ? this._opt || (s(`should be ${r}, but got undefined`), !1) : t === null ? this._null || (s(`should be ${r}, but got null`), !1) : this._guard(t) || (s(`custom validation${this._name ? `(${this._name})` : ""} failed`), !1);
|
|
551
522
|
}
|
|
552
523
|
}
|
|
553
|
-
function
|
|
524
|
+
function gt(e, t) {
|
|
554
525
|
if (typeof e == "string") {
|
|
555
526
|
if (!t)
|
|
556
527
|
throw new Error("custom type guard must be defined");
|
|
557
|
-
return new
|
|
528
|
+
return new O(e, t);
|
|
558
529
|
}
|
|
559
|
-
return new
|
|
530
|
+
return new O("", e);
|
|
560
531
|
}
|
|
561
|
-
const
|
|
532
|
+
const pt = {
|
|
562
533
|
/**
|
|
563
534
|
* object shape 的定义辅助函数
|
|
564
535
|
*/
|
|
@@ -589,38 +560,38 @@ const jt = {
|
|
|
589
560
|
* 如果需要指定 key 类型,使用 define 辅助工具
|
|
590
561
|
*/
|
|
591
562
|
record(e) {
|
|
592
|
-
return new
|
|
563
|
+
return new B(e);
|
|
593
564
|
},
|
|
594
565
|
/** 数组类型验证 */
|
|
595
566
|
array(e) {
|
|
596
|
-
return new
|
|
567
|
+
return new H(e);
|
|
597
568
|
},
|
|
598
569
|
/** 元组类型验证 */
|
|
599
570
|
tuple(...e) {
|
|
600
|
-
return new
|
|
571
|
+
return new z(...e);
|
|
601
572
|
},
|
|
602
573
|
/** 联合类型验证 */
|
|
603
574
|
union(...e) {
|
|
604
|
-
return new
|
|
575
|
+
return new K(...e);
|
|
605
576
|
},
|
|
606
577
|
/** 字符串类型验证 */
|
|
607
578
|
string() {
|
|
608
|
-
return new
|
|
579
|
+
return new L();
|
|
609
580
|
},
|
|
610
581
|
/** 布尔型类型验证 */
|
|
611
582
|
bool() {
|
|
612
|
-
return new
|
|
583
|
+
return new q();
|
|
613
584
|
},
|
|
614
585
|
/** 数字验证 */
|
|
615
586
|
number() {
|
|
616
|
-
return new
|
|
587
|
+
return new C();
|
|
617
588
|
},
|
|
618
589
|
/** bigint 验证 */
|
|
619
590
|
bigint() {
|
|
620
|
-
return new
|
|
591
|
+
return new D();
|
|
621
592
|
},
|
|
622
593
|
/** 自定义验证 */
|
|
623
|
-
custom:
|
|
594
|
+
custom: gt,
|
|
624
595
|
/**
|
|
625
596
|
* 允许一个 unknown 类型,validate 总是返回 true
|
|
626
597
|
*/
|
|
@@ -641,9 +612,9 @@ const jt = {
|
|
|
641
612
|
}
|
|
642
613
|
};
|
|
643
614
|
}
|
|
644
|
-
},
|
|
645
|
-
|
|
646
|
-
function
|
|
615
|
+
}, bt = (e) => k(e) && Object.keys(e).length === 0;
|
|
616
|
+
pt.custom("EmptyObject", bt);
|
|
617
|
+
function yt(e, t = "数据未能正确识别") {
|
|
647
618
|
return typeof e == "function" ? {
|
|
648
619
|
guard: e,
|
|
649
620
|
message: t
|
|
@@ -652,20 +623,20 @@ function Nt(e, t = "数据未能正确识别") {
|
|
|
652
623
|
message: e.message || t
|
|
653
624
|
};
|
|
654
625
|
}
|
|
655
|
-
function
|
|
656
|
-
return !t ||
|
|
626
|
+
function wt(e, t = "") {
|
|
627
|
+
return !t || P(e, !0) ? J(e) : (J(t) + "/" + e).replace(/\/{2,}/g, "/").replace(/:\//, "://");
|
|
657
628
|
}
|
|
658
|
-
function
|
|
659
|
-
return
|
|
629
|
+
function J(e) {
|
|
630
|
+
return P(e, !0) ? e.startsWith("http") ? e : ("location" in globalThis ? location.protocol : "https:") + e : ("location" in globalThis ? location.origin : "http://127.0.0.1") + "/" + e.replace(/^\/+/, "");
|
|
660
631
|
}
|
|
661
|
-
function
|
|
632
|
+
function kt(e, t) {
|
|
662
633
|
const s = {};
|
|
663
634
|
return (e.match(/([^=&#?]+)=[^&#]*/g) || []).forEach(function(r) {
|
|
664
635
|
const n = r.split("="), i = n[0], a = decodeURIComponent(n[1] || "");
|
|
665
636
|
s[i] !== void 0 ? s[i] += "," + a : s[i] = a;
|
|
666
637
|
}), t !== !0 ? s[t] || "" : s;
|
|
667
638
|
}
|
|
668
|
-
function
|
|
639
|
+
function vt(e, t) {
|
|
669
640
|
if (t) {
|
|
670
641
|
if (t === !0)
|
|
671
642
|
return e.replace(/\?[^#]*/, "");
|
|
@@ -673,30 +644,30 @@ function Ot(e, t) {
|
|
|
673
644
|
const s = e.split("#"), r = s[0].split("?"), n = r[0], i = r.length > 1 ? r[1] : "", a = s.length > 1 ? "#" + s[1] : "", h = typeof t == "string" ? [t] : Array.isArray(t) ? t : [];
|
|
674
645
|
return !h.length || !i ? s[0] + a : (h.map((c) => c.replace(/([\\(){}[\]^$+\-*?|])/g, "\\$1")), (n + "?" + i.replace(new RegExp("(?:^|&)(?:" + h.join("|") + ")=[^&$]+", "g"), "").replace(/^&/, "")).replace(/\?$/, "") + a);
|
|
675
646
|
}
|
|
676
|
-
function
|
|
647
|
+
function Ht(e, t, s = !1) {
|
|
677
648
|
const r = typeof t == "string" ? t : Object.keys(t).map((a) => `${a}=${encodeURIComponent(t[a])}`).join("&");
|
|
678
649
|
if (!r)
|
|
679
650
|
return e;
|
|
680
651
|
const n = e.split("#");
|
|
681
|
-
s && (n[0] =
|
|
652
|
+
s && (n[0] = vt(
|
|
682
653
|
n[0],
|
|
683
654
|
(r.match(/([^=&#?]+)=[^&#]+/g) || []).map((a) => a.replace(/=.+$/, ""))
|
|
684
655
|
));
|
|
685
656
|
const i = n[0].indexOf("?") + 1 ? "&" : "?";
|
|
686
657
|
return (n[0] + i + r + (n.length > 1 ? "#" + n[1] : "")).replace(/\?&/, "?");
|
|
687
658
|
}
|
|
688
|
-
function
|
|
659
|
+
function $t(e) {
|
|
689
660
|
const t = e.match(/(?:\?|&)([^=]+)(?:&|$)/g);
|
|
690
661
|
return t ? t.join("").replace(/(?:\?|^&+|&+$)/g, "").replace(/&{2}/g, "&").split("&").sort() : [];
|
|
691
662
|
}
|
|
692
|
-
class
|
|
663
|
+
class jt {
|
|
693
664
|
constructor(t = 500) {
|
|
694
665
|
v(this, "ttl");
|
|
695
666
|
v(this, "cache");
|
|
696
667
|
this.cache = {}, this.ttl = Math.max(t, 0);
|
|
697
668
|
}
|
|
698
669
|
getKey(t, s) {
|
|
699
|
-
const r = t.replace(/#.+/, ""), n = r.replace(/\?.+/g, ""), i = Object.assign(
|
|
670
|
+
const r = t.replace(/#.+/, ""), n = r.replace(/\?.+/g, ""), i = Object.assign(kt(r, !0), s), a = $t(r), h = Object.keys(i).sort().map((c) => `${c}#${i[c]}`);
|
|
700
671
|
return `${n}_${h.join(",")}_${a.join(",")}`;
|
|
701
672
|
}
|
|
702
673
|
updateTTL(t) {
|
|
@@ -715,7 +686,7 @@ class Ft {
|
|
|
715
686
|
});
|
|
716
687
|
}
|
|
717
688
|
}
|
|
718
|
-
class
|
|
689
|
+
class Rt {
|
|
719
690
|
constructor(t) {
|
|
720
691
|
// 保存的配置需要部分字段强制设置默认值
|
|
721
692
|
v(this, "config", {
|
|
@@ -740,7 +711,7 @@ class St {
|
|
|
740
711
|
t && this.set(t);
|
|
741
712
|
}
|
|
742
713
|
set(t) {
|
|
743
|
-
if (t.baseURL && !/^\/.+/.test(t.baseURL) && !
|
|
714
|
+
if (t.baseURL && !/^\/.+/.test(t.baseURL) && !P(t.baseURL))
|
|
744
715
|
throw console.warn("baseURL 需要以 / 开头,或者是完整的 url 地址"), new Error("BaseURLError");
|
|
745
716
|
Object.assign(this.config, t);
|
|
746
717
|
}
|
|
@@ -749,14 +720,14 @@ class St {
|
|
|
749
720
|
}
|
|
750
721
|
/** 基于 baseURL 返回完整的 url 地址 */
|
|
751
722
|
getFullUrl(t) {
|
|
752
|
-
return
|
|
723
|
+
return wt(t, this.config.baseURL);
|
|
753
724
|
}
|
|
754
725
|
/** 提示消息 */
|
|
755
726
|
showMessage(t, s, r, n) {
|
|
756
727
|
this.config.messageHandler && s && this.config.messageHandler(t, s, r, n);
|
|
757
728
|
}
|
|
758
729
|
}
|
|
759
|
-
const
|
|
730
|
+
const et = {
|
|
760
731
|
/** 响应数据校验失败 */
|
|
761
732
|
UnexpectResponse: "UnexpectResponse",
|
|
762
733
|
/** 请求被取消 */
|
|
@@ -772,19 +743,19 @@ const lt = {
|
|
|
772
743
|
/** url 格式错误 */
|
|
773
744
|
URLFormatError: "URLFormatError"
|
|
774
745
|
};
|
|
775
|
-
function
|
|
776
|
-
if (t.ok && !
|
|
777
|
-
const n =
|
|
778
|
-
return n.guard(t.data) || (t.code =
|
|
746
|
+
function Nt(e, t, s, r) {
|
|
747
|
+
if (t.ok && !mt(t.data) && r) {
|
|
748
|
+
const n = yt(r, s.get("defaultTypeGuardMessage"));
|
|
749
|
+
return n.guard(t.data) || (t.code = et.UnexpectResponse, s.showMessage(!0, `${e} ${n.message}`, t.code, t.status), console.error(t.code, e, t.data), t.data = null, t.message = n.message), t;
|
|
779
750
|
}
|
|
780
751
|
return t;
|
|
781
752
|
}
|
|
782
|
-
class
|
|
753
|
+
class zt {
|
|
783
754
|
constructor(t, s) {
|
|
784
755
|
v(this, "agent");
|
|
785
756
|
v(this, "config");
|
|
786
757
|
v(this, "cache");
|
|
787
|
-
this.config = new
|
|
758
|
+
this.config = new Rt(s), this.agent = t, this.cache = new jt(this.config.get("cacheTTL")), this.setConfig = this.setConfig.bind(this), this.getConfig = this.getConfig.bind(this), this.request = this.request.bind(this), this.get = this.get.bind(this), this.post = this.post.bind(this), this.del = this.del.bind(this), this.patch = this.patch.bind(this), this.put = this.put.bind(this), this.head = this.head.bind(this);
|
|
788
759
|
}
|
|
789
760
|
/**
|
|
790
761
|
* 执行网络请求
|
|
@@ -796,7 +767,7 @@ class Xt {
|
|
|
796
767
|
return console.error("RequestError", r), {
|
|
797
768
|
ok: !1,
|
|
798
769
|
status: -9,
|
|
799
|
-
code:
|
|
770
|
+
code: et.Unknown,
|
|
800
771
|
message: r instanceof Error ? `${r.message}
|
|
801
772
|
${r.stack || ""}` : String(r),
|
|
802
773
|
headers: {},
|
|
@@ -808,7 +779,7 @@ ${r.stack || ""}` : String(r),
|
|
|
808
779
|
* 检查响应的数据类型
|
|
809
780
|
*/
|
|
810
781
|
async guard(t, s, r) {
|
|
811
|
-
return
|
|
782
|
+
return Nt(t, s, this.config, r);
|
|
812
783
|
}
|
|
813
784
|
/**
|
|
814
785
|
* 修改默认请求配置: baseURL / timeout / credentials / errorHandler / messageHandler / responseHandler / logHandler / responseRule
|
|
@@ -855,8 +826,8 @@ ${r.stack || ""}` : String(r),
|
|
|
855
826
|
return i.method = "PATCH", i.body = s || {}, this.guard(t, await this.request(t, i), r || null);
|
|
856
827
|
}
|
|
857
828
|
}
|
|
858
|
-
async function
|
|
859
|
-
var
|
|
829
|
+
async function Kt(e, t, s) {
|
|
830
|
+
var y;
|
|
860
831
|
const r = Object.assign({ method: "GET" }, s), n = j.FormData ? r.body instanceof FormData : !1, i = n && r.method !== "POST" && r.method !== "PUT" ? "POST" : r.method, a = i === "GET" || i === "HEAD" || i === "DELETE";
|
|
861
832
|
a && r.body !== void 0 && (console.warn("request body is invalid with method get, head, delete"), delete r.body);
|
|
862
833
|
const h = Object.assign(
|
|
@@ -864,39 +835,39 @@ async function Yt(e, t, s) {
|
|
|
864
835
|
"Content-Type": j.Blob && r.body instanceof Blob ? r.body.type || "application/octet-stream" : "application/json;charset=utf-8"
|
|
865
836
|
},
|
|
866
837
|
r.headers
|
|
867
|
-
), c = r.params || {},
|
|
838
|
+
), c = r.params || {}, _ = {};
|
|
868
839
|
Object.keys(c).forEach(($) => {
|
|
869
|
-
c[$] !== void 0 && (
|
|
840
|
+
c[$] !== void 0 && (_[$] = xt(c[$]));
|
|
870
841
|
});
|
|
871
|
-
const f = t.getFullUrl(e), d =
|
|
842
|
+
const f = t.getFullUrl(e), d = Et(r.body), p = r.timeout || t.get("timeout"), b = await async function() {
|
|
872
843
|
const $ = t.get("requestTransformer");
|
|
873
844
|
if ($)
|
|
874
|
-
return await $({ headers: h, params:
|
|
875
|
-
}(),
|
|
876
|
-
return (
|
|
877
|
-
url:
|
|
845
|
+
return await $({ headers: h, params: _, method: i, url: f, body: d });
|
|
846
|
+
}(), w = typeof b == "string" && b ? b : f;
|
|
847
|
+
return (y = t.get("logHandler")) == null || y({ type: "ready", url: w, method: i, headers: h, timeout: p, body: d }), {
|
|
848
|
+
url: w,
|
|
878
849
|
method: i,
|
|
879
850
|
body: d,
|
|
880
|
-
params:
|
|
851
|
+
params: _,
|
|
881
852
|
headers: h,
|
|
882
853
|
timeout: p,
|
|
883
854
|
abort: r.abort,
|
|
884
855
|
credentials: r.credentials || t.get("credentials")
|
|
885
856
|
};
|
|
886
857
|
}
|
|
887
|
-
function
|
|
858
|
+
function xt(e) {
|
|
888
859
|
return typeof e == "string" ? e : Array.isArray(e) ? e.join(",") : e + "";
|
|
889
860
|
}
|
|
890
|
-
function
|
|
861
|
+
function Et(e) {
|
|
891
862
|
if (e)
|
|
892
863
|
return typeof e == "string" || j.URLSearchParams && e instanceof URLSearchParams || e instanceof ArrayBuffer || j.Blob && e instanceof Blob || j.FormData && e instanceof FormData ? e : JSON.stringify(e);
|
|
893
864
|
}
|
|
894
|
-
const
|
|
895
|
-
function
|
|
865
|
+
const st = "data", N = "message";
|
|
866
|
+
function Ot(e, t, s, r, n) {
|
|
896
867
|
const i = n || r;
|
|
897
|
-
return
|
|
868
|
+
return G(e) ? Mt(i.ok || r.ok, e, t, s) : Ft(i.failed || r.failed, t, s);
|
|
898
869
|
}
|
|
899
|
-
const
|
|
870
|
+
const Gt = function(e) {
|
|
900
871
|
const t = [], s = e.failed || { resolve: "json" };
|
|
901
872
|
switch (t.push("- 当http状态码 <200 或者 >=400 时"), s.resolve) {
|
|
902
873
|
case "body":
|
|
@@ -913,7 +884,7 @@ const Qt = function(e) {
|
|
|
913
884
|
break;
|
|
914
885
|
case "json":
|
|
915
886
|
t.push(
|
|
916
|
-
" 将响应解析为 json,读取 " + (r.dataField ||
|
|
887
|
+
" 将响应解析为 json,读取 " + (r.dataField || st) + " 作为响应数据,读取 " + (r.messageField || N) + " 作为提示消息"
|
|
917
888
|
), r.statusField && t.push(
|
|
918
889
|
" 当 " + r.statusField + " 为 " + (r.statusOKValue || "空值") + " 时是成功提示,否则是错误消息"
|
|
919
890
|
), r.ignoreMessage && t.push(" 并忽略以下消息:" + r.ignoreMessage);
|
|
@@ -922,7 +893,7 @@ const Qt = function(e) {
|
|
|
922
893
|
return t.join(`
|
|
923
894
|
`);
|
|
924
895
|
};
|
|
925
|
-
function
|
|
896
|
+
function Ft(e, t, s) {
|
|
926
897
|
const r = e || { resolve: "json", messageField: N }, n = {
|
|
927
898
|
ok: !1,
|
|
928
899
|
code: t,
|
|
@@ -931,43 +902,43 @@ function Pt(e, t, s) {
|
|
|
931
902
|
};
|
|
932
903
|
switch (r.resolve) {
|
|
933
904
|
case "body":
|
|
934
|
-
n.message =
|
|
905
|
+
n.message = V(s) || s;
|
|
935
906
|
break;
|
|
936
907
|
case "json":
|
|
937
|
-
const { code: i, message: a } =
|
|
938
|
-
n.code = i || t, n.message =
|
|
908
|
+
const { code: i, message: a } = At(s, r.converter, r.statusField, r.messageField);
|
|
909
|
+
n.code = i || t, n.message = V(s) || a;
|
|
939
910
|
break;
|
|
940
911
|
}
|
|
941
912
|
return n;
|
|
942
913
|
}
|
|
943
|
-
function
|
|
944
|
-
if (!
|
|
914
|
+
function At(e, t, s, r = N) {
|
|
915
|
+
if (!tt(e))
|
|
945
916
|
return { message: "" };
|
|
946
|
-
const n =
|
|
947
|
-
return !n || !
|
|
948
|
-
code: s ?
|
|
949
|
-
message:
|
|
917
|
+
const n = M(S(e), t);
|
|
918
|
+
return !n || !k(n) ? { message: e } : {
|
|
919
|
+
code: s ? T(n, s) : "",
|
|
920
|
+
message: T(n, r) || e
|
|
950
921
|
};
|
|
951
922
|
}
|
|
952
|
-
function
|
|
923
|
+
function T(e, t) {
|
|
953
924
|
const s = Array.isArray(t) ? t : [t];
|
|
954
925
|
for (const r of s)
|
|
955
926
|
if (r in e)
|
|
956
|
-
return
|
|
927
|
+
return St(e[r]);
|
|
957
928
|
return "";
|
|
958
929
|
}
|
|
959
|
-
function
|
|
930
|
+
function St(e) {
|
|
960
931
|
return e ? typeof e == "string" ? e : JSON.stringify(e) : "";
|
|
961
932
|
}
|
|
962
|
-
const
|
|
963
|
-
function
|
|
964
|
-
const t = e.match(
|
|
933
|
+
const Ut = /<title>([^<]+)<\/title>/i, Tt = /<message>([^<]+)<\/message>/i;
|
|
934
|
+
function V(e) {
|
|
935
|
+
const t = e.match(Ut);
|
|
965
936
|
if (t)
|
|
966
937
|
return t[1];
|
|
967
|
-
const s = e.match(
|
|
938
|
+
const s = e.match(Tt);
|
|
968
939
|
return s ? s[1] : "";
|
|
969
940
|
}
|
|
970
|
-
function
|
|
941
|
+
function Mt(e, t, s, r) {
|
|
971
942
|
const n = e || { resolve: "body" }, i = {
|
|
972
943
|
ok: !0,
|
|
973
944
|
code: s,
|
|
@@ -977,30 +948,30 @@ function Bt(e, t, s, r) {
|
|
|
977
948
|
if (t === 204 || !r)
|
|
978
949
|
return i;
|
|
979
950
|
if (n.resolve === "body")
|
|
980
|
-
return i.data =
|
|
981
|
-
const a =
|
|
982
|
-
if (!a || !
|
|
951
|
+
return i.data = tt(r) ? M(S(r), e.converter) : r, i;
|
|
952
|
+
const a = M(S(r), e.converter);
|
|
953
|
+
if (!a || !k(a))
|
|
983
954
|
return i.ok = !1, i.code = "ResponseFormatError", i.message = "响应内容无法格式化为 Object", i;
|
|
984
|
-
const h = n.statusField, c = n.statusOKValue || "",
|
|
955
|
+
const h = n.statusField, c = n.statusOKValue || "", _ = n.dataField || st, f = n.messageField || N, d = n.ignoreMessage || "";
|
|
985
956
|
if (h && !(h in a))
|
|
986
957
|
return i.ok = !1, i.code = "ResponseFieldMissing", i.message = "响应内容找不到状态字段 " + h, i;
|
|
987
958
|
const p = h ? a[h] + "" : "";
|
|
988
|
-
return i.ok = h ? p === c : !0, i.code = p || s, i.data =
|
|
959
|
+
return i.ok = h ? p === c : !0, i.code = p || s, i.data = _ === !0 ? a : _ in a ? a[_] : null, i.message = T(a, f), d && i.message && (Array.isArray(d) && d.includes(i.message) || typeof d == "string" && i.message === d) && (i.message = ""), i;
|
|
989
960
|
}
|
|
990
|
-
function
|
|
961
|
+
function G(e) {
|
|
991
962
|
return e >= 200 && e < 400;
|
|
992
963
|
}
|
|
993
|
-
function
|
|
994
|
-
return t
|
|
964
|
+
function M(e, t) {
|
|
965
|
+
return t ? typeof t == "function" ? t(e) : (console.warn('工具不再支持 "camelize", "snakify" 参数,请自行提供函数来转化 body 内容'), e) : e;
|
|
995
966
|
}
|
|
996
|
-
const
|
|
997
|
-
function
|
|
967
|
+
const Pt = lt("APIError");
|
|
968
|
+
function It(e) {
|
|
998
969
|
const t = {};
|
|
999
970
|
for (const n in e.headers)
|
|
1000
971
|
(n.startsWith("x-") || n.includes("trace") || n.includes("server") || /\b(?:id|uuid)\b/.test(n)) && (t[n] = e.headers[n]);
|
|
1001
972
|
const s = e.url.replace(/^(?:https?:)?\/*/i, "").replace(/\?.+/, ""), r = e.status < 0 ? "unknown" : e.status;
|
|
1002
973
|
return {
|
|
1003
|
-
sentryError: new
|
|
974
|
+
sentryError: new Pt(`${s} | ${r}${e.code ? ` | ${e.code}` : ""}`),
|
|
1004
975
|
sentryTags: {
|
|
1005
976
|
...t,
|
|
1006
977
|
status: r,
|
|
@@ -1016,25 +987,25 @@ function zt(e) {
|
|
|
1016
987
|
}
|
|
1017
988
|
};
|
|
1018
989
|
}
|
|
1019
|
-
function
|
|
990
|
+
function Lt(e) {
|
|
1020
991
|
return e.reduce(
|
|
1021
992
|
(t, [s, r]) => (s && (t[s] = r || ""), t),
|
|
1022
993
|
{}
|
|
1023
994
|
);
|
|
1024
995
|
}
|
|
1025
|
-
function
|
|
1026
|
-
var
|
|
1027
|
-
const n = e.status, i = e.method, a =
|
|
1028
|
-
Object.entries(e.headers || {}).map(([
|
|
1029
|
-
), { ok: h, code: c, data:
|
|
996
|
+
function Wt(e, t, s, r) {
|
|
997
|
+
var b;
|
|
998
|
+
const n = e.status, i = e.method, a = Lt(
|
|
999
|
+
Object.entries(e.headers || {}).map(([w, y]) => [w.toLowerCase(), y])
|
|
1000
|
+
), { ok: h, code: c, data: _, message: f } = Ot(
|
|
1030
1001
|
n,
|
|
1031
1002
|
e.statusText,
|
|
1032
1003
|
e.body,
|
|
1033
1004
|
s.get("responseRule"),
|
|
1034
1005
|
r == null ? void 0 : r.responseRule
|
|
1035
1006
|
);
|
|
1036
|
-
if (!
|
|
1037
|
-
const
|
|
1007
|
+
if (!G(n)) {
|
|
1008
|
+
const w = It({
|
|
1038
1009
|
url: e.url,
|
|
1039
1010
|
method: e.method,
|
|
1040
1011
|
status: n,
|
|
@@ -1044,7 +1015,7 @@ function te(e, t, s, r) {
|
|
|
1044
1015
|
headers: a,
|
|
1045
1016
|
error: e.rawError
|
|
1046
1017
|
});
|
|
1047
|
-
(s.get("errorHandler") ||
|
|
1018
|
+
(s.get("errorHandler") || Ct)({
|
|
1048
1019
|
url: t,
|
|
1049
1020
|
method: i,
|
|
1050
1021
|
status: n,
|
|
@@ -1053,11 +1024,11 @@ function te(e, t, s, r) {
|
|
|
1053
1024
|
headers: a,
|
|
1054
1025
|
rawError: e.rawError,
|
|
1055
1026
|
responseBody: e.body,
|
|
1056
|
-
...
|
|
1027
|
+
...w
|
|
1057
1028
|
});
|
|
1058
1029
|
}
|
|
1059
1030
|
if (n < 0)
|
|
1060
|
-
return
|
|
1031
|
+
return Z(
|
|
1061
1032
|
{ ok: !1, status: n, code: e.statusText, headers: {}, message: "", data: null },
|
|
1062
1033
|
`${i} ${t} ${e.statusText}`,
|
|
1063
1034
|
i,
|
|
@@ -1065,12 +1036,12 @@ function te(e, t, s, r) {
|
|
|
1065
1036
|
s,
|
|
1066
1037
|
r
|
|
1067
1038
|
);
|
|
1068
|
-
const d = { ok: h, data:
|
|
1069
|
-
(
|
|
1039
|
+
const d = { ok: h, data: _, code: c, message: f, status: n, headers: a };
|
|
1040
|
+
(b = s.get("responseHandler")) == null || b({ ...d }, i, t);
|
|
1070
1041
|
const p = h ? f : f || e.statusText;
|
|
1071
|
-
return
|
|
1042
|
+
return Z(d, p, i, t, s, r);
|
|
1072
1043
|
}
|
|
1073
|
-
function
|
|
1044
|
+
function Z(e, t, s, r, n, i) {
|
|
1074
1045
|
const a = n.get("message"), h = a === !1 || (i == null ? void 0 : i.message) === !1 ? !1 : (i == null ? void 0 : i.message) || a;
|
|
1075
1046
|
if (h !== !1) {
|
|
1076
1047
|
const c = typeof h == "function" ? h(e, s, r, t) : t;
|
|
@@ -1078,13 +1049,13 @@ function et(e, t, s, r, n, i) {
|
|
|
1078
1049
|
}
|
|
1079
1050
|
return e;
|
|
1080
1051
|
}
|
|
1081
|
-
function
|
|
1052
|
+
function Ct(e) {
|
|
1082
1053
|
const t = {};
|
|
1083
1054
|
for (const s in e)
|
|
1084
1055
|
s.startsWith("sentry") || (t[s] = e[s]);
|
|
1085
1056
|
console.error("RequestError", t);
|
|
1086
1057
|
}
|
|
1087
|
-
async function
|
|
1058
|
+
async function Dt(e, t, s, r, n) {
|
|
1088
1059
|
const i = n || 0, a = Math.max(0, Math.min(10, (r == null ? void 0 : r.maxRetry) ?? s.get("maxRetry") ?? 0)), h = (r == null ? void 0 : r.retryResolve) ?? s.get("retryResolve"), c = s.get("logHandler");
|
|
1089
1060
|
c == null || c({
|
|
1090
1061
|
type: "prepare",
|
|
@@ -1096,40 +1067,40 @@ async function Wt(e, t, s, r, n) {
|
|
|
1096
1067
|
headers: r == null ? void 0 : r.headers,
|
|
1097
1068
|
options: r
|
|
1098
1069
|
});
|
|
1099
|
-
const
|
|
1070
|
+
const _ = Date.now(), f = await e(t, s, r), d = f.status, p = Date.now() - _, b = `[cost ${p}][${d}] ${d < 0 ? f.body : ""}`;
|
|
1100
1071
|
c == null || c({
|
|
1101
1072
|
type: "finished",
|
|
1102
1073
|
url: t,
|
|
1103
1074
|
method: f.method,
|
|
1104
1075
|
retry: i,
|
|
1105
1076
|
maxRetry: a,
|
|
1106
|
-
message: i === 0 ? `finish ${
|
|
1077
|
+
message: i === 0 ? `finish ${b}` : `retry ${i}/${a} finish ${b}`,
|
|
1107
1078
|
response: f,
|
|
1108
1079
|
headers: f.headers,
|
|
1109
1080
|
cost: p
|
|
1110
1081
|
});
|
|
1111
|
-
const
|
|
1112
|
-
if (!a || i >= a || h === "network" && d > 0 || h === "status" &&
|
|
1082
|
+
const w = G(d);
|
|
1083
|
+
if (!a || i >= a || h === "network" && d > 0 || h === "status" && w || Array.isArray(h) && !h.includes(d) || typeof h == "function" && h(f, i) !== !0)
|
|
1113
1084
|
return f;
|
|
1114
|
-
const
|
|
1115
|
-
return await
|
|
1085
|
+
const y = (r == null ? void 0 : r.retryInterval) ?? s.get("retryInterval") ?? 100;
|
|
1086
|
+
return await at(
|
|
1116
1087
|
Math.max(
|
|
1117
1088
|
100,
|
|
1118
|
-
|
|
1089
|
+
y === "2EB" ? Math.pow(2, i) * 100 : typeof y == "function" ? y(i + 1, { url: t, status: d, method: f.method }) || 0 : y
|
|
1119
1090
|
)
|
|
1120
|
-
), await
|
|
1091
|
+
), await Dt(e, t, s, r, i + 1);
|
|
1121
1092
|
}
|
|
1122
1093
|
export {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1094
|
+
P as A,
|
|
1095
|
+
zt as N,
|
|
1096
|
+
Rt as R,
|
|
1097
|
+
et as a,
|
|
1098
|
+
Bt as b,
|
|
1099
|
+
Kt as c,
|
|
1100
|
+
Gt as d,
|
|
1101
|
+
Lt as f,
|
|
1102
|
+
Ht as g,
|
|
1103
|
+
Wt as h,
|
|
1133
1104
|
j,
|
|
1134
|
-
|
|
1105
|
+
Dt as r
|
|
1135
1106
|
};
|