AshTypescript.Codegen.SchemaCore (ash_typescript v0.17.2)

Copy Markdown View Source

Shared logic for schema generation across all validation library targets.

All resource introspection, topological sorting, field resolution, and structural code generation lives here. Output syntax is delegated to a module implementing AshTypescript.Codegen.SchemaFormatter.

Consumers (e.g. ZodSchemaGenerator) pass __MODULE__ as the first formatter argument to each public function.

Summary

Functions

Builds a JS regex flag string from Elixir Regex opts.

Generates a schema definition for an RPC action's input. Returns an empty string when the action has no input.

Generates a schema for a single resource.

Generates schemas for a list of resources (embedded resources, struct args). Returns an empty string when generation is disabled or the list is empty.

Maps Ash type structs (attribute/argument maps) to a schema string. Handles allow_nil? for string types (non-nullable strings get min-length 1).

Wraps a schema string with wrap_nullable (innermost) and/or wrap_optional (outermost) based on the two booleans, using the given formatter.

Returns true when a regex source string is safe to emit as a JS literal.

Functions

build_js_flags(opts)

Builds a JS regex flag string from Elixir Regex opts.

generate_action_schema(formatter, resource, action, rpc_action_name)

Generates a schema definition for an RPC action's input. Returns an empty string when the action has no input.

generate_schema_for_resource(formatter, resource)

Generates a schema for a single resource.

generate_schemas_for_resources(formatter, resources)

Generates schemas for a list of resources (embedded resources, struct args). Returns an empty string when generation is disabled or the list is empty.

get_type(formatter, type_and_constraints, context \\ nil)

Maps Ash type structs (attribute/argument maps) to a schema string. Handles allow_nil? for string types (non-nullable strings get min-length 1).

maybe_wrap_nullable_optional(formatter, schema, nullable?, omittable?)

Wraps a schema string with wrap_nullable (innermost) and/or wrap_optional (outermost) based on the two booleans, using the given formatter.

regex_safe_for_js?(source)

Returns true when a regex source string is safe to emit as a JS literal.