koatty 3.11.4-2 → 3.11.6

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/LICENSE CHANGED
@@ -1,29 +1,29 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2020, Koatty
4
- All rights reserved.
5
-
6
- Redistribution and use in source and binary forms, with or without
7
- modification, are permitted provided that the following conditions are met:
8
-
9
- 1. Redistributions of source code must retain the above copyright notice, this
10
- list of conditions and the following disclaimer.
11
-
12
- 2. Redistributions in binary form must reproduce the above copyright notice,
13
- this list of conditions and the following disclaimer in the documentation
14
- and/or other materials provided with the distribution.
15
-
16
- 3. Neither the name of the copyright holder nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020, Koatty
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,168 +1,177 @@
1
- # koatty
2
-
3
- Koa2 + Typescript + IOC = koatty.
4
-
5
- Use Typescript's decorator implement IOC and AOP.
6
-
7
- [![Version npm](https://img.shields.io/npm/v/koatty.svg?style=flat-square)](https://www.npmjs.com/package/koatty)[![npm Downloads](https://img.shields.io/npm/dm/koatty.svg?style=flat-square)](https://npmcharts.com/compare/koatty?minimal=true)
8
-
9
- ## New features
10
-
11
- * HTTP、HTTPS、HTTP2、gRPC、WebSocket server.
12
- * Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env)
13
- * `@ExceptionHandler()` Register global exception handling
14
- * graceful shutdown and pre-exit event
15
- * custom decorator based on app events
16
-
17
-
18
- ## Documentation
19
-
20
- [koatty_doc_CN](https://koatty.org/) (In progress💪)
21
-
22
-
23
- ## Installation CLI tools
24
-
25
- ```shell
26
- npm i -g koatty_cli
27
- ```
28
-
29
- ## Quick Start
30
-
31
- ### 1.Create Project
32
-
33
- ```shell
34
- kt new projectName
35
-
36
- ```
37
-
38
- ### 2. Install deps
39
-
40
- ```
41
- cd ./projectName
42
-
43
- npm i
44
- ```
45
-
46
- ### 3. Start up
47
-
48
- ```
49
- npm run dev
50
-
51
- // or
52
- npm start
53
- ```
54
-
55
- ## Code style
56
-
57
- default Controller:
58
-
59
- ```javascript
60
- import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
61
- PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
62
- import { TestDTO } from "../model/dto/TestDTO";
63
- import { TestService } from "../service/TestService";
64
- import { App } from "../App";
65
-
66
- @Controller()
67
- export class IndexController {
68
- app: App;
69
- ctx: KoattyContext;
70
-
71
- @Autowired()
72
- private testService: TestService;
73
-
74
- /**
75
- * constructor
76
- *
77
- */
78
- constructor(ctx: KoattyContext) {
79
- this.ctx = ctx;
80
- }
81
-
82
- @RequestMapping("/:name", RequestMethod.ALL)
83
- async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
84
- try {
85
- const info = await this.testService.sayHello(name);
86
- return Output.ok(this.ctx, "success", info);
87
- } catch (err: Error) {
88
- return Output.fail(this.ctx, err.message));
89
- }
90
- }
91
-
92
- @PostMapping("/test")
93
- @Validated() //need DTOClass
94
- test(@RequestParam() params: TestDTO) {
95
- return Output.ok(this.ctx, "test", params);
96
- }
97
- }
98
- ```
99
-
100
- ## How to do Unit Testing
101
-
102
- >only support `jest` UT framework now
103
-
104
- ```javascript
105
- import request from 'supertest';
106
- import { ExecBootStrap } from 'koatty';
107
- import { App } from '../src/App';
108
-
109
- describe('UT example', () => {
110
-
111
- let server: any;
112
- beforeAll(async () => {
113
- jest.useFakeTimers();
114
- const appInstance = await ExecBootStrap()(App);
115
- server = await appInstance.listen();
116
- });
117
-
118
- afterAll(done => {
119
- server.close();
120
- done();
121
- });
122
-
123
- it('request', async () => {
124
- const rsp = await request(server).get('/');
125
- expect(rsp.status).toBe(200);
126
- });
127
- });
128
-
129
- ```
130
-
131
- ## How to debug
132
-
133
- if you use vscode , edit the `.vscode/launch.json` , like this:
134
- ```
135
- {
136
- "version": "0.2.0",
137
- "configurations": [
138
- {
139
- "type": "node",
140
- "request": "launch",
141
- "name": "TS Program",
142
- "args": [
143
- "${workspaceRoot}/src/App.ts"
144
- ],
145
- "runtimeArgs": [
146
- "--nolazy",
147
- "-r",
148
- "ts-node/register"
149
- ],
150
- "sourceMaps": true,
151
- "cwd": "${workspaceRoot}",
152
- "protocol": "inspector",
153
- "outputCapture": "std",
154
- "internalConsoleOptions": "neverOpen"
155
- }
156
- ]
157
- }
158
- ```
159
- Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
160
-
161
- ## Example
162
-
163
- Check out the [quick start example][quick-example].
164
-
165
- [quick-example]: https://github.com/Koatty/koatty_template
166
-
167
-
168
-
1
+ # koatty
2
+
3
+ Koa2 + Typescript + IOC = koatty.
4
+
5
+ Use Typescript's decorator implement IOC and AOP.
6
+
7
+ [![Version npm](https://img.shields.io/npm/v/koatty.svg?style=flat-square)](https://www.npmjs.com/package/koatty)[![npm Downloads](https://img.shields.io/npm/dm/koatty.svg?style=flat-square)](https://npmcharts.com/compare/koatty?minimal=true)
8
+
9
+ ## New features
10
+
11
+ * HTTP、HTTPS、HTTP2、gRPC、WebSocket server.
12
+ * Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env)
13
+ * `@ExceptionHandler()` Register global exception handling
14
+ * graceful shutdown and pre-exit event
15
+ * custom decorator based on app events
16
+
17
+
18
+ ## Documentation
19
+
20
+ [koatty_doc_CN](https://koatty.org/) (In progress💪)
21
+
22
+
23
+ ## Installation CLI tools
24
+
25
+ ```shell
26
+ npm i -g koatty_cli
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ### 1.Create Project
32
+
33
+ ```shell
34
+ kt new projectName
35
+
36
+ ```
37
+
38
+ ### 2. Install deps
39
+
40
+ ```
41
+ cd ./projectName
42
+
43
+ npm i
44
+ ```
45
+
46
+ ### 3. Start up
47
+
48
+ ```
49
+ npm run dev
50
+
51
+ // or
52
+ npm start
53
+ ```
54
+
55
+ ## Code style
56
+
57
+ default Controller:
58
+
59
+ ```javascript
60
+ import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
61
+ PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
62
+ import { TestDTO } from "../model/dto/TestDTO";
63
+ import { TestService } from "../service/TestService";
64
+ import { App } from "../App";
65
+
66
+ @Controller()
67
+ export class IndexController {
68
+ app: App;
69
+ ctx: KoattyContext;
70
+
71
+ @Autowired()
72
+ private testService: TestService;
73
+
74
+ /**
75
+ * constructor
76
+ *
77
+ */
78
+ constructor(ctx: KoattyContext) {
79
+ this.ctx = ctx;
80
+ }
81
+
82
+ @GetMapping('/')
83
+ index() {
84
+ return Output.ok("Hello, koatty!");
85
+ }
86
+
87
+ @RequestMapping("/:name", RequestMethod.ALL)
88
+ async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
89
+ try {
90
+ const info = await this.testService.sayHello(name);
91
+ return Output.ok(this.ctx, "success", info);
92
+ } catch (err: Error) {
93
+ return Output.fail(this.ctx, err.message));
94
+ }
95
+ }
96
+
97
+ @PostMapping("/test")
98
+ @Validated() //need DTOClass
99
+ test(@RequestParam() params: TestDTO) {
100
+ return Output.ok(this.ctx, "test", params);
101
+ }
102
+ }
103
+ ```
104
+
105
+ ## How to do Unit Testing
106
+
107
+ >only support `jest` UT framework now
108
+
109
+ ```javascript
110
+ import request from 'supertest';
111
+ import { ExecBootStrap } from 'koatty';
112
+ import { App } from '../src/App';
113
+
114
+ describe('UT example', () => {
115
+
116
+ let app: KoattyApplication;
117
+ beforeAll(async () => {
118
+ jest.useFakeTimers();
119
+ // test env
120
+ process.env.KOATTY_ENV = 'ts-node';
121
+ app = await ExecBootStrap()(App);
122
+ // app.use(async (ctx: any) => {
123
+ // ctx.body = 'Hello, World!';
124
+ // });
125
+ });
126
+
127
+ afterAll(done => {
128
+ done();
129
+ jest.clearAllMocks();
130
+ });
131
+
132
+ it('request', async () => {
133
+ const res = await request(app.callback()).get('/');
134
+ expect(res.status).toBe(200);
135
+ });
136
+ });
137
+
138
+ ```
139
+
140
+ ## How to debug
141
+
142
+ if you use vscode , edit the `.vscode/launch.json` , like this:
143
+ ```
144
+ {
145
+ "version": "0.2.0",
146
+ "configurations": [
147
+ {
148
+ "type": "node",
149
+ "request": "launch",
150
+ "name": "TS Program",
151
+ "args": [
152
+ "${workspaceRoot}/src/App.ts"
153
+ ],
154
+ "runtimeArgs": [
155
+ "--nolazy",
156
+ "-r",
157
+ "ts-node/register"
158
+ ],
159
+ "sourceMaps": true,
160
+ "cwd": "${workspaceRoot}",
161
+ "protocol": "inspector",
162
+ "outputCapture": "std",
163
+ "internalConsoleOptions": "neverOpen"
164
+ }
165
+ ]
166
+ }
167
+ ```
168
+ Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
169
+
170
+ ## Example
171
+
172
+ Check out the [quick start example][quick-example].
173
+
174
+ [quick-example]: https://github.com/Koatty/koatty_template
175
+
176
+
177
+
package/dist/LICENSE CHANGED
@@ -1,29 +1,29 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2020, Koatty
4
- All rights reserved.
5
-
6
- Redistribution and use in source and binary forms, with or without
7
- modification, are permitted provided that the following conditions are met:
8
-
9
- 1. Redistributions of source code must retain the above copyright notice, this
10
- list of conditions and the following disclaimer.
11
-
12
- 2. Redistributions in binary form must reproduce the above copyright notice,
13
- this list of conditions and the following disclaimer in the documentation
14
- and/or other materials provided with the distribution.
15
-
16
- 3. Neither the name of the copyright holder nor the names of its
17
- contributors may be used to endorse or promote products derived from
18
- this software without specific prior written permission.
19
-
20
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020, Koatty
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.