我在名为 tasks.bolt 的 .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 < tasks.bolt),输出包含以下内容:
"channels": {
"$key4": {
".validate": "$key4.length <= 20 && ***TYPE RECURSION***"
},
".validate": "newData.hasChildren()"
}
我知道这是一个递归,因为类型 Channel 有用户并且用户有 Channels。这是螺栓编译器的正常行为吗?我的类型定义正确吗?我的方法好吗?
谢谢您的帮助!