-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A Haskell client for the Riak decentralized data store
--   
--   A Haskell client library for the Riak decentralized data store,
--   designed for efficiency, ease of use, and flexibility. Uses the Riak
--   protocol buffers API for speed.
--   
--   This library is organized to allow a tradeoff between power and ease
--   of use. If you would like a different degree of automation with
--   storage and conflict resolution, you may want to use one of the
--   following modules (ranked from easiest to most tricky to use):
--   
--   <ul>
--   <li><i>Network.Riak</i> JSON for storage, automatic conflict
--   resolution. This is the easiest module to work with.</li>
--   <li><i>Network.Riak.JSON</i> JSON for storage, manual conflict
--   resolution.</li>
--   <li><i>Network.Riak.Value.Resolvable</i> More complex (but still
--   automatic) storage, automatic conflict resolution.</li>
--   <li><i>Network.Riak.Value</i> More complex (but still automatic)
--   storage, manual conflict resolution.</li>
--   <li><i>Network.Riak.Basic</i> manual storage, manual conflict
--   resolution. This is the most demanding module to work with, as you
--   must encode and decode data yourself, and handle all conflict
--   resolution yourself</li>
--   <li><i>Network.Riak.CRDT</i> CRDT operations.</li>
--   </ul>
@package riak
@version 1.1.2.5


-- | Haskell-side view of CRDT
module Network.Riak.CRDT.Types

-- | CRDT ADT.
--   
--   <a>get</a> operations return value of this type
data DataType
DTCounter :: Counter -> DataType
DTSet :: Set -> DataType
DTMap :: Map -> DataType

-- | CRDT Counter hold a integer <a>Count</a>
--   
--   <pre>
--   &gt;&gt;&gt; Counter 42
--   </pre>
newtype Counter
Counter :: Count -> Counter
type Count = Int64

-- | Counters can be incremented/decremented
--   
--   <pre>
--   &gt;&gt;&gt; CounterInc 1
--   </pre>
data CounterOp
CounterInc :: !Count -> CounterOp

-- | CRDT Set is a Data.Set
--   
--   <pre>
--   &gt;&gt;&gt; Set (Data.Set.fromList ["foo","bar"])
--   </pre>
newtype Set
Set :: (Set ByteString) -> Set

-- | CRDT Set operations
data SetOp

-- | add element to the set
--   
--   <pre>
--   &gt;&gt;&gt; SetAdd "foo"
--   </pre>
SetAdd :: ByteString -> SetOp

-- | remove element from the set
--   
--   <pre>
--   &gt;&gt;&gt; SetRemove "bar"
--   </pre>
SetRemove :: ByteString -> SetOp

-- | CRDT Map is a Data.Map indexed by <a>MapField</a> and holding
--   <a>MapEntry</a>.
--   
--   Maps are specials in a way that they can additionally hold
--   <a>Flag</a>s, <a>Register</a>s, and most importantly, other
--   <a>Map</a>s.
newtype Map
Map :: MapContent -> Map
type MapContent = Map MapField MapEntry

-- | CRDT Map is indexed by MapField, which is a name tagged by a type
--   (there may be different entries with the same name, but different
--   types)
data MapField
MapField :: MapEntryTag -> ByteString -> MapField

-- | CRDT Map holds values of type <a>MapEntry</a>
data MapEntry
MapCounter :: !Counter -> MapEntry
MapSet :: !Set -> MapEntry
MapRegister :: !Register -> MapEntry
MapFlag :: !Flag -> MapEntry
MapMap :: !Map -> MapEntry

-- | Lookup a value of a given <a>MapEntryTag</a> type on a given
--   <a>MapPath</a> inside a map
--   
--   <pre>
--   &gt;&gt;&gt; lookup ("a" -/ "b") MapFlagTag $ { "a"/Map: { "b"/Flag: Flag False } } -- pseudo
--   Just (MapFlag (Flag False))
--   </pre>
xlookup :: MapPath -> MapEntryTag -> Map -> Maybe MapEntry

-- | map operations It's easier to use <a>mapUpdate</a>:
--   
--   <pre>
--   &gt;&gt;&gt; "x" -/ "y" -/ "z" `mapUpdate` SetAdd "elem"
--   MapUpdate (MapPath ("x" :| ["y","z"])) (MapCounterOp (CounterInc 1))
--   </pre>
data MapOp

-- | remove value in map
MapRemove :: MapField -> MapOp

-- | update value on path by operation
MapUpdate :: MapPath -> MapValueOp -> MapOp

-- | Selector (“xpath”) inside <a>Map</a>
newtype MapPath
MapPath :: (NonEmpty ByteString) -> MapPath

-- | Operations on map values
data MapValueOp
MapCounterOp :: !CounterOp -> MapValueOp
MapSetOp :: !SetOp -> MapValueOp
MapRegisterOp :: !RegisterOp -> MapValueOp
MapFlagOp :: !FlagOp -> MapValueOp
MapMapOp :: !MapOp -> MapValueOp
mapUpdate :: IsMapOp o => MapPath -> o -> MapOp
infixr 5 `mapUpdate`
(-/) :: ByteString -> MapPath -> MapPath
infixr 6 -/

-- | Registers can only be held as a <a>Map</a> element.
--   
--   Register holds a <a>ByteString</a>.
newtype Register
Register :: ByteString -> Register

-- | Registers can be set to a value
--   
--   <pre>
--   &gt;&gt;&gt; RegisterSet "foo"
--   </pre>
data RegisterOp
RegisterSet :: !ByteString -> RegisterOp

-- | Flags can only be held as a <a>Map</a> element.
--   
--   Flag can be set or unset
--   
--   <pre>
--   &gt;&gt;&gt; Flag False
--   </pre>
newtype Flag
Flag :: Bool -> Flag

-- | Flags can be enabled / disabled
--   
--   <pre>
--   &gt;&gt;&gt; FlagSet True
--   </pre>
data FlagOp
FlagSet :: !Bool -> FlagOp

-- | Non-empty (and non-strict) list type.
data NonEmpty a
(:|) :: a -> [a] -> NonEmpty a
mapEntryTag :: MapValueOp -> MapEntryTag
setFromSeq :: Seq ByteString -> Set
data MapEntryTag
MapCounterTag :: MapEntryTag
MapSetTag :: MapEntryTag
MapRegisterTag :: MapEntryTag
MapFlagTag :: MapEntryTag
MapMapTag :: MapEntryTag
instance GHC.Show.Show Network.Riak.CRDT.Types.MapOp
instance GHC.Classes.Eq Network.Riak.CRDT.Types.MapOp
instance GHC.Show.Show Network.Riak.CRDT.Types.MapValueOp
instance GHC.Classes.Eq Network.Riak.CRDT.Types.MapValueOp
instance GHC.Show.Show Network.Riak.CRDT.Types.CounterOp
instance GHC.Classes.Eq Network.Riak.CRDT.Types.CounterOp
instance GHC.Generics.Generic Network.Riak.CRDT.Types.DataType
instance GHC.Show.Show Network.Riak.CRDT.Types.DataType
instance GHC.Classes.Eq Network.Riak.CRDT.Types.DataType
instance GHC.Generics.Generic Network.Riak.CRDT.Types.Map
instance GHC.Show.Show Network.Riak.CRDT.Types.Map
instance GHC.Classes.Eq Network.Riak.CRDT.Types.Map
instance GHC.Generics.Generic Network.Riak.CRDT.Types.MapEntry
instance GHC.Show.Show Network.Riak.CRDT.Types.MapEntry
instance GHC.Classes.Eq Network.Riak.CRDT.Types.MapEntry
instance GHC.Generics.Generic Network.Riak.CRDT.Types.Counter
instance GHC.Show.Show Network.Riak.CRDT.Types.Counter
instance GHC.Num.Num Network.Riak.CRDT.Types.Counter
instance GHC.Classes.Ord Network.Riak.CRDT.Types.Counter
instance GHC.Classes.Eq Network.Riak.CRDT.Types.Counter
instance GHC.Show.Show Network.Riak.CRDT.Types.SetOp
instance GHC.Classes.Eq Network.Riak.CRDT.Types.SetOp
instance GHC.Base.Monoid Network.Riak.CRDT.Types.Set
instance GHC.Generics.Generic Network.Riak.CRDT.Types.Set
instance GHC.Show.Show Network.Riak.CRDT.Types.Set
instance GHC.Classes.Ord Network.Riak.CRDT.Types.Set
instance GHC.Classes.Eq Network.Riak.CRDT.Types.Set
instance GHC.Generics.Generic Network.Riak.CRDT.Types.Register
instance GHC.Show.Show Network.Riak.CRDT.Types.Register
instance GHC.Classes.Eq Network.Riak.CRDT.Types.Register
instance GHC.Generics.Generic Network.Riak.CRDT.Types.Flag
instance GHC.Show.Show Network.Riak.CRDT.Types.Flag
instance GHC.Classes.Ord Network.Riak.CRDT.Types.Flag
instance GHC.Classes.Eq Network.Riak.CRDT.Types.Flag
instance GHC.Show.Show Network.Riak.CRDT.Types.FlagOp
instance GHC.Classes.Eq Network.Riak.CRDT.Types.FlagOp
instance GHC.Show.Show Network.Riak.CRDT.Types.RegisterOp
instance GHC.Classes.Eq Network.Riak.CRDT.Types.RegisterOp
instance GHC.Show.Show op => GHC.Show.Show (Network.Riak.CRDT.Types.MapOp_ op)
instance GHC.Show.Show Network.Riak.CRDT.Types.MapPath
instance GHC.Classes.Eq Network.Riak.CRDT.Types.MapPath
instance GHC.Generics.Generic Network.Riak.CRDT.Types.MapField
instance GHC.Show.Show Network.Riak.CRDT.Types.MapField
instance GHC.Classes.Ord Network.Riak.CRDT.Types.MapField
instance GHC.Classes.Eq Network.Riak.CRDT.Types.MapField
instance GHC.Generics.Generic Network.Riak.CRDT.Types.MapEntryTag
instance GHC.Show.Show Network.Riak.CRDT.Types.MapEntryTag
instance GHC.Classes.Ord Network.Riak.CRDT.Types.MapEntryTag
instance GHC.Classes.Eq Network.Riak.CRDT.Types.MapEntryTag
instance Network.Riak.CRDT.Types.IsMapOp Network.Riak.CRDT.Types.CounterOp
instance Network.Riak.CRDT.Types.IsMapOp Network.Riak.CRDT.Types.FlagOp
instance Network.Riak.CRDT.Types.IsMapOp Network.Riak.CRDT.Types.RegisterOp
instance Network.Riak.CRDT.Types.IsMapOp Network.Riak.CRDT.Types.SetOp
instance GHC.Base.Semigroup Network.Riak.CRDT.Types.CounterOp
instance GHC.Base.Monoid Network.Riak.CRDT.Types.CounterOp
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.DataType
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.Map
instance Data.Default.Class.Default Network.Riak.CRDT.Types.Map
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.MapEntry
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.Counter
instance GHC.Base.Semigroup Network.Riak.CRDT.Types.Counter
instance GHC.Base.Monoid Network.Riak.CRDT.Types.Counter
instance Data.Default.Class.Default Network.Riak.CRDT.Types.Counter
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.Set
instance GHC.Base.Semigroup Network.Riak.CRDT.Types.Set
instance Data.Default.Class.Default Network.Riak.CRDT.Types.Set
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.Register
instance GHC.Base.Monoid Network.Riak.CRDT.Types.Register
instance GHC.Base.Semigroup Network.Riak.CRDT.Types.Register
instance Data.Default.Class.Default Network.Riak.CRDT.Types.Register
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.Flag
instance GHC.Base.Monoid Network.Riak.CRDT.Types.Flag
instance GHC.Base.Semigroup Network.Riak.CRDT.Types.Flag
instance Data.Default.Class.Default Network.Riak.CRDT.Types.Flag
instance Data.String.IsString Network.Riak.CRDT.Types.MapPath
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.MapField
instance Control.DeepSeq.NFData Network.Riak.CRDT.Types.MapEntryTag


