This commit is contained in:
what 2024-05-12 01:15:30 +08:00
parent 605fe39c40
commit 2ee9324e76
3 changed files with 80 additions and 80 deletions

156
dist/ff-request.js vendored
View File

@ -1,14 +1,14 @@
var ae = Object.defineProperty; var ae = Object.defineProperty;
var ie = (t, e, r) => e in t ? ae(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r; var ie = (t, e, r) => e in t ? ae(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
var A = (t, e, r) => (ie(t, typeof e != "symbol" ? e + "" : e, r), r), Z = (t, e, r) => { var A = (t, e, r) => (ie(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);
}; };
var f = (t, e, r) => (Z(t, e, "read from private field"), r ? r.call(t) : e.get(t)), S = (t, e, r) => { var f = (t, e, r) => (k(t, e, "read from private field"), r ? r.call(t) : e.get(t)), _ = (t, e, r) => {
if (e.has(t)) if (e.has(t))
throw TypeError("Cannot add the same private member more than once"); throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(t) : e.set(t, r); e instanceof WeakSet ? e.add(t) : e.set(t, r);
}, M = (t, e, r, n) => (Z(t, e, "write to private field"), n ? n.call(t, r) : e.set(t, r), r); }, M = (t, e, r, n) => (k(t, e, "write to private field"), n ? n.call(t, r) : e.set(t, r), r);
function te(t) { function te(t) {
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
} }
@ -24,15 +24,15 @@ function oe(t) {
e[v] = n; e[v] = n;
} }
var u = t.length, N = t.charAt(0), B = Math.log(u) / Math.log(256), j = Math.log(256) / Math.log(u); var u = t.length, N = t.charAt(0), B = Math.log(u) / Math.log(256), j = Math.log(256) / Math.log(u);
function m(i) { function m(a) {
if (i instanceof Uint8Array || (ArrayBuffer.isView(i) ? i = new Uint8Array(i.buffer, i.byteOffset, i.byteLength) : Array.isArray(i) && (i = Uint8Array.from(i))), !(i instanceof Uint8Array)) if (a instanceof Uint8Array || (ArrayBuffer.isView(a) ? a = new Uint8Array(a.buffer, a.byteOffset, a.byteLength) : Array.isArray(a) && (a = Uint8Array.from(a))), !(a instanceof Uint8Array))
throw new TypeError("Expected Uint8Array"); throw new TypeError("Expected Uint8Array");
if (i.length === 0) if (a.length === 0)
return ""; return "";
for (var a = 0, c = 0, g = 0, o = i.length; g !== o && i[g] === 0; ) for (var i = 0, c = 0, g = 0, o = a.length; g !== o && a[g] === 0; )
g++, a++; g++, i++;
for (var l = (o - g) * j + 1 >>> 0, d = new Uint8Array(l); g !== o; ) { for (var l = (o - g) * j + 1 >>> 0, d = new Uint8Array(l); g !== o; ) {
for (var T = i[g], E = 0, w = l - 1; (T !== 0 || E < c) && w !== -1; w--, E++) for (var T = a[g], E = 0, w = l - 1; (T !== 0 || E < c) && w !== -1; w--, E++)
T += 256 * d[w] >>> 0, d[w] = T % u >>> 0, T = T / u >>> 0; T += 256 * d[w] >>> 0, d[w] = T % u >>> 0, T = T / u >>> 0;
if (T !== 0) if (T !== 0)
throw new Error("Non-zero carry"); throw new Error("Non-zero carry");
@ -40,26 +40,26 @@ function oe(t) {
} }
for (var s = l - c; s !== l && d[s] === 0; ) for (var s = l - c; s !== l && d[s] === 0; )
s++; s++;
for (var y = N.repeat(a); s < l; ++s) for (var y = N.repeat(i); s < l; ++s)
y += t.charAt(d[s]); y += t.charAt(d[s]);
return y; return y;
} }
function _(i) { function S(a) {
if (typeof i != "string") if (typeof a != "string")
throw new TypeError("Expected String"); throw new TypeError("Expected String");
if (i.length === 0) if (a.length === 0)
return new Uint8Array(); return new Uint8Array();
for (var a = 0, c = 0, g = 0; i[a] === N; ) for (var i = 0, c = 0, g = 0; a[i] === N; )
c++, a++; c++, i++;
for (var o = (i.length - a) * B + 1 >>> 0, l = new Uint8Array(o); i[a]; ) { for (var o = (a.length - i) * B + 1 >>> 0, l = new Uint8Array(o); a[i]; ) {
var d = e[i.charCodeAt(a)]; var d = e[a.charCodeAt(i)];
if (d === 255) if (d === 255)
return; return;
for (var T = 0, E = o - 1; (d !== 0 || T < g) && E !== -1; E--, T++) for (var T = 0, E = o - 1; (d !== 0 || T < g) && E !== -1; E--, T++)
d += u * l[E] >>> 0, l[E] = d % 256 >>> 0, d = d / 256 >>> 0; d += u * l[E] >>> 0, l[E] = d % 256 >>> 0, d = d / 256 >>> 0;
if (d !== 0) if (d !== 0)
throw new Error("Non-zero carry"); throw new Error("Non-zero carry");
g = T, a++; g = T, i++;
} }
for (var w = o - g; w !== o && l[w] === 0; ) for (var w = o - g; w !== o && l[w] === 0; )
w++; w++;
@ -67,15 +67,15 @@ function oe(t) {
s[y++] = l[w++]; s[y++] = l[w++];
return s; return s;
} }
function p(i) { function p(a) {
var a = _(i); var i = S(a);
if (a) if (i)
return a; return i;
throw new Error("Non-base" + u + " character"); throw new Error("Non-base" + u + " character");
} }
return { return {
encode: m, encode: m,
decodeUnsafe: _, decodeUnsafe: S,
decode: p decode: p
}; };
} }
@ -85,10 +85,10 @@ var re = {};
(function(t) { (function(t) {
(function(e) { (function(e) {
e([], function() { e([], function() {
var r = -1, n = -2, h = -3, v = -4, u = -5, N = function(a, c) { var r = -1, n = -2, h = -3, v = -4, u = -5, N = function(i, c) {
c = c || {}; c = c || {};
var g = c.verbose || !1; var g = c.verbose || !1;
g && console.log("Normalize the JSON Object"), a = typeof a == "string" ? this.JSON.parse(a) : a, g && console.log("Creating a empty dictionary"); g && console.log("Normalize the JSON Object"), i = typeof i == "string" ? this.JSON.parse(i) : i, g && console.log("Creating a empty dictionary");
var o = { var o = {
strings: [], strings: [],
integers: [], integers: [],
@ -126,21 +126,21 @@ var re = {};
index: v index: v
}; };
if (y === "string") { if (y === "string") {
var P = i.call(o.strings, s); var P = a.call(o.strings, s);
return P == -1 && (o.strings.push(j(s)), P = o.strings.length - 1), { return P == -1 && (o.strings.push(j(s)), P = o.strings.length - 1), {
type: "strings", type: "strings",
index: P index: P
}; };
} }
if (y === "number" && s % 1 === 0) { if (y === "number" && s % 1 === 0) {
var P = i.call(o.integers, s); var P = a.call(o.integers, s);
return P == -1 && (o.integers.push(_(s)), P = o.integers.length - 1), { return P == -1 && (o.integers.push(S(s)), P = o.integers.length - 1), {
type: "integers", type: "integers",
index: P index: P
}; };
} }
if (y === "number") { if (y === "number") {
var P = i.call(o.floats, s); var P = a.call(o.floats, s);
return P == -1 && (o.floats.push(s), P = o.floats.length - 1), { return P == -1 && (o.floats.push(s), P = o.floats.length - 1), {
type: "floats", type: "floats",
index: P index: P
@ -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), d = o.strings.length, T = o.integers.length; }(i), d = o.strings.length, T = o.integers.length;
o.floats.length, g && console.log("Parsing the dictionary"); o.floats.length, g && console.log("Parsing the dictionary");
var E = o.strings.join("|"); var E = o.strings.join("|");
return E += "^" + o.integers.join("|"), E += "^" + o.floats.join("|"), g && console.log("Parsing the structure"), E += "^" + function w(s) { return E += "^" + o.integers.join("|"), E += "^" + o.floats.join("|"), g && console.log("Parsing the structure"), E += "^" + function w(s) {
@ -164,11 +164,11 @@ var re = {};
} }
var O = s.type, R = s.index; var O = s.type, R = s.index;
if (O === "strings") if (O === "strings")
return _(R); return S(R);
if (O === "integers") if (O === "integers")
return _(d + R); return S(d + R);
if (O === "floats") if (O === "floats")
return _(d + T + R); return S(d + T + R);
if (O === "boolean") if (O === "boolean")
return s.index; return s.index;
if (O === "null") if (O === "null")
@ -183,9 +183,9 @@ var re = {};
ast: l, ast: l,
packed: E packed: E
} : E; } : E;
}, B = function(a, c) { }, B = function(i, c) {
c = c || {}; c = c || {};
var g = a.split("^"); var g = i.split("^");
c.verbose && console.log("Building dictionary"); c.verbose && console.log("Building dictionary");
var o = [], l = g[0]; var o = [], l = g[0];
if (l !== "") { if (l !== "") {
@ -275,8 +275,8 @@ var re = {};
} }
throw new TypeError("Bad token " + P + " isn't a type"); throw new TypeError("Bad token " + P + " isn't a type");
}(); }();
}, j = function(a) { }, j = function(i) {
return typeof a != "string" ? a : a.replace(/[\+ \|\^\%]/g, function(c) { return typeof i != "string" ? i : i.replace(/[\+ \|\^\%]/g, function(c) {
return { return {
" ": "+", " ": "+",
"+": "%2B", "+": "%2B",
@ -285,8 +285,8 @@ var re = {};
"%": "%25" "%": "%25"
}[c]; }[c];
}); });
}, m = function(a) { }, m = function(i) {
return typeof a != "string" ? a : a.replace(/\+|%2B|%7C|%5E|%25/g, function(c) { return typeof i != "string" ? i : i.replace(/\+|%2B|%7C|%5E|%25/g, function(c) {
return { return {
"+": " ", "+": " ",
"%2B": "+", "%2B": "+",
@ -295,13 +295,13 @@ var re = {};
"%25": "%" "%25": "%"
}[c]; }[c];
}); });
}, _ = function(a) { }, S = function(i) {
return Number.prototype.toString.call(a, 36).toUpperCase(); return Number.prototype.toString.call(i, 36).toUpperCase();
}, p = function(a) { }, p = function(i) {
return parseInt(a, 36); return parseInt(i, 36);
}, i = Array.prototype.indexOf || function(a, c) { }, a = Array.prototype.indexOf || function(i, c) {
for (var g = c || 0, o = this.length; g < o; g++) for (var g = c || 0, o = this.length; g < o; g++)
if (this[g] === a) if (this[g] === i)
return g; return g;
return -1; return -1;
}; };
@ -318,8 +318,8 @@ var re = {};
}); });
})(re); })(re);
const ee = /* @__PURE__ */ te(re); const ee = /* @__PURE__ */ te(re);
var q, z, J, D, L, H, K, V, k; var q, z, J, D, L, H, K, V, Y;
class W { class X {
constructor(e, r, n, h, v) { constructor(e, r, n, h, v) {
A(this, "code", 0); A(this, "code", 0);
A(this, "message", "操作成功"); A(this, "message", "操作成功");
@ -327,12 +327,12 @@ class W {
A(this, "url", ""); A(this, "url", "");
A(this, "res", ""); A(this, "res", "");
// static [Symbol.hasInstance](self) { return self?.IS_ECHO_MSG !== undefined } // static [Symbol.hasInstance](self) { return self?.IS_ECHO_MSG !== undefined }
S(this, q, null); _(this, q, null);
// 判断返回 Response 对象, 还是 Response 中的 data // 判断返回 Response 对象, 还是 Response 中的 data
S(this, z, !0); _(this, z, !0);
// 判罚是否已经给出错误提示 // 判罚是否已经给出错误提示
S(this, J, !0); _(this, J, !0);
S(this, D, { _(this, D, {
get: (e, r) => f(this, L).call(this, r), get: (e, r) => f(this, L).call(this, r),
ownKeys: () => Object.keys(f(this, D).getPrototypeOf() || {}), ownKeys: () => Object.keys(f(this, D).getPrototypeOf() || {}),
getPrototypeOf: () => f(this, z) ? this : this.data, getPrototypeOf: () => f(this, z) ? this : this.data,
@ -343,18 +343,18 @@ class W {
value: f(this, D).getPrototypeOf() value: f(this, D).getPrototypeOf()
}) })
}); });
S(this, L, (e) => e === "$toast" ? f(this, K) : e === "msg" ? f(this, H) : e === "then" || e === "resp" ? (M(this, J, !0), M(this, z, e === "resp"), f(this, V)) : e === "catch" ? f(this, k) : e === "IS_ECHO_MSG" ? f(this, J) : Reflect.get(this, e)); _(this, L, (e) => e === "$toast" ? f(this, K) : e === "msg" ? f(this, H) : e === "then" || e === "resp" ? (M(this, J, !0), M(this, z, e === "resp"), f(this, V)) : e === "catch" ? f(this, Y) : e === "IS_ECHO_MSG" ? f(this, J) : Reflect.get(this, e));
S(this, H, (e = (n) => n, r = !1) => (f(this, K).call(this), M(this, z, r), Promise.resolve(e == null ? void 0 : e(f(this, D).getPrototypeOf())))); _(this, H, (e = (n) => n, r = !1) => (f(this, K).call(this), M(this, z, r), Promise.resolve(e == null ? void 0 : e(f(this, D).getPrototypeOf()))));
S(this, K, () => { _(this, K, () => {
f(this, J) && (M(this, J, !1), we.onToast(this.code, this.message)); f(this, J) && (M(this, J, !1), we.onToast(this.code, this.message));
}); });
S(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(f(this, D).getPrototypeOf())) : Promise.reject(f(this, q))); _(this, V, (e) => [0, 1].includes(this.code) ? Promise.resolve(e == null ? void 0 : e(f(this, D).getPrototypeOf())) : Promise.reject(f(this, q)));
S(this, k, (e) => Promise.resolve(e(f(this, q)))); _(this, Y, (e) => Promise.resolve(e(f(this, q))));
return this.code = e, this.message = r, this.data = n, this.url = h, this.res = v, M(this, q, new Proxy(this, f(this, D))); return this.code = e, this.message = r, this.data = n, this.url = h, this.res = v, M(this, q, new Proxy(this, f(this, D)));
} }
} }
q = new WeakMap(), z = new WeakMap(), J = new WeakMap(), D = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), k = new WeakMap(); q = new WeakMap(), z = new WeakMap(), J = new WeakMap(), D = new WeakMap(), L = new WeakMap(), H = new WeakMap(), K = new WeakMap(), V = new WeakMap(), Y = new WeakMap();
const Q = (t, e, r, n = "/", h = "") => new W(t, e, r, n, h); const W = (t, e, r, n = "/", h = "") => new X(t, e, r, n, h);
var ne = [ var ne = [
"utf8", "utf8",
"utf-8", "utf-8",
@ -401,33 +401,33 @@ const ce = new se.TextEncoder("utf8"), ge = new se.TextDecoder("utf8"), de = (t)
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"), ""), pe = (t) => ce.encode(t || ""), ve = (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, Y, $, I; var F, G, Q, $, I;
class X { class Z {
constructor(e, r, n = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) { constructor(e, r, n = ({}) => Promise.reject({ code: -1, msg: "请初始化HTTP请求方法主体" })) {
S(this, F, void 0); _(this, F, void 0);
S(this, G, void 0); _(this, G, void 0);
S(this, Y, void 0); _(this, Q, void 0);
S(this, $, { _(this, $, {
"#": /* @__PURE__ */ new Map(), "#": /* @__PURE__ */ new Map(),
// 系统缓存 // 系统缓存
$: /* @__PURE__ */ new Map() $: /* @__PURE__ */ new Map()
// 普通缓存 // 普通缓存
}); });
S(this, I, /* @__PURE__ */ new Map()); _(this, I, /* @__PURE__ */ new Map());
A(this, "request", ({ url: e = "/", method: r = "GET", ...n }, h = !1) => { A(this, "request", ({ url: e = "/", method: r = "GET", ...n }, h = !1) => {
var j; var j;
const v = r.toUpperCase(), u = de(JSON.stringify([e, v, n])), N = (j = e == null ? void 0 : e.includes) != null && j.call(e, "/_/") ? "#" : "$", B = new Promise((m, _) => { const v = r.toUpperCase(), u = de(JSON.stringify([e, v, n])), N = (j = e == null ? void 0 : e.includes) != null && j.call(e, "/_/") ? "#" : "$", B = new Promise((m, S) => {
!h && N !== "#" && f(this, $)[N].delete(u), f(this, $)[N].has(u) ? (console.log("缓存命中", e), m(f(this, $)[N].get(u))) : f(this, I).has(u) ? f(this, I).get(u).push([m, _]) : (f(this, I).set(u, [[m, _]]), f(this, F).call(this, { url: e, method: v, ...n }).then((p) => { !h && N !== "#" && f(this, $)[N].delete(u), f(this, $)[N].has(u) ? (console.log("缓存命中", e), m(f(this, $)[N].get(u))) : f(this, I).has(u) ? f(this, I).get(u).push([m, S]) : (f(this, I).set(u, [[m, S]]), f(this, F).call(this, { url: e, method: v, ...n }).then((p) => {
if (![0, 1].includes(p.code)) if (![0, 1].includes(p.code))
throw Q(p.code, p.msg, p.data, e, p == null ? void 0 : p.res); throw W(p.code, p.msg, p.data, e, p == null ? void 0 : p.res);
return [p.code, p.msg, p.data, e, p == null ? void 0 : p.res]; return [p.code, p.msg, p.data, e, p == null ? void 0 : p.res];
}).then((p) => ((N == "#" || h && v === "GET") && f(this, $)[N].set(u, p), p)).then((p) => f(this, I).get(u).forEach(([i, a]) => i(p))).catch((p) => (f(this, $)[N].delete(u), f(this, I).get(u).forEach(([i, a]) => a(p instanceof W ? p : Q(-1, p, null, e))))).finally(() => f(this, I).delete(u))); }).then((p) => ((N == "#" || h && v === "GET") && f(this, $)[N].set(u, p), p)).then((p) => f(this, I).get(u).forEach(([a, i]) => a(p))).catch((p) => (f(this, $)[N].delete(u), f(this, I).get(u).forEach(([a, i]) => i(p instanceof X ? p : W(-1, p, null, e))))).finally(() => f(this, I).delete(u)));
}); });
return new Proxy(B, { return new Proxy(B, {
get: (m, _) => (...p) => m.then((i) => Q(...i)[_](...p)).catch((i) => { get: (m, S) => (...p) => m.then((a) => W(...a)[S](...p)).catch((a) => {
if (!i instanceof W) if (!a instanceof X)
throw i; throw a;
return i[_](...p); return typeof a[S] == "function" ? a[S](...p) : a[S];
}) })
}); });
}); });
@ -458,16 +458,16 @@ class X {
const r = JSON.stringify(e, (n, h) => h === void 0 ? null : h); const r = JSON.stringify(e, (n, h) => h === void 0 ? null : h);
return f(this, G).encode(pe(ee.pack(r))); return f(this, G).encode(pe(ee.pack(r)));
}); });
M(this, Y, e), M(this, F, n), M(this, G, he(r)); M(this, Q, e), M(this, F, n), M(this, G, he(r));
} }
} }
F = new WeakMap(), G = new WeakMap(), Y = new WeakMap(), $ = new WeakMap(), I = new WeakMap(); F = new WeakMap(), G = new WeakMap(), Q = new WeakMap(), $ = new WeakMap(), I = new WeakMap();
const we = X; const we = Z;
X.onUnhandledRejection = (t) => { Z.onUnhandledRejection = (t) => {
var e, r, n, h, v, u; var e, r, n, h, v, u;
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 = (h = t.reason) == null ? void 0 : h.$toast) == null || v.call(h), (u = t == null ? void 0 : t.preventDefault) == null || u.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 = (h = t.reason) == null ? void 0 : h.$toast) == null || v.call(h), (u = t == null ? void 0 : t.preventDefault) == null || u.call(t));
}; };
X.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,

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.1", "version": "0.9.2",
"type": "module", "type": "module",
"files": [ "files": [
"dist" "dist"