@tachyon-rs/server 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 CHANGED
@@ -1,87 +1,76 @@
1
- # `@napi-rs/package-template`
1
+ # @tachyon-rs/server
2
2
 
3
- ![https://github.com/napi-rs/package-template/actions](https://github.com/napi-rs/package-template/workflows/CI/badge.svg)
3
+ Native NAPI bindings from tachyon-rs for Node.js and Bun. This package is the bridge between the Rust HTTP server and the JavaScript runtime.
4
4
 
5
- > Template project for writing node packages with napi-rs.
5
+ **[Leia em Portugues](README.pt-BR.md)**
6
6
 
7
- # Usage
7
+ > **Note:** This package is used internally by [`tachyon-rs`](https://www.npmjs.com/package/tachyon-rs). For most use cases, use `tachyon-rs` directly.
8
8
 
9
- 1. Click **Use this template**.
10
- 2. **Clone** your project.
11
- 3. Run `yarn install` to install dependencies.
12
- 4. Run `yarn napi rename -n [@your-scope/package-name] -b [binary-name]` command under the project folder to rename your package.
13
-
14
- ## Install this test package
9
+ ## Installation
15
10
 
16
11
  ```bash
17
- yarn add @napi-rs/package-template
12
+ npm install @tachyon-rs/server
18
13
  ```
19
14
 
20
- ## Ability
21
-
22
- ### Build
23
-
24
- After `yarn build/npm run build` command, you can see `package-template.[darwin|win32|linux].node` file in project root. This is the native addon built from [lib.rs](./src/lib.rs).
25
-
26
- ### Test
27
-
28
- With [ava](https://github.com/avajs/ava), run `yarn test/npm run test` to testing native addon. You can also switch to another testing framework if you want.
29
-
30
- ### CI
31
-
32
- With GitHub Actions, each commit and pull request will be built and tested automatically in [`node@20`, `@node22`] x [`macOS`, `Linux`, `Windows`] matrix. You will never be afraid of the native addon broken in these platforms.
33
-
34
- ### Release
35
-
36
- Release native package is very difficult in old days. Native packages may ask developers who use it to install `build toolchain` like `gcc/llvm`, `node-gyp` or something more.
37
-
38
- With `GitHub actions`, we can easily prebuild a `binary` for major platforms. And with `N-API`, we should never be afraid of **ABI Compatible**.
15
+ The correct native binary for your platform is installed automatically via `optionalDependencies`.
39
16
 
40
- The other problem is how to deliver prebuild `binary` to users. Downloading it in `postinstall` script is a common way that most packages do it right now. The problem with this solution is it introduced many other packages to download binary that has not been used by `runtime codes`. The other problem is some users may not easily download the binary from `GitHub/CDN` if they are behind a private network (But in most cases, they have a private NPM mirror).
17
+ ### Supported platforms
41
18
 
42
- In this package, we choose a better way to solve this problem. We release different `npm packages` for different platforms. And add it to `optionalDependencies` before releasing the `Major` package to npm.
19
+ | Platform | Architecture | Package |
20
+ |---|---|---|
21
+ | Linux | x64 | `@tachyon-rs/server-linux-x64-gnu` |
22
+ | macOS | x64 | `@tachyon-rs/server-darwin-x64` |
23
+ | macOS | ARM64 | `@tachyon-rs/server-darwin-arm64` |
24
+ | Windows | x64 | `@tachyon-rs/server-win32-x64-msvc` |
43
25
 
44
- `NPM` will choose which native package should download from `registry` automatically. You can see [npm](./npm) dir for details. And you can also run `yarn add @napi-rs/package-template` to see how it works.
26
+ ## Direct usage (low-level)
45
27
 
46
- ## Develop requirements
28
+ ```typescript
29
+ import { TachyonRawServer } from '@tachyon-rs/server'
47
30
 
48
- - Install the latest `Rust`
49
- - Install `Node.js@10+` which fully supported `Node-API`
50
- - Install `yarn@1.x`
31
+ const server = new TachyonRawServer({
32
+ bindAddr: '0.0.0.0:3000',
33
+ workers: 4,
34
+ security: 'basic',
35
+ compressionThreshold: 1024,
36
+ })
51
37
 
52
- ## Test in local
53
-
54
- - yarn
55
- - yarn build
56
- - yarn test
57
-
58
- And you will see:
59
-
60
- ```bash
61
- $ ava --verbose
62
-
63
- ✔ sync function from native code
64
- ✔ sleep function from native code (201ms)
65
-
66
-
67
- 2 tests passed
68
- ✨ Done in 1.12s.
38
+ server.start((request) => {
39
+ return {
40
+ status: 200,
41
+ body: JSON.stringify({ hello: 'world' }),
42
+ headers: [{ name: 'Content-Type', value: 'application/json' }],
43
+ }
44
+ })
69
45
  ```
70
46
 
71
- ## Release package
72
-
73
- Ensure you have set your **NPM_TOKEN** in the `GitHub` project setting.
74
-
75
- In `Settings -> Secrets`, add **NPM_TOKEN** into it.
76
-
77
- When you want to release the package:
47
+ ## Configuration
48
+
49
+ | Option | Type | Default | Description |
50
+ |---|---|---|---|
51
+ | `bindAddr` | `string` | `"0.0.0.0:3000"` | Address and port |
52
+ | `workers` | `number` | CPU count | Worker threads |
53
+ | `stackSizeKb` | `number` | `64` | Coroutine stack size (KB) |
54
+ | `buffersPerWorker` | `number` | `128` | Buffers in pool per worker |
55
+ | `bufferSize` | `number` | `8192` | Size of each buffer (bytes) |
56
+ | `timeoutSecs` | `number` | `30` | Handler timeout (seconds) |
57
+ | `tcpNodelay` | `boolean` | `true` | TCP_NODELAY |
58
+ | `reusePort` | `boolean` | `true` | SO_REUSEPORT (Linux/BSD) |
59
+ | `tcpFastopen` | `boolean` | `true` | TCP Fast Open (Linux) |
60
+ | `busyPollUs` | `number` | `0` | SO_BUSY_POLL microseconds |
61
+ | `recvBufSize` | `number` | `0` | SO_RCVBUF (0 = OS default) |
62
+ | `sendBufSize` | `number` | `0` | SO_SNDBUF (0 = OS default) |
63
+ | `security` | `string` | `"basic"` | `"none"` \| `"basic"` \| `"strict"` |
64
+ | `compressionThreshold` | `number` | `1024` | 0 = compress all, -1 = disabled |
65
+
66
+ ## Local build
78
67
 
79
68
  ```bash
80
- npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
81
-
82
- git push
69
+ bun install
70
+ bun run build # release
71
+ bun run build:debug # debug
83
72
  ```
84
73
 
85
- GitHub actions will do the rest job for you.
74
+ ## License
86
75
 
87
- > WARN: Don't run `npm publish` manually.
76
+ MIT
@@ -0,0 +1,76 @@
1
+ # @tachyon-rs/server
2
+
3
+ Bindings NAPI nativos do tachyon-rs para Node.js e Bun. Este pacote e a ponte entre o servidor HTTP em Rust e o runtime JavaScript.
4
+
5
+ **[Read in English](README.md)**
6
+
7
+ > **Nota:** Este pacote e usado internamente pelo [`tachyon-rs`](https://www.npmjs.com/package/tachyon-rs). Para a maioria dos casos, use `tachyon-rs` diretamente.
8
+
9
+ ## Instalacao
10
+
11
+ ```bash
12
+ npm install @tachyon-rs/server
13
+ ```
14
+
15
+ O binario nativo correto para sua plataforma e instalado automaticamente via `optionalDependencies`.
16
+
17
+ ### Plataformas suportadas
18
+
19
+ | Plataforma | Arquitetura | Pacote |
20
+ |---|---|---|
21
+ | Linux | x64 | `@tachyon-rs/server-linux-x64-gnu` |
22
+ | macOS | x64 | `@tachyon-rs/server-darwin-x64` |
23
+ | macOS | ARM64 | `@tachyon-rs/server-darwin-arm64` |
24
+ | Windows | x64 | `@tachyon-rs/server-win32-x64-msvc` |
25
+
26
+ ## Uso direto (baixo nivel)
27
+
28
+ ```typescript
29
+ import { TachyonRawServer } from '@tachyon-rs/server'
30
+
31
+ const server = new TachyonRawServer({
32
+ bindAddr: '0.0.0.0:3000',
33
+ workers: 4,
34
+ security: 'basic',
35
+ compressionThreshold: 1024,
36
+ })
37
+
38
+ server.start((request) => {
39
+ return {
40
+ status: 200,
41
+ body: JSON.stringify({ hello: 'world' }),
42
+ headers: [{ name: 'Content-Type', value: 'application/json' }],
43
+ }
44
+ })
45
+ ```
46
+
47
+ ## Configuracao
48
+
49
+ | Opcao | Tipo | Default | Descricao |
50
+ |---|---|---|---|
51
+ | `bindAddr` | `string` | `"0.0.0.0:3000"` | Endereco e porta |
52
+ | `workers` | `number` | CPU count | Threads de worker |
53
+ | `stackSizeKb` | `number` | `64` | Stack size das coroutines (KB) |
54
+ | `buffersPerWorker` | `number` | `128` | Buffers no pool por worker |
55
+ | `bufferSize` | `number` | `8192` | Tamanho de cada buffer (bytes) |
56
+ | `timeoutSecs` | `number` | `30` | Timeout do handler (segundos) |
57
+ | `tcpNodelay` | `boolean` | `true` | TCP_NODELAY |
58
+ | `reusePort` | `boolean` | `true` | SO_REUSEPORT (Linux/BSD) |
59
+ | `tcpFastopen` | `boolean` | `true` | TCP Fast Open (Linux) |
60
+ | `busyPollUs` | `number` | `0` | SO_BUSY_POLL microseconds |
61
+ | `recvBufSize` | `number` | `0` | SO_RCVBUF (0 = OS default) |
62
+ | `sendBufSize` | `number` | `0` | SO_SNDBUF (0 = OS default) |
63
+ | `security` | `string` | `"basic"` | `"none"` \| `"basic"` \| `"strict"` |
64
+ | `compressionThreshold` | `number` | `1024` | 0 = comprime tudo, -1 = desabilitado |
65
+
66
+ ## Build local
67
+
68
+ ```bash
69
+ bun install
70
+ bun run build # release
71
+ bun run build:debug # debug
72
+ ```
73
+
74
+ ## Licenca
75
+
76
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachyon-rs/server",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "Template project for writing node package with napi-rs",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -48,7 +48,7 @@
48
48
  "format:toml": "taplo format",
49
49
  "format:rs": "cargo fmt",
50
50
  "lint": "oxlint .",
51
- "prepublish:napi": "napi prepublish -t npm",
51
+ "prepublishOnly": "napi prepublish -t npm",
52
52
  "test": "ava",
53
53
  "preversion": "napi build --platform && git add .",
54
54
  "version": "napi version",
@@ -104,9 +104,9 @@
104
104
  },
105
105
  "packageManager": "bun@1.2.5",
106
106
  "optionalDependencies": {
107
- "@tachyon-rs/server-win32-x64-msvc": "0.2.9",
108
- "@tachyon-rs/server-darwin-x64": "0.2.9",
109
- "@tachyon-rs/server-linux-x64-gnu": "0.2.9",
110
- "@tachyon-rs/server-darwin-arm64": "0.2.9"
107
+ "@tachyon-rs/server-win32-x64-msvc": "0.2.11",
108
+ "@tachyon-rs/server-darwin-x64": "0.2.11",
109
+ "@tachyon-rs/server-linux-x64-gnu": "0.2.11",
110
+ "@tachyon-rs/server-darwin-arm64": "0.2.11"
111
111
  }
112
112
  }