Disallow Firebase Snapshot and String methods
We should not allow Firebase methods to be used in Bolt.
I think getPriority() should be supported.
Do you use it? It's no longer recommended to do so. Preferred is using orderByChild.
Currently I don't, but I was thinking about it.
For example /games/1
{
"lastMove": "1,1"
}
/gamesMoves/1
{
"0,0": {".priority": 1},
"1,1": {".priority": 2}
}
path /gamesMoves/$gameId {
write() { prior(this) == null && this.getPriority() == root.gamesMoves[$gameId][root.games[$gameId].lastMove].getPriority() + 1 }
}
I want to validate new move has priority 3. Alternatively I could use numChildren(). Thoughts?
No reason to use .priority at all - just use your own property index (or any other name of your choice):
{
"0,0": {"index": 1},
"1,1": {"index": 2}
}
path /gamesMoves/$gameId {
write() { prior(this) == null && this.index == getLastMove($gameId).index + 1;
}
getMove(gameId, moveId) = root.gamesMoves[gameId][moveId];
getLastMove(gameId) = getMove($gameid, root.games[gameId].lastMove);
That's what a thought. Thanks.
btw. there is no notice about deprecation. https://www.firebase.com/docs/web/api/datasnapshot/getpriority.html
priority also have use case when you query parent object of collection (players/x). /games/1
{
"players": {
"x": {
"user1": 1,
"user3": 2
},
"o": {
"user2": 1,
"user4": 2,
"user5": 3
}
},
"next": "user1"
}
Players must be next is specific order. So without priority I must move players out of /games and use orderByValue.
.priority isn't officially "deprecated" yet - but we're going to start warning developers away from it, now that there is a better, more flexible method.
Does this mean I couldn't perform string validation such as this?
type UserId extends Id {
validate() = this.startsWith("user_");
}