Skip to content

Commit 7f63ad3

Browse files
committed
Initial docs for implementing functions
1 parent a057807 commit 7f63ad3

File tree

1 file changed

+12
-263
lines changed

1 file changed

+12
-263
lines changed

README.md

Lines changed: 12 additions & 263 deletions
Original file line numberDiff line numberDiff line change
@@ -2,266 +2,15 @@
22

33
> A schema for Flipper Expressions
44
5-
```
6-
PASS test/schemas.test.js
7-
expressions.schema.json
8-
expressions
9-
valid
10-
✓ "string" (2 ms)
11-
✓ true
12-
✓ false (1 ms)
13-
✓ 1
14-
✓ 1.1
15-
invalid
16-
✓ null
17-
✓ {}
18-
✓ []
19-
Time
20-
valid
21-
✓ {"Number":{"Time":["2021-01-01T00:00:00Z"]}} (1 ms)
22-
✓ {"Number":{"Time":"2021-01-01T00:00:00-05:00"}} (1 ms)
23-
✓ {"Number":{"Time":{"Property":"created_at"}}}
24-
invalid
25-
✓ {"Time":"2021-01-01"} (1 ms)
26-
✓ {"Time":"January 1, 2021 10:00"}
27-
✓ {"Time":null}
28-
✓ {"Time":false} (1 ms)
29-
✓ {"Time":[{"Property":"created_at"},{"Property":"updated_at"}]}
30-
String
31-
valid
32-
✓ {"String":true}
33-
✓ {"String":false}
34-
✓ {"String":"already a string"}
35-
✓ {"String":1} (1 ms)
36-
✓ {"String":1.1}
37-
✓ {"String":[true]}
38-
✓ {"String":[false]}
39-
✓ {"String":["already a string"]}
40-
✓ {"String":[1]}
41-
✓ {"String":[1.1]}
42-
✓ {"String":{"All":[]}}
43-
✓ {"String":[{"Any":[]}]}
44-
invalid
45-
✓ {"String":null}
46-
✓ {"String":[true,false]}
47-
✓ {"String":true,"Any":[]}
48-
Random
49-
valid
50-
✓ {"Random":[]}
51-
✓ {"Random":2}
52-
✓ {"Random":[100]}
53-
✓ {"Random":[{"Property":"max_rand"}]} (1 ms)
54-
invalid
55-
✓ {"Random":null}
56-
✓ {"Random":[1,2]}
57-
Property
58-
valid
59-
✓ {"Property":"name"}
60-
✓ {"Property":["flipper_id"]}
61-
✓ {"Property":["flipper_id"]}
62-
✓ {"Property":["flipper_id"]}
63-
invalid
64-
✓ {"Property":[]}
65-
✓ {"Property":null}
66-
PercentageOfActors
67-
valid
68-
✓ {"PercentageOfActors":["User;1",42]} (1 ms)
69-
✓ {"PercentageOfActors":["User;1",0]}
70-
✓ {"PercentageOfActors":["string",99.99]}
71-
✓ {"PercentageOfActors":["string",100]}
72-
✓ {"PercentageOfActors":[{"Property":["flipper_id"]},{"Property":["probability"]}]}
73-
✓ {"PercentageOfActors":["User;1",70]}
74-
✓ {"PercentageOfActors":["User;1",70]}
75-
✓ {"PercentageOfActors":["string",-1]}
76-
✓ {"PercentageOfActors":["string",101]}
77-
invalid
78-
✓ {"PercentageOfActors":["string"]}
79-
✓ {"PercentageOfActors":[100]}
80-
✓ {"PercentageOfActors":[{"Property":["flipper_id"]}]} (1 ms)
81-
Percentage
82-
valid
83-
✓ {"Percentage":[0]}
84-
✓ {"Percentage":[99.999]}
85-
✓ {"Percentage":[100]}
86-
✓ {"Percentage":[{"Property":["nines"]}]}
87-
✓ {"Percentage":[-1]}
88-
✓ {"Percentage":[101]} (1 ms)
89-
invalid
90-
✓ {"Percentage":[1,2]}
91-
✓ {"Percentage":[null]}
92-
✓ {"Percentage":null}
93-
Number
94-
valid
95-
✓ {"Number":0}
96-
✓ {"Number":1}
97-
✓ {"Number":1} (1 ms)
98-
✓ {"Number":"0"}
99-
✓ {"Number":"1"}
100-
✓ {"Number":"1.0"}
101-
✓ {"Number":[0]}
102-
✓ {"Number":[1]}
103-
✓ {"Number":[1]}
104-
✓ {"Number":{"Property":"age"}}
105-
invalid
106-
✓ {"Number":null}
107-
✓ {"Number":[true,false]}
108-
✓ {"Number":true,"Any":[]}
109-
Now
110-
valid
111-
✓ {"Now":[]}
112-
✓ {"String":{"Now":[]}}
113-
invalid
114-
✓ {"Now":null}
115-
✓ {"Now":[1]} (2 ms)
116-
✓ {"Now":1}
117-
NotEqual
118-
valid
119-
✓ {"NotEqual":[1,1]} (1 ms)
120-
✓ {"NotEqual":["a","a"]}
121-
✓ {"NotEqual":[1,2]}
122-
✓ {"NotEqual":["a","b"]}
123-
✓ {"NotEqual":[true,false]}
124-
✓ {"NotEqual":[true,true]} (1 ms)
125-
✓ {"NotEqual":[{"Property":"age"},21]}
126-
invalid
127-
✓ {"NotEqual":[1,2,3]}
128-
✓ {"NotEqual":[1]}
129-
✓ {"NotEqual":1}
130-
✓ {"NotEqual":null}
131-
✓ {"NotEqual":[1,2],"Any":[]}
132-
LessThanOrEqualTo
133-
valid
134-
✓ {"LessThanOrEqualTo":[1,1]}
135-
✓ {"LessThanOrEqualTo":[2,1]}
136-
✓ {"LessThanOrEqualTo":["a","b"]} (1 ms)
137-
✓ {"LessThanOrEqualTo":["b","b"]}
138-
✓ {"LessThanOrEqualTo":[1,2]}
139-
✓ {"LessThanOrEqualTo":["b","a"]}
140-
✓ {"LessThanOrEqualTo":[{"Property":"age"},21]}
141-
✓ {"LessThanOrEqualTo":[{"Property":"age"},18]}
142-
invalid
143-
✓ {"LessThanOrEqualTo":[1,2,3]}
144-
✓ {"LessThanOrEqualTo":[1]}
145-
✓ {"LessThanOrEqualTo":1}
146-
✓ {"LessThanOrEqualTo":null}
147-
✓ {"LessThanOrEqualTo":[1,2],"Any":[]}
148-
LessThan
149-
valid
150-
✓ {"LessThan":[1,1]}
151-
✓ {"LessThan":["a","a"]}
152-
✓ {"LessThan":[2,1]}
153-
✓ {"LessThan":[1,2]}
154-
✓ {"LessThan":["b","a"]}
155-
✓ {"LessThan":["a","b"]}
156-
✓ {"LessThan":[{"Property":"age"},18]}
157-
✓ {"LessThan":[{"Property":"age"},18]}
158-
invalid
159-
✓ {"LessThan":[1,2,3]}
160-
✓ {"LessThan":[1]}
161-
✓ {"LessThan":1}
162-
✓ {"LessThan":null} (1 ms)
163-
✓ {"LessThan":[1,2],"Any":[]}
164-
GreaterThanOrEqualTo
165-
valid
166-
✓ {"GreaterThanOrEqualTo":[1,1]}
167-
✓ {"GreaterThanOrEqualTo":[2,1]}
168-
✓ {"GreaterThanOrEqualTo":["a","b"]}
169-
✓ {"GreaterThanOrEqualTo":["b","b"]}
170-
✓ {"GreaterThanOrEqualTo":[1,2]}
171-
✓ {"GreaterThanOrEqualTo":["b","a"]}
172-
✓ {"GreaterThanOrEqualTo":["a","b"]}
173-
✓ {"GreaterThanOrEqualTo":[true,false]}
174-
✓ {"GreaterThanOrEqualTo":[{"Property":"age"},18]}
175-
invalid
176-
✓ {"GreaterThanOrEqualTo":[1,2,3]}
177-
✓ {"GreaterThanOrEqualTo":[1]}
178-
✓ {"GreaterThanOrEqualTo":1}
179-
✓ {"GreaterThanOrEqualTo":null}
180-
✓ {"GreaterThanOrEqualTo":[1,2],"Any":[]}
181-
GreaterThan
182-
valid
183-
✓ {"GreaterThan":[1,1]}
184-
✓ {"GreaterThan":["a","a"]}
185-
✓ {"GreaterThan":[2,1]}
186-
✓ {"GreaterThan":["b","a"]}
187-
✓ {"GreaterThan":["a","b"]}
188-
✓ {"GreaterThan":[{"Property":"age"},18]}
189-
invalid
190-
✓ {"GreaterThan":[1,2,3]}
191-
✓ {"GreaterThan":[1]}
192-
✓ {"GreaterThan":1}
193-
✓ {"GreaterThan":null}
194-
✓ {"GreaterThan":[1,2],"Any":[]}
195-
Equal
196-
valid
197-
✓ {"Equal":[1,1]}
198-
✓ {"Equal":["a","a"]}
199-
✓ {"Equal":[1,2]}
200-
✓ {"Equal":["a","b"]}
201-
✓ {"Equal":[true,false]}
202-
✓ {"Equal":[{"Property":"age"},21]}
203-
invalid
204-
✓ {"Equal":[1,2,3]} (1 ms)
205-
✓ {"Equal":[1]}
206-
✓ {"Equal":1}
207-
✓ {"Equal":null}
208-
✓ {"Equal":[1,2],"Any":[]}
209-
Durations
210-
valid
211-
✓ {"Duration":[2,"seconds"]} (1 ms)
212-
✓ {"Duration":[2,"minutes"]}
213-
✓ {"Duration":[2,"hours"]}
214-
✓ {"Duration":[2,"days"]}
215-
✓ {"Duration":[2,"weeks"]}
216-
✓ {"Duration":[2,"months"]} (1 ms)
217-
✓ {"Duration":[2,"years"]}
218-
invalid
219-
✓ {"Duration":2}
220-
✓ {"Duration":[2]}
221-
✓ {"Duration":[4,"score"]}
222-
Boolean
223-
valid
224-
✓ {"Boolean":true}
225-
✓ {"Boolean":"true"}
226-
✓ {"Boolean":1}
227-
✓ {"Boolean":[true]}
228-
✓ {"Boolean":["true"]}
229-
✓ {"Boolean":[1]}
230-
✓ {"Boolean":{"All":[]}}
231-
✓ {"Boolean":false}
232-
✓ {"Boolean":"false"}
233-
✓ {"Boolean":0}
234-
✓ {"Boolean":[false]}
235-
✓ {"Boolean":["false"]}
236-
✓ {"Boolean":[0]}
237-
✓ {"Boolean":[{"Any":[]}]}
238-
invalid
239-
✓ {"Boolean":null}
240-
✓ {"Boolean":[true,false]}
241-
✓ {"Boolean":true,"Any":[]}
242-
Any
243-
valid
244-
✓ {"Any":[]} (1 ms)
245-
✓ {"Any":[true]}
246-
✓ {"Any":[true,false]}
247-
✓ {"Any":[false,false]}
248-
✓ {"Any":[1,true,"string"]}
249-
✓ {"Any":true} (1 ms)
250-
✓ {"Any":false}
251-
✓ {"Any":[{"Boolean":false},{"Property":"admin"}]}
252-
invalid
253-
✓ {"Any":null}
254-
✓ {"Any":[],"All":[]}
255-
All
256-
valid
257-
✓ {"All":[]}
258-
✓ {"All":[true]}
259-
✓ {"All":[true,false]}
260-
✓ {"All":[1,true,"string"]}
261-
✓ {"All":true}
262-
✓ {"All":false}
263-
✓ {"All":[{"Boolean":true},{"Property":"admin"}]}
264-
invalid
265-
✓ {"All":null}
266-
✓ {"All":[],"Any":[]}
267-
❯```
5+
The structure for flipper Expressions is defined in `[`schemas/schema.json`](./schemas/schema.json) using [JSON Schema](https://json-schema.org) ([draft-07](https://json-schema.org/specification-links.html#draft-7)).
6+
7+
To learn more about JSON Schema, read [Understanding JSON Schema](https://json-schema.org/understanding-json-schema/) or the [Ajv JSON schema validator docs](https://ajv.js.org/json-schema.html).
8+
9+
## Adding a new expression
10+
11+
1. Describe arguments by creating a new file in [`schemas/`](schemas/) named `NewName.schema.json`. You can copy an existing function that has similar semantics to get started.
12+
2. Add the new function in [`schemas/schema.json`](schemas/schema.json) to `$defs/function`.
13+
3. Create a new file in [`examples/`](./examples) named `NewName.json` with valid and invalid examples for the new function. See other examples for inspiration.
14+
4. Implement the function in [`lib/flipper/expressions/`](../../lib/flipper/expressions/).
15+
16+
See [this commit that adds Min/Max functions](https://github.com/jnunemaker/flipper/commit/ee46fab0cda21a32c3a921a8ed1fb94b0842b6b4) for a concrete example.

0 commit comments

Comments
 (0)