Skip to content

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
});
  • pull, push — direct HTTP (collections use these via SyncConfig)
  • subscribe — WS bucket pings
  • track / untrack, presenceState, onPresence — presence v2
  • Cursor and scope helpers for advanced wiring

On WS reconnect, the client runs a catch-up pull. Combined with pull.intervalMs, convergence does not depend on every ping arriving.

import { createCloudflareSubscribeSource } from "@nizhal/db-collection";

Use when the server exposes the Cloudflare DO WebSocket URL shape.

Prefer createNizhalNitroClient from @nizhal/react-native — see React Native.