veloce-ts 0.1.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/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/README.md +442 -0
- package/bin/veloce.ts +2 -0
- package/dist/cjs/src/cli/index.js +425 -0
- package/dist/cjs/src/cli/index.js.map +22 -0
- package/dist/cjs/src/docs/index.js +7 -0
- package/dist/cjs/src/docs/index.js.map +55 -0
- package/dist/cjs/src/errors/index.js +4 -0
- package/dist/cjs/src/errors/index.js.map +12 -0
- package/dist/cjs/src/graphql/index.js +83 -0
- package/dist/cjs/src/graphql/index.js.map +24 -0
- package/dist/cjs/src/index.js +126 -0
- package/dist/cjs/src/index.js.map +108 -0
- package/dist/cjs/src/middleware/index.js +3 -0
- package/dist/cjs/src/middleware/index.js.map +12 -0
- package/dist/cjs/src/plugins/index.js +125 -0
- package/dist/cjs/src/plugins/index.js.map +67 -0
- package/dist/cjs/src/testing/index.js +17 -0
- package/dist/cjs/src/testing/index.js.map +54 -0
- package/dist/cjs/src/types/index.js +3 -0
- package/dist/cjs/src/types/index.js.map +16 -0
- package/dist/cjs/src/validation/index.js +3 -0
- package/dist/cjs/src/validation/index.js.map +19 -0
- package/dist/cjs/src/websocket/index.js +3 -0
- package/dist/cjs/src/websocket/index.js.map +12 -0
- package/dist/esm/chunk-0zxhx5b8.js +7 -0
- package/dist/esm/chunk-0zxhx5b8.js.map +10 -0
- package/dist/esm/chunk-159eqj8q.js +5 -0
- package/dist/esm/chunk-159eqj8q.js.map +12 -0
- package/dist/esm/chunk-1hqjkm44.js +5 -0
- package/dist/esm/chunk-1hqjkm44.js.map +11 -0
- package/dist/esm/chunk-2q6s8v3j.js +6 -0
- package/dist/esm/chunk-2q6s8v3j.js.map +10 -0
- package/dist/esm/chunk-42h6trpf.js +5 -0
- package/dist/esm/chunk-42h6trpf.js.map +9 -0
- package/dist/esm/chunk-82f2j0k2.js +60 -0
- package/dist/esm/chunk-82f2j0k2.js.map +10 -0
- package/dist/esm/chunk-8wrnr45g.js +338 -0
- package/dist/esm/chunk-8wrnr45g.js.map +10 -0
- package/dist/esm/chunk-9p6d0t33.js +5 -0
- package/dist/esm/chunk-9p6d0t33.js.map +10 -0
- package/dist/esm/chunk-awven6dt.js +4 -0
- package/dist/esm/chunk-awven6dt.js.map +16 -0
- package/dist/esm/chunk-gv5n8ddb.js +18 -0
- package/dist/esm/chunk-gv5n8ddb.js.map +10 -0
- package/dist/esm/chunk-pn7z890c.js +72 -0
- package/dist/esm/chunk-pn7z890c.js.map +13 -0
- package/dist/esm/chunk-qfsjy9bg.js +7 -0
- package/dist/esm/chunk-qfsjy9bg.js.map +10 -0
- package/dist/esm/chunk-vkkzgaf7.js +5 -0
- package/dist/esm/chunk-vkkzgaf7.js.map +12 -0
- package/dist/esm/src/cli/index.js +30 -0
- package/dist/esm/src/cli/index.js.map +18 -0
- package/dist/esm/src/docs/index.js +8 -0
- package/dist/esm/src/docs/index.js.map +48 -0
- package/dist/esm/src/errors/index.js +4 -0
- package/dist/esm/src/errors/index.js.map +9 -0
- package/dist/esm/src/graphql/index.js +4 -0
- package/dist/esm/src/graphql/index.js.map +9 -0
- package/dist/esm/src/index.js +4 -0
- package/dist/esm/src/index.js.map +16 -0
- package/dist/esm/src/middleware/index.js +4 -0
- package/dist/esm/src/middleware/index.js.map +9 -0
- package/dist/esm/src/plugins/index.js +42 -0
- package/dist/esm/src/plugins/index.js.map +10 -0
- package/dist/esm/src/testing/index.js +4 -0
- package/dist/esm/src/testing/index.js.map +39 -0
- package/dist/esm/src/types/index.js +4 -0
- package/dist/esm/src/types/index.js.map +9 -0
- package/dist/esm/src/validation/index.js +4 -0
- package/dist/esm/src/validation/index.js.map +9 -0
- package/dist/esm/src/websocket/index.js +4 -0
- package/dist/esm/src/websocket/index.js.map +9 -0
- package/dist/types/adapters/base.d.ts +24 -0
- package/dist/types/adapters/base.d.ts.map +1 -0
- package/dist/types/adapters/express.d.ts +44 -0
- package/dist/types/adapters/express.d.ts.map +1 -0
- package/dist/types/adapters/hono.d.ts +44 -0
- package/dist/types/adapters/hono.d.ts.map +1 -0
- package/dist/types/cli/commands/build.d.ts +3 -0
- package/dist/types/cli/commands/build.d.ts.map +1 -0
- package/dist/types/cli/commands/dev.d.ts +3 -0
- package/dist/types/cli/commands/dev.d.ts.map +1 -0
- package/dist/types/cli/commands/generate.d.ts +3 -0
- package/dist/types/cli/commands/generate.d.ts.map +1 -0
- package/dist/types/cli/commands/new.d.ts +3 -0
- package/dist/types/cli/commands/new.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +3 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/core/application.d.ts +268 -0
- package/dist/types/core/application.d.ts.map +1 -0
- package/dist/types/core/compiled-metadata.d.ts +58 -0
- package/dist/types/core/compiled-metadata.d.ts.map +1 -0
- package/dist/types/core/metadata.d.ts +175 -0
- package/dist/types/core/metadata.d.ts.map +1 -0
- package/dist/types/core/plugin.d.ts +63 -0
- package/dist/types/core/plugin.d.ts.map +1 -0
- package/dist/types/core/router-compiler.d.ts +61 -0
- package/dist/types/core/router-compiler.d.ts.map +1 -0
- package/dist/types/decorators/dependencies.d.ts +28 -0
- package/dist/types/decorators/dependencies.d.ts.map +1 -0
- package/dist/types/decorators/docs.d.ts +38 -0
- package/dist/types/decorators/docs.d.ts.map +1 -0
- package/dist/types/decorators/graphql.d.ts +126 -0
- package/dist/types/decorators/graphql.d.ts.map +1 -0
- package/dist/types/decorators/http.d.ts +74 -0
- package/dist/types/decorators/http.d.ts.map +1 -0
- package/dist/types/decorators/middleware.d.ts +30 -0
- package/dist/types/decorators/middleware.d.ts.map +1 -0
- package/dist/types/decorators/params.d.ts +82 -0
- package/dist/types/decorators/params.d.ts.map +1 -0
- package/dist/types/decorators/websocket.d.ts +61 -0
- package/dist/types/decorators/websocket.d.ts.map +1 -0
- package/dist/types/dependencies/container.d.ts +93 -0
- package/dist/types/dependencies/container.d.ts.map +1 -0
- package/dist/types/docs/index.d.ts +3 -0
- package/dist/types/docs/index.d.ts.map +1 -0
- package/dist/types/docs/openapi-generator.d.ts +50 -0
- package/dist/types/docs/openapi-generator.d.ts.map +1 -0
- package/dist/types/docs/zod-to-json-schema.d.ts +46 -0
- package/dist/types/docs/zod-to-json-schema.d.ts.map +1 -0
- package/dist/types/errors/exceptions.d.ts +48 -0
- package/dist/types/errors/exceptions.d.ts.map +1 -0
- package/dist/types/errors/handler.d.ts +61 -0
- package/dist/types/errors/handler.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +7 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/graphql/index.d.ts +4 -0
- package/dist/types/graphql/index.d.ts.map +1 -0
- package/dist/types/graphql/plugin.d.ts +60 -0
- package/dist/types/graphql/plugin.d.ts.map +1 -0
- package/dist/types/graphql/schema-builder.d.ts +46 -0
- package/dist/types/graphql/schema-builder.d.ts.map +1 -0
- package/dist/types/graphql/zod-to-graphql.d.ts +22 -0
- package/dist/types/graphql/zod-to-graphql.d.ts.map +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/middleware/compression.d.ts +7 -0
- package/dist/types/middleware/compression.d.ts.map +1 -0
- package/dist/types/middleware/cors.d.ts +7 -0
- package/dist/types/middleware/cors.d.ts.map +1 -0
- package/dist/types/middleware/index.d.ts +4 -0
- package/dist/types/middleware/index.d.ts.map +1 -0
- package/dist/types/middleware/rate-limit.d.ts +7 -0
- package/dist/types/middleware/rate-limit.d.ts.map +1 -0
- package/dist/types/plugins/index.d.ts +4 -0
- package/dist/types/plugins/index.d.ts.map +1 -0
- package/dist/types/plugins/openapi.d.ts +23 -0
- package/dist/types/plugins/openapi.d.ts.map +1 -0
- package/dist/types/responses/response.d.ts +200 -0
- package/dist/types/responses/response.d.ts.map +1 -0
- package/dist/types/testing/helpers.d.ts +98 -0
- package/dist/types/testing/helpers.d.ts.map +1 -0
- package/dist/types/testing/index.d.ts +4 -0
- package/dist/types/testing/index.d.ts.map +1 -0
- package/dist/types/testing/test-client.d.ts +86 -0
- package/dist/types/testing/test-client.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +232 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/validation/exceptions.d.ts +25 -0
- package/dist/types/validation/exceptions.d.ts.map +1 -0
- package/dist/types/validation/index.d.ts +3 -0
- package/dist/types/validation/index.d.ts.map +1 -0
- package/dist/types/validation/validator.d.ts +54 -0
- package/dist/types/validation/validator.d.ts.map +1 -0
- package/dist/types/websocket/connection.d.ts +51 -0
- package/dist/types/websocket/connection.d.ts.map +1 -0
- package/dist/types/websocket/index.d.ts +4 -0
- package/dist/types/websocket/index.d.ts.map +1 -0
- package/dist/types/websocket/manager.d.ts +82 -0
- package/dist/types/websocket/manager.d.ts.map +1 -0
- package/dist/types/websocket/plugin.d.ts +51 -0
- package/dist/types/websocket/plugin.d.ts.map +1 -0
- package/package.json +149 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of veloce-ts framework
|
|
12
|
+
- Decorator-based routing with @Controller, @Get, @Post, @Put, @Delete, @Patch
|
|
13
|
+
- Functional API for decorator-free routing
|
|
14
|
+
- Automatic request validation with Zod schemas
|
|
15
|
+
- Dependency injection system with singleton, request, and transient scopes
|
|
16
|
+
- Automatic OpenAPI documentation generation
|
|
17
|
+
- Response handling with JSONResponse, HTMLResponse, FileResponse, StreamResponse, RedirectResponse
|
|
18
|
+
- Plugin system for extensibility
|
|
19
|
+
- WebSocket support with decorators
|
|
20
|
+
- GraphQL support with decorators
|
|
21
|
+
- CLI tool for project scaffolding and development
|
|
22
|
+
- Middleware system with CORS, rate limiting, and compression
|
|
23
|
+
- Error handling with custom exceptions
|
|
24
|
+
- Testing utilities with TestClient
|
|
25
|
+
- Multi-runtime support (Bun, Node.js, Deno, Cloudflare Workers)
|
|
26
|
+
- Adapter system for Express and Hono
|
|
27
|
+
- Type safety with full TypeScript support
|
|
28
|
+
- Performance optimizations with metadata compilation and schema caching
|
|
29
|
+
|
|
30
|
+
## [0.1.0] - 2025-10-12
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
- Initial development version
|
|
34
|
+
- Core framework architecture
|
|
35
|
+
- Basic routing and validation
|
|
36
|
+
- Documentation generation
|
|
37
|
+
- Plugin system
|
|
38
|
+
- WebSocket and GraphQL support
|
|
39
|
+
- CLI tooling
|
|
40
|
+
- Testing utilities
|
|
41
|
+
|
|
42
|
+
[Unreleased]: https://github.com/AlfredoMejia3001/veloce-ts/compare/v0.1.0...HEAD
|
|
43
|
+
[0.1.0]: https://github.com/AlfredoMejia3001/veloce-ts/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Veloce-TS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# ⚡ Veloce-TS
|
|
4
|
+
|
|
5
|
+
### Modern, Fast Web Framework for TypeScript
|
|
6
|
+
|
|
7
|
+
*Inspired by FastAPI, Built on Hono.js*
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/veloce-ts)
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
[](https://www.typescriptlang.org/)
|
|
12
|
+
[](https://bun.sh/)
|
|
13
|
+
[](https://docs-veloce.netlify.app)
|
|
14
|
+
|
|
15
|
+
[Documentation](https://docs-veloce.netlify.app) • [Examples](./examples) • [API Reference](https://docs-veloce.netlify.app/reference/api-reference)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
> **Veloce** (Italian for "fast") brings the elegance of Python's FastAPI to TypeScript with decorators, automatic validation, and blazing-fast performance.
|
|
22
|
+
|
|
23
|
+
## ✨ Features
|
|
24
|
+
|
|
25
|
+
<table>
|
|
26
|
+
<tr>
|
|
27
|
+
<td width="50%">
|
|
28
|
+
|
|
29
|
+
### 🚀 **Performance First**
|
|
30
|
+
Built on Hono.js - **10x faster** than Express
|
|
31
|
+
- Optimized routing
|
|
32
|
+
- Minimal overhead
|
|
33
|
+
- Edge-ready
|
|
34
|
+
|
|
35
|
+
### 🎯 **Type Safety**
|
|
36
|
+
Full TypeScript with inference
|
|
37
|
+
- Zod schema validation
|
|
38
|
+
- Automatic type generation
|
|
39
|
+
- Zero runtime surprises
|
|
40
|
+
|
|
41
|
+
### ✨ **Developer Experience**
|
|
42
|
+
Clean, intuitive API
|
|
43
|
+
- Decorator-based routing
|
|
44
|
+
- Auto-generated docs
|
|
45
|
+
- Hot reload support
|
|
46
|
+
|
|
47
|
+
</td>
|
|
48
|
+
<td width="50%">
|
|
49
|
+
|
|
50
|
+
### 🔌 **Dependency Injection**
|
|
51
|
+
Built-in DI container
|
|
52
|
+
- Singleton, Request, Transient scopes
|
|
53
|
+
- Constructor injection
|
|
54
|
+
- Easy testing
|
|
55
|
+
|
|
56
|
+
### 🌐 **Multi-Runtime**
|
|
57
|
+
Write once, run anywhere
|
|
58
|
+
- Bun (recommended)
|
|
59
|
+
- Node.js 18+
|
|
60
|
+
- Deno
|
|
61
|
+
- Cloudflare Workers
|
|
62
|
+
|
|
63
|
+
### 🔧 **Extensible**
|
|
64
|
+
Plugin ecosystem
|
|
65
|
+
- OpenAPI/Swagger
|
|
66
|
+
- GraphQL
|
|
67
|
+
- WebSocket
|
|
68
|
+
- Custom plugins
|
|
69
|
+
|
|
70
|
+
</td>
|
|
71
|
+
</tr>
|
|
72
|
+
</table>
|
|
73
|
+
|
|
74
|
+
## 📦 Installation
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Using Bun (recommended)
|
|
78
|
+
bun add veloce-ts zod
|
|
79
|
+
|
|
80
|
+
# Using npm
|
|
81
|
+
npm install veloce-ts zod
|
|
82
|
+
|
|
83
|
+
# Using pnpm
|
|
84
|
+
pnpm add veloce-ts zod
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**CLI Tool (optional)**
|
|
88
|
+
```bash
|
|
89
|
+
npm install -g veloce-ts
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 🚀 Quick Start
|
|
93
|
+
|
|
94
|
+
Create your first API in under 2 minutes:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { Veloce, Controller, Get, Post, Body, Param, Query } from 'veloce-ts';
|
|
98
|
+
import { z } from 'zod';
|
|
99
|
+
|
|
100
|
+
// Define validation schemas
|
|
101
|
+
const CreateUserSchema = z.object({
|
|
102
|
+
name: z.string().min(2),
|
|
103
|
+
email: z.string().email(),
|
|
104
|
+
age: z.number().min(18).optional(),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const QuerySchema = z.object({
|
|
108
|
+
page: z.string().transform(Number).default('1'),
|
|
109
|
+
limit: z.string().transform(Number).default('10'),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
@Controller('/users')
|
|
113
|
+
class UserController {
|
|
114
|
+
@Get('/')
|
|
115
|
+
async listUsers(@Query(QuerySchema) query: z.infer<typeof QuerySchema>) {
|
|
116
|
+
return {
|
|
117
|
+
users: [{ id: 1, name: 'John', email: 'john@example.com' }],
|
|
118
|
+
page: query.page,
|
|
119
|
+
limit: query.limit,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@Get('/:id')
|
|
124
|
+
async getUser(@Param('id') id: string) {
|
|
125
|
+
return { id, name: 'John', email: 'john@example.com' };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@Post('/')
|
|
129
|
+
async createUser(@Body(CreateUserSchema) user: z.infer<typeof CreateUserSchema>) {
|
|
130
|
+
return { id: 2, ...user, createdAt: new Date() };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const app = new Veloce({
|
|
135
|
+
title: 'My API',
|
|
136
|
+
version: '1.0.0',
|
|
137
|
+
description: 'A sample API built with Veloce',
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
app.include(UserController);
|
|
141
|
+
|
|
142
|
+
app.listen(3000, () => {
|
|
143
|
+
console.log('🚀 Server running on http://localhost:3000');
|
|
144
|
+
console.log('📚 Docs available at http://localhost:3000/docs');
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**That's it!** 🎉 Your API is now running with:
|
|
149
|
+
- ✅ Automatic validation
|
|
150
|
+
- ✅ Type safety
|
|
151
|
+
- ✅ OpenAPI docs at `/docs`
|
|
152
|
+
- ✅ Swagger UI ready
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 💡 More Examples
|
|
157
|
+
|
|
158
|
+
<details>
|
|
159
|
+
<summary><b>Functional API (No Decorators)</b></summary>
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { Veloce } from 'veloce-ts';
|
|
163
|
+
import { z } from 'zod';
|
|
164
|
+
|
|
165
|
+
const app = new Veloce();
|
|
166
|
+
|
|
167
|
+
const UserSchema = z.object({
|
|
168
|
+
name: z.string(),
|
|
169
|
+
email: z.string().email(),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
app.get('/users', {
|
|
173
|
+
handler: async (c) => {
|
|
174
|
+
return [{ id: 1, name: 'John' }];
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
app.post('/users', {
|
|
179
|
+
body: UserSchema,
|
|
180
|
+
handler: async (c) => {
|
|
181
|
+
const user = await c.req.json();
|
|
182
|
+
return { id: 2, ...user };
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
app.listen(3000);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
</details>
|
|
190
|
+
|
|
191
|
+
<details>
|
|
192
|
+
<summary><b>With Dependency Injection</b></summary>
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { Veloce, Controller, Get, Depends } from 'veloce-ts';
|
|
196
|
+
|
|
197
|
+
class DatabaseService {
|
|
198
|
+
async getUsers() {
|
|
199
|
+
return [{ id: 1, name: 'John' }];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Controller('/users')
|
|
204
|
+
class UserController {
|
|
205
|
+
@Get('/')
|
|
206
|
+
async getUsers(@Depends(DatabaseService) db: DatabaseService) {
|
|
207
|
+
return await db.getUsers();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const app = new Veloce();
|
|
212
|
+
app.getContainer().register(DatabaseService, { scope: 'singleton' });
|
|
213
|
+
app.include(UserController);
|
|
214
|
+
app.listen(3000);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
</details>
|
|
218
|
+
|
|
219
|
+
<details>
|
|
220
|
+
<summary><b>WebSocket Support</b></summary>
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { WebSocket, OnConnect, OnMessage, OnDisconnect } from 'veloce-ts';
|
|
224
|
+
import { z } from 'zod';
|
|
225
|
+
|
|
226
|
+
const MessageSchema = z.object({
|
|
227
|
+
type: z.string(),
|
|
228
|
+
content: z.string(),
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
@WebSocket('/chat')
|
|
232
|
+
class ChatHandler {
|
|
233
|
+
@OnConnect()
|
|
234
|
+
handleConnect(client: WebSocketConnection) {
|
|
235
|
+
client.join('lobby');
|
|
236
|
+
client.send({ type: 'welcome', message: 'Hello!' });
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@OnMessage(MessageSchema)
|
|
240
|
+
handleMessage(client: WebSocketConnection, message: z.infer<typeof MessageSchema>) {
|
|
241
|
+
client.broadcast(message, 'lobby');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@OnDisconnect()
|
|
245
|
+
handleDisconnect(client: WebSocketConnection) {
|
|
246
|
+
console.log('Client disconnected');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
</details>
|
|
252
|
+
|
|
253
|
+
<details>
|
|
254
|
+
<summary><b>GraphQL API</b></summary>
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { Resolver, Query, Mutation, Arg } from 'veloce-ts';
|
|
258
|
+
import { z } from 'zod';
|
|
259
|
+
|
|
260
|
+
const CreateUserInput = z.object({
|
|
261
|
+
name: z.string(),
|
|
262
|
+
email: z.string().email(),
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
@Resolver()
|
|
266
|
+
class UserResolver {
|
|
267
|
+
@Query()
|
|
268
|
+
async users() {
|
|
269
|
+
return [{ id: 1, name: 'John' }];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
@Mutation()
|
|
273
|
+
async createUser(@Arg('input', CreateUserInput) input: z.infer<typeof CreateUserInput>) {
|
|
274
|
+
return { id: 2, ...input };
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
</details>
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## 🛠️ CLI Commands
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# Create a new project
|
|
287
|
+
veloce-ts new my-api --template rest
|
|
288
|
+
|
|
289
|
+
# Start development server
|
|
290
|
+
veloce-ts dev
|
|
291
|
+
|
|
292
|
+
# Build for production
|
|
293
|
+
veloce-ts build
|
|
294
|
+
|
|
295
|
+
# Generate OpenAPI spec
|
|
296
|
+
veloce-ts generate openapi
|
|
297
|
+
|
|
298
|
+
# Generate TypeScript client
|
|
299
|
+
veloce-ts generate client
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**Available Templates:**
|
|
303
|
+
- `rest` - REST API with examples
|
|
304
|
+
- `graphql` - GraphQL API
|
|
305
|
+
- `websocket` - WebSocket server
|
|
306
|
+
- `fullstack` - All features combined
|
|
307
|
+
|
|
308
|
+
## 📚 Core Concepts
|
|
309
|
+
|
|
310
|
+
### Validation with Zod
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
import { z } from 'zod';
|
|
314
|
+
|
|
315
|
+
const UserSchema = z.object({
|
|
316
|
+
name: z.string().min(2),
|
|
317
|
+
email: z.string().email(),
|
|
318
|
+
age: z.number().min(18).optional(),
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
type User = z.infer<typeof UserSchema>; // Automatic type inference
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Middleware
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
// Global middleware
|
|
328
|
+
app.use(async (c, next) => {
|
|
329
|
+
console.log(`${c.req.method} ${c.req.url}`);
|
|
330
|
+
await next();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// Built-in middleware
|
|
334
|
+
app.useCors({ origin: '*' });
|
|
335
|
+
app.useRateLimit({ windowMs: 15 * 60 * 1000, max: 100 });
|
|
336
|
+
app.useCompression();
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Error Handling
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
import { HTTPException } from 'veloce-ts';
|
|
343
|
+
|
|
344
|
+
@Get('/:id')
|
|
345
|
+
async getUser(@Param('id') id: string) {
|
|
346
|
+
const user = await findUser(id);
|
|
347
|
+
if (!user) {
|
|
348
|
+
throw new HTTPException(404, 'User not found');
|
|
349
|
+
}
|
|
350
|
+
return user;
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## 🔌 Plugin System
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
import { Veloce, OpenAPIPlugin, GraphQLPlugin } from 'veloce-ts';
|
|
358
|
+
|
|
359
|
+
const app = new Veloce();
|
|
360
|
+
|
|
361
|
+
// OpenAPI documentation
|
|
362
|
+
app.usePlugin(new OpenAPIPlugin({
|
|
363
|
+
path: '/openapi.json',
|
|
364
|
+
docsPath: '/docs',
|
|
365
|
+
}));
|
|
366
|
+
|
|
367
|
+
// GraphQL support
|
|
368
|
+
app.usePlugin(new GraphQLPlugin({
|
|
369
|
+
path: '/graphql',
|
|
370
|
+
playground: true,
|
|
371
|
+
}));
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## 🌐 Multi-Runtime Support
|
|
375
|
+
|
|
376
|
+
| Runtime | Status | Notes |
|
|
377
|
+
|---------|--------|-------|
|
|
378
|
+
| **Bun** | ✅ Recommended | Best performance |
|
|
379
|
+
| **Node.js** | ✅ Supported | v18+ required |
|
|
380
|
+
| **Deno** | ✅ Supported | Use `npm:veloce` |
|
|
381
|
+
| **Cloudflare Workers** | ✅ Supported | Edge-ready |
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
// Same code works everywhere!
|
|
385
|
+
import { Veloce } from 'veloce-ts';
|
|
386
|
+
const app = new Veloce();
|
|
387
|
+
app.listen(3000);
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## 📖 Documentation
|
|
391
|
+
|
|
392
|
+
| Resource | Description |
|
|
393
|
+
|----------|-------------|
|
|
394
|
+
| [📚 Full Documentation](https://docs-veloce.netlify.app) | Complete guides and API reference |
|
|
395
|
+
| [💡 Examples](./examples) | Sample projects and code examples |
|
|
396
|
+
| [🔧 API Reference](https://docs-veloce.netlify.app/reference/api-reference) | Detailed API documentation |
|
|
397
|
+
|
|
398
|
+
## ⚙️ Requirements
|
|
399
|
+
|
|
400
|
+
- **Runtime**: Bun >= 1.0.0 (recommended) or Node.js >= 18.0.0
|
|
401
|
+
- **TypeScript**: >= 5.0.0
|
|
402
|
+
- **Zod**: >= 3.22.0
|
|
403
|
+
|
|
404
|
+
### TypeScript Configuration
|
|
405
|
+
|
|
406
|
+
```json
|
|
407
|
+
{
|
|
408
|
+
"compilerOptions": {
|
|
409
|
+
"experimentalDecorators": true,
|
|
410
|
+
"emitDecoratorMetadata": true,
|
|
411
|
+
"target": "ES2022",
|
|
412
|
+
"module": "ESNext",
|
|
413
|
+
"moduleResolution": "bundler"
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## 🤝 Contributing
|
|
419
|
+
|
|
420
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
421
|
+
|
|
422
|
+
## 📄 License
|
|
423
|
+
|
|
424
|
+
MIT © 2025 Veloce Contributors
|
|
425
|
+
|
|
426
|
+
## 🙏 Acknowledgments
|
|
427
|
+
|
|
428
|
+
Built with ❤️ using:
|
|
429
|
+
- [FastAPI](https://fastapi.tiangolo.com/) - Inspiration
|
|
430
|
+
- [Hono.js](https://hono.dev/) - Core framework
|
|
431
|
+
- [Zod](https://zod.dev/) - Validation
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
<div align="center">
|
|
436
|
+
|
|
437
|
+
**[⭐ Star us on GitHub](https://github.com/AlfredoMejia3001/veloce)** • **[📖 Read the Docs](https://docs-veloce.netlify.app)** • **[💬 Join Discussions](https://github.com/AlfredoMejia3001/veloce/discussions)**
|
|
438
|
+
|
|
439
|
+
Made with ⚡ by the Veloce team
|
|
440
|
+
|
|
441
|
+
</div>
|
|
442
|
+
|
package/bin/veloce.ts
ADDED