module Database.EventStore.Internal.Operation.Write.Common where
import Data.Int
import Database.EventStore.Internal.Control (freshUUID)
import Database.EventStore.Internal.Prelude
import Database.EventStore.Internal.Types
data WriteResult
= WriteResult
{ WriteResult -> Int64
writeNextExpectedVersion :: !Int64
, WriteResult -> Position
writePosition :: !Position
}
deriving (WriteResult -> WriteResult -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WriteResult -> WriteResult -> Bool
$c/= :: WriteResult -> WriteResult -> Bool
== :: WriteResult -> WriteResult -> Bool
$c== :: WriteResult -> WriteResult -> Bool
Eq, Int -> WriteResult -> ShowS
[WriteResult] -> ShowS
WriteResult -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WriteResult] -> ShowS
$cshowList :: [WriteResult] -> ShowS
show :: WriteResult -> String
$cshow :: WriteResult -> String
showsPrec :: Int -> WriteResult -> ShowS
$cshowsPrec :: Int -> WriteResult -> ShowS
Show)
eventToNewEventIO :: Event -> IO NewEvent
eventToNewEventIO :: Event -> IO NewEvent
eventToNewEventIO Event
evt = do
UUID
uuid <- forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (m :: * -> *). MonadIO m => m UUID
freshUUID forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe UUID
evt_id
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Text
-> UUID
-> Int32
-> Int32
-> ByteString
-> Maybe ByteString
-> NewEvent
newEvent Text
evt_type
UUID
uuid
Int32
evt_data_type
Int32
evt_metadata_type
ByteString
evt_data_bytes
Maybe ByteString
evt_metadata_bytes
where
evt_type :: Text
evt_type = EventType -> Text
eventTypeText forall a b. (a -> b) -> a -> b
$ Event -> EventType
eventType Event
evt
evt_id :: Maybe UUID
evt_id = Event -> Maybe UUID
eventId Event
evt
evt_data_bytes :: ByteString
evt_data_bytes = EventData -> ByteString
eventDataBytes forall a b. (a -> b) -> a -> b
$ Event -> EventData
eventData Event
evt
evt_data_type :: Int32
evt_data_type = EventData -> Int32
eventDataType forall a b. (a -> b) -> a -> b
$ Event -> EventData
eventData Event
evt
evt_metadata_bytes :: Maybe ByteString
evt_metadata_bytes = EventData -> Maybe ByteString
eventMetadataBytes forall a b. (a -> b) -> a -> b
$ Event -> EventData
eventData Event
evt
evt_metadata_type :: Int32
evt_metadata_type = EventData -> Int32
eventMetadataType forall a b. (a -> b) -> a -> b
$ Event -> EventData
eventData Event
evt