cel
0.6.1, released 4 weeks ago by wafrat.com
Parses and evaluates Common Expression Language (CEL) expressions in Dart.
What it does
Parses and compiles Common Expression Language (CEL) code into an abstract syntax tree and evaluates it against runtime input maps. It allows running expressions and rules similar to those used in Firebase Security Rules and Google Cloud policies. The implementation acts as a simplified Dart port of cel-go.
AI-written summary of version 0.6.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to evaluate CEL rules, filters, or expressions dynamically on client or backend Dart applications.
- You are building local emulation or evaluation of security rules compatible with Google CEL or Firebase rules.
Skip it when
- You need complete CEL spec coverage, specifically protobuf timestamps, durations, or explicit type conversions.
- You need compile-time static type checking rather than evaluation-time runtime errors.
Strengths
- Supports core CEL operators, ternary conditions, regex matching, and map/list lookups.
- Simple API to compile expressions once into programs and evaluate repeatedly with different inputs.
- Pure Dart implementation compatible across all Flutter and Dart platforms.
Weaknesses
- Lacks support for timestamps, durations, bytes manipulation, and protobuf type conversions.
- No compile-time type checking compared to cel-go (errors occur at runtime evaluation).
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
import 'package:cel/cel.dart';
void main() {
final input = "request.auth.claims.group == 'admin'";
final e = Environment.standard();
final ast = e.compile(input);
final p = e.makeProgram(ast);
final result = p.evaluate({
'request': {
'auth': {
'claims': {'group': 'admin'}
}
}
});
print(result); // true
}Alternatives
Packages that do the same job and could replace cel.
- expressions
Parse and evaluate simple Dart and JavaScript like expressions.
51Compare - super_string
Provides common string manipulation and validation extension methods.
50Compare
Works with
Packages commonly used together with cel: ones it builds on, ones built on it, and its own family.