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

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

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

generate_action_metadata_type(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

  • 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).