diff --git a/.tool-versions b/.tool-versions index 55e53bf..44acbf0 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 25.2.2 -elixir 1.14.3 +erlang 26.0.2 +elixir 1.15.4 diff --git a/lib/ash_state_machine.ex b/lib/ash_state_machine.ex index ce286ea..0d314be 100644 --- a/lib/ash_state_machine.ex +++ b/lib/ash_state_machine.ex @@ -6,16 +6,18 @@ defmodule AshStateMachine do @type t :: %__MODULE__{ action: atom, from: [atom], - to: [atom] + to: [atom], + __identifier__: any } - defstruct [:action, :from, :to] + defstruct [:action, :from, :to, :__identifier__] end @transition %Spark.Dsl.Entity{ name: :transition, target: Transition, args: [:action], + identifier: {:auto, :unique_integer}, schema: [ action: [ type: :atom, @@ -26,13 +28,13 @@ defmodule AshStateMachine do type: {:or, [{:list, :atom}, :atom]}, required: true, doc: - "The states in which this action may be called. If not specified, then any state is accepted." + "The states in which this action may be called. If not specified, then any state is accepted. Use `:*` to refer to all states." ], to: [ type: {:or, [{:list, :atom}, :atom]}, required: true, doc: - "The states that this action may move to. If not specified, then any state is accepted." + "The states that this action may move to. If not specified, then any state is accepted. Use `:*` to refer to all states." ] ] } diff --git a/lib/transformers/fill_in_event_defaults.ex b/lib/transformers/fill_in_event_defaults.ex index 9e74fc6..c231a85 100644 --- a/lib/transformers/fill_in_event_defaults.ex +++ b/lib/transformers/fill_in_event_defaults.ex @@ -26,6 +26,27 @@ defmodule AshStateMachine.Transformers.FillInTransitionDefaults do List.wrap(initial_states) ) - {:ok, Transformer.persist(dsl_state, :all_state_machine_states, all_states)} + {:ok, + transitions + |> Enum.reduce(dsl_state, fn transition, dsl_state -> + Transformer.replace_entity(dsl_state, [:ash_state_machine, :transitions], %{ + transition + | from: replace_star(transition.from, all_states), + to: replace_star(transition.to, all_states) + }) + end) + |> Transformer.persist(:all_state_machine_states, all_states)} + end + + defp replace_star(states, all_states) do + states + |> List.wrap() + |> Enum.flat_map(fn + :* -> + all_states + + other -> + List.wrap(other) + end) end end diff --git a/mix.exs b/mix.exs index 136ed25..0c62cc9 100644 --- a/mix.exs +++ b/mix.exs @@ -136,7 +136,7 @@ defmodule AshStateMachine.MixProject do defp deps do [ {:ash, "~> 2.7"}, - {:spark, ">= 1.1.0"}, + {:spark, ">= 1.1.22"}, {:ex_doc, "~> 0.22", only: [:dev, :test], runtime: false}, {:ex_check, "~> 0.12.0", only: [:dev, :test]}, {:credo, ">= 0.0.0", only: [:dev, :test], runtime: false}, diff --git a/mix.lock b/mix.lock index b3025eb..0868cab 100644 --- a/mix.lock +++ b/mix.lock @@ -30,8 +30,8 @@ "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, "picosat_elixir": {:hex, :picosat_elixir, "0.2.3", "bf326d0f179fbb3b706bb2c15fbc367dacfa2517157d090fdfc32edae004c597", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f76c9db2dec9d2561ffaa9be35f65403d53e984e8cd99c832383b7ab78c16c66"}, "sobelow": {:hex, :sobelow, "0.12.2", "45f4d500e09f95fdb5a7b94c2838d6b26625828751d9f1127174055a78542cf5", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "2f0b617dce551db651145662b84c8da4f158e7abe049a76daaaae2282df01c5d"}, - "sourceror": {:hex, :sourceror, "0.12.2", "2ae55efd149193572e0eb723df7c7a1bda9ab33c43373c82642931dbb2f4e428", [:mix], [], "hexpm", "7ad74ade6fb079c71f29fae10c34bcf2323542d8c51ee1bcd77a546cfa89d59c"}, - "spark": {:hex, :spark, "1.1.0", "7fcd19a08998f1287ddd7a5de14543f9edb99b1d34eab81b37dfca79efa4f3a2", [:mix], [{:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "ecf8eaa6d934a4993b80a3744c0a5acb2c1c1333ba90c5ab306aa25795af332f"}, + "sourceror": {:hex, :sourceror, "0.12.3", "a2ad3a1a4554b486d8a113ae7adad5646f938cad99bf8bfcef26dc0c88e8fade", [:mix], [], "hexpm", "4d4e78010ca046524e8194ffc4683422f34a96f6b82901abbb45acc79ace0316"}, + "spark": {:hex, :spark, "1.1.22", "68ba00f9acb4c8bc2c93ef82249493687ddf0f0a4f7e79c3c0e22b06719add56", [:mix], [{:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "b798b95990eed8f2409df47b818b5dbcd00e9b5c30d0355465d0b04bbf9b5c4c"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},