ff-request-dist/dist/ff-request.js
2025-11-03 20:30:44 +08:00

506 lines
19 KiB
JavaScript

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