AshTypescript.Codegen.TypeMapper (ash_typescript v0.17.2)

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 resource type for non-Ash resources.

Builds an input type for unions (discriminated union syntax).

Builds a union type with metadata for field selection.

Generates a TypeScript union of primitive field names.

Gets the TypeScript field specification for a resource field.

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.

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_resource_type(resource, select_and_loads \\ nil)

Builds a resource type for non-Ash resources.

build_union_input_type(types)

Builds an input type for unions (discriminated union syntax).

build_union_type(types)

Builds a union type with metadata for field selection.

generate_primitive_fields_union(fields)

Generates a TypeScript union of primitive field names.

get_resource_field_spec(field, resource)

Gets the TypeScript field specification for a resource field.

get_ts_input_type(map)

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, constraints)

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(), 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.