bolt
bolt copied to clipboard
ref.hasChild(prop) does not equal ref.prop != null as the docs says
I have this setup where the intent is to make both value optional, but if you write key1 you must also write key2 at the same time. If you write only key2 it is ok.
path /keys/{uid} is AutoLoginKeys
{
read() { auth.uid == uid }
write() { auth.uid == uid }
}
type AutoLoginKeys
{
key1 : String | Null,
key2 : String | Null
write()
{
(this.key1 != null && this.key2 != null) ||
(this.key1 == null)
}
}
This is the generated code
"keys": {
"$uid": {
".validate": "newData.hasChildren()",
"key1": {
".validate": "newData.isString()"
},
"key2": {
".validate": "newData.isString()"
},
"$other": {
".validate": "false"
},
".write": "(newData.child('key1').val() != null && newData.child('key2').val() != null || newData.child('key1').val() == null) && auth.uid == $uid",
".read": "auth.uid == $uid"
}
}
It uses .child(prop).val() instead of ref.hasChild(prop) that the doc claims.
The doc only describes how to convert your firebase rules to bolt. How a bolt definition translate to firebase rules is an implementation detail.
Does it matter that it uses newData.child('key1').val() != null
instead of newData.hasChild('key1')
. AFAIK, using either is correct; maybe one is more efficient but that's not a documentation issue.