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 IsDyn(elem interface{}) bool
- func IsError(val ref.Val) bool
- func IsUnknown(val ref.Val) bool
- func IsUnknownOrError(val ref.Val) bool
- func NativeToValue(value interface{}) ref.Val
- func NewDynamicList(value interface{}) traits.Lister
- func NewDynamicMap(value interface{}) traits.Mapper
- func NewErr(format string, args ...interface{}) ref.Val
- func NewJSONList(l *structpb.ListValue) traits.Lister
- func NewJSONStruct(st *structpb.Struct) traits.Mapper
- func NewObject(value proto.Message) ref.Val
- func NewProvider(types ...proto.Message) ref.TypeProvider
- func NewStringList(elems []string) traits.Lister
- func NewStringStringMap(value map[string]string) traits.Mapper
- func NewValueList(elems []ref.Val) traits.Lister
- 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 ( // 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 ( // DynType singleton. DynType = NewTypeValue("dyn") )
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 IsDyn ¶
func IsDyn(elem interface{}) bool
IsDyn indicates whether the input ref.Val or ref.Type is equal to DynType.
func IsError ¶
IsError returns whether the input element ref.Type or ref.Val is equal to the ErrType singleton.
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.Type or ref.Val is an ErrType or UnknonwType.
func NativeToValue ¶
NativeToValue converts various "native" types to ref.Val. It should be the inverse of ref.Val.ConvertToNative.
func NewDynamicList ¶
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 ¶
NewDynamicMap returns a traits.Mapper value with dynamic key, value pairs.
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.
func NewJSONStruct ¶
NewJSONStruct creates a traits.Mapper implementation backed by a JSON struct that has been encoded in protocol buffer form.
func NewObject ¶
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.
func NewProvider ¶
func NewProvider(types ...proto.Message) ref.TypeProvider
NewProvider 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 ¶
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 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 traits.Comparer.Compare.
func (Bool) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Bool) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Bool) Equal ¶
Equal implements ref.Val.Equal.
func (Bool) Negate ¶
Negate implements traits.Negater.Negate.
func (Bool) Type ¶
Type implements ref.Val.Type.
func (Bool) Value ¶
func (b Bool) Value() interface{}
Value implements ref.Val.Value.
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.Add by concatenating byte sequences.
func (Bytes) Compare ¶
Compare implments traits.Comparer.Compare by lexicographic ordering.
func (Bytes) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Bytes) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
func (Bytes) Equal ¶
Equal implements ref.Val.Equal.
func (Bytes) Size ¶
Size implements traits.Sizer.Size.
func (Bytes) Type ¶
Type implements ref.Val.Type.
func (Bytes) Value ¶
func (b Bytes) Value() interface{}
Value implements ref.Val.Value.
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 dyn.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.1.0
- Published
- Feb 5, 2019
- Platform
- js/wasm
- Imports
- 18 packages
- Last checked
- now –
Tools for package owners.