@agntcy/slim-bindings 2.0.0-alpha.2 → 2.0.0-alpha.3

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
@@ -12,7 +12,7 @@ npm installs this package and, when published for your OS/arch, the matching opt
12
12
 
13
13
  ## Module shape
14
14
 
15
- The published entry loads the generated UniFFI/Node bindings (see `package.json` `main` / `types`). From TypeScript or ESM-aware tooling you typically import the default export from the package path your bundler resolves (examples in this repo import from `generated/slim-bindings-node.js` when running inside the bindings workspace).
15
+ This package is **native ESM** (`require()` is not supported — use `import`). The published entry loads the generated UniFFI/Node bindings (see `package.json` `main` / `types`). Examples in this repo import from `generated/index.js` when running inside the bindings workspace.
16
16
 
17
17
  ```typescript
18
18
  import slimBindings from '@agntcy/slim-bindings';
@@ -45,7 +45,7 @@ Full TypeScript types ship under `types/` in the published package (`index.d.ts`
45
45
  `await service.connectAsync(config)`
46
46
  Returns a connection id used for routing/subscriptions.
47
47
 
48
- 6. **Subscribe** the app to receive traffic for its name (often passing `BigInt(connId)` if the generated API expects `bigint` — see note below).
48
+ 6. **Subscribe** the app to receive traffic for its name, passing the connection id as a real `bigint` (e.g. `await app.subscribeAsync(name, connId)` where `connId` is what `connectAsync` returned).
49
49
 
50
50
  7. **Server** — for a network node that accepts clients, initialize the same way, then build a server config (e.g. `newInsecureServerConfig('0.0.0.0:46357')`) and run:
51
51
 
@@ -54,15 +54,15 @@ Full TypeScript types ship under `types/` in the published package (`index.d.ts`
54
54
 
55
55
  ## Examples
56
56
 
57
- Runnable scripts live under `examples/` (from repo root, use the `Taskfile` targets `example:server`, `example:alice`, `example:bob`, or run them via npm from `examples/` as documented in [README_dev.md](./README_dev.md)).
57
+ Runnable scripts live under `examples/` (from repo root, use the `Taskfile` targets `example:server`, `example:alice`, `example:bob`, `example:group`, or run them via npm from `examples/` as documented in [README_dev.md](./README_dev.md)). `example:group` demonstrates multicast (group) sessions — a moderator creates a channel and invites participants; see [README_dev.md](./README_dev.md#3-run-the-group-multicast-example) for usage.
58
58
 
59
- ## `bigint` vs `number` (FFI)
59
+ ## Type notes
60
60
 
61
- Some APIs are typed with `bigint` for 64-bit values, but `connectAsync` may return a JavaScript `number` at runtime. When you pass that value into a method that expects `bigint` (for example `subscribeAsync`), wrap it: `BigInt(connId)`. See [README_dev.md](./README_dev.md#ffi-type-conversions) for details.
61
+ 64-bit values (like the connection id from `connectAsync`) are real `bigint` end to end — pass them through as-is rather than converting to `Number`. Enum-typed fields (like `SessionConfig.sessionType`) are real TypeScript enums (`SessionType.PointToPoint`), not string literals. See [README_dev.md](./README_dev.md#type-conversions-and-api-notes) for details.
62
62
 
63
63
  ## Building from source / contributing
64
64
 
65
- Generator setup, Task commands, publishing, and FFI patches are documented for maintainers in **[README_dev.md](./README_dev.md)**.
65
+ Generator setup, Task commands, and publishing are documented for maintainers in **[README_dev.md](./README_dev.md)**.
66
66
 
67
67
  ## Links
68
68
 
package/binding.js ADDED
@@ -0,0 +1,64 @@
1
+ // Copyright AGNTCY Contributors (https://github.com/agntcy)
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { detectLinuxLibc } from './libc-linux.js';
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
+ const libc = detectLinuxLibc();
18
+ if (arch === 'arm64') {
19
+ return `linux-arm64-${libc}`;
20
+ }
21
+ if (arch === 'x64') {
22
+ return `linux-x64-${libc}`;
23
+ }
24
+ }
25
+ if (platform === 'win32') {
26
+ return arch === 'arm64' ? 'win32-arm64-msvc' : 'win32-x64-msvc';
27
+ }
28
+ throw new Error(`Unsupported platform: ${platform} ${arch}`);
29
+ }
30
+
31
+ const platformId = getCurrentPlatformId();
32
+ const packageName = `@agntcy/slim-bindings-${platformId}`;
33
+
34
+ // The generated bindings (uniffi-bindgen-react-native, napi target) are native ESM
35
+ // (they use import.meta.url for colocated native-library resolution), so the
36
+ // platform package must be loaded via dynamic import rather than require().
37
+ // Importing it also runs its required one-time initialization side effect
38
+ // (registering the UnaryUnaryHandler/etc. callback vtables), so this module
39
+ // must be the sole entry point consumers use - do not import the platform
40
+ // package's inner files directly.
41
+ let bindings;
42
+ try {
43
+ bindings = await import(packageName);
44
+ } catch (err) {
45
+ if (err.code === 'ERR_MODULE_NOT_FOUND') {
46
+ throw new Error(
47
+ `Platform package ${packageName} is not installed. ` +
48
+ `Run: npm install @agntcy/slim-bindings (optional dependencies include linux-*-gnu, linux-*-musl, darwin-*, win32-*). ` +
49
+ `On Alpine or other musl Linux, ensure the linux-*-musl optional package is available for your Node arch.`
50
+ );
51
+ }
52
+ throw err;
53
+ }
54
+
55
+ /**
56
+ * The resolved platform-binding module namespace. Holds every named export of
57
+ * the generated bindings (Channel, Server, RpcError, ...). Because the platform
58
+ * package name is computed at runtime, ESM cannot statically `export *` from it;
59
+ * `named-exports.js` (generated) re-exports these names individually so that
60
+ * `import { Channel } from '@agntcy/slim-bindings'` works.
61
+ */
62
+ export const ns = bindings;
63
+
64
+ export default bindings;
package/index.d.ts CHANGED
@@ -4,5 +4,13 @@
4
4
  /**
5
5
  * Type definitions for @agntcy/slim-bindings.
6
6
  * Full types are in types/ (generated from bindings before publish).
7
+ *
8
+ * Both import styles are supported:
9
+ * - named: `import { Channel, RpcError } from '@agntcy/slim-bindings';`
10
+ * (runtime values come from ./named-exports.js; types from here)
11
+ * - default: `import slimBindings from '@agntcy/slim-bindings';`
12
+ * then access the API off it (`slimBindings.SessionType`).
7
13
  */
8
- export * from './types/slim-bindings-node';
14
+ export * from './types/slim_bindings';
15
+ import * as slimBindings from './types/slim_bindings';
16
+ export default slimBindings;
package/index.js CHANGED
@@ -1,50 +1,14 @@
1
1
  // Copyright AGNTCY Contributors (https://github.com/agntcy)
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- 'use strict';
5
-
6
- const { detectLinuxLibc } = require('./libc-linux.js');
7
-
8
- /**
9
- * Resolves the platform id for the current Node process.
10
- * Must match the optionalDependency package suffixes.
11
- */
12
- function getCurrentPlatformId() {
13
- const platform = process.platform;
14
- const arch = process.arch;
15
- if (platform === 'darwin') {
16
- return arch === 'arm64' ? 'darwin-arm64' : 'darwin-x64';
17
- }
18
- if (platform === 'linux') {
19
- const libc = detectLinuxLibc();
20
- if (arch === 'arm64') {
21
- return `linux-arm64-${libc}`;
22
- }
23
- if (arch === 'x64') {
24
- return `linux-x64-${libc}`;
25
- }
26
- }
27
- if (platform === 'win32') {
28
- return arch === 'arm64' ? 'win32-arm64-msvc' : 'win32-x64-msvc';
29
- }
30
- throw new Error(`Unsupported platform: ${platform} ${arch}`);
31
- }
32
-
33
- const platformId = getCurrentPlatformId();
34
- const packageName = `@agntcy/slim-bindings-${platformId}`;
35
-
36
- let bindings;
37
- try {
38
- bindings = require(packageName);
39
- } catch (err) {
40
- if (err.code === 'MODULE_NOT_FOUND') {
41
- throw new Error(
42
- `Platform package ${packageName} is not installed. ` +
43
- `Run: npm install @agntcy/slim-bindings (optional dependencies include linux-*-gnu, linux-*-musl, darwin-*, win32-*). ` +
44
- `On Alpine or other musl Linux, ensure the linux-*-musl optional package is available for your Node arch.`
45
- );
46
- }
47
- throw err;
48
- }
49
-
50
- module.exports = bindings;
4
+ // Main entry point for @agntcy/slim-bindings.
5
+ //
6
+ // Exposes the platform binding both ways:
7
+ // * named exports — `import { Channel, RpcError } from '@agntcy/slim-bindings'`
8
+ // (from the generated ./named-exports.js barrel), and
9
+ // * a default export — `import slim from '@agntcy/slim-bindings'` (the resolved
10
+ // platform-binding namespace), for backwards compatibility.
11
+ //
12
+ // The platform-specific package is selected and loaded in ./binding.js.
13
+ export * from './named-exports.js';
14
+ export { default } from './binding.js';
package/libc-linux.js CHANGED
@@ -1,16 +1,14 @@
1
1
  // Copyright AGNTCY Contributors (https://github.com/agntcy)
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- 'use strict';
5
-
6
- const fs = require('fs');
7
- const { execFileSync } = require('child_process');
4
+ import fs from 'fs';
5
+ import { execFileSync } from 'child_process';
8
6
 
9
7
  /**
10
8
  * Best-effort libc family for Linux (gnu vs musl).
11
9
  * Used to pick the correct @agntcy/slim-bindings-linux-* optional package.
12
10
  */
13
- function detectLinuxLibc() {
11
+ export function detectLinuxLibc() {
14
12
  try {
15
13
  const maps = fs.readFileSync('/proc/self/maps', 'utf8');
16
14
  if (maps.includes('ld-musl')) {
@@ -31,5 +29,3 @@ function detectLinuxLibc() {
31
29
  }
32
30
  return 'gnu';
33
31
  }
34
-
35
- module.exports = { detectLinuxLibc };
@@ -0,0 +1,112 @@
1
+ // AUTO-GENERATED by scripts/gen-named-exports.mjs — DO NOT EDIT.
2
+ // Runtime named re-exports of the platform binding so that
3
+ // `import { Channel, RpcError, ... } from '@agntcy/slim-bindings'` works.
4
+ // The platform package is selected at runtime (see binding.js), so ESM's
5
+ // `export *` cannot be used here; each value export is re-bound explicitly.
6
+ import { ns } from './binding.js';
7
+
8
+ export const App = ns.App;
9
+ export const BackoffConfig = ns.BackoffConfig;
10
+ export const BackoffConfig_Tags = ns.BackoffConfig_Tags;
11
+ export const BasicAuth = ns.BasicAuth;
12
+ export const BidiStreamHandler = ns.BidiStreamHandler;
13
+ export const BuildInfo = ns.BuildInfo;
14
+ export const CaSource = ns.CaSource;
15
+ export const CaSource_Tags = ns.CaSource_Tags;
16
+ export const Channel = ns.Channel;
17
+ export const ClientAuthenticationConfig = ns.ClientAuthenticationConfig;
18
+ export const ClientAuthenticationConfig_Tags = ns.ClientAuthenticationConfig_Tags;
19
+ export const ClientConfig = ns.ClientConfig;
20
+ export const ClientJwtAuth = ns.ClientJwtAuth;
21
+ export const CompletionHandle = ns.CompletionHandle;
22
+ export const CompressionType = ns.CompressionType;
23
+ export const Context = ns.Context;
24
+ export const DataplaneConfig = ns.DataplaneConfig;
25
+ export const Direction = ns.Direction;
26
+ export const ExponentialBackoff = ns.ExponentialBackoff;
27
+ export const FixedIntervalBackoff = ns.FixedIntervalBackoff;
28
+ export const IdentityProviderConfig = ns.IdentityProviderConfig;
29
+ export const IdentityProviderConfig_Tags = ns.IdentityProviderConfig_Tags;
30
+ export const IdentityVerifierConfig = ns.IdentityVerifierConfig;
31
+ export const IdentityVerifierConfig_Tags = ns.IdentityVerifierConfig_Tags;
32
+ export const JwtAlgorithm = ns.JwtAlgorithm;
33
+ export const JwtAuth = ns.JwtAuth;
34
+ export const JwtKeyConfig = ns.JwtKeyConfig;
35
+ export const JwtKeyData = ns.JwtKeyData;
36
+ export const JwtKeyData_Tags = ns.JwtKeyData_Tags;
37
+ export const JwtKeyFormat = ns.JwtKeyFormat;
38
+ export const JwtKeyType = ns.JwtKeyType;
39
+ export const JwtKeyType_Tags = ns.JwtKeyType_Tags;
40
+ export const KeepaliveConfig = ns.KeepaliveConfig;
41
+ export const KeepaliveServerParameters = ns.KeepaliveServerParameters;
42
+ export const MessageContext = ns.MessageContext;
43
+ export const MlsSettings = ns.MlsSettings;
44
+ export const MulticastBidiStreamHandler = ns.MulticastBidiStreamHandler;
45
+ export const MulticastResponseReader = ns.MulticastResponseReader;
46
+ export const MulticastStreamMessage = ns.MulticastStreamMessage;
47
+ export const MulticastStreamMessage_Tags = ns.MulticastStreamMessage_Tags;
48
+ export const Name = ns.Name;
49
+ export const ProxyConfig = ns.ProxyConfig;
50
+ export const ReceivedMessage = ns.ReceivedMessage;
51
+ export const RequestStream = ns.RequestStream;
52
+ export const RequestStreamWriter = ns.RequestStreamWriter;
53
+ export const ResponseSink = ns.ResponseSink;
54
+ export const ResponseStreamReader = ns.ResponseStreamReader;
55
+ export const RpcCode = ns.RpcCode;
56
+ export const RpcError = ns.RpcError;
57
+ export const RpcError_Tags = ns.RpcError_Tags;
58
+ export const RpcMessageContext = ns.RpcMessageContext;
59
+ export const RpcMulticastItem = ns.RpcMulticastItem;
60
+ export const RuntimeConfig = ns.RuntimeConfig;
61
+ export const Server = ns.Server;
62
+ export const ServerAuthenticationConfig = ns.ServerAuthenticationConfig;
63
+ export const ServerAuthenticationConfig_Tags = ns.ServerAuthenticationConfig_Tags;
64
+ export const ServerConfig = ns.ServerConfig;
65
+ export const Service = ns.Service;
66
+ export const ServiceConfig = ns.ServiceConfig;
67
+ export const Session = ns.Session;
68
+ export const SessionConfig = ns.SessionConfig;
69
+ export const SessionType = ns.SessionType;
70
+ export const SessionWithCompletion = ns.SessionWithCompletion;
71
+ export const SlimError = ns.SlimError;
72
+ export const SlimError_Tags = ns.SlimError_Tags;
73
+ export const SpireConfig = ns.SpireConfig;
74
+ export const StaticJwtAuth = ns.StaticJwtAuth;
75
+ export const StreamMessage = ns.StreamMessage;
76
+ export const StreamMessage_Tags = ns.StreamMessage_Tags;
77
+ export const StreamStreamHandlerImpl = ns.StreamStreamHandlerImpl;
78
+ export const StreamUnaryHandlerImpl = ns.StreamUnaryHandlerImpl;
79
+ export const TlsClientConfig = ns.TlsClientConfig;
80
+ export const TlsServerConfig = ns.TlsServerConfig;
81
+ export const TlsSource = ns.TlsSource;
82
+ export const TlsSource_Tags = ns.TlsSource_Tags;
83
+ export const TracingConfig = ns.TracingConfig;
84
+ export const TransportProtocol = ns.TransportProtocol;
85
+ export const UnaryStreamHandlerImpl = ns.UnaryStreamHandlerImpl;
86
+ export const UnaryUnaryHandlerImpl = ns.UnaryUnaryHandlerImpl;
87
+ export const createService = ns.createService;
88
+ export const createServiceWithConfig = ns.createServiceWithConfig;
89
+ export const getBuildInfo = ns.getBuildInfo;
90
+ export const getGlobalService = ns.getGlobalService;
91
+ export const getServices = ns.getServices;
92
+ export const getVersion = ns.getVersion;
93
+ export const initializeFromConfig = ns.initializeFromConfig;
94
+ export const initializeFromConfigWithError = ns.initializeFromConfigWithError;
95
+ export const initializeWithConfigs = ns.initializeWithConfigs;
96
+ export const initializeWithDefaults = ns.initializeWithDefaults;
97
+ export const isInitialized = ns.isInitialized;
98
+ export const newConfigFromJson = ns.newConfigFromJson;
99
+ export const newDataplaneConfig = ns.newDataplaneConfig;
100
+ export const newInsecureClientConfig = ns.newInsecureClientConfig;
101
+ export const newInsecureServerConfig = ns.newInsecureServerConfig;
102
+ export const newRuntimeConfig = ns.newRuntimeConfig;
103
+ export const newRuntimeConfigWith = ns.newRuntimeConfigWith;
104
+ export const newSecureClientConfig = ns.newSecureClientConfig;
105
+ export const newSecureServerConfig = ns.newSecureServerConfig;
106
+ export const newServerConfig = ns.newServerConfig;
107
+ export const newServiceConfig = ns.newServiceConfig;
108
+ export const newServiceConfigWith = ns.newServiceConfigWith;
109
+ export const newServiceConfiguration = ns.newServiceConfiguration;
110
+ export const newTracingConfig = ns.newTracingConfig;
111
+ export const newTracingConfigWith = ns.newTracingConfigWith;
112
+ export const shutdownBlocking = ns.shutdownBlocking;
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@agntcy/slim-bindings",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "SLIM Node.js bindings using UniFFI",
5
+ "type": "module",
5
6
  "main": "index.js",
6
7
  "types": "index.d.ts",
7
8
  "files": [
8
9
  "index.js",
10
+ "binding.js",
11
+ "named-exports.js",
9
12
  "libc-linux.js",
10
13
  "index.d.ts",
11
14
  "types/",
@@ -34,21 +37,24 @@
34
37
  "directory": "node"
35
38
  },
36
39
  "license": "Apache-2.0",
40
+ "dependencies": {
41
+ "@ubjs/core": "0.31.0-3",
42
+ "@ubjs/node": "0.31.0-3"
43
+ },
37
44
  "optionalDependencies": {
38
- "@agntcy/slim-bindings-darwin-arm64": "2.0.0-alpha.2",
39
- "@agntcy/slim-bindings-darwin-x64": "2.0.0-alpha.2",
40
- "@agntcy/slim-bindings-linux-arm64-gnu": "2.0.0-alpha.2",
41
- "@agntcy/slim-bindings-linux-arm64-musl": "2.0.0-alpha.2",
42
- "@agntcy/slim-bindings-linux-x64-gnu": "2.0.0-alpha.2",
43
- "@agntcy/slim-bindings-linux-x64-musl": "2.0.0-alpha.2",
44
- "@agntcy/slim-bindings-win32-arm64-msvc": "2.0.0-alpha.2",
45
- "@agntcy/slim-bindings-win32-x64-gnu": "2.0.0-alpha.2",
46
- "@agntcy/slim-bindings-win32-x64-msvc": "2.0.0-alpha.2"
45
+ "@agntcy/slim-bindings-darwin-arm64": "2.0.0-alpha.3",
46
+ "@agntcy/slim-bindings-darwin-x64": "2.0.0-alpha.3",
47
+ "@agntcy/slim-bindings-linux-arm64-gnu": "2.0.0-alpha.3",
48
+ "@agntcy/slim-bindings-linux-arm64-musl": "2.0.0-alpha.3",
49
+ "@agntcy/slim-bindings-linux-x64-gnu": "2.0.0-alpha.3",
50
+ "@agntcy/slim-bindings-linux-x64-musl": "2.0.0-alpha.3",
51
+ "@agntcy/slim-bindings-win32-arm64-msvc": "2.0.0-alpha.3",
52
+ "@agntcy/slim-bindings-win32-x64-gnu": "2.0.0-alpha.3",
53
+ "@agntcy/slim-bindings-win32-x64-msvc": "2.0.0-alpha.3"
47
54
  },
48
55
  "devDependencies": {
49
56
  "@types/node": "^20.0.0",
50
- "ffi-rs": "^1.3.0",
51
57
  "typescript": "^5.0.0",
52
- "uniffi-bindgen-react-native": "^0.29.3-1"
58
+ "uniffi-bindgen-react-native": "0.31.0-3"
53
59
  }
54
60
  }
package/types/index.d.ts CHANGED
@@ -1 +1,7 @@
1
- export * from './slim-bindings-node';
1
+ export * from './slim_bindings';
2
+ import * as slim_bindings from './slim_bindings';
3
+ export declare function uniffiInitAsync(): Promise<void>;
4
+ declare const _default: {
5
+ slim_bindings: typeof slim_bindings;
6
+ };
7
+ export default _default;