import type { VerificationDigest } from './types.js'; /** Nonnegative Int64 decimal string, never a JS number. Sequence orders content; time does not. */ export type HistoryPosition = string; export interface HistoryBlobReference { digest: VerificationDigest; length: number; } export interface HistoryHead { revision: HistoryPosition; state: HistoryBlobReference; } export interface HistoryHeadInitializationResult { initialized: boolean; head: HistoryHead; } export interface DocxHistoryArchiveInfo { documentId: string; head: HistoryHead; blobCount: number; totalBlobBytes: HistoryPosition; } export interface DocxHistoryImportResult { archive: DocxHistoryArchiveInfo; view: DocxHistoryView; alreadyPresent: boolean; } export declare const MAX_HISTORY_ARCHIVE_BYTES: number; export interface HistoryRequestIdentity { id: string; fingerprint: VerificationDigest; } export interface HistoryRequestJournal { documentId: string; revision: HistoryPosition; index: HistoryBlobReference | null; current: HistoryRequestIdentity | null; } export interface DocxSnapshotReference { blob: HistoryBlobReference; contentDigest: VerificationDigest; } export interface DocxVersionMetadata { author: string; createdAt: string; label?: string | null; message?: string | null; applicationMetadata?: Readonly>; } export interface DocxVersionRecord { documentId: string; metadata: DocxVersionMetadata; nonce: string; parent: HistoryBlobReference | null; restoredFrom: HistoryBlobReference | null; sequence: HistoryPosition; snapshot: DocxSnapshotReference; } export interface DocxStoredVersion { id: HistoryBlobReference; record: DocxVersionRecord; } export interface DocxHistoryState { requests?: HistoryRequestJournal; parentPublication?: HistoryHead; operation?: HistoryBlobReference; commit: HistoryBlobReference | null; documentId: string; epoch: HistoryPosition; initialSnapshot: DocxSnapshotReference; sequence: HistoryPosition; snapshot: DocxSnapshotReference; version: HistoryBlobReference; } export interface DocxHistoryView { head: HistoryHead; state: DocxHistoryState; version: DocxStoredVersion; } export interface DocxVersionPage { versions: DocxStoredVersion[]; next: HistoryBlobReference | null; } export interface PackageHistoryCommit { after: DocxSnapshotReference; before: DocxSnapshotReference; contribution: HistoryBlobReference | null; documentId: string; epoch: HistoryPosition; kind: 'import' | 'restore'; parent: HistoryBlobReference | null; sequence: HistoryPosition; version: HistoryBlobReference; } export interface DocxHistoryLogEntry { id: HistoryBlobReference; commit: PackageHistoryCommit; metadata: DocxVersionMetadata; } export interface DocxHistoryUpdate { after: HistoryHead | null; view: DocxHistoryView; entries: DocxHistoryLogEntry[]; reset: boolean; } export interface DocxTextSplice { partUri: string; textNode: number; offset: number; deleteCount: number; insert: string; } export interface DocxOperationRequest { requestId: string; base: HistoryHead; kind: 'text' | 'package' | 'discard'; metadata: DocxVersionMetadata; text: DocxTextSplice | null; readParts: string[]; resolves: HistoryBlobReference | null; } export interface DocxOperationInput { documentId: string; request: DocxOperationRequest; candidate: HistoryBlobReference | null; } export interface DocxOperationRecord { documentId: string; input: HistoryBlobReference; parent: HistoryBlobReference | null; revision: HistoryPosition; before: HistoryHead; proposedSnapshot: DocxSnapshotReference; afterSnapshot: DocxSnapshotReference; version: HistoryBlobReference; contentCommit: HistoryBlobReference | null; status: 'accepted' | 'conflict'; conflict: string | null; appliedText: DocxTextSplice | null; } export interface DocxStoredOperation { id: HistoryBlobReference; record: DocxOperationRecord; input: DocxOperationInput; } export interface DocxOperationUpdate { after: HistoryHead | null; view: DocxHistoryView; operations: DocxStoredOperation[]; } /** Host-owned storage. Persist blobs before returning; advanceHead must be an atomic CAS. * References and returned bytes are verified in the core. Methods must settle their promises. * No fetching, subscription, timer, authorization or retention policy is supplied by this API. */ export interface HistoryStorage { readBlob(reference: HistoryBlobReference): Promise; putBlob(reference: HistoryBlobReference, bytes: Uint8Array): Promise; readHead(documentId: string): Promise; advanceHead(documentId: string, expected: HistoryHead | null, state: HistoryBlobReference): Promise; /** Optional import capability. Atomically insert the exact head only if absent; otherwise return * the unchanged existing head. Must share exclusion with advanceHead, never overwrite/revise it. */ initializeHead?(documentId: string, head: HistoryHead): Promise; } export interface HistoryBridge { Open(adapterId: number): number; OpenWithInitialization?(adapterId: number): number; OpenArchive?(bytes: Uint8Array): Promise; Close(handle: number): void; Invoke(handle: number, requestJson: string, bytes: Uint8Array): Promise; } export declare class DocxHistoryError extends Error { readonly code: string; constructor(code: string, message: string); } interface Result { handle: number | null; archive: DocxHistoryArchiveInfo | null; import: DocxHistoryImportResult | null; success: boolean; errorCode: string | null; message: string | null; view: DocxHistoryView | null; version: DocxStoredVersion | null; page: DocxVersionPage | null; sequence: HistoryPosition | null; bytes: string | null; update: DocxHistoryUpdate | null; operationUpdate: DocxOperationUpdate | null; operation: DocxStoredOperation | null; } /** For custom WASM loaders. initialize() installs these automatically. */ export declare function installHistoryStorageImports(setModuleImports: (name: string, imports: object) => void): void; /** Durable package-history client. Reopening over the same adapters preserves history. * Await active calls before close(); it releases handles but never deletes host data. */ export declare class DocxHistoryClient { private readonly bridge; private readonly adapterId; private readonly handle; private closed; constructor(bridge: HistoryBridge, storage: HistoryStorage); close(): void; /** Bind an identity without reading, creating a version, or taking ownership of this client. */ document(documentId: string): DocxHistoryDocument; exportHistoryArchive(documentId: string): Promise; importHistoryArchive(bytes: Uint8Array): Promise; read(documentId: string): Promise; /** Host-triggered validated metadata tail; first join starts at the latest checkpoint. */ readChangesSince(documentId: string, after: HistoryHead | null, maxEntriesToScan?: number): Promise; readOperationsSince(documentId: string, after: HistoryHead | null, maxEntriesToScan?: number): Promise; getOperation(documentId: string, operationId: HistoryBlobReference): Promise; exportOperationProposal(documentId: string, operationId: HistoryBlobReference): Promise; compareVersions(documentId: string, beforeVersionId: HistoryBlobReference, afterVersionId: HistoryBlobReference): Promise; createVersion(documentId: string, expectedHead: HistoryHead | null, bytes: Uint8Array, metadata: DocxVersionMetadata, requestId?: string): Promise; listVersions(documentId: string, cursor?: HistoryBlobReference | null, limit?: number): Promise; getVersion(documentId: string, versionId: HistoryBlobReference): Promise; exportVersion(documentId: string, versionId: HistoryBlobReference): Promise; materialize(documentId: string, sequence: HistoryPosition, maxEntriesToScan?: number): Promise; replay(documentId: string, sequence: HistoryPosition, maxEntriesToScan?: number): Promise; resolveSequenceAtTime(documentId: string, cutoff: string, maxEntriesToScan?: number): Promise; restoreVersion(documentId: string, expectedHead: HistoryHead, versionId: HistoryBlobReference, metadata: DocxVersionMetadata, requestId?: string): Promise; private call; } type HistoryCall = (operation: string, fields?: object, bytes?: Uint8Array) => Promise; /** Document-scoped reads. No method publishes or changes an editor. */ export declare class DocxHistoryReader { #private; protected readonly call: HistoryCall; get documentId(): string; /** @internal Obtain through client.document() or openDocxHistoryArchive(). */ constructor(documentId: string, call: HistoryCall); read(): Promise; listVersions(cursor?: HistoryBlobReference | null, limit?: number): Promise; getVersion(versionId: HistoryBlobReference): Promise; /** Omit versionId for latest; pass an ID to keep a UI operation pinned to a captured version. */ exportDocx(versionId?: HistoryBlobReference | null): Promise; exportHistoryArchive(): Promise; materialize(sequence: HistoryPosition, maxEntriesToScan?: number): Promise; replay(sequence: HistoryPosition, maxEntriesToScan?: number): Promise; resolveSequenceAtTime(cutoff: string, maxEntriesToScan?: number): Promise; readChangesSince(after: HistoryHead | null, maxEntriesToScan?: number): Promise; readOperationsSince(after: HistoryHead | null, maxEntriesToScan?: number): Promise; getOperation(operationId: HistoryBlobReference): Promise; exportOperationProposal(operationId: HistoryBlobReference): Promise; /** Redlined DOCX through DocxCompare's existing accepted-input revision policy. */ compareVersions(beforeVersionId: HistoryBlobReference, afterVersionId: HistoryBlobReference): Promise; } /** Explicit checkpoint/restore controls over host-owned storage; request IDs are required here. */ export declare class DocxHistoryDocument extends DocxHistoryReader { createVersion(expectedHead: HistoryHead | null, bytes: Uint8Array, metadata: DocxVersionMetadata, requestId: string): Promise; restoreVersion(expectedHead: HistoryHead, versionId: HistoryBlobReference, metadata: DocxVersionMetadata, requestId: string): Promise; } /** Standalone readonly file. Owns its handle and captured bytes; await calls before close(). */ export declare class DocxHistoryArchive extends DocxHistoryReader { private readonly bridge; private readonly handle; readonly info: DocxHistoryArchiveInfo; private closed; private constructor(); /** For custom loaders; normal callers use openDocxHistoryArchive(). */ static open(bridge: HistoryBridge, bytes: Uint8Array): Promise; close(): void; } /** Reference process-local storage. Share one instance among local clients; it is not durable * across a page/process restart. Every incoming blob is copied and SHA-256 verified. */ export declare function createMemoryHistoryStorage(maxBlobBytes?: number): HistoryStorage; export {}; //# sourceMappingURL=history.d.ts.map