AshTypescript.Codegen.Helpers (ash_typescript v0.17.3)

Copy Markdown View Source

Shared helper functions for code generation.

Summary

Functions

Builds a TypeScript type name from a resource module. Uses the custom typescript_type_name if defined, otherwise derives from module name.

Converts a PascalCase name to camelCase by lowercasing the first character.

Returns formatted client field names for a resource's public fields.

Determines if a return type is complex (requires special metadata handling).

Determines if a calculation is simple (no arguments, no complex return type). Simple calculations are treated like regular fields in the schema.

Looks up the type of an aggregate field by traversing relationship paths.

Functions

build_resource_type_name(resource_module)

Builds a TypeScript type name from a resource module. Uses the custom typescript_type_name if defined, otherwise derives from module name.

camel_case_prefix(arg)

Converts a PascalCase name to camelCase by lowercasing the first character.

Examples

iex> AshTypescript.Codegen.Helpers.camel_case_prefix("Todo")
"todo"

iex> AshTypescript.Codegen.Helpers.camel_case_prefix("OrgTodo")
"orgTodo"

client_field_names(resource, opts \\ [])

Returns formatted client field names for a resource's public fields.

Collects public attributes, calculations (with field?: true), and aggregates. Optionally includes relationships when include_relationships: true.

Field names are formatted using the configured output formatter.

is_complex_return_type(arg1, constraints)

Determines if a return type is complex (requires special metadata handling).

is_simple_calculation(calc)

Determines if a calculation is simple (no arguments, no complex return type). Simple calculations are treated like regular fields in the schema.

lookup_aggregate_type(current_resource, relationship_path, field)

Looks up the type of an aggregate field by traversing relationship paths.