Skip to content

TypeScript

TypeScript binding

The TypeScript binding lets a Node.js application host decorated service methods and call remote peers with typed clients, dynamic proxies, and async streams. TypeScript supplies schemas and handlers; the NAPI-RS addon connects them to the shared Rust transport and dispatcher.

Use it when adding peer RPC to a Node application. Defining a typed service requires generated wire metadata as well as compiled JavaScript, so follow the complete first-service project through its build and run steps before adapting the references.

Packages:

  • @aster-rpc/transport — NAPI-RS native addon (Iroh P2P transport)
  • @aster-rpc/aster — TypeScript service API and runtime adapters

Runtime requirement: Node.js 20+. The examples use the TypeScript compiler before running JavaScript.

The TypeScript preview is distributed through Forgejo packages. Configure the Aster scope before installing it.

Add this scope mapping to your project’s .npmrc:

@aster-rpc:registry=https://forge.emrul.dev/api/packages/Aster/npm/

Then install the pinned preview and TypeScript compiler:

Terminal window
npm install @aster-rpc/aster@0.3.893
npm install --save-dev typescript@^5 @types/node

The @aster-rpc/transport native addon is included as a dependency and auto-selects the correct binary for your platform.

Follow the TypeScript quickstart to define a service, run aster-gen, compile with tsc, and call it from a typed consumer. TypeScript build setup explains compiler settings and generated metadata discovery.

Client choice Contract source Use it when
client.client(ServiceClass) Shared class plus generated metadata Both sides share definitions and you want named typed methods
client.proxy("ServiceName") Producer manifest discovered at runtime You inspect services dynamically and supply your own application interface

The dynamic proxy declaration has no application method names, so it needs an application interface assertion. That assertion supplies compiler information. The runtime manifest and codec still determine what gets serialized. Use matching wire names and payload representations regardless of which client surface you choose.

TypeScript decorators and generated metadata describe services and payloads. Handlers run in the JavaScript runtime. The NAPI-RS bridge connects them to Rust dispatch, which owns framing, method lookup, sessions, deadlines, and capability checks.

Area TypeScript surface
Services Standard decorators and generated type metadata
Calls Typed clients or dynamic proxies over published contracts
Streaming Async iterators and generators
Sessions Calls share a connection-scoped session ID
Data Node APIs for blobs, documents, and gossip
Coordination Wrappers over the durable Rust client engine
Telemetry Shared Rust pipeline with language-level helpers

Use explicit wire tags and generated metadata for XLANG payloads. Interoperability requires agreement with the other binding’s contract, not just an equivalent TypeScript class shape. See release compatibility for package and feature boundaries.