From fb3bb31b8717d5108de96190aafc27e5456d21db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:13:40 +0200 Subject: [PATCH 01/92] Revert "Always be closing" This reverts commit ac1b713df2db5dd028df3f361814c73e56085a61. --- ruby_event_store-browser/elm/src/Layout.elm | 5 +---- ruby_event_store-browser/public/bootstrap.js | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 543f7c8ce4..d4ae6c3920 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -56,9 +56,6 @@ port requestSearch : (() -> msg) -> Sub msg port requestSearchClose : (() -> msg) -> Sub msg -port closeSearch : String -> Cmd msg - - port toggleBookmark : String -> Cmd msg @@ -154,7 +151,7 @@ update msg model = ( model, toggleDialog searchModalId ) RequestSearchClose -> - ( model, closeSearch searchModalId ) + ( model, toggleDialog searchModalId ) ToggleBookmarksMenu -> ( { model | internal = Model model.internal.search (not model.internal.displayBookmarksMenu) model.internal.bookmarks }, Cmd.none ) diff --git a/ruby_event_store-browser/public/bootstrap.js b/ruby_event_store-browser/public/bootstrap.js index 7669f23bea..da8b98d3ae 100644 --- a/ruby_event_store-browser/public/bootstrap.js +++ b/ruby_event_store-browser/public/bootstrap.js @@ -11,10 +11,6 @@ app.ports.toggleDialog.subscribe(function (id) { dialog.open ? dialog.close() : dialog.showModal(); }); -app.ports.closeSearch.subscribe(function (id) { - document.querySelector(`#${id}`).close(); -}); - window.addEventListener("keydown", function (event) { if (event.key === "k" && (event.ctrlKey || event.metaKey)) { app.ports.requestSearch.send(null); From 39fad7d96627eb689431236440b18d1e8e913fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:13:45 +0200 Subject: [PATCH 02/92] Revert "Improve naming to better reveal the intention" This reverts commit 25cc5d8e1d77993df69f0e19f9d9ef87b49e1adb. --- ruby_event_store-browser/elm/src/Layout.elm | 8 ++++---- ruby_event_store-browser/public/bootstrap.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index d4ae6c3920..4309e919a3 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -29,7 +29,7 @@ type Msg | OnSelect Search.Stream | OnQueryChanged Search.Stream | RequestSearch - | RequestSearchClose + | CloseSearch | ToggleBookmark String @@ -53,7 +53,7 @@ port toggleDialog : String -> Cmd msg port requestSearch : (() -> msg) -> Sub msg -port requestSearchClose : (() -> msg) -> Sub msg +port closeSearch : (() -> msg) -> Sub msg port toggleBookmark : String -> Cmd msg @@ -63,7 +63,7 @@ subscriptions : Sub Msg subscriptions = Sub.batch [ requestSearch (always RequestSearch) - , requestSearchClose (always RequestSearchClose) + , closeSearch (always CloseSearch) ] @@ -150,7 +150,7 @@ update msg model = RequestSearch -> ( model, toggleDialog searchModalId ) - RequestSearchClose -> + CloseSearch -> ( model, toggleDialog searchModalId ) ToggleBookmarksMenu -> diff --git a/ruby_event_store-browser/public/bootstrap.js b/ruby_event_store-browser/public/bootstrap.js index da8b98d3ae..94b175ec0c 100644 --- a/ruby_event_store-browser/public/bootstrap.js +++ b/ruby_event_store-browser/public/bootstrap.js @@ -18,7 +18,7 @@ window.addEventListener("keydown", function (event) { } if (event.key === "Escape") { - app.ports.requestSearchClose.send(null); + app.ports.closeSearch.send(null); event.preventDefault(); } }); From 0225eb37dadb3108159e9e08098db1486c587977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:13:51 +0200 Subject: [PATCH 03/92] Revert "Kosher way to communicate via subscriptions" This reverts commit 76b8c186628c732440222dbccf53c9ff44f5de30. --- ruby_event_store-browser/elm/src/Layout.elm | 12 +----------- ruby_event_store-browser/public/bootstrap.js | 3 ++- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 4309e919a3..d0c5e0741f 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -29,7 +29,6 @@ type Msg | OnSelect Search.Stream | OnQueryChanged Search.Stream | RequestSearch - | CloseSearch | ToggleBookmark String @@ -53,18 +52,12 @@ port toggleDialog : String -> Cmd msg port requestSearch : (() -> msg) -> Sub msg -port closeSearch : (() -> msg) -> Sub msg - - port toggleBookmark : String -> Cmd msg subscriptions : Sub Msg subscriptions = - Sub.batch - [ requestSearch (always RequestSearch) - , closeSearch (always CloseSearch) - ] + requestSearch (always RequestSearch) buildModel : Model @@ -150,9 +143,6 @@ update msg model = RequestSearch -> ( model, toggleDialog searchModalId ) - CloseSearch -> - ( model, toggleDialog searchModalId ) - ToggleBookmarksMenu -> ( { model | internal = Model model.internal.search (not model.internal.displayBookmarksMenu) model.internal.bookmarks }, Cmd.none ) diff --git a/ruby_event_store-browser/public/bootstrap.js b/ruby_event_store-browser/public/bootstrap.js index 94b175ec0c..17eb71f537 100644 --- a/ruby_event_store-browser/public/bootstrap.js +++ b/ruby_event_store-browser/public/bootstrap.js @@ -18,7 +18,8 @@ window.addEventListener("keydown", function (event) { } if (event.key === "Escape") { - app.ports.closeSearch.send(null); + const dialog = document.querySelector(`#${id}`); + dialog.open ? dialog.close() : null; event.preventDefault(); } }); From 1504613cad33dc6ce031a93da69b09b0e06696d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:13:55 +0200 Subject: [PATCH 04/92] Revert "Move functions and helpers before place of use" This reverts commit e2bdbe6f1da04503de567be1d181addf8018c005. --- ruby_event_store-browser/elm/src/Search.elm | 112 ++++++++++---------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 69e1a9d8dd..943ec6591f 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -3,7 +3,7 @@ module Search exposing (..) import FeatherIcons import Html exposing (..) import Html.Attributes exposing (autofocus, class, href, placeholder, value) -import Html.Events exposing (onClick, onInput, onSubmit) +import Html.Events exposing (onInput, onSubmit, onClick) import List import Task @@ -25,16 +25,6 @@ type Msg | GoToStream Stream -emptyStreamName : Stream -emptyStreamName = - "" - - -emptyStreams : List Stream -emptyStreams = - [] - - init : (Stream -> a) -> (Stream -> a) -> Model a init onSelectMsg onQueryMsg = { streams = emptyStreams @@ -44,21 +34,6 @@ init onSelectMsg onQueryMsg = } -onSelectCmd : (Stream -> a) -> Stream -> Cmd a -onSelectCmd onSelectMsg stream = - Task.perform onSelectMsg (Task.succeed stream) - - -onQueryChangedCmd : (Stream -> a) -> Stream -> Cmd a -onQueryChangedCmd onQueryMsg stream = - Task.perform onQueryMsg (Task.succeed stream) - - -hasAtLeastThreeChars : Stream -> Bool -hasAtLeastThreeChars stream = - String.length stream >= 3 - - update : Msg -> Model a -> ( Model a, Cmd a ) update msg model = case msg of @@ -77,31 +52,6 @@ update msg model = ) -caseInsensitiveContains : Stream -> Stream -> Maybe Stream -caseInsensitiveContains needle haystack = - let - needleLower = - String.toLower needle - - haystackLower = - String.toLower haystack - in - if String.contains needleLower haystackLower then - Just haystack - - else - Nothing - - -filterStreams : Stream -> List Stream -> List Stream -filterStreams stream streams = - if String.isEmpty stream then - emptyStreams - - else - List.filterMap (caseInsensitiveContains stream) streams - - view : Model a -> Html Msg view model = let @@ -129,11 +79,6 @@ view model = ] -streamsPresent : List Stream -> Bool -streamsPresent streams = - not <| List.isEmpty streams - - viewStreamList : List Stream -> Html Msg viewStreamList streams = if streams |> streamsPresent then @@ -158,3 +103,58 @@ viewStreamListItem stream = ] [ text stream ] ] + + +emptyStreamName : Stream +emptyStreamName = + "" + + +emptyStreams : List Stream +emptyStreams = + [] + + +onSelectCmd : (Stream -> a) -> Stream -> Cmd a +onSelectCmd onSelectMsg stream = + Task.perform onSelectMsg (Task.succeed stream) + + +onQueryChangedCmd : (Stream -> a) -> Stream -> Cmd a +onQueryChangedCmd onQueryMsg stream = + Task.perform onQueryMsg (Task.succeed stream) + + +hasAtLeastThreeChars : Stream -> Bool +hasAtLeastThreeChars stream = + String.length stream >= 3 + + +streamsPresent : List Stream -> Bool +streamsPresent streams = + not <| List.isEmpty streams + + +filterStreams : Stream -> List Stream -> List Stream +filterStreams stream streams = + if String.isEmpty stream then + emptyStreams + + else + List.filterMap (caseInsensitiveContains stream) streams + + +caseInsensitiveContains : Stream -> Stream -> Maybe Stream +caseInsensitiveContains needle haystack = + let + needleLower = + String.toLower needle + + haystackLower = + String.toLower haystack + in + if String.contains needleLower haystackLower then + Just haystack + + else + Nothing From af8adf62b0adf2d45503df5d196aa5ad07602962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:00 +0200 Subject: [PATCH 05/92] Revert "Close search modal on Escape keypress" This reverts commit 10cf276bffa9a6ee8f9eb4b4b6d160b7df416df1. --- ruby_event_store-browser/public/bootstrap.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ruby_event_store-browser/public/bootstrap.js b/ruby_event_store-browser/public/bootstrap.js index 17eb71f537..f635744be2 100644 --- a/ruby_event_store-browser/public/bootstrap.js +++ b/ruby_event_store-browser/public/bootstrap.js @@ -16,12 +16,6 @@ window.addEventListener("keydown", function (event) { app.ports.requestSearch.send(null); event.preventDefault(); } - - if (event.key === "Escape") { - const dialog = document.querySelector(`#${id}`); - dialog.open ? dialog.close() : null; - event.preventDefault(); - } }); app.ports.toggleBookmark.subscribe(function (id) { From df4eaf625eaffd352e44beb50dcd46b2249c2636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:05 +0200 Subject: [PATCH 06/92] Revert "Close modal after clicking on stream from dropdown" This reverts commit 9b60202d880437a6b137dfc6e1e5b6f6ddb5a314. --- ruby_event_store-browser/elm/src/Search.elm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 943ec6591f..42ff44f97d 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -3,7 +3,7 @@ module Search exposing (..) import FeatherIcons import Html exposing (..) import Html.Attributes exposing (autofocus, class, href, placeholder, value) -import Html.Events exposing (onInput, onSubmit, onClick) +import Html.Events exposing (onInput, onSubmit) import List import Task @@ -99,7 +99,6 @@ viewStreamListItem stream = [ a [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono" , href ("/streams/" ++ stream) - , onClick (GoToStream stream) ] [ text stream ] ] From 3a099c47959d48fa1d2a4dc85c91acce00fe0bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:10 +0200 Subject: [PATCH 07/92] Revert "Do not assert specific adapter being used" This reverts commit fe9b7e4f027f47e83a1cf3527f3358045ae80f8d. --- ruby_event_store-active_record/spec/event_repository_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 1e87c14917..65865f1a5a 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -380,7 +380,7 @@ module ActiveRecord describe "#inspect" do specify "returns string representation" do - expect(repository.inspect).to eq("RubyEventStore::ActiveRecord::EventRepository with #{::ActiveRecord::Base.connection.adapter_name} db adapter") + expect(repository.inspect).to eq("RubyEventStore::ActiveRecord::EventRepository with SQLite db adapter") end end From bae7d77e95368ef8d3630ae8337300f797652248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:15 +0200 Subject: [PATCH 08/92] Revert "specification -> inspect, repository_specification -> inspect_repository" This reverts commit 33c90647d54abf7b66f61c74103e6544f3c6157c. --- .../active_record/event_repository.rb | 4 +-- .../spec/event_repository_spec.rb | 6 ---- .../lib/ruby_event_store/browser/app.rb | 2 +- .../lib/ruby_event_store/client.rb | 8 +++--- .../instrumented_repository.rb | 13 +++++---- ruby_event_store/spec/client_spec.rb | 16 ----------- .../spec/instrumented_repository_spec.rb | 28 ++++++------------- 7 files changed, 22 insertions(+), 55 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb index c7e4712e7c..4ef9a72b35 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb @@ -85,8 +85,8 @@ def event_in_stream?(event_id, stream) @repo_reader.event_in_stream?(event_id, stream) end - def inspect - "#{self.class} with #{::ActiveRecord::Base.connection.adapter_name} db adapter" + def specification + "#{self.class.name} with #{::ActiveRecord::Base.connection.adapter_name} db adapter" end private diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 65865f1a5a..0d188f18f3 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -378,12 +378,6 @@ module ActiveRecord }x end - describe "#inspect" do - specify "returns string representation" do - expect(repository.inspect).to eq("RubyEventStore::ActiveRecord::EventRepository with SQLite db adapter") - end - end - private def with_precision(time) diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb index b8b2e08fe1..022c8515be 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb @@ -172,7 +172,7 @@ def res_version end def repository_adapter - event_store.inspect_repository + event_store.repository_specification end end end diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index 2aa77f3ec1..98fc07e212 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -337,11 +337,11 @@ def inspect "#<#{self.class}:0x#{__id__.to_s(16)}>" end - def inspect_repository - if repository.public_method(:inspect).owner.equal?(Kernel) - repository.class.inspect + def repository_specification + if repository.respond_to?(:specification) + repository.specification else - repository.inspect + repository.class.to_s end end diff --git a/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb b/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb index b0a635974b..a5049e5e2d 100644 --- a/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb +++ b/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb @@ -61,12 +61,13 @@ def respond_to_missing?(method_name, _include_private) repository.respond_to?(method_name) end - def inspect - "Instrumented " + if repository.public_method(:inspect).owner.equal?(Kernel) - repository.class.inspect - else - repository.inspect - end + def specification + "Instrumented " + + if repository.respond_to?(:specification) + repository.specification + else + repository.class.to_s + end end private diff --git a/ruby_event_store/spec/client_spec.rb b/ruby_event_store/spec/client_spec.rb index 5ce529ef9a..996d937122 100644 --- a/ruby_event_store/spec/client_spec.rb +++ b/ruby_event_store/spec/client_spec.rb @@ -1001,21 +1001,5 @@ def event_id expect(client.event_in_stream?(fact.event_id, GLOBAL_STREAM)).to eq(true) expect(client.event_in_stream?("924acfb8-755d-4fd5-b758-f92423b6560a", GLOBAL_STREAM)).to eq(false) end - - describe "#inspect_repository" do - specify "repository class name is returned unless inspect is overridden" do - expect(client.inspect_repository).to eq("RubyEventStore::InMemoryRepository") - end - - specify "repository custom inspection string returned if defined" do - class CustomRepository - def inspect - "CustomInspectionString" - end - end - client = Client.new(repository: CustomRepository.new) - expect(client.inspect_repository).to eq("CustomInspectionString") - end - end end end diff --git a/ruby_event_store/spec/instrumented_repository_spec.rb b/ruby_event_store/spec/instrumented_repository_spec.rb index 8096cf1995..4243855a7d 100644 --- a/ruby_event_store/spec/instrumented_repository_spec.rb +++ b/ruby_event_store/spec/instrumented_repository_spec.rb @@ -171,23 +171,11 @@ module RubyEventStore end end - describe "inspect" do - it "'Instrumented ' + repository class name is returned unless inspect is overridden" do - SomeRepository = Class.new - instrumented_repository = InstrumentedRepository.new(SomeRepository.new, ActiveSupport::Notifications) - expect(instrumented_repository.inspect).to eq("Instrumented RubyEventStore::SomeRepository") - end - - specify "'Instrumented ' + repository custom inspection string returned if defined" do - class CustomRepository - def inspect - "CustomInspectionString" - end - end - - instrumented_repository = InstrumentedRepository.new(CustomRepository.new, ActiveSupport::Notifications) - client = Client.new(repository: instrumented_repository) - expect(client.inspect_repository).to eq("Instrumented CustomInspectionString") + describe "specification" do + it "present which repository is instrumented" do + some_repository = double("Some repository") + instrumented_repository = InstrumentedRepository.new(some_repository, ActiveSupport::Notifications) + expect(instrumented_repository.specification).to eq("Instrumented RSpec::Mocks::Double") end end @@ -209,9 +197,9 @@ def inspect expect(instrumented_repository).not_to respond_to(:arbitrary_method_name) expect { instrumented_repository.arbitrary_method_name }.to raise_error( - NoMethodError, - /undefined method `arbitrary_method_name' for .+RubyEventStore::InstrumentedRepository/ - ) + NoMethodError, + /undefined method `arbitrary_method_name' for .+RubyEventStore::InstrumentedRepository/ + ) end def subscribe_to(name) From c96755ca93f79042cb46377d21683c3d041b0d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:19 +0200 Subject: [PATCH 09/92] Revert "Hide conditionals from the Search view" This reverts commit 6ede4f8960bc9bdf30f61faffb4bcf1c3e0860bb. --- ruby_event_store-browser/elm/src/Search.elm | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 42ff44f97d..a7c60f93bc 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -75,22 +75,22 @@ view model = [ span [ class "text-gray-500 bg-gray-50 font-bold block p-1 border border-gray-300 rounded " ] [ text "ESC" ] ] ] - , viewStreamList streams_ + , if streams_ |> streamsPresent then + viewStreamList streams_ + + else + text "" ] viewStreamList : List Stream -> Html Msg viewStreamList streams = - if streams |> streamsPresent then - div - [] - [ ul - [ class "mt-4 overflow-auto space-y-2 w-full" ] - (List.map viewStreamListItem streams) - ] - - else - text "" + div + [] + [ ul + [ class "mt-4 overflow-auto space-y-2 w-full" ] + (List.map viewStreamListItem streams) + ] viewStreamListItem : Stream -> Html Msg From a526955434abd7bd92d62de30f2002d9b6e23691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:24 +0200 Subject: [PATCH 10/92] Revert "Only streams matter after refactoring" This reverts commit b560a356bd45e47af85fa341f0d6f11f1f340652. --- ruby_event_store-browser/elm/src/Search.elm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index a7c60f93bc..dc4974032f 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -76,15 +76,15 @@ view model = ] ] , if streams_ |> streamsPresent then - viewStreamList streams_ + viewStreamList model.value streams_ else text "" ] -viewStreamList : List Stream -> Html Msg -viewStreamList streams = +viewStreamList : Stream -> List Stream -> Html Msg +viewStreamList stream streams = div [] [ ul From debd4a590a0782911fc9f1280c3e1f867d6be0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:29 +0200 Subject: [PATCH 11/92] Revert "value always sounded odd to me" This reverts commit f43b1c911b19f2865b50ca245f80b7d518352a7c. --- ruby_event_store-browser/elm/src/Search.elm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index dc4974032f..faea699cd9 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -14,7 +14,7 @@ type alias Stream = type alias Model a = { streams : List Stream - , searchedStream : Stream + , value : Stream , onSelectMsg : Stream -> a , onQueryMsg : Stream -> a } @@ -28,7 +28,7 @@ type Msg init : (Stream -> a) -> (Stream -> a) -> Model a init onSelectMsg onQueryMsg = { streams = emptyStreams - , searchedStream = emptyStreamName + , value = emptyStreamName , onSelectMsg = onSelectMsg , onQueryMsg = onQueryMsg } @@ -39,15 +39,15 @@ update msg model = case msg of StreamChanged stream -> if hasAtLeastThreeChars stream then - ( { model | searchedStream = stream } + ( { model | value = stream } , onQueryChangedCmd model.onQueryMsg stream ) else - ( { model | searchedStream = stream }, Cmd.none ) + ( { model | value = stream }, Cmd.none ) GoToStream stream -> - ( { model | searchedStream = emptyStreamName } + ( { model | value = emptyStreamName } , onSelectCmd model.onSelectMsg stream ) @@ -56,16 +56,16 @@ view : Model a -> Html Msg view model = let streams_ = - filterStreams model.searchedStream model.streams + filterStreams model.value model.streams in - form [ onSubmit (GoToStream model.searchedStream) ] + form [ onSubmit (GoToStream model.value) ] [ div [ class "relative" ] [ FeatherIcons.search |> FeatherIcons.withClass "size-4 text-gray-400 absolute pointer-events-none top-3.5 left-2" |> FeatherIcons.toHtml [] , input [ class "rounded text-gray-800 cursor-pointer pl-8 pr-12 py-2 w-full appearance-none outline-none focus:ring-2 focus:ring-red-500 focus:ring-opacity-50" - , value model.searchedStream + , value model.value , onInput StreamChanged , placeholder "Quick search…" , autofocus True From aa9eef7add15b66a03f8e8d6559f442039a2ad66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:32 +0200 Subject: [PATCH 12/92] Revert "Utility function for empty streams list" This reverts commit 1af9fab385dc148ffe337660c9f0cbf044d93b9c. --- ruby_event_store-browser/elm/src/Search.elm | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index faea699cd9..59b05a3282 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -27,7 +27,7 @@ type Msg init : (Stream -> a) -> (Stream -> a) -> Model a init onSelectMsg onQueryMsg = - { streams = emptyStreams + { streams = [] , value = emptyStreamName , onSelectMsg = onSelectMsg , onQueryMsg = onQueryMsg @@ -109,11 +109,6 @@ emptyStreamName = "" -emptyStreams : List Stream -emptyStreams = - [] - - onSelectCmd : (Stream -> a) -> Stream -> Cmd a onSelectCmd onSelectMsg stream = Task.perform onSelectMsg (Task.succeed stream) @@ -137,7 +132,7 @@ streamsPresent streams = filterStreams : Stream -> List Stream -> List Stream filterStreams stream streams = if String.isEmpty stream then - emptyStreams + [] else List.filterMap (caseInsensitiveContains stream) streams From c92200a1e3c66480755d4d0b787991ecc97b25b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:36 +0200 Subject: [PATCH 13/92] Revert "Filter visible streams early in the view" This reverts commit 88b53fa05d6345660104d2d821c0330e8672edcb. --- ruby_event_store-browser/elm/src/Search.elm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 59b05a3282..759b7cc5ae 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -54,10 +54,6 @@ update msg model = view : Model a -> Html Msg view model = - let - streams_ = - filterStreams model.value model.streams - in form [ onSubmit (GoToStream model.value) ] [ div [ class "relative" ] [ FeatherIcons.search @@ -75,21 +71,24 @@ view model = [ span [ class "text-gray-500 bg-gray-50 font-bold block p-1 border border-gray-300 rounded " ] [ text "ESC" ] ] ] - , if streams_ |> streamsPresent then - viewStreamList model.value streams_ + , if model |> streamsPresent then + viewStreamList model else text "" ] -viewStreamList : Stream -> List Stream -> Html Msg -viewStreamList stream streams = +viewStreamList : Model a -> Html Msg +viewStreamList { value, streams } = div [] [ ul [ class "mt-4 overflow-auto space-y-2 w-full" ] - (List.map viewStreamListItem streams) + (streams + |> filterStreams value + |> List.map viewStreamListItem + ) ] @@ -124,8 +123,8 @@ hasAtLeastThreeChars stream = String.length stream >= 3 -streamsPresent : List Stream -> Bool -streamsPresent streams = +streamsPresent : Model a -> Bool +streamsPresent { streams } = not <| List.isEmpty streams From e4578fb54112c8cb062ec01324df4c1ade5972fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:42 +0200 Subject: [PATCH 14/92] Revert "Clientside filtering is case insensitive now" This reverts commit a87d7f69519b115b3c93fbc79d9c5f02010cea7f. --- ruby_event_store-browser/elm/src/Search.elm | 18 +----------------- .../elm/tests/SearchTest.elm | 7 +------ 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 759b7cc5ae..1d901feb73 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -134,20 +134,4 @@ filterStreams stream streams = [] else - List.filterMap (caseInsensitiveContains stream) streams - - -caseInsensitiveContains : Stream -> Stream -> Maybe Stream -caseInsensitiveContains needle haystack = - let - needleLower = - String.toLower needle - - haystackLower = - String.toLower haystack - in - if String.contains needleLower haystackLower then - Just haystack - - else - Nothing + List.filter (String.contains stream) streams diff --git a/ruby_event_store-browser/elm/tests/SearchTest.elm b/ruby_event_store-browser/elm/tests/SearchTest.elm index 19b53ddd74..9d15d97d3a 100644 --- a/ruby_event_store-browser/elm/tests/SearchTest.elm +++ b/ruby_event_store-browser/elm/tests/SearchTest.elm @@ -1,7 +1,7 @@ module SearchTest exposing (suite) import Expect -import Search exposing (filterStreams) +import Search exposing (Stream, filterStreams) import Test exposing (..) @@ -29,10 +29,5 @@ suite = Expect.equal [ "DummyStream$78" ] (filterStreams "78" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams is case insensitive" <| - \_ -> - Expect.equal - [ "DummyStream$78", "DummyStream$79" ] - (filterStreams "stream" [ "DummyStream$78", "DummyStream$79" ]) ] ] From bd070eac8a746a16304b6c0b756ab55d7f6f9a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:46 +0200 Subject: [PATCH 15/92] =?UTF-8?q?Revert=20"Improved=20non=E2=80=93matching?= =?UTF-8?q?=20stream=20names=20clearing"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 2bb07e6f947673acc30519e4866901bb6ebf3486. --- ruby_event_store-browser/elm/src/Search.elm | 18 ++-------- .../elm/tests/SearchTest.elm | 33 ------------------- 2 files changed, 3 insertions(+), 48 deletions(-) delete mode 100644 ruby_event_store-browser/elm/tests/SearchTest.elm diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 1d901feb73..87fa5ac6af 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -44,7 +44,7 @@ update msg model = ) else - ( { model | value = stream }, Cmd.none ) + ( { model | value = stream, streams = [] }, Cmd.none ) GoToStream stream -> ( { model | value = emptyStreamName } @@ -80,15 +80,12 @@ view model = viewStreamList : Model a -> Html Msg -viewStreamList { value, streams } = +viewStreamList model = div [] [ ul [ class "mt-4 overflow-auto space-y-2 w-full" ] - (streams - |> filterStreams value - |> List.map viewStreamListItem - ) + (List.map (\stream -> viewStreamListItem stream) model.streams) ] @@ -126,12 +123,3 @@ hasAtLeastThreeChars stream = streamsPresent : Model a -> Bool streamsPresent { streams } = not <| List.isEmpty streams - - -filterStreams : Stream -> List Stream -> List Stream -filterStreams stream streams = - if String.isEmpty stream then - [] - - else - List.filter (String.contains stream) streams diff --git a/ruby_event_store-browser/elm/tests/SearchTest.elm b/ruby_event_store-browser/elm/tests/SearchTest.elm deleted file mode 100644 index 9d15d97d3a..0000000000 --- a/ruby_event_store-browser/elm/tests/SearchTest.elm +++ /dev/null @@ -1,33 +0,0 @@ -module SearchTest exposing (suite) - -import Expect -import Search exposing (Stream, filterStreams) -import Test exposing (..) - - -suite : Test -suite = - describe "Suite" - [ describe "filter streams" <| - [ test "filterStreams starting with" <| - \_ -> - Expect.equal - [ "DummyStream$78", "DummyStream$79" ] - (filterStreams "Dum" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams empty" <| - \_ -> - Expect.equal - [] - (filterStreams "" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams non matching" <| - \_ -> - Expect.equal - [] - (filterStreams "foo" [ "DummyStream$78", "DummyStream$79" ]) - , test "filterStreams ending with" <| - \_ -> - Expect.equal - [ "DummyStream$78" ] - (filterStreams "78" [ "DummyStream$78", "DummyStream$79" ]) - ] - ] From b27668f71a3e9170ab9824200671bcf2b7251f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:50 +0200 Subject: [PATCH 16/92] Revert "Extract list item to view" This reverts commit 84240873cad08f3d70b6d311be19654461df76d9. --- ruby_event_store-browser/elm/src/Search.elm | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 87fa5ac6af..151cb45639 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -83,20 +83,19 @@ viewStreamList : Model a -> Html Msg viewStreamList model = div [] - [ ul - [ class "mt-4 overflow-auto space-y-2 w-full" ] - (List.map (\stream -> viewStreamListItem stream) model.streams) - ] - - -viewStreamListItem : Stream -> Html Msg -viewStreamListItem stream = - li [] - [ a - [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono" - , href ("/streams/" ++ stream) - ] - [ text stream ] + [ ul [ class "mt-4 h-80 overflow-auto space-y-2 w-full" ] + (List.map + (\stream -> + li [] + [ a + [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono" + , href ("/streams/" ++ stream) + ] + [ text stream ] + ] + ) + model.streams + ) ] From 46badcc9bdea047c05bc502cd42e0c0da091eafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:54 +0200 Subject: [PATCH 17/92] Revert "Clear streams when deleting last 3 characters" This reverts commit 372dc97ad6af99e36bcb4ae0050d7bc9bf3b61af. --- ruby_event_store-browser/elm/src/Search.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 151cb45639..3422e8c6be 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -44,7 +44,7 @@ update msg model = ) else - ( { model | value = stream, streams = [] }, Cmd.none ) + ( { model | value = stream }, Cmd.none ) GoToStream stream -> ( { model | value = emptyStreamName } From 3197f9218541090a540c90511f958ace94e63ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:14:57 +0200 Subject: [PATCH 18/92] Revert "More specific naming" This reverts commit c7e895004d6f56f3af33a753d04332da56408d69. --- ruby_event_store-browser/elm/src/Search.elm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 3422e8c6be..a7430815b1 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -72,15 +72,15 @@ view model = ] ] , if model |> streamsPresent then - viewStreamList model + viewList model else text "" ] -viewStreamList : Model a -> Html Msg -viewStreamList model = +viewList : Model a -> Html Msg +viewList model = div [] [ ul [ class "mt-4 h-80 overflow-auto space-y-2 w-full" ] From 5f6c47d4a62b142c974cdd642fa6cf963f544143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:15:02 +0200 Subject: [PATCH 19/92] Revert "Break lines, not bones" This reverts commit 6c2bb94fbd7b111afe1bf15e5d6c708e0290cad0. --- ruby_event_store-browser/elm/src/Search.elm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index a7430815b1..ff6a033600 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -87,11 +87,7 @@ viewList model = (List.map (\stream -> li [] - [ a - [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono" - , href ("/streams/" ++ stream) - ] - [ text stream ] + [ a [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono", href ("/streams/" ++ stream) ] [ text stream ] ] ) model.streams From b097db15dfd54ed1e8c7a0e433cc504ffa36f2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:15:08 +0200 Subject: [PATCH 20/92] Revert "Move helper functions to bottom of the module" This reverts commit c3a6fcee59a6b97c595b633f6ce4403e0b35a7a0. --- ruby_event_store-browser/elm/src/Search.elm | 40 ++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index ff6a033600..b54f90d32e 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -25,6 +25,11 @@ type Msg | GoToStream Stream +emptyStreamName : Stream +emptyStreamName = + "" + + init : (Stream -> a) -> (Stream -> a) -> Model a init onSelectMsg onQueryMsg = { streams = [] @@ -34,6 +39,21 @@ init onSelectMsg onQueryMsg = } +onSelectCmd : (Stream -> a) -> Stream -> Cmd a +onSelectCmd onSelectMsg stream = + Task.perform onSelectMsg (Task.succeed stream) + + +onQueryChangedCmd : (Stream -> a) -> Stream -> Cmd a +onQueryChangedCmd onQueryMsg stream = + Task.perform onQueryMsg (Task.succeed stream) + + +hasAtLeastThreeChars : Stream -> Bool +hasAtLeastThreeChars stream = + String.length stream >= 3 + + update : Msg -> Model a -> ( Model a, Cmd a ) update msg model = case msg of @@ -95,26 +115,6 @@ viewList model = ] -emptyStreamName : Stream -emptyStreamName = - "" - - -onSelectCmd : (Stream -> a) -> Stream -> Cmd a -onSelectCmd onSelectMsg stream = - Task.perform onSelectMsg (Task.succeed stream) - - -onQueryChangedCmd : (Stream -> a) -> Stream -> Cmd a -onQueryChangedCmd onQueryMsg stream = - Task.perform onQueryMsg (Task.succeed stream) - - -hasAtLeastThreeChars : Stream -> Bool -hasAtLeastThreeChars stream = - String.length stream >= 3 - - streamsPresent : Model a -> Bool streamsPresent { streams } = not <| List.isEmpty streams From e3e3c30dd4194eb08d6a617691012f24863ae31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:15:15 +0200 Subject: [PATCH 21/92] Revert "Replace use of datalist with ul" This reverts commit 1227afe7647eb32be3d8d4a46a47f0afe84407f4. --- ruby_event_store-browser/elm/src/Search.elm | 29 ++++----------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index b54f90d32e..fa30bb0223 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -2,7 +2,7 @@ module Search exposing (..) import FeatherIcons import Html exposing (..) -import Html.Attributes exposing (autofocus, class, href, placeholder, value) +import Html.Attributes exposing (autofocus, class, id, list, placeholder, value) import Html.Events exposing (onInput, onSubmit) import List import Task @@ -84,6 +84,7 @@ view model = , value model.value , onInput StreamChanged , placeholder "Quick search…" + , list "streams" , autofocus True ] [] @@ -91,30 +92,10 @@ view model = [ span [ class "text-gray-500 bg-gray-50 font-bold block p-1 border border-gray-300 rounded " ] [ text "ESC" ] ] ] - , if model |> streamsPresent then - viewList model - - else - text "" - ] - - -viewList : Model a -> Html Msg -viewList model = - div - [] - [ ul [ class "mt-4 h-80 overflow-auto space-y-2 w-full" ] + , datalist + [ id "streams", class "appearance-none" ] (List.map - (\stream -> - li [] - [ a [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono", href ("/streams/" ++ stream) ] [ text stream ] - ] - ) + (\stream -> option [] [ text stream ]) model.streams ) ] - - -streamsPresent : Model a -> Bool -streamsPresent { streams } = - not <| List.isEmpty streams From 45a5177bcef004cf0da9a9a28df313ddecd7321f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:15:29 +0200 Subject: [PATCH 22/92] Revert "Doh" This reverts commit 28cbbac40db187b1f8e80648d4de899a95109124. --- ruby_event_store-browser/elm/src/Layout.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index d0c5e0741f..3de863ab4a 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -259,7 +259,7 @@ browserFooter { flags, time } = timeZoneSelect time = let mkOption timeZone = - option [ value timeZone.zoneName, selected <| timeZone == time.selected ] [ text timeZone.zoneName ] + option [ value timeZone.zoneName, selected ((==) time.selected) ] [ text timeZone.zoneName ] in Html.select [ onInput TimeZoneSelected ] From 1764691940adc86fb5f22956b97d6c9e73d4718e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:16:06 +0200 Subject: [PATCH 23/92] Revert "Refactor" This reverts commit 5a8b4687dfec82a714ccb7fb75f5c690d84733f1. --- ruby_event_store-browser/elm/src/Layout.elm | 42 ++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 3de863ab4a..d5a9ef4c22 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -1,7 +1,6 @@ port module Layout exposing (Model, Msg, buildModel, subscriptions, update, view, viewIncorrectConfig, viewNotFound) import Api exposing (SearchStream, getSearchStreams) -import Browser exposing (Document) import Browser.Navigation import BrowserTime import Dict @@ -231,10 +230,9 @@ browserFooter : WrappedModel Model -> Html Msg browserFooter { flags, time } = let spacer = - span [ class "ml-4 font-bold inline-block text-gray-400" ] [ text "•" ] - - link label url = - a [ href url, class "ml-4" ] [ text label ] + span + [ class "ml-4 font-bold inline-block text-gray-400" ] + [ text "•" ] in footer [ class "border-gray-400 border-t py-4 px-8 flex justify-between" ] @@ -242,11 +240,23 @@ browserFooter { flags, time } = [ class "text-gray-500 text-sm" ] [ text ("RubyEventStore v" ++ flags.resVersion) , spacer - , link "Documentation" "https://railseventstore.org/docs/install/" + , a + [ href "https://railseventstore.org/docs/install/" + , class "ml-4" + ] + [ text "Documentation" ] , spacer - , link "Support" "https://railseventstore.org/support/" + , a + [ href "https://railseventstore.org/support/" + , class "ml-4" + ] + [ text "Support" ] , spacer - , link "Debug" (Route.debugUrl flags.rootUrl) + , a + [ href (Route.debugUrl flags.rootUrl) + , class "ml-4" + ] + [ text "Debug" ] ] , div [ class "text-gray-500 text-sm flex item-center gap-2" ] @@ -257,13 +267,19 @@ browserFooter { flags, time } = timeZoneSelect time = - let - mkOption timeZone = - option [ value timeZone.zoneName, selected ((==) time.selected) ] [ text timeZone.zoneName ] - in Html.select [ onInput TimeZoneSelected ] - (availableTimeZones time.detected |> List.map mkOption) + (List.map + (\timeZone -> + option + [ value timeZone.zoneName + , selected (timeZone == time.selected) + ] + [ text timeZone.zoneName + ] + ) + (availableTimeZones time.detected) + ) visibleBookmarksMenu : Bool -> String From 5eca1620f038505876c8486e68848dd2ea72b625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:16:17 +0200 Subject: [PATCH 24/92] Revert "Prefer same variable" This reverts commit 1c110493376f2d4918f174ded44d948391030f2e. --- ruby_event_store-browser/elm/src/Search.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index fa30bb0223..06185f3fe8 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -72,7 +72,7 @@ update msg model = ) -view : Model a -> Html Msg +view : Model msg -> Html Msg view model = form [ onSubmit (GoToStream model.value) ] [ div [ class "relative" ] From b3a192ed4d5e3e3187a1bbb703eae737398f2f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:16:21 +0200 Subject: [PATCH 25/92] Revert "One more formatter round" This reverts commit 974d1b66612ff6992304be8e815f62f19d748f96. --- ruby_event_store-browser/elm/src/Api.elm | 17 ++++------------- ruby_event_store-browser/elm/src/Main.elm | 20 +++++++++----------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index 5588e6cde4..4296e7db1c 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -1,9 +1,9 @@ -module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), SearchStream, Stats, Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getSearchStreams, getStats, getStream, searchStreamsDecoder) +module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), SearchStream, Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getSearchStreams, getStream, searchStreamsDecoder, Stats, getStats) import Flags exposing (Flags) import Http import Iso8601 -import Json.Decode exposing (Decoder, field, int, list, maybe, string, succeed, value) +import Json.Decode exposing (Decoder, field, list, maybe, string, succeed, value, int) import Json.Decode.Pipeline exposing (optional, optionalAt, required, requiredAt) import Json.Encode exposing (encode) import Maybe.Extra @@ -42,12 +42,10 @@ type alias SearchStream = { streamId : String } - type alias Stats = - { eventsInTotal : Int + { eventsInTotal: Int } - type alias PaginatedList a = { pagination : Pagination.Specification , events : List a @@ -98,12 +96,10 @@ searchStreamsUrl : Flags -> String -> String searchStreamsUrl flags query = buildUrl (Url.toString flags.apiUrl ++ "/search_streams") query - getStatsUrl : Flags -> String getStatsUrl flags = Url.toString flags.apiUrl ++ "/stats" - getEvent : (Result Http.Error Event -> msg) -> Flags -> String -> Cmd msg getEvent msgBuilder flags eventId = Http.get @@ -127,15 +123,13 @@ getSearchStreams msgBuilder flags query = , expect = Http.expectJson msgBuilder searchStreamsDecoder } - -getStats : (Result Http.Error Stats -> msg) -> Flags -> Cmd msg +getStats : (Result Http.Error (Stats) -> msg) -> Flags -> Cmd msg getStats msgBuilder flags = Http.get { url = getStatsUrl flags , expect = Http.expectJson msgBuilder statsDecoder } - eventDecoder : Decoder Event eventDecoder = eventDecoder_ @@ -201,19 +195,16 @@ searchStreamsDecoder = list searchStreamDecoder |> field "data" - statsDecoder : Decoder Stats statsDecoder = statsDecoder_ |> field "meta" - statsDecoder_ : Decoder Stats statsDecoder_ = succeed Stats |> required "events_in_total" int - linksDecoder : Decoder PaginationLinks linksDecoder = succeed PaginationLinks diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index c610bf064a..979c5fa74e 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -11,6 +11,7 @@ import LinkedTimezones exposing (mapLinkedTimeZone) import Page.Debug import Page.ShowEvent import Page.ShowStream +import Page.Debug import Route import Task import Time @@ -52,7 +53,6 @@ type Msg | ReceiveTimeZone (Result String Time.ZoneName) | GotDebugMsg Page.Debug.Msg - type Page = NotFound | ShowEvent Page.ShowEvent.Model @@ -133,12 +133,13 @@ update msg model = ( GotDebugMsg gotDebugMsg, Debug debugModel ) -> let - ( subModel, subCmd ) = + (subModel, subCmd) = Page.Debug.update gotDebugMsg debugModel in - ( { model | page = Debug subModel } - , Cmd.map GotDebugMsg subCmd - ) + ({model | page = Debug subModel} + , Cmd.map GotDebugMsg subCmd + ) + ( GotLayoutMsg layoutMsg, _ ) -> case model.flags of @@ -224,13 +225,10 @@ navigate model location = Nothing -> ( { model | page = NotFound }, Cmd.none ) - Just Route.Debug -> + Just (Route.Debug) -> let - page = - Page.Debug.init flags - - cmd = - Page.Debug.initCmd flags + page = Page.Debug.init flags + cmd = Page.Debug.initCmd flags in ( { model | page = Debug page }, Cmd.map GotDebugMsg cmd ) From 4c17d12b8cf8c59f0b534c542b8542f11d33fa7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:16:25 +0200 Subject: [PATCH 26/92] Revert "Remove autosubmit of matching stream name" This reverts commit d28d3e653390aac9994e8b90d20fd6cddcc7a535. --- ruby_event_store-browser/elm/src/Search.elm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 06185f3fe8..5ad91bcb3f 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -49,6 +49,11 @@ onQueryChangedCmd onQueryMsg stream = Task.perform onQueryMsg (Task.succeed stream) +isExactStream : Stream -> List Stream -> Bool +isExactStream stream streams = + List.any ((==) stream) streams + + hasAtLeastThreeChars : Stream -> Bool hasAtLeastThreeChars stream = String.length stream >= 3 @@ -58,7 +63,12 @@ update : Msg -> Model a -> ( Model a, Cmd a ) update msg model = case msg of StreamChanged stream -> - if hasAtLeastThreeChars stream then + if isExactStream stream model.streams then + ( { model | value = emptyStreamName } + , onSelectCmd model.onSelectMsg stream + ) + + else if hasAtLeastThreeChars stream then ( { model | value = stream } , onQueryChangedCmd model.onQueryMsg stream ) From 091c1cdb9bc934da69fb0f5f1f96cb8912ff3556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:32:40 +0200 Subject: [PATCH 27/92] Revert "Dead code" This reverts commit de9eca0189ffdda5979979081fc3174b97f10c8d. --- .../elm/src/Page/ShowStream.elm | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Page/ShowStream.elm b/ruby_event_store-browser/elm/src/Page/ShowStream.elm index 90247a0040..e7a093772a 100644 --- a/ruby_event_store-browser/elm/src/Page/ShowStream.elm +++ b/ruby_event_store-browser/elm/src/Page/ShowStream.elm @@ -22,6 +22,7 @@ type alias Model = , relatedStreams : Maybe (List String) , problems : List Problem , pagination : Pagination.Specification + , searchStreams : List Api.SearchStream } @@ -37,6 +38,7 @@ initModel flags streamName paginationSpecification = , flags = flags , problems = [] , pagination = paginationSpecification + , searchStreams = [] } @@ -47,6 +49,7 @@ initModel flags streamName paginationSpecification = type Msg = EventsFetched (Result Http.Error (Api.PaginatedList Api.Event)) | StreamFetched (Result Http.Error Api.Stream) + | SearchedStreamsFetched (Result Http.Error (List Api.SearchStream)) initCmd : Flags -> String -> Cmd Msg @@ -77,9 +80,15 @@ update msg model = in ( { model | problems = serverErrors }, Cmd.none ) + SearchedStreamsFetched (Ok result) -> + ( { model | searchStreams = result }, Cmd.none ) + + SearchedStreamsFetched (Err _) -> + ( model, Cmd.none ) + view : Model -> BrowserTime.TimeZone -> ( String, Html Msg ) -view { streamName, events, relatedStreams, problems, flags } selectedTime = +view { streamName, events, relatedStreams, problems, flags, pagination, searchStreams } selectedTime = let title = "Stream " ++ streamName @@ -90,7 +99,7 @@ view { streamName, events, relatedStreams, problems, flags } selectedTime = case problems of [] -> ( title - , browseEvents flags.rootUrl header streamName events relatedStreams selectedTime + , browseEvents flags.rootUrl header streamName events relatedStreams selectedTime searchStreams ) _ -> @@ -106,8 +115,8 @@ view { streamName, events, relatedStreams, problems, flags } selectedTime = ) -browseEvents : Url.Url -> String -> String -> Api.PaginatedList Api.Event -> Maybe (List String) -> BrowserTime.TimeZone -> Html Msg -browseEvents baseUrl title streamName { links, events } relatedStreams timeZone = +browseEvents : Url.Url -> String -> String -> Api.PaginatedList Api.Event -> Maybe (List String) -> BrowserTime.TimeZone -> List Api.SearchStream -> Html Msg +browseEvents baseUrl title streamName { links, events } relatedStreams timeZone searchStreams = div [ class "py-8 container mx-auto" ] [ div [ class "flex justify-between" ] @@ -118,6 +127,7 @@ browseEvents baseUrl title streamName { links, events } relatedStreams timeZone ] , div [] [ renderResults baseUrl events timeZone ] , div [] [ renderRelatedStreams baseUrl relatedStreams ] + , div [ class "bg-red-500" ] [ renderSearchStreams searchStreams ] ] @@ -132,6 +142,12 @@ viewProblem problem = li [] [ text errorMessage ] +renderSearchStreams : List Api.SearchStream -> Html msg +renderSearchStreams searchStreams = + ul [] + (List.map (\searchStream -> li [] [ text searchStream.streamId ]) searchStreams) + + renderRelatedStreams : Url.Url -> Maybe (List String) -> Html Msg renderRelatedStreams baseUrl relatedStreams_ = case relatedStreams_ of From b5272d511c9cc97a64abfe07fa89943daeb8a523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:32:48 +0200 Subject: [PATCH 28/92] Revert "formatting" This reverts commit df409f4dabcf6b09e8fd5e5a05096609756cde92. --- .../elm/src/Page/Debug.elm | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Page/Debug.elm b/ruby_event_store-browser/elm/src/Page/Debug.elm index 63d9c47489..db3fa8d655 100644 --- a/ruby_event_store-browser/elm/src/Page/Debug.elm +++ b/ruby_event_store-browser/elm/src/Page/Debug.elm @@ -1,45 +1,37 @@ module Page.Debug exposing (..) -import Api exposing (Stats, getStats) -import Flags exposing (Flags) import Html exposing (..) +import Flags exposing (Flags) +import Api exposing (getStats, Stats) import Http - -type alias Model = - { resVersion : String, repositoryAdapter : String, eventsInTotal : String } - +type alias Model = { resVersion : String, repositoryAdapter : String, eventsInTotal : String } type Msg - = GotStats (Result Http.Error Stats) - + = GotStats (Result Http.Error Stats) init : Flags -> Model -init flags = +init flags = { resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter, eventsInTotal = "" } - initCmd : Flags -> Cmd Msg initCmd flags = getStats GotStats flags - -view : Model -> Html a +view: Model -> Html a view model = - div [] - [ p [] [ text ("RubyEventStore version: " ++ model.resVersion) ] - , p [] [ text ("RubyEventStore adapter: " ++ model.repositoryAdapter) ] - , p [] [ text ("Events in total: " ++ model.eventsInTotal) ] - ] + div [] [ + p [] [text ("RubyEventStore version: " ++ model.resVersion)], + p [] [text ("RubyEventStore adapter: " ++ model.repositoryAdapter)], + p [] [text ("Events in total: " ++ model.eventsInTotal)] + ] - -update : Msg -> Model -> ( Model, Cmd Msg ) +update : Msg -> Model -> (Model, Cmd Msg) update msg model = - case msg of - GotStats result -> - case result of - Ok stats -> - ( { model | eventsInTotal = String.fromInt stats.eventsInTotal }, Cmd.none ) - - Err _ -> - ( model, Cmd.none ) + case msg of + GotStats result -> + case result of + Ok stats -> + ({ model | eventsInTotal = String.fromInt stats.eventsInTotal }, Cmd.none) + Err _ -> + (model, Cmd.none) \ No newline at end of file From 6df184e66d66246a600a7b56e46d18988c3928a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:32:54 +0200 Subject: [PATCH 29/92] Revert "Add total events counter to the debug page" This reverts commit 4376e1fc098784457d43582d60e7c81b3a274f87. --- ruby_event_store-browser/elm/src/Api.elm | 25 +----------- ruby_event_store-browser/elm/src/Main.elm | 21 ++-------- .../elm/src/Page/Debug.elm | 38 ++++++------------- .../lib/ruby_event_store/browser.rb | 1 - .../lib/ruby_event_store/browser/app.rb | 6 +-- .../lib/ruby_event_store/browser/get_stats.rb | 27 ------------- .../spec/api/stats_spec.rb | 16 -------- 7 files changed, 17 insertions(+), 117 deletions(-) delete mode 100644 ruby_event_store-browser/lib/ruby_event_store/browser/get_stats.rb delete mode 100644 ruby_event_store-browser/spec/api/stats_spec.rb diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index 4296e7db1c..6ed645f59a 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -1,9 +1,9 @@ -module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), SearchStream, Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getSearchStreams, getStream, searchStreamsDecoder, Stats, getStats) +module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), SearchStream, Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getSearchStreams, getStream, searchStreamsDecoder) import Flags exposing (Flags) import Http import Iso8601 -import Json.Decode exposing (Decoder, field, list, maybe, string, succeed, value, int) +import Json.Decode exposing (Decoder, field, list, maybe, string, succeed, value) import Json.Decode.Pipeline exposing (optional, optionalAt, required, requiredAt) import Json.Encode exposing (encode) import Maybe.Extra @@ -42,9 +42,6 @@ type alias SearchStream = { streamId : String } -type alias Stats = - { eventsInTotal: Int - } type alias PaginatedList a = { pagination : Pagination.Specification @@ -96,9 +93,6 @@ searchStreamsUrl : Flags -> String -> String searchStreamsUrl flags query = buildUrl (Url.toString flags.apiUrl ++ "/search_streams") query -getStatsUrl : Flags -> String -getStatsUrl flags = - Url.toString flags.apiUrl ++ "/stats" getEvent : (Result Http.Error Event -> msg) -> Flags -> String -> Cmd msg getEvent msgBuilder flags eventId = @@ -123,12 +117,6 @@ getSearchStreams msgBuilder flags query = , expect = Http.expectJson msgBuilder searchStreamsDecoder } -getStats : (Result Http.Error (Stats) -> msg) -> Flags -> Cmd msg -getStats msgBuilder flags = - Http.get - { url = getStatsUrl flags - , expect = Http.expectJson msgBuilder statsDecoder - } eventDecoder : Decoder Event eventDecoder = @@ -195,15 +183,6 @@ searchStreamsDecoder = list searchStreamDecoder |> field "data" -statsDecoder : Decoder Stats -statsDecoder = - statsDecoder_ - |> field "meta" - -statsDecoder_ : Decoder Stats -statsDecoder_ = - succeed Stats - |> required "events_in_total" int linksDecoder : Decoder PaginationLinks linksDecoder = diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index 979c5fa74e..0bb2dec205 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -11,7 +11,6 @@ import LinkedTimezones exposing (mapLinkedTimeZone) import Page.Debug import Page.ShowEvent import Page.ShowStream -import Page.Debug import Route import Task import Time @@ -51,7 +50,7 @@ type Msg | GotShowEventMsg Page.ShowEvent.Msg | GotShowStreamMsg Page.ShowStream.Msg | ReceiveTimeZone (Result String Time.ZoneName) - | GotDebugMsg Page.Debug.Msg + type Page = NotFound @@ -131,16 +130,6 @@ update msg model = , Cmd.map GotShowEventMsg subCmd ) - ( GotDebugMsg gotDebugMsg, Debug debugModel ) -> - let - (subModel, subCmd) = - Page.Debug.update gotDebugMsg debugModel - in - ({model | page = Debug subModel} - , Cmd.map GotDebugMsg subCmd - ) - - ( GotLayoutMsg layoutMsg, _ ) -> case model.flags of Nothing -> @@ -225,12 +214,8 @@ navigate model location = Nothing -> ( { model | page = NotFound }, Cmd.none ) - Just (Route.Debug) -> - let - page = Page.Debug.init flags - cmd = Page.Debug.initCmd flags - in - ( { model | page = Debug page }, Cmd.map GotDebugMsg cmd ) + Just Route.Debug -> + ( { model | page = Debug (Page.Debug.init flags) }, Cmd.none ) Nothing -> ( { model | page = NotFound }, Cmd.none ) diff --git a/ruby_event_store-browser/elm/src/Page/Debug.elm b/ruby_event_store-browser/elm/src/Page/Debug.elm index db3fa8d655..c5cf926cdc 100644 --- a/ruby_event_store-browser/elm/src/Page/Debug.elm +++ b/ruby_event_store-browser/elm/src/Page/Debug.elm @@ -1,37 +1,21 @@ module Page.Debug exposing (..) -import Html exposing (..) import Flags exposing (Flags) -import Api exposing (getStats, Stats) -import Http +import Html exposing (..) -type alias Model = { resVersion : String, repositoryAdapter : String, eventsInTotal : String } -type Msg - = GotStats (Result Http.Error Stats) +type alias Model = + { resVersion : String, repositoryAdapter : String } + init : Flags -> Model -init flags = - { resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter, eventsInTotal = "" } +init flags = + { resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter } -initCmd : Flags -> Cmd Msg -initCmd flags = - getStats GotStats flags -view: Model -> Html a +view : Model -> Html a view model = - div [] [ - p [] [text ("RubyEventStore version: " ++ model.resVersion)], - p [] [text ("RubyEventStore adapter: " ++ model.repositoryAdapter)], - p [] [text ("Events in total: " ++ model.eventsInTotal)] - ] - -update : Msg -> Model -> (Model, Cmd Msg) -update msg model = - case msg of - GotStats result -> - case result of - Ok stats -> - ({ model | eventsInTotal = String.fromInt stats.eventsInTotal }, Cmd.none) - Err _ -> - (model, Cmd.none) \ No newline at end of file + div [] + [ p [] [ text ("RubyEventStore version: " ++ model.resVersion) ] + , p [] [ text ("RubyEventStore adapter: " ++ model.repositoryAdapter) ] + ] diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser.rb b/ruby_event_store-browser/lib/ruby_event_store/browser.rb index 586eafe817..8b73ff80d2 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser.rb @@ -17,4 +17,3 @@ module Browser require_relative "browser/urls" require_relative "browser/gem_source" require_relative "browser/router" -require_relative "browser/get_stats" \ No newline at end of file diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb index 022c8515be..af6d495578 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb @@ -100,11 +100,7 @@ def call(env) stream_name: params.fetch("stream_name"), ) end - router.add_route("GET", "/api/stats") do - json GetStats.new( - event_store: event_store - ) - end + %w[/ /events/:event_id /streams/:stream_name /debug].each do |starting_route| router.add_route("GET", starting_route) do |_, urls| erb bootstrap_html, diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/get_stats.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/get_stats.rb deleted file mode 100644 index 9048eda6f4..0000000000 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/get_stats.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -module RubyEventStore - module Browser - class GetStats - def initialize(event_store:) - @event_store = event_store - end - - def to_h - { - meta: { - events_in_total: events - } - } - end - - private - - def events - event_store.read.count - end - - attr_reader :event_store - end - end -end diff --git a/ruby_event_store-browser/spec/api/stats_spec.rb b/ruby_event_store-browser/spec/api/stats_spec.rb deleted file mode 100644 index 881a228a5e..0000000000 --- a/ruby_event_store-browser/spec/api/stats_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module RubyEventStore - ::RSpec.describe Browser do - include Browser::IntegrationHelpers - - specify "not existing" do - api_client.get "/api/stats" - expect(api_client.parsed_body["meta"]).to match({ - "events_in_total" => 0 - }) - end - end -end From 0b42fb3cefc2c007ff0622eecebc8779bca7caf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:32:59 +0200 Subject: [PATCH 30/92] Revert "Format Page.Debug" This reverts commit e0b6a24c013cb0a4d8732e3419c5b75ac2655cac. --- .../elm/src/Page/Debug.elm | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Page/Debug.elm b/ruby_event_store-browser/elm/src/Page/Debug.elm index c5cf926cdc..016d8e4926 100644 --- a/ruby_event_store-browser/elm/src/Page/Debug.elm +++ b/ruby_event_store-browser/elm/src/Page/Debug.elm @@ -1,21 +1,17 @@ module Page.Debug exposing (..) -import Flags exposing (Flags) import Html exposing (..) +import Flags exposing (Flags) - -type alias Model = - { resVersion : String, repositoryAdapter : String } - +type alias Model = { resVersion : String, repositoryAdapter : String } init : Flags -> Model -init flags = - { resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter } - +init flags = + { resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter } -view : Model -> Html a +view: Model -> Html a view model = - div [] - [ p [] [ text ("RubyEventStore version: " ++ model.resVersion) ] - , p [] [ text ("RubyEventStore adapter: " ++ model.repositoryAdapter) ] - ] + div [] [ + p [] [text ("RubyEventStore version: " ++ model.resVersion)], + p [] [text ("RubyEventStore adapter: " ++ model.repositoryAdapter)] + ] From 7391a7f7ce4169ab018baaefbf2e40bb72cbd153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:03 +0200 Subject: [PATCH 31/92] Revert "Format Main" This reverts commit 124b235305a5397d0f46b0d94fd6dd73439fb2e0. --- ruby_event_store-browser/elm/src/Main.elm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index 0bb2dec205..c379067ae8 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -8,9 +8,9 @@ import Flags exposing (Flags, RawFlags, buildFlags) import Html exposing (..) import Layout import LinkedTimezones exposing (mapLinkedTimeZone) -import Page.Debug import Page.ShowEvent import Page.ShowStream +import Page.Debug import Route import Task import Time @@ -214,7 +214,7 @@ navigate model location = Nothing -> ( { model | page = NotFound }, Cmd.none ) - Just Route.Debug -> + Just (Route.Debug) -> ( { model | page = Debug (Page.Debug.init flags) }, Cmd.none ) Nothing -> From 487eb1a6ced8f37e1a1014a5bcaa2201d8bc0441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:07 +0200 Subject: [PATCH 32/92] Revert "Format Route" This reverts commit 8459e55ce34df26d67d7d8123309a2b63648f9b3. --- ruby_event_store-browser/elm/src/Route.elm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Route.elm b/ruby_event_store-browser/elm/src/Route.elm index 28a9085abb..d867de1956 100644 --- a/ruby_event_store-browser/elm/src/Route.elm +++ b/ruby_event_store-browser/elm/src/Route.elm @@ -1,4 +1,4 @@ -module Route exposing (Route(..), buildUrl, debugUrl, decodeLocation, eventUrl, paginatedStreamUrl, streamUrl) +module Route exposing (Route(..), buildUrl, decodeLocation, eventUrl, paginatedStreamUrl, streamUrl, debugUrl) import Maybe.Extra import Pagination @@ -54,12 +54,10 @@ eventUrl : Url.Url -> String -> String eventUrl baseUrl eventId = buildUrl baseUrl [ "events", Url.percentEncode eventId ] [] - debugUrl : Url.Url -> String debugUrl baseUrl = buildUrl baseUrl [ "debug" ] [] - pathSegments : Url.Url -> List String pathSegments baseUrl = List.filter (\e -> e /= "") (String.split "/" baseUrl.path) From 9e4a12a7ca306d1ba80d995de9e5c93ded22ff13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:11 +0200 Subject: [PATCH 33/92] Revert "Format Search" This reverts commit 5889e11c177997ac48105260e71f29934747f3fa. --- ruby_event_store-browser/elm/src/Search.elm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 5ad91bcb3f..0d75cf61d2 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -53,7 +53,6 @@ isExactStream : Stream -> List Stream -> Bool isExactStream stream streams = List.any ((==) stream) streams - hasAtLeastThreeChars : Stream -> Bool hasAtLeastThreeChars stream = String.length stream >= 3 @@ -68,14 +67,15 @@ update msg model = , onSelectCmd model.onSelectMsg stream ) - else if hasAtLeastThreeChars stream then + else + if hasAtLeastThreeChars stream then ( { model | value = stream } , onQueryChangedCmd model.onQueryMsg stream ) - - else + else ( { model | value = stream }, Cmd.none ) + GoToStream stream -> ( { model | value = emptyStreamName } , onSelectCmd model.onSelectMsg stream From 7c6c28a4dd16710827d4518ef7ead33f38f755ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:21 +0200 Subject: [PATCH 34/92] Revert "add order to rom" This reverts commit 3ab31cf4fe083944217b2c49e095d4cb35a482c3. --- .../lib/ruby_event_store/rom/repositories/stream_entries.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb b/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb index fb507206b0..b9f8ba1b6f 100644 --- a/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb +++ b/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb @@ -52,7 +52,6 @@ def search_streams(stream_name) .where { stream.like("#{stream_name}%") } .distinct .limit(10) - .order(:stream) .pluck(:stream) .map { |name| Stream.new(name) } end From 5b651f0e980bf047033e43e21342480263acb9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:25 +0200 Subject: [PATCH 35/92] Revert "Search streams for sequel" This reverts commit 0f0b8a04c91e17df96ebaf9be849a86387b1ce47. --- .../lib/ruby_event_store/sequel/event_repository.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/contrib/ruby_event_store-sequel/lib/ruby_event_store/sequel/event_repository.rb b/contrib/ruby_event_store-sequel/lib/ruby_event_store/sequel/event_repository.rb index e7732d1d53..2bb0571a7e 100644 --- a/contrib/ruby_event_store-sequel/lib/ruby_event_store/sequel/event_repository.rb +++ b/contrib/ruby_event_store-sequel/lib/ruby_event_store/sequel/event_repository.rb @@ -172,14 +172,6 @@ def streams_of(event_id) @db[:event_store_events_in_streams].where(event_id: event_id).map { |h| Stream.new(h[:stream]) } end - def search_streams(stream_name) - @db[:event_store_events_in_streams] - .where(::Sequel.like(:stream, "#{stream_name}%")) - .select(:stream) - .limit(10) - .map { |h| Stream.new(h[:stream]) } - end - private def optimize_timestamp(valid_at, created_at) From c18c9a1b0b90c3b2be965110b9c2cabaa41bd50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:29 +0200 Subject: [PATCH 36/92] Revert "Implement search_streams in ROM" This reverts commit daad41762ddc2bda94dd78cb9744863b07da160d. --- .../lib/ruby_event_store/rom/event_repository.rb | 4 ---- .../ruby_event_store/rom/repositories/stream_entries.rb | 9 --------- 2 files changed, 13 deletions(-) diff --git a/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/event_repository.rb b/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/event_repository.rb index dc25c9d24f..a25b7055f6 100644 --- a/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/event_repository.rb +++ b/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/event_repository.rb @@ -94,10 +94,6 @@ def streams_of(event_id) @stream_entries.streams_of(event_id).map { |name| Stream.new(name) } end - def search_streams(stream_name) - @stream_entries.search_streams(stream_name) - end - private def validate_event_ids(event_ids) diff --git a/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb b/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb index b9f8ba1b6f..df662482e8 100644 --- a/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb +++ b/contrib/ruby_event_store-rom/lib/ruby_event_store/rom/repositories/stream_entries.rb @@ -46,15 +46,6 @@ def position_in_stream(event_id, stream) def event_in_stream?(event_id, stream) stream_entries.by_stream(stream).by_event_id(event_id).exist? end - - def search_streams(stream_name) - stream_entries - .where { stream.like("#{stream_name}%") } - .distinct - .limit(10) - .pluck(:stream) - .map { |name| Stream.new(name) } - end end end end From c866447a31836a8c639db74f9d9374dd901fc839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:33 +0200 Subject: [PATCH 37/92] Revert "Don't add "all" stream to search results" This reverts commit 94e5d20c2170da5680ac70a6b5f0ccdf18fc658c. --- ruby_event_store-browser/elm/src/Layout.elm | 2 +- ruby_event_store-browser/elm/src/Search.elm | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index d5a9ef4c22..1623ad491e 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -151,7 +151,7 @@ update msg model = SearchedStreamsFetched (Ok streams) -> let streams_ = - List.map .streamId streams + "all" :: List.map .streamId streams searchModel = model.internal.search diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 0d75cf61d2..410aeb9991 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -25,6 +25,11 @@ type Msg | GoToStream Stream +globalStreamName : Stream +globalStreamName = + "all" + + emptyStreamName : Stream emptyStreamName = "" @@ -32,7 +37,7 @@ emptyStreamName = init : (Stream -> a) -> (Stream -> a) -> Model a init onSelectMsg onQueryMsg = - { streams = [] + { streams = [ globalStreamName ] , value = emptyStreamName , onSelectMsg = onSelectMsg , onQueryMsg = onQueryMsg From a88572181f302c53f0d96d1f3edcd65285d872d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:37 +0200 Subject: [PATCH 38/92] Revert "Refactor" This reverts commit e8ecb48966296bbe729ad017837d63b9a1ddaa8a. --- ruby_event_store-browser/elm/src/Layout.elm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 1623ad491e..5fdd902f1c 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -76,8 +76,8 @@ goToStream { key, flags } stream = Browser.Navigation.pushUrl key (Route.streamUrl flags.rootUrl stream) -searchStreams : WrappedModel Model -> String -> Cmd Msg -searchStreams { flags } stream = +searchStreams : Flags -> String -> Cmd Msg +searchStreams flags stream = getSearchStreams SearchedStreamsFetched flags stream @@ -100,7 +100,7 @@ update msg model = ) OnQueryChanged streamName -> - ( model, searchStreams model streamName ) + ( model, searchStreams model.flags streamName ) TimeZoneSelected zoneName -> let From b2b53c53ae5f93aae3b97af9f7e54bb3db41e518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:50 +0200 Subject: [PATCH 39/92] =?UTF-8?q?Revert=20"Stream=20is=20our=20domain?= =?UTF-8?q?=E2=80=93specific=20type"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 28edc412cfea71e2fa16fd5b2e5714dace527457. --- ruby_event_store-browser/elm/src/Search.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 410aeb9991..143d58839d 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -54,7 +54,7 @@ onQueryChangedCmd onQueryMsg stream = Task.perform onQueryMsg (Task.succeed stream) -isExactStream : Stream -> List Stream -> Bool +isExactStream : String -> List String -> Bool isExactStream stream streams = List.any ((==) stream) streams From 29a6035fd049b3b93d631c5caebd8d00e07f0dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:33:57 +0200 Subject: [PATCH 40/92] Revert "Require at lest 3 chars before fetching streams" This reverts commit 31c16dfb65f7c0db3e655cb22a5eeca9b21b5dad. --- ruby_event_store-browser/elm/src/Search.elm | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 143d58839d..17e4f55ee2 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -58,10 +58,6 @@ isExactStream : String -> List String -> Bool isExactStream stream streams = List.any ((==) stream) streams -hasAtLeastThreeChars : Stream -> Bool -hasAtLeastThreeChars stream = - String.length stream >= 3 - update : Msg -> Model a -> ( Model a, Cmd a ) update msg model = @@ -73,13 +69,9 @@ update msg model = ) else - if hasAtLeastThreeChars stream then ( { model | value = stream } , onQueryChangedCmd model.onQueryMsg stream ) - else - ( { model | value = stream }, Cmd.none ) - GoToStream stream -> ( { model | value = emptyStreamName } From 0e2e52c16ed9002eff377da993fdf00648dc588a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:34:02 +0200 Subject: [PATCH 41/92] Revert "Refactor" This reverts commit 39fd968a3d6749ae9a662d278ef8d182476e0af5. --- ruby_event_store-browser/elm/src/Search.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 17e4f55ee2..898570859e 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -56,7 +56,7 @@ onQueryChangedCmd onQueryMsg stream = isExactStream : String -> List String -> Bool isExactStream stream streams = - List.any ((==) stream) streams + List.any (\s -> s == stream) streams update : Msg -> Model a -> ( Model a, Cmd a ) From 10693dac46009725cefd1c277af4e9831abf22de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:34:06 +0200 Subject: [PATCH 42/92] Revert "Add debug url to the browser layout" This reverts commit c42c546ab6ef2ae6f616e97fa8f23d7e6023becb. --- ruby_event_store-browser/elm/src/Layout.elm | 6 ------ ruby_event_store-browser/elm/src/Route.elm | 5 +---- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 5fdd902f1c..b801a7981f 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -251,12 +251,6 @@ browserFooter { flags, time } = , class "ml-4" ] [ text "Support" ] - , spacer - , a - [ href (Route.debugUrl flags.rootUrl) - , class "ml-4" - ] - [ text "Debug" ] ] , div [ class "text-gray-500 text-sm flex item-center gap-2" ] diff --git a/ruby_event_store-browser/elm/src/Route.elm b/ruby_event_store-browser/elm/src/Route.elm index d867de1956..6aa7599145 100644 --- a/ruby_event_store-browser/elm/src/Route.elm +++ b/ruby_event_store-browser/elm/src/Route.elm @@ -1,4 +1,4 @@ -module Route exposing (Route(..), buildUrl, decodeLocation, eventUrl, paginatedStreamUrl, streamUrl, debugUrl) +module Route exposing (Route(..), buildUrl, decodeLocation, eventUrl, paginatedStreamUrl, streamUrl) import Maybe.Extra import Pagination @@ -54,9 +54,6 @@ eventUrl : Url.Url -> String -> String eventUrl baseUrl eventId = buildUrl baseUrl [ "events", Url.percentEncode eventId ] [] -debugUrl : Url.Url -> String -debugUrl baseUrl = - buildUrl baseUrl [ "debug" ] [] pathSegments : Url.Url -> List String pathSegments baseUrl = From 7b9fa5091239131ee7e49f3e2f768ac8d41be3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:41:30 +0200 Subject: [PATCH 43/92] Revert "Search module communicates important state changes to upper module" This reverts commit 2cdaae05f3c541530b0a61dc9ef2c6bd1311f721. --- ruby_event_store-browser/elm/src/Layout.elm | 40 +++++++++--------- ruby_event_store-browser/elm/src/Search.elm | 46 +++++++++++---------- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index b801a7981f..29a23c1a2a 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -25,14 +25,12 @@ type Msg | ToggleBookmarksMenu | ToggleDialog | SearchedStreamsFetched (Result Http.Error (List SearchStream)) - | OnSelect Search.Stream - | OnQueryChanged Search.Stream | RequestSearch | ToggleBookmark String type alias Model = - { search : Search.Model Msg + { search : Search.Model , displayBookmarksMenu : Bool , bookmarks : List Bookmark } @@ -62,7 +60,7 @@ subscriptions = buildModel : Model buildModel = { search = - Search.init OnSelect OnQueryChanged + Search.init , displayBookmarksMenu = False , bookmarks = [ { itemType = "Stream", label = "Bookmark 1", link = "/" } @@ -85,22 +83,24 @@ update : Msg -> WrappedModel Model -> ( WrappedModel Model, Cmd Msg ) update msg model = case msg of SearchMsg searchMsg -> - let - ( newSearch, cmd ) = - Search.update searchMsg model.internal.search - in - ( { model | internal = Model newSearch model.internal.displayBookmarksMenu model.internal.bookmarks }, cmd ) - - OnSelect streamName -> - ( model - , Cmd.batch - [ toggleDialog searchModalId - , goToStream model streamName - ] - ) - - OnQueryChanged streamName -> - ( model, searchStreams model.flags streamName ) + case searchMsg of + OnSelect streamName -> + ( model + , Cmd.batch + [ toggleDialog searchModalId + , goToStream model streamName + ] + ) + + OnQueryChanged streamName -> + ( model, searchStreams model.flags streamName ) + + _ -> + let + ( newSearch, cmd ) = + Search.update searchMsg model.internal.search + in + ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) TimeZoneSelected zoneName -> let diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 898570859e..0569f651f4 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -4,7 +4,9 @@ import FeatherIcons import Html exposing (..) import Html.Attributes exposing (autofocus, class, id, list, placeholder, value) import Html.Events exposing (onInput, onSubmit) -import List +import Http +import List exposing (any) +import Page.ShowStream exposing (Msg(..)) import Task @@ -12,46 +14,42 @@ type alias Stream = String -type alias Model a = +type alias Model = { streams : List Stream , value : Stream - , onSelectMsg : Stream -> a - , onQueryMsg : Stream -> a } type Msg = StreamChanged Stream | GoToStream Stream + | OnSelect Stream + | OnQueryChanged Stream -globalStreamName : Stream globalStreamName = "all" -emptyStreamName : Stream emptyStreamName = "" -init : (Stream -> a) -> (Stream -> a) -> Model a -init onSelectMsg onQueryMsg = +init : Model +init = { streams = [ globalStreamName ] , value = emptyStreamName - , onSelectMsg = onSelectMsg - , onQueryMsg = onQueryMsg } -onSelectCmd : (Stream -> a) -> Stream -> Cmd a -onSelectCmd onSelectMsg stream = - Task.perform onSelectMsg (Task.succeed stream) +hackWithInternalOnSelectMsg : Stream -> Cmd Msg +hackWithInternalOnSelectMsg stream = + Task.perform OnSelect (Task.succeed stream) -onQueryChangedCmd : (Stream -> a) -> Stream -> Cmd a -onQueryChangedCmd onQueryMsg stream = - Task.perform onQueryMsg (Task.succeed stream) +hackWithInternalOnQueryChangedMsg : Stream -> Cmd Msg +hackWithInternalOnQueryChangedMsg stream = + Task.perform OnQueryChanged (Task.succeed stream) isExactStream : String -> List String -> Bool @@ -59,27 +57,33 @@ isExactStream stream streams = List.any (\s -> s == stream) streams -update : Msg -> Model a -> ( Model a, Cmd a ) +update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of StreamChanged stream -> if isExactStream stream model.streams then ( { model | value = emptyStreamName } - , onSelectCmd model.onSelectMsg stream + , hackWithInternalOnSelectMsg stream ) else ( { model | value = stream } - , onQueryChangedCmd model.onQueryMsg stream + , hackWithInternalOnQueryChangedMsg stream ) GoToStream stream -> ( { model | value = emptyStreamName } - , onSelectCmd model.onSelectMsg stream + , hackWithInternalOnSelectMsg stream ) + OnSelect _ -> + ( model, Cmd.none ) -view : Model msg -> Html Msg + OnQueryChanged _ -> + ( model, Cmd.none ) + + +view : Model -> Html Msg view model = form [ onSubmit (GoToStream model.value) ] [ div [ class "relative" ] From be3bf9b405f78f2958afc073c1ad13e0fabb1bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:41:37 +0200 Subject: [PATCH 44/92] Revert "Adjust test" This reverts commit 35d33de20f97fb3a795dc213a63393b965b3a52f. --- ruby_event_store/spec/client_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ruby_event_store/spec/client_spec.rb b/ruby_event_store/spec/client_spec.rb index 996d937122..c9661827e0 100644 --- a/ruby_event_store/spec/client_spec.rb +++ b/ruby_event_store/spec/client_spec.rb @@ -852,11 +852,11 @@ module RubyEventStore client.append(event_2, stream_name: stream_2.name) client.append(event_3, stream_name: stream_3.name) - expect(client.search_streams("str")).to match_array [stream_3, stream_2, stream_1] - expect(client.search_streams("stream-1")).to match_array [stream_1] - expect(client.search_streams("stream-2")).to match_array [stream_2] - expect(client.search_streams("stream-3")).to match_array [stream_3] - expect(client.search_streams("stream-4")).to match_array [] + expect(client.search_streams("str")).to eq [stream_3, stream_2, stream_1] + expect(client.search_streams("stream-1")).to eq [stream_1] + expect(client.search_streams("stream-2")).to eq [stream_2] + expect(client.search_streams("stream-3")).to eq [stream_3] + expect(client.search_streams("stream-4")).to eq [] end describe "#subscribers_for" do From e6914da30aa31c1c717443b5d24dce34f6c3eef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:41:45 +0200 Subject: [PATCH 45/92] Revert "We don't mind the order" This reverts commit 0f3f4ffe39092d5404e5eb95503c5a31f9fe0763. --- ruby_event_store/lib/ruby_event_store/in_memory_repository.rb | 1 + 1 file changed, 1 insertion(+) 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 abb25aca8f..7f96811c72 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 @@ -130,6 +130,7 @@ def search_streams(stream_name) streams .select { |name,| name.include?(stream_name) } .take(10) + .reverse .map { |name,| Stream.new(name) } end From 05e4a59dcc1b1e8bad43bf0156cb7932cb7b0fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:41:50 +0200 Subject: [PATCH 46/92] Revert "adjust tests" This reverts commit f1726beae17be5b1027e56cc4fa4d90473387761. --- .../spec/event_repository_spec.rb | 10 +++++++--- .../spec/api/search_streams_spec.rb | 1 + .../lib/ruby_event_store/in_memory_repository.rb | 2 +- .../ruby_event_store/spec/event_repository_lint.rb | 11 ++++++----- ruby_event_store/spec/client_spec.rb | 2 ++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 0d188f18f3..59557f75b4 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -196,12 +196,16 @@ module ActiveRecord ) repository.append_to_stream( [SRecord.new(event_id: e3 = SecureRandom.uuid)], - s3 = Stream.new("Dummy$#{e3}"), + s3 = Stream.new("dUmMY$#{e3}"), ExpectedVersion.any ) - expect(repository.search_streams("Du")).to contain_exactly(s3, s2, s1) - expect(repository.search_streams("Dummy")).to contain_exactly(s3, s2, s1) + expect(repository.search_streams("Du")).to eq([s3, s2, s1]) + expect(repository.search_streams("du")).to eq([s3, s2, s1]) + expect(repository.search_streams("dum")).to eq([s3, s2, s1]) + expect(repository.search_streams("dumm")).to eq([s3, s2, s1]) + expect(repository.search_streams("dummy")).to eq([s3, s2, s1]) + expect(repository.search_streams("Dummy")).to eq([s3, s2, s1]) end specify "limits searched streams to 10" do diff --git a/ruby_event_store-browser/spec/api/search_streams_spec.rb b/ruby_event_store-browser/spec/api/search_streams_spec.rb index d05c9f32b3..e82e1503b9 100644 --- a/ruby_event_store-browser/spec/api/search_streams_spec.rb +++ b/ruby_event_store-browser/spec/api/search_streams_spec.rb @@ -13,6 +13,7 @@ module RubyEventStore expect(api_client.last_response).to be_ok expect(api_client.parsed_body["data"]).to match_array( [ + { "id" => "$by_type_DummyEvent", "type" => "streams" }, { "id" => "dummy-2", "type" => "streams" }, { "id" => "dummy-1", "type" => "streams" } ] 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 7f96811c72..681c3829f5 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 @@ -128,7 +128,7 @@ def streams_of(event_id) def search_streams(stream_name) streams - .select { |name,| name.include?(stream_name) } + .select { |name,| name.downcase.include?(stream_name.downcase) } .take(10) .reverse .map { |name,| Stream.new(name) } 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 d91ea95d0f..1cd112594b 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 @@ -1195,10 +1195,11 @@ def read_events_backward(repository, stream = nil, from: nil, to: nil, count: ni repository.append_to_stream([event_2], stream_b, version_any) repository.append_to_stream([event_3], stream_c, version_any) - expect(repository.search_streams("Str")).to contain_exactly stream_c, stream_b, stream_a - expect(repository.search_streams("Stream A")).to contain_exactly stream_a - expect(repository.search_streams("Stream B")).to contain_exactly stream_b - expect(repository.search_streams("Stream C")).to contain_exactly stream_c + expect(repository.search_streams("str")).to eq [stream_c, stream_b, stream_a] + expect(repository.search_streams("Str")).to eq [stream_c, stream_b, stream_a] + expect(repository.search_streams("Stream A")).to eq [stream_a] + expect(repository.search_streams("Stream B")).to eq [stream_b] + expect(repository.search_streams("Stream C")).to eq [stream_c] end specify do @@ -1207,7 +1208,7 @@ def read_events_backward(repository, stream = nil, from: nil, to: nil, count: ni repository.append_to_stream([ SRecord.new(event_id: SecureRandom.uuid)], stream, version_any) end - expect(repository.search_streams("Stream").size).to eq 10 + expect(repository.search_streams("stream").size).to eq 10 end specify do diff --git a/ruby_event_store/spec/client_spec.rb b/ruby_event_store/spec/client_spec.rb index c9661827e0..637cbb2d61 100644 --- a/ruby_event_store/spec/client_spec.rb +++ b/ruby_event_store/spec/client_spec.rb @@ -853,6 +853,8 @@ module RubyEventStore client.append(event_3, stream_name: stream_3.name) expect(client.search_streams("str")).to eq [stream_3, stream_2, stream_1] + expect(client.search_streams("Str")).to eq [stream_3, stream_2, stream_1] + expect(client.search_streams("sTr")).to eq [stream_3, stream_2, stream_1] expect(client.search_streams("stream-1")).to eq [stream_1] expect(client.search_streams("stream-2")).to eq [stream_2] expect(client.search_streams("stream-3")).to eq [stream_3] From eafe327e99d2d2984554ca2135ca53fde500e490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:41:54 +0200 Subject: [PATCH 47/92] Revert "Optimize querys performance" This reverts commit 1596bf78a631530db4c77e54492ede8f6b88a3eb. --- .../active_record/event_repository_reader.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb index b6158b6171..85ab0cd0e0 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb @@ -59,9 +59,10 @@ def event_in_stream?(event_id, stream) def search_streams(stream) @stream_klass - .where("stream LIKE ?", "#{stream}%") + .where("lower(stream) LIKE ?", "#{stream.downcase}%") + .order("position DESC, id DESC") .limit(10) - .pluck("distinct stream") + .pluck(:stream) .map { |name| Stream.new(name) } end From 02a607c85936017f7a735db295d57f3d8a8c3277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:41:58 +0200 Subject: [PATCH 48/92] Revert "Move navigation out of Stream" This reverts commit ed475f6849cb8657f6f75b34ad3125012caaec9d. --- ruby_event_store-browser/elm/src/Layout.elm | 58 +++++---------------- ruby_event_store-browser/elm/src/Search.elm | 49 +++++++++++------ 2 files changed, 44 insertions(+), 63 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 29a23c1a2a..e370698097 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -1,6 +1,6 @@ port module Layout exposing (Model, Msg, buildModel, subscriptions, update, view, viewIncorrectConfig, viewNotFound) -import Api exposing (SearchStream, getSearchStreams) +import Browser.Events import Browser.Navigation import BrowserTime import Dict @@ -9,6 +9,7 @@ import Html exposing (..) import Html.Attributes exposing (class, href, id, selected, title, value) import Html.Events exposing (onClick, onInput) import Http +import Json.Decode import LinkedTimezones exposing (mapLinkedTimeZone) import List.Extra import Route @@ -24,11 +25,9 @@ type Msg | SearchMsg Search.Msg | ToggleBookmarksMenu | ToggleDialog - | SearchedStreamsFetched (Result Http.Error (List SearchStream)) | RequestSearch | ToggleBookmark String - type alias Model = { search : Search.Model , displayBookmarksMenu : Bool @@ -70,36 +69,26 @@ buildModel = goToStream : WrappedModel Model -> String -> Cmd msg -goToStream { key, flags } stream = - Browser.Navigation.pushUrl key (Route.streamUrl flags.rootUrl stream) - - -searchStreams : Flags -> String -> Cmd Msg -searchStreams flags stream = - getSearchStreams SearchedStreamsFetched flags stream +goToStream model stream = + Browser.Navigation.pushUrl model.key (Route.streamUrl model.flags.rootUrl stream) update : Msg -> WrappedModel Model -> ( WrappedModel Model, Cmd Msg ) update msg model = case msg of SearchMsg searchMsg -> + let + ( newSearch, cmd ) = + Search.update searchMsg model.internal.search model.flags (goToStream model) + in case searchMsg of - OnSelect streamName -> - ( model - , Cmd.batch - [ toggleDialog searchModalId - , goToStream model streamName - ] - ) + OnSelect _ -> + ( { model | internal = Model newSearch }, toggleDialog searchModalId ) - OnQueryChanged streamName -> - ( model, searchStreams model.flags streamName ) + OnQueryChanged _ -> + ( model, Cmd.none ) _ -> - let - ( newSearch, cmd ) = - Search.update searchMsg model.internal.search - in ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) TimeZoneSelected zoneName -> @@ -148,29 +137,6 @@ update msg model = ToggleDialog -> ( model, toggleDialog searchModalId ) - SearchedStreamsFetched (Ok streams) -> - let - streams_ = - "all" :: List.map .streamId streams - - searchModel = - model.internal.search - - newModel = - { searchModel | streams = streams_ } - in - ( { model | internal = Model newModel model.internal.displayBookmarksMenu model.internal.bookmarks }, Cmd.none ) - - SearchedStreamsFetched (Err _) -> - let - searchModel = - model.internal.search - - newModel = - { searchModel | streams = [] } - in - ( { model | internal = Model newModel model.internal.displayBookmarksMenu model.internal.bookmarks }, Cmd.none ) - ToggleBookmark id -> ( model, toggleBookmark id ) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 0569f651f4..067c42d0bf 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -1,6 +1,8 @@ module Search exposing (..) +import Api exposing (SearchStream, getSearchStreams) import FeatherIcons +import Flags exposing (Flags) import Html exposing (..) import Html.Attributes exposing (autofocus, class, id, list, placeholder, value) import Html.Events exposing (onInput, onSubmit) @@ -23,22 +25,15 @@ type alias Model = type Msg = StreamChanged Stream | GoToStream Stream + | SearchedStreamsFetched (Result Http.Error (List SearchStream)) | OnSelect Stream | OnQueryChanged Stream -globalStreamName = - "all" - - -emptyStreamName = - "" - - init : Model init = - { streams = [ globalStreamName ] - , value = emptyStreamName + { streams = [ "all" ] + , value = "" } @@ -52,30 +47,50 @@ hackWithInternalOnQueryChangedMsg stream = Task.perform OnQueryChanged (Task.succeed stream) +searchStreams : Flags -> Stream -> Cmd Msg +searchStreams flags stream = + getSearchStreams SearchedStreamsFetched flags stream + + isExactStream : String -> List String -> Bool isExactStream stream streams = List.any (\s -> s == stream) streams -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = +update : Msg -> Model -> Flags -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) +update msg model flags onSubmit = case msg of StreamChanged stream -> if isExactStream stream model.streams then - ( { model | value = emptyStreamName } - , hackWithInternalOnSelectMsg stream + ( { model | value = "" } + , Cmd.batch + [ onSubmit stream + , hackWithInternalOnSelectMsg stream + ] ) else ( { model | value = stream } - , hackWithInternalOnQueryChangedMsg stream + , Cmd.batch + [ searchStreams flags stream + , hackWithInternalOnQueryChangedMsg stream + ] ) GoToStream stream -> - ( { model | value = emptyStreamName } - , hackWithInternalOnSelectMsg stream + ( { model | value = "" } + , Cmd.batch + [ onSubmit stream + , hackWithInternalOnSelectMsg stream + ] ) + SearchedStreamsFetched (Ok streams) -> + ( { model | streams = "all" :: List.map .streamId streams }, Cmd.none ) + + SearchedStreamsFetched (Err _) -> + ( { model | streams = [] }, Cmd.none ) + OnSelect _ -> ( model, Cmd.none ) From d1cf5c13e07b705eef9ced59a8c99fde2f3b11d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:11 +0200 Subject: [PATCH 49/92] Revert "One more intermediate, dummy message to handle in Layout" This reverts commit 100077b331cbb3fbf211ff193c72a3f769e317cf. --- ruby_event_store-browser/elm/src/Layout.elm | 3 --- ruby_event_store-browser/elm/src/Search.elm | 16 +--------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index e370698097..9b70f9a3df 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -85,9 +85,6 @@ update msg model = OnSelect _ -> ( { model | internal = Model newSearch }, toggleDialog searchModalId ) - OnQueryChanged _ -> - ( model, Cmd.none ) - _ -> ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 067c42d0bf..692a9313a1 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -27,7 +27,6 @@ type Msg | GoToStream Stream | SearchedStreamsFetched (Result Http.Error (List SearchStream)) | OnSelect Stream - | OnQueryChanged Stream init : Model @@ -42,11 +41,6 @@ hackWithInternalOnSelectMsg stream = Task.perform OnSelect (Task.succeed stream) -hackWithInternalOnQueryChangedMsg : Stream -> Cmd Msg -hackWithInternalOnQueryChangedMsg stream = - Task.perform OnQueryChanged (Task.succeed stream) - - searchStreams : Flags -> Stream -> Cmd Msg searchStreams flags stream = getSearchStreams SearchedStreamsFetched flags stream @@ -70,12 +64,7 @@ update msg model flags onSubmit = ) else - ( { model | value = stream } - , Cmd.batch - [ searchStreams flags stream - , hackWithInternalOnQueryChangedMsg stream - ] - ) + ( { model | value = stream }, searchStreams flags stream ) GoToStream stream -> ( { model | value = "" } @@ -94,9 +83,6 @@ update msg model flags onSubmit = OnSelect _ -> ( model, Cmd.none ) - OnQueryChanged _ -> - ( model, Cmd.none ) - view : Model -> Html Msg view model = From 65762786327ed0d05701322cccede4d18758c8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:16 +0200 Subject: [PATCH 50/92] Revert "test if InstrumentedRepository presents which repository is instrumented" This reverts commit 1d0dd28ecdd8dcff5f6980ca2cdb5dfff5db9462. --- ruby_event_store/spec/instrumented_repository_spec.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ruby_event_store/spec/instrumented_repository_spec.rb b/ruby_event_store/spec/instrumented_repository_spec.rb index 4243855a7d..3545d28b23 100644 --- a/ruby_event_store/spec/instrumented_repository_spec.rb +++ b/ruby_event_store/spec/instrumented_repository_spec.rb @@ -171,14 +171,6 @@ module RubyEventStore end end - describe "specification" do - it "present which repository is instrumented" do - some_repository = double("Some repository") - instrumented_repository = InstrumentedRepository.new(some_repository, ActiveSupport::Notifications) - expect(instrumented_repository.specification).to eq("Instrumented RSpec::Mocks::Double") - end - end - specify "method unknown by instrumentation but known by repository" do some_repository = double("Some repository", custom_method: 42) instrumented_repository = InstrumentedRepository.new(some_repository, ActiveSupport::Notifications) From 9026c885b9aa623ce0f69fdb55f4d38ec4eecf4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:19 +0200 Subject: [PATCH 51/92] Revert "present which exactly repository is instrumented" This reverts commit 366e4bd8076ecd8118f3b98af1adec8edee85757. --- .../lib/ruby_event_store/instrumented_repository.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb b/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb index a5049e5e2d..a70311818c 100644 --- a/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb +++ b/ruby_event_store/lib/ruby_event_store/instrumented_repository.rb @@ -61,15 +61,6 @@ def respond_to_missing?(method_name, _include_private) repository.respond_to?(method_name) end - def specification - "Instrumented " + - if repository.respond_to?(:specification) - repository.specification - else - repository.class.to_s - end - end - private attr_reader :repository, :instrumentation From c9344df62d3acc51a8682d32cdf72ffe2c906d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:23 +0200 Subject: [PATCH 52/92] Revert "prettier" This reverts commit 80b88309631aa1dfa1b132b639c38b16d5bda948. --- .../active_record/event_repository_reader.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb index 85ab0cd0e0..87eef89b2a 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb @@ -58,12 +58,7 @@ def event_in_stream?(event_id, stream) end def search_streams(stream) - @stream_klass - .where("lower(stream) LIKE ?", "#{stream.downcase}%") - .order("position DESC, id DESC") - .limit(10) - .pluck(:stream) - .map { |name| Stream.new(name) } + @stream_klass.where("lower(stream) LIKE ?", "#{stream.downcase}%").order("position DESC, id DESC").limit(10).pluck(:stream).map { |name| Stream.new(name) } end private From 9538406b44ce32bdcb3e83b49fa3a186028e6abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:27 +0200 Subject: [PATCH 53/92] Revert "test if /debug page is served" This reverts commit 39178013124fe0b1fac16eeab27d704e70419ca1. --- ruby_event_store-browser/spec/web_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/ruby_event_store-browser/spec/web_spec.rb b/ruby_event_store-browser/spec/web_spec.rb index 7cca4a5a7f..3acf98ac69 100644 --- a/ruby_event_store-browser/spec/web_spec.rb +++ b/ruby_event_store-browser/spec/web_spec.rb @@ -10,7 +10,6 @@ module RubyEventStore specify { expect(web_client.get("/").content_type).to eq("text/html;charset=utf-8") } specify { expect(web_client.post("/")).to be_not_found } specify { expect(web_client.get("/streams/all")).to be_ok } - specify { expect(web_client.get("/debug")).to be_ok } specify do event_store.append(event = DummyEvent.new) expect(web_client.get("/events/#{event.event_id}")).to be_ok From d82f8f19d1a58568dc9223c92dc040cac5b5a13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:30 +0200 Subject: [PATCH 54/92] Revert "test if repositoryAdapter flag is set" This reverts commit 5fba4c8eaa5dd4fb741a8ab9178ca6e2cb90da51. --- ruby_event_store-browser/spec/browser_settings_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ruby_event_store-browser/spec/browser_settings_spec.rb b/ruby_event_store-browser/spec/browser_settings_spec.rb index 39eacad2d7..c929c89940 100644 --- a/ruby_event_store-browser/spec/browser_settings_spec.rb +++ b/ruby_event_store-browser/spec/browser_settings_spec.rb @@ -13,12 +13,6 @@ module RubyEventStore expect(parsed_meta_content(response.body)["resVersion"]).to eq(RubyEventStore::VERSION) end - specify "passes RES repository adapter specification" do - response = web_client.get "/res" - - expect(parsed_meta_content(response.body)["repositoryAdapter"]).to eq('RubyEventStore::InMemoryRepository') - end - specify "passes root_url" do response = web_client.get "/res" From 17ccddc5b2071d605119fa19c9302ca00eb1ef76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:34 +0200 Subject: [PATCH 55/92] Revert "move `repository_specification` method to the proper class" This reverts commit 947325b3326ff8bc6c12d699d11cab5a72797473. --- ruby_event_store/lib/ruby_event_store/client.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index 98fc07e212..3326c1c3ff 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -234,6 +234,14 @@ def call unsubs.each(&:call) if unsubs end + def repository_specification + if repository.respond_to?(:specification) + repository.specification + else + repository.class.to_s + end + end + private attr_reader :resolver @@ -337,14 +345,6 @@ def inspect "#<#{self.class}:0x#{__id__.to_s(16)}>" end - def repository_specification - if repository.respond_to?(:specification) - repository.specification - else - repository.class.to_s - end - end - EMPTY_HASH = {}.freeze private_constant :EMPTY_HASH From a22e38adc90ae5341f619a95699b5ee06ace6d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:39 +0200 Subject: [PATCH 56/92] Revert "Clear input on exact match too" This reverts commit 69d36b154f0464062bd504f9bf427acc762ec519. --- ruby_event_store-browser/elm/src/Search.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 692a9313a1..f514dc80a6 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -56,7 +56,7 @@ update msg model flags onSubmit = case msg of StreamChanged stream -> if isExactStream stream model.streams then - ( { model | value = "" } + ( { model | value = stream } , Cmd.batch [ onSubmit stream , hackWithInternalOnSelectMsg stream From e786de388ef0cc7edb61676ecbb3884fc3532dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:43 +0200 Subject: [PATCH 57/92] Revert "Rely on special internal OnSelect message to close modal" This reverts commit 1536fc91d7501e0d7bf75b0644d01280fdb2a75e. --- ruby_event_store-browser/elm/src/Layout.elm | 9 ++++++-- ruby_event_store-browser/elm/src/Search.elm | 24 ++------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 9b70f9a3df..d10145efe5 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -82,8 +82,13 @@ update msg model = Search.update searchMsg model.internal.search model.flags (goToStream model) in case searchMsg of - OnSelect _ -> - ( { model | internal = Model newSearch }, toggleDialog searchModalId ) + GoToStream _ -> + ( { model | internal = Model newSearch } + , Cmd.batch + [ Cmd.map SearchMsg cmd + , toggleDialog searchModalId + ] + ) _ -> ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index f514dc80a6..d4d323933b 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -9,7 +9,6 @@ import Html.Events exposing (onInput, onSubmit) import Http import List exposing (any) import Page.ShowStream exposing (Msg(..)) -import Task type alias Stream = @@ -26,7 +25,6 @@ type Msg = StreamChanged Stream | GoToStream Stream | SearchedStreamsFetched (Result Http.Error (List SearchStream)) - | OnSelect Stream init : Model @@ -36,11 +34,6 @@ init = } -hackWithInternalOnSelectMsg : Stream -> Cmd Msg -hackWithInternalOnSelectMsg stream = - Task.perform OnSelect (Task.succeed stream) - - searchStreams : Flags -> Stream -> Cmd Msg searchStreams flags stream = getSearchStreams SearchedStreamsFetched flags stream @@ -56,23 +49,13 @@ update msg model flags onSubmit = case msg of StreamChanged stream -> if isExactStream stream model.streams then - ( { model | value = stream } - , Cmd.batch - [ onSubmit stream - , hackWithInternalOnSelectMsg stream - ] - ) + ( { model | value = stream }, onSubmit stream ) else ( { model | value = stream }, searchStreams flags stream ) GoToStream stream -> - ( { model | value = "" } - , Cmd.batch - [ onSubmit stream - , hackWithInternalOnSelectMsg stream - ] - ) + ( { model | value = "" }, onSubmit stream ) SearchedStreamsFetched (Ok streams) -> ( { model | streams = "all" :: List.map .streamId streams }, Cmd.none ) @@ -80,9 +63,6 @@ update msg model flags onSubmit = SearchedStreamsFetched (Err _) -> ( { model | streams = [] }, Cmd.none ) - OnSelect _ -> - ( model, Cmd.none ) - view : Model -> Html Msg view model = From 67e21f14f13ce636ff6537f80d4b3d0dd1384302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:48 +0200 Subject: [PATCH 58/92] Revert "Forgotten signature" This reverts commit b0c59c8731e7b36ef759fb5a13571205c84c39de. --- ruby_event_store-browser/elm/src/Layout.elm | 1 - 1 file changed, 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index d10145efe5..23433a37fd 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -68,7 +68,6 @@ buildModel = } -goToStream : WrappedModel Model -> String -> Cmd msg goToStream model stream = Browser.Navigation.pushUrl model.key (Route.streamUrl model.flags.rootUrl stream) From bd4b47a1fddc608dc826c026db5c77f91c5ba7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:54 +0200 Subject: [PATCH 59/92] Revert "Clear selected value when submitting stream" This reverts commit 65b99a51c88f9566e37d27b924de7af86d087f56. --- ruby_event_store-browser/elm/src/Search.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index d4d323933b..1bd9bab57e 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -55,7 +55,7 @@ update msg model flags onSubmit = ( { model | value = stream }, searchStreams flags stream ) GoToStream stream -> - ( { model | value = "" }, onSubmit stream ) + ( model, onSubmit stream ) SearchedStreamsFetched (Ok streams) -> ( { model | streams = "all" :: List.map .streamId streams }, Cmd.none ) From e22eeadba4435b5dc22023f3578ac9a0b99171a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:47:57 +0200 Subject: [PATCH 60/92] Revert "kill mutants" This reverts commit ae7b96bd73c9a81fbb6a8d518e19182ec239d78f. --- ruby_event_store-browser/lib/ruby_event_store/browser/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb index af6d495578..46b9ed2912 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb @@ -94,7 +94,7 @@ def call(env) page: params["page"] ) end - router.add_route("GET", "/api/search_streams/:stream_name") do |params| + router.add_route("GET", "/api/search_streams/:stream_name") do |params, urls| json SearchStreams.new( event_store: event_store, stream_name: params.fetch("stream_name"), From e66f79a5e98569e844387c7f27f4e352af9b8b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:49:12 +0200 Subject: [PATCH 61/92] Revert "Hide dialog when stream is selected" This reverts commit 0f0c61fd2c03dfd6a6d18abf4c7b614442d8d235. --- ruby_event_store-browser/elm/src/Layout.elm | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 23433a37fd..9efd0eb958 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -80,17 +80,7 @@ update msg model = ( newSearch, cmd ) = Search.update searchMsg model.internal.search model.flags (goToStream model) in - case searchMsg of - GoToStream _ -> - ( { model | internal = Model newSearch } - , Cmd.batch - [ Cmd.map SearchMsg cmd - , toggleDialog searchModalId - ] - ) - - _ -> - ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) + ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) TimeZoneSelected zoneName -> let @@ -324,7 +314,7 @@ searchModal model = [ button [ onClick ToggleDialog, class "inset-0 fixed z-0" ] [ text "" ] - , div [ class "isolate" ] + , div [ class "isolate "] [ realSearchInput model ] ] From b9c6c113237dc7abe9f1a267c3f48b84413d4ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:49:17 +0200 Subject: [PATCH 62/92] Revert "Kill mutants" This reverts commit c7556ea6ba11f338ac248ae2073aeb51198c083f. --- .../lib/ruby_event_store/in_memory_repository.rb | 1 + .../lib/ruby_event_store/spec/event_repository_lint.rb | 9 --------- 2 files changed, 1 insertion(+), 9 deletions(-) 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 681c3829f5..45ee6fef75 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 @@ -129,6 +129,7 @@ def streams_of(event_id) def search_streams(stream_name) streams .select { |name,| name.downcase.include?(stream_name.downcase) } + .to_a .take(10) .reverse .map { |name,| Stream.new(name) } 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 1cd112594b..25e4e5a9ba 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 @@ -1202,15 +1202,6 @@ def read_events_backward(repository, stream = nil, from: nil, to: nil, count: ni expect(repository.search_streams("Stream C")).to eq [stream_c] end - specify do - 11.times do |index| - stream = Stream.new("Stream #{index}") - repository.append_to_stream([ SRecord.new(event_id: SecureRandom.uuid)], stream, version_any) - end - - expect(repository.search_streams("stream").size).to eq 10 - end - specify do e1 = SRecord.new(event_id: "8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea") e2 = SRecord.new(event_id: "8cee1139-4f96-483a-a175-2b947283c3c7") From b2d8dfed346fb66cf917a027ee7e9b5b713b9cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:49:20 +0200 Subject: [PATCH 63/92] Revert "Limit number of searched streams to 10" This reverts commit b41cc6b702cc773b276443712c70375bfa04b434. --- .../active_record/event_repository_reader.rb | 2 +- .../spec/event_repository_spec.rb | 12 ------------ .../spec/api/search_streams_spec.rb | 13 +------------ .../lib/ruby_event_store/in_memory_repository.rb | 1 - 4 files changed, 2 insertions(+), 26 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb index 87eef89b2a..8d65059017 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb @@ -58,7 +58,7 @@ def event_in_stream?(event_id, stream) end def search_streams(stream) - @stream_klass.where("lower(stream) LIKE ?", "#{stream.downcase}%").order("position DESC, id DESC").limit(10).pluck(:stream).map { |name| Stream.new(name) } + @stream_klass.where("lower(stream) LIKE ?", "#{stream.downcase}%").order("position DESC, id DESC").pluck(:stream).map { |name| Stream.new(name) } end private diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 59557f75b4..0ce7a87461 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -208,18 +208,6 @@ module ActiveRecord expect(repository.search_streams("Dummy")).to eq([s3, s2, s1]) end - specify "limits searched streams to 10" do - 11.times do |index| - repository.append_to_stream( - [SRecord.new(event_id: e1 = SecureRandom.uuid)], - Stream.new("Dummy$#{e1}"), - ExpectedVersion.any - ) - end - - expect(repository.search_streams("Du").size).to eq 10 - end - specify "finds no streams when search phrase doesn't match anything" do repository.append_to_stream( [SRecord.new(event_id: e1 = SecureRandom.uuid)], diff --git a/ruby_event_store-browser/spec/api/search_streams_spec.rb b/ruby_event_store-browser/spec/api/search_streams_spec.rb index e82e1503b9..97a52a5c7c 100644 --- a/ruby_event_store-browser/spec/api/search_streams_spec.rb +++ b/ruby_event_store-browser/spec/api/search_streams_spec.rb @@ -4,7 +4,7 @@ module RubyEventStore ::RSpec.describe Browser do include Browser::IntegrationHelpers - specify "finds desired streams" do + specify "something" do event_store.publish(DummyEvent.new, stream_name: "dummy-1") event_store.publish(DummyEvent.new, stream_name: "dummy-2") @@ -26,16 +26,5 @@ module RubyEventStore [{ "id" => "dummy-2", "type" => "streams" }, { "id" => "dummy-1", "type" => "streams" }] ) end - - specify "limits results to 10" do - 11.times do |index| - event_store.publish(DummyEvent.new, stream_name: "dummy-#{index}") - end - - api_client.get "/api/search_streams/dum" - - expect(api_client.last_response).to be_ok - expect(api_client.parsed_body["data"].size).to eq(10) - end end end 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 45ee6fef75..fad6f0a89f 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 @@ -130,7 +130,6 @@ def search_streams(stream_name) streams .select { |name,| name.downcase.include?(stream_name.downcase) } .to_a - .take(10) .reverse .map { |name,| Stream.new(name) } end From fe6a5bba0a6dd038713eb368174f49b2d7e7e6e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:49:23 +0200 Subject: [PATCH 64/92] Revert "Make global stream available on top of the search" This reverts commit 9f5c25d5ad283356105027c60e5f842b4ccf8c7d. --- ruby_event_store-browser/elm/src/Search.elm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 1bd9bab57e..eef97ee1c9 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -29,7 +29,7 @@ type Msg init : Model init = - { streams = [ "all" ] + { streams = [] , value = "" } @@ -58,7 +58,7 @@ update msg model flags onSubmit = ( model, onSubmit stream ) SearchedStreamsFetched (Ok streams) -> - ( { model | streams = "all" :: List.map .streamId streams }, Cmd.none ) + ( { model | streams = List.map .streamId streams }, Cmd.none ) SearchedStreamsFetched (Err _) -> ( { model | streams = [] }, Cmd.none ) From adde5f135d6f4c45dd44cb2ee5eb2e42ac532f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:51:06 +0200 Subject: [PATCH 65/92] Revert "Add repositoryAdapter eml flag" This reverts commit 2d8de23e070eaf5cecb59d28a79a96fbf9f44e2b. --- ruby_event_store-browser/elm/src/Flags.elm | 6 +- ruby_event_store-browser/elm/src/Main.elm | 2 +- .../elm/src/Page/Debug.elm | 14 ++- .../lib/ruby_event_store/browser/app.rb | 90 ++++++++++++------- 4 files changed, 65 insertions(+), 47 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Flags.elm b/ruby_event_store-browser/elm/src/Flags.elm index 372acbe756..d24891ab10 100644 --- a/ruby_event_store-browser/elm/src/Flags.elm +++ b/ruby_event_store-browser/elm/src/Flags.elm @@ -7,7 +7,6 @@ type alias RawFlags = { rootUrl : String , apiUrl : String , resVersion : String - , repositoryAdapter : String , platform : String } @@ -16,11 +15,10 @@ type alias Flags = { rootUrl : Url.Url , apiUrl : Url.Url , resVersion : String - , repositoryAdapter : String , platform : String } buildFlags : RawFlags -> Maybe Flags -buildFlags { rootUrl, apiUrl, resVersion, repositoryAdapter, platform } = - Maybe.map5 Flags (Url.fromString rootUrl) (Url.fromString apiUrl) (Just resVersion) (Just repositoryAdapter) (Just platform) +buildFlags { rootUrl, apiUrl, resVersion, platform } = + Maybe.map4 Flags (Url.fromString rootUrl) (Url.fromString apiUrl) (Just resVersion) (Just platform) diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index c379067ae8..19f4f8ba14 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -215,7 +215,7 @@ navigate model location = ( { model | page = NotFound }, Cmd.none ) Just (Route.Debug) -> - ( { model | page = Debug (Page.Debug.init flags) }, Cmd.none ) + ( { model | page = Debug (Page.Debug.init flags.resVersion) }, Cmd.none ) Nothing -> ( { model | page = NotFound }, Cmd.none ) diff --git a/ruby_event_store-browser/elm/src/Page/Debug.elm b/ruby_event_store-browser/elm/src/Page/Debug.elm index 016d8e4926..e75b0c2a85 100644 --- a/ruby_event_store-browser/elm/src/Page/Debug.elm +++ b/ruby_event_store-browser/elm/src/Page/Debug.elm @@ -1,17 +1,13 @@ module Page.Debug exposing (..) import Html exposing (..) -import Flags exposing (Flags) -type alias Model = { resVersion : String, repositoryAdapter : String } +type alias Model = { resVersion : String } -init : Flags -> Model -init flags = - { resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter } +init : String -> Model +init resVersion = + { resVersion = resVersion } view: Model -> Html a view model = - div [] [ - p [] [text ("RubyEventStore version: " ++ model.resVersion)], - p [] [text ("RubyEventStore adapter: " ++ model.repositoryAdapter)] - ] + text ("RubyEventStore version: " ++ model.resVersion) diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb index 46b9ed2912..18234915bc 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb @@ -40,23 +40,24 @@ def self.for( Rack::Builder.new do use Rack::Static, - urls: %w[ - bootstrap.js - ruby_event_store_browser.css - ruby_event_store_browser.js - android-chrome-192x192.png - android-chrome-512x512.png - apple-touch-icon.png - favicon.ico - favicon-16x16.png - favicon-32x32.png - mstile-70x70.png - mstile-144x144.png - mstile-150x150.png - mstile-310x150.png - mstile-310x310.png - safari-pinned-tab.svg - ].map {|f| ["/#{f}", f] }.to_h, + urls: + %w[ + bootstrap.js + ruby_event_store_browser.css + ruby_event_store_browser.js + android-chrome-192x192.png + android-chrome-512x512.png + apple-touch-icon.png + favicon.ico + favicon-16x16.png + favicon-32x32.png + mstile-70x70.png + mstile-144x144.png + mstile-150x150.png + mstile-310x150.png + mstile-310x310.png + safari-pinned-tab.svg + ].map { |f| ["/#{f}", f] }.to_h, root: "#{__dir__}/../../../public" run App.new( event_store_locator: event_store_locator, @@ -68,7 +69,13 @@ def self.for( end end - def initialize(event_store_locator:, related_streams_query:, host:, root_path:, api_url:) + def initialize( + event_store_locator:, + related_streams_query:, + host:, + root_path:, + api_url: + ) @event_store_locator = event_store_locator @related_streams_query = related_streams_query @routing = Urls.from_configuration(host, root_path, api_url) @@ -77,7 +84,10 @@ def initialize(event_store_locator:, related_streams_query:, host:, root_path:, def call(env) router = Router.new(routing) router.add_route("GET", "/api/events/:event_id") do |params| - json GetEvent.new(event_store: event_store, event_id: params.fetch("event_id")) + json GetEvent.new( + event_store: event_store, + event_id: params.fetch("event_id") + ) end router.add_route("GET", "/api/streams/:stream_name") do |params, urls| json GetStream.new( @@ -86,7 +96,10 @@ def call(env) related_streams_query: related_streams_query ) end - router.add_route("GET", "/api/streams/:stream_name/relationships/events") do |params, urls| + router.add_route( + "GET", + "/api/streams/:stream_name/relationships/events" + ) do |params, urls| json GetEventsFromStream.new( event_store: event_store, routing: urls, @@ -94,14 +107,22 @@ def call(env) page: params["page"] ) end - router.add_route("GET", "/api/search_streams/:stream_name") do |params, urls| + router.add_route( + "GET", + "/api/search_streams/:stream_name" + ) do |params, urls| json SearchStreams.new( - event_store: event_store, - stream_name: params.fetch("stream_name"), - ) + event_store: event_store, + stream_name: params.fetch("stream_name") + ) end - %w[/ /events/:event_id /streams/:stream_name /debug].each do |starting_route| + %w[ + / + /events/:event_id + /streams/:stream_name + /debug + ].each do |starting_route| router.add_route("GET", starting_route) do |_, urls| erb bootstrap_html, browser_js_src: urls.browser_js_url, @@ -110,8 +131,7 @@ def call(env) initial_data: { rootUrl: urls.app_url, apiUrl: urls.api_url, - resVersion: res_version, - repositoryAdapter: repository_adapter + resVersion: res_version } end end @@ -156,20 +176,24 @@ def not_found end def json(body) - [200, { "content-type" => "application/vnd.api+json" }, [JSON.dump(body.to_h)]] + [ + 200, + { "content-type" => "application/vnd.api+json" }, + [JSON.dump(body.to_h)] + ] end def erb(template, **locals) - [200, { "content-type" => "text/html;charset=utf-8" }, [ERB.new(template).result_with_hash(locals)]] + [ + 200, + { "content-type" => "text/html;charset=utf-8" }, + [ERB.new(template).result_with_hash(locals)] + ] end def res_version RubyEventStore::VERSION end - - def repository_adapter - event_store.repository_specification - end end end end From 0a2d6f2cc1e7c95309b50572348bc4f56c939dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:53:15 +0200 Subject: [PATCH 66/92] Revert "Debug module with its own model" This reverts commit 8a61cd9ca379d6d8d9495714ccd29597fab43ec1. --- ruby_event_store-browser/elm/src/Main.elm | 8 ++++---- ruby_event_store-browser/elm/src/Page/Debug.elm | 12 +++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index 19f4f8ba14..b33008d0ca 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -56,7 +56,7 @@ type Page = NotFound | ShowEvent Page.ShowEvent.Model | ShowStream Page.ShowStream.Model - | Debug Page.Debug.Model + | Debug subscriptions : Model -> Sub Msg @@ -215,7 +215,7 @@ navigate model location = ( { model | page = NotFound }, Cmd.none ) Just (Route.Debug) -> - ( { model | page = Debug (Page.Debug.init flags.resVersion) }, Cmd.none ) + ( { model | page = Debug }, Cmd.none ) Nothing -> ( { model | page = NotFound }, Cmd.none ) @@ -269,10 +269,10 @@ viewPage page selectedTime = in ( Just title, Html.map GotShowEventMsg content ) - Debug pageModel -> + Debug -> let content = - Page.Debug.view pageModel + Page.Debug.view in ( Just "Debug", content ) diff --git a/ruby_event_store-browser/elm/src/Page/Debug.elm b/ruby_event_store-browser/elm/src/Page/Debug.elm index e75b0c2a85..2c4bd51d80 100644 --- a/ruby_event_store-browser/elm/src/Page/Debug.elm +++ b/ruby_event_store-browser/elm/src/Page/Debug.elm @@ -2,12 +2,6 @@ module Page.Debug exposing (..) import Html exposing (..) -type alias Model = { resVersion : String } - -init : String -> Model -init resVersion = - { resVersion = resVersion } - -view: Model -> Html a -view model = - text ("RubyEventStore version: " ++ model.resVersion) +view: Html a +view = + text "to be filled with some helpful content" From 9ecd55774cd40cbd175b804d88c7fbf00d0b234d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:54:15 +0200 Subject: [PATCH 67/92] Revert "Set value when is exact stream" This reverts commit dc74ff7a3fc04a35518db1628f13e7938ac2089f. --- ruby_event_store-browser/elm/src/Search.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index eef97ee1c9..4fa5351735 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -49,7 +49,7 @@ update msg model flags onSubmit = case msg of StreamChanged stream -> if isExactStream stream model.streams then - ( { model | value = stream }, onSubmit stream ) + ( model, onSubmit stream ) else ( { model | value = stream }, searchStreams flags stream ) From 59f8fbe8ef2c023bd24793d0f3a8c5ac835de7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:54:21 +0200 Subject: [PATCH 68/92] Revert "refactor" This reverts commit 4586316e3ecd6484a6f92a1f2f5a88e0e37b5cfb. --- ruby_event_store-browser/elm/src/Search.elm | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 4fa5351735..d584fb680d 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -39,18 +39,12 @@ searchStreams flags stream = getSearchStreams SearchedStreamsFetched flags stream -isExactStream : String -> List String -> Bool -isExactStream stream streams = - List.any (\s -> s == stream) streams - - update : Msg -> Model -> Flags -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) update msg model flags onSubmit = case msg of StreamChanged stream -> - if isExactStream stream model.streams then - ( model, onSubmit stream ) - + if List.any (\s -> s == stream) model.streams then + ( model, onSubmit stream ) else ( { model | value = stream }, searchStreams flags stream ) From 20b62fd1a73034680262f66ffe549321bf80a948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:54:28 +0200 Subject: [PATCH 69/92] Revert "Redirect to stream on exact match" This reverts commit bca63ae841997877796c3f49c32325432c3e4811. --- ruby_event_store-browser/elm/src/Search.elm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index d584fb680d..17cd2487ac 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -7,7 +7,6 @@ import Html exposing (..) import Html.Attributes exposing (autofocus, class, id, list, placeholder, value) import Html.Events exposing (onInput, onSubmit) import Http -import List exposing (any) import Page.ShowStream exposing (Msg(..)) @@ -43,10 +42,7 @@ update : Msg -> Model -> Flags -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) update msg model flags onSubmit = case msg of StreamChanged stream -> - if List.any (\s -> s == stream) model.streams then - ( model, onSubmit stream ) - else - ( { model | value = stream }, searchStreams flags stream ) + ( { model | value = stream }, searchStreams flags stream ) GoToStream stream -> ( model, onSubmit stream ) From e066ff05fd00846fc9723d79d5c0802eed92849a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:54:31 +0200 Subject: [PATCH 70/92] Revert "move Debug page to separate module" This reverts commit 99cf19a3cb38fd251c22dcd0f288db14ea8e7c75. --- ruby_event_store-browser/elm/src/Main.elm | 7 +------ ruby_event_store-browser/elm/src/Page/Debug.elm | 7 ------- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 ruby_event_store-browser/elm/src/Page/Debug.elm diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index b33008d0ca..e2187e2024 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -10,7 +10,6 @@ import Layout import LinkedTimezones exposing (mapLinkedTimeZone) import Page.ShowEvent import Page.ShowStream -import Page.Debug import Route import Task import Time @@ -270,11 +269,7 @@ viewPage page selectedTime = ( Just title, Html.map GotShowEventMsg content ) Debug -> - let - content = - Page.Debug.view - in - ( Just "Debug", content ) + ( Just "Debug", text "to be filled with some helpful content" ) NotFound -> ( Nothing, Layout.viewNotFound ) diff --git a/ruby_event_store-browser/elm/src/Page/Debug.elm b/ruby_event_store-browser/elm/src/Page/Debug.elm deleted file mode 100644 index 2c4bd51d80..0000000000 --- a/ruby_event_store-browser/elm/src/Page/Debug.elm +++ /dev/null @@ -1,7 +0,0 @@ -module Page.Debug exposing (..) - -import Html exposing (..) - -view: Html a -view = - text "to be filled with some helpful content" From 63e26d2c73c9fd213adaa36230cb50208f4dded8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:56:52 +0200 Subject: [PATCH 71/92] Revert "Autocomplete stream names" This reverts commit 5aa78154c1aa46b59e99213c294d5aecbf30f627. --- ruby_event_store-browser/elm/src/Layout.elm | 2 +- ruby_event_store-browser/elm/src/Search.elm | 27 +++------------------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 9efd0eb958..4ebb82727a 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -78,7 +78,7 @@ update msg model = SearchMsg searchMsg -> let ( newSearch, cmd ) = - Search.update searchMsg model.internal.search model.flags (goToStream model) + Search.update searchMsg model.internal.search (goToStream model) in ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 17cd2487ac..0cd31a20b1 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -1,13 +1,9 @@ module Search exposing (..) -import Api exposing (SearchStream, getSearchStreams) import FeatherIcons -import Flags exposing (Flags) import Html exposing (..) import Html.Attributes exposing (autofocus, class, id, list, placeholder, value) import Html.Events exposing (onInput, onSubmit) -import Http -import Page.ShowStream exposing (Msg(..)) type alias Stream = @@ -23,7 +19,6 @@ type alias Model = type Msg = StreamChanged Stream | GoToStream Stream - | SearchedStreamsFetched (Result Http.Error (List SearchStream)) init : Model @@ -33,26 +28,15 @@ init = } -searchStreams : Flags -> Stream -> Cmd Msg -searchStreams flags stream = - getSearchStreams SearchedStreamsFetched flags stream - - -update : Msg -> Model -> Flags -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) -update msg model flags onSubmit = +update : Msg -> Model -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) +update msg model onSubmit = case msg of StreamChanged stream -> - ( { model | value = stream }, searchStreams flags stream ) + ( { model | value = stream }, Cmd.none ) GoToStream stream -> ( model, onSubmit stream ) - SearchedStreamsFetched (Ok streams) -> - ( { model | streams = List.map .streamId streams }, Cmd.none ) - - SearchedStreamsFetched (Err _) -> - ( { model | streams = [] }, Cmd.none ) - view : Model -> Html Msg view model = @@ -76,8 +60,5 @@ view model = ] , datalist [ id "streams", class "appearance-none" ] - (List.map - (\stream -> option [] [ text stream ]) - model.streams - ) + [] ] From 5d90be99b3355eceb5c77e47dbf3a63b7bcb1a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:57:01 +0200 Subject: [PATCH 72/92] Revert "Revert "Use WrappedModel in search"" This reverts commit 84529ae9d47e347ce298b1e87d6aa1a41a4c0e8f. --- ruby_event_store-browser/elm/src/Layout.elm | 13 +++++++++++-- ruby_event_store-browser/elm/src/Search.elm | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 4ebb82727a..9ccba1f5ac 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -77,8 +77,17 @@ update msg model = case msg of SearchMsg searchMsg -> let - ( newSearch, cmd ) = - Search.update searchMsg model.internal.search (goToStream model) + internal = + model.internal + + search = + internal.search + + ( newSearchWrapped, cmd ) = + Search.update searchMsg (WrappedModel search model.key model.time model.flags) (goToStream model) + + newSearch = + newSearchWrapped.internal in ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 0cd31a20b1..57a833a715 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -4,6 +4,7 @@ import FeatherIcons import Html exposing (..) import Html.Attributes exposing (autofocus, class, id, list, placeholder, value) import Html.Events exposing (onInput, onSubmit) +import WrappedModel exposing (WrappedModel) type alias Stream = @@ -28,11 +29,21 @@ init = } -update : Msg -> Model -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) +update : Msg -> WrappedModel Model -> (String -> Cmd Msg) -> ( WrappedModel Model, Cmd Msg ) update msg model onSubmit = case msg of StreamChanged stream -> - ( { model | value = stream }, Cmd.none ) + let + internal = + model.internal + + updatedInternal = + { internal | value = stream } + + wrappedModel = + { model | internal = updatedInternal } + in + ( wrappedModel, Cmd.none ) GoToStream stream -> ( model, onSubmit stream ) From 93daea23e009d16bd36a3531a7e5e08e8203d410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:57:05 +0200 Subject: [PATCH 73/92] Revert "Use WrappedModel in search" This reverts commit 61839679799a36da0f4bc1f98081cbb70b7f0fb9. --- ruby_event_store-browser/elm/src/Layout.elm | 13 ++----------- ruby_event_store-browser/elm/src/Search.elm | 15 ++------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 9ccba1f5ac..4ebb82727a 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -77,17 +77,8 @@ update msg model = case msg of SearchMsg searchMsg -> let - internal = - model.internal - - search = - internal.search - - ( newSearchWrapped, cmd ) = - Search.update searchMsg (WrappedModel search model.key model.time model.flags) (goToStream model) - - newSearch = - newSearchWrapped.internal + ( newSearch, cmd ) = + Search.update searchMsg model.internal.search (goToStream model) in ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 57a833a715..0cd31a20b1 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -4,7 +4,6 @@ import FeatherIcons import Html exposing (..) import Html.Attributes exposing (autofocus, class, id, list, placeholder, value) import Html.Events exposing (onInput, onSubmit) -import WrappedModel exposing (WrappedModel) type alias Stream = @@ -29,21 +28,11 @@ init = } -update : Msg -> WrappedModel Model -> (String -> Cmd Msg) -> ( WrappedModel Model, Cmd Msg ) +update : Msg -> Model -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) update msg model onSubmit = case msg of StreamChanged stream -> - let - internal = - model.internal - - updatedInternal = - { internal | value = stream } - - wrappedModel = - { model | internal = updatedInternal } - in - ( wrappedModel, Cmd.none ) + ( { model | value = stream }, Cmd.none ) GoToStream stream -> ( model, onSubmit stream ) From fd824e5a31a90a68088cc6d198dafaf294f11313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:58:14 +0200 Subject: [PATCH 74/92] Revert "initiate /debug browser page" This reverts commit 623c125ff3ce20bb8e150db2451a3d50293e93b4. --- ruby_event_store-browser/elm/src/Main.elm | 7 ------- ruby_event_store-browser/elm/src/Route.elm | 2 -- .../lib/ruby_event_store/browser/app.rb | 7 +------ 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Main.elm b/ruby_event_store-browser/elm/src/Main.elm index e2187e2024..d18aa4cab6 100644 --- a/ruby_event_store-browser/elm/src/Main.elm +++ b/ruby_event_store-browser/elm/src/Main.elm @@ -55,7 +55,6 @@ type Page = NotFound | ShowEvent Page.ShowEvent.Model | ShowStream Page.ShowStream.Model - | Debug subscriptions : Model -> Sub Msg @@ -213,9 +212,6 @@ navigate model location = Nothing -> ( { model | page = NotFound }, Cmd.none ) - Just (Route.Debug) -> - ( { model | page = Debug }, Cmd.none ) - Nothing -> ( { model | page = NotFound }, Cmd.none ) @@ -268,8 +264,5 @@ viewPage page selectedTime = in ( Just title, Html.map GotShowEventMsg content ) - Debug -> - ( Just "Debug", text "to be filled with some helpful content" ) - NotFound -> ( Nothing, Layout.viewNotFound ) diff --git a/ruby_event_store-browser/elm/src/Route.elm b/ruby_event_store-browser/elm/src/Route.elm index 6aa7599145..e50aa6a95d 100644 --- a/ruby_event_store-browser/elm/src/Route.elm +++ b/ruby_event_store-browser/elm/src/Route.elm @@ -12,7 +12,6 @@ import Url.Parser.Query as Query type Route = BrowseEvents String Pagination.Specification | ShowEvent String - | Debug decodeLocation : Url.Url -> Url.Url -> Maybe Route @@ -26,7 +25,6 @@ routeParser = [ Url.Parser.map (BrowseEvents "all" Pagination.empty) Url.Parser.top , Url.Parser.map browseEvents (Url.Parser.s "streams" Url.Parser.string Query.string "page[position]" Query.string "page[direction]" Query.string "page[count]") , Url.Parser.map ShowEvent (Url.Parser.s "events" Url.Parser.string) - , Url.Parser.map Debug (Url.Parser.s "debug" Url.Parser.top) ] diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb index 18234915bc..249bd66a38 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb @@ -117,12 +117,7 @@ def call(env) ) end - %w[ - / - /events/:event_id - /streams/:stream_name - /debug - ].each do |starting_route| + %w[/ /events/:event_id /streams/:stream_name].each do |starting_route| router.add_route("GET", starting_route) do |_, urls| erb bootstrap_html, browser_js_src: urls.browser_js_url, From 7c17c7683f22120b028312f62c1356bba35c0fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 14:59:28 +0200 Subject: [PATCH 75/92] Revert "No need those gymnastics with Maybe" This reverts commit 5ae886ac3041c2a7a8ae21b66839a79dd9e17ec1. --- ruby_event_store-browser/elm/src/Search.elm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Search.elm b/ruby_event_store-browser/elm/src/Search.elm index 0cd31a20b1..af488ef24a 100644 --- a/ruby_event_store-browser/elm/src/Search.elm +++ b/ruby_event_store-browser/elm/src/Search.elm @@ -12,7 +12,7 @@ type alias Stream = type alias Model = { streams : List Stream - , value : Stream + , value : Maybe Stream } @@ -24,15 +24,25 @@ type Msg init : Model init = { streams = [] - , value = "" + , value = Nothing } +extractStream : Maybe Stream -> Stream +extractStream maybeStream = + case maybeStream of + Just stream -> + stream + + Nothing -> + "" + + update : Msg -> Model -> (String -> Cmd Msg) -> ( Model, Cmd Msg ) update msg model onSubmit = case msg of StreamChanged stream -> - ( { model | value = stream }, Cmd.none ) + ( { model | value = Just stream }, Cmd.none ) GoToStream stream -> ( model, onSubmit stream ) @@ -40,14 +50,14 @@ update msg model onSubmit = view : Model -> Html Msg view model = - form [ onSubmit (GoToStream model.value) ] + form [ onSubmit (GoToStream (extractStream model.value)) ] [ div [ class "relative" ] [ FeatherIcons.search |> FeatherIcons.withClass "size-4 text-gray-400 absolute pointer-events-none top-3.5 left-2" |> FeatherIcons.toHtml [] , input [ class "rounded text-gray-800 cursor-pointer pl-8 pr-12 py-2 w-full appearance-none outline-none focus:ring-2 focus:ring-red-500 focus:ring-opacity-50" - , value model.value + , value (extractStream model.value) , onInput StreamChanged , placeholder "Quick search…" , list "streams" From eca467834ac8982ee78293dc36fab3d8f5449e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:08:01 +0200 Subject: [PATCH 76/92] Revert "Don't render search streams here" This reverts commit 203f6cd8b2fa2be99318551d7fb2bc8997389264. --- ruby_event_store-browser/elm/src/Page/ShowStream.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-browser/elm/src/Page/ShowStream.elm b/ruby_event_store-browser/elm/src/Page/ShowStream.elm index e7a093772a..5a633222cc 100644 --- a/ruby_event_store-browser/elm/src/Page/ShowStream.elm +++ b/ruby_event_store-browser/elm/src/Page/ShowStream.elm @@ -54,7 +54,7 @@ type Msg initCmd : Flags -> String -> Cmd Msg initCmd flags streamId = - Api.getStream StreamFetched flags streamId + Cmd.batch [ Api.getStream StreamFetched flags streamId, Api.getSearchStreams SearchedStreamsFetched ] update : Msg -> Model -> ( Model, Cmd Msg ) From e85e710aaf2223ca103604425916e047e6eea523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:08:05 +0200 Subject: [PATCH 77/92] Revert "Use function" This reverts commit e7ddcf9124057f97713b0391251954c2898e3f38. --- ruby_event_store-browser/elm/src/Api.elm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index 6ed645f59a..aed0e81891 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -110,10 +110,10 @@ getStream msgBuilder flags streamId = } -getSearchStreams : (Result Http.Error (List SearchStream) -> msg) -> Flags -> String -> Cmd msg -getSearchStreams msgBuilder flags query = +getSearchStreams : (Result Http.Error (List SearchStream) -> msg) -> Cmd msg +getSearchStreams msgBuilder = Http.get - { url = searchStreamsUrl flags query + { url = "//localhost:9393/api/search_streams/dum" , expect = Http.expectJson msgBuilder searchStreamsDecoder } From 048a84c8d9b6fa33b038f2d4022869aaefee57a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:08:08 +0200 Subject: [PATCH 78/92] Revert "Extract function" This reverts commit f0bc5ce8edf154db6c6cd5ff0c15759301dc4f97. --- ruby_event_store-browser/elm/src/Api.elm | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index aed0e81891..8782a27aaa 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -89,11 +89,6 @@ streamUrl flags streamId = buildUrl (Url.toString flags.apiUrl ++ "/streams") streamId -searchStreamsUrl : Flags -> String -> String -searchStreamsUrl flags query = - buildUrl (Url.toString flags.apiUrl ++ "/search_streams") query - - getEvent : (Result Http.Error Event -> msg) -> Flags -> String -> Cmd msg getEvent msgBuilder flags eventId = Http.get From 0b53bf41d33e448f7f084f22a17c5a76a000d927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:08:11 +0200 Subject: [PATCH 79/92] Revert "Kill mutant" This reverts commit 52e7a56be683aec39b003efb1fce901c1e6c23b4. --- ruby_event_store-active_record/spec/event_repository_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 0ce7a87461..885ff21301 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -196,7 +196,7 @@ module ActiveRecord ) repository.append_to_stream( [SRecord.new(event_id: e3 = SecureRandom.uuid)], - s3 = Stream.new("dUmMY$#{e3}"), + s3 = Stream.new("Dummy$#{e3}"), ExpectedVersion.any ) From dede46747a1d1a6c2cc465f472568ef082b9b8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:08:14 +0200 Subject: [PATCH 80/92] Revert "lowercase" This reverts commit d22b979cca41bff080d5eb0b48488f46849a2b64. --- .../ruby_event_store/active_record/event_repository_reader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb index 8d65059017..73a69f7965 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb @@ -58,7 +58,7 @@ def event_in_stream?(event_id, stream) end def search_streams(stream) - @stream_klass.where("lower(stream) LIKE ?", "#{stream.downcase}%").order("position DESC, id DESC").pluck(:stream).map { |name| Stream.new(name) } + @stream_klass.where("stream LIKE ?", "#{stream}%").order("position DESC, id DESC").pluck(:stream).map { |name| Stream.new(name) } end private From 30ca059cab02397e098ba8791d4bb077bb5c3499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:09:40 +0200 Subject: [PATCH 81/92] Revert "render search streams" This reverts commit a8fd23628d88c9e967288e7ea52bd5e61ce69a88. --- ruby_event_store-browser/elm/src/Api.elm | 2 +- .../elm/src/Page/ShowStream.elm | 26 ++++--------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index 8782a27aaa..8a8020d20a 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -1,4 +1,4 @@ -module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), SearchStream, Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getSearchStreams, getStream, searchStreamsDecoder) +module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getStream, searchStreamsDecoder) import Flags exposing (Flags) import Http diff --git a/ruby_event_store-browser/elm/src/Page/ShowStream.elm b/ruby_event_store-browser/elm/src/Page/ShowStream.elm index 5a633222cc..df125ca05e 100644 --- a/ruby_event_store-browser/elm/src/Page/ShowStream.elm +++ b/ruby_event_store-browser/elm/src/Page/ShowStream.elm @@ -22,7 +22,6 @@ type alias Model = , relatedStreams : Maybe (List String) , problems : List Problem , pagination : Pagination.Specification - , searchStreams : List Api.SearchStream } @@ -38,7 +37,6 @@ initModel flags streamName paginationSpecification = , flags = flags , problems = [] , pagination = paginationSpecification - , searchStreams = [] } @@ -49,12 +47,11 @@ initModel flags streamName paginationSpecification = type Msg = EventsFetched (Result Http.Error (Api.PaginatedList Api.Event)) | StreamFetched (Result Http.Error Api.Stream) - | SearchedStreamsFetched (Result Http.Error (List Api.SearchStream)) initCmd : Flags -> String -> Cmd Msg initCmd flags streamId = - Cmd.batch [ Api.getStream StreamFetched flags streamId, Api.getSearchStreams SearchedStreamsFetched ] + Api.getStream StreamFetched flags streamId update : Msg -> Model -> ( Model, Cmd Msg ) @@ -80,15 +77,9 @@ update msg model = in ( { model | problems = serverErrors }, Cmd.none ) - SearchedStreamsFetched (Ok result) -> - ( { model | searchStreams = result }, Cmd.none ) - - SearchedStreamsFetched (Err _) -> - ( model, Cmd.none ) - view : Model -> BrowserTime.TimeZone -> ( String, Html Msg ) -view { streamName, events, relatedStreams, problems, flags, pagination, searchStreams } selectedTime = +view { streamName, events, relatedStreams, problems, flags, pagination } selectedTime = let title = "Stream " ++ streamName @@ -99,7 +90,7 @@ view { streamName, events, relatedStreams, problems, flags, pagination, searchSt case problems of [] -> ( title - , browseEvents flags.rootUrl header streamName events relatedStreams selectedTime searchStreams + , browseEvents flags.rootUrl header streamName events relatedStreams selectedTime ) _ -> @@ -115,8 +106,8 @@ view { streamName, events, relatedStreams, problems, flags, pagination, searchSt ) -browseEvents : Url.Url -> String -> String -> Api.PaginatedList Api.Event -> Maybe (List String) -> BrowserTime.TimeZone -> List Api.SearchStream -> Html Msg -browseEvents baseUrl title streamName { links, events } relatedStreams timeZone searchStreams = +browseEvents : Url.Url -> String -> String -> Api.PaginatedList Api.Event -> Maybe (List String) -> BrowserTime.TimeZone -> Html Msg +browseEvents baseUrl title streamName { links, events } relatedStreams timeZone = div [ class "py-8 container mx-auto" ] [ div [ class "flex justify-between" ] @@ -127,7 +118,6 @@ browseEvents baseUrl title streamName { links, events } relatedStreams timeZone ] , div [] [ renderResults baseUrl events timeZone ] , div [] [ renderRelatedStreams baseUrl relatedStreams ] - , div [ class "bg-red-500" ] [ renderSearchStreams searchStreams ] ] @@ -142,12 +132,6 @@ viewProblem problem = li [] [ text errorMessage ] -renderSearchStreams : List Api.SearchStream -> Html msg -renderSearchStreams searchStreams = - ul [] - (List.map (\searchStream -> li [] [ text searchStream.streamId ]) searchStreams) - - renderRelatedStreams : Url.Url -> Maybe (List String) -> Html Msg renderRelatedStreams baseUrl relatedStreams_ = case relatedStreams_ of From 3f3883f6b789d92a599837eebcc8d1c2e031ae30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:09:45 +0200 Subject: [PATCH 82/92] Revert "hardcoded api call" This reverts commit 387f56d8ca05e51c4607477229f8b0a9b9767334. --- ruby_event_store-browser/elm/src/Api.elm | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index 8a8020d20a..dffc8804b1 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -105,14 +105,6 @@ getStream msgBuilder flags streamId = } -getSearchStreams : (Result Http.Error (List SearchStream) -> msg) -> Cmd msg -getSearchStreams msgBuilder = - Http.get - { url = "//localhost:9393/api/search_streams/dum" - , expect = Http.expectJson msgBuilder searchStreamsDecoder - } - - eventDecoder : Decoder Event eventDecoder = eventDecoder_ From 8f102d72fa65f6d061a4e5a630f2996d68029b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:09:49 +0200 Subject: [PATCH 83/92] Revert "Add searchStreamsDecoder" This reverts commit 04986f79856f2f2aeece50d11f8f55de470a1070. --- ruby_event_store-browser/elm/src/Api.elm | 19 +---------- .../elm/tests/DecodersTest.elm | 32 +------------------ 2 files changed, 2 insertions(+), 49 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Api.elm b/ruby_event_store-browser/elm/src/Api.elm index dffc8804b1..69f31f008c 100644 --- a/ruby_event_store-browser/elm/src/Api.elm +++ b/ruby_event_store-browser/elm/src/Api.elm @@ -1,4 +1,4 @@ -module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getStream, searchStreamsDecoder) +module Api exposing (Event, PaginatedList, PaginationLink, PaginationLinks, RemoteResource(..), Stream, emptyPaginatedList, eventDecoder, eventsDecoder, getEvent, getEvents, getStream) import Flags exposing (Flags) import Http @@ -38,11 +38,6 @@ type alias Event = } -type alias SearchStream = - { streamId : String - } - - type alias PaginatedList a = { pagination : Pagination.Specification , events : List a @@ -159,18 +154,6 @@ eventsDecoder pagination = |> required "links" linksDecoder -searchStreamDecoder : Decoder SearchStream -searchStreamDecoder = - succeed SearchStream - |> required "id" string - - -searchStreamsDecoder : Decoder (List SearchStream) -searchStreamsDecoder = - list searchStreamDecoder - |> field "data" - - linksDecoder : Decoder PaginationLinks linksDecoder = succeed PaginationLinks diff --git a/ruby_event_store-browser/elm/tests/DecodersTest.elm b/ruby_event_store-browser/elm/tests/DecodersTest.elm index add018c5d7..a90afd1aa4 100644 --- a/ruby_event_store-browser/elm/tests/DecodersTest.elm +++ b/ruby_event_store-browser/elm/tests/DecodersTest.elm @@ -1,6 +1,6 @@ module DecodersTest exposing (suite) -import Api exposing (eventDecoder, eventsDecoder, searchStreamsDecoder) +import Api exposing (eventDecoder, eventsDecoder) import Expect import Json.Decode import Pagination @@ -143,35 +143,5 @@ suite = , validAt = Time.millisToPosix 1513813785273 } ) - , test "search decoder" <| - \_ -> - let - input = - """ - { - "data": [ - { - "id": "$by_tenant_id_133", - "type": "streams" - }, - { - "id": "$by_tenant_id_444", - "type": "streams" - } - ] - } - """ - - output = - Json.Decode.decodeString searchStreamsDecoder input - in - Expect.equal output - (Ok - [ { streamId = "$by_tenant_id_133" - } - , { streamId = "$by_tenant_id_444" - } - ] - ) ] ] From 1f61050cc7655a4b5e226a821e0c47aedb3e3f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:10:44 +0200 Subject: [PATCH 84/92] Revert "search streams endpoint for browser" This reverts commit 2cb25fa1fee11858a4db93a0e3c94bcf54b2bc4e. --- .../lib/ruby_event_store/browser.rb | 1 - .../lib/ruby_event_store/browser/app.rb | 9 ------ .../browser/search_streams.rb | 26 ---------------- .../spec/api/search_streams_spec.rb | 30 ------------------- 4 files changed, 66 deletions(-) delete mode 100644 ruby_event_store-browser/lib/ruby_event_store/browser/search_streams.rb delete mode 100644 ruby_event_store-browser/spec/api/search_streams_spec.rb diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser.rb b/ruby_event_store-browser/lib/ruby_event_store/browser.rb index 8b73ff80d2..c82d1cefce 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser.rb @@ -13,7 +13,6 @@ module Browser require_relative "browser/json_api_stream" require_relative "browser/get_events_from_stream" require_relative "browser/get_stream" -require_relative "browser/search_streams" require_relative "browser/urls" require_relative "browser/gem_source" require_relative "browser/router" diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb index 249bd66a38..154aade724 100644 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb +++ b/ruby_event_store-browser/lib/ruby_event_store/browser/app.rb @@ -107,15 +107,6 @@ def call(env) page: params["page"] ) end - router.add_route( - "GET", - "/api/search_streams/:stream_name" - ) do |params, urls| - json SearchStreams.new( - event_store: event_store, - stream_name: params.fetch("stream_name") - ) - end %w[/ /events/:event_id /streams/:stream_name].each do |starting_route| router.add_route("GET", starting_route) do |_, urls| diff --git a/ruby_event_store-browser/lib/ruby_event_store/browser/search_streams.rb b/ruby_event_store-browser/lib/ruby_event_store/browser/search_streams.rb deleted file mode 100644 index 84aa4562d8..0000000000 --- a/ruby_event_store-browser/lib/ruby_event_store/browser/search_streams.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -module RubyEventStore - module Browser - class SearchStreams - def initialize(event_store:, stream_name:) - @event_store = event_store - @stream_name = stream_name - end - - def to_h - { - data: streams - } - end - - private - - def streams - event_store.search_streams(stream_name).map { |stream| { id: stream.name, type: "streams" } } - end - - attr_reader :event_store, :stream_name - end - end -end diff --git a/ruby_event_store-browser/spec/api/search_streams_spec.rb b/ruby_event_store-browser/spec/api/search_streams_spec.rb deleted file mode 100644 index 97a52a5c7c..0000000000 --- a/ruby_event_store-browser/spec/api/search_streams_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "spec_helper" - -module RubyEventStore - ::RSpec.describe Browser do - include Browser::IntegrationHelpers - - specify "something" do - event_store.publish(DummyEvent.new, stream_name: "dummy-1") - event_store.publish(DummyEvent.new, stream_name: "dummy-2") - - api_client.get "/api/search_streams/dum" - - expect(api_client.last_response).to be_ok - expect(api_client.parsed_body["data"]).to match_array( - [ - { "id" => "$by_type_DummyEvent", "type" => "streams" }, - { "id" => "dummy-2", "type" => "streams" }, - { "id" => "dummy-1", "type" => "streams" } - ] - ) - - api_client.get "/api/search_streams/dummy-" - - expect(api_client.last_response).to be_ok - expect(api_client.parsed_body["data"]).to match_array( - [{ "id" => "dummy-2", "type" => "streams" }, { "id" => "dummy-1", "type" => "streams" }] - ) - end - end -end From 41c2d860641e4fcb4b9eb813ecc2966cf544eeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:10:55 +0200 Subject: [PATCH 85/92] Revert "Add search_streams in RubyEventStore::Client" This reverts commit 8a1d9f9ff16e0cf334e0846ca49b625b7c09444a. --- .../lib/ruby_event_store/client.rb | 4 ---- .../ruby_event_store/in_memory_repository.rb | 1 + ruby_event_store/spec/client_spec.rb | 21 ------------------- 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index 3326c1c3ff..92aa1a9781 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -92,10 +92,6 @@ def streams_of(event_id) repository.streams_of(event_id) end - def search_streams(stream) - repository.search_streams(stream) - end - # Gets position of the event in given stream # # The position is always nonnegative. 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 fad6f0a89f..bc3ad5dd62 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 @@ -131,6 +131,7 @@ def search_streams(stream_name) .select { |name,| name.downcase.include?(stream_name.downcase) } .to_a .reverse + .to_h .map { |name,| Stream.new(name) } end diff --git a/ruby_event_store/spec/client_spec.rb b/ruby_event_store/spec/client_spec.rb index 637cbb2d61..d9a4a88b8b 100644 --- a/ruby_event_store/spec/client_spec.rb +++ b/ruby_event_store/spec/client_spec.rb @@ -840,27 +840,6 @@ module RubyEventStore end end - specify "finds streams that are similar to searching criteria" do - event_1 = OrderCreated.new(event_id: SecureRandom.uuid, data: {}) - event_2 = OrderCreated.new(event_id: SecureRandom.uuid, data: {}) - event_3 = OrderCreated.new(event_id: SecureRandom.uuid, data: {}) - stream_1 = Stream.new("stream-1") - stream_2 = Stream.new("stream-2") - stream_3 = Stream.new("stream-3") - - client.append(event_1, stream_name: stream_1.name) - client.append(event_2, stream_name: stream_2.name) - client.append(event_3, stream_name: stream_3.name) - - expect(client.search_streams("str")).to eq [stream_3, stream_2, stream_1] - expect(client.search_streams("Str")).to eq [stream_3, stream_2, stream_1] - expect(client.search_streams("sTr")).to eq [stream_3, stream_2, stream_1] - expect(client.search_streams("stream-1")).to eq [stream_1] - expect(client.search_streams("stream-2")).to eq [stream_2] - expect(client.search_streams("stream-3")).to eq [stream_3] - expect(client.search_streams("stream-4")).to eq [] - end - describe "#subscribers_for" do specify do handler = Subscribers::ValidHandler.new From 6e12ec3f8506d6135379c8fa966aaa4e711499d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:11:00 +0200 Subject: [PATCH 86/92] Revert "Add search_streams to InMemoryRepository" This reverts commit 053dcd8ac5fa704abd66a6fe13bc98a52b458161. --- .../lib/ruby_event_store/in_memory_repository.rb | 9 --------- 1 file changed, 9 deletions(-) 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 bc3ad5dd62..3549d23373 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 @@ -126,15 +126,6 @@ def streams_of(event_id) streams.select { |name,| has_event_in_stream?(event_id, name) }.map { |name,| Stream.new(name) } end - def search_streams(stream_name) - streams - .select { |name,| name.downcase.include?(stream_name.downcase) } - .to_a - .reverse - .to_h - .map { |name,| Stream.new(name) } - end - def position_in_stream(event_id, stream) event_in_stream = streams[stream.name].find { |event_in_stream| event_in_stream.event_id.eql?(event_id) } raise EventNotFoundInStream if event_in_stream.nil? From 02712723b6eef371625df034f389ef4f912179de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:11:03 +0200 Subject: [PATCH 87/92] Revert "Add search_streams test into event_repository_lint" This reverts commit af9e835833bbb5ea7d008622886369e605075092. --- .../spec/event_repository_lint.rb | 18 ------------------ 1 file changed, 18 deletions(-) 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 25e4e5a9ba..faebee594f 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 @@ -1184,24 +1184,6 @@ def read_events_backward(repository, stream = nil, from: nil, to: nil, count: ni expect(repository.streams_of("d10c8fe9-2163-418d-ba47-88c9a1f9391b")).to eq [] end - specify do - event_1 = SRecord.new(event_id: "8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea") - event_2 = SRecord.new(event_id: "8cee1139-4f96-483a-a175-2b947283c3c7") - event_3 = SRecord.new(event_id: "d345f86d-b903-4d78-803f-38990c078d9e") - stream_a = Stream.new("Stream A") - stream_b = Stream.new("Stream B") - stream_c = Stream.new("Stream C") - repository.append_to_stream([event_1], stream_a, version_any) - repository.append_to_stream([event_2], stream_b, version_any) - repository.append_to_stream([event_3], stream_c, version_any) - - expect(repository.search_streams("str")).to eq [stream_c, stream_b, stream_a] - expect(repository.search_streams("Str")).to eq [stream_c, stream_b, stream_a] - expect(repository.search_streams("Stream A")).to eq [stream_a] - expect(repository.search_streams("Stream B")).to eq [stream_b] - expect(repository.search_streams("Stream C")).to eq [stream_c] - end - specify do e1 = SRecord.new(event_id: "8a6f053e-3ce2-4c82-a55b-4d02c66ae6ea") e2 = SRecord.new(event_id: "8cee1139-4f96-483a-a175-2b947283c3c7") From 835b27aa420612b403661785653d83e9c4748951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:11:06 +0200 Subject: [PATCH 88/92] Revert "Reverse results order" This reverts commit 0c68d7e85c8dc6615aa7024c45ab8707c8f18cd6. --- .../active_record/event_repository_reader.rb | 2 +- .../spec/event_repository_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb index 73a69f7965..99b96beae1 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb @@ -58,7 +58,7 @@ def event_in_stream?(event_id, stream) end def search_streams(stream) - @stream_klass.where("stream LIKE ?", "#{stream}%").order("position DESC, id DESC").pluck(:stream).map { |name| Stream.new(name) } + @stream_klass.where("stream LIKE ?", "#{stream}%").order("position ASC").pluck(:stream).map { |name| Stream.new(name) } end private diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 885ff21301..7cee0a75b2 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -200,12 +200,12 @@ module ActiveRecord ExpectedVersion.any ) - expect(repository.search_streams("Du")).to eq([s3, s2, s1]) - expect(repository.search_streams("du")).to eq([s3, s2, s1]) - expect(repository.search_streams("dum")).to eq([s3, s2, s1]) - expect(repository.search_streams("dumm")).to eq([s3, s2, s1]) - expect(repository.search_streams("dummy")).to eq([s3, s2, s1]) - expect(repository.search_streams("Dummy")).to eq([s3, s2, s1]) + expect(repository.search_streams("Du")).to eq([s1, s2, s3]) + expect(repository.search_streams("du")).to eq([s1, s2, s3]) + expect(repository.search_streams("dum")).to eq([s1, s2, s3]) + expect(repository.search_streams("dumm")).to eq([s1, s2, s3]) + expect(repository.search_streams("dummy")).to eq([s1, s2, s3]) + expect(repository.search_streams("Dummy")).to eq([s1, s2, s3]) end specify "finds no streams when search phrase doesn't match anything" do From 5da01b39fea6c9fc4ec1fc51147eda586b02beb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:11:09 +0200 Subject: [PATCH 89/92] Revert "Return stream object instead of name" This reverts commit a7e2e559ca8010231359890d4fc9cfd43f2d10f7. --- .../active_record/event_repository_reader.rb | 2 +- .../spec/event_repository_spec.rb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb index 99b96beae1..4fe46d2af1 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb @@ -58,7 +58,7 @@ def event_in_stream?(event_id, stream) end def search_streams(stream) - @stream_klass.where("stream LIKE ?", "#{stream}%").order("position ASC").pluck(:stream).map { |name| Stream.new(name) } + @stream_klass.where("stream LIKE ?", "#{stream}%").pluck(:stream).uniq end private diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 7cee0a75b2..65bb504739 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -186,26 +186,26 @@ module ActiveRecord specify "finds streams that match the search phrase" do repository.append_to_stream( [SRecord.new(event_id: e1 = SecureRandom.uuid)], - s1 = Stream.new("Dummy$#{e1}"), + Stream.new("Dummy$#{e1}"), ExpectedVersion.any ) repository.append_to_stream( [SRecord.new(event_id: e2 = SecureRandom.uuid)], - s2 = Stream.new("Dummy$#{e2}"), + Stream.new("Dummy$#{e2}"), ExpectedVersion.any ) repository.append_to_stream( [SRecord.new(event_id: e3 = SecureRandom.uuid)], - s3 = Stream.new("Dummy$#{e3}"), + Stream.new("Dummy$#{e3}"), ExpectedVersion.any ) - expect(repository.search_streams("Du")).to eq([s1, s2, s3]) - expect(repository.search_streams("du")).to eq([s1, s2, s3]) - expect(repository.search_streams("dum")).to eq([s1, s2, s3]) - expect(repository.search_streams("dumm")).to eq([s1, s2, s3]) - expect(repository.search_streams("dummy")).to eq([s1, s2, s3]) - expect(repository.search_streams("Dummy")).to eq([s1, s2, s3]) + expect(repository.search_streams("Du")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) + expect(repository.search_streams("du")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) + expect(repository.search_streams("dum")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) + expect(repository.search_streams("dumm")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) + expect(repository.search_streams("dummy")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) + expect(repository.search_streams("Dummy")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) end specify "finds no streams when search phrase doesn't match anything" do From 96e34e2f4cc0f705b68e2fb43af904f4fa7e6178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 15:11:13 +0200 Subject: [PATCH 90/92] Revert "Introduce search_streams in EventRepository" This reverts commit e930fbfdea6a5675777f82db6309d7ae78ba27f2. --- .../active_record/event_repository.rb | 4 -- .../active_record/event_repository_reader.rb | 4 -- .../spec/event_repository_spec.rb | 51 ------------------- 3 files changed, 59 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb index 4ef9a72b35..611afb93c1 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb @@ -47,10 +47,6 @@ def count(specification) @repo_reader.count(specification) end - def search_streams(stream_name) - @repo_reader.search_streams(stream_name) - end - def update_messages(records) hashes = records.map { |record| upsert_hash(record, record.serialize(serializer)) } for_update = records.map(&:event_id) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb index 4fe46d2af1..0a1d4eae52 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository_reader.rb @@ -57,10 +57,6 @@ def event_in_stream?(event_id, stream) @stream_klass.where(event_id: event_id, stream: stream.name).exists? end - def search_streams(stream) - @stream_klass.where("stream LIKE ?", "#{stream}%").pluck(:stream).uniq - end - private attr_reader :serializer diff --git a/ruby_event_store-active_record/spec/event_repository_spec.rb b/ruby_event_store-active_record/spec/event_repository_spec.rb index 65bb504739..dfd8bc9466 100644 --- a/ruby_event_store-active_record/spec/event_repository_spec.rb +++ b/ruby_event_store-active_record/spec/event_repository_spec.rb @@ -183,57 +183,6 @@ module ActiveRecord expect(event_record.valid_at).to eq(t2) end - specify "finds streams that match the search phrase" do - repository.append_to_stream( - [SRecord.new(event_id: e1 = SecureRandom.uuid)], - Stream.new("Dummy$#{e1}"), - ExpectedVersion.any - ) - repository.append_to_stream( - [SRecord.new(event_id: e2 = SecureRandom.uuid)], - Stream.new("Dummy$#{e2}"), - ExpectedVersion.any - ) - repository.append_to_stream( - [SRecord.new(event_id: e3 = SecureRandom.uuid)], - Stream.new("Dummy$#{e3}"), - ExpectedVersion.any - ) - - expect(repository.search_streams("Du")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) - expect(repository.search_streams("du")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) - expect(repository.search_streams("dum")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) - expect(repository.search_streams("dumm")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) - expect(repository.search_streams("dummy")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) - expect(repository.search_streams("Dummy")).to eq(["Dummy$#{e1}", "Dummy$#{e2}", "Dummy$#{e3}"]) - end - - specify "finds no streams when search phrase doesn't match anything" do - repository.append_to_stream( - [SRecord.new(event_id: e1 = SecureRandom.uuid)], - Stream.new("Dummy$#{e1}"), - ExpectedVersion.any - ) - repository.append_to_stream( - [SRecord.new(event_id: e2 = SecureRandom.uuid)], - Stream.new("Dummy$#{e2}"), - ExpectedVersion.any - ) - repository.append_to_stream( - [SRecord.new(event_id: e3 = SecureRandom.uuid)], - Stream.new("Dummy$#{e3}"), - ExpectedVersion.any - ) - - expect(repository.search_streams("Da")).to eq([]) - expect(repository.search_streams("da")).to eq([]) - expect(repository.search_streams("dam")).to eq([]) - expect(repository.search_streams("damm")).to eq([]) - expect(repository.search_streams("dammy")).to eq([]) - expect(repository.search_streams("Dammy")).to eq([]) - end - - specify "with batches and bi-temporal queries use offset + limit" do repository.append_to_stream( [ From 31928ac5a1258ede3d0f03c87e3e78dd9a1911f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 16:32:27 +0200 Subject: [PATCH 91/92] Revert "Introduce Search module" This reverts commit 198bfc4f26240f512875a4507b3ac6ef3db94b96. --- ruby_event_store-browser/elm/src/Layout.elm | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/ruby_event_store-browser/elm/src/Layout.elm b/ruby_event_store-browser/elm/src/Layout.elm index 4ebb82727a..7b63b9b0c1 100644 --- a/ruby_event_store-browser/elm/src/Layout.elm +++ b/ruby_event_store-browser/elm/src/Layout.elm @@ -68,20 +68,9 @@ buildModel = } -goToStream model stream = - Browser.Navigation.pushUrl model.key (Route.streamUrl model.flags.rootUrl stream) - - update : Msg -> WrappedModel Model -> ( WrappedModel Model, Cmd Msg ) update msg model = case msg of - SearchMsg searchMsg -> - let - ( newSearch, cmd ) = - Search.update searchMsg model.internal.search (goToStream model) - in - ( { model | internal = Model newSearch }, Cmd.map SearchMsg cmd ) - TimeZoneSelected zoneName -> let defaultTimeZone = @@ -131,6 +120,9 @@ update msg model = ToggleBookmark id -> ( model, toggleBookmark id ) + SearchMsg _ -> + ( model, Cmd.none ) + view : (Msg -> a) -> WrappedModel Model -> Html a -> Html a view layoutMsgBuilder model pageView = From c9167ef433ee1d65dbd56dbcd6ff8b8b45e3924a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Reszke?= Date: Wed, 24 Jul 2024 17:30:02 +0200 Subject: [PATCH 92/92] Revert "Show real repository adapter on Debug page" This reverts commit 89d0275dbaf2fb60cac430a5ef8e6d5b74c75714. --- .../ruby_event_store/active_record/event_repository.rb | 4 ---- ruby_event_store/lib/ruby_event_store/client.rb | 8 -------- 2 files changed, 12 deletions(-) diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb index 611afb93c1..931e095d5b 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/event_repository.rb @@ -81,10 +81,6 @@ def event_in_stream?(event_id, stream) @repo_reader.event_in_stream?(event_id, stream) end - def specification - "#{self.class.name} with #{::ActiveRecord::Base.connection.adapter_name} db adapter" - end - private attr_reader :serializer diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index 92aa1a9781..0ed4217195 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -230,14 +230,6 @@ def call unsubs.each(&:call) if unsubs end - def repository_specification - if repository.respond_to?(:specification) - repository.specification - else - repository.class.to_s - end - end - private attr_reader :resolver