/** * OPERATIONAL TRANSFORM (OT) ENGINE * Core collaborative editing algorithm with CRDT principles * * Features: * - Insert/Delete/Replace operations * - Transformation to resolve conflicts * - Vector clock versioning * - Operation history/undo * - Commutative & idempotent operations */ import type { DocumentId, OTOperation, OperationId, UserId, VectorClock } from '@materi.ai/frame/core/types'; export type { DocumentId, OTOperation, OperationId, UserId, VectorClock }; /** * Operation type definitions */ export type OperationType = 'insert' | 'delete' | 'retain' | 'replace'; /** * Transform a sequence of operations against another sequence * Returns the transformed operations */ export declare function transformSequence(ops1: OTOperation[], ops2: OTOperation[]): OTOperation[]; /** * Transform two concurrent operations symmetrically * Returns transformed versions of both operations */ export declare function transformOperations(localOp: OTOperation, remoteOp: OTOperation): { local: OTOperation; remote: OTOperation; }; /** * Transform two concurrent operations to resolve conflicts * Returns transformed version of op2 that accounts for op1 */ export declare function transformOperation(op1: OTOperation, op2: OTOperation): OTOperation; /** * Apply operation to document content * Returns new content after operation applied */ export declare function applyOperation(content: string, operation: OTOperation): string; /** * Increment vector clock for user */ export declare function incrementVectorClock(clock: VectorClock, userId: UserId): VectorClock; /** * Compare vector clocks * -1: vc1 < vc2, 0: equal, 1: vc1 > vc2, null: concurrent */ export declare function compareVectorClocks(vc1: VectorClock, vc2: VectorClock): -1 | 0 | 1 | null; /** * Check if operation happened before another (causality) */ export declare function happensBefore(op1: OTOperation, op2: OTOperation): boolean; /** * Operation history manager * Tracks operations, provides undo/redo, conflict resolution */ export declare class OperationHistory { private operations; private documentId; private maxHistorySize; constructor(documentId: DocumentId, maxSize?: number); /** * Add operation to history */ addOperation(operation: OTOperation): void; /** * Get all operations since specific version */ getOperationsSince(vectorClock: VectorClock): OTOperation[]; /** * Get operation by ID */ getOperation(opId: OperationId): OTOperation | undefined; /** * Get all operations */ getAllOperations(): OTOperation[]; /** * Clear history */ clear(): void; /** * Get history size */ size(): number; } /** * Apply list of operations in order */ export declare function applyOperations(initialContent: string, operations: OTOperation[]): string; /** * Inverse operation (undo) */ export declare function inverseOperation(operation: OTOperation): OTOperation; /** * Compose operations: combine consecutive operations * Returns single operation representing both operations */ export declare function composeOperations(op1: OTOperation, op2: OTOperation): OTOperation; /** * Convert diff between two strings into OT operations * Uses simple character-by-character comparison */ export declare function diffToOperations(before: string, after: string, userId: UserId, baseVersion: number): OTOperation[]; //# sourceMappingURL=index.d.ts.map