{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}

-- |
-- Module:      Network.Riak.Request
-- Copyright:   (c) 2011 MailRank, Inc.
-- License:     Apache
-- Maintainer:  Mark Hibberd <mark@hibberd.id.au>, Nathan Hunter <nhunter@janrain.com>
-- Stability:   experimental
-- Portability: portable
--
-- 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
  ( -- * Connection management
    Proto.RpbPingReq,
    ping,
    Proto.RpbGetClientIdReq,
    getClientID,
    Proto.RpbGetServerInfoReq,
    getServerInfo,

    -- * Data management
    Proto.RpbGetReq,
    get,
    getByIndex,
    Proto.RpbIndexReq,
    Proto.RpbPutReq,
    put,
    Proto.RpbDelReq,
    delete,

    -- * Metadata
    Proto.RpbLink,
    link,
    Proto.RpbListBucketsReq,
    listBuckets,
    Proto.RpbListKeysReq,
    listKeys,
    Proto.RpbGetBucketReq,
    getBucket,
    Proto.RpbSetBucketReq,
    setBucket,
    getBucketType,

    -- * Map/reduce
    Proto.RpbMapRedReq,
    mapReduce,

    -- * Search
    search,
    getIndex,
    putIndex,
    deleteIndex,
  )
where

#if __GLASGOW_HASKELL__ < 710
import Control.Applicative ((<$>))
#endif
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B8
#if __GLASGOW_HASKELL__ < 804
import Data.Monoid
#endif
import qualified Data.Riak.Proto as Proto
import Network.Riak.Escape (escape)
import Network.Riak.Lens
import Network.Riak.Types.Internal hiding (MessageTag (..))

