-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.rules.bolt
More file actions
71 lines (54 loc) · 1.48 KB
/
database.rules.bolt
File metadata and controls
71 lines (54 loc) · 1.48 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
path /users/{uid} {
read() { isCurrentUser(uid) }
write() { isCurrentUser(uid) }
}
path /locations/{approxLat} {
read() { isSignedIn() }
}
path /locations/{approxLat}/{approxLong} {
write() { isSignedIn() }
}
path /locations/{approxLat}/{approxLong}/{gameId} {
}
// path /games/{id} is Timestamped<GameInfo> {
// read() { isSignedIn() && areLocationsClose(getMyLocation(), this.location) }
path /games {
read() { true }
write() { true }
}
type Timestamped<T> extends T {
timestamp: InitialTimestamp
}
type GameInfo {
location: Location,
type: String,
id: String,
timestamp: InitialTimestamp,
game: Object | Null,
}
type UUID extends String {
validate() { this.length == 36 }
}
type Location {
lat: Number,
long: Number,
}
type CurrentTimestamp extends Number {
validate() { this == now }
}
type InitialTimestamp extends Number {
validate() { initial(this, now) }
}
isSignedIn() { auth != null }
isCurrentUser(uid) { auth != null && auth.uid == uid }
initial(value, init) { value == (prior(value) == null ? init : prior(value)) }
writeOnce(value) { prior(value) == null ? true : value == prior(value) }
isExpired(data) { now - data.timestamp > 60 * 60 * 1000 }
getMyLocation() { root.users[auth.uid].location }
distanceThreshold() { 1000000 }
areLocationsClose(loc1, loc2) {
loc1.lat - loc2.lat < distanceThreshold() &&
loc2.lat - loc1.lat < distanceThreshold() &&
loc1.long - loc2.long < distanceThreshold() &&
loc2.long - loc1.long < distanceThreshold()
}