AshTypescript.Resource.Info (ash_typescript v0.17.3)

Copy Markdown View Source

Provides introspection functions for AshTypescript.Resource configuration.

This module generates helper functions to access TypeScript configuration defined on resources using the AshTypescript.Resource DSL extension.

Summary

Functions

Gets the pre-computed formatted client name for a field under a built-in formatter.

Gets the mapped name for an argument, or returns the original name if no mapping exists.

Gets the mapped TypeScript client name for a field, or returns nil if no mapping exists.

Gets the original invalid argument name for a mapped argument name. Returns the argument name that was mapped to the given valid name, or the same name if no mapping exists.

Gets the original Elixir field name for a TypeScript client field name.

A keyword list mapping Elixir argument names to TypeScript client names per action. Use strings for the client names - no additional formatting is applied. (e.g., [read_action: [is_active?: "isActive"]])

A keyword list mapping Elixir argument names to TypeScript client names per action. Use strings for the client names - no additional formatting is applied. (e.g., [read_action: [is_active?: "isActive"]])

A keyword list mapping Elixir field names to TypeScript client names. Use strings for the client names - no additional formatting is applied. (e.g., [is_active?: "isActive", address_line_1: "addressLine1"])

A keyword list mapping Elixir field names to TypeScript client names. Use strings for the client names - no additional formatting is applied. (e.g., [is_active?: "isActive", address_line_1: "addressLine1"])

typescript DSL options

Whether or not a given module is a resource module using the AshTypescript.Resource extension

The name of the TypeScript type for the resource

The name of the TypeScript type for the resource

Functions

get_formatted_field(resource, field, formatter)

Gets the pre-computed formatted client name for a field under a built-in formatter.

Backed by Spark.Dsl.Transformer.persist/3 populated at compile time by AshTypescript.Resource.Transformers.PersistFormattedFields. Returns the formatted string, or nil if the resource is not an AshTypescript.Resource, the field is not a public attribute/relationship/calculation/aggregate, or the formatter is not one of the built-in atoms (:camel_case, :snake_case, :pascal_case).

Examples

iex> AshTypescript.Resource.Info.get_formatted_field(MyApp.User, :first_name, :camel_case)
"firstName"

iex> AshTypescript.Resource.Info.get_formatted_field(MyApp.User, :is_active?, :camel_case)
"isActive"

get_mapped_argument_name(resource, action_name, argument_name)

Gets the mapped name for an argument, or returns the original name if no mapping exists.

Examples

iex> AshTypescript.Resource.Info.get_mapped_argument_name(MyApp.User, :read_with_invalid_arg, :is_active?)
:is_active

get_mapped_field_name(resource, field_name)

Gets the mapped TypeScript client name for a field, or returns nil if no mapping exists.

The mapped value is always a string representing the exact TypeScript client name.

Examples

iex> AshTypescript.Resource.Info.get_mapped_field_name(MyApp.User, :is_active?)
"isActive"

iex> AshTypescript.Resource.Info.get_mapped_field_name(MyApp.User, :normal_field)
nil

get_original_argument_name(resource, action_name, mapped_argument_name)

Gets the original invalid argument name for a mapped argument name. Returns the argument name that was mapped to the given valid name, or the same name if no mapping exists.

Examples

iex> AshTypescript.Resource.Info.get_original_argument_name(MyApp.User, :read_with_invalid_arg, :is_active)
:is_active?

get_original_field_name(resource, client_field_name)

Gets the original Elixir field name for a TypeScript client field name.

The client_field_name should be a string like "isActive". Returns the original Elixir atom like :is_active?, or the input if no mapping exists.

Examples

iex> AshTypescript.Resource.Info.get_original_field_name(MyApp.User, "isActive")
:is_active?

iex> AshTypescript.Resource.Info.get_original_field_name(MyApp.User, "normalField")
"normalField"

typescript_argument_names(dsl_or_extended)

@spec typescript_argument_names(dsl_or_extended :: module() | map()) ::
  {:ok, keyword()} | :error

A keyword list mapping Elixir argument names to TypeScript client names per action. Use strings for the client names - no additional formatting is applied. (e.g., [read_action: [is_active?: "isActive"]])

typescript_argument_names!(dsl_or_extended)

@spec typescript_argument_names!(dsl_or_extended :: module() | map()) ::
  keyword() | no_return()

A keyword list mapping Elixir argument names to TypeScript client names per action. Use strings for the client names - no additional formatting is applied. (e.g., [read_action: [is_active?: "isActive"]])

typescript_field_names(dsl_or_extended)

@spec typescript_field_names(dsl_or_extended :: module() | map()) ::
  {:ok, keyword()} | :error

A keyword list mapping Elixir field names to TypeScript client names. Use strings for the client names - no additional formatting is applied. (e.g., [is_active?: "isActive", address_line_1: "addressLine1"])

typescript_field_names!(dsl_or_extended)

@spec typescript_field_names!(dsl_or_extended :: module() | map()) ::
  keyword() | no_return()

A keyword list mapping Elixir field names to TypeScript client names. Use strings for the client names - no additional formatting is applied. (e.g., [is_active?: "isActive", address_line_1: "addressLine1"])

typescript_options(dsl_or_extended)

@spec typescript_options(dsl_or_extended :: module() | map()) :: %{
  required(atom()) => any()
}

typescript DSL options

Returns a map containing the and any configured or default values.

typescript_resource?(module)

@spec typescript_resource?(module()) :: boolean()

Whether or not a given module is a resource module using the AshTypescript.Resource extension

typescript_type_name(dsl_or_extended)

@spec typescript_type_name(dsl_or_extended :: module() | map()) ::
  {:ok, String.t()} | :error

The name of the TypeScript type for the resource

typescript_type_name!(dsl_or_extended)

@spec typescript_type_name!(dsl_or_extended :: module() | map()) ::
  String.t() | no_return()

The name of the TypeScript type for the resource