types

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package types provides the unified type system for Effectus

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreComparableTypes

func AreComparableTypes(t1, t2 *Type) bool

AreComparableTypes checks if two types can be compared with operators like <, >, etc.

func AreTypesCompatible

func AreTypesCompatible(actual, expected *Type) bool

AreTypesCompatible checks if two types are compatible (actual can be assigned to expected)

func CanAssign

func CanAssign(sourceType, targetType *Type) bool

CanAssign checks if a value of sourceType can be assigned to a variable of targetType

func GetLiteralValue

func GetLiteralValue(lit ast.Literal) interface{}

GetLiteralValue extracts the actual value from a Literal

func IsCoercibleTo

func IsCoercibleTo(sourceType, targetType *Type) bool

IsCoercibleTo checks if a value can be coerced to another type

func IsComparableType

func IsComparableType(t *Type) bool

IsComparableType returns whether a type supports comparison operators

func IsContainerType

func IsContainerType(t *Type) bool

IsContainerType returns whether a type can be used with 'contains' operators

Types

type AdvancedFactProvider

type AdvancedFactProvider interface {
	FactProvider
	GetWithContext(path string) (interface{}, *ResolutionResult)
}

AdvancedFactProvider extends FactProvider with context

type Capability

type Capability uint32

Capability represents the capability required by a verb

const (
	// CapabilityNone represents no capability
	CapabilityNone Capability = iota
	// CapabilityRead represents read-only access
	CapabilityRead
	// CapabilityModify represents modification access
	CapabilityModify
	// CapabilityCreate represents creation access
	CapabilityCreate
	// CapabilityDelete represents deletion access
	CapabilityDelete
)

func (Capability) CanPerform

func (c Capability) CanPerform(required Capability) bool

CanPerform checks if this capability can perform the specified capability Implements a simple capability lattice where higher capabilities include lower ones

func (Capability) String

func (c Capability) String() string

String returns a string representation of the capability

type FactProvider

type FactProvider interface {
	Get(path string) (interface{}, bool)
}

FactProvider represents a simple interface for retrieving facts

type Facts

type Facts interface {
	Get(path string) (interface{}, bool)
}

Facts interface for type checking

type FunctionSpec

type FunctionSpec struct {
	Name        string
	Func        interface{}
	ArgTypes    []string
	ReturnType  string
	Unsafe      bool
	Description string
}

FunctionSpec describes an expression function signature.

func StandardLibrary

func StandardLibrary() []*FunctionSpec

StandardLibrary returns the built-in expression function specs.

type PrimitiveType

type PrimitiveType int

PrimitiveType represents a basic type in the type system

const (
	// TypeUnknown represents an unknown type
	TypeUnknown PrimitiveType = iota

	// TypeBool represents a boolean type
	TypeBool

	// TypeInt represents an integer type
	TypeInt

	// TypeFloat represents a floating-point number
	TypeFloat

	// TypeString represents a string
	TypeString

	// TypeList represents a list/array type
	TypeList

	// TypeMap represents a map type
	TypeMap

	// TypeTime represents a timestamp
	TypeTime

	// TypeDate represents a date
	TypeDate

	// TypeDuration represents a time duration
	TypeDuration

	// TypeObject represents an object type
	TypeObject
)

type ResolutionResult

type ResolutionResult struct {
	Exists   bool
	Path     string
	Value    interface{}
	Error    error
	Depth    int
	Resolved []string
}

ResolutionResult provides details about path resolution

type Type

type Type struct {
	// Name is a custom type name (for named types)
	Name string

	// PrimType is the primitive type
	PrimType PrimitiveType

	// ElementType is the element type for lists (replaces ListType)
	ElementType *Type

	// Properties is a map of property types (for objects and maps)
	// For maps, "__key" and "__value" represent key and value types
	Properties map[string]*Type

	// ReferenceType is for types defined elsewhere
	ReferenceType string
}