module Network.Riak.CRDT.Response
get :: DtFetchResponse -> Maybe DataType


-- | Conversions of CRDT operations to <a>DtOp</a>
module Network.Riak.CRDT.Ops
counterUpdateOp :: [CounterOp] -> DtOp
setUpdateOp :: [SetOp] -> DtOp
data SetOpsComb
SetOpsComb :: Set ByteString -> Set ByteString -> SetOpsComb
[setAdds] :: SetOpsComb -> Set ByteString
[setRemoves] :: SetOpsComb -> Set ByteString
toOpsComb :: SetOp -> SetOpsComb
mapUpdateOp :: [MapOp] -> DtOp
instance GHC.Show.Show Network.Riak.CRDT.Ops.SetOpsComb
instance GHC.Base.Semigroup Network.Riak.CRDT.Ops.SetOpsComb
instance GHC.Base.Monoid Network.Riak.CRDT.Ops.SetOpsComb


-- | Support for REST-safe name handling.
--   
--   Riak's protocol buffer (PBC) API will accept unescaped bucket, link,
--   and key names. Its REST API does not unescape names, so it is possible
--   to use the PBC API to construct names that cannot be accessed via the
--   REST API (e.g. containing an embedded slash or other URL-unsafe
--   octet).
module Network.Riak.Escape

-- | The class of string-like types that can be URL-escaped and unescaped.
class Escape e

-- | URL-escape a string.
escape :: Escape e => e -> ByteString

-- | URL-unescape a string.
unescape' :: Escape e => ByteString -> Either String e

-- | URL-unescape a string that is presumed to be properly escaped. If the
--   string is invalid, an error will be thrown that cannot be caught from
--   pure code.
unescape :: Escape e => ByteString -> e
instance Network.Riak.Escape.Escape Data.ByteString.Internal.ByteString
instance Network.Riak.Escape.Escape Data.ByteString.Lazy.Internal.ByteString
instance Network.Riak.Escape.Escape Data.Text.Internal.Text
instance Network.Riak.Escape.Escape Data.Text.Internal.Lazy.Text
instance Network.Riak.Escape.Escape [GHC.Types.Char]


-- | Useful functions.
module Network.Riak.Functions
strict :: ByteString -> ByteString
lazy :: ByteString -> ByteString


-- | Basic types.
module Network.Riak.Types.Internal

-- | A client identifier. This is used by the Riak cluster when logging
--   vector clock changes, and should be unique for each client.
type ClientID = ByteString
data Client
Client :: HostName -> ServiceName -> ClientID -> Client

-- | Name of the server to connect to.
[host] :: Client -> HostName

-- | Port number to connect to (default is 8087).
[port] :: Client -> ServiceName

-- | Client identifier.
[clientID] :: Client -> ClientID

-- | A connection to a Riak server.
data Connection
Connection :: Socket -> Client -> IORef ByteString -> Connection
[connSock] :: Connection -> Socket

-- | The configuration we connected with.
[connClient] :: Connection -> Client

-- | Received data that has not yet been consumed.
[connBuffer] :: Connection -> IORef ByteString

-- | The main Riak exception type.
data RiakException
netError :: String -> String -> String -> a
typeError :: String -> String -> String -> a
unexError :: String -> String -> String -> a

-- | A Bucket is a container and keyspace for data stored in Riak, with a
--   set of common properties for its contents (the number of replicas, for
--   instance).
type Bucket = ByteString

-- | Bucket types is a riak &gt;= 2.0 feature allowing groups of buckets to
--   share configuration details
type BucketType = ByteString

-- | Keys are unique object identifiers in Riak and are scoped within
--   buckets.
type Key = ByteString

-- | Name of a secondary index
type Index = ByteString

-- | Name of an index schema
type Schema = ByteString

-- | Index query. Can be exact or range, int or bin. Index name should not
--   contain the "_bin" or "_int" part, since it's determined from data
--   constructor.
data IndexQuery
IndexQueryExactInt :: !Index -> !Int -> IndexQuery
IndexQueryExactBin :: !Index -> !ByteString -> IndexQuery
IndexQueryRangeInt :: !Index -> !Int -> !Int -> IndexQuery
IndexQueryRangeBin :: !Index -> !ByteString -> !ByteString -> IndexQuery
data IndexValue
IndexInt :: !Index -> !Int -> IndexValue
IndexBin :: !Index -> !ByteString -> IndexValue

-- | An application-specific identifier for a link. See
--   <a>http://wiki.basho.com/Links.html</a> for details.
type Tag = ByteString

-- | Search request
type SearchQuery = ByteString

-- | Solr search result
data SearchResult
SearchResult :: !(Seq (Seq (ByteString, Maybe ByteString))) -> !(Maybe Float) -> !(Maybe Word32) -> SearchResult
[docs] :: SearchResult -> !(Seq (Seq (ByteString, Maybe ByteString)))
[maxScore] :: SearchResult -> !(Maybe Float)
[numFound] :: SearchResult -> !(Maybe Word32)

-- | Search result score
type Score = Double

-- | Search index info
type IndexInfo = YzIndex

-- | A wrapper that keeps Riak vector clocks opaque.
newtype VClock
VClock :: ByteString -> VClock

-- | Unwrap the <a>ByteString</a>. (This is really only useful for printing
--   the raw vclock string.)
[fromVClock] :: VClock -> ByteString

-- | A specification of a MapReduce job.
--   <a>http://wiki.basho.com/MapReduce.html</a>.
data Job
JSON :: ByteString -> Job
Erlang :: ByteString -> Job

-- | N value
--   
--   <a>http://docs.basho.com/riak/kv/2.1.4/learn/concepts/replication/</a>
type N = Word32

-- | Timeout in milliseconds
type Timeout = Word32

-- | A read/write quorum. The quantity of replicas that must respond to a
--   read or write request before it is considered successful. This is
--   defined as a bucket property or as one of the relevant parameters to a
--   single request (<a>R</a>,<a>W</a>,<a>DW</a>,<a>RW</a>).
data Quorum

-- | Use the default quorum settings for the bucket.
Default :: Quorum

-- | Success after one server has responded.
One :: Quorum

-- | Success after a quorum of servers has responded.
Quorum :: Quorum

-- | Success after all servers have responded.
All :: Quorum

-- | Durable write quorum. How many replicas to commit to durable storage
--   before returning a successful response.
type DW = Quorum

-- | Read quorum. How many replicas need to agree when retrieving a value.
type R = Quorum

-- | Read/write quorum. How many replicas need to collaborate when deleting
--   a value.
type RW = Quorum

-- | Write quorum. How many replicas to write to before returning a
--   successful response.
type W = Quorum
fromQuorum :: Quorum -> Maybe Word32
toQuorum :: Word32 -> Maybe Quorum

-- | A message representing a request from client to server.
class (Tagged msg, ReflectDescriptor msg, Show msg, Wire msg) => Request msg
expectedResponse :: Request msg => msg -> MessageTag

-- | A message representing a response from server to client.
class (Tagged msg, ReflectDescriptor msg, Show msg, Wire msg) => Response msg
class (Request req, Response resp) => Exchange req resp | req -> resp

