Spark DSL extension for defining typed controller routes.
This extension generates TypeScript path helper functions and a thin Phoenix
controller from routes configured in the DSL. Unlike AshTypescript.ControllerResource,
this is a standalone Spark DSL — not attached to Ash.Resource.
Routes contain colocated arguments and handler functions (inline closures or
handler modules implementing AshTypescript.TypedController.Route).
Usage
Three syntaxes are supported for defining routes:
defmodule MyApp.Session do
use AshTypescript.TypedController
typed_controller do
module_name MyAppWeb.SessionController
# Verb shortcut (preferred)
post :login do
run fn conn, params -> Plug.Conn.send_resp(conn, 200, "OK") end
argument :code, :string, allow_nil?: false
argument :remember_me, :boolean
end
# Positional method arg
route :auth, :get do
run fn conn, _params -> Plug.Conn.send_resp(conn, 200, "Auth") end
end
# Method defaults to :get when omitted
route :home do
run fn conn, _params -> Plug.Conn.send_resp(conn, 200, "Home") end
end
end
end