Skip to main content
Version: v10.5.2

SnapshotSyncOptions

Options of a snapshot sync, .sync(listener, { type: "snapshot" }) : a sync whose every event carries all rows of its filters. It serves queries like a loader, so a collection can load from a socket with no request.


Import
import { SnapshotSyncOptions } from "@hyper-fetch/db"

Preview​

type SnapshotSyncOptions<Row,Listener,Mapped,Fields,Listen> = {
listen?: Listen & SyncListen;
resumes?: boolean;
rows?: (message: SyncMessage<Listener>) => readonly Mapped[];
type: snapshot;
where?: SyncWhere<Row, Fields>;
}

Structure​

SnapshotSyncOptions
NameTypeDescription
listen
Listen & SyncListen

mounted , the default, listens while a query uses the sync. always listens from createDb on, for a server that sends the snapshot once when the socket connects. A sync with where cannot always listen.

resumes
boolean

The adapter resumes the subscription from its last event id after a reconnect, so nothing is missed

type
snapshot

Every message carries all rows of the sync's filters, so the sync loads the collection without a loader

where
SyncWhere<Row, Fields>

Filters a query must set with eq , mapped to listener params or a subscription payload. Each set of values has its own subscription and its own snapshot. Without it, the snapshot holds every row of the collection.

rows
(message: SyncMessage<Listener>) => readonly Mapped[]

Reads the complete rows from a message, for example from a wrapped list such as { items } . Without it, the message is the list of rows.