Common Expression Language (CEL) Guide
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.
Numbers
2 > 13 > 2 && 2 > 13 > 2 || 4 < 3size([1,2,3]) == 3[1,2,3].size() == 31 in [2,1,3]((25 < 50) ? 'yes' : 'no') == 'yes'int(3.14) == 3uint(3.14) == 3uint("3") == 3Strings
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"]"pet".size() == 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}$')"%s %s".format(["hello", "world"]) == "hello world"'hello mellow'.indexOf('ello') == 1'hello mellow'.lastIndexOf('ello') == 7int("123") == 123string(123) == "123"string(3.14) == "3.14"string(true) == "true"bool("true")'a' < 'b'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] == 6Maps
{'a': 10, 'b': 5, 'c': 20}.size() == 3{'a': 1, 'b': 2, 'c': 3}.exists(key, key == 'b')has({'a': 1, 'b':2}.a)'key1' in {'key1': 'value1', 'key2': 'value2'}{'id': 123, 'age': 42}['age'] == 42Math
math.least([2,1,3]) == 1math.greatest([2,1,3]) == 3math.abs(-1) == 1Time
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")duration('1h') == duration('60m')duration("1.5h") - duration("-1.5h") == duration("3h")timestamp('2024-04-21T12:00:00Z') <= timestamp('2025-02-26T12:00:00Z')time.isWeekday(timestamp("2023-10-18T12:00:00Z"))time.isWeekdayInTZ(timestamp("2023-10-22T23:00:00Z"), "Asia/Tokyo")time.isWeekend(timestamp("2023-10-21T12:00:00Z"))time.isWeekendInTZ(timestamp("2023-10-20T23:00:00Z"), "Asia/Tokyo")JSON
You can parse/unmarshal a JSON string as a map and use it in your logic. Here is an example:
json.parse('{"key1": "val1"}')["key1"] == "val1"You can also marshal a JSON object to a string as follows:
json.marshal(json.parse('{"key1": "val1"}')) == '{"key1": "val1"}'Net
Octelium CEL engine supports a few network-specific functions as follows:
net.isIP("192.168.1.1")net.isIPv4("10.0.0.1")net.isIPv6("2001:db8::1")net.isPrivateIP("10.5.0.1")net.isIPInRange("192.168.1.50", "192.168.1.0/24")