1

I have the following type definitions in my .bolt file called tasks.bolt

//...

type Channel {
   name: ShortNonEmptyString,
   tasks: Map<TaskId, Task>,
   members: Map<UserId, User>
}

type User {
   displayName: ShortNonEmptyString,
   tasks: Map<UserId, Task>,
   channels: Map<ChannelId, Channel>
}

type ChannelId extends String {
    validate() { this.length <= 20 }
}

type TaskId extends String {
    validate() { this.length <= 20 }
}

type UserId extends String {
    //XXX: min. max. length of the user's ID?
    validate() { this.length >= 10 }
}

type Percent {
    validate() { this >= 0 && this <= 1 }
}

type State {
   //TODO: check in client
    validate() { this >= 0 && this <= 3 }
}

type ShortNonEmptyString extends String {
    validate() { this.length > 0 && this.length < 16}
}

//...

After compiling (firebase-bolt < tasks.bolt), the output contains the followings:

"channels": {
    "$key4": {
        ".validate": "$key4.length <= 20 && ***TYPE RECURSION***"
    },
    ".validate": "newData.hasChildren()"
}

I understand it's a recursion because type Channel has Users and Users has Channels. Is this the normal behavior of the bolt compiler? Is my type definition correct? Is my approach good?

Thank you for your help!

  • 1
    Recursion is a problem because the types are directly mapped onto the structure of the database. That is, members within types are mapped to paths. The security rules deal with paths, hence the problem. Recursion implies an infinite path. – cartant Oct 10 '17 at 07:42
  • Thank you for your reply! I will make a secondary alias class to avoid recursion! –  Oct 10 '17 at 07:47

0 Answers0