Module: Hecks::Facade::CommandRequest

Defined in:
lib/hecks/facade/command_request.rb

Overview

Turns an external command request into the dispatcher's receiver/payload envelope. Human-facing doors may accept their old flat id spelling at the edge, but every call leaving this boundary has one shape:

aggregate command: { to: "record-id", with: { declared: "facts" } }
entity command:    { to: { aggregate: "...", entity: "..." },
                   with: { declared: "facts" } }

The command interpreter remains the authority on which facts are declared. This helper only prevents routing fields from leaking into the fact payload and gives every external door the same wire contract.

Class Method Summary collapse

Class Method Details

.normalize(input, receiver:, legacy_receiver: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hecks/facade/command_request.rb', line 19

def normalize(input, receiver:, legacy_receiver: nil)
  request = symbolize(input)
  unless request.is_a?(Hash)
    raise Runtime::TypeMismatch, "a command request must be a hash"
  end

  route, facts = split(request, receiver: receiver, legacy_receiver: legacy_receiver)
  validate_route!(route, receiver)

  envelope = { with: facts }
  envelope[:to] = route if receiver
  envelope
end