@yorm/hono
v0.1.0
Published
Hono transport adapter for YORM: mounts the HTTP document routes and the y-protocols WebSocket collaboration endpoint on any Hono app.
Maintainers
Readme
@yorm/hono
Hono adapter for @yorm/server:
app.route("/yorm", createHonoYorm(yorm)) turns any Hono app into a YORM
server. Routes, WebSocket protocol, query params and options are documented
in @yorm/server — this README covers only what is
Hono-specific.
Mounting (Node)
Hono's upgradeWebSocket is runtime-specific (Node/Bun/Deno/Cloudflare), so
the adapter takes it via injection instead of locking in a runtime. On Node:
import { serve } from "@hono/node-server";
import { createNodeWebSocket } from "@hono/node-ws";
import { Hono } from "hono";
import { createHonoYorm } from "@yorm/hono";
const app = new Hono();
const { upgradeWebSocket, injectWebSocket } = createNodeWebSocket({ app });
app.route(
"/yorm",
createHonoYorm(yorm, {
upgradeWebSocket, // mounts GET /yorm/ws/:type/:id
onAuthorize: (request, { type, id }) => checkToken(request.header("authorization"), type, id),
defaultPolicy: { kind: "idle", ms: 30_000 },
maxLagMs: 120_000,
}),
);
const server = serve({ fetch: app.fetch, port: 3000 });
injectWebSocket(server);Without options.upgradeWebSocket, createHonoYorm mounts the HTTP routes
only; mount the WebSocket route separately with:
app.route("/yorm", createHonoYormWebSocket(yorm, upgradeWebSocket, options));
createHonoYormWebSocketbuilds its own session cache. Use the singlecreateHonoYorm(yorm, { upgradeWebSocket })call unless you have a reason to serve the two halves from separate apps.
Options
interface HonoYormOptions extends YormServerOptions {
upgradeWebSocket?: UpgradeWebSocket; // lets createHonoYorm mount /ws itself
}Everything inherited from YormServerOptions (onAuthorize,
onAuthorizeWrite, rolePolicies, defaultPolicy, maxLagMs) is described
in @yorm/server → Options. The hooks receive a
neutral YormRequest, not a Hono Context, so authorization code ports
unchanged to the Fastify and Express adapters.
