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