Skip to content
Strata Sync

AI agents: fetch the documentation index at llms.txt. Markdown versions are available by appending .md to any page URL, including this page's markdown.

Configuration

SyncClientOptions reference for configuring the Strata Sync client.

Pass SyncClientOptions to createSyncClient.

Quick example

import { createSyncClient } from "@stratasync/client";

const client = createSyncClient({
  // Required adapters
  storage: storageAdapter,
  transport: transportAdapter,
  reactivity: reactivityAdapter,

  // Optional
  dbName: "my-app-sync",
  userId: "user-123",
  version: 1,
  userVersion: 1,
  groups: ["workspace-abc"],
  optimistic: true,
  batchMutations: true,
  batchDelay: 50,
  bootstrapMode: "auto",
  rebaseStrategy: "server-wins",
  fieldLevelConflicts: true,
});

Required adapters

storage

Type: StorageAdapter

Local persistence for model rows, metadata, the outbox, partial indexes, and sync actions.

import { createIndexedDbStorage } from "@stratasync/storage-idb";

const storage = createIndexedDbStorage();

The StorageAdapter interface defines methods for:

  • get, getAll, put, delete: basic CRUD for model rows
  • getByIndex: indexed lookups
  • getMeta, setMeta: sync metadata (last sync ID, schema hash, and more)
  • getOutbox, addToOutbox, removeFromOutbox: pending transaction persistence
  • hasPartialIndex, setPartialIndex: partial model index tracking
  • addSyncActions, getSyncActions, clearSyncActions: sync action log
  • writeBatch: batch write operations
  • clear, count: storage management

transport

Type: TransportAdapter

Server communication: bootstrap, delta subscriptions, batch mutations, and connection state.

import { createGraphQLTransport } from "@stratasync/transport-graphql";

const transport = createGraphQLTransport({
  endpoint: "https://api.example.com/graphql",
  syncEndpoint: "https://api.example.com/sync",
  wsEndpoint: "wss://api.example.com/sync/ws",
  auth: { getAccessToken: async () => "token" },
});

The TransportAdapter interface defines:

  • bootstrap(options): stream initial data as AsyncGenerator<ModelRow>
  • batchLoad(options): lazy-load models by index
  • mutate(batch): submit transaction batches
  • subscribe(options): real-time delta subscription
  • fetchDeltas(after, limit?): poll for missed deltas
  • getConnectionState(): current connection state
  • onConnectionStateChange(callback): subscribe to connection changes
  • close(): clean up resources

reactivity

Type: ReactivityAdapter

Makes identity map entries observable for UI re-rendering.

import { createMobXReactivity } from "@stratasync/mobx";

const reactivity = createMobXReactivity();

Simple options

All optional.

OptionTypeDefaultDescription
dbNamestring"sync-db"Database name for storage. Each unique name creates a separate IndexedDB database.
userIdstring-Logged-in user ID. Used for storage isolation in multi-user scenarios.
versionnumber-Client version for storage naming. Incrementing triggers a fresh bootstrap.
userVersionnumber-Per-user version for storage naming. Incrementing triggers a fresh bootstrap.
groupsstring[]-Sync groups for multi-tenancy. The client syncs only models belonging to the specified groups.
optimisticbooleantrueApply mutations to the identity map before the server confirms them. Rolls back on rejection.
batchMutationsbooleanfalseBatch multiple mutations into a single network request.
batchDelaynumber (ms)-Delay before sending a mutation batch. Only applies when batchMutations is true.
bootstrapMode"auto" | "full" | "local""auto"auto: use local storage if available and the schema matches, otherwise bootstrap from server. full: always bootstrap from server. local: never contact the server.
schemaSchemaDefinition | ModelRegistrySnapshot-Explicit schema definition. If omitted, the client uses the global ModelRegistry populated by decorators.
modelFactoryModelFactory | ModelFactoryFactory-Custom factory for creating model instances from raw data. Defaults to ModelRegistry constructors with _applyUpdate.
yjsTransportYjsTransport-Yjs transport for collaborative editing. Enables client.yjs with document and presence managers. See Y-Doc.

Conflict resolution

rebaseStrategy

Type: "server-wins" | "client-wins" | "merge": Default: "server-wins"

How the client resolves conflicts with concurrent server changes.

StrategyBehavior
"server-wins"Server changes take precedence. Client changes drop on conflict.
"client-wins"Client changes take precedence. Server changes are overridden.
"merge"Field-level merge. Non-conflicting fields from both sides are kept.

fieldLevelConflicts

Type: boolean: Default: true

Detect conflicts per-field rather than per-model. When enabled, non-overlapping field changes coexist without conflict.