@kevisual/router 0.0.37 → 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/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.37",
4
+ "version": "0.0.38",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
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<T = {}> = {
66
+ export type RouteOpts<U = {}, T = SimpleObject> = {
67
67
  path?: string;
68
68
  key?: string;
69
69
  id?: string;
70
- run?: Run<T>;
70
+ run?: Run<U>;
71
71
  nextRoute?: NextRoute; // route to run after this route
72
72
  description?: string;
73
- metadata?: { [key: string]: any };
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?: { [key: string]: any };
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,7 +655,7 @@ export class QueryRouterServer extends QueryRouter {
655
655
  * @param param0
656
656
  * @returns
657
657
  */
658
- async run(msg: { id?: string; path?: string; key?: string; payload?: any }, ctx?: RouteContext & { [key: string]: any }) {
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
661
  const result = await this.call(msg, ctx);