@kevisual/router 0.2.5 → 0.2.6

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 CHANGED
@@ -24,6 +24,11 @@ app
24
24
  })
25
25
  .addTo(app);
26
26
  ```
27
+ ## 浏览器模块使用 router
28
+
29
+ ```ts
30
+ import { App } from '@kevisual/router/browser';
31
+ ```
27
32
 
28
33
  ## 核心概念
29
34
 
@@ -112,7 +117,7 @@ app
112
117
  .define(async (ctx) => {
113
118
  const { id } = ctx.query;
114
119
  if (!id) {
115
- ctx.throw(400, '缺少参数', 'id is required');
120
+ ctx.throw(400, '缺少参数:id is required');
116
121
  }
117
122
  ctx.body = { success: true };
118
123
  })
@@ -129,7 +134,7 @@ const app = new App();
129
134
  // 定义中间件
130
135
  app
131
136
  .route({
132
- rid: 'auth-example',
137
+ rid: 'auth',
133
138
  description: '权限校验中间件',
134
139
  })
135
140
  .define(async (ctx) => {
@@ -144,7 +149,7 @@ app
144
149
 
145
150
  // 使用中间件(通过 rid 引用)
146
151
  app
147
- .route({ path: 'admin', key: 'panel', middleware: ['auth-example'] })
152
+ .route({ path: 'admin', key: 'panel', middleware: ['auth'] })
148
153
  .define(async (ctx) => {
149
154
  // 可以访问中间件设置的 state
150
155
  const { tokenUser } = ctx.state;
@@ -163,18 +168,18 @@ app
163
168
  .router({
164
169
  path: 'dog',
165
170
  key: 'info',
166
- description: '获取狗的信息',
171
+ description: '获取小狗的信息',
167
172
  metadata: {
168
173
  args: {
169
- name: z.string().describe('狗的姓名'),
170
- age: z.number().describe('狗的年龄'),
174
+ name: z.string().describe('小狗的姓名'),
175
+ age: z.number().describe('小狗的年龄'),
171
176
  },
172
177
  },
173
178
  })
174
179
  .define(async (ctx) => {
175
180
  const { name, age } = ctx.query;
176
181
  ctx.body = {
177
- content: `这是一只${age}岁的狗,名字是${name}`,
182
+ content: `这是一只${age}岁的小狗,名字是${name}`,
178
183
  };
179
184
  })
180
185
  .addTo(app);
@@ -184,9 +189,7 @@ app
184
189
 
185
190
  1. **path 和 key 的组合是路由的唯一标识**,同一个 path+key 只能添加一个路由,后添加的会覆盖之前的。
186
191
 
187
- 2. **ctx.call vs ctx.run**:
188
- - `call` 返回完整 context,包含所有属性
189
- - `run` 返回 `{ code, data, message }` 格式,data 即 body
192
+ 2. `ctx.run` 返回 `{ code, data, message }` 格式,data 即 body
190
193
 
191
194
  3. **ctx.throw 会自动结束执行**,抛出自定义错误。
192
195
 
@@ -199,5 +202,3 @@ app
199
202
  7. **needSerialize 默认为 true**,会自动对 body 进行 JSON 序列化和反序列化。
200
203
 
201
204
  8. **progress 记录执行路径**,可用于调试和追踪路由调用链。
202
-
203
- 9. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
package/dist/app.js CHANGED
@@ -3691,7 +3691,7 @@ var listenProcess = async ({ app, mockProcess, params = {}, timeout: timeout2 =
3691
3691
  const ctx = mergeParams?.context || {};
3692
3692
  if (!msg.path && !msg.id) {
3693
3693
  const route = app.routes.find((r) => r.path !== "router");
3694
- msg.id = route?.id;
3694
+ msg.id = route?.rid;
3695
3695
  }
3696
3696
  const result = await app.run(msg, ctx);
3697
3697
  const response = {
@@ -17707,9 +17707,9 @@ class QueryRouter {
17707
17707
  if (!message?.path) {
17708
17708
  return Promise.resolve({ code: 404, body: null, message: "Not found path" });
17709
17709
  }
17710
- const { path, key = "", payload = {}, ...query } = message;
17710
+ const { path, key = "", payload = {}, args = {}, ...query } = message;
17711
17711
  ctx = ctx || {};
17712
- ctx.query = { ...ctx.query, ...query, ...payload };
17712
+ ctx.query = { ...ctx.query, ...query, ...payload, ...args };
17713
17713
  ctx.args = ctx.query;
17714
17714
  ctx.state = { ...ctx?.state };
17715
17715
  ctx.throw = this.throw;
@@ -17919,7 +17919,8 @@ class QueryRouterServer extends QueryRouter {
17919
17919
  const { path, key, rid } = api2;
17920
17920
  return this.run({ path, key, rid, payload }, ctx);
17921
17921
  }
17922
- async createAuth(fun) {
17922
+ async createAuth(fun, opts) {
17923
+ const overwrite = opts?.overwrite ?? false;
17923
17924
  this.route({
17924
17925
  path: "auth",
17925
17926
  key: "auth",
@@ -17929,7 +17930,7 @@ class QueryRouterServer extends QueryRouter {
17929
17930
  if (fun) {
17930
17931
  await fun(ctx, "auth");
17931
17932
  }
17932
- }).addTo(this, { overwrite: false });
17933
+ }).addTo(this, { overwrite });
17933
17934
  this.route({
17934
17935
  path: "auth-admin",
17935
17936
  key: "auth-admin",
@@ -17940,7 +17941,7 @@ class QueryRouterServer extends QueryRouter {
17940
17941
  if (fun) {
17941
17942
  await fun(ctx, "auth-admin");
17942
17943
  }
17943
- }).addTo(this, { overwrite: false });
17944
+ }).addTo(this, { overwrite });
17944
17945
  this.route({
17945
17946
  path: "auth-can",
17946
17947
  key: "auth-can",
@@ -17950,7 +17951,7 @@ class QueryRouterServer extends QueryRouter {
17950
17951
  if (fun) {
17951
17952
  await fun(ctx, "auth-can");
17952
17953
  }
17953
- }).addTo(this, { overwrite: false });
17954
+ }).addTo(this, { overwrite });
17954
17955
  }
17955
17956
  }
17956
17957
 
@@ -20108,7 +20109,7 @@ app
20108
20109
  10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
20109
20110
  `;
