AshTypescript.Rpc.ValidationErrorSchemas (ash_typescript v0.18.1)

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 explicit validation error types for input schemas with pre-computed resource_lookup.

Generates validation error schemas for embedded resources.

Generates validation error schemas for embedded resources with pre-computed resource_lookup.

Generates validation error type for an RPC action.

Generates validation error type for an RPC action with pre-computed resource_lookup.

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_input_validation_errors_schema(resource, resource_lookup)

Generates explicit validation error types for input schemas with pre-computed resource_lookup.

generate_validation_error_schemas_for_embedded_resources(embedded_resources)

Generates validation error schemas for embedded resources.

generate_validation_error_schemas_for_embedded_resources(embedded_resources, resource_lookup)

Generates validation error schemas for embedded resources with pre-computed resource_lookup.

generate_validation_error_type(resource, action, rpc_action_name)

Generates validation error type for an RPC action.

generate_validation_error_type(resource, action, rpc_action_name, resource_lookup)

Generates validation error type for an RPC action with pre-computed resource_lookup.

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() | Ash.Info.Manifest.Type.t(),
  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")