@kevisual/router 0.2.4 → 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/dist/router.d.ts CHANGED
@@ -22,7 +22,7 @@ declare class CustomError extends Error {
22
22
  static fromCode(code?: number): CustomError;
23
23
  static fromErrorData(code?: number, data?: any): CustomError;
24
24
  static parseError(e: CustomError): {
25
- code: number | undefined;
25
+ code: number;
26
26
  data: any;
27
27
  message: string;
28
28
  };
@@ -36,7 +36,7 @@ declare class CustomError extends Error {
36
36
  static throw(code?: number | string, opts?: CustomErrorOptions): void;
37
37
  static throw(opts?: CustomErrorOptions): void;
38
38
  parse(e?: CustomError): {
39
- code: number | undefined;
39
+ code: number;
40
40
  data: any;
41
41
  message: string;
42
42
  };
@@ -59,22 +59,6 @@ declare class MockProcess {
59
59
  on(fn: (msg?: any) => any): void;
60
60
  desctroy(): void;
61
61
  }
62
- type ListenProcessParams = {
63
- message?: RunMessage;
64
- context?: any;
65
- };
66
- type ListenProcessResponse = {
67
- success?: boolean;
68
- data?: {
69
- code?: number;
70
- data?: any;
71
- message?: string;
72
- [key: string]: any;
73
- };
74
- error?: any;
75
- timestamp?: string;
76
- [key: string]: any;
77
- };
78
62
 
79
63
  type RouterContextT = {
80
64
  code?: number;
@@ -232,7 +216,7 @@ declare class Route<M extends SimpleObject$1 = SimpleObject$1, U extends SimpleO
232
216
  description?: string;
233
217
  metadata?: M;
234
218
  middleware?: RouteMiddleware[];
235
- type?: string | undefined;
219
+ type?: string;
236
220
  /**
237
221
  * 是否开启debug,开启后会打印错误信息
238
222
  */
@@ -325,6 +309,7 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
325
309
  path: string;
326
310
  key?: string;
327
311
  payload?: any;
312
+ args?: any;
328
313
  }, ctx?: RouteContext<T> & {
329
314
  [key: string]: any;
330
315
  }): Promise<RouteContext<T, {}, {
@@ -341,13 +326,14 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
341
326
  path?: string;
342
327
  key?: string;
343
328
  payload?: any;
329
+ args?: any;
344
330
  }, ctx?: RouteContext<T> & {
345
331
  [key: string]: any;
346
332
  }): Promise<RouteContext<T, {}, {
347
333
  [key: string]: any;
348
334
  }> | {
349
335
  code: number;
350
- body: null;
336
+ body: any;
351
337
  message: string;
352
338
  }>;
353
339
  /**
@@ -362,12 +348,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
362
348
  path: string;
363
349
  key?: string;
364
350
  payload?: any;
351
+ args?: any;
365
352
  }, ctx?: RouteContext & {
366
353
  [key: string]: any;
367
354
  }): Promise<{
368
- code: number | undefined;
369
- data: string | number | Object | null | undefined;
370
- message: string | undefined;
355
+ code: number;
356
+ data: any;
357
+ message: string;
371
358
  }>;
372
359
  /**
373
360
  * Router Run获取数据
@@ -380,12 +367,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
380
367
  path?: string;
381
368
  key?: string;
382
369
  payload?: any;
370
+ args?: any;
383
371
  }, ctx?: RouteContext<T> & {
384
372
  [key: string]: any;
385
373
  }): Promise<{
386
- code: number | undefined;
387
- data: string | number | Object | null | undefined;
388
- message: string | undefined;
374
+ code: number;
375
+ data: any;
376
+ message: string;
389
377
  }>;
390
378
  /**
391
379
  * 设置上下文
@@ -420,12 +408,12 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
420
408
  importRoutes(routes: Route[]): void;
421
409
  importRouter(router: QueryRouter): void;
422
410
  throw(...args: any[]): void;
423
- hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1> | undefined;
411
+ hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1>;
424
412
  findRoute(opts?: {
425
413
  path?: string;
426
414
  key?: string;
427
415
  rid?: string;
428
- }): Route<SimpleObject$1, SimpleObject$1> | undefined;
416
+ }): Route<SimpleObject$1, SimpleObject$1>;
429
417
  createRouteList(opts?: {
430
418
  force?: boolean;
431
419
  filter?: (route: Route) => boolean;
@@ -519,6 +507,7 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
519
507
  path?: string;
520
508
  key?: string;
521
509
  payload?: any;
510
+ args?: any;
522
511
  token?: string;
523
512
  data?: any;
524
513
  }, ctx?: Partial<RouteContext<C>>): Promise<any>;
@@ -534,7 +523,9 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
534
523
  * 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
535
524
  * @param fun 认证函数,接收 RouteContext 和认证类型
536
525
  */
537
- createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
526
+ createAuth(fun?: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any, opts?: {
527
+ overwrite?: boolean;
528
+ }): Promise<void>;
538
529
  }
539
530
  declare class Mini extends QueryRouterServer {
540
531
  }
@@ -628,8 +619,8 @@ declare class Chain {
628
619
  object: RouteOpts;
629
620
  app?: QueryRouterServer;
630
621
  constructor(object: RouteOpts, opts?: ChainOptions);
631
- get key(): string | undefined;
632
- get path(): string | undefined;
622
+ get key(): string;
623
+ get path(): string;
633
624
  setDescription(desc: string): this;
634
625
  setMeta(metadata: {
635
626
  [key: string]: any;
@@ -1031,7 +1022,10 @@ declare class ServerNode extends ServerBase implements ServerType {
1031
1022
  * @param res
1032
1023
  * @returns
1033
1024
  */
1034
- declare const handleServer: (req: IncomingMessage, res: ServerResponse) => Promise<any>;
1025
+ declare const handleServer: (req: IncomingMessage, res: ServerResponse) => Promise<{
1026
+ cookies: Record<string, string>;
1027
+ token: string;
1028
+ }>;
1035
1029
 
1036
1030
  type RouterHandle = (msg: {
1037
1031
  path: string;
@@ -1073,9 +1067,12 @@ declare class App<U = {}> extends QueryRouterServer<AppRouteContext<U>> {
1073
1067
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
1074
1068
  listen(handle: any, listeningListener?: () => void): void;
1075
1069
  Route: typeof Route;
1076
- static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<any>;
1070
+ static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<{
1071
+ cookies: Record<string, string>;
1072
+ token: string;
1073
+ }>;
1077
1074
  onServerRequest(fn: (req: IncomingMessage$1, res: ServerResponse$1) => void): void;
1078
1075
  }
1079
1076
 
1080
- export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, toJSONSchema, tool, util };
1081
- export type { HttpListenerFun, ListenProcessParams, ListenProcessResponse, Listener, OnListener, OnWebSocketFn, RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema, Skill, WS, WebSocketListenerFun, WebSocketReq, WebSocketRes };
1077
+ export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, toJSONSchema, tool, util };
1078
+ export type { HttpListenerFun, Listener, OnListener, OnWebSocketFn, RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema, Skill, WS, WebSocketListenerFun, WebSocketReq, WebSocketRes };