This commit is contained in:
what 2024-05-25 21:26:25 +08:00
parent e1dcde17b5
commit ff33fd75aa
3 changed files with 88 additions and 88 deletions

172
dist/ff-request.js vendored
View File

@ -1,6 +1,6 @@
var ae = Object.defineProperty; var oe = Object.defineProperty;
var oe = (t, e, r) => e in t ? ae(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; var ae = (t, e, r) => e in t ? oe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
var A = (t, e, r) => (oe(t, typeof e != "symbol" ? e + "" : e, r), r), k = (t, e, r) => { var A = (t, e, r) => (ae(t, typeof e != "symbol" ? e + "" : e, r), r), k = (t, e, r) => {
if (!e.has(t)) if (!e.has(t))
throw TypeError("Cannot " + r); throw TypeError("Cannot " + r);
}; };
@ -18,10 +18,10 @@ function ie(t) {
for (var e = new Uint8Array(256), r = 0; r < e.length; r++) for (var e = new Uint8Array(256), r = 0; r < e.length; r++)
e[r] = 255; e[r] = 255;
for (var n = 0; n < t.length; n++) { for (var n = 0; n < t.length; n++) {
var u = t.charAt(n), p = u.charCodeAt(0); var u = t.charAt(n), v = u.charCodeAt(0);
if (e[p] !== 255) if (e[v] !== 255)
throw new TypeError(u + " is ambiguous"); throw new TypeError(u + " is ambiguous");
e[p] = n; e[v] = n;
} }
var d = t.length, U = t.charAt(0), B = Math.log(d) / Math.log(256), D = Math.log(256) / Math.log(d); var d = t.length, U = t.charAt(0), B = Math.log(d) / Math.log(256), D = Math.log(256) / Math.log(d);
function q(f) { function q(f) {
@ -29,18 +29,18 @@ function ie(t) {
throw new TypeError("Expected Uint8Array"); throw new TypeError("Expected Uint8Array");
if (f.length === 0) if (f.length === 0)
return ""; return "";
for (var a = 0, o = 0, c = 0, i = f.length; c !== i && f[c] === 0; ) for (var o = 0, a = 0, c = 0, i = f.length; c !== i && f[c] === 0; )
c++, a++; c++, o++;
for (var h = (i - c) * D + 1 >>> 0, g = new Uint8Array(h); c !== i; ) { for (var h = (i - c) * D + 1 >>> 0, g = new Uint8Array(h); c !== i; ) {
for (var T = f[c], E = 0, w = h - 1; (T !== 0 || E < o) && w !== -1; w--, E++) for (var T = f[c], E = 0, w = h - 1; (T !== 0 || E < a) && w !== -1; w--, E++)
T += 256 * g[w] >>> 0, g[w] = T % d >>> 0, T = T / d >>> 0; T += 256 * g[w] >>> 0, g[w] = T % d >>> 0, T = T / d >>> 0;
if (T !== 0) if (T !== 0)
throw new Error("Non-zero carry"); throw new Error("Non-zero carry");
o = E, c++; a = E, c++;
} }
for (var s = h - o; s !== h && g[s] === 0; ) for (var s = h - a; s !== h && g[s] === 0; )
s++; s++;
for (var y = U.repeat(a); s < h; ++s) for (var y = U.repeat(o); s < h; ++s)
y += t.charAt(g[s]); y += t.charAt(g[s]);
return y; return y;
} }
@ -49,34 +49,34 @@ function ie(t) {
throw new TypeError("Expected String"); throw new TypeError("Expected String");
if (f.length === 0) if (f.length === 0)
return new Uint8Array(); return new Uint8Array();
for (var a = 0, o = 0, c = 0; f[a] === U; ) for (var o = 0, a = 0, c = 0; f[o] === U; )
o++, a++; a++, o++;
for (var i = (f.length - a) * B + 1 >>> 0, h = new Uint8Array(i); f[a]; ) { for (var i = (f.length - o) * B + 1 >>> 0, h = new Uint8Array(i); f[o]; ) {
var g = e[f.charCodeAt(a)]; var g = e[f.charCodeAt(o)];
if (g === 255) if (g === 255)
return; return;
for (var T = 0, E = i - 1; (g !== 0 || T < c) && E !== -1; E--, T++) for (var T = 0, E = i - 1; (g !== 0 || T < c) && E !== -1; E--, T++)
g += d * h[E] >>> 0, h[E] = g % 256 >>> 0, g = g / 256 >>> 0; g += d * h[E] >>> 0, h[E] = g % 256 >>> 0, g = g / 256 >>> 0;
if (g !== 0) if (g !== 0)
throw new Error("Non-zero carry"); throw new Error("Non-zero carry");
c = T, a++; c = T, o++;
} }
for (var w = i - c; w !== i && h[w] === 0; ) for (var w = i - c; w !== i && h[w] === 0; )
w++; w++;
for (var s = new Uint8Array(o + (i - w)), y = o; w !== i; ) for (var s = new Uint8Array(a + (i - w)), y = a; w !== i; )
s[y++] = h[w++]; s[y++] = h[w++];
return s; return s;
} }
function v(f) { function p(f) {
var a = x(f); var o = x(f);
if (a) if (o)
return a; return o;
throw new Error("Non-base" + d + " character"); throw new Error("Non-base" + d + " character");
} }
return { return {
encode: q, encode: q,
decodeUnsafe: x, decodeUnsafe: x,
decode: v decode: p
}; };
} }
var fe = ie; var fe = ie;
@ -85,10 +85,10 @@ var re = {};
(function(t) { (function(t) {
(function(e) { (function(e) {
e([], function() { e([], function() {
var r = -1, n = -2, u = -3, p = -4, d = -5, U = function(a, o) { var r = -1, n = -2, u = -3, v = -4, d = -5, U = function(o, a) {
o = o || {}; a = a || {};
var c = o.verbose || !1; var c = a.verbose || !1;
c && console.log("Normalize the JSON Object"), a = typeof a == "string" ? this.JSON.parse(a) : a, c && console.log("Creating a empty dictionary"); c && console.log("Normalize the JSON Object"), o = typeof o == "string" ? this.JSON.parse(o) : o, c && console.log("Creating a empty dictionary");
var i = { var i = {
strings: [], strings: [],
integers: [], integers: [],
@ -123,7 +123,7 @@ var re = {};
if (s === "") if (s === "")
return { return {
type: "empty", type: "empty",
index: p index: v
}; };
if (y === "string") { if (y === "string") {
var P = f.call(i.strings, s); var P = f.call(i.strings, s);
@ -152,7 +152,7 @@ var re = {};
index: s ? r : n index: s ? r : n
}; };
throw new Error("Unexpected argument of type " + typeof s); throw new Error("Unexpected argument of type " + typeof s);
}(a), g = i.strings.length, T = i.integers.length; }(o), g = i.strings.length, T = i.integers.length;
i.floats.length, c && console.log("Parsing the dictionary"); i.floats.length, c && console.log("Parsing the dictionary");
var E = i.strings.join("|"); var E = i.strings.join("|");
return E += "^" + i.integers.join("|"), E += "^" + i.floats.join("|"), c && console.log("Parsing the structure"), E += "^" + function w(s) { return E += "^" + i.integers.join("|"), E += "^" + i.floats.join("|"), c && console.log("Parsing the structure"), E += "^" + function w(s) {
@ -176,45 +176,45 @@ var re = {};
if (O === "undefined") if (O === "undefined")
return d; return d;
if (O === "empty") if (O === "empty")
return p; return v;
throw new TypeError("The item is alien!"); throw new TypeError("The item is alien!");
}(h), c && console.log("Ending parser"), o.debug ? { }(h), c && console.log("Ending parser"), a.debug ? {
dictionary: i, dictionary: i,
ast: h, ast: h,
packed: E packed: E
} : E; } : E;
}, B = function(a, o) { }, B = function(o, a) {
o = o || {}; a = a || {};
var c = a.split("^"); var c = o.split("^");
o.verbose && console.log("Building dictionary"); a.verbose && console.log("Building dictionary");
var i = [], h = c[0]; var i = [], h = c[0];
if (h !== "") { if (h !== "") {
h = h.split("|"), o.verbose && console.log("Parse the strings dictionary"); h = h.split("|"), a.verbose && console.log("Parse the strings dictionary");
for (var g = 0, T = h.length; g < T; g++) for (var g = 0, T = h.length; g < T; g++)
i.push(q(h[g])); i.push(q(h[g]));
} }
if (h = c[1], h !== "") { if (h = c[1], h !== "") {
h = h.split("|"), o.verbose && console.log("Parse the integers dictionary"); h = h.split("|"), a.verbose && console.log("Parse the integers dictionary");
for (var g = 0, T = h.length; g < T; g++) for (var g = 0, T = h.length; g < T; g++)
i.push(v(h[g])); i.push(p(h[g]));
} }
if (h = c[2], h !== "") { if (h = c[2], h !== "") {
h = h.split("|"), o.verbose && console.log("Parse the floats dictionary"); h = h.split("|"), a.verbose && console.log("Parse the floats dictionary");
for (var g = 0, T = h.length; g < T; g++) for (var g = 0, T = h.length; g < T; g++)
i.push(parseFloat(h[g])); i.push(parseFloat(h[g]));
} }
h = null, o.verbose && console.log("Tokenizing the structure"); h = null, a.verbose && console.log("Tokenizing the structure");
for (var E = "", w = [], s = c[3].length, g = 0; g < s; g++) { for (var E = "", w = [], s = c[3].length, g = 0; g < s; g++) {
var y = c[3].charAt(g); var y = c[3].charAt(g);
y === "|" || y === "$" || y === "@" || y === "]" ? (E && (w.push(v(E)), E = ""), y !== "|" && w.push(y)) : E += y; y === "|" || y === "$" || y === "@" || y === "]" ? (E && (w.push(p(E)), E = ""), y !== "|" && w.push(y)) : E += y;
} }
var _ = w.length, O = 0; var _ = w.length, O = 0;
return o.verbose && console.log("Starting recursive parser"), function R() { return a.verbose && console.log("Starting recursive parser"), function R() {
var P = w[O++]; var P = w[O++];
if (o.verbose && console.log("Reading collection type " + (P === "$" ? "object" : "Array")), P === "@") { if (a.verbose && console.log("Reading collection type " + (P === "$" ? "object" : "Array")), P === "@") {
for (var b = []; O < _; O++) { for (var b = []; O < _; O++) {
var N = w[O]; var N = w[O];
if (o.verbose && console.log("Read " + N + " symbol"), N === "]") if (a.verbose && console.log("Read " + N + " symbol"), N === "]")
return b; return b;
if (N === "@" || N === "$") if (N === "@" || N === "$")
b.push(R()); b.push(R());
@ -232,21 +232,21 @@ var re = {};
case d: case d:
b.push(void 0); b.push(void 0);
break; break;
case p: case v:
b.push(""); b.push("");
break; break;
default: default:
b.push(i[N]); b.push(i[N]);
} }
} }
return o.verbose && console.log("Parsed " + this.JSON.stringify(b)), b; return a.verbose && console.log("Parsed " + this.JSON.stringify(b)), b;
} }
if (P === "$") { if (P === "$") {
for (var b = {}; O < _; O++) { for (var b = {}; O < _; O++) {
var C = w[O]; var C = w[O];
if (C === "]") if (C === "]")
return b; return b;
C === p ? C = "" : C = i[C]; C === v ? C = "" : C = i[C];
var N = w[++O]; var N = w[++O];
if (N === "@" || N === "$") if (N === "@" || N === "$")
b[C] = R(); b[C] = R();
@ -264,44 +264,44 @@ var re = {};
case d: case d:
b[C] = void 0; b[C] = void 0;
break; break;
case p: case v:
b[C] = ""; b[C] = "";
break; break;
default: default:
b[C] = i[N]; b[C] = i[N];
} }
} }
return o.verbose && console.log("Parsed " + this.JSON.stringify(b)), b; return a.verbose && console.log("Parsed " + this.JSON.stringify(b)), b;
} }
throw new TypeError("Bad token " + P + " isn't a type"); throw new TypeError("Bad token " + P + " isn't a type");
}(); }();
}, D = function(a) { }, D = function(o) {
return typeof a != "string" ? a : a.replace(/[\+ \|\^\%]/g, function(o) { return typeof o != "string" ? o : o.replace(/[\+ \|\^\%]/g, function(a) {
return { return {
" ": "+", " ": "+",
"+": "%2B", "+": "%2B",
"|": "%7C", "|": "%7C",
"^": "%5E", "^": "%5E",
"%": "%25" "%": "%25"
}[o]; }[a];
}); });
}, q = function(a) { }, q = function(o) {
return typeof a != "string" ? a : a.replace(/\+|%2B|%7C|%5E|%25/g, function(o) { return typeof o != "string" ? o : o.replace(/\+|%2B|%7C|%5E|%25/g, function(a) {
return { return {
"+": " ", "+": " ",
"%2B": "+", "%2B": "+",
"%7C": "|", "%7C": "|",
"%5E": "^", "%5E": "^",
"%25": "%" "%25": "%"
}[o]; }[a];
}); });
}, x = function(a) { }, x = function(o) {
return Number.prototype.toString.call(a, 36).toUpperCase(); return Number.prototype.toString.call(o, 36).toUpperCase();
}, v = function(a) { }, p = function(o) {
return parseInt(a, 36); return parseInt(o, 36);
}, f = Array.prototype.indexOf || function(a, o) { }, f = Array.prototype.indexOf || function(o, a) {
for (var c = o || 0, i = this.length; c < i; c++) for (var c = a || 0, i = this.length; c < i; c++)
if (this[c] === a) if (this[c] === o)
return c; return c;
return -1; return -1;
}; };
@ -320,7 +320,7 @@ var re = {};
const ee = /* @__PURE__ */ te(re); const ee = /* @__PURE__ */ te(re);
var J, z, j, I, L, H, K, V, Y; var J, z, j, I, L, H, K, V, Y;
class X { class X {
constructor(e, r, n, u, p) { constructor(e, r, n, u, v) {
A(this, "code", 0); A(this, "code", 0);
A(this, "message", "操作成功"); A(this, "message", "操作成功");
A(this, "data", null); A(this, "data", null);
@ -350,7 +350,7 @@ class X {
}); });
S(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(l(this, I).getPrototypeOf())) : Promise.reject(l(this, J))); S(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(l(this, I).getPrototypeOf())) : Promise.reject(l(this, J)));
S(this, Y, (e) => Promise.resolve(e(l(this, J)))); S(this, Y, (e) => Promise.resolve(e(l(this, J))));
return this.code = e, this.message = r, this.data = n, this.url = u, this.res = p, $(this, J, new Proxy(this, l(this, I))); return this.code = e, this.message = r, this.data = n, this.url = u, this.res = v, $(this, J, new Proxy(this, l(this, I)));
} }
} }
J = new WeakMap(), z = new WeakMap(), j = new WeakMap(), I = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap(); J = new WeakMap(), z = new WeakMap(), j = new WeakMap(), I = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap();
@ -368,8 +368,8 @@ function le(t) {
throw new TypeError("passed argument must be of tye string"); throw new TypeError("passed argument must be of tye string");
var r = unescape(encodeURIComponent(e)), n = new Uint8Array(r.length); var r = unescape(encodeURIComponent(e)), n = new Uint8Array(r.length);
const u = r.split(""); const u = r.split("");
for (let p = 0; p < u.length; p++) for (let v = 0; v < u.length; v++)
n[p] = u[p].charCodeAt(0); n[v] = u[v].charCodeAt(0);
return n; return n;
}; };
} }
@ -383,10 +383,10 @@ function ue(t) {
if (typeof n != "boolean") if (typeof n != "boolean")
throw new TypeError("stream option must be boolean"); throw new TypeError("stream option must be boolean");
if (ArrayBuffer.isView(e)) { if (ArrayBuffer.isView(e)) {
var u = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), p = new Array(u.length); var u = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), v = new Array(u.length);
for (let d = 0; d < u.length; d++) for (let d = 0; d < u.length; d++)
p[d] = String.fromCharCode(u[d]); v[d] = String.fromCharCode(u[d]);
return decodeURIComponent(escape(p.join(""))); return decodeURIComponent(escape(v.join("")));
} else } else
throw new TypeError("passed argument must be an array buffer view"); throw new TypeError("passed argument must be an array buffer view");
}; };
@ -400,7 +400,7 @@ const ce = new se.TextEncoder("utf8"), ge = new se.TextDecoder("utf8"), de = (t)
for (let r = 0; r < t.length; r++) for (let r = 0; r < t.length; r++)
e = e * 33 ^ t.charCodeAt(r); e = e * 33 ^ t.charCodeAt(r);
return (e >>> 0).toString(16); return (e >>> 0).toString(16);
}, be = (t, e) => t.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), ve = (t) => ce.encode(t || ""), pe = (t) => ge.decode(new DataView(t), {}); }, 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, M; var F, G, Q, m, M;
class Z { class Z {
constructor(e, r, n = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { constructor(e, r, n = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) {
@ -416,16 +416,16 @@ class Z {
S(this, M, /* @__PURE__ */ new Map()); S(this, M, /* @__PURE__ */ new Map());
A(this, "request", ({ url: e = "/", method: r = "GET", ...n }, u = !1) => { A(this, "request", ({ url: e = "/", method: r = "GET", ...n }, u = !1) => {
var x; var x;
const p = r.toUpperCase(), d = de(JSON.stringify([e, p, n])), U = (x = e == null ? void 0 : e.includes) != null && x.call(e, "/_/") ? "#" : "$", { p: B, resolve: D, reject: q } = Promise.withResolvers(); const v = r.toUpperCase(), d = de(JSON.stringify([e, v, n])), U = (x = e == null ? void 0 : e.includes) != null && x.call(e, "/_/") ? "#" : "$", { promise: B, resolve: D, reject: q } = Promise.withResolvers();
return l(this, m)[U].has(d) ? (console.log("缓存命中", e), D(l(this, m)[U].get(d))) : l(this, M).has(d) ? l(this, M).get(d).push([D, q]) : (l(this, M).set(d, [[D, q]]), l(this, F).call(this, { url: e, method: p, ...n }).then((v) => { return l(this, m)[U].has(d) ? (console.log("缓存命中", e), D(l(this, m)[U].get(d))) : l(this, M).has(d) ? l(this, M).get(d).push([D, q]) : (l(this, M).set(d, [[D, q]]), l(this, F).call(this, { url: e, method: v, ...n }).then((p) => {
if (![0, 1].includes(v.code)) if (![0, 1].includes(p.code))
throw W(v.code, v.msg, v.data, e, v == null ? void 0 : v.res); throw W(p.code, p.msg, p.data, e, p == null ? void 0 : p.res);
return [v.code, v.msg, v.data, e, v == null ? void 0 : v.res]; return [p.code, p.msg, p.data, e, p == null ? void 0 : p.res];
}).then((v) => ((U == "#" || u && p === "GET") && l(this, m)[U].set(d, v), v)).then((v) => l(this, M).get(d).forEach(([f, a]) => f(v))).catch((v) => (l(this, m)[U].delete(d), l(this, M).get(d).forEach(([f, a]) => a(v instanceof X ? v : W(-1, v, null, e))))).finally(() => l(this, M).delete(d))), new Proxy(B, { }).then((p) => ((U == "#" || u && v === "GET") && l(this, m)[U].set(d, p), p)).then((p) => l(this, M).get(d).forEach(([f, o]) => f(p))).catch((p) => (l(this, m)[U].delete(d), l(this, M).get(d).forEach(([f, o]) => o(p instanceof X ? p : W(-1, p, null, e))))).finally(() => l(this, M).delete(d))), new Proxy(B, {
get: (v, f) => (...a) => v.then((o) => W(...o)[f](...a)).catch((o) => { get: (p, f) => (...o) => p.then((a) => W(...a)[f](...o)).catch((a) => {
if (!o instanceof X) if (!a instanceof X)
throw o; throw a;
return typeof o[f] == "function" ? o[f](...a) : o[f]; return typeof a[f] == "function" ? a[f](...o) : a[f];
}) })
}); });
}); });
@ -447,14 +447,14 @@ class Z {
return r; return r;
try { try {
const n = l(this, G).decode(e).buffer; const n = l(this, G).decode(e).buffer;
return ee.unpack(pe(n)); return ee.unpack(ve(n));
} catch { } catch {
return console.warn("core.decode", e), r; return console.warn("core.decode", e), r;
} }
}); });
A(this, "encode", (e = {}) => { A(this, "encode", (e = {}) => {
const r = JSON.stringify(e, (n, u) => u === void 0 ? null : u); const r = JSON.stringify(e, (n, u) => u === void 0 ? null : u);
return l(this, G).encode(ve(ee.pack(r))); return l(this, G).encode(pe(ee.pack(r)));
}); });
$(this, Q, e), $(this, F, n), $(this, G, he(r)); $(this, Q, e), $(this, F, n), $(this, G, he(r));
} }
@ -462,14 +462,14 @@ class Z {
F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), M = new WeakMap(); F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), M = new WeakMap();
const we = Z; const we = Z;
Z.onUnhandledRejection = (t) => { Z.onUnhandledRejection = (t) => {
var e, r, n, u, p, d; var e, r, n, u, v, d;
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)) : (n = t.reason) != null && n.IS_ECHO_MSG && ((p = (u = t.reason) == null ? void 0 : u.$toast) == null || p.call(u), (d = t == null ? void 0 : t.preventDefault) == null || d.call(t)); 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)) : (n = t.reason) != null && n.IS_ECHO_MSG && ((v = (u = t.reason) == null ? void 0 : u.$toast) == null || v.call(u), (d = t == null ? void 0 : t.preventDefault) == null || d.call(t));
}; };
Z.onToast = (t, e) => [0, 1].includes(t) ? console.log(e) : console.warn(e); Z.onToast = (t, e) => [0, 1].includes(t) ? console.log(e) : console.warn(e);
export { export {
we as default, we as default,
de as signature, de as signature,
ve as str2uint8array, pe as str2uint8array,
be as trim, be as trim,
pe as uint8array2str ve as uint8array2str
}; };

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{ {
"name": "ff-request", "name": "ff-request",
"private": true, "private": true,
"version": "0.9.3", "version": "0.9.4",
"type": "module", "type": "module",
"files": [ "files": [
"dist" "dist"