package types
import "github.com/google/cel-go/common/types"
Package types contains the types, traits, and utilities common to all components of expression handling.
Index ¶
- Constants
- Variables
- func IsBool(elem interface{}) 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 interface{}) traits.Lister
- func NewDynamicMap(adapter ref.TypeAdapter, value interface{}) traits.Mapper
- func NewEmptyRegistry() ref.TypeRegistry
- func NewErr(format string, args ...interface{}) ref.Val
- func NewJSONList(adapter ref.TypeAdapter, l *structpb.ListValue) traits.Lister
- func NewJSONStruct(adapter ref.TypeAdapter, st *structpb.Struct) traits.Mapper
- func NewObject(adapter ref.TypeAdapter, typeDesc *pb.TypeDescription, typeValue *TypeValue, value proto.Message) ref.Val
- func NewRegistry(types ...proto.Message) ref.TypeRegistry
- func NewStringList(adapter ref.TypeAdapter, elems []string) traits.Lister
- func NewStringStringMap(adapter ref.TypeAdapter, value map[string]string) traits.Mapper
- func NewValueList(adapter ref.TypeAdapter, elems []ref.Val) traits.Lister
- func NoSuchOverloadErr() ref.Val
- func ValOrErr(val ref.Val, format string, args ...interface{}) ref.Val
- type Bool
- func (b Bool) Compare(other ref.Val) ref.Val
- func (b Bool) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (b Bool) ConvertToType(typeVal ref.Type) ref.Val
- func (b Bool) Equal(other ref.Val) ref.Val
- func (b Bool) Negate() ref.Val
- func (b Bool) Type() ref.Type
- func (b Bool) Value() interface{}
- 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) (interface{}, error)
- func (b Bytes) ConvertToType(typeVal ref.Type) ref.Val
- func (b Bytes) Equal(other ref.Val) ref.Val
- func (b Bytes) Size() ref.Val
- func (b Bytes) Type() ref.Type
- func (b Bytes) Value() interface{}
- 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) (interface{}, 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) 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() interface{}
- 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) (interface{}, error)
- func (d Duration) ConvertToType(typeVal ref.Type) ref.Val
- func (d Duration) Equal(other ref.Val) ref.Val
- 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() interface{}
- type Err
- func (e *Err) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (e *Err) ConvertToType(typeVal ref.Type) ref.Val
- func (e *Err) Equal(other ref.Val) ref.Val
- func (e *Err) String() string
- func (e *Err) Type() ref.Type
- func (e *Err) Value() interface{}
- 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) (interface{}, 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) 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() interface{}
- type Null
- func (n Null) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (n Null) ConvertToType(typeVal ref.Type) ref.Val
- func (n Null) Equal(other ref.Val) ref.Val
- func (n Null) Type() ref.Type
- func (n Null) Value() interface{}
- 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) (interface{}, error)
- func (s String) ConvertToType(typeVal ref.Type) ref.Val
- func (s String) Equal(other ref.Val) ref.Val
- 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() interface{}
- 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) (interface{}, error)
- func (t Timestamp) ConvertToType(typeVal ref.Type) ref.Val
- func (t Timestamp) Equal(other ref.Val) ref.Val
- 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() interface{}
- type TypeValue
- func NewObjectTypeValue(name string) *TypeValue
- func NewTypeValue(name string, traits ...int) *TypeValue
- func (t *TypeValue) ConvertToNative(typeDesc reflect.Type) (interface{}, 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() interface{}
- 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) (interface{}, 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) 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() interface{}
- type Unknown
Constants ¶
Int constants used for comparison results.
Variables ¶
Boolean constants
var ( // NullType singleton. NullType = NewTypeValue("null_type") // NullValue singleton. NullValue = Null(structpb.NullValue_NULL_VALUE) )
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 IsBool ¶
func IsBool(elem interface{}) bool
IsBool returns whether the input ref.Val or ref.Type is equal to BoolType.
func IsError ¶
IsError returns whether the input element ref.Type or ref.Val is equal to the ErrType singleton.
func IsPrimitiveType ¶
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 UnknonwType.
func MaybeNoSuchOverloadErr ¶
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 interface{}) 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 interface{}) traits.Mapper
NewDynamicMap returns a traits.Mapper value with dynamic key, value pairs.
func NewEmptyRegistry ¶
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 creates a traits.Lister implementation backed by a JSON list that has been encoded in protocol buffer form.
The `adapter` argument provides type adaptation capabilities from proto to CEL.
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 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 NewRegistry ¶
func NewRegistry(types ...proto.Message) ref.TypeRegistry
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 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 NewValueList ¶
NewValueList returns a traits.Lister with ref.Val elements.
func NoSuchOverloadErr ¶
NoSuchOverloadErr returns a new types.Err instance with a no such overload message.
func ValOrErr ¶
ValOrErr either returns the existing error or create a new one. TODO: Audit the use of this function and standardize the error messages and codes.
Types ¶
type Bool ¶
type Bool bool
Bool type that implements ref.Val and supports comparison and negation.
func (Bool) Compare ¶
Compare implements the traits.Comparer interface method.
func (Bool) ConvertToNative ¶
ConvertToNative implements the ref.Val interface method.
func (Bool) ConvertToType ¶
ConvertToType implements the ref.Val interface method.
func (Bool) Equal ¶
Equal implements the ref.Val interface method.
func (Bool) Negate ¶
Negate implements the traits.Negater interface method.
func (Bool) Type ¶
Type implements the ref.Val interface method.
func (Bool) Value ¶
func (b Bool) Value() interface{}
Value implements the ref.Val interface method.
type Bytes ¶
type Bytes []byte
Bytes type that implements ref.Val and supports add, compare, and size operations.
func (Bytes) Add ¶
Add implements traits.Adder interface method by concatenating byte sequences.
func (Bytes) Compare ¶
Compare implments 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) Equal ¶
Equal implements the ref.Val interface method.
func (Bytes) Size ¶
Size implements the traits.Sizer interface method.
func (Bytes) Type ¶
Type implements the ref.Val interface method.
func (Bytes) Value ¶
func (b Bytes) Value() interface{}
Value implements the ref.Val interface method.
type Double ¶
type Double float64
Double type that implements ref.Val, comparison, and mathematical operations.
func (Double) Add ¶
Add implements traits.Adder.Add.
func (Double) Compare ¶
Compare implements traits.Comparer.Compare.
func (Double) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Double) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Double) Divide ¶
Divide implements traits.Divider.Divide.
func (Double) Equal ¶
Equal implements ref.Val.Equal.
func (Double) Multiply ¶
Multiply implements traits.Multiplier.Multiply.
func (Double) Negate ¶
Negate implements traits.Negater.Negate.
func (Double) Subtract ¶
Subtract implements traits.Subtractor.Subtract.
func (Double) Type ¶
Type implements ref.Val.Type.
func (Double) Value ¶
func (d Double) Value() interface{}
Value implements ref.Val.Value.
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) Add ¶
Add implements traits.Adder.Add.
func (Duration) Compare ¶
Compare implements traits.Comparer.Compare.
func (Duration) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Duration) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Duration) Equal ¶
Equal implements ref.Val.Equal.
func (Duration) Negate ¶
Negate implements traits.Negater.Negate.
func (Duration) Receive ¶
Receive implements traits.Receiver.Receive.
func (Duration) Subtract ¶
Subtract implements traits.Subtractor.Subtract.
func (Duration) Type ¶
Type implements ref.Val.Type.
func (Duration) Value ¶
func (d Duration) Value() interface{}
Value implements ref.Val.Value.
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.
func (*Err) Equal ¶
Equal implements ref.Val.Equal.
func (*Err) String ¶
String implements fmt.Stringer.
func (*Err) Type ¶
Type implements ref.Val.Type.
func (*Err) Value ¶
func (e *Err) Value() interface{}
Value implements ref.Val.Value.
type Int ¶
type Int int64
Int type that implements ref.Val as well as comparison and math operators.
func (Int) Add ¶
Add implements traits.Adder.Add.
func (Int) Compare ¶
Compare implements traits.Comparer.Compare.
func (Int) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Int) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Int) Divide ¶
Divide implements traits.Divider.Divide.
func (Int) Equal ¶
Equal implements ref.Val.Equal.
func (Int) Modulo ¶
Modulo implements traits.Modder.Modulo.
func (Int) Multiply ¶
Multiply implements traits.Multiplier.Multiply.
func (Int) Negate ¶
Negate implements traits.Negater.Negate.
func (Int) Subtract ¶
Subtract implements traits.Subtractor.Subtract.
func (Int) Type ¶
Type implements ref.Val.Type.
func (Int) Value ¶
func (i Int) Value() interface{}
Value implements ref.Val.Value.
type Null ¶
Null type implementation.
func (Null) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Null) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Null) Equal ¶
Equal implements ref.Val.Equal.
func (Null) Type ¶
Type implements ref.Val.Type.
func (Null) Value ¶
func (n Null) Value() interface{}
Value implements ref.Val.Value.
type String ¶
type String string
String type implementation which supports addition, comparison, matching, and size functions.
func (String) Add ¶
Add implements traits.Adder.Add.
func (String) Compare ¶
Compare implements traits.Comparer.Compare.
func (String) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (String) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (String) Equal ¶
Equal implements ref.Val.Equal.
func (String) Match ¶
Match implements traits.Matcher.Match.
func (String) Receive ¶
Receive implements traits.Reciever.Receive.
func (String) Size ¶
Size implements traits.Sizer.Size.
func (String) Type ¶
Type implements ref.Val.Type.
func (String) Value ¶
func (s String) Value() interface{}
Value implements ref.Val.Value.
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) Add ¶
Add implements traits.Adder.Add.
func (Timestamp) Compare ¶
Compare implements traits.Comparer.Compare.
func (Timestamp) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Timestamp) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Timestamp) Equal ¶
Equal implements ref.Val.Equal.
func (Timestamp) Receive ¶
Receive implements traits.Reciever.Receive.
func (Timestamp) Subtract ¶
Subtract implements traits.Subtractor.Subtract.
func (Timestamp) Type ¶
Type implements ref.Val.Type.
func (Timestamp) Value ¶
func (t Timestamp) Value() interface{}
Value implements ref.Val.Value.
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) Equal ¶
Equal implements ref.Val.Equal.
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.
func (*TypeValue) String ¶
String implements fmt.Stringer.
func (*TypeValue) Type ¶
Type implements ref.Val.Type.
func (*TypeValue) TypeName ¶
TypeName gives the type's name as a string.
func (*TypeValue) Value ¶
func (t *TypeValue) Value() interface{}
Value implements ref.Val.Value.
type Uint ¶
type Uint uint64
Uint type implementation which supports comparison and math operators.
func (Uint) Add ¶
Add implements traits.Adder.Add.
func (Uint) Compare ¶
Compare implements traits.Comparer.Compare.
func (Uint) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Uint) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Uint) Divide ¶
Divide implements traits.Divider.Divide.
func (Uint) Equal ¶
Equal implements ref.Val.Equal.
func (Uint) Modulo ¶
Modulo implements traits.Modder.Modulo.
func (Uint) Multiply ¶
Multiply implements traits.Multiplier.Multiply.
func (Uint) Subtract ¶
Subtract implements traits.Subtractor.Subtract.
func (Uint) Type ¶
Type implements ref.Val.Type.
func (Uint) Value ¶
func (i Uint) Value() interface{}
Value implements ref.Val.Value.
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 implements ref.Val.ConvertToType.
func (Unknown) Equal ¶
Equal implements ref.Val.Equal.
func (Unknown) Type ¶
Type implements ref.Val.Type.
func (Unknown) Value ¶
func (u Unknown) Value() interface{}
Value implements ref.Val.Value.
Source Files ¶
any_value.go bool.go bytes.go doc.go double.go duration.go err.go int.go iterator.go json_list.go json_struct.go json_value.go list.go map.go null.go object.go provider.go string.go timestamp.go type.go uint.go unknown.go util.go
Directories ¶
Path | Synopsis |
---|---|
common/types/pb | Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup. |
common/types/ref | Package ref contains the reference interfaces used throughout the types components. |
common/types/traits | Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch. |
- Version
- v0.5.0
- Published
- May 6, 2020
- Platform
- js/wasm
- Imports
- 25 packages
- Last checked
- now –
Tools for package owners.