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