@kevisual/router 0.0.15 → 0.0.16
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 +7 -2
- package/dist/router-browser.js +9 -1
- package/dist/router-define.d.ts +11 -6
- package/dist/router.d.ts +8 -3
- package/dist/router.js +9 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/route.ts +17 -3
- package/src/router-define.ts +3 -2
- package/src/test/define.ts +10 -0
package/dist/router-browser.d.ts
CHANGED
|
@@ -110,6 +110,11 @@ type RouteContext<T = {
|
|
|
110
110
|
} & T;
|
|
111
111
|
type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
112
112
|
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
|
113
|
+
type RouteMiddleware = {
|
|
114
|
+
path: string;
|
|
115
|
+
key?: string;
|
|
116
|
+
id?: string;
|
|
117
|
+
} | string;
|
|
113
118
|
type RouteOpts = {
|
|
114
119
|
path?: string;
|
|
115
120
|
key?: string;
|
|
@@ -120,7 +125,7 @@ type RouteOpts = {
|
|
|
120
125
|
metadata?: {
|
|
121
126
|
[key: string]: any;
|
|
122
127
|
};
|
|
123
|
-
middleware?:
|
|
128
|
+
middleware?: RouteMiddleware[];
|
|
124
129
|
type?: 'route' | 'middleware';
|
|
125
130
|
/**
|
|
126
131
|
* validator: {
|
|
@@ -171,7 +176,7 @@ declare class Route<U = {
|
|
|
171
176
|
metadata?: {
|
|
172
177
|
[key: string]: any;
|
|
173
178
|
};
|
|
174
|
-
middleware?:
|
|
179
|
+
middleware?: RouteMiddleware[];
|
|
175
180
|
type?: string;
|
|
176
181
|
private _validator?;
|
|
177
182
|
schema?: {
|
package/dist/router-browser.js
CHANGED
|
@@ -5911,7 +5911,15 @@ class QueryRouter {
|
|
|
5911
5911
|
route = this.routes.find((r) => r.id === item);
|
|
5912
5912
|
}
|
|
5913
5913
|
else {
|
|
5914
|
-
route = this.routes.find((r) =>
|
|
5914
|
+
route = this.routes.find((r) => {
|
|
5915
|
+
if (item.id) {
|
|
5916
|
+
return r.id === item.id;
|
|
5917
|
+
}
|
|
5918
|
+
else {
|
|
5919
|
+
// key 可以是空,所以可以不严格验证
|
|
5920
|
+
return r.path === item.path && r.key == item.key;
|
|
5921
|
+
}
|
|
5922
|
+
});
|
|
5915
5923
|
}
|
|
5916
5924
|
if (!route) {
|
|
5917
5925
|
if (isString) {
|
package/dist/router-define.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as node_modules_zod_lib_types_js from 'node_modules/zod/lib/types.js';
|
|
2
2
|
import { Schema } from 'zod';
|
|
3
3
|
|
|
4
4
|
type BaseRule = {
|
|
@@ -107,6 +107,11 @@ type RouteContext<T = {
|
|
|
107
107
|
} & T;
|
|
108
108
|
type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
109
109
|
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
|
110
|
+
type RouteMiddleware = {
|
|
111
|
+
path: string;
|
|
112
|
+
key?: string;
|
|
113
|
+
id?: string;
|
|
114
|
+
} | string;
|
|
110
115
|
type RouteOpts = {
|
|
111
116
|
path?: string;
|
|
112
117
|
key?: string;
|
|
@@ -117,7 +122,7 @@ type RouteOpts = {
|
|
|
117
122
|
metadata?: {
|
|
118
123
|
[key: string]: any;
|
|
119
124
|
};
|
|
120
|
-
middleware?:
|
|
125
|
+
middleware?: RouteMiddleware[];
|
|
121
126
|
type?: 'route' | 'middleware';
|
|
122
127
|
/**
|
|
123
128
|
* validator: {
|
|
@@ -168,7 +173,7 @@ declare class Route<U = {
|
|
|
168
173
|
metadata?: {
|
|
169
174
|
[key: string]: any;
|
|
170
175
|
};
|
|
171
|
-
middleware?:
|
|
176
|
+
middleware?: RouteMiddleware[];
|
|
172
177
|
type?: string;
|
|
173
178
|
private _validator?;
|
|
174
179
|
schema?: {
|
|
@@ -410,7 +415,7 @@ declare class Chain {
|
|
|
410
415
|
[key: string]: any;
|
|
411
416
|
}): this;
|
|
412
417
|
setPath(path: string): this;
|
|
413
|
-
setMiddleware(middleware:
|
|
418
|
+
setMiddleware(middleware: RouteMiddleware[]): this;
|
|
414
419
|
setKey(key: string): this;
|
|
415
420
|
setId(key: string): this;
|
|
416
421
|
setRun(run: Run): this;
|
|
@@ -438,13 +443,13 @@ declare class QueryUtil<T extends RouteObject = RouteObject> {
|
|
|
438
443
|
metadata?: {
|
|
439
444
|
[key: string]: any;
|
|
440
445
|
};
|
|
441
|
-
middleware?:
|
|
446
|
+
middleware?: RouteMiddleware[];
|
|
442
447
|
type?: "route" | "middleware";
|
|
443
448
|
validator?: {
|
|
444
449
|
[key: string]: Rule;
|
|
445
450
|
};
|
|
446
451
|
schema?: {
|
|
447
|
-
[key: string]:
|
|
452
|
+
[key: string]: node_modules_zod_lib_types_js.ZodType<any>;
|
|
448
453
|
};
|
|
449
454
|
isVerify?: boolean;
|
|
450
455
|
verify?: (ctx?: RouteContext, dev?: boolean) => boolean;
|
package/dist/router.d.ts
CHANGED
|
@@ -113,6 +113,11 @@ type RouteContext<T = {
|
|
|
113
113
|
} & T;
|
|
114
114
|
type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
115
115
|
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
|
116
|
+
type RouteMiddleware = {
|
|
117
|
+
path: string;
|
|
118
|
+
key?: string;
|
|
119
|
+
id?: string;
|
|
120
|
+
} | string;
|
|
116
121
|
type RouteOpts = {
|
|
117
122
|
path?: string;
|
|
118
123
|
key?: string;
|
|
@@ -123,7 +128,7 @@ type RouteOpts = {
|
|
|
123
128
|
metadata?: {
|
|
124
129
|
[key: string]: any;
|
|
125
130
|
};
|
|
126
|
-
middleware?:
|
|
131
|
+
middleware?: RouteMiddleware[];
|
|
127
132
|
type?: 'route' | 'middleware';
|
|
128
133
|
/**
|
|
129
134
|
* validator: {
|
|
@@ -174,7 +179,7 @@ declare class Route<U = {
|
|
|
174
179
|
metadata?: {
|
|
175
180
|
[key: string]: any;
|
|
176
181
|
};
|
|
177
|
-
middleware?:
|
|
182
|
+
middleware?: RouteMiddleware[];
|
|
178
183
|
type?: string;
|
|
179
184
|
private _validator?;
|
|
180
185
|
schema?: {
|
|
@@ -643,4 +648,4 @@ declare class App<T = {}, U = AppReqRes> {
|
|
|
643
648
|
}
|
|
644
649
|
|
|
645
650
|
export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, Route, Server, createSchema, handleServer };
|
|
646
|
-
export type { RouteContext, RouteOpts, Rule, Run };
|
|
651
|
+
export type { RouteContext, RouteMiddleware, RouteOpts, Rule, Run };
|
package/dist/router.js
CHANGED
|
@@ -5933,7 +5933,15 @@ class QueryRouter {
|
|
|
5933
5933
|
route = this.routes.find((r) => r.id === item);
|
|
5934
5934
|
}
|
|
5935
5935
|
else {
|
|
5936
|
-
route = this.routes.find((r) =>
|
|
5936
|
+
route = this.routes.find((r) => {
|
|
5937
|
+
if (item.id) {
|
|
5938
|
+
return r.id === item.id;
|
|
5939
|
+
}
|
|
5940
|
+
else {
|
|
5941
|
+
// key 可以是空,所以可以不严格验证
|
|
5942
|
+
return r.path === item.path && r.key == item.key;
|
|
5943
|
+
}
|
|
5944
|
+
});
|
|
5937
5945
|
}
|
|
5938
5946
|
if (!route) {
|
|
5939
5947
|
if (isString) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Route, QueryRouter, QueryRouterServer } from './route.ts';
|
|
2
2
|
export { Connect, QueryConnect } from './connect.ts';
|
|
3
3
|
|
|
4
|
-
export type { RouteContext, RouteOpts } from './route.ts';
|
|
4
|
+
export type { RouteContext, RouteOpts, RouteMiddleware } from './route.ts';
|
|
5
5
|
|
|
6
6
|
export type { Run } from './route.ts';
|
|
7
7
|
|
package/src/route.ts
CHANGED
|
@@ -61,6 +61,13 @@ export type RouteContext<T = { code?: number }, S = any> = {
|
|
|
61
61
|
export type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
|
|
62
62
|
|
|
63
63
|
export type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
|
64
|
+
export type RouteMiddleware =
|
|
65
|
+
| {
|
|
66
|
+
path: string;
|
|
67
|
+
key?: string;
|
|
68
|
+
id?: string;
|
|
69
|
+
}
|
|
70
|
+
| string;
|
|
64
71
|
export type RouteOpts = {
|
|
65
72
|
path?: string;
|
|
66
73
|
key?: string;
|
|
@@ -69,7 +76,7 @@ export type RouteOpts = {
|
|
|
69
76
|
nextRoute?: NextRoute; // route to run after this route
|
|
70
77
|
description?: string;
|
|
71
78
|
metadata?: { [key: string]: any };
|
|
72
|
-
middleware?:
|
|
79
|
+
middleware?: RouteMiddleware[]; // middleware
|
|
73
80
|
type?: 'route' | 'middleware';
|
|
74
81
|
/**
|
|
75
82
|
* validator: {
|
|
@@ -112,7 +119,7 @@ export class Route<U = { [key: string]: any }> {
|
|
|
112
119
|
nextRoute?: NextRoute; // route to run after this route
|
|
113
120
|
description?: string;
|
|
114
121
|
metadata?: { [key: string]: any };
|
|
115
|
-
middleware?:
|
|
122
|
+
middleware?: RouteMiddleware[]; // middleware
|
|
116
123
|
type? = 'route';
|
|
117
124
|
private _validator?: { [key: string]: Rule };
|
|
118
125
|
schema?: { [key: string]: Schema<any> };
|
|
@@ -379,7 +386,14 @@ export class QueryRouter {
|
|
|
379
386
|
if (isString) {
|
|
380
387
|
route = this.routes.find((r) => r.id === item);
|
|
381
388
|
} else {
|
|
382
|
-
route = this.routes.find((r) =>
|
|
389
|
+
route = this.routes.find((r) => {
|
|
390
|
+
if (item.id) {
|
|
391
|
+
return r.id === item.id;
|
|
392
|
+
} else {
|
|
393
|
+
// key 可以是空,所以可以不严格验证
|
|
394
|
+
return r.path === item.path && r.key == item.key;
|
|
395
|
+
}
|
|
396
|
+
});
|
|
383
397
|
}
|
|
384
398
|
if (!route) {
|
|
385
399
|
if (isString) {
|
package/src/router-define.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { QueryRouterServer, Route, RouteOpts, Run } from '
|
|
1
|
+
// import type { QueryRouterServer, Route, RouteOpts, Run } from '@kevisual/router';
|
|
2
|
+
import type { QueryRouterServer, RouteOpts, Run, RouteMiddleware } from './index.ts';
|
|
2
3
|
|
|
3
4
|
// export type RouteObject<T extends readonly string[]> = {
|
|
4
5
|
// [K in T[number]]: RouteOpts;
|
|
@@ -45,7 +46,7 @@ class Chain {
|
|
|
45
46
|
this.object.path = path;
|
|
46
47
|
return this;
|
|
47
48
|
}
|
|
48
|
-
setMiddleware(middleware:
|
|
49
|
+
setMiddleware(middleware: RouteMiddleware[]) {
|
|
49
50
|
this.object.middleware = middleware;
|
|
50
51
|
return this;
|
|
51
52
|
}
|