20110
20111
  // package.json
20111
- var version2 = "0.2.4";
20112
+ var version2 = "0.2.5";
20112
20113
 
20113
20114
  // agent/routes/route-create.ts
20114
20115
  app.route({
@@ -171,7 +171,7 @@ declare class Route<M extends SimpleObject = SimpleObject, U extends SimpleObjec
171
171
  description?: string;
172
172
  metadata?: M;
173
173
  middleware?: RouteMiddleware[];
174
- type?: string | undefined;
174
+ type?: string;
175
175
  /**
176
176
  * 是否开启debug,开启后会打印错误信息
177
177
  */
@@ -247,6 +247,7 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
247
247
  path: string;
248
248
  key?: string;
249
249
  payload?: any;
250
+ args?: any;
250
251
  }, ctx?: RouteContext<T> & {
251
252
  [key: string]: any;
252
253
  }): Promise<RouteContext<T, {}, {
@@ -263,13 +264,14 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
263
264
  path?: string;
264
265
  key?: string;
265
266
  payload?: any;
267
+ args?: any;
266
268
  }, ctx?: RouteContext<T> & {
267
269
  [key: string]: any;
268
270
  }): Promise<RouteContext<T, {}, {
269
271
  [key: string]: any;
270
272
  }> | {
271
273
  code: number;
272
- body: null;
274
+ body: any;
273
275
  message: string;
274
276
  }>;