Type represents a type in the Effectus type system

func InferTypeFromInterface

func InferTypeFromInterface(value interface{}) *Type

InferTypeFromInterface infers a Type from any interface value

func InferTypeFromJSON

func InferTypeFromJSON(jsonData []byte) (*Type, error)

Create type inference wrapper for JSON data

func InferTypeFromLiteral

func InferTypeFromLiteral(lit *ast.Literal) *Type

InferTypeFromLiteral infers a Type from an AST Literal

func InferTypeFromValue

func InferTypeFromValue(value interface{}) *Type

InferTypeFromValue infers a Type from a Go value

func NewAnyType

func NewAnyType() *Type

NewAnyType creates a type that can hold any value

func NewBoolType

func NewBoolType() *Type

NewBoolType creates a new boolean type

func NewDateType

func NewDateType() *Type

NewDateType creates a new date type

func NewDurationType

func NewDurationType() *Type

NewDurationType creates a new duration type

func NewFloatType

func NewFloatType() *Type

NewFloatType creates a new float type

func NewIntType

func NewIntType() *Type

NewIntType creates a new integer type

func NewListType

func NewListType(elemType *Type) *Type

NewListType creates a new list type with the given element type

func NewMapType

func NewMapType(keyType, valueType *Type) *Type

NewMapType creates a new map type

func NewObjectType

func NewObjectType() *Type

NewObjectType creates a new object type

func NewStringType

func NewStringType() *Type

NewStringType creates a new string type

func NewTimeType

func NewTimeType() *Type

NewTimeType creates a new time type

func ParseTypeName

func ParseTypeName(name string) (*Type, error)

ParseTypeName converts a string type name into a Type.

func (*Type) AddProperty

func (t *Type) AddProperty(name string, propType *Type) error

AddProperty adds a property to an object type

func (*Type) Clone

func (t *Type) Clone() *Type

Clone creates a deep copy of this type

func (*Type) Equals

func (t *Type) Equals(other *Type) bool

Equals checks if two types are equivalent

func (*Type) IsContainer

func (t *Type) IsContainer() bool

IsContainer returns true if the type is a container type (list or map)

func (*Type) IsNamed

func (t *Type) IsNamed() bool

IsNamed returns true if the type has a name

func (*Type) IsNumeric

func (t *Type) IsNumeric() bool

IsNumeric returns true if the type is a numeric type

func (*Type) IsPrimitive

func (t *Type) IsPrimitive() bool

IsPrimitive returns true if the type is a primitive type

func (*Type) IsReference

func (t *Type) IsReference() bool

IsReference returns true if the type references another type

func (*Type) ListType

func (t *Type) ListType() *Type

ListType returns the element type for list types.

func (*Type) MapKeyType

func (t *Type) MapKeyType() *Type

MapKeyType returns the key type of a map

func (*Type) MapValueType

func (t *Type) MapValueType() *Type

MapValueType returns the value type of a map

func (*Type) String

func (t *Type) String() string

String returns the string representation of the type

type TypeSystem

type TypeSystem struct {
	// contains filtered or unexported fields
}

TypeSystem is the central type management system for Effectus

func NewTypeSystem

func NewTypeSystem() *TypeSystem

NewTypeSystem creates a new type system

func (*TypeSystem) AutoRegisterTypes

func (ts *TypeSystem) AutoRegisterTypes(facts effectus.Facts)

AutoRegisterTypes automatically registers types for all facts

func (*TypeSystem) BuildTypeSchemaFromFacts

func (ts *TypeSystem) BuildTypeSchemaFromFacts(facts effectus.Facts)

BuildTypeSchemaFromFacts builds a type schema from facts

func (*TypeSystem) CheckValueTypeCompatibility

func (ts *TypeSystem) CheckValueTypeCompatibility(operator string, factType, valueType *Type) error

CheckValueTypeCompatibility checks if the value type is compatible with the fact type for the given operator

