Octelium conditions are based on the Common Expression Language (CEL). CEL expressions are used to easily write dynamic, context aware and performant one-liner conditions that evaluate a boolean value used to match a rule without having to actually have to learn a new programming language.
Basic Expressions
Here are some simple expressions that match:
2 > 1
3 > 2 && 2 > 1
3 > 2 || 4 < 3
size([1,2,3]) == 3
1 in [2,1,3]
Strings
Strings have their own methods and functions. Here are some examples:
"group-1".startsWith("group")
"other-group".endsWith("group")
"one-more-group".contains("more")
"group-1" in ["group-1", "group-2", "group-3"]
["group-1", "group-3"].hasAny(["group-1", "group-2"])
["group-1", "group-2", "group-3"].hasAll(["group-1", "group-3"])
"City".toLower() == "city"
"City".toUpper() == "CITY"
"some_val".split("_")[0] == "some"
["hello", "mellow"].join() == "hellomellow"
" \ttrim\n ".trim() == "trim"
"tacocat".substring(4) == "cat"
"gums".reverse() == "smug"
"hello hello".replace("he", "we") == "wello wello"
"cairo".matches('^[a-z]{5}$')
Lists
Lists have their own methods that provides you with some important utilities. Here are some examples:
[1,2,3,4].min() == 1
[1,2,3,4].max() == 4
[1,2,3].all(i, i > 0)
["group-1", "group-2"].all(x, x.startsWith("group"))
["london", "paris", "berlin"].filter(x, x.contains("in"))[0] == "berlin"
["london", "paris"].exists(x, x.endsWith("is"))
[10, -10, 100].exists_one(x, x < 0)
[1,2,3].map(x, x*2)[2] == 6
Time
Octelium provides you with the function now()
to use the current timestamp. Also, the timestamp()
function converts a RFC3339 time format to a timestamp. Moreover, you can use the duration()
function to compare time durations. Here are some examples:
now() > timestamp(ctx.user.metadata.createdAt)
(now() - timestamp(ctx.user.metadata.createdAt)) > duration("12h")
JSON
You can parse a JSON string as a map and use it in your logic. Here is an example:
json.parse('{"key1": "val1"}')["key1"] == "val1"