Skip to content

Reference

Client API

Complete reference for the @syndra/client package.

On this page

createClient

Creates a client instance. You typically create one per app and share it.

ts
function createClient(options: ClientOptions): SyndraClient
Option Type Default Description
project string — Required. Your project id.
publicKey string — Required. The project’s public key.
auth () => Promise<string> undefined Returns a user token. See Authentication.
storage StorageAdapter memory() Where replicas are persisted.
region string 'auto' Pin connections to a region.
logLevel 'silent' | 'warn' | 'debug' 'warn' Console verbosity.

client.doc

Opens a document by path.

ts
client.doc<T>(path: string, options?: { initial?: T }): Doc<T>;

doc.get

Returns the current merged state synchronously.

doc.update

ts
doc.update(recipe: (draft: T) => void, options?: { origin?: string }): void;

Applies a change. Pass an origin to tag the change useful for skipping your own updates in subscribe.

doc.subscribe

ts
doc.subscribe(listener: (state: T, meta: ChangeMeta) => void): () => void;
doc.subscribe<S>(selector: (state: T) => S, listener: (slice: S) => void): () => void;

Returns an unsubscribe function.

doc.history

Undo and redo local changes. Remote changes are never undone.

ts
doc.history.undo()
doc.history.redo()
doc.history.canUndo // boolean

client.channel

Opens a channel for ephemeral messages.

ts
client.channel<Events>(path: string): Channel<Events>;

client.status

A store with the connection status: 'online', 'connecting' or 'offline'.

client.disconnect

Closes the connection. Local reads and writes continue to work and sync on client.connect().