Skip to content

Commit 5004b6f

Browse files
committed
Initial docs for implementing functions
1 parent 08b03c1 commit 5004b6f

File tree

1 file changed

+12
-263
lines changed

1 file changed

+12
-263
lines changed

β€Žpackages/expressions/README.md

+12-263
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)