@kevisual/router 0.0.32 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/router-browser.d.ts +2 -1
- package/dist/router-browser.js +73 -45
- package/dist/router-sign.d.ts +2 -2
- package/dist/router-sign.js +13711 -28503
- package/dist/router-simple.d.ts +18 -1
- package/dist/router-simple.js +24 -3
- package/dist/router.d.ts +2 -1
- package/dist/router.js +259 -120
- package/package.json +8 -8
- package/src/route.ts +6 -8
- package/src/router-simple.ts +28 -3
- package/src/test/listen-ip.ts +18 -0
package/dist/router-browser.d.ts
CHANGED
|
@@ -171,7 +171,6 @@ declare class Route<U = {
|
|
|
171
171
|
*/
|
|
172
172
|
key?: string;
|
|
173
173
|
id?: string;
|
|
174
|
-
share?: boolean;
|
|
175
174
|
run?: Run;
|
|
176
175
|
nextRoute?: NextRoute;
|
|
177
176
|
description?: string;
|
|
@@ -365,6 +364,7 @@ declare class QueryRouter {
|
|
|
365
364
|
hasRoute(path: string, key?: string): Route<{
|
|
366
365
|
[key: string]: any;
|
|
367
366
|
}>;
|
|
367
|
+
createRouteList(force?: boolean): void;
|
|
368
368
|
/**
|
|
369
369
|
* 等待程序运行, 获取到message的数据,就执行
|
|
370
370
|
*
|
|
@@ -380,6 +380,7 @@ declare class QueryRouter {
|
|
|
380
380
|
}, opts?: {
|
|
381
381
|
emitter?: any;
|
|
382
382
|
timeout?: number;
|
|
383
|
+
getList?: boolean;
|
|
383
384
|
}): Promise<void>;
|
|
384
385
|
}
|
|
385
386
|
type QueryRouterServerOpts = {
|
package/dist/router-browser.js
CHANGED
|
@@ -97,21 +97,30 @@ try {
|
|
|
97
97
|
/** A special constant with type `never` */
|
|
98
98
|
function $constructor(name, initializer, params) {
|
|
99
99
|
function init(inst, def) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
if (!inst._zod) {
|
|
101
|
+
Object.defineProperty(inst, "_zod", {
|
|
102
|
+
value: {
|
|
103
|
+
def,
|
|
104
|
+
constr: _,
|
|
105
|
+
traits: new Set(),
|
|
106
|
+
},
|
|
107
|
+
enumerable: false,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (inst._zod.traits.has(name)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
106
113
|
inst._zod.traits.add(name);
|
|
107
114
|
initializer(inst, def);
|
|
108
115
|
// support prototype modifications
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
const proto = _.prototype;
|
|
117
|
+
const keys = Object.keys(proto);
|
|
118
|
+
for (let i = 0; i < keys.length; i++) {
|
|
119
|
+
const k = keys[i];
|
|
120
|
+
if (!(k in inst)) {
|
|
121
|
+
inst[k] = proto[k].bind(inst);
|
|
122
|
+
}
|
|
112
123
|
}
|
|
113
|
-
inst._zod.constr = _;
|
|
114
|
-
inst._zod.def = def;
|
|
115
124
|
}
|
|
116
125
|
// doesn't work if Parent has a constructor with arguments
|
|
117
126
|
const Parent = params?.Parent ?? Object;
|
|
@@ -246,6 +255,14 @@ function mergeDefs(...defs) {
|
|
|
246
255
|
function esc(str) {
|
|
247
256
|
return JSON.stringify(str);
|
|
248
257
|
}
|
|
258
|
+
function slugify(input) {
|
|
259
|
+
return input
|
|
260
|
+
.toLowerCase()
|
|
261
|
+
.trim()
|
|
262
|
+
.replace(/[^\w\s-]/g, "")
|
|
263
|
+
.replace(/[\s_-]+/g, "-")
|
|
264
|
+
.replace(/^-+|-+$/g, "");
|
|
265
|
+
}
|
|
249
266
|
const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
|
250
267
|
function isObject$1(data) {
|
|
251
268
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
@@ -271,6 +288,8 @@ function isPlainObject(o) {
|
|
|
271
288
|
const ctor = o.constructor;
|
|
272
289
|
if (ctor === undefined)
|
|
273
290
|
return true;
|
|
291
|
+
if (typeof ctor !== "function")
|
|
292
|
+
return true;
|
|
274
293
|
// modified prototype
|
|
275
294
|
const prot = ctor.prototype;
|
|
276
295
|
if (isObject$1(prot) === false)
|
|
@@ -734,9 +753,6 @@ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?:
|
|
|
734
753
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
735
754
|
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
736
755
|
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
737
|
-
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
738
|
-
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
739
|
-
const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
740
756
|
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
|
741
757
|
const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
|
742
758
|
// const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
@@ -1227,7 +1243,7 @@ class Doc {
|
|
|
1227
1243
|
const version = {
|
|
1228
1244
|
major: 4,
|
|
1229
1245
|
minor: 1,
|
|
1230
|
-
patch:
|
|
1246
|
+
patch: 13,
|
|
1231
1247
|
};
|
|
1232
1248
|
|
|
1233
1249
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
@@ -1430,7 +1446,7 @@ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
|
|
|
1430
1446
|
code: "invalid_format",
|
|
1431
1447
|
format: "url",
|
|
1432
1448
|
note: "Invalid hostname",
|
|
1433
|
-
pattern: hostname.source,
|
|
1449
|
+
pattern: def.hostname.source,
|
|
1434
1450
|
input: payload.value,
|
|
1435
1451
|
inst,
|
|
1436
1452
|
continue: !def.abort,
|
|
@@ -1520,18 +1536,12 @@ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def
|
|
|
1520
1536
|
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
|
|
1521
1537
|
def.pattern ?? (def.pattern = ipv4);
|
|
1522
1538
|
$ZodStringFormat.init(inst, def);
|
|
1523
|
-
inst._zod.
|
|
1524
|
-
const bag = inst._zod.bag;
|
|
1525
|
-
bag.format = `ipv4`;
|
|
1526
|
-
});
|
|
1539
|
+
inst._zod.bag.format = `ipv4`;
|
|
1527
1540
|
});
|
|
1528
1541
|
const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
|
|
1529
1542
|
def.pattern ?? (def.pattern = ipv6);
|
|
1530
1543
|
$ZodStringFormat.init(inst, def);
|
|
1531
|
-
inst._zod.
|
|
1532
|
-
const bag = inst._zod.bag;
|
|
1533
|
-
bag.format = `ipv6`;
|
|
1534
|
-
});
|
|
1544
|
+
inst._zod.bag.format = `ipv6`;
|
|
1535
1545
|
inst._zod.check = (payload) => {
|
|
1536
1546
|
try {
|
|
1537
1547
|
// @ts-ignore
|
|
@@ -1601,9 +1611,7 @@ function isValidBase64(data) {
|
|
|
1601
1611
|
const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
|
|
1602
1612
|
def.pattern ?? (def.pattern = base64);
|
|
1603
1613
|
$ZodStringFormat.init(inst, def);
|
|
1604
|
-
inst._zod.
|
|
1605
|
-
inst._zod.bag.contentEncoding = "base64";
|
|
1606
|
-
});
|
|
1614
|
+
inst._zod.bag.contentEncoding = "base64";
|
|
1607
1615
|
inst._zod.check = (payload) => {
|
|
1608
1616
|
if (isValidBase64(payload.value))
|
|
1609
1617
|
return;
|
|
@@ -1627,9 +1635,7 @@ function isValidBase64URL(data) {
|
|
|
1627
1635
|
const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
|
|
1628
1636
|
def.pattern ?? (def.pattern = base64url);
|
|
1629
1637
|
$ZodStringFormat.init(inst, def);
|
|
1630
|
-
inst._zod.
|
|
1631
|
-
inst._zod.bag.contentEncoding = "base64url";
|
|
1632
|
-
});
|
|
1638
|
+
inst._zod.bag.contentEncoding = "base64url";
|
|
1633
1639
|
inst._zod.check = (payload) => {
|
|
1634
1640
|
if (isValidBase64URL(payload.value))
|
|
1635
1641
|
return;
|
|
@@ -1713,9 +1719,9 @@ const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
|
|
|
1713
1719
|
return payload;
|
|
1714
1720
|
};
|
|
1715
1721
|
});
|
|
1716
|
-
const $ZodNumberFormat = /*@__PURE__*/ $constructor("$
|
|
1722
|
+
const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
|
|
1717
1723
|
$ZodCheckNumberFormat.init(inst, def);
|
|
1718
|
-
$ZodNumber.init(inst, def); // no format
|
|
1724
|
+
$ZodNumber.init(inst, def); // no format checks
|
|
1719
1725
|
});
|
|
1720
1726
|
const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
|
|
1721
1727
|
$ZodType.init(inst, def);
|
|
@@ -1833,7 +1839,7 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1833
1839
|
const keySet = def.keySet;
|
|
1834
1840
|
const _catchall = def.catchall._zod;
|
|
1835
1841
|
const t = _catchall.def.type;
|
|
1836
|
-
for (const key
|
|
1842
|
+
for (const key in input) {
|
|
1837
1843
|
if (keySet.has(key))
|
|
1838
1844
|
continue;
|
|
1839
1845
|
if (t === "never") {
|
|
@@ -2387,8 +2393,8 @@ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
|
|
|
2387
2393
|
$ZodType.init(inst, def);
|
|
2388
2394
|
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
2389
2395
|
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2390
|
-
defineLazy(inst._zod, "optin", () => def.innerType
|
|
2391
|
-
defineLazy(inst._zod, "optout", () => def.innerType
|
|
2396
|
+
defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
|
2397
|
+
defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
|
2392
2398
|
inst._zod.parse = (payload, ctx) => {
|
|
2393
2399
|
if (ctx.direction === "backward") {
|
|
2394
2400
|
return def.innerType._zod.run(payload, ctx);
|
|
@@ -2436,6 +2442,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
2436
2442
|
}
|
|
2437
2443
|
}
|
|
2438
2444
|
|
|
2445
|
+
var _a;
|
|
2439
2446
|
class $ZodRegistry {
|
|
2440
2447
|
constructor() {
|
|
2441
2448
|
this._map = new WeakMap();
|
|
@@ -2485,7 +2492,8 @@ class $ZodRegistry {
|
|
|
2485
2492
|
function registry() {
|
|
2486
2493
|
return new $ZodRegistry();
|
|
2487
2494
|
}
|
|
2488
|
-
|
|
2495
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
2496
|
+
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2489
2497
|
|
|
2490
2498
|
function _string(Class, params) {
|
|
2491
2499
|
return new Class({
|
|
@@ -2897,6 +2905,10 @@ function _toLowerCase() {
|
|
|
2897
2905
|
function _toUpperCase() {
|
|
2898
2906
|
return _overwrite((input) => input.toUpperCase());
|
|
2899
2907
|
}
|
|
2908
|
+
// slugify
|
|
2909
|
+
function _slugify() {
|
|
2910
|
+
return _overwrite((input) => slugify(input));
|
|
2911
|
+
}
|
|
2900
2912
|
function _array(Class, element, params) {
|
|
2901
2913
|
return new Class({
|
|
2902
2914
|
type: "array",
|
|
@@ -3140,6 +3152,7 @@ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
|
|
|
3140
3152
|
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
3141
3153
|
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
3142
3154
|
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
3155
|
+
inst.slugify = () => inst.check(_slugify());
|
|
3143
3156
|
});
|
|
3144
3157
|
const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
|
|
3145
3158
|
$ZodString.init(inst, def);
|
|
@@ -4799,7 +4812,6 @@ class Route {
|
|
|
4799
4812
|
*/
|
|
4800
4813
|
key;
|
|
4801
4814
|
id;
|
|
4802
|
-
share = false;
|
|
4803
4815
|
run;
|
|
4804
4816
|
nextRoute; // route to run after this route
|
|
4805
4817
|
description;
|
|
@@ -5276,9 +5288,7 @@ class QueryRouter {
|
|
|
5276
5288
|
ctx.query = { ...ctx.query, ...query, ...payload };
|
|
5277
5289
|
ctx.state = { ...ctx?.state };
|
|
5278
5290
|
ctx.throw = this.throw;
|
|
5279
|
-
|
|
5280
|
-
// TODO: 是否需要queryRouter,函数内部处理router路由执行,这应该是避免去内部去包含的功能过
|
|
5281
|
-
ctx.queryRouter = this;
|
|
5291
|
+
ctx.app = this;
|
|
5282
5292
|
ctx.call = this.call.bind(this);
|
|
5283
5293
|
ctx.queryRoute = this.queryRoute.bind(this);
|
|
5284
5294
|
ctx.index = 0;
|
|
@@ -5299,7 +5309,11 @@ class QueryRouter {
|
|
|
5299
5309
|
async call(message, ctx) {
|
|
5300
5310
|
let path = message.path;
|
|
5301
5311
|
let key = message.key;
|
|
5302
|
-
|
|
5312
|
+
// 优先 path + key
|
|
5313
|
+
if (path) {
|
|
5314
|
+
return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
|
|
5315
|
+
}
|
|
5316
|
+
else if (message.id) {
|
|
5303
5317
|
const route = this.routes.find((r) => r.id === message.id);
|
|
5304
5318
|
if (route) {
|
|
5305
5319
|
path = route.path;
|
|
@@ -5310,9 +5324,6 @@ class QueryRouter {
|
|
|
5310
5324
|
}
|
|
5311
5325
|
return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
|
|
5312
5326
|
}
|
|
5313
|
-
else if (path) {
|
|
5314
|
-
return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
|
|
5315
|
-
}
|
|
5316
5327
|
else {
|
|
5317
5328
|
return { code: 404, body: null, message: 'Not found path' };
|
|
5318
5329
|
}
|
|
@@ -5324,7 +5335,7 @@ class QueryRouter {
|
|
|
5324
5335
|
* @returns
|
|
5325
5336
|
*/
|
|
5326
5337
|
async queryRoute(message, ctx) {
|
|
5327
|
-
const res = await this.
|
|
5338
|
+
const res = await this.call(message, { ...this.context, ...ctx });
|
|
5328
5339
|
return {
|
|
5329
5340
|
code: res.code,
|
|
5330
5341
|
data: res.body,
|
|
@@ -5394,6 +5405,19 @@ class QueryRouter {
|
|
|
5394
5405
|
hasRoute(path, key = '') {
|
|
5395
5406
|
return this.routes.find((r) => r.path === path && r.key === key);
|
|
5396
5407
|
}
|
|
5408
|
+
createRouteList(force = false) {
|
|
5409
|
+
const hasListRoute = this.hasRoute('route', 'list');
|
|
5410
|
+
if (!hasListRoute || force) {
|
|
5411
|
+
const listRoute = new Route('route', 'list', {
|
|
5412
|
+
description: '列出当前应用下的所有的路由信息',
|
|
5413
|
+
run: async (ctx) => {
|
|
5414
|
+
const list = this.getList();
|
|
5415
|
+
ctx.body = list;
|
|
5416
|
+
},
|
|
5417
|
+
});
|
|
5418
|
+
this.add(listRoute);
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5397
5421
|
/**
|
|
5398
5422
|
* 等待程序运行, 获取到message的数据,就执行
|
|
5399
5423
|
*
|
|
@@ -5403,6 +5427,10 @@ class QueryRouter {
|
|
|
5403
5427
|
* -- .send
|
|
5404
5428
|
*/
|
|
5405
5429
|
wait(params, opts) {
|
|
5430
|
+
const getList = opts?.getList ?? true;
|
|
5431
|
+
if (getList) {
|
|
5432
|
+
this.createRouteList();
|
|
5433
|
+
}
|
|
5406
5434
|
return listenProcess({ app: this, params, ...opts });
|
|
5407
5435
|
}
|
|
5408
5436
|
}
|