Declarations on an Ecto schema. They say:
- the object type it protects
- the associations its decision covers
- what kind of thing its rows are
- the fact mapping, column by column
Each macro records its declaration and does nothing else. The seam reads
them back through __mediate__/1.
defmodule Example.Domain.Visibility do
use Ecto.Schema
use Mediate.Schema
object_type(:visibility)
audited(:entity)
fact(:labels, kind: :object_attribute, object: :repository_id, element: :label)
fact(:restrictions, kind: :object_attribute, object: :repository_id, element: :restriction)
fact(:releasable_to, kind: :object_attribute, object: :repository_id, element: :country)
fact(:invited, kind: :relationship, object: :repository_id, element: :user)
endA schema that declares an object type is protected: the seam refuses to
read or write it without a decision. A schema that declares
carries/1 names the associations the root's decision covers. A grant
row declares relationship/1 with its subject and object columns.
__mediate__/1 answers each declaration:
:object_type, the declared type ornil:carries, the carried association names:kind, the kindaudited/1declared ornil:facts, theMediate.Schema.Factrecords in declaration order:relationship, theMediate.Schema.Relationshipornil
This file defines every structure it needs, so a schema's compile-time dependency on it reaches nothing else.
Summary
Functions
Declare what kind of thing a row of this schema is, which is what makes its writes audited. An audited schema need not declare an object type, and then the seam records its writes and passes them without a decision.
Whether the seam audits a module's writes, which is whether it declares what kind of thing its rows are.
Declare the associations the parent's decision covers.
The associations a module's decision covers, or [] where it declares none.
Whether a module used Mediate.Schema.
Declare one fact column and how it maps to a fact kind.
The columns a module declares as facts: its fact columns and the columns of its relationship, each once, in declaration order.
Whether a module carries fact declarations: a fact column or a relationship.
The fact columns a module declares, in declaration order, or [] where it declares none.
A row's primary key: the value of its one key column, or a map of the columns where it has several.
What kind of thing a module's rows are, or nil for a module that declares none.
Declare the object type this schema's rows are, so a query over it needs a decision.
The object type a module declares, or nil for a module that declares none or is not a schema.
Declare that a row of this schema is a relationship grant.
The relationship a module's rows are, or nil.
Functions
Declare what kind of thing a row of this schema is, which is what makes its writes audited. An audited schema need not declare an object type, and then the seam records its writes and passes them without a decision.
Whether the seam audits a module's writes, which is whether it declares what kind of thing its rows are.
Declare the associations the parent's decision covers.
The associations a module's decision covers, or [] where it declares none.
Whether a module used Mediate.Schema.
Declare one fact column and how it maps to a fact kind.
The columns a module declares as facts: its fact columns and the columns of its relationship, each once, in declaration order.
Whether a module carries fact declarations: a fact column or a relationship.
@spec facts_of(term()) :: [Mediate.Schema.Fact.t()]
The fact columns a module declares, in declaration order, or [] where it declares none.
A row's primary key: the value of its one key column, or a map of the columns where it has several.
What kind of thing a module's rows are, or nil for a module that declares none.
Declare the object type this schema's rows are, so a query over it needs a decision.
The object type a module declares, or nil for a module that declares none or is not a schema.
Declare that a row of this schema is a relationship grant.
@spec relationship_of(term()) :: Mediate.Schema.Relationship.t() | nil
The relationship a module's rows are, or nil.