diff --git a/dist/ff-request.js b/dist/ff-request.js index e121cf0..6837401 100644 --- a/dist/ff-request.js +++ b/dist/ff-request.js @@ -1,491 +1,492 @@ -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) => { +var ce = Object.defineProperty; +var le = (r, e, t) => e in r ? ce(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; +var v = (r, e, t) => (le(r, typeof e != "symbol" ? e + "" : e, t), t), re = (r, e, t) => { if (!e.has(r)) throw TypeError("Cannot " + t); }; -var u = (r, e, t) => (k(r, e, "read from private field"), t ? t.call(r) : e.get(r)), A = (r, e, t) => { +var o = (r, e, t) => (re(r, e, "read from private field"), t ? t.call(r) : e.get(r)), E = (r, e, t) => { if (e.has(r)) throw TypeError("Cannot add the same private member more than once"); 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) { +}, C = (r, e, t, n) => (re(r, e, "write to private field"), n ? n.call(r, t) : e.set(r, t), t); +function he(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } -function ae(r) { - if (r.length >= 255) - throw new TypeError("Alphabet too long"); - 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 = 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 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, i++; - } - for (var a = c - f; a !== c && d[a] === 0; ) - a++; - for (var w = N.repeat(o); a < c; ++a) - w += r.charAt(d[a]); - return w; - } - function U(n) { - if (typeof n != "string") - throw new TypeError("Expected String"); - if (n.length === 0) - return new Uint8Array(); - 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 < 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"); - i = O, o++; - } - 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 j(n) { - var o = U(n); - if (o) - return o; - throw new Error("Non-base" + g + " character"); - } - return { - encode: q, - decodeUnsafe: U, - decode: j - }; -} -var fe = ae; -const he = /* @__PURE__ */ re(fe); -var te = {}; +var oe = {}; (function(r) { (function(e) { e([], function() { - var t = -1, s = -2, l = -3, v = -4, g = -5, N = function(o, f) { - f = f || {}; - 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 = { + var t = -1, n = -2, s = -3, f = -4, h = -5, $ = function(a, c) { + c = c || {}; + var l = c.verbose || !1; + l && console.log("Normalize the JSON Object"), a = typeof a == "string" ? this.JSON.parse(a) : a, l && console.log("Creating a empty dictionary"); + var d = { strings: [], integers: [], floats: [] }; - 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) + l && console.log("Creating the AST"); + var g = function T(i) { + l && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(i)); + var w = typeof i; + if (i === null) return { type: "null", - index: l + index: s }; - if (typeof a > "u") + if (typeof i > "u") return { type: "undefined", - index: g + index: h }; - if (a instanceof Array) { - var S = ["@"]; - for (var E in a) - a.hasOwnProperty(E) && S.push(p(a[E])); - return S; + if (i instanceof Array) { + var P = ["@"]; + for (var y in i) + i.hasOwnProperty(y) && P.push(T(i[y])); + return P; } if (w === "object") { - var S = ["$"]; - for (var x in a) - a.hasOwnProperty(x) && (S.push(p(x)), S.push(p(a[x]))); - return S; + var P = ["$"]; + for (var M in i) + i.hasOwnProperty(M) && (P.push(T(M)), P.push(T(i[M]))); + return P; } - if (a === "") + if (i === "") return { type: "empty", - index: v + index: f }; if (w === "string") { - var T = n.call(h.strings, a); - return T == -1 && (h.strings.push(I(a)), T = h.strings.length - 1), { + var O = u.call(d.strings, i); + return O == -1 && (d.strings.push(q(i)), O = d.strings.length - 1), { type: "strings", - index: T + index: O }; } - if (w === "number" && a % 1 === 0) { - var T = n.call(h.integers, a); - return T == -1 && (h.integers.push(U(a)), T = h.integers.length - 1), { + if (w === "number" && i % 1 === 0) { + var O = u.call(d.integers, i); + return O == -1 && (d.integers.push(U(i)), O = d.integers.length - 1), { type: "integers", - index: T + index: O }; } if (w === "number") { - var T = n.call(h.floats, a); - return T == -1 && (h.floats.push(a), T = h.floats.length - 1), { + var O = u.call(d.floats, i); + return O == -1 && (d.floats.push(i), O = d.floats.length - 1), { type: "floats", - index: T + index: O }; } if (w === "boolean") return { type: "boolean", - index: a ? t : s + index: i ? t : n }; - throw new Error("Unexpected argument of type " + typeof a); - }(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("|"), 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 += p(a[S]) + "|"); + throw new Error("Unexpected argument of type " + typeof i); + }(a), b = d.strings.length, F = d.integers.length; + d.floats.length, l && console.log("Parsing the dictionary"); + var A = d.strings.join("|"); + return A += "^" + d.integers.join("|"), A += "^" + d.floats.join("|"), l && console.log("Parsing the structure"), A += "^" + function T(i) { + if (l && console.log("Calling a recursiveParser with " + this.JSON.stringify(i)), i instanceof Array) { + var w = i.shift(); + for (var P in i) + i.hasOwnProperty(P) && (w += T(i[P]) + "|"); return (w[w.length - 1] === "|" ? w.slice(0, -1) : w) + "]"; } - var E = a.type, x = a.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 a.index; - if (E === "null") - return l; - if (E === "undefined") - return g; - if (E === "empty") - return v; + var y = i.type, M = i.index; + if (y === "strings") + return U(M); + if (y === "integers") + return U(b + M); + if (y === "floats") + return U(b + F + M); + if (y === "boolean") + return i.index; + if (y === "null") + return s; + if (y === "undefined") + return h; + if (y === "empty") + return f; throw new TypeError("The item is alien!"); - }(c), i && console.log("Ending parser"), f.debug ? { - dictionary: h, - ast: c, - packed: b - } : b; - }, B = function(o, f) { - f = f || {}; - var i = o.split("^"); - f.verbose && console.log("Building dictionary"); - 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])); + }(g), l && console.log("Ending parser"), c.debug ? { + dictionary: d, + ast: g, + packed: A + } : A; + }, _ = function(a, c) { + c = c || {}; + var l = a.split("^"); + c.verbose && console.log("Building dictionary"); + var d = [], g = l[0]; + if (g !== "") { + g = g.split("|"), c.verbose && console.log("Parse the strings dictionary"); + for (var b = 0, F = g.length; b < F; b++) + d.push(z(g[b])); } - 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 (g = l[1], g !== "") { + g = g.split("|"), c.verbose && console.log("Parse the integers dictionary"); + for (var b = 0, F = g.length; b < F; b++) + d.push(J(g[b])); } - 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])); + if (g = l[2], g !== "") { + g = g.split("|"), c.verbose && console.log("Parse the floats dictionary"); + for (var b = 0, F = g.length; b < F; b++) + d.push(parseFloat(g[b])); } - 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; + g = null, c.verbose && console.log("Tokenizing the structure"); + for (var A = "", T = [], i = l[3].length, b = 0; b < i; b++) { + var w = l[3].charAt(b); + w === "|" || w === "$" || w === "@" || w === "]" ? (A && (T.push(J(A)), A = ""), w !== "|" && T.push(w)) : A += w; } - var S = p.length, E = 0; - return f.verbose && console.log("Starting recursive parser"), function x() { - var T = p[E++]; - if (f.verbose && console.log("Reading collection type " + (T === "$" ? "object" : "Array")), T === "@") { - for (var y = []; E < S; E++) { - var C = p[E]; - if (f.verbose && console.log("Read " + C + " symbol"), C === "]") - return y; - if (C === "@" || C === "$") - y.push(x()); + var P = T.length, y = 0; + return c.verbose && console.log("Starting recursive parser"), function M() { + var O = T[y++]; + if (c.verbose && console.log("Reading collection type " + (O === "$" ? "object" : "Array")), O === "@") { + for (var p = []; y < P; y++) { + var S = T[y]; + if (c.verbose && console.log("Read " + S + " symbol"), S === "]") + return p; + if (S === "@" || S === "$") + p.push(M()); else - switch (C) { + switch (S) { case t: - y.push(!0); + p.push(!0); + break; + case n: + p.push(!1); break; case s: - y.push(!1); + p.push(null); break; - case l: - y.push(null); + case h: + p.push(void 0); break; - case g: - y.push(void 0); - break; - case v: - y.push(""); + case f: + p.push(""); break; default: - y.push(h[C]); + p.push(d[S]); } } - return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y; + return c.verbose && console.log("Parsed " + this.JSON.stringify(p)), p; } - if (T === "$") { - for (var y = {}; E < S; E++) { - var _ = p[E]; - if (_ === "]") - return y; - _ === v ? _ = "" : _ = h[_]; - var C = p[++E]; - if (C === "@" || C === "$") - y[_] = x(); + if (O === "$") { + for (var p = {}; y < P; y++) { + var x = T[y]; + if (x === "]") + return p; + x === f ? x = "" : x = d[x]; + var S = T[++y]; + if (S === "@" || S === "$") + p[x] = M(); else - switch (C) { + switch (S) { case t: - y[_] = !0; + p[x] = !0; + break; + case n: + p[x] = !1; break; case s: - y[_] = !1; + p[x] = null; break; - case l: - y[_] = null; + case h: + p[x] = void 0; break; - case g: - y[_] = void 0; - break; - case v: - y[_] = ""; + case f: + p[x] = ""; break; default: - y[_] = h[C]; + p[x] = d[S]; } } - return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y; + return c.verbose && console.log("Parsed " + this.JSON.stringify(p)), p; } - throw new TypeError("Bad token " + T + " isn't a type"); + throw new TypeError("Bad token " + O + " isn't a type"); }(); - }, I = function(o) { - return typeof o != "string" ? o : o.replace(/[\+ \|\^\%]/g, function(f) { + }, q = function(a) { + return typeof a != "string" ? a : a.replace(/[\+ \|\^\%]/g, function(c) { return { " ": "+", "+": "%2B", "|": "%7C", "^": "%5E", "%": "%25" - }[f]; + }[c]; }); - }, q = function(o) { - return typeof o != "string" ? o : o.replace(/\+|%2B|%7C|%5E|%25/g, function(f) { + }, z = function(a) { + return typeof a != "string" ? a : a.replace(/\+|%2B|%7C|%5E|%25/g, function(c) { return { "+": " ", "%2B": "+", "%7C": "|", "%5E": "^", "%25": "%" - }[f]; + }[c]; }); - }, 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; + }, U = function(a) { + return Number.prototype.toString.call(a, 36).toUpperCase(); + }, J = function(a) { + return parseInt(a, 36); + }, u = Array.prototype.indexOf || function(a, c) { + for (var l = c || 0, d = this.length; l < d; l++) + if (this[l] === a) + return l; return -1; }; return { JSON, - pack: N, - unpack: B + pack: $, + unpack: _ }; }); })(function(e, t) { - var s = t(); - for (var l in s) - r[l] = s[l]; + var n = t(); + for (var s in n) + r[s] = n[s]; }); -})(te); -const ee = /* @__PURE__ */ re(te); -var J, z, D, $, L, H, K, V, Y; -class X { - constructor(e, t, s, l, v) { - P(this, "code", 0); - P(this, "message", "操作成功"); - P(this, "data", null); - P(this, "url", ""); - P(this, "res", ""); +})(oe); +const ne = /* @__PURE__ */ he(oe); +var D, j, I, R, Y, Q, K, W, X; +class ee { + constructor(e, t, n, s, f) { + v(this, "code", 0); + v(this, "message", "操作成功"); + v(this, "data", null); + v(this, "url", ""); + v(this, "res", ""); // static [Symbol.hasInstance](self) { return self?.IS_ECHO_MSG !== undefined } - A(this, J, null); + E(this, D, null); // 判断返回 Response 对象, 还是 Response 中的 data - A(this, z, !0); + E(this, j, !0); // 判罚是否已经给出错误提示 - 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, + E(this, I, !0); + E(this, R, { + get: (e, t) => o(this, Y).call(this, t), + ownKeys: () => Object.keys(o(this, R).getPrototypeOf() || {}), + getPrototypeOf: () => o(this, j) ? this : this.data, getOwnPropertyDescriptor: () => ({ configurable: !0, enumerable: !0, writable: !0, - value: u(this, $).getPrototypeOf() + value: o(this, R).getPrototypeOf() }) }); - 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)); + E(this, Y, (e) => e === "$echoMsg" ? o(this, K) : e === "msg" ? o(this, Q) : e === "then" || e === "resp" ? (C(this, I, !0), C(this, j, e === "resp"), o(this, W)) : e === "catch" ? o(this, X) : e === "IS_ECHO_MSG" ? o(this, I) : Reflect.get(this, e)); + E(this, Q, (e = (n) => n, t = !1) => (o(this, K).call(this), C(this, j, t), Promise.resolve(e == null ? void 0 : e(o(this, R).getPrototypeOf())))); + E(this, K, () => { + o(this, I) && (C(this, I, !1), Te.onMsg(this.code, this.message)); }); - 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, $))); + E(this, W, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(o(this, R).getPrototypeOf())) : Promise.reject(o(this, D))); + E(this, X, (e) => Promise.resolve(e(o(this, D)))); + return this.code = e, this.message = t, this.data = n, this.url = s, this.res = f, C(this, D, new Proxy(this, o(this, R))); } } -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 = [ +D = new WeakMap(), j = new WeakMap(), I = new WeakMap(), R = new WeakMap(), Y = new WeakMap(), Q = new WeakMap(), K = new WeakMap(), W = new WeakMap(), X = new WeakMap(); +const k = (r, e, t, n = "/", s = "") => new ee(r, e, t, n, s); +var ie = [ "utf8", "utf-8", "unicode-1-1-utf-8" ]; -function le(r) { - if (ne.indexOf(r) < 0 && typeof r < "u" && r != null) +function ue(r) { + if (ie.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 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; + var t = unescape(encodeURIComponent(e)), n = new Uint8Array(t.length); + const s = t.split(""); + for (let f = 0; f < s.length; f++) + n[f] = s[f].charCodeAt(0); + return n; }; } -function ue(r) { - if (ne.indexOf(r) < 0 && typeof r < "u" && r != null) +function fe(r) { + if (ie.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, t) { if (typeof e > "u") return ""; - var s = typeof t < "u" && s in t ? t.stream : !1; - if (typeof s != "boolean") + var n = typeof t < "u" && n in t ? t.stream : !1; + if (typeof n != "boolean") throw new TypeError("stream option must be boolean"); if (ArrayBuffer.isView(e)) { - 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(""))); + var s = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), f = new Array(s.length); + for (let h = 0; h < s.length; h++) + f[h] = String.fromCharCode(s[h]); + return decodeURIComponent(escape(f.join(""))); } else throw new TypeError("passed argument must be an array buffer view"); }; } -var se = { - TextEncoder: le, - TextDecoder: ue +var ae = { + TextEncoder: ue, + TextDecoder: fe }; -const ce = new se.TextEncoder("utf8"), ge = new se.TextDecoder("utf8"), de = (r) => { +const de = new ae.TextEncoder("utf8"), ge = new ae.TextDecoder("utf8"), pe = (r) => { let e = 5381; for (let t = 0; t < r.length; t++) e = e * 33 ^ r.charCodeAt(t); return (e >>> 0).toString(16); -}, be = (r, e) => r.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), ve = (r) => ce.encode(r || ""), pe = (r) => ge.decode(new DataView(r), {}); +}, xe = (r, e) => r.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), ve = (r) => de.encode(r || ""), Se = (r) => ge.decode(new DataView(r), {}), we = 62, V = 30, se = 31, ye = 63; +class be { + constructor(e) { + v(this, "encodeTable", []); + v(this, "decodeMap", new Uint8Array(256).fill(255)); + if (e.length !== we) + throw new Error("Encoding alphabet must be 62 characters long"); + if (e.includes(` +`) || e.includes("\r")) + throw new Error("Encoding alphabet contains newline character"); + this.encodeTable = e.split(""), this.decodeMap = new Uint8Array(256).fill(255); + for (let t = 0; t < e.length; t++) + this.decodeMap[e.charCodeAt(t)] = t; + } + // 编码方法 + encode(e) { + if (!e || e.length === 0) + return []; + const t = new Ee(this).encodeV2(e); + return String.fromCharCode(...t); + } + // 解码方法 + decode(e) { + if (!e || e.length === 0) + return new Uint8Array(); + const t = new Oe(this).decode(e); + return new TextDecoder().decode(t); + } +} +var G; +class Ee { + constructor(e) { + E(this, G, null); + C(this, G, e); + } + get6bits() { + let e = this.pos & 7, t = this.pos >> 3; + e === 0 && (t -= 1, e = 8); + let n = this.src[t] >> 8 - e; + return e < 6 && t > 0 && (n |= this.src[t - 1] << e), n & ye; + } + encodeV2(e) { + this.src = ve(e), this.pos = this.src.length * 8; + const t = []; + for (; this.pos > 0; ) { + let n = 6, s = this.get6bits(); + (s & V) === V && ((this.pos > 6 || s > se) && (n = 5), s &= se), t.push(o(this, G).encodeTable[s].charCodeAt(0)), this.pos -= n; + } + return t; + } +} +G = new WeakMap(); +var H; +class Oe { + constructor(e) { + E(this, H, null); + C(this, H, e); + } + decode(e) { + const t = new Uint8Array(Math.ceil(e.length * 6 / 8) + 1); + let n = t.length, s = 0, f = 0; + for (let h = 0; h < e.length; h++) { + const $ = e[h].charCodeAt(0), _ = o(this, H).decodeMap[$]; + if (_ === 255) + throw new Error(`CorruptInputError at index ${h}`); + h === e.length - 1 ? (f |= _ << s, s += Math.ceil(Math.log2(_ + 1))) : (_ & V) === V ? (f |= _ << s, s += 5) : (f |= _ << s, s += 6), s >= 8 && (n--, t[n] = f & 255, s %= 8, f >>= 8); + } + return s > 0 && (n--, t[n] = f & 255), t.slice(n); + } +} +H = new WeakMap(); Promise.withResolvers || (Promise.withResolvers = function() { let r, e; - return { promise: new Promise((s, l) => { - r = s, e = l; + return { promise: new Promise((n, s) => { + r = n, e = s; }), resolve: r, reject: e }; }); -var F, G, Q, m, R; -class Z { - 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, { +var L, B, Z, m, N; +class te { + constructor(e, t, n = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { + E(this, L, void 0); + E(this, B, void 0); + E(this, Z, void 0); + E(this, m, { "#": /* @__PURE__ */ new Map(), // 系统缓存 $: /* @__PURE__ */ new Map() // 普通缓存 }); - 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 == "#" || 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]; + E(this, N, /* @__PURE__ */ new Map()); + v(this, "request", ({ url: e = "/", method: t = "GET", ...n }, s = !1) => { + var U, J; + const f = t.toUpperCase(), h = pe(JSON.stringify([e, f, n])), $ = (U = e == null ? void 0 : e.includes) != null && U.call(e, "/_/") ? "#" : "$", { promise: _, resolve: q, reject: z } = Promise.withResolvers(); + return o(this, m)[$].has(h) ? (console.log("缓存命中", e), q(o(this, m)[$].get(h))) : (o(this, N).has(h) ? o(this, N).get(h).push([q, z]) : o(this, N).set(h, [[q, z]]), (J = o(this, N).get(h)) != null && J.some((u) => u) && o(this, L).call(this, { url: e, method: f, ...n }).then((u) => { + if (![0, 1].includes(u.code)) + throw k(u.code, u.msg, u.data, e, u == null ? void 0 : u.res); + return [u.code, u.msg, u.data, e, u == null ? void 0 : u.res]; + }).then((u) => (($ == "#" || s && f === "GET") && o(this, m)[$].set(h, u), u)).then((u) => { + var a; + return (a = o(this, N).get(h)) == null ? void 0 : a.forEach((c, l, d) => { + c && c[0](u), delete d[l]; }); - }).catch((n) => { - 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]; + }).catch((u) => { + var a; + o(this, m)[$].delete(h), (a = o(this, N).get(h)) == null || a.forEach((c, l, d) => { + c && c[1](u instanceof ee ? u : k(-1, u, null, e)), delete d[l]; }); - }).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]; + }).finally(() => o(this, N).delete(h))), new Proxy(_, { + get: (u, a) => (...c) => u.then((l) => k(...l)[a](...c)).catch((l) => { + if (!l instanceof ee) + throw l; + return typeof l[a] == "function" ? l[a](...c) : l[a]; }) }); }); - 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) => { + v(this, "get", (e, t = {}) => this.request({ url: e, method: "GET", params: t })); + v(this, "post", (e, t = {}, n = {}) => this.request({ url: e, method: "POST", data: t, params: n })); + v(this, "put", (e, t = {}, n = {}) => this.request({ url: e, method: "PUT", data: t, params: n })); + v(this, "del", (e, t = {}, n = {}) => this.request({ url: e, method: "DELETE", data: t, params: n })); + v(this, "download", (e, t) => { }); - 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", () => { + v(this, "cache", (e, t = {}) => this.request({ url: e, method: "GET", params: t }, !0)); + v(this, "list", (e, t = {}) => this.get(`/api/${e}/${this.encode(t)}`)); + v(this, "getAppInfo", () => { }); - P(this, "refreshCache", (e = !1) => { - e && u(this, m)["#"].clear(), u(this, m).$.clear(); + v(this, "refreshCache", (e = !1) => { + e && o(this, m)["#"].clear(), o(this, m).$.clear(); }); - P(this, "decode", (e = "", t = {}) => { + v(this, "decode", (e = "", t = {}) => { if (e === void 0 || e === "" || e === null) return t; try { - const s = u(this, G).decode(e).buffer; - return ee.unpack(pe(s)); + const n = o(this, B).decode(e); + return ne.unpack(n); } catch { return console.warn("core.decode", e), t; } }); - 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))); + v(this, "encode", (e = {}) => { + const t = JSON.stringify(e, (n, s) => s === void 0 ? null : s); + return o(this, B).encode(ne.pack(t)); }); - M(this, Q, e), M(this, F, s), M(this, G, he(t)); + C(this, Z, e), C(this, L, n), C(this, B, new be(t)); } } -F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), R = new WeakMap(); -const we = Z; -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)); +L = new WeakMap(), B = new WeakMap(), Z = new WeakMap(), m = new WeakMap(), N = new WeakMap(); +const Te = te; +te.onUnhandledRejection = (r) => { + var e, t, n, s, f, h; + 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)) : (n = r.reason) != null && n.IS_ECHO_MSG && ((f = (s = r.reason) == null ? void 0 : s.$echoMsg) == null || f.call(s), (h = r == null ? void 0 : r.preventDefault) == null || h.call(r)); }; -Z.onMsg = (r, e) => [0, 1].includes(r) ? console.log(e) : console.warn(e); +te.onMsg = (r, e) => [0, 1].includes(r) ? console.log(e) : console.warn(e); export { - we as default, - de as signature, + Te as default, + pe as signature, ve as str2uint8array, - be as trim, - pe as uint8array2str + xe as trim, + Se as uint8array2str }; diff --git a/dist/ff-request.umd.cjs b/dist/ff-request.umd.cjs index d57633b..e4cc74f 100644 --- a/dist/ff-request.umd.cjs +++ b/dist/ff-request.umd.cjs @@ -1 +1,2 @@ -(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"}})}); +(function(u,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(u=typeof globalThis<"u"?globalThis:u||self,p(u["ff-request"]={}))})(this,function(u){"use strict";var Se=Object.defineProperty;var xe=(u,p,b)=>p in u?Se(u,p,{enumerable:!0,configurable:!0,writable:!0,value:b}):u[p]=b;var w=(u,p,b)=>(xe(u,typeof p!="symbol"?p+"":p,b),b),he=(u,p,b)=>{if(!p.has(u))throw TypeError("Cannot "+b)};var i=(u,p,b)=>(he(u,p,"read from private field"),b?b.call(u):p.get(u)),P=(u,p,b)=>{if(p.has(u))throw TypeError("Cannot add the same private member more than once");p instanceof WeakSet?p.add(u):p.set(u,b)},M=(u,p,b,G)=>(he(u,p,"write to private field"),G?G.call(u,b):p.set(u,b),b);var q,J,j,I,X,Z,H,k,ee,L,z,V,K,te,U,m;function p(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var b={};(function(r){(function(e){e([],function(){var t=-1,n=-2,s=-3,d=-4,f=-5,F=function(a,c){c=c||{};var l=c.verbose||!1;l&&console.log("Normalize the JSON Object"),a=typeof a=="string"?this.JSON.parse(a):a,l&&console.log("Creating a empty dictionary");var g={strings:[],integers:[],floats:[]};l&&console.log("Creating the AST");var v=function x(o){l&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(o));var E=typeof o;if(o===null)return{type:"null",index:s};if(typeof o>"u")return{type:"undefined",index:f};if(o instanceof Array){var _=["@"];for(var O in o)o.hasOwnProperty(O)&&_.push(x(o[O]));return _}if(E==="object"){var _=["$"];for(var R in o)o.hasOwnProperty(R)&&(_.push(x(R)),_.push(x(o[R])));return _}if(o==="")return{type:"empty",index:d};if(E==="string"){var S=h.call(g.strings,o);return S==-1&&(g.strings.push(Y(o)),S=g.strings.length-1),{type:"strings",index:S}}if(E==="number"&&o%1===0){var S=h.call(g.integers,o);return S==-1&&(g.integers.push(D(o)),S=g.integers.length-1),{type:"integers",index:S}}if(E==="number"){var S=h.call(g.floats,o);return S==-1&&(g.floats.push(o),S=g.floats.length-1),{type:"floats",index:S}}if(E==="boolean")return{type:"boolean",index:o?t:n};throw new Error("Unexpected argument of type "+typeof o)}(a),T=g.strings.length,B=g.integers.length;g.floats.length,l&&console.log("Parsing the dictionary");var $=g.strings.join("|");return $+="^"+g.integers.join("|"),$+="^"+g.floats.join("|"),l&&console.log("Parsing the structure"),$+="^"+function x(o){if(l&&console.log("Calling a recursiveParser with "+this.JSON.stringify(o)),o instanceof Array){var E=o.shift();for(var _ in o)o.hasOwnProperty(_)&&(E+=x(o[_])+"|");return(E[E.length-1]==="|"?E.slice(0,-1):E)+"]"}var O=o.type,R=o.index;if(O==="strings")return D(R);if(O==="integers")return D(T+R);if(O==="floats")return D(T+B+R);if(O==="boolean")return o.index;if(O==="null")return s;if(O==="undefined")return f;if(O==="empty")return d;throw new TypeError("The item is alien!")}(v),l&&console.log("Ending parser"),c.debug?{dictionary:g,ast:v,packed:$}:$},N=function(a,c){c=c||{};var l=a.split("^");c.verbose&&console.log("Building dictionary");var g=[],v=l[0];if(v!==""){v=v.split("|"),c.verbose&&console.log("Parse the strings dictionary");for(var T=0,B=v.length;Ti(this,X).call(this,t),ownKeys:()=>Object.keys(i(this,I).getPrototypeOf()||{}),getPrototypeOf:()=>i(this,J)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:i(this,I).getPrototypeOf()})});P(this,X,e=>e==="$echoMsg"?i(this,H):e==="msg"?i(this,Z):e==="then"||e==="resp"?(M(this,j,!0),M(this,J,e==="resp"),i(this,k)):e==="catch"?i(this,ee):e==="IS_ECHO_MSG"?i(this,j):Reflect.get(this,e));P(this,Z,(e=n=>n,t=!1)=>(i(this,H).call(this),M(this,J,t),Promise.resolve(e==null?void 0:e(i(this,I).getPrototypeOf()))));P(this,H,()=>{i(this,j)&&(M(this,j,!1),fe.onMsg(this.code,this.message))});P(this,k,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(i(this,I).getPrototypeOf())):Promise.reject(i(this,q)));P(this,ee,e=>Promise.resolve(e(i(this,q))));return this.code=e,this.message=t,this.data=n,this.url=s,this.res=d,M(this,q,new Proxy(this,i(this,I)))}}q=new WeakMap,J=new WeakMap,j=new WeakMap,I=new WeakMap,X=new WeakMap,Z=new WeakMap,H=new WeakMap,k=new WeakMap,ee=new WeakMap;const se=(r,e,t,n="/",s="")=>new ne(r,e,t,n,s);var oe=["utf8","utf-8","unicode-1-1-utf-8"];function de(r){if(oe.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 t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);const s=t.split("");for(let d=0;d"u")return"";var n=typeof t<"u"&&n in t?t.stream:!1;if(typeof n!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var s=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),d=new Array(s.length);for(let f=0;f{let e=5381;for(let t=0;t>>0).toString(16)},ye=(r,e)=>r.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),le=r=>pe.encode(r||""),we=r=>ve.decode(new DataView(r),{}),be=62,W=30,ue=31,Ee=63;class Oe{constructor(e){w(this,"encodeTable",[]);w(this,"decodeMap",new Uint8Array(256).fill(255));if(e.length!==be)throw new Error("Encoding alphabet must be 62 characters long");if(e.includes(` +`)||e.includes("\r"))throw new Error("Encoding alphabet contains newline character");this.encodeTable=e.split(""),this.decodeMap=new Uint8Array(256).fill(255);for(let t=0;t>3;e===0&&(t-=1,e=8);let n=this.src[t]>>8-e;return e<6&&t>0&&(n|=this.src[t-1]<0;){let n=6,s=this.get6bits();(s&W)===W&&((this.pos>6||s>ue)&&(n=5),s&=ue),t.push(i(this,L).encodeTable[s].charCodeAt(0)),this.pos-=n}return t}}L=new WeakMap;class Pe{constructor(e){P(this,z,null);M(this,z,e)}decode(e){const t=new Uint8Array(Math.ceil(e.length*6/8)+1);let n=t.length,s=0,d=0;for(let f=0;f=8&&(n--,t[n]=d&255,s%=8,d>>=8)}return s>0&&(n--,t[n]=d&255),t.slice(n)}}z=new WeakMap,Promise.withResolvers||(Promise.withResolvers=function(){let r,e;return{promise:new Promise((n,s)=>{r=n,e=s}),resolve:r,reject:e}});class ie{constructor(e,t,n=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){P(this,V,void 0);P(this,K,void 0);P(this,te,void 0);P(this,U,{"#":new Map,$:new Map});P(this,m,new Map);w(this,"request",({url:e="/",method:t="GET",...n},s=!1)=>{var D,Q;const d=t.toUpperCase(),f=ce(JSON.stringify([e,d,n])),F=(D=e==null?void 0:e.includes)!=null&&D.call(e,"/_/")?"#":"$",{promise:N,resolve:Y,reject:re}=Promise.withResolvers();return i(this,U)[F].has(f)?(console.log("缓存命中",e),Y(i(this,U)[F].get(f))):(i(this,m).has(f)?i(this,m).get(f).push([Y,re]):i(this,m).set(f,[[Y,re]]),(Q=i(this,m).get(f))!=null&&Q.some(h=>h)&&i(this,V).call(this,{url:e,method:d,...n}).then(h=>{if(![0,1].includes(h.code))throw se(h.code,h.msg,h.data,e,h==null?void 0:h.res);return[h.code,h.msg,h.data,e,h==null?void 0:h.res]}).then(h=>((F=="#"||s&&d==="GET")&&i(this,U)[F].set(f,h),h)).then(h=>{var a;return(a=i(this,m).get(f))==null?void 0:a.forEach((c,l,g)=>{c&&c[0](h),delete g[l]})}).catch(h=>{var a;i(this,U)[F].delete(f),(a=i(this,m).get(f))==null||a.forEach((c,l,g)=>{c&&c[1](h instanceof ne?h:se(-1,h,null,e)),delete g[l]})}).finally(()=>i(this,m).delete(f))),new Proxy(N,{get:(h,a)=>(...c)=>h.then(l=>se(...l)[a](...c)).catch(l=>{if(!l instanceof ne)throw l;return typeof l[a]=="function"?l[a](...c):l[a]})})});w(this,"get",(e,t={})=>this.request({url:e,method:"GET",params:t}));w(this,"post",(e,t={},n={})=>this.request({url:e,method:"POST",data:t,params:n}));w(this,"put",(e,t={},n={})=>this.request({url:e,method:"PUT",data:t,params:n}));w(this,"del",(e,t={},n={})=>this.request({url:e,method:"DELETE",data:t,params:n}));w(this,"download",(e,t)=>{});w(this,"cache",(e,t={})=>this.request({url:e,method:"GET",params:t},!0));w(this,"list",(e,t={})=>this.get(`/api/${e}/${this.encode(t)}`));w(this,"getAppInfo",()=>{});w(this,"refreshCache",(e=!1)=>{e&&i(this,U)["#"].clear(),i(this,U).$.clear()});w(this,"decode",(e="",t={})=>{if(e===void 0||e===""||e===null)return t;try{const n=i(this,K).decode(e);return G.unpack(n)}catch{return console.warn("core.decode",e),t}});w(this,"encode",(e={})=>{const t=JSON.stringify(e,(n,s)=>s===void 0?null:s);return i(this,K).encode(G.pack(t))});M(this,te,e),M(this,V,n),M(this,K,new Oe(t))}}V=new WeakMap,K=new WeakMap,te=new WeakMap,U=new WeakMap,m=new WeakMap;const fe=ie;ie.onUnhandledRejection=r=>{var e,t,n,s,d,f;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)):(n=r.reason)!=null&&n.IS_ECHO_MSG&&((d=(s=r.reason)==null?void 0:s.$echoMsg)==null||d.call(s),(f=r==null?void 0:r.preventDefault)==null||f.call(r))},ie.onMsg=(r,e)=>[0,1].includes(r)?console.log(e):console.warn(e),u.default=fe,u.signature=ce,u.str2uint8array=le,u.trim=ye,u.uint8array2str=we,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/package.json b/package.json index 5735abb..8ae580a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ff-request", "private": true, - "version": "0.9.13", + "version": "0.9.14", "type": "module", "files": [ "dist" @@ -17,7 +17,6 @@ "build": "vite build" }, "dependencies": { - "base-x": "^4.0.0", "jsonpack": "^1.1.5", "text-encoder": "^0.0.4" },