Documentation
¶
Overview ¶
Package types provides the unified type system for Effectus
Index ¶
- func AreComparableTypes(t1, t2 *Type) bool
- func AreTypesCompatible(actual, expected *Type) bool
- func CanAssign(sourceType, targetType *Type) bool
- func GetLiteralValue(lit ast.Literal) interface{}
- func IsCoercibleTo(sourceType, targetType *Type) bool
- func IsComparableType(t *Type) bool
- func IsContainerType(t *Type) bool
- type AdvancedFactProvider
- type Capability
- type FactProvider
- type Facts
- type FunctionSpec
- type PrimitiveType
- type ResolutionResult
- type Type
- func InferTypeFromInterface(value interface{}) *Type
- func InferTypeFromJSON(jsonData []byte) (*Type, error)
- func InferTypeFromLiteral(lit *ast.Literal) *Type
- func InferTypeFromValue(value interface{}) *Type
- func NewAnyType() *Type
- func NewBoolType() *Type
- func NewDateType() *Type
- func NewDurationType() *Type
- func NewFloatType() *Type
- func NewIntType() *Type
- func NewListType(elemType *Type) *Type
- func NewMapType(keyType, valueType *Type) *Type
- func NewObjectType() *Type
- func NewStringType() *Type
- func NewTimeType() *Type
- func ParseTypeName(name string) (*Type, error)
- func (t *Type) AddProperty(name string, propType *Type) error
- func (t *Type) Clone() *Type
- func (t *Type) Equals(other *Type) bool
- func (t *Type) IsContainer() bool
- func (t *Type) IsNamed() bool
- func (t *Type) IsNumeric() bool
- func (t *Type) IsPrimitive() bool
- func (t *Type) IsReference() bool
- func (t *Type) ListType() *Type
- func (t *Type) MapKeyType() *Type
- func (t *Type) MapValueType() *Type
- func (t *Type) String() string
- type TypeSystem
- func (ts *TypeSystem) AutoRegisterTypes(facts effectus.Facts)
- func (ts *TypeSystem) BuildTypeSchemaFromFacts(facts effectus.Facts)
- func (ts *TypeSystem) CheckValueTypeCompatibility(operator string, factType, valueType *Type) error
- func (ts *TypeSystem) GenerateTypeReport() string
- func (ts *TypeSystem) GetAllFactPaths() []string
- func (ts *TypeSystem) GetAllTypes() map[string]*Type
- func (ts *TypeSystem) GetAllVerbNames() []string
- func (ts *TypeSystem) GetFactType(path string) (*Type, error)
- func (ts *TypeSystem) GetFactTypeVersion(path, version string) (*Type, error)
- func (ts *TypeSystem) GetFunctionSpec(name string) (*FunctionSpec, bool)
- func (ts *TypeSystem) GetFunctionSpecs() map[string]*FunctionSpec
- func (ts *TypeSystem) GetType(name string) (*Type, bool)
- func (ts *TypeSystem) GetVerbSpec(verbName string) (*VerbSpec, error)
- func (ts *TypeSystem) GetVerbType(verbName string) (*VerbInfo, bool)
- func (ts *TypeSystem) GetVerbTypes() map[string]*VerbInfo
- func (ts *TypeSystem) InferTypeFromFactPath(facts effectus.Facts, path string) (*Type, error)
- func (ts *TypeSystem) LoadJSONSchemaBytes(prefix string, data []byte) error
- func (ts *TypeSystem) LoadJSONSchemaBytesVersion(prefix, version string, data []byte, setDefault bool) error
- func (ts *TypeSystem) LoadJSONSchemaFile(filename string) error
- func (ts *TypeSystem) LoadSchemaFile(filename string) error
- func (ts *TypeSystem) LoadSchemaJSONBytes(prefix string, data []byte) error
- func (ts *TypeSystem) LoadSchemaJSONBytesVersion(prefix, version string, data []byte, setDefault bool) error
- func (ts *TypeSystem) LoadVerbSpecs(filename string) error
- func (ts *TypeSystem) MergeTypeSystem(other *TypeSystem)
- func (ts *TypeSystem) OperatorCompatibility(operator string, valueType *Type) error
- func (ts *TypeSystem) RegisterFactType(path string, typ *Type)
- func (ts *TypeSystem) RegisterFactTypeVersion(path, version string, typ *Type, setDefault bool)
- func (ts *TypeSystem) RegisterFunctionSpec(spec *FunctionSpec)
- func (ts *TypeSystem) RegisterNamespaceAlias(alias, target string)
- func (ts *TypeSystem) RegisterProtoTypes(protoFile string) error
- func (ts *TypeSystem) RegisterStandardLibrary()
- func (ts *TypeSystem) RegisterType(name string, typ *Type)
- func (ts *TypeSystem) RegisterVerb(verbName string, argTypes map[string]*Type, returnType *Type, ...) error
- func (ts *TypeSystem) RegisterVerbType(verbName string, argTypes map[string]*Type, returnType *Type) error
- func (ts *TypeSystem) ResetFactTypes()
- func (ts *TypeSystem) ResolveAlias(path string) string
- func (ts *TypeSystem) SetDefaultFactVersion(path, version string)
- func (ts *TypeSystem) TypeCheckArgValue(value *ast.ArgValue, requiredType *Type, facts Facts) error
- func (ts *TypeSystem) TypeCheckArgValueWithBindings(value *ast.ArgValue, requiredType *Type, facts Facts, ...) error
- func (ts *TypeSystem) TypeCheckArgumentValue(arg *ast.ArgValue, requiredType *Type, facts Facts) error
- func (ts *TypeSystem) TypeCheckEffect(effect *ast.Effect, facts Facts) error
- func (ts *TypeSystem) TypeCheckFact(facts effectus.Facts, path string, expectedType *Type) error
- func (ts *TypeSystem) TypeCheckFile(file *ast.File, facts effectus.Facts) error
- func (ts *TypeSystem) TypeCheckListElements(elements []ast.Literal, elementType *Type) error
- func (ts *TypeSystem) TypeCheckLiteralArgument(lit *ast.Literal, requiredType *Type) error
- func (ts *TypeSystem) TypeCheckLogicalExpressionAST(expr string) error
- func (ts *TypeSystem) TypeCheckMapEntries(entries []*ast.MapEntry, keyType, valueType *Type) error
- func (ts *TypeSystem) TypeCheckPayload(payload interface{}, expectedType *Type) error
- func (ts *TypeSystem) TypeCheckPredicate(expr string) error
- func (ts *TypeSystem) TypeCheckPredicateAST(expr string) error
- func (ts *TypeSystem) TypeCheckStep(step *ast.Step, facts Facts) error
- func (ts *TypeSystem) TypeCheckValue(value interface{}, expectedType *Type) error
- type TypedProvider
- func (p *TypedProvider) EnrichWithTypes(facts effectus.Facts) *TypedProvider
- func (p *TypedProvider) Get(path string) (interface{}, bool)
- func (p *TypedProvider) GetTypeSystem() *TypeSystem
- func (p *TypedProvider) GetWithContext(path string) (interface{}, *ResolutionResult)
- func (p *TypedProvider) WithProvider(provider FactProvider) *TypedProvider
- type VerbInfo
- type VerbSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreComparableTypes ¶
AreComparableTypes checks if two types can be compared with operators like <, >, etc.
func AreTypesCompatible ¶
AreTypesCompatible checks if two types are compatible (actual can be assigned to expected)
func CanAssign ¶
CanAssign checks if a value of sourceType can be assigned to a variable of targetType
func GetLiteralValue ¶
GetLiteralValue extracts the actual value from a Literal
func IsCoercibleTo ¶
IsCoercibleTo checks if a value can be coerced to another type
func IsComparableType ¶
IsComparableType returns whether a type supports comparison operators
func IsContainerType ¶
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 ¶
FactProvider represents a simple interface for retrieving facts
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 ¶
Create type inference wrapper for JSON data
func InferTypeFromLiteral ¶
InferTypeFromLiteral infers a Type from an AST Literal
func InferTypeFromValue ¶
func InferTypeFromValue(value interface{}) *Type
InferTypeFromValue infers a Type from a Go value
func NewListType ¶
NewListType creates a new list type with the given element type
func ParseTypeName ¶
ParseTypeName converts a string type name into a Type.
func (*Type) AddProperty ¶
AddProperty adds a property to an object type
func (*Type) IsContainer ¶
IsContainer returns true if the type is a container type (list or map)
func (*Type) IsPrimitive ¶
IsPrimitive returns true if the type is a primitive type
func (*Type) IsReference ¶
IsReference returns true if the type references another type
func (*Type) MapKeyType ¶
MapKeyType returns the key type of a map
func (*Type) MapValueType ¶
MapValueType returns the value type of a map
type TypeSystem ¶
type TypeSystem struct {
// contains filtered or unexported fields
}
TypeSystem is the central type management system for Effectus
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 ¶
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 ¶
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 ¶
TypeCheckFact checks if a fact at the given path has the expected type
func (*TypeSystem) TypeCheckFile ¶
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