-- | List of (known to us) inbound or outbound message identifiers.
data MessageTag
ErrorResponse :: MessageTag
PingRequest :: MessageTag
PingResponse :: MessageTag
GetClientIDRequest :: MessageTag
GetClientIDResponse :: MessageTag
SetClientIDRequest :: MessageTag
SetClientIDResponse :: MessageTag
GetServerInfoRequest :: MessageTag
GetServerInfoResponse :: MessageTag
GetRequest :: MessageTag
GetResponse :: MessageTag
PutRequest :: MessageTag
PutResponse :: MessageTag
DeleteRequest :: MessageTag
DeleteResponse :: MessageTag
ListBucketsRequest :: MessageTag
ListBucketsResponse :: MessageTag
ListKeysRequest :: MessageTag
ListKeysResponse :: MessageTag
GetBucketRequest :: MessageTag
GetBucketResponse :: MessageTag
SetBucketRequest :: MessageTag
SetBucketResponse :: MessageTag
GetBucketTypeRequest :: MessageTag
MapReduceRequest :: MessageTag
MapReduceResponse :: MessageTag
IndexRequest :: MessageTag
IndexResponse :: MessageTag
DtFetchRequest :: MessageTag
DtFetchResponse :: MessageTag
DtUpdateRequest :: MessageTag
DtUpdateResponse :: MessageTag
SearchQueryRequest :: MessageTag
SearchQueryResponse :: MessageTag
YokozunaIndexGetRequest :: MessageTag
YokozunaIndexGetResponse :: MessageTag
YokozunaIndexPutRequest :: MessageTag
YokozunaIndexDeleteRequest :: MessageTag

-- | Messages are tagged.
class Tagged msg
messageTag :: Tagged msg => msg -> MessageTag
instance GHC.Show.Show Network.Riak.Types.Internal.Quorum
instance GHC.Classes.Ord Network.Riak.Types.Internal.Quorum
instance GHC.Enum.Enum Network.Riak.Types.Internal.Quorum
instance GHC.Classes.Eq Network.Riak.Types.Internal.Quorum
instance GHC.Enum.Bounded Network.Riak.Types.Internal.Quorum
instance GHC.Classes.Eq Network.Riak.Types.Internal.VClock
instance GHC.Generics.Generic Network.Riak.Types.Internal.MessageTag
instance GHC.Show.Show Network.Riak.Types.Internal.MessageTag
instance GHC.Classes.Eq Network.Riak.Types.Internal.MessageTag
instance GHC.Show.Show Network.Riak.Types.Internal.SearchResult
instance GHC.Classes.Ord Network.Riak.Types.Internal.SearchResult
instance GHC.Classes.Eq Network.Riak.Types.Internal.SearchResult
instance GHC.Show.Show Network.Riak.Types.Internal.Job
instance GHC.Classes.Eq Network.Riak.Types.Internal.Job
instance GHC.Classes.Eq Network.Riak.Types.Internal.IndexValue
instance GHC.Show.Show Network.Riak.Types.Internal.IndexValue
instance GHC.Classes.Eq Network.Riak.Types.Internal.IndexQuery
instance GHC.Show.Show Network.Riak.Types.Internal.IndexQuery
instance GHC.Classes.Eq Network.Riak.Types.Internal.RiakException
instance GHC.Classes.Eq Network.Riak.Types.Internal.Connection
instance GHC.Show.Show Network.Riak.Types.Internal.Client
instance GHC.Classes.Eq Network.Riak.Types.Internal.Client
instance GHC.Show.Show Network.Riak.Types.Internal.VClock
instance Network.Riak.Types.Internal.Tagged Network.Riak.Types.Internal.MessageTag
instance Data.Hashable.Class.Hashable Network.Riak.Types.Internal.MessageTag
instance GHC.Show.Show Network.Riak.Types.Internal.RiakException
instance GHC.Exception.Exception Network.Riak.Types.Internal.RiakException
instance GHC.Show.Show Network.Riak.Types.Internal.Connection


-- | Basic types.
module Network.Riak.Types

-- | A client identifier. This is used by the Riak cluster when logging
--   vector clock changes, and should be unique for each client.
type ClientID = ByteString
data Client
Client :: HostName -> ServiceName -> ClientID -> Client

-- | Name of the server to connect to.
[host] :: Client -> HostName

-- | Port number to connect to (default is 8087).
[port] :: Client -> ServiceName

-- | Client identifier.
[clientID] :: Client -> ClientID

-- | A connection to a Riak server.
data Connection

-- | The main Riak exception type.
data RiakException

-- | Bucket types is a riak &gt;= 2.0 feature allowing groups of buckets to
--   share configuration details
type BucketType = ByteString

-- | A Bucket is a container and keyspace for data stored in Riak, with a
--   set of common properties for its contents (the number of replicas, for
--   instance).
type Bucket = ByteString

-- | Keys are unique object identifiers in Riak and are scoped within
--   buckets.
type Key = ByteString

-- | An application-specific identifier for a link. See
--   <a>http://wiki.basho.com/Links.html</a> for details.
type Tag = ByteString

-- | A wrapper that keeps Riak vector clocks opaque.
newtype VClock
VClock :: ByteString -> VClock

-- | Unwrap the <a>ByteString</a>. (This is really only useful for printing
--   the raw vclock string.)
[fromVClock] :: VClock -> ByteString

-- | A specification of a MapReduce job.
--   <a>http://wiki.basho.com/MapReduce.html</a>.
data Job
JSON :: ByteString -> Job
Erlang :: ByteString -> Job

-- | A read/write quorum. The quantity of replicas that must respond to a
--   read or write request before it is considered successful. This is
--   defined as a bucket property or as one of the relevant parameters to a
--   single request (<a>R</a>,<a>W</a>,<a>DW</a>,<a>RW</a>).
data Quorum

-- | Use the default quorum settings for the bucket.
Default :: Quorum

-- | Success after one server has responded.
One :: Quorum

-- | Success after a quorum of servers has responded.
Quorum :: Quorum

-- | Success after all servers have responded.
All :: Quorum

-- | Read/write quorum. How many replicas need to collaborate when deleting
--   a value.
type RW = Quorum

-- | Read quorum. How many replicas need to agree when retrieving a value.
type R = Quorum

-- | Write quorum. How many replicas to write to before returning a
--   successful response.
type W = Quorum

-- | Durable write quorum. How many replicas to commit to durable storage
--   before returning a successful response.
type DW = Quorum

-- | A message representing a request from client to server.
class (Tagged msg, ReflectDescriptor msg, Show msg, Wire msg) => Request msg

-- | A message representing a response from server to client.
class (Tagged msg, ReflectDescriptor msg, Show msg, Wire msg) => Response msg
class (Request req, Response resp) => Exchange req resp | req -> resp

-- | List of (known to us) inbound or outbound message identifiers.
data MessageTag
ErrorResponse :: MessageTag
PingRequest :: MessageTag
PingResponse :: MessageTag
GetClientIDRequest :: MessageTag
GetClientIDResponse :: MessageTag
SetClientIDRequest :: MessageTag
SetClientIDResponse :: MessageTag
GetServerInfoRequest :: MessageTag
GetServerInfoResponse :: MessageTag
GetRequest :: MessageTag
GetResponse :: MessageTag
PutRequest :: MessageTag
PutResponse :: MessageTag
DeleteRequest :: MessageTag
DeleteResponse :: MessageTag
ListBucketsRequest :: MessageTag
ListBucketsResponse :: MessageTag
ListKeysRequest :: MessageTag
ListKeysResponse :: MessageTag
GetBucketRequest :: MessageTag
GetBucketResponse :: MessageTag
SetBucketRequest :: MessageTag
SetBucketResponse :: MessageTag
GetBucketTypeRequest :: MessageTag
MapReduceRequest :: MessageTag
MapReduceResponse :: MessageTag
IndexRequest :: MessageTag
IndexResponse :: MessageTag
DtFetchRequest :: MessageTag
DtFetchResponse :: MessageTag
DtUpdateRequest :: MessageTag
DtUpdateResponse :: MessageTag
SearchQueryRequest :: MessageTag
SearchQueryResponse :: MessageTag
YokozunaIndexGetRequest :: MessageTag
YokozunaIndexGetResponse :: MessageTag
YokozunaIndexPutRequest :: MessageTag
YokozunaIndexDeleteRequest :: MessageTag

-- | Messages are tagged.
class Tagged msg
messageTag :: Tagged msg => msg -> MessageTag
data IndexValue
IndexInt :: !Index -> !Int -> IndexValue
IndexBin :: !Index -> !ByteString -> IndexValue

-- | Index query. Can be exact or range, int or bin. Index name should not
--   contain the "_bin" or "_int" part, since it's determined from data
--   constructor.
data IndexQuery
IndexQueryExactInt :: !Index -> !Int -> IndexQuery
IndexQueryExactBin :: !Index -> !ByteString -> IndexQuery
IndexQueryRangeInt :: !Index -> !Int -> !Int -> IndexQuery
IndexQueryRangeBin :: !Index -> !ByteString -> !ByteString -> IndexQuery

-- | Solr search result
data SearchResult
SearchResult :: !(Seq (Seq (ByteString, Maybe ByteString))) -> !(Maybe Float) -> !(Maybe Word32) -> SearchResult
[docs] :: SearchResult -> !(Seq (Seq (ByteString, Maybe ByteString)))
[maxScore] :: SearchResult -> !(Maybe Float)
[numFound] :: SearchResult -> !(Maybe Word32)


module Network.Riak.CRDT.Request
get :: ByteString -> ByteString -> ByteString -> DtFetchRequest
counterUpdate :: [CounterOp] -> BucketType -> Bucket -> Key -> DtUpdateRequest
setUpdate :: [SetOp] -> BucketType -> Bucket -> Key -> DtUpdateRequest
mapUpdate :: [MapOp] -> BucketType -> Bucket -> Key -> DtUpdateRequest


-- | Smart deconstructors for Riak types. These functions correctly
--   URL-unescape bucket, key, and link names. You should thus use them in
--   preference to direct pattern matching against raw data constructors.
module Network.Riak.Response
getClientID :: GetClientIDResponse -> ClientID

-- | Construct a get response. Bucket and key names in links are
--   URL-unescaped.
get :: Maybe GetResponse -> Maybe (Seq Content, VClock)

-- | Construct a put response. Bucket and key names in links are
--   URL-unescaped.
put :: PutResponse -> (Seq Content, VClock)

-- | Construct a list-buckets response. Bucket names are unescaped.
listBuckets :: ListBucketsResponse -> Seq Bucket
getBucket :: GetBucketResponse -> BucketProps

