types

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: Apache-2.0 Imports: 22 Imported by: 422

Documentation

Overview

Package types contains the types, traits, and utilities common to all components of expression handling.

Index

Constants

View Source
const (
	// IntZero is the zero-value for Int
	IntZero   = Int(0)
	IntOne    = Int(1)
	IntNegOne = Int(-1)
)

Int constants used for comparison results.

Variables

View Source
var (
	False = Bool(false)
	True  = Bool(true)
)

Boolean constants

View Source
var (
	// NullType singleton.
	NullType = NewTypeValue("null_type")
	// NullValue singleton.
	NullValue = Null(structpb.NullValue_NULL_VALUE)
)
View Source
var (
	// BoolType singleton.
	BoolType = NewTypeValue("bool",
		traits.ComparerType,
		traits.NegatorType)
)
View Source
var (
	// BytesType singleton.
	BytesType = NewTypeValue("bytes",
		traits.AdderType,
		traits.ComparerType,
		traits.SizerType)
)
View Source
var (
	// DefaultTypeAdapter adapts canonical CEL types from their equivalent Go values.
	DefaultTypeAdapter = &defaultTypeAdapter{}
)
View Source
var (
	// DurationType singleton.
	DurationType = NewTypeValue("google.protobuf.Duration",
		traits.AdderType,
		traits.ComparerType,
		traits.NegatorType,
		traits.ReceiverType,
		traits.SubtractorType)
)
View Source
var (
	// DynType singleton.
	DynType = NewTypeValue("dyn")
)
View Source
var (
	// ErrType singleton.
	ErrType = NewTypeValue("error")
)
View Source
var (
	// IteratorType singleton.
	IteratorType = NewTypeValue("iterator", traits.IteratorType)
)
View Source
var (
	// MapType singleton.
	MapType = NewTypeValue("map",
		traits.ContainerType,
		traits.IndexerType,
		traits.IterableType,
		traits.SizerType)
)
View Source
var (
	// StringType singleton.
	StringType = NewTypeValue("string",
		traits.AdderType,
		traits.ComparerType,
		traits.MatcherType,
		traits.ReceiverType,
		traits.SizerType)
)
View Source
var (
	// TimestampType singleton.
	TimestampType = NewTypeValue("google.protobuf.Timestamp",
		traits.AdderType,
		traits.ComparerType,
		traits.ReceiverType,
		traits.SubtractorType)
)
View Source
var (
	// TypeType is the type of a TypeValue.
	TypeType = NewTypeValue("type")
)
View Source
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

func IsError(val ref.Val) bool

IsError returns whether the input element ref.Type or ref.Val is equal to the ErrType singleton.

func IsPrimitiveType added in v0.3.0

func IsPrimitiveType(val ref.Val) bool

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

func IsUnknown(val ref.Val) bool

IsUnknown returns whether the element ref.Type or ref.Val is equal to the UnknownType singleton.

func IsUnknownOrError

func IsUnknownOrError(val ref.Val) bool

IsUnknownOrError returns whether the input element ref.Val is an ErrType or UnknonwType.

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 NewErr

func NewErr(format string, args ...interface{}) ref.Val

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

func NewJSONList(adapter ref.TypeAdapter, l *structpb.ListValue) traits.Lister

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

func NewJSONStruct(adapter ref.TypeAdapter, st *structpb.Struct) traits.Mapper

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,
	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: only uses default Db.

func NewRegistry added in v0.2.0

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

func NewStringStringMap(adapter ref.TypeAdapter, value map[string]string) traits.Mapper

NewStringStringMap returns a specialized traits.Mapper with string keys and values.

func NewValueList

func NewValueList(adapter ref.TypeAdapter, elems []ref.Val) traits.Lister

NewValueList returns a traits.Lister with ref.Val elements.

func ValOrErr

func ValOrErr(val ref.Val, format string, args ...interface{}) ref.Val

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

func (b Bool) Compare(other ref.Val) ref.Val

Compare implements the traits.Comparer interface method.

func (Bool) ConvertToNative

func (b Bool) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements the ref.Val interface method.

func (Bool) ConvertToType

func (b Bool) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements the ref.Val interface method.

func (Bool) Equal

func (b Bool) Equal(other ref.Val) ref.Val

