koatty 3.13.2 → 4.0.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/dist/package.json CHANGED
@@ -1,106 +1,107 @@
1
- {
2
- "name": "koatty",
3
- "version": "3.13.2",
4
- "description": "Koa2 + Typescript = koatty. Use Typescript's decorator implement auto injection.",
5
- "scripts": {
6
- "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp",
7
- "build:cp": "node scripts/postBuild && npx copyfiles package.json LICENSE README.md dist/",
8
- "build:js": "npx rollup --bundleConfigAsCjs -c .rollup.config.js",
9
- "build:doc": "npx api-documenter markdown --input temp --output docs/api",
10
- "build:dts": "npx tsc && npx api-extractor run --local --verbose",
11
- "eslint": "eslint --ext .ts,.js ./",
12
- "prepublishOnly": "npm test && npm run build && git push --follow-tags origin",
13
- "prerelease": "npm test && npm run build",
14
- "release": "standard-version",
15
- "release:pre": "npm run release -- --prerelease",
16
- "release:major": "npm run release -- --release-as major",
17
- "release:minor": "npm run release -- --release-as minor",
18
- "test": "npm run eslint && jest --passWithNoTests",
19
- "test:cov": "jest --collectCoverage --detectOpenHandles",
20
- "version": "conventional-changelog -p angular -i CHANGELOG.md -s"
21
- },
22
- "main": "./dist/index.js",
23
- "exports": {
24
- "require": "./dist/index.js",
25
- "import": "./dist/index.mjs",
26
- "types": "./dist/index.d.ts"
27
- },
28
- "directories": {
29
- "doc": "docs"
30
- },
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/thinkkoa/koatty.git"
34
- },
35
- "engines": {
36
- "node": ">12.0.0"
37
- },
38
- "author": {
39
- "name": "richenlin",
40
- "email": "richenlin@gmail.com"
41
- },
42
- "license": "BSD-3-Clause",
43
- "bugs": {
44
- "url": "https://github.com/thinkkoa/koatty/issues"
45
- },
46
- "homepage": "https://github.com/thinkkoa/koatty",
47
- "maintainers": [
48
- {
49
- "name": "richenlin",
50
- "email": "richenlin@gmail.com"
51
- }
52
- ],
53
- "devDependencies": {
54
- "@commitlint/cli": "^19.x.x",
55
- "@commitlint/config-conventional": "^19.x.x",
56
- "@grpc/grpc-js": "^1.12.2",
57
- "@microsoft/api-documenter": "^7.x.x",
58
- "@microsoft/api-extractor": "^7.x.x",
59
- "@rollup/plugin-commonjs": "^28.x.x",
60
- "@rollup/plugin-json": "^6.x.x",
61
- "@rollup/plugin-node-resolve": "^16.0.1",
62
- "@rollup/plugin-terser": "^0.x.x",
63
- "@types/formidable": "^3.x.x",
64
- "@types/jest": "^29.x.x",
65
- "@types/koa": "^2.x.x",
66
- "@types/koa-compose": "^3.x.x",
67
- "@types/lodash": "^4.x.x",
68
- "@types/node": "^22.x.x",
69
- "@types/on-finished": "^2.x.x",
70
- "@types/supertest": "^6.x.x",
71
- "@types/ws": "^8.x.x",
72
- "@typescript-eslint/eslint-plugin": "^8.x.x",
73
- "@typescript-eslint/parser": "^8.x.x",
74
- "conventional-changelog-cli": "^5.x.x",
75
- "eslint": "^8.x.x",
76
- "eslint-plugin-jest": "^28.x.x",
77
- "husky": "^4.x.x",
78
- "jest": "^29.x.x",
79
- "jest-html-reporters": "^3.x.x",
80
- "koatty_validation": "~1.x.x",
81
- "reflect-metadata": "^0.x.x",
82
- "rollup": "^4.x.x",
83
- "rollup-plugin-delete": "^2.x.x",
84
- "rollup-plugin-typescript2": "^0.x.x",
85
- "standard-version": "^9.x.x",
86
- "supertest": "^7.x.x",
87
- "ts-jest": "^29.x.x",
88
- "ts-node": "^10.x.x",
89
- "tslib": "^2.x.x",
90
- "typescript": "^5.x.x"
91
- },
92
- "dependencies": {
93
- "koa": "~2.16.1",
94
- "koatty_config": "~1.2.0",
95
- "koatty_container": "~1.12.0",
96
- "koatty_core": "~1.16.2",
97
- "koatty_exception": "~1.6.0",
98
- "koatty_lib": "~1.4.2",
99
- "koatty_loader": "~1.1.0",
100
- "koatty_logger": "~2.2.0",
101
- "koatty_router": "~1.15.0",
102
- "koatty_serve": "~2.4.0",
103
- "koatty_trace": "~1.15.2",
104
- "ts-morph": "^25.0.1"
105
- }
106
- }
1
+ {
2
+ "name": "koatty",
3
+ "version": "4.0.0",
4
+ "description": "Koa + Typescript = koatty. Use Typescript's decorator implement auto injection.",
5
+ "scripts": {
6
+ "build": "npm run build:js && npm run build:dts && npm run build:doc && npm run build:cp && npm run build:fix",
7
+ "build:cp": "npx copyfiles package.json LICENSE README.md dist/ && node scripts/postBuild",
8
+ "build:fix": "node scripts/fixWorkspaceDeps",
9
+ "build:js": "npx rollup --bundleConfigAsCjs -c .rollup.config.js",
10
+ "build:doc": "npx api-documenter markdown --input temp --output docs/api",
11
+ "build:dts": "npx tsc --skipLibCheck && npx api-extractor run --local --verbose",
12
+ "eslint": "eslint --ext .ts,.js ./",
13
+ "prepublishOnly": "echo 'Skipping prepublishOnly in monorepo'",
14
+ "prerelease": "npm test && npm run build",
15
+ "release": "standard-version",
16
+ "release:pre": "npm run release -- --prerelease",
17
+ "release:major": "npm run release -- --release-as major",
18
+ "release:minor": "npm run release -- --release-as minor",
19
+ "test": "npm run eslint && jest --passWithNoTests",
20
+ "test:cov": "jest --collectCoverage --detectOpenHandles",
21
+ "version": "conventional-changelog -p angular -i CHANGELOG.md -s"
22
+ },
23
+ "main": "./dist/index.js",
24
+ "exports": {
25
+ "require": "./dist/index.js",
26
+ "import": "./dist/index.mjs",
27
+ "types": "./dist/index.d.ts"
28
+ },
29
+ "directories": {
30
+ "doc": "docs"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/thinkkoa/koatty.git"
35
+ },
36
+ "engines": {
37
+ "node": ">=18.0.0"
38
+ },
39
+ "author": {
40
+ "name": "richenlin",
41
+ "email": "richenlin@gmail.com"
42
+ },
43
+ "license": "BSD-3-Clause",
44
+ "bugs": {
45
+ "url": "https://github.com/thinkkoa/koatty/issues"
46
+ },
47
+ "homepage": "https://github.com/thinkkoa/koatty",
48
+ "maintainers": [
49
+ {
50
+ "name": "richenlin",
51
+ "email": "richenlin@gmail.com"
52
+ }
53
+ ],
54
+ "devDependencies": {
55
+ "@commitlint/cli": "^19.x.x",
56
+ "@commitlint/config-conventional": "^19.x.x",
57
+ "@grpc/grpc-js": "^1.12.2",
58
+ "@microsoft/api-documenter": "^7.x.x",
59
+ "@microsoft/api-extractor": "^7.x.x",
60
+ "@rollup/plugin-commonjs": "^28.x.x",
61
+ "@rollup/plugin-json": "^6.x.x",
62
+ "@rollup/plugin-node-resolve": "^16.0.1",
63
+ "@rollup/plugin-terser": "^0.x.x",
64
+ "@types/formidable": "^3.x.x",
65
+ "@types/jest": "^29.x.x",
66
+ "@types/koa": "^2.x.x",
67
+ "@types/koa-compose": "^3.x.x",
68
+ "@types/lodash": "^4.x.x",
69
+ "@types/node": "^22.x.x",
70
+ "@types/on-finished": "^2.x.x",
71
+ "@types/supertest": "^6.x.x",
72
+ "@types/ws": "^8.x.x",
73
+ "@typescript-eslint/eslint-plugin": "^8.x.x",
74
+ "@typescript-eslint/parser": "^8.x.x",
75
+ "conventional-changelog-cli": "^5.x.x",
76
+ "eslint": "^8.x.x",
77
+ "eslint-plugin-jest": "^28.x.x",
78
+ "husky": "^4.x.x",
79
+ "jest": "^29.x.x",
80
+ "jest-html-reporters": "^3.x.x",
81
+ "koatty_validation": "~1.x.x",
82
+ "reflect-metadata": "^0.x.x",
83
+ "rollup": "^4.x.x",
84
+ "rollup-plugin-delete": "^2.x.x",
85
+ "rollup-plugin-typescript2": "^0.x.x",
86
+ "standard-version": "^9.x.x",
87
+ "supertest": "^7.x.x",
88
+ "ts-jest": "^29.x.x",
89
+ "ts-node": "^10.x.x",
90
+ "tslib": "^2.x.x",
91
+ "typescript": "^5.x.x"
92
+ },
93
+ "dependencies": {
94
+ "koa": "^3.0.3",
95
+ "koatty_config": "^1.2.2",
96
+ "koatty_container": "^1.17.0",
97
+ "koatty_core": "^2.0.8",
98
+ "koatty_exception": "^2.0.4",
99
+ "koatty_lib": "^1.4.3",
100
+ "koatty_loader": "^1.3.0",
101
+ "koatty_logger": "2.8.1",
102
+ "koatty_router": "^2.0.2",
103
+ "koatty_serve": "^3.0.0",
104
+ "koatty_trace": "^2.0.0",
105
+ "ts-morph": "^27.0.2"
106
+ }
107
+ }
@@ -0,0 +1,172 @@
1
+ # Koatty Examples
2
+
3
+ 这个目录包含了Koatty框架的各种示例应用,帮助你快速上手和理解框架的使用方法。
4
+
5
+ ## 📚 示例列表
6
+
7
+ ### 🟢 basic-app - 基础应用示例
8
+
9
+ 完整的基础应用示例,展示Koatty框架的核心功能。
10
+
11
+ **功能特性**:
12
+ - ✅ HTTP路由和控制器
13
+ - ✅ 中间件使用
14
+ - ✅ 服务层和依赖注入
15
+ - ✅ 数据验证(DTO)
16
+ - ✅ 异常处理
17
+ - ✅ AOP切面编程
18
+ - ✅ 静态资源服务
19
+ - ✅ 视图模板
20
+
21
+ **查看详情**: [basic-app/README.md](./basic-app/README.md)
22
+
23
+ ---
24
+
25
+ ### 🔵 graphql-app - GraphQL应用示例 (规划中)
26
+
27
+ 展示如何使用Koatty构建GraphQL API。
28
+
29
+ **功能特性**:
30
+ - GraphQL Schema定义
31
+ - Resolver实现
32
+ - GraphiQL调试界面
33
+ - DataLoader优化
34
+
35
+ ---
36
+
37
+ ### 🟣 grpc-app - gRPC应用示例 (规划中)
38
+
39
+ 展示如何使用Koatty构建gRPC服务。
40
+
41
+ **功能特性**:
42
+ - Protocol Buffers定义
43
+ - gRPC服务实现
44
+ - 双向流通信
45
+ - 健康检查
46
+
47
+ ---
48
+
49
+ ### 🟡 microservices - 微服务示例 (规划中)
50
+
51
+ 展示如何使用Koatty构建微服务架构。
52
+
53
+ **功能特性**:
54
+ - 服务发现
55
+ - 负载均衡
56
+ - 熔断降级
57
+ - 分布式追踪
58
+
59
+ ---
60
+
61
+ ## 🚀 快速开始
62
+
63
+ ### 1. 克隆仓库
64
+
65
+ ```bash
66
+ git clone https://github.com/koatty/koatty-monorepo.git
67
+ cd koatty-monorepo
68
+ ```
69
+
70
+ ### 2. 安装依赖
71
+
72
+ ```bash
73
+ pnpm install
74
+ ```
75
+
76
+ ### 3. 运行示例
77
+
78
+ ```bash
79
+ # 运行基础应用示例
80
+ cd examples/basic-app
81
+ pnpm dev
82
+ ```
83
+
84
+ ### 4. 使用VS Code调试
85
+
86
+ 按 `F5` 启动调试,选择对应的调试配置。
87
+
88
+ ---
89
+
90
+ ## 📋 通用要求
91
+
92
+ 所有示例都需要:
93
+
94
+ - **Node.js**: >= 18.0.0
95
+ - **pnpm**: >= 8.0.0
96
+
97
+ ---
98
+
99
+ ## 🏗️ 项目结构
100
+
101
+ ```
102
+ examples/
103
+ ├── basic-app/ # 基础应用示例
104
+ │ ├── src/ # 源代码
105
+ │ ├── static/ # 静态资源
106
+ │ ├── view/ # 视图模板
107
+ │ ├── package.json # 依赖配置
108
+ │ ├── tsconfig.json # TypeScript配置
109
+ │ └── README.md # 示例说明
110
+ ├── graphql-app/ # GraphQL示例 (规划中)
111
+ ├── grpc-app/ # gRPC示例 (规划中)
112
+ ├── microservices/ # 微服务示例 (规划中)
113
+ └── README.md # 本文件
114
+ ```
115
+
116
+ ---
117
+
118
+ ## 📝 贡献示例
119
+
120
+ 欢迎贡献新的示例!请遵循以下规范:
121
+
122
+ ### 示例结构
123
+
124
+ ```
125
+ your-example/
126
+ ├── src/ # 源代码
127
+ ├── package.json # 必须使用workspace依赖
128
+ ├── tsconfig.json # TypeScript配置
129
+ └── README.md # 详细说明
130
+ ```
131
+
132
+ ### package.json规范
133
+
134
+ ```json
135
+ {
136
+ "name": "@koatty/example-your-name",
137
+ "version": "1.0.0",
138
+ "private": true,
139
+ "dependencies": {
140
+ "koatty": "workspace:*"
141
+ }
142
+ }
143
+ ```
144
+
145
+ ### README规范
146
+
147
+ 每个示例必须包含:
148
+ 1. 功能描述
149
+ 2. 项目结构
150
+ 3. 快速开始指南
151
+ 4. API示例
152
+ 5. 相关链接
153
+
154
+ ---
155
+
156
+ ## 🔗 相关链接
157
+
158
+ - [Koatty主项目](https://github.com/koatty/koatty)
159
+ - [Koatty文档](https://koatty.github.io/)
160
+ - [API文档](https://koatty.github.io/api/)
161
+ - [问题反馈](https://github.com/koatty/koatty/issues)
162
+
163
+ ---
164
+
165
+ ## 📄 许可证
166
+
167
+ 所有示例代码均采用 BSD-3-Clause 许可证。
168
+
169
+ ---
170
+
171
+ **享受使用Koatty构建应用!** 🚀
172
+
@@ -0,0 +1,72 @@
1
+ # Koatty Basic Application Example
2
+
3
+ 这是一个基本的 Koatty 应用示例,位于 `packages/koatty/examples/basic-app` 目录下。
4
+
5
+ ## 目录结构
6
+
7
+ ```
8
+ packages/koatty/examples/basic-app/
9
+ ├── src/
10
+ │ ├── App.ts # 应用入口
11
+ │ ├── bootstrap/ # 启动引导
12
+ │ ├── controller/ # 控制器
13
+ │ ├── service/ # 服务层
14
+ │ ├── middleware/ # 中间件
15
+ │ ├── dto/ # 数据传输对象
16
+ │ ├── aspect/ # 切面
17
+ │ ├── plugin/ # 插件
18
+ │ └── config/ # 配置文件
19
+ ├── package.json
20
+ └── tsconfig.json
21
+ ```
22
+
23
+ ## 安装依赖
24
+
25
+ ```bash
26
+ cd packages/koatty/examples/basic-app
27
+ pnpm install
28
+ ```
29
+
30
+ ## 运行
31
+
32
+ ### 开发模式
33
+
34
+ ```bash
35
+ pnpm run dev
36
+ ```
37
+
38
+ ### VSCode 调试
39
+
40
+ 1. 在 VSCode 中打开项目根目录
41
+ 2. 按 F5 或点击调试面板中的 "Koatty Demo Program"
42
+ 3. 可以在 `packages/koatty/src` 目录下的源码中设置断点进行调试
43
+
44
+ ## 导入说明
45
+
46
+ 由于示例项目位于 `packages/koatty/examples/basic-app` 下,使用相对路径导入 Koatty 框架:
47
+
48
+ ```typescript
49
+ // 导入 Koatty 核心功能
50
+ import { Bootstrap } from "../../../src";
51
+ import { Koatty } from "../../../../koatty-core/src";
52
+ import { AppEvent, KoattyApplication } from "../../../../../koatty-core/src";
53
+ ```
54
+
55
+ 这样可以直接调试框架源码,无需编译。
56
+
57
+ ## 配置文件
58
+
59
+ 配置文件位于 `src/config/` 目录:
60
+
61
+ - `config.ts` - 主配置文件
62
+ - `router.ts` - 路由配置
63
+ - `middleware.ts` - 中间件配置
64
+ - `plugin.ts` - 插件配置
65
+ - `db.ts` - 数据库配置
66
+
67
+ ## 项目特点
68
+
69
+ - ✅ 支持 TypeScript 源码级调试
70
+ - ✅ 使用相对路径直接引用框架源码
71
+ - ✅ 完整的 MVC 架构示例
72
+ - ✅ 包含控制器、服务、中间件、切面等示例代码
@@ -0,0 +1,142 @@
1
+ /*
2
+ * @Description: app config
3
+ * @Usage:
4
+ * @Author: richen
5
+ * @Date: 2023-12-09 21:56:32
6
+ * @LastEditTime: 2025-10-25 10:15:00
7
+ * @License: BSD (3-Clause)
8
+ * @Copyright (c): <richenlin(at)gmail.com>
9
+ */
10
+ export default {
11
+ /*app config*/
12
+ logsLevel: "debug", // Level log is printed to the console, "debug" | "info" | "warning" | "error"
13
+ // logsPath: "./logs", // Log file directory
14
+ // sensFields: ["password"] // Defined privacy fields will not be printed in logs.
15
+
16
+ server: { // server configuration
17
+ hostname: process.env.IP || '127.0.0.1', // server hostname
18
+ // server port: single value (e.g. 3000) or array (e.g. [3000, 3001])
19
+ // For multi-protocol: if port is array, each port maps to corresponding protocol
20
+ // If port is single value, first protocol uses it, others auto-increment (3000, 3001, 3002...)
21
+ port: process.env.PORT || process.env.APP_PORT || 3000,
22
+ protocol: ["http"], // Server protocol 'http' | 'https' | 'http2' | 'http3' | 'grpc' | 'ws' | 'wss' | 'graphql'
23
+ trace: false, // Full stack debug & trace, default: false
24
+ ssl: {
25
+ mode: 'auto', // 'auto' | 'manual' | 'mutual_tls'
26
+ key: '', // key file path
27
+ cert: '', // crt file path
28
+ ca: '' // ca file path
29
+ },
30
+ ext: {}
31
+ },
32
+ trace: { // trace configuration
33
+ // response timeout in milliseconds
34
+ timeout: 10000,
35
+ // request id header name
36
+ requestIdHeaderName: 'X-Request-Id',
37
+ // request id name
38
+ requestIdName: "requestId",
39
+ // encoding
40
+ encoding: 'utf-8',
41
+ // Whether to enable trace (default: false)
42
+ enableTrace: false,
43
+ // asynchooks enabled
44
+ asyncHooks: false,
45
+ /**
46
+ * Metrics configuration
47
+ */
48
+ metricsConf: {
49
+ /**
50
+ * Default attributes for metrics
51
+ */
52
+ defaultAttributes: {},
53
+ /**
54
+ * Prometheus metrics endpoint (production only)
55
+ */
56
+ metricsEndpoint: '/metrics',
57
+ /**
58
+ * Metrics report interval in milliseconds (default: 5000)
59
+ */
60
+ reportInterval: 5000,
61
+ /**
62
+ * Prometheus metrics port (default: 9464)
63
+ */
64
+ metricsPort: 9464,
65
+ },
66
+
67
+ /**
68
+ * OpenTelemetry configuration
69
+ */
70
+ opentelemetryConf: {
71
+ /**
72
+ * OTLP endpoint URL
73
+ */
74
+ endpoint: "http://localhost:4318/v1/traces",
75
+ /**
76
+ * Whether to enable topology analysis (default: same as enableTrace)
77
+ */
78
+ enableTopology: false,
79
+ /**
80
+ * OTLP headers
81
+ */
82
+ headers: {},
83
+ /**
84
+ * Resource attributes
85
+ */
86
+ resourceAttributes: {},
87
+ /**
88
+ * Instrumentations to enable
89
+ */
90
+ instrumentations: [] as any,
91
+ /**
92
+ * Exporter timeout in milliseconds
93
+ */
94
+ timeout: 10000,
95
+ /**
96
+ * Maximum lifetime for a span in milliseconds
97
+ */
98
+ spanTimeout: 30000,
99
+ /**
100
+ * Maximum number of active spans in memory (default: 1000)
101
+ */
102
+ maxActiveSpans: 1000,
103
+ /**
104
+ * Sampling rate (0.0 - 1.0)
105
+ */
106
+ samplingRate: 1.0,
107
+ /**
108
+ * Maximum number of spans in batch queue
109
+ */
110
+ batchMaxQueueSize: 2048,
111
+ /**
112
+ * Maximum number of spans to export in one batch
113
+ */
114
+ batchMaxExportSize: 512,
115
+ /**
116
+ * Delay between batch exports in milliseconds
117
+ */
118
+ batchDelayMillis: 5000,
119
+ /**
120
+ * Timeout for batch export in milliseconds
121
+ */
122
+ batchExportTimeout: 30000,
123
+ },
124
+ /**
125
+ * Retry configuration
126
+ */
127
+ retryConf: {
128
+ /**
129
+ * Whether to enable retry mechanism (default: false)
130
+ */
131
+ enabled: false,
132
+ /**
133
+ * Max retry count when error occurs (default: 3)
134
+ */
135
+ count: 3,
136
+ /**
137
+ * Retry interval in milliseconds (default: 1000)
138
+ */
139
+ interval: 1000,
140
+ },
141
+ }
142
+ };
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@koatty/example-basic-app",
3
+ "version": "1.0.0",
4
+ "description": "Koatty framework basic application example",
5
+ "private": true,
6
+ "main": "src/App.ts",
7
+ "keywords": [
8
+ "koatty",
9
+ "example",
10
+ "demo"
11
+ ],
12
+ "author": "richenlin",
13
+ "license": "BSD-3-Clause",
14
+ "devDependencies": {
15
+ "@types/node": "^24.9.1",
16
+ "ts-node": "^10.x.x",
17
+ "tsconfig-paths": "^4.x.x",
18
+ "typescript": "^5.x.x"
19
+ }
20
+ }
@@ -0,0 +1,4 @@
1
+ # This file ensures pnpm treats this as a standalone workspace
2
+ packages:
3
+ - '.'
4
+
File without changes
@@ -0,0 +1,13 @@
1
+ import { Bootstrap, Koatty } from "koatty";
2
+
3
+ @Bootstrap(() => {
4
+ console.log("Bootstrap function called");
5
+ })
6
+ export class TestApp extends Koatty {
7
+ public init() {
8
+ console.log("Init method called");
9
+ this.appDebug = true;
10
+ }
11
+ }
12
+
13
+ console.log("File loaded");
@@ -0,0 +1,25 @@
1
+ <!--
2
+ * @Description:
3
+ * @Usage:
4
+ * @Author: richen
5
+ * @Date: 2020-12-22 15:57:16
6
+ * @LastEditTime: 2022-03-15 14:23:33
7
+ -->
8
+ <!DOCTYPE html>
9
+ <html lang="en">
10
+
11
+ <head>
12
+ <meta charset="UTF-8">
13
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
14
+ <title>
15
+ <%=title%>
16
+ </title>
17
+ </head>
18
+
19
+ <body>
20
+ <H1>
21
+ <%=content%>
22
+ </H1>
23
+ </body>
24
+
25
+ </html>