tritio 0.1.1 → 0.2.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/README.md CHANGED
@@ -1,15 +1,146 @@
1
- # core
1
+ # Tritio
2
2
 
3
- To install dependencies:
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 install
24
+ bun add tritio
7
25
  ```
8
26
 
9
- To run:
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
- This project was created using `bun init` in bun v1.3.4. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
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
@@ -0,0 +1,9 @@
1
+ import { H3Event } from 'h3';
2
+ import { Context, RouteSchema } from '../types';
3
+ export type InternalContext<S extends RouteSchema, Env> = Context<S, Env> & {
4
+ _query?: Record<string, unknown>;
5
+ _params?: Record<string, unknown>;
6
+ };
7
+ export declare class ContextFactory {
8
+ static create<S extends RouteSchema, Env>(event: H3Event, rawBody: unknown): Context<S, Env>;
9
+ }
@@ -0,0 +1,2 @@
1
+ export * from './pipeline';
2
+ export * from './context';
@@ -0,0 +1,6 @@
1
+ import { EventHandlerResponse, H3Event } from 'h3';
2
+ import { HTTPMethod } from '../http';
3
+ import { Context, MiddlewareHandler, RouteSchema } from '../types';
4
+ export declare class ExecutionPipeline {
5
+ static build<S extends RouteSchema, Env>(schema: S, middlewares: MiddlewareHandler<Env>[], handler: (ctx: Context<S, Env>) => unknown, method: HTTPMethod): (event: H3Event) => Promise<EventHandlerResponse>;
6
+ }
@@ -1,9 +1,20 @@
1
- export declare const generateOpenApiSpec: (routes: any[]) => {
1
+ import { HTTPMethod } from '../http/methods';
2
+ import { RouteSchema } from '../types';
3
+ interface Route {
4
+ method: HTTPMethod;
5
+ path: string;
6
+ schema: RouteSchema;
7
+ }
8
+ interface OpenApiPaths {
9
+ [key: string]: Record<string, unknown>;
10
+ }
11
+ export declare const generateOpenApiSpec: (routes: Route[]) => {
2
12
  openapi: string;
3
13
  info: {
4
14
  title: string;
5
15
  version: string;
6
16
  description: string;
7
17
  };
8
- paths: any;
18
+ paths: OpenApiPaths;
9
19
  };
20
+ export {};
@@ -1,3 +1,4 @@
1
+ import { HTTPError as H3Error } from 'h3';
1
2
  export interface HTTPErrorOptions {
2
3
  res?: Response;
3
4
  message?: string;
@@ -65,3 +66,4 @@ export declare class ServiceUnavailableException extends HTTPError {
65
66
  export declare class GatewayTimeoutException extends HTTPError {
66
67
  constructor(options?: HTTPErrorOptions);
67
68
  }
69
+ export declare const errorHandler: (error: H3Error | HTTPError) => Response;
@@ -1,2 +1,3 @@
1
1
  export * from './methods';
2
2
  export * from './cors';
3
+ export * from './errors';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export * from './schema';
1
+ import { Tritio } from './tritio';
2
2
  export * from './types';
3
3
  export * from './tritio';
4
- export * from './error/http-error';
5
- export * from './error/handler';
4
+ export * from './validation';
5
+ export * from './core';
6
6
  export * from './docs';
7
7
  export * from './http';
8
+ export type InferApp<T> = T extends Tritio<any, infer S> ? S : never;