Documentation
¶
Overview ¶
Package celx provides utilities for working with CEL (Common Expression Language) expressions, including environment creation, expression compilation, evaluation, and conversion between CEL values and JSON-compatible types.
Index ¶
- Variables
- func NewEnv(cfg EnvConfig, vars ...cel.EnvOption) (*cel.Env, error)
- func ToJSON(val ref.Val) (any, error)
- func ToJSONMap(val ref.Val) (map[string]any, error)
- type EnvConfig
- type EvalConfig
- type Evaluator
- func (e *Evaluator) Compile(expression string) (*cel.Ast, *cel.Issues)
- func (e *Evaluator) Evaluate(ctx context.Context, expression string, vars map[string]any) (ref.Val, *cel.EvalDetails, error)
- func (e *Evaluator) EvaluateJSONMap(ctx context.Context, expression string, vars map[string]any) (map[string]any, error)
- func (e *Evaluator) Program(ast *cel.Ast) (cel.Program, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrJSONMapExpected = errors.New("expected JSON object")
ErrJSONMapExpected indicates a CEL value could not be converted into a JSON object map
Functions ¶
Types ¶
type EnvConfig ¶
type EnvConfig struct {
// ParserRecursionLimit caps the parser recursion depth, 0 uses CEL defaults
ParserRecursionLimit int
// ParserExpressionSizeLimit caps expression size (code points), 0 uses CEL defaults
ParserExpressionSizeLimit int
// ComprehensionNestingLimit caps nested comprehensions, 0 disables the check
ComprehensionNestingLimit int
// ExtendedValidations enables extra AST validations (regex, duration, timestamps, homogeneous aggregates)
ExtendedValidations bool
// OptionalTypes enables CEL optional types and optional field syntax
OptionalTypes bool
// IdentifierEscapeSyntax enables backtick escaped identifiers
IdentifierEscapeSyntax bool
// CrossTypeNumericComparisons enables comparisons across numeric types
CrossTypeNumericComparisons bool
// MacroCallTracking records macro calls in AST source info for debugging
MacroCallTracking bool
}
type EvalConfig ¶
type EvalConfig struct {
// Timeout is the maximum duration allowed for evaluating a CEL expression
Timeout time.Duration
// CostLimit caps the runtime cost of CEL evaluation, 0 disables the limit
CostLimit uint64
// InterruptCheckFrequency controls how often CEL checks for interrupts during comprehensions
InterruptCheckFrequency uint
// EvalOptimize enables evaluation-time optimizations for repeated program runs
EvalOptimize bool
// TrackState enables evaluation state tracking for debugging
TrackState bool
}
EvalConfig configures CEL evaluation behavior
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator compiles and evaluates CEL expressions with caching
func NewEvaluator ¶
func NewEvaluator(env *cel.Env, config EvalConfig) *Evaluator
NewEvaluator creates a new CEL evaluator with the provided environment and configuration
func (*Evaluator) Compile ¶
Compile parses and type-checks a CEL expression using the evaluator environment
func (*Evaluator) Evaluate ¶
func (e *Evaluator) Evaluate(ctx context.Context, expression string, vars map[string]any) (ref.Val, *cel.EvalDetails, error)
Evaluate runs a CEL expression against the provided variables
Click to show internal directories.
Click to hide internal directories.