Classes
RulesAssertionError
Thrown by assertCase / a runner case’s run() when the simulated
decision did not match the case’s expectation. The message is the
rendered trace from explainCase, so a test runner surfaces the “why”
without extra wiring.
Extends
Error
Constructors
Constructor
new RulesAssertionError(message: string): RulesAssertionError;
Parameters
| Parameter | Type |
|---|---|
message | string |
Returns
Overrides
Error.constructor
RulesCompileError
Thrown by firestoreRules(source) / rtdbRules(...) when the source
cannot compile. Carries the compile-blocking issues on .issues so a
caller can surface them without re-parsing.
Extends
Error
Constructors
Constructor
new RulesCompileError(message: string, issues: RuleIssue[]): RulesCompileError;
Parameters
| Parameter | Type |
|---|---|
message | string |
issues | RuleIssue[] |
Returns
Overrides
Error.constructor
Properties
| Property | Modifier | Type |
|---|---|---|
issues | readonly | RuleIssue[] |
RulesUnsupportedError
Thrown by assertCase / a runner case’s run() when the simulator
abstained — it hit a feature it does not implement, so neither a pass nor
a genuine failure can be asserted. Distinct from
RulesAssertionError so a runner can choose to skip rather than
fail on a known simulator gap.
Extends
Error
Constructors
Constructor
new RulesUnsupportedError(message: string): RulesUnsupportedError;
Parameters
| Parameter | Type |
|---|---|
message | string |
Returns
Overrides
Error.constructor
Interfaces
CaseResult
The outcome of running one Firestore case through simulate. Never a
thrown error — a denied or abstained case is data, not an exception.
Properties
| Property | Type | Description |
|---|---|---|
case | FirestoreCase | The case that produced this result. |
decision | "UNSUPPORTED" | "ALLOW" | "DENY" | The engine’s absolute verdict, independent of expectation. |
description | string | - |
expectation | "ALLOW" | "DENY" | - |
notes | string[] | Top-level diagnostic strings. |
passed | boolean | true when decision matched expectation. |
pathResolution? | PathResolutionTrace | Which match blocks the resolver considered and where each fell apart. |
trace | RuleEvaluation[] | Per-rule evaluation entries in source order. |
unsupported | boolean | true when the simulator abstained on a feature it does not implement — neither a pass nor a genuine failure. |
EvaluatedRuleInfo
The DECIDING rule’s source position + sub-expression trace, projected from a
TestResult — for BOTH verdicts: the allow rule that granted an
ALLOW, or the rule responsible for a DENY. Additive companion to
renderLegacyDebugMessages: that flattens the per-rule trace to
strings (dropping line and expressionTrace); this preserves the
structured detail a UI needs to point at the exact source line and step
through the evaluation (“show the work”). Position/trace fields are optional
so a partial trace projects honestly.
Properties
| Property | Type | Description |
|---|---|---|
citation? | string | - |
col? | number | - |
column? | number | - |
expression? | string | Pretty-printed condition text of the deciding rule. |
expressionTrace? | ExprTraceEntry[] | Per-sub-expression evaluation trace of the deciding rule. |
file? | string | - |
line? | number | 1-indexed source line of the deciding allow rule. |
verdict | "allow" | "deny" | The verdict the deciding rule produced for the op. |
Explanation
The structured account of why one Firestore case resolved as it did.
Properties
| Property | Type | Description |
|---|---|---|
deciding? | EvaluatedRuleInfo | The deciding allow rule (line, condition text, sub-expression trace), when one was evaluated. Absent on default-deny / abstain. |
decision | "UNSUPPORTED" | "ALLOW" | "DENY" | - |
expectation | "ALLOW" | "DENY" | - |
notes | string[] | - |
passed | boolean | - |
pathResolution? | PathResolutionTrace | - |
trace | RuleEvaluation[] | - |
unsupported | boolean | - |
ExprTraceEntry
One entry in a per-rule expression trace, emitted in evaluation order.
Properties
FirestoreCase
One Firestore rules case: a single request plus the outcome it should
produce. Structurally identical to the engine’s TestCase — re-exported
here under the public name so callers never reach into the engine seam.
Properties
FirestoreRuleset
Methods
explain()
explain(oneCase: FirestoreCase): Explanation;
The structured account of why one case resolved as it did.
Parameters
| Parameter | Type |
|---|---|
oneCase | FirestoreCase |
Returns
lint()
lint(): RuleIssue[];
Structural, security, and budget findings on the compiled ruleset. No parse errors — the source already compiled.
Returns
simulate()
simulate(cases: FirestoreCase[]): SimulationSummary;
Run every case. Never throws on a rule outcome: a denied or abstained case is reported in the returned summary.
Parameters
| Parameter | Type |
|---|---|
cases | FirestoreCase[] |
Returns
toJSON()
toJSON(): FirestoreRules;
The parsed ruleset as plain data (the AST).
Returns
FirestoreRules
PathDef
Definition of rules for a single database path.
Properties
| Property | Type |
|---|---|
children? | Record<string, PathDef> |
fieldConstraints? | Record<string, Expr[]> |
indexOn? | string[] |
read? | string |
schema? | ZodObject<any> |
validate? | string |
write? | string |
PathResolutionEntry
One match block the simulator considered while resolving the
request path. Together, PathResolutionTrace.attempts forms a
complete picture of “what did the resolver try, and where did
each attempt fall apart?” — useful for the agent when a request
lands in the default-deny path because no block matched.
Recorded only by the local simulator; the production Test API client doesn’t expose path-resolution internals.
Properties
PathResolutionTrace
Properties
| Property | Type | Description |
|---|---|---|
attempts | PathResolutionEntry[] | One entry per match block the resolver considered, in the order it tried them. attempts[i].matched: true marks a block that fully resolved; one or more per trace, since overlapping blocks all match and OR-combine. |
requestPath | string | The request path that was resolved, verbatim from TestCase.path. |
RtdbCase
One Realtime Database rules case. expectation is required so a simulate
run can partition cases into passed/failed the same way Firestore does —
the RTDB simulator otherwise returns only a raw allow/deny with no notion
of an expectation.
Properties
RtdbCaseResult
The outcome of running one RTDB case through simulate.
Properties
| Property | Type | Description |
|---|---|---|
case | RtdbCase | - |
decision | "UNSUPPORTED" | "ALLOW" | "DENY" | - |
description? | string | - |
expectation | "ALLOW" | "DENY" | - |
matchedPath | string | The tree path whose rule decided the request. |
matchedRule | string | Which rule kind (.read / .write / .validate) decided. |
passed | boolean | - |
reason | string | Engine-provided reason string. |
unsupported | boolean | - |
RtdbExplanation
Properties
| Property | Type |
|---|---|
decision | "UNSUPPORTED" | "ALLOW" | "DENY" |
expectation | "ALLOW" | "DENY" |
matchedPath | string |
matchedRule | string |
passed | boolean |
reason | string |
unsupported | boolean |
RtdbRulesCheckResult
Properties
| Property | Type |
|---|---|
errors | RtdbRulesFinding[] |
ok | boolean |
warnings | RtdbRulesFinding[] |
RtdbRulesDefinition
Properties
| Property | Type |
|---|---|
paths | | Record<string, PathDef> | (ctx: RulesetContext) => void |
RtdbRulesDocument
The authored RTDB rules artifact defineRtdbRules returns.
Deliberately INERT on the public surface: it exposes no methods. It is a
value you author and hand to rtdbRules(), which is the one analysis
surface (lint / simulate / explain / toJSON). The brand is
type-level only; nothing exists at runtime.
Properties
RtdbRuleset
Methods
explain()
explain(oneCase: RtdbCase): RtdbExplanation;
The structured account of why one case resolved as it did.
Parameters
| Parameter | Type |
|---|---|
oneCase | RtdbCase |
Returns
lint()
lint(): RuleIssue[];
Structural findings on the compiled ruleset (from check()).
Returns
simulate()
simulate(cases: RtdbCase[]): RtdbSimulationSummary;
Run every case. Never throws on a rule outcome.
Parameters
| Parameter | Type |
|---|---|
cases | RtdbCase[] |
Returns
toJSON()
toJSON(): RtdbRulesJson;
The compiled rules.json.
Returns
RtdbRulesFinding
Properties
| Property | Type |
|---|---|
code | string |
message | string |
path | string |
rule | RtdbRulesFindingRule |
RtdbSimulationSummary
Properties
| Property | Type |
|---|---|
cases | RtdbCaseResult[] |
failed | number |
passed | number |
unsupported | number |
RuleEvaluation
Per-rule evaluation entry produced by the local simulator. Each entry
corresponds to one allow declaration the simulator evaluated, in
source order.
Populated only by the internal simulator (which has the parsed
AST in hand); the production Test API client (TestFirestoreRulesHandler)
returns an empty trace and surfaces the wire text on TestResult.notes.
Properties
| Property | Type | Description |
|---|---|---|
citation? | string | - |
col? | number | - |
column? | number | - |
conditionText? | string | Pretty-printed condition expression. Use this verbatim in agent-facing summaries — derived from the AST via printExpression, so it survives comment removal and whitespace re-flow in the source. |
expressionTrace? | ExprTraceEntry[] | Per-sub-expression evaluation trace for this rule’s condition. Flat, in evaluation order; reconstruct the tree via the parent index on each entry. Populated by the local simulator when the caller enables tracing — currently always on for the simulator so agents can see why a rule’s condition resolved as it did (which disjunct was true, which let binding the value flowed through, which method call threw). Absent on entries that came from the production Test API client (no AST visibility). |
file? | string | - |
line? | number | 1-indexed source line of the allow keyword. Populated when the rule’s loc was set by the parser. |
matchPath? | string | Source-rendered path of the match block this rule belongs to, e.g. '/docs/{docId}' or '/{document=**}'. Populated when the request path matches MORE THAN ONE overlapping match block: allows OR-combine across every matching block (production semantics — there is no first-match-wins), so a DENY trace can carry entries from several blocks. This field keeps them unambiguous — which block did this rule live in. Absent for the common single-block case. |
message? | string | Human-readable diagnostic — populated for UNSUPPORTED (which sim surface is missing) and ERROR (which runtime error caused the rule to abort). |
operations | ("read" | "write" | "delete" | "get" | "list" | "create" | "update")[] | Operations declared on the allow rule (read, write, get, …). |
ruleIndex | number | Position of the allow declaration within its match block, 0-indexed in source order. |
verdict | "ERROR" | "UNSUPPORTED" | "ALLOW" | "DENY" | Outcome for this single rule. The TestResult’s overall decision is derived from the trace under OR semantics (any 'ALLOW' ⇒ ALLOW, else any 'UNSUPPORTED' ⇒ UNSUPPORTED, else DENY). |
RuleIssue
Properties
| Property | Type | Description |
|---|---|---|
code | string | Stable machine code, e.g. 'PARSE_ERROR', 'SEC-4', 'GET_BUDGET'. |
fix? | string | Suggested remediation, verbatim, when the producing stage offers one. |
line? | number | 1-indexed source line, when known. |
message | string | Human-readable description. |
origin | RuleIssueOrigin | - |
path? | string | Rules path the issue applies to, when known (e.g. '/users/{uid}'). |
severity | RuleIssueSeverity | - |
RulesetContext
Context passed to the callback overload of ruleset().
Properties
| Property | Type |
|---|---|
path | (path: string, def: PathDef) => void |
SchemaRulesResult
Properties
| Property | Type |
|---|---|
children | Record<string, { children?: Record<string, { validate: Expr; }>; validate: Expr; }> |
validate | string |
SimulationSummary
Aggregate of a simulate(cases) run. Counts partition the cases:
passed + failed + unsupported === cases.length.
Properties
| Property | Type |
|---|---|
cases | CaseResult[] |
failed | number |
passed | number |
unsupported | number |
Type Aliases
Expr
type Expr = string;
Type alias for RTDB rule expression strings.
FirestoreMethod
type FirestoreMethod = typeof FIRESTORE_METHODS[number];
RtdbRulesFindingRule
type RtdbRulesFindingRule = ".read" | ".write" | ".validate" | "ruleset";
RtdbRulesJson
type RtdbRulesJson = {
rules: Record<string, unknown>;
};
Properties
RtdbRulesSimulationAuth
type RtdbRulesSimulationAuth =
| string
| {
token?: Record<string, unknown>;
uid: string;
}
| null;
RtdbRulesSimulationInput
type RtdbRulesSimulationInput = Omit<SimulationInput, "auth" | "mockData"> & {
auth?: RtdbRulesSimulationAuth;
data?: Record<string, unknown>;
mockData?: Record<string, unknown>;
};
Type Declaration
auth?
optional auth: RtdbRulesSimulationAuth;
data?
optional data: Record<string, unknown>;
mockData?
optional mockData: Record<string, unknown>;
RuleIssueOrigin
type RuleIssueOrigin = "parse" | "validate" | "lint";
The stage that produced the issue.
parse— the source did not parse; nothing downstream ran.validate— a structural/security finding on a parsed ruleset.lint— a budget/quality/hallucination warning.
RuleIssueSeverity
type RuleIssueSeverity = "error" | "warning" | "info";
Ordered by decreasing urgency. info is advisory.
Segment
type Segment =
| string
| {
$: string;
};
A path segment: string for literal, { $: name } for path variable.
Variables
all()
const all: (...exprs: Expr[]) => Expr;
All conditions must be true (AND).
Parameters
| Parameter | Type |
|---|---|
…exprs | Expr[] |
Returns
allow()
const allow: () => Expr;
Always allow (true). Readable alias for always().
Returns
always()
const always: () => Expr;
Always allow (true).
Returns
any()
const any: (...exprs: Expr[]) => Expr;
At least one condition must be true (OR).
Parameters
| Parameter | Type |
|---|---|
…exprs | Expr[] |
Returns
AUTH_UID
const AUTH_UID: Segment;
auth.uid as a comparison value (unquoted in expressions)
authenticated()
const authenticated: () => Expr;
Returns
dataExists()
const dataExists: (path?: string) => Expr;
Check if data exists at current node or a child path
Parameters
| Parameter | Type |
|---|---|
path? | string |
Returns
dataParentVal()
const dataParentVal: (depth: number, field: string) => Expr;
Navigate up from data snapshot, then read a child field’s value
Parameters
| Parameter | Type |
|---|---|
depth | number |
field | string |
Returns
dataVal()
const dataVal: (path?: string) => Expr;
Read data value at current node or a child path (pre-write state)
Parameters
| Parameter | Type |
|---|---|
path? | string |
Returns
deny()
const deny: () => Expr;
Always deny (false).
Returns
eq()
const eq: (left: Expr, right: CompareValue) => Expr;
Strict equality: left === right (right is a literal value or runtime ref)
Parameters
| Parameter | Type |
|---|---|
left | Expr |
right | CompareValue |
Returns
expr()
const expr: (raw: string) => Expr;
Create an Expr from a raw expression string.
Parameters
| Parameter | Type |
|---|---|
raw | string |
Returns
fieldEnum()
const fieldEnum: (field: string, values: string[]) => Expr;
Field must be one of the allowed string values
Parameters
| Parameter | Type |
|---|---|
field | string |
values | string[] |
Returns
fieldIsBoolean()
const fieldIsBoolean: (field: string) => Expr;
Field must be a boolean
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
fieldIsNumber()
const fieldIsNumber: (field: string) => Expr;
Field must be a number
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
fieldIsString()
const fieldIsString: (field: string) => Expr;
Field must be a string
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
fieldOwnerOnly()
const fieldOwnerOnly: (field: string) => Expr;
Only the field owner (auth.uid === data.child(field).val()) can access
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
gt()
const gt: (left: Expr, right: number) => Expr;
Greater than: left > right
Parameters
| Parameter | Type |
|---|---|
left | Expr |
right | number |
Returns
hasChild()
const hasChild: (field: string) => Expr;
Incoming data must have a specific child field
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
hasChildren()
const hasChildren: () => Expr;
Incoming data must be an object with at least one child
Returns
hasRole()
const hasRole: (segments: Segment[], role: string) => Expr;
Cross-path role check via root lookup
Parameters
| Parameter | Type |
|---|---|
segments | Segment[] |
role | string |
Returns
immutable()
const immutable: (field: string) => Expr;
Field can be set on creation but never changed after
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
immutableSelf()
const immutableSelf: () => Expr;
This node’s own value can be set on creation but never changed
Returns
isMember()
const isMember: (listName: string, pathVarName: string) => Expr;
Cross-path membership check: root.child(list).child($var).child(auth.uid).exists()
Parameters
| Parameter | Type |
|---|---|
listName | string |
pathVarName | string |
Returns
isNew()
const isNew: () => Expr;
Data at this path doesn’t exist yet (creation check)
Returns
lte()
const lte: (left: Expr, right: number) => Expr;
Less than or equal: left <= right
Parameters
| Parameter | Type |
|---|---|
left | Expr |
right | number |
Returns
neq()
const neq: (left: Expr, right: CompareValue) => Expr;
Strict inequality: left !== right
Parameters
| Parameter | Type |
|---|---|
left | Expr |
right | CompareValue |
Returns
newDataExists()
const newDataExists: (path?: string) => Expr;
Check if incoming data exists at current node or a child path
Parameters
| Parameter | Type |
|---|---|
path? | string |
Returns
newDataIs()
const newDataIs: (type: "String" | "Number" | "Boolean") => Expr;
Check incoming data type at current node
Parameters
| Parameter | Type |
|---|---|
type | "String" | "Number" | "Boolean" |
Returns
newDataParentExists()
const newDataParentExists: (depth: number, field: string) => Expr;
Navigate up from newData snapshot, then check if a child field exists
Parameters
| Parameter | Type |
|---|---|
depth | number |
field | string |
Returns
newDataParentVal()
const newDataParentVal: (depth: number, field: string) => Expr;
Navigate up from newData snapshot, then read a child field’s value
Parameters
| Parameter | Type |
|---|---|
depth | number |
field | string |
Returns
newDataVal()
const newDataVal: (path?: string) => Expr;
Read incoming data value at current node or a child path (post-write state)
Parameters
| Parameter | Type |
|---|---|
path? | string |
Returns
not()
const not: (e: Expr) => Expr;
Negate a condition.
Parameters
| Parameter | Type |
|---|---|
e | Expr |
Returns
ownerOrNew()
const ownerOrNew: (field: string) => Expr;
Anyone authenticated can create; only the field owner can edit
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
ownField()
const ownField: (field: string) => Expr;
Field-based ownership: auth.uid matches a value stored in a data field
Parameters
| Parameter | Type |
|---|---|
field | string |
Returns
ownPath()
const ownPath: (pathVar: string) => Expr;
Path-based ownership: auth.uid matches a URL path variable
Parameters
| Parameter | Type |
|---|---|
pathVar | string |
Returns
pathOwnerOnly()
const pathOwnerOnly: (pathVar: string) => Expr;
Only the path owner (auth.uid === $pathVar) can access
Parameters
| Parameter | Type |
|---|---|
pathVar | string |
Returns
required()
const required: (...fields: string[]) => Expr;
All specified fields must be present in the incoming data
Parameters
| Parameter | Type |
|---|---|
…fields | string[] |
Returns
rootEquals()
const rootEquals: (segments: Segment[], value: string) => Expr;
Check if a path’s value equals a specific string (via root)
Parameters
| Parameter | Type |
|---|---|
segments | Segment[] |
value | string |
Returns
rootExists()
const rootExists: (segments: Segment[]) => Expr;
Check if a path exists in the database (via root)
Parameters
| Parameter | Type |
|---|---|
segments | Segment[] |
Returns
transition()
const transition: (field: string, allowed: [string, string][]) => Expr;
State machine: only allowed transitions on a field
Parameters
| Parameter | Type |
|---|---|
field | string |
allowed | [string, string][] |
Returns
Functions
assertCase()
Call Signature
function assertCase(result: CaseResult | RtdbCaseResult): void;
Throw when a case result did not pass. A simulator abstention throws
RulesUnsupportedError; a genuine expectation mismatch throws
RulesAssertionError. Both carry the explainCase trace as
their message. Returns void on a passing result.
Parameters
| Parameter | Type |
|---|---|
result | CaseResult | RtdbCaseResult |
Returns
void
Call Signature
function assertCase(ruleset: FirestoreRuleset, oneCase: FirestoreCase): void;
Simulate one case against a ruleset and throw on a miss — the runner
form: for (const c of cases) test(c.description, () => assertCase(ruleset, c)).
Parameters
| Parameter | Type |
|---|---|
ruleset | FirestoreRuleset |
oneCase | FirestoreCase |
Returns
void
Call Signature
function assertCase(ruleset: RtdbRuleset, oneCase: RtdbCase): void;
Throw when a case result did not pass. A simulator abstention throws
RulesUnsupportedError; a genuine expectation mismatch throws
RulesAssertionError. Both carry the explainCase trace as
their message. Returns void on a passing result.
Parameters
| Parameter | Type |
|---|---|
ruleset | RtdbRuleset |
oneCase | RtdbCase |
Returns
void
Call Signature
function assertCase(source: string, oneCase: FirestoreCase): void;
Convenience: compile Firestore source and assert one case against it.
Parameters
| Parameter | Type |
|---|---|
source | string |
oneCase | FirestoreCase |
Returns
void
bytes()
function bytes(input: string | Uint8Array<ArrayBufferLike>): Bytes;
A bytes value.
- string → UTF-8 encoded
- Uint8Array → used verbatim
Parameters
| Parameter | Type |
|---|---|
input | string | Uint8Array<ArrayBufferLike> |
Returns
Bytes
defineRtdbRules()
function defineRtdbRules(definition: RtdbRulesDefinition): RtdbRulesDocument;
Parameters
| Parameter | Type |
|---|---|
definition | RtdbRulesDefinition |
Returns
duration()
function duration(value: number, unit?: string): Duration;
A duration value. unit is one of the Firestore duration units
('w' | 'd' | 'h' | 'm' | 's' | 'ms' | 'ns'); defaults to seconds.
Parameters
| Parameter | Type |
|---|---|
value | number |
unit? | string |
Returns
Duration
explainCase()
function explainCase(result: CaseResult | RtdbCaseResult): string;
Render a case result as a human-readable trace. The single sanctioned
trace renderer — used as the message of the error assertCase throws, and
available directly for logging a result without asserting.
Parameters
| Parameter | Type |
|---|---|
result | CaseResult | RtdbCaseResult |
Returns
string
firestoreRules()
function firestoreRules(source: string): FirestoreRuleset;
Compile Firestore rules source into a deep, safe-by-default handle.
Parameters
| Parameter | Type |
|---|---|
source | string |
Returns
Throws
when the source does not parse. The thrown
error carries the compile-blocking issues on .issues.
flip()
function flip(marks: string[]): string;
Turn flip: validates a turn field alternates between marks. First mark is the initial value on creation. Supports 2+ players with circular rotation.
Parameters
| Parameter | Type | Description |
|---|---|---|
marks | string[] | ordered list of marks (e.g., [“X”, “O”]) |
Returns
string
latlng()
function latlng(lat: number, lng: number): LatLng;
A latlng geographic point.
Parameters
| Parameter | Type |
|---|---|
lat | number |
lng | number |
Returns
LatLng
lint()
function lint(source: string): RuleIssue[];
Lint Firestore rules source. Accepts anything — including empty or syntactically broken source — and always returns an issue list.
Parameters
| Parameter | Type |
|---|---|
source | string |
Returns
reference()
function reference(path: string): Reference;
A reference to a document, by its path (e.g. "users/alice").
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
Reference
rtdbRules()
function rtdbRules(input: RtdbRulesInput): RtdbRuleset;
Build a deep handle on a Realtime Database ruleset from a definition, a
compiled document, or compiled { rules } JSON.
Parameters
| Parameter | Type |
|---|---|
input | RtdbRulesInput |
Returns
ruleset()
function ruleset(input:
| Record<string, PathDef>
| (ctx: RulesetContext) => void): RtdbNode;
Compile a declarative rules definition into an environment-independent tree.
Parameters
| Parameter | Type |
|---|---|
input | | Record<string, PathDef> | (ctx: RulesetContext) => void |
Returns
RtdbNode
schemaRules()
function schemaRules(schema: ZodObject<any>, fieldConstraints?: Record<string, Expr[]>): SchemaRulesResult;
Generate RTDB validate rules from a Zod object schema. Optional fieldConstraints are AND-composed with the schema type check.
Parameters
| Parameter | Type |
|---|---|
schema | ZodObject<any> |
fieldConstraints? | Record<string, Expr[]> |
Returns
serverTimestamp()
function serverTimestamp(): {
};
The server-timestamp sentinel — the case-data equivalent of
FieldValue.serverTimestamp(). The simulator resolves it to the request
time, so a rule comparing data.createdAt == request.time sees a match.
Returns
{
}
timestamp()
function timestamp(input:
| string
| number
| {
nanos?: number;
seconds: number;
}): Timestamp;
A Firestore timestamp value.
- number → milliseconds since the epoch
- string → ISO-8601
- object → explicit
{ seconds, nanos }
Parameters
| Parameter | Type |
|---|---|
input | | string | number | { nanos?: number; seconds: number; } |
Returns
Timestamp
turnGuard()
function turnGuard(
turnField: string,
players: Record<string, string>,
statusField?: string,
playingValue?: string): string;
Turn enforcement: only the current turn’s player can write. Uses data (pre-write) for the turn check — NOT newData.
Parameters
| Parameter | Type | Description |
|---|---|---|
turnField | string | the field that stores whose turn it is (e.g., “currentTurn”) |
players | Record<string, string> | map of mark → player field (e.g., { X: “playerX”, O: “playerO” }) |
statusField? | string | optional field that must equal playingValue for moves to be allowed |
playingValue? | string | the value of statusField during active play (e.g., “playing”) |
Returns
string
vector()
function vector(values: readonly number[]): Vector;
A vector value from its numeric components.
Parameters
| Parameter | Type |
|---|---|
values | readonly number[] |
Returns
Vector
winCheckHelper()
function winCheckHelper(
mark: string,
lines: number[][],
boardPath?: string): string;
Win check helper: validates a boolean field against winning lines on a board. If true, at least one winning line must exist. If false, no winning line can exist. Uses the “client claims, rules verify” pattern.
Parameters
| Parameter | Type | Description |
|---|---|---|
mark | string | the player mark to check (e.g., “X”) |
lines | number[][] | array of winning line coordinates (e.g., [[0,1,2], [3,4,5], …]) |
boardPath? | string | the path to the board relative to the parent (default “board”) |
Returns
string