koatty_router 1.7.9 → 1.7.10
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/CHANGELOG.md +2 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +47 -41
- package/dist/index.mjs +47 -41
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.7.10](https://github.com/koatty/koatty_router/compare/v1.7.9...v1.7.10) (2022-10-31)
|
|
6
|
+
|
|
5
7
|
### [1.7.9](https://github.com/koatty/koatty_router/compare/v1.7.8...v1.7.9) (2022-08-19)
|
|
6
8
|
|
|
7
9
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2022-
|
|
3
|
+
* @Date: 2022-10-31 15:15:47
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -71,6 +71,7 @@ export declare const GetMapping: (path?: string, routerOptions?: {
|
|
|
71
71
|
|
|
72
72
|
export declare class GrpcRouter implements KoattyRouter {
|
|
73
73
|
app: Koatty;
|
|
74
|
+
readonly protocol: string;
|
|
74
75
|
options: GrpcRouterOptions;
|
|
75
76
|
router: Map<string, ServiceImplementation>;
|
|
76
77
|
constructor(app: Koatty, options?: RouterOptions);
|
|
@@ -138,6 +139,7 @@ export declare type HttpImplementation = (ctx: KoattyContext, next: KoattyNext)
|
|
|
138
139
|
*/
|
|
139
140
|
export declare class HttpRouter implements KoattyRouter {
|
|
140
141
|
app: Koatty;
|
|
142
|
+
readonly protocol: string;
|
|
141
143
|
options: RouterOptions;
|
|
142
144
|
router: KoaRouter;
|
|
143
145
|
constructor(app: Koatty, options?: RouterOptions);
|
|
@@ -370,6 +372,7 @@ export declare interface ServiceImplementation {
|
|
|
370
372
|
|
|
371
373
|
export declare class WebsocketRouter implements KoattyRouter {
|
|
372
374
|
app: Koatty;
|
|
375
|
+
readonly protocol: string;
|
|
373
376
|
options: WebsocketRouterOptions;
|
|
374
377
|
router: KoaRouter;
|
|
375
378
|
constructor(app: Koatty, options?: RouterOptions);
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2022-
|
|
3
|
+
* @Date: 2022-10-31 15:15:33
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -412,7 +412,7 @@ function injectParam(app, target, instance) {
|
|
|
412
412
|
* @Usage:
|
|
413
413
|
* @Author: richen
|
|
414
414
|
* @Date: 2021-06-29 14:10:30
|
|
415
|
-
* @LastEditTime: 2022-
|
|
415
|
+
* @LastEditTime: 2022-10-29 11:24:18
|
|
416
416
|
*/
|
|
417
417
|
class GrpcRouter {
|
|
418
418
|
constructor(app, options) {
|
|
@@ -520,7 +520,7 @@ class GrpcRouter {
|
|
|
520
520
|
* @Usage:
|
|
521
521
|
* @Author: richen
|
|
522
522
|
* @Date: 2021-06-28 19:02:06
|
|
523
|
-
* @LastEditTime: 2022-
|
|
523
|
+
* @LastEditTime: 2022-10-29 11:24:21
|
|
524
524
|
*/
|
|
525
525
|
/**
|
|
526
526
|
* HttpRouter class
|
|
@@ -575,11 +575,14 @@ class HttpRouter {
|
|
|
575
575
|
const path = router.path;
|
|
576
576
|
const requestMethod = router.requestMethod;
|
|
577
577
|
const params = ctlParams[method];
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
578
|
+
// websocket only handler get request
|
|
579
|
+
if (requestMethod == exports.RequestMethod.GET || requestMethod == exports.RequestMethod.ALL) {
|
|
580
|
+
koatty_logger.DefaultLogger.Debug(`Register request mapping: [${requestMethod}] : ["${path}" => ${n}.${method}]`);
|
|
581
|
+
this.SetRouter(path, (ctx) => {
|
|
582
|
+
const ctl = koatty_container.IOCContainer.getInsByClass(ctlClass, [ctx]);
|
|
583
|
+
return Handler(this.app, ctx, ctl, method, params);
|
|
584
|
+
}, requestMethod);
|
|
585
|
+
}
|
|
583
586
|
}
|
|
584
587
|
}
|
|
585
588
|
// exp: in middleware
|
|
@@ -598,7 +601,7 @@ class HttpRouter {
|
|
|
598
601
|
* @Usage:
|
|
599
602
|
* @Author: richen
|
|
600
603
|
* @Date: 2021-06-29 14:16:44
|
|
601
|
-
* @LastEditTime: 2022-
|
|
604
|
+
* @LastEditTime: 2022-10-29 11:25:18
|
|
602
605
|
*/
|
|
603
606
|
class WebsocketRouter {
|
|
604
607
|
constructor(app, options) {
|
|
@@ -669,6 +672,41 @@ class WebsocketRouter {
|
|
|
669
672
|
}
|
|
670
673
|
}
|
|
671
674
|
|
|
675
|
+
/*
|
|
676
|
+
* @Description:
|
|
677
|
+
* @Usage:
|
|
678
|
+
* @Author: richen
|
|
679
|
+
* @Date: 2022-10-29 11:15:30
|
|
680
|
+
* @LastEditTime: 2022-10-29 11:26:39
|
|
681
|
+
*/
|
|
682
|
+
/**
|
|
683
|
+
* get instance of Router
|
|
684
|
+
*
|
|
685
|
+
* @export
|
|
686
|
+
* @param {Koatty} app
|
|
687
|
+
* @param {RouterOptions} options
|
|
688
|
+
* @param {string} [protocol]
|
|
689
|
+
* @returns {*} {KoattyRouter}
|
|
690
|
+
*/
|
|
691
|
+
function NewRouter(app, options, protocol) {
|
|
692
|
+
let router;
|
|
693
|
+
switch (protocol) {
|
|
694
|
+
case "grpc":
|
|
695
|
+
router = new GrpcRouter(app, options);
|
|
696
|
+
Helper.Helper.define(router, "protocol", protocol);
|
|
697
|
+
break;
|
|
698
|
+
case "ws":
|
|
699
|
+
case "wss":
|
|
700
|
+
router = new WebsocketRouter(app, options);
|
|
701
|
+
Helper.Helper.define(router, "protocol", protocol);
|
|
702
|
+
break;
|
|
703
|
+
default:
|
|
704
|
+
router = new HttpRouter(app, options);
|
|
705
|
+
Helper.Helper.define(router, "protocol", protocol);
|
|
706
|
+
}
|
|
707
|
+
return router;
|
|
708
|
+
}
|
|
709
|
+
|
|
672
710
|
/*
|
|
673
711
|
* @Description:
|
|
674
712
|
* @Usage:
|
|
@@ -847,38 +885,6 @@ const Inject = (fn, name) => {
|
|
|
847
885
|
};
|
|
848
886
|
};
|
|
849
887
|
|
|
850
|
-
/*
|
|
851
|
-
* @Description:
|
|
852
|
-
* @Usage:
|
|
853
|
-
* @Author: richen
|
|
854
|
-
* @Date: 2021-06-28 18:48:14
|
|
855
|
-
* @LastEditTime: 2022-03-15 17:10:39
|
|
856
|
-
*/
|
|
857
|
-
/**
|
|
858
|
-
* get instance of Router
|
|
859
|
-
*
|
|
860
|
-
* @export
|
|
861
|
-
* @param {Koatty} app
|
|
862
|
-
* @param {RouterOptions} options
|
|
863
|
-
* @param {string} [protocol]
|
|
864
|
-
* @returns {*} {KoattyRouter}
|
|
865
|
-
*/
|
|
866
|
-
function NewRouter(app, options, protocol) {
|
|
867
|
-
let router;
|
|
868
|
-
switch (protocol) {
|
|
869
|
-
case "grpc":
|
|
870
|
-
router = new GrpcRouter(app, options);
|
|
871
|
-
break;
|
|
872
|
-
case "ws":
|
|
873
|
-
case "wss":
|
|
874
|
-
router = new WebsocketRouter(app, options);
|
|
875
|
-
break;
|
|
876
|
-
default:
|
|
877
|
-
router = new HttpRouter(app, options);
|
|
878
|
-
}
|
|
879
|
-
return router;
|
|
880
|
-
}
|
|
881
|
-
|
|
882
888
|
exports.Body = Body;
|
|
883
889
|
exports.CONTROLLER_ROUTER = CONTROLLER_ROUTER;
|
|
884
890
|
exports.DeleteMapping = DeleteMapping;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2022-
|
|
3
|
+
* @Date: 2022-10-31 15:15:33
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -386,7 +386,7 @@ function injectParam(app, target, instance) {
|
|
|
386
386
|
* @Usage:
|
|
387
387
|
* @Author: richen
|
|
388
388
|
* @Date: 2021-06-29 14:10:30
|
|
389
|
-
* @LastEditTime: 2022-
|
|
389
|
+
* @LastEditTime: 2022-10-29 11:24:18
|
|
390
390
|
*/
|
|
391
391
|
class GrpcRouter {
|
|
392
392
|
constructor(app, options) {
|
|
@@ -494,7 +494,7 @@ class GrpcRouter {
|
|
|
494
494
|
* @Usage:
|
|
495
495
|
* @Author: richen
|
|
496
496
|
* @Date: 2021-06-28 19:02:06
|
|
497
|
-
* @LastEditTime: 2022-
|
|
497
|
+
* @LastEditTime: 2022-10-29 11:24:21
|
|
498
498
|
*/
|
|
499
499
|
/**
|
|
500
500
|
* HttpRouter class
|
|
@@ -549,11 +549,14 @@ class HttpRouter {
|
|
|
549
549
|
const path = router.path;
|
|
550
550
|
const requestMethod = router.requestMethod;
|
|
551
551
|
const params = ctlParams[method];
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
552
|
+
// websocket only handler get request
|
|
553
|
+
if (requestMethod == RequestMethod.GET || requestMethod == RequestMethod.ALL) {
|
|
554
|
+
DefaultLogger.Debug(`Register request mapping: [${requestMethod}] : ["${path}" => ${n}.${method}]`);
|
|
555
|
+
this.SetRouter(path, (ctx) => {
|
|
556
|
+
const ctl = IOCContainer.getInsByClass(ctlClass, [ctx]);
|
|
557
|
+
return Handler(this.app, ctx, ctl, method, params);
|
|
558
|
+
}, requestMethod);
|
|
559
|
+
}
|
|
557
560
|
}
|
|
558
561
|
}
|
|
559
562
|
// exp: in middleware
|
|
@@ -572,7 +575,7 @@ class HttpRouter {
|
|
|
572
575
|
* @Usage:
|
|
573
576
|
* @Author: richen
|
|
574
577
|
* @Date: 2021-06-29 14:16:44
|
|
575
|
-
* @LastEditTime: 2022-
|
|
578
|
+
* @LastEditTime: 2022-10-29 11:25:18
|
|
576
579
|
*/
|
|
577
580
|
class WebsocketRouter {
|
|
578
581
|
constructor(app, options) {
|
|
@@ -643,6 +646,41 @@ class WebsocketRouter {
|
|
|
643
646
|
}
|
|
644
647
|
}
|
|
645
648
|
|
|
649
|
+
/*
|
|
650
|
+
* @Description:
|
|
651
|
+
* @Usage:
|
|
652
|
+
* @Author: richen
|
|
653
|
+
* @Date: 2022-10-29 11:15:30
|
|
654
|
+
* @LastEditTime: 2022-10-29 11:26:39
|
|
655
|
+
*/
|
|
656
|
+
/**
|
|
657
|
+
* get instance of Router
|
|
658
|
+
*
|
|
659
|
+
* @export
|
|
660
|
+
* @param {Koatty} app
|
|
661
|
+
* @param {RouterOptions} options
|
|
662
|
+
* @param {string} [protocol]
|
|
663
|
+
* @returns {*} {KoattyRouter}
|
|
664
|
+
*/
|
|
665
|
+
function NewRouter(app, options, protocol) {
|
|
666
|
+
let router;
|
|
667
|
+
switch (protocol) {
|
|
668
|
+
case "grpc":
|
|
669
|
+
router = new GrpcRouter(app, options);
|
|
670
|
+
Helper$1.define(router, "protocol", protocol);
|
|
671
|
+
break;
|
|
672
|
+
case "ws":
|
|
673
|
+
case "wss":
|
|
674
|
+
router = new WebsocketRouter(app, options);
|
|
675
|
+
Helper$1.define(router, "protocol", protocol);
|
|
676
|
+
break;
|
|
677
|
+
default:
|
|
678
|
+
router = new HttpRouter(app, options);
|
|
679
|
+
Helper$1.define(router, "protocol", protocol);
|
|
680
|
+
}
|
|
681
|
+
return router;
|
|
682
|
+
}
|
|
683
|
+
|
|
646
684
|
/*
|
|
647
685
|
* @Description:
|
|
648
686
|
* @Usage:
|
|
@@ -821,36 +859,4 @@ const Inject = (fn, name) => {
|
|
|
821
859
|
};
|
|
822
860
|
};
|
|
823
861
|
|
|
824
|
-
/*
|
|
825
|
-
* @Description:
|
|
826
|
-
* @Usage:
|
|
827
|
-
* @Author: richen
|
|
828
|
-
* @Date: 2021-06-28 18:48:14
|
|
829
|
-
* @LastEditTime: 2022-03-15 17:10:39
|
|
830
|
-
*/
|
|
831
|
-
/**
|
|
832
|
-
* get instance of Router
|
|
833
|
-
*
|
|
834
|
-
* @export
|
|
835
|
-
* @param {Koatty} app
|
|
836
|
-
* @param {RouterOptions} options
|
|
837
|
-
* @param {string} [protocol]
|
|
838
|
-
* @returns {*} {KoattyRouter}
|
|
839
|
-
*/
|
|
840
|
-
function NewRouter(app, options, protocol) {
|
|
841
|
-
let router;
|
|
842
|
-
switch (protocol) {
|
|
843
|
-
case "grpc":
|
|
844
|
-
router = new GrpcRouter(app, options);
|
|
845
|
-
break;
|
|
846
|
-
case "ws":
|
|
847
|
-
case "wss":
|
|
848
|
-
router = new WebsocketRouter(app, options);
|
|
849
|
-
break;
|
|
850
|
-
default:
|
|
851
|
-
router = new HttpRouter(app, options);
|
|
852
|
-
}
|
|
853
|
-
return router;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
862
|
export { Body, CONTROLLER_ROUTER, DeleteMapping, File, Get, GetMapping, GrpcRouter, HeadMapping, Header, HttpRouter, NewRouter, OptionsMapping, Param, PatchMapping, PathVariable, Post, PostMapping, PutMapping, ROUTER_KEY, RequestBody, RequestMapping, RequestMethod, RequestParam, WebsocketRouter };
|
package/dist/package.json
CHANGED
package/package.json
CHANGED