MishkaGervaz.Table.Transformers.Helpers (MishkaGervaz v0.0.1-alpha.3)

Copy Markdown View Source

Shared helper functions for MishkaGervaz transformers.

These functions are used across both table and form transformers to reduce duplication and provide consistent DSL state manipulation.

Imported by MishkaGervaz.Table.Transformers.{MergeDefaults, ResolveColumns, BuildDomainConfig, BuildRuntimeConfig} and MishkaGervaz.Form.Transformers.{MergeDefaults, ResolveFields, BuildDomainConfig, BuildRuntimeConfig}.

See MishkaGervaz.Form.Web.State.Helpers and MishkaGervaz.Form.Web.DataLoader.Helpers for the runtime-side equivalent helpers.

Summary

Functions

Checks if any value in the list is not nil.

Returns the default if value is nil, otherwise returns the value.

Extracts a nested entity from a list or single value. Spark stores nested entities as lists.

Filters entities by struct type.

Finds a single entity of the given type at the specified path.

Gets the full domain config for a resource module.

Gets entities from the DSL state at the given path, always returning a list.

Gets an option from the DSL state at the given path.

Checks if a module has a specific Spark extension.

Safely gets the domain module for a resource.

Safely gets the MishkaGervaz domain config from a domain module.

Sets an option in the DSL state at the given path.

Functions

any_set?(values)

@spec any_set?([term()]) :: boolean()

Checks if any value in the list is not nil.

default_if_nil(value, default)

@spec default_if_nil(term(), term()) :: term()

Returns the default if value is nil, otherwise returns the value.

extract_nested_entity(entity, type)

@spec extract_nested_entity(list() | struct() | nil, module()) :: struct() | nil

Extracts a nested entity from a list or single value. Spark stores nested entities as lists.

filter_by_type(entities, type)

@spec filter_by_type([struct()], module()) :: [struct()]

Filters entities by struct type.

find_entity(dsl_state, path, type)

@spec find_entity(Spark.Dsl.t(), [atom()], module()) :: struct() | nil

Finds a single entity of the given type at the specified path.

get_domain_config(module)

@spec get_domain_config(module()) :: map() | nil

Gets the full domain config for a resource module.

get_entities(dsl_state, path)

@spec get_entities(Spark.Dsl.t(), [atom()]) :: [struct()]

Gets entities from the DSL state at the given path, always returning a list.

get_opt(dsl_state, path, key, default \\ nil)

@spec get_opt(Spark.Dsl.t(), [atom()], atom(), term()) :: term()

Gets an option from the DSL state at the given path.

has_extension?(module, extension)

@spec has_extension?(module(), module()) :: boolean()

Checks if a module has a specific Spark extension.

safe_domain(module)

@spec safe_domain(module()) :: {:ok, module()} | :error

Safely gets the domain module for a resource.

safe_domain_config(domain)

@spec safe_domain_config(module()) :: map() | nil

Safely gets the MishkaGervaz domain config from a domain module.

set_opt(dsl_state, path, key, value)

@spec set_opt(Spark.Dsl.t(), [atom()], atom(), term()) :: Spark.Dsl.t()

Sets an option in the DSL state at the given path.