Firelaw
raw JSON → 0.0.0 verified Fri May 01 auth: no javascript
Firelaw is a TypeScript transpiler that lets you write type-safe and scalable Firestore Security Rules using TypeScript syntax. Version 0.0.0 is an initial release with rapid iteration. It differentiates by enabling full TypeScript type checking and IDE support for rules, reducing runtime errors compared to writing raw Firebase rules. The library compiles TypeScript to Firestore rules format, handling complex rule generation with type safety.
Common errors
error ReferenceError: firelaw is not defined ↓
cause Using CommonJS require instead of ESM import.
fix
Use import { firelaw } from 'firelaw' and ensure your project is ESM (type: module in package.json or .mjs file).
error TypeError: firelaw is not a function ↓
cause Firelaw is a tagged template tag, not a function that returns a string directly.
fix
Use firelaw
... (backtick template literal) instead of firelaw('...'). Warnings
deprecated firelaw() tagged template literal syntax may change in future versions. ↓
fix Watch for breaking changes in pre-1.0 releases.
gotcha The package is in initial development (v0.0.0). APIs are unstable and may break frequently. ↓
fix Pin to specific version and test thoroughly.
gotcha Cannot use JavaScript; only TypeScript is supported due to compile step. ↓
fix Write rules in TypeScript files with .ts extension.
gotcha Firelaw does not support all Firestore rule features; check documentation for limitations. ↓
fix Review the list of supported functions and operators.
Install
npm install firelaw yarn add firelaw pnpm add firelaw Imports
- firelaw wrong
const firelaw = require('firelaw')correctimport { firelaw } from 'firelaw' - Resource wrong
import Resource from 'firelaw'correctimport { Resource } from 'firelaw' - Request
import { Request } from 'firelaw'
Quickstart
import { firelaw, Resource, Request } from 'firelaw'
const rules = firelaw`
match /databases/{database}/documents {
match /{document=**} {
allow read: if ${(req: Request, res?: Resource) => req.auth != null};
}
}
`
console.log(rules)