tachyon-rs 0.2.8 → 0.2.10

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.
Files changed (2) hide show
  1. package/README.md +108 -6
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,15 +1,117 @@
1
1
  # tachyon-rs
2
2
 
3
- To install dependencies:
3
+ HTTP server nativo em Rust com API TypeScript para Node.js e Bun. Rapido, seguro e extensivel.
4
+
5
+ ## Instalacao
4
6
 
5
7
  ```bash
6
- bun install
8
+ npm install tachyon-rs
9
+ # ou
10
+ bun add tachyon-rs
7
11
  ```
8
12
 
9
- To run:
13
+ ## Quick Start
10
14
 
11
- ```bash
12
- bun run index.ts
15
+ ```typescript
16
+ import { Tachyon, TachyonResponse } from 'tachyon-rs'
17
+
18
+ new Tachyon()
19
+ .get('/', 'Hello Tachyon!')
20
+ .get('/json', { message: 'fast' })
21
+ .get('/dynamic', (req) => {
22
+ return new TachyonResponse(200, JSON.stringify({ path: req.path }))
23
+ })
24
+ .listen(3000)
13
25
  ```
14
26
 
15
- This project was created using `bun init` in bun v1.3.10. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
27
+ ## Plugins
28
+
29
+ Hooks de ciclo de vida: `pre` (antes do handler) e `pos` (depois do handler).
30
+
31
+ ```typescript
32
+ import { Tachyon, TachyonResponse, type Plugin } from 'tachyon-rs'
33
+
34
+ const auth: Plugin = {
35
+ pre: (req) => {
36
+ if (!req.header('authorization')) {
37
+ return new TachyonResponse(401, JSON.stringify({ error: 'Unauthorized' }))
38
+ }
39
+ }
40
+ }
41
+
42
+ const cors: Plugin = {
43
+ pre: (req) => {
44
+ if (req.method === 'OPTIONS') {
45
+ return new TachyonResponse(204, '')
46
+ .header('Access-Control-Allow-Origin', '*')
47
+ .header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')
48
+ .header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
49
+ }
50
+ },
51
+ pos: (_req, res) => {
52
+ return res.header('Access-Control-Allow-Origin', '*')
53
+ }
54
+ }
55
+
56
+ const logger: Plugin = {
57
+ pos: (req, res) => {
58
+ console.log(`${req.method} ${req.path} -> ${res.status}`)
59
+ }
60
+ }
61
+
62
+ new Tachyon({ security: 'strict' })
63
+ .use(cors)
64
+ .use(auth)
65
+ .use(logger)
66
+ .get('/api/users', () => new TachyonResponse(200, '[]'))
67
+ .listen(3000)
68
+ ```
69
+
70
+ ## Configuracao
71
+
72
+ ```typescript
73
+ new Tachyon({
74
+ workers: 4, // threads (default: CPU count)
75
+ security: 'basic', // 'none' | 'basic' | 'strict'
76
+ compressionThreshold: 1024, // bytes, 0 = tudo, -1 = desabilitado
77
+ })
78
+ ```
79
+
80
+ ### Seguranca
81
+
82
+ | Preset | Headers |
83
+ |--------|---------|
84
+ | `none` | Nenhum |
85
+ | `basic` | `X-Content-Type-Options: nosniff`, `X-Frame-Options: SAMEORIGIN` |
86
+ | `strict` | Todos de basic + `X-XSS-Protection`, `Referrer-Policy`, `Permissions-Policy`, `COOP`, `CORP` |
87
+
88
+ ### Compressao
89
+
90
+ Respostas grandes sao comprimidas com gzip automaticamente quando o cliente suporta (`Accept-Encoding: gzip`).
91
+
92
+ ```typescript
93
+ new Tachyon() // default: comprime bodies >= 1KB
94
+ new Tachyon({ compressionThreshold: 0 }) // comprime tudo
95
+ new Tachyon({ compressionThreshold: 4096 })// comprime bodies >= 4KB
96
+ new Tachyon({ compressionThreshold: -1 }) // desabilita compressao
97
+ ```
98
+
99
+ ## Por que tachyon?
100
+
101
+ - **Servidor em Rust** — loop, parsing HTTP e I/O rodam em Rust com coroutines
102
+ - **Parser SIMD** — scanning HTTP com SSE4.2/AVX2/NEON, 68-90% mais rapido
103
+ - **Zero allocation** — buffer pool pre-alocado, zero alloc por request
104
+ - **Gzip nativo** — compressao transparente no Rust
105
+ - **Minimo overhead JS** — so o handler do usuario roda em JavaScript
106
+
107
+ ## Plataformas
108
+
109
+ | OS | Arquitetura |
110
+ |---|---|
111
+ | Linux | x64 |
112
+ | macOS | x64, ARM64 |
113
+ | Windows | x64 |
114
+
115
+ ## Licenca
116
+
117
+ MIT
package/package.json CHANGED
@@ -17,11 +17,11 @@
17
17
  "build": "bun build src/index.ts --outdir dist --format esm --minify --external @tachyon-rs/server && tsc"
18
18
  },
19
19
  "dependencies": {
20
- "@tachyon-rs/server": "0.2.8"
20
+ "@tachyon-rs/server": "0.2.10"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/bun": "latest",
24
24
  "typescript": "^5"
25
25
  },
26
- "version": "0.2.8"
26
+ "version": "0.2.10"
27
27
  }