koatty_router 1.7.9 → 1.7.12
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 -43
- package/dist/index.mjs +50 -43
- 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.12](https://github.com/koatty/koatty_router/compare/v1.7.10...v1.7.12) (2022-11-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* ctx.body 赋值 ([2a8d8c8](https://github.com/koatty/koatty_router/commit/2a8d8c8d4e8615777f50dc4ccaf331e4f10bc66b))
|
|
11
|
+
|
|
12
|
+
### [1.7.10](https://github.com/koatty/koatty_router/compare/v1.7.9...v1.7.10) (2022-10-31)
|
|
13
|
+
|
|
5
14
|
### [1.7.9](https://github.com/koatty/koatty_router/compare/v1.7.8...v1.7.9) (2022-08-19)
|
|
6
15
|
|
|
7
16
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2022-
|
|
3
|
+
* @Date: 2022-11-01 15:47:40
|
|
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-11-01 15:47:18
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -294,7 +294,7 @@ const HeadMapping = (path = "/", routerOptions = {}) => {
|
|
|
294
294
|
* @Usage:
|
|
295
295
|
* @Author: richen
|
|
296
296
|
* @Date: 2021-11-10 16:58:57
|
|
297
|
-
* @LastEditTime: 2022-
|
|
297
|
+
* @LastEditTime: 2022-11-01 15:41:24
|
|
298
298
|
*/
|
|
299
299
|
/**
|
|
300
300
|
* controller handler
|
|
@@ -319,7 +319,8 @@ async function Handler(app, ctx, ctl, method, ctlParams) {
|
|
|
319
319
|
args = await getParamter(app, ctx, ctlParams);
|
|
320
320
|
}
|
|
321
321
|
// method
|
|
322
|
-
|
|
322
|
+
const res = await ctl[method](...args);
|
|
323
|
+
ctx.body = res;
|
|
323
324
|
}
|
|
324
325
|
/**
|
|
325
326
|
*
|
|
@@ -412,7 +413,7 @@ function injectParam(app, target, instance) {
|
|
|
412
413
|
* @Usage:
|
|
413
414
|
* @Author: richen
|
|
414
415
|
* @Date: 2021-06-29 14:10:30
|
|
415
|
-
* @LastEditTime: 2022-
|
|
416
|
+
* @LastEditTime: 2022-10-29 11:24:18
|
|
416
417
|
*/
|
|
417
418
|
class GrpcRouter {
|
|
418
419
|
constructor(app, options) {
|
|
@@ -520,7 +521,7 @@ class GrpcRouter {
|
|
|
520
521
|
* @Usage:
|
|
521
522
|
* @Author: richen
|
|
522
523
|
* @Date: 2021-06-28 19:02:06
|
|
523
|
-
* @LastEditTime: 2022-
|
|
524
|
+
* @LastEditTime: 2022-10-29 11:24:21
|
|
524
525
|
*/
|
|
525
526
|
/**
|
|
526
527
|
* HttpRouter class
|
|
@@ -575,11 +576,14 @@ class HttpRouter {
|
|
|
575
576
|
const path = router.path;
|
|
576
577
|
const requestMethod = router.requestMethod;
|
|
577
578
|
const params = ctlParams[method];
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
579
|
+
// websocket only handler get request
|
|
580
|
+
if (requestMethod == exports.RequestMethod.GET || requestMethod == exports.RequestMethod.ALL) {
|
|
581
|
+
koatty_logger.DefaultLogger.Debug(`Register request mapping: [${requestMethod}] : ["${path}" => ${n}.${method}]`);
|
|
582
|
+
this.SetRouter(path, (ctx) => {
|
|
583
|
+
const ctl = koatty_container.IOCContainer.getInsByClass(ctlClass, [ctx]);
|
|
584
|
+
return Handler(this.app, ctx, ctl, method, params);
|
|
585
|
+
}, requestMethod);
|
|
586
|
+
}
|
|
583
587
|
}
|
|
584
588
|
}
|
|
585
589
|
// exp: in middleware
|
|
@@ -598,7 +602,7 @@ class HttpRouter {
|
|
|
598
602
|
* @Usage:
|
|
599
603
|
* @Author: richen
|
|
600
604
|
* @Date: 2021-06-29 14:16:44
|
|
601
|
-
* @LastEditTime: 2022-
|
|
605
|
+
* @LastEditTime: 2022-10-29 11:25:18
|
|
602
606
|
*/
|
|
603
607
|
class WebsocketRouter {
|
|
604
608
|
constructor(app, options) {
|
|
@@ -669,6 +673,41 @@ class WebsocketRouter {
|
|
|
669
673
|
}
|
|
670
674
|
}
|
|
671
675
|
|
|
676
|
+
/*
|
|
677
|
+
* @Description:
|
|
678
|
+
* @Usage:
|
|
679
|
+
* @Author: richen
|
|
680
|
+
* @Date: 2022-10-29 11:15:30
|
|
681
|
+
* @LastEditTime: 2022-10-29 11:26:39
|
|
682
|
+
*/
|
|
683
|
+
/**
|
|
684
|
+
* get instance of Router
|
|
685
|
+
*
|
|
686
|
+
* @export
|
|
687
|
+
* @param {Koatty} app
|
|
688
|
+
* @param {RouterOptions} options
|
|
689
|
+
* @param {string} [protocol]
|
|
690
|
+
* @returns {*} {KoattyRouter}
|
|
691
|
+
*/
|
|
692
|
+
function NewRouter(app, options, protocol) {
|
|
693
|
+
let router;
|
|
694
|
+
switch (protocol) {
|
|
695
|
+
case "grpc":
|
|
696
|
+
router = new GrpcRouter(app, options);
|
|
697
|
+
Helper.Helper.define(router, "protocol", protocol);
|
|
698
|
+
break;
|
|
699
|
+
case "ws":
|
|
700
|
+
case "wss":
|
|
701
|
+
router = new WebsocketRouter(app, options);
|
|
702
|
+
Helper.Helper.define(router, "protocol", protocol);
|
|
703
|
+
break;
|
|
704
|
+
default:
|
|
705
|
+
router = new HttpRouter(app, options);
|
|
706
|
+
Helper.Helper.define(router, "protocol", protocol);
|
|
707
|
+
}
|
|
708
|
+
return router;
|
|
709
|
+
}
|
|
710
|
+
|
|
672
711
|
/*
|
|
673
712
|
* @Description:
|
|
674
713
|
* @Usage:
|
|
@@ -847,38 +886,6 @@ const Inject = (fn, name) => {
|
|
|
847
886
|
};
|
|
848
887
|
};
|
|
849
888
|
|
|
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
889
|
exports.Body = Body;
|
|
883
890
|
exports.CONTROLLER_ROUTER = CONTROLLER_ROUTER;
|
|
884
891
|
exports.DeleteMapping = DeleteMapping;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2022-
|
|
3
|
+
* @Date: 2022-11-01 15:47:18
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
@@ -268,7 +268,7 @@ const HeadMapping = (path = "/", routerOptions = {}) => {
|
|
|
268
268
|
* @Usage:
|
|
269
269
|
* @Author: richen
|
|
270
270
|
* @Date: 2021-11-10 16:58:57
|
|
271
|
-
* @LastEditTime: 2022-
|
|
271
|
+
* @LastEditTime: 2022-11-01 15:41:24
|
|
272
272
|
*/
|
|
273
273
|
/**
|
|
274
274
|
* controller handler
|
|
@@ -293,7 +293,8 @@ async function Handler(app, ctx, ctl, method, ctlParams) {
|
|
|
293
293
|
args = await getParamter(app, ctx, ctlParams);
|
|
294
294
|
}
|
|
295
295
|
// method
|
|
296
|
-
|
|
296
|
+
const res = await ctl[method](...args);
|
|
297
|
+
ctx.body = res;
|
|
297
298
|
}
|
|
298
299
|
/**
|
|
299
300
|
*
|
|
@@ -386,7 +387,7 @@ function injectParam(app, target, instance) {
|
|
|
386
387
|
* @Usage:
|
|
387
388
|
* @Author: richen
|
|
388
389
|
* @Date: 2021-06-29 14:10:30
|
|
389
|
-
* @LastEditTime: 2022-
|
|
390
|
+
* @LastEditTime: 2022-10-29 11:24:18
|
|
390
391
|
*/
|
|
391
392
|
class GrpcRouter {
|
|
392
393
|
constructor(app, options) {
|
|
@@ -494,7 +495,7 @@ class GrpcRouter {
|
|
|
494
495
|
* @Usage:
|
|
495
496
|
* @Author: richen
|
|
496
497
|
* @Date: 2021-06-28 19:02:06
|
|
497
|
-
* @LastEditTime: 2022-
|
|
498
|
+
* @LastEditTime: 2022-10-29 11:24:21
|
|
498
499
|
*/
|
|
499
500
|
/**
|
|
500
501
|
* HttpRouter class
|
|
@@ -549,11 +550,14 @@ class HttpRouter {
|
|
|
549
550
|
const path = router.path;
|
|
550
551
|
const requestMethod = router.requestMethod;
|
|
551
552
|
const params = ctlParams[method];
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
553
|
+
// websocket only handler get request
|
|
554
|
+
if (requestMethod == RequestMethod.GET || requestMethod == RequestMethod.ALL) {
|
|
555
|
+
DefaultLogger.Debug(`Register request mapping: [${requestMethod}] : ["${path}" => ${n}.${method}]`);
|
|
556
|
+
this.SetRouter(path, (ctx) => {
|
|
557
|
+
const ctl = IOCContainer.getInsByClass(ctlClass, [ctx]);
|
|
558
|
+
return Handler(this.app, ctx, ctl, method, params);
|
|
559
|
+
}, requestMethod);
|
|
560
|
+
}
|
|
557
561
|
}
|
|
558
562
|
}
|
|
559
563
|
// exp: in middleware
|
|
@@ -572,7 +576,7 @@ class HttpRouter {
|
|
|
572
576
|
* @Usage:
|
|
573
577
|
* @Author: richen
|
|
574
578
|
* @Date: 2021-06-29 14:16:44
|
|
575
|
-
* @LastEditTime: 2022-
|
|
579
|
+
* @LastEditTime: 2022-10-29 11:25:18
|
|
576
580
|
*/
|
|
577
581
|
class WebsocketRouter {
|
|
578
582
|
constructor(app, options) {
|
|
@@ -643,6 +647,41 @@ class WebsocketRouter {
|
|
|
643
647
|
}
|
|
644
648
|
}
|
|
645
649
|
|
|
650
|
+
/*
|
|
651
|
+
* @Description:
|
|
652
|
+
* @Usage:
|
|
653
|
+
* @Author: richen
|
|
654
|
+
* @Date: 2022-10-29 11:15:30
|
|
655
|
+
* @LastEditTime: 2022-10-29 11:26:39
|
|
656
|
+
*/
|
|
657
|
+
/**
|
|
658
|
+
* get instance of Router
|
|
659
|
+
*
|
|
660
|
+
* @export
|
|
661
|
+
* @param {Koatty} app
|
|
662
|
+
* @param {RouterOptions} options
|
|
663
|
+
* @param {string} [protocol]
|
|
664
|
+
* @returns {*} {KoattyRouter}
|
|
665
|
+
*/
|
|
666
|
+
function NewRouter(app, options, protocol) {
|
|
667
|
+
let router;
|
|
668
|
+
switch (protocol) {
|
|
669
|
+
case "grpc":
|
|
670
|
+
router = new GrpcRouter(app, options);
|
|
671
|
+
Helper$1.define(router, "protocol", protocol);
|
|
672
|
+
break;
|
|
673
|
+
case "ws":
|
|
674
|
+
case "wss":
|
|
675
|
+
router = new WebsocketRouter(app, options);
|
|
676
|
+
Helper$1.define(router, "protocol", protocol);
|
|
677
|
+
break;
|
|
678
|
+
default:
|
|
679
|
+
router = new HttpRouter(app, options);
|
|
680
|
+
Helper$1.define(router, "protocol", protocol);
|
|
681
|
+
}
|
|
682
|
+
return router;
|
|
683
|
+
}
|
|
684
|
+
|
|
646
685
|
/*
|
|
647
686
|
* @Description:
|
|
648
687
|
* @Usage:
|
|
@@ -821,36 +860,4 @@ const Inject = (fn, name) => {
|
|
|
821
860
|
};
|
|
822
861
|
};
|
|
823
862
|
|
|
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
863
|
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