Type Aliases
RtdbRulesJson
type RtdbRulesJson = {
rules: Record<string, unknown>;
};
Properties
RtdbTarget
type RtdbTarget =
| LocalSandbox
| {
[TARGET_SYMBOL]: unknown;
};
Target accepting either a LocalSandbox root or a branded Database handle.
Functions
getActiveRules()
function getActiveRules(target: RtdbTarget): RtdbRulesJson;
Read the currently active rules as detached JSON.
Parameters
| Parameter | Type |
|---|---|
target | RtdbTarget |
Returns
setData()
function setData(target: RtdbTarget, data: Record<string, unknown>): void;
Replace RTDB data in bulk without applying security rules.
Parameters
| Parameter | Type |
|---|---|
target | RtdbTarget |
data | Record<string, unknown> |
Returns
void
setDefaultPolicy()
function setDefaultPolicy(target: RtdbTarget, policy: "allow" | "deny"): void;
Set default access policy when no rules are loaded (‘allow’ or ‘deny’). Internal test/dev harness control.
Parameters
| Parameter | Type |
|---|---|
target | RtdbTarget |
policy | "allow" | "deny" |
Returns
void
setRules()
function setRules(target: RtdbTarget, rules: RtdbRulesJson): void;
Replace the active RTDB rules. Pass null to restore default deny.
Parameters
| Parameter | Type |
|---|---|
target | RtdbTarget |
rules | RtdbRulesJson |
Returns
void
snapshotState()
function snapshotState(target: RtdbTarget): JsonValue;
Snapshot the complete RTDB tree without applying security rules.
Parameters
| Parameter | Type |
|---|---|
target | RtdbTarget |
Returns
stripJsonComments()
function stripJsonComments(text: string): string;
Strip JavaScript-style line comments (//...) and block comments (/*...*/)
from JSON source text without altering string literals. Realtime Database
rules files permit comment blocks, requiring pre-processing before evaluation.
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
string
toStrictRulesJson()
function toStrictRulesJson(text: string): string;
Turn Realtime Database rules text into strict JSON text for JSON.parse.
A rules file Firebase deploys may carry three things strict JSON refuses:
line and block comments, a rule expression broken across lines inside its
string, and a trailing comma before } or ]. Comments are removed, raw
control characters inside a string are escaped (a line break stays a line
break in the parsed expression, where it is whitespace), and trailing commas
are dropped. String contents are otherwise unchanged, and every other
malformation is left for JSON.parse to report.
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
string