-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.bolt
More file actions
96 lines (75 loc) · 2.01 KB
/
rules.bolt
File metadata and controls
96 lines (75 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
path /users/$userId is User {
read() = isSignedUser();
write() = isCurrentUser($userId);
}
path /feeds/$feedId is Feed {
read() = isFeedUser($feedId);
write() = isNew(this) || isFeedUser($feedId);
}
path /feeds/$feedId/users/$userId is String {
write() = isCurrentUser($userId);
validate() = this == root.feeds[$feedId].password;
}
path /posts/$feedId {
read() = isFeedUser($feedId) || $feedId == 'start';
write() = isFeedUser($feedId);
}
path /posts/$feedId/$postId is Search | Page | Text | Image | Comment;
type User {
name: String,
image: String,
selectedFeed: String | Null,
feeds: Boolean[]
}
type Feed {
name: String,
timestamp: Number,
password: Immutable<String>
}
type Post {
type: String,
user: String,
timestamp: Number,
ancestor: String
}
type Search extends Post {
url: String,
query: String,
validate() = this.type == 'search' && isAncestorType(this, 'root');
}
type Page extends Post {
url: String,
title: String,
favIconUrl: String,
validate() = this.type == 'page' && (isAncestorType(this, 'root') || isAncestorType(this, 'search'));
}
type Text extends Post {
text: String,
validate() = this.type == 'text' && isAncestorType(this, 'page');
}
type Image extends Post {
image: String,
validate() = this.type == 'image' && isAncestorType(this, 'page');
}
type Comment extends Post {
text: String,
validate() = this.type == 'comment';
}
type UserId extends String {
validate() = root.users[this] != null;
}
type FeedId extends String {
validate() = root.feeds[this] != null;
}
type AncestorId extends String {
validate() = this == 'root' || this.parent().parent()[this] != null;
}
type Immutable<T> {
validate() = isNew(this) || this == prior(this);
}
isAncestorType(post, type) = true;
//type == 'root' || post.parent()[post.ancestor].type == type;
isSignedUser() = auth != null;
isCurrentUser(userId) = isSignedUser() && auth.uid == userId;
isFeedUser(feedId) = isSignedUser() && root.feeds[feedId].users[auth.uid] == root.feeds[feedId].password;
isNew(ref) = prior(ref) == null;