ff-request-dist/dist/ff-request.js

492 lines
18 KiB
JavaScript
Raw Normal View History

2024-07-23 11:16:38 +08:00
var oe = Object.defineProperty;
var ie = (r, e, t) => e in r ? oe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var P = (r, e, t) => (ie(r, typeof e != "symbol" ? e + "" : e, t), t), k = (r, e, t) => {
if (!e.has(r))
throw TypeError("Cannot " + t);
2024-04-04 11:47:06 +08:00
};
2024-07-23 11:16:38 +08:00
var u = (r, e, t) => (k(r, e, "read from private field"), t ? t.call(r) : e.get(r)), A = (r, e, t) => {
if (e.has(r))
2024-04-04 11:47:06 +08:00
throw TypeError("Cannot add the same private member more than once");
2024-07-23 11:16:38 +08:00
e instanceof WeakSet ? e.add(r) : e.set(r, t);
}, M = (r, e, t, s) => (k(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t);
function re(r) {
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
function ae(r) {
if (r.length >= 255)
2024-04-04 11:47:06 +08:00
throw new TypeError("Alphabet too long");
2024-07-23 11:16:38 +08:00
for (var e = new Uint8Array(256), t = 0; t < e.length; t++)
e[t] = 255;
for (var s = 0; s < r.length; s++) {
var l = r.charAt(s), v = l.charCodeAt(0);
if (e[v] !== 255)
throw new TypeError(l + " is ambiguous");
e[v] = s;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
var g = r.length, N = r.charAt(0), B = Math.log(g) / Math.log(256), I = Math.log(256) / Math.log(g);
2024-05-25 23:24:11 +08:00
function q(n) {
if (n instanceof Uint8Array || (ArrayBuffer.isView(n) ? n = new Uint8Array(n.buffer, n.byteOffset, n.byteLength) : Array.isArray(n) && (n = Uint8Array.from(n))), !(n instanceof Uint8Array))
2024-04-04 11:47:06 +08:00
throw new TypeError("Expected Uint8Array");
2024-05-25 23:24:11 +08:00
if (n.length === 0)
2024-04-04 11:47:06 +08:00
return "";
2024-07-23 11:16:38 +08:00
for (var o = 0, f = 0, i = 0, h = n.length; i !== h && n[i] === 0; )
i++, o++;
for (var c = (h - i) * I + 1 >>> 0, d = new Uint8Array(c); i !== h; ) {
for (var O = n[i], b = 0, p = c - 1; (O !== 0 || b < f) && p !== -1; p--, b++)
O += 256 * d[p] >>> 0, d[p] = O % g >>> 0, O = O / g >>> 0;
2024-05-25 23:24:11 +08:00
if (O !== 0)
2024-04-04 11:47:06 +08:00
throw new Error("Non-zero carry");
2024-07-23 11:16:38 +08:00
f = b, i++;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
for (var a = c - f; a !== c && d[a] === 0; )
2024-06-12 10:22:16 +08:00
a++;
2024-07-23 11:16:38 +08:00
for (var w = N.repeat(o); a < c; ++a)
w += r.charAt(d[a]);
2024-05-25 23:24:11 +08:00
return w;
2024-04-04 11:47:06 +08:00
}
2024-05-25 23:24:11 +08:00
function U(n) {
if (typeof n != "string")
2024-04-04 11:47:06 +08:00
throw new TypeError("Expected String");
2024-05-25 23:24:11 +08:00
if (n.length === 0)
2024-04-04 11:47:06 +08:00
return new Uint8Array();
2024-07-23 11:16:38 +08:00
for (var o = 0, f = 0, i = 0; n[o] === N; )
f++, o++;
for (var h = (n.length - o) * B + 1 >>> 0, c = new Uint8Array(h); n[o]; ) {
var d = e[n.charCodeAt(o)];
2024-05-25 22:16:06 +08:00
if (d === 255)
2024-04-04 11:47:06 +08:00
return;
2024-07-23 11:16:38 +08:00
for (var O = 0, b = h - 1; (d !== 0 || O < i) && b !== -1; b--, O++)
d += g * c[b] >>> 0, c[b] = d % 256 >>> 0, d = d / 256 >>> 0;
2024-05-25 22:16:06 +08:00
if (d !== 0)
2024-04-04 11:47:06 +08:00
throw new Error("Non-zero carry");
2024-07-23 11:16:38 +08:00
i = O, o++;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
for (var p = h - i; p !== h && c[p] === 0; )
p++;
for (var a = new Uint8Array(f + (h - p)), w = f; p !== h; )
a[w++] = c[p++];
2024-06-12 10:22:16 +08:00
return a;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
function j(n) {
var o = U(n);
if (o)
return o;
2024-05-25 23:24:11 +08:00
throw new Error("Non-base" + g + " character");
2024-04-04 11:47:06 +08:00
}
return {
2024-05-25 21:16:42 +08:00
encode: q,
2024-05-25 23:24:11 +08:00
decodeUnsafe: U,
2024-07-23 11:16:38 +08:00
decode: j
2024-04-04 11:47:06 +08:00
};
}
2024-06-12 10:22:16 +08:00
var fe = ae;
2024-07-23 11:16:38 +08:00
const he = /* @__PURE__ */ re(fe);
var te = {};
(function(r) {
2024-04-04 11:47:06 +08:00
(function(e) {
e([], function() {
2024-07-23 11:16:38 +08:00
var t = -1, s = -2, l = -3, v = -4, g = -5, N = function(o, f) {
2024-05-25 23:24:11 +08:00
f = f || {};
2024-07-23 11:16:38 +08:00
var i = f.verbose || !1;
i && console.log("Normalize the JSON Object"), o = typeof o == "string" ? this.JSON.parse(o) : o, i && console.log("Creating a empty dictionary");
2024-05-25 23:24:11 +08:00
var h = {
2024-04-04 11:47:06 +08:00
strings: [],
integers: [],
floats: []
};
2024-07-23 11:16:38 +08:00
i && console.log("Creating the AST");
var c = function p(a) {
i && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(a));
2024-06-12 10:22:16 +08:00
var w = typeof a;
if (a === null)
2024-04-04 11:47:06 +08:00
return {
type: "null",
2024-07-23 11:16:38 +08:00
index: l
2024-04-04 11:47:06 +08:00
};
2024-06-12 10:22:16 +08:00
if (typeof a > "u")
2024-04-04 11:47:06 +08:00
return {
type: "undefined",
2024-05-25 23:24:11 +08:00
index: g
2024-04-04 11:47:06 +08:00
};
2024-06-12 10:22:16 +08:00
if (a instanceof Array) {
2024-05-25 23:24:11 +08:00
var S = ["@"];
2024-06-12 10:22:16 +08:00
for (var E in a)
2024-07-23 11:16:38 +08:00
a.hasOwnProperty(E) && S.push(p(a[E]));
2024-05-25 23:24:11 +08:00
return S;
2024-04-04 11:47:06 +08:00
}
2024-05-25 23:24:11 +08:00
if (w === "object") {
var S = ["$"];
2024-06-12 10:22:16 +08:00
for (var x in a)
2024-07-23 11:16:38 +08:00
a.hasOwnProperty(x) && (S.push(p(x)), S.push(p(a[x])));
2024-05-25 23:24:11 +08:00
return S;
2024-04-04 11:47:06 +08:00
}
2024-06-12 10:22:16 +08:00
if (a === "")
2024-04-04 11:47:06 +08:00
return {
type: "empty",
2024-07-23 11:16:38 +08:00
index: v
2024-04-04 11:47:06 +08:00
};
2024-05-25 23:24:11 +08:00
if (w === "string") {
2024-07-23 11:16:38 +08:00
var T = n.call(h.strings, a);
return T == -1 && (h.strings.push(I(a)), T = h.strings.length - 1), {
2024-04-04 11:47:06 +08:00
type: "strings",
2024-07-23 11:16:38 +08:00
index: T
2024-04-04 11:47:06 +08:00
};
}
2024-06-12 10:22:16 +08:00
if (w === "number" && a % 1 === 0) {
2024-07-23 11:16:38 +08:00
var T = n.call(h.integers, a);
return T == -1 && (h.integers.push(U(a)), T = h.integers.length - 1), {
2024-04-04 11:47:06 +08:00
type: "integers",
2024-07-23 11:16:38 +08:00
index: T
2024-04-04 11:47:06 +08:00
};
}
2024-05-25 23:24:11 +08:00
if (w === "number") {
2024-07-23 11:16:38 +08:00
var T = n.call(h.floats, a);
return T == -1 && (h.floats.push(a), T = h.floats.length - 1), {
2024-04-04 11:47:06 +08:00
type: "floats",
2024-07-23 11:16:38 +08:00
index: T
2024-04-04 11:47:06 +08:00
};
}
2024-05-25 23:24:11 +08:00
if (w === "boolean")
2024-04-04 11:47:06 +08:00
return {
type: "boolean",
2024-07-23 11:16:38 +08:00
index: a ? t : s
2024-04-04 11:47:06 +08:00
};
2024-06-12 10:22:16 +08:00
throw new Error("Unexpected argument of type " + typeof a);
2024-07-23 11:16:38 +08:00
}(o), d = h.strings.length, O = h.integers.length;
h.floats.length, i && console.log("Parsing the dictionary");
2024-05-25 23:24:11 +08:00
var b = h.strings.join("|");
2024-07-23 11:16:38 +08:00
return b += "^" + h.integers.join("|"), b += "^" + h.floats.join("|"), i && console.log("Parsing the structure"), b += "^" + function p(a) {
if (i && console.log("Calling a recursiveParser with " + this.JSON.stringify(a)), a instanceof Array) {
2024-06-12 10:22:16 +08:00
var w = a.shift();
for (var S in a)
2024-07-23 11:16:38 +08:00
a.hasOwnProperty(S) && (w += p(a[S]) + "|");
2024-05-25 23:24:11 +08:00
return (w[w.length - 1] === "|" ? w.slice(0, -1) : w) + "]";
2024-04-04 11:47:06 +08:00
}
2024-06-12 10:22:16 +08:00
var E = a.type, x = a.index;
2024-05-25 23:24:11 +08:00
if (E === "strings")
return U(x);
if (E === "integers")
return U(d + x);
if (E === "floats")
return U(d + O + x);
if (E === "boolean")
2024-06-12 10:22:16 +08:00
return a.index;
2024-05-25 23:24:11 +08:00
if (E === "null")
2024-07-23 11:16:38 +08:00
return l;
2024-05-25 23:24:11 +08:00
if (E === "undefined")
return g;
if (E === "empty")
2024-07-23 11:16:38 +08:00
return v;
2024-04-04 11:47:06 +08:00
throw new TypeError("The item is alien!");
2024-07-23 11:16:38 +08:00
}(c), i && console.log("Ending parser"), f.debug ? {
2024-05-25 23:24:11 +08:00
dictionary: h,
2024-07-23 11:16:38 +08:00
ast: c,
2024-05-25 23:24:11 +08:00
packed: b
} : b;
2024-07-23 11:16:38 +08:00
}, B = function(o, f) {
2024-05-25 23:24:11 +08:00
f = f || {};
2024-07-23 11:16:38 +08:00
var i = o.split("^");
2024-05-25 23:24:11 +08:00
f.verbose && console.log("Building dictionary");
2024-07-23 11:16:38 +08:00
var h = [], c = i[0];
if (c !== "") {
c = c.split("|"), f.verbose && console.log("Parse the strings dictionary");
for (var d = 0, O = c.length; d < O; d++)
h.push(q(c[d]));
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
if (c = i[1], c !== "") {
c = c.split("|"), f.verbose && console.log("Parse the integers dictionary");
for (var d = 0, O = c.length; d < O; d++)
h.push(j(c[d]));
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
if (c = i[2], c !== "") {
c = c.split("|"), f.verbose && console.log("Parse the floats dictionary");
for (var d = 0, O = c.length; d < O; d++)
h.push(parseFloat(c[d]));
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
c = null, f.verbose && console.log("Tokenizing the structure");
for (var b = "", p = [], a = i[3].length, d = 0; d < a; d++) {
var w = i[3].charAt(d);
w === "|" || w === "$" || w === "@" || w === "]" ? (b && (p.push(j(b)), b = ""), w !== "|" && p.push(w)) : b += w;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
var S = p.length, E = 0;
2024-05-25 23:24:11 +08:00
return f.verbose && console.log("Starting recursive parser"), function x() {
2024-07-23 11:16:38 +08:00
var T = p[E++];
if (f.verbose && console.log("Reading collection type " + (T === "$" ? "object" : "Array")), T === "@") {
2024-05-25 23:24:11 +08:00
for (var y = []; E < S; E++) {
2024-07-23 11:16:38 +08:00
var C = p[E];
2024-05-25 23:24:11 +08:00
if (f.verbose && console.log("Read " + C + " symbol"), C === "]")
return y;
if (C === "@" || C === "$")
y.push(x());
2024-04-04 11:47:06 +08:00
else
2024-05-25 23:24:11 +08:00
switch (C) {
2024-07-23 11:16:38 +08:00
case t:
2024-05-25 23:24:11 +08:00
y.push(!0);
2024-04-04 11:47:06 +08:00
break;
2024-07-23 11:16:38 +08:00
case s:
2024-05-25 23:24:11 +08:00
y.push(!1);
2024-04-04 11:47:06 +08:00
break;
2024-07-23 11:16:38 +08:00
case l:
2024-05-25 23:24:11 +08:00
y.push(null);
2024-04-04 11:47:06 +08:00
break;
2024-05-25 23:24:11 +08:00
case g:
y.push(void 0);
break;
2024-07-23 11:16:38 +08:00
case v:
2024-05-25 23:24:11 +08:00
y.push("");
2024-04-04 11:47:06 +08:00
break;
default:
2024-05-25 23:24:11 +08:00
y.push(h[C]);
2024-04-04 11:47:06 +08:00
}
}
2024-05-25 23:24:11 +08:00
return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
if (T === "$") {
2024-05-25 23:24:11 +08:00
for (var y = {}; E < S; E++) {
2024-07-23 11:16:38 +08:00
var _ = p[E];
2024-05-25 23:24:11 +08:00
if (_ === "]")
return y;
2024-07-23 11:16:38 +08:00
_ === v ? _ = "" : _ = h[_];
var C = p[++E];
2024-05-25 23:24:11 +08:00
if (C === "@" || C === "$")
y[_] = x();
2024-04-04 11:47:06 +08:00
else
2024-05-25 23:24:11 +08:00
switch (C) {
2024-07-23 11:16:38 +08:00
case t:
2024-05-25 23:24:11 +08:00
y[_] = !0;
2024-04-04 11:47:06 +08:00
break;
2024-07-23 11:16:38 +08:00
case s:
2024-05-25 23:24:11 +08:00
y[_] = !1;
2024-04-04 11:47:06 +08:00
break;
2024-07-23 11:16:38 +08:00
case l:
2024-05-25 23:24:11 +08:00
y[_] = null;
break;
case g:
y[_] = void 0;
2024-05-25 21:16:42 +08:00
break;
2024-07-23 11:16:38 +08:00
case v:
2024-05-25 23:24:11 +08:00
y[_] = "";
2024-04-04 11:47:06 +08:00
break;
default:
2024-05-25 23:24:11 +08:00
y[_] = h[C];
2024-04-04 11:47:06 +08:00
}
}
2024-05-25 23:24:11 +08:00
return f.verbose && console.log("Parsed " + this.JSON.stringify(y)), y;
2024-04-04 11:47:06 +08:00
}
2024-07-23 11:16:38 +08:00
throw new TypeError("Bad token " + T + " isn't a type");
2024-04-04 11:47:06 +08:00
}();
2024-07-23 11:16:38 +08:00
}, I = function(o) {
return typeof o != "string" ? o : o.replace(/[\+ \|\^\%]/g, function(f) {
2024-04-04 11:47:06 +08:00
return {
" ": "+",
"+": "%2B",
"|": "%7C",
"^": "%5E",
"%": "%25"
2024-05-25 23:24:11 +08:00
}[f];
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
}, q = function(o) {
return typeof o != "string" ? o : o.replace(/\+|%2B|%7C|%5E|%25/g, function(f) {
2024-04-04 11:47:06 +08:00
return {
"+": " ",
"%2B": "+",
"%7C": "|",
"%5E": "^",
"%25": "%"
2024-05-25 23:24:11 +08:00
}[f];
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
}, U = function(o) {
return Number.prototype.toString.call(o, 36).toUpperCase();
}, j = function(o) {
return parseInt(o, 36);
}, n = Array.prototype.indexOf || function(o, f) {
for (var i = f || 0, h = this.length; i < h; i++)
if (this[i] === o)
return i;
2024-04-04 11:47:06 +08:00
return -1;
};
return {
JSON,
2024-05-25 23:24:11 +08:00
pack: N,
2024-04-04 11:47:06 +08:00
unpack: B
};
});
2024-07-23 11:16:38 +08:00
})(function(e, t) {
var s = t();
for (var l in s)
r[l] = s[l];
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
})(te);
const ee = /* @__PURE__ */ re(te);
var J, z, D, $, L, H, K, V, Y;
2024-05-12 01:15:30 +08:00
class X {
2024-07-23 11:16:38 +08:00
constructor(e, t, s, l, v) {
P(this, "code", 0);
P(this, "message", "操作成功");
P(this, "data", null);
P(this, "url", "");
P(this, "res", "");
2024-04-04 11:47:06 +08:00
// static [Symbol.hasInstance](self) { return self?.IS_ECHO_MSG !== undefined }
2024-07-23 11:16:38 +08:00
A(this, J, null);
2024-04-04 11:47:06 +08:00
// 判断返回 Response 对象, 还是 Response 中的 data
2024-07-23 11:16:38 +08:00
A(this, z, !0);
2024-04-04 11:47:06 +08:00
// 判罚是否已经给出错误提示
2024-07-23 11:16:38 +08:00
A(this, D, !0);
A(this, $, {
get: (e, t) => u(this, L).call(this, t),
ownKeys: () => Object.keys(u(this, $).getPrototypeOf() || {}),
getPrototypeOf: () => u(this, z) ? this : this.data,
2024-04-04 11:47:06 +08:00
getOwnPropertyDescriptor: () => ({
configurable: !0,
enumerable: !0,
writable: !0,
2024-07-23 11:16:38 +08:00
value: u(this, $).getPrototypeOf()
2024-04-04 11:47:06 +08:00
})
});
2024-07-23 11:16:38 +08:00
A(this, L, (e) => e === "$echoMsg" ? u(this, K) : e === "msg" ? u(this, H) : e === "then" || e === "resp" ? (M(this, D, !0), M(this, z, e === "resp"), u(this, V)) : e === "catch" ? u(this, Y) : e === "IS_ECHO_MSG" ? u(this, D) : Reflect.get(this, e));
A(this, H, (e = (s) => s, t = !1) => (u(this, K).call(this), M(this, z, t), Promise.resolve(e == null ? void 0 : e(u(this, $).getPrototypeOf()))));
A(this, K, () => {
u(this, D) && (M(this, D, !1), we.onMsg(this.code, this.message));
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
A(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(u(this, $).getPrototypeOf())) : Promise.reject(u(this, J)));
A(this, Y, (e) => Promise.resolve(e(u(this, J))));
return this.code = e, this.message = t, this.data = s, this.url = l, this.res = v, M(this, J, new Proxy(this, u(this, $)));
2024-04-04 11:47:06 +08:00
}
}
2024-07-23 11:16:38 +08:00
J = new WeakMap(), z = new WeakMap(), D = new WeakMap(), $ = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap();
const W = (r, e, t, s = "/", l = "") => new X(r, e, t, s, l);
2024-04-04 11:47:06 +08:00
var ne = [
"utf8",
"utf-8",
"unicode-1-1-utf-8"
];
2024-07-23 11:16:38 +08:00
function le(r) {
if (ne.indexOf(r) < 0 && typeof r < "u" && r != null)
2024-04-04 11:47:06 +08:00
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");
2024-07-23 11:16:38 +08:00
var t = unescape(encodeURIComponent(e)), s = new Uint8Array(t.length);
const l = t.split("");
for (let v = 0; v < l.length; v++)
s[v] = l[v].charCodeAt(0);
return s;
2024-04-04 11:47:06 +08:00
};
}
2024-07-23 11:16:38 +08:00
function ue(r) {
if (ne.indexOf(r) < 0 && typeof r < "u" && r != null)
2024-04-04 11:47:06 +08:00
throw new RangeError("Invalid encoding type. Only utf-8 is supported");
2024-07-23 11:16:38 +08:00
this.encoding = "utf-8", this.decode = function(e, t) {
2024-04-04 11:47:06 +08:00
if (typeof e > "u")
return "";
2024-07-23 11:16:38 +08:00
var s = typeof t < "u" && s in t ? t.stream : !1;
if (typeof s != "boolean")
2024-04-04 11:47:06 +08:00
throw new TypeError("stream option must be boolean");
if (ArrayBuffer.isView(e)) {
2024-07-23 11:16:38 +08:00
var l = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), v = new Array(l.length);
for (let g = 0; g < l.length; g++)
v[g] = String.fromCharCode(l[g]);
return decodeURIComponent(escape(v.join("")));
2024-04-04 11:47:06 +08:00
} else
throw new TypeError("passed argument must be an array buffer view");
};
}
var se = {
TextEncoder: le,
TextDecoder: ue
};
2024-07-23 11:16:38 +08:00
const ce = new se.TextEncoder("utf8"), ge = new se.TextDecoder("utf8"), de = (r) => {
2024-04-04 11:47:06 +08:00
let e = 5381;
2024-07-23 11:16:38 +08:00
for (let t = 0; t < r.length; t++)
e = e * 33 ^ r.charCodeAt(t);
2024-04-04 11:47:06 +08:00
return (e >>> 0).toString(16);
2024-07-23 11:16:38 +08:00
}, be = (r, e) => r.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), ve = (r) => ce.encode(r || ""), pe = (r) => ge.decode(new DataView(r), {});
Promise.withResolvers || (Promise.withResolvers = function() {
let r, e;
return { promise: new Promise((s, l) => {
r = s, e = l;
}), resolve: r, reject: e };
});
var F, G, Q, m, R;
2024-05-12 01:15:30 +08:00
class Z {
2024-07-23 11:16:38 +08:00
constructor(e, t, s = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) {
A(this, F, void 0);
A(this, G, void 0);
A(this, Q, void 0);
A(this, m, {
2024-04-04 11:47:06 +08:00
"#": /* @__PURE__ */ new Map(),
// 系统缓存
$: /* @__PURE__ */ new Map()
// 普通缓存
});
2024-07-23 11:16:38 +08:00
A(this, R, /* @__PURE__ */ new Map());
P(this, "request", ({ url: e = "/", method: t = "GET", ...s }, l = !1) => {
var U, j;
const v = t.toUpperCase(), g = de(JSON.stringify([e, v, s])), N = (U = e == null ? void 0 : e.includes) != null && U.call(e, "/_/") ? "#" : "$", { promise: B, resolve: I, reject: q } = Promise.withResolvers();
return u(this, m)[N].has(g) ? (console.log("缓存命中", e), I(u(this, m)[N].get(g))) : (u(this, R).has(g) ? u(this, R).get(g).push([I, q]) : u(this, R).set(g, [[I, q]]), (j = u(this, R).get(g)) != null && j.some((n) => n) && u(this, F).call(this, { url: e, method: v, ...s }).then((n) => {
2024-05-25 23:24:11 +08:00
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];
2024-07-23 11:16:38 +08:00
}).then((n) => ((N == "#" || l && v === "GET") && u(this, m)[N].set(g, n), n)).then((n) => {
var o;
return (o = u(this, R).get(g)) == null ? void 0 : o.forEach((f, i, h) => {
f && f[0](n), delete h[i];
2024-05-28 11:41:59 +08:00
});
}).catch((n) => {
2024-07-23 11:16:38 +08:00
var o;
u(this, m)[N].delete(g), (o = u(this, R).get(g)) == null || o.forEach((f, i, h) => {
f && f[1](n instanceof X ? n : W(-1, n, null, e)), delete h[i];
2024-05-25 22:42:00 +08:00
});
2024-07-23 11:16:38 +08:00
}).finally(() => u(this, R).delete(g))), new Proxy(B, {
get: (n, o) => (...f) => n.then((i) => W(...i)[o](...f)).catch((i) => {
if (!i instanceof X)
throw i;
return typeof i[o] == "function" ? i[o](...f) : i[o];
2024-04-04 11:47:06 +08:00
})
});
});
2024-07-23 11:16:38 +08:00
P(this, "get", (e, t = {}) => this.request({ url: e, method: "GET", params: t }));
P(this, "post", (e, t = {}, s = {}) => this.request({ url: e, method: "POST", data: t, params: s }));
P(this, "put", (e, t = {}, s = {}) => this.request({ url: e, method: "PUT", data: t, params: s }));
P(this, "del", (e, t = {}, s = {}) => this.request({ url: e, method: "DELETE", data: t, params: s }));
P(this, "download", (e, t) => {
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
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", () => {
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
P(this, "refreshCache", (e = !1) => {
e && u(this, m)["#"].clear(), u(this, m).$.clear();
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
P(this, "decode", (e = "", t = {}) => {
2024-04-04 11:47:06 +08:00
if (e === void 0 || e === "" || e === null)
2024-07-23 11:16:38 +08:00
return t;
2024-04-04 11:47:06 +08:00
try {
2024-07-23 11:16:38 +08:00
const s = u(this, G).decode(e).buffer;
return ee.unpack(pe(s));
2024-04-04 11:47:06 +08:00
} catch {
2024-07-23 11:16:38 +08:00
return console.warn("core.decode", e), t;
2024-04-04 11:47:06 +08:00
}
});
2024-07-23 11:16:38 +08:00
P(this, "encode", (e = {}) => {
const t = JSON.stringify(e, (s, l) => l === void 0 ? null : l);
return u(this, G).encode(ve(ee.pack(t)));
2024-04-04 11:47:06 +08:00
});
2024-07-23 11:16:38 +08:00
M(this, Q, e), M(this, F, s), M(this, G, he(t));
2024-04-04 11:47:06 +08:00
}
}
2024-07-23 11:16:38 +08:00
F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), m = new WeakMap(), R = new WeakMap();
2024-05-12 01:15:30 +08:00
const we = Z;
2024-07-23 11:16:38 +08:00
Z.onUnhandledRejection = (r) => {
var e, t, s, l, v, g;
r != null && r.IS_ECHO_MSG ? ((e = r == null ? void 0 : r.$echoMsg) == null || e.call(r), (t = r == null ? void 0 : r.preventDefault) == null || t.call(r)) : (s = r.reason) != null && s.IS_ECHO_MSG && ((v = (l = r.reason) == null ? void 0 : l.$echoMsg) == null || v.call(l), (g = r == null ? void 0 : r.preventDefault) == null || g.call(r));
2024-04-04 11:47:06 +08:00
};
2024-07-23 11:16:38 +08:00
Z.onMsg = (r, e) => [0, 1].includes(r) ? console.log(e) : console.warn(e);
2024-04-04 11:47:06 +08:00
export {
we as default,
de as signature,
2024-07-23 11:16:38 +08:00
ve as str2uint8array,
2024-04-04 11:47:06 +08:00
be as trim,
2024-07-23 11:16:38 +08:00
pe as uint8array2str
2024-04-04 11:47:06 +08:00
};