AshTypescript.Rpc.Codegen.TypeGenerators.MetadataTypes (ash_typescript v0.18.2)

Copy Markdown View Source

Generates TypeScript metadata types for RPC actions.

Metadata types define the shape of metadata that can be returned from RPC actions. Actions can expose specific metadata fields via the show_metadata option.

Summary

Functions

Reads the precomputed exposed metadata fields off the decorated entrypoint for a {resource, rpc_action} pair, falling back to [] when no entrypoint matches.

Generates the TypeScript metadata type for an RPC action.

Gets the list of metadata fields that should be exposed for an RPC action.

Checks if metadata is enabled for an action based on exposed fields.

Functions

exposed_metadata_fields(resource, rpc_action)

Reads the precomputed exposed metadata fields off the decorated entrypoint for a {resource, rpc_action} pair, falling back to [] when no entrypoint matches.

generate_action_metadata_type(resource, action, rpc_action, rpc_action_name_pascal)

Generates the TypeScript metadata type for an RPC action.

Returns an empty string if no metadata fields are exposed.

Parameters

  • resource - The Ash resource module
  • action - The Ash action
  • rpc_action - The RPC action configuration
  • rpc_action_name_pascal - The PascalCase name of the RPC action

Returns

A string containing the TypeScript metadata type definition, or an empty string if no metadata is exposed.

get_exposed_metadata_fields(rpc_action, ash_action)

Gets the list of metadata fields that should be exposed for an RPC action.

Parameters

  • rpc_action - The RPC action configuration
  • ash_action - The underlying Ash action

Returns

A list of metadata field names (atoms) that should be exposed.

Examples

# No metadata override - expose all metadata fields
iex> get_exposed_metadata_fields(%{}, %{metadata: [%{name: :total_count}]})
[:total_count]

# Empty list - expose no metadata fields
iex> get_exposed_metadata_fields(%{show_metadata: []}, %{metadata: [%{name: :total_count}]})
[]

# Specific fields - expose only listed fields
iex> get_exposed_metadata_fields(%{show_metadata: [:total_count]}, %{metadata: [...]})
[:total_count]

metadata_enabled?(exposed_fields)

Checks if metadata is enabled for an action based on exposed fields.

Parameters

  • exposed_fields - List of metadata fields that are exposed

Returns

Boolean indicating if metadata is enabled (has at least one exposed field).