Something went wrong. Try again.
collection of js libraries
Something went wrong. Try again.
README.md
@rlib/rpc #
Typed RPC over message-based transports, with zod contracts and optional streaming responses.
Installation #
bun add @rlib/rpc
Concepts #
RpcContractdefines request/response schemasRpcPeerinvokes remote procedures and serves local handlersNodeWorkerTransportandWorkerThreadTransportconnect peers over worker threads
Usage #
import z from "zod";
import {
NodeWorkerTransport,
RpcContract,
RpcPeer,
} from "@rlib/rpc";
const mainContract = new RpcContract({
echo: {
input: z.string(),
output: z.string(),
},
});
const workerContract = new RpcContract({
add: {
input: z.object({ a: z.number(), b: z.number() }),
output: z.number(),
},
});
const rpc = new RpcPeer(
{
localContract: mainContract,
remoteContract: workerContract,
transport: new NodeWorkerTransport({
path: "worker.ts",
basePath: import.meta.url,
}),
},
{
echo: (value) => value,
},
);
const sum = await rpc.call("add", { a: 1, b: 2 });