Jidoka.Schema (Jidoka v0.8.0-beta.1)

Copy Markdown View Source

Small Zoi helpers for Jidoka's data-first structs.

This module is intentionally narrow. It keeps repeated constructor mechanics in one place while each domain module owns its actual Zoi schema.

Summary

Functions

Returns a schema that accepts atoms or matching atom-name strings.

Fetches a map value by atom key, falling back to the equivalent string key.

Gets a map value by atom or string key with a default.

Returns a coercing non-empty string schema.

Normalizes structs and keyword lists into map-like attributes for schema parsing.

Parses keyword or map attributes through a Zoi schema.

Parses attributes through a Zoi schema or raises with a labeled error.

Puts a default value when neither atom nor string key is already present.

Types

parse_result(t)

@type parse_result(t) :: {:ok, t} | {:error, term()}

Functions

atom_enum(values)

@spec atom_enum([atom()]) :: Zoi.schema()

Returns a schema that accepts atoms or matching atom-name strings.

fetch_key(map, key)

@spec fetch_key(map(), atom()) :: {:ok, term()} | :error

Fetches a map value by atom key, falling back to the equivalent string key.

get_key(map, key, default \\ nil)

@spec get_key(map(), atom(), term()) :: term()

Gets a map value by atom or string key with a default.

non_empty_string()

@spec non_empty_string() :: Zoi.schema()

Returns a coercing non-empty string schema.

normalize_attrs(attrs)

@spec normalize_attrs(term()) :: term()

Normalizes structs and keyword lists into map-like attributes for schema parsing.

parse(schema, attrs)

@spec parse(Zoi.schema(), keyword() | map()) :: parse_result(struct())

Parses keyword or map attributes through a Zoi schema.

parse!(schema, attrs, label)

@spec parse!(Zoi.schema(), keyword() | map(), String.t()) :: struct()

Parses attributes through a Zoi schema or raises with a labeled error.

put_default(attrs, key, value)

@spec put_default(map(), atom(), term()) :: map()

Puts a default value when neither atom nor string key is already present.