canWriteCell
The canWriteCell method is used to decide whether a client may write a given Cell.
canWriteCell(
pathId: string,
tableId: string,
rowId: string,
cellId: string,
cell: CellOrUndefined,
context: {[key: string]: any} | undefined,
): boolean| Type | Description | |
|---|---|---|
pathId | string | The |
tableId | string | |
rowId | string | |
cellId | string | |
cell | CellOrUndefined | The new value of the |
context | {[key: string]: any} | undefined | The context from the client's |
| returns | boolean | Whether the client may write the |
It is called for each Cell in the changes that a writable client sends, including deletions, where the cell parameter is undefined. It must be synchronous. Cells for which it returns false are neither merged into the Durable Object's MergeableStore nor relayed to other clients, and a client that wrote a newer version is brought back into line with the server.
Example
This example lets staff write anything, but lets customers write only to the orders Table.
import {WsServerDurableObject} from 'tinybase/synchronizers/synchronizer-ws-server-durable-object';
export class MyDurableObject extends WsServerDurableObject {
authorize(pathId, request) {
return {
context: {role: new URL(request.url).searchParams.get('role')},
};
}
canWriteCell(pathId, tableId, rowId, cellId, cell, {role}) {
return role == 'staff' || tableId == 'orders';
}
}
Since
v10.1.0