348ff9f66a
Switch on package publishing for sync libraries so we can start building templates on the canaries. ### Change type - [x] `other`
503 lines
15 KiB
Markdown
503 lines
15 KiB
Markdown
## 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<T extends object>(object: T, objectDiff: ObjectDiff): T;
|
|
|
|
// @public (undocumented)
|
|
export function chunk(msg: string, maxSafeMessageSize?: number): string[];
|
|
|
|
// @public (undocumented)
|
|
export class ClientWebSocketAdapter implements TLPersistentClientSocket<TLRecord> {
|
|
constructor(getUri: () => Promise<string> | string);
|
|
// (undocumented)
|
|
close(): void;
|
|
// (undocumented)
|
|
_closeSocket(): void;
|
|
// (undocumented)
|
|
get connectionStatus(): TLPersistentClientSocketStatus;
|
|
// (undocumented)
|
|
_connectionStatus: Atom<'initial' | TLPersistentClientSocketStatus>;
|
|
// (undocumented)
|
|
isDisposed: boolean;
|
|
// (undocumented)
|
|
onReceiveMessage(cb: (val: TLSocketServerSentEvent<TLRecord>) => void): () => void;
|
|
// (undocumented)
|
|
onStatusChange(cb: (val: TLPersistentClientSocketStatus, closeCode?: number) => void): () => void;
|
|
// @internal (undocumented)
|
|
readonly _reconnectManager: ReconnectManager;
|
|
// (undocumented)
|
|
restart(): void;
|
|
// (undocumented)
|
|
sendMessage(msg: TLSocketClientSentEvent<TLRecord>): 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<R extends UnknownRecord> {
|
|
// (undocumented)
|
|
_atom: Atom<{
|
|
lastChangedClock: number;
|
|
state: R;
|
|
}>;
|
|
// (undocumented)
|
|
static createAndValidate<R extends UnknownRecord>(state: R, lastChangedClock: number, recordType: RecordType<R, any>): Result<DocumentState<R>, Error>;
|
|
// (undocumented)
|
|
static createWithoutValidating<R extends UnknownRecord>(state: R, lastChangedClock: number, recordType: RecordType<R, any>): DocumentState<R>;
|
|
// (undocumented)
|
|
get lastChangedClock(): number;
|
|
// (undocumented)
|
|
mergeDiff(diff: ObjectDiff, clock: number): Result<null | ObjectDiff, Error>;
|
|
// (undocumented)
|
|
replaceState(state: R, clock: number): Result<null | ObjectDiff, Error>;
|
|
// (undocumented)
|
|
get state(): R;
|
|
}
|
|
|
|
// @public
|
|
export const getNetworkDiff: <R extends UnknownRecord>(diff: RecordsDiff<R>) => NetworkDiff<R> | null;
|
|
|
|
// @public (undocumented)
|
|
export function getTlsyncProtocolVersion(): number;
|
|
|
|
// @public
|
|
export interface NetworkDiff<R extends UnknownRecord> {
|
|
// (undocumented)
|
|
[id: string]: RecordOp<R>;
|
|
}
|
|
|
|
// @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> | string);
|
|
// (undocumented)
|
|
close(): void;
|
|
// (undocumented)
|
|
connected(): void;
|
|
// (undocumented)
|
|
disconnected(): void;
|
|
// (undocumented)
|
|
intendedDelay: number;
|
|
// (undocumented)
|
|
maybeReconnected(): void;
|
|
}
|
|
|
|
// @public (undocumented)
|
|
export type RecordOp<R extends UnknownRecord> = [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<R extends UnknownRecord, Meta> = {
|
|
cancellationTime: number;
|
|
meta: Meta;
|
|
presenceId: string;
|
|
sessionKey: string;
|
|
socket: TLRoomSocket<R>;
|
|
state: typeof RoomSessionState.AwaitingRemoval;
|
|
} | {
|
|
debounceTimer: null | ReturnType<typeof setTimeout>;
|
|
lastInteractionTime: number;
|
|
meta: Meta;
|
|
outstandingDataMessages: TLSocketServerSentDataEvent<R>[];
|
|
presenceId: string;
|
|
serializedSchema: SerializedSchema;
|
|
sessionKey: string;
|
|
socket: TLRoomSocket<R>;
|
|
state: typeof RoomSessionState.Connected;
|
|
} | {
|
|
meta: Meta;
|
|
presenceId: string;
|
|
sessionKey: string;
|
|
sessionStartTime: number;
|
|
socket: TLRoomSocket<R>;
|
|
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<string, number>;
|
|
}
|
|
|
|
// @public (undocumented)
|
|
export type SubscribingFn<T> = (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<R extends UnknownRecord = UnknownRecord> {
|
|
connectionStatus: 'error' | 'offline' | 'online';
|
|
onReceiveMessage: SubscribingFn<TLSocketServerSentEvent<R>>;
|
|
onStatusChange: SubscribingFn<TLPersistentClientSocketStatus>;
|
|
restart: () => void;
|
|
sendMessage: (msg: TLSocketClientSentEvent<R>) => void;
|
|
}
|
|
|
|
// @public (undocumented)
|
|
export type TLPersistentClientSocketStatus = 'error' | 'offline' | 'online';
|
|
|
|
// @public (undocumented)
|
|
export interface TLPingRequest {
|
|
// (undocumented)
|
|
type: 'ping';
|
|
}
|
|
|
|
// @public (undocumented)
|
|
export interface TLPushRequest<R extends UnknownRecord> {
|
|
// (undocumented)
|
|
clientClock: number;
|
|
// (undocumented)
|
|
diff?: NetworkDiff<R>;
|
|
// (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<R extends UnknownRecord> {
|
|
// (undocumented)
|
|
close: () => void;
|
|
// (undocumented)
|
|
isOpen: boolean;
|
|
// (undocumented)
|
|
sendMessage: (msg: TLSocketServerSentEvent<R>) => void;
|
|
}
|
|
|
|
// @public (undocumented)
|
|
export type TLSocketClientSentEvent<R extends UnknownRecord> = TLConnectRequest | TLPingRequest | TLPushRequest<R>;
|
|
|
|
// @public (undocumented)
|
|
export class TLSocketRoom<R extends UnknownRecord, SessionMeta> {
|
|
constructor(opts: {
|
|
clientTimeout?: number;
|
|
initialSnapshot?: RoomSnapshot;
|
|
log?: TLSyncLog;
|
|
onAfterReceiveMessage?: (args: {
|
|
message: TLSocketServerSentEvent<R>;
|
|
meta: SessionMeta;
|
|
sessionId: string;
|
|
stringified: string;
|
|
}) => void;
|
|
onBeforeSendMessage?: (args: {
|
|
message: TLSocketServerSentEvent<R>;
|
|
meta: SessionMeta;
|
|
sessionId: string;
|
|
stringified: string;
|
|
}) => void;
|
|
onDataChange?: () => void;
|
|
onSessionRemoved?: (room: TLSocketRoom<R, SessionMeta>, args: {
|
|
meta: SessionMeta;
|
|
numSessionsRemaining: number;
|
|
sessionKey: string;
|
|
}) => void;
|
|
schema?: StoreSchema<R, any>;
|
|
});
|
|
// (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<R>;
|
|
meta: SessionMeta;
|
|
sessionId: string;
|
|
stringified: string;
|
|
}) => void;
|
|
onBeforeSendMessage?: (args: {
|
|
message: TLSocketServerSentEvent<R>;
|
|
meta: SessionMeta;
|
|
sessionId: string;
|
|
stringified: string;
|
|
}) => void;
|
|
onDataChange?: () => void;
|
|
onSessionRemoved?: (room: TLSocketRoom<R, SessionMeta>, args: {
|
|
meta: SessionMeta;
|
|
numSessionsRemaining: number;
|
|
sessionKey: string;
|
|
}) => void;
|
|
schema?: StoreSchema<R, any>;
|
|
};
|
|
}
|
|
|
|
// @public (undocumented)
|
|
export type TLSocketServerSentDataEvent<R extends UnknownRecord> = {
|
|
action: 'commit' | 'discard' | {
|
|
rebaseWithDiff: NetworkDiff<R>;
|
|
};
|
|
clientClock: number;
|
|
serverClock: number;
|
|
type: 'push_result';
|
|
} | {
|
|
diff: NetworkDiff<R>;
|
|
serverClock: number;
|
|
type: 'patch';
|
|
};
|
|
|
|
// @public (undocumented)
|
|
export type TLSocketServerSentEvent<R extends UnknownRecord> = {
|
|
connectRequestId: string;
|
|
diff: NetworkDiff<R>;
|
|
hydrationType: 'wipe_all' | 'wipe_presence';
|
|
protocolVersion: number;
|
|
schema: SerializedSchema;
|
|
serverClock: number;
|
|
type: 'connect';
|
|
} | {
|
|
data: TLSocketServerSentDataEvent<R>[];
|
|
type: 'data';
|
|
} | {
|
|
error?: any;
|
|
type: 'error';
|
|
} | {
|
|
reason: TLIncompatibilityReason;
|
|
type: 'incompatibility_error';
|
|
} | {
|
|
type: 'pong';
|
|
} | TLSocketServerSentDataEvent<R>;
|
|
|
|
// @public
|
|
export class TLSyncClient<R extends UnknownRecord, S extends Store<R> = Store<R>> {
|
|
constructor(config: {
|
|
didCancel?: () => boolean;
|
|
onAfterConnect?: (self: TLSyncClient<R, S>, isNew: boolean) => void;
|
|
onLoad: (self: TLSyncClient<R, S>) => void;
|
|
onLoadError: (error: Error) => void;
|
|
onSyncError: (reason: TLIncompatibilityReason) => void;
|
|
presence: Signal<null | R>;
|
|
socket: TLPersistentClientSocket<R>;
|
|
store: S;
|
|
});
|
|
// (undocumented)
|
|
close(): void;
|
|
// (undocumented)
|
|
didCancel?: () => boolean;
|
|
// (undocumented)
|
|
incomingDiffBuffer: TLSocketServerSentDataEvent<R>[];
|
|
// (undocumented)
|
|
isConnectedToRoom: boolean;
|
|
// (undocumented)
|
|
lastPushedPresenceState: null | R;
|
|
// (undocumented)
|
|
latestConnectRequestId: null | string;
|
|
readonly onAfterConnect?: (self: TLSyncClient<R, S>, isNew: boolean) => void;
|
|
// (undocumented)
|
|
readonly onSyncError: (reason: TLIncompatibilityReason) => void;
|
|
// (undocumented)
|
|
readonly presenceState: Signal<null | R> | undefined;
|
|
// (undocumented)
|
|
readonly socket: TLPersistentClientSocket<R>;
|
|
// (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<R extends UnknownRecord, SessionMeta> {
|
|
constructor(schema: StoreSchema<R, any>, snapshot?: RoomSnapshot);
|
|
broadcastPatch({ diff, sourceSessionKey: sourceSessionKey, }: {
|
|
diff: NetworkDiff<R>;
|
|
sourceSessionKey: string;
|
|
}): this;
|
|
// (undocumented)
|
|
clock: number;
|
|
// (undocumented)
|
|
close(): void;
|
|
// (undocumented)
|
|
documentClock: number;
|
|
// (undocumented)
|
|
readonly documentTypes: Set<string>;
|
|
// (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<R>) => Promise<void>;
|
|
handleNewSession: (sessionKey: string, socket: TLRoomSocket<R>, meta: SessionMeta) => this;
|
|
// (undocumented)
|
|
readonly presenceType: RecordType<R, any>;
|
|
// (undocumented)
|
|
pruneSessions: () => void;
|
|
// (undocumented)
|
|
readonly schema: StoreSchema<R, any>;
|
|
// (undocumented)
|
|
readonly serializedSchema: SerializedSchema;
|
|
// (undocumented)
|
|
readonly sessions: Map<string, RoomSession<R, SessionMeta>>;
|
|
// @internal (undocumented)
|
|
state: Atom<{
|
|
documents: Record<string, DocumentState<R>>;
|
|
tombstones: Record<string, number>;
|
|
}, 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)
|
|
|
|
```
|