# `Mediate.Port`
[🔗](https://github.com/mrmeku/mediate/blob/v0.1.0/lib/mediate/port.ex#L1)

The mechanism behind the functions of `Mediate`. It resolves the
configuration and builds the environment from the caller's map and the
clock. It asks the adapter. It fails closed on an engine error or on an
exception the decider raised. It stamps a `Mediate.Decision` and
publishes it.

Every decision publishes one `[:mediate, :decision]` event.
[Events](events.html) under "Decision" has the payload. A decision is a
read, so it has no transaction. The one measurement is `duration`, in
microseconds.

The port denies a subject whose kind it does not know before it asks the
adapter. The event of that denial says `:unknown` as the kind.

# `options`

```elixir
@type options() :: [env: %{required(atom()) =&gt; term()}, operation_id: Mediate.Id.t()]
```

The options every port function takes.

# `reviewed`

```elixir
@type reviewed() :: %{
  required(Mediate.subject()) =&gt;
    {Ecto.Query.dynamic_expr(), Mediate.Decision.t()}
}
```

A review's answer per subject: the rule over the object type and the decision it runs under.

# `authorize`

```elixir
@spec authorize(Mediate.subject(), atom(), Mediate.object(), options()) ::
  {:ok, Mediate.Decision.t()} | {:error, Mediate.Error.t()}
```

Decide for one object. The decision is the record and the value the seam takes.

# `check`

```elixir
@spec check(Mediate.subject(), atom(), Mediate.object(), options()) :: boolean()
```

Decide for one object and answer the verdict alone.

# `event`

```elixir
@spec event() :: [atom()]
```

The telemetry event each decision publishes, which is what a consumer attaches to.

# `options_schema`

```elixir
@spec options_schema() :: NimbleOptions.t()
```

The schema of the options.

# `review`

```elixir
@spec review(Mediate.subject(), [Mediate.subject()], atom(), atom(), options()) ::
  reviewed()
```

Who can do what: `scope` per subject over an object type, under one
operation id. Each subject's decision is its own record. A query the
reviewer runs under that decision enters the log under that subject. The
reviewer's own decision over the type is the record of the review.

# `scope`

```elixir
@spec scope(Mediate.subject(), atom(), atom(), options()) ::
  {Ecto.Query.dynamic_expr(), Mediate.Decision.t()}
```

The rule a row of the object type must satisfy, with the decision the
query carries. Under a denied precondition or an unreachable engine the
rule is one no row satisfies and the verdict is `:deny`.

# `subject_kinds`

```elixir
@spec subject_kinds() :: [Mediate.subject_kind()]
```

The three subject kinds the port knows.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
