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