انتقل إلى المحتوى

لم تُترجم هذه الصفحة بعد، لذا تُعرض بالإنجليزية.

CEL API Reference

The elide:cel module: compile and evaluate Common Expression Language expressions.

في هذه الصفحة
Open in ChatGPTOpen in Claude

elide:cel compiles and evaluates CEL expressions. Expressions have no side effects and always terminate, so they suit user-supplied rules, filters and policies.

import { compile } from "elide:cel";

const rule = compile("user.age >= 18 && 'admin' in user.roles");
rule.variables; // ["user"]
rule.test({ user: { age: 30, roles: ["admin"] } }); // true
compile("xs.filter(x, x % 2 == 0)").evaluate({ xs: [1, 2, 3, 4] }); // [2, 4]
  • compile(expression) parses and type-checks once and returns a reusable program. Free identifiers become variables, typed dyn. Invalid expressions throw an Error with the CEL diagnostic.
  • program.evaluate(variables?) returns the result; program.test(variables?) requires a boolean. Evaluation failures throw an Error.
  • The standard library and macros (has, all, exists, exists_one, map, filter) are available. CEL extension libraries are not.

Values

JavaScriptCEL
integral number, bigint within int64int
other numberdouble
string, boolean, nullstring, bool, null
Uint8Array, Bufferbytes
array, plain objectlist, map

Results convert back the same way. An int beyond Number.MAX_SAFE_INTEGER returns as a bigint; a timestamp or duration returns as its string form. Comparisons mix int and double freely, arithmetic does not: write double(x) / 2.0 when x may be integral.

Samples

هل كانت هذه الصفحة مفيدة؟