cel

package
v0.0.4-0...-bd9932a Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BindingsType = cel.OpaqueType("bindings")
	BaseEnv      = sync.OnceValues(func() (*cel.Env, error) {
		return cel.NewEnv(
			cel.Variable("object", cel.DynType),
			cel.Variable("bindings", BindingsType),
			cel.Function("resolve",
				cel.MemberOverload("bindings_resolve_string",
					[]*cel.Type{BindingsType, cel.StringType},
					cel.AnyType,
					cel.BinaryBinding(func(lhs, rhs ref.Val) ref.Val {
						bindings, ok := lhs.(Val[binding.Bindings])
						if !ok {
							return types.ValOrErr(bindings, "invalid bindings type")
						}
						name, ok := rhs.(types.String)
						if !ok {
							return types.ValOrErr(name, "invalid name type")
						}
						value, err := binding.Resolve("$"+string(name), bindings.Unwrap())
						if err != nil {
							return types.WrapErr(err)
						}
						return types.DefaultTypeAdapter.NativeToValue(value)
					}),
				),
			),
		)
	})
	DefaultEnv = sync.OnceValues(func() (*cel.Env, error) {
		if env, err := BaseEnv(); err != nil {
			return nil, err
		} else if env, err := env.Extend(
			cel.HomogeneousAggregateLiterals(),
			cel.EagerlyValidateDeclarations(true),
			cel.DefaultUTCTimeZone(true),
			cel.CrossTypeNumericComparisons(true),
			cel.OptionalTypes(),
			ext.Strings(),
			ext.Sets(),
		); err != nil {
			return nil, err
		} else {
			return env, nil
		}
	})
)

Functions

func Execute

func Execute(program cel.Program, value any, bindings binding.Bindings) (any, error)

func NewCompiler

func NewCompiler(env func() (*cel.Env, error)) *compiler

Types

type Compiler

type Compiler interface {
	Compile(string) (Program, error)
}

type Program

type Program = func(any, binding.Bindings) (any, error)

type Val

type Val[T comparable] struct {
	// contains filtered or unexported fields
}

func NewVal

func NewVal[T comparable](value T, celType ref.Type) Val[T]

func (Val[T]) ConvertToNative

func (w Val[T]) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

func (Val[T]) ConvertToType

func (w Val[T]) ConvertToType(typeVal ref.Type) ref.Val

func (Val[T]) Equal

func (w Val[T]) Equal(other ref.Val) ref.Val

func (Val[T]) Type

func (w Val[T]) Type() ref.Type

func (Val[T]) Unwrap

func (w Val[T]) Unwrap() T

func (Val[T]) Value

func (w Val[T]) Value() interface{}

Jump to

Keyboard shortcuts

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