AshTypescript.TypedController.Codegen (ash_typescript v0.18.2)

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.

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

Groups route infos by resolved namespace.

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.

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_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.