A design's contract with its slots' schemas, and the facts it reads from them (spec/02 §7.3).
A design does not carry a source's facts as variables: it states a contract (a
slot's requires) and reads facts (%Macaw.Frame.Fact{}) from the schema bound to
the slot. Reading a fact is a requirement, so contract/1 is the slot's requires
together with every attribute a fact of it reads. resolve/2 replaces every fact by
its value from the schemas given, and check/2 holds the contract to them, every fault
of every slot at once.
iex> design = %{slots: %{"p" => %{fields: ["lat"], requires: %{"lat" => [:unit]}}},
...> labels: [%{anchor: :title, text: "\#{fact(p, lat, label)}"}]}
iex> Macaw.Frame.Document.Facts.contract(design)
%{"p" => %{"lat" => [:unit, :label]}}
Summary
Functions
The contract held to the schemas bound to the slots (§7.3): :ok, or every fault. A
slot the contract names with no schema is {:no_schema, slot} at [:slots, slot]; an
attribute a schema does not give is {:missing_attribute, slot, field, key}; a type the
slot's types disagrees with is {:schema_type, field, declared, described} at
[:slots, slot, :types, field]. colors is the page's colors, as resolve/3 reads them.
The contract of a design (§7.3): %{slot => %{field => [key, …]}}, each slot's
requires and every attribute a fact of it reads, keys in Macaw.Frame.Fact.keys/0
order. Any term that is no design answers %{}.
Every fact a design reads, at any position and in any text's holes.
The design with every fact replaced by its value from the schemas (§7.3): at a position
the value as it is, in a text's hole its words. A fact no schema gives is
{:missing_attribute, slot, field, key} at its path, a slot with no schema
{:no_schema, slot}; every fault at once. colors is the page's colors for a field's
values, the render context's (%{field => %{value => color}}), which a :colors fact
reads first (Macaw.Frame.Fact).
Functions
@spec check(term(), term(), map()) :: :ok | {:error, [Macaw.Base.Fault.t(), ...]}
The contract held to the schemas bound to the slots (§7.3): :ok, or every fault. A
slot the contract names with no schema is {:no_schema, slot} at [:slots, slot]; an
attribute a schema does not give is {:missing_attribute, slot, field, key}; a type the
slot's types disagrees with is {:schema_type, field, declared, described} at
[:slots, slot, :types, field]. colors is the page's colors, as resolve/3 reads them.
The contract of a design (§7.3): %{slot => %{field => [key, …]}}, each slot's
requires and every attribute a fact of it reads, keys in Macaw.Frame.Fact.keys/0
order. Any term that is no design answers %{}.
@spec facts(term()) :: [Macaw.Frame.Fact.t()]
Every fact a design reads, at any position and in any text's holes.
@spec resolve(term(), term(), map()) :: {:ok, term()} | {:error, [Macaw.Base.Fault.t(), ...]}
The design with every fact replaced by its value from the schemas (§7.3): at a position
the value as it is, in a text's hole its words. A fact no schema gives is
{:missing_attribute, slot, field, key} at its path, a slot with no schema
{:no_schema, slot}; every fault at once. colors is the page's colors for a field's
values, the render context's (%{field => %{value => color}}), which a :colors fact
reads first (Macaw.Frame.Fact).