/** * Server-side Yjs document manager with LRU caching and SQL persistence. * * Performance notes: * - `getDoc()` loads from the DB once on cache miss; subsequent calls return * the cached Y.Doc directly with no DB I/O. * - Mutations no longer call `applyStoredState()` unconditionally on every * write. The defensive re-read from the DB happens only inside * `persistMergedState` (needed for the CAS version read), not as a * separate SELECT before applying the new update. This removes the * redundant double-read that the previous implementation performed on * every write even on a hot cache. * - Compaction: when the stored blob is >4x the freshly encoded state, the * GC'd encoding is stored instead (removes accumulated Yjs tombstones, * preventing unbounded blob growth without any background jobs). */ import * as Y from "yjs"; import { type PatchOp } from "./json-to-yjs.js"; /** * Compute a small "what changed" descriptor from a text diff by trimming the * common prefix/suffix. Used for lingering edit highlights client-side. */ export declare function computeTextEditDescriptor(oldText: string, newText: string): { kind: "text"; quote: string; } | { kind: "doc"; }; /** * Get or load a Yjs document by ID. Creates a new empty doc if none exists. */ export declare function getDoc(docId: string): Promise; /** * Apply a binary Yjs update (from a client) to a document. * Persists the result and emits a change event. */ export declare function applyUpdate(docId: string, update: Uint8Array, requestSource?: string): Promise; /** * Apply a text change to a document. Computes the minimal diff and * converts it to Yjs operations. * * Returns the text snapshot after the update. */ export declare function applyText(docId: string, newText: string, fieldName?: string, requestSource?: string, options?: { /** * Validate the fully converged text after cross-process Yjs updates have * merged, but before the state is persisted or broadcast. A rejected * candidate is discarded from this process's cache so the next read * reloads the last durable state instead of leaking an uncommitted merge. */ validateSnapshot?: (snapshot: string) => void; }): Promise; /** * Search-and-replace text within a Y.XmlFragment (ProseMirror tree). * Produces minimal Yjs operations for cursor-preserving updates. * * Returns whether the text was found and the binary update. */ export declare function searchAndReplace(docId: string, find: string, replace: string, requestSource?: string): Promise<{ found: boolean; update: Uint8Array; }>; /** * Get the current text content of a document field. */ export declare function getText(docId: string, fieldName?: string): Promise; /** * Get the full document state as a Uint8Array. */ export declare function getState(docId: string): Promise; /** * Get an incremental update relative to a client's state vector. */ export declare function getIncUpdate(docId: string, clientStateVector: Uint8Array): Promise; /** * Seed a document from existing text content (for migration). * Only seeds if no collab state exists yet. */ export declare function seedFromText(docId: string, text: string, fieldName?: string): Promise; /** * Apply a full JSON update to a document. Computes the minimal diff * and converts it to Yjs operations on Y.Map/Y.Array. */ export declare function applyJson(docId: string, newJson: any, fieldName?: string, _type?: "map" | "array", requestSource?: string): Promise; /** * Apply surgical JSON patch operations to a document. */ export declare function applyPatchOps(docId: string, ops: PatchOp[], fieldName?: string, requestSource?: string): Promise; /** * Get the current JSON state of a document field. */ export declare function getJson(docId: string, fieldName?: string): Promise; /** * Seed a document from existing JSON content (for migration). * Only seeds if no collab state exists yet. */ export declare function seedFromJson(docId: string, json: any, fieldName?: string, type?: "map" | "array"): Promise; /** * Release a document from the in-memory cache. */ export declare function releaseDoc(docId: string): void; //# sourceMappingURL=ydoc-manager.d.ts.map