Macaw.Data.Source.Description (macaw_data v0.5.3)

Copy Markdown View Source

What a source is (spec/01 §2.1): its schema, its parameters, the capabilities it honors, and whether it answers every viewer the same.

  • schema: a Macaw.Data.Schema;
  • params: the parameters it takes, by name (strings), each a Macaw.Data.Parameter;
  • supports: the capabilities it honors, distinct, among :window | :box | :region | :latest | :budget | :push | :as_of. Every one is optional: Macaw finishes what a source does not honor (spec/01 §2.4);
  • viewer_independent: true declares the source answers every viewer the same, which only allows pooling across viewers, fetched with the anonymous viewer (spec/01 §6). false by default.

new/1 builds one and reports every fault at once.

Summary

Types

A capability a source may honor.

t()

Functions

The capabilities, in the order spec/01 §2.1 lists them.

A description of the given fields, schema required: {:ok, description} or every fault, {path, reason}, ordered by path.

As new/1, raising ArgumentError naming every fault.

Types

capability()

@type capability() :: :window | :box | :region | :latest | :budget | :push | :as_of

A capability a source may honor.

t()

@type t() :: %Macaw.Data.Source.Description{
  params: %{required(String.t()) => Macaw.Data.Parameter.t()},
  schema: Macaw.Data.Schema.t(),
  supports: [capability()],
  viewer_independent: boolean()
}

Functions

capabilities()

@spec capabilities() :: [capability(), ...]

The capabilities, in the order spec/01 §2.1 lists them.

new(fields)

@spec new(keyword() | map()) :: {:ok, t()} | {:error, [{list(), term()}, ...]}

A description of the given fields, schema required: {:ok, description} or every fault, {path, reason}, ordered by path.

iex> alias Macaw.Data.{Schema, Source.Description}
iex> {:ok, d} = Description.new(schema: Schema.new!(%{v: %{type: :number}}), supports: [:budget])
iex> {d.supports, d.viewer_independent}
{[:budget], false}
iex> Description.new(schema: :nope, supports: [:region, :teleport, :region])
{:error, [{[:schema], {:type, :schema}}, {[:supports, 1], {:enum, Description.capabilities()}}, {[:supports, 2], :duplicate}]}

new!(fields)

@spec new!(keyword() | map()) :: t()

As new/1, raising ArgumentError naming every fault.