-- | URL-unescape the names of keys and buckets in the links of a
--   <a>Content</a> value.
unescapeLinks :: Content -> Content
search :: SearchQueryResponse -> SearchResult
getIndex :: YzIndexGetResponse -> [IndexInfo]


-- | Smart constructors for Riak types. These functions correctly
--   URL-escape bucket, key, and link names. You should thus use them in
--   preference to the raw data constructors.
module Network.Riak.Request
data PingRequest

-- | Create a ping request.
ping :: PingRequest
data GetClientIDRequest

-- | Create a client-ID request.
getClientID :: GetClientIDRequest
data GetServerInfoRequest

-- | Create a server-info request.
getServerInfo :: GetServerInfoRequest
data GetRequest

-- | Create a get request. The bucket and key names are URL-escaped.
get :: Maybe BucketType -> Bucket -> Key -> R -> GetRequest

-- | Create a secondary index request. Bucket, key and index names and
--   values are URL-escaped.
getByIndex :: Bucket -> IndexQuery -> IndexRequest
data IndexRequest
data PutRequest

-- | Create a put request. The bucket and key names are URL-escaped. Any
--   <tt>Link</tt> values inside the <a>Content</a> are assumed to have
--   been constructed with the <a>link</a> function, and hence <i>not</i>
--   escaped.
put :: Maybe BucketType -> Bucket -> Key -> Maybe VClock -> Content -> W -> DW -> Bool -> PutRequest
data DeleteRequest

-- | Create a delete request. The bucket and key names are URL-escaped.
delete :: Maybe BucketType -> Bucket -> Key -> RW -> DeleteRequest
data Link

-- | Create a link. The bucket and key names are URL-escaped.
link :: Bucket -> Key -> Tag -> Link
data ListBucketsRequest

-- | Create a list-buckets request.
listBuckets :: Maybe BucketType -> ListBucketsRequest
data ListKeysRequest

-- | Create a list-keys request. The bucket type and name are URL-escaped.
listKeys :: Maybe BucketType -> Bucket -> ListKeysRequest
data GetBucketRequest

-- | Create a get-bucket request. The bucket type and name are URL-escaped.
getBucket :: Maybe BucketType -> Bucket -> GetBucketRequest
data SetBucketRequest

-- | Create a set-bucket request. The bucket type and name are URL-escaped.
setBucket :: Maybe BucketType -> Bucket -> BucketProps -> SetBucketRequest

-- | Create a get-bucket-type request. The bucket type is URL-escaped.
getBucketType :: BucketType -> GetBucketTypeRequest
data MapReduceRequest

-- | Create a map-reduce request.
mapReduce :: Job -> MapReduceRequest

-- | Create a search request
search :: SearchQuery -> Index -> SearchQueryRequest
getIndex :: Maybe Index -> YzIndexGetRequest
putIndex :: IndexInfo -> Maybe Timeout -> YzIndexPutRequest
deleteIndex :: Index -> YzIndexDeleteRequest


-- | Support for debug logging. The code in this package only works if the
--   package was built with the <tt>-fdebug</tt> flag. Otherwise, they are
--   all no-ops.
module Network.Riak.Debug

-- | The current debugging level. This is established once by reading the
--   <tt>RIAK_DEBUG</tt> environment variable.
level :: Int

-- | Print a debug message, if debugging is enabled.
debug :: String -> String -> IO ()

-- | Print a debug message, and information about some values. If the debug
--   level is greater than 1, print the values themselves.
debugValues :: (Show a) => String -> String -> [a] -> IO ()

-- | Set the <a>Handle</a> to log to (<a>stderr</a> is the default).
setHandle :: Handle -> IO ()

-- | Show a <a>Tagged</a> value. Show the entire value if the debug level
--   is above 1, just the tag otherwise.
showM :: (Show a, Tagged a) => a -> String


-- | Storage and retrieval of data with automatic conflict resolution.
module Network.Riak.Resolvable

-- | A type that can automatically resolve a vector clock conflict between
--   two or more versions of a value.
--   
--   Instances must be symmetric in their behaviour, such that the
--   following law is obeyed:
--   
--   <pre>
--   resolve a b == resolve b a
--   </pre>
--   
--   Otherwise, there are no restrictions on the behaviour of
--   <a>resolve</a>. The result may be <tt>a</tt>, <tt>b</tt>, a value
--   derived from <tt>a</tt> and <tt>b</tt>, or something else.
--   
--   If several conflicting siblings are found, <a>resolve</a> will be
--   applied over all of them using a fold, to yield a single "winner".
class (Show a) => Resolvable a

-- | Resolve a conflict between two values.
resolve :: Resolvable a => a -> a -> a

-- | A newtype wrapper that uses the <a>mappend</a> method of a type's
--   <a>Monoid</a> instance to perform vector clock conflict resolution.
newtype ResolvableMonoid a
RM :: a -> ResolvableMonoid a
[unRM] :: ResolvableMonoid a -> a

-- | Automated conflict resolution failed.
data ResolutionFailure

-- | Too many attempts were made to resolve a conflict, with each attempt
--   resulting in another conflict.
--   
--   The number of retries that the library will attempt is high (64). This
--   makes it extremely unlikely that this exception will be thrown during
--   normal application operation. Instead, this exception is most likely
--   to be thrown as a result of a bug in your application code, for
--   example if your <a>resolve</a> function is misbehaving.
RetriesExceeded :: ResolutionFailure


-- | Low-level content and link types and functions.
module Network.Riak.Content
data Content
Content :: !ByteString -> !Maybe ByteString -> !Maybe ByteString -> !Maybe ByteString -> !Maybe ByteString -> !Seq Link -> !Maybe Word32 -> !Maybe Word32 -> !Seq Pair -> !Seq Pair -> !Maybe Bool -> Content
[value] :: Content -> !ByteString
[content_type] :: Content -> !Maybe ByteString
[charset] :: Content -> !Maybe ByteString
[content_encoding] :: Content -> !Maybe ByteString
[vtag] :: Content -> !Maybe ByteString
[links] :: Content -> !Seq Link
[last_mod] :: Content -> !Maybe Word32
[last_mod_usecs] :: Content -> !Maybe Word32
[usermeta] :: Content -> !Seq Pair
[indexes] :: Content -> !Seq Pair
[deleted] :: Content -> !Maybe Bool
data Link
Link :: !Maybe ByteString -> !Maybe ByteString -> !Maybe ByteString -> Link
[bucket] :: Link -> !Maybe ByteString
[key] :: Link -> !Maybe ByteString
[tag] :: Link -> !Maybe ByteString

-- | An empty piece of content.
empty :: Content

-- | Content encoded as <tt>application/octet-stream</tt>.
binary :: ByteString -> Content

-- | Content encoded as <tt>application/json</tt>.
json :: ToJSON a => a -> Content

-- | Create a link.
link :: Bucket -> Key -> Tag -> Link


-- | Low-level network connection management.
module Network.Riak.Connection.Internal

-- | Connect to a server.
connect :: Client -> IO Connection

-- | Disconnect from a server.
disconnect :: Connection -> IO ()

-- | Tell the server our client ID.
setClientID :: Connection -> ClientID -> IO ()

-- | Default client configuration. Talks to localhost, port 8087, with a
--   randomly chosen client ID.
defaultClient :: Client

-- | Generate a random client ID.
makeClientID :: IO ClientID

-- | Send a request to the server, and receive its response.
exchange :: Exchange req resp => Connection -> req -> IO resp

-- | Send a request to the server, and receive its response (which may be
--   empty).
exchangeMaybe :: Exchange req resp => Connection -> req -> IO (Maybe resp)

-- | Send a request to the server, and receive its response, but do not
--   decode it.
exchange_ :: Request req => Connection -> req -> IO ()

-- | Send a series of requests to the server, back to back, and receive a
--   response for each request sent. The sending and receiving will be
--   overlapped if possible, to improve concurrency and reduce latency.
pipeline :: (Exchange req resp) => Connection -> [req] -> IO [resp]

-- | Send a series of requests to the server, back to back, and receive a
--   response for each request sent (the responses may be empty). The
--   sending and receiving will be overlapped if possible, to improve
--   concurrency and reduce latency.
pipelineMaybe :: (Exchange req resp) => Connection -> [req] -> IO [Maybe resp]

-- | Send a series of requests to the server, back to back, and receive
--   (but do not decode) a response for each request sent. The sending and
--   receiving will be overlapped if possible, to improve concurrency and
--   reduce latency.
pipeline_ :: (Request req) => Connection -> [req] -> IO ()
sendRequest :: (Request req) => Connection -> req -> IO ()
recvResponse :: (Response a) => Connection -> IO a
recvMaybeResponse :: (Response a) => Connection -> IO (Maybe a)
recvResponse_ :: Connection -> MessageTag -> IO ()
instance GHC.Exception.Exception Network.Riak.Protocol.ErrorResponse.ErrorResponse


-- | Solr search
--   
--   <a>http://docs.basho.com/riak/2.1.3/dev/using/search/</a>
module Network.Riak.Search

-- | Search index info
type IndexInfo = YzIndex

-- | Solr search result
data SearchResult
SearchResult :: !(Seq (Seq (ByteString, Maybe ByteString))) -> !(Maybe Float) -> !(Maybe Word32) -> SearchResult
[docs] :: SearchResult -> !(Seq (Seq (ByteString, Maybe ByteString)))
[maxScore] :: SearchResult -> !(Maybe Float)
[numFound] :: SearchResult -> !(Maybe Word32)

-- | Search result score
type Score = Double

