Documentation
¶
Index ¶
- type ASTSet
- func (set ASTSet) Merge(other ASTSet) ASTSet
- func (set ASTSet) ReduceResiduals(opts ...cel.ProgramOption) (ProgramSet, error)
- func (set *ASTSet) SetRuleValue(ruleValue protoreflect.Value, ruleDescriptor protoreflect.FieldDescriptor)
- func (set ASTSet) ToProgramSet(opts ...cel.ProgramOption) (out ProgramSet, err error)
- type Expressions
- type Now
- type NowPool
- type ProgramSet
- type Variable
- type VariablePool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ASTSet ¶
type ASTSet struct {
// contains filtered or unexported fields
}
ASTSet represents a collection of compiledAST and their associated cel.Env.
func CompileASTs ¶
func CompileASTs( expressions Expressions, env *cel.Env, envOpts ...cel.EnvOption, ) (set ASTSet, err error)
CompileASTs parses and type checks a set of expressions, producing a resulting ASTSet. The value can then be converted to a ProgramSet via ASTSet.ToProgramSet or ASTSet.ReduceResiduals. Use Compile instead if no cel.ProgramOption args need to be provided or residuals do not need to be computed.
func (ASTSet) ReduceResiduals ¶
func (set ASTSet) ReduceResiduals(opts ...cel.ProgramOption) (ProgramSet, error)
ReduceResiduals generates a ProgramSet, performing a partial evaluation of the ASTSet to optimize the expression. If the expression is optimized to either a true or empty string constant result, no compiledProgram is generated for it. The main usage of this is to elide tautological expressions from the final result.
func (*ASTSet) SetRuleValue ¶ added in v0.8.0
func (set *ASTSet) SetRuleValue( ruleValue protoreflect.Value, ruleDescriptor protoreflect.FieldDescriptor, )
SetRuleValue sets the rule value for the programs in the ASTSet.
func (ASTSet) ToProgramSet ¶
func (set ASTSet) ToProgramSet(opts ...cel.ProgramOption) (out ProgramSet, err error)
ToProgramSet generates a ProgramSet from the specified ASTs.
type Expressions ¶ added in v0.8.0
type Expressions struct {
Constraints []*validate.Constraint
RulePath []*validate.FieldPathElement
}
An Expressions instance is a container for the information needed to compile and evaluate a list of CEL-based expressions, originating from a validate.Constraint.
type Now ¶
type Now struct {
// TS is the already resolved timestamp. If unset, the field is populated with
// timestamppb.Now.
TS *timestamppb.Timestamp
}
Now implements interpreter.Activation, providing a lazily produced timestamp for accessing the variable `now` that's constant within an evaluation.
func (*Now) Parent ¶
func (n *Now) Parent() interpreter.Activation
type ProgramSet ¶
type ProgramSet []compiledProgram
ProgramSet is a list of compiledProgram expressions that are evaluated together with the same input value. All expressions in a ProgramSet may refer to a `this` variable.
func Compile ¶
func Compile( expressions Expressions, env *cel.Env, envOpts ...cel.EnvOption, ) (set ProgramSet, err error)
Compile produces a ProgramSet from the provided expressions in the given environment. If the generated cel.Program require cel.ProgramOption params, use CompileASTs instead with a subsequent call to ASTSet.ToProgramSet.
func (ProgramSet) Eval ¶
func (s ProgramSet) Eval(val protoreflect.Value, failFast bool) error
Eval applies the contained expressions to the provided `this` val, returning either *errors.ValidationError if the input is invalid or errors.RuntimeError if there is a type or range error. If failFast is true, execution stops at the first failed expression.
type Variable ¶
type Variable struct {
// Next is the parent activation
Next interpreter.Activation
// Name is the variable's name
Name string
// Val is the value for this variable
Val any
}
Variable implements interpreter.Activation, providing a lightweight named variable to cel.Program executions.
func (*Variable) Parent ¶
func (v *Variable) Parent() interpreter.Activation
type VariablePool ¶
func (*VariablePool) Get ¶
func (p *VariablePool) Get() *Variable
func (*VariablePool) Put ¶
func (p *VariablePool) Put(v *Variable)