From c52281efb0f8d2011675500bf8f697586417c802 Mon Sep 17 00:00:00 2001 From: Damien Lebrun Date: Wed, 4 Jan 2017 10:28:34 +0000 Subject: [PATCH] feat: use firebase-json to load rules targaryen cli now load rules using firebase-json which support comments and multi lines string. Fix #30 --- bin/targaryen | 6 ++---- package.json | 1 + test/integration/rules.json | 12 +++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/targaryen b/bin/targaryen index 5395d5a..709814d 100755 --- a/bin/targaryen +++ b/bin/targaryen @@ -2,8 +2,7 @@ 'use strict'; -const fs = require('fs'); -const stripJsonComments = require('strip-json-comments'); +const json = require('firebase-json'); const path = require('path'); const Table = require('cli-table'); @@ -21,8 +20,7 @@ if (argv._.length < 2) { const rulesJSONPath = path.resolve(argv._[0]); const testJSONPath = path.resolve(argv._[1]); -const rulesJSONFile = fs.readFileSync(rulesJSONPath); -const rules = JSON.parse(stripJsonComments(rulesJSONFile.toString())); +const rules = json.loadSync(rulesJSONPath, 'utf8'); const tests = require(testJSONPath); const jig = new TestJig(rules, tests); diff --git a/package.json b/package.json index 1f27ec1..b52218b 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "colors": "^1.0.3", "debug": "^2.3.3", "esprima": "^1.2.2", + "firebase-json": "^0.1.0", "firebase-token-generator": "^2.0.0", "lodash.set": "^4.3.2", "minimist": "^1.1.0", diff --git a/test/integration/rules.json b/test/integration/rules.json index 13e8b18..bcc25a9 100644 --- a/test/integration/rules.json +++ b/test/integration/rules.json @@ -1,16 +1,26 @@ { "rules": { "posts": { + /** + * Post. + * + * Read: anybody with the correct clearance level; each post has its own level requirement + * Write: by the author only. + */ "$post": { ".read": "root.child('users').child(auth.uid).child('clearance-level').val() >= data.child('clearance-level').val()", ".write": "root.child('users').child(auth.uid).child('author').val() === true", ".validate": "newData.hasChildren() && newData.hasChild('date')", "date": { - ".validate": "data.parent().exists() === false && newData.val() <= now" + ".validate": " + data.parent().exists() === false + && newData.val() <= now + " } } }, "flight-routes": { + // Flight routes are public and can be added/edited bu ticket agents "$from": { "$to": { ".read": "true",