← All packages

API reference

@searsuite/sear-domain-collaboration

Host-neutral revision, pending-operation, acknowledgement, catch-up, and rebase algorithms.

17 exportsderived from source

classCollaborationAuthoritysource ↗
class CollaborationAuthority

In-memory authority that validates, rebases, orders, and deduplicates collaboration batches.

constructorconstructor
CollaborationAuthority(contributors: CollaborationContributorRegistry): CollaborationAuthority
contributors: CollaborationContributorRegistry
methodaccept
accept(submission: CollaborationSubmission): CollaborationAcceptedBatch

Accepts one client submission into the canonical resource order.

submission: CollaborationSubmission
methodsync
sync(resourceId: string, fromRevision: number): CollaborationSyncMessage

Returns ordered canonical batches after a known revision.

resourceId: string
fromRevision: number
classCollaborationContributorRegistrysource ↗
class CollaborationContributorRegistry

Owner-to-OT mapping used by clients, authorities, and editor bridges.

constructorconstructor
CollaborationContributorRegistry(operations: TransactionOTRegistry): CollaborationContributorRegistry
operations: TransactionOTRegistry
propertyoperations
readonly operations: TransactionOTRegistry
methoddestroy
destroy(): void
methodgetRegisteredOwnerIds
getRegisteredOwnerIds(): readonly string[]
methodhas
has(ownerId: string): boolean
ownerId: string
methodregister
register<OperationType>(ownerId: string, definition: TransactionOTDefinition<OperationType>, relations?: readonly OTTransformRelation<OTOperation, OTOperation>[]): (): void

Registers one collaborative state owner and returns an idempotent disposer.

ownerId: string
definition: TransactionOTDefinition<OperationType>
relations: readonly OTTransformRelation<OTOperation, OTOperation>[]
methodrequire
require(ownerId: string, operationType?: CollaborationOperationType): TransactionOTDefinition

Resolves one registered owner and optionally validates its wire operation type.

ownerId: string
operationType: CollaborationOperationType
classCollaborationEnginesource ↗
class CollaborationEngine

Single client-side collaboration algorithm shared by all editor bridges.

constructorconstructor
CollaborationEngine(contributors: CollaborationContributorRegistry): CollaborationEngine
contributors: CollaborationContributorRegistry
methodconnect
connect(resourceId: string, clientId: string, revision?: number): void

Starts one resource session from a host-supplied document revision.

resourceId: string
clientId: string
revision: number
methoddisconnect
disconnect(): void

Ends the current session and releases transient pending state.

methodgetPendingCount
getPendingCount(): number
methodgetRevision
getRevision(): number
methodreceive
receive(message: CollaborationServerMessage): readonly CollaborationEngineEffect[]

Applies one authority message and returns host/transport effects in deterministic order.

message: CollaborationServerMessage
methodsubmitLocal
submitLocal<OperationType>(ownerId: string, operations: readonly OperationType[]): readonly CollaborationEngineEffect[]

Queues one already-committed local transaction and emits at most one in-flight submission.

ownerId: string
operations: readonly OperationType[]
classCollaborationErrorsource ↗
class CollaborationError extends SearError

Public collaboration failure with stable diagnostics.

constructorconstructor
CollaborationError(code: CollaborationErrorCode, message: string, details?: SearErrorDetails): CollaborationError
code: CollaborationErrorCode
message: string
details: SearErrorDetails
propertycode
readonly code: CollaborationErrorCode

Stable machine-readable identifier for this error category.

Inherited members 9

Inherited from SearError.

interfaceCollaborationAcceptedBatchsource ↗
interface CollaborationAcceptedBatch

Canonical operation batch accepted and ordered by the authority.

propertybaseRevision
readonly baseRevision: number
propertyclientId
readonly clientId: string
propertykind
readonly kind: "accepted"
propertyoperationId
readonly operationId: string
propertyoperationType
readonly operationType: CollaborationOperationType
propertyownerId
readonly ownerId: string
propertypayload
readonly payload: OTEncodedValue
propertyprotocolVersion
readonly protocolVersion: 1
propertyresourceId
readonly resourceId: string
propertyserverRevision
readonly serverRevision: number
interfaceCollaborationContributionsource ↗
interface CollaborationContribution<OperationType>

Open collaboration contribution shared by editor clients and authorities.

