Decree.Middleware.ExtractAggregateIdentity (decree v0.1.0)

Copy Markdown View Source

An internal Decree.Middleware that extracts the target aggregate's identity from the command.

It runs after every middleware a router registers, and after Decree.Middleware.CommandId, so it reads the command they leave. It resolves the identity once per dispatch, and assigns it twice: :aggregate_uuid is the stream name, with any identify prefix, and :aggregate_identity is the same string before the prefix.

The identity is checked as the command's field, or the route's identity function, gave it, before the prefix: it must be a lowercase canonical UUID (Decree.UUID.canonical?/1), or, on a route declared opaque: true, a non-empty binary. Anything else, a missing field and nil included, answers {:error, :invalid_aggregate_identity} and halts. Nothing converts, trims or downcases it, so the stream is named by exactly what the requester sent.

Summary

Functions

after_dispatch(pipeline)

Callback implementation for Decree.Middleware.after_dispatch/1.

after_failure(pipeline)

Callback implementation for Decree.Middleware.after_failure/1.

before_dispatch(pipeline)

Callback implementation for Decree.Middleware.before_dispatch/1.