-- | Create a ping request.
ping :: Proto.RpbPingReq
ping :: RpbPingReq
ping = RpbPingReq
forall msg. Message msg => msg
Proto.defMessage
{-# INLINE ping #-}

{-
-- | Create a dtUpdate request.
dtUpdate :: DtUpdate.DtUpdateRequest
dtUpdate = DtUpdate.DtUpdateRequest
{-# INLINE dtUpdate #-}
-}

-- | Create a client-ID request.
getClientID :: Proto.RpbGetClientIdReq
getClientID :: RpbGetClientIdReq
getClientID = RpbGetClientIdReq
forall msg. Message msg => msg
Proto.defMessage
{-# INLINE getClientID #-}

-- | Create a server-info request.
getServerInfo :: Proto.RpbGetServerInfoReq
getServerInfo :: RpbGetServerInfoReq
getServerInfo = RpbGetServerInfoReq
forall msg. Message msg => msg
Proto.defMessage
{-# INLINE getServerInfo #-}

-- | Create a get request.  The bucket and key names are URL-escaped.
get :: Maybe BucketType -> Bucket -> Key -> R -> Proto.RpbGetReq
get :: Maybe BucketType -> BucketType -> BucketType -> R -> RpbGetReq
get Maybe BucketType
btype BucketType
bucket BucketType
key R
r =
  RpbGetReq
forall msg. Message msg => msg
Proto.defMessage
    RpbGetReq -> (RpbGetReq -> RpbGetReq) -> RpbGetReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbGetReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbGetReq BucketType
-> BucketType -> RpbGetReq -> RpbGetReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
bucket
    RpbGetReq -> (RpbGetReq -> RpbGetReq) -> RpbGetReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbGetReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "key" a) =>
LensLike' f s a
Proto.key LensLike' Identity RpbGetReq BucketType
-> BucketType -> RpbGetReq -> RpbGetReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
key
    RpbGetReq -> (RpbGetReq -> RpbGetReq) -> RpbGetReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbGetReq (Maybe Word32)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'r" a) =>
LensLike' f s a
Proto.maybe'r LensLike' Identity RpbGetReq (Maybe Word32)
-> Maybe Word32 -> RpbGetReq -> RpbGetReq
forall s a. Setter s a -> a -> s -> s
.~ R -> Maybe Word32
fromQuorum R
r
    RpbGetReq -> (RpbGetReq -> RpbGetReq) -> RpbGetReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbGetReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'type'" a) =>
LensLike' f s a
Proto.maybe'type' LensLike' Identity RpbGetReq (Maybe BucketType)
-> Maybe BucketType -> RpbGetReq -> RpbGetReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
btype -- no escaping intentional
    -- TODO don't escape anything
{-# INLINE get #-}

-- | Create a secondary index request. Bucket, key and index names and
-- values are URL-escaped.
getByIndex ::
  Bucket ->
  IndexQuery ->
  Proto.RpbIndexReq
getByIndex :: BucketType -> IndexQuery -> RpbIndexReq
getByIndex BucketType
bucket IndexQuery
q =
  case IndexQuery
q of
    IndexQueryExactInt BucketType
index Int
key ->
      BucketType
-> Maybe BucketType
-> RpbIndexReq'IndexQueryType
-> Maybe BucketType
-> Maybe BucketType
-> RpbIndexReq
req
        (BucketType
index BucketType -> BucketType -> BucketType
forall a. Semigroup a => a -> a -> a
<> BucketType
"_int")
        (Int -> Maybe BucketType
showIntKey Int
key)
        RpbIndexReq'IndexQueryType
Proto.RpbIndexReq'Eq
        Maybe BucketType
forall a. Maybe a
Nothing
        Maybe BucketType
forall a. Maybe a
Nothing
    IndexQueryExactBin BucketType
index BucketType
key ->
      BucketType
-> Maybe BucketType
-> RpbIndexReq'IndexQueryType
-> Maybe BucketType
-> Maybe BucketType
-> RpbIndexReq
req
        (BucketType
index BucketType -> BucketType -> BucketType
forall a. Semigroup a => a -> a -> a
<> BucketType
"_bin")
        (BucketType -> Maybe BucketType
showBsKey (BucketType -> Maybe BucketType) -> BucketType -> Maybe BucketType
forall a b. (a -> b) -> a -> b
$ BucketType
key)
        RpbIndexReq'IndexQueryType
Proto.RpbIndexReq'Eq
        Maybe BucketType
forall a. Maybe a
Nothing
        Maybe BucketType
forall a. Maybe a
Nothing
    IndexQueryRangeInt BucketType
index Int
from Int
to ->
      BucketType
-> Maybe BucketType
-> RpbIndexReq'IndexQueryType
-> Maybe BucketType
-> Maybe BucketType
-> RpbIndexReq
req
        (BucketType
index BucketType -> BucketType -> BucketType
forall a. Semigroup a => a -> a -> a
<> BucketType
"_int")
        Maybe BucketType
forall a. Maybe a
Nothing
        RpbIndexReq'IndexQueryType
Proto.RpbIndexReq'Range
        (Int -> Maybe BucketType
showIntKey Int
from)
        (Int -> Maybe BucketType
showIntKey Int
to)
    IndexQueryRangeBin BucketType
index BucketType
from BucketType
to ->
      BucketType
-> Maybe BucketType
-> RpbIndexReq'IndexQueryType
-> Maybe BucketType
-> Maybe BucketType
-> RpbIndexReq
req
        (BucketType
index BucketType -> BucketType -> BucketType
forall a. Semigroup a => a -> a -> a
<> BucketType
"_bin")
        Maybe BucketType
forall a. Maybe a
Nothing
        RpbIndexReq'IndexQueryType
Proto.RpbIndexReq'Range
        (BucketType -> Maybe BucketType
showBsKey BucketType
from)
        (BucketType -> Maybe BucketType
showBsKey BucketType
to)
  where
    showIntKey :: Int -> Maybe BucketType
showIntKey = BucketType -> Maybe BucketType
forall a. a -> Maybe a
Just (BucketType -> Maybe BucketType)
-> (Int -> BucketType) -> Int -> Maybe BucketType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape (BucketType -> BucketType)
-> (Int -> BucketType) -> Int -> BucketType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> BucketType
B8.pack (String -> BucketType) -> (Int -> String) -> Int -> BucketType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show
    showBsKey :: BucketType -> Maybe BucketType
showBsKey = BucketType -> Maybe BucketType
forall a. a -> Maybe a
Just (BucketType -> Maybe BucketType)
-> (BucketType -> BucketType) -> BucketType -> Maybe BucketType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape
    req ::
      ByteString ->
      Maybe ByteString ->
      Proto.RpbIndexReq'IndexQueryType ->
      Maybe ByteString ->
      Maybe ByteString ->
      Proto.RpbIndexReq
    req :: BucketType
-> Maybe BucketType
-> RpbIndexReq'IndexQueryType
-> Maybe BucketType
-> Maybe BucketType
-> RpbIndexReq
req BucketType
i Maybe BucketType
k RpbIndexReq'IndexQueryType
qt Maybe BucketType
rmin Maybe BucketType
rmax =
      RpbIndexReq
forall msg. Message msg => msg
Proto.defMessage
        RpbIndexReq -> (RpbIndexReq -> RpbIndexReq) -> RpbIndexReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbIndexReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbIndexReq BucketType
-> BucketType -> RpbIndexReq -> RpbIndexReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
bucket
        RpbIndexReq -> (RpbIndexReq -> RpbIndexReq) -> RpbIndexReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbIndexReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "index" a) =>
LensLike' f s a
Proto.index LensLike' Identity RpbIndexReq BucketType
-> BucketType -> RpbIndexReq -> RpbIndexReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
i
        RpbIndexReq -> (RpbIndexReq -> RpbIndexReq) -> RpbIndexReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbIndexReq RpbIndexReq'IndexQueryType
forall (f :: * -> *) s a.
(Functor f, HasField s "qtype" a) =>
LensLike' f s a
Proto.qtype LensLike' Identity RpbIndexReq RpbIndexReq'IndexQueryType
-> RpbIndexReq'IndexQueryType -> RpbIndexReq -> RpbIndexReq
forall s a. Setter s a -> a -> s -> s
.~ RpbIndexReq'IndexQueryType
qt
        RpbIndexReq -> (RpbIndexReq -> RpbIndexReq) -> RpbIndexReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbIndexReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'key" a) =>
LensLike' f s a
Proto.maybe'key LensLike' Identity RpbIndexReq (Maybe BucketType)
-> Maybe BucketType -> RpbIndexReq -> RpbIndexReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
k
        RpbIndexReq -> (RpbIndexReq -> RpbIndexReq) -> RpbIndexReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbIndexReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'rangeMin" a) =>
LensLike' f s a
Proto.maybe'rangeMin LensLike' Identity RpbIndexReq (Maybe BucketType)
-> Maybe BucketType -> RpbIndexReq -> RpbIndexReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
rmin
        RpbIndexReq -> (RpbIndexReq -> RpbIndexReq) -> RpbIndexReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbIndexReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'rangeMax" a) =>
LensLike' f s a
Proto.maybe'rangeMax LensLike' Identity RpbIndexReq (Maybe BucketType)
-> Maybe BucketType -> RpbIndexReq -> RpbIndexReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
rmax

-- | Create a put request.  The bucket and key names are URL-escaped.
-- Any 'Link' values inside the 'Content' are assumed to have been
-- constructed with the 'link' function, and hence /not/ escaped.
put ::
  Maybe BucketType ->
  Bucket ->
  Key ->
  Maybe VClock ->
  Proto.RpbContent ->
  W ->
  DW ->
  Bool ->
  Proto.RpbPutReq
put :: Maybe BucketType
-> BucketType
-> BucketType
-> Maybe VClock
-> RpbContent
-> R
-> R
-> Bool
-> RpbPutReq
put Maybe BucketType
btype BucketType
bucket BucketType
key Maybe VClock
mvclock RpbContent
cont R
mw R
mdw Bool
returnBody =
  RpbPutReq
forall msg. Message msg => msg
Proto.defMessage
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbPutReq BucketType
-> BucketType -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
bucket
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "key" a) =>
LensLike' f s a
Proto.key LensLike' Identity RpbPutReq BucketType
-> BucketType -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
key
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'vclock" a) =>
LensLike' f s a
Proto.maybe'vclock LensLike' Identity RpbPutReq (Maybe BucketType)
-> Maybe BucketType -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ (VClock -> BucketType
fromVClock (VClock -> BucketType) -> Maybe VClock -> Maybe BucketType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe VClock
mvclock)
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq RpbContent
forall (f :: * -> *) s a.
(Functor f, HasField s "content" a) =>
LensLike' f s a
Proto.content LensLike' Identity RpbPutReq RpbContent
-> RpbContent -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ RpbContent
cont
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq (Maybe Word32)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'w" a) =>
LensLike' f s a
Proto.maybe'w LensLike' Identity RpbPutReq (Maybe Word32)
-> Maybe Word32 -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ R -> Maybe Word32
fromQuorum R
mw
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq (Maybe Word32)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'dw" a) =>
LensLike' f s a
Proto.maybe'dw LensLike' Identity RpbPutReq (Maybe Word32)
-> Maybe Word32 -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ R -> Maybe Word32
fromQuorum R
mdw
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq Bool
forall (f :: * -> *) s a.
(Functor f, HasField s "returnBody" a) =>
LensLike' f s a
Proto.returnBody LensLike' Identity RpbPutReq Bool -> Bool -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ Bool
returnBody
    RpbPutReq -> (RpbPutReq -> RpbPutReq) -> RpbPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbPutReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'type'" a) =>
LensLike' f s a
Proto.maybe'type' LensLike' Identity RpbPutReq (Maybe BucketType)
-> Maybe BucketType -> RpbPutReq -> RpbPutReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
btype -- same as get
{-# INLINE put #-}

-- | Create a link.  The bucket and key names are URL-escaped.
link :: Bucket -> Key -> Tag -> Proto.RpbLink
link :: BucketType -> BucketType -> BucketType -> RpbLink
link BucketType
bucket BucketType
key BucketType
tag =
  RpbLink
forall msg. Message msg => msg
Proto.defMessage
    RpbLink -> (RpbLink -> RpbLink) -> RpbLink
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbLink BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbLink BucketType
-> BucketType -> RpbLink -> RpbLink
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
bucket
    RpbLink -> (RpbLink -> RpbLink) -> RpbLink
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbLink BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "key" a) =>
LensLike' f s a
Proto.key LensLike' Identity RpbLink BucketType
-> BucketType -> RpbLink -> RpbLink
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
key
    RpbLink -> (RpbLink -> RpbLink) -> RpbLink
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbLink BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "tag" a) =>
LensLike' f s a
Proto.tag LensLike' Identity RpbLink BucketType
-> BucketType -> RpbLink -> RpbLink
forall s a. Setter s a -> a -> s -> s
.~ BucketType
tag
{-# INLINE link #-}

-- | Create a delete request.  The bucket and key names are URL-escaped.
delete :: Maybe BucketType -> Bucket -> Key -> RW -> Proto.RpbDelReq
delete :: Maybe BucketType -> BucketType -> BucketType -> R -> RpbDelReq
delete Maybe BucketType
btype BucketType
bucket BucketType
key R
rw =
  RpbDelReq
forall msg. Message msg => msg
Proto.defMessage
    RpbDelReq -> (RpbDelReq -> RpbDelReq) -> RpbDelReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbDelReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbDelReq BucketType
-> BucketType -> RpbDelReq -> RpbDelReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
bucket
    RpbDelReq -> (RpbDelReq -> RpbDelReq) -> RpbDelReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbDelReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "key" a) =>
LensLike' f s a
Proto.key LensLike' Identity RpbDelReq BucketType
-> BucketType -> RpbDelReq -> RpbDelReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
key
    RpbDelReq -> (RpbDelReq -> RpbDelReq) -> RpbDelReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbDelReq (Maybe Word32)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'rw" a) =>
LensLike' f s a
Proto.maybe'rw LensLike' Identity RpbDelReq (Maybe Word32)
-> Maybe Word32 -> RpbDelReq -> RpbDelReq
forall s a. Setter s a -> a -> s -> s
.~ R -> Maybe Word32
fromQuorum R
rw
    RpbDelReq -> (RpbDelReq -> RpbDelReq) -> RpbDelReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbDelReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'type'" a) =>
LensLike' f s a
Proto.maybe'type' LensLike' Identity RpbDelReq (Maybe BucketType)
-> Maybe BucketType -> RpbDelReq -> RpbDelReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
btype -- same as get
{-# INLINE delete #-}

-- | Create a list-buckets request.
listBuckets :: Maybe BucketType -> Proto.RpbListBucketsReq
listBuckets :: Maybe BucketType -> RpbListBucketsReq
listBuckets Maybe BucketType
btype = RpbListBucketsReq
forall msg. Message msg => msg
Proto.defMessage RpbListBucketsReq
-> (RpbListBucketsReq -> RpbListBucketsReq) -> RpbListBucketsReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbListBucketsReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'type'" a) =>
LensLike' f s a
Proto.maybe'type' LensLike' Identity RpbListBucketsReq (Maybe BucketType)
-> Maybe BucketType -> RpbListBucketsReq -> RpbListBucketsReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
btype
{-# INLINE listBuckets #-}

-- | Create a list-keys request.  The bucket type and name are URL-escaped.
listKeys :: Maybe BucketType -> Bucket -> Proto.RpbListKeysReq
listKeys :: Maybe BucketType -> BucketType -> RpbListKeysReq
listKeys Maybe BucketType
t BucketType
b =
  RpbListKeysReq
forall msg. Message msg => msg
Proto.defMessage RpbListKeysReq
-> (RpbListKeysReq -> RpbListKeysReq) -> RpbListKeysReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbListKeysReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'type'" a) =>
LensLike' f s a
Proto.maybe'type' LensLike' Identity RpbListKeysReq (Maybe BucketType)
-> Maybe BucketType -> RpbListKeysReq -> RpbListKeysReq
forall s a. Setter s a -> a -> s -> s
.~ (BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape (BucketType -> BucketType) -> Maybe BucketType -> Maybe BucketType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe BucketType
t)
    RpbListKeysReq
-> (RpbListKeysReq -> RpbListKeysReq) -> RpbListKeysReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbListKeysReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbListKeysReq BucketType
-> BucketType -> RpbListKeysReq -> RpbListKeysReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
b
{-# INLINE listKeys #-}

-- | Create a get-bucket request.  The bucket type and name are URL-escaped.
getBucket :: Maybe BucketType -> Bucket -> Proto.RpbGetBucketReq
getBucket :: Maybe BucketType -> BucketType -> RpbGetBucketReq
getBucket Maybe BucketType
t BucketType
b =
  RpbGetBucketReq
forall msg. Message msg => msg
Proto.defMessage RpbGetBucketReq
-> (RpbGetBucketReq -> RpbGetBucketReq) -> RpbGetBucketReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbGetBucketReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'type'" a) =>
LensLike' f s a
Proto.maybe'type' LensLike' Identity RpbGetBucketReq (Maybe BucketType)
-> Maybe BucketType -> RpbGetBucketReq -> RpbGetBucketReq
forall s a. Setter s a -> a -> s -> s
.~ (BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape (BucketType -> BucketType) -> Maybe BucketType -> Maybe BucketType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe BucketType
t)
    RpbGetBucketReq
-> (RpbGetBucketReq -> RpbGetBucketReq) -> RpbGetBucketReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbGetBucketReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbGetBucketReq BucketType
-> BucketType -> RpbGetBucketReq -> RpbGetBucketReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
b
{-# INLINE getBucket #-}

-- | Create a set-bucket request.  The bucket type and name are URL-escaped.
setBucket :: Maybe BucketType -> Bucket -> Proto.RpbBucketProps -> Proto.RpbSetBucketReq
setBucket :: Maybe BucketType -> BucketType -> RpbBucketProps -> RpbSetBucketReq
setBucket Maybe BucketType
t BucketType
b RpbBucketProps
ps =
  RpbSetBucketReq
forall msg. Message msg => msg
Proto.defMessage RpbSetBucketReq
-> (RpbSetBucketReq -> RpbSetBucketReq) -> RpbSetBucketReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbSetBucketReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "bucket" a) =>
LensLike' f s a
Proto.bucket LensLike' Identity RpbSetBucketReq BucketType
-> BucketType -> RpbSetBucketReq -> RpbSetBucketReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
b
    RpbSetBucketReq
-> (RpbSetBucketReq -> RpbSetBucketReq) -> RpbSetBucketReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbSetBucketReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'type'" a) =>
LensLike' f s a
Proto.maybe'type' LensLike' Identity RpbSetBucketReq (Maybe BucketType)
-> Maybe BucketType -> RpbSetBucketReq -> RpbSetBucketReq
forall s a. Setter s a -> a -> s -> s
.~ (BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape (BucketType -> BucketType) -> Maybe BucketType -> Maybe BucketType
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe BucketType
t)
    RpbSetBucketReq
-> (RpbSetBucketReq -> RpbSetBucketReq) -> RpbSetBucketReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbSetBucketReq RpbBucketProps
forall (f :: * -> *) s a.
(Functor f, HasField s "props" a) =>
LensLike' f s a
Proto.props LensLike' Identity RpbSetBucketReq RpbBucketProps
-> RpbBucketProps -> RpbSetBucketReq -> RpbSetBucketReq
forall s a. Setter s a -> a -> s -> s
.~ RpbBucketProps
ps
{-# INLINE setBucket #-}

-- | Create a get-bucket-type request.  The bucket type is URL-escaped.
getBucketType :: BucketType -> Proto.RpbGetBucketTypeReq
getBucketType :: BucketType -> RpbGetBucketTypeReq
getBucketType BucketType
t = RpbGetBucketTypeReq
forall msg. Message msg => msg
Proto.defMessage RpbGetBucketTypeReq
-> (RpbGetBucketTypeReq -> RpbGetBucketTypeReq)
-> RpbGetBucketTypeReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbGetBucketTypeReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "type'" a) =>
LensLike' f s a
Proto.type' LensLike' Identity RpbGetBucketTypeReq BucketType
-> BucketType -> RpbGetBucketTypeReq -> RpbGetBucketTypeReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
t

-- | Create a map-reduce request.
mapReduce :: Job -> Proto.RpbMapRedReq
mapReduce :: Job -> RpbMapRedReq
mapReduce (JSON BucketType
bs) =
  RpbMapRedReq
forall msg. Message msg => msg
Proto.defMessage RpbMapRedReq -> (RpbMapRedReq -> RpbMapRedReq) -> RpbMapRedReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbMapRedReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "request" a) =>
LensLike' f s a
Proto.request LensLike' Identity RpbMapRedReq BucketType
-> BucketType -> RpbMapRedReq -> RpbMapRedReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType
bs
    RpbMapRedReq -> (RpbMapRedReq -> RpbMapRedReq) -> RpbMapRedReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbMapRedReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "contentType" a) =>
LensLike' f s a
Proto.contentType LensLike' Identity RpbMapRedReq BucketType
-> BucketType -> RpbMapRedReq -> RpbMapRedReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType
"application/json"
mapReduce (Erlang BucketType
bs) =
  RpbMapRedReq
forall msg. Message msg => msg
Proto.defMessage RpbMapRedReq -> (RpbMapRedReq -> RpbMapRedReq) -> RpbMapRedReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbMapRedReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "request" a) =>
LensLike' f s a
Proto.request LensLike' Identity RpbMapRedReq BucketType
-> BucketType -> RpbMapRedReq -> RpbMapRedReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType
bs
    RpbMapRedReq -> (RpbMapRedReq -> RpbMapRedReq) -> RpbMapRedReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbMapRedReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "contentType" a) =>