-- | <a>IndexInfo</a> smart constructor.
--   
--   If <a>Nothing</a>, <tt>schema</tt> defaults to <tt>"_yz_default"</tt>.
--   
--   If <a>Nothing</a>, <tt>n</tt> defaults to the default <tt>n</tt> value
--   for buckets that have not explicitly set the property. In the default
--   installation of <tt>riak</tt>, this is 3 (see
--   <a>https://github.com/basho/riak_core/blob/develop/priv/riak_core.schema)</a>.
indexInfo :: Index -> Maybe Schema -> Maybe N -> IndexInfo

-- | Get an index info for <tt>Just index</tt>, or get all indexes for
--   <tt>Nothing</tt>.
--   
--   
--   <a>https://docs.basho.com/riak/kv/2.1.4/developing/api/protocol-buffers/yz-index-get/</a>
getIndex :: Connection -> Maybe Index -> IO [IndexInfo]

-- | Create a new index or modify an existing index.
--   
--   
--   <a>https://docs.basho.com/riak/kv/2.1.4/developing/api/protocol-buffers/yz-index-put/</a>
putIndex :: Connection -> IndexInfo -> Maybe Timeout -> IO (Seq Content, VClock)

-- | Delete an index.
--   
--   
--   <a>https://docs.basho.com/riak/kv/2.1.4/developing/api/protocol-buffers/yz-index-delete/</a>
deleteIndex :: Connection -> Index -> IO ()

-- | Search by raw <a>SearchQuery</a> request (a <a>Bytestring</a>) using
--   an <a>Index</a>.
searchRaw :: Connection -> SearchQuery -> Index -> IO SearchResult


-- | Low-level network connection management.
module Network.Riak.Connection

-- | Connect to a server.
connect :: Client -> IO Connection

-- | Disconnect from a server.
disconnect :: Connection -> IO ()

-- | Default client configuration. Talks to localhost, port 8087, with a
--   randomly chosen client ID.
defaultClient :: Client

-- | Generate a random client ID.
makeClientID :: IO ClientID

-- | Send a request to the server, and receive its response.
exchange :: Exchange req resp => Connection -> req -> IO resp

-- | Send a request to the server, and receive its response (which may be
--   empty).
exchangeMaybe :: Exchange req resp => Connection -> req -> IO (Maybe resp)

-- | Send a request to the server, and receive its response, but do not
--   decode it.
exchange_ :: Request req => Connection -> req -> IO ()

-- | Send a series of requests to the server, back to back, and receive a
--   response for each request sent. The sending and receiving will be
--   overlapped if possible, to improve concurrency and reduce latency.
pipeline :: (Exchange req resp) => Connection -> [req] -> IO [resp]

-- | Send a series of requests to the server, back to back, and receive a
--   response for each request sent (the responses may be empty). The
--   sending and receiving will be overlapped if possible, to improve
--   concurrency and reduce latency.
pipelineMaybe :: (Exchange req resp) => Connection -> [req] -> IO [Maybe resp]

-- | Send a series of requests to the server, back to back, and receive
--   (but do not decode) a response for each request sent. The sending and
--   receiving will be overlapped if possible, to improve concurrency and
--   reduce latency.
pipeline_ :: (Request req) => Connection -> [req] -> IO ()


-- | CRDT operations
module Network.Riak.CRDT.Riak
counterSendUpdate :: Connection -> BucketType -> Bucket -> Key -> [CounterOp] -> IO ()
setSendUpdate :: Connection -> BucketType -> Bucket -> Key -> [SetOp] -> IO ()
mapSendUpdate :: Connection -> BucketType -> Bucket -> Key -> [MapOp] -> IO ()
get :: Connection -> BucketType -> Bucket -> Key -> IO (Maybe DataType)


-- | CRDT operations
--   
--   <ul>
--   <li>Haskell-side<ul><li>Haskell values: <a>Counter</a>, <a>Set</a>
--   etc</li><li>ADT for operations: <a>CounterOp</a>, <a>SetOp</a>
--   etc</li><li><a>modify</a> to locally modify a value (matching
--   riak-side behaviour)</li></ul></li>
--   <li>Riak-side<ul><li><a>get</a> to get a current
--   value</li><li><a>sendModify</a> to ask Riak to apply
--   modifications</li></ul></li>
--   </ul>
--   
--   TL;DR example
--   
--   <pre>
--   &gt;&gt;&gt; let c = Counter 41
--   
--   &gt;&gt;&gt; let op = CounterInc 1
--   
--   &gt;&gt;&gt; modify op c
--   Counter 42
--   
--   &gt;&gt;&gt; get conn "counters" "bucket" "key"
--   Just (DTCounter (Counter 41))
--   
--   &gt;&gt;&gt; sendModify conn "counters" "bucket" "key" [op] &gt;&gt; get conn "counters" "bucket" "key"
--   Just (DTCounter (Counter 42))
--   </pre>
module Network.Riak.CRDT
get :: Connection -> BucketType -> Bucket -> Key -> IO (Maybe DataType)

-- | CRDT types
class MapCRDT a => CRDT a op | a -> op, op -> a

-- | Modify a value by applying an operation
modify :: CRDT a op => op -> a -> a

-- | Request riak a modification
sendModify :: CRDT a op => Connection -> BucketType -> Bucket -> Key -> [op] -> IO ()
instance Network.Riak.CRDT.MapCRDT Network.Riak.CRDT.Types.Set
instance Network.Riak.CRDT.MapCRDT Network.Riak.CRDT.Types.Counter
instance Network.Riak.CRDT.MapCRDT Network.Riak.CRDT.Types.Map
instance Network.Riak.CRDT.CRDT Network.Riak.CRDT.Types.Counter Network.Riak.CRDT.Types.CounterOp
instance Network.Riak.CRDT.CRDT Network.Riak.CRDT.Types.Set Network.Riak.CRDT.Types.SetOp
instance Network.Riak.CRDT.CRDT Network.Riak.CRDT.Types.Map Network.Riak.CRDT.Types.MapOp
instance Network.Riak.CRDT.MapCRDT Network.Riak.CRDT.Types.Flag
instance Network.Riak.CRDT.MapCRDT Network.Riak.CRDT.Types.Register


-- | Basic support for the Riak decentralized data store.
--   
--   When storing and retrieving data, the functions in this module do not
--   perform any encoding or decoding of data, nor do they resolve
--   conflicts.
module Network.Riak.Basic

-- | A client identifier. This is used by the Riak cluster when logging
--   vector clock changes, and should be unique for each client.
type ClientID = ByteString
data Client
Client :: HostName -> ServiceName -> ClientID -> Client

-- | Name of the server to connect to.
[host] :: Client -> HostName

-- | Port number to connect to (default is 8087).
[port] :: Client -> ServiceName

-- | Client identifier.
[clientID] :: Client -> ClientID

-- | Default client configuration. Talks to localhost, port 8087, with a
--   randomly chosen client ID.
defaultClient :: Client

-- | A connection to a Riak server.
data Connection
Connection :: Socket -> Client -> IORef ByteString -> Connection
[connSock] :: Connection -> Socket

-- | The configuration we connected with.
[connClient] :: Connection -> Client

-- | Received data that has not yet been consumed.
[connBuffer] :: Connection -> IORef ByteString

-- | Connect to a server.
connect :: Client -> IO Connection

-- | Disconnect from a server.
disconnect :: Connection -> IO ()

-- | Check to see if the connection to the server is alive.
ping :: Connection -> IO ()

-- | Find out from the server what client ID this connection is using.
getClientID :: Connection -> IO ClientID

-- | Tell the server our client ID.
setClientID :: Connection -> ClientID -> IO ()

-- | Retrieve information about the server.
getServerInfo :: Connection -> IO ServerInfo

-- | A read/write quorum. The quantity of replicas that must respond to a
--   read or write request before it is considered successful. This is
--   defined as a bucket property or as one of the relevant parameters to a
--   single request (<a>R</a>,<a>W</a>,<a>DW</a>,<a>RW</a>).
data Quorum

-- | Use the default quorum settings for the bucket.
Default :: Quorum

-- | Success after one server has responded.
One :: Quorum

-- | Success after a quorum of servers has responded.
Quorum :: Quorum

-- | Success after all servers have responded.
All :: Quorum

-- | Retrieve a value. This may return multiple conflicting siblings.
--   Choosing among them is your responsibility.
get :: Connection -> Maybe BucketType -> Bucket -> Key -> R -> IO (Maybe (Seq Content, VClock))

-- | Store a single value. This may return multiple conflicting siblings.
--   Choosing among them, and storing a new value, is your responsibility.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored.
put :: Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> Content -> W -> DW -> IO (Seq Content, VClock)

-- | Store a single value, without the possibility of conflict resolution.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored, and you will not be notified.
put_ :: Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> Content -> W -> DW -> IO ()

-- | Delete a value.
delete :: Connection -> Maybe BucketType -> Bucket -> Key -> RW -> IO ()

-- | List the buckets in the cluster.
--   
--   <i>Note</i>: this operation is expensive. Do not use it in production.
listBuckets :: Connection -> Maybe BucketType -> IO (Seq Bucket)

-- | Fold over the keys in a bucket.
--   
--   <i>Note</i>: this operation is expensive. Do not use it in production.
foldKeys :: (MonadIO m) => Connection -> Maybe BucketType -> Bucket -> (a -> Key -> m a) -> a -> m a

-- | Retrieve the properties of a bucket.
getBucket :: Connection -> Maybe BucketType -> Bucket -> IO BucketProps

-- | Store new properties for a bucket.
setBucket :: Connection -> Maybe BucketType -> Bucket -> BucketProps -> IO ()

-- | Gets the bucket properties associated with a bucket type.
getBucketType :: Connection -> BucketType -> IO BucketProps

-- | Run a <a>MapReduce</a> job. Its result is consumed via a strict left
--   fold.
mapReduce :: Connection -> Job -> (a -> MapReduce -> a) -> a -> IO a


-- | This module allows storage and retrieval of data using the
--   <a>IsContent</a> typeclass. This provides access to more of Riak's
--   storage features than JSON, e.g. links.
--   
--   The functions in this module do not perform any conflict resolution.
module Network.Riak.Value
class IsContent c
parseContent :: IsContent c => Content -> Parser c
toContent :: IsContent c => c -> Content
fromContent :: IsContent c => Content -> Maybe c

-- | Retrieve a value. This may return multiple conflicting siblings.
--   Choosing among them is your responsibility.
get :: (IsContent c) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> IO (Maybe ([c], VClock))
getMany :: (IsContent c) => Connection -> Maybe BucketType -> Bucket -> [Key] -> R -> IO [Maybe ([c], VClock)]

-- | Retrieve list of keys matching some index query.
getByIndex :: Connection -> Bucket -> IndexQuery -> IO [Key]

-- | Add indexes to a content value for a further put request.
addIndexes :: [IndexValue] -> Content -> Content

-- | Store a single value. This may return multiple conflicting siblings.
--   Choosing among them, and storing a new value, is your responsibility.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored.
put :: (IsContent c) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> c -> W -> DW -> IO ([c], VClock)

-- | Store an indexed value.
putIndexed :: (IsContent c) => Connection -> Maybe BucketType -> Bucket -> Key -> [IndexValue] -> Maybe VClock -> c -> W -> DW -> IO ([c], VClock)

-- | Store a single value, without the possibility of conflict resolution.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored, and you will not be notified.
put_ :: (IsContent c) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> c -> W -> DW -> IO ()

-- | Store many values. This may return multiple conflicting siblings for
--   each value stored. Choosing among them, and storing a new value in
--   each case, is your responsibility.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored.
putMany :: (IsContent c) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW -> IO [([c], VClock)]

-- | Store many values, without the possibility of conflict resolution.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored, and you will not be notified.
putMany_ :: (IsContent c) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW -> IO ()
instance Network.Riak.Value.IsContent a => Network.Riak.Value.IsContent (Network.Riak.Resolvable.Internal.ResolvableMonoid a)
instance Network.Riak.Value.IsContent Network.Riak.Protocol.Content.Content
instance Network.Riak.Value.IsContent ()
instance Network.Riak.Value.IsContent Data.Aeson.Types.Internal.Value


-- | This module allows storage and retrieval of JSON-encoded data.
--   
--   The functions in this module do not perform any conflict resolution.
module Network.Riak.JSON
data JSON a

-- | Wrap up a value so that it will be encoded and decoded as JSON when
--   converted to/from <tt>Content</tt>.
json :: a -> JSON a

-- | Unwrap a <a>JSON</a>-wrapped value.
plain :: JSON a -> a

-- | Retrieve a value. This may return multiple conflicting siblings.
--   Choosing among them is your responsibility.
get :: (FromJSON c, ToJSON c) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> IO (Maybe ([c], VClock))
getMany :: (FromJSON c, ToJSON c) => Connection -> Maybe BucketType -> Bucket -> [Key] -> R -> IO [Maybe ([c], VClock)]

-- | Store a single value. This may return multiple conflicting siblings.
--   Choosing among them, and storing a new value, is your responsibility.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored.
put :: (FromJSON c, ToJSON c) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> c -> W -> DW -> IO ([c], VClock)

-- | Store a single value indexed.
putIndexed :: (FromJSON c, ToJSON c) => Connection -> Maybe BucketType -> Bucket -> Key -> [IndexValue] -> Maybe VClock -> c -> W -> DW -> IO ([c], VClock)

-- | Store a single value, without the possibility of conflict resolution.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored, and you will not be notified.
put_ :: (FromJSON c, ToJSON c) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> c -> W -> DW -> IO ()

-- | Store many values. This may return multiple conflicting siblings for
--   each value stored. Choosing among them, and storing a new value in
--   each case, is your responsibility.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored.
putMany :: (FromJSON c, ToJSON c) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW -> IO [([c], VClock)]

-- | Store many values, without the possibility of conflict resolution.
--   
--   You should <i>only</i> supply <a>Nothing</a> as a <a>VClock</a> if you
--   are sure that the given type+bucket+key combination does not already
--   exist. If you omit a <a>VClock</a> but the type+bucket+key <i>does</i>
--   exist, your value will not be stored, and you will not be notified.
putMany_ :: (FromJSON c, ToJSON c) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW -> IO ()
instance GHC.Base.Monoid a => GHC.Base.Monoid (Network.Riak.JSON.JSON a)
instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Network.Riak.JSON.JSON a)
instance GHC.Enum.Bounded a => GHC.Enum.Bounded (Network.Riak.JSON.JSON a)
instance GHC.Read.Read a => GHC.Read.Read (Network.Riak.JSON.JSON a)
instance GHC.Show.Show a => GHC.Show.Show (Network.Riak.JSON.JSON a)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Network.Riak.JSON.JSON a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Network.Riak.JSON.JSON a)
instance GHC.Base.Functor Network.Riak.JSON.JSON
instance (Data.Aeson.Types.FromJSON.FromJSON a, Data.Aeson.Types.ToJSON.ToJSON a) => Network.Riak.Value.IsContent (Network.Riak.JSON.JSON a)