func (*TypeSystem) GenerateTypeReport

func (ts *TypeSystem) GenerateTypeReport() string

GenerateTypeReport generates a human-readable report of types

func (*TypeSystem) GetAllFactPaths

func (ts *TypeSystem) GetAllFactPaths() []string

GetAllFactPaths returns all registered fact paths

func (*TypeSystem) GetAllTypes

func (ts *TypeSystem) GetAllTypes() map[string]*Type

GetAllTypes returns all registered named types

func (*TypeSystem) GetAllVerbNames

func (ts *TypeSystem) GetAllVerbNames() []string

GetAllVerbNames returns all registered verb names.

func (*TypeSystem) GetFactType

func (ts *TypeSystem) GetFactType(path string) (*Type, error)

GetFactType retrieves the type for a fact path

func (*TypeSystem) GetFactTypeVersion

func (ts *TypeSystem) GetFactTypeVersion(path, version string) (*Type, error)

GetFactTypeVersion retrieves a versioned fact type.

func (*TypeSystem) GetFunctionSpec

func (ts *TypeSystem) GetFunctionSpec(name string) (*FunctionSpec, bool)

GetFunctionSpec returns the function spec if registered.

func (*TypeSystem) GetFunctionSpecs

func (ts *TypeSystem) GetFunctionSpecs() map[string]*FunctionSpec

GetFunctionSpecs returns all function specs.

func (*TypeSystem) GetType

func (ts *TypeSystem) GetType(name string) (*Type, bool)

GetType retrieves a type by name

func (*TypeSystem) GetVerbSpec

func (ts *TypeSystem) GetVerbSpec(verbName string) (*VerbSpec, error)

GetVerbSpec retrieves a verb specification

func (*TypeSystem) GetVerbType

func (ts *TypeSystem) GetVerbType(verbName string) (*VerbInfo, bool)

GetVerbType returns type information for a specific verb

func (*TypeSystem) GetVerbTypes

func (ts *TypeSystem) GetVerbTypes() map[string]*VerbInfo

GetVerbTypes returns all verb type information

func (*TypeSystem) InferTypeFromFactPath

func (ts *TypeSystem) InferTypeFromFactPath(facts effectus.Facts, path string) (*Type, error)

InferTypeFromFactPath tries to infer a type from a fact if no type is registered

func (*TypeSystem) LoadJSONSchemaBytes

func (ts *TypeSystem) LoadJSONSchemaBytes(prefix string, data []byte) error

LoadJSONSchemaBytes loads a JSON Schema payload into fact types with a prefix.

func (*TypeSystem) LoadJSONSchemaBytesVersion

func (ts *TypeSystem) LoadJSONSchemaBytesVersion(prefix, version string, data []byte, setDefault bool) error

LoadJSONSchemaBytesVersion loads a JSON Schema payload into versioned fact types.

func (*TypeSystem) LoadJSONSchemaFile

func (ts *TypeSystem) LoadJSONSchemaFile(filename string) error

LoadJSONSchemaFile loads a JSON Schema (subset) into fact types.

func (*TypeSystem) LoadSchemaFile

func (ts *TypeSystem) LoadSchemaFile(filename string) error

LoadSchemaFile loads fact types from a schema file

func (*TypeSystem) LoadSchemaJSONBytes

func (ts *TypeSystem) LoadSchemaJSONBytes(prefix string, data []byte) error

LoadSchemaJSONBytes loads either JSON schema or Effectus schema entries.

func (*TypeSystem) LoadSchemaJSONBytesVersion

func (ts *TypeSystem) LoadSchemaJSONBytesVersion(prefix, version string, data []byte, setDefault bool) error

LoadSchemaJSONBytesVersion loads schema payloads into versioned fact types.

func (*TypeSystem) LoadVerbSpecs

func (ts *TypeSystem) LoadVerbSpecs(filename string) error

LoadVerbSpecs loads verb specifications from a JSON file

