TLSocketRoomOptions
Table of contents
Base options for TLSocketRoom.
interface TLSocketRoomOptions<R extends UnknownRecord, SessionMeta> {}Properties
authorizeRecord
Per-type authorizers for client record writes (create, update, delete): veto writes the session isn't allowed to make, or rewrite the record on create — e.g. force a comment's authorId to the signed-in user. See TLRecordAuthorizers.
authorizeRecord?: TLRecordAuthorizers<R, SessionMeta>;clientTimeout
clientTimeout?: number;initialSnapshot
Deprecated: use the storage option instead
initialSnapshot?: RoomSnapshot | TLStoreSnapshot;log
log?: TLSyncLog;objectTypes
Record type names to serve through the object-store lane instead of the document lane. Each must be a document-scoped type registered in the schema. Object-lane writes are gated per session by objectAccess (see TLSocketRoom.handleSocketConnect) rather than isReadonly, so e.g. a session can be allowed to comment without being allowed to edit.
objectTypes?: readonly string[];onAfterReceiveMessage
onAfterReceiveMessage?: (args: {
message: TLSocketServerSentEvent<R>;
meta: SessionMeta;
sessionId: string;
stringified: string;
}) => void;onBeforeSendMessage
onBeforeSendMessage?: (args: {
message: TLSocketServerSentEvent<R>;
meta: SessionMeta;
sessionId: string;
stringified: string;
}) => void;onCommittedChanges
Called once after a client push commits, with the committed document diff. Use to react to document changes as soon as they commit — e.g. project certain record types to an external store. Best-effort: do not throw and do not block.
Only fires for client pushes. Server-initiated changes — updateStore, loadSnapshot, or writing to the storage directly — do not trigger it, so anything mirroring room state through this callback must handle those paths itself.
onCommittedChanges?: (args: {
diff: TLSyncForwardDiff<R>;
documentClock: number;
}) => void;onSessionRemoved
onSessionRemoved?: (
room: TLSocketRoom<R, SessionMeta>,
args: {
meta: SessionMeta;
numSessionsRemaining: number;
sessionId: string;
},
) => void;onSessionSnapshot
When set, the room will call TLSocketRoom.getSessionSnapshot after no message activity for a session for 5s and pass the result to this callback. Use for persisting snapshots to WebSocket attachments (e.g. Cloudflare hibernation). The room clears any pending snapshot when the session closes.
onSessionSnapshot?: (
sessionId: string,
snapshot: SessionStateSnapshot,
) => void;schema
schema?: StoreSchema<R, any>;storage
storage?: TLSyncStorage<R>;Methods
onDataChange
Deprecated: use the storage option with an onChange callback instead