bolt icon indicating copy to clipboard operation
bolt copied to clipboard

Disallow Firebase Snapshot and String methods

Open mckoss opened this issue 10 years ago • 7 comments

We should not allow Firebase methods to be used in Bolt.

mckoss avatar Sep 11 '15 03:09 mckoss

I think getPriority() should be supported.

matjaz avatar Sep 11 '15 07:09 matjaz

Do you use it? It's no longer recommended to do so. Preferred is using orderByChild.

mckoss avatar Sep 11 '15 13:09 mckoss

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?

matjaz avatar Sep 11 '15 13:09 matjaz

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);

mckoss avatar Sep 11 '15 17:09 mckoss

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.

matjaz avatar Sep 11 '15 20:09 matjaz

.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.

mckoss avatar Sep 11 '15 20:09 mckoss

Does this mean I couldn't perform string validation such as this?

type UserId extends Id {
  validate() = this.startsWith("user_");
}

scriby avatar Jan 08 '16 05:01 scriby