eventsource-geteventstore-store 1.1.0 → 1.2.0
raw patch · 5 files changed
+80/−69 lines, 5 filesdep +lifted-asyncdep +lifted-basedep +streamingdep ~basedep ~eventsource-apidep ~eventsource-store-specsPVP ok
version bump matches the API change (PVP)
Dependencies added: lifted-async, lifted-base, streaming
Dependency ranges changed: base, eventsource-api, eventsource-store-specs, eventstore
API changes (from Hackage documentation)
+ EventSource.Store.GetEventStore: fromGesEvent :: ResolvedEvent -> SavedEvent
Files
- CHANGELOG.md +5/−0
- README.md +3/−4
- eventsource-geteventstore-store.cabal +30/−24
- library/EventSource/Store/GetEventStore.hs +30/−31
- package.yaml +12/−10
CHANGELOG.md view
@@ -1,3 +1,8 @@+1.1.0+=====+* Migrate to `eventsource-api` 1.5.0.+* Expose `fromGESEvent` function.+ 1.0.6 ===== * Support evenstore >= 1.1
README.md view
@@ -1,4 +1,4 @@-# [eventsource-geteventstore-store][]+# eventsource-geteventstore-store [GetEventStore][] `Store` implementation. It's based on [eventstore][] driver. @@ -6,6 +6,5 @@ In order to run the tests, you'll need a running [GetEventStore][] server at `localhost` on the `1113` port. -[eventsource-geteventstore-store]: https://github.com/YoEight/eventsource-api-[GetEventStore]: http://geteventstore.com-[eventstore]: https://github.com/YoEight/eventstore+[GetEventStore]: http://eventstore.org+[eventstore]: https://gitlab.com/YoEight/eventstore-hs
eventsource-geteventstore-store.cabal view
@@ -1,67 +1,73 @@--- This file has been generated from package.yaml by hpack version 0.20.0.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.1. -- -- see: https://github.com/sol/hpack ----- hash: 2f7d6b067b79c8e983367020e1da7747b66bdc8de579d77677a35442661b4f34+-- hash: f70a57042b5ec5e9068d0bdcd9377197f1ea13010e8a19aa9c0cfd1a27602409 name: eventsource-geteventstore-store-version: 1.1.0+version: 1.2.0 synopsis: GetEventStore store implementation. description: GetEventStore store implementation. category: Eventsourcing-homepage: https://github.com/YoEight/eventsource-api#readme-bug-reports: https://github.com/YoEight/eventsource-api/issues+homepage: https://gitlab.com/YoEight/eventsource-api-hs author: Yorick Laupa maintainer: yo.eight@gmail.com license: BSD3 license-file: LICENSE.md build-type: Simple-cabal-version: >= 1.10- extra-source-files: CHANGELOG.md LICENSE.md package.yaml README.md -source-repository head- type: git- location: https://github.com/YoEight/eventsource-api- library+ exposed-modules:+ EventSource.Store.GetEventStore+ other-modules:+ Paths_eventsource_geteventstore_store hs-source-dirs: library ghc-options: -Wall build-depends: aeson , base >=4.9 && <5- , eventsource-api >=1.3- , eventstore >=1.1+ , eventsource-api >=1.5+ , eventsource-store-specs+ , eventstore >=1.2+ , lifted-async+ , lifted-base , mtl+ , streaming , string-conversions , transformers-base- exposed-modules:- EventSource.Store.GetEventStore- other-modules:- Paths_eventsource_geteventstore_store default-language: Haskell2010 test-suite geteventstore-store-test-suite type: exitcode-stdio-1.0 main-is: Main.hs+ other-modules:+ Test.EventSource.Store.GetEventStore+ Paths_eventsource_geteventstore_store hs-source-dirs: test-suite ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N build-depends:- base- , eventsource-api+ aeson+ , base >=4.9 && <5+ , eventsource-api >=1.5 , eventsource-geteventstore-store- , eventsource-store-specs ==1.*- , eventstore >=1.1+ , eventsource-store-specs+ , eventstore >=1.2+ , lifted-async+ , lifted-base+ , mtl , protolude+ , streaming+ , string-conversions , tasty , tasty-hspec- other-modules:- Test.EventSource.Store.GetEventStore- Paths_eventsource_geteventstore_store+ , transformers-base default-language: Haskell2010
library/EventSource/Store/GetEventStore.hs view
@@ -17,18 +17,20 @@ ( GetEventStore , gesConnection , gesStore+ , fromGesEvent ) where ---------------------------------------------------------------------------------import Control.Exception (try)---------------------------------------------------------------------------------- import Control.Monad.Base (MonadBase, liftBase)+import Control.Monad.Except (withExceptT) import Control.Monad.State.Strict (execState) import Data.Aeson (encode, decodeStrict) import Data.String.Conversions (convertString)-import qualified Database.EventStore as GES+import qualified Database.EventStore as GES hiding (ReadError, StreamDeleted, AccessDenied)+import qualified Database.EventStore.Streaming as GES import EventSource+import Streaming (hoist)+import qualified Streaming.Prelude as Streaming -------------------------------------------------------------------------------- newtype GetEventStore = GetEventStore { gesConnection :: GES.Connection }@@ -77,6 +79,7 @@ DataAsJson v -> GES.withJsonAndMetadata v p --------------------------------------------------------------------------------+-- | Converts a GetEventStore event to a more abstract 'SavedEvent' event. fromGesEvent :: GES.ResolvedEvent -> SavedEvent fromGesEvent e@(GES.ResolvedEvent recEvt lnkEvt _) = saved where@@ -102,30 +105,19 @@ } ---------------------------------------------------------------------------------fromGesSlice :: GES.StreamSlice -> Slice-fromGesSlice s = Slice { sliceEvents = fromGesEvent <$> GES.sliceEvents s- , sliceEndOfStream = GES.sliceEOS s- , sliceNextEventNumber = EventNumber $ GES.sliceNext s- }+toGESStreamName :: StreamName -> GES.StreamName+toGESStreamName (StreamName name) = GES.StreamName name ---------------------------------------------------------------------------------fromGesReadResult :: StreamName -> GES.ReadResult t a -> ReadStatus a-fromGesReadResult _ (GES.ReadSuccess a) =- ReadSuccess a-fromGesReadResult n GES.ReadNoStream =- ReadFailure $ StreamNotFound n-fromGesReadResult n (GES.ReadStreamDeleted _) =- ReadFailure $ StreamNotFound n-fromGesReadResult _ GES.ReadNotModified =- ReadFailure (ReadError $ Just "not modified")-fromGesReadResult _ (GES.ReadError e) =- ReadFailure $ ReadError e-fromGesReadResult n (GES.ReadAccessDenied _) =- ReadFailure $ AccessDenied n+fromGESStreamName :: GES.StreamId t -> StreamName+fromGESStreamName (GES.StreamName n) = StreamName n+fromGESStreamName GES.All = StreamName "$all" ---------------------------------------------------------------------------------toGESStreamName :: StreamName -> GES.StreamName-toGESStreamName (StreamName name) = GES.StreamName name+fromGESError :: GES.ReadError t -> ReadFailure+fromGESError (GES.StreamDeleted name) = StreamNotFound $ fromGESStreamName name+fromGESError (GES.ReadError reason) = ReadError reason+fromGESError (GES.AccessDenied name) = AccessDenied $ fromGESStreamName name -------------------------------------------------------------------------------- instance Store GetEventStore where@@ -135,18 +127,25 @@ Nothing return $ fmap (EventNumber . GES.writeNextExpectedVersion) w - readBatch (GetEventStore conn) name b = liftBase $ do+ readStream (GetEventStore conn) name b = let EventNumber n = batchFrom b- w <- GES.readStreamEventsForward conn (toGESStreamName name) n (batchSize b)- True Nothing- return $ fmap (fmap fromGesSlice . fromGesReadResult name) w+ from = GES.rawEventNumber n+ stream =+ GES.readThroughForward conn+ (toGESStreamName name) GES.ResolveLink from (Just $ batchSize b) Nothing + in hoist (hoist liftBase . withExceptT fromGESError)+ $ Streaming.map fromGesEvent stream+ subscribe (GetEventStore conn) name = liftBase $ do- sub <- GES.subscribe conn (toGESStreamName name) True Nothing+ sub <- GES.subscribe conn (toGESStreamName name) GES.ResolveLink Nothing sid <- freshSubscriptionId - return $ Subscription sid $ liftBase $- try $ fmap fromGesEvent $ GES.nextEvent sub+ pure $ Subscription sid+ $ Streaming.repeatM+ $ liftBase+ $ fmap fromGesEvent+ $ GES.nextEvent sub -------------------------------------------------------------------------------- -- | Returns a GetEventStore based store implementation.
package.yaml view
@@ -9,16 +9,22 @@ - package.yaml - README.md ghc-options: -Wall-github: YoEight/eventsource-api-library:- dependencies:+homepage: https://gitlab.com/YoEight/eventsource-api-hs++dependencies: - base >=4.9 && <5- - eventstore >=1.1- - eventsource-api >= 1.3+ - eventstore >=1.2+ - eventsource-api >= 1.5 - aeson - mtl - transformers-base - string-conversions+ - lifted-async+ - lifted-base+ - eventsource-store-specs+ - streaming++library: source-dirs: library license: BSD3 license-file: LICENSE.md@@ -29,11 +35,7 @@ tests: geteventstore-store-test-suite: dependencies:- - base - eventsource-geteventstore-store- - eventsource-api- - eventsource-store-specs ==1.*- - eventstore >= 1.1 - tasty - tasty-hspec - protolude@@ -43,4 +45,4 @@ - -with-rtsopts=-N main: Main.hs source-dirs: test-suite-version: '1.1.0'+version: '1.2.0'