polix.effects.schema

Malli schemas for effects and results.

Defines the structure of effects, references, and the result type returned by polix.effects.core/apply-effect. Built-in effect types use the :polix.effects/* namespace, while domain-specific effects use their own namespace (e.g., :bashketball/draw-cards).

AssocInEffect

Sets a value at a path in the state.

ConditionalEffect

Evaluates a polix policy condition and applies then or else effect.

The condition is a polix policy expression evaluated against the current state. If satisfied, applies :then. If conflict, applies :else. If residual (open constraints from missing data), behavior depends on :on-residual strategy.

Options: - :on-residual - How to handle open residuals (default :block)

ConjInEffect

Adds a value to a collection at a path.

CtxRef

Reference to a value in the effect context.

CustomEffect

Schema for domain-specific effects. Requires :type and allows any keys.

DissocInEffect

Removes a value at a path in the state.

Effect

Multi-schema dispatching on :type to validate effect structures.

Built-in effects use the :polix.effects/* namespace. Domain-specific effects use their own namespace (e.g., :bashketball/draw-cards) and are validated by the CustomEffect schema.

explain

(explain effect)

Returns an explanation map if the effect is invalid, nil otherwise.

Failure

A single failure entry with effect, error code, and optional message.

FailureStrategy

How to handle transaction failures.

LetEffect

Binds values for use in a nested effect.

MergeInEffect

Merges a map into the value at a path.

MoveEffect

Moves items from one collection to another.

NoopEffect

Effect that does nothing. Useful as a placeholder or in conditionals.

ParamRef

Reference to an effect parameter.

Path

A vector of path segments for navigating nested data structures.

PathSegment

A single segment in a path - keyword, string, or integer.

PendingInfo

Information about a deferred effect awaiting re-evaluation.

Reference

A symbolic reference resolved at effect application time.

Can be: - A keyword (e.g., :self, :target) resolved from context bindings - A state path [:state :path :to :value] - A context path [:ctx :bindings :foo] - A param reference [:param :amount]

registry

Custom Malli registry with Effect schema for recursive references.

RemoveInEffect

Removes items from a collection matching a predicate.

ResidualStrategy

How to handle open residual (uncertain) conditions.

  • :block - Execute else branch (default, current behavior)
  • :defer - Return pending info for later re-evaluation
  • :proceed - Execute then branch, attach residual to result
  • :speculate - Execute then branch, mark as speculative for rollback

Result

The result of applying an effect.

  • :state - The new state after applying the effect
  • :applied - Vector of effects that were successfully applied
  • :failed - Vector of failure entries
  • :pending - Nil, or pending info for deferred effects
  • :speculative-conditions - Conditions assumed true for speculation

SequenceEffect

Applies a sequence of effects in order, threading state through each.

SpeculativeCondition

A condition that was speculatively assumed true.

StateRef

Reference to a value in the application state.

TransactionEffect

Applies effects atomically, rolling back on failure.

Options: - :on-failure - :rollback (default) reverts to original state, :partial keeps successfully applied effects.

UpdateInEffect

Updates a value at a path by applying a function.

valid?

(valid? effect)

Returns true if the effect is valid according to the Effect schema.

ValueOrRef

Any value, or a reference to be resolved at apply time.