type Source … type Ast … // NativeRep converts the AST to a Go-native representation. func (ast *Ast) NativeRep() *celast.AST { … } // Expr returns the proto serializable instance of the parsed/checked expression. // // Deprecated: prefer cel.AstToCheckedExpr() or cel.AstToParsedExpr() and call GetExpr() // the result instead. func (ast *Ast) Expr() *exprpb.Expr { … } // IsChecked returns whether the Ast value has been successfully type-checked. func (ast *Ast) IsChecked() bool { … } // SourceInfo returns character offset and newline position information about expression elements. func (ast *Ast) SourceInfo() *exprpb.SourceInfo { … } // ResultType returns the output type of the expression if the Ast has been type-checked, else // returns chkdecls.Dyn as the parse step cannot infer the type. // // Deprecated: use OutputType func (ast *Ast) ResultType() *exprpb.Type { … } // OutputType returns the output type of the expression if the Ast has been type-checked, else // returns cel.DynType as the parse step cannot infer types. func (ast *Ast) OutputType() *Type { … } // Source returns a view of the input used to create the Ast. This source may be complete or // constructed from the SourceInfo. func (ast *Ast) Source() Source { … } // FormatType converts a type message into a string representation. // // Deprecated: prefer FormatCELType func FormatType(t *exprpb.Type) string { … } // FormatCELType formats a cel.Type value to a string representation. // // The type formatting is identical to FormatType. func FormatCELType(t *Type) string { … } type Env … // NewEnv creates a program environment configured with the standard library of CEL functions and // macros. The Env value returned can parse and check any CEL program which builds upon the core // features documented in the CEL specification. // // See the EnvOption helper functions for the options that can be used to configure the // environment. func NewEnv(opts ...EnvOption) (*Env, error) { … } // NewCustomEnv creates a custom program environment which is not automatically configured with the // standard library of functions and macros documented in the CEL spec. // // The purpose for using a custom environment might be for subsetting the standard library produced // by the cel.StdLib() function. Subsetting CEL is a core aspect of its design that allows users to // limit the compute and memory impact of a CEL program by controlling the functions and macros // that may appear in a given expression. // // See the EnvOption helper functions for the options that can be used to configure the // environment. func NewCustomEnv(opts ...EnvOption) (*Env, error) { … } // Check performs type-checking on the input Ast and yields a checked Ast and/or set of Issues. // If any `ASTValidators` are configured on the environment, they will be applied after a valid // type-check result. If any issues are detected, the validators will provide them on the // output Issues object. // // Either checking or validation has failed if the returned Issues value and its Issues.Err() // value are non-nil. Issues should be inspected if they are non-nil, but may not represent a // fatal error. // // It is possible to have both non-nil Ast and Issues values returned from this call: however, // the mere presence of an Ast does not imply that it is valid for use. func (e *Env) Check(ast *Ast) (*Ast, *Issues) { … } // Compile combines the Parse and Check phases CEL program compilation to produce an Ast and // associated issues. // // If an error is encountered during parsing the Compile step will not continue with the Check // phase. If non-error issues are encountered during Parse, they may be combined with any issues // discovered during Check. // // Note, for parse-only uses of CEL use Parse. func (e *Env) Compile(txt string) (*Ast, *Issues) { … } // CompileSource combines the Parse and Check phases CEL program compilation to produce an Ast and // associated issues. // // If an error is encountered during parsing the CompileSource step will not continue with the // Check phase. If non-error issues are encountered during Parse, they may be combined with any // issues discovered during Check. // // Note, for parse-only uses of CEL use Parse. func (e *Env) CompileSource(src Source) (*Ast, *Issues) { … } // Extend the current environment with additional options to produce a new Env. // // Note, the extended Env value should not share memory with the original. It is possible, however, // that a CustomTypeAdapter or CustomTypeProvider options could provide values which are mutable. // To ensure separation of state between extended environments either make sure the TypeAdapter and // TypeProvider are immutable, or that their underlying implementations are based on the // ref.TypeRegistry which provides a Copy method which will be invoked by this method. func (e *Env) Extend(opts ...EnvOption) (*Env, error) { … } // HasFeature checks whether the environment enables the given feature // flag, as enumerated in options.go. func (e *Env) HasFeature(flag int) bool { … } // HasLibrary returns whether a specific SingletonLibrary has been configured in the environment. func (e *Env) HasLibrary(libName string) bool { … } // Libraries returns a list of SingletonLibrary that have been configured in the environment. func (e *Env) Libraries() []string { … } // HasFunction returns whether a specific function has been configured in the environment func (e *Env) HasFunction(functionName string) bool { … } // Functions returns map of Functions, keyed by function name, that have been configured in the environment. func (e *Env) Functions() map[string]*decls.FunctionDecl { … } // HasValidator returns whether a specific ASTValidator has been configured in the environment. func (e *Env) HasValidator(name string) bool { … } // Parse parses the input expression value `txt` to a Ast and/or a set of Issues. // // This form of Parse creates a Source value for the input `txt` and forwards to the // ParseSource method. func (e *Env) Parse(txt string) (*Ast, *Issues) { … } // ParseSource parses the input source to an Ast and/or set of Issues. // // Parsing has failed if the returned Issues value and its Issues.Err() value is non-nil. // Issues should be inspected if they are non-nil, but may not represent a fatal error. // // It is possible to have both non-nil Ast and Issues values returned from this call; however, // the mere presence of an Ast does not imply that it is valid for use. func (e *Env) ParseSource(src Source) (*Ast, *Issues) { … } // Program generates an evaluable instance of the Ast within the environment (Env). func (e *Env) Program(ast *Ast, opts ...ProgramOption) (Program, error) { … } // CELTypeAdapter returns the `types.Adapter` configured for the environment. func (e *Env) CELTypeAdapter() types.Adapter { … } // CELTypeProvider returns the `types.Provider` configured for the environment. func (e *Env) CELTypeProvider() types.Provider { … } // TypeAdapter returns the `ref.TypeAdapter` configured for the environment. // // Deprecated: use CELTypeAdapter() func (e *Env) TypeAdapter() ref.TypeAdapter { … } // TypeProvider returns the `ref.TypeProvider` configured for the environment. // // Deprecated: use CELTypeProvider() func (e *Env) TypeProvider() ref.TypeProvider { … } // UnknownVars returns an interpreter.PartialActivation which marks all variables declared in the // Env as unknown AttributePattern values. // // Note, the UnknownVars will behave the same as an interpreter.EmptyActivation unless the // PartialAttributes option is provided as a ProgramOption. func (e *Env) UnknownVars() interpreter.PartialActivation { … } // PartialVars returns an interpreter.PartialActivation where all variables not in the input variable // set, but which have been configured in the environment, are marked as unknown. // // The `vars` value may either be an interpreter.Activation or any valid input to the // interpreter.NewActivation call. // // Note, this is equivalent to calling cel.PartialVars and manually configuring the set of unknown // variables. For more advanced use cases of partial state where portions of an object graph, rather // than top-level variables, are missing the PartialVars() method may be a more suitable choice. // // Note, the PartialVars will behave the same as an interpreter.EmptyActivation unless the // PartialAttributes option is provided as a ProgramOption. func (e *Env) PartialVars(vars any) (interpreter.PartialActivation, error) { … } // ResidualAst takes an Ast and its EvalDetails to produce a new Ast which only contains the // attribute references which are unknown. // // Residual expressions are beneficial in a few scenarios: // // - Optimizing constant expression evaluations away. // - Indexing and pruning expressions based on known input arguments. // - Surfacing additional requirements that are needed in order to complete an evaluation. // - Sharing the evaluation of an expression across multiple machines/nodes. // // For example, if an expression targets a 'resource' and 'request' attribute and the possible // values for the resource are known, a PartialActivation could mark the 'request' as an unknown // interpreter.AttributePattern and the resulting ResidualAst would be reduced to only the parts // of the expression that reference the 'request'. // // Note, the expression ids within the residual AST generated through this method have no // correlation to the expression ids of the original AST. // // See the PartialVars helper for how to construct a PartialActivation. // // TODO: Consider adding an option to generate a Program.Residual to avoid round-tripping to an // Ast format and then Program again. func (e *Env) ResidualAst(a *Ast, details *EvalDetails) (*Ast, error) { … } // EstimateCost estimates the cost of a type checked CEL expression using the length estimates of input data and // extension functions provided by estimator. func (e *Env) EstimateCost(ast *Ast, estimator checker.CostEstimator, opts ...checker.CostOption) (checker.CostEstimate, error) { … } // configure applies a series of EnvOptions to the current environment. func (e *Env) configure(opts []EnvOption) (*Env, error) { … } func (e *Env) initChecker() (*checker.Env, error) { … } // setCheckerOrError sets the checker.Env or error state in a concurrency-safe manner func (e *Env) setCheckerOrError(chk *checker.Env, chkErr error) { … } // getCheckerOrError gets the checker.Env or error state in a concurrency-safe manner func (e *Env) getCheckerOrError() (*checker.Env, error) { … } // maybeApplyFeature determines whether the feature-guarded option is enabled, and if so applies // the feature if it has not already been enabled. func (e *Env) maybeApplyFeature(feature int, option EnvOption) (*Env, error) { … } // computeUnknownVars determines a set of missing variables based on the input activation and the // environment's configured declaration set. func (e *Env) computeUnknownVars(vars interpreter.Activation) []*interpreter.AttributePattern { … } type Error … type Issues … // NewIssues returns an Issues struct from a common.Errors object. func NewIssues(errs *common.Errors) *Issues { … } // NewIssuesWithSourceInfo returns an Issues struct from a common.Errors object with SourceInfo metatata // which can be used with the `ReportErrorAtID` method for additional error reports within the context // information that's inferred from an expression id. func NewIssuesWithSourceInfo(errs *common.Errors, info *celast.SourceInfo) *Issues { … } // Err returns an error value if the issues list contains one or more errors. func (i *Issues) Err() error { … } // Errors returns the collection of errors encountered in more granular detail. func (i *Issues) Errors() []*Error { … } // Append collects the issues from another Issues struct into a new Issues object. func (i *Issues) Append(other *Issues) *Issues { … } // String converts the issues to a suitable display string. func (i *Issues) String() string { … } // ReportErrorAtID reports an error message with an optional set of formatting arguments. // // The source metadata for the expression at `id`, if present, is attached to the error report. // To ensure that source metadata is attached to error reports, use NewIssuesWithSourceInfo. func (i *Issues) ReportErrorAtID(id int64, message string, args ...any) { … } // getStdEnv lazy initializes the CEL standard environment. func getStdEnv() (*Env, error) { … } type interopCELTypeProvider … // FindStructType returns a types.Type instance for the given fully-qualified typeName if one exists. // // This method proxies to the underlying ref.TypeProvider's FindType method and converts protobuf type // into a native type representation. If the conversion fails, the type is listed as not found. func (p *interopCELTypeProvider) FindStructType(typeName string) (*types.Type, bool) { … } // FindStructFieldNames returns an empty set of field for the interop provider. // // To inspect the field names, migrate to a `types.Provider` implementation. func (p *interopCELTypeProvider) FindStructFieldNames(typeName string) ([]string, bool) { … } // FindStructFieldType returns a types.FieldType instance for the given fully-qualified typeName and field // name, if one exists. // // This method proxies to the underlying ref.TypeProvider's FindFieldType method and converts protobuf type // into a native type representation. If the conversion fails, the type is listed as not found. func (p *interopCELTypeProvider) FindStructFieldType(structType, fieldName string) (*types.FieldType, bool) { … } type interopLegacyTypeProvider … // FindType retruns the protobuf Type representation for the input type name if one exists. // // This method proxies to the underlying types.Provider FindStructType method and converts the types.Type // value to a protobuf Type representation. // // Failure to convert the type will result in the type not being found. func (p *interopLegacyTypeProvider) FindType(typeName string) (*exprpb.Type, bool) { … } // FindFieldType returns the protobuf-based FieldType representation for the input type name and field, // if one exists. // // This call proxies to the types.Provider FindStructFieldType method and converts the types.FIeldType // value to a protobuf-based ref.FieldType representation if found. // // Failure to convert the FieldType will result in the field not being found. func (p *interopLegacyTypeProvider) FindFieldType(structType, fieldName string) (*ref.FieldType, bool) { … } var stdEnvInit … var stdEnv … var stdEnvErr …