@lambdalisue/messagepack-rpc@2.4.0Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
🦕 TypeScript module that allows for the implementation of MessagePack-RPC using MessagePack as the message schema.
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers




JSR Score
88%
Published
a year ago (2.4.0)
This is a TypeScript module that allows for the implementation of MessagePack-RPC using MessagePack as the message schema.
Usage
Server
import { assert, is } from "@core/unknownutil"; import { Session } from "@lambdalisue/messagepack-rpc"; async function handleConnection(conn: Deno.Conn): Promise<void> { const session = new Session(conn.readable, conn.writable); // Define APIs session.dispatcher = { sum(x, y) { assert(x, is.Number); assert(y, is.Number); return x + y; }, }; // Start the session session.start(); // Do whatever // Shutdown the session await session.shutdown(); } const listener = Deno.listen({ hostname: "localhost", port: 8080 }); for await (const conn of listener) { handleConnection(conn).catch((err) => console.error(err)); }
Client
import { Client, Session } from "@lambdalisue/messagepack-rpc"; const conn = await Deno.connect({ hostname: "localhost", port: 8080 }); const session = new Session(conn.readable, conn.writable); const client = new Client(session); // Start the session session.start(); // Do whatever console.log(await client.call("sum", 1, 2)); // 3 console.log(await client.call("sum", 2, 3)); // 5 // Shutdown the session await session.shutdown();
Although the original MessagePack-RPC specification does not mention bidirectional communication, this module supports it. Therefore, APIs defined on the client side can be called from the server side.
Built and signed on
GitHub Actions
Add Package
deno add jsr:@lambdalisue/messagepack-rpc
Import symbol
import * as messagepack_rpc from "@lambdalisue/messagepack-rpc";
Import directly with a jsr specifier
import * as messagepack_rpc from "jsr:@lambdalisue/messagepack-rpc";
Add Package
pnpm i jsr:@lambdalisue/messagepack-rpc
pnpm dlx jsr add @lambdalisue/messagepack-rpc
Import symbol
import * as messagepack_rpc from "@lambdalisue/messagepack-rpc";
Add Package
yarn add jsr:@lambdalisue/messagepack-rpc
yarn dlx jsr add @lambdalisue/messagepack-rpc
Import symbol
import * as messagepack_rpc from "@lambdalisue/messagepack-rpc";
Add Package
npx jsr add @lambdalisue/messagepack-rpc
Import symbol
import * as messagepack_rpc from "@lambdalisue/messagepack-rpc";
Add Package
bunx jsr add @lambdalisue/messagepack-rpc
Import symbol
import * as messagepack_rpc from "@lambdalisue/messagepack-rpc";