koatty 3.11.8 → 3.12.0

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  * @Usage:
4
4
  * @Author: richen
5
5
  * @Date: 2021-12-17 10:20:44
6
- * @LastEditTime: 2024-11-29 17:33:44
6
+ * @LastEditTime: 2025-03-15 18:06:51
7
7
  */
8
8
  import commonjs from '@rollup/plugin-commonjs';
9
9
  import json from "@rollup/plugin-json";
@@ -12,6 +12,7 @@ import { builtinModules } from 'module';
12
12
  import del from "rollup-plugin-delete";
13
13
  import typescript from 'rollup-plugin-typescript2';
14
14
  // import babel from '@rollup/plugin-babel';
15
+ // import terser from '@rollup/plugin-terser';
15
16
  const pkg = require('./package.json');
16
17
 
17
18
  export default [
@@ -49,11 +50,17 @@ export default [
49
50
  module: "ESNext"
50
51
  }
51
52
  }
52
- })
53
+ }),
54
+ // terser({
55
+ // format: { comments: false },
56
+ // compress: false,
57
+ // mangle: false
58
+ // }),
53
59
  ],
54
60
  external: [
55
61
  ...builtinModules, // 排除 Node.js 内置模块
56
62
  ...Object.keys(pkg.dependencies || {}), // 排除 package.json 中的外部依赖
63
+ ...Object.keys(pkg.devDependencies || {}),
57
64
  ],
58
65
  },
59
66
 
package/CHANGELOG.md CHANGED
@@ -2,21 +2,30 @@
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
- ### [3.11.8](https://github.com/thinkkoa/koatty/compare/v3.11.7...v3.11.8) (2025-01-14)
5
+ ## [3.12.0](https://github.com/thinkkoa/koatty/compare/v3.11.9...v3.12.0) (2025-03-15)
6
6
 
7
7
 
8
- ### Bug Fixes
8
+ ### Features
9
9
 
