AshTypescript.Rpc.ValidationErrorSchemas (ash_typescript v0.17.2)

Copy Markdown View Source

Generates validation error schemas for TypeScript RPC clients.

This module uses a unified type-driven dispatch pattern for mapping Ash types to their corresponding validation error types. The core dispatcher map_error_type/2 handles NewType unwrapping at entry and delegates to type-specific handlers.

Summary

Functions

Builds a union error type from a list of union type definitions. Creates an object with optional error fields for each union variant.

Generates explicit validation error types for input schemas.

Generates validation error schemas for embedded resources.

Generates validation error schemas for types with field constraints.

Generates validation error type for an RPC action.

Maps Ash types to their corresponding validation error types. Backward compatible wrapper around map_error_type/2.

Maps an Ash type to its corresponding validation error type.

Functions

build_union_error_type(union_types)

Builds a union error type from a list of union type definitions. Creates an object with optional error fields for each union variant.

Example: Input union: { text: TextInput } | { note: string } Error type: { text?: TextValidationErrors; note?: string[]; }

generate_input_validation_errors_schema(resource)

Generates explicit validation error types for input schemas.

generate_validation_error_schemas_for_embedded_resources(embedded_resources)

Generates validation error schemas for embedded resources.

generate_validation_error_schemas_for_typed_structs(type_infos)

Generates validation error schemas for types with field constraints.

Accepts either:

  • A list of type info maps (new format): %{instance_of:, constraints:, field_name_mappings:}
  • A list of modules (legacy format): for backward compatibility

Returns TypeScript validation error schema definitions.

generate_validation_error_type(resource, action, rpc_action_name)

Generates validation error type for an RPC action.

get_ts_error_type(map)

Maps Ash types to their corresponding validation error types. Backward compatible wrapper around map_error_type/2.

map_error_type(type, constraints \\ [])

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

Maps an Ash type to its corresponding validation error type.

This is the unified dispatcher that handles all type-to-error-type mappings. NewTypes are unwrapped at entry for consistent handling.

Parameters

  • type - The Ash type (atom, tuple, or module)
  • constraints - Type constraints (keyword list)

Returns

A TypeScript error type string (e.g., "string[]", "FooValidationErrors")