types

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 1 Imported by: 105

Documentation

Overview

Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.

Package types declares data types for Rego values and helper functions to operate on these types.

Index

Constants

This section is empty.

Variables

View Source
var A = NewAny()

A represents the superset of all types.

B represents an instance of the boolean type.

N represents an instance of the number type.

S represents an instance of the string type.

Functions

func Arity added in v0.34.0

func Arity(x Type) int

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

func Compare(a, b Type) int

Compare returns -1, 0, 1 based on comparison between a and b.

func Contains added in v0.5.7

func Contains(a, b Type) bool

Contains returns true if a is a superset or equal to b.

func Nil

func Nil(a Type) bool

Nil returns true if a's type is unknown.

func Sprint

func Sprint(x Type) string

Sprint returns the string representation of the type.

func Void added in v0.34.0

func Void(x Type) bool

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 = v1.Any

Any represents a dynamic type.

func NewAny

func NewAny(of ...Type) Any

NewAny returns a new Any type.

type Array

type Array = v1.Array

Array represents the array type.

func NewArray

func NewArray(static []Type, dynamic Type) *Array

NewArray returns a new Array type.

type Boolean

type Boolean = v1.Boolean

Boolean represents the boolean type.

func NewBoolean

func NewBoolean() Boolean

NewBoolean returns a new Boolean type.

type DynamicProperty added in v0.5.7

type DynamicProperty = v1.DynamicProperty

DynamicProperty represents a dynamic object property.

func NewDynamicProperty added in v0.5.7

func NewDynamicProperty(key, value Type) *DynamicProperty

NewDynamicProperty returns a new DynamicProperty object.

type FuncArgs added in v0.33.0

type FuncArgs = v1.FuncArgs

FuncArgs represents the arguments that can be passed to a function.

type Function added in v0.5.9

type Function = v1.Function

Function represents a function type.

func NewFunction added in v0.5.9

func NewFunction(args []Type, result Type) *Function

NewFunction returns a new Function object of the given argument and result types.

func NewVariadicFunction added in v0.33.0

func NewVariadicFunction(args []Type, varargs Type, result Type) *Function

NewVariadicFunction returns a new Function object. This function sets the variadic bit on the signature. Non-void variadic functions are not currently supported.

type NamedType added in v0.41.0

type NamedType = v1.NamedType

NamedType represents a type alias with an arbitrary name and description. This is useful for generating documentation for built-in functions.

func Named added in v0.41.0

func Named(name string, t Type) *NamedType

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.

type Null

type Null = v1.Null

Null represents the null type.

func NewNull

func NewNull() Null

NewNull returns a new Null type.

type Number

type Number = v1.Number

Number represents the number type.

func NewNumber

func NewNumber() Number

NewNumber returns a new Number type.

type Object

type Object = v1.Object

Object represents the object type.

func NewObject

func NewObject(static []*StaticProperty, dynamic *DynamicProperty) *Object

NewObject returns a new Object type.

type Set

type Set = v1.Set

Set represents the set type.

func NewSet

func NewSet(of Type) *Set

NewSet returns a new Set type.

type StaticProperty added in v0.5.7

type StaticProperty = v1.StaticProperty

StaticProperty represents a static object property.

func NewStaticProperty added in v0.5.7

func NewStaticProperty(key interface{}, value Type) *StaticProperty

NewStaticProperty returns a new StaticProperty object.

type String

type String = v1.String

String represents the string type.

func NewString

func NewString() String

NewString returns a new String type.

type Type

type Type = v1.Type

Type represents a type of a term in the language.

func Args added in v0.5.11

func Args(x ...Type) []Type

Args returns an argument list.

func Keys

func Keys(a Type) Type

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

func Or(a, b Type) Type

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

func Select(a Type, x interface{}) Type

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 added in v0.23.0

func Unmarshal(bs []byte) (result Type, err error)

Unmarshal deserializes bs and returns the resulting type.

func Values

func Values(a Type) Type

Values returns the type of values that can be enumerated for a.

Jump to

Keyboard shortcuts

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