@kevisual/router 0.0.36 → 0.0.38
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 +11 -14
- package/dist/router-browser.js +688 -17
- package/dist/router-sign.js +3 -1
- package/dist/router.d.ts +18 -16
- package/dist/router.js +690 -19
- package/package.json +2 -2
- package/src/app.ts +2 -2
- package/src/route.ts +11 -11
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@kevisual/router",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.38",
|
|
5
5
|
"description": "",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/router.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
29
29
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
30
30
|
"@types/lodash-es": "^4.17.12",
|
|
31
|
-
"@types/node": "^24.10.
|
|
31
|
+
"@types/node": "^24.10.2",
|
|
32
32
|
"@types/send": "^1.2.1",
|
|
33
33
|
"@types/ws": "^8.18.1",
|
|
34
34
|
"@types/xml2js": "^0.4.14",
|
package/src/app.ts
CHANGED
|
@@ -107,8 +107,8 @@ export class App<U = {}> {
|
|
|
107
107
|
async queryRoute(path: string, key?: string, payload?: any, ctx?: AppRouteContext<U> & { [key: string]: any }) {
|
|
108
108
|
return await this.router.queryRoute({ path, key, payload }, ctx);
|
|
109
109
|
}
|
|
110
|
-
async run(
|
|
111
|
-
return await this.router.run(
|
|
110
|
+
async run(msg: { id?: string, path?: string; key?: string; payload?: any }, ctx?: AppRouteContext<U> & { [key: string]: any }) {
|
|
111
|
+
return await this.router.run(msg, ctx);
|
|
112
112
|
}
|
|
113
113
|
exportRoutes() {
|
|
114
114
|
return this.router.exportRoutes();
|
package/src/route.ts
CHANGED
|
@@ -63,14 +63,14 @@ export type RouteMiddleware =
|
|
|
63
63
|
id?: string;
|
|
64
64
|
}
|
|
65
65
|
| string;
|
|
66
|
-
export type RouteOpts<
|
|
66
|
+
export type RouteOpts<U = {}, T = SimpleObject> = {
|
|
67
67
|
path?: string;
|
|
68
68
|
key?: string;
|
|
69
69
|
id?: string;
|
|
70
|
-
run?: Run<
|
|
70
|
+
run?: Run<U>;
|
|
71
71
|
nextRoute?: NextRoute; // route to run after this route
|
|
72
72
|
description?: string;
|
|
73
|
-
metadata?:
|
|
73
|
+
metadata?: T;
|
|
74
74
|
middleware?: RouteMiddleware[]; // middleware
|
|
75
75
|
type?: 'route' | 'middleware';
|
|
76
76
|
/**
|
|
@@ -86,7 +86,7 @@ export type RouteOpts<T = {}> = {
|
|
|
86
86
|
export type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
87
87
|
const pickValue = ['path', 'key', 'id', 'description', 'type', 'middleware', 'metadata'] as const;
|
|
88
88
|
export type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
89
|
-
export class Route<U = { [key: string]: any }> {
|
|
89
|
+
export class Route<U = { [key: string]: any }, T extends SimpleObject =SimpleObject> {
|
|
90
90
|
/**
|
|
91
91
|
* 一级路径
|
|
92
92
|
*/
|
|
@@ -99,7 +99,7 @@ export class Route<U = { [key: string]: any }> {
|
|
|
99
99
|
run?: Run;
|
|
100
100
|
nextRoute?: NextRoute; // route to run after this route
|
|
101
101
|
description?: string;
|
|
102
|
-
metadata?:
|
|
102
|
+
metadata?: T;
|
|
103
103
|
middleware?: RouteMiddleware[]; // middleware
|
|
104
104
|
type? = 'route';
|
|
105
105
|
data?: any;
|
|
@@ -124,7 +124,7 @@ export class Route<U = { [key: string]: any }> {
|
|
|
124
124
|
this.run = opts.run;
|
|
125
125
|
this.nextRoute = opts.nextRoute;
|
|
126
126
|
this.description = opts.description;
|
|
127
|
-
this.metadata = opts.metadata;
|
|
127
|
+
this.metadata = opts.metadata as T;
|
|
128
128
|
this.type = opts.type || 'route';
|
|
129
129
|
this.middleware = opts.middleware || [];
|
|
130
130
|
this.key = opts.key || key;
|
|
@@ -511,8 +511,8 @@ export class QueryRouter {
|
|
|
511
511
|
setContext(ctx: RouteContext) {
|
|
512
512
|
this.context = ctx;
|
|
513
513
|
}
|
|
514
|
-
getList(): RouteInfo[] {
|
|
515
|
-
return this.routes.map((r) => {
|
|
514
|
+
getList(filter?: (route: Route) => boolean): RouteInfo[] {
|
|
515
|
+
return this.routes.filter(filter || (() => true)).map((r) => {
|
|
516
516
|
return pick(r, pickValue as any);
|
|
517
517
|
});
|
|
518
518
|
}
|
|
@@ -655,13 +655,13 @@ export class QueryRouterServer extends QueryRouter {
|
|
|
655
655
|
* @param param0
|
|
656
656
|
* @returns
|
|
657
657
|
*/
|
|
658
|
-
async run({
|
|
658
|
+
async run(msg: { id?: string; path?: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) {
|
|
659
659
|
const handle = this.handle;
|
|
660
660
|
if (handle) {
|
|
661
|
-
const result = await this.call(
|
|
661
|
+
const result = await this.call(msg, ctx);
|
|
662
662
|
return handle(result);
|
|
663
663
|
}
|
|
664
|
-
return super.run(
|
|
664
|
+
return super.run(msg, ctx);
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
667
|
|