@searsuite/sear-domain-ot
Operations and transforms
TransactionOTRegistry chooses the transform for concurrent operations. Use the built-in registry when a host must rebase local and remote changes.
- enumOTTransformPriority
-
Tie-break direction used when two concurrent operations target the same position.
enum member LEFT: "left"enum member RIGHT: "right" - classBaseOT
-
Base class for Operational Transformation implementations.
Concrete domains provide the actual apply, append, compose, and transform semantics while sharing validation and creation helpers here.
constructor BaseOT(name: string): BaseOTConstructs an OT implementation descriptor.
nameStable implementation name.
property readonly name: stringHuman-readable OT implementation name for diagnostics and debugging.
method append(destination: OTOperation[], current: OTOperation): voidstaticAppends one operation into a composed destination list.
ThrowsSearError until implemented by a concrete OT class.
method apply(snapshot: unknown, operations: OTOperation[]): voidstaticApplies operations to a domain snapshot.
ThrowsSearError until implemented by a concrete OT class.
method checkValidOp(operations: OTOperation[]): voidstaticValidates the structural contract common to all operations.
ThrowsSearError when an operation is missing its path.
operationsOperations that must each carry an array path.
method compose(operation1: OTOperation[], operation2: OTOperation[]): OTOperation[]staticComposes two sequential operation lists into one equivalent list.
ThrowsSearError until implemented by a concrete OT class.
method create(data?: OTOperation[]): OTOperation[]staticCreates an operation list snapshot.
ReturnsA mutable operation list detached from the caller's array.
dataOptional operations to clone into the new list.
method transform(operation: OTOperation[], otherOperation: OTOperation[], type: OTTransformPriority): OTOperation[]staticTransforms an operation list against concurrent operations.
ThrowsSearError until implemented by a concrete OT class.
- classTransactionOTError
-
class TransactionOTError extends SearErrorPublic error for invalid or unavailable transaction OT behavior.
constructor TransactionOTError(code: TransactionOTErrorCode, message: string, details?: SearErrorDetails): TransactionOTErrorproperty readonly code: TransactionOTErrorCodeStable machine-readable identifier for this error category.
Inherited members 9
Inherited from SearError.
- classTransactionOTRegistry
-
Local registry of versioned OT families and explicit pair transformations.
constructor TransactionOTRegistry(): TransactionOTRegistrymethod decode(id: string, version: number, payload: unknown): OTOperation[]Decodes a wire payload through its registered family definition.
method destroy(): voidPermanently clears the registry.
method encode<OperationType>(definition: TransactionOTDefinition<OperationType>, operations: readonly OperationType[]): OTEncodedValueEncodes and validates one operation family payload.
method invert<OperationType>(definition: TransactionOTDefinition<OperationType>, operations: readonly OperationType[]): OperationType[]Inverts operations through their family definition.
method registerIndependent(left: TransactionOTDefinition, right: TransactionOTDefinition): (): voidRegisters two families as independent, so pair transformation is explicit identity.
method registerRelation<Left, Right>(relation: OTTransformRelation<Left, Right>): (): voidRegisters one explicit relation. Reverse lookup uses the same implementation with swapped branches.
method registerType<OperationType>(definition: TransactionOTDefinition<OperationType>): (): voidRegisters one operation family and returns an idempotent disposer.
method requireType(id: string, version: number): TransactionOTDefinitionResolves a registered operation family.
method transformPair<Left, Right>(leftDefinition: TransactionOTDefinition<Left>, leftOperations: readonly Left[], rightDefinition: TransactionOTDefinition<Right>, rightOperations: readonly Right[], priority: OTTransformPriority): OTTransformPair<Left, Right>Rebases two concurrent operation lists through their registered relation.
- interfaceOTOperation
-
Minimal operation contract shared by every domain OT implementation.
property p: OTOperationPathPath locating the operation target inside the snapshot.
- interfaceOTTransformPair
-
interface OTTransformPair<Left, Right>Pair transformation result preserving both concurrent branches.
property readonly left: Left[]property readonly right: Right[] - interfaceOTTransformRelation
-
interface OTTransformRelation<Left, Right>Domain-specific transformation relation between two operation families.
- interfaceTransactionOTDefinition
-
interface TransactionOTDefinition<OperationType>Stable, versioned operation family shared by history and collaboration.
- typeOperation
-
type Operation = MatrixOTOperation<unknown> | UpdateRectOTOperation | RichDocOTOperationBuilt-in operation union. Third-party callers use OTOperation as their open base contract.
- typeOTEncodedValue
-
type OTEncodedValue = null | boolean | number | string | readonly OTEncodedValue[] | { }JSON-compatible values accepted by collaboration transports.
- typeTransactionOTErrorCode
-
type TransactionOTErrorCode = typeof TransactionOTErrorCode[keyof typeof TransactionOTErrorCode]TransactionOTErrorCode: { InvalidDefinition: "SEAR_TRANSACTION_OT_INVALID_DEFINITION"; InvalidPayload: "SEAR_TRANSACTION_OT_INVALID_PAYLOAD"; InvertUnsupported: "SEAR_TRANSACTION_OT_INVERT_UNSUPPORTED"; RegistryDestroyed: "SEAR_TRANSACTION_OT_REGISTRY_DESTROYED"; RelationConflict: "SEAR_TRANSACTION_OT_RELATION_CONFLICT"; RelationNotRegistered: "SEAR_TRANSACTION_OT_RELATION_NOT_REGISTERED"; TypeConflict: "SEAR_TRANSACTION_OT_TYPE_CONFLICT"; TypeNotRegistered: "SEAR_TRANSACTION_OT_TYPE_NOT_REGISTERED" }Stable errors raised by transaction OT definitions and registries.
- variableMatrixTransactionOT
-
MatrixTransactionOT: TransactionOTDefinition<MatrixOTOperation<unknown>>Built-in MatrixOT family shared by matrix-backed transaction owners.
- variableMatrixTransactionOTRelation
-
MatrixTransactionOTRelation: OTTransformRelation<MatrixOTOperation<unknown>, MatrixOTOperation<unknown>>Matrix-to-matrix pair transformation used by every matrix-backed owner.
- variableRichDocTransactionOT
-
RichDocTransactionOT: TransactionOTDefinition<RichDocOTOperation>Built-in rich-document operation family.
- variableRichDocTransactionOTRelation
-
RichDocTransactionOTRelation: OTTransformRelation<RichDocOTOperation, RichDocOTOperation>Rich-document pair transformation.
- functioncreateBuiltinTransactionOTRegistry
-
createBuiltinTransactionOTRegistry(): TransactionOTRegistryCreates an isolated registry containing all built-in OT definitions and relations.
- functiongetAllActionNames
-
getAllActionNames(): Set<string>Returns a Set of all known OT action name strings. Used by the engine to identify which action types are present in an operation.
- functionOTClone
-
OTClone<T>(object: T): TDeep-clones JSON-compatible OT payloads before mutation or composition.
- functiontransactionOTTypeKey
-
transactionOTTypeKey(definition: Pick<TransactionOTDefinition, "id" | "version">): stringReturns the wire identity of one versioned OT family.
Row and column operations
- interfaceDeleteColOTOperation
-
interface DeleteColOTOperation<T> extends OTOperationDeletes one column and carries the deleted column payload for inversion.
property cd: T | null[]property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
- interfaceDeleteRowOTOperation
-
interface DeleteRowOTOperation<T> extends OTOperationDeletes one row and carries the deleted row payload for inversion.
property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
property rd: T | null[] - interfaceInsertColOTOperation
-
interface InsertColOTOperation<T> extends OTOperationInserts one column at the target column index.
property ci: T | null[]property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
- interfaceInsertRowOTOperation
-
interface InsertRowOTOperation<T> extends OTOperationInserts one row at the target row index.
property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
property ri: T | null[] - interfaceMoveColOTOperation
-
interface MoveColOTOperation<T> extends OTOperationExchanges the column at the path index with the column index encoded by cm.
property cm: MatrixOTOperationPathproperty p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
- interfaceMoveRowOTOperation
-
interface MoveRowOTOperation<T> extends OTOperationExchanges the row at the path index with the row index encoded by rm.
property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
property rm: MatrixOTOperationPath - interfaceResizeColOTOperation
-
interface ResizeColOTOperation extends OTOperationUpdates one column dimension in a dimension matrix.
property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
property rc: { prev: number | null; value: number | null } - interfaceResizeRowOTOperation
-
interface ResizeRowOTOperation extends OTOperationUpdates one row dimension in a dimension matrix.
property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
property rr: { prev: number | null; value: number | null } - typeMatrixStructureOTOperation
-
type MatrixStructureOTOperation = InsertRowOTOperation<T> | DeleteRowOTOperation<T> | MoveRowOTOperation<T> | InsertColOTOperation<T> | DeleteColOTOperation<T> | MoveColOTOperation<T>Structural matrix operations that shift row or column coordinates.
- functioncreateDeleteColOTOperation
-
createDeleteColOTOperation<T>(path: readonly number[], values: readonly T | null[]): DeleteColOTOperation<T>Creates a semantic column-delete operation carrying the deleted values required for inversion.
- functioncreateDeleteRowOTOperation
-
createDeleteRowOTOperation<T>(path: readonly number[], values: readonly T | null[]): DeleteRowOTOperation<T>Creates a semantic row-delete operation carrying the deleted values required for inversion.
- functioncreateInsertColOTOperation
-
createInsertColOTOperation<T>(path: readonly number[], values: readonly T | null[]): InsertColOTOperation<T>Creates a semantic column-insert operation without changing the MatrixOT wire shape.
- functioncreateInsertRowOTOperation
-
createInsertRowOTOperation<T>(path: readonly number[], values: readonly T | null[]): InsertRowOTOperation<T>Creates a semantic row-insert operation without changing the MatrixOT wire shape.
- functioncreateMoveColOTOperation
-
createMoveColOTOperation(path: readonly number[], destination: readonly number[]): MoveColOTOperation<unknown>Creates a semantic column-move operation.
- functioncreateMoveRowOTOperation
-
createMoveRowOTOperation(path: readonly number[], destination: readonly number[]): MoveRowOTOperation<unknown>Creates a semantic row-move operation.
- functioncreateResizeColOTOperation
-
createResizeColOTOperation(path: readonly number[], value: number | null, previousValue: number | null): ResizeColOTOperationCreates a semantic column-resize operation.
- functioncreateResizeRowOTOperation
-
createResizeRowOTOperation(path: readonly number[], value: number | null, previousValue: number | null): ResizeRowOTOperationCreates a semantic row-resize operation.
- functionisMatrixStructureOperation
-
isMatrixStructureOperation<T>(operation: OTOperation): operationNarrows an OT operation to one of the row or column structure operations.
- functionisResizeColOperation
-
isResizeColOperation(operation: OTOperation): operationNarrows an OT operation to a column-resize operation with a present action payload.
- functionisResizeRowOperation
-
isResizeRowOperation(operation: OTOperation): operationNarrows an OT operation to a row-resize operation with a present action payload.
Cell and rectangle operations
- enumMatrixOTActionName
-
Compact command keys persisted in matrix OT payloads.
enum member ColDelete: "cd"enum member ColInsert: "ci"enum member ColMove: "cm"enum member ResizeCol: "rc"enum member ResizeRow: "rr"enum member RowDelete: "rd"enum member RowInsert: "ri"enum member RowMove: "rm"enum member UpdateCell: "uc" - enumRectOTActionName
-
Compact command keys persisted in rectangle OT payloads.
enum member UpdateRect: "ur" - classMatrixOT
-
class MatrixOT extends BaseOTOperational Transformation implementation for CSRMatrix-backed sheet state.
MatrixOT owns cell updates, row/column structure edits, dimension resize operations, and the transform rules that keep concurrent matrix changes convergent.
constructor MatrixOT(): MatrixOTCreates a MatrixOT descriptor for diagnostics and shared OT registries.
method append<U>(destination: MatrixOTOperation<U>[], current: MatrixOTOperation<U>): voidstaticAppends one component into a composed matrix operation list.
destinationComposition destination mutated in place.
currentOperation to append.
method apply<U, S>(snapshot: S, operations: MatrixOTOperation<U>[]): SstaticApplies operations to a CSR matrix snapshot.
ReturnsThe same snapshot instance after mutation.
snapshotMutable CSR-backed state.
operationsMatrix operations to apply.
method commonLengthForOps<U>(operation1: MatrixOTOperation<U>, operation2: MatrixOTOperation<U>): numberstaticComputes the common parent depth used by component transformation.
ReturnsThe depth of the shared parent segment.
operation1First operation whose parent path is compared.
operation2Second operation whose parent path is compared.
method compose<U>(operation1: MatrixOTOperation<U>[], operation2: MatrixOTOperation<U>[]): MatrixOTOperation<U>[]staticComposes two sequential matrix operation lists.
ReturnsEquivalent composed operation list.
operation1Earlier operation list.
operation2Later operation list.
method invert<U>(operations: MatrixOTOperation<U>[]): MatrixOTOperation<U>[]staticInverts an operation list in rollback order.
ReturnsOperations that undo the input when applied in order.
operationsForward operations to invert.
method invertComponent<U>(currentOperation: MatrixOTOperation<U>): MatrixOTOperation<U>staticBuilds the inverse of one matrix component.
ReturnsA component that restores the previous matrix state.
currentOperationComponent to invert.
method transform<U>(operation: MatrixOTOperation<U>[], otherOperation: MatrixOTOperation<U>[], type: OTTransformPriority): MatrixOTOperation<U>[]staticTransforms concurrent Matrix OT operations into a convergent pair.
method transformComponent<U>(destination: MatrixOTOperation<U>[], currentOperation: MatrixOTOperation<U>, otherOperation: MatrixOTOperation<U>, type: OTTransformPriority): MatrixOTOperation<U>[]staticTransforms one matrix component over one concurrent component.
ReturnsThe destination list after appending any transformed component.
destinationOutput list receiving the transformed component or no-op.
currentOperationOperation being rebased.
otherOperationConcurrent operation already applied on the target branch.
typeTie-break side for equal-position edits.
method transformComponentX<U>(left: MatrixOTOperation<U>, right: MatrixOTOperation<U>, destLeft: MatrixOTOperation<U>[], destRight: MatrixOTOperation<U>[]): voidstaticTransforms one Matrix OT component against another concurrent component.
method transformX<U>(leftOperation: MatrixOTOperation<U>[], rightOperation: MatrixOTOperation<U>[]): MatrixOTOperation<U>[][]staticTransforms one Matrix OT operation against a concurrent operation.
- classRectOT
-
class RectOT extends BaseOTOperational Transformation implementation for sheet rectangle state.
RectOT applies direct rectangle updates and matrix structure operations that shift row/column coordinates inside the rectangle.
constructor RectOT(): RectOTCreates a RectOT descriptor for diagnostics and shared OT registries.
method apply<U>(snapshot: Rect, operations: RectOTOperation[]): RectstaticApplies rectangle operations to a mutable Rect snapshot.
ReturnsThe same rectangle after mutation.
snapshotRectangle to mutate.
operationsOperations to apply in order.
method invert(operations: RectOTOperation[], beforeRect: Rect): RectOTOperation[]staticInverts a rectangle operation list using the rectangle state before each component.
ReturnsOperations that undo the input when applied in order.
operationsForward operations to invert.
beforeRectRectangle state before any forward operations are applied.
method invertComponent(currentOperation: RectOTOperation, beforeRect?: Rect): RectOTOperationstaticBuilds the inverse of one rectangle operation.
ReturnsAn operation that restores the previous rectangle state.
currentOperationOperation to invert.
beforeRectRectangle state before the forward update operation.
- interfaceUpdateCellOTOperation
-
interface UpdateCellOTOperation<T> extends OTOperationUpdates a single cell and carries both forward and previous values.
property p: MatrixOTOperationPathPath locating the operation target inside the snapshot.
property uc: { intent?: "relocation"; prev: T | null; value: T | null } - interfaceUpdateRectOTOperation
-
interface UpdateRectOTOperation extends OTOperationReplaces a rectangle's two corner points.
property p: MatrixOTOperationPathTarget rectangle path or matrix coordinate path.
property ur: [Point, Point]New rectangle range as [startPoint, endPoint].
- typeMatrixCellUpdateIntent
-
type MatrixCellUpdateIntent = typeof MatrixCellUpdateIntent[keyof typeof MatrixCellUpdateIntent]MatrixCellUpdateIntent: { Relocation: "relocation" }Distinguishes ordinary replacement from relocation that preserves independently owned cell state.
- typeMatrixOTOperation
-
type MatrixOTOperation = InsertRowOTOperation<T> | DeleteRowOTOperation<T> | UpdateCellOTOperation<T> | MoveRowOTOperation<T> | InsertColOTOperation<T> | DeleteColOTOperation<T> | MoveColOTOperation<T> | ResizeRowOTOperation | ResizeColOTOperationEvery operation understood by MatrixOT and matrix-backed sheet state.
- functioncreateUpdateCellOTOperation
-
createUpdateCellOTOperation<T>(path: readonly number[], value: T | null, previousValue: T | null, intent?: "relocation"): UpdateCellOTOperation<T>Creates a semantic cell-update operation carrying both values required for inversion.
- functioncreateUpdateRectOTOperation
-
createUpdateRectOTOperation(path: readonly number[], start: readonly [number, number], end: readonly [number, number]): UpdateRectOTOperationCreates a semantic rectangle update without changing the RectOT wire shape.
- functionisMatrixOperation
-
isMatrixOperation(operation: OTOperation): operationNarrows an operation to any operation understood by MatrixOT.
- functionisUpdateCellOperation
-
isUpdateCellOperation<T>(operation: OTOperation): operationNarrows an OT operation to an update-cell operation with a present action payload.
Document operations
Rich-document operations target nodes, text, and attributes in the document tree.
- enumRichDocOTActionName
-
Compact operation keys persisted in rich-document OT payloads.
enum member NodeDelete: "nd"enum member NodeInsert: "ni"enum member NodeMove: "nm"enum member StringDelete: "sd"enum member StringInsert: "si"enum member UpdateAttrs: "ua" - classRichDocOT
-
class RichDocOT extends BaseOTOperational Transformation implementation for the JSON rich-document model.
RichDocOT applies node, text, and attribute operations and rebases concurrent edits so document trees converge across collaboration clients.
constructor RichDocOT(): RichDocOTCreates a RichDocOT descriptor for diagnostics and shared OT registries.
method append(destination: RichDocOTOperation[], current: RichDocOTOperation): voidstaticAppends one rich-document operation into a composed destination list.
destinationComposition destination mutated in place.
currentOperation to append.
method apply(snapshot: NodeSchema, operations: RichDocOTOperation[]): NodeSchemastaticApplies rich-document operations to a mutable node snapshot.
ReturnsThe same snapshot instance after mutation.
snapshotRoot node to mutate.
operationsOperations to apply in order.
method compose(operation1: RichDocOTOperation[], operation2: RichDocOTOperation[]): RichDocOTOperation[]staticComposes two sequential rich-document operation lists.
ReturnsEquivalent composed operation list.
operation1Earlier operation list.
operation2Later operation list.
method create(data?: RichDocOTOperation[]): RichDocOTOperation[]staticCreates a detached rich-document operation list.
ReturnsA mutable operation list owned by the caller.
dataOptional operation list to clone.
method invert(operations: RichDocOTOperation[]): RichDocOTOperation[]staticCreates the inverse operation list for a committed rich-document change.
method transform(operation: RichDocOTOperation[], otherOperation: RichDocOTOperation[], type: OTTransformPriority): RichDocOTOperation[]staticTransforms one rich-document operation list against concurrent operations.
ReturnsThe operation list rebased over otherOperation.
operationOperation list being rebased.
otherOperationConcurrent operation list already applied on the target branch.
typeTie-break side for equal-position edits.
- interfaceDeleteNodeOTOperation
-
interface DeleteNodeOTOperation extends OTOperationDeletes a node and carries the removed payload for inversion.
property nd: NodeSchemaDeleted node payload.
property p: OTOperationPathTarget node path.
- interfaceDeleteStringOTOperation
-
interface DeleteStringOTOperation extends OTOperationDeletes text from a leaf text node and carries the removed string.
property p: OTOperationPathPath ending in the string offset.
property sd: stringDeleted string payload.
- interfaceInsertNodeOTOperation
-
interface InsertNodeOTOperation extends OTOperationInserts a node into a parent content array.
property ni: NodeSchemaNode payload inserted at the target path.
property p: OTOperationPathTarget insertion path.
- interfaceInsertStringOTOperation
-
interface InsertStringOTOperation extends OTOperationInserts text into a leaf text node.
property p: OTOperationPathPath ending in the string offset.
property si: stringString inserted at the offset.
- interfaceMoveNodeOTOperation
-
interface MoveNodeOTOperation extends OTOperationMoves a node within its parent content array.
property nm: [number]Destination sibling index.
property p: OTOperationPathSource node path.
- interfaceReplaceNodeOTOperation
-
interface ReplaceNodeOTOperation extends OTOperationReplaces one node in a content array while retaining both sides for OT inversion.
property nd: NodeSchemaNode payload removed from the target path.
property ni: NodeSchemaNode payload inserted at the target path.
property p: OTOperationPathTarget node path.
- interfaceUpdateAttrsOTOperation
-
interface UpdateAttrsOTOperation extends OTOperationUpdates one node attribute and carries both previous and next values.
property p: OTOperationPathPath ending in the attribute key.
property ua: { prev: unknown; value: unknown }New attribute value and previous attribute value.
- typeRichDocOTOperation
-
type RichDocOTOperation = InsertNodeOTOperation | DeleteNodeOTOperation | ReplaceNodeOTOperation | MoveNodeOTOperation | InsertStringOTOperation | DeleteStringOTOperation | UpdateAttrsOTOperationEvery operation understood by RichDocOT.
- typeRichDocOTOperationPath
-
type RichDocOTOperationPath = OTOperationPathPath into a rich-document tree; numeric segments address content arrays and string segments address attrs.
- interfaceNodeSchema
-
Persisted rich-document node schema shared by document runtime, commands, and OT.
property attrs?: Record<string, any>Node attributes for styles, formatting, and feature-owned metadata.
property content?: Schema[]Child rich-document nodes.
property id?: stringStable structural identity for layout, retained render nodes, and collaboration mapping.
property text?: stringOptional text content for leaf text nodes.
property type: stringDomain node type identifier.
- interfaceTextSchema
-
interface TextSchema extends NodeSchemaPersisted text-bearing rich-document node schema.
property text: stringOptional text content for leaf text nodes.
No matching API entries.