This commit is contained in:
2026-08-24 18:00:15 +08:00
parent 7801b7000c
commit e2fe23e792
4 changed files with 37 additions and 24 deletions
+28 -21
View File
@@ -245,7 +245,7 @@ var fe = {};
}); });
})(fe); })(fe);
const le = /* @__PURE__ */ we(fe); const le = /* @__PURE__ */ we(fe);
var $, q, B, D, W, X, z, Z, ee, te, re; var $, q, j, B, W, X, z, Z, ee, te, re;
const ae = class ae { const ae = class ae {
/** /**
* @param {number} code * @param {number} code
@@ -272,8 +272,8 @@ const ae = class ae {
p(this, q, !0); p(this, q, !0);
// 判断是否已经给出错误提示 // 判断是否已经给出错误提示
/** @type {boolean} */ /** @type {boolean} */
p(this, B, !0); p(this, j, !0);
p(this, D, { p(this, B, {
/** @param {any} __ @param {string} key */ /** @param {any} __ @param {string} key */
get: (e, t) => s(this, W).call(this, t), get: (e, t) => s(this, W).call(this, t),
/** @param {any} __ @param {string} key */ /** @param {any} __ @param {string} key */
@@ -281,7 +281,7 @@ const ae = class ae {
throw new TypeError(`HttpResponse 是只读的,不能设置属性 "${t}"`); throw new TypeError(`HttpResponse 是只读的,不能设置属性 "${t}"`);
}, },
/** @returns {string[]} */ /** @returns {string[]} */
ownKeys: () => Object.keys(s(this, D).getPrototypeOf() || {}), ownKeys: () => Object.keys(s(this, B).getPrototypeOf() || {}),
/** @returns {HttpResponse | unknown} */ /** @returns {HttpResponse | unknown} */
getPrototypeOf: () => s(this, q) ? this : this.data, getPrototypeOf: () => s(this, q) ? this : this.data,
/** @returns {PropertyDescriptor} */ /** @returns {PropertyDescriptor} */
@@ -289,24 +289,31 @@ const ae = class ae {
configurable: !0, configurable: !0,
enumerable: !0, enumerable: !0,
writable: !0, writable: !0,
value: s(this, D).getPrototypeOf() value: s(this, B).getPrototypeOf()
}) })
}); });
/** /**
* @param {string} key * @param {string} key
* @returns {unknown} * @returns {unknown}
*/ */
p(this, W, (e) => e === "$echoMsg" ? s(this, z) : e === "msg" ? s(this, X) : e === "then" ? (_(this, B, !0), s(this, Z)) : e === "resp" ? (_(this, B, !0), s(this, ee)) : e === "catch" ? s(this, te) : e === "finally" ? s(this, re) : e === "IS_ECHO_MSG" ? s(this, B) : Reflect.get(this, e)); p(this, W, (e) => e === "$echoMsg" ? s(this, z) : e === "msg" ? s(this, X) : e === "then" ? (_(this, j, !0), s(this, Z)) : e === "resp" ? (_(this, j, !0), s(this, ee)) : e === "catch" ? s(this, te) : e === "finally" ? s(this, re) : e === "IS_ECHO_MSG" ? s(this, j) : Reflect.get(this, e));
/** /**
* @param {(value: unknown) => unknown} [fn] * @param {(value: unknown) => unknown} [fn] 回调参数默认是 data(isResp=false), 传 isResp=true 则是完整的 HttpResponse(含 code/message)
* @param {boolean} [isResp] * @param {boolean} [isResp]
* @returns {Promise<unknown>} * @returns {Promise<unknown>} fn 内部抛出的异常会变成 reject, 而不是像之前那样在参数求值阶段直接同步抛出(违反"永远返回 Promise"的约定, .then() 链式调用捕获不到)
*/ */
p(this, X, (e = (n) => n, t = !1) => (s(this, z).call(this), _(this, q, t), Promise.resolve(e == null ? void 0 : e(s(this, D).getPrototypeOf())))); p(this, X, (e = (n) => n, t = !1) => {
s(this, z).call(this), _(this, q, t);
try {
return Promise.resolve(e == null ? void 0 : e(s(this, B).getPrototypeOf()));
} catch (n) {
return Promise.reject(n);
}
});
g(this, "toJSON", () => ({ code: this.code, message: this.message, data: this.data, url: this.url, res: this.res })); g(this, "toJSON", () => ({ code: this.code, message: this.message, data: this.data, url: this.url, res: this.res }));
g(this, "toString", () => this.message); g(this, "toString", () => this.message);
p(this, z, () => { p(this, z, () => {
s(this, B) && (_(this, B, !1), oe.onMsg(this.code, this.message)); s(this, j) && (_(this, j, !1), oe.onMsg(this.code, this.message));
}); });
/** /**
* @param {(value: unknown) => unknown} [fn] * @param {(value: unknown) => unknown} [fn]
@@ -329,14 +336,14 @@ const ae = class ae {
* @param {(() => void) | undefined} [fn] * @param {(() => void) | undefined} [fn]
* @returns {Promise<unknown>} * @returns {Promise<unknown>}
*/ */
p(this, re, (e) => (e == null || e(), [0, 1].includes(this.code) ? Promise.resolve(s(this, D).getPrototypeOf()) : Promise.reject(s(this, $)))); p(this, re, (e) => (e == null || e(), [0, 1].includes(this.code) ? Promise.resolve(s(this, B).getPrototypeOf()) : Promise.reject(s(this, $))));
return this.code = e, this.message = t, this.data = n, this.url = i, this.res = c, _(this, $, new Proxy(this, s(this, D))); return this.code = e, this.message = t, this.data = n, this.url = i, this.res = c, _(this, $, new Proxy(this, s(this, B)));
} }
static [Symbol.hasInstance](e) { static [Symbol.hasInstance](e) {
return (e == null ? void 0 : e.constructor) === ae || (e == null ? void 0 : e[Symbol.for("HttpResponse")]) === !0; return (e == null ? void 0 : e.constructor) === ae || (e == null ? void 0 : e[Symbol.for("HttpResponse")]) === !0;
} }
}; };
$ = new WeakMap(), q = new WeakMap(), B = new WeakMap(), D = new WeakMap(), W = new WeakMap(), X = new WeakMap(), z = new WeakMap(), Z = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), re = new WeakMap(); $ = new WeakMap(), q = new WeakMap(), j = new WeakMap(), B = new WeakMap(), W = new WeakMap(), X = new WeakMap(), z = new WeakMap(), Z = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), re = new WeakMap();
let L = ae; let L = ae;
const ie = (r, e, t, n = "/", i = "") => new L(r, e, t, n, i); const ie = (r, e, t, n = "/", i = "") => new L(r, e, t, n, i);
var de = [ var de = [
@@ -504,7 +511,7 @@ Promise.withResolvers || (Promise.withResolvers = function() {
r = n, e = i; r = n, e = i;
}), resolve: r, reject: e }; }), resolve: r, reject: e };
}); });
var G, j, ne, R, F, K, se, Y; var G, D, ne, R, F, K, se, Y;
class oe { class oe {
/** /**
* @param {string} [appKey] * @param {string} [appKey]
@@ -515,7 +522,7 @@ class oe {
/** @type {RequestFn | undefined} */ /** @type {RequestFn | undefined} */
p(this, G); p(this, G);
/** @type {Base62 | undefined} */ /** @type {Base62 | undefined} */
p(this, j); p(this, D);
/** @type {string | undefined} */ /** @type {string | undefined} */
p(this, ne); p(this, ne);
p(this, R, { p(this, R, {
@@ -535,7 +542,7 @@ class oe {
* @param {RequestFn} [reqFn] * @param {RequestFn} [reqFn]
*/ */
g(this, "init", (e, t, n) => { g(this, "init", (e, t, n) => {
e && _(this, ne, e), n && _(this, G, n), t && _(this, j, new Ae(t)), s(this, se).call(this); e && _(this, ne, e), n && _(this, G, n), t && _(this, D, new Ae(t)), s(this, se).call(this);
}); });
p(this, se, () => { p(this, se, () => {
!s(this, K).size || !s(this, G) || (s(this, K).forEach((e) => s(this, Y).call(this, ...e)), s(this, K).clear()); !s(this, K).size || !s(this, G) || (s(this, K).forEach((e) => s(this, Y).call(this, ...e)), s(this, K).clear());
@@ -681,8 +688,8 @@ class oe {
if (e === void 0 || e === "" || e === null) if (e === void 0 || e === "" || e === null)
return t; return t;
try { try {
if (!s(this, j)) throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret"); if (!s(this, D)) throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret");
const n = s(this, j).decode(e); const n = s(this, D).decode(e);
return le.unpack(n); return le.unpack(n);
} catch { } catch {
return console.warn("core.decode", e), t; return console.warn("core.decode", e), t;
@@ -694,14 +701,14 @@ class oe {
* @returns {string} * @returns {string}
*/ */
g(this, "encode", (e = {}) => { g(this, "encode", (e = {}) => {
if (!s(this, j)) throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret"); if (!s(this, D)) throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret");
const t = JSON.stringify(e, (n, i) => i === void 0 ? null : i); const t = JSON.stringify(e, (n, i) => i === void 0 ? null : i);
return s(this, j).encode(le.pack(t)); return s(this, D).encode(le.pack(t));
}); });
this.init(e, t, n); this.init(e, t, n);
} }
} }
G = new WeakMap(), j = new WeakMap(), ne = new WeakMap(), R = new WeakMap(), F = new WeakMap(), K = new WeakMap(), se = new WeakMap(), Y = new WeakMap(); G = new WeakMap(), D = new WeakMap(), ne = new WeakMap(), R = new WeakMap(), F = new WeakMap(), K = new WeakMap(), se = new WeakMap(), Y = new WeakMap();
oe.onUnhandledRejection = (r) => { oe.onUnhandledRejection = (r) => {
var t; var t;
const e = r instanceof L ? r : (r == null ? void 0 : r.reason) instanceof L ? r.reason : null; const e = r instanceof L ? r : (r == null ? void 0 : r.reason) instanceof L ? r.reason : null;
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ff-request", "name": "ff-request",
"version": "0.11.3", "version": "0.11.4",
"type": "module", "type": "module",
"main": "./ff-request.umd.cjs", "main": "./ff-request.umd.cjs",
"module": "./ff-request.js", "module": "./ff-request.js",
+6
View File
@@ -154,6 +154,12 @@ export declare class HttpResponse {
res: string; res: string;
}; };
toString: () => string; toString: () => string;
msg(fn?: (value: unknown) => unknown, isResp?: false): Promise<unknown>;
msg(fn?: (value: HttpResponse) => unknown, isResp: true): Promise<unknown>;
then(fn?: (value: unknown) => unknown, onrejected?: (reason: unknown) => unknown): Promise<unknown>;
resp(fn?: (value: HttpResponse) => unknown, onrejected?: (reason: unknown) => unknown): Promise<unknown>;
catch(fn: (reason: HttpResponse) => unknown): Promise<unknown>;
finally(fn?: () => void): Promise<unknown>;
#private; #private;
} }