AshTypescript.Codegen.TypeMapper (ash_typescript v0.18.1)

Copy Markdown View Source

Maps Ash types to TypeScript types using unified type-driven dispatch.

This module provides a unified approach to type mapping with a single core dispatcher (map_type/3) that handles both input and output directions.

Summary

Functions

Builds a TypeScript map type with optional field filtering and name mapping.

Builds a union input type from spec members (discriminated union syntax).

Builds a union output type from spec members (list of %{name, type} maps).

Generates a TypeScript union of primitive field names.

Maps an Ash type to a TypeScript type for input schemas. Backward compatible wrapper around map_type/3.

Maps an Ash type to a TypeScript type for output schemas. Backward compatible wrapper around map_type/3.

Determines if a union member is a "primitive" (no selectable fields).

Maps an Ash type to a TypeScript type for channel event payloads.

Maps an Ash type to a TypeScript type string.

Raises the canonical "unsupported type" error for a type AshTypescript cannot map to TypeScript. Accepts a %Ash.Info.Manifest.Type{} or a bare type module.

Maps a type module the manifest generator could not classify to a TypeScript type, when possible.

Types

direction()

@type direction() :: :input | :output

Functions

build_map_type(fields, select \\ nil, field_name_mappings \\ nil)

Builds a TypeScript map type with optional field filtering and name mapping.

build_union_input_type_from_members(members)

Builds a union input type from spec members (discriminated union syntax).

build_union_type_from_members(members)

Builds a union output type from spec members (list of %{name, type} maps).

generate_primitive_fields_union(fields)

Generates a TypeScript union of primitive field names.

get_ts_input_type(arg1)

Maps an Ash type to a TypeScript type for input schemas. Backward compatible wrapper around map_type/3.

get_ts_type(type_and_constraints, select_and_loads \\ nil)

Maps an Ash type to a TypeScript type for output schemas. Backward compatible wrapper around map_type/3.

is_primitive_union_member?(type_info)

Determines if a union member is a "primitive" (no selectable fields).

map_channel_payload_type(type, constraints)

@spec map_channel_payload_type(
  atom() | tuple(),
  keyword()
) :: String.t()

Maps an Ash type to a TypeScript type for channel event payloads.

Like map_type/3 with :output direction, but typed containers (maps/structs with :fields constraint) generate plain object types without the __type/__primitiveFields metadata that the RPC field-selection system needs.

map_type(type, constraints, direction)

@spec map_type(atom() | tuple() | Ash.Info.Manifest.Type.t(), keyword(), direction()) ::
  String.t()

Maps an Ash type to a TypeScript type string.

Parameters

  • type - The Ash type (atom, tuple, or map with :type/:constraints)
  • constraints - Type constraints
  • direction - :input or :output

Returns

A TypeScript type string.

raise_unsupported_type!(type)

@spec raise_unsupported_type!(Ash.Info.Manifest.Type.t() | atom() | binary()) ::
  no_return()

Raises the canonical "unsupported type" error for a type AshTypescript cannot map to TypeScript. Accepts a %Ash.Info.Manifest.Type{} or a bare type module.

unknown_module_mapping(type_info)

@spec unknown_module_mapping(Ash.Info.Manifest.Type.t()) ::
  {:ok, String.t()} | :unsupported

Maps a type module the manifest generator could not classify to a TypeScript type, when possible.

This is the single accept-list for unclassified (kind: :unknown) type modules, shared by map_type/3, AshTypescript.Codegen.TypeAliases, and the compile-time AshTypescript.Manifest.Verifiers.VerifyMappableTypes verifier: custom types implementing typescript_type_name/0 (or decorated with a type_name in the manifest), type_mapping_overrides config entries, and known third-party types with bespoke aliases.