AshTypescript.Codegen.ResourceSchemas (ash_typescript v0.17.3)

Copy Markdown View Source

Generates TypeScript schemas for Ash resources.

Uses a unified field classification pattern for determining how to generate TypeScript definitions. The classify_field/1 function categorizes fields into types like :primitive, :relationship, :embedded, :union, etc.

Summary

Types

Field categories for schema generation.

Functions

Classifies a field by its type, handling NewType unwrapping and array wrappers.

Classifies an Ash field into a category for schema generation.

Generates all schemas for a single resource. Includes the unified resource schema and optionally an input schema for resources that need it (embedded resources or struct argument resources).

Generates an attributes-only schema for a resource.

Generates an input schema for embedded resources.

Generates a unified resource schema with metadata fields and direct field access. This replaces the multiple separate schemas with a single, metadata-driven schema.

Types

field_category()

@type field_category() ::
  :primitive
  | :relationship
  | :embedded
  | :union
  | :typed_map
  | :typed_struct
  | :calculation

Field categories for schema generation.

  • :primitive - Simple types mapped directly to TypeScript
  • :relationship - Ash relationships (has_many, belongs_to, etc.)
  • :embedded - Embedded resources
  • :union - Ash.Type.Union types
  • :typed_map - Map/Keyword/Tuple with field constraints
  • :typed_struct - Struct with fields and instance_of constraints
  • :calculation - Complex calculations with arguments

Functions

classify_by_type(field)

@spec classify_by_type(map()) :: field_category()

Classifies a field by its type, handling NewType unwrapping and array wrappers.

classify_field(field)

@spec classify_field(map()) :: field_category()

Classifies an Ash field into a category for schema generation.

Handles relationships, calculations, and attribute types. Returns the field category which determines how to generate its TypeScript definition.

generate_all_schemas_for_resource(resource, allowed_resources, input_schema_resources \\ [])

Generates all schemas for a single resource. Includes the unified resource schema and optionally an input schema for resources that need it (embedded resources or struct argument resources).

generate_all_schemas_for_resources(resources, allowed_resources, resources_needing_input_schema \\ [])

Generates all schemas (unified + input) for a list of resources.

Parameters

  • resources - List of resources to generate schemas for
  • allowed_resources - List of resources allowed for schema generation (used for filtering)
  • resources_needing_input_schema - Optional list of resources that need InputSchema generated (defaults to embedded resources)

generate_attributes_only_schema(resource, allowed_resources)

Generates an attributes-only schema for a resource.

This schema only includes attributes (no calculations, relationships, or aggregates). It's used for first aggregates where nested field selection is possible but limited to fields that don't require loading.

For embedded resource attributes, recursively references their AttributesOnlySchema.

generate_input_schema(resource)

Generates an input schema for embedded resources.

generate_unified_resource_schema(resource, allowed_resources)

Generates a unified resource schema with metadata fields and direct field access. This replaces the multiple separate schemas with a single, metadata-driven schema.