@kevisual/router 0.0.52 → 0.0.54

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.
@@ -1,6 +1,4 @@
1
1
  import { z } from 'zod';
2
- import * as node_querystring from 'node:querystring';
3
- import { IncomingMessage } from 'node:http';
4
2
  import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
5
3
  import { Query, DataOpts, Result } from '@kevisual/query/query';
6
4
 
@@ -11,6 +9,11 @@ type RouterContextT = {
11
9
  type RouteContext<T = {
12
10
  code?: number;
13
11
  }, S = any> = {
12
+ /**
13
+ * 本地自己调用的时候使用,可以标识为当前自调用,那么 auth 就不许重复的校验
14
+ * 或者不需要登录的,直接调用
15
+ */
16
+ appId?: string;
14
17
  query?: {
15
18
  [key: string]: any;
16
19
  };
@@ -104,6 +107,14 @@ type RouteOpts<U = {}, T = SimpleObject$1> = {
104
107
  };
105
108
  type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
106
109
  declare const pickValue: readonly ["path", "key", "id", "description", "type", "middleware", "metadata"];
110
+ type Skill<T = SimpleObject$1> = {
111
+ skill: string;
112
+ title: string;
113
+ summary?: string;
114
+ args?: z.ZodTypeAny;
115
+ } & T;
116
+ /** */
117
+ declare const createSkill: <T = SimpleObject$1>(skill: Skill<T>) => Skill<T>;
107
118
  type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
108
119
  declare class Route<U = {
109
120
  [key: string]: any;
@@ -152,6 +163,7 @@ declare class Route<U = {
152
163
  throw(code?: number | string, message?: string, tips?: string): void;
153
164
  }
154
165
  declare class QueryRouter {
166
+ appId: string;
155
167
  routes: Route[];
156
168
  maxNextRoute: number;
157
169
  context?: RouteContext;
@@ -280,6 +292,13 @@ declare class QueryRouter {
280
292
  hasRoute(path: string, key?: string): Route<{
281
293
  [key: string]: any;
282
294
  }, SimpleObject$1>;
295
+ findRoute(opts?: {
296
+ path?: string;
297
+ key?: string;
298
+ id?: string;
299
+ }): Route<{
300
+ [key: string]: any;
301
+ }, SimpleObject$1>;
283
302
  createRouteList(force?: boolean, filter?: (route: Route) => boolean): void;
284
303
  /**
285
304
  * 等待程序运行, 获取到message的数据,就执行
@@ -304,6 +323,7 @@ declare class QueryRouter {
304
323
  type QueryRouterServerOpts = {
305
324
  handleFn?: HandleFn;
306
325
  context?: RouteContext;
326
+ appId?: string;
307
327
  };
308
328
  interface HandleFn<T = any> {
309
329
  (msg: {
@@ -322,6 +342,7 @@ interface HandleFn<T = any> {
322
342
  * @description 移除server相关的功能,只保留router相关的功能,和http.createServer不相关,独立
323
343
  */
324
344
  declare class QueryRouterServer extends QueryRouter {
345
+ appId: string;
325
346
  handle: any;
326
347
  constructor(opts?: QueryRouterServerOpts);
327
348
  setHandle(wrapperFn?: HandleFn, ctx?: RouteContext): void;
@@ -417,16 +438,6 @@ declare class CustomError extends Error {
417
438
  };
418
439
  }
419
440
 
420
- declare const parseBody: <T = Record<string, any>>(req: IncomingMessage) => Promise<T>;
421
- declare const parseSearch: (req: IncomingMessage) => node_querystring.ParsedUrlQuery;
422
- /**
423
- * 把url当个key 的 value 的字符串转成json
424
- * @param value
425
- */
426
- declare const parseSearchValue: (value?: string, opts?: {
427
- decode?: boolean;
428
- }) => any;
429
-
430
441
  type RouteObject = {
431
442
  [key: string]: RouteOpts$1;
432
443
  };
@@ -497,5 +508,5 @@ declare class QueryUtil<T extends RouteObject = RouteObject> {
497
508
 
498
509
  declare const App: typeof QueryRouterServer;
499
510
 
500
- export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, define, parseBody, parseSearch, parseSearchValue, util };
501
- export type { RouteArray, RouteContext, RouteObject, RouteOpts, Rule, Run, Schema };
511
+ export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, util };
512
+ export type { RouteArray, RouteContext, RouteObject, RouteOpts, Rule, Run, Schema, Skill };