event_store_client 1.1.0 → 1.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 301a92ed47fa04e52d45989042f82571e30eeba810c73b7c0f73af55a95304f0
4
- data.tar.gz: 0a58c9b4dc19bb56a2f2082b06552de05f39e0983f5c7379a1e058cbe5c65332
3
+ metadata.gz: '098a9968e45cc7aa2d8374d48658a354f9d43b6338555b115718fb89aa1288a8'
4
+ data.tar.gz: cedd89ced40f1a571f12e841fd5266fc83e05e73a087a0135b74d27f6d8621eb
5
5
  SHA512:
6
- metadata.gz: f87b1b7516fdae3a51a23970485ad6d492a50b91550208eee10d3d01530cbda57641941c0dc7a9c2696f25c2f442b87bfc02dc70149fdea499dbb11e02bc8d73
7
- data.tar.gz: 903f6f6b64725911be55f7d4730f988f1a4596b4f4c8de05c226a77fb6ac477f90063854c0ae2b0981abba5cc78928feebc3aff52c38f6b5863f12408f8bcc84
6
+ metadata.gz: 12eac04fd6a932acbf7573edbcec9a8aa8d8deb85b91ea5a8de572e4976d1964f0791e71749f2157095be60c0d0e7e7a6ace270fdbccb3dc6eeef565b25cc5d0
7
+ data.tar.gz: 42579bd365d172bc63ae7bc10ff7c2e9543de5e7d69e29e3ef6d773f2cf5f595717fbdc4049d683ea5f90a6ba531cc3ec45c2533b0b4addd662c1c3c626a5c72
@@ -110,7 +110,10 @@ module EventStoreClient
110
110
  # @return Dry::Monads::Result::Success or Dry::Monads::Result::Failure
111
111
  #
112
112
  def join_streams(name, streams)
113
- Commands::Projections::Create.new.call(name, streams)
113
+ res = Commands::Projections::Create.new.call(name, streams)
114
+ return if res.success?
115
+
116
+ Commands::Projections::Update.new.call(name, streams)
114
117
  end
115
118
 
116
119
  # @api private
@@ -12,7 +12,7 @@ module EventStoreClient
12
12
  def self.inherited(klass)
13
13
  super
14
14
  klass.class_eval do
15
- include Dry::Monads[:result]
15
+ include Dry::Monads[:try, :result]
16
16
 
17
17
  def self.use_request(request_klass)
18
18
  CommandRegistrar.register_request(self, request: request_klass)
@@ -33,8 +33,11 @@ module EventStoreClient
33
33
  }
34
34
  }
35
35
 
36
- service.create(request.new(options: options), metadata: metadata)
37
- Success()
36
+ res = Try do
37
+ service.create(request.new(options: options), metadata: metadata)
38
+ end
39
+
40
+ res.error? ? res.to_result : Success()
38
41
  rescue ::GRPC::Unknown => e
39
42
  Failure(:conflict) if e.message.include?('Conflict')
40
43
  end
@@ -30,7 +30,9 @@ module EventStoreClient
30
30
  name: name,
31
31
  emit_enabled: true
32
32
  }
33
+
33
34
  service.update(request.new(options: options), metadata: metadata)
35
+
34
36
  Success()
35
37
  rescue ::GRPC::AlreadyExists
36
38
  Failure(:conflict)
@@ -6,6 +6,7 @@ require 'event_store_client/adapters/http/commands/persistent_subscriptions/crea
6
6
  require 'event_store_client/adapters/http/commands/persistent_subscriptions/read'
7
7
 
8
8
  require 'event_store_client/adapters/http/commands/projections/create'
9
+ require 'event_store_client/adapters/http/commands/projections/update'
9
10
 
10
11
  require 'event_store_client/adapters/http/commands/streams/append'
11
12
  require 'event_store_client/adapters/http/commands/streams/delete'
@@ -137,7 +137,10 @@ module EventStoreClient
137
137
  # @return Dry::Monads::Result::Success or Dry::Monads::Result::Failure
138
138
  #
139
139
  def join_streams(name, streams, options: {})
140
- Commands::Projections::Create.new(connection).call(name, streams, options: options)
140
+ res = Commands::Projections::Create.new(connection).call(name, streams, options: options)
141
+ return res if res.success?
142
+
143
+ Commands::Projections::Update.new(connection).call(name, streams, options: options)
141
144
  end
142
145
 
143
146
  # @api private
@@ -16,12 +16,15 @@ module EventStoreClient
16
16
  })
17
17
  STRING
18
18
 
19
- connection.call(
19
+
20
+ res = connection.call(
20
21
  :post,
21
22
  "/projections/continuous?name=#{name}&type=js&enabled=yes&emit=true&trackemittedstreams=true", # rubocop:disable Metrics/LineLength
22
23
  body: data,
23
24
  headers: {}
24
25
  )
26
+
27
+ (200...300).cover?(res.status) ? Success() : Failure(res)
25
28
  end
26
29
  end
27
30
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EventStoreClient
4
+ module HTTP
5
+ module Commands
6
+ module Projections
7
+ class Update < Command
8
+ def call(name, streams, options: {})
9
+ data =
10
+ <<~STRING
11
+ fromStreams(#{streams})
12
+ .when({
13
+ $any: function(s,e) {
14
+ linkTo("#{name}", e)
15
+ }
16
+ })
17
+ STRING
18
+ res = connection.call(
19
+ :put,
20
+ "/projection/#{name}/query?type=js&enabled=yes&emit=true&trackemittedstreams=true", # rubocop:disable Metrics/LineLength
21
+ body: data,
22
+ headers: {}
23
+ )
24
+
25
+ (200...300).cover?(res.status) ? Success() : Failure(res)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EventStoreClient
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_store_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wilgosz
@@ -199,6 +199,7 @@ files:
199
199
  - lib/event_store_client/adapters/http/commands/persistent_subscriptions/create.rb
200
200
  - lib/event_store_client/adapters/http/commands/persistent_subscriptions/read.rb
201
201
  - lib/event_store_client/adapters/http/commands/projections/create.rb
202
+ - lib/event_store_client/adapters/http/commands/projections/update.rb
202
203
  - lib/event_store_client/adapters/http/commands/streams/append.rb
203
204
  - lib/event_store_client/adapters/http/commands/streams/delete.rb
204
205
  - lib/event_store_client/adapters/http/commands/streams/link_to.rb