我的.bolt文件中有以下类型定义,名为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}
}
//...
编译后(firebase-bolt&lt; tasks.bolt),输出包含以下内容:
"channels": {
"$key4": {
".validate": "$key4.length <= 20 && ***TYPE RECURSION***"
},
".validate": "newData.hasChildren()"
}
我理解这是递归,因为类型频道有用户和用户有频道。这是bolt编译器的正常行为吗?我的类型定义是否正确?我的做法好吗?
感谢您的帮助!