LensLike' f s a
Proto.contentType LensLike' Identity RpbMapRedReq BucketType
-> BucketType -> RpbMapRedReq -> RpbMapRedReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType
"application/x-erlang-binary"

-- | Create a search request
search :: SearchQuery -> Index -> Proto.RpbSearchQueryReq
search :: BucketType -> BucketType -> RpbSearchQueryReq
search BucketType
q BucketType
ix =
  RpbSearchQueryReq
forall msg. Message msg => msg
Proto.defMessage
    RpbSearchQueryReq
-> (RpbSearchQueryReq -> RpbSearchQueryReq) -> RpbSearchQueryReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbSearchQueryReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "q" a) =>
LensLike' f s a
Proto.q LensLike' Identity RpbSearchQueryReq BucketType
-> BucketType -> RpbSearchQueryReq -> RpbSearchQueryReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType
q
    RpbSearchQueryReq
-> (RpbSearchQueryReq -> RpbSearchQueryReq) -> RpbSearchQueryReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbSearchQueryReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "index" a) =>
LensLike' f s a
Proto.index LensLike' Identity RpbSearchQueryReq BucketType
-> BucketType -> RpbSearchQueryReq -> RpbSearchQueryReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType -> BucketType
forall e. Escape e => e -> BucketType
escape BucketType
ix

