Documentation ¶
Overview ¶
Package types contains the types, traits, and utilities common to all components of expression handling.
Index ¶
- Constants
- Variables
- func Equal(lhs ref.Val, rhs ref.Val) ref.Val
- func IndexOrError(index ref.Val) (int, error)
- func IsBool(elem ref.Val) bool
- func IsError(val ref.Val) bool
- func IsPrimitiveType(val ref.Val) bool
- func IsUnknown(val ref.Val) bool
- func IsUnknownOrError(val ref.Val) bool
- func MaybeNoSuchOverloadErr(val ref.Val) ref.Val
- func NewDynamicList(adapter ref.TypeAdapter, value any) traits.Lister
- func NewDynamicMap(adapter ref.TypeAdapter, value any) traits.Mapper
- func NewEmptyRegistry() ref.TypeRegistry
- func NewErr(format string, args ...any) ref.Val
- func NewJSONList(adapter ref.TypeAdapter, l *structpb.ListValue) traits.Lister
- func NewJSONStruct(adapter ref.TypeAdapter, value *structpb.Struct) traits.Mapper
- func NewMutableList(adapter ref.TypeAdapter) traits.MutableLister
- func NewObject(adapter ref.TypeAdapter, typeDesc *pb.TypeDescription, typeValue *TypeValue, ...) ref.Val
- func NewProtoList(adapter ref.TypeAdapter, list protoreflect.List) traits.Lister
- func NewProtoMap(adapter ref.TypeAdapter, value *pb.Map) traits.Mapper
- func NewRefValList(adapter ref.TypeAdapter, elems []ref.Val) traits.Lister
- func NewRefValMap(adapter ref.TypeAdapter, value map[ref.Val]ref.Val) traits.Mapper
- func NewRegistry(types ...proto.Message) (ref.TypeRegistry, error)
- func NewStringInterfaceMap(adapter ref.TypeAdapter, value map[string]any) traits.Mapper
- func NewStringList(adapter ref.TypeAdapter, elems []string) traits.Lister
- func NewStringStringMap(adapter ref.TypeAdapter, value map[string]string) traits.Mapper
- func NoSuchOverloadErr() ref.Val
- func UnsupportedRefValConversionErr(val any) ref.Val
- func ValOrErr(val ref.Val, format string, args ...any) ref.Val
- func WrapErr(err error) ref.Val
- type Bool
- func (b Bool) Compare(other ref.Val) ref.Val
- func (b Bool) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (b Bool) ConvertToType(typeVal ref.Type) ref.Val
- func (b Bool) Equal(other ref.Val) ref.Val
- func (b Bool) IsZeroValue() bool
- func (b Bool) Negate() ref.Val
- func (b Bool) Type() ref.Type
- func (b Bool) Value() any
- type Bytes
- func (b Bytes) Add(other ref.Val) ref.Val
- func (b Bytes) Compare(other ref.Val) ref.Val
- func (b Bytes) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (b Bytes) ConvertToType(typeVal ref.Type) ref.Val
- func (b Bytes) Equal(other ref.Val) ref.Val
- func (b Bytes) IsZeroValue() bool
- func (b Bytes) Size() ref.Val
- func (b Bytes) Type() ref.Type
- func (b Bytes) Value() any
- type Double
- func (d Double) Add(other ref.Val) ref.Val
- func (d Double) Compare(other ref.Val) ref.Val
- func (d Double) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (d Double) ConvertToType(typeVal ref.Type) ref.Val
- func (d Double) Divide(other ref.Val) ref.Val
- func (d Double) Equal(other ref.Val) ref.Val
- func (d Double) IsZeroValue() bool
- func (d Double) Multiply(other ref.Val) ref.Val
- func (d Double) Negate() ref.Val
- func (d Double) Subtract(subtrahend ref.Val) ref.Val
- func (d Double) Type() ref.Type
- func (d Double) Value() any
- type Duration
- func (d Duration) Add(other ref.Val) ref.Val
- func (d Duration) Compare(other ref.Val) ref.Val
- func (d Duration) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (d Duration) ConvertToType(typeVal ref.Type) ref.Val
- func (d Duration) Equal(other ref.Val) ref.Val
- func (d Duration) IsZeroValue() bool
- func (d Duration) Negate() ref.Val
- func (d Duration) Receive(function string, overload string, args []ref.Val) ref.Val
- func (d Duration) Subtract(subtrahend ref.Val) ref.Val
- func (d Duration) Type() ref.Type
- func (d Duration) Value() any
- type Err
- type Error
- type Int
- func (i Int) Add(other ref.Val) ref.Val
- func (i Int) Compare(other ref.Val) ref.Val
- func (i Int) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (i Int) ConvertToType(typeVal ref.Type) ref.Val
- func (i Int) Divide(other ref.Val) ref.Val
- func (i Int) Equal(other ref.Val) ref.Val
- func (i Int) IsZeroValue() bool
- func (i Int) Modulo(other ref.Val) ref.Val
- func (i Int) Multiply(other ref.Val) ref.Val
- func (i Int) Negate() ref.Val
- func (i Int) Subtract(subtrahend ref.Val) ref.Val
- func (i Int) Type() ref.Type
- func (i Int) Value() any
- type Null
- type Optional
- func (o *Optional) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (o *Optional) ConvertToType(typeVal ref.Type) ref.Val
- func (o *Optional) Equal(other ref.Val) ref.Val
- func (o *Optional) GetValue() ref.Val
- func (o *Optional) HasValue() bool
- func (o *Optional) String() string
- func (o *Optional) Type() ref.Type
- func (o *Optional) Value() any
- type String
- func (s String) Add(other ref.Val) ref.Val
- func (s String) Compare(other ref.Val) ref.Val
- func (s String) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (s String) ConvertToType(typeVal ref.Type) ref.Val
- func (s String) Equal(other ref.Val) ref.Val
- func (s String) IsZeroValue() bool
- func (s String) Match(pattern ref.Val) ref.Val
- func (s String) Receive(function string, overload string, args []ref.Val) ref.Val
- func (s String) Size() ref.Val
- func (s String) Type() ref.Type
- func (s String) Value() any
- type Timestamp
- func (t Timestamp) Add(other ref.Val) ref.Val
- func (t Timestamp) Compare(other ref.Val) ref.Val
- func (t Timestamp) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (t Timestamp) ConvertToType(typeVal ref.Type) ref.Val
- func (t Timestamp) Equal(other ref.Val) ref.Val
- func (t Timestamp) IsZeroValue() bool
- func (t Timestamp) Receive(function string, overload string, args []ref.Val) ref.Val
- func (t Timestamp) Subtract(subtrahend ref.Val) ref.Val
- func (t Timestamp) Type() ref.Type
- func (t Timestamp) Value() any
- type TypeValue
- func (t *TypeValue) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (t *TypeValue) ConvertToType(typeVal ref.Type) ref.Val
- func (t *TypeValue) Equal(other ref.Val) ref.Val
- func (t *TypeValue) HasTrait(trait int) bool
- func (t *TypeValue) String() string
- func (t *TypeValue) Type() ref.Type
- func (t *TypeValue) TypeName() string
- func (t *TypeValue) Value() any
- type Uint
- func (i Uint) Add(other ref.Val) ref.Val
- func (i Uint) Compare(other ref.Val) ref.Val
- func (i Uint) ConvertToNative(typeDesc reflect.Type) (any, error)
- func (i Uint) ConvertToType(typeVal ref.Type) ref.Val
- func (i Uint) Divide(other ref.Val) ref.Val
- func (i Uint) Equal(other ref.Val) ref.Val
- func (i Uint) IsZeroValue() bool
- func (i Uint) Modulo(other ref.Val) ref.Val
- func (i Uint) Multiply(other ref.Val) ref.Val
- func (i Uint) Subtract(subtrahend ref.Val) ref.Val
- func (i Uint) Type() ref.Type
- func (i Uint) Value() any
- type Unknown
Constants ¶
const ( False = Bool(false) True = Bool(true) )
Boolean constants
const ( // IntZero is the zero-value for Int IntZero = Int(0) IntOne = Int(1) IntNegOne = Int(-1) )
Int constants used for comparison results.
Variables ¶
var ( // NullType singleton. NullType = NewTypeValue("null_type") // NullValue singleton. NullValue = Null(structpb.NullValue_NULL_VALUE) )
var ( // OptionalType indicates the runtime type of an optional value. OptionalType = NewTypeValue("optional") // OptionalNone is a sentinel value which is used to indicate an empty optional value. OptionalNone = &Optional{} )
var ( // BoolType singleton. BoolType = NewTypeValue("bool", traits.ComparerType, traits.NegatorType) )
var ( // BytesType singleton. BytesType = NewTypeValue("bytes", traits.AdderType, traits.ComparerType, traits.SizerType) )
var (
// DefaultTypeAdapter adapts canonical CEL types from their equivalent Go values.
DefaultTypeAdapter = &defaultTypeAdapter{}
)
var ( // DoubleType singleton. DoubleType = NewTypeValue("double", traits.AdderType, traits.ComparerType, traits.DividerType, traits.MultiplierType, traits.NegatorType, traits.SubtractorType) )
var ( // DurationType singleton. DurationType = NewTypeValue("google.protobuf.Duration", traits.AdderType, traits.ComparerType, traits.NegatorType, traits.ReceiverType, traits.SubtractorType) )
var ( // ErrType singleton. ErrType = NewTypeValue("error") )
var ( // IntType singleton. IntType = NewTypeValue("int", traits.AdderType, traits.ComparerType, traits.DividerType, traits.ModderType, traits.MultiplierType, traits.NegatorType, traits.SubtractorType) )
var ( // IteratorType singleton. IteratorType = NewTypeValue("iterator", traits.IteratorType) )
var ( // ListType singleton. ListType = NewTypeValue("list", traits.AdderType, traits.ContainerType, traits.IndexerType, traits.IterableType, traits.SizerType) )
var ( // MapType singleton. MapType = NewTypeValue("map", traits.ContainerType, traits.IndexerType, traits.IterableType, traits.SizerType) )
var ( // StringType singleton. StringType = NewTypeValue("string", traits.AdderType, traits.ComparerType, traits.MatcherType, traits.ReceiverType, traits.SizerType) )
var ( // TimestampType singleton. TimestampType = NewTypeValue("google.protobuf.Timestamp", traits.AdderType, traits.ComparerType, traits.ReceiverType, traits.SubtractorType) )
var ( // TypeType is the type of a TypeValue. TypeType = NewTypeValue("type") )
var ( // UintType singleton. UintType = NewTypeValue("uint", traits.AdderType, traits.ComparerType, traits.DividerType, traits.ModderType, traits.MultiplierType, traits.SubtractorType) )
var ( // UnknownType singleton. UnknownType = NewTypeValue("unknown") )
Functions ¶
func Equal ¶ added in v0.10.0
Equal returns whether the two ref.Value are heterogeneously equivalent.
func IndexOrError ¶ added in v0.13.0
IndexOrError converts an input index value into either a lossless integer index or an error.
func IsError ¶
IsError returns whether the input element ref.Type or ref.Val is equal to the ErrType singleton.
func IsPrimitiveType ¶ added in v0.3.0
IsPrimitiveType returns whether the input element ref.Val is a primitive type. Note, primitive types do not include well-known types such as Duration and Timestamp.
func IsUnknown ¶
IsUnknown returns whether the element ref.Type or ref.Val is equal to the UnknownType singleton.
func IsUnknownOrError ¶
IsUnknownOrError returns whether the input element ref.Val is an ErrType or UnknownType.
func MaybeNoSuchOverloadErr ¶ added in v0.4.0
MaybeNoSuchOverloadErr returns the error or unknown if the input ref.Val is one of these types, else a new no such overload error.
func NewDynamicList ¶
func NewDynamicList(adapter ref.TypeAdapter, value any) traits.Lister
NewDynamicList returns a traits.Lister with heterogenous elements. value should be an array of "native" types, i.e. any type that NativeToValue() can convert to a ref.Val.
func NewDynamicMap ¶
func NewDynamicMap(adapter ref.TypeAdapter, value any) traits.Mapper
NewDynamicMap returns a traits.Mapper value with dynamic key, value pairs.
func NewEmptyRegistry ¶ added in v0.4.0
func NewEmptyRegistry() ref.TypeRegistry
NewEmptyRegistry returns a registry which is completely unconfigured.
func NewErr ¶
NewErr creates a new Err described by the format string and args. TODO: Audit the use of this function and standardize the error messages and codes.
func NewJSONList ¶
NewJSONList returns a traits.Lister based on structpb.ListValue instance.
func NewJSONStruct ¶
NewJSONStruct creates a traits.Mapper implementation backed by a JSON struct that has been encoded in protocol buffer form.
The `adapter` argument provides type adaptation capabilities from proto to CEL.
func NewMutableList ¶ added in v0.10.0
func NewMutableList(adapter ref.TypeAdapter) traits.MutableLister
NewMutableList creates a new mutable list whose internal state can be modified.
func NewObject ¶
func NewObject(adapter ref.TypeAdapter, typeDesc *pb.TypeDescription, typeValue *TypeValue, value proto.Message) ref.Val
NewObject returns an object based on a proto.Message value which handles conversion between protobuf type values and expression type values. Objects support indexing and iteration.
Note: the type value is pulled from the list of registered types within the type provider. If the proto type is not registered within the type provider, then this will result in an error within the type adapter / provider.
func NewProtoList ¶ added in v0.7.0
func NewProtoList(adapter ref.TypeAdapter, list protoreflect.List) traits.Lister
NewProtoList returns a traits.Lister based on a pb.List instance.
func NewProtoMap ¶ added in v0.7.0
NewProtoMap returns a specialized traits.Mapper for handling protobuf map values.
func NewRefValList ¶ added in v0.7.0
NewRefValList returns a traits.Lister with ref.Val elements.
This type specialization is used with list literals within CEL expressions.
func NewRefValMap ¶ added in v0.7.0
NewRefValMap returns a specialized traits.Mapper with CEL valued keys and values.
func NewRegistry ¶ added in v0.2.0
func NewRegistry(types ...proto.Message) (ref.TypeRegistry, error)
NewRegistry accepts a list of proto message instances and returns a type provider which can create new instances of the provided message or any message that proto depends upon in its FileDescriptor.
func NewStringInterfaceMap ¶ added in v0.7.0
NewStringInterfaceMap returns a specialized traits.Mapper with string keys and interface values.
func NewStringList ¶
func NewStringList(adapter ref.TypeAdapter, elems []string) traits.Lister
NewStringList returns a traits.Lister containing only strings.
func NewStringStringMap ¶
NewStringStringMap returns a specialized traits.Mapper with string keys and values.
func NoSuchOverloadErr ¶ added in v0.4.0
NoSuchOverloadErr returns a new types.Err instance with a no such overload message.
func UnsupportedRefValConversionErr ¶ added in v0.7.0
UnsupportedRefValConversionErr returns a types.NewErr instance with a no such conversion message that indicates that the native value could not be converted to a CEL ref.Val.
Types ¶
type Bool ¶
type Bool bool
Bool type that implements ref.Val and supports comparison and negation.
func (Bool) ConvertToNative ¶
ConvertToNative implements the ref.Val interface method.
func (Bool) ConvertToType ¶
ConvertToType implements the ref.Val interface method.
func (Bool) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if the boolean value is false.
type Bytes ¶
type Bytes []byte
Bytes type that implements ref.Val and supports add, compare, and size operations.
func (Bytes) Compare ¶
Compare implements traits.Comparer interface method by lexicographic ordering.
func (Bytes) ConvertToNative ¶
ConvertToNative implements the ref.Val interface method.
func (Bytes) ConvertToType ¶
ConvertToType implements the ref.Val interface method.
func (Bytes) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if the byte array is empty.
type Double ¶
type Double float64
Double type that implements ref.Val, comparison, and mathematical operations.
func (Double) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Double) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Double) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if double value is 0.0
type Duration ¶
Duration type that implements ref.Val and supports add, compare, negate, and subtract operators. This type is also a receiver which means it can participate in dispatch to receiver functions.
func (Duration) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Duration) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Duration) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if the duration value is zero
type Err ¶
type Err struct {
// contains filtered or unexported fields
}
Err type which extends the built-in go error and implements ref.Val.
func (*Err) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (*Err) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
type Error ¶ added in v0.14.0
Error interface which allows types types.Err values to be treated as error values.
type Int ¶
type Int int64
Int type that implements ref.Val as well as comparison and math operators.
func (Int) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Int) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Int) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if integer is equal to 0
type Null ¶
Null type implementation.
func (Null) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Null) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Null) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true as null always represents an absent value.
type Optional ¶ added in v0.13.0
type Optional struct {
// contains filtered or unexported fields
}
Optional value which points to a value if non-empty.
func OptionalOf ¶ added in v0.13.0
OptionalOf returns an optional value which wraps a concrete CEL value.
func (*Optional) ConvertToNative ¶ added in v0.13.0
ConvertToNative implements the ref.Val interface method.
func (*Optional) ConvertToType ¶ added in v0.13.0
ConvertToType implements the ref.Val interface method.
func (*Optional) Equal ¶ added in v0.13.0
Equal determines whether the values contained by two optional values are equal.
func (*Optional) GetValue ¶ added in v0.13.0
GetValue returns the wrapped value contained in the optional.
type String ¶
type String string
String type implementation which supports addition, comparison, matching, and size functions.
func (String) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (String) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (String) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if the string is empty.
type Timestamp ¶
Timestamp type implementation which supports add, compare, and subtract operations. Timestamps are also capable of participating in dynamic function dispatch to instance methods.
func (Timestamp) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Timestamp) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Timestamp) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if the timestamp is epoch 0.
type TypeValue ¶
type TypeValue struct {
// contains filtered or unexported fields
}
TypeValue is an instance of a Value that describes a value's type.
func NewObjectTypeValue ¶
NewObjectTypeValue returns a *TypeValue based on the input name, which is annotated with the traits relevant to all objects.
func NewTypeValue ¶
NewTypeValue returns *TypeValue which is both a ref.Type and ref.Val.
func (*TypeValue) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (*TypeValue) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (*TypeValue) HasTrait ¶
HasTrait indicates whether the type supports the given trait. Trait codes are defined in the traits package, e.g. see traits.AdderType.
type Uint ¶
type Uint uint64
Uint type implementation which supports comparison and math operators.
func (Uint) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Uint) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Uint) IsZeroValue ¶ added in v0.13.0
IsZeroValue returns true if the uint is zero.
type Unknown ¶
type Unknown []int64
Unknown type implementation which collects expression ids which caused the current value to become unknown.
func (Unknown) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Unknown) ConvertToType ¶
ConvertToType is an identity function since unknown values cannot be modified.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup.
|
Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup. |
Package ref contains the reference interfaces used throughout the types components.
|
Package ref contains the reference interfaces used throughout the types components. |
Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch.
|
Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch. |