Runtime-facing representation of a compiled workflow definition.
SquidMesh.Workflow builds the declarative DSL at compile time. This module
loads the compiled definition and applies the runtime operations needed for
run creation, payload resolution, and persistence serialization.
Summary
Functions
Applies the declared output mapping for one step result.
Resolves the success and rejection targets for an approval step.
Returns the default trigger for the workflow definition.
Returns true when the workflow uses dependency-based step progression.
Resolves dependency-mode progress from persisted per-step state.
Deserializes persisted payload keys back to declared workflow field names.
Deserializes a persisted step name back to the declared workflow step.
Deserializes a persisted trigger name back to the declared workflow trigger.
Returns the workflow entry step.
Returns the workflow entry steps in semantic execution order.
Returns the explicit failure recovery route for a step when one was declared.
Returns the first step scheduled when a run starts.
Builds the public per-step inspection view from declared steps and persisted step statuses.
Loads a compiled workflow definition from a workflow module.
Loads a workflow definition from its persisted module name.
Resolves the next step after a successful execution.
Resolves payload defaults and validates the final payload for a new run.
Resolves one named trigger from the workflow definition.
Serializes a step identifier for persistence.
Serializes a trigger identifier for persistence.
Serializes a workflow module name for persistence.
Fetches one declared workflow step by name.
Returns the compensation callback for one declared step, if any.
Returns the explicit input mapping for one declared step, if any.
Returns the explicit output mapping key for one declared step, if any.
Returns the recovery policy for one declared step.
Returns the local transaction boundary for one declared step, if any.
Resolves the full transition metadata for one step outcome.
Resolves the transition target for a step outcome.
Fetches one declared workflow trigger by name.
Returns completed steps whose recovery policy makes replay unsafe by default.
Validates a payload map against the workflow payload contract.
Types
@type built_in_step_kind() :: :wait | :log | :pause | :approval
@type dependency_step_status() :: :pending | :running | :completed | :failed
@type failure_recovery() :: %{ strategy: failure_recovery_strategy(), target: transition_target() | String.t() }
@type failure_recovery_strategy() :: :compensation | :undo
@type inspect_step() :: %{ step: atom(), depends_on: [atom()], status: inspect_step_status(), recovery: recovery_policy() }
@type inspect_step_status() :: dependency_step_status() | :waiting
@type recovery_policy() :: %{ optional(:compensation) => map(), optional(:failure) => failure_recovery(), irreversible?: boolean(), compensatable?: boolean(), recovery: :automatic | :manual_intervention, replay: :allowed | :manual_review_required }
@type step() :: %{ name: atom(), module: module() | built_in_step_kind(), opts: keyword() }
@type step_input_mapping() :: [atom()]
@type step_output_mapping() :: atom()
@type step_transaction_boundary() :: :repo
@type t() :: %{ triggers: [trigger()], payload: [payload_field()], steps: [step()], transitions: [transition()], retries: [retry()], entry_steps: [atom()], initial_step: atom(), entry_step: atom() | nil }
@type transition() :: %{ :from => atom(), :on => transition_outcome(), :to => transition_target(), optional(:recovery) => failure_recovery_strategy() }
@type transition_outcome() :: :ok | :error
@type transition_target() :: atom() | :complete
@type trigger() :: %{ name: atom(), type: trigger_type(), config: map(), payload: [payload_field()] }
@type trigger_type() :: :manual | :cron
Functions
Applies the declared output mapping for one step result.
@spec approval_transition_targets(t(), atom()) :: {:ok, %{ok: transition_target(), error: transition_target()}} | {:error, {:unknown_transition, atom(), atom()}}
Resolves the success and rejection targets for an approval step.
Returns the default trigger for the workflow definition.
Returns true when the workflow uses dependency-based step progression.
@spec dependency_progress( t(), %{optional(atom() | String.t()) => dependency_step_status() | String.t()} ) :: dependency_progress()
Resolves dependency-mode progress from persisted per-step state.
Ready steps are scheduled breadth-first by dependency phase so newly unlocked descendants do not bypass incomplete root or sibling steps.
Deserializes persisted payload keys back to declared workflow field names.
Deserializes a persisted step name back to the declared workflow step.
Deserializes a persisted trigger name back to the declared workflow trigger.
Returns the workflow entry step.
Returns the workflow entry steps in semantic execution order.
@spec failure_recovery(t(), atom()) :: {:ok, failure_recovery() | nil} | {:error, {:unknown_transition, atom(), atom()}}
Returns the explicit failure recovery route for a step when one was declared.
Returns the first step scheduled when a run starts.
@spec inspect_steps( t(), %{ optional(atom() | String.t()) => dependency_step_status() | inspect_step_status() } ) :: [inspect_step()]
Builds the public per-step inspection view from declared steps and persisted step statuses.
@spec load(module()) :: {:ok, t()} | {:error, load_error()}
Loads a compiled workflow definition from a workflow module.
@spec load_serialized(String.t()) :: {:ok, module(), t()} | {:error, load_error()}
Loads a workflow definition from its persisted module name.
@spec next_step_after_success(t(), atom(), [atom() | String.t()]) :: {:ok, transition_target()} | {:error, {:no_runnable_step, [atom()]}}
Resolves the next step after a successful execution.
@spec resolve_payload(t(), map()) :: {:ok, map()} | {:error, {:invalid_payload, payload_error_details()}}
Resolves payload defaults and validates the final payload for a new run.
@spec resolve_trigger(t(), atom()) :: {:ok, atom()} | {:error, trigger_error()}
Resolves one named trigger from the workflow definition.
Serializes a step identifier for persistence.
Serializes a trigger identifier for persistence.
Serializes a workflow module name for persistence.
Fetches one declared workflow step by name.
@spec step_compensation_callback(t(), atom()) :: {:ok, module() | nil} | {:error, {:unknown_step, atom()}}
Returns the compensation callback for one declared step, if any.
A callback means the step's completed side effect is reversible by a host application action. The runtime uses it only during saga rollback after a downstream terminal failure, never as a same-step fallback.
@spec step_input_mapping(t(), atom()) :: {:ok, step_input_mapping() | nil} | {:error, {:unknown_step, atom()}}
Returns the explicit input mapping for one declared step, if any.
@spec step_output_mapping(t(), atom()) :: {:ok, step_output_mapping() | nil} | {:error, {:unknown_step, atom()}}
Returns the explicit output mapping key for one declared step, if any.
@spec step_recovery_policy(t(), atom()) :: {:ok, recovery_policy()} | {:error, {:unknown_step, atom()}}
Returns the recovery policy for one declared step.
Irreversible steps are always treated as non-compensatable. Steps marked
compensatable: false keep their reversibility marker but still require
explicit operator review before replay.
@spec step_transaction_boundary(t(), atom()) :: {:ok, step_transaction_boundary() | nil} | {:error, {:unknown_step, atom()}}
Returns the local transaction boundary for one declared step, if any.
:repo wraps only the host action execution in the configured Ecto repo
transaction. Squid Mesh persists attempt, step, and run progression in its
normal durable phase after the action returns.
@spec transition(t(), atom(), transition_outcome()) :: {:ok, transition()} | {:error, {:unknown_transition, atom(), atom()}}
Resolves the full transition metadata for one step outcome.
@spec transition_target(t(), atom(), transition_outcome()) :: {:ok, transition_target()} | {:error, {:unknown_transition, atom(), atom()}}
Resolves the transition target for a step outcome.
@spec trigger(t(), atom()) :: {:ok, trigger()} | {:error, trigger_error()}
Fetches one declared workflow trigger by name.
@spec unsafe_replay_steps(t(), [ atom() | String.t() | {atom() | String.t(), map() | nil} ]) :: [map()]
Returns completed steps whose recovery policy makes replay unsafe by default.
@spec validate_payload(t(), map()) :: :ok | {:error, {:invalid_payload, payload_error_details()}}
Validates a payload map against the workflow payload contract.