getIndex :: Maybe Index -> Proto.RpbYokozunaIndexGetReq
getIndex :: Maybe BucketType -> RpbYokozunaIndexGetReq
getIndex Maybe BucketType
ix = RpbYokozunaIndexGetReq
forall msg. Message msg => msg
Proto.defMessage RpbYokozunaIndexGetReq
-> (RpbYokozunaIndexGetReq -> RpbYokozunaIndexGetReq)
-> RpbYokozunaIndexGetReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbYokozunaIndexGetReq (Maybe BucketType)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'name" a) =>
LensLike' f s a
Proto.maybe'name LensLike' Identity RpbYokozunaIndexGetReq (Maybe BucketType)
-> Maybe BucketType
-> RpbYokozunaIndexGetReq
-> RpbYokozunaIndexGetReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe BucketType
ix

putIndex :: IndexInfo -> Maybe Timeout -> Proto.RpbYokozunaIndexPutReq
putIndex :: IndexInfo -> Maybe Word32 -> RpbYokozunaIndexPutReq
putIndex IndexInfo
info Maybe Word32
timeout =
  RpbYokozunaIndexPutReq
forall msg. Message msg => msg
Proto.defMessage
    RpbYokozunaIndexPutReq
-> (RpbYokozunaIndexPutReq -> RpbYokozunaIndexPutReq)
-> RpbYokozunaIndexPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbYokozunaIndexPutReq IndexInfo
forall (f :: * -> *) s a.
(Functor f, HasField s "index" a) =>
LensLike' f s a
Proto.index LensLike' Identity RpbYokozunaIndexPutReq IndexInfo
-> IndexInfo -> RpbYokozunaIndexPutReq -> RpbYokozunaIndexPutReq
forall s a. Setter s a -> a -> s -> s
.~ IndexInfo
info
    RpbYokozunaIndexPutReq
