## API Report File for "@tldraw/tlsync" > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts import { Atom } from 'signia'; import { BaseRecord } from '@tldraw/tlstore'; import { MigrationFailureReason } from '@tldraw/tlstore'; import { RecordsDiff } from '@tldraw/tlstore'; import { RecordType } from '@tldraw/tlstore'; import { Result } from '@tldraw/utils'; import { SerializedSchema } from '@tldraw/tlstore'; import { Signal } from 'signia'; import { Store } from '@tldraw/tlstore'; import { StoreSchema } from '@tldraw/tlstore'; import * as WebSocket_2 from 'ws'; // @public (undocumented) export type AppendOp = [type: ValueOpType.Append, values: unknown[], offset: number]; // @public (undocumented) export function applyObjectDiff(object: T, objectDiff: ObjectDiff): T; // @public (undocumented) export type DeleteOp = [type: ValueOpType.Delete]; // @public (undocumented) export function diffRecord(prev: object, next: object): null | ObjectDiff; // @public export const getNetworkDiff: >(diff: RecordsDiff) => NetworkDiff | null; // @public export type NetworkDiff = { [id: string]: RecordOp; }; // @public (undocumented) export type ObjectDiff = { [k: string]: ValueOp; }; // @public (undocumented) export type PatchOp = [type: ValueOpType.Patch, diff: ObjectDiff]; // @public (undocumented) export type PersistedRoomSnapshot = { id: string; slug: string; drawing: RoomSnapshot; }; // @public (undocumented) export type PutOp = [type: ValueOpType.Put, value: unknown]; // @public (undocumented) export type RecordOp = [RecordOpType.Patch, ObjectDiff] | [RecordOpType.Put, R] | [RecordOpType.Remove]; // @public (undocumented) export enum RecordOpType { // (undocumented) Patch = "patch", // (undocumented) Put = "put", // (undocumented) Remove = "remove" } // @public (undocumented) export type RoomClient = { serializedSchema: SerializedSchema; socket: TLRoomSocket; id: string; }; // @public (undocumented) export type RoomForId = { id: string; persistenceId?: string; timeout?: any; room: TLSyncRoom; clients: Map>; }; // @public (undocumented) export type RoomSnapshot = { clock: number; documents: Array<{ state: BaseRecord; lastChangedClock: number; }>; tombstones?: Record; schema?: SerializedSchema; }; // @public export function serializeMessage(message: Message): string; // @public (undocumented) export type TLConnectRequest = { type: 'connect'; lastServerClock: number; protocolVersion: number; schema: SerializedSchema; instanceId: string; }; // @public (undocumented) export enum TLIncompatibilityReason { // (undocumented) ClientTooOld = "clientTooOld", // (undocumented) InvalidOperation = "invalidOperation", // (undocumented) InvalidRecord = "invalidRecord", // (undocumented) ServerTooOld = "serverTooOld" } // @public export type TLPersistentClientSocket = { connectionStatus: 'error' | 'offline' | 'online'; sendMessage: (msg: TLSocketClientSentEvent) => void; onReceiveMessage: SubscribingFn>; onStatusChange: SubscribingFn; restart: () => void; }; // @public (undocumented) export type TLPersistentClientSocketStatus = 'error' | 'offline' | 'online'; // @public (undocumented) export type TLPingRequest = { type: 'ping'; }; // @public (undocumented) export type TLPushRequest = { type: 'push'; clientClock: number; diff: NetworkDiff; } | { type: 'push'; clientClock: number; presence: [RecordOpType.Patch, ObjectDiff] | [RecordOpType.Put, R]; }; // @public (undocumented) export type TLRoomSocket = { isOpen: boolean; sendMessage: (msg: TLSocketServerSentEvent) => void; }; // @public export abstract class TLServer { abstract deleteRoomForId(roomId: string): void; abstract getRoomForId(roomId: string): RoomForId | undefined; handleConnection: (ws: WebSocket_2.WebSocket, roomId: string) => Promise; loadFromDatabase?(roomId: string): Promise; logEvent?(_event: { roomId: string; name: string; clientId?: string; }): void; persistToDatabase?(roomId: string): Promise; abstract setRoomForId(roomId: string, roomForId: RoomForId): void; } // @public (undocumented) export type TLSocketClientSentEvent = TLConnectRequest | TLPingRequest | TLPushRequest; // @public (undocumented) export type TLSocketServerSentEvent = { type: 'connect'; hydrationType: 'wipe_all' | 'wipe_presence'; protocolVersion: number; schema: SerializedSchema; diff: NetworkDiff; serverClock: number; } | { type: 'error'; error?: any; } | { type: 'incompatibility_error'; reason: TLIncompatibilityReason; } | { type: 'patch'; diff: NetworkDiff; serverClock: number; } | { type: 'pong'; } | { type: 'push_result'; clientClock: number; serverClock: number; action: 'commit' | 'discard' | { rebaseWithDiff: NetworkDiff; }; }; // @public (undocumented) export const TLSYNC_PROTOCOL_VERSION = 3; // @public export class TLSyncClient = Store> { constructor(config: { store: S; socket: TLPersistentClientSocket; instanceId: string; onLoad: (self: TLSyncClient) => void; onLoadError: (error: Error) => void; onSyncError: (reason: TLIncompatibilityReason) => void; onAfterConnect?: (self: TLSyncClient) => void; }); // (undocumented) close(): void; // (undocumented) incomingDiffBuffer: Extract, { type: 'patch' | 'push_result'; }>[]; readonly instanceId: string; // (undocumented) isConnectedToRoom: boolean; // (undocumented) lastPushedPresenceState: null | R; readonly onAfterConnect?: (self: TLSyncClient) => void; // (undocumented) readonly onSyncError: (reason: TLIncompatibilityReason) => void; // (undocumented) readonly presenceState: Signal; // (undocumented) readonly socket: TLPersistentClientSocket; // (undocumented) readonly store: S; } // @public export class TLSyncRoom { constructor(schema: StoreSchema, snapshot?: RoomSnapshot); addClient(client: RoomClient): void; broadcastPatch({ diff, sourceClient }: { diff: NetworkDiff; sourceClient: RoomClient; }): this; // (undocumented) clientIdsToInstanceIds: Map; // (undocumented) clients: Map>; // (undocumented) clock: number; // (undocumented) readonly documentTypes: Set; // (undocumented) getSnapshot(): RoomSnapshot; handleClose: (client: RoomClient) => void; handleConnection: (client: RoomClient) => this; handleMessage: (client: RoomClient, message: TLSocketClientSentEvent) => Promise; migrateDiffForClient(client: RoomClient, diff: NetworkDiff): Result, MigrationFailureReason>; // (undocumented) readonly presenceType: RecordType; // (undocumented) pruneTombstones(): void; removeClient(client: RoomClient): void; // (undocumented) readonly schema: StoreSchema; sendMessageToClient(client: RoomClient, message: TLSocketServerSentEvent): this; // (undocumented) readonly serializedSchema: SerializedSchema; // (undocumented) state: Atom<{ documents: Record>; tombstones: Record; }, unknown>; // (undocumented) tombstoneHistoryStartsAtClock: number; } // @public (undocumented) export type ValueOp = AppendOp | DeleteOp | PatchOp | PutOp; // @public (undocumented) export enum ValueOpType { // (undocumented) Append = "append", // (undocumented) Delete = "delete", // (undocumented) Patch = "patch", // (undocumented) Put = "put" } // (No @packageDocumentation comment for this package) ```