@kevisual/router 0.0.33 → 0.0.35
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 +24 -3
- package/dist/router-browser.js +80 -81
- package/dist/router-sign.d.ts +2 -2
- package/dist/router-sign.js +13711 -28503
- package/dist/router-simple.d.ts +18 -1
- package/dist/router-simple.js +24 -3
- package/dist/router.d.ts +24 -3
- package/dist/router.js +266 -156
- package/package.json +8 -8
- package/src/route.ts +29 -41
- package/src/router-simple.ts +28 -3
- package/src/test/listen-ip.ts +18 -0
package/dist/router-simple.d.ts
CHANGED
|
@@ -56,9 +56,19 @@ type HttpChainOpts = {
|
|
|
56
56
|
req?: Req;
|
|
57
57
|
res?: ServerResponse;
|
|
58
58
|
simpleRouter?: SimpleRouter;
|
|
59
|
+
server?: Server;
|
|
59
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* HttpChain 类, 用于链式调用,router.get内部使用
|
|
63
|
+
*/
|
|
60
64
|
declare class HttpChain {
|
|
65
|
+
/**
|
|
66
|
+
* 请求对象, 每一次请求都是不一样的
|
|
67
|
+
*/
|
|
61
68
|
req: Req;
|
|
69
|
+
/**
|
|
70
|
+
* 响应对象, 每一次请求响应都是不一样的
|
|
71
|
+
*/
|
|
62
72
|
res: ServerResponse;
|
|
63
73
|
simpleRouter: SimpleRouter;
|
|
64
74
|
server: Server;
|
|
@@ -84,7 +94,14 @@ declare class HttpChain {
|
|
|
84
94
|
*/
|
|
85
95
|
end(data: SimpleObject | string): this;
|
|
86
96
|
listen(opts: ListenOptions, callback?: () => void): this;
|
|
87
|
-
|
|
97
|
+
/**
|
|
98
|
+
* 外部 parse 方法
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
parse(opts?: {
|
|
102
|
+
listenOptions?: ListenOptions;
|
|
103
|
+
listenCallBack?: () => void;
|
|
104
|
+
}): () => void;
|
|
88
105
|
getString(value: string | SimpleObject): string;
|
|
89
106
|
sse(value: string | SimpleObject): this;
|
|
90
107
|
close(): this;
|
package/dist/router-simple.js
CHANGED
|
@@ -593,16 +593,29 @@ class SimpleRouter {
|
|
|
593
593
|
return new HttpChain(opts);
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
|
+
/**
|
|
597
|
+
* HttpChain 类, 用于链式调用,router.get内部使用
|
|
598
|
+
*/
|
|
596
599
|
class HttpChain {
|
|
600
|
+
/**
|
|
601
|
+
* 请求对象, 每一次请求都是不一样的
|
|
602
|
+
*/
|
|
597
603
|
req;
|
|
604
|
+
/**
|
|
605
|
+
* 响应对象, 每一次请求响应都是不一样的
|
|
606
|
+
*/
|
|
598
607
|
res;
|
|
599
608
|
simpleRouter;
|
|
600
609
|
server;
|
|
601
610
|
hasSetHeader = false;
|
|
602
611
|
isSseSet = false;
|
|
603
612
|
constructor(opts) {
|
|
604
|
-
|
|
605
|
-
|
|
613
|
+
if (opts?.res) {
|
|
614
|
+
this.res = opts.res;
|
|
615
|
+
}
|
|
616
|
+
if (opts?.req) {
|
|
617
|
+
this.req = opts.req;
|
|
618
|
+
}
|
|
606
619
|
this.simpleRouter = opts?.simpleRouter;
|
|
607
620
|
}
|
|
608
621
|
setReq(req) {
|
|
@@ -675,7 +688,12 @@ class HttpChain {
|
|
|
675
688
|
this.server.listen(opts, callback);
|
|
676
689
|
return this;
|
|
677
690
|
}
|
|
678
|
-
|
|
691
|
+
/**
|
|
692
|
+
* 外部 parse 方法
|
|
693
|
+
* @returns
|
|
694
|
+
*/
|
|
695
|
+
parse(opts) {
|
|
696
|
+
const { listenOptions, listenCallBack } = opts || {};
|
|
679
697
|
if (!this.server || !this.simpleRouter) {
|
|
680
698
|
throw new Error('Server and SimpleRouter must be set before calling parse');
|
|
681
699
|
}
|
|
@@ -692,6 +710,9 @@ class HttpChain {
|
|
|
692
710
|
}
|
|
693
711
|
}
|
|
694
712
|
};
|
|
713
|
+
if (listenOptions) {
|
|
714
|
+
this.server.listen(listenOptions, listenCallBack);
|
|
715
|
+
}
|
|
695
716
|
this.server.on('request', listener);
|
|
696
717
|
return () => {
|
|
697
718
|
that.server.removeListener('request', listener);
|
package/dist/router.d.ts
CHANGED
|
@@ -175,7 +175,6 @@ declare class Route<U = {
|
|
|
175
175
|
*/
|
|
176
176
|
key?: string;
|
|
177
177
|
id?: string;
|
|
178
|
-
share?: boolean;
|
|
179
178
|
run?: Run;
|
|
180
179
|
nextRoute?: NextRoute;
|
|
181
180
|
description?: string;
|
|
@@ -317,6 +316,7 @@ declare class QueryRouter {
|
|
|
317
316
|
* 请求 result 的数据
|
|
318
317
|
* @param message
|
|
319
318
|
* @param ctx
|
|
319
|
+
* @deprecated use run or call instead
|
|
320
320
|
* @returns
|
|
321
321
|
*/
|
|
322
322
|
queryRoute(message: {
|
|
@@ -331,6 +331,24 @@ declare class QueryRouter {
|
|
|
331
331
|
data: any;
|
|
332
332
|
message: any;
|
|
333
333
|
}>;
|
|
334
|
+
/**
|
|
335
|
+
* Router Run获取数据
|
|
336
|
+
* @param message
|
|
337
|
+
* @param ctx
|
|
338
|
+
* @returns
|
|
339
|
+
*/
|
|
340
|
+
run(message: {
|
|
341
|
+
id?: string;
|
|
342
|
+
path?: string;
|
|
343
|
+
key?: string;
|
|
344
|
+
payload?: any;
|
|
345
|
+
}, ctx?: RouteContext & {
|
|
346
|
+
[key: string]: any;
|
|
347
|
+
}): Promise<{
|
|
348
|
+
code: any;
|
|
349
|
+
data: any;
|
|
350
|
+
message: any;
|
|
351
|
+
}>;
|
|
334
352
|
/**
|
|
335
353
|
* 设置上下文
|
|
336
354
|
* @description 这里的上下文是为了在handle函数中使用
|
|
@@ -422,7 +440,7 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
422
440
|
prompt(description: string): Route<Required<RouteContext>>;
|
|
423
441
|
prompt(description: Function): Route<Required<RouteContext>>;
|
|
424
442
|
/**
|
|
425
|
-
*
|
|
443
|
+
* 调用了handle
|
|
426
444
|
* @param param0
|
|
427
445
|
* @returns
|
|
428
446
|
*/
|
|
@@ -430,9 +448,12 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
430
448
|
path: string;
|
|
431
449
|
key?: string;
|
|
432
450
|
payload?: any;
|
|
451
|
+
}, ctx?: RouteContext & {
|
|
452
|
+
[key: string]: any;
|
|
433
453
|
}): Promise<any>;
|
|
434
454
|
}
|
|
435
|
-
declare
|
|
455
|
+
declare class Mini extends QueryRouterServer {
|
|
456
|
+
}
|
|
436
457
|
|
|
437
458
|
declare class Connect {
|
|
438
459
|
path: string;
|