@kevisual/router 0.0.34 → 0.0.36
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-browser.d.ts +75 -115
- package/dist/router-browser.js +3320 -4543
- package/dist/router-define.d.ts +1 -1
- package/dist/router.d.ts +101 -128
- package/dist/router.js +4514 -5719
- package/package.json +1 -1
- package/src/app.ts +20 -12
- package/src/route.ts +50 -210
- package/src/router-define.ts +3 -3
- package/src/server/server.ts +12 -2
- package/src/test/app-type.ts +13 -0
package/dist/router-browser.d.ts
CHANGED
|
@@ -4,43 +4,6 @@ import { IncomingMessage } from 'node:http';
|
|
|
4
4
|
import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
|
|
5
5
|
import { Query, DataOpts, Result } from '@kevisual/query/query';
|
|
6
6
|
|
|
7
|
-
type BaseRule = {
|
|
8
|
-
value?: any;
|
|
9
|
-
required?: boolean;
|
|
10
|
-
message?: string;
|
|
11
|
-
};
|
|
12
|
-
type RuleString = {
|
|
13
|
-
type: 'string';
|
|
14
|
-
min?: number;
|
|
15
|
-
max?: number;
|
|
16
|
-
regex?: string;
|
|
17
|
-
} & BaseRule;
|
|
18
|
-
type RuleNumber = {
|
|
19
|
-
type: 'number';
|
|
20
|
-
min?: number;
|
|
21
|
-
max?: number;
|
|
22
|
-
} & BaseRule;
|
|
23
|
-
type RuleBoolean = {
|
|
24
|
-
type: 'boolean';
|
|
25
|
-
} & BaseRule;
|
|
26
|
-
type RuleArray = {
|
|
27
|
-
type: 'array';
|
|
28
|
-
items: Rule;
|
|
29
|
-
} & BaseRule;
|
|
30
|
-
type RuleObject = {
|
|
31
|
-
type: 'object';
|
|
32
|
-
properties: {
|
|
33
|
-
[key: string]: Rule;
|
|
34
|
-
};
|
|
35
|
-
} & BaseRule;
|
|
36
|
-
type RuleAny = {
|
|
37
|
-
type: 'any';
|
|
38
|
-
} & BaseRule;
|
|
39
|
-
type Rule = RuleString | RuleNumber | RuleBoolean | RuleArray | RuleObject | RuleAny;
|
|
40
|
-
declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
|
|
41
|
-
|
|
42
|
-
type Schema = z.ZodType<any, any, any>;
|
|
43
|
-
|
|
44
7
|
type RouterContextT = {
|
|
45
8
|
code?: number;
|
|
46
9
|
[key: string]: any;
|
|
@@ -53,6 +16,11 @@ type RouteContext<T = {
|
|
|
53
16
|
};
|
|
54
17
|
/** return body */
|
|
55
18
|
body?: number | string | Object;
|
|
19
|
+
forward?: (response: {
|
|
20
|
+
code: number;
|
|
21
|
+
data?: any;
|
|
22
|
+
message?: any;
|
|
23
|
+
}) => void;
|
|
56
24
|
/** return code */
|
|
57
25
|
code?: number;
|
|
58
26
|
/** return msg */
|
|
@@ -78,12 +46,9 @@ type RouteContext<T = {
|
|
|
78
46
|
[key: string]: any;
|
|
79
47
|
};
|
|
80
48
|
end?: boolean;
|
|
81
|
-
|
|
82
|
-
* 请求 route的返回结果,包函ctx
|
|
83
|
-
*/
|
|
84
|
-
queryRouter?: QueryRouter;
|
|
49
|
+
app?: QueryRouter;
|
|
85
50
|
error?: any;
|
|
86
|
-
/** 请求 route
|
|
51
|
+
/** 请求 route的返回结果,不解析body为data */
|
|
87
52
|
call?: (message: {
|
|
88
53
|
path: string;
|
|
89
54
|
key?: string;
|
|
@@ -96,8 +61,8 @@ type RouteContext<T = {
|
|
|
96
61
|
}, ctx?: RouteContext & {
|
|
97
62
|
[key: string]: any;
|
|
98
63
|
}) => Promise<any>;
|
|
99
|
-
/** 请求 route
|
|
100
|
-
|
|
64
|
+
/** 请求 route的返回结果,解析了body为data,就类同于 query.post获取的数据*/
|
|
65
|
+
run?: (message: {
|
|
101
66
|
path: string;
|
|
102
67
|
key?: string;
|
|
103
68
|
payload?: any;
|
|
@@ -117,11 +82,11 @@ type RouteMiddleware = {
|
|
|
117
82
|
key?: string;
|
|
118
83
|
id?: string;
|
|
119
84
|
} | string;
|
|
120
|
-
type RouteOpts = {
|
|
85
|
+
type RouteOpts<T = {}> = {
|
|
121
86
|
path?: string;
|
|
122
87
|
key?: string;
|
|
123
88
|
id?: string;
|
|
124
|
-
run?: Run
|
|
89
|
+
run?: Run<T>;
|
|
125
90
|
nextRoute?: NextRoute;
|
|
126
91
|
description?: string;
|
|
127
92
|
metadata?: {
|
|
@@ -129,23 +94,6 @@ type RouteOpts = {
|
|
|
129
94
|
};
|
|
130
95
|
middleware?: RouteMiddleware[];
|
|
131
96
|
type?: 'route' | 'middleware';
|
|
132
|
-
/**
|
|
133
|
-
* validator: {
|
|
134
|
-
* packageName: {
|
|
135
|
-
* type: 'string',
|
|
136
|
-
* required: true,
|
|
137
|
-
* },
|
|
138
|
-
* }
|
|
139
|
-
*/
|
|
140
|
-
validator?: {
|
|
141
|
-
[key: string]: Rule;
|
|
142
|
-
};
|
|
143
|
-
schema?: {
|
|
144
|
-
[key: string]: any;
|
|
145
|
-
};
|
|
146
|
-
isVerify?: boolean;
|
|
147
|
-
verify?: (ctx?: RouteContext, dev?: boolean) => boolean;
|
|
148
|
-
verifyKey?: (key: string, ctx?: RouteContext, dev?: boolean) => boolean;
|
|
149
97
|
/**
|
|
150
98
|
* $#$ will be used to split path and key
|
|
151
99
|
*/
|
|
@@ -156,8 +104,8 @@ type RouteOpts = {
|
|
|
156
104
|
delimiter?: string;
|
|
157
105
|
isDebug?: boolean;
|
|
158
106
|
};
|
|
159
|
-
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | '
|
|
160
|
-
declare const pickValue: readonly ["path", "key", "id", "description", "type", "
|
|
107
|
+
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
108
|
+
declare const pickValue: readonly ["path", "key", "id", "description", "type", "middleware", "metadata"];
|
|
161
109
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
162
110
|
declare class Route<U = {
|
|
163
111
|
[key: string]: any;
|
|
@@ -179,59 +127,12 @@ declare class Route<U = {
|
|
|
179
127
|
};
|
|
180
128
|
middleware?: RouteMiddleware[];
|
|
181
129
|
type?: string;
|
|
182
|
-
private _validator?;
|
|
183
|
-
schema?: {
|
|
184
|
-
[key: string]: any;
|
|
185
|
-
};
|
|
186
130
|
data?: any;
|
|
187
|
-
/**
|
|
188
|
-
* 是否需要验证
|
|
189
|
-
*/
|
|
190
|
-
isVerify?: boolean;
|
|
191
131
|
/**
|
|
192
132
|
* 是否开启debug,开启后会打印错误信息
|
|
193
133
|
*/
|
|
194
134
|
isDebug?: boolean;
|
|
195
135
|
constructor(path?: string, key?: string, opts?: RouteOpts);
|
|
196
|
-
private createSchema;
|
|
197
|
-
/**
|
|
198
|
-
* set validator and create schema
|
|
199
|
-
* @param validator
|
|
200
|
-
*/
|
|
201
|
-
set validator(validator: {
|
|
202
|
-
[key: string]: Rule;
|
|
203
|
-
});
|
|
204
|
-
get validator(): {
|
|
205
|
-
[key: string]: Rule;
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* has code, body, message in ctx, return ctx if has error
|
|
209
|
-
* @param ctx
|
|
210
|
-
* @param dev
|
|
211
|
-
* @returns
|
|
212
|
-
*/
|
|
213
|
-
verify(ctx: RouteContext, dev?: boolean): void;
|
|
214
|
-
/**
|
|
215
|
-
* Need to manully call return ctx fn and configure body, code, message
|
|
216
|
-
* @param key
|
|
217
|
-
* @param ctx
|
|
218
|
-
* @param dev
|
|
219
|
-
* @returns
|
|
220
|
-
*/
|
|
221
|
-
verifyKey(key: string, ctx: RouteContext, dev?: boolean): {
|
|
222
|
-
message: string;
|
|
223
|
-
path: string;
|
|
224
|
-
key: string;
|
|
225
|
-
error: any;
|
|
226
|
-
} | {
|
|
227
|
-
message: string;
|
|
228
|
-
path: string;
|
|
229
|
-
key: string;
|
|
230
|
-
error?: undefined;
|
|
231
|
-
};
|
|
232
|
-
setValidator(validator: {
|
|
233
|
-
[key: string]: Rule;
|
|
234
|
-
}): this;
|
|
235
136
|
prompt(description: string): this;
|
|
236
137
|
prompt(description: Function): this;
|
|
237
138
|
define<T extends {
|
|
@@ -312,6 +213,7 @@ declare class QueryRouter {
|
|
|
312
213
|
* 请求 result 的数据
|
|
313
214
|
* @param message
|
|
314
215
|
* @param ctx
|
|
216
|
+
* @deprecated use run or call instead
|
|
315
217
|
* @returns
|
|
316
218
|
*/
|
|
317
219
|
queryRoute(message: {
|
|
@@ -326,6 +228,24 @@ declare class QueryRouter {
|
|
|
326
228
|
data: any;
|
|
327
229
|
message: any;
|
|
328
230
|
}>;
|
|
231
|
+
/**
|
|
232
|
+
* Router Run获取数据
|
|
233
|
+
* @param message
|
|
234
|
+
* @param ctx
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
run(message: {
|
|
238
|
+
id?: string;
|
|
239
|
+
path?: string;
|
|
240
|
+
key?: string;
|
|
241
|
+
payload?: any;
|
|
242
|
+
}, ctx?: RouteContext & {
|
|
243
|
+
[key: string]: any;
|
|
244
|
+
}): Promise<{
|
|
245
|
+
code: any;
|
|
246
|
+
data: any;
|
|
247
|
+
message: any;
|
|
248
|
+
}>;
|
|
329
249
|
/**
|
|
330
250
|
* 设置上下文
|
|
331
251
|
* @description 这里的上下文是为了在handle函数中使用
|
|
@@ -417,7 +337,7 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
417
337
|
prompt(description: string): Route<Required<RouteContext>>;
|
|
418
338
|
prompt(description: Function): Route<Required<RouteContext>>;
|
|
419
339
|
/**
|
|
420
|
-
*
|
|
340
|
+
* 调用了handle
|
|
421
341
|
* @param param0
|
|
422
342
|
* @returns
|
|
423
343
|
*/
|
|
@@ -425,9 +345,49 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
425
345
|
path: string;
|
|
426
346
|
key?: string;
|
|
427
347
|
payload?: any;
|
|
348
|
+
}, ctx?: RouteContext & {
|
|
349
|
+
[key: string]: any;
|
|
428
350
|
}): Promise<any>;
|
|
429
351
|
}
|
|
430
|
-
declare
|
|
352
|
+
declare class Mini extends QueryRouterServer {
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
type BaseRule = {
|
|
356
|
+
value?: any;
|
|
357
|
+
required?: boolean;
|
|
358
|
+
message?: string;
|
|
359
|
+
};
|
|
360
|
+
type RuleString = {
|
|
361
|
+
type: 'string';
|
|
362
|
+
min?: number;
|
|
363
|
+
max?: number;
|
|
364
|
+
regex?: string;
|
|
365
|
+
} & BaseRule;
|
|
366
|
+
type RuleNumber = {
|
|
367
|
+
type: 'number';
|
|
368
|
+
min?: number;
|
|
369
|
+
max?: number;
|
|
370
|
+
} & BaseRule;
|
|
371
|
+
type RuleBoolean = {
|
|
372
|
+
type: 'boolean';
|
|
373
|
+
} & BaseRule;
|
|
374
|
+
type RuleArray = {
|
|
375
|
+
type: 'array';
|
|
376
|
+
items: Rule;
|
|
377
|
+
} & BaseRule;
|
|
378
|
+
type RuleObject = {
|
|
379
|
+
type: 'object';
|
|
380
|
+
properties: {
|
|
381
|
+
[key: string]: Rule;
|
|
382
|
+
};
|
|
383
|
+
} & BaseRule;
|
|
384
|
+
type RuleAny = {
|
|
385
|
+
type: 'any';
|
|
386
|
+
} & BaseRule;
|
|
387
|
+
type Rule = RuleString | RuleNumber | RuleBoolean | RuleArray | RuleObject | RuleAny;
|
|
388
|
+
declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
|
|
389
|
+
|
|
390
|
+
type Schema = z.ZodType<any, any, any>;
|
|
431
391
|
|
|
432
392
|
/** 自定义错误 */
|
|
433
393
|
declare class CustomError extends Error {
|
|
@@ -514,7 +474,7 @@ declare class QueryChain {
|
|
|
514
474
|
* @param queryData
|
|
515
475
|
* @returns
|
|
516
476
|
*/
|
|
517
|
-
getKey(queryData?: SimpleObject): Pick<RouteOpts$1, 'path' | 'key' | 'metadata' | 'description'
|
|
477
|
+
getKey(queryData?: SimpleObject): Pick<RouteOpts$1, 'path' | 'key' | 'metadata' | 'description'>;
|
|
518
478
|
post<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
519
479
|
get<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
520
480
|
}
|