493 lines
18 KiB
JavaScript
493 lines
18 KiB
JavaScript
var ce = Object.defineProperty;
|
|
var le = (r, e, t) => e in r ? ce(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
var v = (r, e, t) => (le(r, typeof e != "symbol" ? e + "" : e, t), t), re = (r, e, t) => {
|
|
if (!e.has(r))
|
|
throw TypeError("Cannot " + t);
|
|
};
|
|
var o = (r, e, t) => (re(r, e, "read from private field"), t ? t.call(r) : e.get(r)), E = (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);
|
|
}, C = (r, e, t, n) => (re(r, e, "write to private field"), n ? n.call(r, t) : e.set(r, t), t);
|
|
function he(r) {
|
|
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
}
|
|
var oe = {};
|
|
(function(r) {
|
|
(function(e) {
|
|
e([], function() {
|
|
var t = -1, n = -2, s = -3, f = -4, h = -5, $ = function(a, c) {
|
|
c = c || {};
|
|
var l = c.verbose || !1;
|
|
l && console.log("Normalize the JSON Object"), a = typeof a == "string" ? this.JSON.parse(a) : a, l && console.log("Creating a empty dictionary");
|
|
var d = {
|
|
strings: [],
|
|
integers: [],
|
|
floats: []
|
|
};
|
|
l && console.log("Creating the AST");
|
|
var g = function T(i) {
|
|
l && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(i));
|
|
var w = typeof i;
|
|
if (i === null)
|
|
return {
|
|
type: "null",
|
|
index: s
|
|
};
|
|
if (typeof i > "u")
|
|
return {
|
|
type: "undefined",
|
|
index: h
|
|
};
|
|
if (i instanceof Array) {
|
|
var P = ["@"];
|
|
for (var y in i)
|
|
i.hasOwnProperty(y) && P.push(T(i[y]));
|
|
return P;
|
|
}
|
|
if (w === "object") {
|
|
var P = ["$"];
|
|
for (var M in i)
|
|
i.hasOwnProperty(M) && (P.push(T(M)), P.push(T(i[M])));
|
|
return P;
|
|
}
|
|
if (i === "")
|
|
return {
|
|
type: "empty",
|
|
index: f
|
|
};
|
|
if (w === "string") {
|
|
var O = u.call(d.strings, i);
|
|
return O == -1 && (d.strings.push(q(i)), O = d.strings.length - 1), {
|
|
type: "strings",
|
|
index: O
|
|
};
|
|
}
|
|
if (w === "number" && i % 1 === 0) {
|
|
var O = u.call(d.integers, i);
|
|
return O == -1 && (d.integers.push(U(i)), O = d.integers.length - 1), {
|
|
type: "integers",
|
|
index: O
|
|
};
|
|
}
|
|
if (w === "number") {
|
|
var O = u.call(d.floats, i);
|
|
return O == -1 && (d.floats.push(i), O = d.floats.length - 1), {
|
|
type: "floats",
|
|
index: O
|
|
};
|
|
}
|
|
if (w === "boolean")
|
|
return {
|
|
type: "boolean",
|
|
index: i ? t : n
|
|
};
|
|
throw new Error("Unexpected argument of type " + typeof i);
|
|
}(a), b = d.strings.length, F = d.integers.length;
|
|
d.floats.length, l && console.log("Parsing the dictionary");
|
|
var A = d.strings.join("|");
|
|
return A += "^" + d.integers.join("|"), A += "^" + d.floats.join("|"), l && console.log("Parsing the structure"), A += "^" + function T(i) {
|
|
if (l && console.log("Calling a recursiveParser with " + this.JSON.stringify(i)), i instanceof Array) {
|
|
var w = i.shift();
|
|
for (var P in i)
|
|
i.hasOwnProperty(P) && (w += T(i[P]) + "|");
|
|
return (w[w.length - 1] === "|" ? w.slice(0, -1) : w) + "]";
|
|
}
|
|
var y = i.type, M = i.index;
|
|
if (y === "strings")
|
|
return U(M);
|
|
if (y === "integers")
|
|
return U(b + M);
|
|
if (y === "floats")
|
|
return U(b + F + M);
|
|
if (y === "boolean")
|
|
return i.index;
|
|
if (y === "null")
|
|
return s;
|
|
if (y === "undefined")
|
|
return h;
|
|
if (y === "empty")
|
|
return f;
|
|
throw new TypeError("The item is alien!");
|
|
}(g), l && console.log("Ending parser"), c.debug ? {
|
|
dictionary: d,
|
|
ast: g,
|
|
packed: A
|
|
} : A;
|
|
}, _ = function(a, c) {
|
|
c = c || {};
|
|
var l = a.split("^");
|
|
c.verbose && console.log("Building dictionary");
|
|
var d = [], g = l[0];
|
|
if (g !== "") {
|
|
g = g.split("|"), c.verbose && console.log("Parse the strings dictionary");
|
|
for (var b = 0, F = g.length; b < F; b++)
|
|
d.push(z(g[b]));
|
|
}
|
|
if (g = l[1], g !== "") {
|
|
g = g.split("|"), c.verbose && console.log("Parse the integers dictionary");
|
|
for (var b = 0, F = g.length; b < F; b++)
|
|
d.push(J(g[b]));
|
|
}
|
|
if (g = l[2], g !== "") {
|
|
g = g.split("|"), c.verbose && console.log("Parse the floats dictionary");
|
|
for (var b = 0, F = g.length; b < F; b++)
|
|
d.push(parseFloat(g[b]));
|
|
}
|
|
g = null, c.verbose && console.log("Tokenizing the structure");
|
|
for (var A = "", T = [], i = l[3].length, b = 0; b < i; b++) {
|
|
var w = l[3].charAt(b);
|
|
w === "|" || w === "$" || w === "@" || w === "]" ? (A && (T.push(J(A)), A = ""), w !== "|" && T.push(w)) : A += w;
|
|
}
|
|
var P = T.length, y = 0;
|
|
return c.verbose && console.log("Starting recursive parser"), function M() {
|
|
var O = T[y++];
|
|
if (c.verbose && console.log("Reading collection type " + (O === "$" ? "object" : "Array")), O === "@") {
|
|
for (var p = []; y < P; y++) {
|
|
var S = T[y];
|
|
if (c.verbose && console.log("Read " + S + " symbol"), S === "]")
|
|
return p;
|
|
if (S === "@" || S === "$")
|
|
p.push(M());
|
|
else
|
|
switch (S) {
|
|
case t:
|
|
p.push(!0);
|
|
break;
|
|
case n:
|
|
p.push(!1);
|
|
break;
|
|
case s:
|
|
p.push(null);
|
|
break;
|
|
case h:
|
|
p.push(void 0);
|
|
break;
|
|
case f:
|
|
p.push("");
|
|
break;
|
|
default:
|
|
p.push(d[S]);
|
|
}
|
|
}
|
|
return c.verbose && console.log("Parsed " + this.JSON.stringify(p)), p;
|
|
}
|
|
if (O === "$") {
|
|
for (var p = {}; y < P; y++) {
|
|
var x = T[y];
|
|
if (x === "]")
|
|
return p;
|
|
x === f ? x = "" : x = d[x];
|
|
var S = T[++y];
|
|
if (S === "@" || S === "$")
|
|
p[x] = M();
|
|
else
|
|
switch (S) {
|
|
case t:
|
|
p[x] = !0;
|
|
break;
|
|
case n:
|
|
p[x] = !1;
|
|
break;
|
|
case s:
|
|
p[x] = null;
|
|
break;
|
|
case h:
|
|
p[x] = void 0;
|
|
break;
|
|
case f:
|
|
p[x] = "";
|
|
break;
|
|
default:
|
|
p[x] = d[S];
|
|
}
|
|
}
|
|
return c.verbose && console.log("Parsed " + this.JSON.stringify(p)), p;
|
|
}
|
|
throw new TypeError("Bad token " + O + " isn't a type");
|
|
}();
|
|
}, q = function(a) {
|
|
return typeof a != "string" ? a : a.replace(/[\+ \|\^\%]/g, function(c) {
|
|
return {
|
|
" ": "+",
|
|
"+": "%2B",
|
|
"|": "%7C",
|
|
"^": "%5E",
|
|
"%": "%25"
|
|
}[c];
|
|
});
|
|
}, z = function(a) {
|
|
return typeof a != "string" ? a : a.replace(/\+|%2B|%7C|%5E|%25/g, function(c) {
|
|
return {
|
|
"+": " ",
|
|
"%2B": "+",
|
|
"%7C": "|",
|
|
"%5E": "^",
|
|
"%25": "%"
|
|
}[c];
|
|
});
|
|
}, U = function(a) {
|
|
return Number.prototype.toString.call(a, 36).toUpperCase();
|
|
}, J = function(a) {
|
|
return parseInt(a, 36);
|
|
}, u = Array.prototype.indexOf || function(a, c) {
|
|
for (var l = c || 0, d = this.length; l < d; l++)
|
|
if (this[l] === a)
|
|
return l;
|
|
return -1;
|
|
};
|
|
return {
|
|
JSON,
|
|
pack: $,
|
|
unpack: _
|
|
};
|
|
});
|
|
})(function(e, t) {
|
|
var n = t();
|
|
for (var s in n)
|
|
r[s] = n[s];
|
|
});
|
|
})(oe);
|
|
const ne = /* @__PURE__ */ he(oe);
|
|
var D, j, I, R, Y, Q, K, W, X;
|
|
class ee {
|
|
constructor(e, t, n, s, f) {
|
|
v(this, "code", 0);
|
|
v(this, "message", "操作成功");
|
|
v(this, "data", null);
|
|
v(this, "url", "");
|
|
v(this, "res", "");
|
|
// static [Symbol.hasInstance](self) { return self?.IS_ECHO_MSG !== undefined }
|
|
E(this, D, null);
|
|
// 判断返回 Response 对象, 还是 Response 中的 data
|
|
E(this, j, !0);
|
|
// 判罚是否已经给出错误提示
|
|
E(this, I, !0);
|
|
E(this, R, {
|
|
get: (e, t) => o(this, Y).call(this, t),
|
|
ownKeys: () => Object.keys(o(this, R).getPrototypeOf() || {}),
|
|
getPrototypeOf: () => o(this, j) ? this : this.data,
|
|
getOwnPropertyDescriptor: () => ({
|
|
configurable: !0,
|
|
enumerable: !0,
|
|
writable: !0,
|
|
value: o(this, R).getPrototypeOf()
|
|
})
|
|
});
|
|
E(this, Y, (e) => e === "$echoMsg" ? o(this, K) : e === "msg" ? o(this, Q) : e === "then" || e === "resp" ? (C(this, I, !0), C(this, j, e === "resp"), o(this, W)) : e === "catch" ? o(this, X) : e === "IS_ECHO_MSG" ? o(this, I) : Reflect.get(this, e));
|
|
E(this, Q, (e = (n) => n, t = !1) => (o(this, K).call(this), C(this, j, t), Promise.resolve(e == null ? void 0 : e(o(this, R).getPrototypeOf()))));
|
|
E(this, K, () => {
|
|
o(this, I) && (C(this, I, !1), Te.onMsg(this.code, this.message));
|
|
});
|
|
E(this, W, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(o(this, R).getPrototypeOf())) : Promise.reject(o(this, D)));
|
|
E(this, X, (e) => Promise.resolve(e(o(this, D))));
|
|
return this.code = e, this.message = t, this.data = n, this.url = s, this.res = f, C(this, D, new Proxy(this, o(this, R)));
|
|
}
|
|
}
|
|
D = new WeakMap(), j = new WeakMap(), I = new WeakMap(), R = new WeakMap(), Y = new WeakMap(), Q = new WeakMap(), K = new WeakMap(), W = new WeakMap(), X = new WeakMap();
|
|
const k = (r, e, t, n = "/", s = "") => new ee(r, e, t, n, s);
|
|
var ie = [
|
|
"utf8",
|
|
"utf-8",
|
|
"unicode-1-1-utf-8"
|
|
];
|
|
function ue(r) {
|
|
if (ie.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 f = 0; f < s.length; f++)
|
|
n[f] = s[f].charCodeAt(0);
|
|
return n;
|
|
};
|
|
}
|
|
function fe(r) {
|
|
if (ie.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")
|
|
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), f = new Array(s.length);
|
|
for (let h = 0; h < s.length; h++)
|
|
f[h] = String.fromCharCode(s[h]);
|
|
return decodeURIComponent(escape(f.join("")));
|
|
} else
|
|
throw new TypeError("passed argument must be an array buffer view");
|
|
};
|
|
}
|
|
var ae = {
|
|
TextEncoder: ue,
|
|
TextDecoder: fe
|
|
};
|
|
const de = new ae.TextEncoder("utf8"), ge = new ae.TextDecoder("utf8"), pe = (r) => {
|
|
let e = 5381;
|
|
for (let t = 0; t < r.length; t++)
|
|
e = e * 33 ^ r.charCodeAt(t);
|
|
return (e >>> 0).toString(16);
|
|
}, xe = (r, e) => r.replace(new RegExp(`^${e}+|${e}+$`, "g"), ""), ve = (r) => de.encode(r || ""), Se = (r) => ge.decode(new DataView(r), {}), we = 62, V = 30, se = 31, ye = 63;
|
|
class be {
|
|
constructor(e) {
|
|
v(this, "encodeTable", []);
|
|
v(this, "decodeMap", new Uint8Array(256).fill(255));
|
|
if (e.length !== we)
|
|
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 < e.length; t++)
|
|
this.decodeMap[e.charCodeAt(t)] = t;
|
|
}
|
|
// 编码方法
|
|
encode(e) {
|
|
if (!e || e.length === 0)
|
|
return [];
|
|
const t = new Ee(this).encodeV2(e);
|
|
return String.fromCharCode(...t);
|
|
}
|
|
// 解码方法
|
|
decode(e) {
|
|
if (!e || e.length === 0)
|
|
return new Uint8Array();
|
|
const t = new Oe(this).decode(e);
|
|
return new TextDecoder().decode(t);
|
|
}
|
|
}
|
|
var G;
|
|
class Ee {
|
|
constructor(e) {
|
|
E(this, G, null);
|
|
C(this, G, 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 & ye;
|
|
}
|
|
encodeV2(e) {
|
|
this.src = ve(e), this.pos = this.src.length * 8;
|
|
const t = [];
|
|
for (; this.pos > 0; ) {
|
|
let n = 6, s = this.get6bits();
|
|
(s & V) === V && ((this.pos > 6 || s > se) && (n = 5), s &= se), t.push(o(this, G).encodeTable[s].charCodeAt(0)), this.pos -= n;
|
|
}
|
|
return t;
|
|
}
|
|
}
|
|
G = new WeakMap();
|
|
var H;
|
|
class Oe {
|
|
constructor(e) {
|
|
E(this, H, null);
|
|
C(this, H, e);
|
|
}
|
|
decode(e) {
|
|
const t = new Uint8Array(Math.ceil(e.length * 6 / 8) + 1);
|
|
let n = t.length, s = 0, f = 0;
|
|
for (let h = 0; h < e.length; h++) {
|
|
const $ = e[h].charCodeAt(0), _ = o(this, H).decodeMap[$];
|
|
if (_ === 255)
|
|
throw new Error(`CorruptInputError at index ${h}`);
|
|
h === e.length - 1 ? (f |= _ << s, s += Math.ceil(Math.log2(_ + 1))) : (_ & V) === V ? (f |= _ << s, s += 5) : (f |= _ << s, s += 6), s >= 8 && (n--, t[n] = f & 255, s %= 8, f >>= 8);
|
|
}
|
|
return s > 0 && (n--, t[n] = f & 255), t.slice(n);
|
|
}
|
|
}
|
|
H = new WeakMap();
|
|
Promise.withResolvers || (Promise.withResolvers = function() {
|
|
let r, e;
|
|
return { promise: new Promise((n, s) => {
|
|
r = n, e = s;
|
|
}), resolve: r, reject: e };
|
|
});
|
|
var L, B, Z, m, N;
|
|
class te {
|
|
constructor(e, t, n = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) {
|
|
E(this, L, void 0);
|
|
E(this, B, void 0);
|
|
E(this, Z, void 0);
|
|
E(this, m, {
|
|
"#": /* @__PURE__ */ new Map(),
|
|
// 系统缓存
|
|
$: /* @__PURE__ */ new Map()
|
|
// 普通缓存
|
|
});
|
|
E(this, N, /* @__PURE__ */ new Map());
|
|
v(this, "request", ({ url: e = "/", method: t = "GET", ...n }, s = !1) => {
|
|
var U, J;
|
|
const f = t.toUpperCase(), h = pe(JSON.stringify([e, f, n])), $ = (U = e == null ? void 0 : e.includes) != null && U.call(e, "/_/") ? "#" : "$", { promise: _, resolve: q, reject: z } = Promise.withResolvers();
|
|
return o(this, m)[$].has(h) ? (console.log("缓存命中", e), q(o(this, m)[$].get(h))) : (o(this, N).has(h) ? o(this, N).get(h).push([q, z]) : o(this, N).set(h, [[q, z]]), (J = o(this, N).get(h)) != null && J.some((u) => u) && o(this, L).call(this, { url: e, method: f, ...n }).then((u) => {
|
|
if (![0, 1].includes(u.code))
|
|
throw k(u.code, u.msg, u.data, e, u == null ? void 0 : u.res);
|
|
return [u.code, u.msg, u.data, e, u == null ? void 0 : u.res];
|
|
}).then((u) => (($ == "#" || s && f === "GET") && o(this, m)[$].set(h, u), u)).then((u) => {
|
|
var a;
|
|
return (a = o(this, N).get(h)) == null ? void 0 : a.forEach((c, l, d) => {
|
|
c && c[0](u), delete d[l];
|
|
});
|
|
}).catch((u) => {
|
|
var a;
|
|
o(this, m)[$].delete(h), (a = o(this, N).get(h)) == null || a.forEach((c, l, d) => {
|
|
c && c[1](u instanceof ee ? u : k(-1, u, null, e)), delete d[l];
|
|
});
|
|
}).finally(() => o(this, N).delete(h))), new Proxy(_, {
|
|
get: (u, a) => (...c) => u.then((l) => k(...l)[a](...c)).catch((l) => {
|
|
if (!l instanceof ee)
|
|
throw l;
|
|
return typeof l[a] == "function" ? l[a](...c) : l[a];
|
|
})
|
|
});
|
|
});
|
|
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, m)["#"].clear(), o(this, m).$.clear();
|
|
});
|
|
v(this, "decode", (e = "", t = {}) => {
|
|
if (e === void 0 || e === "" || e === null)
|
|
return t;
|
|
try {
|
|
const n = o(this, B).decode(e);
|
|
return ne.unpack(n);
|
|
} catch {
|
|
return console.warn("core.decode", e), t;
|
|
}
|
|
});
|
|
v(this, "encode", (e = {}) => {
|
|
const t = JSON.stringify(e, (n, s) => s === void 0 ? null : s);
|
|
return o(this, B).encode(ne.pack(t));
|
|
});
|
|
C(this, Z, e), C(this, L, n), C(this, B, new be(t));
|
|
}
|
|
}
|
|
L = new WeakMap(), B = new WeakMap(), Z = new WeakMap(), m = new WeakMap(), N = new WeakMap();
|
|
const Te = te;
|
|
te.onUnhandledRejection = (r) => {
|
|
var e, t, n, s, f, 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 && ((f = (s = r.reason) == null ? void 0 : s.$echoMsg) == null || f.call(s), (h = r == null ? void 0 : r.preventDefault) == null || h.call(r));
|
|
};
|
|
te.onMsg = (r, e) => [0, 1].includes(r) ? console.log(e) : console.warn(e);
|
|
export {
|
|
Te as default,
|
|
pe as signature,
|
|
ve as str2uint8array,
|
|
xe as trim,
|
|
Se as uint8array2str
|
|
};
|