Class: Yes::Core::TransactionDetails

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/yes/core/transaction_details.rb

Overview

Value object representing a command transaction’s context.

Carries correlation/causation IDs for event sourcing traceability, caller identity, and OpenTelemetry trace context.

Examples:

TransactionDetails.new(
  name: "CreateUser",
  correlation_id: SecureRandom.uuid,
  caller_id: current_user.id,
  caller_type: 'User'
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_event(event) ⇒ TransactionDetails

Creates TransactionDetails from an existing event.

Parameters:

Returns:



81
82
83
84
85
86
87
# File 'lib/yes/core/transaction_details.rb', line 81

def self.from_event(event)
  new(
    correlation_id: event.['$correlationId'].presence || SecureRandom.uuid,
    causation_id: event.id,
    otl_contexts: event.['otl_contexts']
  )
end

Instance Method Details

#for_eventstore_metadataHash

Returns metadata formatted for the event store.

Returns:

  • (Hash)

    with :$correlationId and :$causationId keys



65
66
67
68
69
70
# File 'lib/yes/core/transaction_details.rb', line 65

def 
  to_h.slice(:correlation_id, :causation_id, :otl_contexts).tap do |h|
    h[:$correlationId] = h.delete(:correlation_id)
    h[:$causationId] = h.delete(:causation_id)
  end
end

#to_hHash

Returns compact hash representation.

Returns:

  • (Hash)

    compact hash representation



73
74
75
# File 'lib/yes/core/transaction_details.rb', line 73

def to_h
  super.compact
end