@agntcy/slim-bindings-node 0.1.4

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 ADDED
@@ -0,0 +1,104 @@
1
+ # SLIM Node.js Bindings
2
+
3
+ Node.js bindings for SLIM using UniFFI.
4
+ Bindings generated with [uniffi-bindgen-node](https://github.com/livekit/uniffi-bindgen-node).
5
+
6
+ ## Installation
7
+
8
+ For released versions, install from npm (no Rust or build required):
9
+
10
+ ```bash
11
+ npm install @agntcy/slim-bindings-node
12
+ ```
13
+
14
+ This installs the main package and the matching platform-specific native addon for your OS/arch.
15
+
16
+ To build from source (e.g. for development or unsupported platforms), see [Build from source](#build-from-source) below.
17
+
18
+ ## Prerequisites (build from source)
19
+
20
+ - Rust toolchain
21
+ - Node.js >= 18
22
+ - [Task](https://taskfile.dev/)
23
+
24
+ ## Usage
25
+
26
+ ### 1. Generate Bindings (build from source)
27
+
28
+ ```bash
29
+ task generate
30
+ ```
31
+
32
+ ### 2. Run P2P Examples
33
+
34
+ ```bash
35
+ # Terminal 1: Start the server
36
+ task example:server
37
+
38
+ # Terminal 2: Start Alice (receiver)
39
+ task example:alice
40
+
41
+ # Terminal 3: Start Bob (sender)
42
+ task example:bob
43
+ ```
44
+
45
+ ### Available Commands
46
+
47
+ ```bash
48
+ task generate # Generate bindings
49
+ task clean # Clean build artifacts
50
+ task example:server # Run server
51
+ task example:alice # Run Alice receiver
52
+ task example:bob # Run Bob sender
53
+ ```
54
+
55
+ ## Build Process
56
+
57
+ The bindings generation includes patching to fix compatibility issues between `uniffi-bindgen-node` (code generator) and `uniffi-bindgen-react-native` (runtime library):
58
+
59
+ - **Naming fixes**: `FfiConverterBytes` → `FfiConverterArrayBuffer`
60
+ - **Buffer wrapping**: Proper RustBuffer allocation for byte arrays
61
+ - **Pointer conversions**: BigInt → Number for FFI calls
62
+ - **Error handling**: Enhanced error extraction from Rust
63
+
64
+ ## FFI Type Conversions
65
+
66
+ The generated bindings use `bigint` in TypeScript signatures for u64 types, but the underlying FFI layer returns JavaScript `number` types at runtime. Application code handles conversions at API boundaries:
67
+
68
+ ```typescript
69
+ // connectAsync returns a number at runtime, despite bigint type signature
70
+ const connId = await service.connectAsync(config);
71
+
72
+ // Convert to BigInt when passing to methods expecting bigint
73
+ await app.subscribeAsync(name, BigInt(connId));
74
+
75
+ // When using with methods that need number (for direct FFI calls)
76
+ app.setRoute(name, Number(connId));
77
+ ```
78
+
79
+ **Key conversions:**
80
+ - `connectAsync` returns `number` → convert to `BigInt()` for TypeScript bigint parameters
81
+ - When calling FFI methods with u64 params → convert to `Number()` if passing bigint
82
+
83
+ This explicit conversion at API boundaries ensures type safety and makes FFI requirements visible.
84
+
85
+ ## Build from source
86
+
87
+ If you need to build from source (development or a platform not yet published):
88
+
89
+ 1. Ensure Rust and Task are installed.
90
+ 2. Run `task generate` (builds the Rust lib and generates Node bindings).
91
+ 3. Use the bindings from `generated/` or run the examples with `task example:server`, etc.
92
+
93
+ ## Publishing (maintainers)
94
+
95
+ - **Dry run**: From `data-plane/bindings/node`, run `npm pack` to produce a tarball and inspect contents (main package: no `generated/`; platform packages: `task pack:platform TARGET=<target>` then check `dist/node-<platform>.tgz`).
96
+ - **Version**: Set in package.json; CI derives version from tag `slim-bindings-v*` via `.github/scripts/get-binding-version.sh`.
97
+ - **Secrets**: `NPM_TOKEN` must be set in the repo for `npm publish`.
98
+
99
+ ## Resources
100
+
101
+ - [uniffi-bindgen-node](https://github.com/livekit/uniffi-bindgen-node)
102
+ - [UniFFI Documentation](https://mozilla.github.io/uniffi-rs/)
103
+ - [ffi-rs](https://www.npmjs.com/package/ffi-rs)
104
+ - [SLIM Core](https://github.com/agntcy/slim)
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ // Copyright AGNTCY Contributors (https://github.com/agntcy)
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Type definitions for @agntcy/slim-bindings-node.
6
+ * Full types are in types/ (generated from bindings before publish).
7
+ */
8
+ export * from './types/slim-bindings-node';
package/index.js ADDED
@@ -0,0 +1,40 @@
1
+ // Copyright AGNTCY Contributors (https://github.com/agntcy)
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ 'use strict';
5
+
6
+ /**
7
+ * Resolves the platform id for the current Node process.
8
+ * Must match the optionalDependency package suffixes.
9
+ */
10
+ function getCurrentPlatformId() {
11
+ const platform = process.platform;
12
+ const arch = process.arch;
13
+ if (platform === 'darwin') {
14
+ return arch === 'arm64' ? 'darwin-arm64' : 'darwin-x64';
15
+ }
16
+ if (platform === 'linux') {
17
+ return arch === 'arm64' ? 'linux-arm64-gnu' : 'linux-x64-gnu';
18
+ }
19
+ if (platform === 'win32') {
20
+ return arch === 'arm64' ? 'win32-arm64-msvc' : 'win32-x64-msvc';
21
+ }
22
+ throw new Error(`Unsupported platform: ${platform} ${arch}`);
23
+ }
24
+
25
+ const platformId = getCurrentPlatformId();
26
+ const packageName = `@agntcy/slim-bindings-node-${platformId}`;
27
+
28
+ let bindings;
29
+ try {
30
+ bindings = require(packageName);
31
+ } catch (err) {
32
+ if (err.code === 'MODULE_NOT_FOUND') {
33
+ throw new Error(
34
+ `Platform package ${packageName} is not installed. Install with: npm install @agntcy/slim-bindings-node (includes optional dependencies for your platform).`
35
+ );
36
+ }
37
+ throw err;
38
+ }
39
+
40
+ module.exports = bindings;
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@agntcy/slim-bindings-node",
3
+ "version": "0.1.4",
4
+ "description": "SLIM Node.js bindings using UniFFI",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "index.js",
9
+ "index.d.ts",
10
+ "types/",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "build": "task generate",
15
+ "clean": "task clean",
16
+ "test": "task test:integration",
17
+ "example:server": "task example:server",
18
+ "example:alice": "task example:alice"
19
+ },
20
+ "keywords": [
21
+ "slim",
22
+ "messaging",
23
+ "uniffi",
24
+ "nodejs",
25
+ "ffi"
26
+ ],
27
+ "engines": {
28
+ "node": ">=18.0.0"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/agntcy/slim.git",
33
+ "directory": "data-plane/bindings/node"
34
+ },
35
+ "license": "Apache-2.0",
36
+ "optionalDependencies": {
37
+ "@agntcy/slim-bindings-node-darwin-arm64": "0.1.4",
38
+ "@agntcy/slim-bindings-node-darwin-x64": "0.1.4",
39
+ "@agntcy/slim-bindings-node-linux-arm64-gnu": "0.1.4",
40
+ "@agntcy/slim-bindings-node-linux-arm64-musl": "0.1.4",
41
+ "@agntcy/slim-bindings-node-linux-x64-gnu": "0.1.4",
42
+ "@agntcy/slim-bindings-node-linux-x64-musl": "0.1.4",
43
+ "@agntcy/slim-bindings-node-win32-arm64-msvc": "0.1.4",
44
+ "@agntcy/slim-bindings-node-win32-x64-gnu": "0.1.4",
45
+ "@agntcy/slim-bindings-node-win32-x64-msvc": "0.1.4"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^20.0.0",
49
+ "ffi-rs": "^1.3.0",
50
+ "typescript": "^5.0.0",
51
+ "uniffi-bindgen-react-native": "^0.29.3-1"
52
+ }
53
+ }
@@ -0,0 +1 @@
1
+ export * from './slim-bindings-node';