ArchAstro.Codec (archastro v0.2.0)

Copy Markdown

Converts between ArchAstro structs and their JSON wire representations.

Generated resource and channel modules use descriptor values to validate and decode nested API payloads. Most applications use those generated modules rather than calling this low-level codec directly.

Summary

Types

descriptor()

@type descriptor() ::
  :void
  | :unknown
  | :string
  | :integer
  | :float
  | :boolean
  | :datetime
  | {:list, descriptor()}
  | {:map, descriptor()}
  | {:ref, module()}
  | {:enum, [String.t()]}
  | {:union, [descriptor()]}
  | {:union, [descriptor()], {String.t(), %{optional(String.t()) => module()}}}
  | {:nullable, descriptor()}
  | {:optional, descriptor()}
  | {:object, [{String.t(), descriptor()}]}

field_descriptor()

@type field_descriptor() :: {atom(), {String.t(), descriptor()}}

Functions

decode(value, descriptor)

@spec decode(ArchAstro.JSON.t(), descriptor()) ::
  ArchAstro.JSON.t() | struct() | DateTime.t() | :ok

encode(value)

matches?(value, arg2)

@spec matches?(ArchAstro.JSON.t(), descriptor()) :: boolean()

put_optional(map, key, value)

struct_from_map(module, data, fields)

@spec struct_from_map(module(), ArchAstro.JSON.object(), [field_descriptor()]) ::
  struct()

struct_to_map(value, fields)

@spec struct_to_map(
  struct(),
  [field_descriptor()]
) :: ArchAstro.JSON.object()