@iadev93/zuno-elysia
v0.0.6
Published
<p><b>Elysia adapter for Zuno.</b></p>
Maintainers
Readme
@iadev93/zuno-elysia
Provides seamless state synchronization for ElysiaJS (Bun) applications using native async generators.
pnpm add @iadev93/zuno-elysiaUsage
import { Elysia } from 'elysia'
import { cors } from '@elysiajs/cors'
import { createZunoElysia } from '@iadev93/zuno-elysia'
const app = new Elysia()
.use(cors())
const zuno = createZunoElysia({
batchSync: true // Optional: Enable batching
})
// Register Zuno handlers
app.get('/zuno/sse', zuno.sse)
app.post('/zuno/sync', zuno.sync)
app.get('/zuno/snapshot', zuno.snapshot)
app.listen(3002)API
createZunoElysia()
Returns an object containing the following handlers:
sse (GET)
An async generator handler for Server-Sent Events. It automatically handles:
- Connection keep-alive and heartbeats.
- Reconnection logic via
last-event-id. - Initial state snapshots for fresh connections.
sync (POST)
Validates and applies incoming state events to the Zuno universe. Handles version conflicts and broadcasts updates to all connected SSE clients.
snapshot (GET)
Returns the current full state of the universe, the current version, and the last event ID.
Features
- Native SSE: Uses Elysia's optimized streaming capabilities with async generators.
- Lightweight: Zero runtime dependencies on Elysia itself (uses structural typing).
- Type Safe: Fully written in TypeScript with comprehensive docstrings.
License
MIT
