Quickstart & Client Setup
Get up and running with offline-first synchronization in less than 5 minutes. Predictable mutations, deterministic local SQLite/IndexedDB journal, and seamless server handshakes.
01 import PocketBase from 'pocketbase';02 import { SyncEngine, PocketBaseTransport } from '@pb-sync/client';03 import { SqliteStorageAdapter, openExpoDriver } from '@pb-sync/adapter-expo';04 05 // 1. Initialize PocketBase client06 const pb = new PocketBase('https://api.yourdomain.io');07 08 // 2. Initialize Transport with atomic auth provider & handshake validation09 const transport = new PocketBaseTransport({10 client: pb,11 getAuthToken: () => pb.authStore.token,12 });13 14 // Perform capability handshake & server schema revision verification15 const serverInfo = await transport.fetchInfo();16 console.info('[SyncHandshake] Verified node:', serverInfo.version);17 18 // 3. Local Deterministic Storage Adapter initialization19 const storage = new SqliteStorageAdapter(openExpoDriver('app.db'));20 21 // 4. Instantiate Engine & define collection sync schemas22 export const engine = new SyncEngine({23 storage,24 transport,25 collections: {26 notes: { policy: 'serverWins' },27 projects: { policy: 'serverWins' },28 },29 });30 31 // 5. Deterministic Zero-latency Local Mutation32 await engine.applyLocal('notes', {33 action: 'create',34 data: {35 id: crypto.randomUUID(),36 title: 'Offline Note',37 updated: new Date().toISOString(),38 },39 });40 41 // 6. Trigger reconciliation pipeline (flushes outbox, ingests changesets)42 await engine.syncNow();43 44 // 7. Reactive Server-Sent Event (SSE) Nudge Stream45 transport.subscribe((nudge) => {46 if (nudge.hasUpdates) {47 engine.syncNow();48 }49 });Web (SvelteKit/React) brings its own IndexedDB storage adapter (@pb-sync/adapter-idb) — the core sync engine itself is 100% platform-independent and runs in browsers,
service workers, or React Native.
Deterministic Conflict Resolution Recipes
Declare resolution strategies per collection or implement custom field-level merge drivers.
Authoritative Server
Server revision sequence always takes absolute precedence on concurrent field collisions. Local conflicting mutation is superseded and re-aligned with remote snapshot.
collections: { notes: { policy: 'serverWins' } }Client Supremacy
Local client mutations continuously force-patch the server record during collision. Best for single-user document workflows or mobile offline state captures.
collections: { drafts: { policy: 'clientWins' } }Quarantine & Manual
Failed mutations are discarded from the push cycle and permanently logged to the
internal _conflicts table for user inspection.
collections: { ledgers: { policy: 'reject' } }Replication Lifecycle Visualizer
Deterministic flow when writing to local SQLite and syncing to PocketBase.
Explore the Fully-Fledged Expo Notes Example
Clone the reference project featuring real-time offline syncing, SQLite migration hooks, optimistic UI state management, and SSE-driven multi-device updates.