Class: Igniter::Store::Protocol::Handlers::CommandHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/store/protocol/handlers/command_handler.rb

Overview

Command descriptors are metadata-only. Ledger records the app-owned mutation contract but never executes application commands.

Constant Summary collapse

REQUIRED =
%i[name owner operation].freeze
OPERATIONS =
%i[record_append record_update history_append none].freeze

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ CommandHandler

Returns a new instance of CommandHandler.



13
# File 'lib/igniter/store/protocol/handlers/command_handler.rb', line 13

def initialize(store) = @store = store

Instance Method Details

#call(descriptor) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/igniter/store/protocol/handlers/command_handler.rb', line 15

def call(descriptor)
  missing = REQUIRED.select { |field| descriptor[field].nil? }
  return Receipt.rejection("Missing required fields: #{missing.join(", ")}", kind: :command) if missing.any?

  name = descriptor[:name].to_sym
  owner = descriptor[:owner].to_sym
  operation = descriptor[:operation].to_sym
  unless OPERATIONS.include?(operation)
    return Receipt.rejection("Unsupported command operation: #{operation.inspect}", kind: :command)
  end

  normalized = descriptor.merge(
    name: name,
    owner: owner,
    operation: operation,
    target_shape: token(descriptor[:target_shape] || target_shape_for(operation)),
    boundary: token(descriptor[:boundary] || :app),
    mutation_intent: token(descriptor[:mutation_intent] || operation)
  )

  @store.schema_graph.register_command_descriptor(normalized)
  Receipt.accepted(kind: :command, name: name)
end