275
277
  /**
@@ -284,12 +286,13 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
284
286
  path: string;
285
287
  key?: string;
286
288
  payload?: any;
289
+ args?: any;
287
290
  }, ctx?: RouteContext & {
288
291
  [key: string]: any;
289
292
  }): Promise<{
290
- code: number | undefined;
291
- data: string | number | Object | null | undefined;
292
- message: string | undefined;
293
+ code: number;
294
+ data: any;
295
+ message: string;
293
296
  }>;
294
297
  /**
295
298
  * Router Run获取数据
@@ -302,12 +305,13 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
302
305
  path?: string;
303
306
  key?: string;
304
307
  payload?: any;
308
+ args?: any;
305
309
  }, ctx?: RouteContext<T> & {
306
310
  [key: string]: any;
307
311
  }): Promise<{
308
- code: number | undefined;
309
- data: string | number | Object | null | undefined;
310
- message: string | undefined;
312
+ code: number;
313
+ data: any;
314
+ message: string;
311
315
  }>;
312
316
  /**
313
317
  * 设置上下文
@@ -342,12 +346,12 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
342
346
  importRoutes(routes: Route[]): void;
343
347
  importRouter(router: QueryRouter): void;
344
348
  throw(...args: any[]): void;
345
- hasRoute(path: string, key?: string): Route<SimpleObject, SimpleObject> | undefined;
349
+ hasRoute(path: string, key?: string): Route<SimpleObject, SimpleObject>;
346
350
  findRoute(opts?: {
347
351
  path?: string;
348
352
  key?: string;
349
353
  rid?: string;
350
- }): Route<SimpleObject, SimpleObject> | undefined;
354
+ }): Route<SimpleObject, SimpleObject>;
351
355
  createRouteList(opts?: {
352
356
  force?: boolean;
353
357
  filter?: (route: Route) => boolean;
@@ -441,6 +445,7 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
441
445
  path?: string;
442
446
  key?: string;
443
447
  payload?: any;
448
+ args?: any;
444
449
  token?: string;
445
450
  data?: any;
446
451
  }, ctx?: Partial<RouteContext<C>>): Promise<any>;
@@ -456,7 +461,9 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
456
461
  * 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
457
462
  * @param fun 认证函数,接收 RouteContext 和认证类型
458
463
  */
459
- createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
464
+ createAuth(fun?: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any, opts?: {
465
+ overwrite?: boolean;
466
+ }): Promise<void>;
460
467
  }
461
468
  /** JSON Schema 基本类型映射到 TypeScript 类型 */
