Env
Env is a program environment configured with the standard CEL library.
The environment can parse and check CEL expressions which build upon the core features documented in the CEL specification.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Env(
optionsInput?):Env
constructor configures the standard library and caller-provided declarations.
Parameters
Section titled “Parameters”optionsInput?
Section titled “optionsInput?”EnvOptions = {}
Returns
Section titled “Returns”Env
Methods
Section titled “Methods”[envState]()
Section titled “[envState]()”[envState]():
EnvState
envState exposes the effective environment state to other parts of this implementation which combine or compare environments. The state is keyed by a module-scoped symbol because it is an implementation seam, not configuration a caller may read or reconstruct: an environment is described by what it can compile and evaluate, not by the option values that produced it.
Returns
Section titled “Returns”EnvState
check()
Section titled “check()”check(
parsed,source):CompileResult
check type-checks a parsed AST using its corresponding source.
Parameters
Section titled “Parameters”parsed
Section titled “parsed”source
Section titled “source”Returns
Section titled “Returns”compile()
Section titled “compile()”compile(
source):CompileResult
compile parses and checks a CEL source string.
Parameters
Section titled “Parameters”source
Section titled “source”string
Returns
Section titled “Returns”compileSource()
Section titled “compileSource()”compileSource(
source):CompileResult
compileSource parses and checks a lower-level CEL source while preserving source metadata.
Parameters
Section titled “Parameters”source
Section titled “source”Returns
Section titled “Returns”estimateCost()
Section titled “estimateCost()”estimateCost(
astValue,estimator?):CostEstimate
estimateCost computes the static evaluation-cost range for a checked AST.
Parameters
Section titled “Parameters”astValue
Section titled “astValue”estimator?
Section titled “estimator?”CostEstimator
Returns
Section titled “Returns”CostEstimate
extend()
Section titled “extend()”extend(
options?):Env
extend creates an isolated environment which inherits this environment’s configuration.
Parameters
Section titled “Parameters”options?
Section titled “options?”EnvOptions = {}
Returns
Section titled “Returns”Env
functions()
Section titled “functions()”functions():
Map<string,FunctionDecl>
functions returns the merged function declarations keyed by function name.
Returns
Section titled “Returns”Map<string, FunctionDecl>
hasFunction()
Section titled “hasFunction()”hasFunction(
name):boolean
hasFunction reports whether the environment contains a function declaration.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
hasLibrary()
Section titled “hasLibrary()”hasLibrary(
name):boolean
hasLibrary reports whether a singleton library is configured.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
hasValidator()
Section titled “hasValidator()”hasValidator(
name):boolean
hasValidator reports whether the environment contains a validator with the given name.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
libraries()
Section titled “libraries()”libraries():
string[]
libraries returns the configured singleton library names.
Returns
Section titled “Returns”string[]
macros()
Section titled “macros()”macros():
Macro[]
macros returns the parser macros configured for the environment.
Returns
Section titled “Returns”Macro[]
optimize()
Section titled “optimize()”optimize(
ast, …passes):AST
optimize applies ordered optimization passes to a checked AST using this environment.
Parameters
Section titled “Parameters”passes
Section titled “passes”…ASTOptimizer[]
Returns
Section titled “Returns”parse()
Section titled “parse()”parse(
source):CompileResult
parse parses a CEL source string into an unchecked AST.
Diagnostics are returned alongside the AST rather than thrown, matching cel-go’s
Env.Parse. Malformed user expressions are an expected outcome of this API, not an
exceptional one.
Parameters
Section titled “Parameters”source
Section titled “source”string
Returns
Section titled “Returns”parseSource()
Section titled “parseSource()”parseSource(
source):CompileResult
parseSource parses a lower-level CEL source while preserving its description and locations.
Parameters
Section titled “Parameters”source
Section titled “source”Returns
Section titled “Returns”partialVars()
Section titled “partialVars()”partialVars(
bindings):PartialActivation
partialVars marks configured environment variables missing from the input activation as unknown.
The input may be an Activation or any valid binding map accepted by activation.
Parameters
Section titled “Parameters”bindings
Section titled “bindings”unknown
Returns
Section titled “Returns”PartialActivation
program()
Section titled “program()”program(
ast,options?):Program
program creates an evaluable program from a parsed or checked AST.
Parameters
Section titled “Parameters”options?
Section titled “options?”ProgramOptions = {}
Returns
Section titled “Returns”residualAst()
Section titled “residualAst()”residualAst(
astValue?,details?):AST
residualAst produces an AST containing only attribute references which remain unknown.
Residual expressions can optimize known evaluations away, support expression indexing and pruning, and surface additional inputs required to complete an evaluation.
Parameters
Section titled “Parameters”astValue?
Section titled “astValue?”details?
Section titled “details?”Returns
Section titled “Returns”toConfig()
Section titled “toConfig()”toConfig(
name):Config
toConfig produces a YAML-serializable configuration representing this environment.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Config
typeAdapter()
Section titled “typeAdapter()”typeAdapter():
TypeAdapter
typeAdapter returns the CEL adapter configured for the environment.
Returns
Section titled “Returns”typeProvider()
Section titled “typeProvider()”typeProvider():
Provider
typeProvider returns the CEL type provider configured for the environment.
Returns
Section titled “Returns”unknownVars()
Section titled “unknownVars()”unknownVars():
PartialActivation
unknownVars returns a partial activation which marks every declared environment variable unknown.
The unknown patterns take effect when the program enables partial evaluation.
Returns
Section titled “Returns”PartialActivation
validators()
Section titled “validators()”validators():
ASTValidator[]
validators returns the environment’s validators in execution order.
Returns
Section titled “Returns”variables()
Section titled “variables()”variables():
VariableDecl[]
variables returns a shallow copy of the caller-configured variable declarations.