@kevisual/router 0.1.6 → 0.2.2
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/{readme.md → README.md} +9 -9
- package/dist/app.js +30 -30
- package/dist/commander.d.ts +9 -9
- package/dist/commander.js +1 -0
- package/dist/opencode.d.ts +9 -9
- package/dist/opencode.js +2 -2
- package/dist/router-browser.d.ts +10 -10
- package/dist/router-browser.js +29 -29
- package/dist/router-define.d.ts +10 -10
- package/dist/router-define.js +2 -2
- package/dist/router.d.ts +10 -10
- package/dist/router.js +29 -29
- package/dist/ws.d.ts +9 -9
- package/package.json +4 -4
- package/src/commander.ts +1 -0
- package/src/opencode.ts +2 -2
- package/src/route.ts +34 -34
- package/src/router-define.ts +2 -2
package/{readme.md → README.md}
RENAMED
|
@@ -55,7 +55,7 @@ app
|
|
|
55
55
|
|
|
56
56
|
| 方法 | 参数 | 说明 |
|
|
57
57
|
| ----------------------------------- | ----------------------------------------- | -------------------------------------------- |
|
|
58
|
-
| `ctx.call(msg, ctx?)` | `{ path, key?, payload?, ... } \| {
|
|
58
|
+
| `ctx.call(msg, ctx?)` | `{ path, key?, payload?, ... } \| { rid }` | 调用其他路由,返回完整 context |
|
|
59
59
|
| `ctx.run(msg, ctx?)` | `{ path, key?, payload? }` | 调用其他路由,返回 `{ code, data, message }` |
|
|
60
60
|
| `ctx.forward(res)` | `{ code, data?, message? }` | 设置响应结果 |
|
|
61
61
|
| `ctx.throw(code?, message?, tips?)` | - | 抛出自定义错误 |
|
|
@@ -64,13 +64,13 @@ app
|
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
66
|
import { App } from '@kevisual/router';
|
|
67
|
-
import z from 'zod';
|
|
67
|
+
import { z } from 'zod';
|
|
68
68
|
const app = new App();
|
|
69
69
|
app.listen(4002);
|
|
70
70
|
|
|
71
71
|
// 基本路由
|
|
72
72
|
app
|
|
73
|
-
.route({ path: 'user', key: 'info',
|
|
73
|
+
.route({ path: 'user', key: 'info', rid: 'user-info' })
|
|
74
74
|
.define(async (ctx) => {
|
|
75
75
|
// ctx.query 包含请求参数
|
|
76
76
|
const { id } = ctx.query;
|
|
@@ -129,7 +129,7 @@ const app = new App();
|
|
|
129
129
|
// 定义中间件
|
|
130
130
|
app
|
|
131
131
|
.route({
|
|
132
|
-
|
|
132
|
+
rid: 'auth-example',
|
|
133
133
|
description: '权限校验中间件',
|
|
134
134
|
})
|
|
135
135
|
.define(async (ctx) => {
|
|
@@ -142,7 +142,7 @@ app
|
|
|
142
142
|
})
|
|
143
143
|
.addTo(app);
|
|
144
144
|
|
|
145
|
-
// 使用中间件(通过
|
|
145
|
+
// 使用中间件(通过 rid 引用)
|
|
146
146
|
app
|
|
147
147
|
.route({ path: 'admin', key: 'panel', middleware: ['auth-example'] })
|
|
148
148
|
.define(async (ctx) => {
|
|
@@ -164,17 +164,17 @@ app
|
|
|
164
164
|
path: 'dog',
|
|
165
165
|
key: 'info',
|
|
166
166
|
description: '获取狗的信息',
|
|
167
|
-
|
|
167
|
+
metadata: {
|
|
168
168
|
args: {
|
|
169
|
-
|
|
169
|
+
name: z.string().describe('狗的姓名'),
|
|
170
170
|
age: z.number().describe('狗的年龄'),
|
|
171
171
|
},
|
|
172
172
|
},
|
|
173
173
|
})
|
|
174
174
|
.define(async (ctx) => {
|
|
175
|
-
const {
|
|
175
|
+
const { name, age } = ctx.query;
|
|
176
176
|
ctx.body = {
|
|
177
|
-
content: `这是一只${age}
|
|
177
|
+
content: `这是一只${age}岁的狗,名字是${name}`,
|
|
178
178
|
};
|
|
179
179
|
})
|
|
180
180
|
.addTo(app);
|
package/dist/app.js
CHANGED
|
@@ -17387,7 +17387,7 @@ var fromJSONSchema2 = (args = {}, opts) => {
|
|
|
17387
17387
|
};
|
|
17388
17388
|
|
|
17389
17389
|
// src/route.ts
|
|
17390
|
-
var pickValue = ["path", "key", "
|
|
17390
|
+
var pickValue = ["path", "key", "rid", "description", "type", "middleware", "metadata"];
|
|
17391
17391
|
var tool = {
|
|
17392
17392
|
schema: exports_external
|
|
17393
17393
|
};
|
|
@@ -17407,7 +17407,7 @@ var createSkill = (skill) => {
|
|
|
17407
17407
|
class Route {
|
|
17408
17408
|
path;
|
|
17409
17409
|
key;
|
|
17410
|
-
|
|
17410
|
+
rid;
|
|
17411
17411
|
run;
|
|
17412
17412
|
nextRoute;
|
|
17413
17413
|
description;
|
|
@@ -17425,7 +17425,7 @@ class Route {
|
|
|
17425
17425
|
this.key = key;
|
|
17426
17426
|
const pathKey = `${path}$$${key}`;
|
|
17427
17427
|
if (opts) {
|
|
17428
|
-
this.
|
|
17428
|
+
this.rid = opts.rid || hashIdMd5Sync(pathKey);
|
|
17429
17429
|
this.run = opts.run;
|
|
17430
17430
|
this.nextRoute = opts.nextRoute;
|
|
17431
17431
|
this.description = opts.description;
|
|
@@ -17437,8 +17437,8 @@ class Route {
|
|
|
17437
17437
|
} else {
|
|
17438
17438
|
this.middleware = [];
|
|
17439
17439
|
}
|
|
17440
|
-
if (!this.
|
|
17441
|
-
this.
|
|
17440
|
+
if (!this.rid) {
|
|
17441
|
+
this.rid = hashIdMd5Sync(pathKey);
|
|
17442
17442
|
}
|
|
17443
17443
|
this.isDebug = opts?.isDebug ?? false;
|
|
17444
17444
|
}
|
|
@@ -17544,14 +17544,14 @@ class QueryRouter {
|
|
|
17544
17544
|
this.routes = this.routes.filter((r) => r.path === route.path && r.key == route.key);
|
|
17545
17545
|
}
|
|
17546
17546
|
removeById(uniqueId) {
|
|
17547
|
-
this.routes = this.routes.filter((r) => r.
|
|
17547
|
+
this.routes = this.routes.filter((r) => r.rid !== uniqueId);
|
|
17548
17548
|
}
|
|
17549
17549
|
async runRoute(path, key, ctx) {
|
|
17550
17550
|
const route = this.routes.find((r) => r.path === path && r.key === key);
|
|
17551
17551
|
const maxNextRoute = this.maxNextRoute;
|
|
17552
17552
|
ctx = ctx || {};
|
|
17553
17553
|
ctx.currentPath = path;
|
|
17554
|
-
ctx.currentId = route?.
|
|
17554
|
+
ctx.currentId = route?.rid;
|
|
17555
17555
|
ctx.currentKey = key;
|
|
17556
17556
|
ctx.currentRoute = route;
|
|
17557
17557
|
ctx.index = (ctx.index || 0) + 1;
|
|
@@ -17578,11 +17578,11 @@ class QueryRouter {
|
|
|
17578
17578
|
let route2;
|
|
17579
17579
|
const isString2 = typeof item === "string";
|
|
17580
17580
|
if (isString2) {
|
|
17581
|
-
route2 = this.routes.find((r) => r.
|
|
17581
|
+
route2 = this.routes.find((r) => r.rid === item);
|
|
17582
17582
|
} else {
|
|
17583
17583
|
route2 = this.routes.find((r) => {
|
|
17584
|
-
if (item.
|
|
17585
|
-
return r.
|
|
17584
|
+
if (item.rid) {
|
|
17585
|
+
return r.rid === item.rid;
|
|
17586
17586
|
} else {
|
|
17587
17587
|
return r.path === item.path && r.key == item.key;
|
|
17588
17588
|
}
|
|
@@ -17631,8 +17631,8 @@ class QueryRouter {
|
|
|
17631
17631
|
ctx.message = e.message;
|
|
17632
17632
|
ctx.body = null;
|
|
17633
17633
|
} else {
|
|
17634
|
-
console.error(`[router error] fn:${route.path}-${route.key}:${route.
|
|
17635
|
-
console.error(`[router error] middleware:${middleware.path}-${middleware.key}:${middleware.
|
|
17634
|
+
console.error(`[router error] fn:${route.path}-${route.key}:${route.rid}`);
|
|
17635
|
+
console.error(`[router error] middleware:${middleware.path}-${middleware.key}:${middleware.rid}`);
|
|
17636
17636
|
console.error(e);
|
|
17637
17637
|
ctx.code = 500;
|
|
17638
17638
|
ctx.message = "Internal Server Error";
|
|
@@ -17660,7 +17660,7 @@ class QueryRouter {
|
|
|
17660
17660
|
ctx.code = e.code;
|
|
17661
17661
|
ctx.message = e.message;
|
|
17662
17662
|
} else {
|
|
17663
|
-
console.error(`[router error] fn:${route.path}-${route.key}:${route.
|
|
17663
|
+
console.error(`[router error] fn:${route.path}-${route.key}:${route.rid}`);
|
|
17664
17664
|
console.error(`[router error] error`, e);
|
|
17665
17665
|
ctx.code = 500;
|
|
17666
17666
|
ctx.message = "Internal Server Error";
|
|
@@ -17676,8 +17676,8 @@ class QueryRouter {
|
|
|
17676
17676
|
if (route.nextRoute.path || route.nextRoute.key) {
|
|
17677
17677
|
path2 = route.nextRoute.path;
|
|
17678
17678
|
key2 = route.nextRoute.key;
|
|
17679
|
-
} else if (route.nextRoute.
|
|
17680
|
-
const nextRoute = this.routes.find((r) => r.
|
|
17679
|
+
} else if (route.nextRoute.rid) {
|
|
17680
|
+
const nextRoute = this.routes.find((r) => r.rid === route.nextRoute.rid);
|
|
17681
17681
|
if (nextRoute) {
|
|
17682
17682
|
path2 = nextRoute.path;
|
|
17683
17683
|
key2 = nextRoute.key;
|
|
@@ -17741,8 +17741,8 @@ class QueryRouter {
|
|
|
17741
17741
|
let key = message.key;
|
|
17742
17742
|
if (path) {
|
|
17743
17743
|
return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
|
|
17744
|
-
} else if (message.
|
|
17745
|
-
const route = this.routes.find((r) => r.
|
|
17744
|
+
} else if (message.rid) {
|
|
17745
|
+
const route = this.routes.find((r) => r.rid === message.rid);
|
|
17746
17746
|
if (route) {
|
|
17747
17747
|
path = route.path;
|
|
17748
17748
|
key = route.key;
|
|
@@ -17815,10 +17815,10 @@ class QueryRouter {
|
|
|
17815
17815
|
return this.routes.find((r) => r.path === path && r.key === key);
|
|
17816
17816
|
}
|
|
17817
17817
|
findRoute(opts) {
|
|
17818
|
-
const { path, key,
|
|
17818
|
+
const { path, key, rid } = opts || {};
|
|
17819
17819
|
return this.routes.find((r) => {
|
|
17820
|
-
if (
|
|
17821
|
-
return r.
|
|
17820
|
+
if (rid) {
|
|
17821
|
+
return r.rid === rid;
|
|
17822
17822
|
}
|
|
17823
17823
|
if (path) {
|
|
17824
17824
|
if (key !== undefined) {
|
|
@@ -17839,14 +17839,14 @@ class QueryRouter {
|
|
|
17839
17839
|
const tokenUser = ctx.state;
|
|
17840
17840
|
let isUser = !!tokenUser;
|
|
17841
17841
|
const list = this.getList(opts?.filter).filter((item) => {
|
|
17842
|
-
if (item.
|
|
17842
|
+
if (item.rid === "auth" || item.rid === "auth-can" || item.rid === "check-auth-admin" || item.rid === "auth-admin") {
|
|
17843
17843
|
return false;
|
|
17844
17844
|
}
|
|
17845
17845
|
return true;
|
|
17846
17846
|
});
|
|
17847
17847
|
ctx.body = {
|
|
17848
17848
|
list: list.map((item) => {
|
|
17849
|
-
const route = pick(item, ["
|
|
17849
|
+
const route = pick(item, ["rid", "path", "key", "description", "middleware", "metadata"]);
|
|
17850
17850
|
return toJSONSchemaRoute(route);
|
|
17851
17851
|
}),
|
|
17852
17852
|
isUser
|
|
@@ -17916,14 +17916,14 @@ class QueryRouterServer extends QueryRouter {
|
|
|
17916
17916
|
return super.run(msg, ctx);
|
|
17917
17917
|
}
|
|
17918
17918
|
async runAction(api2, payload, ctx) {
|
|
17919
|
-
const { path, key,
|
|
17920
|
-
return this.run({ path, key,
|
|
17919
|
+
const { path, key, rid } = api2;
|
|
17920
|
+
return this.run({ path, key, rid, payload }, ctx);
|
|
17921
17921
|
}
|
|
17922
17922
|
async createAuth(fun) {
|
|
17923
17923
|
this.route({
|
|
17924
17924
|
path: "auth",
|
|
17925
17925
|
key: "auth",
|
|
17926
|
-
|
|
17926
|
+
rid: "auth",
|
|
17927
17927
|
description: "token验证"
|
|
17928
17928
|
}).define(async (ctx) => {
|
|
17929
17929
|
if (fun) {
|
|
@@ -17933,7 +17933,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
17933
17933
|
this.route({
|
|
17934
17934
|
path: "auth-admin",
|
|
17935
17935
|
key: "auth-admin",
|
|
17936
|
-
|
|
17936
|
+
rid: "auth-admin",
|
|
17937
17937
|
description: "admin token验证",
|
|
17938
17938
|
middleware: ["auth"]
|
|
17939
17939
|
}).define(async (ctx) => {
|
|
@@ -17944,7 +17944,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
17944
17944
|
this.route({
|
|
17945
17945
|
path: "auth-can",
|
|
17946
17946
|
key: "auth-can",
|
|
17947
|
-
|
|
17947
|
+
rid: "auth-can",
|
|
17948
17948
|
description: "权限验证"
|
|
17949
17949
|
}).define(async (ctx) => {
|
|
17950
17950
|
if (fun) {
|
|
@@ -19848,10 +19848,10 @@ var createRouterAgentPluginFn = (opts) => {
|
|
|
19848
19848
|
addCallFn(router);
|
|
19849
19849
|
}
|
|
19850
19850
|
if (router) {
|
|
19851
|
-
router.route({ path: "auth", key: "",
|
|
19851
|
+
router.route({ path: "auth", key: "", rid: "auth", description: "认证" }).define(async (ctx) => {}).addTo(router, {
|
|
19852
19852
|
overwrite: false
|
|
19853
19853
|
});
|
|
19854
|
-
router.route({ path: "auth-admin", key: "",
|
|
19854
|
+
router.route({ path: "auth-admin", key: "", rid: "auth-admin", description: "认证" }).define(async (ctx) => {}).addTo(router, {
|
|
19855
19855
|
overwrite: false
|
|
19856
19856
|
});
|
|
19857
19857
|
}
|
|
@@ -20108,7 +20108,7 @@ app
|
|
|
20108
20108
|
10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
|
|
20109
20109
|
`;
|
|
20110
20110
|
// package.json
|
|
20111
|
-
var version2 = "0.1
|
|
20111
|
+
var version2 = "0.2.1";
|
|
20112
20112
|
|
|
20113
20113
|
// agent/routes/route-create.ts
|
|
20114
20114
|
app.route({
|
package/dist/commander.d.ts
CHANGED
|
@@ -131,16 +131,16 @@ type RunMessage = {
|
|
|
131
131
|
id?: string;
|
|
132
132
|
payload?: any;
|
|
133
133
|
};
|
|
134
|
-
type NextRoute = Pick<Route, '
|
|
134
|
+
type NextRoute = Pick<Route, 'rid' | 'path' | 'key'>;
|
|
135
135
|
type RouteMiddleware = {
|
|
136
136
|
path?: string;
|
|
137
137
|
key?: string;
|
|
138
|
-
|
|
138
|
+
rid?: string;
|
|
139
139
|
} | string;
|
|
140
140
|
type RouteOpts<U = {}, T = SimpleObject> = {
|
|
141
141
|
path?: string;
|
|
142
142
|
key?: string;
|
|
143
|
-
|
|
143
|
+
rid?: string;
|
|
144
144
|
run?: Run<U>;
|
|
145
145
|
nextRoute?: NextRoute;
|
|
146
146
|
description?: string;
|
|
@@ -150,7 +150,7 @@ type RouteOpts<U = {}, T = SimpleObject> = {
|
|
|
150
150
|
isDebug?: boolean;
|
|
151
151
|
};
|
|
152
152
|
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
153
|
-
declare const pickValue: readonly ["path", "key", "
|
|
153
|
+
declare const pickValue: readonly ["path", "key", "rid", "description", "type", "middleware", "metadata"];
|
|
154
154
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
155
155
|
/**
|
|
156
156
|
* @M 是 route的 metadate的类型,默认是 SimpleObject
|
|
@@ -165,7 +165,7 @@ declare class Route<M extends SimpleObject = SimpleObject, U extends SimpleObjec
|
|
|
165
165
|
* 二级路径
|
|
166
166
|
*/
|
|
167
167
|
key?: string;
|
|
168
|
-
|
|
168
|
+
rid?: string;
|
|
169
169
|
run?: Run<BuildRouteContext<M, U>>;
|
|
170
170
|
nextRoute?: NextRoute;
|
|
171
171
|
description?: string;
|
|
@@ -259,7 +259,7 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
|
|
|
259
259
|
* @returns
|
|
260
260
|
*/
|
|
261
261
|
call(message: {
|
|
262
|
-
|
|
262
|
+
rid?: string;
|
|
263
263
|
path?: string;
|
|
264
264
|
key?: string;
|
|
265
265
|
payload?: any;
|
|
@@ -346,7 +346,7 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
|
|
|
346
346
|
findRoute(opts?: {
|
|
347
347
|
path?: string;
|
|
348
348
|
key?: string;
|
|
349
|
-
|
|
349
|
+
rid?: string;
|
|
350
350
|
}): Route<SimpleObject, SimpleObject>;
|
|
351
351
|
createRouteList(opts?: {
|
|
352
352
|
force?: boolean;
|
|
@@ -437,7 +437,7 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
437
437
|
* @returns
|
|
438
438
|
*/
|
|
439
439
|
run(msg: {
|
|
440
|
-
|
|
440
|
+
rid?: string;
|
|
441
441
|
path?: string;
|
|
442
442
|
key?: string;
|
|
443
443
|
payload?: any;
|
|
@@ -445,7 +445,7 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
445
445
|
data?: any;
|
|
446
446
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
447
447
|
runAction<T extends {
|
|
448
|
-
|
|
448
|
+
rid?: string;
|
|
449
449
|
path?: string;
|
|
450
450
|
key?: string;
|
|
451
451
|
metadata?: {
|
package/dist/commander.js
CHANGED
|
@@ -16298,6 +16298,7 @@ var parse5 = async (opts) => {
|
|
|
16298
16298
|
if (opts.remote) {
|
|
16299
16299
|
const { token, username, id } = opts.remote;
|
|
16300
16300
|
const remoteApp = new RemoteApp({
|
|
16301
|
+
app,
|
|
16301
16302
|
token,
|
|
16302
16303
|
username,
|
|
16303
16304
|
id
|
package/dist/opencode.d.ts
CHANGED
|
@@ -131,16 +131,16 @@ type RunMessage = {
|
|
|
131
131
|
id?: string;
|
|
132
132
|
payload?: any;
|
|
133
133
|
};
|
|
134
|
-
type NextRoute = Pick<Route, '
|
|
134
|
+
type NextRoute = Pick<Route, 'rid' | 'path' | 'key'>;
|
|
135
135
|
type RouteMiddleware = {
|
|
136
136
|
path?: string;
|
|
137
137
|
key?: string;
|
|
138
|
-
|
|
138
|
+
rid?: string;
|
|
139
139
|
} | string;
|
|
140
140
|
type RouteOpts<U = {}, T = SimpleObject> = {
|
|
141
141
|
path?: string;
|
|
142
142
|
key?: string;
|
|
143
|
-
|
|
143
|
+
rid?: string;
|
|
144
144
|
run?: Run<U>;
|
|
145
145
|
nextRoute?: NextRoute;
|
|
146
146
|
description?: string;
|
|
@@ -150,7 +150,7 @@ type RouteOpts<U = {}, T = SimpleObject> = {
|
|
|
150
150
|
isDebug?: boolean;
|
|
151
151
|
};
|
|
152
152
|
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
153
|
-
declare const pickValue: readonly ["path", "key", "
|
|
153
|
+
declare const pickValue: readonly ["path", "key", "rid", "description", "type", "middleware", "metadata"];
|
|
154
154
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
155
155
|
/**
|
|
156
156
|
* @M 是 route的 metadate的类型,默认是 SimpleObject
|
|
@@ -165,7 +165,7 @@ declare class Route<M extends SimpleObject = SimpleObject, U extends SimpleObjec
|
|
|
165
165
|
* 二级路径
|
|
166
166
|
*/
|
|
167
167
|
key?: string;
|
|
168
|
-
|
|
168
|
+
rid?: string;
|
|
169
169
|
run?: Run<BuildRouteContext<M, U>>;
|
|
170
170
|
nextRoute?: NextRoute;
|
|
171
171
|
description?: string;
|
|
@@ -259,7 +259,7 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
|
|
|
259
259
|
* @returns
|
|
260
260
|
*/
|
|
261
261
|
call(message: {
|
|
262
|
-
|
|
262
|
+
rid?: string;
|
|
263
263
|
path?: string;
|
|
264
264
|
key?: string;
|
|
265
265
|
payload?: any;
|
|
@@ -346,7 +346,7 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
|
|
|
346
346
|
findRoute(opts?: {
|
|
347
347
|
path?: string;
|
|
348
348
|
key?: string;
|
|
349
|
-
|
|
349
|
+
rid?: string;
|
|
350
350
|
}): Route<SimpleObject, SimpleObject>;
|
|
351
351
|
createRouteList(opts?: {
|
|
352
352
|
force?: boolean;
|
|
@@ -437,7 +437,7 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
437
437
|
* @returns
|
|
438
438
|
*/
|
|
439
439
|
run(msg: {
|
|
440
|
-
|
|
440
|
+
rid?: string;
|
|
441
441
|
path?: string;
|
|
442
442
|
key?: string;
|
|
443
443
|
payload?: any;
|
|
@@ -445,7 +445,7 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
|
|
|
445
445
|
data?: any;
|
|
446
446
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
447
447
|
runAction<T extends {
|
|
448
|
-
|
|
448
|
+
rid?: string;
|
|
449
449
|
path?: string;
|
|
450
450
|
key?: string;
|
|
451
451
|
metadata?: {
|
package/dist/opencode.js
CHANGED
|
@@ -15229,10 +15229,10 @@ var createRouterAgentPluginFn = (opts) => {
|
|
|
15229
15229
|
addCallFn(router);
|
|
15230
15230
|
}
|
|
15231
15231
|
if (router) {
|
|
15232
|
-
router.route({ path: "auth", key: "",
|
|
15232
|
+
router.route({ path: "auth", key: "", rid: "auth", description: "认证" }).define(async (ctx) => {}).addTo(router, {
|
|
15233
15233
|
overwrite: false
|
|
15234
15234
|
});
|
|
15235
|
-
router.route({ path: "auth-admin", key: "",
|
|
15235
|
+
router.route({ path: "auth-admin", key: "", rid: "auth-admin", description: "认证" }).define(async (ctx) => {}).addTo(router, {
|
|
15236
15236
|
overwrite: false
|
|
15237
15237
|
});
|
|
15238
15238
|
}
|
package/dist/router-browser.d.ts
CHANGED
|
@@ -172,16 +172,16 @@ type RunMessage = {
|
|
|
172
172
|
id?: string;
|
|
173
173
|
payload?: any;
|
|
174
174
|
};
|
|
175
|
-
type NextRoute = Pick<Route, '
|
|
175
|
+
type NextRoute = Pick<Route, 'rid' | 'path' | 'key'>;
|
|
176
176
|
type RouteMiddleware = {
|
|
177
177
|
path?: string;
|
|
178
178
|
key?: string;
|
|
179
|
-
|
|
179
|
+
rid?: string;
|
|
180
180
|
} | string;
|
|
181
181
|
type RouteOpts<U = {}, T = SimpleObject$1> = {
|
|
182
182
|
path?: string;
|
|
183
183
|
key?: string;
|
|
184
|
-
|
|
184
|
+
rid?: string;
|
|
185
185
|
run?: Run<U>;
|
|
186
186
|
nextRoute?: NextRoute;
|
|
187
187
|
description?: string;
|
|
@@ -191,7 +191,7 @@ type RouteOpts<U = {}, T = SimpleObject$1> = {
|
|
|
191
191
|
isDebug?: boolean;
|
|
192
192
|
};
|
|
193
193
|
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
194
|
-
declare const pickValue: readonly ["path", "key", "
|
|
194
|
+
declare const pickValue: readonly ["path", "key", "rid", "description", "type", "middleware", "metadata"];
|
|
195
195
|
type Skill<T = SimpleObject$1> = {
|
|
196
196
|
skill: string;
|
|
197
197
|
title: string;
|
|
@@ -220,7 +220,7 @@ declare class Route<M extends SimpleObject$1 = SimpleObject$1, U extends SimpleO
|
|
|
220
220
|
* 二级路径
|
|
221
221
|
*/
|
|
222
222
|
key?: string;
|
|
223
|
-
|
|
223
|
+
rid?: string;
|
|
224
224
|
run?: Run<BuildRouteContext<M, U>>;
|
|
225
225
|
nextRoute?: NextRoute;
|
|
226
226
|
description?: string;
|
|
@@ -331,7 +331,7 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
331
331
|
* @returns
|
|
332
332
|
*/
|
|
333
333
|
call(message: {
|
|
334
|
-
|
|
334
|
+
rid?: string;
|
|
335
335
|
path?: string;
|
|
336
336
|
key?: string;
|
|
337
337
|
payload?: any;
|
|
@@ -418,7 +418,7 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
418
418
|
findRoute(opts?: {
|
|
419
419
|
path?: string;
|
|
420
420
|
key?: string;
|
|
421
|
-
|
|
421
|
+
rid?: string;
|
|
422
422
|
}): Route<SimpleObject$1, SimpleObject$1>;
|
|
423
423
|
createRouteList(opts?: {
|
|
424
424
|
force?: boolean;
|
|
@@ -509,7 +509,7 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
509
509
|
* @returns
|
|
510
510
|
*/
|
|
511
511
|
run(msg: {
|
|
512
|
-
|
|
512
|
+
rid?: string;
|
|
513
513
|
path?: string;
|
|
514
514
|
key?: string;
|
|
515
515
|
payload?: any;
|
|
@@ -517,7 +517,7 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
517
517
|
data?: any;
|
|
518
518
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
519
519
|
runAction<T extends {
|
|
520
|
-
|
|
520
|
+
rid?: string;
|
|
521
521
|
path?: string;
|
|
522
522
|
key?: string;
|
|
523
523
|
metadata?: {
|
|
@@ -631,7 +631,7 @@ declare class Chain {
|
|
|
631
631
|
setPath(path: string): this;
|
|
632
632
|
setMiddleware(middleware: RouteMiddleware[]): this;
|
|
633
633
|
setKey(key: string): this;
|
|
634
|
-
|
|
634
|
+
setRid(key: string): this;
|
|
635
635
|
setRun<U extends SimpleObject = {}>(run: Run<U>): this;
|
|
636
636
|
define<U extends SimpleObject = {}>(run: Run<U>): this;
|
|
637
637
|
createRoute(): this;
|