AST parser and generator for Firebase Firestore and Storage security rules
Full API documentation - Learn about each method
Firestore security rules lacks an available AST parser.... so I made one.
This can come in handy for making additional tools, like IDE plugins, security rules analyzers or even a minifier
- Parses firestore rules into an AST
- Generates rules from an AST
- Support stdin and stdout for the binary commands
npm install --save-dev firetree
The firetree parser can be used as an imported library or as a binary.
To do so, simply
install firetree
as a project dependency and then
import the necessary methods from the firetree
package
npm install --save firetree
import { generate, parse, setupContext } from 'firetree'
const context = setupContext()
const ast = await parse(context, {
filePath: './path/to/firestore.rules')
})
const rulesString = await generate(context, { ast })
You can using the binary directly by installing globally
npm install -g firemin
To parse a rules file, use the parse
command
firetree parse -f ./path/to/my-firestore.rules
By default the output file is ./firestore.ast.rules.json
. To specify a different
path you can use the -o
option.
firetree parse -f ./path/to/my-firestore.rules -o ./output/file/my-firestore.ast.rules.json
To generate a rules file from an AST, use the generate
command
firetree generate -f ./path/to/my-firestore.ast.rules.json
By default the output file is ./firestore.rules
. To specify a different
path you can use the -o
option.
firetree generate -f ./path/to/my-firestore.ast.rules.json -o ./output/file/my-firestore.rules