import * as Y from 'yjs'; import { type YjsUpdateStore } from './yjs-provider.js'; export interface YjsFileBindingOptions { /** Debounce for the cloud -> disk write. */ debounceMs?: number; /** Idle debounce for the disk -> cloud append (DOU-377). Forwarded * to the provider; see YjsProviderOptions. */ appendDebounceMs?: number; /** Ceiling on how long an append may wait during continuous edits. */ appendMaxWaitMs?: number; /** Backlog size that triggers a compaction request. Forwarded to the * provider; see YjsProviderOptions. */ compactThreshold?: number; /** Upper bound of the random delay before a triggered compaction. */ compactJitterMs?: number; /** Ask the server to fold this file's update log. The provider counts * the backlog for free while loading and subscribing, but its trigger * is inert without this callback, so a binding that does not forward * one replays the file's entire edit history on every bind, forever. * Optional because the caller is the only one that can reach the * `compactYjsDoc` callable (it needs the org and file ids, which the * binding never sees). */ requestCompaction?: ((recordCount: number) => Promise) | null; onDiskWrite: (text: string) => void; onDocStateChange?: ((encoded: Uint8Array) => void) | null; initialDocState?: Uint8Array | null; currentDiskText?: string | null; } export declare class YjsFileBinding { readonly doc: Y.Doc; readonly ytext: Y.Text; private readonly store; private readonly provider; private readonly debounceMs; private readonly onDiskWrite; private readonly onDocStateChange; private readonly initialDocState; private readonly currentDiskText; private flushTimer; private lastDiskText; private observer; private stopped; constructor(store: YjsUpdateStore, { debounceMs, appendDebounceMs, appendMaxWaitMs, compactThreshold, compactJitterMs, requestCompaction, onDiskWrite, onDocStateChange, initialDocState, currentDiskText, }: YjsFileBindingOptions); start(): Promise; private _applyTextDiff; private _emitDocState; private _flushNow; applyDiskText(newText: string): void; /** Force the provider's coalesced appends out now. The daemon does * not need this on the happy path (the debounce handles it), but * shutdown, binding eviction, and tests all want a hard "everything * queued is now durable" point. */ flushPendingAppends(): Promise; /** Settle both directions, then stop. For evicting an *idle* binding * (DOU-378) as opposed to disposing a *deleted* file. * * Two things distinguish this from a bare `stop()`, and skipping either * is silent data loss: * * - `stop()` clears the debounced disk-write timer without running * it, so a remote update that arrived inside the last debounce * window would never reach disk. We flush it first. * - the caller must NOT delete the persisted Y.Doc state the way * `disposeBinding` does. That state is the DOU-209 offline-merge * baseline, and re-adopting this file later diffs disk against it. * Dropping it makes the next bind look like first contact, which * skips the disk merge entirely. * * `_flushNow()` also re-persists the state, so the baseline on disk * matches the text on disk at the moment we let go. */ drain(): Promise; stop(): Promise; } //# sourceMappingURL=yjs-file-binding.d.ts.map