package types
import "github.com/open-policy-agent/opa/v1/types"
Package types declares data types for Rego values and helper functions to operate on these types.
Index ¶
- func Arity(x Type) int
- func Compare(a, b Type) int
- func Contains(a, b Type) bool
- func Nil(a Type) bool
- func Sprint(x Type) string
- func Void(x Type) bool
- type Any
- func NewAny(of ...Type) Any
- func (t Any) Contains(other Type) bool
- func (t Any) MarshalJSON() ([]byte, error)
- func (t Any) Merge(other Type) Any
- func (t Any) String() string
- func (t Any) Union(other Any) Any
- type Array
- func NewArray(static []Type, dynamic Type) *Array
- func (t *Array) Dynamic() Type
- func (t *Array) Len() int
- func (t *Array) MarshalJSON() ([]byte, error)
- func (t *Array) Select(pos int) Type
- func (t *Array) String() string
- type Boolean
- func NewBoolean() Boolean
- func (t Boolean) MarshalJSON() ([]byte, error)
- func (t Boolean) String() string
- type DynamicProperty
- func NewDynamicProperty(key, value Type) *DynamicProperty
- func (p *DynamicProperty) MarshalJSON() ([]byte, error)
- func (p *DynamicProperty) String() string
- type FuncArgs
- type Function
- func NewFunction(args []Type, result Type) *Function
- func NewVariadicFunction(args []Type, varargs Type, result Type) *Function
- func (t *Function) Args() []Type
- func (t *Function) Arity() int
- func (t *Function) FuncArgs() FuncArgs
- func (t *Function) MarshalJSON() ([]byte, error)
- func (t *Function) NamedFuncArgs() FuncArgs
- func (t *Function) NamedResult() Type
- func (t *Function) Result() Type
- func (t *Function) String() string
- func (t *Function) Union(other *Function) *Function
- func (t *Function) UnmarshalJSON(bs []byte) error
- type NamedType
- func Named(name string, t Type) *NamedType
- func (n *NamedType) Description(d string) *NamedType
- func (n *NamedType) MarshalJSON() ([]byte, error)
- func (n *NamedType) String() string
- type Null
- type Number
- type Object
- func NewObject(static []*StaticProperty, dynamic *DynamicProperty) *Object
- func (t *Object) DynamicProperties() *DynamicProperty
- func (t *Object) DynamicValue() Type
- func (t *Object) Keys() []interface{}
- func (t *Object) MarshalJSON() ([]byte, error)
- func (t *Object) Merge(other Type) *Object
- func (t *Object) Select(name interface{}) Type
- func (t *Object) StaticProperties() []*StaticProperty
- func (t *Object) String() string
- type Set
- func NewSet(of Type) *Set
- func (t *Set) MarshalJSON() ([]byte, error)
- func (t *Set) Of() Type
- func (t *Set) String() string
- type StaticProperty
- func NewStaticProperty(key interface{}, value Type) *StaticProperty
- func (p *StaticProperty) MarshalJSON() ([]byte, error)
- type String
- type Type
Functions ¶
func Arity ¶
Arity returns the number of arguments in the function signature or zero if x is not a function. If the type is unknown, this function returns -1.
func Compare ¶
Compare returns -1, 0, 1 based on comparison between a and b.
func Contains ¶
Contains returns true if a is a superset or equal to b.
func Nil ¶
Nil returns true if a's type is unknown.
func Sprint ¶
Sprint returns the string representation of the type.
func Void ¶
Void returns true if the function has no return value. This function returns false if x is not a function.
Types ¶
type Any ¶
type Any []Type
Any represents a dynamic type.
func NewAny ¶
NewAny returns a new Any type.
func (Any) Contains ¶
Contains returns true if t is a superset of other.
func (Any) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (Any) Merge ¶
Merge return a new Any type that is the superset of t and other.
func (Any) String ¶
func (Any) Union ¶
Union returns a new Any type that is the union of the two Any types. Note(philipc): The two Any slices MUST be sorted before running Union, or else this method will fail to merge the two slices correctly.
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array represents the array type.
func NewArray ¶
NewArray returns a new Array type.
func (*Array) Dynamic ¶
Dynamic returns the type of the array's dynamic elements.
func (*Array) Len ¶
Len returns the number of static array elements.
func (*Array) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (*Array) Select ¶
Select returns the type of element at the zero-based pos.
func (*Array) String ¶
type Boolean ¶
type Boolean struct{}
Boolean represents the boolean type.
func NewBoolean ¶
func NewBoolean() Boolean
NewBoolean returns a new Boolean type.
func (Boolean) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (Boolean) String ¶
type DynamicProperty ¶
DynamicProperty represents a dynamic object property.
func NewDynamicProperty ¶
func NewDynamicProperty(key, value Type) *DynamicProperty
NewDynamicProperty returns a new DynamicProperty object.
func (*DynamicProperty) MarshalJSON ¶
func (p *DynamicProperty) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of p.
func (*DynamicProperty) String ¶
func (p *DynamicProperty) String() string
type FuncArgs ¶
type FuncArgs struct { Args []Type `json:"args,omitempty"` Variadic Type `json:"variadic,omitempty"` }
FuncArgs represents the arguments that can be passed to a function.
func (FuncArgs) Arg ¶
Arg returns the nth argument's type.
func (FuncArgs) String ¶
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
Function represents a function type.
func NewFunction ¶
NewFunction returns a new Function object of the given argument and result types.
func NewVariadicFunction ¶
NewVariadicFunction returns a new Function object. This function sets the variadic bit on the signature. Non-void variadic functions are not currently supported.
func (*Function) Args ¶
Args returns the function's arguments as a slice, ignoring variadic arguments. Deprecated: Use FuncArgs instead.
func (*Function) Arity ¶
Arity returns the number of arguments in the function signature.
func (*Function) FuncArgs ¶
FuncArgs returns the function's arguments.
func (*Function) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (*Function) NamedFuncArgs ¶
NamedFuncArgs returns the function's arguments, with a name and description if available.
func (*Function) NamedResult ¶
Result returns the function's result type, without stripping name and description.
func (*Function) Result ¶
Result returns the function's result type.
func (*Function) String ¶
func (*Function) Union ¶
Union returns a new function representing the union of t and other. Functions must have the same arity to be unioned.
func (*Function) UnmarshalJSON ¶
UnmarshalJSON decodes the JSON serialized function declaration.
type NamedType ¶
NamedType represents a type alias with an arbitrary name and description. This is useful for generating documentation for built-in functions.
func Named ¶
Named returns the passed type as a named type. Named types are only valid at the top level of built-in functions. Note that nested named types cause panic.
func (*NamedType) Description ¶
func (*NamedType) MarshalJSON ¶
func (*NamedType) String ¶
type Null ¶
type Null struct{}
Null represents the null type.
func NewNull ¶
func NewNull() Null
NewNull returns a new Null type.
func (Null) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (Null) String ¶
type Number ¶
type Number struct{}
Number represents the number type.
func NewNumber ¶
func NewNumber() Number
NewNumber returns a new Number type.
func (Number) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (Number) String ¶
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents the object type.
func NewObject ¶
func NewObject(static []*StaticProperty, dynamic *DynamicProperty) *Object
NewObject returns a new Object type.
func (*Object) DynamicProperties ¶
func (t *Object) DynamicProperties() *DynamicProperty
DynamicProperties returns the type of the object's dynamic elements.
func (*Object) DynamicValue ¶
DynamicValue returns the type of the object's dynamic elements.
func (*Object) Keys ¶
func (t *Object) Keys() []interface{}
Keys returns the keys of the object's static elements.
func (*Object) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (*Object) Merge ¶
func (*Object) Select ¶
Select returns the type of the named property.
func (*Object) StaticProperties ¶
func (t *Object) StaticProperties() []*StaticProperty
StaticProperties returns the type of the object's static elements.
func (*Object) String ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents the set type.
func NewSet ¶
NewSet returns a new Set type.
func (*Set) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (*Set) Of ¶
func (*Set) String ¶
type StaticProperty ¶
type StaticProperty struct { Key interface{} Value Type }
StaticProperty represents a static object property.
func NewStaticProperty ¶
func NewStaticProperty(key interface{}, value Type) *StaticProperty
NewStaticProperty returns a new StaticProperty object.
func (*StaticProperty) MarshalJSON ¶
func (p *StaticProperty) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of p.
type String ¶
type String struct{}
String represents the string type.
func NewString ¶
func NewString() String
NewString returns a new String type.
func (String) MarshalJSON ¶
MarshalJSON returns the JSON encoding of t.
func (String) String ¶
type Type ¶
Type represents a type of a term in the language.
Boxed set types.
var A Type = NewAny()
A represents the superset of all types.
var B Type = NewBoolean()
B represents an instance of the boolean type.
var N Type = NewNumber()
N represents an instance of the number type.
var Nl Type = NewNull()
var S Type = NewString()
S represents an instance of the string type.
func Args ¶
Args returns an argument list.
func Keys ¶
Keys returns the type of keys that can be enumerated for a. For arrays, the keys are always number types, for objects the keys are always string types, and for sets the keys are always the type of the set element.
func Or ¶
Or returns a type that represents the union of a and b. If one type is a superset of the other, the superset is returned unchanged.
func Select ¶
Select returns a property or item of a.
func TypeOf ¶
func TypeOf(x interface{}) Type
TypeOf returns the type of the Golang native value.
func Unmarshal ¶
Unmarshal deserializes bs and returns the resulting type.
func Values ¶
Values returns the type of values that can be enumerated for a.
Source Files ¶
- Version
- v1.4.2 (latest)
- Published
- May 2, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 3 weeks ago –
Tools for package owners.