Class: EventStoreClient::GRPC::Commands::Streams::Append

Inherits:
Command
  • Object
show all
Defined in:
lib/event_store_client/adapters/grpc/commands/streams/append.rb

Instance Method Summary collapse

Methods inherited from Command

inherited, #metadata

Methods included from Configuration

#config

Instance Method Details

#call(stream, events, options: {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: Add support to verify the expected version



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/event_store_client/adapters/grpc/commands/streams/append.rb', line 19

def call(stream, events, options: {}) # rubocop:disable Lint/UnusedMethodArgument,Metrics/LineLength
  serialized_events = events.map { |event| config.mapper.serialize(event) }

  serialized_events.each do |event|
     = JSON.parse(event.)
    payload = [
      request.new(
        options: {
          stream_identifier: {
            streamName: stream
          },
          any: {}
        }
      ),
      request.new(
        proposed_message: {
          id: {
            string: SecureRandom.uuid
          },
          data: event.data,
          custom_metadata: JSON.generate(
            "type": event.type,
            "content-type": 'application/vnd.eventstore.events+json',
            "created_at": Time.now,
            'encryption': ['encryption']
          ),
          metadata: .select { |k| ['type', 'content-type', 'created_at'].include?(k) }
        }
      )
    ]
    service.append(payload, metadata: )
  end
  Success()
end