@inkly/bun
v0.0.0
Published
Bun runtime adapter for inkly (native Bun.serve WebSockets, handlers-once model).
Readme
@inkly/bun
Native Bun runtime adapter for inkly, backed by Bun.serve WebSockets.
Install
pnpm add @inkly/bun @inkly/coreQuickstart
import { contract, inkly } from "@inkly/core";
import { serve } from "@inkly/bun";
import { z } from "zod";
const api = contract({
actions: {
echo: { input: z.object({ msg: z.string() }), output: z.object({ msg: z.string() }) },
},
});
const app = inkly(api);
app.defineAction("echo", (_peer, input) => input);
const handle = serve(app, { port: 3000, path: "/ws" });
console.log(`listening on ws://localhost:${handle.port}/ws`);API
serve(app, options?)
Options:
port?: numberhostname?: stringpath?: string— defaults to/authorize?: (request) => unknown | Promise<unknown>— pre-authorize during HTTP upgradecompression?: boolean— enablepermessage-deflate(RFC 7692) on the websocket handler; off by defaulttls?: unknown— passed through toBun.serve
Returns { stop(), port, server }, where server is the Bun server.
CSWSH protection is inherited from the app: set allowedOrigins on inkly(api, { allowedOrigins })
and the adapter rejects a disallowed Origin with HTTP 403 before the socket opens.
Caveats
- Bun is the only runtime for this adapter; Node-based tests only verify that the module loads.
- Core protocol/auth/resume/rooms behavior lives in
@inkly/core; this package only normalizes Bun WebSocket I/O. - Bun declares WebSocket handlers once per server and exposes per-socket data through
ws.data.
