A deployable TinyBase sync server as an Alchemy.run resource using Cloudflare Durable Objects.
npm install alchemy-tinybase-doIn your alchemy.run.ts file:
import alchemy from 'alchemy';
import { TinybaseDoSync } from 'alchemy-tinybase-do';
const app = alchemy('my-app');
const tinybaseDO = await TinybaseDoSync('tinybase-sync', {
// If data should be persisted to the Durable Object
persist: true, // default: false
});
await app.finalize();- Default:
false - When
true, data is persisted in the Durable Object storage between client sessions - When
false, the Durable Object only provides synchronization between clients (clients are expected to persist their own data)
- Real-time synchronization between multiple clients using WebSockets
- Optional server-side persistence using Cloudflare Durable Objects
- Built on TinyBase's mergeable store for conflict-free synchronization
- Fully typed with TypeScript
Your client applications can connect to the deployed sync server using TinyBase's WebSocket synchronizer:
import { createMergeableStore } from 'tinybase';
import { createWsSynchronizer } from 'tinybase/synchronizers';
const store = createMergeableStore();
const synchronizer = createWsSynchronizer(
store,
'wss://your-worker-url.workers.dev'
);
await synchronizer.startSync();MIT