-- | This module allows storage and retrieval of JSON-encoded data.
--   
--   Functions automatically resolve conflicts using <a>Resolvable</a>
--   instances. For instance, if a <a>get</a> returns three siblings, a
--   winner will be chosen using <a>resolve</a>. If a <a>put</a> results in
--   a conflict, a winner will be chosen using <a>resolve</a>, and the
--   winner will be <a>put</a>; this will be repeated until either no
--   conflict occurs or the process has been repeated too many times.
module Network.Riak.JSON.Resolvable

-- | A type that can automatically resolve a vector clock conflict between
--   two or more versions of a value.
--   
--   Instances must be symmetric in their behaviour, such that the
--   following law is obeyed:
--   
--   <pre>
--   resolve a b == resolve b a
--   </pre>
--   
--   Otherwise, there are no restrictions on the behaviour of
--   <a>resolve</a>. The result may be <tt>a</tt>, <tt>b</tt>, a value
--   derived from <tt>a</tt> and <tt>b</tt>, or something else.
--   
--   If several conflicting siblings are found, <a>resolve</a> will be
--   applied over all of them using a fold, to yield a single "winner".
class (Show a) => Resolvable a

-- | Resolve a conflict between two values.
resolve :: Resolvable a => a -> a -> a

-- | Automated conflict resolution failed.
data ResolutionFailure

-- | Too many attempts were made to resolve a conflict, with each attempt
--   resulting in another conflict.
--   
--   The number of retries that the library will attempt is high (64). This
--   makes it extremely unlikely that this exception will be thrown during
--   normal application operation. Instead, this exception is most likely
--   to be thrown as a result of a bug in your application code, for
--   example if your <a>resolve</a> function is misbehaving.
RetriesExceeded :: ResolutionFailure

-- | Retrieve a single value. If conflicting values are returned,
--   <a>resolve</a> is used to choose a winner.
get :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> IO (Maybe (c, VClock))

-- | Retrieve multiple values. If conflicting values are returned for a
--   key, <a>resolve</a> is used to choose a winner.
getMany :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> [Key] -> R -> IO [Maybe (c, VClock)]

-- | Modify a single value. The value, if any, is retrieved using
--   <a>get</a>; conflict resolution is performed if necessary. The
--   modification function is called on the resulting value, and its result
--   is stored using <a>put</a>, which may again perform conflict
--   resolution.
--   
--   The result of this function is whatever was returned by <a>put</a>,
--   along with the auxiliary value returned by the modification function.
--   
--   If the <a>put</a> phase of this function gives up due to apparently
--   being stuck in a conflict resolution loop, it will throw a
--   <a>ResolutionFailure</a> exception.
modify :: (FromJSON a, ToJSON a, Resolvable a) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> W -> DW -> (Maybe a -> IO (a, b)) -> IO (a, b)

-- | Modify a single value. The value, if any, is retrieved using
--   <a>get</a>; conflict resolution is performed if necessary. The
--   modification function is called on the resulting value, and its result
--   is stored using <a>put</a>, which may again perform conflict
--   resolution.
--   
--   The result of this function is whatever was returned by <a>put</a>.
--   
--   If the <a>put</a> phase of this function gives up due to apparently
--   being stuck in a conflict resolution loop, it will throw a
--   <a>ResolutionFailure</a> exception.
modify_ :: (MonadIO m, FromJSON a, ToJSON a, Resolvable a) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> W -> DW -> (Maybe a -> m a) -> m a

-- | Store a single value, automatically resolving any vector clock
--   conflicts that arise. A single invocation of this function may involve
--   several roundtrips to the server to resolve conflicts.
--   
--   If a conflict arises, a winner will be chosen using <a>resolve</a>,
--   and the winner will be stored; this will be repeated until no conflict
--   occurs or a (fairly large) number of retries has been attempted
--   without success.
--   
--   If this function gives up due to apparently being stuck in a conflict
--   resolution loop, it will throw a <a>ResolutionFailure</a> exception.
put :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> c -> W -> DW -> IO (c, VClock)

-- | Store a single value indexed.
putIndexed :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> Key -> [IndexValue] -> Maybe VClock -> c -> W -> DW -> IO (c, VClock)

-- | Store a single value, automatically resolving any vector clock
--   conflicts that arise. A single invocation of this function may involve
--   several roundtrips to the server to resolve conflicts.
--   
--   If a conflict arises, a winner will be chosen using <a>resolve</a>,
--   and the winner will be stored; this will be repeated until no conflict
--   occurs or a (fairly large) number of retries has been attempted
--   without success.
--   
--   If this function gives up due to apparently being stuck in a conflict
--   resolution loop, it will throw a <a>ResolutionFailure</a> exception.
put_ :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> c -> W -> DW -> IO ()

-- | Store multiple values, resolving any vector clock conflicts that
--   arise. A single invocation of this function may involve several
--   roundtrips to the server to resolve conflicts.
--   
--   If any conflicts arise, a winner will be chosen in each case using
--   <a>resolve</a>, and the winners will be stored; this will be repeated
--   until either no conflicts occur or a (fairly large) number of retries
--   has been attempted without success.
--   
--   For each original value to be stored, the final value that was stored
--   at the end of any conflict resolution is returned.
--   
--   If this function gives up due to apparently being stuck in a loop, it
--   will throw a <a>ResolutionFailure</a> exception.
putMany :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW -> IO [(c, VClock)]

