Hooks to the local cache of the client.

Every method may be synchronous or return a promise, the synchronizer awaits the result before moving the cursor further.

interface MessagesSyncStore {
    applyMessages(update): void | Promise<void>;
    getCachedRanges?(entity): CachedWindow[] | Promise<CachedWindow[]>;
    getCachedWindow?(entity): CachedWindow | Promise<CachedWindow>;
    getCursors(): StoredCursor[] | Promise<StoredCursor[]>;
    saveCursor(cursor): void | Promise<void>;
}

Methods

  • Upsert messages by id. Called once per difference page, and once per entity on a full resync.

    Parameters

    Returns void | Promise<void>

  • Every interval of the entity the client holds, for a cache that is not one contiguous range: a jump to a search result or to a quotation leaves the cache with a hole no single window can describe.

    Read once per entity and per synchronization run, exactly like getCachedWindow, and takes priority over it. The intervals must be sorted by CachedWindow.from and must not overlap, and there must be at most MAX_CACHED_RANGES of them: the client collapses the excess ones by gluing the small holes shut, which always widens the coverage rather than narrows it.

    An interval must not appear here before its messages are loaded. The cursor of the entity has long passed the journal records of a newly cached range, so the difference will never return them and the protocol carries no sign of the loss: a range joins the coverage and gets loaded by a MessagesSyncApi.loadMessages of its own as a single operation. Dropping a range out of the coverage needs no such care.

    Parameters

    Returns CachedWindow[] | Promise<CachedWindow[]>

  • Bounds of the contiguous range of messages the client holds for the entity, read once per entity and per synchronization run.

    Changes outside the window are not sent: the client has nothing to update, and it will read that range in its current state whenever it loads it. Not implementing the method means the whole history, which is only correct for a client that caches entities in full.

    Ignored when getCachedRanges is implemented.

    Parameters

    Returns CachedWindow | Promise<CachedWindow>

  • Persist the new cursor of an entity. Called after the whole difference page is applied.

    Parameters

    Returns void | Promise<void>