-> (RpbYokozunaIndexPutReq -> RpbYokozunaIndexPutReq)
-> RpbYokozunaIndexPutReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbYokozunaIndexPutReq (Maybe Word32)
forall (f :: * -> *) s a.
(Functor f, HasField s "maybe'timeout" a) =>
LensLike' f s a
Proto.maybe'timeout LensLike' Identity RpbYokozunaIndexPutReq (Maybe Word32)
-> Maybe Word32 -> RpbYokozunaIndexPutReq -> RpbYokozunaIndexPutReq
forall s a. Setter s a -> a -> s -> s
.~ Maybe Word32
timeout

deleteIndex :: Index -> Proto.RpbYokozunaIndexDeleteReq
deleteIndex :: BucketType -> RpbYokozunaIndexDeleteReq
deleteIndex BucketType
ix = RpbYokozunaIndexDeleteReq
forall msg. Message msg => msg
Proto.defMessage RpbYokozunaIndexDeleteReq
-> (RpbYokozunaIndexDeleteReq -> RpbYokozunaIndexDeleteReq)
-> RpbYokozunaIndexDeleteReq
forall a b. a -> (a -> b) -> b
& LensLike' Identity RpbYokozunaIndexDeleteReq BucketType
forall (f :: * -> *) s a.
(Functor f, HasField s "name" a) =>
LensLike' f s a
Proto.name LensLike' Identity RpbYokozunaIndexDeleteReq BucketType
-> BucketType
-> RpbYokozunaIndexDeleteReq
-> RpbYokozunaIndexDeleteReq
forall s a. Setter s a -> a -> s -> s
.~ BucketType
ix