AI agents: fetch the documentation index at llms.txt. Markdown versions are available by appending .md to any page URL, including this page's markdown.
@stratasync/y-doc
Yjs CRDT integration for real-time collaborative editing in Strata Sync.
DocumentKey serialization helpers and message type guardsnpm install @stratasync/y-doc yjsyjs is a peer dependency, so install it alongside @stratasync/y-doc.
The root barrel re-exports the managers, persistence helpers, public types from types.ts, and the type guards.
import {
YjsDocumentManager,
YjsPresenceManager,
clearPersistedYjsDocuments,
createPersistedYjsPrefix,
toDocumentKeyString,
fromDocumentKeyString,
isYjsSyncStep2Message,
isYjsUpdateMessage,
isSessionStateMessage,
isLiveEditingErrorMessage,
} from "@stratasync/y-doc";
import type {
ConnectOptions,
DocumentConnectionState,
DocumentKey,
DocViewMessage,
DocFocusMessage,
LiveEditingErrorCode,
LiveEditingErrorMessage,
SessionParticipant,
SessionState,
YjsDocumentManagerConfig,
YjsTransport,
ClientMessage,
ServerMessage,
YjsTransportConnectionState,
YjsSyncStep1Message,
YjsSyncStep2Message,
YjsUpdateMessage,
YjsUpdateToServerMessage,
} from "@stratasync/y-doc";A triple identifying a collaborative field: entity type, entity ID, and field name.
interface DocumentKey {
entityType: string; // Model name, such as "Task"
entityId: string; // Model instance ID
fieldName: string; // Field name, such as "description"
}Use toDocumentKeyString and fromDocumentKeyString to convert between DocumentKey objects and their string form ("Task:abc-123:description").
Two-step sync:
All Yjs data is binary-encoded (Uint8Array) and transmitted as base64 strings within JSON messages.
Both managers need a YjsTransport to send and receive messages:
interface YjsTransport {
send(message: ClientMessage): void;
onMessage(callback: (message: ServerMessage) => void): () => void;
isConnected(): boolean;
}@stratasync/transport-graphql provides YjsTransportAdapter, which bridges the Yjs protocol over the existing WebSocket connection.
Sits between @stratasync/core and higher-level packages.
sync-core
^-- sync-y-doc
^-- sync-transport-graphql (provides YjsTransportAdapter)
^-- sync-react (useYjsDocument, useYjsPresence hooks)
Framework-agnostic: no React or browser dependencies beyond yjs.