v0.11.4
This commit is contained in:
+28
-21
@@ -245,7 +245,7 @@ var fe = {};
|
||||
});
|
||||
})(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 {
|
||||
/**
|
||||
* @param {number} code
|
||||
@@ -272,8 +272,8 @@ const ae = class ae {
|
||||
p(this, q, !0);
|
||||
// 判断是否已经给出错误提示
|
||||
/** @type {boolean} */
|
||||
p(this, B, !0);
|
||||
p(this, D, {
|
||||
p(this, j, !0);
|
||||
p(this, B, {
|
||||
/** @param {any} __ @param {string} key */
|
||||
get: (e, t) => s(this, W).call(this, t),
|
||||
/** @param {any} __ @param {string} key */
|
||||
@@ -281,7 +281,7 @@ const ae = class ae {
|
||||
throw new TypeError(`HttpResponse 是只读的,不能设置属性 "${t}"`);
|
||||
},
|
||||
/** @returns {string[]} */
|
||||
ownKeys: () => Object.keys(s(this, D).getPrototypeOf() || {}),
|
||||
ownKeys: () => Object.keys(s(this, B).getPrototypeOf() || {}),
|
||||
/** @returns {HttpResponse | unknown} */
|
||||
getPrototypeOf: () => s(this, q) ? this : this.data,
|
||||
/** @returns {PropertyDescriptor} */
|
||||
@@ -289,24 +289,31 @@ const ae = class ae {
|
||||
configurable: !0,
|
||||
enumerable: !0,
|
||||
writable: !0,
|
||||
value: s(this, D).getPrototypeOf()
|
||||
value: s(this, B).getPrototypeOf()
|
||||
})
|
||||
});
|
||||
/**
|
||||
* @param {string} key
|
||||
* @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]
|
||||
* @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, "toString", () => this.message);
|
||||
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]
|
||||
@@ -329,14 +336,14 @@ const ae = class ae {
|
||||
* @param {(() => void) | undefined} [fn]
|
||||
* @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, $))));
|
||||
return this.code = e, this.message = t, this.data = n, this.url = i, this.res = c, _(this, $, new Proxy(this, s(this, D)));
|
||||
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, B)));
|
||||
}
|
||||
static [Symbol.hasInstance](e) {
|
||||
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;
|
||||
const ie = (r, e, t, n = "/", i = "") => new L(r, e, t, n, i);
|
||||
var de = [
|
||||
@@ -504,7 +511,7 @@ Promise.withResolvers || (Promise.withResolvers = function() {
|
||||
r = n, e = i;
|
||||
}), resolve: r, reject: e };
|
||||
});
|
||||
var G, j, ne, R, F, K, se, Y;
|
||||
var G, D, ne, R, F, K, se, Y;
|
||||
class oe {
|
||||
/**
|
||||
* @param {string} [appKey]
|
||||
@@ -515,7 +522,7 @@ class oe {
|
||||
/** @type {RequestFn | undefined} */
|
||||
p(this, G);
|
||||
/** @type {Base62 | undefined} */
|
||||
p(this, j);
|
||||
p(this, D);
|
||||
/** @type {string | undefined} */
|
||||
p(this, ne);
|
||||
p(this, R, {
|
||||
@@ -535,7 +542,7 @@ class oe {
|
||||
* @param {RequestFn} [reqFn]
|
||||
*/
|
||||
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, () => {
|
||||
!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)
|
||||
return t;
|
||||
try {
|
||||
if (!s(this, j)) throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret");
|
||||
const n = s(this, j).decode(e);
|
||||
if (!s(this, D)) throw new Error("未初始化 appSecret,请先通过 init 设置 appSecret");
|
||||
const n = s(this, D).decode(e);
|
||||
return le.unpack(n);
|
||||
} catch {
|
||||
return console.warn("core.decode", e), t;
|
||||
@@ -694,14 +701,14 @@ class oe {
|
||||
* @returns {string}
|
||||
*/
|
||||
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);
|
||||
return s(this, j).encode(le.pack(t));
|
||||
return s(this, D).encode(le.pack(t));
|
||||
});
|
||||
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) => {
|
||||
var t;
|
||||
const e = r instanceof L ? r : (r == null ? void 0 : r.reason) instanceof L ? r.reason : null;
|
||||
|
||||
Reference in New Issue
Block a user