eventsource-stub-store 1.0.3 → 1.1.0
raw patch · 5 files changed
+44/−40 lines, 5 filesdep +streamingdep ~eventsource-apiPVP ok
version bump matches the API change (PVP)
Dependencies added: streaming
Dependency ranges changed: eventsource-api
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- README.md +1/−3
- eventsource-stub-store.cabal +17/−20
- library/EventSource/Store/Stub.hs +15/−14
- package.yaml +7/−3
CHANGELOG.md view
@@ -1,3 +1,7 @@+1.1.0+=====+ * Migrate to `eventsource-api` 1.5.0.+ 1.0.3 ===== * Fix `ExpectedVersion` logic.
README.md view
@@ -1,5 +1,3 @@-# [eventsource-stub-store][]+# eventsource-stub-store In-memory `Store` implementation. Meant for testing purpose, so don't expect crazy performance.--[eventsource-stub-store]: https://github.com/YoEight/eventsource-api
eventsource-stub-store.cabal view
@@ -1,34 +1,33 @@--- 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: 6a21808b5f7d73e5d2c75c4c4a57bf948ececa55aac722e20385c26e3c37cf75+-- hash: 6bf5cd36883ab45f3f130b02c76266552e44fb5e1924500305bb13c68056edb5 name: eventsource-stub-store-version: 1.0.3+version: 1.1.0 synopsis: An in-memory stub store implementation. description: An in-memory stub 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.Stub+ other-modules:+ Paths_eventsource_stub_store hs-source-dirs: library ghc-options: -Wall@@ -36,19 +35,20 @@ async , base >=4.9 && <5 , containers- , eventsource-api >=1.1+ , eventsource-api >=1.5 , mtl , stm+ , streaming , transformers-base- exposed-modules:- EventSource.Store.Stub- other-modules:- Paths_eventsource_stub_store default-language: Haskell2010 test-suite eventsource-stub-store-test-suite type: exitcode-stdio-1.0 main-is: Main.hs+ other-modules:+ Test.EventSource.Event+ Test.EventSource.Store.Stub+ Paths_eventsource_stub_store hs-source-dirs: test-suite ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N@@ -59,10 +59,7 @@ , eventsource-store-specs ==1.* , eventsource-stub-store , protolude+ , streaming , tasty , tasty-hspec- other-modules:- Test.EventSource.Event- Test.EventSource.Store.Stub- Paths_eventsource_stub_store default-language: Haskell2010
library/EventSource/Store/Stub.hs view
@@ -26,16 +26,19 @@ -------------------------------------------------------------------------------- import Control.Concurrent.STM (STM) import qualified Control.Concurrent.STM as STM-import Data.Foldable (toList, for_, foldl')+import Data.Foldable (for_, foldl') -------------------------------------------------------------------------------- import Control.Concurrent.Async (async) import Control.Monad.Base (MonadBase, liftBase)+import Control.Monad.Except (throwError) import Control.Monad.State.Strict (execState) import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map import Data.Sequence (Seq, (|>)) import qualified Data.Sequence as S+import Streaming (effect)+import qualified Streaming.Prelude as Streaming -------------------------------------------------------------------------------- import EventSource.Store@@ -189,26 +192,24 @@ | otherwise -> STM.throwSTM $ ExpectedVersionException ver $ ExactVersion num - readBatch StubStore{..} name (Batch start _) = liftBase $ async $ STM.atomically $ do- streamMap <- STM.readTVar _streams+ readStream StubStore{..} name (Batch' start _) = effect $ do+ streamMap <- liftBase $ STM.readTVarIO _streams case Map.lookup name streamMap of- Nothing -> return $ ReadFailure $ StreamNotFound name- Just stream -> do+ Nothing -> throwError $ StreamNotFound name+ Just stream -> let events = S.filter ((>= start) . eventNumber) $ streamEvents stream- slice = Slice { sliceEvents = toList events- , sliceEndOfStream = True- , sliceNextEventNumber = streamNumber stream- }-- return $ ReadSuccess slice+ in pure $ Streaming.each events subscribe StubStore{..} name = do sid <- freshSubscriptionId liftBase $ STM.atomically $ do chan <- STM.newTChan- let sub = Subscription sid $ liftBase $ STM.atomically $ do- saved <- STM.readTChan chan- return $ Right saved+ let sub =+ Subscription sid+ $ Streaming.repeatM+ $ liftBase+ $ STM.atomically+ $ STM.readTChan chan subMap <- STM.readTVar _subs let _F Nothing = Just $ Map.singleton sid chan
package.yaml view
@@ -9,11 +9,15 @@ - package.yaml - README.md ghc-options: -Wall-github: YoEight/eventsource-api+homepage: https://gitlab.com/YoEight/eventsource-api-hs++dependencies:+ - streaming+ library: dependencies: - base >=4.9 && <5- - eventsource-api >=1.1+ - eventsource-api >=1.5 - containers - mtl - stm@@ -43,4 +47,4 @@ - -with-rtsopts=-N main: Main.hs source-dirs: test-suite-version: '1.0.3'+version: '1.1.0'