From fab62e0aa99dd84f71d5e1b169dce64b07933f16 Mon Sep 17 00:00:00 2001 From: what Date: Sat, 25 May 2024 23:24:11 +0800 Subject: [PATCH] v0.9.10 --- dist/ff-request.js | 558 ++++++++++++++++++++-------------------- dist/ff-request.umd.cjs | 2 +- package.json | 2 +- 3 files changed, 280 insertions(+), 282 deletions(-) diff --git a/dist/ff-request.js b/dist/ff-request.js index d002a62..2bc1f52 100644 --- a/dist/ff-request.js +++ b/dist/ff-request.js @@ -1,14 +1,14 @@ var oe = Object.defineProperty; var ae = (t, e, r) => e in t ? oe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; -var A = (t, e, r) => (ae(t, typeof e != "symbol" ? e + "" : e, r), r), k = (t, e, r) => { +var T = (t, e, r) => (ae(t, typeof e != "symbol" ? e + "" : e, r), r), k = (t, e, r) => { if (!e.has(t)) throw TypeError("Cannot " + r); }; -var h = (t, e, r) => (k(t, e, "read from private field"), r ? r.call(t) : e.get(t)), S = (t, e, r) => { +var l = (t, e, r) => (k(t, e, "read from private field"), r ? r.call(t) : e.get(t)), P = (t, e, r) => { if (e.has(t)) throw TypeError("Cannot add the same private member more than once"); e instanceof WeakSet ? e.add(t) : e.set(t, r); -}, M = (t, e, r, n) => (k(t, e, "write to private field"), n ? n.call(t, r) : e.set(t, r), r); +}, $ = (t, e, r, o) => (k(t, e, "write to private field"), o ? o.call(t, r) : e.set(t, r), r); function te(t) { return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; } @@ -17,66 +17,66 @@ function ie(t) { throw new TypeError("Alphabet too long"); for (var e = new Uint8Array(256), r = 0; r < e.length; r++) e[r] = 255; - for (var n = 0; n < t.length; n++) { - var u = t.charAt(n), v = u.charCodeAt(0); - if (e[v] !== 255) - throw new TypeError(u + " is ambiguous"); - e[v] = n; + for (var o = 0; o < t.length; o++) { + var c = t.charAt(o), p = c.charCodeAt(0); + if (e[p] !== 255) + throw new TypeError(c + " is ambiguous"); + e[p] = o; } - var c = t.length, U = t.charAt(0), B = Math.log(c) / Math.log(256), D = Math.log(256) / Math.log(c); - function q(i) { - if (i instanceof Uint8Array || (ArrayBuffer.isView(i) ? i = new Uint8Array(i.buffer, i.byteOffset, i.byteLength) : Array.isArray(i) && (i = Uint8Array.from(i))), !(i instanceof Uint8Array)) + var g = t.length, N = t.charAt(0), B = Math.log(g) / Math.log(256), I = Math.log(256) / Math.log(g); + function q(n) { + if (n instanceof Uint8Array || (ArrayBuffer.isView(n) ? n = new Uint8Array(n.buffer, n.byteOffset, n.byteLength) : Array.isArray(n) && (n = Uint8Array.from(n))), !(n instanceof Uint8Array)) throw new TypeError("Expected Uint8Array"); - if (i.length === 0) + if (n.length === 0) return ""; - for (var a = 0, s = 0, g = 0, f = i.length; g !== f && i[g] === 0; ) - g++, a++; - for (var l = (f - g) * D + 1 >>> 0, d = new Uint8Array(l); g !== f; ) { - for (var T = i[g], E = 0, w = l - 1; (T !== 0 || E < s) && w !== -1; w--, E++) - T += 256 * d[w] >>> 0, d[w] = T % c >>> 0, T = T / c >>> 0; - if (T !== 0) + for (var s = 0, f = 0, a = 0, h = n.length; a !== h && n[a] === 0; ) + a++, s++; + for (var u = (h - a) * I + 1 >>> 0, d = new Uint8Array(u); a !== h; ) { + for (var O = n[a], b = 0, v = u - 1; (O !== 0 || b < f) && v !== -1; v--, b++) + O += 256 * d[v] >>> 0, d[v] = O % g >>> 0, O = O / g >>> 0; + if (O !== 0) throw new Error("Non-zero carry"); - s = E, g++; + f = b, a++; } - for (var o = l - s; o !== l && d[o] === 0; ) - o++; - for (var y = U.repeat(a); o < l; ++o) - y += t.charAt(d[o]); - return y; + for (var i = u - f; i !== u && d[i] === 0; ) + i++; + for (var w = N.repeat(s); i < u; ++i) + w += t.charAt(d[i]); + return w; } - function x(i) { - if (typeof i != "string") + function U(n) { + if (typeof n != "string") throw new TypeError("Expected String"); - if (i.length === 0) + if (n.length === 0) return new Uint8Array(); - for (var a = 0, s = 0, g = 0; i[a] === U; ) - s++, a++; - for (var f = (i.length - a) * B + 1 >>> 0, l = new Uint8Array(f); i[a]; ) { - var d = e[i.charCodeAt(a)]; + for (var s = 0, f = 0, a = 0; n[s] === N; ) + f++, s++; + for (var h = (n.length - s) * B + 1 >>> 0, u = new Uint8Array(h); n[s]; ) { + var d = e[n.charCodeAt(s)]; if (d === 255) return; - for (var T = 0, E = f - 1; (d !== 0 || T < g) && E !== -1; E--, T++) - d += c * l[E] >>> 0, l[E] = d % 256 >>> 0, d = d / 256 >>> 0; + for (var O = 0, b = h - 1; (d !== 0 || O < a) && b !== -1; b--, O++) + d += g * u[b] >>> 0, u[b] = d % 256 >>> 0, d = d / 256 >>> 0; if (d !== 0) throw new Error("Non-zero carry"); - g = T, a++; + a = O, s++; } - for (var w = f - g; w !== f && l[w] === 0; ) - w++; - for (var o = new Uint8Array(s + (f - w)), y = s; w !== f; ) - o[y++] = l[w++]; - return o; + for (var v = h - a; v !== h && u[v] === 0; ) + v++; + for (var i = new Uint8Array(f + (h - v)), w = f; v !== h; ) + i[w++] = u[v++]; + return i; } - function p(i) { - var a = x(i); - if (a) - return a; - throw new Error("Non-base" + c + " character"); + function D(n) { + var s = U(n); + if (s) + return s; + throw new Error("Non-base" + g + " character"); } return { encode: q, - decodeUnsafe: x, - decode: p + decodeUnsafe: U, + decode: D }; } var fe = ie; @@ -85,276 +85,276 @@ var re = {}; (function(t) { (function(e) { e([], function() { - var r = -1, n = -2, u = -3, v = -4, c = -5, U = function(a, s) { - s = s || {}; - var g = s.verbose || !1; - g && console.log("Normalize the JSON Object"), a = typeof a == "string" ? this.JSON.parse(a) : a, g && console.log("Creating a empty dictionary"); - var f = { + var r = -1, o = -2, c = -3, p = -4, g = -5, N = function(s, f) { + f = f || {}; + var a = f.verbose || !1; + a && console.log("Normalize the JSON Object"), s = typeof s == "string" ? this.JSON.parse(s) : s, a && console.log("Creating a empty dictionary"); + var h = { strings: [], integers: [], floats: [] }; - g && console.log("Creating the AST"); - var l = function w(o) { - g && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(o)); - var y = typeof o; - if (o === null) + a && console.log("Creating the AST"); + var u = function v(i) { + a && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(i)); + var w = typeof i; + if (i === null) return { type: "null", - index: u - }; - if (typeof o > "u") - return { - type: "undefined", index: c }; - if (o instanceof Array) { - var _ = ["@"]; - for (var O in o) - o.hasOwnProperty(O) && _.push(w(o[O])); - return _; + if (typeof i > "u") + return { + type: "undefined", + index: g + }; + if (i instanceof Array) { + var S = ["@"]; + for (var E in i) + i.hasOwnProperty(E) && S.push(v(i[E])); + return S; } - if (y === "object") { - var _ = ["$"]; - for (var R in o) - o.hasOwnProperty(R) && (_.push(w(R)), _.push(w(o[R]))); - return _; + if (w === "object") { + var S = ["$"]; + for (var x in i) + i.hasOwnProperty(x) && (S.push(v(x)), S.push(v(i[x]))); + return S; } - if (o === "") + if (i === "") return { type: "empty", - index: v + index: p }; - if (y === "string") { - var P = i.call(f.strings, o); - return P == -1 && (f.strings.push(D(o)), P = f.strings.length - 1), { + if (w === "string") { + var A = n.call(h.strings, i); + return A == -1 && (h.strings.push(I(i)), A = h.strings.length - 1), { type: "strings", - index: P + index: A }; } - if (y === "number" && o % 1 === 0) { - var P = i.call(f.integers, o); - return P == -1 && (f.integers.push(x(o)), P = f.integers.length - 1), { + if (w === "number" && i % 1 === 0) { + var A = n.call(h.integers, i); + return A == -1 && (h.integers.push(U(i)), A = h.integers.length - 1), { type: "integers", - index: P + index: A }; } - if (y === "number") { - var P = i.call(f.floats, o); - return P == -1 && (f.floats.push(o), P = f.floats.length - 1), { + if (w === "number") { + var A = n.call(h.floats, i); + return A == -1 && (h.floats.push(i), A = h.floats.length - 1), { type: "floats", - index: P + index: A }; } - if (y === "boolean") + if (w === "boolean") return { type: "boolean", - index: o ? r : n + index: i ? r : o }; - throw new Error("Unexpected argument of type " + typeof o); - }(a), d = f.strings.length, T = f.integers.length; - f.floats.length, g && console.log("Parsing the dictionary"); - var E = f.strings.join("|"); - return E += "^" + f.integers.join("|"), E += "^" + f.floats.join("|"), g && console.log("Parsing the structure"), E += "^" + function w(o) { - if (g && console.log("Calling a recursiveParser with " + this.JSON.stringify(o)), o instanceof Array) { - var y = o.shift(); - for (var _ in o) - o.hasOwnProperty(_) && (y += w(o[_]) + "|"); - return (y[y.length - 1] === "|" ? y.slice(0, -1) : y) + "]"; + throw new Error("Unexpected argument of type " + typeof i); + }(s), d = h.strings.length, O = h.integers.length; + h.floats.length, a && console.log("Parsing the dictionary"); + var b = h.strings.join("|"); + return b += "^" + h.integers.join("|"), b += "^" + h.floats.join("|"), a && console.log("Parsing the structure"), b += "^" + function v(i) { + if (a && console.log("Calling a recursiveParser with " + this.JSON.stringify(i)), i instanceof Array) { + var w = i.shift(); + for (var S in i) + i.hasOwnProperty(S) && (w += v(i[S]) + "|"); + return (w[w.length - 1] === "|" ? w.slice(0, -1) : w) + "]"; } - var O = o.type, R = o.index; - if (O === "strings") - return x(R); - if (O === "integers") - return x(d + R); - if (O === "floats") - return x(d + T + R); - if (O === "boolean") - return o.index; - if (O === "null") - return u; - if (O === "undefined") + var E = i.type, x = i.index; + if (E === "strings") + return U(x); + if (E === "integers") + return U(d + x); + if (E === "floats") + return U(d + O + x); + if (E === "boolean") + return i.index; + if (E === "null") return c; - if (O === "empty") - return v; + if (E === "undefined") + return g; + if (E === "empty") + return p; throw new TypeError("The item is alien!"); - }(l), g && console.log("Ending parser"), s.debug ? { - dictionary: f, - ast: l, - packed: E - } : E; - }, B = function(a, s) { - s = s || {}; - var g = a.split("^"); - s.verbose && console.log("Building dictionary"); - var f = [], l = g[0]; - if (l !== "") { - l = l.split("|"), s.verbose && console.log("Parse the strings dictionary"); - for (var d = 0, T = l.length; d < T; d++) - f.push(q(l[d])); + }(u), a && console.log("Ending parser"), f.debug ? { + dictionary: h, + ast: u, + packed: b + } : b; + }, B = function(s, f) { + f = f || {}; + var a = s.split("^"); + f.verbose && console.log("Building dictionary"); + var h = [], u = a[0]; + if (u !== "") { + u = u.split("|"), f.verbose && console.log("Parse the strings dictionary"); + for (var d = 0, O = u.length; d < O; d++) + h.push(q(u[d])); } - if (l = g[1], l !== "") { - l = l.split("|"), s.verbose && console.log("Parse the integers dictionary"); - for (var d = 0, T = l.length; d < T; d++) - f.push(p(l[d])); + if (u = a[1], u !== "") { + u = u.split("|"), f.verbose && console.log("Parse the integers dictionary"); + for (var d = 0, O = u.length; d < O; d++) + h.push(D(u[d])); } - if (l = g[2], l !== "") { - l = l.split("|"), s.verbose && console.log("Parse the floats dictionary"); - for (var d = 0, T = l.length; d < T; d++) - f.push(parseFloat(l[d])); + if (u = a[2], u !== "") { + u = u.split("|"), f.verbose && console.log("Parse the floats dictionary"); + for (var d = 0, O = u.length; d < O; d++) + h.push(parseFloat(u[d])); } - l = null, s.verbose && console.log("Tokenizing the structure"); - for (var E = "", w = [], o = g[3].length, d = 0; d < o; d++) { - var y = g[3].charAt(d); - y === "|" || y === "$" || y === "@" || y === "]" ? (E && (w.push(p(E)), E = ""), y !== "|" && w.push(y)) : E += y; + u = null, f.verbose && console.log("Tokenizing the structure"); + for (var b = "", v = [], i = a[3].length, d = 0; d < i; d++) { + var w = a[3].charAt(d); + w === "|" || w === "$" || w === "@" || w === "]" ? (b && (v.push(D(b)), b = ""), w !== "|" && v.push(w)) : b += w; } - var _ = w.length, O = 0; - return s.verbose && console.log("Starting recursive parser"), function R() { - var P = w[O++]; - if (s.verbose && console.log("Reading collection type " + (P === "$" ? "object" : "Array")), P === "@") { - for (var b = []; O < _; O++) { - var N = w[O]; - if (s.verbose && console.log("Read " + N + " symbol"), N === "]") - return b; - if (N === "@" || N === "$") - b.push(R()); + var S = v.length, E = 0; + return f.verbose && console.log("Starting recursive parser"), function x() { + var A = v[E++]; + if (f.verbose && console.log("Reading collection type " + (A === "$" ? "object" : "Array")), A === "@") { + for (var y = []; E < S; E++) { + var C = v[E]; + if (f.verbose && console.log("Read " + C + " symbol"), C === "]") + return y; + if (C === "@" || C === "$") + y.push(x()); else - switch (N) { + switch (C) { case r: - b.push(!0); + y.push(!0); break; - case n: - b.push(!1); - break; - case u: - b.push(null); + case o: + y.push(!1); break; case c: - b.push(void 0); + y.push(null); break; - case v: - b.push(""); + case g: + y.push(void 0); + break; + case p: + y.push(""); break; default: - b.push(f[N]); + y.push(h[C]); } } - return s.verbose && console.log("Parsed " + this.JSON.stringify(b)), b; + return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y; } - if (P === "$") { - for (var b = {}; O < _; O++) { - var C = w[O]; - if (C === "]") - return b; - C === v ? C = "" : C = f[C]; - var N = w[++O]; - if (N === "@" || N === "$") - b[C] = R(); + if (A === "$") { + for (var y = {}; E < S; E++) { + var _ = v[E]; + if (_ === "]") + return y; + _ === p ? _ = "" : _ = h[_]; + var C = v[++E]; + if (C === "@" || C === "$") + y[_] = x(); else - switch (N) { + switch (C) { case r: - b[C] = !0; + y[_] = !0; break; - case n: - b[C] = !1; - break; - case u: - b[C] = null; + case o: + y[_] = !1; break; case c: - b[C] = void 0; + y[_] = null; break; - case v: - b[C] = ""; + case g: + y[_] = void 0; + break; + case p: + y[_] = ""; break; default: - b[C] = f[N]; + y[_] = h[C]; } } - return s.verbose && console.log("Parsed " + this.JSON.stringify(b)), b; + return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y; } - throw new TypeError("Bad token " + P + " isn't a type"); + throw new TypeError("Bad token " + A + " isn't a type"); }(); - }, D = function(a) { - return typeof a != "string" ? a : a.replace(/[\+ \|\^\%]/g, function(s) { + }, I = function(s) { + return typeof s != "string" ? s : s.replace(/[\+ \|\^\%]/g, function(f) { return { " ": "+", "+": "%2B", "|": "%7C", "^": "%5E", "%": "%25" - }[s]; + }[f]; }); - }, q = function(a) { - return typeof a != "string" ? a : a.replace(/\+|%2B|%7C|%5E|%25/g, function(s) { + }, q = function(s) { + return typeof s != "string" ? s : s.replace(/\+|%2B|%7C|%5E|%25/g, function(f) { return { "+": " ", "%2B": "+", "%7C": "|", "%5E": "^", "%25": "%" - }[s]; + }[f]; }); - }, x = function(a) { - return Number.prototype.toString.call(a, 36).toUpperCase(); - }, p = function(a) { - return parseInt(a, 36); - }, i = Array.prototype.indexOf || function(a, s) { - for (var g = s || 0, f = this.length; g < f; g++) - if (this[g] === a) - return g; + }, U = function(s) { + return Number.prototype.toString.call(s, 36).toUpperCase(); + }, D = function(s) { + return parseInt(s, 36); + }, n = Array.prototype.indexOf || function(s, f) { + for (var a = f || 0, h = this.length; a < h; a++) + if (this[a] === s) + return a; return -1; }; return { JSON, - pack: U, + pack: N, unpack: B }; }); })(function(e, r) { - var n = r(); - for (var u in n) - t[u] = n[u]; + var o = r(); + for (var c in o) + t[c] = o[c]; }); })(re); const ee = /* @__PURE__ */ te(re); -var J, z, j, I, L, H, K, V, Y; +var J, z, j, M, L, H, K, V, Y; class X { - constructor(e, r, n, u, v) { - A(this, "code", 0); - A(this, "message", "操作成功"); - A(this, "data", null); - A(this, "url", ""); - A(this, "res", ""); + constructor(e, r, o, c, p) { + T(this, "code", 0); + T(this, "message", "操作成功"); + T(this, "data", null); + T(this, "url", ""); + T(this, "res", ""); // static [Symbol.hasInstance](self) { return self?.IS_ECHO_MSG !== undefined } - S(this, J, null); + P(this, J, null); // 判断返回 Response 对象, 还是 Response 中的 data - S(this, z, !0); + P(this, z, !0); // 判罚是否已经给出错误提示 - S(this, j, !0); - S(this, I, { - get: (e, r) => h(this, L).call(this, r), - ownKeys: () => Object.keys(h(this, I).getPrototypeOf() || {}), - getPrototypeOf: () => h(this, z) ? this : this.data, + P(this, j, !0); + P(this, M, { + get: (e, r) => l(this, L).call(this, r), + ownKeys: () => Object.keys(l(this, M).getPrototypeOf() || {}), + getPrototypeOf: () => l(this, z) ? this : this.data, getOwnPropertyDescriptor: () => ({ configurable: !0, enumerable: !0, writable: !0, - value: h(this, I).getPrototypeOf() + value: l(this, M).getPrototypeOf() }) }); - S(this, L, (e) => e === "$toast" ? h(this, K) : e === "msg" ? h(this, H) : e === "then" || e === "resp" ? (M(this, j, !0), M(this, z, e === "resp"), h(this, V)) : e === "catch" ? h(this, Y) : e === "IS_ECHO_MSG" ? h(this, j) : Reflect.get(this, e)); - S(this, H, (e = (n) => n, r = !1) => (h(this, K).call(this), M(this, z, r), Promise.resolve(e == null ? void 0 : e(h(this, I).getPrototypeOf())))); - S(this, K, () => { - h(this, j) && (M(this, j, !1), we.onToast(this.code, this.message)); + P(this, L, (e) => e === "$toast" ? l(this, K) : e === "msg" ? l(this, H) : e === "then" || e === "resp" ? ($(this, j, !0), $(this, z, e === "resp"), l(this, V)) : e === "catch" ? l(this, Y) : e === "IS_ECHO_MSG" ? l(this, j) : Reflect.get(this, e)); + P(this, H, (e = (o) => o, r = !1) => (l(this, K).call(this), $(this, z, r), Promise.resolve(e == null ? void 0 : e(l(this, M).getPrototypeOf())))); + P(this, K, () => { + l(this, j) && ($(this, j, !1), we.onToast(this.code, this.message)); }); - S(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(h(this, I).getPrototypeOf())) : Promise.reject(h(this, J))); - S(this, Y, (e) => Promise.resolve(e(h(this, J)))); - return this.code = e, this.message = r, this.data = n, this.url = u, this.res = v, M(this, J, new Proxy(this, h(this, I))); + P(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(l(this, M).getPrototypeOf())) : Promise.reject(l(this, J))); + P(this, Y, (e) => Promise.resolve(e(l(this, J)))); + return this.code = e, this.message = r, this.data = o, this.url = c, this.res = p, $(this, J, new Proxy(this, l(this, M))); } } -J = new WeakMap(), z = new WeakMap(), j = new WeakMap(), I = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap(); -const W = (t, e, r, n = "/", u = "") => new X(t, e, r, n, u); +J = new WeakMap(), z = new WeakMap(), j = new WeakMap(), M = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap(); +const W = (t, e, r, o = "/", c = "") => new X(t, e, r, o, c); var ne = [ "utf8", "utf-8", @@ -366,11 +366,11 @@ function le(t) { this.encoding = "utf-8", this.encode = function(e) { if (typeof e != "string") throw new TypeError("passed argument must be of tye string"); - var r = unescape(encodeURIComponent(e)), n = new Uint8Array(r.length); - const u = r.split(""); - for (let v = 0; v < u.length; v++) - n[v] = u[v].charCodeAt(0); - return n; + var r = unescape(encodeURIComponent(e)), o = new Uint8Array(r.length); + const c = r.split(""); + for (let p = 0; p < c.length; p++) + o[p] = c[p].charCodeAt(0); + return o; }; } function ue(t) { @@ -379,14 +379,14 @@ function ue(t) { this.encoding = "utf-8", this.decode = function(e, r) { if (typeof e > "u") return ""; - var n = typeof r < "u" && n in r ? r.stream : !1; - if (typeof n != "boolean") + var o = typeof r < "u" && o in r ? r.stream : !1; + if (typeof o != "boolean") throw new TypeError("stream option must be boolean"); if (ArrayBuffer.isView(e)) { - var u = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), v = new Array(u.length); - for (let c = 0; c < u.length; c++) - v[c] = String.fromCharCode(u[c]); - return decodeURIComponent(escape(v.join(""))); + var c = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), p = new Array(c.length); + for (let g = 0; g < c.length; g++) + p[g] = String.fromCharCode(c[g]); + return decodeURIComponent(escape(p.join(""))); } else throw new TypeError("passed argument must be an array buffer view"); }; @@ -401,77 +401,75 @@ const ce = new se.TextEncoder("utf8"), ge = new se.TextDecoder("utf8"), de = (t) e = e * 33 ^ t.charCodeAt(r); return (e >>> 0).toString(16); }, be = (t, e) => t.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), pe = (t) => ce.encode(t || ""), ve = (t) => ge.decode(new DataView(t), {}); -var F, G, Q, m, $; +var F, G, Q, m, R; class Z { - constructor(e, r, n = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { - S(this, F, void 0); - S(this, G, void 0); - S(this, Q, void 0); - S(this, m, { + constructor(e, r, o = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { + P(this, F, void 0); + P(this, G, void 0); + P(this, Q, void 0); + P(this, m, { "#": /* @__PURE__ */ new Map(), // 系统缓存 $: /* @__PURE__ */ new Map() // 普通缓存 }); - S(this, $, /* @__PURE__ */ new Map()); - A(this, "request", ({ url: e = "/", method: r = "GET", ...n }, u = !1) => { - var x; - const v = r.toUpperCase(), c = de(JSON.stringify([e, v, n])), U = (x = e == null ? void 0 : e.includes) != null && x.call(e, "/_/") ? "#" : "$", { promise: B, resolve: D, reject: q } = Promise.withResolvers(); - return h(this, m)[U].has(c) ? (console.log("缓存命中", e), D(h(this, m)[U].get(c))) : h(this, $).has(c) ? h(this, $).get(c).push([D, q]) : (h(this, $).set(c, [[D, q]]), h(this, F).call(this, { url: e, method: v, ...n }).then((p) => { - if (![0, 1].includes(p.code)) - throw W(p.code, p.msg, p.data, e, p == null ? void 0 : p.res); - return [p.code, p.msg, p.data, e, p == null ? void 0 : p.res]; - }).then((p) => ((U == "#" || u && v === "GET") && h(this, m)[U].set(c, p), p)).then((p) => h(this, $).get(c).forEach((i, a, s) => { - i && i[0](p), delete s[a]; - })).catch((p) => { - h(this, m)[U].delete(c), h(this, $).get(c).forEach((i, a, s) => { - i && i[1](p instanceof X ? p : W(-1, p, null, e)), delete s[a]; + P(this, R, /* @__PURE__ */ new Map()); + T(this, "request", ({ url: e = "/", method: r = "GET", ...o }, c = !1) => { + var U, D; + const p = r.toUpperCase(), g = de(JSON.stringify([e, p, o])), N = (U = e == null ? void 0 : e.includes) != null && U.call(e, "/_/") ? "#" : "$", { promise: B, resolve: I, reject: q } = Promise.withResolvers(); + return l(this, m)[N].has(g) ? (console.log("缓存命中", e), I(l(this, m)[N].get(g))) : (l(this, R).has(g) ? l(this, R).get(g).push([I, q]) : l(this, R).set(g, [[I, q]]), (D = l(this, R).get(g)) != null && D.some((n) => n) && l(this, F).call(this, { url: e, method: p, ...o }).then((n) => { + if (![0, 1].includes(n.code)) + throw W(n.code, n.msg, n.data, e, n == null ? void 0 : n.res); + return [n.code, n.msg, n.data, e, n == null ? void 0 : n.res]; + }).then((n) => ((N == "#" || c && p === "GET") && l(this, m)[N].set(g, n), n)).then((n) => l(this, R).get(g).forEach((s, f, a) => { + s && s[0](n), delete a[f]; + })).catch((n) => { + l(this, m)[N].delete(g), l(this, R).get(g).forEach((s, f, a) => { + s && s[1](n instanceof X ? n : W(-1, n, null, e)), delete a[f]; }); - }).finally(() => { - console.log(1111, h(this, $).get(c)), h(this, $).delete(c); - })), new Proxy(B, { - get: (p, i) => (...a) => p.then((s) => W(...s)[i](...a)).catch((s) => { - if (!s instanceof X) - throw s; - return typeof s[i] == "function" ? s[i](...a) : s[i]; + }).finally(() => l(this, R).delete(g))), new Proxy(B, { + get: (n, s) => (...f) => n.then((a) => W(...a)[s](...f)).catch((a) => { + if (!a instanceof X) + throw a; + return typeof a[s] == "function" ? a[s](...f) : a[s]; }) }); }); - A(this, "get", (e, r = {}) => this.request({ url: e, method: "GET", params: r })); - A(this, "post", (e, r = {}, n = {}) => this.request({ url: e, method: "POST", data: r, params: n })); - A(this, "put", (e, r = {}, n = {}) => this.request({ url: e, method: "PUT", data: r, params: n })); - A(this, "del", (e, r = {}, n = {}) => this.request({ url: e, method: "DELETE", data: r, params: n })); - A(this, "download", (e, r) => { + T(this, "get", (e, r = {}) => this.request({ url: e, method: "GET", params: r })); + T(this, "post", (e, r = {}, o = {}) => this.request({ url: e, method: "POST", data: r, params: o })); + T(this, "put", (e, r = {}, o = {}) => this.request({ url: e, method: "PUT", data: r, params: o })); + T(this, "del", (e, r = {}, o = {}) => this.request({ url: e, method: "DELETE", data: r, params: o })); + T(this, "download", (e, r) => { }); - A(this, "cache", (e, r = {}) => this.request({ url: e, method: "GET", params: r }, !0)); - A(this, "list", (e, r = {}) => this.get(`/api/${e}/${this.encode(r)}`)); - A(this, "getAppInfo", () => { + T(this, "cache", (e, r = {}) => this.request({ url: e, method: "GET", params: r }, !0)); + T(this, "list", (e, r = {}) => this.get(`/api/${e}/${this.encode(r)}`)); + T(this, "getAppInfo", () => { }); - A(this, "refreshCache", (e = !1) => { - e && h(this, m)["#"].clear(), h(this, m).$.clear(); + T(this, "refreshCache", (e = !1) => { + e && l(this, m)["#"].clear(), l(this, m).$.clear(); }); - A(this, "decode", (e = "", r = {}) => { + T(this, "decode", (e = "", r = {}) => { if (e === void 0 || e === "" || e === null) return r; try { - const n = h(this, G).decode(e).buffer; - return ee.unpack(ve(n)); + const o = l(this, G).decode(e).buffer; + return ee.unpack(ve(o)); } catch { return console.warn("core.decode", e), r; } }); - A(this, "encode", (e = {}) => { - const r = JSON.stringify(e, (n, u) => u === void 0 ? null : u); - return h(this, G).encode(pe(ee.pack(r))); + T(this, "encode", (e = {}) => { + const r = JSON.stringify(e, (o, c) => c === void 0 ? null : c); + return l(this, G).encode(pe(ee.pack(r))); }); - M(this, Q, e), M(this, F, n), M(this, G, he(r)); + $(this, Q, e), $(this, F, o), $(this, G, he(r)); } } -F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), $ = new WeakMap(); +F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), R = new WeakMap(); const we = Z; Z.onUnhandledRejection = (t) => { - var e, r, n, u, v, c; - t != null && t.IS_ECHO_MSG ? ((e = t == null ? void 0 : t.$toast) == null || e.call(t), (r = t == null ? void 0 : t.preventDefault) == null || r.call(t)) : (n = t.reason) != null && n.IS_ECHO_MSG && ((v = (u = t.reason) == null ? void 0 : u.$toast) == null || v.call(u), (c = t == null ? void 0 : t.preventDefault) == null || c.call(t)); + var e, r, o, c, p, g; + t != null && t.IS_ECHO_MSG ? ((e = t == null ? void 0 : t.$toast) == null || e.call(t), (r = t == null ? void 0 : t.preventDefault) == null || r.call(t)) : (o = t.reason) != null && o.IS_ECHO_MSG && ((p = (c = t.reason) == null ? void 0 : c.$toast) == null || p.call(c), (g = t == null ? void 0 : t.preventDefault) == null || g.call(t)); }; Z.onToast = (t, e) => [0, 1].includes(t) ? console.log(e) : console.warn(e); export { diff --git a/dist/ff-request.umd.cjs b/dist/ff-request.umd.cjs index 6a22f49..95e928d 100644 --- a/dist/ff-request.umd.cjs +++ b/dist/ff-request.umd.cjs @@ -1 +1 @@ -(function(p,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(p=typeof globalThis<"u"?globalThis:p||self,w(p["ff-request"]={}))})(this,function(p){"use strict";var ye=Object.defineProperty;var be=(p,w,A)=>w in p?ye(p,w,{enumerable:!0,configurable:!0,writable:!0,value:A}):p[w]=A;var _=(p,w,A)=>(be(p,typeof w!="symbol"?w+"":w,A),A),ue=(p,w,A)=>{if(!w.has(p))throw TypeError("Cannot "+A)};var h=(p,w,A)=>(ue(p,w,"read from private field"),A?A.call(p):w.get(p)),N=(p,w,A)=>{if(w.has(p))throw TypeError("Cannot add the same private member more than once");w instanceof WeakSet?w.add(p):w.set(p,A)},D=(p,w,A,Y)=>(ue(p,w,"write to private field"),Y?Y.call(p,A):w.set(p,A),A);var G,B,J,q,Q,W,L,X,Z,H,K,k,I,$;function w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function A(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r>>0,g=new Uint8Array(l);d!==f;){for(var P=a[d],T=0,b=l-1;(P!==0||T>>0,g[b]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");n=T,d++}for(var s=l-n;s!==l&&g[s]===0;)s++;for(var E=m.repeat(o);s>>0,l=new Uint8Array(f);a[o];){var g=e[a.charCodeAt(o)];if(g===255)return;for(var P=0,T=f-1;(g!==0||P>>0,l[T]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");d=P,o++}for(var b=f-d;b!==f&&l[b]===0;)b++;for(var s=new Uint8Array(n+(f-b)),E=n;b!==f;)s[E++]=l[b++];return s}function v(a){var o=M(a);if(o)return o;throw new Error("Non-base"+c+" character")}return{encode:F,decodeUnsafe:M,decode:v}}var Y=A;const ce=w(Y);var ne={};(function(t){(function(e){e([],function(){var r=-1,i=-2,u=-3,y=-4,c=-5,m=function(o,n){n=n||{};var d=n.verbose||!1;d&&console.log("Normalize the JSON Object"),o=typeof o=="string"?this.JSON.parse(o):o,d&&console.log("Creating a empty dictionary");var f={strings:[],integers:[],floats:[]};d&&console.log("Creating the AST");var l=function b(s){d&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(s));var E=typeof s;if(s===null)return{type:"null",index:u};if(typeof s>"u")return{type:"undefined",index:c};if(s instanceof Array){var U=["@"];for(var S in s)s.hasOwnProperty(S)&&U.push(b(s[S]));return U}if(E==="object"){var U=["$"];for(var j in s)s.hasOwnProperty(j)&&(U.push(b(j)),U.push(b(s[j])));return U}if(s==="")return{type:"empty",index:y};if(E==="string"){var C=a.call(f.strings,s);return C==-1&&(f.strings.push(z(s)),C=f.strings.length-1),{type:"strings",index:C}}if(E==="number"&&s%1===0){var C=a.call(f.integers,s);return C==-1&&(f.integers.push(M(s)),C=f.integers.length-1),{type:"integers",index:C}}if(E==="number"){var C=a.call(f.floats,s);return C==-1&&(f.floats.push(s),C=f.floats.length-1),{type:"floats",index:C}}if(E==="boolean")return{type:"boolean",index:s?r:i};throw new Error("Unexpected argument of type "+typeof s)}(o),g=f.strings.length,P=f.integers.length;f.floats.length,d&&console.log("Parsing the dictionary");var T=f.strings.join("|");return T+="^"+f.integers.join("|"),T+="^"+f.floats.join("|"),d&&console.log("Parsing the structure"),T+="^"+function b(s){if(d&&console.log("Calling a recursiveParser with "+this.JSON.stringify(s)),s instanceof Array){var E=s.shift();for(var U in s)s.hasOwnProperty(U)&&(E+=b(s[U])+"|");return(E[E.length-1]==="|"?E.slice(0,-1):E)+"]"}var S=s.type,j=s.index;if(S==="strings")return M(j);if(S==="integers")return M(g+j);if(S==="floats")return M(g+P+j);if(S==="boolean")return s.index;if(S==="null")return u;if(S==="undefined")return c;if(S==="empty")return y;throw new TypeError("The item is alien!")}(l),d&&console.log("Ending parser"),n.debug?{dictionary:f,ast:l,packed:T}:T},V=function(o,n){n=n||{};var d=o.split("^");n.verbose&&console.log("Building dictionary");var f=[],l=d[0];if(l!==""){l=l.split("|"),n.verbose&&console.log("Parse the strings dictionary");for(var g=0,P=l.length;gh(this,Q).call(this,r),ownKeys:()=>Object.keys(h(this,q).getPrototypeOf()||{}),getPrototypeOf:()=>h(this,B)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:h(this,q).getPrototypeOf()})});N(this,Q,e=>e==="$toast"?h(this,L):e==="msg"?h(this,W):e==="then"||e==="resp"?(D(this,J,!0),D(this,B,e==="resp"),h(this,X)):e==="catch"?h(this,Z):e==="IS_ECHO_MSG"?h(this,J):Reflect.get(this,e));N(this,W,(e=i=>i,r=!1)=>(h(this,L).call(this),D(this,B,r),Promise.resolve(e==null?void 0:e(h(this,q).getPrototypeOf()))));N(this,L,()=>{h(this,J)&&(D(this,J,!1),le.onToast(this.code,this.message))});N(this,X,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(h(this,q).getPrototypeOf())):Promise.reject(h(this,G)));N(this,Z,e=>Promise.resolve(e(h(this,G))));return this.code=e,this.message=r,this.data=i,this.url=u,this.res=y,D(this,G,new Proxy(this,h(this,q)))}}G=new WeakMap,B=new WeakMap,J=new WeakMap,q=new WeakMap,Q=new WeakMap,W=new WeakMap,L=new WeakMap,X=new WeakMap,Z=new WeakMap;const te=(t,e,r,i="/",u="")=>new ee(t,e,r,i,u);var ie=["utf8","utf-8","unicode-1-1-utf-8"];function de(t){if(ie.indexOf(t)<0&&typeof t<"u"&&t!=null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if(typeof e!="string")throw new TypeError("passed argument must be of tye string");var r=unescape(encodeURIComponent(e)),i=new Uint8Array(r.length);const u=r.split("");for(let y=0;y"u")return"";var i=typeof r<"u"&&i in r?r.stream:!1;if(typeof i!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var u=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),y=new Array(u.length);for(let c=0;c{let e=5381;for(let r=0;r>>0).toString(16)},we=(t,e)=>t.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),fe=t=>pe.encode(t||""),he=t=>ve.decode(new DataView(t),{});class re{constructor(e,r,i=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){N(this,H,void 0);N(this,K,void 0);N(this,k,void 0);N(this,I,{"#":new Map,$:new Map});N(this,$,new Map);_(this,"request",({url:e="/",method:r="GET",...i},u=!1)=>{var M;const y=r.toUpperCase(),c=ae(JSON.stringify([e,y,i])),m=(M=e==null?void 0:e.includes)!=null&&M.call(e,"/_/")?"#":"$",{promise:V,resolve:z,reject:F}=Promise.withResolvers();return h(this,I)[m].has(c)?(console.log("缓存命中",e),z(h(this,I)[m].get(c))):h(this,$).has(c)?h(this,$).get(c).push([z,F]):(h(this,$).set(c,[[z,F]]),h(this,H).call(this,{url:e,method:y,...i}).then(v=>{if(![0,1].includes(v.code))throw te(v.code,v.msg,v.data,e,v==null?void 0:v.res);return[v.code,v.msg,v.data,e,v==null?void 0:v.res]}).then(v=>((m=="#"||u&&y==="GET")&&h(this,I)[m].set(c,v),v)).then(v=>h(this,$).get(c).forEach((a,o,n)=>{a&&a[0](v),delete n[o]})).catch(v=>{h(this,I)[m].delete(c),h(this,$).get(c).forEach((a,o,n)=>{a&&a[1](v instanceof ee?v:te(-1,v,null,e)),delete n[o]})}).finally(()=>{console.log(1111,h(this,$).get(c)),h(this,$).delete(c)})),new Proxy(V,{get:(v,a)=>(...o)=>v.then(n=>te(...n)[a](...o)).catch(n=>{if(!n instanceof ee)throw n;return typeof n[a]=="function"?n[a](...o):n[a]})})});_(this,"get",(e,r={})=>this.request({url:e,method:"GET",params:r}));_(this,"post",(e,r={},i={})=>this.request({url:e,method:"POST",data:r,params:i}));_(this,"put",(e,r={},i={})=>this.request({url:e,method:"PUT",data:r,params:i}));_(this,"del",(e,r={},i={})=>this.request({url:e,method:"DELETE",data:r,params:i}));_(this,"download",(e,r)=>{});_(this,"cache",(e,r={})=>this.request({url:e,method:"GET",params:r},!0));_(this,"list",(e,r={})=>this.get(`/api/${e}/${this.encode(r)}`));_(this,"getAppInfo",()=>{});_(this,"refreshCache",(e=!1)=>{e&&h(this,I)["#"].clear(),h(this,I).$.clear()});_(this,"decode",(e="",r={})=>{if(e===void 0||e===""||e===null)return r;try{const i=h(this,K).decode(e).buffer;return se.unpack(he(i))}catch{return console.warn("core.decode",e),r}});_(this,"encode",(e={})=>{const r=JSON.stringify(e,(i,u)=>u===void 0?null:u);return h(this,K).encode(fe(se.pack(r)))});D(this,k,e),D(this,H,i),D(this,K,ce(r))}}H=new WeakMap,K=new WeakMap,k=new WeakMap,I=new WeakMap,$=new WeakMap;const le=re;re.onUnhandledRejection=t=>{var e,r,i,u,y,c;t!=null&&t.IS_ECHO_MSG?((e=t==null?void 0:t.$toast)==null||e.call(t),(r=t==null?void 0:t.preventDefault)==null||r.call(t)):(i=t.reason)!=null&&i.IS_ECHO_MSG&&((y=(u=t.reason)==null?void 0:u.$toast)==null||y.call(u),(c=t==null?void 0:t.preventDefault)==null||c.call(t))},re.onToast=(t,e)=>[0,1].includes(t)?console.log(e):console.warn(e),p.default=le,p.signature=ae,p.str2uint8array=fe,p.trim=we,p.uint8array2str=he,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(p,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(p=typeof globalThis<"u"?globalThis:p||self,v(p["ff-request"]={}))})(this,function(p){"use strict";var ye=Object.defineProperty;var be=(p,v,S)=>v in p?ye(p,v,{enumerable:!0,configurable:!0,writable:!0,value:S}):p[v]=S;var P=(p,v,S)=>(be(p,typeof v!="symbol"?v+"":v,S),S),ue=(p,v,S)=>{if(!v.has(p))throw TypeError("Cannot "+S)};var l=(p,v,S)=>(ue(p,v,"read from private field"),S?S.call(p):v.get(p)),C=(p,v,S)=>{if(v.has(p))throw TypeError("Cannot add the same private member more than once");v instanceof WeakSet?v.add(p):v.set(p,S)},I=(p,v,S,Y)=>(ue(p,v,"write to private field"),Y?Y.call(p,S):v.set(p,S),S);var G,B,q,D,Q,W,L,X,Z,H,K,k,j,R;function v(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function S(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,g=new Uint8Array(u);i!==h;){for(var A=r[i],O=0,y=u-1;(A!==0||O>>0,g[y]=A%d>>>0,A=A/d>>>0;if(A!==0)throw new Error("Non-zero carry");f=O,i++}for(var o=u-f;o!==u&&g[o]===0;)o++;for(var b=m.repeat(s);o>>0,u=new Uint8Array(h);r[s];){var g=e[r.charCodeAt(s)];if(g===255)return;for(var A=0,O=h-1;(g!==0||A>>0,u[O]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");i=A,s++}for(var y=h-i;y!==h&&u[y]===0;)y++;for(var o=new Uint8Array(f+(h-y)),b=f;y!==h;)o[b++]=u[y++];return o}function z(r){var s=$(r);if(s)return s;throw new Error("Non-base"+d+" character")}return{encode:F,decodeUnsafe:$,decode:z}}var Y=S;const ce=v(Y);var ne={};(function(t){(function(e){e([],function(){var n=-1,a=-2,c=-3,w=-4,d=-5,m=function(s,f){f=f||{};var i=f.verbose||!1;i&&console.log("Normalize the JSON Object"),s=typeof s=="string"?this.JSON.parse(s):s,i&&console.log("Creating a empty dictionary");var h={strings:[],integers:[],floats:[]};i&&console.log("Creating the AST");var u=function y(o){i&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(o));var b=typeof o;if(o===null)return{type:"null",index:c};if(typeof o>"u")return{type:"undefined",index:d};if(o instanceof Array){var N=["@"];for(var T in o)o.hasOwnProperty(T)&&N.push(y(o[T]));return N}if(b==="object"){var N=["$"];for(var M in o)o.hasOwnProperty(M)&&(N.push(y(M)),N.push(y(o[M])));return N}if(o==="")return{type:"empty",index:w};if(b==="string"){var _=r.call(h.strings,o);return _==-1&&(h.strings.push(J(o)),_=h.strings.length-1),{type:"strings",index:_}}if(b==="number"&&o%1===0){var _=r.call(h.integers,o);return _==-1&&(h.integers.push($(o)),_=h.integers.length-1),{type:"integers",index:_}}if(b==="number"){var _=r.call(h.floats,o);return _==-1&&(h.floats.push(o),_=h.floats.length-1),{type:"floats",index:_}}if(b==="boolean")return{type:"boolean",index:o?n:a};throw new Error("Unexpected argument of type "+typeof o)}(s),g=h.strings.length,A=h.integers.length;h.floats.length,i&&console.log("Parsing the dictionary");var O=h.strings.join("|");return O+="^"+h.integers.join("|"),O+="^"+h.floats.join("|"),i&&console.log("Parsing the structure"),O+="^"+function y(o){if(i&&console.log("Calling a recursiveParser with "+this.JSON.stringify(o)),o instanceof Array){var b=o.shift();for(var N in o)o.hasOwnProperty(N)&&(b+=y(o[N])+"|");return(b[b.length-1]==="|"?b.slice(0,-1):b)+"]"}var T=o.type,M=o.index;if(T==="strings")return $(M);if(T==="integers")return $(g+M);if(T==="floats")return $(g+A+M);if(T==="boolean")return o.index;if(T==="null")return c;if(T==="undefined")return d;if(T==="empty")return w;throw new TypeError("The item is alien!")}(u),i&&console.log("Ending parser"),f.debug?{dictionary:h,ast:u,packed:O}:O},V=function(s,f){f=f||{};var i=s.split("^");f.verbose&&console.log("Building dictionary");var h=[],u=i[0];if(u!==""){u=u.split("|"),f.verbose&&console.log("Parse the strings dictionary");for(var g=0,A=u.length;gl(this,Q).call(this,n),ownKeys:()=>Object.keys(l(this,D).getPrototypeOf()||{}),getPrototypeOf:()=>l(this,B)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:l(this,D).getPrototypeOf()})});C(this,Q,e=>e==="$toast"?l(this,L):e==="msg"?l(this,W):e==="then"||e==="resp"?(I(this,q,!0),I(this,B,e==="resp"),l(this,X)):e==="catch"?l(this,Z):e==="IS_ECHO_MSG"?l(this,q):Reflect.get(this,e));C(this,W,(e=a=>a,n=!1)=>(l(this,L).call(this),I(this,B,n),Promise.resolve(e==null?void 0:e(l(this,D).getPrototypeOf()))));C(this,L,()=>{l(this,q)&&(I(this,q,!1),le.onToast(this.code,this.message))});C(this,X,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(l(this,D).getPrototypeOf())):Promise.reject(l(this,G)));C(this,Z,e=>Promise.resolve(e(l(this,G))));return this.code=e,this.message=n,this.data=a,this.url=c,this.res=w,I(this,G,new Proxy(this,l(this,D)))}}G=new WeakMap,B=new WeakMap,q=new WeakMap,D=new WeakMap,Q=new WeakMap,W=new WeakMap,L=new WeakMap,X=new WeakMap,Z=new WeakMap;const te=(t,e,n,a="/",c="")=>new ee(t,e,n,a,c);var ie=["utf8","utf-8","unicode-1-1-utf-8"];function de(t){if(ie.indexOf(t)<0&&typeof t<"u"&&t!=null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if(typeof e!="string")throw new TypeError("passed argument must be of tye string");var n=unescape(encodeURIComponent(e)),a=new Uint8Array(n.length);const c=n.split("");for(let w=0;w"u")return"";var a=typeof n<"u"&&a in n?n.stream:!1;if(typeof a!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var c=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),w=new Array(c.length);for(let d=0;d{let e=5381;for(let n=0;n>>0).toString(16)},we=(t,e)=>t.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),fe=t=>pe.encode(t||""),he=t=>ve.decode(new DataView(t),{});class re{constructor(e,n,a=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){C(this,H,void 0);C(this,K,void 0);C(this,k,void 0);C(this,j,{"#":new Map,$:new Map});C(this,R,new Map);P(this,"request",({url:e="/",method:n="GET",...a},c=!1)=>{var $,z;const w=n.toUpperCase(),d=ae(JSON.stringify([e,w,a])),m=($=e==null?void 0:e.includes)!=null&&$.call(e,"/_/")?"#":"$",{promise:V,resolve:J,reject:F}=Promise.withResolvers();return l(this,j)[m].has(d)?(console.log("缓存命中",e),J(l(this,j)[m].get(d))):(l(this,R).has(d)?l(this,R).get(d).push([J,F]):l(this,R).set(d,[[J,F]]),(z=l(this,R).get(d))!=null&&z.some(r=>r)&&l(this,H).call(this,{url:e,method:w,...a}).then(r=>{if(![0,1].includes(r.code))throw te(r.code,r.msg,r.data,e,r==null?void 0:r.res);return[r.code,r.msg,r.data,e,r==null?void 0:r.res]}).then(r=>((m=="#"||c&&w==="GET")&&l(this,j)[m].set(d,r),r)).then(r=>l(this,R).get(d).forEach((s,f,i)=>{s&&s[0](r),delete i[f]})).catch(r=>{l(this,j)[m].delete(d),l(this,R).get(d).forEach((s,f,i)=>{s&&s[1](r instanceof ee?r:te(-1,r,null,e)),delete i[f]})}).finally(()=>l(this,R).delete(d))),new Proxy(V,{get:(r,s)=>(...f)=>r.then(i=>te(...i)[s](...f)).catch(i=>{if(!i instanceof ee)throw i;return typeof i[s]=="function"?i[s](...f):i[s]})})});P(this,"get",(e,n={})=>this.request({url:e,method:"GET",params:n}));P(this,"post",(e,n={},a={})=>this.request({url:e,method:"POST",data:n,params:a}));P(this,"put",(e,n={},a={})=>this.request({url:e,method:"PUT",data:n,params:a}));P(this,"del",(e,n={},a={})=>this.request({url:e,method:"DELETE",data:n,params:a}));P(this,"download",(e,n)=>{});P(this,"cache",(e,n={})=>this.request({url:e,method:"GET",params:n},!0));P(this,"list",(e,n={})=>this.get(`/api/${e}/${this.encode(n)}`));P(this,"getAppInfo",()=>{});P(this,"refreshCache",(e=!1)=>{e&&l(this,j)["#"].clear(),l(this,j).$.clear()});P(this,"decode",(e="",n={})=>{if(e===void 0||e===""||e===null)return n;try{const a=l(this,K).decode(e).buffer;return se.unpack(he(a))}catch{return console.warn("core.decode",e),n}});P(this,"encode",(e={})=>{const n=JSON.stringify(e,(a,c)=>c===void 0?null:c);return l(this,K).encode(fe(se.pack(n)))});I(this,k,e),I(this,H,a),I(this,K,ce(n))}}H=new WeakMap,K=new WeakMap,k=new WeakMap,j=new WeakMap,R=new WeakMap;const le=re;re.onUnhandledRejection=t=>{var e,n,a,c,w,d;t!=null&&t.IS_ECHO_MSG?((e=t==null?void 0:t.$toast)==null||e.call(t),(n=t==null?void 0:t.preventDefault)==null||n.call(t)):(a=t.reason)!=null&&a.IS_ECHO_MSG&&((w=(c=t.reason)==null?void 0:c.$toast)==null||w.call(c),(d=t==null?void 0:t.preventDefault)==null||d.call(t))},re.onToast=(t,e)=>[0,1].includes(t)?console.log(e):console.warn(e),p.default=le,p.signature=ae,p.str2uint8array=fe,p.trim=we,p.uint8array2str=he,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/package.json b/package.json index 2d08b52..a8453ba 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ff-request", "private": true, - "version": "0.9.9", + "version": "0.9.10", "type": "module", "files": [ "dist"