TinyBase logoTinyBase β

WsServerOptions

The WsServerOptions type describes the options that can be passed to the createWsServer function when using its options object form.

{
  createPersisterForPath?: (pathId: Id) => PathPersister | [PathPersister, (store: MergeableStore) => void] | Promise<PathPersister> | Promise<[PathPersister, (store: MergeableStore) => void]> | undefined;
  authorize?: Authorize;
  canWriteCell?: CanWriteCell;
  canWriteValue?: CanWriteValue;
  onIgnoredError?: (error: any) => void;
  requestTimeoutSeconds?: number;
  fragmentSize?: number;
  maxBufferSize?: number;
}
TypeDescription
createPersisterForPath?(pathId: Id) => PathPersister | [PathPersister, (store: MergeableStore) => void] | Promise<PathPersister> | Promise<[PathPersister, (store: MergeableStore) => void]> | undefined

The createPersisterForPath property is an optional function that will create a Persister to synchronize with the clients on a given path (or a two-item array of Persister and callback that lets you handle data after persistence has started).

authorize?Authorize

The authorize property is an optional Authorize function that decides whether each client may join a path, and how.

canWriteCell?CanWriteCell

The canWriteCell property is an optional CanWriteCell function that decides whether a client may write a given Cell.

canWriteValue?CanWriteValue

The canWriteValue property is an optional CanWriteValue function that decides whether a client may write a given Value.

onIgnoredError?(error: any) => void

The onIgnoredError property is an optional handler for the errors that the server would otherwise ignore when trying to sync data. This is suitable for debugging issues in a development environment.

requestTimeoutSeconds?number

The requestTimeoutSeconds property is an optional time in seconds that the server will wait for responses to synchronization requests and incomplete fragments, defaulting to 1.

fragmentSize?number

The fragmentSize property is an optional target maximum UTF-8 byte size for each WebSocket message fragment sent by the server.

maxBufferSize?number

The maxBufferSize property is an optional number of UTF-8 bytes that each WebSocket may hold, defaulting to 16 MiB (16777216).

Setting any of the authorize, canWriteCell, or canWriteValue options makes each path's MergeableStore the only peer that its clients synchronize with. Clients no longer answer each other directly, so that everything they read and write passes through the server. A path gets an in-memory MergeableStore if the createPersisterForPath option does not provide one.

Since

v10.1.0