propertydefinition
readonly definition: TransactionOTDefinition<OperationType>
propertyownerId
readonly ownerId: string
propertyrelations
readonly relations?: readonly OTTransformRelation<OTOperation, OTOperation>[]
interfaceCollaborationOperationTypesource ↗
interface CollaborationOperationType

Versioned OT family identity carried on the wire.

propertyid
readonly id: string
propertyversion
readonly version: number
interfaceCollaborationRejectedMessagesource ↗
interface CollaborationRejectedMessage

Explicit authority rejection; clients must not infer recovery from dropped frames.

propertycode
readonly code: string
propertykind
readonly kind: "rejected"
propertymessage
readonly message: string
propertyoperationId
readonly operationId?: string
propertyprotocolVersion
readonly protocolVersion: 1
propertyresourceId
readonly resourceId: string
interfaceCollaborationSubmissionsource ↗
interface CollaborationSubmission

Client submission before the authority assigns a canonical revision.

propertybaseRevision
readonly baseRevision: number
propertyclientId
readonly clientId: string
propertykind
readonly kind: "submit"
propertyoperationId
readonly operationId: string
propertyoperationType
readonly operationType: CollaborationOperationType
propertyownerId
readonly ownerId: string
propertypayload
readonly payload: OTEncodedValue
propertyprotocolVersion
readonly protocolVersion: 1
propertyresourceId
readonly resourceId: string
interfaceCollaborationSyncMessagesource ↗
interface CollaborationSyncMessage

Ordered catch-up response sent when a transport joins a resource.

propertybatches
readonly batches: readonly CollaborationAcceptedBatch[]
propertyfromRevision
readonly fromRevision: number
propertykind
readonly kind: "sync"
propertyprotocolVersion
readonly protocolVersion: 1
propertyresourceId
readonly resourceId: string
propertyserverRevision
readonly serverRevision: number
typeCollaborationClientMessagesource ↗
type CollaborationClientMessage = CollaborationSubmission
typeCollaborationEngineEffectsource ↗
type CollaborationEngineEffect = { kind: "send"; submission: CollaborationSubmission } | { kind: "applyRemote"; operations: readonly OTOperation[]; ownerId: string; serverRevision: number }

Effects emitted by the pure collaboration client state machine.

typeCollaborationErrorCodesource ↗
type CollaborationErrorCode = typeof CollaborationErrorCode[keyof typeof CollaborationErrorCode]

Stable collaboration protocol and state-machine errors.

typeCollaborationServerMessagesource ↗
type CollaborationServerMessage = CollaborationAcceptedBatch | CollaborationSyncMessage | CollaborationRejectedMessage
variableCollaborationErrorCodesource ↗
CollaborationErrorCode: { AcknowledgementMismatch: "SEAR_COLLABORATION_ACKNOWLEDGEMENT_MISMATCH"; EngineDisconnected: "SEAR_COLLABORATION_ENGINE_DISCONNECTED"; InvalidIdentity: "SEAR_COLLABORATION_INVALID_IDENTITY"; InvalidProtocol: "SEAR_COLLABORATION_INVALID_PROTOCOL"; InvalidRevision: "SEAR_COLLABORATION_INVALID_REVISION"; OperationRejected: "SEAR_COLLABORATION_OPERATION_REJECTED"; OwnerConflict: "SEAR_COLLABORATION_OWNER_CONFLICT"; OwnerNotRegistered: "SEAR_COLLABORATION_OWNER_NOT_REGISTERED"; … }

Stable collaboration protocol and state-machine errors.

variableCollaborationProtocolVersionsource ↗
CollaborationProtocolVersion: 1

Current collaboration wire protocol version.

variableCollaborationErrorCodeTypesource ↗
CollaborationErrorCodeType: { AcknowledgementMismatch: "SEAR_COLLABORATION_ACKNOWLEDGEMENT_MISMATCH"; EngineDisconnected: "SEAR_COLLABORATION_ENGINE_DISCONNECTED"; InvalidIdentity: "SEAR_COLLABORATION_INVALID_IDENTITY"; InvalidProtocol: "SEAR_COLLABORATION_INVALID_PROTOCOL"; InvalidRevision: "SEAR_COLLABORATION_INVALID_REVISION"; OperationRejected: "SEAR_COLLABORATION_OPERATION_REJECTED"; OwnerConflict: "SEAR_COLLABORATION_OWNER_CONFLICT"; OwnerNotRegistered: "SEAR_COLLABORATION_OWNER_NOT_REGISTERED"; … }

Stable collaboration protocol and state-machine errors.