koatty 3.9.1 → 3.9.2
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/.rollup.config.js +62 -62
- package/.vscode/launch.json +41 -41
- package/CHANGELOG.md +161 -153
- package/LICENSE +29 -29
- package/README.md +162 -162
- package/dist/LICENSE +29 -29
- package/dist/README.md +162 -162
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/index.mjs +9 -9
- package/dist/package.json +94 -94
- package/package.json +94 -94
- package/tsconfig.test.json +14 -14
package/README.md
CHANGED
@@ -1,162 +1,162 @@
|
|
1
|
-
# koatty
|
2
|
-
|
3
|
-
Koa2 + Typescript + IOC = koatty.
|
4
|
-
|
5
|
-
Use Typescript's decorator implement IOC and AOP.
|
6
|
-
|
7
|
-
[](https://www.npmjs.com/package/koatty)[](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
|
-
|
16
|
-
|
17
|
-
## Documentation
|
18
|
-
|
19
|
-
[koatty_doc_CN](https://koatty.org/) (In progress💪)
|
20
|
-
|
21
|
-
|
22
|
-
## Installation CLI tools
|
23
|
-
|
24
|
-
```shell
|
25
|
-
npm i -g koatty_cli
|
26
|
-
```
|
27
|
-
|
28
|
-
## Quick Start
|
29
|
-
|
30
|
-
### 1.Create Project
|
31
|
-
|
32
|
-
```shell
|
33
|
-
kt new projectName
|
34
|
-
|
35
|
-
npm start
|
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, BaseController, Autowired, GetMapping, RequestBody, PathVariable,
|
61
|
-
PostMapping, RequestMapping, RequestMethod, Valid } 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 extends BaseController {
|
68
|
-
app: App;
|
69
|
-
|
70
|
-
@Autowired()
|
71
|
-
private testService: TestService;
|
72
|
-
|
73
|
-
init() {
|
74
|
-
this.cache = {};
|
75
|
-
}
|
76
|
-
|
77
|
-
@RequestMapping("/:name", RequestMethod.ALL)
|
78
|
-
async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
|
79
|
-
try {
|
80
|
-
const info = await this.testService.sayHello(name);
|
81
|
-
return this.ok("success", info);
|
82
|
-
} catch (err: Error) {
|
83
|
-
return this.fail(err.message));
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
@PostMapping("/test")
|
88
|
-
@Validated() //need DTOClass
|
89
|
-
test(@RequestParam() params: TestDTO) {
|
90
|
-
return this.ok("test", params);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
```
|
94
|
-
|
95
|
-
## How to do Unit Testing
|
96
|
-
|
97
|
-
>only support `jest` UT framework now
|
98
|
-
|
99
|
-
```javascript
|
100
|
-
import request from 'supertest';
|
101
|
-
import { ExecBootStrap } from 'koatty';
|
102
|
-
import { App } from '../src/App';
|
103
|
-
|
104
|
-
describe('UT example', () => {
|
105
|
-
|
106
|
-
let server: any;
|
107
|
-
beforeAll(async () => {
|
108
|
-
jest.useFakeTimers();
|
109
|
-
const appInstance = await ExecBootStrap()(App);
|
110
|
-
server = await appInstance.listen();
|
111
|
-
});
|
112
|
-
|
113
|
-
afterAll(done => {
|
114
|
-
server.close();
|
115
|
-
done();
|
116
|
-
});
|
117
|
-
|
118
|
-
it('request', async () => {
|
119
|
-
const rsp = await request(server).get('/');
|
120
|
-
expect(rsp.status).toBe(200);
|
121
|
-
});
|
122
|
-
});
|
123
|
-
|
124
|
-
```
|
125
|
-
|
126
|
-
## How to debug
|
127
|
-
|
128
|
-
if you use vscode , edit the `.vscode/launch.json` , like this:
|
129
|
-
```
|
130
|
-
{
|
131
|
-
"version": "0.2.0",
|
132
|
-
"configurations": [
|
133
|
-
{
|
134
|
-
"type": "node",
|
135
|
-
"request": "launch",
|
136
|
-
"name": "TS Program",
|
137
|
-
"args": [
|
138
|
-
"${workspaceRoot}/src/App.ts"
|
139
|
-
],
|
140
|
-
"runtimeArgs": [
|
141
|
-
"--nolazy",
|
142
|
-
"-r",
|
143
|
-
"ts-node/register"
|
144
|
-
],
|
145
|
-
"sourceMaps": true,
|
146
|
-
"cwd": "${workspaceRoot}",
|
147
|
-
"protocol": "inspector",
|
148
|
-
"internalConsoleOptions": "neverOpen"
|
149
|
-
}
|
150
|
-
]
|
151
|
-
}
|
152
|
-
```
|
153
|
-
Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
|
154
|
-
|
155
|
-
## Example
|
156
|
-
|
157
|
-
Check out the [quick start example][quick-example].
|
158
|
-
|
159
|
-
[quick-example]: https://github.com/thinkkoa/koatty_demo/
|
160
|
-
|
161
|
-
|
162
|
-
|
1
|
+
# koatty
|
2
|
+
|
3
|
+
Koa2 + Typescript + IOC = koatty.
|
4
|
+
|
5
|
+
Use Typescript's decorator implement IOC and AOP.
|
6
|
+
|
7
|
+
[](https://www.npmjs.com/package/koatty)[](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
|
+
|
16
|
+
|
17
|
+
## Documentation
|
18
|
+
|
19
|
+
[koatty_doc_CN](https://koatty.org/) (In progress💪)
|
20
|
+
|
21
|
+
|
22
|
+
## Installation CLI tools
|
23
|
+
|
24
|
+
```shell
|
25
|
+
npm i -g koatty_cli
|
26
|
+
```
|
27
|
+
|
28
|
+
## Quick Start
|
29
|
+
|
30
|
+
### 1.Create Project
|
31
|
+
|
32
|
+
```shell
|
33
|
+
kt new projectName
|
34
|
+
|
35
|
+
npm start
|
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, BaseController, Autowired, GetMapping, RequestBody, PathVariable,
|
61
|
+
PostMapping, RequestMapping, RequestMethod, Valid } 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 extends BaseController {
|
68
|
+
app: App;
|
69
|
+
|
70
|
+
@Autowired()
|
71
|
+
private testService: TestService;
|
72
|
+
|
73
|
+
init() {
|
74
|
+
this.cache = {};
|
75
|
+
}
|
76
|
+
|
77
|
+
@RequestMapping("/:name", RequestMethod.ALL)
|
78
|
+
async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
|
79
|
+
try {
|
80
|
+
const info = await this.testService.sayHello(name);
|
81
|
+
return this.ok("success", info);
|
82
|
+
} catch (err: Error) {
|
83
|
+
return this.fail(err.message));
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
@PostMapping("/test")
|
88
|
+
@Validated() //need DTOClass
|
89
|
+
test(@RequestParam() params: TestDTO) {
|
90
|
+
return this.ok("test", params);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
## How to do Unit Testing
|
96
|
+
|
97
|
+
>only support `jest` UT framework now
|
98
|
+
|
99
|
+
```javascript
|
100
|
+
import request from 'supertest';
|
101
|
+
import { ExecBootStrap } from 'koatty';
|
102
|
+
import { App } from '../src/App';
|
103
|
+
|
104
|
+
describe('UT example', () => {
|
105
|
+
|
106
|
+
let server: any;
|
107
|
+
beforeAll(async () => {
|
108
|
+
jest.useFakeTimers();
|
109
|
+
const appInstance = await ExecBootStrap()(App);
|
110
|
+
server = await appInstance.listen();
|
111
|
+
});
|
112
|
+
|
113
|
+
afterAll(done => {
|
114
|
+
server.close();
|
115
|
+
done();
|
116
|
+
});
|
117
|
+
|
118
|
+
it('request', async () => {
|
119
|
+
const rsp = await request(server).get('/');
|
120
|
+
expect(rsp.status).toBe(200);
|
121
|
+
});
|
122
|
+
});
|
123
|
+
|
124
|
+
```
|
125
|
+
|
126
|
+
## How to debug
|
127
|
+
|
128
|
+
if you use vscode , edit the `.vscode/launch.json` , like this:
|
129
|
+
```
|
130
|
+
{
|
131
|
+
"version": "0.2.0",
|
132
|
+
"configurations": [
|
133
|
+
{
|
134
|
+
"type": "node",
|
135
|
+
"request": "launch",
|
136
|
+
"name": "TS Program",
|
137
|
+
"args": [
|
138
|
+
"${workspaceRoot}/src/App.ts"
|
139
|
+
],
|
140
|
+
"runtimeArgs": [
|
141
|
+
"--nolazy",
|
142
|
+
"-r",
|
143
|
+
"ts-node/register"
|
144
|
+
],
|
145
|
+
"sourceMaps": true,
|
146
|
+
"cwd": "${workspaceRoot}",
|
147
|
+
"protocol": "inspector",
|
148
|
+
"internalConsoleOptions": "neverOpen"
|
149
|
+
}
|
150
|
+
]
|
151
|
+
}
|
152
|
+
```
|
153
|
+
Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
|
154
|
+
|
155
|
+
## Example
|
156
|
+
|
157
|
+
Check out the [quick start example][quick-example].
|
158
|
+
|
159
|
+
[quick-example]: https://github.com/thinkkoa/koatty_demo/
|
160
|
+
|
161
|
+
|
162
|
+
|
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.
|