Arc.Types (cratis_arc v0.1.0)

Copy Markdown View Source

The field types Arc understands, and conversion between wire values and Elixir values.

A type is one of :string, :integer, :float, :boolean, :uuid, :date, :datetime, :map, {:list, type}, a Chronicle.Concept module (a strongly typed wrapper over one primitive), or a module that use Arc.Schema (a nested type).

Summary

Functions

Converts a wire value to the Elixir value of type.

Whether module is a Chronicle.Concept.

Resolves a concept to the primitive it wraps (:string, :integer, :float, :boolean or :uuid).

A human-readable name for a type, used in validation messages.

Whether type is one of the built-in primitive types.

Whether module is an Arc schema (declares fields with schema do ... end).

Types

t()

@type t() :: atom() | {:list, t()}

Functions

cast(module, v)

@spec cast(t(), term()) :: {:ok, term()} | :error

Converts a wire value to the Elixir value of type.

Strings are accepted for numbers and booleans so the same function converts query-string arguments. Returns {:ok, value} or :error.

concept?(module)

@spec concept?(term()) :: boolean()

Whether module is a Chronicle.Concept.

concept_primitive(module)

@spec concept_primitive(module()) :: atom()

Resolves a concept to the primitive it wraps (:string, :integer, :float, :boolean or :uuid).

describe(type)

@spec describe(t()) :: String.t()

A human-readable name for a type, used in validation messages.

primitive?(type)

@spec primitive?(term()) :: boolean()

Whether type is one of the built-in primitive types.

schema?(module)

@spec schema?(term()) :: boolean()

Whether module is an Arc schema (declares fields with schema do ... end).