import * as Y from "yjs"; export interface YjsProviderOptions { /** Idle ms before a coalesced flush. 0 flushes on the next tick. */ appendDebounceMs?: number; /** Max ms a queued update may wait while edits keep arriving. */ appendMaxWaitMs?: number; /** Compact once this many records sit past the baseline. 0 disables * the automatic trigger (DOU-391). */ compactThreshold?: number; /** Upper bound of the random delay before an automatic compaction, so * every client holding the file open does not compact at the same * instant. Set 0 in tests. */ compactJitterMs?: number; /** Ask the server to fold the log. Clients cannot do it themselves * since DOU-409 — the rules no longer grant `delete` on yupdates or * write on yjs/state, so compaction is the `compactYjsDoc` callable * running on the admin SDK. Without this the provider counts the * backlog and never acts on it. */ requestCompaction?: (recordCount: number) => Promise; } import type { Snapshot, UpdateRecord, UpdateStore } from '@doubling/types'; export type YjsUpdateRecord = UpdateRecord; export type YjsSnapshot = Snapshot; export type YjsUpdateStore = UpdateStore; export type YjsUpdateListener = (record: UpdateRecord) => void; export declare class YjsProvider { private readonly doc; private readonly store; private unsubscribeStore; private updateHandler; private loaded; private subscribed; private stopped; private baselineId; private readonly appendDebounceMs; private readonly appendMaxWaitMs; private pendingAppends; private idleTimer; private maxWaitTimer; private flushChain; private readonly compactThreshold; private readonly compactJitterMs; private recordsSinceBaseline; private compactTimer; private compacting; private readonly requestCompaction; constructor(doc: Y.Doc, store: YjsUpdateStore, options?: YjsProviderOptions); /** Phase 1: snapshot + initial updates → Y.Doc. No remote * subscription yet. Callers that intend to attach a Y.Text observer * (e.g. a disk-write debouncer here, yCollab on the web) should * install that observer between `loadInitial()` and * `startSubscription()` so the first remote update routes through * to it instead of mutating Y.Text silently in the gap (DOU-204). */ loadInitial(): Promise; /** Phase 2: subscribe to remote updates and push local Y.Doc * mutations back to the store. */ startSubscription(): void; /** Buffer an update and (re)arm the coalescing timers (DOU-377). */ private queueAppend; private clearAppendTimers; /** Merge and append everything queued. Safe after `stop()` and after * the Y.Doc has been destroyed: the queue holds encoded bytes, not * doc state. Never rejects — a failed append is requeued so the next * successful flush carries it forward. */ flushPendingAppends(): Promise; /** Number of updates waiting to be flushed. Tests/diagnostics. */ get pendingAppendCount(): number; /** Convenience: load + subscribe in one call. Use only when no * view-layer observer needs to attach between the phases. */ start(): Promise; /** Detach from the store and the doc, draining the coalesce queue on * the way out (fire-and-forget). Callers that can await should * `await flushPendingAppends()` first for a durability guarantee — * `YjsFileBinding.stop()` does. */ stop(): void; /** Arm a jittered compaction once the backlog crosses the threshold. * Best-effort: a failure leaves the log intact and the next trigger * retries (DOU-391). */ private maybeScheduleCompaction; /** Records past the current baseline. For tests and diagnostics. */ get recordsSinceBaselineCount(): number; compact(): Promise; private runCompaction; } //# sourceMappingURL=yjs-provider.d.ts.map