Documentation
¶
Overview ¶
Package ir defines Effectus's callback-free, checked execution representation.
Index ¶
- Constants
- Variables
- func CanonicalPlanOrder(plans []*effectusv1.Plan)
- func ContractHash(contract VerbContract) (string, error)
- func EnvironmentDigest(environment Environment) (string, error)
- func NormalizeValue(environment Environment, typeName string, value any) (any, error)
- type Checked
- type Environment
- type FunctionContract
- type IdempotencyPolicy
- type Limits
- type RetryPolicy
- type TypeDefinition
- type TypeKind
- type VerbContract
Constants ¶
const FormatVersion uint32 = 1
FormatVersion is the only artifact format accepted by this package.
Variables ¶
var ( // ErrInvalidArtifact identifies a structural or semantic IR failure. ErrInvalidArtifact = errors.New("invalid checked IR artifact") // ErrLimitExceeded identifies a configured structural or value limit. ErrLimitExceeded = errors.New("checked IR limit exceeded") )
var DefaultLimits = ValidationDefaults()
DefaultLimits is a compatibility copy of the production defaults. Mutating this variable has no effect on checking. Removal requires compatibility review and an approved breaking release. Deprecated: use ValidationDefaults. Removal deadline: 2027-09-01.
Functions ¶
func CanonicalPlanOrder ¶
func CanonicalPlanOrder(plans []*effectusv1.Plan)
CanonicalPlanOrder sorts a mutable artifact into the only accepted plan order. Callers must still pass the result to Check.
func ContractHash ¶
func ContractHash(contract VerbContract) (string, error)
ContractHash returns the canonical SHA-256 digest of a verb contract.
func EnvironmentDigest ¶
func EnvironmentDigest(environment Environment) (string, error)
EnvironmentDigest returns the canonical SHA-256 digest used by artifacts.
func NormalizeValue ¶ added in v0.5.0
func NormalizeValue(environment Environment, typeName string, value any) (any, error)
NormalizeValue validates a value against a closed checked type and returns an owned, JSON-safe copy. Integers are signed int64, floats are finite float64, and bytes are canonical padded base64 strings (raw []byte is also accepted). Lists accept Go slices/arrays; maps and objects require string keys. Null is accepted only by the null type. Values deeper than 64 levels are rejected. The environment is declarations only; no callbacks are invoked.
Types ¶
type Checked ¶
type Checked struct {
// contains filtered or unexported fields
}
Checked is an opaque, immutable execution plan. It contains no callbacks.
func Check ¶
func Check(artifact *effectusv1.RuleArtifact, environment Environment, limits Limits) (*Checked, error)
Check validates an artifact and stores only its deterministic protobuf form. The input and environment may be mutated after this call without changing the returned Checked value.
func Parse ¶
func Parse(data []byte, environment Environment, limits Limits) (*Checked, error)
Parse decodes untrusted protobuf bytes and rechecks every reference.
func (*Checked) CloneArtifact ¶
func (c *Checked) CloneArtifact() *effectusv1.RuleArtifact
CloneArtifact returns a mutable copy for compatibility and inspection. The returned value is not checked state and must be passed through Check again.
type Environment ¶
type Environment struct {
Facts map[string]string `json:"facts"`
Verbs map[string]VerbContract `json:"verbs"`
Functions map[string]FunctionContract `json:"functions"`
Types map[string]TypeDefinition `json:"types"`
}
Environment is immutable input to checking. Check copies it before use. It contains declarations only; checking never calls executors or user code.
type FunctionContract ¶
type FunctionContract struct {
ArgumentTypes []string `json:"argument_types"`
ReturnType string `json:"return_type"`
Pure bool `json:"pure"`
Total bool `json:"total"`
}
FunctionContract describes an expression function. Checked predicates may reference only functions explicitly declared pure and total.
type IdempotencyPolicy ¶
type IdempotencyPolicy string
IdempotencyPolicy states which retry guarantee an executor binding provides.
const ( IdempotencyNone IdempotencyPolicy = "none" IdempotencyKeyRequired IdempotencyPolicy = "key_required" IdempotencySinkGuaranteed IdempotencyPolicy = "sink_guaranteed" )
type Limits ¶
type Limits struct {
MaxArtifactBytes int
MaxPlans int
MaxSteps int
MaxStepsPerPlan int
MaxArgumentsPerStep int
MaxPredicateNodes int
MaxLiteralNodes int
MaxDepth int
MaxStringBytes int
MaxBytesValue int
MaxCollectionItems int
MaxObjectFields int
MaxTotalStringBytes int
}
Limits bounds untrusted artifacts. Zero fields use fixed production defaults; negative fields are invalid.
func ValidationDefaults ¶ added in v0.5.0
func ValidationDefaults() Limits
ValidationDefaults returns an independent copy of the fixed production bounds. Zero-valued Limits use these same bounds without reading mutable globals.
type RetryPolicy ¶
type RetryPolicy struct {
MaxAttempts uint32 `json:"max_attempts"`
InitialBackoffMillis uint64 `json:"initial_backoff_millis"`
MaxBackoffMillis uint64 `json:"max_backoff_millis"`
}
RetryPolicy is frozen into every checked step that invokes the verb.
type TypeDefinition ¶
type TypeDefinition struct {
Kind TypeKind `json:"kind"`
ElementType string `json:"element_type,omitempty"`
Fields map[string]string `json:"fields,omitempty"`
RequiredFields []string `json:"required_fields,omitempty"`
}
TypeDefinition declares a named structural type. Object fields not present in Fields are rejected. Maps always have string keys.
type VerbContract ¶
type VerbContract struct {
Arguments map[string]string `json:"arguments"`
RequiredArgs []string `json:"required_args"`
ResultType string `json:"result_type"`
InverseVerb string `json:"inverse_verb,omitempty"`
RetryPolicy RetryPolicy `json:"retry_policy"`
IdempotencyPolicy IdempotencyPolicy `json:"idempotency_policy"`
FencingRequired bool `json:"fencing_required"`
}
VerbContract describes the serializable part of a verb contract.