10
- * 调整app.env定义逻辑 ([eb4ae59](https://github.com/thinkkoa/koatty/commit/eb4ae5983831543e93eabac52c272f0dad2fb907))
11
- * enable debug mode and update dependencies ([651f1c8](https://github.com/thinkkoa/koatty/commit/651f1c85c85fcd166ee8f0c07d445baf4ffd662a))
12
-
13
- ### [3.11.7](https://github.com/thinkkoa/koatty/compare/v3.11.6...v3.11.7) (2024-12-06)
14
-
15
-
16
- ### Bug Fixes
17
-
18
- * export koatty_exception ([93e96bc](https://github.com/thinkkoa/koatty/commit/93e96bc703da57c0e555d5b384f0eb93501e3cfb))
10
+ * add GraphQL support and update router configuration ([f6fff69](https://github.com/thinkkoa/koatty/commit/f6fff69edca036450aba02400c2a8debead9db80))
19
11
 
12
+ ### [3.11.9](https://github.com/thinkkoa/koatty/compare/v3.11.8...v3.11.9) (2025-01-14)
13
+
14
+ ### [3.11.8](https://github.com/thinkkoa/koatty/compare/v3.11.7...v3.11.8) (2025-01-14)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * 调整app.env定义逻辑 ([eb4ae59](https://github.com/thinkkoa/koatty/commit/eb4ae5983831543e93eabac52c272f0dad2fb907))
20
+ * enable debug mode and update dependencies ([651f1c8](https://github.com/thinkkoa/koatty/commit/651f1c85c85fcd166ee8f0c07d445baf4ffd662a))
21
+
22
+ ### [3.11.7](https://github.com/thinkkoa/koatty/compare/v3.11.6...v3.11.7) (2024-12-06)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * export koatty_exception ([93e96bc](https://github.com/thinkkoa/koatty/commit/93e96bc703da57c0e555d5b384f0eb93501e3cfb))
28
+
20
29
  ### [3.11.6](https://github.com/thinkkoa/koatty/compare/v3.11.4-2...v3.11.6) (2024-12-05)
21
30
 
22
31
 
package/README.md CHANGED
@@ -1,179 +1,151 @@
1
- # koatty
1
+ # Koatty 🚀
2
2
 
3
- Koa2 + Typescript + IOC = koatty.
3
+ [![npm version](https://img.shields.io/npm/v/koatty)](https://www.npmjs.com/package/koatty)
4
+ [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
4
5
 
5
- Use Typescript's decorator implement IOC and AOP.
6
+ Koa2 + Typescript + IOC = koatty. **Koatty** is a progressive Node.js framework for building efficient and scalable server-side applications. Perfect for crafting enterprise-level APIs, microservices, and full-stack applications with TypeScript excellence.
6
7
 
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
+ ## Why Koatty? 💡
8
9
 
9
- ## New features
10
+ - 🚄 **High Performance**: Built on top of Koa2 with optimized architecture
11
+ - 🧩 **Full-Featured**: Supports gRPC, HTTP, WebSocket, Schedule tasks, and more
12
+ - 🧠 **TypeScript First**: Native TypeScript support with elegant OOP design
13
+ - 🌀 **Spring-like IOC Container**: Powerful dependency injection system with autowiring
14
+ - ✂️ **AOP Support**: Aspect-oriented programming with decorator-based interceptors
15
+ - 🔌 **Extensible Architecture**: Plugin system with dependency injection
16
+ - 📦 **Modern Tooling**: CLI scaffolding, testing utilities, and production-ready configs
17
+ - 🌐 **Protocol Agnostic**: Write once, deploy as HTTP/gRPC/WebSocket services
18
+
19
+
20
+ ## New features ✨
10
21
 
11
22
  * HTTP、HTTPS、HTTP2、gRPC、WebSocket server.✔️
12
- * Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env).✔️
23
+ * Support loading configurations based on the environment, support command-line argument parsing(process.argv), and support environment variable parsing(process.env).✔️
13
24
  * `@ExceptionHandler()` Register global exception handling.✔️
14
- * graceful shutdown and pre-exit event.✔️
15
- * custom decorator based on app events.✔️
16
- * GraphQL supporting. 💪
25
+ * Graceful shutdown and pre-exit event.✔️
26
+ * Supports custom decorators, bound to app events for execution.✔️
27
+ * GraphQL supporting. ✔️
17
28
  * OpenTelemetry . 💪
18
29
 
19
30
 
20
- ## Documentation
21
-
22
- [koatty_doc_CN](https://koatty.org/) (In progress💪)
31
+ ## Core Features ✨
23
32
 
24
-
25
- ## Installation CLI tools
26
-
27
- ```shell
28
- npm i -g koatty_cli
33
+ ### 📡 Multi-Protocol Support
34
+ ```typescript
35
+ // config/config.ts
36
+ export default {
37
+ ...
38
+ protocol: "grpc", // Server protocol 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss'
39
+ ...
40
+ }
29
41
  ```
30
42
 
31
- ## Quick Start
43
+ ### 💉 Dependency Injection
44
+ ```typescript
45
+ @Service()
46
+ export class UserService {
47
+ async findUser(id: number) {
48
+ return { id, name: 'Koatty User' };
49
+ }
50
+ }
32
51
 
33
- ### 1.Create Project
52
+ @Controller()
53
+ export class IndexController {
54
+ app: App;
55
+ ctx: KoattyContext;
56
+ ...
34
57
 
35
- ```shell
36
- kt new projectName
58
+ @Autowired()
59
+ private userService: UserService;
37
60
 
61
+ async test(id: number) {
62
+ const info = await this.userService.findUser(id);
63
+ ...
64
+ }
65
+ }
38
66
  ```
39
67
 
40
- ### 2. Install deps
68
+ ### ✂️ Aspect-Oriented Programming
69
+ ```javascript
70
+ @Aspect()
71
+ export class LogAspect implements IAspect {
72
+ app: App;
41
73
 
42
- ```
43
- cd ./projectName
74
+ run() {
75
+ console.log('LogAspect');
76
+ }
77
+ }
44
78
 
45
- npm i
79
+ // Apply aspect to controller
80
+ @Controller()
81
+ @BeforeEach(LogAspect)
82
+ export class UserController {}
46
83
  ```
47
84
 
48
- ### 3. Start up
49
-
85
+ ### 🔌 Plugin System
86
+ ```javascript
87
+ // plugin/logger.ts
88
+ export class LoggerPlugin implements IPlugin {
89
+ app: App;
90
+
91
+ run() {
92
+ // todo something or hook on app.event
93
+ Logger.Debug("LoggerPlugin");
94
+ return Promise.resolve();
95
+ }
96
+ }
50
97
  ```
51
- npm run dev
52
98
 
53
- // or
54
- npm start
55
- ```
56
99
 
57
- ## Code style
100
+ ## Benchmarks 📊
58
101
 
59
- default Controller:
102
+ | Framework | Requests/sec | Latency | Memory Usage |
103
+ | ---------- | ------------ | ------- | ------------ |
104
+ | **Koatty** | 13,321 | 1.43ms | 54MB |
105
+ | Express | 12,456 | 1.45ms | 52MB |
106
+ | NestJS | 11,892 | 1.51ms | 63MB |
60
107
 
61
- ```javascript
62
- import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
63
- PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
64
- import { TestDTO } from "../model/dto/TestDTO";
65
- import { TestService } from "../service/TestService";
66
- import { App } from "../App";
108
+ *Tested on AWS t3.micro with 100 concurrent connections*
67
109
 
68
- @Controller()
69
- export class IndexController {
70
- app: App;
71
- ctx: KoattyContext;
110
+ ## Documentation 📚
72
111
 
73
- @Autowired()
74
- private testService: TestService;
75
-
76
- /**
77
- * constructor
78
- *
79
- */
80
- constructor(ctx: KoattyContext) {
81
- this.ctx = ctx;
82
- }
112
+ - [中文文档](https://koatty.org/)
113
+ - [Getting Started Guide](https://github.com/Koatty/koatty_doc/blob/master/docs/README-en.md)
114
+ - [API Reference](https://koatty.org/#/?id=api)
115
+ - [Recipes & Best Practices](https://github.com/Koatty/koatty_awesome)
116
+ - [Example](https://github.com/Koatty/koatty_demo)
83
117
 
84
- @GetMapping('/')
85
- index() {
86
- return Output.ok("Hello, koatty!");
87
- }
88
118
 
89
- @RequestMapping("/:name", RequestMethod.ALL)
90
- async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
91
- try {
92
- const info = await this.testService.sayHello(name);
93
- return Output.ok(this.ctx, "success", info);
94
- } catch (err: Error) {
95
- return Output.fail(this.ctx, err.message));
96
- }
97
- }
119
+ ## Quick Start ⚡
98
120
 
99
- @PostMapping("/test")
100
- @Validated() //need DTOClass
101
- test(@RequestParam() params: TestDTO) {
102
- return Output.ok(this.ctx, "test", params);
103
- }
104
- }
121
+ 1. **Install CLI**:
122
+ ```bash
123
+ npm install -g koatty_cli
105
124
  ```
106
125
 
107
- ## How to do Unit Testing
108
-
109
- >only support `jest` UT framework now
110
-
111
- ```javascript
112
- import request from 'supertest';
113
- import { ExecBootStrap } from 'koatty';
114
- import { App } from '../src/App';
115
-
116
- describe('UT example', () => {
117
-
118
- let app: KoattyApplication;
119
- beforeAll(async () => {
120
- jest.useFakeTimers();
121
- // test env
122
- process.env.KOATTY_ENV = 'ts-node';
123
- app = await ExecBootStrap()(App);
124
- // app.use(async (ctx: any) => {
125
- // ctx.body = 'Hello, World!';
126
- // });
127
- });
128
-
129
- afterAll(done => {
130
- done();
131
- jest.clearAllMocks();
132
- });
133
-
134
- it('request', async () => {
135
- const res = await request(app.callback()).get('/');
136
- expect(res.status).toBe(200);
137
- });
138
- });
126
+ 2. **Create Project**:
127
+ ```bash
128
+ koatty new awesome-app
129
+ ```
139
130
 
131
+ 3. **Run Development Server**:
132
+ ```bash
133
+ cd awesome-app
134
+ npm run dev
140
135
  ```
141
136
 
142
- ## How to debug
143
137
 
144
- if you use vscode , edit the `.vscode/launch.json` , like this:
145
- ```
146
- {
147
- "version": "0.2.0",
148
- "configurations": [
149
- {
150
- "type": "node",
151
- "request": "launch",
152
- "name": "TS Program",
153
- "args": [
154
- "${workspaceRoot}/src/App.ts"
155
- ],
156
- "runtimeArgs": [
157
- "--nolazy",
158
- "-r",
159
- "ts-node/register"
160
- ],
161
- "sourceMaps": true,
162
- "cwd": "${workspaceRoot}",
163
- "protocol": "inspector",
164
- "outputCapture": "std",
165
- "internalConsoleOptions": "neverOpen"
166
- }
167
- ]
168
- }
169
- ```
170
- Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
138
+ ## Community 🌍
139
+
140
+ - [GitHub Discussions](https://github.com/Koatty/koatty/discussions)
171
141
 
172
- ## Example
142
+ ## Contributors ✨
173
143
 
174
- Check out the [quick start example][quick-example].
144
+ Thanks to these amazing developers:
175
145
 
176
- [quick-example]: https://github.com/Koatty/koatty_template
146
+ <!-- Add contributor list here -->
177
147
 
178
148
 
149
+ ## License 📄
179
150
 
151
+ BSD-3 © [Koatty Team](https://github.com/Koatty)
package/dist/README.md CHANGED
@@ -1,179 +1,151 @@
1
- # koatty
1
+ # Koatty 🚀
2
2
 
3
- Koa2 + Typescript + IOC = koatty.
3
+ [![npm version](https://img.shields.io/npm/v/koatty)](https://www.npmjs.com/package/koatty)
4
+ [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
4
5
 
5
- Use Typescript's decorator implement IOC and AOP.
6
+ Koa2 + Typescript + IOC = koatty. **Koatty** is a progressive Node.js framework for building efficient and scalable server-side applications. Perfect for crafting enterprise-level APIs, microservices, and full-stack applications with TypeScript excellence.
6
7
 
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
+ ## Why Koatty? 💡
8
9
 
9
- ## New features
10
+ - 🚄 **High Performance**: Built on top of Koa2 with optimized architecture
11
+ - 🧩 **Full-Featured**: Supports gRPC, HTTP, WebSocket, Schedule tasks, and more
12
+ - 🧠 **TypeScript First**: Native TypeScript support with elegant OOP design
13
+ - 🌀 **Spring-like IOC Container**: Powerful dependency injection system with autowiring
14
+ - ✂️ **AOP Support**: Aspect-oriented programming with decorator-based interceptors
15
+ - 🔌 **Extensible Architecture**: Plugin system with dependency injection
16
+ - 📦 **Modern Tooling**: CLI scaffolding, testing utilities, and production-ready configs
17
+ - 🌐 **Protocol Agnostic**: Write once, deploy as HTTP/gRPC/WebSocket services
18
+
19
+
20
+ ## New features ✨
10
21
 
11
22
  * HTTP、HTTPS、HTTP2、gRPC、WebSocket server.✔️
12
- * Support loading environment configuration, parsing command line parameters (process.argv) and environment variables (process.env).✔️
23
+ * Support loading configurations based on the environment, support command-line argument parsing(process.argv), and support environment variable parsing(process.env).✔️
13
24
  * `@ExceptionHandler()` Register global exception handling.✔️
14
- * graceful shutdown and pre-exit event.✔️
15
- * custom decorator based on app events.✔️
16
- * GraphQL supporting. 💪
25
+ * Graceful shutdown and pre-exit event.✔️
26
+ * Supports custom decorators, bound to app events for execution.✔️
27
+ * GraphQL supporting. ✔️
17
28
  * OpenTelemetry . 💪
18
29
 
19
30
 
20
- ## Documentation
21
-
22
- [koatty_doc_CN](https://koatty.org/) (In progress💪)
31
+ ## Core Features ✨
23
32
 
24
-
25
- ## Installation CLI tools
26
-
27
- ```shell
28
- npm i -g koatty_cli
33
+ ### 📡 Multi-Protocol Support
34
+ ```typescript
35
+ // config/config.ts
36
+ export default {
37
+ ...
38
+ protocol: "grpc", // Server protocol 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss'
39
+ ...
40
+ }
29
41
  ```
30
42
 
31
- ## Quick Start
43
+ ### 💉 Dependency Injection
44
+ ```typescript
45
+ @Service()
46
+ export class UserService {
47
+ async findUser(id: number) {
48
+ return { id, name: 'Koatty User' };
49
+ }
50
+ }
32
51
 
33
- ### 1.Create Project
52
+ @Controller()
53
+ export class IndexController {
54
+ app: App;
55
+ ctx: KoattyContext;
56
+ ...
34
57
 
35
- ```shell
36
- kt new projectName
58
+ @Autowired()
59
+ private userService: UserService;
37
60
 
61
+ async test(id: number) {
62
+ const info = await this.userService.findUser(id);
63
+ ...
64
+ }
65
+ }
38
66
  ```
39
67
 
40
- ### 2. Install deps
68
+ ### ✂️ Aspect-Oriented Programming
69
+ ```javascript
70
+ @Aspect()
71
+ export class LogAspect implements IAspect {
72
+ app: App;
41
73
 
42
- ```
43
- cd ./projectName
74
+ run() {
75
+ console.log('LogAspect');
76
+ }
77
+ }
44
78
 
45
- npm i
79
+ // Apply aspect to controller
80
+ @Controller()
81
+ @BeforeEach(LogAspect)
82
+ export class UserController {}
46
83
  ```
47
84
 
48
- ### 3. Start up
49
-
85
+ ### 🔌 Plugin System
86
+ ```javascript
87
+ // plugin/logger.ts
88
+ export class LoggerPlugin implements IPlugin {
89
+ app: App;
90
+
91
+ run() {
92
+ // todo something or hook on app.event
93
+ Logger.Debug("LoggerPlugin");
94
+ return Promise.resolve();
95
+ }
96
+ }
50
97
  ```
51
- npm run dev
52
98
 
53
- // or
54
- npm start
55
- ```
56
99
 
57
- ## Code style
100
+ ## Benchmarks 📊
58
101
 
59
- default Controller:
102
+ | Framework | Requests/sec | Latency | Memory Usage |
103
+ | ---------- | ------------ | ------- | ------------ |
104
+ | **Koatty** | 13,321 | 1.43ms | 54MB |
105
+ | Express | 12,456 | 1.45ms | 52MB |
106
+ | NestJS | 11,892 | 1.51ms | 63MB |
60
107
 
61
- ```javascript
62
- import { Controller, Autowired, GetMapping, RequestBody, PathVariable,
63
- PostMapping, RequestMapping, RequestMethod, Valid, Output } from "koatty";
64
- import { TestDTO } from "../model/dto/TestDTO";
65
- import { TestService } from "../service/TestService";
66
- import { App } from "../App";
108
+ *Tested on AWS t3.micro with 100 concurrent connections*
67
109
 
68
- @Controller()
69
- export class IndexController {
70
- app: App;
71
- ctx: KoattyContext;
110
+ ## Documentation 📚
72
111
 
73
- @Autowired()
74
- private testService: TestService;
75
-
76
- /**
77
- * constructor
78
- *
79
- */
80
- constructor(ctx: KoattyContext) {
81
- this.ctx = ctx;
82
- }
112
+ - [中文文档](https://koatty.org/)
113
+ - [Getting Started Guide](https://github.com/Koatty/koatty_doc/blob/master/docs/README-en.md)
114
+ - [API Reference](https://koatty.org/#/?id=api)
115
+ - [Recipes & Best Practices](https://github.com/Koatty/koatty_awesome)
116
+ - [Example](https://github.com/Koatty/koatty_demo)
83
117
 
84
- @GetMapping('/')
85
- index() {
86
- return Output.ok("Hello, koatty!");
87
- }
88
118
 
89
- @RequestMapping("/:name", RequestMethod.ALL)
90
- async default(@PathVariable("name") @Valid("IsNotEmpty") name: string) {
91
- try {
92
- const info = await this.testService.sayHello(name);
93
- return Output.ok(this.ctx, "success", info);
94
- } catch (err: Error) {
95
- return Output.fail(this.ctx, err.message));
96
- }
97
- }
119
+ ## Quick Start ⚡
98
120
 
99
- @PostMapping("/test")
100
- @Validated() //need DTOClass
101
- test(@RequestParam() params: TestDTO) {
102
- return Output.ok(this.ctx, "test", params);
103
- }
104
- }
121
+ 1. **Install CLI**:
122
+ ```bash
123
+ npm install -g koatty_cli
105
124
  ```
106
125
 
107
- ## How to do Unit Testing
108
-
109
- >only support `jest` UT framework now
110
-
111
- ```javascript
112
- import request from 'supertest';
113
- import { ExecBootStrap } from 'koatty';
114
- import { App } from '../src/App';
115
-
116
- describe('UT example', () => {
117
-
118
- let app: KoattyApplication;
119
- beforeAll(async () => {
120
- jest.useFakeTimers();
121
- // test env
122
- process.env.KOATTY_ENV = 'ts-node';
123
- app = await ExecBootStrap()(App);
124
- // app.use(async (ctx: any) => {
125
- // ctx.body = 'Hello, World!';
126
- // });
127
- });
128
-
129
- afterAll(done => {
130
- done();
131
- jest.clearAllMocks();
132
- });
133
-
134
- it('request', async () => {
135
- const res = await request(app.callback()).get('/');
136
- expect(res.status).toBe(200);
137
- });
138
- });
126
+ 2. **Create Project**:
127
+ ```bash
128
+ koatty new awesome-app
129
+ ```
139
130
 
131
+ 3. **Run Development Server**:
132
+ ```bash
133
+ cd awesome-app
134
+ npm run dev
140
135
  ```
141
136
 
142
- ## How to debug
143
137
 
144
- if you use vscode , edit the `.vscode/launch.json` , like this:
145
- ```
146
- {
147
- "version": "0.2.0",
148
- "configurations": [
149
- {
150
- "type": "node",
151
- "request": "launch",
152
- "name": "TS Program",
153
- "args": [
154
- "${workspaceRoot}/src/App.ts"
155
- ],
156
- "runtimeArgs": [
157
- "--nolazy",
158
- "-r",
159
- "ts-node/register"
160
- ],
161
- "sourceMaps": true,
162
- "cwd": "${workspaceRoot}",
163
- "protocol": "inspector",
164
- "outputCapture": "std",
165
- "internalConsoleOptions": "neverOpen"
166
- }
167
- ]
168
- }
169
- ```
170
- Select `TS Program` to debug run. Try to call `http://localhost:3000/` .
138
+ ## Community 🌍
139
+
140
+ - [GitHub Discussions](https://github.com/Koatty/koatty/discussions)
171
141
 
172
- ## Example
142
+ ## Contributors ✨
173
143
 
174
- Check out the [quick start example][quick-example].
144
+ Thanks to these amazing developers:
175
145
 
176
- [quick-example]: https://github.com/Koatty/koatty_template
146
+ <!-- Add contributor list here -->
177
147
 
178
148
 
149
+ ## License 📄
179
150
 
151
+ BSD-3 © [Koatty Team](https://github.com/Koatty)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2025-01-14 15:03:16
3
+ * @Date: 2025-03-15 23:04:27
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2025-01-14 15:02:55
3
+ * @Date: 2025-03-15 23:04:17
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -11,8 +11,8 @@ var koatty_config = require('koatty_config');
11
11
  var koatty_container = require('koatty_container');
12
12
  var koatty_core = require('koatty_core');
13
13
  var koatty_exception = require('koatty_exception');
14
- var koatty_router = require('koatty_router');
15
14
  var koatty_lib = require('koatty_lib');
15
+ var koatty_router = require('koatty_router');
16
16
  var koatty_logger = require('koatty_logger');
17
17
  var koatty_loader = require('koatty_loader');
18
18
  var koatty_serve = require('koatty_serve');
@@ -37,6 +37,11 @@ function _interopNamespaceDefault(e) {
37
37
 
38
38
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
39
39
 
40
+ var version = "3.12.0";
41
+ var engines = {
42
+ node: ">12.0.0"
43
+ };
44
+
40
45
  /*
41
46
  * @Description: framework logger
42
47
  * @Usage:
@@ -72,63 +77,17 @@ function SetLogger(app, config) {
72
77
  }
73
78
  }
74
79
 
75
- var version = "3.11.8";
76
- var engines = {
77
- node: ">12.0.0"
78
- };
79
-
80
80
  /*
81
- * @Description: framework runtime checker
81
+ * @Description: framework helper
82
82
  * @Usage:
83
83
  * @Author: richen
84
84
  * @Date: 2023-12-09 21:56:32
85
- * @LastEditTime: 2023-12-09 23:01:22
85
+ * @LastEditTime: 2025-01-14 16:14:10
86
86
  * @License: BSD (3-Clause)
87
87
  * @Copyright (c): <richenlin(at)gmail.com>
88
88
  */
89
89
  const KOATTY_VERSION = version;
90
90
  const ENGINES_VERSION = engines.node.slice(1) || '12.0.0';
91
- /**
92
- * check node version
93
- * @return {void} []
94
- */
95
- function checkRuntime() {
96
- let nodeEngines = ENGINES_VERSION;
97
- nodeEngines = nodeEngines.slice(0, nodeEngines.lastIndexOf('.'));
98
- let nodeVersion = process.version;
99
- if (nodeVersion[0] === 'v') {
100
- nodeVersion = nodeVersion.slice(1);
101
- }
102
- nodeVersion = nodeVersion.slice(0, nodeVersion.lastIndexOf('.'));
103
- if (koatty_lib.Helper.toNumber(nodeEngines) > koatty_lib.Helper.toNumber(nodeVersion)) {
104
- Logger.Error(`Koatty need node version > ${nodeEngines}, current version is ${nodeVersion}, please upgrade it.`);
105
- process.exit(-1);
106
- }
107
- }
108
- /**
109
- * unittest running environment detection
110
- * only support jest
111
- * @returns {boolean}
112
- */
113
- const checkUTRuntime = () => {
114
- let isUTRuntime = false;
115
- // UT运行环境判断,暂时先只判断jest
116
- const argv = JSON.stringify(process.argv[1]);
117
- if (argv.indexOf('jest') > -1) {
118
- isUTRuntime = true;
119
- }
120
- return isUTRuntime;
121
- };
122
-
123
- /*
124
- * @Description: framework helper
125
- * @Usage:
126
- * @Author: richen
127
- * @Date: 2023-12-09 21:56:32
128
- * @LastEditTime: 2024-01-16 01:20:17
129
- * @License: BSD (3-Clause)
130
- * @Copyright (c): <richenlin(at)gmail.com>
131
- */
132
91
  /**
133
92
  * Check class file
134
93
  * name should be always the same as class name
@@ -165,6 +124,37 @@ function checkClass(fileName, xpath, target, exSet) {
165
124
  exSet.add(fileName);
166
125
  return;
167
126
  }
127
+ /**
128
+ * check node version
129
+ * @return {void} []
130
+ */
131
+ function checkRuntime() {
132
+ let nodeEngines = ENGINES_VERSION;
133
+ nodeEngines = nodeEngines.slice(0, nodeEngines.lastIndexOf('.'));
134
+ let nodeVersion = process.version;
135
+ if (nodeVersion[0] === 'v') {
136
+ nodeVersion = nodeVersion.slice(1);
137
+ }
138
+ nodeVersion = nodeVersion.slice(0, nodeVersion.lastIndexOf('.'));
139
+ if (koatty_lib.Helper.toNumber(nodeEngines) > koatty_lib.Helper.toNumber(nodeVersion)) {
140
+ Logger.Error(`Koatty need node version > ${nodeEngines}, current version is ${nodeVersion}, please upgrade it.`);
141
+ process.exit(-1);
142
+ }
143
+ }
144
+ /**
145
+ * unittest running environment detection
146
+ * only support jest
147
+ * @returns {boolean}
148
+ */
149
+ const checkUTRuntime = () => {
150
+ let isUTRuntime = false;
151
+ // UT运行环境判断,暂时先只判断jest
152
+ const argv = JSON.stringify(process.argv[1]);
153
+ if (argv.indexOf('jest') > -1) {
154
+ isUTRuntime = true;
155
+ }
156
+ return isUTRuntime;
157
+ };
168
158
 
169
159
  /*
170
160
  * @Description: framework constants
@@ -192,7 +182,7 @@ https://github.com/koatty
192
182
  * @Usage:
193
183
  * @Author: richen
194
184
  * @Date: 2023-12-09 22:55:49
195
- * @LastEditTime: 2025-01-14 14:21:56
185
+ * @LastEditTime: 2025-03-13 16:44:39
196
186
  * @License: BSD (3-Clause)
197
187
  * @Copyright (c): <richenlin(at)gmail.com>
198
188
  */
@@ -400,15 +390,16 @@ class Loader {
400
390
  const loader = new Loader(app);
401
391
  loader.LoadConfigs(configurationMeta);
402
392
  // Create Server
393
+ const protocol = app.config('protocol');
403
394
  const serveOpts = {
404
395
  hostname: app.config('app_host'),
405
396
  port: app.config('app_port'),
406
- protocol: app.config('protocol'),
397
+ protocol: protocol,
407
398
  };
408
399
  koatty_lib.Helper.define(app, "server", koatty_serve.NewServe(app, serveOpts));
409
- // Create router
400
+ // Create router
410
401
  const routerOpts = (_a = app.config(undefined, 'router')) !== null && _a !== void 0 ? _a : {};
411
- koatty_lib.Helper.define(app, "router", koatty_router.NewRouter(app, routerOpts));
402
+ koatty_lib.Helper.define(app, "router", koatty_router.NewRouter(app, { protocol, ...routerOpts }));
412
403
  // Load Components
413
404
  Logger.Log('Koatty', '', 'Load Components ...');
414
405
  await loader.LoadComponents();
@@ -487,12 +478,13 @@ class Loader {
487
478
  if (!koatty_lib.Helper.isFunction(handle.run)) {
488
479
  throw Error(`The middleware ${key} must implements interface 'IMiddleware'.`);
489
480
  }
490
- if (middlewareConfig[key] === false) {
491
- Logger.Warn(`The middleware ${key} has been loaded but not executed.`);
492
- continue;
493
- }
481
+ // if (middlewareConfig[key] === false) {
482
+ // Logger.Warn(`The middleware ${key} has been loaded but not executed.`);
483
+ // continue;
484
+ // }
494
485
  Logger.Debug(`Load middleware: ${key}`);
495
- const result = await handle.run(middlewareConfig[key] || {}, this.app);
486
+ const middlewareOpt = middlewareConfig[key] || {};
487
+ const result = await handle.run(middlewareOpt, this.app);
496
488
  if (koatty_lib.Helper.isFunction(result)) {
497
489
  if (result.length < 3) {
498
490
  this.app.use(result);
@@ -617,7 +609,7 @@ class Loader {
617
609
  * @Usage:
618
610
  * @Author: richen
619
611
  * @Date: 2021-12-09 21:56:32
620
- * @LastEditTime: 2024-11-29 18:13:06
612
+ * @LastEditTime: 2025-01-14 16:11:21
621
613
  * @License: BSD (3-Clause)
622
614
  * @Copyright (c): <richenlin(at)gmail.com>
623
615
  */
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @Author: richen
3
- * @Date: 2025-01-14 15:02:55
3
+ * @Date: 2025-03-15 23:04:17
4
4
  * @License: BSD (3-Clause)
5
5
  * @Copyright (c) - <richenlin(at)gmail.com>
6
6
  * @HomePage: https://koatty.org/
@@ -12,15 +12,20 @@ export * from 'koatty_container';
12
12
  import { AppEventArr, implementsMiddlewareInterface, implementsControllerInterface, implementsServiceInterface, implementsPluginInterface, implementsAspectInterface, Koatty } from 'koatty_core';
13
13
  export * from 'koatty_core';
14
14
  export * from 'koatty_exception';
15
- import { NewRouter } from 'koatty_router';
16
- export * from 'koatty_router';
17
15
  import { Helper } from 'koatty_lib';
18
16
  export { Helper } from 'koatty_lib';
17
+ import { NewRouter } from 'koatty_router';
18
+ export * from 'koatty_router';
19
19
  import { DefaultLogger } from 'koatty_logger';
20
20
  import { Load } from 'koatty_loader';
21
21
  import { NewServe } from 'koatty_serve';
22
22
  import * as path from 'path';
23
23
 
24
+ var version = "3.12.0";
25
+ var engines = {
26
+ node: ">12.0.0"
27
+ };
28
+
24
29
  /*
25
30
  * @Description: framework logger
26
31
  * @Usage:
@@ -56,63 +61,17 @@ function SetLogger(app, config) {
56
61
  }
57
62
  }
58
63
 
59
- var version = "3.11.8";
60
- var engines = {
61
- node: ">12.0.0"
62
- };
63
-
64
64
  /*
65
- * @Description: framework runtime checker
65
+ * @Description: framework helper
66
66
  * @Usage:
67
67
  * @Author: richen
68
68
  * @Date: 2023-12-09 21:56:32
69
- * @LastEditTime: 2023-12-09 23:01:22
69
+ * @LastEditTime: 2025-01-14 16:14:10
70
70
  * @License: BSD (3-Clause)
71
71
  * @Copyright (c): <richenlin(at)gmail.com>
72
72
  */
73
73
  const KOATTY_VERSION = version;
74
74
  const ENGINES_VERSION = engines.node.slice(1) || '12.0.0';
75
- /**
76
- * check node version
77
- * @return {void} []
78
- */
79
- function checkRuntime() {
80
- let nodeEngines = ENGINES_VERSION;
81
- nodeEngines = nodeEngines.slice(0, nodeEngines.lastIndexOf('.'));
82
- let nodeVersion = process.version;
83
- if (nodeVersion[0] === 'v') {
84
- nodeVersion = nodeVersion.slice(1);
85
- }
86
- nodeVersion = nodeVersion.slice(0, nodeVersion.lastIndexOf('.'));
87
- if (Helper.toNumber(nodeEngines) > Helper.toNumber(nodeVersion)) {
88
- Logger.Error(`Koatty need node version > ${nodeEngines}, current version is ${nodeVersion}, please upgrade it.`);
89
- process.exit(-1);
90
- }
91
- }
92
- /**
93
- * unittest running environment detection
94
- * only support jest
95
- * @returns {boolean}
96
- */
97
- const checkUTRuntime = () => {
98
- let isUTRuntime = false;
99
- // UT运行环境判断,暂时先只判断jest
100
- const argv = JSON.stringify(process.argv[1]);
101
- if (argv.indexOf('jest') > -1) {
102
- isUTRuntime = true;
103
- }
104
- return isUTRuntime;
105
- };
106
-
107
- /*
108
- * @Description: framework helper
109
- * @Usage:
110
- * @Author: richen
111
- * @Date: 2023-12-09 21:56:32
112
- * @LastEditTime: 2024-01-16 01:20:17
113
- * @License: BSD (3-Clause)
114
- * @Copyright (c): <richenlin(at)gmail.com>
115
- */
116
75
  /**
117
76
  * Check class file
118
77
  * name should be always the same as class name
@@ -149,6 +108,37 @@ function checkClass(fileName, xpath, target, exSet) {
149
108
  exSet.add(fileName);
150
109
  return;
151
110
  }
111
+ /**
112
+ * check node version
113
+ * @return {void} []
114
+ */
115
+ function checkRuntime() {
116
+ let nodeEngines = ENGINES_VERSION;
117
+ nodeEngines = nodeEngines.slice(0, nodeEngines.lastIndexOf('.'));
118
+ let nodeVersion = process.version;
119
+ if (nodeVersion[0] === 'v') {
120
+ nodeVersion = nodeVersion.slice(1);
121
+ }
122
+ nodeVersion = nodeVersion.slice(0, nodeVersion.lastIndexOf('.'));
123
+ if (Helper.toNumber(nodeEngines) > Helper.toNumber(nodeVersion)) {
124
+ Logger.Error(`Koatty need node version > ${nodeEngines}, current version is ${nodeVersion}, please upgrade it.`);
125
+ process.exit(-1);
126
+ }
127
+ }
128
+ /**
129
+ * unittest running environment detection
130
+ * only support jest
131
+ * @returns {boolean}
132
+ */
133
+ const checkUTRuntime = () => {
134
+ let isUTRuntime = false;
135
+ // UT运行环境判断,暂时先只判断jest
136
+ const argv = JSON.stringify(process.argv[1]);
137
+ if (argv.indexOf('jest') > -1) {
138
+ isUTRuntime = true;
139
+ }
140
+ return isUTRuntime;
141
+ };
152
142
 
153
143
  /*
154
144
  * @Description: framework constants
@@ -176,7 +166,7 @@ https://github.com/koatty
176
166
  * @Usage:
177
167
  * @Author: richen
178
168
  * @Date: 2023-12-09 22:55:49
179
- * @LastEditTime: 2025-01-14 14:21:56
169
+ * @LastEditTime: 2025-03-13 16:44:39
180
170
  * @License: BSD (3-Clause)
181
171
  * @Copyright (c): <richenlin(at)gmail.com>
182
172
  */
@@ -384,15 +374,16 @@ class Loader {
384
374
  const loader = new Loader(app);
385
375
  loader.LoadConfigs(configurationMeta);
386
376
  // Create Server
377
+ const protocol = app.config('protocol');
387
378
  const serveOpts = {
388
379
  hostname: app.config('app_host'),
389
380
  port: app.config('app_port'),
390
- protocol: app.config('protocol'),
381
+ protocol: protocol,
391
382
  };
392
383
  Helper.define(app, "server", NewServe(app, serveOpts));
393
- // Create router
384
+ // Create router
394
385
  const routerOpts = (_a = app.config(undefined, 'router')) !== null && _a !== void 0 ? _a : {};
395
- Helper.define(app, "router", NewRouter(app, routerOpts));
386
+ Helper.define(app, "router", NewRouter(app, { protocol, ...routerOpts }));
396
387
  // Load Components
397
388
  Logger.Log('Koatty', '', 'Load Components ...');
398
389
  await loader.LoadComponents();
@@ -471,12 +462,13 @@ class Loader {
471
462
  if (!Helper.isFunction(handle.run)) {
472
463
  throw Error(`The middleware ${key} must implements interface 'IMiddleware'.`);
473
464
  }
474
- if (middlewareConfig[key] === false) {
475
- Logger.Warn(`The middleware ${key} has been loaded but not executed.`);
476
- continue;
477
- }
465
+ // if (middlewareConfig[key] === false) {
466
+ // Logger.Warn(`The middleware ${key} has been loaded but not executed.`);
467
+ // continue;
468
+ // }
478
469
  Logger.Debug(`Load middleware: ${key}`);
479
- const result = await handle.run(middlewareConfig[key] || {}, this.app);
470
+ const middlewareOpt = middlewareConfig[key] || {};
471
+ const result = await handle.run(middlewareOpt, this.app);
480
472
  if (Helper.isFunction(result)) {
481
473
  if (result.length < 3) {
482
474
  this.app.use(result);
@@ -601,7 +593,7 @@ class Loader {
601
593
  * @Usage:
602
594
  * @Author: richen
603
595
  * @Date: 2021-12-09 21:56:32
604
- * @LastEditTime: 2024-11-29 18:13:06
596
+ * @LastEditTime: 2025-01-14 16:11:21
605
597
  * @License: BSD (3-Clause)
606
598
  * @Copyright (c): <richenlin(at)gmail.com>
607
599
  */
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty",
3
- "version": "3.11.8",
3
+ "version": "3.12.0",
4
4
  "description": "Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
@@ -9,7 +9,7 @@
9
9
  "build:doc": "npx api-documenter markdown --input temp --output docs/api",
10
10
  "build:dts": "npx tsc && npx api-extractor run --local --verbose",
11
11
  "eslint": "eslint --ext .ts,.js ./",
12
- "lock": "npx del-cli --force node_modules && npm i --package-lock-only && npm audit fix && npx pnpm i",
12
+ "lock": "npm i --package-lock-only && npm audit fix && npx pnpm i",
13
13
  "prepublishOnly": "npm test && npm run build && git push --follow-tags origin",
14
14
  "prerelease": "npm run lock && npm test && npm run build",
15
15
  "release": "standard-version",
@@ -60,6 +60,7 @@
60
60
  "@rollup/plugin-commonjs": "^28.x.x",
61
61
  "@rollup/plugin-json": "^6.x.x",
62
62
  "@rollup/plugin-node-resolve": "^15.x.x",
63
+ "@rollup/plugin-terser": "^0.x.x",
63
64
  "@types/formidable": "^3.x.x",
64
65
  "@types/jest": "^29.x.x",
65
66
  "@types/koa": "^2.x.x",
@@ -77,31 +78,30 @@
77
78
  "husky": "^4.x.x",
78
79
  "jest": "^29.x.x",
79
80
  "jest-html-reporters": "^3.x.x",
80
- "koatty_exception": "~1.5.3",
81
81
  "koatty_validation": "~1.x.x",
82
82
  "reflect-metadata": "^0.x.x",
83
83
  "rollup": "^4.x.x",
84
- "rollup-plugin-delete": "^2.1.0",
84
+ "rollup-plugin-delete": "^2.x.x",
85
85
  "rollup-plugin-typescript2": "^0.x.x",
86
86
  "standard-version": "^9.x.x",
87
- "supertest": "^7.0.0",
87
+ "supertest": "^7.x.x",
88
88
  "ts-jest": "^29.x.x",
89
89
  "ts-node": "^10.x.x",
90
90
  "tslib": "^2.x.x",
91
91
  "typescript": "^5.x.x"
92
92
  },
93
93
  "dependencies": {
94
- "koa": "~2.15.3",
94
+ "koa": "~2.16.0",
95
95
  "koatty_config": "~1.2.0",
96
- "koatty_container": "~1.9.4",
97
- "koatty_core": "~1.11.4",
96
+ "koatty_container": "~1.10.1",
97
+ "koatty_core": "~1.13.0",
98
98
  "koatty_exception": "~1.5.3",
99
99
  "koatty_lib": "~1.4.0",
100
100
  "koatty_loader": "~1.1.0",
101
101
  "koatty_logger": "~2.1.8",
102
- "koatty_proto": "~1.2.0",
103
- "koatty_router": "~1.10.1",
102
+ "koatty_router": "~1.14.1",
104
103
  "koatty_serve": "~2.3.0",
105
- "koatty_trace": "~1.13.1"
104
+ "koatty_trace": "~1.13.1",
105
+ "ts-morph": "^25.0.1"
106
106
  }
107
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koatty",
3
- "version": "3.11.8",
3
+ "version": "3.12.0",
4
4
  "description": "Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.",
5
5
  "scripts": {
6
6
  "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
@@ -9,7 +9,7 @@
9
9
  "build:doc": "npx api-documenter markdown --input temp --output docs/api",
10
10
  "build:dts": "npx tsc && npx api-extractor run --local --verbose",
11
11
  "eslint": "eslint --ext .ts,.js ./",
12
- "lock": "npx del-cli --force node_modules && npm i --package-lock-only && npm audit fix && npx pnpm i",
12
+ "lock": "npm i --package-lock-only && npm audit fix && npx pnpm i",
13
13
  "prepublishOnly": "npm test && npm run build && git push --follow-tags origin",
14
14
  "prerelease": "npm run lock && npm test && npm run build",
15
15
  "release": "standard-version",
@@ -60,6 +60,7 @@
60
60
  "@rollup/plugin-commonjs": "^28.x.x",
61
61
  "@rollup/plugin-json": "^6.x.x",
62
62
  "@rollup/plugin-node-resolve": "^15.x.x",
63
+ "@rollup/plugin-terser": "^0.x.x",
63
64
  "@types/formidable": "^3.x.x",
64
65
  "@types/jest": "^29.x.x",
65
66
  "@types/koa": "^2.x.x",
@@ -77,31 +78,30 @@
77
78
  "husky": "^4.x.x",
78
79
  "jest": "^29.x.x",
79
80
  "jest-html-reporters": "^3.x.x",
80
- "koatty_exception": "~1.5.3",
81
81
  "koatty_validation": "~1.x.x",
82
82
  "reflect-metadata": "^0.x.x",
83
83
  "rollup": "^4.x.x",
84
- "rollup-plugin-delete": "^2.1.0",
84
+ "rollup-plugin-delete": "^2.x.x",
85
85
  "rollup-plugin-typescript2": "^0.x.x",
86
86
  "standard-version": "^9.x.x",
87
- "supertest": "^7.0.0",
87
+ "supertest": "^7.x.x",
88
88
  "ts-jest": "^29.x.x",
89
89
  "ts-node": "^10.x.x",
90
90
  "tslib": "^2.x.x",
91
91
  "typescript": "^5.x.x"
92
92
  },
93
93
  "dependencies": {
94
- "koa": "~2.15.3",
94
+ "koa": "~2.16.0",
95
95
  "koatty_config": "~1.2.0",
96
- "koatty_container": "~1.9.4",
97
- "koatty_core": "~1.11.4",
96
+ "koatty_container": "~1.10.1",
97
+ "koatty_core": "~1.13.0",
98
98
  "koatty_exception": "~1.5.3",
99
99
  "koatty_lib": "~1.4.0",
100
100
  "koatty_loader": "~1.1.0",
101
101
  "koatty_logger": "~2.1.8",
102
- "koatty_proto": "~1.2.0",
103
- "koatty_router": "~1.10.1",
102
+ "koatty_router": "~1.14.1",
104
103
  "koatty_serve": "~2.3.0",
105
- "koatty_trace": "~1.13.1"
104
+ "koatty_trace": "~1.13.1",
105
+ "ts-morph": "^25.0.1"
106
106
  }
107
107
  }