Choreo.Lab.DSL.Sequence (Choreo v0.12.0)

Copy Markdown View Source

Experimental Livebook-friendly DSL for sketching sequence diagrams.

Unlike most Choreo Lab DSLs, sequence diagrams are primarily ordered event streams rather than static topology. This DSL still uses participant constructors for nouns, but message, activation, note, and fragment statements compile to ordered Choreo.Sequence events.

Examples

iex> import Choreo.Lab.DSL.Sequence
...> diagram = sequence do
...>   user = actor("User")
...>   api = participant("API")
...>   db = participant("Database")
...>
...>   user ~> api |> call("GET /accounts")
...>   activate api
...>   api ~> db |> call("SELECT accounts")
...>   reply db ~> api, "rows"
...>   deactivate api
...>   reply api ~> user, "200 OK"
...> end
iex> Choreo.Sequence.participants(diagram)
[:user, :api, :db]
iex> Choreo.Sequence.messages(diagram) |> Enum.map(& &1[:label])
["GET /accounts", "SELECT accounts", "rows", "200 OK"]

Message edges can use pipe modifiers, typed constructors, or generic edge:

user ~> api |> call("GET /accounts")
async api ~> worker, "enqueue job"
reply db ~> api, "rows"
edge api ~> db, async: "fire and forget"

Notes and fragments are event statements:

over api, "Validates bearer token"
between api, db, "Tenant scoped query"

loop "retry up to 3 times" do
  api ~> worker |> async("process job")
end

alt "authorized" do
  api ~> db |> call("read tenant")
  otherwise "denied"
  api ~> user |> reply("403")
end

Summary

Functions

Builds a %Choreo.Sequence{} from a compact Lab DSL block.

Returns the vocabulary supported by the sequence DSL.

Compatibility alias for taxonomy/0.

Types

participant_decl()

@type participant_decl() :: %{id: atom(), builder: atom(), opts: keyword()}

step()

@type step() ::
  {:participant, participant_decl()}
  | {:message, map()}
  | {:activation, atom(), atom()}
  | {:note, tuple(), String.t()}
  | {:fragment, atom(), String.t() | nil}
  | :end_fragment

Functions

activate(arg1 \\ nil, arg2 \\ nil, opts \\ [])

actor(arg1 \\ nil, arg2 \\ nil, opts \\ [])

alt(arg1 \\ nil, arg2 \\ nil, opts \\ [])

async(arg1 \\ nil, arg2 \\ nil, opts \\ [])

between(arg1 \\ nil, arg2 \\ nil, opts \\ [])

break(arg1 \\ nil, arg2 \\ nil, opts \\ [])

call(arg1 \\ nil, arg2 \\ nil, opts \\ [])

critical(arg1 \\ nil, arg2 \\ nil, opts \\ [])

deactivate(arg1 \\ nil, arg2 \\ nil, opts \\ [])

else(arg1 \\ nil, arg2 \\ nil, opts \\ [])

left(arg1 \\ nil, arg2 \\ nil, opts \\ [])

loop(arg1 \\ nil, arg2 \\ nil, opts \\ [])

message(arg1 \\ nil, arg2 \\ nil, opts \\ [])

note(arg1 \\ nil, arg2 \\ nil, opts \\ [])

opt(arg1 \\ nil, arg2 \\ nil, opts \\ [])

otherwise(arg1 \\ nil, arg2 \\ nil, opts \\ [])

over(arg1 \\ nil, arg2 \\ nil, opts \\ [])

par(arg1 \\ nil, arg2 \\ nil, opts \\ [])

participant(arg1 \\ nil, arg2 \\ nil, opts \\ [])

publish(arg1 \\ nil, arg2 \\ nil, opts \\ [])

reply(arg1 \\ nil, arg2 \\ nil, opts \\ [])

request(arg1 \\ nil, arg2 \\ nil, opts \\ [])

response(arg1 \\ nil, arg2 \\ nil, opts \\ [])

return(arg1 \\ nil, arg2 \\ nil, opts \\ [])

right(arg1 \\ nil, arg2 \\ nil, opts \\ [])

sequence(list)

(macro)

Builds a %Choreo.Sequence{} from a compact Lab DSL block.

sequence(opts, list)

(macro)

service(arg1 \\ nil, arg2 \\ nil, opts \\ [])

signal(arg1 \\ nil, arg2 \\ nil, opts \\ [])

sync(arg1 \\ nil, arg2 \\ nil, opts \\ [])

system(arg1 \\ nil, arg2 \\ nil, opts \\ [])

taxonomy()

@spec taxonomy() :: %{
  participants: [atom()],
  messages: [atom()],
  events: [atom()],
  notes: [atom()],
  fragments: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Returns the vocabulary supported by the sequence DSL.

This is meant as a lightweight Livebook discovery helper when autocomplete is not enough.

iex> taxonomy = Choreo.Lab.DSL.Sequence.taxonomy()
iex> :actor in taxonomy.participants
true
iex> :reply in taxonomy.messages
true
iex> :loop in taxonomy.fragments
true

user(arg1 \\ nil, arg2 \\ nil, opts \\ [])

verbs()

@spec verbs() :: map()

Compatibility alias for taxonomy/0.