2023-04-22 16:33:28 +12:00
|
|
|
defmodule AshStateMachine.Verifiers.VerifyTransitionActions do
|
2023-09-16 01:40:28 +12:00
|
|
|
# Verifies that each transition corresponds to an update action
|
|
|
|
@moduledoc false
|
2023-04-22 07:25:39 +12:00
|
|
|
use Spark.Dsl.Verifier
|
|
|
|
|
|
|
|
def verify(dsl_state) do
|
|
|
|
dsl_state
|
2023-04-22 16:33:28 +12:00
|
|
|
|> AshStateMachine.Info.state_machine_transitions()
|
2023-04-23 10:27:39 +12:00
|
|
|
|> Enum.reject(fn transition ->
|
|
|
|
transition.action == :*
|
|
|
|
end)
|
2023-04-22 16:33:28 +12:00
|
|
|
|> Enum.each(fn transition ->
|
|
|
|
action = Ash.Resource.Info.action(dsl_state, transition.action)
|
2023-04-22 07:25:39 +12:00
|
|
|
|
|
|
|
unless action && action.type == :update do
|
|
|
|
raise Spark.Error.DslError,
|
|
|
|
module: Spark.Dsl.Verifier.get_persisted(dsl_state, :module),
|
2023-04-22 16:33:28 +12:00
|
|
|
path: [:state_machine, :transitions, :transition, transition.action],
|
2023-04-22 07:25:39 +12:00
|
|
|
message: """
|
2023-04-22 16:33:28 +12:00
|
|
|
Transition configured with action `:#{transition.action}` but no such update action is defined.
|
2023-04-22 07:25:39 +12:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end
|