celenv

package
v0.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package celenv builds CEL type environments from EvaluationContext proto message descriptors. The environment declares a "ctx" variable of the message type and registers prefix-stripped enum constants for each enum type referenced by the context's fields (e.g., PLAN_LEVEL_ENTERPRISE becomes accessible as PlanLevel.ENTERPRISE in CEL expressions).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoundedDimsFromDescriptor

func BoundedDimsFromDescriptor(md protoreflect.MessageDescriptor) map[string]bool

BoundedDimsFromDescriptor returns the set of inherently bounded dimension names (enum or bool fields) from an EvaluationContext message descriptor.

func ClassifyDimensions

func ClassifyDimensions(
	conditions []*cel.Ast,
	values []*pbflagsv1.FlagValue,
	boundedDims map[string]bool,
) map[string]*DimensionMeta

ClassifyDimensions analyzes a flag's compiled condition chain and classifies each referenced dimension for cache key construction.

conditions and values must have the same length. conditions[i] is the compiled AST (nil for "otherwise") and values[i] is the flag value. boundedDims is the set of inherently bounded dimensions (enum/bool).

func New

New creates a CEL type-checking environment from an EvaluationContext message descriptor. It declares a "ctx" variable of the message type and registers prefix-stripped enum constants for each enum type referenced by the context's fields.

Types

type CompiledExpr

type CompiledExpr struct {
	Source  string      // original CEL source text
	AST     *cel.Ast    // type-checked AST (for dimension extraction)
	Program cel.Program // compiled program (for evaluation)
}

CompiledExpr holds a compiled CEL expression ready for evaluation.

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler compiles and type-checks CEL expressions against the EvaluationContext. Compiled programs can be reused across evaluations.

func NewCompiler

func NewCompiler(md protoreflect.MessageDescriptor) (*Compiler, error)

NewCompiler creates a compiler for the given EvaluationContext message descriptor.

func (*Compiler) Compile

func (c *Compiler) Compile(expr string) (*CompiledExpr, error)

Compile compiles a single CEL expression. The expression must evaluate to bool and use only the v1 restricted subset of CEL operations.

func (*Compiler) Env

func (c *Compiler) Env() *cel.Env

Env returns the underlying CEL environment.

type DimClassification

type DimClassification string

DimClassification describes how a dimension is used for cache key construction.

const (
	Bounded              DimClassification = "bounded"
	FiniteFilterUniform  DimClassification = "finite_filter_uniform"
	FiniteFilterDistinct DimClassification = "finite_filter_distinct"
	Unbounded            DimClassification = "unbounded"
)

type DimensionMeta

type DimensionMeta struct {
	Classification DimClassification `json:"classification"`
	LiteralSet     []string          `json:"literal_set,omitempty"`
}

DimensionMeta holds classification metadata for a single dimension as used by a flag's condition chain.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL