Skip to content

Commit 0b0ed38

Browse files
authored
Merge pull request #81 from Koatty/3.x
3.x
2 parents e914448 + a0d136e commit 0b0ed38

24 files changed

+4911
-15313
lines changed

.rollup.config.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
/*
1+
/**
2+
*
23
* @Description:
3-
* @Usage:
44
* @Author: richen
5-
* @Date: 2021-12-17 10:20:44
6-
* @LastEditTime: 2025-03-15 18:06:51
5+
* @Date: 2024-11-07 11:22:26
6+
* @LastEditTime: 2025-04-02 15:05:36
7+
* @License: BSD (3-Clause)
8+
* @Copyright (c): <richenlin(at)gmail.com>
79
*/
810
import commonjs from '@rollup/plugin-commonjs';
911
import json from "@rollup/plugin-json";
@@ -12,7 +14,7 @@ import { builtinModules } from 'module';
1214
import del from "rollup-plugin-delete";
1315
import typescript from 'rollup-plugin-typescript2';
1416
// import babel from '@rollup/plugin-babel';
15-
// import terser from '@rollup/plugin-terser';
17+
import terser from "@rollup/plugin-terser";
1618
const pkg = require('./package.json');
1719

1820
export default [
@@ -28,7 +30,7 @@ export default [
2830
format: 'es',
2931
file: './dist/index.mjs',
3032
banner: require('./scripts/copyright'),
31-
},
33+
}
3234
],
3335
plugins: [
3436
del({ targets: ["dist/*", "temp/*", "docs/api"] }),
@@ -51,11 +53,24 @@ export default [
5153
}
5254
}
5355
}),
54-
// terser({
55-
// format: { comments: false },
56-
// compress: false,
57-
// mangle: false
58-
// }),
56+
terser({
57+
compress: {
58+
defaults: false, // 改为 `false`(新版本默认启用所有优化)
59+
arrows: true, // 保留箭头函数转换
60+
booleans: true, // 保留布尔简化
61+
drop_console: false, // 保留 console
62+
keep_fnames: true // 保留函数名
63+
},
64+
mangle: {
65+
reserved: ['$super'], // 保留关键字
66+
keep_classnames: true // 保留类名
67+
},
68+
format: {
69+
beautify: true, // 启用格式化
70+
indent_level: 2, // 缩进层级
71+
comments: /@Author|@License|@Copyright/ // 保留特定注释
72+
}
73+
})
5974
],
6075
external: [
6176
...builtinModules, // 排除 Node.js 内置模块
@@ -64,4 +79,4 @@ export default [
6479
],
6580
},
6681

67-
]
82+
]

CHANGELOG.md

