@kevisual/router 0.1.2 → 0.1.4
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/package.json +3 -3
- package/src/commander.ts +103 -23
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -20175
- package/dist/commander.d.ts +0 -816
- package/dist/commander.js +0 -2790
- package/dist/opencode.d.ts +0 -811
- package/dist/opencode.js +0 -15308
- package/dist/router-browser.d.ts +0 -676
- package/dist/router-browser.js +0 -33383
- package/dist/router-define.d.ts +0 -560
- package/dist/router-define.js +0 -135
- package/dist/router-simple.d.ts +0 -110
- package/dist/router-simple.js +0 -708
- package/dist/router.d.ts +0 -1082
- package/dist/router.js +0 -19059
- package/dist/ws.d.ts +0 -860
- package/dist/ws.js +0 -3041
package/dist/router-browser.d.ts
DELETED
|
@@ -1,676 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'eventemitter3';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { Query, DataOpts, Result } from '@kevisual/query/query';
|
|
4
|
-
|
|
5
|
-
type CustomErrorOptions = {
|
|
6
|
-
cause?: Error | string;
|
|
7
|
-
code?: number;
|
|
8
|
-
message?: string;
|
|
9
|
-
};
|
|
10
|
-
/** 自定义错误 */
|
|
11
|
-
declare class CustomError extends Error {
|
|
12
|
-
code?: number;
|
|
13
|
-
data?: any;
|
|
14
|
-
message: string;
|
|
15
|
-
constructor(code?: number | string | CustomErrorOptions, opts?: CustomErrorOptions);
|
|
16
|
-
static fromCode(code?: number): CustomError;
|
|
17
|
-
static fromErrorData(code?: number, data?: any): CustomError;
|
|
18
|
-
static parseError(e: CustomError): {
|
|
19
|
-
code: number;
|
|
20
|
-
data: any;
|
|
21
|
-
message: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* 判断 throw 的错误是否不是当前这个错误
|
|
25
|
-
* @param err
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
static isError(error: unknown): error is CustomError;
|
|
29
|
-
static throw(code?: number | string, message?: string): void;
|
|
30
|
-
static throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
31
|
-
static throw(opts?: CustomErrorOptions): void;
|
|
32
|
-
parse(e?: CustomError): {
|
|
33
|
-
code: number;
|
|
34
|
-
data: any;
|
|
35
|
-
message: string;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
interface throwError {
|
|
39
|
-
throw(code?: number | string, message?: string): void;
|
|
40
|
-
throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
41
|
-
throw(opts?: CustomErrorOptions): void;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
declare class MockProcess {
|
|
45
|
-
emitter?: EventEmitter;
|
|
46
|
-
process?: NodeJS.Process;
|
|
47
|
-
constructor(opts?: {
|
|
48
|
-
emitter?: EventEmitter;
|
|
49
|
-
isNode?: boolean;
|
|
50
|
-
});
|
|
51
|
-
send(data?: any, callback?: (err?: Error) => void): void;
|
|
52
|
-
exit(flag?: number): void;
|
|
53
|
-
on(fn: (msg?: any) => any): void;
|
|
54
|
-
desctroy(): void;
|
|
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
|
-
|
|
73
|
-
type RouterContextT = {
|
|
74
|
-
code?: number;
|
|
75
|
-
[key: string]: any;
|
|
76
|
-
};
|
|
77
|
-
type BuildRouteContext<M, U> = M extends {
|
|
78
|
-
args?: infer A;
|
|
79
|
-
} ? A extends z.ZodObject<any> ? RouteContext<{
|
|
80
|
-
args?: z.infer<A>;
|
|
81
|
-
}, U> : A extends Record<string, z.ZodTypeAny> ? RouteContext<{
|
|
82
|
-
args?: {
|
|
83
|
-
[K in keyof A]: z.infer<A[K]>;
|
|
84
|
-
};
|
|
85
|
-
}, U> : RouteContext<U> : RouteContext<U>;
|
|
86
|
-
type RouteContext<T = {
|
|
87
|
-
code?: number;
|
|
88
|
-
}, U extends SimpleObject$1 = {}, S = {
|
|
89
|
-
[key: string]: any;
|
|
90
|
-
}> = {
|
|
91
|
-
/**
|
|
92
|
-
* 本地自己调用的时候使用,可以标识为当前自调用,那么 auth 就不许重复的校验
|
|
93
|
-
* 或者不需要登录的,直接调用
|
|
94
|
-
*/
|
|
95
|
-
appId?: string;
|
|
96
|
-
query?: {
|
|
97
|
-
[key: string]: any;
|
|
98
|
-
};
|
|
99
|
-
args?: {
|
|
100
|
-
[key: string]: any;
|
|
101
|
-
};
|
|
102
|
-
/** return body */
|
|
103
|
-
body?: number | string | Object;
|
|
104
|
-
forward?: (response: {
|
|
105
|
-
code: number;
|
|
106
|
-
data?: any;
|
|
107
|
-
message?: any;
|
|
108
|
-
}) => void;
|
|
109
|
-
/** return code */
|
|
110
|
-
code?: number;
|
|
111
|
-
/** return msg */
|
|
112
|
-
message?: string;
|
|
113
|
-
/**
|
|
114
|
-
* 传递状态
|
|
115
|
-
*/
|
|
116
|
-
state?: S;
|
|
117
|
-
/**
|
|
118
|
-
* 当前routerId
|
|
119
|
-
*/
|
|
120
|
-
currentId?: string;
|
|
121
|
-
/**
|
|
122
|
-
* 当前路径
|
|
123
|
-
*/
|
|
124
|
-
currentPath?: string;
|
|
125
|
-
/**
|
|
126
|
-
* 当前key
|
|
127
|
-
*/
|
|
128
|
-
currentKey?: string;
|
|
129
|
-
/**
|
|
130
|
-
* 当前route
|
|
131
|
-
*/
|
|
132
|
-
currentRoute?: Route;
|
|
133
|
-
/**
|
|
134
|
-
* 进度
|
|
135
|
-
*/
|
|
136
|
-
progress?: [string, string][];
|
|
137
|
-
nextQuery?: {
|
|
138
|
-
[key: string]: any;
|
|
139
|
-
};
|
|
140
|
-
end?: boolean;
|
|
141
|
-
app?: QueryRouter;
|
|
142
|
-
error?: any;
|
|
143
|
-
/** 请求 route的返回结果,不解析body为data */
|
|
144
|
-
call?: (message: {
|
|
145
|
-
path: string;
|
|
146
|
-
key?: string;
|
|
147
|
-
payload?: any;
|
|
148
|
-
[key: string]: any;
|
|
149
|
-
} | {
|
|
150
|
-
id: string;
|
|
151
|
-
apyload?: any;
|
|
152
|
-
[key: string]: any;
|
|
153
|
-
}, ctx?: RouteContext & {
|
|
154
|
-
[key: string]: any;
|
|
155
|
-
}) => Promise<any>;
|
|
156
|
-
/** 请求 route的返回结果,解析了body为data,就类同于 query.post获取的数据*/
|
|
157
|
-
run?: (message: {
|
|
158
|
-
path: string;
|
|
159
|
-
key?: string;
|
|
160
|
-
payload?: any;
|
|
161
|
-
}, ctx?: RouteContext) => Promise<any>;
|
|
162
|
-
index?: number;
|
|
163
|
-
throw?: throwError['throw'];
|
|
164
|
-
/** 是否需要序列化, 使用JSON.stringify和JSON.parse */
|
|
165
|
-
needSerialize?: boolean;
|
|
166
|
-
} & T & U;
|
|
167
|
-
type SimpleObject$1 = Record<string, any>;
|
|
168
|
-
type Run<T extends SimpleObject$1 = {}> = (ctx: Required<RouteContext<T>>) => Promise<typeof ctx | null | void>;
|
|
169
|
-
type RunMessage = {
|
|
170
|
-
path?: string;
|
|
171
|
-
key?: string;
|
|
172
|
-
id?: string;
|
|
173
|
-
payload?: any;
|
|
174
|
-
};
|
|
175
|
-
type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
|
|
176
|
-
type RouteMiddleware = {
|
|
177
|
-
path?: string;
|
|
178
|
-
key?: string;
|
|
179
|
-
id?: string;
|
|
180
|
-
} | string;
|
|
181
|
-
type RouteOpts<U = {}, T = SimpleObject$1> = {
|
|
182
|
-
path?: string;
|
|
183
|
-
key?: string;
|
|
184
|
-
id?: string;
|
|
185
|
-
run?: Run<U>;
|
|
186
|
-
nextRoute?: NextRoute;
|
|
187
|
-
description?: string;
|
|
188
|
-
metadata?: T;
|
|
189
|
-
middleware?: RouteMiddleware[];
|
|
190
|
-
type?: 'route' | 'middleware' | 'compound';
|
|
191
|
-
isDebug?: boolean;
|
|
192
|
-
};
|
|
193
|
-
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
194
|
-
declare const pickValue: readonly ["path", "key", "id", "description", "type", "middleware", "metadata"];
|
|
195
|
-
type Skill<T = SimpleObject$1> = {
|
|
196
|
-
skill: string;
|
|
197
|
-
title: string;
|
|
198
|
-
summary?: string;
|
|
199
|
-
tags?: string[];
|
|
200
|
-
args?: {
|
|
201
|
-
[key: string]: any;
|
|
202
|
-
};
|
|
203
|
-
} & T;
|
|
204
|
-
declare const tool: {
|
|
205
|
-
schema: typeof z;
|
|
206
|
-
};
|
|
207
|
-
/** */
|
|
208
|
-
declare const createSkill: <T = SimpleObject$1>(skill: Skill<T>) => Skill<T>;
|
|
209
|
-
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
210
|
-
/**
|
|
211
|
-
* @M 是 route的 metadate的类型,默认是 SimpleObject
|
|
212
|
-
* @U 是 RouteContext 里 state的类型
|
|
213
|
-
*/
|
|
214
|
-
declare class Route<M extends SimpleObject$1 = SimpleObject$1, U extends SimpleObject$1 = SimpleObject$1> implements throwError {
|
|
215
|
-
/**
|
|
216
|
-
* 一级路径
|
|
217
|
-
*/
|
|
218
|
-
path?: string;
|
|
219
|
-
/**
|
|
220
|
-
* 二级路径
|
|
221
|
-
*/
|
|
222
|
-
key?: string;
|
|
223
|
-
id?: string;
|
|
224
|
-
run?: Run<BuildRouteContext<M, U>>;
|
|
225
|
-
nextRoute?: NextRoute;
|
|
226
|
-
description?: string;
|
|
227
|
-
metadata?: M;
|
|
228
|
-
middleware?: RouteMiddleware[];
|
|
229
|
-
type?: string;
|
|
230
|
-
/**
|
|
231
|
-
* 是否开启debug,开启后会打印错误信息
|
|
232
|
-
*/
|
|
233
|
-
isDebug?: boolean;
|
|
234
|
-
constructor(path?: string, key?: string, opts?: RouteOpts);
|
|
235
|
-
prompt(description: string): this;
|
|
236
|
-
prompt(description: Function): this;
|
|
237
|
-
define<T extends {
|
|
238
|
-
[key: string]: any;
|
|
239
|
-
} = RouterContextT>(opts: DefineRouteOpts): this;
|
|
240
|
-
define<T extends {
|
|
241
|
-
[key: string]: any;
|
|
242
|
-
} = RouterContextT>(fn: Run<T & BuildRouteContext<M, U>>): this;
|
|
243
|
-
define<T extends {
|
|
244
|
-
[key: string]: any;
|
|
245
|
-
} = RouterContextT>(key: string, fn: Run<T & BuildRouteContext<M, U>>): this;
|
|
246
|
-
define<T extends {
|
|
247
|
-
[key: string]: any;
|
|
248
|
-
} = RouterContextT>(path: string, key: string, fn: Run<T & BuildRouteContext<M, U>>): this;
|
|
249
|
-
update(opts: DefineRouteOpts, onlyUpdateList?: string[]): this;
|
|
250
|
-
addTo(router: QueryRouter | {
|
|
251
|
-
add: (route: Route) => void;
|
|
252
|
-
[key: string]: any;
|
|
253
|
-
}, opts?: AddOpts): void;
|
|
254
|
-
throw(...args: any[]): void;
|
|
255
|
-
}
|
|
256
|
-
declare const toJSONSchema: (args: any, opts?: {
|
|
257
|
-
mergeObject?: boolean;
|
|
258
|
-
override?: (opts: {
|
|
259
|
-
jsonSchema: any;
|
|
260
|
-
path: string[];
|
|
261
|
-
zodSchema: z.ZodTypeAny;
|
|
262
|
-
}) => void;
|
|
263
|
-
}) => {
|
|
264
|
-
[key: string]: any;
|
|
265
|
-
};
|
|
266
|
-
declare const fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
267
|
-
mergeObject?: boolean;
|
|
268
|
-
}) => Merge extends true ? z.ZodObject<{
|
|
269
|
-
[key: string]: any;
|
|
270
|
-
}, z.core.$strip> : {
|
|
271
|
-
[key: string]: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* @parmas overwrite 是否覆盖已存在的route,默认true
|
|
275
|
-
*/
|
|
276
|
-
type AddOpts = {
|
|
277
|
-
overwrite?: boolean;
|
|
278
|
-
};
|
|
279
|
-
declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements throwError {
|
|
280
|
-
appId: string;
|
|
281
|
-
routes: Route[];
|
|
282
|
-
maxNextRoute: number;
|
|
283
|
-
context?: RouteContext<T>;
|
|
284
|
-
constructor();
|
|
285
|
-
/**
|
|
286
|
-
* add route
|
|
287
|
-
* @param route
|
|
288
|
-
* @param opts
|
|
289
|
-
*/
|
|
290
|
-
add(route: Route, opts?: AddOpts): void;
|
|
291
|
-
/**
|
|
292
|
-
* remove route by path and key
|
|
293
|
-
* @param route
|
|
294
|
-
*/
|
|
295
|
-
remove(route: Route | {
|
|
296
|
-
path: string;
|
|
297
|
-
key?: string;
|
|
298
|
-
}): void;
|
|
299
|
-
/**
|
|
300
|
-
* remove route by id
|
|
301
|
-
* @param uniqueId
|
|
302
|
-
*/
|
|
303
|
-
removeById(uniqueId: string): void;
|
|
304
|
-
/**
|
|
305
|
-
* 执行route
|
|
306
|
-
* @param path
|
|
307
|
-
* @param key
|
|
308
|
-
* @param ctx
|
|
309
|
-
* @returns
|
|
310
|
-
*/
|
|
311
|
-
runRoute(path: string, key: string, ctx?: RouteContext<T>): Promise<RouteContext<T>>;
|
|
312
|
-
/**
|
|
313
|
-
* 第一次执行
|
|
314
|
-
* @param message
|
|
315
|
-
* @param ctx
|
|
316
|
-
* @returns
|
|
317
|
-
*/
|
|
318
|
-
parse(message: {
|
|
319
|
-
path: string;
|
|
320
|
-
key?: string;
|
|
321
|
-
payload?: any;
|
|
322
|
-
}, ctx?: RouteContext<T> & {
|
|
323
|
-
[key: string]: any;
|
|
324
|
-
}): Promise<RouteContext<T, {}, {
|
|
325
|
-
[key: string]: any;
|
|
326
|
-
}>>;
|
|
327
|
-
/**
|
|
328
|
-
* 返回的数据包含所有的context的请求返回的内容,可做其他处理
|
|
329
|
-
* @param message
|
|
330
|
-
* @param ctx
|
|
331
|
-
* @returns
|
|
332
|
-
*/
|
|
333
|
-
call(message: {
|
|
334
|
-
id?: string;
|
|
335
|
-
path?: string;
|
|
336
|
-
key?: string;
|
|
337
|
-
payload?: any;
|
|
338
|
-
}, ctx?: RouteContext<T> & {
|
|
339
|
-
[key: string]: any;
|
|
340
|
-
}): Promise<RouteContext<T, {}, {
|
|
341
|
-
[key: string]: any;
|
|
342
|
-
}> | {
|
|
343
|
-
code: number;
|
|
344
|
-
body: any;
|
|
345
|
-
message: string;
|
|
346
|
-
}>;
|
|
347
|
-
/**
|
|
348
|
-
* 请求 result 的数据
|
|
349
|
-
* @param message
|
|
350
|
-
* @param ctx
|
|
351
|
-
* @deprecated use run or call instead
|
|
352
|
-
* @returns
|
|
353
|
-
*/
|
|
354
|
-
queryRoute(message: {
|
|
355
|
-
id?: string;
|
|
356
|
-
path: string;
|
|
357
|
-
key?: string;
|
|
358
|
-
payload?: any;
|
|
359
|
-
}, ctx?: RouteContext & {
|
|
360
|
-
[key: string]: any;
|
|
361
|
-
}): Promise<{
|
|
362
|
-
code: number;
|
|
363
|
-
data: any;
|
|
364
|
-
message: string;
|
|
365
|
-
}>;
|
|
366
|
-
/**
|
|
367
|
-
* Router Run获取数据
|
|
368
|
-
* @param message
|
|
369
|
-
* @param ctx
|
|
370
|
-
* @returns
|
|
371
|
-
*/
|
|
372
|
-
run(message: {
|
|
373
|
-
id?: string;
|
|
374
|
-
path?: string;
|
|
375
|
-
key?: string;
|
|
376
|
-
payload?: any;
|
|
377
|
-
}, ctx?: RouteContext<T> & {
|
|
378
|
-
[key: string]: any;
|
|
379
|
-
}): Promise<{
|
|
380
|
-
code: number;
|
|
381
|
-
data: any;
|
|
382
|
-
message: string;
|
|
383
|
-
}>;
|
|
384
|
-
/**
|
|
385
|
-
* 设置上下文
|
|
386
|
-
* @description 这里的上下文是为了在handle函数中使用
|
|
387
|
-
* @param ctx
|
|
388
|
-
*/
|
|
389
|
-
setContext(ctx: RouteContext): void;
|
|
390
|
-
getList(filter?: (route: Route) => boolean): RouteInfo[];
|
|
391
|
-
/**
|
|
392
|
-
* 获取handle函数, 这里会去执行parse函数
|
|
393
|
-
*/
|
|
394
|
-
getHandle<T = any>(router: QueryRouter, wrapperFn?: HandleFn, ctx?: RouteContext): (msg: {
|
|
395
|
-
id?: string;
|
|
396
|
-
path?: string;
|
|
397
|
-
key?: string;
|
|
398
|
-
[key: string]: any;
|
|
399
|
-
}, handleContext?: RouteContext<T>) => Promise<{
|
|
400
|
-
[key: string]: any;
|
|
401
|
-
code: string;
|
|
402
|
-
data?: any;
|
|
403
|
-
message?: string;
|
|
404
|
-
} | {
|
|
405
|
-
code: any;
|
|
406
|
-
data: any;
|
|
407
|
-
message: any;
|
|
408
|
-
} | {
|
|
409
|
-
code: number;
|
|
410
|
-
message: any;
|
|
411
|
-
data?: undefined;
|
|
412
|
-
}>;
|
|
413
|
-
exportRoutes(): Route<SimpleObject$1, SimpleObject$1>[];
|
|
414
|
-
importRoutes(routes: Route[]): void;
|
|
415
|
-
importRouter(router: QueryRouter): void;
|
|
416
|
-
throw(...args: any[]): void;
|
|
417
|
-
hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1>;
|
|
418
|
-
findRoute(opts?: {
|
|
419
|
-
path?: string;
|
|
420
|
-
key?: string;
|
|
421
|
-
id?: string;
|
|
422
|
-
}): Route<SimpleObject$1, SimpleObject$1>;
|
|
423
|
-
createRouteList(opts?: {
|
|
424
|
-
force?: boolean;
|
|
425
|
-
filter?: (route: Route) => boolean;
|
|
426
|
-
middleware?: string[];
|
|
427
|
-
}): void;
|
|
428
|
-
/**
|
|
429
|
-
* 等待程序运行, 获取到message的数据,就执行
|
|
430
|
-
* params 是预设参数
|
|
431
|
-
* emitter = process
|
|
432
|
-
* -- .exit
|
|
433
|
-
* -- .on
|
|
434
|
-
* -- .send
|
|
435
|
-
*/
|
|
436
|
-
wait(params?: {
|
|
437
|
-
message: RunMessage;
|
|
438
|
-
}, opts?: {
|
|
439
|
-
mockProcess?: MockProcess;
|
|
440
|
-
timeout?: number;
|
|
441
|
-
getList?: boolean;
|
|
442
|
-
force?: boolean;
|
|
443
|
-
filter?: (route: Route) => boolean;
|
|
444
|
-
routeListMiddleware?: string[];
|
|
445
|
-
}): Promise<void>;
|
|
446
|
-
toJSONSchema: (args: any, opts?: {
|
|
447
|
-
mergeObject?: boolean;
|
|
448
|
-
override?: (opts: {
|
|
449
|
-
jsonSchema: any;
|
|
450
|
-
path: string[];
|
|
451
|
-
zodSchema: z.ZodTypeAny;
|
|
452
|
-
}) => void;
|
|
453
|
-
}) => {
|
|
454
|
-
[key: string]: any;
|
|
455
|
-
};
|
|
456
|
-
fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
457
|
-
mergeObject?: boolean;
|
|
458
|
-
}) => Merge extends true ? z.ZodObject<{
|
|
459
|
-
[key: string]: any;
|
|
460
|
-
}, z.core.$strip> : {
|
|
461
|
-
[key: string]: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
type QueryRouterServerOpts<C extends SimpleObject$1 = SimpleObject$1> = {
|
|
465
|
-
handleFn?: HandleFn;
|
|
466
|
-
context?: RouteContext<C>;
|
|
467
|
-
appId?: string;
|
|
468
|
-
initHandle?: boolean;
|
|
469
|
-
};
|
|
470
|
-
interface HandleFn<T = any> {
|
|
471
|
-
(msg: {
|
|
472
|
-
path: string;
|
|
473
|
-
[key: string]: any;
|
|
474
|
-
}, ctx?: any): {
|
|
475
|
-
code: string;
|
|
476
|
-
data?: any;
|
|
477
|
-
message?: string;
|
|
478
|
-
[key: string]: any;
|
|
479
|
-
};
|
|
480
|
-
(res: RouteContext<T>): any;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* QueryRouterServer
|
|
484
|
-
* @description 移除server相关的功能,只保留router相关的功能,和http.createServer不相关,独立
|
|
485
|
-
* @template C 自定义 RouteContext 类型
|
|
486
|
-
*/
|
|
487
|
-
declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> extends QueryRouter<C> {
|
|
488
|
-
appId: string;
|
|
489
|
-
handle: any;
|
|
490
|
-
context: RouteContext<C>;
|
|
491
|
-
constructor(opts?: QueryRouterServerOpts<C>);
|
|
492
|
-
setHandle(wrapperFn?: HandleFn, ctx?: RouteContext): void;
|
|
493
|
-
addRoute(route: Route, opts?: AddOpts): void;
|
|
494
|
-
Route: typeof Route;
|
|
495
|
-
route<M extends SimpleObject$1 = SimpleObject$1>(opts: RouteOpts & {
|
|
496
|
-
metadata?: M;
|
|
497
|
-
}): Route<M, Required<RouteContext<C>>>;
|
|
498
|
-
route<M extends SimpleObject$1 = SimpleObject$1>(path: string, opts?: RouteOpts & {
|
|
499
|
-
metadata?: M;
|
|
500
|
-
}): Route<M, Required<RouteContext<C>>>;
|
|
501
|
-
route<M extends SimpleObject$1 = SimpleObject$1>(path: string, key?: string): Route<M, Required<RouteContext<C>>>;
|
|
502
|
-
route<M extends SimpleObject$1 = SimpleObject$1>(path: string, key?: string, opts?: RouteOpts & {
|
|
503
|
-
metadata?: M;
|
|
504
|
-
}): Route<M, Required<RouteContext<C>>>;
|
|
505
|
-
prompt(description: string): Route<SimpleObject$1, SimpleObject$1>;
|
|
506
|
-
/**
|
|
507
|
-
* 调用了handle
|
|
508
|
-
* @param param0
|
|
509
|
-
* @returns
|
|
510
|
-
*/
|
|
511
|
-
run(msg: {
|
|
512
|
-
id?: string;
|
|
513
|
-
path?: string;
|
|
514
|
-
key?: string;
|
|
515
|
-
payload?: any;
|
|
516
|
-
token?: string;
|
|
517
|
-
data?: any;
|
|
518
|
-
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
519
|
-
runAction<T extends {
|
|
520
|
-
id?: string;
|
|
521
|
-
path?: string;
|
|
522
|
-
key?: string;
|
|
523
|
-
metadata?: {
|
|
524
|
-
args?: any;
|
|
525
|
-
};
|
|
526
|
-
} = {}>(api: T, payload: RunActionPayload<T>, ctx?: RouteContext<C>): Promise<any>;
|
|
527
|
-
}
|
|
528
|
-
declare class Mini extends QueryRouterServer {
|
|
529
|
-
}
|
|
530
|
-
/** JSON Schema 基本类型映射到 TypeScript 类型 */
|
|
531
|
-
type JsonSchemaTypeToTS<T> = T extends {
|
|
532
|
-
type: "string";
|
|
533
|
-
} ? string : T extends {
|
|
534
|
-
type: "boolean";
|
|
535
|
-
} ? boolean : T extends {
|
|
536
|
-
type: "number";
|
|
537
|
-
} ? number : T extends {
|
|
538
|
-
type: "integer";
|
|
539
|
-
} ? number : T extends {
|
|
540
|
-
type: "object";
|
|
541
|
-
} ? object : T extends {
|
|
542
|
-
type: "array";
|
|
543
|
-
} ? any[] : any;
|
|
544
|
-
/** 将 args shape(key -> JSON Schema 类型)转换为 payload 类型,支持 optional: true 的字段为可选 */
|
|
545
|
-
type ArgsShapeToPayload<T> = {
|
|
546
|
-
[K in keyof T as T[K] extends {
|
|
547
|
-
optional: true;
|
|
548
|
-
} ? never : K]: JsonSchemaTypeToTS<T[K]>;
|
|
549
|
-
} & {
|
|
550
|
-
[K in keyof T as T[K] extends {
|
|
551
|
-
optional: true;
|
|
552
|
-
} ? K : never]?: JsonSchemaTypeToTS<T[K]>;
|
|
553
|
-
};
|
|
554
|
-
/** 处理两种 args 格式:完整 JSON Schema(含 properties)或简单 key->type 映射 */
|
|
555
|
-
type ArgsToPayload<T> = T extends {
|
|
556
|
-
type: "object";
|
|
557
|
-
properties: infer P;
|
|
558
|
-
} ? ArgsShapeToPayload<P> : ArgsShapeToPayload<T>;
|
|
559
|
-
/** 从 API 定义中提取 metadata.args */
|
|
560
|
-
type ExtractArgs<T> = T extends {
|
|
561
|
-
metadata: {
|
|
562
|
-
args: infer A;
|
|
563
|
-
};
|
|
564
|
-
} ? A : {};
|
|
565
|
-
/** runAction 第二个参数的类型,根据第一个参数的 metadata.args 推断 */
|
|
566
|
-
type RunActionPayload<T> = ArgsToPayload<ExtractArgs<T>>;
|
|
567
|
-
|
|
568
|
-
type BaseRule = {
|
|
569
|
-
value?: any;
|
|
570
|
-
required?: boolean;
|
|
571
|
-
message?: string;
|
|
572
|
-
};
|
|
573
|
-
type RuleString = {
|
|
574
|
-
type: 'string';
|
|
575
|
-
min?: number;
|
|
576
|
-
max?: number;
|
|
577
|
-
regex?: string;
|
|
578
|
-
} & BaseRule;
|
|
579
|
-
type RuleNumber = {
|
|
580
|
-
type: 'number';
|
|
581
|
-
min?: number;
|
|
582
|
-
max?: number;
|
|
583
|
-
} & BaseRule;
|
|
584
|
-
type RuleBoolean = {
|
|
585
|
-
type: 'boolean';
|
|
586
|
-
} & BaseRule;
|
|
587
|
-
type RuleArray = {
|
|
588
|
-
type: 'array';
|
|
589
|
-
items: Rule;
|
|
590
|
-
} & BaseRule;
|
|
591
|
-
type RuleObject = {
|
|
592
|
-
type: 'object';
|
|
593
|
-
properties: {
|
|
594
|
-
[key: string]: Rule;
|
|
595
|
-
};
|
|
596
|
-
} & BaseRule;
|
|
597
|
-
type RuleAny = {
|
|
598
|
-
type: 'any';
|
|
599
|
-
} & BaseRule;
|
|
600
|
-
type Rule = RuleString | RuleNumber | RuleBoolean | RuleArray | RuleObject | RuleAny;
|
|
601
|
-
declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
|
|
602
|
-
|
|
603
|
-
type Schema = z.ZodType<any, any, any>;
|
|
604
|
-
|
|
605
|
-
type RouteObject = {
|
|
606
|
-
[key: string]: RouteOpts;
|
|
607
|
-
};
|
|
608
|
-
type SimpleObject = Record<string, any>;
|
|
609
|
-
declare function define<T extends Record<string, RouteOpts>>(value: T): {
|
|
610
|
-
[K in keyof T]: T[K] & RouteOpts;
|
|
611
|
-
};
|
|
612
|
-
type RouteArray = RouteOpts[];
|
|
613
|
-
type ChainOptions = {
|
|
614
|
-
app: QueryRouterServer;
|
|
615
|
-
};
|
|
616
|
-
declare class Chain {
|
|
617
|
-
object: RouteOpts;
|
|
618
|
-
app?: QueryRouterServer;
|
|
619
|
-
constructor(object: RouteOpts, opts?: ChainOptions);
|
|
620
|
-
get key(): string;
|
|
621
|
-
get path(): string;
|
|
622
|
-
setDescription(desc: string): this;
|
|
623
|
-
setMeta(metadata: {
|
|
624
|
-
[key: string]: any;
|
|
625
|
-
}): this;
|
|
626
|
-
setPath(path: string): this;
|
|
627
|
-
setMiddleware(middleware: RouteMiddleware[]): this;
|
|
628
|
-
setKey(key: string): this;
|
|
629
|
-
setId(key: string): this;
|
|
630
|
-
setRun<U extends SimpleObject = {}>(run: Run<U>): this;
|
|
631
|
-
define<U extends SimpleObject = {}>(run: Run<U>): this;
|
|
632
|
-
createRoute(): this;
|
|
633
|
-
}
|
|
634
|
-
type QueryChainOptions = {
|
|
635
|
-
query?: Query;
|
|
636
|
-
omitKeys?: string[];
|
|
637
|
-
};
|
|
638
|
-
declare class QueryChain {
|
|
639
|
-
obj: SimpleObject;
|
|
640
|
-
query: Query;
|
|
641
|
-
omitKeys: string[];
|
|
642
|
-
constructor(value?: SimpleObject, opts?: QueryChainOptions);
|
|
643
|
-
omit(obj: SimpleObject, key?: string[]): {
|
|
644
|
-
[x: string]: any;
|
|
645
|
-
};
|
|
646
|
-
/**
|
|
647
|
-
* 生成
|
|
648
|
-
* @param queryData
|
|
649
|
-
* @returns
|
|
650
|
-
*/
|
|
651
|
-
getKey(queryData?: SimpleObject): Pick<RouteOpts, 'path' | 'key' | 'metadata' | 'description'>;
|
|
652
|
-
post<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
653
|
-
get<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
654
|
-
}
|
|
655
|
-
declare const util: {
|
|
656
|
-
getChain: (obj: RouteOpts, opts?: ChainOptions) => Chain;
|
|
657
|
-
};
|
|
658
|
-
declare class QueryUtil<T extends RouteObject = RouteObject> {
|
|
659
|
-
obj: T;
|
|
660
|
-
app: QueryRouterServer;
|
|
661
|
-
query: Query;
|
|
662
|
-
constructor(object: T, opts?: ChainOptions & QueryChainOptions);
|
|
663
|
-
static createFormObj<U extends RouteObject>(object: U, opts?: ChainOptions): QueryUtil<U>;
|
|
664
|
-
static create<U extends Record<string, RouteOpts>>(value: U, opts?: ChainOptions): QueryUtil<U>;
|
|
665
|
-
get<K extends keyof T>(key: K): RouteOpts;
|
|
666
|
-
chain<K extends keyof T>(key: K, opts?: ChainOptions): Chain;
|
|
667
|
-
queryChain<K extends keyof T>(key: K, opts?: QueryChainOptions): QueryChain;
|
|
668
|
-
static Chain: typeof Chain;
|
|
669
|
-
static QueryChain: typeof QueryChain;
|
|
670
|
-
get routeObject(): T;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
declare const App: typeof QueryRouterServer;
|
|
674
|
-
|
|
675
|
-
export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, fromJSONSchema, toJSONSchema, tool, util };
|
|
676
|
-
export type { ListenProcessParams, ListenProcessResponse, RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, Rule, Run, Schema, Skill };
|