ENGINE: RUNNING / RUNTIME: UNIVERSAL TS / STORAGE: PLUGGABLE L1/L2
terminal 02 // INTEGRATION GUIDE

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.

Zero Server Modifications Required
01 Install Core Runtime & Adapters
$ npm install @pb-sync/client @pb-sync/adapter-expo pocketbase
code_blocks src/lib/syncEngine.ts -- Verified Production Blueprint
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 });
Engine Size: 8.4kB gzipped Zero dependencies outside PocketBase SDK
dataset
Platform Independence & Pluggable Drivers Isomorphic Architecture

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.

alt_route Conflict Engine Configurations

Deterministic Conflict Resolution Recipes

Declare resolution strategies per collection or implement custom field-level merge drivers.

serverWins Default

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' } }
clientWins Optimistic

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' } }
reject Audited

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.

Zero Lock Contention
Local Mutationengine.applyLocal()_outbox JournalAtomic SQLite TxBatch Transportengine.syncNow()PocketBaseServer Record
rocket_launch Production Blueprint

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.