import * as Y from "yjs"; import { type DbExec } from "../db/client.js"; import { type PatchOp } from "./json-to-yjs.js"; import { type LiveCopyBinding, type LiveCopyOutcome } from "./live-copy.js"; export declare class CollabBaseVersionConflictError extends Error { constructor(message: string); } export declare function computeTextEditDescriptor(oldText: string, newText: string): { kind: "text"; quote: string; } | { kind: "doc"; }; export interface PreparedYDocMutationLease { doc: Y.Doc; baseVersion: number | null; persist(transaction: DbExec, textSnapshot: string): Promise; } export declare function withPreparedYDocMutation(docId: string, requestSource: string | undefined, run: (lease: PreparedYDocMutationLease) => Promise): Promise; /** Refuses live copies with `read_refused`; read those with `readLiveCopy`. */ export declare function getDoc(docId: string): Promise; /** * Commits a client update. Once any live copy is defined, the result says * whether the app's rows were derived from it; with none defined it is * undefined, as before live copies existed. */ export declare function applyUpdate(docId: string, update: Uint8Array, requestSource?: string): Promise; export type LiveCopyRead = { kind: "absent"; } | { kind: "unseeded"; version: number; state: Uint8Array; } | { kind: "live"; version: number; state: Uint8Array; text: string; }; /** * The stored live copy and derive(state). Absent (no row), unseeded (a row * with nothing in the field, including a zero-byte state) and malformed * (throws `malformed_state`) are never conflated. */ export declare function readLiveCopy(binding: LiveCopyBinding, docId: string): Promise; export interface MutateLiveCopyOptions { /** * The name of an edit in the runner's module * (`defineLiveCopyTasks({ edits })`). It runs in the runner and is re-run * against fresh state after each version conflict. */ edit: string; /** Passed to the edit. */ input?: unknown; requestSource?: string; maxAttempts?: number; /** * Writes this call's own rows (say, claiming the suggestion the edit * applies) in the transaction that commits the edit, after the binding's * persist and before `_collab_docs`, so they commit or roll back together. * When the edit changes nothing it runs in a transaction of its own. A * throw reaches the caller and nothing is published. Re-run on each * version-conflict attempt. */ persist?(tx: DbExec, change: LiveCopyCallChange): Promise; } export interface LiveCopyCallChange { changed: boolean; /** The version this call leaves stored. */ version: number; /** derive(state) at that version. */ text: string; } export interface LiveCopyMutationResult extends LiveCopyOutcome { changed: boolean; /** The stored version after the call; an unchanged edit leaves it as is. */ version: number; state: Uint8Array; /** derive(state). */ text: string; /** What this call added to the state it edited. Empty when unchanged. */ update: Uint8Array; attempts: number; } /** * Applies a named edit to a seeded live copy and commits it with its derived * text, retrying on `_collab_docs.version` conflicts. Throws `not_seeded` * for an absent or unseeded copy; seed it with `seedLiveCopy` first. */ export declare function mutateLiveCopy(binding: LiveCopyBinding, docId: string, options: MutateLiveCopyOptions): Promise; export interface SeedLiveCopyOptions { /** Passed to the seed handler in the runner's module. */ source: string; requestSource?: string; } export interface LiveCopySeedResult extends LiveCopyOutcome { seeded: boolean; version: number; state: Uint8Array; /** derive(state). */ text: string; } /** * Seeds an absent or unseeded live copy from `source`. A live copy that * already has content comes back unchanged with `seeded: false`; malformed * stored state throws `malformed_state` and is never overwritten. */ export declare function seedLiveCopy(binding: LiveCopyBinding, docId: string, options: SeedLiveCopyOptions): Promise; export declare function seedXmlFragmentIfEmpty(docId: string, seedUpdate: Uint8Array, requestSource?: string): Promise<{ seeded: boolean; state: Uint8Array; }>; export type SnapshotAdoptionStatus = "adopted" | "already-adopted" | "rebase" | "stale"; /** * Takes a saved-body snapshot into the live doc at most once per revision. * Every open editor proposes the same change, and without one arbiter each * editor's inserts survive the merge, so the text appears once per editor. * * `adoptionUpdate` is the proposing editor's whole doc with the snapshot * taken in. A proposal built before the server took in another revision is * refused with `rebase`: its inserts would land beside that revision's. So is * one built on a doc missing live edits the server holds, which would put an * edit in a second time, or delete one the proposal never saw. * * `body` is the saved body at `revision`. The doc keeps it next to the * revision, so an editor that never saw that revision can still plan the next * one against it rather than against its own unsaved typing. */ export declare function adoptSnapshotOnce(docId: string, adoptionUpdate: Uint8Array, revision: string, options?: { isCurrent?: () => Promise | boolean; body?: string; requestSource?: string; }): Promise<{ status: SnapshotAdoptionStatus; state: Uint8Array; adoptedRevision: string | null; adoptedBody: string | null; }>; export declare function applyText(docId: string, newText: string, fieldName?: string, requestSource?: string, options?: { validateBase?: (base: string) => void; validateSnapshot?: (snapshot: string) => void; }): Promise; export declare function searchAndReplace(docId: string, find: string, replace: string, requestSource?: string): Promise<{ found: boolean; update: Uint8Array; }>; export declare function getText(docId: string, fieldName?: string): Promise; export declare function getState(docId: string): Promise; export declare function getIncUpdate(docId: string, clientStateVector: Uint8Array): Promise; export declare function seedFromText(docId: string, text: string, fieldName?: string, client?: DbExec): Promise; export declare function applyJson(docId: string, newJson: any, fieldName?: string, _type?: "map" | "array", requestSource?: string): Promise; export declare function applyPatchOps(docId: string, ops: PatchOp[], fieldName?: string, requestSource?: string): Promise; export declare function getJson(docId: string, fieldName?: string): Promise; export declare function seedFromJson(docId: string, json: any, fieldName?: string, type?: "map" | "array", client?: DbExec): Promise; /** Overwrites a document's stored state and text. Refuses live copies. */ export declare function saveYDocState(docId: string, state: Uint8Array, textSnapshot: string): Promise; export declare function releaseDoc(docId: string): void;