Mediate.Port (mediate v0.1.0)

Copy Markdown View Source

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 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.

Summary

Types

The options every port function takes.

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

Functions

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

Decide for one object and answer the verdict alone.

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

The schema of the options.

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.

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.

The three subject kinds the port knows.

Types

options()

@type options() :: [env: %{required(atom()) => term()}, operation_id: Mediate.Id.t()]

The options every port function takes.

reviewed()

@type reviewed() :: %{
  required(Mediate.subject()) =>
    {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.

Functions

authorize(subject, operation, object, opts)

@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(subject, operation, object, opts)

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

Decide for one object and answer the verdict alone.

event()

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

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

options_schema()

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

The schema of the options.

review(reviewer, subjects, operation, object_type, opts)

@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(subject, operation, object_type, opts)

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()

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

The three subject kinds the port knows.