Lines changed: 1873 additions & 185 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@
33
[![npm version](https://img.shields.io/npm/v/koatty)](https://www.npmjs.com/package/koatty)
44
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
55

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+
Koa2 + TypeScript + IOC = Koatty. **Koatty** is a progressive Node.js framework for building efficient and scalable server-side applications. It's perfect for crafting enterprise-level APIs, microservices, and full-stack applications with TypeScript excellence.
77

88
## Why Koatty? 💡
99

1010
- 🚄 **High Performance**: Built on top of Koa2 with optimized architecture
11-
- 🧩 **Full-Featured**: Supports gRPC, HTTP, WebSocket, Schedule tasks, and more
11+
- 🧩 **Full-Featured**: Supports gRPC, HTTP, WebSocket, scheduled tasks, and more
1212
- 🧠 **TypeScript First**: Native TypeScript support with elegant OOP design
1313
- 🌀 **Spring-like IOC Container**: Powerful dependency injection system with autowiring
1414
- ✂️ **AOP Support**: Aspect-oriented programming with decorator-based interceptors
1515
- 🔌 **Extensible Architecture**: Plugin system with dependency injection
16-
- 📦 **Modern Tooling**: CLI scaffolding, testing utilities, and production-ready configs
16+
- 📦 **Modern Tooling**: CLI scaffolding, testing utilities, and production-ready configurations
1717
- 🌐 **Protocol Agnostic**: Write once, deploy as HTTP/gRPC/WebSocket services
1818

19+
## New Features ✨
1920

20-
## New features ✨
21-
22-
* HTTP、HTTPS、HTTP2、gRPC、WebSocket server.✔️
23-
* Support loading configurations based on the environment, support command-line argument parsing(process.argv), and support environment variable parsing(process.env).✔️
24-
* `@ExceptionHandler()` Register global exception handling.✔️
25-
* Graceful shutdown and pre-exit event.✔️
26-
* Supports custom decorators, bound to app events for execution.✔️
27-
* GraphQL supporting. ✔️
28-
* OpenTelemetry . 💪
29-
21+
- HTTP, HTTPS, HTTP2, gRPC, and WebSocket server support ✔️
22+
- Environment-based configuration loading, command-line argument parsing (process.argv), and environment variable parsing (process.env) ✔️
23+
- `@ExceptionHandler()` for global exception handling ✔️
24+
- Graceful shutdown and pre-exit events ✔️
25+
- Custom decorators bound to app events ✔️
26+
- GraphQL integration ✔️
27+
- Full-stack tracing through OpenTelemetry ✔️
28+
- Middleware binding to controllers and method routes ✔️
29+
- gRPC streaming support ✔️
30+
- Swagger OpenAPI 3.0 support 💪
3031

3132
## Core Features ✨
3233

@@ -35,7 +36,7 @@ Koa2 + Typescript + IOC = koatty. **Koatty** is a progressive Node.js framework
3536
// config/config.ts
3637
export default {
3738
...
38-
protocol: "grpc", // Server protocol 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss'
39+
protocol: "grpc", // Server protocol 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss' | 'graphql'
3940
...
4041
}
4142
```
@@ -53,6 +54,8 @@ export class UserService {
5354
export class IndexController {
5455
app: App;
5556
ctx: KoattyContext;
57+
@Config("protocol")
58+
conf: { protocol: string };
5659
...
5760

5861
@Autowired()
@@ -66,7 +69,7 @@ export class IndexController {
6669
```
6770

6871
### ✂️ Aspect-Oriented Programming
69-
```javascript
72+
```typescript
7073
@Aspect()
7174
export class LogAspect implements IAspect {
7275
app: App;
@@ -79,11 +82,17 @@ export class LogAspect implements IAspect {
7982
// Apply aspect to controller
8083
@Controller()
8184
@BeforeEach(LogAspect)
82-
export class UserController {}
85+
export class UserController {
86+
...
87+
@After(LogAspect)
88+
test() {
89+
...
90+
}
91+
}
8392
```
8493

8594
### 🔌 Plugin System
86-
```javascript
95+
```typescript
8796
// plugin/logger.ts
8897
export class LoggerPlugin implements IPlugin {
8998
app: App;
@@ -96,7 +105,6 @@ export class LoggerPlugin implements IPlugin {
96105
}
97106
```
98107

99-
100108
## Benchmarks 📊
101109

102110
| Framework | Requests/sec | Latency | Memory Usage |
@@ -115,7 +123,6 @@ export class LoggerPlugin implements IPlugin {
115123
- [Recipes & Best Practices](https://github.com/Koatty/koatty_awesome)
116124
- [Example](https://github.com/Koatty/koatty_demo)
117125

118-
119126
## Quick Start ⚡
120127

121128
1. **Install CLI**:
@@ -134,7 +141,6 @@ cd awesome-app
134141
npm run dev
135142
```
136143

137-
138144
## Community 🌍
139145

140146
- [GitHub Discussions](https://github.com/Koatty/koatty/discussions)
@@ -145,7 +151,6 @@ Thanks to these amazing developers:
145151

146152
<!-- Add contributor list here -->
147153

148-
149154
## License 📄
150155

151156
BSD-3 © [Koatty Team](https://github.com/Koatty)

demo/src/config/config.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,5 @@
77
*/
88
export default {
99
/*app config*/
10-
app_port: 3000, // Listening port
11-
app_host: "", // Hostname
12-
protocol: "http", // Server protocol 'http' | 'https' | 'http2' | 'grpc' | 'ws' | 'wss' | 'graphql'
13-
open_trace: true, // Full stack debug & trace, default: false
14-
http_timeout: 10, // HTTP request timeout time(seconds)
15-
key_file: "", // HTTPS certificate key
16-
crt_file: "", // HTTPS certificate crt
17-
encoding: "utf-8", // Character Encoding
1810

19-
logs_level: "debug", // Level log is printed to the console, "debug" | "info" | "warning" | "error"
20-
// logs_path: "./logs", // Log file directory
21-
// sens_fields: ["password"] // Sensitive words
2211
};

demo/src/config/middleware.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default {
1010
list: [], //加载的中间件列表
1111
config: { //中间件配置
1212
// 静态服务器中间件默认未开启
13-
StaticMiddleware: false,
13+
// StaticMiddleware: false,
1414
// 需要开启请修改为:
15-
// StaticMiddleware: {
16-
// cache: true
17-
// },
15+
StaticMiddleware: {
16+
cache: true
17+
},
1818

1919
SessionMiddleware: {
2020
key: 'koa.sess', /** (string) cookie key (default is koa.sess) */

demo/src/middleware/SessionMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
// @Middleware()
15-
// export class SessionMiddleware implements IMiddleware {
15+
// export class SessionMiddleware {
1616
// run(options: any, app: App) {
1717
// return session(options, app);
1818
// }

demo/src/middleware/StaticMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { App } from '../App';
99
// import { Static } from "koatty_static";
1010

1111
@Middleware()
12-
export class StaticMiddleware implements IMiddleware {
12+
export class StaticMiddleware {
1313
run(options: any, app: App) {
1414
return function (ctx: KoattyContext, next: KoattyNext) {
1515
return next();

docs/api/index.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2-
3-
[Home](./index.md)
4-
5-
## API Reference
6-
7-
## Packages
8-
9-
<table><thead><tr><th>
10-
11-
Package
12-
13-
14-
</th><th>
15-
16-
Description
17-
18-
19-
</th></tr></thead>
20-
<tbody><tr><td>
21-
22-
[koatty](./koatty.md)
23-
24-
25-
</td><td>
26-
27-
28-
</td></tr>
29-
</tbody></table>
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md)
4+
5+
## API Reference
6+
7+
## Packages
8+
9+
<table><thead><tr><th>
10+
11+
Package
12+
13+
14+
</th><th>
15+
16+
Description
17+
18+
19+
</th></tr></thead>
20+
<tbody><tr><td>
21+
22+
[koatty](./koatty.md)
23+
24+
25+
</td><td>
26+
27+
28+
</td></tr>
29+
</tbody></table>

0 commit comments

Comments
 (0)