@kevisual/router 0.2.10 → 0.2.12

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.
@@ -53,6 +53,80 @@ 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
+ type ListenProcessOptions = {
73
+ app?: QueryRouterServer;
74
+ mockProcess?: MockProcess;
75
+ params?: ListenProcessParams;
76
+ timeout?: number;
77
+ };
78
+ declare const listenProcess: ({ app, mockProcess, params, timeout }: ListenProcessOptions) => Promise<void>;
79
+
80
+ /** JSON Schema 基本类型映射到 TypeScript 类型 */
81
+ type JsonSchemaTypeToTS<T> = T extends {
82
+ type: "string";
83
+ } ? string : T extends {
84
+ type: "boolean";
85
+ } ? boolean : T extends {
86
+ type: "number";
87
+ } ? number : T extends {
88
+ type: "integer";
89
+ } ? number : T extends {
90
+ type: "object";
91
+ } ? object : T extends {
92
+ type: "array";
93
+ } ? any[] : any;
94
+ /** 将 args shape(key -> JSON Schema 类型)转换为 payload 类型,支持 optional: true 的字段为可选 */
95
+ type ArgsShapeToPayload<T> = {
96
+ [K in keyof T as T[K] extends {
97
+ optional: true;
98
+ } ? never : K]: JsonSchemaTypeToTS<T[K]>;
99
+ } & {
100
+ [K in keyof T as T[K] extends {
101
+ optional: true;
102
+ } ? K : never]?: JsonSchemaTypeToTS<T[K]>;
103
+ };
104
+ /** 处理两种 args 格式:完整 JSON Schema(含 properties)或简单 key->type 映射 */
105
+ type ArgsToPayload<T> = T extends {
106
+ type: "object";
107
+ properties: infer P;
108
+ } ? ArgsShapeToPayload<P> : ArgsShapeToPayload<T>;
109
+ /** 从 API 定义中提取 metadata.args */
110
+ type ExtractArgs<T> = T extends {
111
+ metadata: {
112
+ args: infer A;
113
+ };
114
+ } ? A : {};
115
+ /** 从 API 定义中提取 metadata.returns */
116
+ type ExtractReturns<T> = T extends {
117
+ metadata: {
118
+ returns: infer R;
119
+ };
120
+ } ? R : unknown;
121
+ /** runAction 第二个参数的类型,根据第一个参数的 metadata.args 推断 */
122
+ type RunActionPayload<T> = ArgsToPayload<ExtractArgs<T>>;
123
+ /** runAction 的返回类型,根据 API 定义中的 metadata.returns 推断 data 字段类型 */
124
+ type RunActionReturns<T> = {
125
+ code: number | string;
126
+ data?: unknown extends ExtractReturns<T> ? any : ArgsToPayload<ExtractReturns<T>>;
127
+ message?: string;
128
+ [key: string]: any;
129
+ };
56
130
 
57
131
  type RouterContextT = {
58
132
  code?: number;
@@ -525,8 +599,9 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
525
599
  key?: string;
526
600
  metadata?: {
527
601
  args?: any;
602
+ returns?: any;
528
603
  };
529
- } = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
604
+ } = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<RunActionReturns<T>>;
530
605
  /**
531
606
  * 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
532
607
  * @param fun 认证函数,接收 RouteContext 和认证类型
@@ -537,43 +612,6 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
537
612
  }
538
613
  declare class Mini extends QueryRouterServer {
539
614
  }
540
- /** JSON Schema 基本类型映射到 TypeScript 类型 */
541
- type JsonSchemaTypeToTS<T> = T extends {
542
- type: "string";
543
- } ? string : T extends {
544
- type: "boolean";
545
- } ? boolean : T extends {
546
- type: "number";
547
- } ? number : T extends {
548
- type: "integer";
549
- } ? number : T extends {
550
- type: "object";
551
- } ? object : T extends {
552
- type: "array";
553
- } ? any[] : any;
554
- /** 将 args shape(key -> JSON Schema 类型)转换为 payload 类型,支持 optional: true 的字段为可选 */
555
- type ArgsShapeToPayload<T> = {
556
- [K in keyof T as T[K] extends {
557
- optional: true;
558
- } ? never : K]: JsonSchemaTypeToTS<T[K]>;
559
- } & {
560
- [K in keyof T as T[K] extends {
561
- optional: true;
562
- } ? K : never]?: JsonSchemaTypeToTS<T[K]>;
563
- };
564
- /** 处理两种 args 格式:完整 JSON Schema(含 properties)或简单 key->type 映射 */
565
- type ArgsToPayload<T> = T extends {
566
- type: "object";
567
- properties: infer P;
568
- } ? ArgsShapeToPayload<P> : ArgsShapeToPayload<T>;
569
- /** 从 API 定义中提取 metadata.args */
570
- type ExtractArgs<T> = T extends {
571
- metadata: {
572
- args: infer A;
573
- };
574
- } ? A : {};
575
- /** runAction 第二个参数的类型,根据第一个参数的 metadata.args 推断 */
576
- type RunActionPayload<T> = ArgsToPayload<ExtractArgs<T>>;
577
615
 
578
616
  type BaseRule = {
579
617
  value?: any;
@@ -682,5 +720,5 @@ declare class QueryUtil<T extends RouteObject = RouteObject> {
682
720
 
683
721
  declare const App: typeof QueryRouterServer;
684
722
 
685
- export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, fromJSONSchema, toJSONSchema, tool, util };
686
- export type { RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, Rule, Run, Schema, Skill };
723
+ export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, fromJSONSchema, listenProcess, toJSONSchema, tool, util };
724
+ export type { ListenProcessOptions, ListenProcessParams, ListenProcessResponse, RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, Rule, Run, Schema, Skill };