ObjectStackObjectStack

Collaboration

Collaboration protocol schemas

Real-Time Collaboration Protocol

Defines schemas for real-time collaborative editing in ObjectStack.

Supports Operational Transformation (OT), CRDT (Conflict-free Replicated Data Types),

cursor sharing, and awareness state for collaborative applications.

Industry alignment: Google Docs, Figma, VSCode Live Share, Yjs

Source: packages/spec/src/system/collaboration.zod.ts

TypeScript Usage

import { AwarenessEvent, AwarenessSession, AwarenessUpdate, AwarenessUserState, CRDTMergeResult, CRDTState, CRDTType, CollaborationMode, CollaborationSession, CollaborationSessionConfig, CollaborativeCursor, CounterOperation, CursorColorPreset, CursorSelection, CursorStyle, CursorUpdate, GCounter, LWWRegister, ORSet, ORSetElement, OTComponent, OTOperation, OTOperationType, OTTransformResult, PNCounter, TextCRDTOperation, TextCRDTState, UserActivityStatus, VectorClock } from '@objectstack/spec/system';
import type { AwarenessEvent, AwarenessSession, AwarenessUpdate, AwarenessUserState, CRDTMergeResult, CRDTState, CRDTType, CollaborationMode, CollaborationSession, CollaborationSessionConfig, CollaborativeCursor, CounterOperation, CursorColorPreset, CursorSelection, CursorStyle, CursorUpdate, GCounter, LWWRegister, ORSet, ORSetElement, OTComponent, OTOperation, OTOperationType, OTTransformResult, PNCounter, TextCRDTOperation, TextCRDTState, UserActivityStatus, VectorClock } from '@objectstack/spec/system';

// Validate data
const result = AwarenessEvent.parse(data);

AwarenessEvent

Properties

PropertyTypeRequiredDescription
eventIdstringEvent identifier
sessionIdstringSession identifier
eventTypeEnum<'user.joined' | 'user.left' | 'user.updated' | 'session.created' | 'session.ended'>Type of awareness event
userIdstringoptionalUser involved in event
timestampstringISO 8601 datetime of event
payloadanyEvent payload

AwarenessSession

Properties

PropertyTypeRequiredDescription
sessionIdstringSession identifier
documentIdstringoptionalDocument ID this session is for
usersObject[]Active users in session
startedAtstringISO 8601 datetime when session started
lastUpdatestringISO 8601 datetime of last update
metadataRecord<string, any>optionalSession metadata

AwarenessUpdate

Properties

PropertyTypeRequiredDescription
statusEnum<'active' | 'idle' | 'viewing' | 'disconnected'>optionalUpdated status
currentDocumentstringoptionalUpdated current document
currentViewstringoptionalUpdated current view
metadataRecord<string, any>optionalUpdated metadata

AwarenessUserState

Properties

PropertyTypeRequiredDescription
userIdstringUser identifier
sessionIdstringSession identifier
userNamestringDisplay name
userAvatarstringoptionalUser avatar URL
statusEnum<'active' | 'idle' | 'viewing' | 'disconnected'>Current activity status
currentDocumentstringoptionalDocument ID user is currently editing
currentViewstringoptionalCurrent view/page user is on
lastActivitystringISO 8601 datetime of last activity
joinedAtstringISO 8601 datetime when user joined session
permissionsstring[]optionalUser permissions in this session
metadataRecord<string, any>optionalAdditional user state metadata

CRDTMergeResult

Properties

PropertyTypeRequiredDescription
stateObject | Object | Object | Object | ObjectMerged CRDT state
conflictsObject[]optionalConflicts encountered during merge

CRDTState

Union Options

This schema accepts one of the following structures:

Option 1

Type: lww-register

Properties

PropertyTypeRequiredDescription
typestring
valueanyCurrent register value
timestampstringISO 8601 datetime of last write
replicaIdstringID of replica that performed last write
vectorClockObjectoptionalOptional vector clock for causality tracking

Option 2

Type: g-counter

Properties

PropertyTypeRequiredDescription
typestring
countsRecord<string, integer>Map of replica ID to count

Option 3

Type: pn-counter

Properties

PropertyTypeRequiredDescription
typestring
positiveRecord<string, integer>Positive increments per replica
negativeRecord<string, integer>Negative increments per replica

Option 4

Type: or-set

Properties

PropertyTypeRequiredDescription
typestring
elementsObject[]Set elements with metadata

Option 5

Type: text

Properties

PropertyTypeRequiredDescription
typestring
documentIdstringDocument identifier
contentstringCurrent text content
operationsObject[]History of operations
lamportClockintegerCurrent Lamport clock value
vectorClockObjectVector clock for causality


CRDTType

Allowed Values

  • lww-register
  • g-counter
  • pn-counter
  • g-set
  • or-set
  • lww-map
  • text
  • tree
  • json

CollaborationMode

Allowed Values

  • ot
  • crdt
  • lock
  • hybrid

CollaborationSession

Properties

PropertyTypeRequiredDescription
sessionIdstringSession identifier
documentIdstringDocument identifier
configObjectSession configuration
usersObject[]Active users
cursorsObject[]Active cursors
versionintegerCurrent document version
operationsObject | Object[]optionalRecent operations
createdAtstringISO 8601 datetime when session was created
lastActivitystringISO 8601 datetime of last activity
statusEnum<'active' | 'idle' | 'ended'>Session status

