A Bun-native WebSocket sync backend for LiveStore.
This package provides a high-performance synchronization backend for LiveStore applications running on Bun, leveraging Bun.serve for WebSockets and bun:sqlite for persistence.
- Bun Native: Built directly on
Bun.serveandbun:sqlitefor maximum performance. - WebSocket Sync: Real-time bidirectional synchronization between clients and server.
- Persistence: robust event storage using SQLite.
- LiveStore Compatible: Implements the standard
SyncBackendinterface.
bun add @phosphor/bun-syncCreate a server entry point (e.g., server.ts):
import { startServer } from "@phosphor/bun-sync/server";
import { makeSqliteStorage, setStorage } from "@phosphor/bun-sync/server/storage";
import { Effect } from "effect";
// 1. Initialize Storage
const storage = makeSqliteStorage("sync.db");
// Ensure tables are created
Effect.runPromise(storage.init());
// 2. Inject Storage into Server
setStorage(storage);
// 3. Start Server
const server = startServer(3000);
console.log(`Sync server running at ws://localhost:${server.port}`);In your LiveStore application (e.g., adapter.ts):
import { makeAdapter } from "@livestore/adapter-web"; // or adapter-node
import { makeBunSyncBackend } from "@phosphor/bun-sync/client";
import { Effect } from "effect";
export const adapter = makeAdapter({
// ... other adapter options (storage, etc.)
sync: {
backend: makeBunSyncBackend("ws://localhost:3000", "my-store-id"),
},
});This package includes a standalone demo to visualize the sync process.
bun run demoOpen http://localhost:3000 to see the demo client.
bun testDual MIT / APACHE 2.0