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