Firebase Bolt Compiler

raw JSON →
0.8.4 verified Fri May 01 auth: no javascript

An experimental security and modeling language compiler for Firebase Realtime Database (not Cloud Storage). Compiles .bolt files into Firebase security rules JSON. Current version 0.8.4, in beta, with typescript declarations added in 0.8.3. Key differentiator: acts as a DSL for Firebase security rules, offering type validation, path templates, and schema modeling to reduce manual rules authoring. Alternates like hand-writing JSON or using other rule generators are less expressive.

error Error: The module 'firebase-bolt' does not export a default.
cause Attempting to import with default import (import bolt from 'firebase-bolt') or require syntax.
fix
Use named import: import { compileRules } from 'firebase-bolt'.
error TypeError: bolt.compile is not a function
cause Using wrong import name (compile vs compileRules).
fix
Use compileRules instead of compile. The correct named export is compileRules.
error ParseError: Expected ( but got something else (line 5, col 20)
cause Using deprecated function syntax or incorrect path template, typically missing parentheses or braces.
fix
Review your Bolt syntax. Ensure functions use modern syntax: read() { true } not read() true.
error Error: Cannot find module 'firebase-bolt'
cause Package not installed locally or globally.
fix
Run npm install firebase-bolt in your project directory, or install globally with npm install -g firebase-bolt.
breaking Path expressions now use path template syntax instead of wildcard variables.
fix Replace wildcard variables (e.g., $uid) with path templates (e.g., /users/$uid) in path definitions.
deprecated Function definition format fn(x) = exp; is deprecated.
fix Use modern function syntax: fn(x) { exp }.
gotcha Bolt only supports Firebase Realtime Database, not Cloud Firestore or Cloud Storage.
fix Do not use for Firestore security rules. Use Firebase CLI's built-in rules languages instead.
gotcha Hand-verify generated JSON rules before production use; compiler is experimental.
fix Review rules.json output manually or test in Firebase console.
gotcha The create()/update()/delete() aliases for write() may not be recognized in older Firebase versions.
fix Ensure your Firebase Realtime Database version supports these aliases, or use write() directly.
npm install firebase-bolt
yarn add firebase-bolt
pnpm add firebase-bolt

Compiles a security rules Bolt snippet to JSON using compileRules.

import { compileRules } from 'firebase-bolt';
const boltCode = `
  path / {
    read() { true }
    write() { auth != null }
  }
  type User {
    name: String,
    age: Number
  }
  path /users/$uid is User {
    read() { true }
    write() { $uid === auth.uid }
  }
`;
const rules = compileRules(boltCode);
console.log(JSON.stringify(rules, null, 2));
// Output: {"rules":{".read":"true",".write":"auth != null","users":{"$uid":{".validate":"newData.hasChildren(['name','age'])",".read":"true",".write":"$uid === auth.uid"}}}}