From 972d72768a0a7aeb10b48694f9268179410940cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Sun, 15 Apr 2018 16:22:19 +0200 Subject: [PATCH 1/7] Formatting. --- .../app/models/rails_event_store/browser/json_api_event.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/rails_event_store-browser/app/models/rails_event_store/browser/json_api_event.rb b/rails_event_store-browser/app/models/rails_event_store/browser/json_api_event.rb index f02f8084ca..faca1018dd 100644 --- a/rails_event_store-browser/app/models/rails_event_store/browser/json_api_event.rb +++ b/rails_event_store-browser/app/models/rails_event_store/browser/json_api_event.rb @@ -1,6 +1,5 @@ module RailsEventStore module Browser - class JsonApiEvent def initialize(event) @event = event @@ -19,9 +18,7 @@ def to_h end private - attr_reader :event end - end end \ No newline at end of file From 2b14c50c2f41112be031200f0ea381f572ede390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Sun, 15 Apr 2018 17:06:03 +0200 Subject: [PATCH 2/7] Reuse JsonApiEvent serializer. --- .../browser/streams_controller.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb b/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb index 0ab941863a..740e5a8972 100644 --- a/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb +++ b/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb @@ -53,7 +53,7 @@ def show end render json: { - data: events.map { |e| serialize_event(e) }, + data: events.map { |e| JsonApiEvent.new(e).to_h }, links: links }, content_type: 'application/vnd.api+json' end @@ -151,18 +151,6 @@ def serialize_stream(stream) type: "streams" } end - - def serialize_event(event) - { - id: event.event_id, - type: "events", - attributes: { - event_type: event.class.to_s, - data: event.data, - metadata: event.metadata.to_h - } - } - end end end end \ No newline at end of file From 1441359319777142ebb2f362881fd7b48c0c0d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Sun, 15 Apr 2018 16:35:33 +0200 Subject: [PATCH 3/7] Start browsing on global stream. https://github.com/RailsEventStore/rails_event_store/issues/212 It should already give an overview of recent events in the system (as global stream has them all). It would not suffer from performance issues of stream browsing. It would still allow jumping into specific stream via URL, like: http://localhost:8080/#streams/Order%24419 which would go to Order$419 stream. --- rails_event_store-browser/elm/src/Main.elm | 11 ++--------- rails_event_store-browser/spec/ui_spec.rb | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/rails_event_store-browser/elm/src/Main.elm b/rails_event_store-browser/elm/src/Main.elm index 3e46e6869d..c4f5a44668 100644 --- a/rails_event_store-browser/elm/src/Main.elm +++ b/rails_event_store-browser/elm/src/Main.elm @@ -37,8 +37,7 @@ type Msg type Page - = BrowseStreams - | BrowseEvents String + = BrowseEvents String | ShowEvent String | NotFound @@ -147,9 +146,6 @@ urlUpdate model location = UrlParser.parseHash routeParser location in case decodeLocation location of - Just BrowseStreams -> - ( { model | page = BrowseStreams }, getItems model.flags.streamsUrl ) - Just (BrowseEvents encodedStreamId) -> case (Http.decodeUri encodedStreamId) of Just streamId -> @@ -176,7 +172,7 @@ urlUpdate model location = routeParser : UrlParser.Parser (Page -> a) a routeParser = UrlParser.oneOf - [ UrlParser.map BrowseStreams UrlParser.top + [ UrlParser.map (BrowseEvents "all") UrlParser.top , UrlParser.map BrowseEvents (UrlParser.s "streams" UrlParser.string) , UrlParser.map ShowEvent (UrlParser.s "events" UrlParser.string) ] @@ -217,9 +213,6 @@ browserFooter model = browserBody : Model -> Html Msg browserBody model = case model.page of - BrowseStreams -> - browseItems "Streams" model.items - BrowseEvents streamName -> browseItems ("Events in " ++ streamName) model.items diff --git a/rails_event_store-browser/spec/ui_spec.rb b/rails_event_store-browser/spec/ui_spec.rb index 2df8e6d878..473a3b4f25 100644 --- a/rails_event_store-browser/spec/ui_spec.rb +++ b/rails_event_store-browser/spec/ui_spec.rb @@ -8,17 +8,33 @@ module RailsEventStore before { load_database_schema } - specify "ui works", mutant: false do + specify "main view", mutant: false do skip("in-memory sqlite cannot run this test") if ENV['DATABASE_URL'].include?(":memory:") foo_bar_event = FooBarEvent.new(data: { foo: :bar }) - event_store.publish_event(foo_bar_event, stream_name: 'foo/bar.xml') + event_store.publish_event(foo_bar_event, stream_name: 'dummy') visit('/res') + expect(page).to have_content("Events in all") + within('.browser__results') do - click_on 'foo/bar.xml' + click_on 'FooBarEvent' end + within('.event__body') do + expect(page).to have_content(foo_bar_event.event_id) + expect(page).to have_content(%Q[{ "timestamp": "#{foo_bar_event.metadata[:timestamp].as_json}" ]) + expect(page).to have_content(%Q[{ "foo": "bar" }]) + end + end + + specify "stream view", mutant: false do + skip("in-memory sqlite cannot run this test") if ENV['DATABASE_URL'].include?(":memory:") + + foo_bar_event = FooBarEvent.new(data: { foo: :bar }) + event_store.publish_event(foo_bar_event, stream_name: 'foo/bar.xml') + + visit('/res/#streams/foo%2Fbar.xml') expect(page).to have_content("Events in foo/bar.xml") within('.browser__results') do From 47a52edfd5002a3c6e25f5d53370a02324bb7223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Sun, 15 Apr 2018 17:03:03 +0200 Subject: [PATCH 4/7] Remove now unneeded code. --- .../browser/events_controller.rb | 3 - .../browser/streams_controller.rb | 69 -------- rails_event_store-browser/config/routes.rb | 4 +- rails_event_store-browser/spec/api_spec.rb | 156 ------------------ 4 files changed, 1 insertion(+), 231 deletions(-) diff --git a/rails_event_store-browser/app/controllers/rails_event_store/browser/events_controller.rb b/rails_event_store-browser/app/controllers/rails_event_store/browser/events_controller.rb index cbddfad84c..d4e1f00db7 100644 --- a/rails_event_store-browser/app/controllers/rails_event_store/browser/events_controller.rb +++ b/rails_event_store-browser/app/controllers/rails_event_store/browser/events_controller.rb @@ -1,6 +1,5 @@ module RailsEventStore module Browser - class EventsController < ApplicationController def show event = event_store.read_event(event_id) @@ -12,8 +11,6 @@ def show def event_id params.fetch(:id) end - end - end end diff --git a/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb b/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb index 740e5a8972..a2dbf415ca 100644 --- a/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb +++ b/rails_event_store-browser/app/controllers/rails_event_store/browser/streams_controller.rb @@ -1,35 +1,6 @@ module RailsEventStore module Browser class StreamsController < ApplicationController - def index - links = {} - streams = case direction - when :forward - items = event_store.get_all_streams - items = items.drop_while { |s| !s.name.eql?(position) }.drop(1) unless position.equal?(:head) - items.take(count).reverse - when :backward - items = event_store.get_all_streams.reverse - items = items.drop_while { |s| !s.name.eql?(position) }.drop(1) unless position.equal?(:head) - items.take(count) - end - - if next_stream?(streams) - links[:next] = streams_next_page_link(streams.last.name) - links[:last] = streams_last_page_link - end - - if prev_stream?(streams) - links[:prev] = streams_prev_page_link(streams.first.name) - links[:first] = streams_first_page_link - end - - render json: { - data: streams.map { |s| serialize_stream(s) }, - links: links - }, content_type: 'application/vnd.api+json' - end - def show links = {} events = case direction @@ -60,39 +31,6 @@ def show private - def next_stream?(streams) - return if streams.empty? - event_store.get_all_streams - .reverse - .drop_while { |s| !s.name.eql?(streams.last.name) } - .drop(1) - .present? - end - - def prev_stream?(streams) - return if streams.empty? - event_store.get_all_streams - .drop_while { |s| !s.name.eql?(streams.first.name) } - .drop(1) - .present? - end - - def streams_next_page_link(stream_name) - streams_url(position: stream_name, direction: :backward, count: count) - end - - def streams_prev_page_link(stream_name) - streams_url(position: stream_name, direction: :forward, count: count) - end - - def streams_first_page_link - streams_url(position: :head, direction: :backward, count: count) - end - - def streams_last_page_link - streams_url(position: :head, direction: :forward, count: count) - end - def next_event?(events) return if events.empty? event_store.read_events_backward(stream_name, start: events.last.event_id).present? @@ -144,13 +82,6 @@ def position def stream_name params.fetch(:id) end - - def serialize_stream(stream) - { - id: stream.name, - type: "streams" - } - end end end end \ No newline at end of file diff --git a/rails_event_store-browser/config/routes.rb b/rails_event_store-browser/config/routes.rb index d92e47d748..9a42c7adce 100644 --- a/rails_event_store-browser/config/routes.rb +++ b/rails_event_store-browser/config/routes.rb @@ -9,7 +9,5 @@ format: false, constraints: { id: %r{[^\/]+} } - get '/streams(/:position/:direction/:count)', - to: "streams#index", - as: :streams + resources :streams, only: [:index] end diff --git a/rails_event_store-browser/spec/api_spec.rb b/rails_event_store-browser/spec/api_spec.rb index 14aec2a3c4..b3fefeba67 100644 --- a/rails_event_store-browser/spec/api_spec.rb +++ b/rails_event_store-browser/spec/api_spec.rb @@ -10,148 +10,6 @@ module RailsEventStore before { load_database_schema } - specify do - event_store.publish_event(dummy_event, stream_name: "dummy") - get "/res/streams" - - expect(response).to have_http_status(200) - expect(parsed_body["data"]).to match_array([all_stream_resource, dummy_stream_resource]) - expect(parsed_body["links"]).to eq({}) - end - - specify "first page, newest streams descending" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(20) - get "/res/streams" - - expect(parsed_body["links"]).to eq({ - "last" => "http://www.example.com/res/streams/head/forward/20", - "next" => "http://www.example.com/res/streams/#{first_page.last}/backward/20" - }) - expect(parsed_body["data"].size).to eq(20) - end - - specify "first page, newest streams descending" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(20) - get "/res/streams/head/backward/20" - - expect(parsed_body["links"]).to eq({ - "last" => "http://www.example.com/res/streams/head/forward/20", - "next" => "http://www.example.com/res/streams/#{first_page.last}/backward/20" - }) - expect(parsed_body["data"].size).to eq(20) - end - - specify "first page, newest streams descending" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(20) - last_page = streams.reverse.drop(20) - get "/res/streams/#{last_page.first}/forward/20" - - expect(parsed_body["links"]).to eq({ - "last" => "http://www.example.com/res/streams/head/forward/20", - "next" => "http://www.example.com/res/streams/#{first_page.last}/backward/20" - }) - expect(parsed_body["data"].size).to eq(20) - end - - specify "last page, oldest events descending" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(20) - last_page = streams.reverse.drop(20) - get "/res/streams/#{first_page.last}/backward/20" - - expect(parsed_body["links"]).to eq({ - "first" => "http://www.example.com/res/streams/head/backward/20", - "prev" => "http://www.example.com/res/streams/#{last_page.first}/forward/20" , - }) - expect(parsed_body["data"].size).to eq(20) - end - - specify "last page, oldest events descending" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(20) - last_page = streams.reverse.drop(20) - get "/res/streams/head/forward/20" - - expect(parsed_body["links"]).to eq({ - "first" => "http://www.example.com/res/streams/head/backward/20", - "prev" => "http://www.example.com/res/streams/#{last_page.first}/forward/20" , - }) - expect(parsed_body["data"].size).to eq(20) - end - - specify "non-edge page" do - streams = 40.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(20) - next_page = streams.reverse.drop(20) - get "/res/streams/#{first_page.last}/backward/20" - - expect(parsed_body["links"]).to eq({ - "first" => "http://www.example.com/res/streams/head/backward/20", - "last" => "http://www.example.com/res/streams/head/forward/20", - "next" => "http://www.example.com/res/streams/#{next_page.last}/backward/20", - "prev" => "http://www.example.com/res/streams/#{next_page.first}/forward/20" - }) - expect(parsed_body["data"].size).to eq(20) - end - - specify do - streams = 20.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - current_page = streams.reverse.drop(1) + ["all"] - get "/res/streams/head/forward/20" - - expect(parsed_body["links"]).to eq({ - "first" => "http://www.example.com/res/streams/head/backward/20", - "prev" => "http://www.example.com/res/streams/#{current_page.first}/forward/20" - }) - expect(parsed_body["data"].size).to eq(20) - end - - specify "custom page size" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(5) - next_page = streams.reverse.drop(5).take(5) - get "/res/streams/#{first_page.last}/backward/5" - - expect(parsed_body["links"]).to eq({ - "first" => "http://www.example.com/res/streams/head/backward/5", - "last" => "http://www.example.com/res/streams/head/forward/5", - "next" => "http://www.example.com/res/streams/#{next_page.last}/backward/5", - "prev" => "http://www.example.com/res/streams/#{next_page.first}/forward/5" - }) - expect(parsed_body["data"].size).to eq(5) - end - - specify "out of bounds beyond oldest" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - last_page = streams.reverse.drop(20) + ["all"] - get "/res/streams/#{last_page.last}/backward/20" - - expect(parsed_body["links"]).to eq({}) - expect(parsed_body["data"].size).to eq(0) - end - - specify "out of bounds beyond newest" do - streams = 39.times.map { |i| "stream_#{i}" } - streams.each { |stream_name| event_store.publish_event(DummyEvent.new, stream_name: stream_name) } - first_page = streams.reverse.take(20) - get "/res/streams/#{first_page.first}/forward/20" - - expect(parsed_body["links"]).to eq({}) - expect(parsed_body["data"].size).to eq(0) - end - specify do event_store.publish_event(dummy_event, stream_name: "dummy") get "/res/streams/all" @@ -329,20 +187,6 @@ def event_resource } end - def all_stream_resource - { - "id" => "all", - "type" => "streams" - } - end - - def dummy_stream_resource - { - "id" => "dummy", - "type" => "streams" - } - end - def event_store Rails.configuration.event_store end From 8d7d3bc09ac99e671b8cf7672a3d40bfa6dbab40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Sun, 15 Apr 2018 23:24:42 +0200 Subject: [PATCH 5/7] Remove dead API. It was there solely for browser feature that is no longer. --- .../event_repository.rb | 4 ---- .../event_repository_reader.rb | 6 ------ .../legacy_event_repository.rb | 6 ------ .../spec/event_repository_spec.rb | 7 ------- ruby_event_store/lib/ruby_event_store/client.rb | 5 ----- .../lib/ruby_event_store/in_memory_repository.rb | 4 ---- .../lib/ruby_event_store/spec/event_repository_lint.rb | 10 ---------- ruby_event_store/spec/client_spec.rb | 7 ------- .../lib/ruby_event_store/rom/event_repository.rb | 4 ---- .../spec/rom/event_repository_spec.rb | 8 -------- 10 files changed, 61 deletions(-) diff --git a/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository.rb b/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository.rb index 91669de467..5193863e9d 100644 --- a/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository.rb +++ b/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository.rb @@ -66,10 +66,6 @@ def read_event(event_id) @repo_reader.read_event(event_id) end - def get_all_streams - @repo_reader.get_all_streams - end - private def add_to_stream(collection, stream, expected_version, include_global, &to_event_id) diff --git a/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository_reader.rb b/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository_reader.rb index c8364d6a83..0eae1edd74 100644 --- a/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository_reader.rb +++ b/rails_event_store_active_record/lib/rails_event_store_active_record/event_repository_reader.rb @@ -82,12 +82,6 @@ def read_event(event_id) raise RubyEventStore::EventNotFound.new(event_id) end - def get_all_streams - (["all"] + EventInStream.order(:id).pluck(:stream)) - .uniq - .map { |name| RubyEventStore::Stream.new(name) } - end - private def build_event_instance(record) diff --git a/rails_event_store_active_record/lib/rails_event_store_active_record/legacy_event_repository.rb b/rails_event_store_active_record/lib/rails_event_store_active_record/legacy_event_repository.rb index e48edb402a..ad25053446 100644 --- a/rails_event_store_active_record/lib/rails_event_store_active_record/legacy_event_repository.rb +++ b/rails_event_store_active_record/lib/rails_event_store_active_record/legacy_event_repository.rb @@ -121,12 +121,6 @@ def read_event(event_id) build_event_entity(LegacyEvent.find_by(event_id: event_id)) or raise RubyEventStore::EventNotFound.new(event_id) end - def get_all_streams - (["all"] + LegacyEvent.pluck(:stream)) - .uniq - .map { |name| RubyEventStore::Stream.new(name) } - end - private def normalize_to_array(events) diff --git a/rails_event_store_active_record/spec/event_repository_spec.rb b/rails_event_store_active_record/spec/event_repository_spec.rb index 2e727b2a94..2bc8d79889 100644 --- a/rails_event_store_active_record/spec/event_repository_spec.rb +++ b/rails_event_store_active_record/spec/event_repository_spec.rb @@ -223,13 +223,6 @@ module RailsEventStoreActiveRecord end end - specify "explicit order when fetching list of streams" do - repository = EventRepository.new - expect_query(/SELECT.*FROM.*event_store_events_in_streams.*ORDER BY.*id.*ASC.*/) do - repository.get_all_streams - end - end - class FillInRepository < EventRepository def fill_ids(in_stream) in_stream.each.with_index.map do |is, index| diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index fb898aad4c..8317f7a4f7 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -75,11 +75,6 @@ def read_event(event_id) deserialize_event(repository.read_event(event_id)) end - def get_all_streams - repository.get_all_streams - end - - DEPRECATED_WITHIN = "subscribe(subscriber, event_types, &task) has been deprecated. Use within(&task).subscribe(subscriber, to: event_types).call instead" DEPRECATED_TO = "subscribe(subscriber, event_types) has been deprecated. Use subscribe(subscriber, to: event_types) instead" # OLD: diff --git a/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb b/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb index 556886b397..2cf97ca3c0 100644 --- a/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb +++ b/ruby_event_store/lib/ruby_event_store/in_memory_repository.rb @@ -61,10 +61,6 @@ def read_event(event_id) streams.fetch(GLOBAL_STREAM).find { |e| event_id.eql?(e.event_id) } or raise EventNotFound.new(event_id) end - def get_all_streams - streams.keys.map { |name| Stream.new(name) } - end - private def normalize_to_array(events) diff --git a/ruby_event_store/lib/ruby_event_store/spec/event_repository_lint.rb b/ruby_event_store/lib/ruby_event_store/spec/event_repository_lint.rb index c17ce4f387..8a8dc7c3d3 100644 --- a/ruby_event_store/lib/ruby_event_store/spec/event_repository_lint.rb +++ b/ruby_event_store/lib/ruby_event_store/spec/event_repository_lint.rb @@ -907,16 +907,6 @@ def self.new( expect(repository.has_event?('9bedf448-e4d0-41a3-a8cd-f94aec7aa763')).to be_falsey end - specify "all stream always present" do - expect(repository.get_all_streams).to match_array([RubyEventStore::Stream.new("all")]) - end - - specify "reading all existing stream names" do - repository.append_to_stream(SRecord.new, RubyEventStore::Stream.new("test"), -1) - repository.append_to_stream(SRecord.new, RubyEventStore::Stream.new("test"), 0) - expect(repository.get_all_streams).to match_array([RubyEventStore::Stream.new("all"), RubyEventStore::Stream.new("test")]) - end - specify 'reading particular event' do test_event = SRecord.new(event_id: "941cd8f5-b3f9-47af-b4e4-07f8cea37467") repository. diff --git a/ruby_event_store/spec/client_spec.rb b/ruby_event_store/spec/client_spec.rb index 93dee1792c..862a88926a 100644 --- a/ruby_event_store/spec/client_spec.rb +++ b/ruby_event_store/spec/client_spec.rb @@ -164,13 +164,6 @@ module RubyEventStore expect { client.subscribe_to_all_events(nil)}.to raise_error(SubscriberNotExist) end - specify 'reading all existing stream names' do - client = RubyEventStore::Client.new(repository: InMemoryRepository.new) - client.publish_event(TestEvent.new, stream_name: 'test') - - expect(client.get_all_streams).to eq([Stream.new('all'), Stream.new('test')]) - end - specify 'reading particular event' do client = RubyEventStore::Client.new(repository: InMemoryRepository.new) test_event = TestEvent.new diff --git a/ruby_event_store_rom_sql/lib/ruby_event_store/rom/event_repository.rb b/ruby_event_store_rom_sql/lib/ruby_event_store/rom/event_repository.rb index fe30d70dc8..81404d0e04 100644 --- a/ruby_event_store_rom_sql/lib/ruby_event_store/rom/event_repository.rb +++ b/ruby_event_store_rom_sql/lib/ruby_event_store/rom/event_repository.rb @@ -68,10 +68,6 @@ def read_event(event_id) raise EventNotFound.new(event_id) end - def get_all_streams - @event_streams.all - end - private def raise_error(ex) diff --git a/ruby_event_store_rom_sql/spec/rom/event_repository_spec.rb b/ruby_event_store_rom_sql/spec/rom/event_repository_spec.rb index 9553ecd113..b4fa68f963 100644 --- a/ruby_event_store_rom_sql/spec/rom/event_repository_spec.rb +++ b/ruby_event_store_rom_sql/spec/rom/event_repository_spec.rb @@ -232,14 +232,6 @@ module RubyEventStore::ROM end end - # TODO: Port from AR to ROM - xspecify "explicit order when fetching list of streams" do - repository = EventRepository.new - expect_query(/SELECT.*FROM.*event_store_events_in_streams.*ORDER BY.*id.*ASC.*/) do - repository.get_all_streams - end - end - def cleanup_concurrency_test rom_db.connection.pool.disconnect end From 522ca0859c6652b9a86a50e14dcc130f56b769dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Mon, 16 Apr 2018 12:12:44 +0200 Subject: [PATCH 6/7] Remove Stream leftovers. We no longer browse list of streams. --- rails_event_store-browser/elm/src/Main.elm | 40 ++-------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/rails_event_store-browser/elm/src/Main.elm b/rails_event_store-browser/elm/src/Main.elm index c4f5a44668..d58038e1c8 100644 --- a/rails_event_store-browser/elm/src/Main.elm +++ b/rails_event_store-browser/elm/src/Main.elm @@ -43,8 +43,7 @@ type Page type Item - = StreamItem Stream - | EventItem Event + = EventItem Event type alias Event = @@ -56,11 +55,6 @@ type alias Event = } -type alias Stream = - { name : String - } - - type alias PaginationLink = String @@ -328,16 +322,6 @@ renderResults items = [] -> p [ class "results__empty" ] [ text "No items" ] - (StreamItem _) :: _ -> - table [] - [ thead [] - [ tr [] - [ th [] [ text "Stream name" ] - ] - ] - , tbody [] (List.map itemRow (items)) - ] - (EventItem _) :: _ -> table [] [ thead [] @@ -369,17 +353,6 @@ itemRow item = ] ] - StreamItem { name } -> - tr [] - [ td [] - [ a - [ class "results__link" - , href (buildUrl "#streams" name) - ] - [ text name ] - ] - ] - getEvent : String -> Cmd Msg getEvent url = @@ -398,12 +371,9 @@ itemsDecoder = let eventItemDecoder = Json.Decode.map EventItem eventDecoder_ - - streamItemDecoder = - Json.Decode.map StreamItem streamDecoder_ in decode PaginatedList - |> required "data" (list (oneOf [ eventItemDecoder, streamItemDecoder ])) + |> required "data" (list eventItemDecoder) |> required "links" linksDecoder @@ -422,12 +392,6 @@ eventDecoder = |> field "data" -streamDecoder_ : Decoder Stream -streamDecoder_ = - decode Stream - |> required "id" string - - eventDecoder_ : Decoder Event eventDecoder_ = decode Event From f52c986c5aa7e513978180529b897d3762965258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Mon, 16 Apr 2018 12:22:08 +0200 Subject: [PATCH 7/7] Events over items. Item made sense when there was more than one thing to browse. Since we only have events, rename to remove that friction. --- rails_event_store-browser/elm/src/Main.elm | 92 +++++++++---------- .../elm/tests/Example.elm | 53 ++--------- 2 files changed, 50 insertions(+), 95 deletions(-) diff --git a/rails_event_store-browser/elm/src/Main.elm b/rails_event_store-browser/elm/src/Main.elm index d58038e1c8..8c759a9cfd 100644 --- a/rails_event_store-browser/elm/src/Main.elm +++ b/rails_event_store-browser/elm/src/Main.elm @@ -22,7 +22,7 @@ main = type alias Model = - { items : PaginatedList Item + { events : PaginatedList Event , event : Maybe Event , page : Page , flags : Flags @@ -30,7 +30,7 @@ type alias Model = type Msg - = GetItems (Result Http.Error (PaginatedList Item)) + = GetEvents (Result Http.Error (PaginatedList Event)) | GetEvent (Result Http.Error Event) | ChangeUrl Navigation.Location | GoToPage PaginationLink @@ -42,10 +42,6 @@ type Page | NotFound -type Item - = EventItem Event - - type alias Event = { eventType : String , eventId : String @@ -68,7 +64,7 @@ type alias PaginationLinks = type alias PaginatedList a = - { items : List a + { events : List a , links : PaginationLinks } @@ -97,7 +93,7 @@ model flags location = } initModel = - { items = PaginatedList [] initLinks + { events = PaginatedList [] initLinks , page = NotFound , event = Nothing , flags = flags @@ -109,10 +105,10 @@ model flags location = update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of - GetItems (Ok result) -> - ( { model | items = result }, Cmd.none ) + GetEvents (Ok result) -> + ( { model | events = result }, Cmd.none ) - GetItems (Err msg) -> + GetEvents (Err msg) -> ( model, Cmd.none ) GetEvent (Ok result) -> @@ -125,7 +121,7 @@ update msg model = urlUpdate model location GoToPage paginationLink -> - ( model, getItems paginationLink ) + ( model, getEvents paginationLink ) buildUrl : String -> String -> String @@ -143,7 +139,7 @@ urlUpdate model location = Just (BrowseEvents encodedStreamId) -> case (Http.decodeUri encodedStreamId) of Just streamId -> - ( { model | page = (BrowseEvents streamId) }, getItems (buildUrl model.flags.streamsUrl streamId) ) + ( { model | page = (BrowseEvents streamId) }, getEvents (buildUrl model.flags.streamsUrl streamId) ) Nothing -> ( { model | page = NotFound }, Cmd.none ) @@ -208,7 +204,7 @@ browserBody : Model -> Html Msg browserBody model = case model.page of BrowseEvents streamName -> - browseItems ("Events in " ++ streamName) model.items + browseEvents ("Events in " ++ streamName) model.events ShowEvent eventId -> showEvent model.event @@ -247,12 +243,12 @@ showEvent event = div [ class "event" ] [] -browseItems : String -> PaginatedList Item -> Html Msg -browseItems title { links, items } = +browseEvents : String -> PaginatedList Event -> Html Msg +browseEvents title { links, events } = div [ class "browser" ] [ h1 [ class "browser__title" ] [ text title ] , div [ class "browser__pagination" ] [ displayPagination links ] - , div [ class "browser__results" ] [ renderResults items ] + , div [ class "browser__results" ] [ renderResults events ] ] @@ -316,13 +312,13 @@ firstPageButton url = [ text "first" ] -renderResults : List Item -> Html Msg -renderResults items = - case items of +renderResults : List Event -> Html Msg +renderResults events = + case events of [] -> p [ class "results__empty" ] [ text "No items" ] - (EventItem _) :: _ -> + _ -> table [] [ thead [] [ tr [] @@ -331,27 +327,25 @@ renderResults items = , th [ class "u-align-right" ] [ text "Created at" ] ] ] - , tbody [] (List.map itemRow items) + , tbody [] (List.map itemRow events) ] -itemRow : Item -> Html Msg -itemRow item = - case item of - EventItem { eventType, createdAt, eventId } -> - tr [] - [ td [] - [ a - [ class "results__link" - , href (buildUrl "#events" eventId) - ] - [ text eventType ] - ] - , td [] [ text eventId ] - , td [ class "u-align-right" ] - [ text createdAt - ] +itemRow : Event -> Html Msg +itemRow { eventType, createdAt, eventId } = + tr [] + [ td [] + [ a + [ class "results__link" + , href (buildUrl "#events" eventId) ] + [ text eventType ] + ] + , td [] [ text eventId ] + , td [ class "u-align-right" ] + [ text createdAt + ] + ] getEvent : String -> Cmd Msg @@ -360,21 +354,17 @@ getEvent url = |> Http.send GetEvent -getItems : String -> Cmd Msg -getItems url = - Http.get url itemsDecoder - |> Http.send GetItems +getEvents : String -> Cmd Msg +getEvents url = + Http.get url eventsDecoder + |> Http.send GetEvents -itemsDecoder : Decoder (PaginatedList Item) -itemsDecoder = - let - eventItemDecoder = - Json.Decode.map EventItem eventDecoder_ - in - decode PaginatedList - |> required "data" (list eventItemDecoder) - |> required "links" linksDecoder +eventsDecoder : Decoder (PaginatedList Event) +eventsDecoder = + decode PaginatedList + |> required "data" (list eventDecoder_) + |> required "links" linksDecoder linksDecoder : Decoder PaginationLinks diff --git a/rails_event_store-browser/elm/tests/Example.elm b/rails_event_store-browser/elm/tests/Example.elm index ccb2771e0c..bd9c743093 100644 --- a/rails_event_store-browser/elm/tests/Example.elm +++ b/rails_event_store-browser/elm/tests/Example.elm @@ -9,41 +9,7 @@ import Main exposing (..) suite : Test suite = describe "JSONAPI decoders" - [ test "streams decoder" <| - \_ -> - let - input = - """ - { - "links": { - "last": "/streams/head/forward/20", - "next": "/streams/all/backward/20" - }, - "data": [ - { - "id": "all", - "type": "streams" - } - ] - } - """ - - output = - Json.Decode.decodeString itemsDecoder input - in - Expect.equal output - (Ok - ({ items = [ StreamItem (Stream "all") ] - , links = - { prev = Nothing - , next = Just "/streams/all/backward/20" - , first = Nothing - , last = Just "/streams/head/forward/20" - } - } - ) - ) - , test "events decoder" <| + [ test "events decoder" <| \_ -> let input = @@ -74,18 +40,17 @@ suite = """ output = - Json.Decode.decodeString itemsDecoder input + Json.Decode.decodeString eventsDecoder input in Expect.equal output (Ok - ({ items = - [ EventItem - { eventType = "DummyEvent" - , eventId = "664ada1e-2f01-4ed0-9c16-63dbc82269d2" - , createdAt = "2017-12-20T23:49:45.273Z" - , rawData = "{\n \"foo\": 1,\n \"bar\": 2,\n \"baz\": \"3\"\n}" - , rawMetadata = "{\n \"timestamp\": \"2017-12-20T23:49:45.273Z\"\n}" - } + ({ events = + [ { eventType = "DummyEvent" + , eventId = "664ada1e-2f01-4ed0-9c16-63dbc82269d2" + , createdAt = "2017-12-20T23:49:45.273Z" + , rawData = "{\n \"foo\": 1,\n \"bar\": 2,\n \"baz\": \"3\"\n}" + , rawMetadata = "{\n \"timestamp\": \"2017-12-20T23:49:45.273Z\"\n}" + } ] , links = { next = Just "/streams/all/004ada1e-2f01-4ed0-9c16-63dbc82269d2/backward/20"