import { type Heads } from '@automerge/automerge'; import { type DocumentId } from '@automerge/automerge-repo'; import { Context, Resource } from '@dxos/context'; import { type DataService } from '@dxos/protocols/rpc'; import { type AutomergeHost } from '../automerge/index.ts'; export type DocumentsSynchronizerProps = { automergeHost: AutomergeHost; sendUpdates: (updates: DataService.BatchedDocumentUpdates) => void; /** Override of {@link MAX_BATCH_BYTES}. */ maxBatchBytes?: number; /** Override of {@link MAX_BATCH_DOCUMENTS}. */ maxBatchDocuments?: number; /** * A space directory's JSON at the heads its document is stored at, for answering a passive subscription that * holds nothing with the stored changes and that JSON, without loading the document. */ readDirectorySnapshot?: (documentId: DocumentId) => Promise<{ heads: Heads; json: string; } | undefined>; }; /** A document a client subscribes to, with the heads it already holds and whether it holds it unloaded. */ export type SubscribedDocument = { documentId: DocumentId; heads?: Heads; passive?: boolean; }; /** * Manages a connection and replication between worker's Automerge Repo and the client's Repo. */ export declare class DocumentsSynchronizer extends Resource { #private; private readonly _params; private readonly _syncStates; /** * Documents that have pending updates. * Used to batch updates. */ private readonly _pendingUpdates; /** * Documents whose on-disk probe completed negative and that need a * mutation-less `requesting: true` transition update sent to the client. * Cleared per-flush in `_checkAndSendUpdates`. */ private readonly _pendingRequesting; /** * Job that schedules if there are pending updates. */ private _sendUpdatesJob?; constructor(_params: DocumentsSynchronizerProps); /** * Test affordance: pause/resume flushing of document updates to the client. * See `#sendUpdatesPaused` for details. Idempotent. */ setSendUpdatesPaused(paused: boolean): void; /** * Subscribes the client to each document, from the heads it names so the first send is only what came * after. A document already subscribed switches to the given mode, and is sent from the heads it names, * or whole when it names none. A passive document is not loaded until storage moves past its heads. */ addDocuments(documents: readonly SubscribedDocument[]): Promise; /** Queues the initial send once the document is loaded, then lets go of it. */ private _sendWhenLoaded; /** * Probe local storage for the document; if not present, enqueue a * `requesting: true` transition update so the client moves the handle * from `'pending'` to `'requesting'` and disk-only callers can give up * without waiting on the network. If the doc became `ready` before the * probe completes (e.g. delivered concurrently by network/peer), no * transition update is sent. */ private _scheduleDiskProbe; holds(documentId: DocumentId): boolean; /** Drops the documents the client no longer subscribes to. */ removeDocuments(documentIds: DocumentId[]): void; protected _open(): Promise; protected _close(): Promise; update(ctx: Context, updates: DataService.DocumentUpdate[]): Promise; private _checkAndSendUpdates; private _getPendingChanges; private _writeMutation; } //# sourceMappingURL=documents-synchronizer.d.ts.map