Mediate.Change (mediate v0.1.0)

Copy Markdown View Source

The change event: one telemetry event for each single-row write to an audited schema. The seam computes it from the write itself and publishes it inside the write's transaction. So a consumer that writes to the same repository from its handler joins that transaction.

Events under "Change" has the payload. The value before a change is the row the caller loaded. A change a second writer made between the load and the write is not in the event. The library publishes the event and stores nothing. What an attached handler does with it is the handler's own business.

Summary

Types

What the write did to the row.

What every event of one operation shares: who asked, under which decision, the identifier, and the moment.

Functions

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

The actor of a change no decision named, which is the library itself: a non-person entity with the nil identifier. A write through the seam under an exemption carries this.

Publish one change. The row before an insert and the row after a delete are nil.

Types

operation()

@type operation() :: :create | :update | :delete

What the write did to the row.

stamp()

@type stamp() :: %{
  by: Mediate.subject(),
  decision_id: Mediate.Id.t() | nil,
  operation_id: Mediate.Id.t(),
  at: DateTime.t()
}

What every event of one operation shares: who asked, under which decision, the identifier, and the moment.

Functions

event()

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

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

library()

@spec library() :: Mediate.subject()

The actor of a change no decision named, which is the library itself: a non-person entity with the nil identifier. A write through the seam under an exemption carries this.

publish(schema, operation, old, new, stamp)

@spec publish(module(), operation(), struct() | nil, struct() | nil, stamp()) :: :ok

Publish one change. The row before an insert and the row after a delete are nil.