createNizhalClient
Copy page
import { createNizhalClient } from "@nizhal/db-collection";
const echo = createNizhalClient({ server: "http://localhost:4000", auth: { getHeaders: () => ({ Authorization: `Bearer ${token}` }), refresh: async () => { /* optional token rotation */ }, }, bucketsForSyncRule: (rule) => { if (rule === "myNotes") return [{ ownerId: session.ownerId }]; return []; }, subscribeSource, // optional — defaults to PartySocket reconnect, // jitter + catch-up pull on reconnect ttl, // evict out-of-scope bucket rows locally pull: { intervalMs: 30_000 }, // optional fallback pull presence, // heartbeat interval status, // SyncStatus + outbox inspection});Methods
Section titled “Methods”pull,push— direct HTTP (collections use these viaSyncConfig)subscribe— WS bucket pingstrack/untrack,presenceState,onPresence— presence v2- Cursor and scope helpers for advanced wiring
Reconnect
Section titled “Reconnect”On WS reconnect, the client runs a catch-up pull. Combined with pull.intervalMs, convergence does not depend on every ping arriving.
Cloudflare client
Section titled “Cloudflare client”import { createCloudflareSubscribeSource } from "@nizhal/db-collection";Use when the server exposes the Cloudflare DO WebSocket URL shape.
React Native
Section titled “React Native”Prefer createNizhalNitroClient from @nizhal/react-native — see React Native.