@tachyon-rs/server 0.2.9 → 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 +54 -67
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,87 +1,74 @@
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
+ 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
4
 
5
- > Template project for writing node packages with napi-rs.
5
+ > **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.
6
6
 
7
- # Usage
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
7
+ ## Instalacao
15
8
 
16
9
  ```bash
17
- yarn add @napi-rs/package-template
10
+ npm install @tachyon-rs/server
18
11
  ```
19
12
 
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**.
13
+ O binario nativo correto para sua plataforma e instalado automaticamente via `optionalDependencies`.
39
14
 
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).
15
+ ### Plataformas suportadas
41
16
 
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.
17
+ | Plataforma | Arquitetura | Pacote |
18
+ |---|---|---|
19
+ | Linux | x64 | `@tachyon-rs/server-linux-x64-gnu` |
20
+ | macOS | x64 | `@tachyon-rs/server-darwin-x64` |
21
+ | macOS | ARM64 | `@tachyon-rs/server-darwin-arm64` |
22
+ | Windows | x64 | `@tachyon-rs/server-win32-x64-msvc` |
43
23
 
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.
24
+ ## Uso direto (baixo nivel)
45
25
 
46
- ## Develop requirements
26
+ ```typescript
27
+ import { TachyonRawServer } from '@tachyon-rs/server'
47
28
 
48
- - Install the latest `Rust`
49
- - Install `Node.js@10+` which fully supported `Node-API`
50
- - Install `yarn@1.x`
29
+ const server = new TachyonRawServer({
30
+ bindAddr: '0.0.0.0:3000',
31
+ workers: 4,
32
+ security: 'basic',
33
+ compressionThreshold: 1024,
34
+ })
51
35
 
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.
36
+ server.start((request) => {
37
+ return {
38
+ status: 200,
39
+ body: JSON.stringify({ hello: 'world' }),
40
+ headers: [{ name: 'Content-Type', value: 'application/json' }],
41
+ }
42
+ })
69
43
  ```
70
44
 
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:
45
+ ## Configuracao
46
+
47
+ | Opcao | Tipo | Default | Descricao |
48
+ |---|---|---|---|
49
+ | `bindAddr` | `string` | `"0.0.0.0:3000"` | Endereco e porta |
50
+ | `workers` | `number` | CPU count | Threads de worker |
51
+ | `stackSizeKb` | `number` | `64` | Stack size das coroutines (KB) |
52
+ | `buffersPerWorker` | `number` | `128` | Buffers no pool por worker |
53
+ | `bufferSize` | `number` | `8192` | Tamanho de cada buffer (bytes) |
54
+ | `timeoutSecs` | `number` | `30` | Timeout do handler (segundos) |
55
+ | `tcpNodelay` | `boolean` | `true` | TCP_NODELAY |
56
+ | `reusePort` | `boolean` | `true` | SO_REUSEPORT (Linux/BSD) |
57
+ | `tcpFastopen` | `boolean` | `true` | TCP Fast Open (Linux) |
58
+ | `busyPollUs` | `number` | `0` | SO_BUSY_POLL microseconds |
59
+ | `recvBufSize` | `number` | `0` | SO_RCVBUF (0 = OS default) |
60
+ | `sendBufSize` | `number` | `0` | SO_SNDBUF (0 = OS default) |
61
+ | `security` | `string` | `"basic"` | `"none"` \| `"basic"` \| `"strict"` |
62
+ | `compressionThreshold` | `number` | `1024` | 0 = comprime tudo, -1 = desabilitado |
63
+
64
+ ## Build local
78
65
 
79
66
  ```bash
80
- npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
81
-
82
- git push
67
+ bun install
68
+ bun run build # release
69
+ bun run build:debug # debug
83
70
  ```
84
71
 
85
- GitHub actions will do the rest job for you.
72
+ ## Licenca
86
73
 
87
- > WARN: Don't run `npm publish` manually.
74
+ 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.10",
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.10",
108
+ "@tachyon-rs/server-darwin-x64": "0.2.10",
109
+ "@tachyon-rs/server-linux-x64-gnu": "0.2.10",
110
+ "@tachyon-rs/server-darwin-arm64": "0.2.10"
111
111
  }
112
112
  }