tachyon-rs 0.2.9 → 0.2.11
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 +110 -6
- package/README.pt-BR.md +119 -0
- package/dist/tachyon.d.ts +4 -4
- package/dist/tachyon.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,15 +1,119 @@
|
|
|
1
1
|
# tachyon-rs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Native Rust HTTP server with TypeScript API for Node.js and Bun. Fast, secure, and extensible.
|
|
4
|
+
|
|
5
|
+
**[Leia em Portugues](README.pt-BR.md)**
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
4
8
|
|
|
5
9
|
```bash
|
|
6
|
-
|
|
10
|
+
npm install tachyon-rs
|
|
11
|
+
# or
|
|
12
|
+
bun add tachyon-rs
|
|
7
13
|
```
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
## Quick Start
|
|
10
16
|
|
|
11
|
-
```
|
|
12
|
-
|
|
17
|
+
```typescript
|
|
18
|
+
import { Tachyon, TachyonResponse } from 'tachyon-rs'
|
|
19
|
+
|
|
20
|
+
new Tachyon()
|
|
21
|
+
.get('/', 'Hello Tachyon!')
|
|
22
|
+
.get('/json', { message: 'fast' })
|
|
23
|
+
.get('/dynamic', (req) => {
|
|
24
|
+
return new TachyonResponse(200, JSON.stringify({ path: req.path }))
|
|
25
|
+
})
|
|
26
|
+
.listen(3000)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Plugins
|
|
30
|
+
|
|
31
|
+
Lifecycle hooks: `pre` (before handler) and `pos` (after handler).
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Tachyon, TachyonResponse, type Plugin } from 'tachyon-rs'
|
|
35
|
+
|
|
36
|
+
const auth: Plugin = {
|
|
37
|
+
pre: (req) => {
|
|
38
|
+
if (!req.header('authorization')) {
|
|
39
|
+
return new TachyonResponse(401, JSON.stringify({ error: 'Unauthorized' }))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const cors: Plugin = {
|
|
45
|
+
pre: (req) => {
|
|
46
|
+
if (req.method === 'OPTIONS') {
|
|
47
|
+
return new TachyonResponse(204, '')
|
|
48
|
+
.header('Access-Control-Allow-Origin', '*')
|
|
49
|
+
.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')
|
|
50
|
+
.header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
pos: (_req, res) => {
|
|
54
|
+
return res.header('Access-Control-Allow-Origin', '*')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const logger: Plugin = {
|
|
59
|
+
pos: (req, res) => {
|
|
60
|
+
console.log(`${req.method} ${req.path} -> ${res.status}`)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
new Tachyon({ security: 'strict' })
|
|
65
|
+
.use(cors)
|
|
66
|
+
.use(auth)
|
|
67
|
+
.use(logger)
|
|
68
|
+
.get('/api/users', () => new TachyonResponse(200, '[]'))
|
|
69
|
+
.listen(3000)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuration
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
new Tachyon({
|
|
76
|
+
workers: 4, // threads (default: CPU count)
|
|
77
|
+
security: 'basic', // 'none' | 'basic' | 'strict'
|
|
78
|
+
compressionThreshold: 1024, // bytes, 0 = all, -1 = disabled
|
|
79
|
+
})
|
|
13
80
|
```
|
|
14
81
|
|
|
15
|
-
|
|
82
|
+
### Security
|
|
83
|
+
|
|
84
|
+
| Preset | Headers |
|
|
85
|
+
|--------|---------|
|
|
86
|
+
| `none` | None |
|
|
87
|
+
| `basic` | `X-Content-Type-Options: nosniff`, `X-Frame-Options: SAMEORIGIN` |
|
|
88
|
+
| `strict` | All from basic + `X-XSS-Protection`, `Referrer-Policy`, `Permissions-Policy`, `COOP`, `CORP` |
|
|
89
|
+
|
|
90
|
+
### Compression
|
|
91
|
+
|
|
92
|
+
Large responses are automatically gzip-compressed when the client supports it (`Accept-Encoding: gzip`).
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
new Tachyon() // default: compress bodies >= 1KB
|
|
96
|
+
new Tachyon({ compressionThreshold: 0 }) // compress everything
|
|
97
|
+
new Tachyon({ compressionThreshold: 4096 })// compress bodies >= 4KB
|
|
98
|
+
new Tachyon({ compressionThreshold: -1 }) // disable compression
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Why tachyon?
|
|
102
|
+
|
|
103
|
+
- **Rust server** — server loop, HTTP parsing, and I/O run in Rust with coroutines
|
|
104
|
+
- **SIMD parser** — HTTP scanning with SSE4.2/AVX2/NEON, 68-90% faster
|
|
105
|
+
- **Zero allocation** — pre-allocated buffer pool, zero alloc per request
|
|
106
|
+
- **Native gzip** — transparent compression in Rust
|
|
107
|
+
- **Minimal JS overhead** — only the user's handler runs in JavaScript
|
|
108
|
+
|
|
109
|
+
## Platforms
|
|
110
|
+
|
|
111
|
+
| OS | Architecture |
|
|
112
|
+
|---|---|
|
|
113
|
+
| Linux | x64 |
|
|
114
|
+
| macOS | x64, ARM64 |
|
|
115
|
+
| Windows | x64 |
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
package/README.pt-BR.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# tachyon-rs
|
|
2
|
+
|
|
3
|
+
HTTP server nativo em Rust com API TypeScript para Node.js e Bun. Rapido, seguro e extensivel.
|
|
4
|
+
|
|
5
|
+
**[Read in English](README.md)**
|
|
6
|
+
|
|
7
|
+
## Instalacao
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install tachyon-rs
|
|
11
|
+
# ou
|
|
12
|
+
bun add tachyon-rs
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Tachyon, TachyonResponse } from 'tachyon-rs'
|
|
19
|
+
|
|
20
|
+
new Tachyon()
|
|
21
|
+
.get('/', 'Hello Tachyon!')
|
|
22
|
+
.get('/json', { message: 'fast' })
|
|
23
|
+
.get('/dynamic', (req) => {
|
|
24
|
+
return new TachyonResponse(200, JSON.stringify({ path: req.path }))
|
|
25
|
+
})
|
|
26
|
+
.listen(3000)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Plugins
|
|
30
|
+
|
|
31
|
+
Hooks de ciclo de vida: `pre` (antes do handler) e `pos` (depois do handler).
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Tachyon, TachyonResponse, type Plugin } from 'tachyon-rs'
|
|
35
|
+
|
|
36
|
+
const auth: Plugin = {
|
|
37
|
+
pre: (req) => {
|
|
38
|
+
if (!req.header('authorization')) {
|
|
39
|
+
return new TachyonResponse(401, JSON.stringify({ error: 'Unauthorized' }))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const cors: Plugin = {
|
|
45
|
+
pre: (req) => {
|
|
46
|
+
if (req.method === 'OPTIONS') {
|
|
47
|
+
return new TachyonResponse(204, '')
|
|
48
|
+
.header('Access-Control-Allow-Origin', '*')
|
|
49
|
+
.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')
|
|
50
|
+
.header('Access-Control-Allow-Headers', 'Content-Type, Authorization')
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
pos: (_req, res) => {
|
|
54
|
+
return res.header('Access-Control-Allow-Origin', '*')
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const logger: Plugin = {
|
|
59
|
+
pos: (req, res) => {
|
|
60
|
+
console.log(`${req.method} ${req.path} -> ${res.status}`)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
new Tachyon({ security: 'strict' })
|
|
65
|
+
.use(cors)
|
|
66
|
+
.use(auth)
|
|
67
|
+
.use(logger)
|
|
68
|
+
.get('/api/users', () => new TachyonResponse(200, '[]'))
|
|
69
|
+
.listen(3000)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Configuracao
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
new Tachyon({
|
|
76
|
+
workers: 4, // threads (default: CPU count)
|
|
77
|
+
security: 'basic', // 'none' | 'basic' | 'strict'
|
|
78
|
+
compressionThreshold: 1024, // bytes, 0 = tudo, -1 = desabilitado
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Seguranca
|
|
83
|
+
|
|
84
|
+
| Preset | Headers |
|
|
85
|
+
|--------|---------|
|
|
86
|
+
| `none` | Nenhum |
|
|
87
|
+
| `basic` | `X-Content-Type-Options: nosniff`, `X-Frame-Options: SAMEORIGIN` |
|
|
88
|
+
| `strict` | Todos de basic + `X-XSS-Protection`, `Referrer-Policy`, `Permissions-Policy`, `COOP`, `CORP` |
|
|
89
|
+
|
|
90
|
+
### Compressao
|
|
91
|
+
|
|
92
|
+
Respostas grandes sao comprimidas com gzip automaticamente quando o cliente suporta (`Accept-Encoding: gzip`).
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
new Tachyon() // default: comprime bodies >= 1KB
|
|
96
|
+
new Tachyon({ compressionThreshold: 0 }) // comprime tudo
|
|
97
|
+
new Tachyon({ compressionThreshold: 4096 })// comprime bodies >= 4KB
|
|
98
|
+
new Tachyon({ compressionThreshold: -1 }) // desabilita compressao
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Por que tachyon?
|
|
102
|
+
|
|
103
|
+
- **Servidor em Rust** — loop, parsing HTTP e I/O rodam em Rust com coroutines
|
|
104
|
+
- **Parser SIMD** — scanning HTTP com SSE4.2/AVX2/NEON, 68-90% mais rapido
|
|
105
|
+
- **Zero allocation** — buffer pool pre-alocado, zero alloc por request
|
|
106
|
+
- **Gzip nativo** — compressao transparente no Rust
|
|
107
|
+
- **Minimo overhead JS** — so o handler do usuario roda em JavaScript
|
|
108
|
+
|
|
109
|
+
## Plataformas
|
|
110
|
+
|
|
111
|
+
| OS | Arquitetura |
|
|
112
|
+
|---|---|
|
|
113
|
+
| Linux | x64 |
|
|
114
|
+
| macOS | x64, ARM64 |
|
|
115
|
+
| Windows | x64 |
|
|
116
|
+
|
|
117
|
+
## Licenca
|
|
118
|
+
|
|
119
|
+
MIT
|
package/dist/tachyon.d.ts
CHANGED
|
@@ -30,10 +30,10 @@ declare class Tachyon {
|
|
|
30
30
|
constructor(config?: TachyonConfig);
|
|
31
31
|
use(plugin: Plugin): this;
|
|
32
32
|
private transformToResponse;
|
|
33
|
-
get(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string,
|
|
34
|
-
post(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string,
|
|
35
|
-
put(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string,
|
|
36
|
-
delete(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string,
|
|
33
|
+
get(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, unknown>): this;
|
|
34
|
+
post(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, unknown>): this;
|
|
35
|
+
put(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, unknown>): this;
|
|
36
|
+
delete(path: string, response: ((req: TachyonRequest) => TachyonResponse) | string | Record<string, unknown>): this;
|
|
37
37
|
listen(port: number): void;
|
|
38
38
|
}
|
|
39
39
|
export { Tachyon };
|
package/dist/tachyon.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tachyon.d.ts","sourceRoot":"","sources":["../src/tachyon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,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,eAAe,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAK5G,MAAM,CAAC,IAAI,EAAE,MAAM;CAiC3B;AAED,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
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.
|
|
20
|
+
"@tachyon-rs/server": "0.2.11"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/bun": "latest",
|
|
24
24
|
"typescript": "^5"
|
|
25
25
|
},
|
|
26
|
-
"version": "0.2.
|
|
26
|
+
"version": "0.2.11"
|
|
27
27
|
}
|