Something went wrong. Try again.
Local-first knowledge base made for Typst and the Atmosphere. typbase.at
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435import type { SyncHost } from "@typbase/spaces";import type { WorkspaceStore } from "@typbase/storage";
/** * SyncHost implementation over the local store. The engine deals in bytes * and version strings. This is where Loro docs come in. All the version math * (JSON version vectors) belongs to the store. */export function createSyncHost( store: WorkspaceStore, log: SyncHost["engineLog"], onImported?: (docIds: string[]) => void,): SyncHost { return { listDocIds: () => store.listDocIds(), exportUpdatesSince: (docId, sinceVersion) => store.exportUpdatesSince(docId, sinceVersion), exportSnapshot: (docId) => store.exportDocSnapshot(docId), importUpdate: async (docId, bytes) => { await store.importDocBytes(docId, bytes); }, importSnapshot: async (docId, bytes) => { await store.importDocBytes(docId, bytes); }, localVersion: (docId) => store.getDocVersion(docId), onImported: (docIds) => { // The store's own subscriptions already refresh open editors. The // event exists for side systems like the search index that watch from // outside (settings, palette, query cache). onImported?.(docIds); window.dispatchEvent(new CustomEvent("typbase:imported", { detail: docIds })); }, engineLog: log, };}