Copyright | (C) 2014 Yorick Laupa |
---|---|
License | (see the file LICENSE) |
Maintainer | Yorick Laupa <yo.eight@gmail.com> |
Stability | provisional |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
- data Event
- data EventData
- createEvent :: Text -> Maybe UUID -> EventData -> Event
- withJson :: Value -> EventData
- withJsonAndMetadata :: Value -> Value -> EventData
- data Connection
- data ConnectionException = MaxAttempt HostName Int Int
- data Credentials
- data Settings = Settings {}
- data Retry
- atMost :: Int -> Retry
- keepRetrying :: Retry
- credentials :: ByteString -> ByteString -> Credentials
- defaultSettings :: Settings
- connect :: Settings -> String -> Int -> IO Connection
- shutdown :: Connection -> IO ()
- data StreamMetadataResult
- readEvent :: Connection -> Text -> Int32 -> Bool -> IO (Async ReadResult)
- readAllEventsBackward :: Connection -> Position -> Int32 -> Bool -> IO (Async AllEventsSlice)
- readAllEventsForward :: Connection -> Position -> Int32 -> Bool -> IO (Async AllEventsSlice)
- readStreamEventsBackward :: Connection -> Text -> Int32 -> Int32 -> Bool -> IO (Async StreamEventsSlice)
- readStreamEventsForward :: Connection -> Text -> Int32 -> Int32 -> Bool -> IO (Async StreamEventsSlice)
- getStreamMetadata :: Connection -> Text -> IO (Async StreamMetadataResult)
- data StreamACL = StreamACL {
- streamACLReadRoles :: ![Text]
- streamACLWriteRoles :: ![Text]
- streamACLDeleteRoles :: ![Text]
- streamACLMetaReadRoles :: ![Text]
- streamACLMetaWriteRoles :: ![Text]
- data StreamMetadata = StreamMetadata {}
- streamMetadataGetCustomPropertyValue :: StreamMetadata -> Text -> Maybe Value
- streamMetadataGetCustomProperty :: FromJSON a => StreamMetadata -> Text -> Maybe a
- emptyStreamACL :: StreamACL
- emptyStreamMetadata :: StreamMetadata
- deleteStream :: Connection -> Text -> ExpectedVersion -> Maybe Bool -> IO (Async DeleteResult)
- sendEvent :: Connection -> Text -> ExpectedVersion -> Event -> IO (Async WriteResult)
- sendEvents :: Connection -> Text -> ExpectedVersion -> [Event] -> IO (Async WriteResult)
- setStreamMetadata :: Connection -> Text -> ExpectedVersion -> StreamMetadata -> IO (Async WriteResult)
- type Builder a = Endo a
- type StreamACLBuilder = Builder StreamACL
- buildStreamACL :: StreamACLBuilder -> StreamACL
- modifyStreamACL :: StreamACLBuilder -> StreamACL -> StreamACL
- setReadRoles :: [Text] -> StreamACLBuilder
- setReadRole :: Text -> StreamACLBuilder
- setWriteRoles :: [Text] -> StreamACLBuilder
- setWriteRole :: Text -> StreamACLBuilder
- setDeleteRoles :: [Text] -> StreamACLBuilder
- setDeleteRole :: Text -> StreamACLBuilder
- setMetaReadRoles :: [Text] -> StreamACLBuilder
- setMetaReadRole :: Text -> StreamACLBuilder
- setMetaWriteRoles :: [Text] -> StreamACLBuilder
- setMetaWriteRole :: Text -> StreamACLBuilder
- type StreamMetadataBuilder = Builder StreamMetadata
- buildStreamMetadata :: StreamMetadataBuilder -> StreamMetadata
- modifyStreamMetadata :: StreamMetadataBuilder -> StreamMetadata -> StreamMetadata
- setMaxCount :: Int32 -> StreamMetadataBuilder
- setMaxAge :: TimeSpan -> StreamMetadataBuilder
- setTruncateBefore :: Int32 -> StreamMetadataBuilder
- setCacheControl :: TimeSpan -> StreamMetadataBuilder
- setACL :: StreamACL -> StreamMetadataBuilder
- modifyACL :: StreamACLBuilder -> StreamMetadataBuilder
- setCustomProperty :: ToJSON a => Text -> a -> StreamMetadataBuilder
- data TimeSpan
- timeSpanTicks :: Int64 -> TimeSpan
- timeSpanHoursMinsSecs :: Int64 -> Int64 -> Int64 -> TimeSpan
- timeSpanDaysHoursMinsSecs :: Int64 -> Int64 -> Int64 -> Int64 -> TimeSpan
- timeSpanDaysHoursMinsSecsMillis :: Int64 -> Int64 -> Int64 -> Int64 -> Int64 -> TimeSpan
- timeSpanGetTicks :: TimeSpan -> Int64
- timeSpanGetDays :: TimeSpan -> Int64
- timeSpanGetHours :: TimeSpan -> Int64
- timeSpanGetMinutes :: TimeSpan -> Int64
- timeSpanGetSeconds :: TimeSpan -> Int64
- timeSpanGetMillis :: TimeSpan -> Int64
- timeSpanFromSeconds :: Double -> TimeSpan
- timeSpanFromMinutes :: Double -> TimeSpan
- timeSpanFromHours :: Double -> TimeSpan
- timeSpanFromDays :: Double -> TimeSpan
- timeSpanTotalMillis :: TimeSpan -> Int64
- data Transaction
- transactionStart :: Connection -> Text -> ExpectedVersion -> IO (Async Transaction)
- transactionCommit :: Transaction -> IO (Async WriteResult)
- transactionRollback :: Transaction -> IO ()
- transactionSendEvents :: Transaction -> [Event] -> IO (Async ())
- data DropReason
- class Identifiable a
- data Subscription a
- type family NextEvent a :: *
- data Regular
- data Catchup
- data Persistent
- subscribe :: Connection -> Text -> Bool -> IO (Async (Subscription Regular))
- subscribeToAll :: Connection -> Bool -> IO (Async (Subscription Regular))
- subNextEvent :: Subscription a -> IO (NextEvent a)
- subId :: Identifiable a => Subscription a -> UUID
- subStreamId :: Subscription a -> Text
- subIsSubscribedToAll :: Subscription a -> Bool
- subResolveLinkTos :: Subscription Regular -> Bool
- subLastCommitPos :: Identifiable a => Subscription a -> Int64
- subLastEventNumber :: Identifiable a => Subscription a -> Maybe Int32
- subUnsubscribe :: Subscription a -> IO ()
- data CatchupError
- subscribeFrom :: Connection -> Text -> Bool -> Maybe Int32 -> Maybe Int32 -> IO (Subscription Catchup)
- subscribeToAllFrom :: Connection -> Bool -> Maybe Position -> Maybe Int32 -> IO (Subscription Catchup)
- waitTillCatchup :: Subscription Catchup -> IO ()
- hasCaughtUp :: Subscription Catchup -> IO Bool
- data PersistentSubscriptionSettings = PersistentSubscriptionSettings {
- psSettingsResolveLinkTos :: !Bool
- psSettingsStartFrom :: !Int32
- psSettingsExtraStats :: !Bool
- psSettingsMsgTimeout :: !TimeSpan
- psSettingsMaxRetryCount :: !Int32
- psSettingsLiveBufSize :: !Int32
- psSettingsReadBatchSize :: !Int32
- psSettingsHistoryBufSize :: !Int32
- psSettingsCheckPointAfter :: !TimeSpan
- psSettingsMinCheckPointCount :: !Int32
- psSettingsMaxCheckPointCount :: !Int32
- psSettingsMaxSubsCount :: !Int32
- psSettingsNamedConsumerStrategy :: !SystemConsumerStrategy
- data SystemConsumerStrategy
- data NakAction
- = NA_Unknown
- | NA_Park
- | NA_Retry
- | NA_Skip
- | NA_Stop
- notifyEventsProcessed :: Subscription Persistent -> [UUID] -> IO ()
- notifyEventsFailed :: Subscription Persistent -> NakAction -> Maybe Text -> [UUID] -> IO ()
- defaultPersistentSubscriptionSettings :: PersistentSubscriptionSettings
- createPersistentSubscription :: Connection -> Text -> Text -> PersistentSubscriptionSettings -> IO (Async ())
- updatePersistentSubscription :: Connection -> Text -> Text -> PersistentSubscriptionSettings -> IO (Async ())
- deletePersistentSubscription :: Connection -> Text -> Text -> IO (Async ())
- connectToPersistentSubscription :: Connection -> Text -> Text -> Int32 -> IO (Async (Subscription Persistent))
- data AllEventsSlice = AllEventsSlice {}
- newtype DeleteResult = DeleteResult {}
- data WriteResult = WriteResult {}
- data ReadResult = ReadResult {}
- data RecordedEvent = RecordedEvent {}
- data StreamEventsSlice = StreamEventsSlice {}
- data Position = Position {
- positionCommit :: !Int64
- positionPrepare :: !Int64
- data ReadDirection
- data ReadAllResult
- data ReadEventResult
- data ResolvedEvent = ResolvedEvent {}
- data ReadStreamResult
- data OperationException
- eventResolved :: ResolvedEvent -> Bool
- resolvedEventOriginal :: ResolvedEvent -> Maybe RecordedEvent
- resolvedEventOriginalStreamId :: ResolvedEvent -> Maybe Text
- resolvedEventOriginalId :: ResolvedEvent -> Maybe UUID
- positionStart :: Position
- positionEnd :: Position
- data ExpectedVersion
- anyStream :: ExpectedVersion
- noStream :: ExpectedVersion
- emptyStream :: ExpectedVersion
- exactStream :: Int32 -> ExpectedVersion
- module Control.Concurrent.Async
- (<>) :: Monoid m => m -> m -> m
Event
Contains event information like its type and data. Only used for write queries.
withJsonAndMetadata :: Value -> Value -> EventData Source
Create a event with metadata using JSON format
Connection
data Connection Source
Represents a connection to a single EventStore node.
data ConnectionException Source
MaxAttempt HostName Int Int | HostName Port MaxAttempt's value |
Global Connection
settings
Settings | |
|
Indicates how many times we should try to reconnect to the server. A value less than or equal to 0 means no retry.
Indicates we should try to reconnect to the server until the end of the Universe.
:: ByteString | Login |
-> ByteString | Password |
-> Credentials |
defaultSettings :: Settings Source
Default global settings.
:: Settings | |
-> String | HostName |
-> Int | Port |
-> IO Connection |
Creates a new Connection
to a single node. It maintains a full duplex
connection to the EventStore. An EventStore Connection
operates quite
differently than say a SQL connection. Normally when you use a SQL
connection you want to keep the connection open for a much longer of time
than when you use a SQL connection.
Another difference is that with the EventStore Connection
all operation
are handled in a full async manner (even if you call the synchronous
behaviors). Many threads can use an EvenStore Connection
at the same time
or a single thread can make many asynchronous requests. To get the most
performance out of the connection it is generally recommend to use it in
this way.
shutdown :: Connection -> IO () Source
Asynchronously closes the Connection
.
Read Operations
data StreamMetadataResult Source
Represents stream metadata as a series of properties for system data and a
StreamMetadata
object for user metadata.
StreamMetadataResult | |
| |
NotFoundStreamMetadataResult | When the stream is either not found or 'no stream'. |
| |
DeletedStreamMetadataResult | When the stream is soft-deleted. |
|
:: Connection | |
-> Text | Stream name |
-> Int32 | Event number |
-> Bool | Resolve Link Tos |
-> IO (Async ReadResult) |
Reads a single event from given stream.
:: Connection | |
-> Position | |
-> Int32 | Batch size |
-> Bool | Resolve Link Tos |
-> IO (Async AllEventsSlice) |
Reads events from the $all stream backward
:: Connection | |
-> Position | |
-> Int32 | Batch size |
-> Bool | Resolve Link Tos |
-> IO (Async AllEventsSlice) |
Reads events from the $all stream forward.
readStreamEventsBackward Source
:: Connection | |
-> Text | Stream name |
-> Int32 | From event number |
-> Int32 | Batch size |
-> Bool | Resolve Link Tos |
-> IO (Async StreamEventsSlice) |
Reads events from a given stream backward.
readStreamEventsForward Source
:: Connection | |
-> Text | Stream name |
-> Int32 | From event number |
-> Int32 | Batch size |
-> Bool | Resolve Link Tos |
-> IO (Async StreamEventsSlice) |
Reads events from a given stream forward.
getStreamMetadata :: Connection -> Text -> IO (Async StreamMetadataResult) Source
Asynchronously gets the metadata of a stream.
Write Operations
Represents an access control list for a stream.
StreamACL | |
|
data StreamMetadata Source
Represents stream metadata with strongly typed properties for system values and a dictionary-like interface for custom values.
StreamMetadata | |
|
streamMetadataGetCustomPropertyValue :: StreamMetadata -> Text -> Maybe Value Source
Gets a custom property value from metadata.
streamMetadataGetCustomProperty :: FromJSON a => StreamMetadata -> Text -> Maybe a Source
Get a custom property value from metadata.
emptyStreamACL :: StreamACL Source
StreamACL
with no role or users whatsoever.
emptyStreamMetadata :: StreamMetadata Source
StreamMetadata
with everything set to Nothing
, using emptyStreamACL
and an empty Object
.
:: Connection | |
-> Text | Stream name |
-> ExpectedVersion | |
-> Maybe Bool | Hard delete |
-> IO (Async DeleteResult) |
Deletes given stream.
:: Connection | |
-> Text | Stream name |
-> ExpectedVersion | |
-> Event | |
-> IO (Async WriteResult) |
Sends a single Event
to given stream.
:: Connection | |
-> Text | Stream name |
-> ExpectedVersion | |
-> [Event] | |
-> IO (Async WriteResult) |
Sends a list of Event
to given stream.
setStreamMetadata :: Connection -> Text -> ExpectedVersion -> StreamMetadata -> IO (Async WriteResult) Source
Asynchronously sets the metadata for a stream.
Builder
Stream ACL Builder
type StreamACLBuilder = Builder StreamACL Source
buildStreamACL :: StreamACLBuilder -> StreamACL Source
Builds a StreamACL
from a StreamACLBuilder
.
modifyStreamACL :: StreamACLBuilder -> StreamACL -> StreamACL Source
Modifies a StreamACL
using a StreamACLBuilder
.
setReadRoles :: [Text] -> StreamACLBuilder Source
Sets role names with read permission for the stream.
setReadRole :: Text -> StreamACLBuilder Source
Sets a single role name with read permission for the stream.
setWriteRoles :: [Text] -> StreamACLBuilder Source
Sets role names with write permission for the stream.
setWriteRole :: Text -> StreamACLBuilder Source
Sets a single role name with write permission for the stream.
setDeleteRoles :: [Text] -> StreamACLBuilder Source
Sets role names with delete permission for the stream.
setDeleteRole :: Text -> StreamACLBuilder Source
Sets a single role name with delete permission for the stream.
setMetaReadRoles :: [Text] -> StreamACLBuilder Source
Sets role names with metadata read permission for the stream.
setMetaReadRole :: Text -> StreamACLBuilder Source
Sets a single role name with metadata read permission for the stream.
setMetaWriteRoles :: [Text] -> StreamACLBuilder Source
Sets role names with metadata write permission for the stream.
setMetaWriteRole :: Text -> StreamACLBuilder Source
Sets a single role name with metadata write permission for the stream.
Stream Metadata Builder
buildStreamMetadata :: StreamMetadataBuilder -> StreamMetadata Source
Builds a StreamMetadata
from a StreamMetadataBuilder
.
modifyStreamMetadata :: StreamMetadataBuilder -> StreamMetadata -> StreamMetadata Source
Modifies a StreamMetadata
using a StreamMetadataBuilder
setMaxCount :: Int32 -> StreamMetadataBuilder Source
Sets the maximum number of events allowed in the stream.
setMaxAge :: TimeSpan -> StreamMetadataBuilder Source
Sets the maximum age of events allowed in the stream.
setTruncateBefore :: Int32 -> StreamMetadataBuilder Source
Sets the event number from which previous events can be scavenged.
setCacheControl :: TimeSpan -> StreamMetadataBuilder Source
Sets the amount of time for which the stream head is cachable.
setCustomProperty :: ToJSON a => Text -> a -> StreamMetadataBuilder Source
Sets a custom metadata property.
TimeSpan
.NET TimeSpan: TimeSpan represents a duration of time. A TimeSpan can be negative or positive. Sorry
timeSpanTicks :: Int64 -> TimeSpan Source
timeSpanGetTicks :: TimeSpan -> Int64 Source
timeSpanGetDays :: TimeSpan -> Int64 Source
timeSpanGetHours :: TimeSpan -> Int64 Source
timeSpanGetMillis :: TimeSpan -> Int64 Source
timeSpanFromDays :: Double -> TimeSpan Source
Transaction
data Transaction Source
Represents a multi-request transaction with the EventStore.
:: Connection | |
-> Text | Stream name |
-> ExpectedVersion | |
-> IO (Async Transaction) |
Starts a transaction on given stream.
transactionCommit :: Transaction -> IO (Async WriteResult) Source
Asynchronously commits this transaction.
transactionRollback :: Transaction -> IO () Source
Rollback this transaction.
transactionSendEvents :: Transaction -> [Event] -> IO (Async ()) Source
Asynchronously writes to a transaction in the EventStore.
Volatile Subscription
data DropReason Source
Represents the reason subscription drop happened.
class Identifiable a Source
Represents a subscription that is directly identifiable. Regular
and
Persistent
fit that description while Catchup
doesn't. Because
Catchup
reads all events from a particular checkpoint and when it's
finished, it issues a subscription request.
data Subscription a Source
Represents a subscription to a stream.
type family NextEvent a :: * Source
Value's type returned when calling subNextEvent
Represents a subscription to a single stream or $all stream in the EventStore.
:: Connection | |
-> Text | Stream name |
-> Bool | Resolve Link Tos |
-> IO (Async (Subscription Regular)) |
Subcribes to given stream.
:: Connection | |
-> Bool | Resolve Link Tos |
-> IO (Async (Subscription Regular)) |
Subcribes to $all stream.
subNextEvent :: Subscription a -> IO (NextEvent a) Source
Awaits for the next event.
subId :: Identifiable a => Subscription a -> UUID Source
Gets the ID of the subscription.
subStreamId :: Subscription a -> Text Source
The name of the stream to which the subscription is subscribed.
subIsSubscribedToAll :: Subscription a -> Bool Source
True if this subscription is to $all stream.
subResolveLinkTos :: Subscription Regular -> Bool Source
Determines whether or not any link events encontered in the stream will be resolved.
subLastCommitPos :: Identifiable a => Subscription a -> Int64 Source
The last commit position seen on the subscription (if this a subscription to $all stream).
subLastEventNumber :: Identifiable a => Subscription a -> Maybe Int32 Source
The last event number seen on the subscription (if this is a subscription to a single stream).
subUnsubscribe :: Subscription a -> IO () Source
Asynchronously unsubscribe from the the stream.
Catch-up Subscription
data CatchupError Source
Errors that could arise during a catch-up subscription. Text
value
represents the stream name.
:: Connection | |
-> Text | Stream name |
-> Bool | Resolve Link Tos |
-> Maybe Int32 | Last checkpoint |
-> Maybe Int32 | Batch size |
-> IO (Subscription Catchup) |
Subscribes to given stream. If last checkpoint is defined, this will
readStreamEventsForward
from that event number, otherwise from the
beginning. Once last stream event reached up, a subscription request will
be sent using subscribe
.
:: Connection | |
-> Bool | Resolve Link Tos |
-> Maybe Position | Last checkpoint |
-> Maybe Int32 | Batch size |
-> IO (Subscription Catchup) |
Same as subscribeFrom
but applied to $all stream.
waitTillCatchup :: Subscription Catchup -> IO () Source
Waits until Catchup
subscription catch-up its stream.
hasCaughtUp :: Subscription Catchup -> IO Bool Source
Non blocking version of waitTillCatchup
.
Persistent Subscription
data PersistentSubscriptionSettings Source
PersistentSubscriptionSettings | |
|
data SystemConsumerStrategy Source
System supported consumer strategies for use with persistent subscriptions.
DispatchToSingle | Distributes events to a single client until it is full. Then round robin to the next client. |
RoundRobin | Distribute events to each client in a round robin fashion. |
notifyEventsProcessed :: Subscription Persistent -> [UUID] -> IO () Source
Acknowledges those event ids have been successfully processed.
notifyEventsFailed :: Subscription Persistent -> NakAction -> Maybe Text -> [UUID] -> IO () Source
Acknowledges those event ids have failed to be processed successfully.
defaultPersistentSubscriptionSettings :: PersistentSubscriptionSettings Source
System default persistent subscription settings.
createPersistentSubscription :: Connection -> Text -> Text -> PersistentSubscriptionSettings -> IO (Async ()) Source
Asynchronously create a persistent subscription group on a stream.
updatePersistentSubscription :: Connection -> Text -> Text -> PersistentSubscriptionSettings -> IO (Async ()) Source
Asynchronously update a persistent subscription group on a stream.
deletePersistentSubscription :: Connection -> Text -> Text -> IO (Async ()) Source
Asynchronously delete a persistent subscription group on a stream.
connectToPersistentSubscription :: Connection -> Text -> Text -> Int32 -> IO (Async (Subscription Persistent)) Source
Asynchronously connect to a persistent subscription given a group on a stream.
Results
data AllEventsSlice Source
The result of a read operation from the $all stream.
AllEventsSlice | |
|
newtype DeleteResult Source
Returned after deleting a stream. Position
of the write.
data WriteResult Source
Returned after writing to a stream.
WriteResult | |
|
data ReadResult Source
Result of a single event read operation to the EventStore.
ReadResult | |
|
data RecordedEvent Source
Represents a previously written event.
RecordedEvent | |
|
data StreamEventsSlice Source
Represents the result of a single read operation to the EventStore.
StreamEventsSlice | |
|
A structure referring to a potential logical record position in the EventStore transaction file.
Position | |
|
data ReadDirection Source
Represents the direction of read operation (both from $all an usual streams).
data ReadAllResult Source
Enumeration detailing the possible outcomes of reading a slice of $all stream.
data ReadEventResult Source
Enumeration representing the status of a single event read operation.
data ResolvedEvent Source
A structure representing a single event or an resolved link event.
ResolvedEvent | |
|
data ReadStreamResult Source
Enumeration detailing the possible outcomes of reading a slice of a stream
data OperationException Source
WrongExpectedVersion Text ExpectedVersion | Stream and Expected Version |
StreamDeleted Text | Stream |
InvalidTransaction | |
AccessDenied Text | Stream |
InvalidServerResponse Word8 Word8 | Expected, Found |
ProtobufDecodingError String | |
ServerError (Maybe Text) | Reason |
InvalidOperation Text |
eventResolved :: ResolvedEvent -> Bool Source
Indicates whether this ResolvedEvent
is a resolved link event.
resolvedEventOriginal :: ResolvedEvent -> Maybe RecordedEvent Source
Returns the event that was read or which triggered the subscription.
If this ResolvedEvent
represents a link event, the link will be the
original event, otherwise it will be the event.
resolvedEventOriginalStreamId :: ResolvedEvent -> Maybe Text Source
The stream name of the original event.
resolvedEventOriginalId :: ResolvedEvent -> Maybe UUID Source
The ID of the original event.
positionStart :: Position Source
Representing the start of the transaction file.
positionEnd :: Position Source
Representing the end of the transaction file.
Misc
data ExpectedVersion Source
Constants used for expected version control.
The use of expected version can be a bit tricky especially when discussing idempotency assurances given by the EventStore.
The EventStore will assure idempotency for all operations using any value
in ExpectedVersion
except for anyStream
. When using anyStream
the
EventStore will do its best to assure idempotency but will not guarantee
idempotency.
anyStream :: ExpectedVersion Source
This write should not conflict with anything and should always succeed.
noStream :: ExpectedVersion Source
The stream being written to should not yet exist. If it does exist treat that as a concurrency problem.
emptyStream :: ExpectedVersion Source
The stream should exist and should be empty. If it does not exist or is not empty, treat that as a concurrency problem.
exactStream :: Int32 -> ExpectedVersion Source
States that the last event written to the stream should have a sequence number matching your expected value.
Re-export
module Control.Concurrent.Async