Equal implements the ref.Val interface method.

func (Bool) Negate

func (b Bool) Negate() ref.Val

Negate implements the traits.Negater interface method.

func (Bool) Type

func (b Bool) Type() ref.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

func (b Bytes) Add(other ref.Val) ref.Val

Add implements traits.Adder interface method by concatenating byte sequences.

func (Bytes) Compare

func (b Bytes) Compare(other ref.Val) ref.Val

Compare implments traits.Comparer interface method by lexicographic ordering.

func (Bytes) ConvertToNative

func (b Bytes) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements the ref.Val interface method.

func (Bytes) ConvertToType

func (b Bytes) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements the ref.Val interface method.

func (Bytes) Equal

func (b Bytes) Equal(other ref.Val) ref.Val

Equal implements the ref.Val interface method.

func (Bytes) Size

func (b Bytes) Size() ref.Val

Size implements the traits.Sizer interface method.

func (Bytes) Type

func (b Bytes) Type() ref.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

func (d Double) Add(other ref.Val) ref.Val

Add implements traits.Adder.Add.

func (Double) Compare

func (d Double) Compare(other ref.Val) ref.Val

Compare implements traits.Comparer.Compare.

func (Double) ConvertToNative

func (d Double) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Double) ConvertToType

func (d Double) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Double) Divide

func (d Double) Divide(other ref.Val) ref.Val

Divide implements traits.Divider.Divide.

func (Double) Equal

func (d Double) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (Double) Multiply

func (d Double) Multiply(other ref.Val) ref.Val

Multiply implements traits.Multiplier.Multiply.

func (Double) Negate

func (d Double) Negate() ref.Val

Negate implements traits.Negater.Negate.

func (Double) Subtract

func (d Double) Subtract(subtrahend ref.Val) ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Double) Type

func (d Double) Type() ref.Type

Type implements ref.Val.Type.

func (Double) Value

func (d Double) Value() interface{}

Value implements ref.Val.Value.

type Duration

type Duration struct {
	*dpb.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

func (d Duration) Add(other ref.Val) ref.Val

Add implements traits.Adder.Add.

func (Duration) Compare

func (d Duration) Compare(other ref.Val) ref.Val

Compare implements traits.Comparer.Compare.

func (Duration) ConvertToNative

func (d Duration) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Duration) ConvertToType

func (d Duration) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Duration) Equal

func (d Duration) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (Duration) Negate

func (d Duration) Negate() ref.Val

Negate implements traits.Negater.Negate.

func (Duration) Receive

func (d Duration) Receive(function string, overload string, args []ref.Val) ref.Val

Receive implements traits.Receiver.Receive.

func (Duration) Subtract

func (d Duration) Subtract(subtrahend ref.Val) ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Duration) Type

func (d Duration) Type() ref.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

func (e *Err) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (*Err) ConvertToType

func (e *Err) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (*Err) Equal

func (e *Err) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (*Err) String

func (e *Err) String() string

String implements fmt.Stringer.

func (*Err) Type

func (e *Err) Type() ref.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

func (i Int) Add(other ref.Val) ref.Val

Add implements traits.Adder.Add.

func (Int) Compare

func (i Int) Compare(other ref.Val) ref.Val

Compare implements traits.Comparer.Compare.

func (Int) ConvertToNative

func (i Int) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Int) ConvertToType

func (i Int) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Int) Divide

func (i Int) Divide(other ref.Val) ref.Val

Divide implements traits.Divider.Divide.

func (Int) Equal

func (i Int) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (Int) Modulo

func (i Int) Modulo(other ref.Val) ref.Val

Modulo implements traits.Modder.Modulo.

func (Int) Multiply

func (i Int) Multiply(other ref.Val) ref.Val

Multiply implements traits.Multiplier.Multiply.

func (Int) Negate

func (i Int) Negate() ref.Val

Negate implements traits.Negater.Negate.

func (Int) Subtract

func (i Int) Subtract(subtrahend ref.Val) ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Int) Type

func (i Int) Type() ref.Type

Type implements ref.Val.Type.

func (Int) Value

func (i Int) Value() interface{}

Value implements ref.Val.Value.

type Null

type Null structpb.NullValue