-- | Store multiple values, resolving any vector clock conflicts that
--   arise. A single invocation of this function may involve several
--   roundtrips to the server to resolve conflicts.
--   
--   If any conflicts arise, a winner will be chosen in each case using
--   <a>resolve</a>, and the winners will be stored; this will be repeated
--   until either no conflicts occur or a (fairly large) number of retries
--   has been attempted without success.
--   
--   If this function gives up due to apparently being stuck in a loop, it
--   will throw a <a>ResolutionFailure</a> exception.
putMany_ :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW -> IO ()


-- | A client for the Riak decentralized data store.
--   
--   The functions in this module use JSON as the storage representation,
--   and automatically perform conflict resolution during storage and
--   retrieval.
--   
--   This library is organized to allow a tradeoff between power and ease
--   of use. If you would like a different degree of automation with
--   storage and conflict resolution, you may want to use one of the
--   following modules (ranked from easiest to most tricky to use):
--   
--   <ul>
--   <li><i>Network.Riak.JSON.Resolvable</i> JSON for storage, automatic
--   conflict resolution. (This module actually re-exports its
--   definitions.) This is the easiest module to work with.</li>
--   <li><i>Network.Riak.JSON</i> JSON for storage, manual conflict
--   resolution.</li>
--   <li><i>Network.Riak.Value.Resolvable</i> More complex (but still
--   automatic) storage, automatic conflict resolution.</li>
--   <li><i>Network.Riak.Value</i> More complex (but still automatic)
--   storage, manual conflict resolution.</li>
--   <li><i>Network.Riak.Basic</i> manual storage, manual conflict
--   resolution. This is the most demanding module to work with, as you
--   must encode and decode data yourself, and handle all conflict
--   resolution yourself.</li>
--   <li><i>Network.Riak.CRDT</i> CRDT operations.</li>
--   </ul>
--   
--   A short getting started guide is available at
--   <a>http://docs.basho.com/riak/latest/dev/taste-of-riak/haskell/</a>
module Network.Riak

-- | A client identifier. This is used by the Riak cluster when logging
--   vector clock changes, and should be unique for each client.
type ClientID = ByteString
data Client
Client :: HostName -> ServiceName -> ClientID -> Client

-- | Name of the server to connect to.
[host] :: Client -> HostName

-- | Port number to connect to (default is 8087).
[port] :: Client -> ServiceName

-- | Client identifier.
[clientID] :: Client -> ClientID

-- | Default client configuration. Talks to localhost, port 8087, with a
--   randomly chosen client ID.
defaultClient :: Client

-- | Find out from the server what client ID this connection is using.
getClientID :: Connection -> IO ClientID

-- | A connection to a Riak server.
data Connection
Connection :: Socket -> Client -> IORef ByteString -> Connection
[connSock] :: Connection -> Socket

-- | The configuration we connected with.
[connClient] :: Connection -> Client

-- | Received data that has not yet been consumed.
[connBuffer] :: Connection -> IORef ByteString

-- | Connect to a server.
connect :: Client -> IO Connection

-- | Disconnect from a server.
disconnect :: Connection -> IO ()

-- | Check to see if the connection to the server is alive.
ping :: Connection -> IO ()

-- | Retrieve information about the server.
getServerInfo :: Connection -> IO ServerInfo

-- | A read/write quorum. The quantity of replicas that must respond to a
--   read or write request before it is considered successful. This is
--   defined as a bucket property or as one of the relevant parameters to a
--   single request (<a>R</a>,<a>W</a>,<a>DW</a>,<a>RW</a>).
data Quorum

-- | Use the default quorum settings for the bucket.
Default :: Quorum

-- | Success after one server has responded.
One :: Quorum

-- | Success after a quorum of servers has responded.
Quorum :: Quorum

-- | Success after all servers have responded.
All :: Quorum

-- | A type that can automatically resolve a vector clock conflict between
--   two or more versions of a value.
--   
--   Instances must be symmetric in their behaviour, such that the
--   following law is obeyed:
--   
--   <pre>
--   resolve a b == resolve b a
--   </pre>
--   
--   Otherwise, there are no restrictions on the behaviour of
--   <a>resolve</a>. The result may be <tt>a</tt>, <tt>b</tt>, a value
--   derived from <tt>a</tt> and <tt>b</tt>, or something else.
--   
--   If several conflicting siblings are found, <a>resolve</a> will be
--   applied over all of them using a fold, to yield a single "winner".
class (Show a) => Resolvable a

-- | Resolve a conflict between two values.
resolve :: Resolvable a => a -> a -> a

-- | Retrieve a single value. If conflicting values are returned,
--   <a>resolve</a> is used to choose a winner.
get :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> IO (Maybe (c, VClock))

-- | Retrieve multiple values. If conflicting values are returned for a
--   key, <a>resolve</a> is used to choose a winner.
getMany :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> [Key] -> R -> IO [Maybe (c, VClock)]

-- | Retrieve list of keys matching some index query.
getByIndex :: Connection -> Bucket -> IndexQuery -> IO [Key]

-- | Add indexes to a content value for a further put request.
addIndexes :: [IndexValue] -> Content -> Content

-- | Modify a single value. The value, if any, is retrieved using
--   <a>get</a>; conflict resolution is performed if necessary. The
--   modification function is called on the resulting value, and its result
--   is stored using <a>put</a>, which may again perform conflict
--   resolution.
--   
--   The result of this function is whatever was returned by <a>put</a>,
--   along with the auxiliary value returned by the modification function.
--   
--   If the <a>put</a> phase of this function gives up due to apparently
--   being stuck in a conflict resolution loop, it will throw a
--   <a>ResolutionFailure</a> exception.
modify :: (FromJSON a, ToJSON a, Resolvable a) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> W -> DW -> (Maybe a -> IO (a, b)) -> IO (a, b)

-- | Modify a single value. The value, if any, is retrieved using
--   <a>get</a>; conflict resolution is performed if necessary. The
--   modification function is called on the resulting value, and its result
--   is stored using <a>put</a>, which may again perform conflict
--   resolution.
--   
--   The result of this function is whatever was returned by <a>put</a>.
--   
--   If the <a>put</a> phase of this function gives up due to apparently
--   being stuck in a conflict resolution loop, it will throw a
--   <a>ResolutionFailure</a> exception.
modify_ :: (MonadIO m, FromJSON a, ToJSON a, Resolvable a) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> W -> DW -> (Maybe a -> m a) -> m a

-- | Delete a value.
delete :: Connection -> Maybe BucketType -> Bucket -> Key -> RW -> IO ()

-- | Store a single value, automatically resolving any vector clock
--   conflicts that arise. A single invocation of this function may involve
--   several roundtrips to the server to resolve conflicts.
--   
--   If a conflict arises, a winner will be chosen using <a>resolve</a>,
--   and the winner will be stored; this will be repeated until no conflict
--   occurs or a (fairly large) number of retries has been attempted
--   without success.
--   
--   If this function gives up due to apparently being stuck in a conflict
--   resolution loop, it will throw a <a>ResolutionFailure</a> exception.
put :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> c -> W -> DW -> IO (c, VClock)

-- | Store a single value indexed.
putIndexed :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> Key -> [IndexValue] -> Maybe VClock -> c -> W -> DW -> IO (c, VClock)

-- | Store multiple values, resolving any vector clock conflicts that
--   arise. A single invocation of this function may involve several
--   roundtrips to the server to resolve conflicts.
--   
--   If any conflicts arise, a winner will be chosen in each case using
--   <a>resolve</a>, and the winners will be stored; this will be repeated
--   until either no conflicts occur or a (fairly large) number of retries
--   has been attempted without success.
--   
--   For each original value to be stored, the final value that was stored
--   at the end of any conflict resolution is returned.
--   
--   If this function gives up due to apparently being stuck in a loop, it
--   will throw a <a>ResolutionFailure</a> exception.
putMany :: (FromJSON c, ToJSON c, Resolvable c) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, c)] -> W -> DW -> IO [(c, VClock)]

-- | List the buckets in the cluster.
--   
--   <i>Note</i>: this operation is expensive. Do not use it in production.
listBuckets :: Connection -> Maybe BucketType -> IO (Seq Bucket)

-- | Fold over the keys in a bucket.
--   
--   <i>Note</i>: this operation is expensive. Do not use it in production.
foldKeys :: (MonadIO m) => Connection -> Maybe BucketType -> Bucket -> (a -> Key -> m a) -> a -> m a

-- | Retrieve the properties of a bucket.
getBucket :: Connection -> Maybe BucketType -> Bucket -> IO BucketProps

-- | Store new properties for a bucket.
setBucket :: Connection -> Maybe BucketType -> Bucket -> BucketProps -> IO ()

-- | Run a <a>MapReduce</a> job. Its result is consumed via a strict left
--   fold.
mapReduce :: Connection -> Job -> (a -> MapReduce -> a) -> a -> IO a

-- | Index query. Can be exact or range, int or bin. Index name should not
--   contain the "_bin" or "_int" part, since it's determined from data
--   constructor.
data IndexQuery
IndexQueryExactInt :: !Index -> !Int -> IndexQuery
IndexQueryExactBin :: !Index -> !ByteString -> IndexQuery
IndexQueryRangeInt :: !Index -> !Int -> !Int -> IndexQuery
IndexQueryRangeBin :: !Index -> !ByteString -> !ByteString -> IndexQuery
data IndexValue
IndexInt :: !Index -> !Int -> IndexValue
IndexBin :: !Index -> !ByteString -> IndexValue


-- | A high-performance striped pooling abstraction for managing
--   connections to a Riak cluster. This is a thin wrapper around
--   <a>Pool</a>.
module Network.Riak.Connection.Pool

-- | A pool of connections to a Riak server.
--   
--   This pool is "striped", i.e. it consists of several sub-pools that are
--   managed independently.
--   
--   The total number of connections that can possibly be open at once is
--   <a>maxConnections</a> * <a>numStripes</a>.
data Pool

-- | Client specification. The client ID is ignored, and always regenerated
--   automatically for each new connection.
client :: Pool -> Client

