Packages
ash_typescript
0.15.3
0.17.3
0.17.2
0.17.1
0.17.0
0.16.0
0.15.3
0.15.2
retired
0.15.1
retired
0.15.0
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
retired
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.9.1
0.9.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.0
0.3.3
0.3.2
0.3.1
0.2.0
0.1.2
0.1.0
Generate type-safe TypeScript clients directly from your Ash resources and actions, ensuring end-to-end type safety between your backend and frontend.
Current section
Files
Jump to
Current section
Files
documentation/dsls/DSL-AshTypescript.TypedController.md
<!--
This file was generated by Spark. Do not edit it by hand.
-->
# AshTypescript.TypedController
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
defmodule MyApp.Session do
use AshTypescript.TypedController
typed_controller do
module_name MyAppWeb.SessionController
route :login do
method :post
run fn conn, params -> Plug.Conn.send_resp(conn, 200, "OK") end
argument :code, :string, allow_nil?: false
argument :remember_me, :boolean
end
route :auth do
method :get
run fn conn, _params -> Plug.Conn.send_resp(conn, 200, "Auth") end
end
end
end
## typed_controller
Define typed controller routes
### Nested DSLs
* [route](#typed_controller-route)
* argument
### Options
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`module_name`](#typed_controller-module_name){: #typed_controller-module_name .spark-required} | `atom` | | The module name for the generated Phoenix controller (e.g. MyAppWeb.SessionController) |
### typed_controller.route
```elixir
route name
```
Define a route that maps a controller action to a handler.
The handler can be an inline function (fn/2) or a module implementing
the `AshTypescript.TypedController.Route` behaviour. Handlers receive
`(conn, params)` and must return a `%Plug.Conn{}`.
### Nested DSLs
* [argument](#typed_controller-route-argument)
### Arguments
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`name`](#typed_controller-route-name){: #typed_controller-route-name .spark-required} | `atom` | | The controller action name (e.g. :login, :auth) |
### Options
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`method`](#typed_controller-route-method){: #typed_controller-route-method .spark-required} | `:get \| :post \| :patch \| :put \| :delete` | | The HTTP method. Required for all routes. |
| [`run`](#typed_controller-route-run){: #typed_controller-route-run .spark-required} | `(any, any -> any) \| atom` | | The handler — an fn/2 closure or a module implementing AshTypescript.TypedController.Route |
| [`description`](#typed_controller-route-description){: #typed_controller-route-description } | `String.t` | | JSDoc description for the generated TypeScript path helper |
| [`deprecated`](#typed_controller-route-deprecated){: #typed_controller-route-deprecated } | `boolean \| String.t` | | Mark this route as deprecated. Set to true for a default message, or provide a custom deprecation notice. |
### typed_controller.route.argument
```elixir
argument name, type
```
Define an argument for this route.
### Arguments
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`name`](#typed_controller-route-argument-name){: #typed_controller-route-argument-name .spark-required} | `atom` | | The argument name |
| [`type`](#typed_controller-route-argument-type){: #typed_controller-route-argument-type .spark-required} | `atom \| {atom, keyword}` | | The Ash type (e.g. :string, :boolean, :integer) |
### Options
| Name | Type | Default | Docs |
|------|------|---------|------|
| [`constraints`](#typed_controller-route-argument-constraints){: #typed_controller-route-argument-constraints } | `keyword` | `[]` | Type constraints |
| [`allow_nil?`](#typed_controller-route-argument-allow_nil?){: #typed_controller-route-argument-allow_nil? } | `boolean` | `true` | Whether this argument can be nil. Set to false to make it required. |
| [`default`](#typed_controller-route-argument-default){: #typed_controller-route-argument-default } | `any` | | Default value for this argument |
### Introspection
Target: `AshTypescript.TypedController.Dsl.RouteArgument`
### Introspection
Target: `AshTypescript.TypedController.Dsl.Route`
<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>