Skip to content

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.

new Env(optionsInput?): Env

constructor configures the standard library and caller-provided declarations.

EnvOptions = {}

Env

[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.

EnvState


check(parsed, source): CompileResult

check type-checks a parsed AST using its corresponding source.

AST

Source

CompileResult


compile(source): CompileResult

compile parses and checks a CEL source string.

string

CompileResult


compileSource(source): CompileResult

compileSource parses and checks a lower-level CEL source while preserving source metadata.

Source

CompileResult


estimateCost(astValue, estimator?): CostEstimate

estimateCost computes the static evaluation-cost range for a checked AST.

AST

CostEstimator

CostEstimate


extend(options?): Env

extend creates an isolated environment which inherits this environment’s configuration.

EnvOptions = {}

Env


functions(): Map<string, FunctionDecl>

functions returns the merged function declarations keyed by function name.

Map<string, FunctionDecl>


hasFunction(name): boolean

hasFunction reports whether the environment contains a function declaration.

string

boolean


hasLibrary(name): boolean

hasLibrary reports whether a singleton library is configured.

string

boolean


hasValidator(name): boolean

hasValidator reports whether the environment contains a validator with the given name.

string

boolean


libraries(): string[]

libraries returns the configured singleton library names.

string[]


macros(): Macro[]

macros returns the parser macros configured for the environment.

Macro[]


optimize(ast, …passes): AST

optimize applies ordered optimization passes to a checked AST using this environment.

AST

…ASTOptimizer[]

AST


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.

string

CompileResult


parseSource(source): CompileResult

parseSource parses a lower-level CEL source while preserving its description and locations.

Source

CompileResult


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.

unknown

PartialActivation


program(ast, options?): Program

program creates an evaluable program from a parsed or checked AST.

AST

ProgramOptions = {}

Program


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.

AST

EvalDetails

AST


toConfig(name): Config

toConfig produces a YAML-serializable configuration representing this environment.

string

Config


typeAdapter(): TypeAdapter

typeAdapter returns the CEL adapter configured for the environment.

TypeAdapter


typeProvider(): Provider

typeProvider returns the CEL type provider configured for the environment.

Provider


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.

PartialActivation


validators(): ASTValidator[]

validators returns the environment’s validators in execution order.

ASTValidator[]


variables(): VariableDecl[]

variables returns a shallow copy of the caller-configured variable declarations.

VariableDecl[]