## API Report File for "@tldraw/sync-core" > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts import { Atom } from '@tldraw/state'; import { Emitter } from 'nanoevents'; import { RecordsDiff } from '@tldraw/store'; import { RecordType } from '@tldraw/store'; import { Result } from '@tldraw/utils'; import { SerializedSchema } from '@tldraw/store'; import { Signal } from '@tldraw/state'; import { Store } from '@tldraw/store'; import { StoreSchema } from '@tldraw/store'; import { TLRecord } from '@tldraw/tlschema'; import { UnknownRecord } from '@tldraw/store'; // @public (undocumented) export type AppendOp = [type: typeof ValueOpType.Append, values: unknown[], offset: number]; // @public (undocumented) export function applyObjectDiff(object: T, objectDiff: ObjectDiff): T; // @public (undocumented) export function chunk(msg: string, maxSafeMessageSize?: number): string[]; // @public (undocumented) export class ClientWebSocketAdapter implements TLPersistentClientSocket { constructor(getUri: () => Promise | string); // (undocumented) close(): void; // (undocumented) _closeSocket(): void; // (undocumented) get connectionStatus(): TLPersistentClientSocketStatus; // (undocumented) _connectionStatus: Atom<'initial' | TLPersistentClientSocketStatus>; // (undocumented) isDisposed: boolean; // (undocumented) onReceiveMessage(cb: (val: TLSocketServerSentEvent) => void): () => void; // (undocumented) onStatusChange(cb: (val: TLPersistentClientSocketStatus, closeCode?: number) => void): () => void; // @internal (undocumented) readonly _reconnectManager: ReconnectManager; // (undocumented) restart(): void; // (undocumented) sendMessage(msg: TLSocketClientSentEvent): void; // (undocumented) _setNewSocket(ws: WebSocket): void; // (undocumented) _ws: null | WebSocket; } // @public (undocumented) export type DeleteOp = [type: typeof ValueOpType.Delete]; // @public (undocumented) export function diffRecord(prev: object, next: object): null | ObjectDiff; // @internal (undocumented) export class DocumentState { // (undocumented) _atom: Atom<{ lastChangedClock: number; state: R; }>; // (undocumented) static createAndValidate(state: R, lastChangedClock: number, recordType: RecordType): Result, Error>; // (undocumented) static createWithoutValidating(state: R, lastChangedClock: number, recordType: RecordType): DocumentState; // (undocumented) get lastChangedClock(): number; // (undocumented) mergeDiff(diff: ObjectDiff, clock: number): Result; // (undocumented) replaceState(state: R, clock: number): Result; // (undocumented) get state(): R; } // @public export const getNetworkDiff: (diff: RecordsDiff) => NetworkDiff | null; // @public (undocumented) export function getTlsyncProtocolVersion(): number; // @public export interface NetworkDiff { // (undocumented) [id: string]: RecordOp; } // @public (undocumented) export interface ObjectDiff { // (undocumented) [k: string]: ValueOp; } // @public (undocumented) export type PatchOp = [type: typeof ValueOpType.Patch, diff: ObjectDiff]; // @public (undocumented) export interface PersistedRoomSnapshotForSupabase { // (undocumented) drawing: RoomSnapshot; // (undocumented) id: string; // (undocumented) slug: string; } // @public (undocumented) export type PutOp = [type: typeof ValueOpType.Put, value: unknown]; // @internal (undocumented) export class ReconnectManager { constructor(socketAdapter: ClientWebSocketAdapter, getUri: () => Promise | string); // (undocumented) close(): void; // (undocumented) connected(): void; // (undocumented) disconnected(): void; // (undocumented) intendedDelay: number; // (undocumented) maybeReconnected(): void; } // @public (undocumented) export type RecordOp = [typeof RecordOpType.Patch, ObjectDiff] | [typeof RecordOpType.Put, R] | [typeof RecordOpType.Remove]; // @public (undocumented) export const RecordOpType: { readonly Patch: "patch"; readonly Put: "put"; readonly Remove: "remove"; }; // @public (undocumented) export type RecordOpType = (typeof RecordOpType)[keyof typeof RecordOpType]; // @public (undocumented) export type RoomSession = { cancellationTime: number; meta: Meta; presenceId: string; sessionKey: string; socket: TLRoomSocket; state: typeof RoomSessionState.AwaitingRemoval; } | { debounceTimer: null | ReturnType; lastInteractionTime: number; meta: Meta; outstandingDataMessages: TLSocketServerSentDataEvent[]; presenceId: string; serializedSchema: SerializedSchema; sessionKey: string; socket: TLRoomSocket; state: typeof RoomSessionState.Connected; } | { meta: Meta; presenceId: string; sessionKey: string; sessionStartTime: number; socket: TLRoomSocket; state: typeof RoomSessionState.AwaitingConnectMessage; }; // @public (undocumented) export const RoomSessionState: { readonly AwaitingConnectMessage: "awaiting-connect-message"; readonly AwaitingRemoval: "awaiting-removal"; readonly Connected: "connected"; }; // @public (undocumented) export type RoomSessionState = (typeof RoomSessionState)[keyof typeof RoomSessionState]; // @public (undocumented) export interface RoomSnapshot { // (undocumented) clock: number; // (undocumented) documents: Array<{ lastChangedClock: number; state: UnknownRecord; }>; // (undocumented) schema?: SerializedSchema; // (undocumented) tombstones?: Record; } // @public (undocumented) export type SubscribingFn = (cb: (val: T) => void) => () => void; // @public export const TLCloseEventCode: { readonly NOT_FOUND: 4099; }; // @public (undocumented) export interface TLConnectRequest { // (undocumented) connectRequestId: string; // (undocumented) lastServerClock: number; // (undocumented) protocolVersion: number; // (undocumented) schema: SerializedSchema; // (undocumented) type: 'connect'; } // @public (undocumented) export const TLIncompatibilityReason: { readonly ClientTooOld: "clientTooOld"; readonly InvalidOperation: "invalidOperation"; readonly InvalidRecord: "invalidRecord"; readonly RoomNotFound: "roomNotFound"; readonly ServerTooOld: "serverTooOld"; }; // @public (undocumented) export type TLIncompatibilityReason = (typeof TLIncompatibilityReason)[keyof typeof TLIncompatibilityReason]; // @public export interface TLPersistentClientSocket { connectionStatus: 'error' | 'offline' | 'online'; onReceiveMessage: SubscribingFn>; onStatusChange: SubscribingFn; restart: () => void; sendMessage: (msg: TLSocketClientSentEvent) => void; } // @public (undocumented) export type TLPersistentClientSocketStatus = 'error' | 'offline' | 'online'; // @public (undocumented) export interface TLPingRequest { // (undocumented) type: 'ping'; } // @public (undocumented) export interface TLPushRequest { // (undocumented) clientClock: number; // (undocumented) diff?: NetworkDiff; // (undocumented) presence?: [typeof RecordOpType.Patch, ObjectDiff] | [typeof RecordOpType.Put, R]; // (undocumented) type: 'push'; } // @public (undocumented) export class TLRemoteSyncError extends Error { constructor(reason: TLIncompatibilityReason); // (undocumented) name: string; // (undocumented) readonly reason: TLIncompatibilityReason; } // @public (undocumented) export interface TLRoomSocket { // (undocumented) close: () => void; // (undocumented) isOpen: boolean; // (undocumented) sendMessage: (msg: TLSocketServerSentEvent) => void; } // @public (undocumented) export type TLSocketClientSentEvent = TLConnectRequest | TLPingRequest | TLPushRequest; // @public (undocumented) export class TLSocketRoom { constructor(opts: { clientTimeout?: number; initialSnapshot?: RoomSnapshot; log?: TLSyncLog; onAfterReceiveMessage?: (args: { message: TLSocketServerSentEvent; meta: SessionMeta; sessionId: string; stringified: string; }) => void; onBeforeSendMessage?: (args: { message: TLSocketServerSentEvent; meta: SessionMeta; sessionId: string; stringified: string; }) => void; onDataChange?: () => void; onSessionRemoved?: (room: TLSocketRoom, args: { meta: SessionMeta; numSessionsRemaining: number; sessionKey: string; }) => void; schema?: StoreSchema; }); // (undocumented) close(): void; // (undocumented) getCurrentDocumentClock(): number; // (undocumented) getCurrentSnapshot(): RoomSnapshot; // (undocumented) getNumActiveSessions(): number; // (undocumented) handleSocketClose(sessionId: string): void; // (undocumented) handleSocketConnect(sessionId: string, socket: WebSocket, meta: SessionMeta): void; // (undocumented) handleSocketError(sessionId: string): void; // (undocumented) handleSocketMessage(sessionId: string, message: ArrayBuffer | string): void; // (undocumented) loadSnapshot(snapshot: RoomSnapshot): void; // (undocumented) readonly log: TLSyncLog; // (undocumented) readonly opts: { clientTimeout?: number; initialSnapshot?: RoomSnapshot; log?: TLSyncLog; onAfterReceiveMessage?: (args: { message: TLSocketServerSentEvent; meta: SessionMeta; sessionId: string; stringified: string; }) => void; onBeforeSendMessage?: (args: { message: TLSocketServerSentEvent; meta: SessionMeta; sessionId: string; stringified: string; }) => void; onDataChange?: () => void; onSessionRemoved?: (room: TLSocketRoom, args: { meta: SessionMeta; numSessionsRemaining: number; sessionKey: string; }) => void; schema?: StoreSchema; }; } // @public (undocumented) export type TLSocketServerSentDataEvent = { action: 'commit' | 'discard' | { rebaseWithDiff: NetworkDiff; }; clientClock: number; serverClock: number; type: 'push_result'; } | { diff: NetworkDiff; serverClock: number; type: 'patch'; }; // @public (undocumented) export type TLSocketServerSentEvent = { connectRequestId: string; diff: NetworkDiff; hydrationType: 'wipe_all' | 'wipe_presence'; protocolVersion: number; schema: SerializedSchema; serverClock: number; type: 'connect'; } | { data: TLSocketServerSentDataEvent[]; type: 'data'; } | { error?: any; type: 'error'; } | { reason: TLIncompatibilityReason; type: 'incompatibility_error'; } | { type: 'pong'; } | TLSocketServerSentDataEvent; // @public export class TLSyncClient = Store> { constructor(config: { didCancel?: () => boolean; onAfterConnect?: (self: TLSyncClient, isNew: boolean) => void; onLoad: (self: TLSyncClient) => void; onLoadError: (error: Error) => void; onSyncError: (reason: TLIncompatibilityReason) => void; presence: Signal; socket: TLPersistentClientSocket; store: S; }); // (undocumented) close(): void; // (undocumented) didCancel?: () => boolean; // (undocumented) incomingDiffBuffer: TLSocketServerSentDataEvent[]; // (undocumented) isConnectedToRoom: boolean; // (undocumented) lastPushedPresenceState: null | R; // (undocumented) latestConnectRequestId: null | string; readonly onAfterConnect?: (self: TLSyncClient, isNew: boolean) => void; // (undocumented) readonly onSyncError: (reason: TLIncompatibilityReason) => void; // (undocumented) readonly presenceState: Signal | undefined; // (undocumented) readonly socket: TLPersistentClientSocket; // (undocumented) readonly store: S; } // @public (undocumented) export interface TLSyncLog { // (undocumented) error?: (...args: any[]) => void; // (undocumented) info?: (...args: any[]) => void; // (undocumented) warn?: (...args: any[]) => void; } // @public export class TLSyncRoom { constructor(schema: StoreSchema, snapshot?: RoomSnapshot); broadcastPatch({ diff, sourceSessionKey: sourceSessionKey, }: { diff: NetworkDiff; sourceSessionKey: string; }): this; // (undocumented) clock: number; // (undocumented) close(): void; // (undocumented) documentClock: number; // (undocumented) readonly documentTypes: Set; // (undocumented) readonly events: Emitter< { room_became_empty: () => void; session_removed: (args: { meta: SessionMeta; sessionKey: string; }) => void; }>; // (undocumented) _flushDataMessages(sessionKey: string): void; // (undocumented) getSnapshot(): RoomSnapshot; handleClose: (sessionKey: string) => void; handleMessage: (sessionKey: string, message: TLSocketClientSentEvent) => Promise; handleNewSession: (sessionKey: string, socket: TLRoomSocket, meta: SessionMeta) => this; // (undocumented) readonly presenceType: RecordType; // (undocumented) pruneSessions: () => void; // (undocumented) readonly schema: StoreSchema; // (undocumented) readonly serializedSchema: SerializedSchema; // (undocumented) readonly sessions: Map>; // @internal (undocumented) state: Atom<{ documents: Record>; tombstones: Record; }, unknown>; // (undocumented) tombstoneHistoryStartsAtClock: number; } // @public (undocumented) export type ValueOp = AppendOp | DeleteOp | PatchOp | PutOp; // @public (undocumented) export const ValueOpType: { readonly Append: "append"; readonly Delete: "delete"; readonly Patch: "patch"; readonly Put: "put"; }; // @public (undocumented) export type ValueOpType = (typeof ValueOpType)[keyof typeof ValueOpType]; // (No @packageDocumentation comment for this package) ```