koatty 4.3.3 → 5.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.
@@ -1,172 +0,0 @@
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
-
@@ -1,72 +0,0 @@
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
- - ✅ 包含控制器、服务、中间件、切面等示例代码
@@ -1,23 +0,0 @@
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
- "scripts": {
15
- "dev": "node --nolazy -r ts-node/register ./src/App.ts"
16
- },
17
- "devDependencies": {
18
- "@types/node": "^25.1.0",
19
- "ts-node": "^10.x.x",
20
- "tsconfig-paths": "^4.x.x",
21
- "typescript": "^5.x.x"
22
- }
23
- }
@@ -1,4 +0,0 @@
1
- # This file ensures pnpm treats this as a standalone workspace
2
- packages:
3
- - '.'
4
-
@@ -1,2 +0,0 @@
1
- // 静态、不需要编译的数据配置
2
- // 例如:白名单、配置等
@@ -1,22 +0,0 @@
1
- type Query {
2
- getUser(id: ID!, username: String): User!
3
- }
4
-
5
- type Mutation {
6
- createUser(input: UserInput!): User!
7
- }
8
-
9
- type User {
10
- id: ID!
11
- username: String!
12
- email: String!
13
- phoneNum: String!
14
- createdAt: String!
15
- }
16
-
17
- input UserInput {
18
- id: ID!
19
- username: String!
20
- email: String!
21
- password: String!
22
- }
File without changes
@@ -1,19 +0,0 @@
1
- syntax = "proto3";
2
-
3
- service Hello {
4
- rpc SayHello(SayHelloRequest) returns (SayHelloReply) {}
5
- }
6
-
7
- message SayHelloRequest {
8
- uint64 id = 1;
9
- string name = 2;
10
- PhoneType phone = 3;
11
- }
12
-
13
- message SayHelloReply { string message = 1; }
14
-
15
- enum PhoneType {
16
- MOBILE = 0; // proto3版本中,首成员必须为0,成员不应有相同的值
17
- HOME = 1;
18
- WORK = 2;
19
- }
File without changes
@@ -1,28 +0,0 @@
1
- const path = require('path');
2
- process.env.UV_THREADPOOL_SIZE = '128';
3
- process.env.TS_NODE_TRANSPILE_ONLY = 'true';
4
- process.env.TS_NODE_PROJECT = './tsconfig.json';
5
-
6
- console.log('🔍 Starting application test...');
7
- console.log('Node version:', process.version);
8
- console.log('');
9
-
10
- require('ts-node/register');
11
-
12
- try {
13
- console.log('📦 Loading App module...');
14
- const appModule = require('./src/App.ts');
15
- console.log('✅ App module loaded:', Object.keys(appModule));
16
- console.log('');
17
- console.log('🎯 Bootstrap decorator should have executed');
18
- console.log('');
19
-
20
- // Keep process alive
21
- setTimeout(() => {
22
- console.log('⏱️ 5 seconds passed, exiting');
23
- process.exit(0);
24
- }, 5000);
25
- } catch (err) {
26
- console.error('❌ Error:', err);
27
- process.exit(1);
28
- }
@@ -1,19 +0,0 @@
1
- const path = require('path');
2
- process.env.TS_NODE_TRANSPILE_ONLY = 'true';
3
- require('ts-node/register');
4
-
5
- console.log('Testing Logger.Fatal...\n');
6
-
7
- const { Logger } = require('../../src/util/Logger');
8
-
9
- console.log('Logger methods:', Object.getOwnPropertyNames(Object.getPrototypeOf(Logger)).filter(m => m.includes('atal')));
10
- console.log('');
11
-
12
- console.log('Calling Logger.Fatal with test error...');
13
- try {
14
- Logger.Fatal(new Error('Test fatal error'));
15
- } catch (e) {
16
- console.error('Caught:', e);
17
- }
18
-
19
- console.log('This line should not execute if Fatal calls process.exit');
@@ -1,13 +0,0 @@
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");
@@ -1,25 +0,0 @@
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>
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "useDefineForClassFields": false,
5
- "types": [
6
- "jest",
7
- "node"
8
- ]
9
- },
10
- "exclude": [
11
- "node_modules"
12
- ],
13
- "include": [
14
- "test/*.test.ts"
15
- ]
16
- }