-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.rules.jsonnet
More file actions
79 lines (74 loc) · 2.21 KB
/
Copy pathdatabase.rules.jsonnet
File metadata and controls
79 lines (74 loc) · 2.21 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
// Firebase Realtime Database security rules shared by crosswords, boobtree, and passthepic.
// Render with: jsonnet database.rules.jsonnet -o database.rules.json
local isBoolean = { ".validate": "newData.isBoolean()" };
local isNumber = { ".validate": "newData.isNumber()" };
local isString(minLen=null, maxLen=null) =
local minCheck = if minLen != null then " && newData.val().length >= " + minLen else "";
local maxCheck = if maxLen != null then " && newData.val().length <= " + maxLen else "";
{ ".validate": "newData.isString()" + minCheck + maxCheck };
local boobtreeRules = {
"$game": {
".read": true,
"id": {
".write": "!data.exists()",
".validate": "newData.isString() && newData.val() == $game",
},
"started": {
".write": "newData.isBoolean() && newData.val() == true",
},
"players": {
".write": true,
"$index": isString(minLen=1, maxLen=30),
},
"archive": {
"$round": {
"$player": {
".write": "!data.exists()",
} + isString(maxLen=2000000),
},
},
},
};
{
"rules": {
"crosswords": {
"$puzzle": {
".read": true,
".write": "newData.exists()",
".validate": "newData.hasChildren(['cells'])",
"cells": {
"$row": {
"$col": {
"solution": isString(maxLen=1),
"author": isString(maxLen=16),
"isPencil": isBoolean,
"wordBoundaryAcross": isBoolean,
"wordBoundaryDown": isBoolean,
},
},
},
"presence": {
"$client": {
".validate": "newData.hasChildren(['color'])",
"color": isString(maxLen=16),
"row": isNumber,
"col": isNumber,
"clueNumber": isNumber,
"direction": isNumber,
},
},
"sharedCursor": {
".validate": "newData.hasChildren(['color', 'row', 'col'])",
"color": isString(maxLen=16),
"row": isNumber,
"col": isNumber,
"clueNumber": isNumber,
"direction": isNumber,
},
"togetherMode": isBoolean,
},
},
"boobtree": boobtreeRules,
"passthepic": boobtreeRules,
},
}