TinyBase logoTinyBase β

CanWriteValue

The CanWriteValue type describes a function that decides whether a client may write a given Value on a path of a WsServer.

(
  pathId: Id,
  valueId: Id,
  value: ValueOrUndefined,
  context: {[key: string]: any} | undefined,
): boolean
TypeDescription
pathIdId

The Id of the path.

valueIdId

The Id of the Value.

valueValueOrUndefined

The new Value, or undefined if it is being deleted.

context{[key: string]: any} | undefined

The context from the client's ClientAccess.

returnsboolean

Whether the client may write the Value.

It is called for each Value in the changes that a writable client sends to the server, including deletions, where the value parameter is undefined. It must be synchronous. Values for which it returns false are neither merged into the path's MergeableStore nor relayed to other clients.

If the rejected change was newer than the server's own version of that Value, and different from it, the server sends that client alone its own version (or a deletion, if it has none), stamped just after the rejected change. The client is brought back into line with the server, rather than silently diverging from it, and nothing changes on the server or for any other client.

This function decides only about Values. Unless you also provide a CanWriteCell function, every writable client may write any Cell. And unless you provide an Authorize function, every client is admitted as writable, with an undefined context.

Since

v10.1.0