462
469
  type JsonSchemaTypeToTS<T> = T extends {
@@ -791,17 +798,25 @@ declare class App<U = {}> extends QueryRouterServer<AppRouteContext<U>> {
791
798
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
792
799
  listen(handle: any, listeningListener?: () => void): void;
793
800
  Route: typeof Route;
794
- static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<any>;
801
+ static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<{
802
+ cookies: Record<string, string>;
803
+ token: string;
804
+ }>;
795
805
  onServerRequest(fn: (req: IncomingMessage$1, res: ServerResponse$1) => void): void;
796
806
  }
797
807
 
798
808
  declare const groupByPath: (routes: App["routes"]) => Record<string, Route<SimpleObject, SimpleObject>[]>;
799
809
  declare const parseArgs: (args: string) => any;
800
810
  declare const parseDescription: (route: App["routes"][number]) => string;
801
- declare const createCommand: (opts: {
811
+ declare const createCommandList: (opts: {
802
812
  app: any;
803
813
  program: Command;
804
814
  }) => void;
815
+ declare const createCommand: (command: Command, opts: {
816
+ description?: string;
817
+ app: App;
818
+ route: any;
819
+ }) => void;
805
820
  declare const parse: (opts: {
806
821
  app: any;
807
822
  description?: string;
@@ -818,4 +833,4 @@ declare const parse: (opts: {
818
833
  exitOnEnd?: boolean;
819
834
  }) => Promise<void>;
820
835
 
821
- export { createCommand, groupByPath, parse, parseArgs, parseDescription };
836
+ export { createCommand, createCommandList, groupByPath, parse, parseArgs, parseDescription };
package/dist/commander.js CHANGED
@@ -16243,51 +16243,61 @@ var parseDescription = (route) => {
16243
16243
  }
16244
16244
  return desc;
16245
16245
  };
16246
- var createCommand2 = (opts) => {
16246
+ var createCommandList = (opts) => {
16247
16247
  const { program: program2 } = opts;
16248
16248
  const app = opts.app;
16249
16249
  const routes = app.routes;
16250
16250
  const groupRoutes = groupByPath(routes);
16251
16251
  for (const path in groupRoutes) {
16252
16252
  const routeList = groupRoutes[path];
16253
- const keys = routeList.map((route) => route.key).filter(Boolean);
16253
+ if (!routeList)
16254
+ continue;
16255
+ const keys = routeList.map((route) => route.key);
16254
16256
  const subProgram = program2.command(path).description(`路由[${path}] ${keys.length > 0 ? ": " + keys.join(", ") : ""}`);
16255
16257
  routeList.forEach((route) => {
16256
- if (!route.key)
16257
- return;
16258
16258
  const description = parseDescription(route);
16259
- subProgram.command(route.key).description(description || "").option("--args <args>", `命令参数,支持 JSON 格式或 key=value 形式,例如: --args '{"a":1}' 或 --args 'a=1 b=2'`).argument("[args...]", `位置参数(推荐通过 -- 分隔传入),支持 JSON 或 key=value 格式,例如: -- a=1 b=2 或 -- '{"a":1}'`).action(async (passedArgs, options, _command) => {
16260
- const output = (data) => {
16261
- if (typeof data === "object") {
16262
- process.stdout.write(JSON.stringify(data, null, 2) + `
16263
- `);
16264
- } else {
16265
- process.stdout.write(String(data) + `
16266
- `);
16267
- }
16268
- };
16269
- try {
16270
- let args = {};
16271
- if (options.args) {
16272
- args = parseArgs(options.args);
16273
- } else if (passedArgs.length > 0) {
16274
- args = parseArgs(passedArgs.join(" "));
16275
- }
16276
- const res = await app.run({ path, key: route.key, payload: args }, { appId: app.appId });
16277
- if (res.code === 200) {
16278
- output(res.data);
16279
- } else {
16280
- output(`Error: ${res.message}`);
16281
- }
16282
- } catch (error48) {
16283
- output(`Execution error: ${error48 instanceof Error ? error48.message : String(error48)}`);
16284
- }
16285
- });
16259
+ if (!route.key) {
16260
+ createCommand2(subProgram, { description, app, route });
16261
+ return;
16262
+ }
16263
+ const _sumCommandy = subProgram.command(route.key);
16264
+ createCommand2(_sumCommandy, { description, app, route });
16286
16265
  });
16287
16266
  }
16288
16267
  };
16268
+ var createCommand2 = (command, opts) => {
16269
+ const { description, app, route } = opts;
16270
+ const path = route.path;
16271
+ command.description(description || "").option("--args <args>", `命令参数,支持 JSON 格式或 key=value 形式,例如: --args '{"a":1}' 或 --args 'a=1 b=2'`).argument("[args...]", `位置参数(推荐通过 -- 分隔传入),支持 JSON 或 key=value 格式,例如: -- a=1 b=2 或 -- '{"a":1}'`).action(async (passedArgs, options, _command) => {
16272
+ const output = (data) => {
16273
+ if (typeof data === "object") {
16274
+ process.stdout.write(JSON.stringify(data, null, 2) + `
16275
+ `);
16276
+ } else {
16277
+ process.stdout.write(String(data) + `
16278
+ `);
16279
+ }
16280
+ };
16281
+ try {
16282
+ let args = {};
16283
+ if (options.args) {
16284
+ args = parseArgs(options.args);
16285
+ } else if (passedArgs.length > 0) {
16286
+ args = parseArgs(passedArgs.join(" "));
16287
+ }
16288
+ const res = await app.run({ path, key: route.key, payload: args }, { appId: app.appId });
16289
+ if (res.code === 200) {
16290
+ output(res.data);
16291
+ } else {
16292
+ output(`Error: ${res.message}`);
16293
+ }
16294
+ } catch (error48) {
16295
+ output(`Execution error: ${error48 instanceof Error ? error48.message : String(error48)}`);
16296
+ }
16297
+ });
16298
+ };
16289
16299
  var parse5 = async (opts) => {
16290
- const { description, parse: parse6 = true, version: version2, exitOnEnd = true } = opts;
16300
+ const { description, parse: parse6 = true, version: version2, exitOnEnd = false } = opts;
16291
16301
  const app = opts.app;
16292
16302
  const _program = opts.program || program;
16293
16303
  _program.description(description || "Router 命令行工具");
@@ -16296,7 +16306,7 @@ var parse5 = async (opts) => {
16296
16306
  }
16297
16307
  app.createRouteList();
16298
16308
  createCliList(app);
16299
- createCommand2({ app, program: _program });
16309
+ createCommandList({ app, program: _program });
16300
16310
  if (opts.remote) {
16301
16311
  const { token, username, id, url: url2 } = opts.remote;
16302
16312
  const remoteApp = new RemoteApp({
@@ -16405,5 +16415,6 @@ export {
16405
16415
  parseArgs,
16406
16416
  parse5 as parse,
16407
16417
  groupByPath,
16418
+ createCommandList,
16408
16419
  createCommand2 as createCommand
16409
16420
  };
@@ -171,7 +171,7 @@ declare class Route<M extends SimpleObject = SimpleObject, U extends SimpleObjec
171
171
  description?: string;
172
172
  metadata?: M;
173
173
  middleware?: RouteMiddleware[];
174
- type?: string | undefined;
174
+ type?: string;
175
175
  /**
176
176
  * 是否开启debug,开启后会打印错误信息
177
177
  */
@@ -247,6 +247,7 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
247
247
  path: string;
248
248
  key?: string;
249
249
  payload?: any;
250
+ args?: any;
250
251
  }, ctx?: RouteContext<T> & {
251
252
  [key: string]: any;
252
253
  }): Promise<RouteContext<T, {}, {
@@ -263,13 +264,14 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
263
264
  path?: string;
264
265
  key?: string;
265
266
  payload?: any;
267
+ args?: any;
266
268
  }, ctx?: RouteContext<T> & {
267
269
  [key: string]: any;
268
270
  }): Promise<RouteContext<T, {}, {
269
271
  [key: string]: any;
270
272
  }> | {
271
273
  code: number;
272
- body: null;
274
+ body: any;
273
275
  message: string;
274
276
  }>;
275
277
  /**
@@ -284,12 +286,13 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
284
286
  path: string;
285
287
  key?: string;
286
288
  payload?: any;
289
+ args?: any;
287
290
  }, ctx?: RouteContext & {
288
291
  [key: string]: any;
289
292
  }): Promise<{
290
- code: number | undefined;
291
- data: string | number | Object | null | undefined;
292
- message: string | undefined;
293
+ code: number;
294
+ data: any;
295
+ message: string;
293
296
  }>;
294
297
  /**
295
298
  * Router Run获取数据
@@ -302,12 +305,13 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
302
305
  path?: string;
303
306
  key?: string;
304
307
  payload?: any;
308
+ args?: any;
305
309
  }, ctx?: RouteContext<T> & {
306
310
  [key: string]: any;
307
311
  }): Promise<{
308
- code: number | undefined;
309
- data: string | number | Object | null | undefined;
310
- message: string | undefined;
312
+ code: number;
313
+ data: any;
314
+ message: string;
311
315
  }>;
312
316
  /**
313
317
  * 设置上下文
@@ -342,12 +346,12 @@ declare class QueryRouter<T extends SimpleObject = SimpleObject> implements thro
342
346
  importRoutes(routes: Route[]): void;
343
347
  importRouter(router: QueryRouter): void;
344
348
  throw(...args: any[]): void;
345
- hasRoute(path: string, key?: string): Route<SimpleObject, SimpleObject> | undefined;
349
+ hasRoute(path: string, key?: string): Route<SimpleObject, SimpleObject>;
346
350
  findRoute(opts?: {
347
351
  path?: string;
348
352
  key?: string;
349
353
  rid?: string;
350
- }): Route<SimpleObject, SimpleObject> | undefined;
354
+ }): Route<SimpleObject, SimpleObject>;
351
355
  createRouteList(opts?: {
352
356
  force?: boolean;
353
357
  filter?: (route: Route) => boolean;
@@ -441,6 +445,7 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
441
445
  path?: string;
442
446
  key?: string;
443
447
  payload?: any;
448
+ args?: any;
444
449
  token?: string;
445
450
  data?: any;
446
451
  }, ctx?: Partial<RouteContext<C>>): Promise<any>;
@@ -456,7 +461,9 @@ declare class QueryRouterServer<C extends SimpleObject = SimpleObject> extends Q
456
461
  * 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
457
462
  * @param fun 认证函数,接收 RouteContext 和认证类型
458
463
  */
459
- createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
464
+ createAuth(fun?: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any, opts?: {
465
+ overwrite?: boolean;
466
+ }): Promise<void>;
460
467
  }
461
468
  /** JSON Schema 基本类型映射到 TypeScript 类型 */
462
469
  type JsonSchemaTypeToTS<T> = T extends {
@@ -791,7 +798,10 @@ declare class App<U = {}> extends QueryRouterServer<AppRouteContext<U>> {
791
798
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
792
799
  listen(handle: any, listeningListener?: () => void): void;
793
800
  Route: typeof Route;
794
- static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<any>;
801
+ static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<{
802
+ cookies: Record<string, string>;
803
+ token: string;
804
+ }>;
795
805
  onServerRequest(fn: (req: IncomingMessage$1, res: ServerResponse$1) => void): void;
796
806
  }
797
807
 
@@ -16,7 +16,7 @@ declare class CustomError extends Error {
16
16
  static fromCode(code?: number): CustomError;
17
17
  static fromErrorData(code?: number, data?: any): CustomError;
18
18
  static parseError(e: CustomError): {
19
- code: number | undefined;
19
+ code: number;
20
20
  data: any;
21
21
  message: string;
22
22
  };
@@ -30,7 +30,7 @@ declare class CustomError extends Error {
30
30
  static throw(code?: number | string, opts?: CustomErrorOptions): void;
31
31
  static throw(opts?: CustomErrorOptions): void;
32
32
  parse(e?: CustomError): {
33
- code: number | undefined;
33
+ code: number;
34
34
  data: any;
35
35
  message: string;
36
36
  };
@@ -53,22 +53,6 @@ declare class MockProcess {
53
53
  on(fn: (msg?: any) => any): void;
54
54
  desctroy(): void;
55
55
  }
56
- type ListenProcessParams = {
57
- message?: RunMessage;
58
- context?: any;
59
- };
60
- type ListenProcessResponse = {
61
- success?: boolean;
62
- data?: {
63
- code?: number;
64
- data?: any;
65
- message?: string;
66
- [key: string]: any;
67
- };
68
- error?: any;
69
- timestamp?: string;
70
- [key: string]: any;
71
- };
72
56
 
73
57
  type RouterContextT = {
74
58
  code?: number;
@@ -226,7 +210,7 @@ declare class Route<M extends SimpleObject$1 = SimpleObject$1, U extends SimpleO
226
210
  description?: string;
227
211
  metadata?: M;
228
212
  middleware?: RouteMiddleware[];
229
- type?: string | undefined;
213
+ type?: string;
230
214
  /**
231
215
  * 是否开启debug,开启后会打印错误信息
232
216
  */
@@ -319,6 +303,7 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
319
303
  path: string;
320
304
  key?: string;
321
305
  payload?: any;
306
+ args?: any;
322
307
  }, ctx?: RouteContext<T> & {
323
308
  [key: string]: any;
324
309
  }): Promise<RouteContext<T, {}, {
@@ -335,13 +320,14 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
335
320
  path?: string;
336
321
  key?: string;
337
322
  payload?: any;
323
+ args?: any;
338
324
  }, ctx?: RouteContext<T> & {
339
325
  [key: string]: any;
340
326
  }): Promise<RouteContext<T, {}, {
341
327
  [key: string]: any;
342
328
  }> | {
343
329
  code: number;
344
- body: null;
330
+ body: any;
345
331
  message: string;
346
332
  }>;
347
333
  /**
@@ -356,12 +342,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
356
342
  path: string;
357
343
  key?: string;
358
344
  payload?: any;
345
+ args?: any;
359
346
  }, ctx?: RouteContext & {
360
347
  [key: string]: any;
361
348
  }): Promise<{
362
- code: number | undefined;
363
- data: string | number | Object | null | undefined;
364
- message: string | undefined;
349
+ code: number;
350
+ data: any;
351
+ message: string;
365
352
  }>;
366
353
  /**
367
354
  * Router Run获取数据
@@ -374,12 +361,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
374
361
  path?: string;
375
362
  key?: string;
376
363
  payload?: any;
364
+ args?: any;
377
365
  }, ctx?: RouteContext<T> & {
378
366
  [key: string]: any;
379
367
  }): Promise<{
380
- code: number | undefined;
381
- data: string | number | Object | null | undefined;
382
- message: string | undefined;
368
+ code: number;
369
+ data: any;
370
+ message: string;
383
371
  }>;
384
372
  /**
385
373
  * 设置上下文
@@ -414,12 +402,12 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
414
402
  importRoutes(routes: Route[]): void;
415
403
  importRouter(router: QueryRouter): void;
416
404
  throw(...args: any[]): void;
417
- hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1> | undefined;
405
+ hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1>;
418
406
  findRoute(opts?: {
419
407
  path?: string;
420
408
  key?: string;
421
409
  rid?: string;
422
- }): Route<SimpleObject$1, SimpleObject$1> | undefined;
410
+ }): Route<SimpleObject$1, SimpleObject$1>;
423
411
  createRouteList(opts?: {
424
412
  force?: boolean;
425
413
  filter?: (route: Route) => boolean;
@@ -513,6 +501,7 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
513
501
  path?: string;
514
502
  key?: string;
515
503
  payload?: any;
504
+ args?: any;
516
505
  token?: string;
517
506
  data?: any;
518
507
  }, ctx?: Partial<RouteContext<C>>): Promise<any>;
@@ -528,7 +517,9 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
528
517
  * 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
529
518
  * @param fun 认证函数,接收 RouteContext 和认证类型
530
519
  */
531
- createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
520
+ createAuth(fun?: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any, opts?: {
521
+ overwrite?: boolean;
522
+ }): Promise<void>;
532
523
  }
533
524
  declare class Mini extends QueryRouterServer {
534
525
  }
@@ -622,8 +613,8 @@ declare class Chain {
622
613
  object: RouteOpts;
623
614
  app?: QueryRouterServer;
624
615
  constructor(object: RouteOpts, opts?: ChainOptions);
625
- get key(): string | undefined;
626
- get path(): string | undefined;
616
+ get key(): string;
617
+ get path(): string;
627
618
  setDescription(desc: string): this;
628
619
  setMeta(metadata: {
629
620
  [key: string]: any;
@@ -677,5 +668,5 @@ declare class QueryUtil<T extends RouteObject = RouteObject> {
677
668
 
678
669
  declare const App: typeof QueryRouterServer;
679
670
 
680
- export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, fromJSONSchema, toJSONSchema, tool, util };
681
- export type { ListenProcessParams, ListenProcessResponse, RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, Rule, Run, Schema, Skill };
671
+ export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, fromJSONSchema, toJSONSchema, tool, util };
672
+ export type { RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, Rule, Run, Schema, Skill };