common

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ObjectTraits = traits.ContainerType

ObjectTraits is the bitmask that represents traits that an object should have.

View Source
const RootTypeReferenceName = "Object"

RootTypeReferenceName is the root reference that all type names should start with.

Variables

This section is empty.

Functions

This section is empty.

Types

type ObjectVal

type ObjectVal struct {
	// contains filtered or unexported fields
}

ObjectVal is the CEL Val for an object that is constructed via the object construction syntax.

func NewObjectVal

func NewObjectVal(typeRef TypeRef, fields map[string]ref.Val) *ObjectVal

NewObjectVal creates an ObjectVal by its TypeRef and its fields.

func (*ObjectVal) ConvertToNative

func (v *ObjectVal) ConvertToNative(typeDesc reflect.Type) (any, error)

ConvertToNative converts the object to map[string]any. All nested lists are converted into []any native type.

It returns an error if the target type is not map[string]any, or any recursive conversion fails.

func (*ObjectVal) ConvertToType

func (v *ObjectVal) ConvertToType(typeValue ref.Type) ref.Val

ConvertToType supports type conversions between CEL value types supported by the expression language.

func (*ObjectVal) Equal

func (v *ObjectVal) Equal(other ref.Val) ref.Val

Equal returns true if the `other` value has the same type and content as the implementing struct.

func (*ObjectVal) IsZeroValue

func (v *ObjectVal) IsZeroValue() bool

IsZeroValue indicates whether the object is the zero value for the type. For the ObjectVal, it is zero value if and only if the fields map is empty.

func (*ObjectVal) Type

func (v *ObjectVal) Type() ref.Type

Type returns the TypeValue of the value.

func (*ObjectVal) Value

func (v *ObjectVal) Value() any

Value returns its value as a map[string]any.

type TypeRef

type TypeRef interface {
	ref.Type

	// CELType wraps the TypeRef to be a type that is understood by CEL.
	CELType() *types.Type

	// Field finds the field by the field name, or false if the field is not known.
	// This function directly return a FieldType that is known to CEL to be more customizable.
	Field(name string) (*types.FieldType, bool)

	// Val creates an instance for the TypeRef, given its fields and their values.
	Val(fields map[string]ref.Val) ref.Val
}

TypeRef refers an object type that can be looked up for its fields.

type TypeResolver

type TypeResolver interface {
	// Resolve resolves the type by its name, starting with "Object" as its root.
	// The type that the name refers to must be an object.
	// This function returns false if the name does not refer to a known object type.
	Resolve(name string) (TypeRef, bool)
}

TypeResolver resolves a type by a given name.

Jump to

Keyboard shortcuts

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