This commit is contained in:
2026-08-25 11:38:20 +08:00
parent 351fb15d69
commit d8cc3ec655
5 changed files with 65 additions and 46 deletions
+43 -35
View File
@@ -22,7 +22,7 @@ var ue = {};
floats: []
};
u && console.log("Creating the AST");
var p = function O(o) {
var p = function S(o) {
u && console.log("Calling recursiveAstBuilder with " + this.JSON.stringify(o));
var y = typeof o;
if (o === null)
@@ -36,16 +36,16 @@ var ue = {};
index: f
};
if (o instanceof Array) {
var S = ["@"];
var O = ["@"];
for (var b in o)
o.hasOwnProperty(b) && S.push(O(o[b]));
return S;
o.hasOwnProperty(b) && O.push(S(o[b]));
return O;
}
if (y === "object") {
var S = ["$"];
var O = ["$"];
for (var N in o)
o.hasOwnProperty(N) && (S.push(O(N)), S.push(O(o[N])));
return S;
o.hasOwnProperty(N) && (O.push(S(N)), O.push(S(o[N])));
return O;
}
if (o === "")
return {
@@ -53,21 +53,21 @@ var ue = {};
index: c
};
if (y === "string") {
var P = H.call(g.strings, o);
var P = q.call(g.strings, o);
return P == -1 && (g.strings.push(T(o)), P = g.strings.length - 1), {
type: "strings",
index: P
};
}
if (y === "number" && o % 1 === 0) {
var P = H.call(g.integers, o);
var P = q.call(g.integers, o);
return P == -1 && (g.integers.push(m(o)), P = g.integers.length - 1), {
type: "integers",
index: P
};
}
if (y === "number") {
var P = H.call(g.floats, o);
var P = q.call(g.floats, o);
return P == -1 && (g.floats.push(o), P = g.floats.length - 1), {
type: "floats",
index: P
@@ -82,11 +82,11 @@ var ue = {};
}(h), E = g.strings.length, J = g.integers.length;
g.floats.length, u && console.log("Parsing the dictionary");
var M = g.strings.join("|");
return M += "^" + g.integers.join("|"), M += "^" + g.floats.join("|"), u && console.log("Parsing the structure"), M += "^" + function O(o) {
return M += "^" + g.integers.join("|"), M += "^" + g.floats.join("|"), u && console.log("Parsing the structure"), M += "^" + function S(o) {
if (u && console.log("Calling a recursiveParser with " + this.JSON.stringify(o)), o instanceof Array) {
var y = o.shift();
for (var S in o)
o.hasOwnProperty(S) && (y += O(o[S]) + "|");
for (var O in o)
o.hasOwnProperty(O) && (y += S(o[O]) + "|");
return (y[y.length - 1] === "|" ? y.slice(0, -1) : y) + "]";
}
var b = o.type, N = o.index;
@@ -131,16 +131,16 @@ var ue = {};
g.push(parseFloat(p[E]));
}
p = null, d.verbose && console.log("Tokenizing the structure");
for (var M = "", O = [], o = u[3].length, E = 0; E < o; E++) {
for (var M = "", S = [], o = u[3].length, E = 0; E < o; E++) {
var y = u[3].charAt(E);
y === "|" || y === "$" || y === "@" || y === "]" ? (M && (O.push(I(M)), M = ""), y !== "|" && O.push(y)) : M += y;
y === "|" || y === "$" || y === "@" || y === "]" ? (M && (S.push(I(M)), M = ""), y !== "|" && S.push(y)) : M += y;
}
var S = O.length, b = 0;
var O = S.length, b = 0;
return d.verbose && console.log("Starting recursive parser"), function N() {
var P = O[b++];
var P = S[b++];
if (d.verbose && console.log("Reading collection type " + (P === "$" ? "object" : "Array")), P === "@") {
for (var v = []; b < S; b++) {
var A = O[b];
for (var v = []; b < O; b++) {
var A = S[b];
if (d.verbose && console.log("Read " + A + " symbol"), A === "]")
return v;
if (A === "@" || A === "$")
@@ -169,12 +169,12 @@ var ue = {};
return d.verbose && console.log("Parsed " + this.JSON.stringify(v)), v;
}
if (P === "$") {
for (var v = {}; b < S; b++) {
var x = O[b];
for (var v = {}; b < O; b++) {
var x = S[b];
if (x === "]")
return v;
x === c ? x = "" : x = g[x];
var A = O[++b];
var A = S[++b];
if (A === "@" || A === "$")
v[x] = N();
else
@@ -226,7 +226,7 @@ var ue = {};
return Number.prototype.toString.call(h, 36).toUpperCase();
}, I = function(h) {
return parseInt(h, 36);
}, H = Array.prototype.indexOf || function(h, d) {
}, q = Array.prototype.indexOf || function(h, d) {
for (var u = d || 0, g = this.length; u < g; u++)
if (this[u] === h)
return u;
@@ -245,7 +245,7 @@ var ue = {};
});
})(ue);
const ce = /* @__PURE__ */ pe(ue);
var $, q, j, B, W, k, X, Z, ee;
var $, H, j, B, W, k, X, Z, ee;
const ie = class ie {
/**
* @param {number} code
@@ -276,7 +276,7 @@ const ie = class ie {
*
* @type {boolean}
*/
w(this, q, !0);
w(this, H, !0);
/**
* 是否已经显示消息
*
@@ -313,7 +313,7 @@ const ie = class ie {
/**
* @returns {HttpResponse | unknown}
*/
getPrototypeOf: () => s(this, q) ? this : this.data,
getPrototypeOf: () => s(this, H) ? this : this.data,
/**
* @returns {PropertyDescriptor}
*/
@@ -354,7 +354,7 @@ const ie = class ie {
* fn 内部抛出的异常会变成 reject,而不是同步抛出。
*/
l(this, "msg", (e = (n) => n, t = !1) => {
s(this, k).call(this), C(this, q, t);
s(this, k).call(this), C(this, H, t);
try {
return Promise.resolve(
e == null ? void 0 : e(s(this, B).getPrototypeOf())
@@ -445,7 +445,7 @@ const ie = class ie {
return (e == null ? void 0 : e.constructor) === ie || (e == null ? void 0 : e[Symbol.for("HttpResponse")]) === !0;
}
};
$ = new WeakMap(), q = new WeakMap(), j = new WeakMap(), B = new WeakMap(), W = new WeakMap(), k = new WeakMap(), X = new WeakMap(), Z = new WeakMap(), ee = new WeakMap();
$ = new WeakMap(), H = new WeakMap(), j = new WeakMap(), B = new WeakMap(), W = new WeakMap(), k = new WeakMap(), X = new WeakMap(), Z = new WeakMap(), ee = new WeakMap();
let L = ie;
const ne = (r, e, t, n = "/", i = "") => (
/** @type {HttpResponseProxy} */
@@ -507,7 +507,7 @@ function Te(r) {
function _e(r) {
return be.decode(new DataView(r), {});
}
const Oe = 62, Q = 30, he = 31, Se = 63;
const Se = 62, Q = 30, he = 31, Oe = 63;
class xe {
/**
* @param {string} alphabet 62 位编码字母表
@@ -517,7 +517,7 @@ class xe {
l(this, "encodeTable", []);
/** @type {Uint8Array} */
l(this, "decodeMap", new Uint8Array(256).fill(255));
if (e.length !== Oe)
if (e.length !== Se)
throw new Error("Encoding alphabet must be 62 characters long");
if (e.includes(`
`) || e.includes("\r"))
@@ -566,7 +566,7 @@ class me {
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 & Se;
return e < 6 && t > 0 && (n |= this.src[t - 1] << e), n & Oe;
}
/**
* @param {string} src
@@ -692,7 +692,7 @@ class se {
* 发起请求,支持缓存与并发合并
* @param {RequestOptions} options
* @param {boolean} [isCacheRequest]
* @returns {any} 返回 Proxy 包裹的 Promise,支持链式调用 .then / .catch / .msg / .resp
* @returns {HttpResponseChainable} 返回 Proxy 包裹的 Promise,支持链式调用 .then / .catch / .msg / .resp
*/
l(this, "request", ({ url: e = "/", method: t = "GET", ...n }, i = !1) => {
var m, I;
@@ -704,9 +704,11 @@ class se {
/** @type {'#' | '$'} */
(m = e == null ? void 0 : e.includes) != null && m.call(e, "/_/") ? "#" : "$"
), { promise: a, resolve: T, reject: _ } = Promise.withResolvers();
return s(this, R)[U].has(f) ? (console.log("cache", e), T(s(this, R)[U].get(f))) : s(this, F).has(f) ? (I = s(this, F).get(f)) == null || I.push([T, _]) : (s(this, F).set(f, [[T, _]]), s(this, Y).call(this, f, U, { url: e, method: c, ...n }, i)), new Proxy(a, {
return s(this, R)[U].has(f) ? (console.log("cache", e), T(s(this, R)[U].get(f))) : s(this, F).has(f) ? (I = s(this, F).get(f)) == null || I.push([T, _]) : (s(this, F).set(f, [[T, _]]), s(this, Y).call(this, f, U, { url: e, method: c, ...n }, i)), /** @type {HttpResponseChainable} */
/** @type {unknown} */
new Proxy(a, {
// Symbol.for('HttpResponse') 是标记,用于外部 instanceof 识别此 Proxy 为 HttpResponse 类型
get: (H, h) => h === Symbol.for("HttpResponse") ? !0 : (...d) => H.then((u) => (
get: (q, h) => h === Symbol.for("HttpResponse") ? !0 : (...d) => q.then((u) => (
/** @type {any} */
ne(
.../** @type {[number, string, unknown, string, string]} */
@@ -722,7 +724,13 @@ class se {
/** @type {any} */
u[h]
);
})
}),
// 这个 Proxy 只用来转发调用 then/catch/finally/msg/resp,不代表任何数据,禁止赋值
set: (q, h) => {
throw new TypeError(
`request() 返回值是只读的,不能设置属性 "${String(h)}"`
);
}
});
});
/**
+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",
"version": "0.12.1",
"version": "0.12.2",
"type": "module",
"main": "./ff-request.umd.cjs",
"module": "./ff-request.js",
+9 -8
View File
@@ -1,4 +1,5 @@
import { RequestFn, RequestOptions, Base62Param } from './types/httpRequest';
import { HttpResponseChainable } from './types/httpResponse';
export default HttpRequest;
declare class HttpRequest {
/**
@@ -18,36 +19,36 @@ declare class HttpRequest {
* 发起请求,支持缓存与并发合并
* @param {RequestOptions} options
* @param {boolean} [isCacheRequest]
* @returns {any} 返回 Proxy 包裹的 Promise,支持链式调用 .then / .catch / .msg / .resp
* @returns {HttpResponseChainable} 返回 Proxy 包裹的 Promise,支持链式调用 .then / .catch / .msg / .resp
*/
request: ({ url, method, ...params }: RequestOptions, isCacheRequest?: boolean) => any;
request: ({ url, method, ...params }: RequestOptions, isCacheRequest?: boolean) => HttpResponseChainable;
/**
* GET 请求
* @param {string} url
* @param {Record<string, unknown>} [params]
*/
get: (url: string, params?: Record<string, unknown>) => any;
get: (url: string, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* POST 请求
* @param {string} url
* @param {unknown} [data]
* @param {Record<string, unknown>} [params]
*/
post: (url: string, data?: unknown, params?: Record<string, unknown>) => any;
post: (url: string, data?: unknown, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* PUT 请求
* @param {string} url
* @param {unknown} [data]
* @param {Record<string, unknown>} [params]
*/
put: (url: string, data?: unknown, params?: Record<string, unknown>) => any;
put: (url: string, data?: unknown, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* DELETE 请求
* @param {string} url
* @param {unknown} [data]
* @param {Record<string, unknown>} [params]
*/
del: (url: string, data?: unknown, params?: Record<string, unknown>) => any;
del: (url: string, data?: unknown, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* 下载(待实现)
* @param {string} url
@@ -59,13 +60,13 @@ declare class HttpRequest {
* @param {string} url
* @param {Record<string, unknown>} [params]
*/
cache: (url: string, params?: Record<string, unknown>) => any;
cache: (url: string, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* 通过 Base62 编码参数请求列表接口
* @param {string} code
* @param {Base62Param} [base62param]
*/
list: (code: string, base62param?: Base62Param) => any;
list: (code: string, base62param?: Base62Param) => HttpResponseChainable;
getAppInfo: () => void;
/**
* 清除缓存
+10
View File
@@ -25,6 +25,16 @@ export type HttpResponseProxyAPI = {
finally: (fn?: () => void) => Promise<unknown>
}
/**
* HttpResponse 上所有"可链式调用"的方法(then/catch/finally 来自 Proxymsg/resp 来自
* HttpResponse 本身——用 Pick 直接引用类上的定义,避免和 @overload 的类型重复维护)。
*
* request() 返回的是一个包裹着 pending Promise 的 Proxy:对任意 key 的访问都会返回一个
* "等 Promise resolve 后再转发调用"的函数,并不提供 code/data 这类同步属性,
* 所以它的类型应该是这个(不能直接用 HttpResponseProxy,那个类型意味着同步属性也存在)。
*/
export type HttpResponseChainable = HttpResponseProxyAPI & Pick<HttpResponse, 'msg' | 'resp'>
/**
* HttpResponse 最终对外类型
*