CollaborationSessionConfig

Properties

PropertyTypeRequiredDescription
modeEnum<'ot' | 'crdt' | 'lock' | 'hybrid'>Collaboration mode to use
enableCursorSharingbooleanEnable cursor sharing
enablePresencebooleanEnable presence tracking
enableAwarenessbooleanEnable awareness state
maxUsersintegeroptionalMaximum concurrent users
idleTimeoutintegerIdle timeout in milliseconds
conflictResolutionEnum<'ot' | 'crdt' | 'manual'>Conflict resolution strategy
persistencebooleanEnable operation persistence
snapshotObjectoptionalSnapshot configuration

CollaborativeCursor

Properties

PropertyTypeRequiredDescription
userIdstringUser identifier
sessionIdstringSession identifier
documentIdstringDocument identifier
userNamestringDisplay name of user
positionObjectCurrent cursor position
selectionObjectoptionalCurrent text selection
styleObjectVisual style for this cursor
isTypingbooleanWhether user is currently typing
lastUpdatestringISO 8601 datetime of last cursor update
metadataRecord<string, any>optionalAdditional cursor metadata

CounterOperation

Properties

PropertyTypeRequiredDescription
replicaIdstringReplica identifier
deltaintegerChange amount (positive for increment, negative for decrement)
timestampstringISO 8601 datetime of operation

CursorColorPreset

Allowed Values

  • blue
  • green
  • red
  • yellow
  • purple
  • orange
  • pink
  • teal
  • indigo
  • cyan

CursorSelection

Properties

PropertyTypeRequiredDescription
anchorObjectSelection anchor (start point)
focusObjectSelection focus (end point)
directionEnum<'forward' | 'backward'>optionalSelection direction

CursorStyle

Properties

PropertyTypeRequiredDescription
colorEnum<'blue' | 'green' | 'red' | 'yellow' | 'purple' | 'orange' | 'pink' | 'teal' | 'indigo' | 'cyan'> | stringCursor color (preset or custom hex)
opacitynumberCursor opacity (0-1)
labelstringoptionalLabel to display with cursor (usually username)
showLabelbooleanWhether to show label
pulseOnUpdatebooleanWhether to pulse when cursor moves

CursorUpdate

Properties

PropertyTypeRequiredDescription
positionObjectoptionalUpdated cursor position
selectionObjectoptionalUpdated selection
isTypingbooleanoptionalUpdated typing state
metadataRecord<string, any>optionalUpdated metadata

GCounter

Properties

PropertyTypeRequiredDescription
typestring
countsRecord<string, integer>Map of replica ID to count

LWWRegister

Properties

PropertyTypeRequiredDescription
typestring
valueanyCurrent register value
timestampstringISO 8601 datetime of last write
replicaIdstringID of replica that performed last write
vectorClockObjectoptionalOptional vector clock for causality tracking

ORSet

Properties

PropertyTypeRequiredDescription
typestring
elementsObject[]Set elements with metadata

ORSetElement

Properties

PropertyTypeRequiredDescription
valueanyElement value
timestampstringAddition timestamp
replicaIdstringReplica that added the element
uidstringUnique identifier for this addition
removedbooleanWhether element has been removed

OTComponent

Union Options

This schema accepts one of the following structures:

Option 1

Type: insert

Properties

PropertyTypeRequiredDescription
typestring
textstringText to insert
attributesRecord<string, any>optionalText formatting attributes (e.g., bold, italic)

Option 2

Type: delete

Properties

PropertyTypeRequiredDescription
typestring
countintegerNumber of characters to delete

Option 3

Type: retain

Properties

PropertyTypeRequiredDescription
typestring
countintegerNumber of characters to retain
attributesRecord<string, any>optionalAttribute changes to apply


OTOperation

Properties

PropertyTypeRequiredDescription
operationIdstringUnique operation identifier
documentIdstringDocument identifier
userIdstringUser who created the operation
sessionIdstringSession identifier
componentsObject | Object | Object[]Operation components
baseVersionintegerDocument version this operation is based on
timestampstringISO 8601 datetime when operation was created
metadataRecord<string, any>optionalAdditional operation metadata

OTOperationType

Allowed Values

  • insert
  • delete
  • retain

OTTransformResult

Properties

PropertyTypeRequiredDescription
operationObjectTransformed operation
transformedbooleanWhether transformation was applied
conflictsstring[]optionalConflict descriptions if any

PNCounter

Properties

PropertyTypeRequiredDescription
typestring
positiveRecord<string, integer>Positive increments per replica
negativeRecord<string, integer>Negative increments per replica

TextCRDTOperation

Properties

PropertyTypeRequiredDescription
operationIdstringUnique operation identifier
replicaIdstringReplica identifier
positionintegerPosition in document
insertstringoptionalText to insert
deleteintegeroptionalNumber of characters to delete
timestampstringISO 8601 datetime of operation
lamportTimestampintegerLamport timestamp for ordering

TextCRDTState

Properties

PropertyTypeRequiredDescription
typestring
documentIdstringDocument identifier
contentstringCurrent text content
operationsObject[]History of operations
lamportClockintegerCurrent Lamport clock value
vectorClockObjectVector clock for causality

UserActivityStatus

Allowed Values

  • active
  • idle
  • viewing
  • disconnected

VectorClock

Properties

PropertyTypeRequiredDescription
clockRecord<string, integer>Map of replica ID to logical timestamp

On this page