## 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 { AtomMap } from '@tldraw/store'; import { DebouncedFunc } from 'lodash'; import { DebouncedFuncLeading } from 'lodash'; import { Emitter } from 'nanoevents'; import { RecordsDiff } from '@tldraw/store'; import { RecordType } from '@tldraw/store'; import { SerializedSchema } from '@tldraw/store'; import { SerializedSchemaV2 } from 'tldraw'; import { Signal } from '@tldraw/state'; import { Store } from '@tldraw/store'; import { StoreSchema } from '@tldraw/store'; import { StoreSnapshot } from '@tldraw/store'; import { SynchronousStorage } from '@tldraw/store'; import { TLDocument } from 'tldraw'; import { TLPage } from 'tldraw'; import { TLRecord } from '@tldraw/tlschema'; import { TLStoreSnapshot } from '@tldraw/tlschema'; import { UnknownRecord } from '@tldraw/store'; // @internal export type AppendOp = [type: typeof ValueOpType.Append, value: string | unknown[], offset: number]; // @internal export function applyObjectDiff(object: T, objectDiff: ObjectDiff): T; // @internal export function chunk(msg: string, maxSafeMessageSize?: number): string[]; // @internal export class ClientWebSocketAdapter implements TLPersistentClientSocket, TLSocketServerSentEvent> { constructor(getUri: () => Promise | string); close(): void; // (undocumented) _closeSocket(): void; get connectionStatus(): TLPersistentClientSocketStatus; // (undocumented) _connectionStatus: Atom<'initial' | TLPersistentClientSocketStatus>; // (undocumented) isDisposed: boolean; onReceiveMessage(cb: (val: TLSocketServerSentEvent) => void): () => void; onStatusChange(cb: TLSocketStatusListener): () => void; // (undocumented) readonly _reconnectManager: ReconnectManager; restart(): void; sendMessage(msg: TLSocketClientSentEvent): void; // (undocumented) _setNewSocket(ws: WebSocket): void; // (undocumented) _ws: null | WebSocket; } // @public export const DEFAULT_INITIAL_SNAPSHOT: { documentClock: number; documents: ({ lastChangedClock: number; state: TLDocument; } | { lastChangedClock: number; state: TLPage; })[]; schema: SerializedSchemaV2; tombstoneHistoryStartsAtClock: number; }; // @internal export type DeleteOp = [type: typeof ValueOpType.Delete]; // @internal export function diffRecord(prev: object, next: object, legacyAppendMode?: boolean): null | ObjectDiff; // @public export class DurableObjectSqliteSyncWrapper implements TLSyncSqliteWrapper { constructor(storage: { sql: { exec(sql: string, ...bindings: unknown[]): Iterable & { toArray(): any[]; }; }; transactionSync(callback: () => any): any; }, config?: TLSyncSqliteWrapperConfig | undefined); // (undocumented) config?: TLSyncSqliteWrapperConfig | undefined; // (undocumented) exec(sql: string): void; // (undocumented) prepare(sql: string): TLSyncSqliteStatement; // (undocumented) transaction(callback: () => T): T; } // @internal export function getNetworkDiff(diff: RecordsDiff): NetworkDiff | null; // @internal export function getTlsyncProtocolVersion(): number; // @public export class InMemorySyncStorage implements TLSyncStorage { constructor({ snapshot, objectTypes, onChange, }?: { objectTypes?: readonly string[]; onChange?(arg: TLSyncStorageOnChangeCallbackProps): unknown; snapshot?: RoomSnapshot; }); // @internal (undocumented) documentClock: Atom; // @internal (undocumented) documents: AtomMap; // (undocumented) getClock(): number; // (undocumented) getObjectsByIds(ids: Iterable): RoomSnapshot['documents']; // (undocumented) getObjectsSnapshot(): RoomSnapshot['documents']; // (undocumented) getSnapshot(): RoomSnapshot; // @internal objects: AtomMap; // @internal (undocumented) readonly objectTypes: ReadonlySet; // (undocumented) onChange(callback: (arg: TLSyncStorageOnChangeCallbackProps) => unknown): () => void; // @internal (undocumented) pruneTombstones: DebouncedFunc<() => void>; // @internal (undocumented) schema: Atom; // @internal (undocumented) tombstoneHistoryStartsAtClock: Atom; // @internal (undocumented) tombstones: AtomMap; // (undocumented) transaction(callback: TLSyncStorageTransactionCallback, opts?: TLSyncStorageTransactionOptions): TLSyncStorageTransactionResult; } // @public export class JsonChunkAssembler { handleMessage(msg: string): { data: object; stringified: string; } | { error: Error; } | null; state: 'idle' | { charsReceived: number; chunksReceived: string[]; totalChunks: number; }; } // @public export function loadSnapshotIntoStorage(txn: TLSyncStorageTransaction, schema: StoreSchema, snapshot: RoomSnapshot | TLStoreSnapshot): void; // @internal (undocumented) export interface MinimalDocStore { // (undocumented) delete(id: string): void; // (undocumented) get(id: string): undefined | UnknownRecord; // (undocumented) set(id: string, record: R): void; } // @internal export interface NetworkDiff { // (undocumented) [id: string]: RecordOp; } // @public export class NodeSqliteWrapper implements TLSyncSqliteWrapper { constructor(db: SyncSqliteDatabase, config?: TLSyncSqliteWrapperConfig | undefined); // (undocumented) config?: TLSyncSqliteWrapperConfig | undefined; // (undocumented) exec(sql: string): void; // (undocumented) prepare(sql: string): TLSyncSqliteStatement; // (undocumented) transaction(callback: () => T): T; } // @internal export interface ObjectDiff { // (undocumented) [k: string]: ValueOp; } // @public export type OmitVoid = { [K in KS extends any ? (void extends T[KS] ? never : KS) : never]: T[K]; }; // @internal export type PatchOp = [type: typeof ValueOpType.Patch, diff: ObjectDiff]; // @internal export interface PersistedRoomSnapshotForSupabase { // (undocumented) drawing: RoomSnapshot; // (undocumented) id: string; // (undocumented) slug: string; } // @internal (undocumented) export class PresenceStore implements MinimalDocStore { // (undocumented) delete(id: string): void; // (undocumented) get(id: string): undefined | UnknownRecord; // (undocumented) set(id: string, state: R): void; // (undocumented) values(): Generator; } // @internal export type PutOp = [type: typeof ValueOpType.Put, value: unknown]; // @internal export class ReconnectManager { constructor(socketAdapter: ClientWebSocketAdapter, getUri: () => Promise | string); close(): void; connected(): void; disconnected(): void; // (undocumented) intendedDelay: number; maybeReconnected(): void; } // @internal export type RecordOp = [typeof RecordOpType.Patch, ObjectDiff] | [typeof RecordOpType.Put, R] | [typeof RecordOpType.Remove]; // @internal export const RecordOpType: { readonly Patch: 'patch'; readonly Put: 'put'; readonly Remove: 'remove'; }; // @internal export type RecordOpType = (typeof RecordOpType)[keyof typeof RecordOpType]; // @internal export type RoomSession = (RoomSessionBase & { state: typeof RoomSessionState.AwaitingConnectMessage; sessionStartTime: number; }) | (RoomSessionBase & { state: typeof RoomSessionState.AwaitingRemoval; cancellationTime: number; }) | (RoomSessionBase & { state: typeof RoomSessionState.Connected; outstandingDataMessages: TLSocketServerSentDataEvent[]; serializedSchema: SerializedSchema; debounceTimer: null | ReturnType; lastInteractionTime: number; requiresDownMigrations: boolean; }); // @internal export interface RoomSessionBase { isReadonly: boolean; meta: Meta; objectAccess: TLObjectStoreAccess; presenceId: null | string; requiresLegacyRejection: boolean; sessionId: string; socket: TLRoomSocket; supportsStringAppend: boolean; } // @internal export const RoomSessionState: { readonly AwaitingRemoval: 'awaiting-removal'; readonly Connected: 'connected'; readonly AwaitingConnectMessage: 'awaiting-connect-message'; }; // @internal export type RoomSessionState = (typeof RoomSessionState)[keyof typeof RoomSessionState]; // @public export interface RoomSnapshot { clock?: number; documentClock?: number; documents: Array<{ lastChangedClock: number; state: UnknownRecord; }>; schema?: SerializedSchema; tombstoneHistoryStartsAtClock?: number; tombstones?: Record; } // @public @deprecated export interface RoomStoreMethods { delete(recordOrId: R | string): void; get(id: string): null | R; getAll(): R[]; put(record: R): void; } // @public export interface SessionStateSnapshot { // (undocumented) isReadonly: boolean; objectAccess?: TLObjectStoreAccess; // (undocumented) presenceId: null | string; // (undocumented) presenceRecord: null | UnknownRecord; // (undocumented) requiresLegacyRejection: boolean; // (undocumented) serializedSchema: SerializedSchema; // (undocumented) supportsStringAppend: boolean; } // @public export class SQLiteSyncStorage implements TLSyncStorage { constructor({ sql, snapshot, objectTypes, onChange, }: { objectTypes?: readonly string[]; onChange?(arg: TLSyncStorageOnChangeCallbackProps): unknown; snapshot?: RoomSnapshot | StoreSnapshot; sql: TLSyncSqliteWrapper; }); // (undocumented) getClock(): number; static getDocumentClock(storage: TLSyncSqliteWrapper): null | number; // (undocumented) getObjectsByIds(ids: Iterable): RoomSnapshot['documents']; // (undocumented) getObjectsSnapshot(): RoomSnapshot['documents']; // @internal (undocumented) _getSchema(): SerializedSchema; // (undocumented) getSnapshot(): RoomSnapshot; // @internal (undocumented) _getTombstoneHistoryStartsAtClock(): number; static hasBeenInitialized(storage: TLSyncSqliteWrapper): boolean; // @internal (undocumented) readonly objectTypes: ReadonlySet; // (undocumented) onChange(callback: (arg: TLSyncStorageOnChangeCallbackProps) => void): () => void; // @internal (undocumented) pruneTombstones: DebouncedFunc<() => void>; // @internal (undocumented) _setSchema(schema: SerializedSchema): void; // (undocumented) transaction(callback: TLSyncStorageTransactionCallback, opts?: TLSyncStorageTransactionOptions): TLSyncStorageTransactionResult; } // @public export type SubscribingFn = (cb: (val: T) => void) => () => void; // @public export interface SyncSqliteDatabase { exec(sql: string): void; prepare(sql: string): { all(...params: unknown[]): unknown[]; iterate(...params: unknown[]): IterableIterator; run(...params: unknown[]): unknown; }; } // @internal export interface TLConnectRequest { // (undocumented) connectRequestId: string; // (undocumented) lastServerClock: number; // (undocumented) protocolVersion: number; // (undocumented) schema: SerializedSchema; // (undocumented) type: 'connect'; } // @public export type TLCustomMessageHandler = (this: null, data: any) => void; // @internal @deprecated export const TLIncompatibilityReason: { readonly ClientTooOld: 'clientTooOld'; readonly InvalidOperation: 'invalidOperation'; readonly InvalidRecord: 'invalidRecord'; readonly ServerTooOld: 'serverTooOld'; }; // @internal @deprecated export type TLIncompatibilityReason = (typeof TLIncompatibilityReason)[keyof typeof TLIncompatibilityReason]; // @public export type TLObjectStoreAccess = 'read' | 'write'; // @public export interface TLPersistentClientSocket { close(): void; connectionStatus: 'error' | 'offline' | 'online'; onReceiveMessage: SubscribingFn; onStatusChange: SubscribingFn; restart(): void; sendMessage(msg: ClientSentMessage): void; } // @internal export type TLPersistentClientSocketStatus = 'error' | 'offline' | 'online'; // @internal export interface TLPingRequest { // (undocumented) type: 'ping'; } // @public export type TLPresenceMode = /** No presence sharing - client operates independently */ 'full' | 'solo' /** Full presence sharing - cursors and selections visible to others */; // @internal export interface TLPushRequest { // (undocumented) clientClock: number; // (undocumented) diff?: NetworkDiff; // (undocumented) presence?: [typeof RecordOpType.Patch, ObjectDiff] | [typeof RecordOpType.Put, R]; // (undocumented) type: 'push'; } // @public export type TLRecordAuthorizer = (args: { session: { isReadonly: boolean; meta: SessionMeta; sessionId: string; }; } & ({ next: null; prev: Rec; type: 'delete'; } | { next: Rec; prev: null; type: 'create'; } | { next: Rec; prev: Rec; type: 'update'; })) => null | Rec; // @public export type TLRecordAuthorizers = { [K in R['typeName']]?: TLRecordAuthorizer, SessionMeta>; }; // @public export class TLRemoteSyncError extends Error { constructor(reason: string | TLSyncErrorCloseEventReason); // (undocumented) name: string; // (undocumented) readonly reason: string | TLSyncErrorCloseEventReason; } // @internal export interface TLRoomSocket { close(code?: number, reason?: string): void; isOpen: boolean; sendMessage(msg: TLSocketServerSentEvent): void; } // @internal export type TLSocketClientSentEvent = TLConnectRequest | TLPingRequest | TLPushRequest; // @public export class TLSocketRoom { constructor(opts: TLSocketRoomOptions); close(): void; closeSession(sessionId: string, fatalReason?: string | TLSyncErrorCloseEventReason): void; getCurrentDocumentClock(): number; getCurrentObjectsSnapshot(): RoomSnapshot['documents']; // @deprecated getCurrentSnapshot(): RoomSnapshot; getNumActiveSessions(): number; // @internal getPresenceRecords(): Record; getRecord(id: string): R; getSessions(): Array<{ isConnected: boolean; isReadonly: boolean; meta: SessionMeta; objectAccess: TLObjectStoreAccess; sessionId: string; }>; getSessionSnapshot(sessionId: string): null | SessionStateSnapshot; handleSocketClose(sessionId: string): void; handleSocketConnect(opts: { isReadonly?: boolean; objectAccess?: TLObjectStoreAccess; sessionId: string; socket: WebSocketMinimal; } & (SessionMeta extends void ? object : { meta: SessionMeta; })): void; handleSocketError(sessionId: string): void; handleSocketMessage(sessionId: string, message: AllowSharedBufferSource | string): void; handleSocketResume(opts: { sessionId: string; snapshot: SessionStateSnapshot; socket: WebSocketMinimal; } & (SessionMeta extends void ? object : { meta: SessionMeta; })): void; isClosed(): boolean; loadSnapshot(snapshot: RoomSnapshot | TLStoreSnapshot): void; // (undocumented) readonly log?: TLSyncLog; // (undocumented) readonly opts: TLSocketRoomOptions; sendCustomMessage(sessionId: string, data: any): void; // (undocumented) storage: TLSyncStorage; // @deprecated updateStore(updater: (store: RoomStoreMethods) => Promise | void): Promise; } // @public export interface TLSocketRoomOptions { authorizeRecord?: TLRecordAuthorizers; // (undocumented) clientTimeout?: number; // @deprecated (undocumented) initialSnapshot?: RoomSnapshot | TLStoreSnapshot; // (undocumented) log?: TLSyncLog; objectTypes?: readonly string[]; // (undocumented) onAfterReceiveMessage?: (args: { message: TLSocketServerSentEvent; meta: SessionMeta; sessionId: string; stringified: string; }) => void; // (undocumented) onBeforeSendMessage?: (args: { message: TLSocketServerSentEvent; meta: SessionMeta; sessionId: string; stringified: string; }) => void; onCommittedChanges?: (args: { diff: TLSyncForwardDiff; documentClock: number; }) => void; // @deprecated (undocumented) onDataChange?(): void; // @internal (undocumented) onPresenceChange?(): void; // (undocumented) onSessionRemoved?: (room: TLSocketRoom, args: { meta: SessionMeta; numSessionsRemaining: number; sessionId: string; }) => void; onSessionSnapshot?: (sessionId: string, snapshot: SessionStateSnapshot) => void; // (undocumented) schema?: StoreSchema; // (undocumented) storage?: TLSyncStorage; } // @internal export type TLSocketServerSentDataEvent = { action: 'commit' | 'discard' | { rebaseWithDiff: NetworkDiff; }; clientClock: number; serverClock: number; type: 'push_result'; } | { diff: NetworkDiff; serverClock: number; type: 'patch'; }; // @internal export type TLSocketServerSentEvent = { objectAccess?: TLObjectStoreAccess; connectRequestId: string; diff: NetworkDiff; hydrationType: 'wipe_all' | 'wipe_presence'; isReadonly: boolean; protocolVersion: number; schema: SerializedSchema; serverClock: number; type: 'connect'; } | { data: any; type: 'custom'; } | { data: TLSocketServerSentDataEvent[]; type: 'data'; } | { reason: TLIncompatibilityReason; type: 'incompatibility_error'; } | { type: 'pong'; } | TLSocketServerSentDataEvent; // @public export type TLSocketStatusChangeEvent = { status: 'offline' | 'online'; } | { status: 'error'; reason: string; }; // @internal export type TLSocketStatusListener = (params: TLSocketStatusChangeEvent) => void; // @public export type TLSqliteInputValue = bigint | null | number | string | Uint8Array; // @public export type TLSqliteOutputValue = bigint | null | number | string | Uint8Array; // @public export type TLSqliteRow = Record; // @public export class TLSyncClient = Store> { constructor(config: { didCancel?(): boolean; onAfterConnect?(self: TLSyncClient, details: { isReadonly: boolean; objectAccess: TLObjectStoreAccess; }): void; onCustomMessageReceived?: TLCustomMessageHandler; onLoad(self: TLSyncClient): void; onSyncError(reason: string): void; presence: Signal; presenceMode?: Signal; socket: TLPersistentClientSocket; store: S; }); close(): void; // @internal (undocumented) isConnectedToRoom: boolean; // @internal (undocumented) latestConnectRequestId: null | string; // @internal (undocumented) readonly presenceMode: Signal | undefined; // @internal (undocumented) readonly presenceState: Signal | undefined; // @internal (undocumented) readonly socket: TLPersistentClientSocket, TLSocketServerSentEvent>; // @internal (undocumented) readonly store: S; } // @public export const TLSyncErrorCloseEventCode: 4099; // @public export const TLSyncErrorCloseEventReason: { readonly MESSAGE_TOO_LARGE: 'MESSAGE_TOO_LARGE'; readonly RATE_LIMITED: 'RATE_LIMITED'; readonly CLIENT_TOO_OLD: 'CLIENT_TOO_OLD'; readonly INVALID_RECORD: 'INVALID_RECORD'; readonly ROOM_FULL: 'ROOM_FULL'; readonly NOT_FOUND: 'NOT_FOUND'; readonly SERVER_TOO_OLD: 'SERVER_TOO_OLD'; readonly UNKNOWN_ERROR: 'UNKNOWN_ERROR'; readonly NOT_AUTHENTICATED: 'NOT_AUTHENTICATED'; readonly FORBIDDEN: 'FORBIDDEN'; }; // @public export type TLSyncErrorCloseEventReason = (typeof TLSyncErrorCloseEventReason)[keyof typeof TLSyncErrorCloseEventReason]; // @public export interface TLSyncForwardDiff { // (undocumented) deletes: string[]; // (undocumented) puts: Record; } // @public export interface TLSyncLog { error?(...args: any[]): void; warn?(...args: any[]): void; } // @internal export class TLSyncRoom { constructor(opts: { onCommittedChanges?(args: { diff: TLSyncForwardDiff; documentClock: number; }): void; authorizeRecord?: TLRecordAuthorizers; objectTypes?: readonly string[]; clientTimeout?: number; log?: TLSyncLog; onPresenceChange?(): void; schema: StoreSchema; storage: TLSyncStorage; }); close(): void; // (undocumented) readonly documentTypes: Set; // (undocumented) readonly events: Emitter< { room_became_empty(): void; session_removed(args: { meta: SessionMeta; sessionId: string; }): void; }>; // (undocumented) _flushDataMessages(sessionId: string): void; getCanEmitStringAppend(): boolean; handleClose(sessionId: string): void; handleMessage(sessionId: string, message: TLSocketClientSentEvent): Promise; handleNewSession(opts: { isReadonly: boolean; meta: SessionMeta; objectAccess?: TLObjectStoreAccess; sessionId: string; socket: TLRoomSocket; }): this; handleResumedSession(opts: { isReadonly: boolean; meta: SessionMeta; objectAccess?: TLObjectStoreAccess; presenceId: null | string; presenceRecord: null | UnknownRecord; requiresLegacyRejection: boolean; serializedSchema: SerializedSchema; sessionId: string; socket: TLRoomSocket; supportsStringAppend: boolean; }): void; // (undocumented) readonly internalTxnId = "TLSyncRoom.txn"; isClosed(): boolean; readonly objectTypes: Set; // (undocumented) readonly presenceStore: PresenceStore; // (undocumented) readonly presenceType: null | RecordType; // (undocumented) pruneSessions: DebouncedFuncLeading<() => void>; rejectSession(sessionId: string, fatalReason?: string | TLSyncErrorCloseEventReason): void; // (undocumented) readonly schema: StoreSchema; sendCustomMessage(sessionId: string, data: any): void; // (undocumented) readonly serializedSchema: SerializedSchema; // (undocumented) readonly sessions: Map>; } // @public export interface TLSyncSqliteStatement { all(...bindings: TParams): TResult[]; iterate(...bindings: TParams): IterableIterator; run(...bindings: TParams): void; } // @public export interface TLSyncSqliteWrapper { readonly config?: TLSyncSqliteWrapperConfig; exec(sql: string): void; prepare(sql: string): TLSyncSqliteStatement; transaction(callback: () => T): T; } // @public export interface TLSyncSqliteWrapperConfig { tablePrefix?: string; } // @public export interface TLSyncStorage { // (undocumented) getClock(): number; getObjectsByIds?(ids: Iterable): RoomSnapshot['documents']; getObjectsSnapshot?(): RoomSnapshot['documents']; getSnapshot?(): RoomSnapshot; // (undocumented) onChange(callback: (arg: TLSyncStorageOnChangeCallbackProps) => unknown): () => void; // (undocumented) transaction(callback: TLSyncStorageTransactionCallback, opts?: TLSyncStorageTransactionOptions): TLSyncStorageTransactionResult; } // @public export interface TLSyncStorageGetChangesSinceResult { diff: TLSyncForwardDiff; wipeAll: boolean; } // @public export interface TLSyncStorageOnChangeCallbackProps { // (undocumented) documentClock: number; id?: string; } // @public export interface TLSyncStorageTransaction extends SynchronousStorage { getChangesSince(sinceClock: number): TLSyncStorageGetChangesSinceResult | undefined; getClock(): number; } // @public export type TLSyncStorageTransactionCallback = (txn: TLSyncStorageTransaction) => T extends Promise ? { __error: 'Transaction callbacks cannot be async. Use synchronous operations only.'; } : T; // @public export interface TLSyncStorageTransactionOptions { emitChanges?: 'always' | 'when-different'; id?: string; } // @public export interface TLSyncStorageTransactionResult { changes?: TLSyncForwardDiff; // (undocumented) didChange: boolean; // (undocumented) documentClock: number; // (undocumented) result: T; } // @internal export type ValueOp = AppendOp | DeleteOp | PatchOp | PutOp; // @internal export const ValueOpType: { readonly Append: 'append'; readonly Delete: 'delete'; readonly Patch: 'patch'; readonly Put: 'put'; }; // @internal export type ValueOpType = (typeof ValueOpType)[keyof typeof ValueOpType]; // @public export interface WebSocketMinimal { addEventListener?: (type: 'close' | 'error' | 'message', listener: (event: any) => void) => void; close: (code?: number, reason?: string) => void; readyState: number; removeEventListener?: (type: 'close' | 'error' | 'message', listener: (event: any) => void) => void; send: (data: string) => void; } // (No @packageDocumentation comment for this package) ```