func (*TypeSystem) MergeTypeSystem

func (ts *TypeSystem) MergeTypeSystem(other *TypeSystem)

MergeTypeSystem merges another type system into this one

func (*TypeSystem) OperatorCompatibility

func (ts *TypeSystem) OperatorCompatibility(operator string, valueType *Type) error

OperatorCompatibility checks if an operator is compatible with a given type

func (*TypeSystem) RegisterFactType

func (ts *TypeSystem) RegisterFactType(path string, typ *Type)

RegisterFactType registers a type for a fact path

func (*TypeSystem) RegisterFactTypeVersion

func (ts *TypeSystem) RegisterFactTypeVersion(path, version string, typ *Type, setDefault bool)

RegisterFactTypeVersion registers a versioned type for a fact path.

func (*TypeSystem) RegisterFunctionSpec

func (ts *TypeSystem) RegisterFunctionSpec(spec *FunctionSpec)

RegisterFunctionSpec registers a function signature for expression type checking.

func (*TypeSystem) RegisterNamespaceAlias

func (ts *TypeSystem) RegisterNamespaceAlias(alias, target string)

RegisterNamespaceAlias registers an alias for a canonical prefix.

func (*TypeSystem) RegisterProtoTypes

func (ts *TypeSystem) RegisterProtoTypes(protoFile string) error

RegisterProtoTypes registers types from protobuf files

func (*TypeSystem) RegisterStandardLibrary

func (ts *TypeSystem) RegisterStandardLibrary()

RegisterStandardLibrary registers built-in expression functions.

func (*TypeSystem) RegisterType

func (ts *TypeSystem) RegisterType(name string, typ *Type)

RegisterType registers a named type in the system

func (*TypeSystem) RegisterVerb

func (ts *TypeSystem) RegisterVerb(verbName string, argTypes map[string]*Type, returnType *Type, requiredArgs []string) error

RegisterVerb registers a verb with full control over which arguments are required This is the most flexible registration method

func (*TypeSystem) RegisterVerbType

func (ts *TypeSystem) RegisterVerbType(verbName string, argTypes map[string]*Type, returnType *Type) error

RegisterVerbType registers a verb with its argument types and return type All arguments are considered required by default

func (*TypeSystem) ResetFactTypes

func (ts *TypeSystem) ResetFactTypes()

ResetFactTypes clears all fact type registrations while keeping verbs/functions intact.

func (*TypeSystem) ResolveAlias

func (ts *TypeSystem) ResolveAlias(path string) string

ResolveAlias resolves a path using registered aliases, if any.

func (*TypeSystem) SetDefaultFactVersion

func (ts *TypeSystem) SetDefaultFactVersion(path, version string)

SetDefaultFactVersion sets the default version for a fact path.

func (*TypeSystem) TypeCheckArgValue

func (ts *TypeSystem) TypeCheckArgValue(value *ast.ArgValue, requiredType *Type, facts Facts) error

TypeCheckArgValue checks an argument without flow result bindings.

func (*TypeSystem) TypeCheckArgValueWithBindings

func (ts *TypeSystem) TypeCheckArgValueWithBindings(value *ast.ArgValue, requiredType *Type, facts Facts, bindings map[string]*Type) error

TypeCheckArgValueWithBindings checks an argument against fact and flow-result types.

func (*TypeSystem) TypeCheckArgumentValue

func (ts *TypeSystem) TypeCheckArgumentValue(arg *ast.ArgValue, requiredType *Type, facts Facts) error

TypeCheckArgumentValue type checks an argument value against the required type

func (*TypeSystem) TypeCheckEffect

func (ts *TypeSystem) TypeCheckEffect(effect *ast.Effect, facts Facts) error

TypeCheckEffect type checks an entire effect

func (*TypeSystem) TypeCheckFact

func (ts *TypeSystem) TypeCheckFact(facts effectus.Facts, path string, expectedType *Type) error

