tritio 0.1.1 → 0.1.2
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/README.md +137 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tritio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**The fast, opinionated H3 framework.**
|
|
4
|
+
|
|
5
|
+
Tritio is a modern backend framework built on top of [H3](https://github.com/unjs/h3) (the HTTP engine behind Nuxt and Nitro). It is designed to run natively on **Bun**, but is fully compatible with any environment that supports Web Standards (Node.js, Cloudflare Workers, etc.).
|
|
6
|
+
|
|
7
|
+
Its core philosophy is **Extreme End-to-End Type Safety** and **Performance**, combining the raw speed of H3 with a superior Developer Experience (DX) inspired by tools like ElysiaJS and Fastify, but architected for robust, enterprise-grade applications.
|
|
8
|
+
|
|
9
|
+
## Core Features
|
|
10
|
+
|
|
11
|
+
- **Built on H3 (Web Standards)**: Leverages the performance and compatibility of the H3 engine.
|
|
12
|
+
- **TypeBox First-Class Integration**: Native input validation and automatic type inference for Body, Query, and Params. No more manual interface duplication.
|
|
13
|
+
- **Modular & Scalable**: Native support for nested applications via `.mount()`. Perfect for monorepos and Vertical Slicing architectures.
|
|
14
|
+
- **Auto-Documentation**: Automatic OpenAPI 3.1 generation and integrated [Scalar](https://scalar.com/) UI for testing your API.
|
|
15
|
+
- **Developer Experience**: Fluent, chainable API request handling (`app.get(...).post(...)`), centralized error handling, and robust CORS support.
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### Installation
|
|
20
|
+
|
|
21
|
+
Tritio works best with Bun, but you can use your preferred package manager.
|
|
4
22
|
|
|
5
23
|
```bash
|
|
6
|
-
bun
|
|
24
|
+
bun add tritio
|
|
7
25
|
```
|
|
8
26
|
|
|
9
|
-
|
|
27
|
+
### Hello World
|
|
28
|
+
|
|
29
|
+
Create a simple server in `src/index.ts`:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Tritio, t } from "tritio";
|
|
33
|
+
|
|
34
|
+
const app = new Tritio();
|
|
35
|
+
|
|
36
|
+
app.get(
|
|
37
|
+
"/",
|
|
38
|
+
{
|
|
39
|
+
response: t.String(),
|
|
40
|
+
},
|
|
41
|
+
() => "Hello from Tritio"
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
app.listen(3000);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run it with:
|
|
10
48
|
|
|
11
49
|
```bash
|
|
12
|
-
bun run index.ts
|
|
50
|
+
bun run src/index.ts
|
|
13
51
|
```
|
|
14
52
|
|
|
15
|
-
|
|
53
|
+
## Features in Detail
|
|
54
|
+
|
|
55
|
+
### End-to-End Type Safety
|
|
56
|
+
|
|
57
|
+
Tritio infers TypeScript types directly from your validation schemas. You define the schema, and `ctx.body`, `ctx.query`, and your return types are strongly typed.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { Tritio, t } from "tritio";
|
|
61
|
+
|
|
62
|
+
const app = new Tritio();
|
|
63
|
+
|
|
64
|
+
app.post(
|
|
65
|
+
"/users",
|
|
66
|
+
{
|
|
67
|
+
body: t.Object({
|
|
68
|
+
name: t.String(),
|
|
69
|
+
age: t.Number(),
|
|
70
|
+
}),
|
|
71
|
+
response: t.Object({
|
|
72
|
+
id: t.Number(),
|
|
73
|
+
message: t.String(),
|
|
74
|
+
}),
|
|
75
|
+
},
|
|
76
|
+
(ctx) => {
|
|
77
|
+
// ctx.body is strictly typed: { name: string; age: number }
|
|
78
|
+
const { name, age } = ctx.body;
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
id: 1,
|
|
82
|
+
message: `User ${name} created successfully`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Modular Architecture (Grouping & Mounting)
|
|
89
|
+
|
|
90
|
+
Tritio shines in complex applications. You can group routes or mount entirely separate application instances.
|
|
91
|
+
|
|
92
|
+
#### Grouping Routes
|
|
93
|
+
|
|
94
|
+
Organize related routes under a common prefix.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
app.group("/api/v1", (api) => {
|
|
98
|
+
api.get("/status", {}, () => ({ status: "ok" }));
|
|
99
|
+
|
|
100
|
+
api.group("/users", (users) => {
|
|
101
|
+
users.get("/", {}, () => ["Alice", "Bob"]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Mounting Sub-Apps
|
|
107
|
+
|
|
108
|
+
For larger systems, separate your domains into independent Tritio instances and assemble them.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// auth.module.ts
|
|
112
|
+
const authApp = new Tritio();
|
|
113
|
+
authApp.post("/login", {}, () => "Login logic");
|
|
114
|
+
|
|
115
|
+
// billing.module.ts
|
|
116
|
+
const billingApp = new Tritio();
|
|
117
|
+
billingApp.get("/invoices", {}, () => ["Inv-001", "Inv-002"]);
|
|
118
|
+
|
|
119
|
+
// main.ts
|
|
120
|
+
const app = new Tritio();
|
|
121
|
+
app.mount("/auth", authApp); // Accessible at /auth/login
|
|
122
|
+
app.mount("/billing", billingApp); // Accessible at /billing/invoices
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Auto-Documentation
|
|
126
|
+
|
|
127
|
+
Tritio automatically generates an OpenAPI 3.1 specification from your routes and schemas. It includes **Scalar**, a modern and beautiful API reference UI.
|
|
128
|
+
|
|
129
|
+
Simply call `app.docs()` to enable it.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const app = new Tritio();
|
|
133
|
+
|
|
134
|
+
// ... define your routes ...
|
|
135
|
+
|
|
136
|
+
// Enable documentation at /docs
|
|
137
|
+
app.docs();
|
|
138
|
+
|
|
139
|
+
app.listen(3000);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Visit `http://localhost:3000/docs` to explore and test your API.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|