canDelCell
The canDelCell
method lets you allow or disallow deletions of a Cell
stored on the server, as sent from a client.
canDelCell(
tableId: string,
rowId: string,
cellId: string,
connection: Connection,
): Promise<boolean>
Type | Description | |
---|---|---|
tableId | string | |
rowId | string | |
cellId | string | |
connection | Connection | |
returns | Promise<boolean> |
This is one of the functions use to sanitize the data that is being sent from a client. Perhaps you might want to make sure the server-stored data adheres to a particular schema, or you might want to make certain data read-only. Remember that you cannot trust the client to only send data that the server considers valid or safe.
This method is passed the Table
Id
, Row
Id
, and Cell
Id
that the client is trying to delete. The connection
parameter will be the web socket connection of that client. You can, for instance, use this to distinguish between different users.
Return false
from this method to disallow this Cell
from being deleted on the server, or true
to allow it. The default implementation returns true
to allow deletion.
Example
The following implementation will strip out any attempts by the client to delete the 'name' Cell
of the 'me' Row
of the 'user' Table
:
import {TinyBasePartyKitServer} from 'tinybase/persisters/persister-partykit-server';
export class MyServer extends TinyBasePartyKitServer {
canDelCell(tableId, rowId, cellId) {
return tableId != 'user' || rowId != 'me' || cellId != 'name';
}
}
Since
v4.3.12