TypeCheckFact checks if a fact at the given path has the expected type

func (*TypeSystem) TypeCheckFile

func (ts *TypeSystem) TypeCheckFile(file *ast.File, facts effectus.Facts) error

TypeCheckFile performs type checking on a parsed file

func (*TypeSystem) TypeCheckListElements

func (ts *TypeSystem) TypeCheckListElements(elements []ast.Literal, elementType *Type) error

Helper type check functions for list elements and map entries

func (*TypeSystem) TypeCheckLiteralArgument

func (ts *TypeSystem) TypeCheckLiteralArgument(lit *ast.Literal, requiredType *Type) error

TypeCheckLiteralArgument type checks a literal argument value against a required type

func (*TypeSystem) TypeCheckLogicalExpressionAST

func (ts *TypeSystem) TypeCheckLogicalExpressionAST(expr string) error

TypeCheckLogicalExpressionAST checks a string expression for type safety

func (*TypeSystem) TypeCheckMapEntries

func (ts *TypeSystem) TypeCheckMapEntries(entries []*ast.MapEntry, keyType, valueType *Type) error

func (*TypeSystem) TypeCheckPayload

func (ts *TypeSystem) TypeCheckPayload(payload interface{}, expectedType *Type) error

TypeCheckPayload validates a payload against an expected type

func (*TypeSystem) TypeCheckPredicate

func (ts *TypeSystem) TypeCheckPredicate(expr string) error

TypeCheckPredicate performs comprehensive type checking on a predicate

func (*TypeSystem) TypeCheckPredicateAST

func (ts *TypeSystem) TypeCheckPredicateAST(expr string) error

TypeCheckPredicateAST checks a string expression for type safety

func (*TypeSystem) TypeCheckStep

func (ts *TypeSystem) TypeCheckStep(step *ast.Step, facts Facts) error

Implement similar functions for steps in flows

func (*TypeSystem) TypeCheckValue

func (ts *TypeSystem) TypeCheckValue(value interface{}, expectedType *Type) error

TypeCheckValue checks if a value matches the expected type

type TypedProvider

type TypedProvider struct {
	// contains filtered or unexported fields
}

TypedProvider is a fact provider that includes type information

func NewTypedProvider

func NewTypedProvider(provider FactProvider, typeSystem *TypeSystem) *TypedProvider

NewTypedProvider creates a new typed provider

func (*TypedProvider) EnrichWithTypes

func (p *TypedProvider) EnrichWithTypes(facts effectus.Facts) *TypedProvider

EnrichWithTypes enriches all values with type information

func (*TypedProvider) Get

func (p *TypedProvider) Get(path string) (interface{}, bool)

Get retrieves a value using a structured path

func (*TypedProvider) GetTypeSystem

func (p *TypedProvider) GetTypeSystem() *TypeSystem

GetTypeSystem returns the underlying type system

func (*TypedProvider) GetWithContext

func (p *TypedProvider) GetWithContext(path string) (interface{}, *ResolutionResult)

GetWithContext retrieves a value with detailed resolution information including type

func (*TypedProvider) WithProvider

func (p *TypedProvider) WithProvider(provider FactProvider) *TypedProvider

WithProvider creates a new typed provider with a different underlying provider

type VerbInfo

type VerbInfo struct {
	// ArgTypes maps argument names to their types
	ArgTypes map[string]*Type

	// ReturnType is the verb's return type
	ReturnType *Type
}

VerbInfo contains type information for a verb

type VerbSpec

type VerbSpec struct {
	Name         string           // Verb name
	ArgTypes     map[string]*Type // Types for each argument
	ReturnType   *Type            // Return type of the verb
	InverseVerb  string           // Optional inverse verb name for compensations
	RequiredArgs []string         // List of required arguments
	Capability   Capability       // Capability ID for locking
	Description  string           // Human-readable description
}

VerbSpec defines type requirements for a verb

Jump to

Keyboard shortcuts

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