eventful-dynamodb 0.1.3 → 0.2.0
raw patch · 4 files changed
+31/−76 lines, 4 filesdep −hlintPVP ok
version bump matches the API change (PVP)
Dependencies removed: hlint
API changes (from Hackage documentation)
- Eventful.Store.DynamoDB: dynamoDBEventStore :: DynamoDBEventStoreConfig serialized -> EventStore serialized AWS
+ Eventful.Store.DynamoDB: dynamoDBEventStoreReader :: DynamoDBEventStoreConfig serialized -> VersionedEventStoreReader AWS serialized
+ Eventful.Store.DynamoDB: dynamoDBEventStoreWriter :: DynamoDBEventStoreConfig serialized -> EventStoreWriter AWS serialized
Files
- eventful-dynamodb.cabal +1/−28
- src/Eventful/Store/DynamoDB.hs +24/−23
- tests/Eventful/Store/DynamoDBSpec.hs +6/−6
- tests/HLint.hs +0/−19
eventful-dynamodb.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: eventful-dynamodb-version: 0.1.3+version: 0.2.0 synopsis: Library for eventful DynamoDB event stores description: Library for eventful DynamoDB event stores category: Database,Eventsourcing,AWS@@ -70,33 +70,6 @@ other-modules: Eventful.Store.DynamoDB.DynamoJSONSpec Eventful.Store.DynamoDBSpec- HLint Eventful.Store.DynamoDB Eventful.Store.DynamoDB.DynamoJSON- default-language: Haskell2010--test-suite style- type: exitcode-stdio-1.0- main-is: HLint.hs- hs-source-dirs:- tests- ghc-options: -Wall- build-depends:- base >= 4.9 && < 5- , eventful-core- , aeson- , amazonka- , amazonka-dynamodb- , bytestring- , conduit- , lens- , safe- , text- , unordered-containers- , vector- , hlint- other-modules:- Eventful.Store.DynamoDB.DynamoJSONSpec- Eventful.Store.DynamoDBSpec- Spec default-language: Haskell2010
src/Eventful/Store/DynamoDB.hs view
@@ -2,7 +2,8 @@ {-# LANGUAGE RecordWildCards #-} module Eventful.Store.DynamoDB- ( dynamoDBEventStore+ ( dynamoDBEventStoreReader+ , dynamoDBEventStoreWriter , DynamoDBEventStoreConfig (..) , defaultDynamoDBEventStoreConfig , initializeDynamoDBEventStore@@ -53,44 +54,45 @@ , dynamoDBEventStoreConfigValueToSerialized = attributeValueToValue } --- | An 'EventStore' that uses AWS DynamoDB as the storage backend. Use a+-- | An 'EventStoreReader' that uses AWS DynamoDB as the storage backend. Use a -- 'DynamoDBEventStoreConfig' to configure this event store.-dynamoDBEventStore+dynamoDBEventStoreReader :: DynamoDBEventStoreConfig serialized- -> EventStore serialized AWS-dynamoDBEventStore config =- let+ -> VersionedEventStoreReader AWS serialized+dynamoDBEventStoreReader config = EventStoreReader $ getDynamoEvents config++dynamoDBEventStoreWriter+ :: DynamoDBEventStoreConfig serialized+ -> EventStoreWriter AWS serialized+dynamoDBEventStoreWriter config = EventStoreWriter $ transactionalExpectedWriteHelper getLatestVersion storeEvents'+ where getLatestVersion = latestEventVersion config- getEvents = getDynamoEvents config storeEvents' = storeDynamoEvents config- storeEvents = transactionalExpectedWriteHelper getLatestVersion storeEvents'- in EventStore{..} getDynamoEvents :: (MonadAWS m) => DynamoDBEventStoreConfig serialized- -> UUID- -> EventStoreQueryRange EventVersion- -> m [StoredEvent serialized]-getDynamoEvents config@DynamoDBEventStoreConfig{..} uuid range = do+ -> QueryRange UUID EventVersion+ -> m [VersionedStreamEvent serialized]+getDynamoEvents config@DynamoDBEventStoreConfig{..} range = do latestEvents <-- paginate (queryBase config uuid range) =$=+ paginate (queryBase config range) =$= CL.concatMap (view qrsItems) $$ CL.consume- return $ mapMaybe (decodeDynamoEvent config uuid) latestEvents+ return $ mapMaybe (decodeDynamoEvent config $ queryRangeKey range) latestEvents decodeDynamoEvent :: DynamoDBEventStoreConfig serialized -> UUID -> HashMap Text AttributeValue- -> Maybe (StoredEvent serialized)+ -> Maybe (VersionedStreamEvent serialized) decodeDynamoEvent DynamoDBEventStoreConfig{..} uuid attributeMap = do versionValue <- HM.lookup dynamoDBEventStoreConfigVersionAttributeName attributeMap versionText <- versionValue ^. avN version <- EventVersion <$> readMay (T.unpack versionText) eventAttributeValue <- HM.lookup dynamoDBEventStoreConfigEventAttributeName attributeMap let event = dynamoDBEventStoreConfigValueToSerialized eventAttributeValue- return $ StoredEvent uuid version event+ return $ StreamEvent uuid version event latestEventVersion :: (MonadAWS m)@@ -99,7 +101,7 @@ -> m EventVersion latestEventVersion config@DynamoDBEventStoreConfig{..} uuid = do latestEvents <- fmap (view qrsItems) . send $- queryBase config uuid allEvents+ queryBase config (allEvents uuid) & qLimit ?~ 1 & qScanIndexForward ?~ False return $ EventVersion $ fromMaybe (-1) $ do@@ -113,10 +115,9 @@ -- UUID. queryBase :: DynamoDBEventStoreConfig serialized- -> UUID- -> EventStoreQueryRange EventVersion+ -> QueryRange UUID EventVersion -> Query-queryBase DynamoDBEventStoreConfig{..} uuid EventStoreQueryRange{..} =+queryBase DynamoDBEventStoreConfig{..} QueryRange{..} = query dynamoDBEventStoreConfigTableName & qKeyConditionExpression ?~ T.intercalate " AND " (uuidCaseExpression : versionCaseExpression)@@ -124,7 +125,7 @@ & qExpressionAttributeValues .~ HM.fromList (uuidAttributeValue : versionAttributeValues) where uuidAttributeName = ("#uuid", dynamoDBEventStoreConfigUUIDAttributeName)- uuidAttributeValue = (":uuid", attributeValue & avS ?~ uuidToText uuid)+ uuidAttributeValue = (":uuid", attributeValue & avS ?~ uuidToText queryRangeKey) uuidCaseExpression = "#uuid = :uuid" mkStartVersionAttributeValue vers = (":startVersion", attributeValue & avN ?~ T.pack (show vers))@@ -138,7 +139,7 @@ ] ) (versionCaseExpression, versionAttributeValues) =- case (eventStoreQueryRangeStart, eventStoreQueryRangeLimit) of+ case (queryRangeStart, queryRangeLimit) of (StartFromBeginning, NoQueryLimit) -> ([], []) (StartFromBeginning, MaxNumberOfEvents maxNum) -> mkJustEnd (EventVersion maxNum - 1) (StartFromBeginning, StopQueryAt end) -> mkJustEnd end
tests/Eventful/Store/DynamoDBSpec.hs view
@@ -16,23 +16,23 @@ describe "DynamoDB event store" $ do eventStoreSpec dynamoRunner -makeStore :: IO (EventStore CounterEvent AWS, Env)+makeStore :: IO (EventStoreWriter AWS CounterEvent, VersionedEventStoreReader AWS CounterEvent, Env) makeStore = do let dynamo = setEndpoint False "localhost" 8000 dynamoDB env <- newEnv Discover <&> configure dynamo let- store = dynamoDBEventStore defaultDynamoDBEventStoreConfig- store' = serializedEventStore jsonSerializer store+ writer = serializedEventStoreWriter jsonSerializer $ dynamoDBEventStoreWriter defaultDynamoDBEventStoreConfig+ reader = serializedVersionedEventStoreReader jsonSerializer $ dynamoDBEventStoreReader defaultDynamoDBEventStoreConfig liftIO $ runResourceT . runAWS env $ do -- Delete and recreate table deleteDynamoDBEventStoreTable defaultDynamoDBEventStoreConfig initializeDynamoDBEventStore defaultDynamoDBEventStoreConfig (provisionedThroughput 1 1) - return (store', env)+ return (writer, reader, env) dynamoRunner :: EventStoreRunner AWS dynamoRunner = EventStoreRunner $ \action -> do- (store, env) <- makeStore- runResourceT $ runAWS env (action store)+ (writer, reader, env) <- makeStore+ runResourceT $ runAWS env (action writer reader)
− tests/HLint.hs
@@ -1,19 +0,0 @@-module Main (main) where--import Language.Haskell.HLint (hlint)-import System.Exit (exitFailure, exitSuccess)--import Prelude (String, IO, null)--arguments :: [String]-arguments =- [ "src"- , "tests"- , "-i=Redundant do"- , "-i=Unused LANGUAGE pragma" -- This fails on DeriveGeneric- ]--main :: IO ()-main = do- hints <- hlint arguments- if null hints then exitSuccess else exitFailure