sourced-message 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/lib/sourced/message.rb +31 -3
  4. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c83eaa51d67e2693a9437766624a7331535d0580e3d7481a6b97baeb58f63f
4
- data.tar.gz: 892f3f3a82b5d9063d830516d167c3f3e7b16b86e8ac2047f1614e787142b48f
3
+ metadata.gz: c32c4b5ea1020c0623e0f572d67a529a70630e21dd9d865a43386c4ca318915b
4
+ data.tar.gz: b1bf6ccf2eadf06ea8c5bf301f692a520bb9cb84de37c07a5a340a0395177ff5
5
5
  SHA512:
6
- metadata.gz: 0264f5b499a6d287ed286e0e80158dad36d171dd0da3ff9dfe8425dff0bab2884b64c2405eae964db1dcee415f20763df415b6938d95247e56e937f7d196daf8
7
- data.tar.gz: 57dd69b783f5d076babe42d2e05ff4c654fc710da47098dafa8f20907f98347a6c0e3728e43505a9acf30a81b7cfb8635d35d16b388c88f8250a20010bffcc35
6
+ metadata.gz: c9d6eb69097f9e6f70df79786f8a285c638d7a985f762ba15d70463109058b5884117d838242834db8771a1ee6996434695d5ab4a4dac4d9809a2d25c0456ffa
7
+ data.tar.gz: a1b78a345ee0f8463372e729d9cce17ad28ce9c9da6a2d137da72c174ed10d668148018b7fdb7f13529d2c6d9db78a14f8401e0d976781457f95ec52944998ba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0]
4
+
5
+ - Add `Sourced::Message#correlation_type`, the type counterpart of `correlation_id`:
6
+ the type of the message at the root of a causal chain. `#correlate` now records the
7
+ source's `correlation_type` under `metadata[:correlation_type]` on the target, so
8
+ every consequence of a command carries the command's type. A message that was never
9
+ correlated answers with its own `type`. A target whose metadata already holds a
10
+ `correlation_type` keeps it, which starts a new chain.
11
+ - `Sourced::Message::VERSION` is now `0.3.0`.
12
+
3
13
  ## [0.2.0]
4
14
 
5
15
  - Add `Sourced::Message::Codec`, the abstract serializer: it compiles a
@@ -22,7 +22,7 @@ module Sourced
22
22
  # +Sourced::Message.registry[type]+ resolves a type registered under any
23
23
  # subclass. Resolve from this root to see the whole tree.
24
24
  class Message < Plumb::Types::Data
25
- VERSION = '0.2.1'
25
+ VERSION = '0.3.0'
26
26
 
27
27
  EMPTY_ARRAY = [].freeze
28
28
 
@@ -231,8 +231,33 @@ module Sourced
231
231
 
232
232
  alias in at
233
233
 
234
+ # Metadata key under which {#correlate} records the {#correlation_type}.
235
+ CORRELATION_TYPE_KEY = :correlation_type
236
+
237
+ # The type of the message at the root of this message's causal chain —
238
+ # the type counterpart of {#correlation_id}.
239
+ #
240
+ # A message that was not produced by {#correlate} is its own root, so
241
+ # this is its own {#type}. A correlated message inherits its source's
242
+ # +correlation_type+, so every consequence of a command — the events it
243
+ # produced, the commands those events triggered, their events in turn —
244
+ # answers with the originating command's type. This is what lets a
245
+ # subscriber that only knows the command it sent recognise everything
246
+ # that came of it, without knowing the shape of each downstream message.
247
+ #
248
+ # Setting +metadata[:correlation_type]+ explicitly on a message before it
249
+ # is correlated starts a new chain from it: the target's own metadata wins
250
+ # the merge in {#correlate}.
251
+ #
252
+ # @return [String] a message type string
253
+ def correlation_type
254
+ metadata.fetch(CORRELATION_TYPE_KEY, type)
255
+ end
256
+
234
257
  # Set causation and correlation IDs on another message, establishing
235
- # a causal link from this message to +message+. Merges metadata.
258
+ # a causal link from this message to +message+. Merges metadata, with the
259
+ # target's keys winning, and records this message's {#correlation_type}
260
+ # under {CORRELATION_TYPE_KEY} unless the target already carries one.
236
261
  #
237
262
  # @param message [Message] the message to correlate
238
263
  # @return [Message] a copy of +message+ with causation/correlation set
@@ -241,11 +266,14 @@ module Sourced
241
266
  # caused = source_event.correlate(SomeCommand.new(payload: { ... }))
242
267
  # caused.causation_id # => source_event.id
243
268
  # caused.correlation_id # => source_event.correlation_id
269
+ # caused.correlation_type # => source_event.correlation_type
244
270
  def correlate(message)
245
271
  attrs = {
246
272
  causation_id: id,
247
273
  correlation_id: correlation_id,
248
- metadata: metadata.merge(message.metadata || Plumb::BLANK_HASH)
274
+ metadata: { CORRELATION_TYPE_KEY => correlation_type }
275
+ .merge(metadata)
276
+ .merge(message.metadata || Plumb::BLANK_HASH)
249
277
  }
250
278
  message.with(attrs)
251
279
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sourced-message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
@@ -13,16 +13,16 @@ dependencies:
13
13
  name: plumb
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - '='
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.0.beta.2
18
+ version: '0.3'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - '='
23
+ - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.2.0.beta.2
25
+ version: '0.3'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: fugit
28
28
  requirement: !ruby/object:Gem::Requirement