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
53
54
55
56
57
58
59
60
|
# File 'lib/event_store_client/adapters/grpc/commands/streams/link_to.rb', line 20
def call(stream_name, events, options: {})
events.each_with_index do |event, index|
custom_metadata = JSON.generate(
"type": '$>',
"created_at": Time.now,
"encryption": event.metadata['encryption'] || ''
)
event_metadata = event.metadata.tap do |h|
h['type'] = '$>'
h['content-type'] = 'application/json'
h.delete('encryption')
end
event_id = event.id
event_id = SecureRandom.uuid if event.id.nil? || event.id.empty?
payload = [
request.new(
options: {
stream_identifier: {
streamName: stream_name
},
any: {}
}
),
request.new(
proposed_message: {
id: {
string: event_id
},
data: event.title,
custom_metadata: custom_metadata,
metadata: event_metadata
}
)
]
service.append(payload, metadata: metadata)
end
Success()
end
|