Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
defineRules is a thin identity function that types a Rules object — it returns its argument unchanged. The real enforcement happens in the runtime, where evaluateRules is called before every database operation: before every get and query result is returned, before every insert, before every patch or replace, and before every delete. The model is deny by default: unless an explicit rule function returns true, the operation is blocked.
Signature
Rules Type Structure
Rules is a two-level nested object:
TableRules object with optional read, insert, update, and delete keys. Missing operation keys default to false — the operation is denied.
Rule Operation Signatures
The input types use generics (TContext, TDocument, TValue) so that you can narrow them to your application’s specific types. In the Baseflare runtime, the ctx value is the live context object created for the surrounding function: a QueryCtx for read, and a MutationCtx for insert, update, and delete.
read
Called once per document when returning results from ctx.db.get() or ctx.db.query(). Documents for which the rule returns false are silently filtered out — they are invisible to the handler.
The context from the surrounding function call. At runtime this is always a
QueryCtx object, providing ctx.auth and ctx.db.The candidate document being evaluated. Includes all stored fields plus
_id and _createdAt.insert
Called before a document is written by ctx.db.insert(). Receives the validated field values that would be stored.
The context from the surrounding mutation. At runtime this is a
MutationCtx.The validated document data about to be inserted (no
_id yet).update
Called before a document is modified by ctx.db.patch() or ctx.db.replace(). Receives both the existing document and the merged/replacement data.
The context from the surrounding mutation.
The current document as stored in the database.
The proposed new document data after the patch or replace is applied.
delete
Called before a document is removed by ctx.db.delete().
The context from the surrounding mutation.
The document about to be deleted.
Full Example
evaluateRules(rules, input)
evaluateRules is an internal function also exported from baseflare/server that the runtime calls before every database operation. Developers generally do not call it directly — it is documented here for completeness and for custom runtime integrations.
EvaluationInput is a discriminated union over tableName and operation:
rules[tableName] and dispatches to the correct operation handler. If no table entry or no operation handler is found, it returns false.