AshTypescript.TypedController.Codegen (ash_typescript v0.19.0)

Copy Markdown View Source

Entry point for TypeScript path helper code generation.

Orchestrates the generation of TypeScript path helper functions from typed controller routes configured in the DSL.

Summary

Functions

Collects all exports for a list of route infos (for namespace re-export files).

Collects all per-route Valibot schemas from typed controller routes.

Collects all per-route Zod schemas from typed controller routes.

Whether a route gets a generated fetch function (in addition to its path helper).

Generates typed controller TypeScript content for the multi-file architecture.

Groups route infos by resolved namespace.

Returns the route's primary exported function name: its fetch function when it has one (see fetch_function?/1), otherwise its path helper. Used by both manifest generators.

Returns the exported input type name of a mutation route's fetch function.

Returns the exported result type name for a route that declares returns.

Returns the exported Valibot schema name for a route, honoring the route's valibot_schema_name override.

Returns the exported Zod schema name for a route, honoring the route's zod_schema_name override.

Functions

collect_route_exports(route_infos)

Collects all exports for a list of route infos (for namespace re-export files).

Returns a list of {name, kind} tuples where kind is :value, :type, :zod_value, or :valibot_value.

collect_route_valibot_schemas(opts \\ [])

Collects all per-route Valibot schemas from typed controller routes.

Returns a list of Valibot schema strings (one per mutation route that has non-path arguments). These are meant to be passed to SharedSchemaGenerator as :additional_schemas.

collect_route_zod_schemas(opts \\ [])

Collects all per-route Zod schemas from typed controller routes.

Returns a list of Zod schema strings (one per mutation route that has non-path arguments). These are meant to be passed to SharedSchemaGenerator as :additional_schemas.

fetch_function?(route_info)

Whether a route gets a generated fetch function (in addition to its path helper).

Only in :full mode: every mutation route, and GET routes that declare returns — those are JSON endpoints, whereas other GET routes typically render pages and are navigated to rather than fetched.

Single source of truth for the rule — used by RouteRenderer, collect_route_exports/1, and both manifest generators.

generate_controller_content(opts)

Generates typed controller TypeScript content for the multi-file architecture.

This generates the controller routes file with imports from shared types file. No inline types, no Zod schemas — those live in ash_types.ts and ash_zod.ts.

Parameters

  • opts - Options keyword list:
    • :router - Phoenix router module
    • :import_paths - %{types: path} for import resolution (types only, no Zod)

generate_controller_namespace_reexport_content(namespace, route_infos, routes_file_path, zod_file_path, valibot_file_path \\ nil)

Generates a namespace re-export file for the given namespace and route infos.

Used by the Orchestrator to generate namespace files with proper import paths.

get_routes_by_namespace(opts \\ [])

Groups route infos by resolved namespace.

Returns a map of %{namespace => [route_info]} where namespace is a string or nil.

route_function_name(route_info)

Returns the route's primary exported function name: its fetch function when it has one (see fetch_function?/1), otherwise its path helper. Used by both manifest generators.

route_input_type_name(route, scope_prefix)

Returns the exported input type name of a mutation route's fetch function.

Single source of truth for the name — used by RouteRenderer, collect_route_exports/1, and both manifest generators.

route_result_type_name(route, scope_prefix)

Returns the exported result type name for a route that declares returns.

Single source of truth for the name — used by RouteRenderer (the export and the action function's return type), collect_route_exports/1, and both manifest generators.

route_valibot_schema_name(route, scope_prefix)

Returns the exported Valibot schema name for a route, honoring the route's valibot_schema_name override.

Single source of truth for the name — used by RouteRenderer.render_valibot_schema/1 (the export itself), collect_route_exports/1 (namespace re-exports), and JsonManifestGenerator (the advertised name), so they cannot drift.

route_zod_schema_name(route, scope_prefix)

Returns the exported Zod schema name for a route, honoring the route's zod_schema_name override.

Single source of truth for the name — used by RouteRenderer.render_zod_schema/1 (the export itself), collect_route_exports/1 (namespace re-exports), and JsonManifestGenerator (the advertised name), so they cannot drift.