CommandTransformer

Turns the commands of one input type into the command that runs: one command into one command, at admission, after the input is decoded and authorized and before the result is validated. A transformer may change the command's type, the aggregate it is sent to, its body and its headers; it cannot change the request id (retries stay idempotent), the tenant or the scope, or the wait plan, which CommandTarget has no field for. A command that must become several is a saga's work.

What it serves:

  • a command whose request names no aggregate, which the transformer finds, such as changing a password by user name (ReservationTargetResolver);

  • a mounted command (@MountedCommand), which no aggregate decides, such as an import that becomes a creation command or an external callback in a provider's shape.

At most one transformer takes an input type, and every mounted command needs exactly one: the gateway refuses to be built otherwise. The gateway authorizes the result again when the type or the aggregate changed, and refuses it as wow.aggregate.not-found when it names no aggregate and does not create one. The command's result (me.ahoo.wow.api.result.CommandResult.transformedFrom) and its event stream's headers (TRANSFORMED_FROM, TRANSFORMED_FROM_ID) record the input.

A transformer refuses its input as a decide function does, by throwing a me.ahoo.wow.api.decide.RejectedException (reject(code, message) in Kotlin): the command is rejected with that code, a local name qualified with the input's aggregate (context.aggregate.code), with its message and extensions, and so answered with the code's status (422 by default). Nothing is appended, so the events a rejection carries are dropped. Anything else it throws fails the request.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val input: CommandType

The command type this transformer takes.

Functions

Link copied to clipboard
abstract suspend fun transform(input: CommandInput): CommandTarget

The command input becomes.