diff --git a/dist/ff-request.js b/dist/ff-request.js index a3c1957..982cf63 100644 --- a/dist/ff-request.js +++ b/dist/ff-request.js @@ -1,6 +1,6 @@ -var oe = Object.defineProperty; -var ae = (t, e, r) => e in t ? oe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; -var T = (t, e, r) => (ae(t, typeof e != "symbol" ? e + "" : e, r), r), k = (t, e, r) => { +var ie = Object.defineProperty; +var oe = (t, e, r) => e in t ? ie(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; +var T = (t, e, r) => (oe(t, typeof e != "symbol" ? e + "" : e, r), r), k = (t, e, r) => { if (!e.has(t)) throw TypeError("Cannot " + r); }; @@ -8,20 +8,20 @@ var l = (t, e, r) => (k(t, e, "read from private field"), r ? r.call(t) : e.get( if (e.has(t)) throw TypeError("Cannot add the same private member more than once"); e instanceof WeakSet ? e.add(t) : e.set(t, r); -}, $ = (t, e, r, o) => (k(t, e, "write to private field"), o ? o.call(t, r) : e.set(t, r), r); +}, R = (t, e, r, i) => (k(t, e, "write to private field"), i ? i.call(t, r) : e.set(t, r), r); function te(t) { return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; } -function ie(t) { +function ae(t) { if (t.length >= 255) throw new TypeError("Alphabet too long"); for (var e = new Uint8Array(256), r = 0; r < e.length; r++) e[r] = 255; - for (var o = 0; o < t.length; o++) { - var c = t.charAt(o), p = c.charCodeAt(0); + for (var i = 0; i < t.length; i++) { + var c = t.charAt(i), p = c.charCodeAt(0); if (e[p] !== 255) throw new TypeError(c + " is ambiguous"); - e[p] = o; + e[p] = i; } var g = t.length, N = t.charAt(0), B = Math.log(g) / Math.log(256), I = Math.log(256) / Math.log(g); function q(n) { @@ -29,19 +29,19 @@ function ie(t) { throw new TypeError("Expected Uint8Array"); if (n.length === 0) return ""; - for (var s = 0, f = 0, a = 0, h = n.length; a !== h && n[a] === 0; ) - a++, s++; - for (var u = (h - a) * I + 1 >>> 0, d = new Uint8Array(u); a !== h; ) { - for (var O = n[a], b = 0, v = u - 1; (O !== 0 || b < f) && v !== -1; v--, b++) + for (var s = 0, f = 0, o = 0, h = n.length; o !== h && n[o] === 0; ) + o++, s++; + for (var u = (h - o) * I + 1 >>> 0, d = new Uint8Array(u); o !== h; ) { + for (var O = n[o], b = 0, v = u - 1; (O !== 0 || b < f) && v !== -1; v--, b++) O += 256 * d[v] >>> 0, d[v] = O % g >>> 0, O = O / g >>> 0; if (O !== 0) throw new Error("Non-zero carry"); - f = b, a++; + f = b, o++; } - for (var i = u - f; i !== u && d[i] === 0; ) - i++; - for (var w = N.repeat(s); i < u; ++i) - w += t.charAt(d[i]); + for (var a = u - f; a !== u && d[a] === 0; ) + a++; + for (var w = N.repeat(s); a < u; ++a) + w += t.charAt(d[a]); return w; } function U(n) { @@ -49,23 +49,23 @@ function ie(t) { throw new TypeError("Expected String"); if (n.length === 0) return new Uint8Array(); - for (var s = 0, f = 0, a = 0; n[s] === N; ) + for (var s = 0, f = 0, o = 0; n[s] === N; ) f++, s++; for (var h = (n.length - s) * B + 1 >>> 0, u = new Uint8Array(h); n[s]; ) { var d = e[n.charCodeAt(s)]; if (d === 255) return; - for (var O = 0, b = h - 1; (d !== 0 || O < a) && b !== -1; b--, O++) + for (var O = 0, b = h - 1; (d !== 0 || O < o) && b !== -1; b--, O++) d += g * u[b] >>> 0, u[b] = d % 256 >>> 0, d = d / 256 >>> 0; if (d !== 0) throw new Error("Non-zero carry"); - a = O, s++; + o = O, s++; } - for (var v = h - a; v !== h && u[v] === 0; ) + for (var v = h - o; v !== h && u[v] === 0; ) v++; - for (var i = new Uint8Array(f + (h - v)), w = f; v !== h; ) - i[w++] = u[v++]; - return i; + for (var a = new Uint8Array(f + (h - v)), w = f; v !== h; ) + a[w++] = u[v++]; + return a; } function D(n) { var s = U(n); @@ -79,69 +79,69 @@ function ie(t) { decode: D }; } -var fe = ie; +var fe = ae; const he = /* @__PURE__ */ te(fe); var re = {}; (function(t) { (function(e) { e([], function() { - var r = -1, o = -2, c = -3, p = -4, g = -5, N = function(s, f) { + var r = -1, i = -2, c = -3, p = -4, g = -5, N = function(s, f) { f = f || {}; - var a = f.verbose || !1; - a && console.log("Normalize the JSON Object"), s = typeof s == "string" ? this.JSON.parse(s) : s, a && console.log("Creating a empty dictionary"); + var o = f.verbose || !1; + o && console.log("Normalize the JSON Object"), s = typeof s == "string" ? this.JSON.parse(s) : s, o && console.log("Creating a empty dictionary"); var h = { strings: [], integers: [], floats: [] }; - a && console.log("Creating the AST"); - var u = function v(i) { - a && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(i)); - var w = typeof i; - if (i === null) + o && console.log("Creating the AST"); + var u = function v(a) { + o && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(a)); + var w = typeof a; + if (a === null) return { type: "null", index: c }; - if (typeof i > "u") + if (typeof a > "u") return { type: "undefined", index: g }; - if (i instanceof Array) { + if (a instanceof Array) { var S = ["@"]; - for (var E in i) - i.hasOwnProperty(E) && S.push(v(i[E])); + for (var E in a) + a.hasOwnProperty(E) && S.push(v(a[E])); return S; } if (w === "object") { var S = ["$"]; - for (var x in i) - i.hasOwnProperty(x) && (S.push(v(x)), S.push(v(i[x]))); + for (var x in a) + a.hasOwnProperty(x) && (S.push(v(x)), S.push(v(a[x]))); return S; } - if (i === "") + if (a === "") return { type: "empty", index: p }; if (w === "string") { - var A = n.call(h.strings, i); - return A == -1 && (h.strings.push(I(i)), A = h.strings.length - 1), { + var A = n.call(h.strings, a); + return A == -1 && (h.strings.push(I(a)), A = h.strings.length - 1), { type: "strings", index: A }; } - if (w === "number" && i % 1 === 0) { - var A = n.call(h.integers, i); - return A == -1 && (h.integers.push(U(i)), A = h.integers.length - 1), { + if (w === "number" && a % 1 === 0) { + var A = n.call(h.integers, a); + return A == -1 && (h.integers.push(U(a)), A = h.integers.length - 1), { type: "integers", index: A }; } if (w === "number") { - var A = n.call(h.floats, i); - return A == -1 && (h.floats.push(i), A = h.floats.length - 1), { + var A = n.call(h.floats, a); + return A == -1 && (h.floats.push(a), A = h.floats.length - 1), { type: "floats", index: A }; @@ -149,20 +149,20 @@ var re = {}; if (w === "boolean") return { type: "boolean", - index: i ? r : o + index: a ? r : i }; - throw new Error("Unexpected argument of type " + typeof i); + throw new Error("Unexpected argument of type " + typeof a); }(s), d = h.strings.length, O = h.integers.length; - h.floats.length, a && console.log("Parsing the dictionary"); + h.floats.length, o && console.log("Parsing the dictionary"); var b = h.strings.join("|"); - return b += "^" + h.integers.join("|"), b += "^" + h.floats.join("|"), a && console.log("Parsing the structure"), b += "^" + function v(i) { - if (a && console.log("Calling a recursiveParser with " + this.JSON.stringify(i)), i instanceof Array) { - var w = i.shift(); - for (var S in i) - i.hasOwnProperty(S) && (w += v(i[S]) + "|"); + return b += "^" + h.integers.join("|"), b += "^" + h.floats.join("|"), o && console.log("Parsing the structure"), b += "^" + function v(a) { + if (o && console.log("Calling a recursiveParser with " + this.JSON.stringify(a)), a instanceof Array) { + var w = a.shift(); + for (var S in a) + a.hasOwnProperty(S) && (w += v(a[S]) + "|"); return (w[w.length - 1] === "|" ? w.slice(0, -1) : w) + "]"; } - var E = i.type, x = i.index; + var E = a.type, x = a.index; if (E === "strings") return U(x); if (E === "integers") @@ -170,7 +170,7 @@ var re = {}; if (E === "floats") return U(d + O + x); if (E === "boolean") - return i.index; + return a.index; if (E === "null") return c; if (E === "undefined") @@ -178,34 +178,34 @@ var re = {}; if (E === "empty") return p; throw new TypeError("The item is alien!"); - }(u), a && console.log("Ending parser"), f.debug ? { + }(u), o && console.log("Ending parser"), f.debug ? { dictionary: h, ast: u, packed: b } : b; }, B = function(s, f) { f = f || {}; - var a = s.split("^"); + var o = s.split("^"); f.verbose && console.log("Building dictionary"); - var h = [], u = a[0]; + var h = [], u = o[0]; if (u !== "") { u = u.split("|"), f.verbose && console.log("Parse the strings dictionary"); for (var d = 0, O = u.length; d < O; d++) h.push(q(u[d])); } - if (u = a[1], u !== "") { + if (u = o[1], u !== "") { u = u.split("|"), f.verbose && console.log("Parse the integers dictionary"); for (var d = 0, O = u.length; d < O; d++) h.push(D(u[d])); } - if (u = a[2], u !== "") { + if (u = o[2], u !== "") { u = u.split("|"), f.verbose && console.log("Parse the floats dictionary"); for (var d = 0, O = u.length; d < O; d++) h.push(parseFloat(u[d])); } u = null, f.verbose && console.log("Tokenizing the structure"); - for (var b = "", v = [], i = a[3].length, d = 0; d < i; d++) { - var w = a[3].charAt(d); + for (var b = "", v = [], a = o[3].length, d = 0; d < a; d++) { + var w = o[3].charAt(d); w === "|" || w === "$" || w === "@" || w === "]" ? (b && (v.push(D(b)), b = ""), w !== "|" && v.push(w)) : b += w; } var S = v.length, E = 0; @@ -223,7 +223,7 @@ var re = {}; case r: y.push(!0); break; - case o: + case i: y.push(!1); break; case c: @@ -255,7 +255,7 @@ var re = {}; case r: y[_] = !0; break; - case o: + case i: y[_] = !1; break; case c: @@ -300,9 +300,9 @@ var re = {}; }, D = function(s) { return parseInt(s, 36); }, n = Array.prototype.indexOf || function(s, f) { - for (var a = f || 0, h = this.length; a < h; a++) - if (this[a] === s) - return a; + for (var o = f || 0, h = this.length; o < h; o++) + if (this[o] === s) + return o; return -1; }; return { @@ -312,15 +312,15 @@ var re = {}; }; }); })(function(e, r) { - var o = r(); - for (var c in o) - t[c] = o[c]; + var i = r(); + for (var c in i) + t[c] = i[c]; }); })(re); const ee = /* @__PURE__ */ te(re); -var J, z, j, M, L, H, K, V, Y; +var J, z, j, m, L, H, K, V, Y; class X { - constructor(e, r, o, c, p) { + constructor(e, r, i, c, p) { T(this, "code", 0); T(this, "message", "操作成功"); T(this, "data", null); @@ -332,29 +332,29 @@ class X { P(this, z, !0); // 判罚是否已经给出错误提示 P(this, j, !0); - P(this, M, { + P(this, m, { get: (e, r) => l(this, L).call(this, r), - ownKeys: () => Object.keys(l(this, M).getPrototypeOf() || {}), + ownKeys: () => Object.keys(l(this, m).getPrototypeOf() || {}), getPrototypeOf: () => l(this, z) ? this : this.data, getOwnPropertyDescriptor: () => ({ configurable: !0, enumerable: !0, writable: !0, - value: l(this, M).getPrototypeOf() + value: l(this, m).getPrototypeOf() }) }); - P(this, L, (e) => e === "$toast" ? l(this, K) : e === "msg" ? l(this, H) : e === "then" || e === "resp" ? ($(this, j, !0), $(this, z, e === "resp"), l(this, V)) : e === "catch" ? l(this, Y) : e === "IS_ECHO_MSG" ? l(this, j) : Reflect.get(this, e)); - P(this, H, (e = (o) => o, r = !1) => (l(this, K).call(this), $(this, z, r), Promise.resolve(e == null ? void 0 : e(l(this, M).getPrototypeOf())))); + P(this, L, (e) => e === "$echoMsg" ? l(this, K) : e === "msg" ? l(this, H) : e === "then" || e === "resp" ? (R(this, j, !0), R(this, z, e === "resp"), l(this, V)) : e === "catch" ? l(this, Y) : e === "IS_ECHO_MSG" ? l(this, j) : Reflect.get(this, e)); + P(this, H, (e = (i) => i, r = !1) => (l(this, K).call(this), R(this, z, r), Promise.resolve(e == null ? void 0 : e(l(this, m).getPrototypeOf())))); P(this, K, () => { - l(this, j) && ($(this, j, !1), we.onToast(this.code, this.message)); + l(this, j) && (R(this, j, !1), we.onMsg(this.code, this.message)); }); - P(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(l(this, M).getPrototypeOf())) : Promise.reject(l(this, J))); + P(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(l(this, m).getPrototypeOf())) : Promise.reject(l(this, J))); P(this, Y, (e) => Promise.resolve(e(l(this, J)))); - return this.code = e, this.message = r, this.data = o, this.url = c, this.res = p, $(this, J, new Proxy(this, l(this, M))); + return this.code = e, this.message = r, this.data = i, this.url = c, this.res = p, R(this, J, new Proxy(this, l(this, m))); } } -J = new WeakMap(), z = new WeakMap(), j = new WeakMap(), M = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap(); -const W = (t, e, r, o = "/", c = "") => new X(t, e, r, o, c); +J = new WeakMap(), z = new WeakMap(), j = new WeakMap(), m = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap(); +const W = (t, e, r, i = "/", c = "") => new X(t, e, r, i, c); var ne = [ "utf8", "utf-8", @@ -366,11 +366,11 @@ function le(t) { this.encoding = "utf-8", this.encode = function(e) { if (typeof e != "string") throw new TypeError("passed argument must be of tye string"); - var r = unescape(encodeURIComponent(e)), o = new Uint8Array(r.length); + var r = unescape(encodeURIComponent(e)), i = new Uint8Array(r.length); const c = r.split(""); for (let p = 0; p < c.length; p++) - o[p] = c[p].charCodeAt(0); - return o; + i[p] = c[p].charCodeAt(0); + return i; }; } function ue(t) { @@ -379,8 +379,8 @@ function ue(t) { this.encoding = "utf-8", this.decode = function(e, r) { if (typeof e > "u") return ""; - var o = typeof r < "u" && o in r ? r.stream : !1; - if (typeof o != "boolean") + var i = typeof r < "u" && i in r ? r.stream : !1; + if (typeof i != "boolean") throw new TypeError("stream option must be boolean"); if (ArrayBuffer.isView(e)) { var c = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), p = new Array(c.length); @@ -401,48 +401,48 @@ const ce = new se.TextEncoder("utf8"), ge = new se.TextDecoder("utf8"), de = (t) e = e * 33 ^ t.charCodeAt(r); return (e >>> 0).toString(16); }, be = (t, e) => t.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), pe = (t) => ce.encode(t || ""), ve = (t) => ge.decode(new DataView(t), {}); -var F, G, Q, m, R; +var F, G, Q, $, M; class Z { - constructor(e, r, o = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { + constructor(e, r, i = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { P(this, F, void 0); P(this, G, void 0); P(this, Q, void 0); - P(this, m, { + P(this, $, { "#": /* @__PURE__ */ new Map(), // 系统缓存 $: /* @__PURE__ */ new Map() // 普通缓存 }); - P(this, R, /* @__PURE__ */ new Map()); - T(this, "request", ({ url: e = "/", method: r = "GET", ...o }, c = !1) => { + P(this, M, /* @__PURE__ */ new Map()); + T(this, "request", ({ url: e = "/", method: r = "GET", ...i }, c = !1) => { var U, D; - const p = r.toUpperCase(), g = de(JSON.stringify([e, p, o])), N = (U = e == null ? void 0 : e.includes) != null && U.call(e, "/_/") ? "#" : "$", { promise: B, resolve: I, reject: q } = Promise.withResolvers(); - return l(this, m)[N].has(g) ? (console.log("缓存命中", e), I(l(this, m)[N].get(g))) : (l(this, R).has(g) ? l(this, R).get(g).push([I, q]) : l(this, R).set(g, [[I, q]]), (D = l(this, R).get(g)) != null && D.some((n) => n) && l(this, F).call(this, { url: e, method: p, ...o }).then((n) => { + const p = r.toUpperCase(), g = de(JSON.stringify([e, p, i])), N = (U = e == null ? void 0 : e.includes) != null && U.call(e, "/_/") ? "#" : "$", { promise: B, resolve: I, reject: q } = Promise.withResolvers(); + return l(this, $)[N].has(g) ? (console.log("缓存命中", e), I(l(this, $)[N].get(g))) : (l(this, M).has(g) ? l(this, M).get(g).push([I, q]) : l(this, M).set(g, [[I, q]]), (D = l(this, M).get(g)) != null && D.some((n) => n) && l(this, F).call(this, { url: e, method: p, ...i }).then((n) => { if (![0, 1].includes(n.code)) throw W(n.code, n.msg, n.data, e, n == null ? void 0 : n.res); return [n.code, n.msg, n.data, e, n == null ? void 0 : n.res]; - }).then((n) => ((N == "#" || c && p === "GET") && l(this, m)[N].set(g, n), n)).then((n) => { + }).then((n) => ((N == "#" || c && p === "GET") && l(this, $)[N].set(g, n), n)).then((n) => { var s; - return (s = l(this, R).get(g)) == null ? void 0 : s.forEach((f, a, h) => { - f && f[0](n), delete h[a]; + return (s = l(this, M).get(g)) == null ? void 0 : s.forEach((f, o, h) => { + f && f[0](n), delete h[o]; }); }).catch((n) => { var s; - l(this, m)[N].delete(g), (s = l(this, R).get(g)) == null || s.forEach((f, a, h) => { - f && f[1](n instanceof X ? n : W(-1, n, null, e)), delete h[a]; + l(this, $)[N].delete(g), (s = l(this, M).get(g)) == null || s.forEach((f, o, h) => { + f && f[1](n instanceof X ? n : W(-1, n, null, e)), delete h[o]; }); - }).finally(() => l(this, R).delete(g))), new Proxy(B, { - get: (n, s) => (...f) => n.then((a) => W(...a)[s](...f)).catch((a) => { - if (!a instanceof X) - throw a; - return typeof a[s] == "function" ? a[s](...f) : a[s]; + }).finally(() => l(this, M).delete(g))), new Proxy(B, { + get: (n, s) => (...f) => n.then((o) => W(...o)[s](...f)).catch((o) => { + if (!o instanceof X) + throw o; + return typeof o[s] == "function" ? o[s](...f) : o[s]; }) }); }); T(this, "get", (e, r = {}) => this.request({ url: e, method: "GET", params: r })); - T(this, "post", (e, r = {}, o = {}) => this.request({ url: e, method: "POST", data: r, params: o })); - T(this, "put", (e, r = {}, o = {}) => this.request({ url: e, method: "PUT", data: r, params: o })); - T(this, "del", (e, r = {}, o = {}) => this.request({ url: e, method: "DELETE", data: r, params: o })); + T(this, "post", (e, r = {}, i = {}) => this.request({ url: e, method: "POST", data: r, params: i })); + T(this, "put", (e, r = {}, i = {}) => this.request({ url: e, method: "PUT", data: r, params: i })); + T(this, "del", (e, r = {}, i = {}) => this.request({ url: e, method: "DELETE", data: r, params: i })); T(this, "download", (e, r) => { }); T(this, "cache", (e, r = {}) => this.request({ url: e, method: "GET", params: r }, !0)); @@ -450,32 +450,32 @@ class Z { T(this, "getAppInfo", () => { }); T(this, "refreshCache", (e = !1) => { - e && l(this, m)["#"].clear(), l(this, m).$.clear(); + e && l(this, $)["#"].clear(), l(this, $).$.clear(); }); T(this, "decode", (e = "", r = {}) => { if (e === void 0 || e === "" || e === null) return r; try { - const o = l(this, G).decode(e).buffer; - return ee.unpack(ve(o)); + const i = l(this, G).decode(e).buffer; + return ee.unpack(ve(i)); } catch { return console.warn("core.decode", e), r; } }); T(this, "encode", (e = {}) => { - const r = JSON.stringify(e, (o, c) => c === void 0 ? null : c); + const r = JSON.stringify(e, (i, c) => c === void 0 ? null : c); return l(this, G).encode(pe(ee.pack(r))); }); - $(this, Q, e), $(this, F, o), $(this, G, he(r)); + R(this, Q, e), R(this, F, i), R(this, G, he(r)); } } -F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), R = new WeakMap(); +F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), $ = new WeakMap(), M = new WeakMap(); const we = Z; Z.onUnhandledRejection = (t) => { - var e, r, o, c, p, g; - t != null && t.IS_ECHO_MSG ? ((e = t == null ? void 0 : t.$toast) == null || e.call(t), (r = t == null ? void 0 : t.preventDefault) == null || r.call(t)) : (o = t.reason) != null && o.IS_ECHO_MSG && ((p = (c = t.reason) == null ? void 0 : c.$toast) == null || p.call(c), (g = t == null ? void 0 : t.preventDefault) == null || g.call(t)); + var e, r, i, c, p, g; + t != null && t.IS_ECHO_MSG ? ((e = t == null ? void 0 : t.$echoMsg) == null || e.call(t), (r = t == null ? void 0 : t.preventDefault) == null || r.call(t)) : (i = t.reason) != null && i.IS_ECHO_MSG && ((p = (c = t.reason) == null ? void 0 : c.$echoMsg) == null || p.call(c), (g = t == null ? void 0 : t.preventDefault) == null || g.call(t)); }; -Z.onToast = (t, e) => [0, 1].includes(t) ? console.log(e) : console.warn(e); +Z.onMsg = (t, e) => [0, 1].includes(t) ? console.log(e) : console.warn(e); export { we as default, de as signature, diff --git a/dist/ff-request.umd.cjs b/dist/ff-request.umd.cjs index 3cfa3e6..93782cb 100644 --- a/dist/ff-request.umd.cjs +++ b/dist/ff-request.umd.cjs @@ -1 +1 @@ -(function(p,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(p=typeof globalThis<"u"?globalThis:p||self,v(p["ff-request"]={}))})(this,function(p){"use strict";var ye=Object.defineProperty;var be=(p,v,S)=>v in p?ye(p,v,{enumerable:!0,configurable:!0,writable:!0,value:S}):p[v]=S;var P=(p,v,S)=>(be(p,typeof v!="symbol"?v+"":v,S),S),ue=(p,v,S)=>{if(!v.has(p))throw TypeError("Cannot "+S)};var l=(p,v,S)=>(ue(p,v,"read from private field"),S?S.call(p):v.get(p)),C=(p,v,S)=>{if(v.has(p))throw TypeError("Cannot add the same private member more than once");v instanceof WeakSet?v.add(p):v.set(p,S)},I=(p,v,S,Y)=>(ue(p,v,"write to private field"),Y?Y.call(p,S):v.set(p,S),S);var G,B,q,D,Q,W,L,X,Z,H,K,k,j,R;function v(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function S(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,g=new Uint8Array(u);i!==h;){for(var A=r[i],O=0,y=u-1;(A!==0||O>>0,g[y]=A%d>>>0,A=A/d>>>0;if(A!==0)throw new Error("Non-zero carry");f=O,i++}for(var o=u-f;o!==u&&g[o]===0;)o++;for(var b=m.repeat(s);o>>0,u=new Uint8Array(h);r[s];){var g=e[r.charCodeAt(s)];if(g===255)return;for(var A=0,O=h-1;(g!==0||A>>0,u[O]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");i=A,s++}for(var y=h-i;y!==h&&u[y]===0;)y++;for(var o=new Uint8Array(f+(h-y)),b=f;y!==h;)o[b++]=u[y++];return o}function z(r){var s=$(r);if(s)return s;throw new Error("Non-base"+d+" character")}return{encode:F,decodeUnsafe:$,decode:z}}var Y=S;const ce=v(Y);var ne={};(function(t){(function(e){e([],function(){var n=-1,a=-2,c=-3,w=-4,d=-5,m=function(s,f){f=f||{};var i=f.verbose||!1;i&&console.log("Normalize the JSON Object"),s=typeof s=="string"?this.JSON.parse(s):s,i&&console.log("Creating a empty dictionary");var h={strings:[],integers:[],floats:[]};i&&console.log("Creating the AST");var u=function y(o){i&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(o));var b=typeof o;if(o===null)return{type:"null",index:c};if(typeof o>"u")return{type:"undefined",index:d};if(o instanceof Array){var N=["@"];for(var T in o)o.hasOwnProperty(T)&&N.push(y(o[T]));return N}if(b==="object"){var N=["$"];for(var M in o)o.hasOwnProperty(M)&&(N.push(y(M)),N.push(y(o[M])));return N}if(o==="")return{type:"empty",index:w};if(b==="string"){var _=r.call(h.strings,o);return _==-1&&(h.strings.push(J(o)),_=h.strings.length-1),{type:"strings",index:_}}if(b==="number"&&o%1===0){var _=r.call(h.integers,o);return _==-1&&(h.integers.push($(o)),_=h.integers.length-1),{type:"integers",index:_}}if(b==="number"){var _=r.call(h.floats,o);return _==-1&&(h.floats.push(o),_=h.floats.length-1),{type:"floats",index:_}}if(b==="boolean")return{type:"boolean",index:o?n:a};throw new Error("Unexpected argument of type "+typeof o)}(s),g=h.strings.length,A=h.integers.length;h.floats.length,i&&console.log("Parsing the dictionary");var O=h.strings.join("|");return O+="^"+h.integers.join("|"),O+="^"+h.floats.join("|"),i&&console.log("Parsing the structure"),O+="^"+function y(o){if(i&&console.log("Calling a recursiveParser with "+this.JSON.stringify(o)),o instanceof Array){var b=o.shift();for(var N in o)o.hasOwnProperty(N)&&(b+=y(o[N])+"|");return(b[b.length-1]==="|"?b.slice(0,-1):b)+"]"}var T=o.type,M=o.index;if(T==="strings")return $(M);if(T==="integers")return $(g+M);if(T==="floats")return $(g+A+M);if(T==="boolean")return o.index;if(T==="null")return c;if(T==="undefined")return d;if(T==="empty")return w;throw new TypeError("The item is alien!")}(u),i&&console.log("Ending parser"),f.debug?{dictionary:h,ast:u,packed:O}:O},V=function(s,f){f=f||{};var i=s.split("^");f.verbose&&console.log("Building dictionary");var h=[],u=i[0];if(u!==""){u=u.split("|"),f.verbose&&console.log("Parse the strings dictionary");for(var g=0,A=u.length;gl(this,Q).call(this,n),ownKeys:()=>Object.keys(l(this,D).getPrototypeOf()||{}),getPrototypeOf:()=>l(this,B)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:l(this,D).getPrototypeOf()})});C(this,Q,e=>e==="$toast"?l(this,L):e==="msg"?l(this,W):e==="then"||e==="resp"?(I(this,q,!0),I(this,B,e==="resp"),l(this,X)):e==="catch"?l(this,Z):e==="IS_ECHO_MSG"?l(this,q):Reflect.get(this,e));C(this,W,(e=a=>a,n=!1)=>(l(this,L).call(this),I(this,B,n),Promise.resolve(e==null?void 0:e(l(this,D).getPrototypeOf()))));C(this,L,()=>{l(this,q)&&(I(this,q,!1),le.onToast(this.code,this.message))});C(this,X,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(l(this,D).getPrototypeOf())):Promise.reject(l(this,G)));C(this,Z,e=>Promise.resolve(e(l(this,G))));return this.code=e,this.message=n,this.data=a,this.url=c,this.res=w,I(this,G,new Proxy(this,l(this,D)))}}G=new WeakMap,B=new WeakMap,q=new WeakMap,D=new WeakMap,Q=new WeakMap,W=new WeakMap,L=new WeakMap,X=new WeakMap,Z=new WeakMap;const te=(t,e,n,a="/",c="")=>new ee(t,e,n,a,c);var ie=["utf8","utf-8","unicode-1-1-utf-8"];function de(t){if(ie.indexOf(t)<0&&typeof t<"u"&&t!=null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if(typeof e!="string")throw new TypeError("passed argument must be of tye string");var n=unescape(encodeURIComponent(e)),a=new Uint8Array(n.length);const c=n.split("");for(let w=0;w"u")return"";var a=typeof n<"u"&&a in n?n.stream:!1;if(typeof a!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var c=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),w=new Array(c.length);for(let d=0;d{let e=5381;for(let n=0;n>>0).toString(16)},we=(t,e)=>t.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),fe=t=>pe.encode(t||""),he=t=>ve.decode(new DataView(t),{});class re{constructor(e,n,a=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){C(this,H,void 0);C(this,K,void 0);C(this,k,void 0);C(this,j,{"#":new Map,$:new Map});C(this,R,new Map);P(this,"request",({url:e="/",method:n="GET",...a},c=!1)=>{var $,z;const w=n.toUpperCase(),d=ae(JSON.stringify([e,w,a])),m=($=e==null?void 0:e.includes)!=null&&$.call(e,"/_/")?"#":"$",{promise:V,resolve:J,reject:F}=Promise.withResolvers();return l(this,j)[m].has(d)?(console.log("缓存命中",e),J(l(this,j)[m].get(d))):(l(this,R).has(d)?l(this,R).get(d).push([J,F]):l(this,R).set(d,[[J,F]]),(z=l(this,R).get(d))!=null&&z.some(r=>r)&&l(this,H).call(this,{url:e,method:w,...a}).then(r=>{if(![0,1].includes(r.code))throw te(r.code,r.msg,r.data,e,r==null?void 0:r.res);return[r.code,r.msg,r.data,e,r==null?void 0:r.res]}).then(r=>((m=="#"||c&&w==="GET")&&l(this,j)[m].set(d,r),r)).then(r=>{var s;return(s=l(this,R).get(d))==null?void 0:s.forEach((f,i,h)=>{f&&f[0](r),delete h[i]})}).catch(r=>{var s;l(this,j)[m].delete(d),(s=l(this,R).get(d))==null||s.forEach((f,i,h)=>{f&&f[1](r instanceof ee?r:te(-1,r,null,e)),delete h[i]})}).finally(()=>l(this,R).delete(d))),new Proxy(V,{get:(r,s)=>(...f)=>r.then(i=>te(...i)[s](...f)).catch(i=>{if(!i instanceof ee)throw i;return typeof i[s]=="function"?i[s](...f):i[s]})})});P(this,"get",(e,n={})=>this.request({url:e,method:"GET",params:n}));P(this,"post",(e,n={},a={})=>this.request({url:e,method:"POST",data:n,params:a}));P(this,"put",(e,n={},a={})=>this.request({url:e,method:"PUT",data:n,params:a}));P(this,"del",(e,n={},a={})=>this.request({url:e,method:"DELETE",data:n,params:a}));P(this,"download",(e,n)=>{});P(this,"cache",(e,n={})=>this.request({url:e,method:"GET",params:n},!0));P(this,"list",(e,n={})=>this.get(`/api/${e}/${this.encode(n)}`));P(this,"getAppInfo",()=>{});P(this,"refreshCache",(e=!1)=>{e&&l(this,j)["#"].clear(),l(this,j).$.clear()});P(this,"decode",(e="",n={})=>{if(e===void 0||e===""||e===null)return n;try{const a=l(this,K).decode(e).buffer;return se.unpack(he(a))}catch{return console.warn("core.decode",e),n}});P(this,"encode",(e={})=>{const n=JSON.stringify(e,(a,c)=>c===void 0?null:c);return l(this,K).encode(fe(se.pack(n)))});I(this,k,e),I(this,H,a),I(this,K,ce(n))}}H=new WeakMap,K=new WeakMap,k=new WeakMap,j=new WeakMap,R=new WeakMap;const le=re;re.onUnhandledRejection=t=>{var e,n,a,c,w,d;t!=null&&t.IS_ECHO_MSG?((e=t==null?void 0:t.$toast)==null||e.call(t),(n=t==null?void 0:t.preventDefault)==null||n.call(t)):(a=t.reason)!=null&&a.IS_ECHO_MSG&&((w=(c=t.reason)==null?void 0:c.$toast)==null||w.call(c),(d=t==null?void 0:t.preventDefault)==null||d.call(t))},re.onToast=(t,e)=>[0,1].includes(t)?console.log(e):console.warn(e),p.default=le,p.signature=ae,p.str2uint8array=fe,p.trim=we,p.uint8array2str=he,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(p,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(p=typeof globalThis<"u"?globalThis:p||self,v(p["ff-request"]={}))})(this,function(p){"use strict";var ye=Object.defineProperty;var be=(p,v,S)=>v in p?ye(p,v,{enumerable:!0,configurable:!0,writable:!0,value:S}):p[v]=S;var P=(p,v,S)=>(be(p,typeof v!="symbol"?v+"":v,S),S),ue=(p,v,S)=>{if(!v.has(p))throw TypeError("Cannot "+S)};var l=(p,v,S)=>(ue(p,v,"read from private field"),S?S.call(p):v.get(p)),C=(p,v,S)=>{if(v.has(p))throw TypeError("Cannot add the same private member more than once");v instanceof WeakSet?v.add(p):v.set(p,S)},I=(p,v,S,Y)=>(ue(p,v,"write to private field"),Y?Y.call(p,S):v.set(p,S),S);var G,B,q,D,Q,W,L,X,Z,H,K,k,j,x;function v(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function S(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,d=new Uint8Array(u);i!==h;){for(var A=r[i],O=0,y=u-1;(A!==0||O>>0,d[y]=A%g>>>0,A=A/g>>>0;if(A!==0)throw new Error("Non-zero carry");f=O,i++}for(var o=u-f;o!==u&&d[o]===0;)o++;for(var b=R.repeat(s);o>>0,u=new Uint8Array(h);r[s];){var d=e[r.charCodeAt(s)];if(d===255)return;for(var A=0,O=h-1;(d!==0||A>>0,u[O]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");i=A,s++}for(var y=h-i;y!==h&&u[y]===0;)y++;for(var o=new Uint8Array(f+(h-y)),b=f;y!==h;)o[b++]=u[y++];return o}function z(r){var s=m(r);if(s)return s;throw new Error("Non-base"+g+" character")}return{encode:F,decodeUnsafe:m,decode:z}}var Y=S;const ce=v(Y);var ne={};(function(t){(function(e){e([],function(){var n=-1,a=-2,c=-3,w=-4,g=-5,R=function(s,f){f=f||{};var i=f.verbose||!1;i&&console.log("Normalize the JSON Object"),s=typeof s=="string"?this.JSON.parse(s):s,i&&console.log("Creating a empty dictionary");var h={strings:[],integers:[],floats:[]};i&&console.log("Creating the AST");var u=function y(o){i&&console.log("Calling recursiveAstBuilder with "+this.JSON.stringify(o));var b=typeof o;if(o===null)return{type:"null",index:c};if(typeof o>"u")return{type:"undefined",index:g};if(o instanceof Array){var N=["@"];for(var T in o)o.hasOwnProperty(T)&&N.push(y(o[T]));return N}if(b==="object"){var N=["$"];for(var $ in o)o.hasOwnProperty($)&&(N.push(y($)),N.push(y(o[$])));return N}if(o==="")return{type:"empty",index:w};if(b==="string"){var _=r.call(h.strings,o);return _==-1&&(h.strings.push(J(o)),_=h.strings.length-1),{type:"strings",index:_}}if(b==="number"&&o%1===0){var _=r.call(h.integers,o);return _==-1&&(h.integers.push(m(o)),_=h.integers.length-1),{type:"integers",index:_}}if(b==="number"){var _=r.call(h.floats,o);return _==-1&&(h.floats.push(o),_=h.floats.length-1),{type:"floats",index:_}}if(b==="boolean")return{type:"boolean",index:o?n:a};throw new Error("Unexpected argument of type "+typeof o)}(s),d=h.strings.length,A=h.integers.length;h.floats.length,i&&console.log("Parsing the dictionary");var O=h.strings.join("|");return O+="^"+h.integers.join("|"),O+="^"+h.floats.join("|"),i&&console.log("Parsing the structure"),O+="^"+function y(o){if(i&&console.log("Calling a recursiveParser with "+this.JSON.stringify(o)),o instanceof Array){var b=o.shift();for(var N in o)o.hasOwnProperty(N)&&(b+=y(o[N])+"|");return(b[b.length-1]==="|"?b.slice(0,-1):b)+"]"}var T=o.type,$=o.index;if(T==="strings")return m($);if(T==="integers")return m(d+$);if(T==="floats")return m(d+A+$);if(T==="boolean")return o.index;if(T==="null")return c;if(T==="undefined")return g;if(T==="empty")return w;throw new TypeError("The item is alien!")}(u),i&&console.log("Ending parser"),f.debug?{dictionary:h,ast:u,packed:O}:O},V=function(s,f){f=f||{};var i=s.split("^");f.verbose&&console.log("Building dictionary");var h=[],u=i[0];if(u!==""){u=u.split("|"),f.verbose&&console.log("Parse the strings dictionary");for(var d=0,A=u.length;dl(this,Q).call(this,n),ownKeys:()=>Object.keys(l(this,D).getPrototypeOf()||{}),getPrototypeOf:()=>l(this,B)?this:this.data,getOwnPropertyDescriptor:()=>({configurable:!0,enumerable:!0,writable:!0,value:l(this,D).getPrototypeOf()})});C(this,Q,e=>e==="$echoMsg"?l(this,L):e==="msg"?l(this,W):e==="then"||e==="resp"?(I(this,q,!0),I(this,B,e==="resp"),l(this,X)):e==="catch"?l(this,Z):e==="IS_ECHO_MSG"?l(this,q):Reflect.get(this,e));C(this,W,(e=a=>a,n=!1)=>(l(this,L).call(this),I(this,B,n),Promise.resolve(e==null?void 0:e(l(this,D).getPrototypeOf()))));C(this,L,()=>{l(this,q)&&(I(this,q,!1),le.onMsg(this.code,this.message))});C(this,X,e=>[0,1].includes(this.code)?Promise.resolve(e==null?void 0:e(l(this,D).getPrototypeOf())):Promise.reject(l(this,G)));C(this,Z,e=>Promise.resolve(e(l(this,G))));return this.code=e,this.message=n,this.data=a,this.url=c,this.res=w,I(this,G,new Proxy(this,l(this,D)))}}G=new WeakMap,B=new WeakMap,q=new WeakMap,D=new WeakMap,Q=new WeakMap,W=new WeakMap,L=new WeakMap,X=new WeakMap,Z=new WeakMap;const te=(t,e,n,a="/",c="")=>new ee(t,e,n,a,c);var ie=["utf8","utf-8","unicode-1-1-utf-8"];function ge(t){if(ie.indexOf(t)<0&&typeof t<"u"&&t!=null)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if(typeof e!="string")throw new TypeError("passed argument must be of tye string");var n=unescape(encodeURIComponent(e)),a=new Uint8Array(n.length);const c=n.split("");for(let w=0;w"u")return"";var a=typeof n<"u"&&a in n?n.stream:!1;if(typeof a!="boolean")throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var c=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),w=new Array(c.length);for(let g=0;g{let e=5381;for(let n=0;n>>0).toString(16)},we=(t,e)=>t.replace(new RegExp(`^${e}+|${e}+$`,"g"),""),fe=t=>pe.encode(t||""),he=t=>ve.decode(new DataView(t),{});class re{constructor(e,n,a=({})=>Promise.reject({code:-1,msg:"请初始化HTTP请求方法主体"})){C(this,H,void 0);C(this,K,void 0);C(this,k,void 0);C(this,j,{"#":new Map,$:new Map});C(this,x,new Map);P(this,"request",({url:e="/",method:n="GET",...a},c=!1)=>{var m,z;const w=n.toUpperCase(),g=ae(JSON.stringify([e,w,a])),R=(m=e==null?void 0:e.includes)!=null&&m.call(e,"/_/")?"#":"$",{promise:V,resolve:J,reject:F}=Promise.withResolvers();return l(this,j)[R].has(g)?(console.log("缓存命中",e),J(l(this,j)[R].get(g))):(l(this,x).has(g)?l(this,x).get(g).push([J,F]):l(this,x).set(g,[[J,F]]),(z=l(this,x).get(g))!=null&&z.some(r=>r)&&l(this,H).call(this,{url:e,method:w,...a}).then(r=>{if(![0,1].includes(r.code))throw te(r.code,r.msg,r.data,e,r==null?void 0:r.res);return[r.code,r.msg,r.data,e,r==null?void 0:r.res]}).then(r=>((R=="#"||c&&w==="GET")&&l(this,j)[R].set(g,r),r)).then(r=>{var s;return(s=l(this,x).get(g))==null?void 0:s.forEach((f,i,h)=>{f&&f[0](r),delete h[i]})}).catch(r=>{var s;l(this,j)[R].delete(g),(s=l(this,x).get(g))==null||s.forEach((f,i,h)=>{f&&f[1](r instanceof ee?r:te(-1,r,null,e)),delete h[i]})}).finally(()=>l(this,x).delete(g))),new Proxy(V,{get:(r,s)=>(...f)=>r.then(i=>te(...i)[s](...f)).catch(i=>{if(!i instanceof ee)throw i;return typeof i[s]=="function"?i[s](...f):i[s]})})});P(this,"get",(e,n={})=>this.request({url:e,method:"GET",params:n}));P(this,"post",(e,n={},a={})=>this.request({url:e,method:"POST",data:n,params:a}));P(this,"put",(e,n={},a={})=>this.request({url:e,method:"PUT",data:n,params:a}));P(this,"del",(e,n={},a={})=>this.request({url:e,method:"DELETE",data:n,params:a}));P(this,"download",(e,n)=>{});P(this,"cache",(e,n={})=>this.request({url:e,method:"GET",params:n},!0));P(this,"list",(e,n={})=>this.get(`/api/${e}/${this.encode(n)}`));P(this,"getAppInfo",()=>{});P(this,"refreshCache",(e=!1)=>{e&&l(this,j)["#"].clear(),l(this,j).$.clear()});P(this,"decode",(e="",n={})=>{if(e===void 0||e===""||e===null)return n;try{const a=l(this,K).decode(e).buffer;return se.unpack(he(a))}catch{return console.warn("core.decode",e),n}});P(this,"encode",(e={})=>{const n=JSON.stringify(e,(a,c)=>c===void 0?null:c);return l(this,K).encode(fe(se.pack(n)))});I(this,k,e),I(this,H,a),I(this,K,ce(n))}}H=new WeakMap,K=new WeakMap,k=new WeakMap,j=new WeakMap,x=new WeakMap;const le=re;re.onUnhandledRejection=t=>{var e,n,a,c,w,g;t!=null&&t.IS_ECHO_MSG?((e=t==null?void 0:t.$echoMsg)==null||e.call(t),(n=t==null?void 0:t.preventDefault)==null||n.call(t)):(a=t.reason)!=null&&a.IS_ECHO_MSG&&((w=(c=t.reason)==null?void 0:c.$echoMsg)==null||w.call(c),(g=t==null?void 0:t.preventDefault)==null||g.call(t))},re.onMsg=(t,e)=>[0,1].includes(t)?console.log(e):console.warn(e),p.default=le,p.signature=ae,p.str2uint8array=fe,p.trim=we,p.uint8array2str=he,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/package.json b/package.json index 4e2d749..f15a9bf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ff-request", "private": true, - "version": "0.9.11", + "version": "0.9.12", "type": "module", "files": [ "dist"