@kevisual/router 0.2.5 → 0.2.7
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/README.md +13 -12
- package/dist/app.js +13 -9
- package/dist/commander.d.ts +43 -14
- package/dist/commander.js +44 -33
- package/dist/opencode.d.ts +36 -12
- package/dist/opencode.js +1 -1
- package/dist/router-browser.d.ts +38 -33
- package/dist/router-browser.js +11 -8
- package/dist/router-define.d.ts +34 -13
- package/dist/router-simple.d.ts +3 -2
- package/dist/router-simple.js +118 -143
- package/dist/router.d.ts +46 -35
- package/dist/router.js +11 -8
- package/dist/ws.d.ts +36 -12
- package/package.json +7 -7
- package/src/auto/listen/server-time.ts +1 -1
- package/src/browser.ts +0 -2
- package/src/commander.ts +46 -37
- package/src/index.ts +0 -2
- package/src/route.ts +21 -13
- package/src/router-simple.ts +1 -1
- package/src/test/api.d.ts +72 -0
- package/src/test/api.js +1 -0
- package/src/test/cli.ts +0 -0
- package/src/test/mini.ts +11 -3
- package/src/test/route-ts.ts +1 -1
- package/src/test/run-schema.ts +2 -1
- package/src/test/static.ts +1 -1
- package/src/test/ws.ts +1 -0
- package/src/utils/listen-process.ts +1 -1
- package/src/test/define.ts +0 -14
- package/src/test/listen-ip.ts +0 -18
- package/src/test/schema.ts +0 -14
package/dist/router-browser.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ declare class CustomError extends Error {
|
|
|
16
16
|
static fromCode(code?: number): CustomError;
|
|
17
17
|
static fromErrorData(code?: number, data?: any): CustomError;
|
|
18
18
|
static parseError(e: CustomError): {
|
|
19
|
-
code: number
|
|
19
|
+
code: number;
|
|
20
20
|
data: any;
|
|
21
21
|
message: string;
|
|
22
22
|
};
|
|
@@ -30,7 +30,7 @@ declare class CustomError extends Error {
|
|
|
30
30
|
static throw(code?: number | string, opts?: CustomErrorOptions): void;
|
|
31
31
|
static throw(opts?: CustomErrorOptions): void;
|
|
32
32
|
parse(e?: CustomError): {
|
|
33
|
-
code: number
|
|
33
|
+
code: number;
|
|
34
34
|
data: any;
|
|
35
35
|
message: string;
|
|
36
36
|
};
|
|
@@ -53,22 +53,6 @@ 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
56
|
|
|
73
57
|
type RouterContextT = {
|
|
74
58
|
code?: number;
|
|
@@ -226,7 +210,7 @@ declare class Route<M extends SimpleObject$1 = SimpleObject$1, U extends SimpleO
|
|
|
226
210
|
description?: string;
|
|
227
211
|
metadata?: M;
|
|
228
212
|
middleware?: RouteMiddleware[];
|
|
229
|
-
type?: string
|
|
213
|
+
type?: string;
|
|
230
214
|
/**
|
|
231
215
|
* 是否开启debug,开启后会打印错误信息
|
|
232
216
|
*/
|
|
@@ -319,6 +303,7 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
319
303
|
path: string;
|
|
320
304
|
key?: string;
|
|
321
305
|
payload?: any;
|
|
306
|
+
args?: any;
|
|
322
307
|
}, ctx?: RouteContext<T> & {
|
|
323
308
|
[key: string]: any;
|
|
324
309
|
}): Promise<RouteContext<T, {}, {
|
|
@@ -335,13 +320,14 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
335
320
|
path?: string;
|
|
336
321
|
key?: string;
|
|
337
322
|
payload?: any;
|
|
323
|
+
args?: any;
|
|
338
324
|
}, ctx?: RouteContext<T> & {
|
|
339
325
|
[key: string]: any;
|
|
340
326
|
}): Promise<RouteContext<T, {}, {
|
|
341
327
|
[key: string]: any;
|
|
342
328
|
}> | {
|
|
343
329
|
code: number;
|
|
344
|
-
body:
|
|
330
|
+
body: any;
|
|
345
331
|
message: string;
|
|
346
332
|
}>;
|
|
347
333
|
/**
|
|
@@ -356,12 +342,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
356
342
|
path: string;
|
|
357
343
|
key?: string;
|
|
358
344
|
payload?: any;
|
|
345
|
+
args?: any;
|
|
359
346
|
}, ctx?: RouteContext & {
|
|
360
347
|
[key: string]: any;
|
|
361
348
|
}): Promise<{
|
|
362
|
-
code: number
|
|
363
|
-
data:
|
|
364
|
-
message: string
|
|
349
|
+
code: number;
|
|
350
|
+
data: any;
|
|
351
|
+
message: string;
|
|
365
352
|
}>;
|
|
366
353
|
/**
|
|
367
354
|
* Router Run获取数据
|
|
@@ -374,12 +361,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
374
361
|
path?: string;
|
|
375
362
|
key?: string;
|
|
376
363
|
payload?: any;
|
|
364
|
+
args?: any;
|
|
377
365
|
}, ctx?: RouteContext<T> & {
|
|
378
366
|
[key: string]: any;
|
|
379
367
|
}): Promise<{
|
|
380
|
-
code: number
|
|
381
|
-
data:
|
|
382
|
-
message: string
|
|
368
|
+
code: number;
|
|
369
|
+
data: any;
|
|
370
|
+
message: string;
|
|
383
371
|
}>;
|
|
384
372
|
/**
|
|
385
373
|
* 设置上下文
|
|
@@ -414,12 +402,12 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
414
402
|
importRoutes(routes: Route[]): void;
|
|
415
403
|
importRouter(router: QueryRouter): void;
|
|
416
404
|
throw(...args: any[]): void;
|
|
417
|
-
hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1
|
|
405
|
+
hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1>;
|
|
418
406
|
findRoute(opts?: {
|
|
419
407
|
path?: string;
|
|
420
408
|
key?: string;
|
|
421
409
|
rid?: string;
|
|
422
|
-
}): Route<SimpleObject$1, SimpleObject$1
|
|
410
|
+
}): Route<SimpleObject$1, SimpleObject$1>;
|
|
423
411
|
createRouteList(opts?: {
|
|
424
412
|
force?: boolean;
|
|
425
413
|
filter?: (route: Route) => boolean;
|
|
@@ -513,6 +501,21 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
513
501
|
path?: string;
|
|
514
502
|
key?: string;
|
|
515
503
|
payload?: any;
|
|
504
|
+
args?: any;
|
|
505
|
+
token?: string;
|
|
506
|
+
data?: any;
|
|
507
|
+
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
508
|
+
/**
|
|
509
|
+
* 调用了handle
|
|
510
|
+
* @param param0
|
|
511
|
+
* @returns
|
|
512
|
+
*/
|
|
513
|
+
runLocal(msg: {
|
|
514
|
+
rid?: string;
|
|
515
|
+
path?: string;
|
|
516
|
+
key?: string;
|
|
517
|
+
payload?: any;
|
|
518
|
+
args?: any;
|
|
516
519
|
token?: string;
|
|
517
520
|
data?: any;
|
|
518
521
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
@@ -528,7 +531,9 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
528
531
|
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
529
532
|
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
530
533
|
*/
|
|
531
|
-
createAuth(fun
|
|
534
|
+
createAuth(fun?: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any, opts?: {
|
|
535
|
+
overwrite?: boolean;
|
|
536
|
+
}): Promise<void>;
|
|
532
537
|
}
|
|
533
538
|
declare class Mini extends QueryRouterServer {
|
|
534
539
|
}
|
|
@@ -622,8 +627,8 @@ declare class Chain {
|
|
|
622
627
|
object: RouteOpts;
|
|
623
628
|
app?: QueryRouterServer;
|
|
624
629
|
constructor(object: RouteOpts, opts?: ChainOptions);
|
|
625
|
-
get key(): string
|
|
626
|
-
get path(): string
|
|
630
|
+
get key(): string;
|
|
631
|
+
get path(): string;
|
|
627
632
|
setDescription(desc: string): this;
|
|
628
633
|
setMeta(metadata: {
|
|
629
634
|
[key: string]: any;
|
|
@@ -677,5 +682,5 @@ declare class QueryUtil<T extends RouteObject = RouteObject> {
|
|
|
677
682
|
|
|
678
683
|
declare const App: typeof QueryRouterServer;
|
|
679
684
|
|
|
680
|
-
export { App, CustomError, Mini,
|
|
681
|
-
export type {
|
|
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 };
|
package/dist/router-browser.js
CHANGED
|
@@ -18980,7 +18980,7 @@ var listenProcess = async ({ app, mockProcess, params = {}, timeout: timeout2 =
|
|
|
18980
18980
|
const ctx = mergeParams?.context || {};
|
|
18981
18981
|
if (!msg.path && !msg.id) {
|
|
18982
18982
|
const route = app.routes.find((r) => r.path !== "router");
|
|
18983
|
-
msg.id = route?.
|
|
18983
|
+
msg.id = route?.rid;
|
|
18984
18984
|
}
|
|
18985
18985
|
const result = await app.run(msg, ctx);
|
|
18986
18986
|
const response = {
|
|
@@ -32971,9 +32971,9 @@ class QueryRouter {
|
|
|
32971
32971
|
if (!message?.path) {
|
|
32972
32972
|
return Promise.resolve({ code: 404, body: null, message: "Not found path" });
|
|
32973
32973
|
}
|
|
32974
|
-
const { path, key = "", payload = {}, ...query } = message;
|
|
32974
|
+
const { path, key = "", payload = {}, args = {}, ...query } = message;
|
|
32975
32975
|
ctx = ctx || {};
|
|
32976
|
-
ctx.query = { ...ctx.query, ...query, ...payload };
|
|
32976
|
+
ctx.query = { ...ctx.query, ...query, ...payload, ...args };
|
|
32977
32977
|
ctx.args = ctx.query;
|
|
32978
32978
|
ctx.state = { ...ctx?.state };
|
|
32979
32979
|
ctx.throw = this.throw;
|
|
@@ -33179,11 +33179,15 @@ class QueryRouterServer extends QueryRouter {
|
|
|
33179
33179
|
}
|
|
33180
33180
|
return super.run(msg, ctx);
|
|
33181
33181
|
}
|
|
33182
|
+
async runLocal(msg, ctx) {
|
|
33183
|
+
return this.run(msg, { ...ctx, appId: this.appId });
|
|
33184
|
+
}
|
|
33182
33185
|
async runAction(api2, payload, ctx) {
|
|
33183
33186
|
const { path, key, rid } = api2;
|
|
33184
33187
|
return this.run({ path, key, rid, payload }, ctx);
|
|
33185
33188
|
}
|
|
33186
|
-
async createAuth(fun) {
|
|
33189
|
+
async createAuth(fun, opts) {
|
|
33190
|
+
const overwrite = opts?.overwrite ?? false;
|
|
33187
33191
|
this.route({
|
|
33188
33192
|
path: "auth",
|
|
33189
33193
|
key: "auth",
|
|
@@ -33193,7 +33197,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
33193
33197
|
if (fun) {
|
|
33194
33198
|
await fun(ctx, "auth");
|
|
33195
33199
|
}
|
|
33196
|
-
}).addTo(this, { overwrite
|
|
33200
|
+
}).addTo(this, { overwrite });
|
|
33197
33201
|
this.route({
|
|
33198
33202
|
path: "auth-admin",
|
|
33199
33203
|
key: "auth-admin",
|
|
@@ -33204,7 +33208,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
33204
33208
|
if (fun) {
|
|
33205
33209
|
await fun(ctx, "auth-admin");
|
|
33206
33210
|
}
|
|
33207
|
-
}).addTo(this, { overwrite
|
|
33211
|
+
}).addTo(this, { overwrite });
|
|
33208
33212
|
this.route({
|
|
33209
33213
|
path: "auth-can",
|
|
33210
33214
|
key: "auth-can",
|
|
@@ -33214,7 +33218,7 @@ class QueryRouterServer extends QueryRouter {
|
|
|
33214
33218
|
if (fun) {
|
|
33215
33219
|
await fun(ctx, "auth-can");
|
|
33216
33220
|
}
|
|
33217
|
-
}).addTo(this, { overwrite
|
|
33221
|
+
}).addTo(this, { overwrite });
|
|
33218
33222
|
}
|
|
33219
33223
|
}
|
|
33220
33224
|
|
|
@@ -33409,7 +33413,6 @@ export {
|
|
|
33409
33413
|
QueryUtil,
|
|
33410
33414
|
QueryRouterServer,
|
|
33411
33415
|
QueryRouter,
|
|
33412
|
-
MockProcess,
|
|
33413
33416
|
Mini,
|
|
33414
33417
|
CustomError,
|
|
33415
33418
|
App
|
package/dist/router-define.d.ts
CHANGED
|
@@ -168,7 +168,7 @@ declare class Route<M extends SimpleObject$1 = SimpleObject$1, U extends SimpleO
|
|
|
168
168
|
description?: string;
|
|
169
169
|
metadata?: M;
|
|
170
170
|
middleware?: RouteMiddleware[];
|
|
171
|
-
type?: string
|
|
171
|
+
type?: string;
|
|
172
172
|
/**
|
|
173
173
|
* 是否开启debug,开启后会打印错误信息
|
|
174
174
|
*/
|
|
@@ -244,6 +244,7 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
244
244
|
path: string;
|
|
245
245
|
key?: string;
|
|
246
246
|
payload?: any;
|
|
247
|
+
args?: any;
|
|
247
248
|
}, ctx?: RouteContext<T> & {
|
|
248
249
|
[key: string]: any;
|
|
249
250
|
}): Promise<RouteContext<T, {}, {
|
|
@@ -260,13 +261,14 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
260
261
|
path?: string;
|
|
261
262
|
key?: string;
|
|
262
263
|
payload?: any;
|
|
264
|
+
args?: any;
|
|
263
265
|
}, ctx?: RouteContext<T> & {
|
|
264
266
|
[key: string]: any;
|
|
265
267
|
}): Promise<RouteContext<T, {}, {
|
|
266
268
|
[key: string]: any;
|
|
267
269
|
}> | {
|
|
268
270
|
code: number;
|
|
269
|
-
body:
|
|
271
|
+
body: any;
|
|
270
272
|
message: string;
|
|
271
273
|
}>;
|
|
272
274
|
/**
|
|
@@ -281,12 +283,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
281
283
|
path: string;
|
|
282
284
|
key?: string;
|
|
283
285
|
payload?: any;
|
|
286
|
+
args?: any;
|
|
284
287
|
}, ctx?: RouteContext & {
|
|
285
288
|
[key: string]: any;
|
|
286
289
|
}): Promise<{
|
|
287
|
-
code: number
|
|
288
|
-
data:
|
|
289
|
-
message: string
|
|
290
|
+
code: number;
|
|
291
|
+
data: any;
|
|
292
|
+
message: string;
|
|
290
293
|
}>;
|
|
291
294
|
/**
|
|
292
295
|
* Router Run获取数据
|
|
@@ -299,12 +302,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
299
302
|
path?: string;
|
|
300
303
|
key?: string;
|
|
301
304
|
payload?: any;
|
|
305
|
+
args?: any;
|
|
302
306
|
}, ctx?: RouteContext<T> & {
|
|
303
307
|
[key: string]: any;
|
|
304
308
|
}): Promise<{
|
|
305
|
-
code: number
|
|
306
|
-
data:
|
|
307
|
-
message: string
|
|
309
|
+
code: number;
|
|
310
|
+
data: any;
|
|
311
|
+
message: string;
|
|
308
312
|
}>;
|
|
309
313
|
/**
|
|
310
314
|
* 设置上下文
|
|
@@ -339,12 +343,12 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
|
|
|
339
343
|
importRoutes(routes: Route[]): void;
|
|
340
344
|
importRouter(router: QueryRouter): void;
|
|
341
345
|
throw(...args: any[]): void;
|
|
342
|
-
hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1
|
|
346
|
+
hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1>;
|
|
343
347
|
findRoute(opts?: {
|
|
344
348
|
path?: string;
|
|
345
349
|
key?: string;
|
|
346
350
|
rid?: string;
|
|
347
|
-
}): Route<SimpleObject$1, SimpleObject$1
|
|
351
|
+
}): Route<SimpleObject$1, SimpleObject$1>;
|
|
348
352
|
createRouteList(opts?: {
|
|
349
353
|
force?: boolean;
|
|
350
354
|
filter?: (route: Route) => boolean;
|
|
@@ -438,6 +442,21 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
438
442
|
path?: string;
|
|
439
443
|
key?: string;
|
|
440
444
|
payload?: any;
|
|
445
|
+
args?: any;
|
|
446
|
+
token?: string;
|
|
447
|
+
data?: any;
|
|
448
|
+
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
449
|
+
/**
|
|
450
|
+
* 调用了handle
|
|
451
|
+
* @param param0
|
|
452
|
+
* @returns
|
|
453
|
+
*/
|
|
454
|
+
runLocal(msg: {
|
|
455
|
+
rid?: string;
|
|
456
|
+
path?: string;
|
|
457
|
+
key?: string;
|
|
458
|
+
payload?: any;
|
|
459
|
+
args?: any;
|
|
441
460
|
token?: string;
|
|
442
461
|
data?: any;
|
|
443
462
|
}, ctx?: Partial<RouteContext<C>>): Promise<any>;
|
|
@@ -453,7 +472,9 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
|
|
|
453
472
|
* 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
|
|
454
473
|
* @param fun 认证函数,接收 RouteContext 和认证类型
|
|
455
474
|
*/
|
|
456
|
-
createAuth(fun
|
|
475
|
+
createAuth(fun?: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any, opts?: {
|
|
476
|
+
overwrite?: boolean;
|
|
477
|
+
}): Promise<void>;
|
|
457
478
|
}
|
|
458
479
|
/** JSON Schema 基本类型映射到 TypeScript 类型 */
|
|
459
480
|
type JsonSchemaTypeToTS<T> = T extends {
|
|
@@ -508,8 +529,8 @@ declare class Chain {
|
|
|
508
529
|
object: RouteOpts;
|
|
509
530
|
app?: QueryRouterServer;
|
|
510
531
|
constructor(object: RouteOpts, opts?: ChainOptions);
|
|
511
|
-
get key(): string
|
|
512
|
-
get path(): string
|
|
532
|
+
get key(): string;
|
|
533
|
+
get path(): string;
|
|
513
534
|
setDescription(desc: string): this;
|
|
514
535
|
setMeta(metadata: {
|
|
515
536
|
[key: string]: any;
|
package/dist/router-simple.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as node_querystring from 'node:querystring';
|
|
1
2
|
import { Key } from 'path-to-regexp';
|
|
2
3
|
import { IncomingMessage, ServerResponse, Server } from 'node:http';
|
|
3
4
|
import { ListenOptions } from 'node:net';
|
|
@@ -24,7 +25,7 @@ declare class SimpleRouter {
|
|
|
24
25
|
exclude?: string[];
|
|
25
26
|
});
|
|
26
27
|
getBody(req: Req): Promise<Record<string, any>>;
|
|
27
|
-
getSearch(req: Req):
|
|
28
|
+
getSearch(req: Req): node_querystring.ParsedUrlQuery;
|
|
28
29
|
parseSearchValue: (value?: string, opts?: {
|
|
29
30
|
decode?: boolean;
|
|
30
31
|
}) => any;
|
|
@@ -102,7 +103,7 @@ declare class HttpChain {
|
|
|
102
103
|
listenCallBack?: () => void;
|
|
103
104
|
}): () => void;
|
|
104
105
|
getString(value: string | SimpleObject): string;
|
|
105
|
-
sse(value: string | SimpleObject): this
|
|
106
|
+
sse(value: string | SimpleObject): this;
|
|
106
107
|
close(): this;
|
|
107
108
|
}
|
|
108
109
|
|