@kataribe/cloudflare
v0.4.0
Published
Cloudflare Workers implementation for kataribe - WebSocket with Durable Objects
Maintainers
Readme
@kataribe/cloudflare
@kataribe/cloudflare brings Kataribe to Cloudflare Workers and Durable
Objects. It wraps the core runtime with adapters for Cloudflare's WebSocket
upgrade flow so you can run typed RPC APIs at the edge.
Highlights
createCloudflareWsHandlerfor Worker WebSocket endpoints- Durable Object helper
KataribeDurableObjectfor sticky sessions - Ships TypeScript declarations for the Workers runtime
- Re-exports
@kataribe/corecontract and runtime utilities
Installation
pnpm add @kataribe/cloudflare
# or
npm install @kataribe/cloudflareWorker Example
import {
createCloudflareWsHandler,
defineContract,
rpc,
} from "@kataribe/cloudflare";
const contract = defineContract({
rpcToServer: {
greet: rpc<{ name: string }, { message: string }>(),
},
});
const handler = createCloudflareWsHandler({
contract,
handlers: {
rpcToServer: {
async greet({ name }) {
return { message: `Hello from Workers, ${name}!` };
},
},
},
});
export default {
fetch(request: Request) {
return handler(request);
},
};For sticky sessions, wrap the same adapter inside KataribeDurableObject and
forward WebSocket upgrade requests to the Durable Object instance.
Development
- Generate Worker typings and declarations with
pnpm build - Run the Vitest suite with
pnpm test - Configure Wrangler using the provided
wrangler.toml
