koatty_router 1.7.8 → 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 +9 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +50 -45
- package/dist/index.mjs +51 -46
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
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
|
+
|
|
7
|
+
### [1.7.9](https://github.com/koatty/koatty_router/compare/v1.7.8...v1.7.9) (2022-08-19)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* querystring must be convert type ([1bec352](https://github.com/koatty/koatty_router/commit/1bec3528a4f29d398a3158a25bcab4824e483433))
|
|
13
|
+
|
|
5
14
|
### [1.7.8](https://github.com/koatty/koatty_router/compare/v1.7.7...v1.7.8) (2022-08-19)
|
|
6
15
|
|
|
7
16
|
### [1.7.7](https://github.com/koatty/koatty_router/compare/v1.7.6...v1.7.7) (2022-08-19)
|
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/
|
|
@@ -46,7 +46,7 @@ var KoaRouter__default = /*#__PURE__*/_interopDefaultLegacy(KoaRouter);
|
|
|
46
46
|
* @Usage:
|
|
47
47
|
* @Author: richen
|
|
48
48
|
* @Date: 2021-11-24 23:21:26
|
|
49
|
-
* @LastEditTime: 2022-08-19
|
|
49
|
+
* @LastEditTime: 2022-08-19 15:37:12
|
|
50
50
|
*/
|
|
51
51
|
/**
|
|
52
52
|
* Parameter binding assignment.
|
|
@@ -104,13 +104,12 @@ async function checkParams(app, value, opt) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
107
|
+
// querystring must be convert type
|
|
108
|
+
value = koatty_validation.convertParamsType(value, opt.type);
|
|
107
109
|
//@Valid()
|
|
108
110
|
if (opt.validRule) {
|
|
109
111
|
validatorFuncs(`${opt.index}`, value, opt.type, opt.validRule, opt.validOpt);
|
|
110
112
|
}
|
|
111
|
-
if (!koatty_validation.checkParamsType(value, opt.type)) {
|
|
112
|
-
throw new koatty_exception.Exception(`TypeError: invalid arguments`, 1, 400);
|
|
113
|
-
}
|
|
114
113
|
}
|
|
115
114
|
return value;
|
|
116
115
|
}
|
|
@@ -413,7 +412,7 @@ function injectParam(app, target, instance) {
|
|
|
413
412
|
* @Usage:
|
|
414
413
|
* @Author: richen
|
|
415
414
|
* @Date: 2021-06-29 14:10:30
|
|
416
|
-
* @LastEditTime: 2022-
|
|
415
|
+
* @LastEditTime: 2022-10-29 11:24:18
|
|
417
416
|
*/
|
|
418
417
|
class GrpcRouter {
|
|
419
418
|
constructor(app, options) {
|
|
@@ -521,7 +520,7 @@ class GrpcRouter {
|
|
|
521
520
|
* @Usage:
|
|
522
521
|
* @Author: richen
|
|
523
522
|
* @Date: 2021-06-28 19:02:06
|
|
524
|
-
* @LastEditTime: 2022-
|
|
523
|
+
* @LastEditTime: 2022-10-29 11:24:21
|
|
525
524
|
*/
|
|
526
525
|
/**
|
|
527
526
|
* HttpRouter class
|
|
@@ -576,11 +575,14 @@ class HttpRouter {
|
|
|
576
575
|
const path = router.path;
|
|
577
576
|
const requestMethod = router.requestMethod;
|
|
578
577
|
const params = ctlParams[method];
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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
|
+
}
|
|
584
586
|
}
|
|
585
587
|
}
|
|
586
588
|
// exp: in middleware
|
|
@@ -599,7 +601,7 @@ class HttpRouter {
|
|
|
599
601
|
* @Usage:
|
|
600
602
|
* @Author: richen
|
|
601
603
|
* @Date: 2021-06-29 14:16:44
|
|
602
|
-
* @LastEditTime: 2022-
|
|
604
|
+
* @LastEditTime: 2022-10-29 11:25:18
|
|
603
605
|
*/
|
|
604
606
|
class WebsocketRouter {
|
|
605
607
|
constructor(app, options) {
|
|
@@ -670,6 +672,41 @@ class WebsocketRouter {
|
|
|
670
672
|
}
|
|
671
673
|
}
|
|
672
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
|
+
|
|
673
710
|
/*
|
|
674
711
|
* @Description:
|
|
675
712
|
* @Usage:
|
|
@@ -848,38 +885,6 @@ const Inject = (fn, name) => {
|
|
|
848
885
|
};
|
|
849
886
|
};
|
|
850
887
|
|
|
851
|
-
/*
|
|
852
|
-
* @Description:
|
|
853
|
-
* @Usage:
|
|
854
|
-
* @Author: richen
|
|
855
|
-
* @Date: 2021-06-28 18:48:14
|
|
856
|
-
* @LastEditTime: 2022-03-15 17:10:39
|
|
857
|
-
*/
|
|
858
|
-
/**
|
|
859
|
-
* get instance of Router
|
|
860
|
-
*
|
|
861
|
-
* @export
|
|
862
|
-
* @param {Koatty} app
|
|
863
|
-
* @param {RouterOptions} options
|
|
864
|
-
* @param {string} [protocol]
|
|
865
|
-
* @returns {*} {KoattyRouter}
|
|
866
|
-
*/
|
|
867
|
-
function NewRouter(app, options, protocol) {
|
|
868
|
-
let router;
|
|
869
|
-
switch (protocol) {
|
|
870
|
-
case "grpc":
|
|
871
|
-
router = new GrpcRouter(app, options);
|
|
872
|
-
break;
|
|
873
|
-
case "ws":
|
|
874
|
-
case "wss":
|
|
875
|
-
router = new WebsocketRouter(app, options);
|
|
876
|
-
break;
|
|
877
|
-
default:
|
|
878
|
-
router = new HttpRouter(app, options);
|
|
879
|
-
}
|
|
880
|
-
return router;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
888
|
exports.Body = Body;
|
|
884
889
|
exports.CONTROLLER_ROUTER = CONTROLLER_ROUTER;
|
|
885
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/
|
|
@@ -11,7 +11,7 @@ import { IOCContainer, RecursiveGetMetadata, TAGGED_PARAM, getOriginMetadata } f
|
|
|
11
11
|
import { LoadProto, ListServices } from 'koatty_proto';
|
|
12
12
|
import { DefaultLogger } from 'koatty_logger';
|
|
13
13
|
import { Exception } from 'koatty_exception';
|
|
14
|
-
import { ClassValidator, plainToClass,
|
|
14
|
+
import { ClassValidator, plainToClass, convertParamsType, FunctionValidator, PARAM_RULE_KEY, PARAM_CHECK_KEY, PARAM_TYPE_KEY, paramterTypes } from 'koatty_validation';
|
|
15
15
|
import 'reflect-metadata';
|
|
16
16
|
import KoaRouter from '@koa/router';
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ import KoaRouter from '@koa/router';
|
|
|
20
20
|
* @Usage:
|
|
21
21
|
* @Author: richen
|
|
22
22
|
* @Date: 2021-11-24 23:21:26
|
|
23
|
-
* @LastEditTime: 2022-08-19
|
|
23
|
+
* @LastEditTime: 2022-08-19 15:37:12
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
26
26
|
* Parameter binding assignment.
|
|
@@ -78,13 +78,12 @@ async function checkParams(app, value, opt) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
+
// querystring must be convert type
|
|
82
|
+
value = convertParamsType(value, opt.type);
|
|
81
83
|
//@Valid()
|
|
82
84
|
if (opt.validRule) {
|
|
83
85
|
validatorFuncs(`${opt.index}`, value, opt.type, opt.validRule, opt.validOpt);
|
|
84
86
|
}
|
|
85
|
-
if (!checkParamsType(value, opt.type)) {
|
|
86
|
-
throw new Exception(`TypeError: invalid arguments`, 1, 400);
|
|
87
|
-
}
|
|
88
87
|
}
|
|
89
88
|
return value;
|
|
90
89
|
}
|
|
@@ -387,7 +386,7 @@ function injectParam(app, target, instance) {
|
|
|
387
386
|
* @Usage:
|
|
388
387
|
* @Author: richen
|
|
389
388
|
* @Date: 2021-06-29 14:10:30
|
|
390
|
-
* @LastEditTime: 2022-
|
|
389
|
+
* @LastEditTime: 2022-10-29 11:24:18
|
|
391
390
|
*/
|
|
392
391
|
class GrpcRouter {
|
|
393
392
|
constructor(app, options) {
|
|
@@ -495,7 +494,7 @@ class GrpcRouter {
|
|
|
495
494
|
* @Usage:
|
|
496
495
|
* @Author: richen
|
|
497
496
|
* @Date: 2021-06-28 19:02:06
|
|
498
|
-
* @LastEditTime: 2022-
|
|
497
|
+
* @LastEditTime: 2022-10-29 11:24:21
|
|
499
498
|
*/
|
|
500
499
|
/**
|
|
501
500
|
* HttpRouter class
|
|
@@ -550,11 +549,14 @@ class HttpRouter {
|
|
|
550
549
|
const path = router.path;
|
|
551
550
|
const requestMethod = router.requestMethod;
|
|
552
551
|
const params = ctlParams[method];
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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
|
+
}
|
|
558
560
|
}
|
|
559
561
|
}
|
|
560
562
|
// exp: in middleware
|
|
@@ -573,7 +575,7 @@ class HttpRouter {
|
|
|
573
575
|
* @Usage:
|
|
574
576
|
* @Author: richen
|
|
575
577
|
* @Date: 2021-06-29 14:16:44
|
|
576
|
-
* @LastEditTime: 2022-
|
|
578
|
+
* @LastEditTime: 2022-10-29 11:25:18
|
|
577
579
|
*/
|
|
578
580
|
class WebsocketRouter {
|
|
579
581
|
constructor(app, options) {
|
|
@@ -644,6 +646,41 @@ class WebsocketRouter {
|
|
|
644
646
|
}
|
|
645
647
|
}
|
|
646
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
|
+
|
|
647
684
|
/*
|
|
648
685
|
* @Description:
|
|
649
686
|
* @Usage:
|
|
@@ -822,36 +859,4 @@ const Inject = (fn, name) => {
|
|
|
822
859
|
};
|
|
823
860
|
};
|
|
824
861
|
|
|
825
|
-
/*
|
|
826
|
-
* @Description:
|
|
827
|
-
* @Usage:
|
|
828
|
-
* @Author: richen
|
|
829
|
-
* @Date: 2021-06-28 18:48:14
|
|
830
|
-
* @LastEditTime: 2022-03-15 17:10:39
|
|
831
|
-
*/
|
|
832
|
-
/**
|
|
833
|
-
* get instance of Router
|
|
834
|
-
*
|
|
835
|
-
* @export
|
|
836
|
-
* @param {Koatty} app
|
|
837
|
-
* @param {RouterOptions} options
|
|
838
|
-
* @param {string} [protocol]
|
|
839
|
-
* @returns {*} {KoattyRouter}
|
|
840
|
-
*/
|
|
841
|
-
function NewRouter(app, options, protocol) {
|
|
842
|
-
let router;
|
|
843
|
-
switch (protocol) {
|
|
844
|
-
case "grpc":
|
|
845
|
-
router = new GrpcRouter(app, options);
|
|
846
|
-
break;
|
|
847
|
-
case "ws":
|
|
848
|
-
case "wss":
|
|
849
|
-
router = new WebsocketRouter(app, options);
|
|
850
|
-
break;
|
|
851
|
-
default:
|
|
852
|
-
router = new HttpRouter(app, options);
|
|
853
|
-
}
|
|
854
|
-
return router;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
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