Null type implementation.

func (Null) ConvertToNative

func (n Null) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Null) ConvertToType

func (n Null) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Null) Equal

func (n Null) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (Null) Type

func (n Null) Type() ref.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

func (s String) Add(other ref.Val) ref.Val

Add implements traits.Adder.Add.

func (String) Compare

func (s String) Compare(other ref.Val) ref.Val

Compare implements traits.Comparer.Compare.

func (String) ConvertToNative

func (s String) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (String) ConvertToType

func (s String) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (String) Equal

func (s String) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (String) Match

func (s String) Match(pattern ref.Val) ref.Val

Match implements traits.Matcher.Match.

func (String) Receive

func (s String) Receive(function string, overload string, args []ref.Val) ref.Val

Receive implements traits.Reciever.Receive.

func (String) Size

func (s String) Size() ref.Val

Size implements traits.Sizer.Size.

func (String) Type

func (s String) Type() ref.Type

Type implements ref.Val.Type.

func (String) Value

func (s String) Value() interface{}

Value implements ref.Val.Value.

type Timestamp

type Timestamp struct {
	*tpb.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

func (t Timestamp) Add(other ref.Val) ref.Val

Add implements traits.Adder.Add.

func (Timestamp) Compare

func (t Timestamp) Compare(other ref.Val) ref.Val

Compare implements traits.Comparer.Compare.

func (Timestamp) ConvertToNative

func (t Timestamp) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Timestamp) ConvertToType

func (t Timestamp) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Timestamp) Equal

func (t Timestamp) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (Timestamp) Receive

func (t Timestamp) Receive(function string, overload string, args []ref.Val) ref.Val

Receive implements traits.Reciever.Receive.

func (Timestamp) Subtract

func (t Timestamp) Subtract(subtrahend ref.Val) ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Timestamp) Type

func (t Timestamp) Type() ref.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

func NewObjectTypeValue(name string) *TypeValue

NewObjectTypeValue returns a *TypeValue based on the input name, which is annotated with the traits relevant to all objects.

func NewTypeValue

func NewTypeValue(name string, traits ...int) *TypeValue

NewTypeValue returns *TypeValue which is both a ref.Type and ref.Val.

func (*TypeValue) ConvertToNative

func (t *TypeValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (*TypeValue) ConvertToType

func (t *TypeValue) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (*TypeValue) Equal

func (t *TypeValue) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (*TypeValue) HasTrait

func (t *TypeValue) HasTrait(trait int) bool

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

func (t *TypeValue) String() string

String implements fmt.Stringer.

func (*TypeValue) Type

func (t *TypeValue) Type() ref.Type

Type implements ref.Val.Type.

func (*TypeValue) TypeName

func (t *TypeValue) TypeName() string

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

func (i Uint) Add(other ref.Val) ref.Val

Add implements traits.Adder.Add.

func (Uint) Compare

func (i Uint) Compare(other ref.Val) ref.Val

Compare implements traits.Comparer.Compare.

func (Uint) ConvertToNative

func (i Uint) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Uint) ConvertToType

func (i Uint) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Uint) Divide

func (i Uint) Divide(other ref.Val) ref.Val

Divide implements traits.Divider.Divide.

func (Uint) Equal

func (i Uint) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (Uint) Modulo

func (i Uint) Modulo(other ref.Val) ref.Val

Modulo implements traits.Modder.Modulo.

func (Uint) Multiply

func (i Uint) Multiply(other ref.Val) ref.Val

Multiply implements traits.Multiplier.Multiply.

func (Uint) Subtract

func (i Uint) Subtract(subtrahend ref.Val) ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Uint) Type

func (i Uint) Type() ref.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

func (u Unknown) ConvertToNative(typeDesc reflect.Type) (interface{}, error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Unknown) ConvertToType

func (u Unknown) ConvertToType(typeVal ref.Type) ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Unknown) Equal

func (u Unknown) Equal(other ref.Val) ref.Val

Equal implements ref.Val.Equal.

func (Unknown) Type

func (u Unknown) Type() ref.Type

Type implements ref.Val.Type.

func (Unknown) Value

func (u Unknown) Value() interface{}

Value implements ref.Val.Value.

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.

Jump to

Keyboard shortcuts

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