-- | Create a new connection pool.
create :: Client -> Int -> NominalDiffTime -> Int -> IO Pool

-- | Amount of time for which an unused connection is kept open. The
--   smallest acceptable value is 0.5 seconds.
--   
--   The elapsed time before closing may be a little longer than requested,
--   as the reaper thread wakes at 1-second intervals.
idleTime :: Pool -> NominalDiffTime

-- | Maximum number of connections to keep open per stripe. The smallest
--   acceptable value is 1.
--   
--   Requests for connections will block if this limit is reached on a
--   single stripe, even if other stripes have idle connections available.
maxConnections :: Pool -> Int

-- | Stripe count. The number of distinct sub-pools to maintain. The
--   smallest acceptable value is 1.
numStripes :: Pool -> Int

-- | Temporarily take a connection from a <a>Pool</a>, perform an action
--   with it, and return it to the pool afterwards.
--   
--   <ul>
--   <li>If the pool has a connection available, it is used
--   immediately.</li>
--   <li>Otherwise, if the maximum number of connections has not been
--   reached, a new connection is created and used.</li>
--   <li>If the maximum number of connections has been reached, this
--   function blocks until a connection becomes available, then that
--   connection is used.</li>
--   </ul>
--   
--   If the action throws an exception of any type, the <a>Connection</a>
--   is destroyed, and not returned to the pool.
--   
--   It probably goes without saying that you should never call
--   <a>disconnect</a> on a connection, as doing so will cause a subsequent
--   user (who expects the connection to be valid) to throw an exception.
withConnection :: Pool -> (Connection -> IO a) -> IO a

-- | Temporarily take a connection from a <a>Pool</a>, perform an action
--   with it, and return it to the pool afterwards. This is a
--   generalization of <a>withConnection</a>, which remains specialized to
--   prevent breaking source compatibility with existing code.
--   
--   <ul>
--   <li>If the pool has a connection available, it is used
--   immediately.</li>
--   <li>Otherwise, if the maximum number of connections has not been
--   reached, a new connection is created and used.</li>
--   <li>If the maximum number of connections has been reached, this
--   function blocks until a connection becomes available, then that
--   connection is used.</li>
--   </ul>
--   
--   If the action throws an exception of any type, the <a>Connection</a>
--   is destroyed, and not returned to the pool.
--   
--   It probably goes without saying that you should never call
--   <a>disconnect</a> on a connection, as doing so will cause a subsequent
--   user (who expects the connection to be valid) to throw an exception.
withConnectionM :: MonadBaseControl IO m => Pool -> (Connection -> m a) -> m a
instance GHC.Show.Show Network.Riak.Connection.Pool.Pool
instance GHC.Classes.Eq Network.Riak.Connection.Pool.Pool

module Network.Riak.Cluster

-- | Datatype holding connection-pool with all known cluster nodes
data Cluster
Cluster :: [Pool] -> TMVar PureMT -> Cluster

-- | Vector of connection pools to riak cluster nodes
[clusterPools] :: Cluster -> [Pool]
[clusterGen] :: Cluster -> TMVar PureMT

-- | Error that gets thrown whenever operation couldn't succeed with any
--   node.
data InClusterError
InClusterError :: [SomeException] -> InClusterError

-- | Function to connect to riak cluster with sane pool defaults
connectToCluster :: [Client] -> IO Cluster

-- | Tries to run some operation for a random riak node. If it fails, tries
--   all other nodes. If all other nodes fail - throws
--   <a>InClusterError</a> exception.
inCluster :: (MonadThrow m, MonadBaseControl IO m) => Cluster -> (Connection -> m a) -> m a

-- | Create a new connection pool.
create :: Client -> Int -> NominalDiffTime -> Int -> IO Pool

-- | Default client configuration. Talks to localhost, port 8087, with a
--   randomly chosen client ID.
defaultClient :: Client
instance GHC.Show.Show Network.Riak.Cluster.InClusterError
instance GHC.Exception.Exception Network.Riak.Cluster.InClusterError


-- | This module allows storage and retrieval of data encoded using the
--   <a>IsContent</a> typeclass. This provides access to more of Riak's
--   storage features than JSON, e.g. links.
--   
--   Functions automatically resolve conflicts using <a>Resolvable</a>
--   instances. For instance, if a <a>get</a> returns three siblings, a
--   winner will be chosen using <a>resolve</a>. If a <a>put</a> results in
--   a conflict, a winner will be chosen using <a>resolve</a>, and the
--   winner will be <a>put</a>; this will be repeated until either no
--   conflict occurs or the process has been repeated too many times.
module Network.Riak.Value.Resolvable
class IsContent c
parseContent :: IsContent c => Content -> Parser c
toContent :: IsContent c => c -> Content

-- | A type that can automatically resolve a vector clock conflict between
--   two or more versions of a value.
--   
--   Instances must be symmetric in their behaviour, such that the
--   following law is obeyed:
--   
--   <pre>
--   resolve a b == resolve b a
--   </pre>
--   
--   Otherwise, there are no restrictions on the behaviour of
--   <a>resolve</a>. The result may be <tt>a</tt>, <tt>b</tt>, a value
--   derived from <tt>a</tt> and <tt>b</tt>, or something else.
--   
--   If several conflicting siblings are found, <a>resolve</a> will be
--   applied over all of them using a fold, to yield a single "winner".
class (Show a) => Resolvable a

-- | Resolve a conflict between two values.
resolve :: Resolvable a => a -> a -> a

-- | Automated conflict resolution failed.
data ResolutionFailure

-- | Too many attempts were made to resolve a conflict, with each attempt
--   resulting in another conflict.
--   
--   The number of retries that the library will attempt is high (64). This
--   makes it extremely unlikely that this exception will be thrown during
--   normal application operation. Instead, this exception is most likely
--   to be thrown as a result of a bug in your application code, for
--   example if your <a>resolve</a> function is misbehaving.
RetriesExceeded :: ResolutionFailure

-- | Retrieve a single value. If conflicting values are returned, the
--   <a>Resolvable</a> is used to choose a winner.
get :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> IO (Maybe (a, VClock))

-- | Retrieve multiple values. If conflicting values are returned for a
--   key, the <a>Resolvable</a> is used to choose a winner.
getMany :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> [Key] -> R -> IO [Maybe (a, VClock)]

-- | Modify a single value. The value, if any, is retrieved using
--   <a>get</a>; conflict resolution is performed if necessary. The
--   modification function is called on the resulting value, and its result
--   is stored using <a>put</a>, which may again perform conflict
--   resolution.
--   
--   The result of this function is whatever was returned by <a>put</a>,
--   along with the auxiliary value returned by the modification function.
--   
--   If the <a>put</a> phase of this function gives up due to apparently
--   being stuck in a conflict resolution loop, it will throw a
--   <a>ResolutionFailure</a> exception.
modify :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> W -> DW -> (Maybe a -> IO (a, b)) -> IO (a, b)

-- | Modify a single value. The value, if any, is retrieved using
--   <a>get</a>; conflict resolution is performed if necessary. The
--   modification function is called on the resulting value, and its result
--   is stored using <a>put</a>, which may again perform conflict
--   resolution.
--   
--   The result of this function is whatever was returned by <a>put</a>.
--   
--   If the <a>put</a> phase of this function gives up due to apparently
--   being stuck in a conflict resolution loop, it will throw a
--   <a>ResolutionFailure</a> exception.
modify_ :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> Key -> R -> W -> DW -> (Maybe a -> IO a) -> IO a

-- | Store a single value, automatically resolving any vector clock
--   conflicts that arise. A single invocation of this function may involve
--   several roundtrips to the server to resolve conflicts.
--   
--   If a conflict arises, a winner will be chosen using <a>resolve</a>,
--   and the winner will be stored; this will be repeated until no conflict
--   occurs or a (fairly large) number of retries has been attempted
--   without success.
--   
--   If this function gives up due to apparently being stuck in a conflict
--   resolution loop, it will throw a <a>ResolutionFailure</a> exception.
put :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> a -> W -> DW -> IO (a, VClock)

-- | Store a single value, automatically resolving any vector clock
--   conflicts that arise. A single invocation of this function may involve
--   several roundtrips to the server to resolve conflicts.
--   
--   If a conflict arises, a winner will be chosen using <a>resolve</a>,
--   and the winner will be stored; this will be repeated until no conflict
--   occurs or a (fairly large) number of retries has been attempted
--   without success.
--   
--   If this function gives up due to apparently being stuck in a conflict
--   resolution loop, it will throw a <a>ResolutionFailure</a> exception.
put_ :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> Key -> Maybe VClock -> a -> W -> DW -> IO ()

-- | Store multiple values, resolving any vector clock conflicts that
--   arise. A single invocation of this function may involve several
--   roundtrips to the server to resolve conflicts.
--   
--   If any conflicts arise, a winner will be chosen in each case using
--   <a>resolve</a>, and the winners will be stored; this will be repeated
--   until either no conflicts occur or a (fairly large) number of retries
--   has been attempted without success.
--   
--   For each original value to be stored, the final value that was stored
--   at the end of any conflict resolution is returned.
--   
--   If this function gives up due to apparently being stuck in a loop, it
--   will throw a <a>ResolutionFailure</a> exception.
putMany :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, a)] -> W -> DW -> IO [(a, VClock)]

-- | Store multiple values, resolving any vector clock conflicts that
--   arise. A single invocation of this function may involve several
--   roundtrips to the server to resolve conflicts.
--   
--   If any conflicts arise, a winner will be chosen in each case using
--   <a>resolve</a>, and the winners will be stored; this will be repeated
--   until either no conflicts occur or a (fairly large) number of retries
--   has been attempted without success.
--   
--   If this function gives up due to apparently being stuck in a loop, it
--   will throw a <a>ResolutionFailure</a> exception.
putMany_ :: (Resolvable a, IsContent a) => Connection -> Maybe BucketType -> Bucket -> [(Key, Maybe VClock, a)] -> W -> DW -> IO ()
