{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies               #-}

module Aws.DynamoDb.Commands.Table
    ( -- * Commands
      CreateTable(..)
    , createTable
    , CreateTableResult(..)
    , DescribeTable(..)
    , DescribeTableResult(..)
    , UpdateTable(..)
    , UpdateTableResult(..)
    , DeleteTable(..)
    , DeleteTableResult(..)
    , ListTables(..)
    , ListTablesResult(..)

    -- * Data passed in the commands
    , AttributeType(..)
    , AttributeDefinition(..)
    , KeySchema(..)
    , Projection(..)
    , LocalSecondaryIndex(..)
    , LocalSecondaryIndexStatus(..)
    , ProvisionedThroughput(..)
    , ProvisionedThroughputStatus(..)
    , GlobalSecondaryIndex(..)
    , GlobalSecondaryIndexStatus(..)
    , GlobalSecondaryIndexUpdate(..)
    , TableDescription(..)
    ) where

-------------------------------------------------------------------------------
import           Control.Applicative
import           Data.Aeson            ((.!=), (.:), (.:?), (.=))
import qualified Data.Aeson            as A
import qualified Data.Aeson.KeyMap     as KM
import qualified Data.Aeson.Types      as A
import           Data.Char             (toUpper)
import           Data.Scientific       (Scientific)
import qualified Data.Text             as T
import           Data.Time
import           Data.Time.Clock.POSIX
import           Data.Typeable
import qualified Data.Vector           as V
import           GHC.Generics          (Generic)
import           Prelude
-------------------------------------------------------------------------------
import           Aws.Core
import           Aws.DynamoDb.Core
-------------------------------------------------------------------------------


capitalizeOpt :: A.Options
capitalizeOpt :: Options
capitalizeOpt = Options
A.defaultOptions
    { fieldLabelModifier :: String -> String
A.fieldLabelModifier = \String
x -> case String
x of
                                     (Char
c:String
cs) -> Char -> Char
toUpper Char
c forall a. a -> [a] -> [a]
: String
cs
                                     [] -> []
    }


dropOpt :: Int -> A.Options
dropOpt :: Int -> Options
dropOpt Int
d = Options
A.defaultOptions { fieldLabelModifier :: String -> String
A.fieldLabelModifier = forall a. Int -> [a] -> [a]
drop Int
d }


convertToUTCTime :: Scientific -> UTCTime
convertToUTCTime :: Scientific -> UTCTime
convertToUTCTime = POSIXTime -> UTCTime
posixSecondsToUTCTime forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (RealFrac a, Integral b) => a -> b
round


-- | The type of a key attribute that appears in the table key or as a
-- key in one of the indices.
data AttributeType = AttrString | AttrNumber | AttrBinary
    deriving (Int -> AttributeType -> String -> String
[AttributeType] -> String -> String
AttributeType -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [AttributeType] -> String -> String
$cshowList :: [AttributeType] -> String -> String
show :: AttributeType -> String
$cshow :: AttributeType -> String
showsPrec :: Int -> AttributeType -> String -> String
$cshowsPrec :: Int -> AttributeType -> String -> String
Show, ReadPrec [AttributeType]
ReadPrec AttributeType
Int -> ReadS AttributeType
ReadS [AttributeType]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttributeType]
$creadListPrec :: ReadPrec [AttributeType]
readPrec :: ReadPrec AttributeType
$creadPrec :: ReadPrec AttributeType
readList :: ReadS [AttributeType]
$creadList :: ReadS [AttributeType]
readsPrec :: Int -> ReadS AttributeType
$creadsPrec :: Int -> ReadS AttributeType
Read, Eq AttributeType
AttributeType -> AttributeType -> Bool
AttributeType -> AttributeType -> Ordering
AttributeType -> AttributeType -> AttributeType
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: AttributeType -> AttributeType -> AttributeType
$cmin :: AttributeType -> AttributeType -> AttributeType
max :: AttributeType -> AttributeType -> AttributeType
$cmax :: AttributeType -> AttributeType -> AttributeType
>= :: AttributeType -> AttributeType -> Bool
$c>= :: AttributeType -> AttributeType -> Bool
> :: AttributeType -> AttributeType -> Bool
$c> :: AttributeType -> AttributeType -> Bool
<= :: AttributeType -> AttributeType -> Bool
$c<= :: AttributeType -> AttributeType -> Bool
< :: AttributeType -> AttributeType -> Bool
$c< :: AttributeType -> AttributeType -> Bool
compare :: AttributeType -> AttributeType -> Ordering
$ccompare :: AttributeType -> AttributeType -> Ordering
Ord, Typeable, AttributeType -> AttributeType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeType -> AttributeType -> Bool
$c/= :: AttributeType -> AttributeType -> Bool
== :: AttributeType -> AttributeType -> Bool
$c== :: AttributeType -> AttributeType -> Bool
Eq, Int -> AttributeType
AttributeType -> Int
AttributeType -> [AttributeType]
AttributeType -> AttributeType
AttributeType -> AttributeType -> [AttributeType]
AttributeType -> AttributeType -> AttributeType -> [AttributeType]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: AttributeType -> AttributeType -> AttributeType -> [AttributeType]
$cenumFromThenTo :: AttributeType -> AttributeType -> AttributeType -> [AttributeType]
enumFromTo :: AttributeType -> AttributeType -> [AttributeType]
$cenumFromTo :: AttributeType -> AttributeType -> [AttributeType]
enumFromThen :: AttributeType -> AttributeType -> [AttributeType]
$cenumFromThen :: AttributeType -> AttributeType -> [AttributeType]
enumFrom :: AttributeType -> [AttributeType]
$cenumFrom :: AttributeType -> [AttributeType]
fromEnum :: AttributeType -> Int
$cfromEnum :: AttributeType -> Int
toEnum :: Int -> AttributeType
$ctoEnum :: Int -> AttributeType
pred :: AttributeType -> AttributeType
$cpred :: AttributeType -> AttributeType
succ :: AttributeType -> AttributeType
$csucc :: AttributeType -> AttributeType
Enum, AttributeType
forall a. a -> a -> Bounded a
maxBound :: AttributeType
$cmaxBound :: AttributeType
minBound :: AttributeType
$cminBound :: AttributeType
Bounded, forall x. Rep AttributeType x -> AttributeType
forall x. AttributeType -> Rep AttributeType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeType x -> AttributeType
$cfrom :: forall x. AttributeType -> Rep AttributeType x
Generic)

instance A.ToJSON AttributeType where
    toJSON :: AttributeType -> Value
toJSON AttributeType
AttrString = Text -> Value
A.String Text
"S"
    toJSON AttributeType
AttrNumber = Text -> Value
A.String Text
"N"
    toJSON AttributeType
AttrBinary = Text -> Value
A.String Text
"B"

instance A.FromJSON AttributeType where
    parseJSON :: Value -> Parser AttributeType
parseJSON (A.String Text
str) =
        case Text
str of
            Text
"S" -> forall (m :: * -> *) a. Monad m => a -> m a
return AttributeType
AttrString
            Text
"N" -> forall (m :: * -> *) a. Monad m => a -> m a
return AttributeType
AttrNumber
            Text
"B" -> forall (m :: * -> *) a. Monad m => a -> m a
return AttributeType
AttrBinary
            Text
_   -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"Invalid attribute type " forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
str
    parseJSON Value
_ = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Attribute type must be a string"

-- | A key attribute that appears in the table key or as a key in one of the indices.
data AttributeDefinition = AttributeDefinition {
      AttributeDefinition -> Text
attributeName :: T.Text
    , AttributeDefinition -> AttributeType
attributeType :: AttributeType
    } deriving (AttributeDefinition -> AttributeDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeDefinition -> AttributeDefinition -> Bool
$c/= :: AttributeDefinition -> AttributeDefinition -> Bool
== :: AttributeDefinition -> AttributeDefinition -> Bool
$c== :: AttributeDefinition -> AttributeDefinition -> Bool
Eq,ReadPrec [AttributeDefinition]
ReadPrec AttributeDefinition
Int -> ReadS AttributeDefinition
ReadS [AttributeDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttributeDefinition]
$creadListPrec :: ReadPrec [AttributeDefinition]
readPrec :: ReadPrec AttributeDefinition
$creadPrec :: ReadPrec AttributeDefinition
readList :: ReadS [AttributeDefinition]
$creadList :: ReadS [AttributeDefinition]
readsPrec :: Int -> ReadS AttributeDefinition
$creadsPrec :: Int -> ReadS AttributeDefinition
Read,Eq AttributeDefinition
AttributeDefinition -> AttributeDefinition -> Bool
AttributeDefinition -> AttributeDefinition -> Ordering
AttributeDefinition -> AttributeDefinition -> AttributeDefinition
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: AttributeDefinition -> AttributeDefinition -> AttributeDefinition
$cmin :: AttributeDefinition -> AttributeDefinition -> AttributeDefinition
max :: AttributeDefinition -> AttributeDefinition -> AttributeDefinition
$cmax :: AttributeDefinition -> AttributeDefinition -> AttributeDefinition
>= :: AttributeDefinition -> AttributeDefinition -> Bool
$c>= :: AttributeDefinition -> AttributeDefinition -> Bool
> :: AttributeDefinition -> AttributeDefinition -> Bool
$c> :: AttributeDefinition -> AttributeDefinition -> Bool
<= :: AttributeDefinition -> AttributeDefinition -> Bool
$c<= :: AttributeDefinition -> AttributeDefinition -> Bool
< :: AttributeDefinition -> AttributeDefinition -> Bool
$c< :: AttributeDefinition -> AttributeDefinition -> Bool
compare :: AttributeDefinition -> AttributeDefinition -> Ordering
$ccompare :: AttributeDefinition -> AttributeDefinition -> Ordering
Ord,Int -> AttributeDefinition -> String -> String
[AttributeDefinition] -> String -> String
AttributeDefinition -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [AttributeDefinition] -> String -> String
$cshowList :: [AttributeDefinition] -> String -> String
show :: AttributeDefinition -> String
$cshow :: AttributeDefinition -> String
showsPrec :: Int -> AttributeDefinition -> String -> String
$cshowsPrec :: Int -> AttributeDefinition -> String -> String
Show,Typeable,forall x. Rep AttributeDefinition x -> AttributeDefinition
forall x. AttributeDefinition -> Rep AttributeDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeDefinition x -> AttributeDefinition
$cfrom :: forall x. AttributeDefinition -> Rep AttributeDefinition x
Generic)

instance A.ToJSON AttributeDefinition where
    toJSON :: AttributeDefinition -> Value
toJSON = forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
A.genericToJSON Options
capitalizeOpt

instance A.FromJSON AttributeDefinition where
    parseJSON :: Value -> Parser AttributeDefinition
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON Options
capitalizeOpt

-- | The key schema can either be a hash of a single attribute name or a hash attribute name
-- and a range attribute name.
data KeySchema = HashOnly T.Text
               | HashAndRange T.Text T.Text
    deriving (KeySchema -> KeySchema -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeySchema -> KeySchema -> Bool
$c/= :: KeySchema -> KeySchema -> Bool
== :: KeySchema -> KeySchema -> Bool
$c== :: KeySchema -> KeySchema -> Bool
Eq,ReadPrec [KeySchema]
ReadPrec KeySchema
Int -> ReadS KeySchema
ReadS [KeySchema]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KeySchema]
$creadListPrec :: ReadPrec [KeySchema]
readPrec :: ReadPrec KeySchema
$creadPrec :: ReadPrec KeySchema
readList :: ReadS [KeySchema]
$creadList :: ReadS [KeySchema]
readsPrec :: Int -> ReadS KeySchema
$creadsPrec :: Int -> ReadS KeySchema
Read,Int -> KeySchema -> String -> String
[KeySchema] -> String -> String
KeySchema -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [KeySchema] -> String -> String
$cshowList :: [KeySchema] -> String -> String
show :: KeySchema -> String
$cshow :: KeySchema -> String
showsPrec :: Int -> KeySchema -> String -> String
$cshowsPrec :: Int -> KeySchema -> String -> String
Show,Eq KeySchema
KeySchema -> KeySchema -> Bool
KeySchema -> KeySchema -> Ordering
KeySchema -> KeySchema -> KeySchema
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: KeySchema -> KeySchema -> KeySchema
$cmin :: KeySchema -> KeySchema -> KeySchema
max :: KeySchema -> KeySchema -> KeySchema
$cmax :: KeySchema -> KeySchema -> KeySchema
>= :: KeySchema -> KeySchema -> Bool
$c>= :: KeySchema -> KeySchema -> Bool
> :: KeySchema -> KeySchema -> Bool
$c> :: KeySchema -> KeySchema -> Bool
<= :: KeySchema -> KeySchema -> Bool
$c<= :: KeySchema -> KeySchema -> Bool
< :: KeySchema -> KeySchema -> Bool
$c< :: KeySchema -> KeySchema -> Bool
compare :: KeySchema -> KeySchema -> Ordering
$ccompare :: KeySchema -> KeySchema -> Ordering
Ord,Typeable,forall x. Rep KeySchema x -> KeySchema
forall x. KeySchema -> Rep KeySchema x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KeySchema x -> KeySchema
$cfrom :: forall x. KeySchema -> Rep KeySchema x
Generic)


instance A.ToJSON KeySchema where
    toJSON :: KeySchema -> Value
toJSON (HashOnly Text
a)
        = Array -> Value
A.Array forall a b. (a -> b) -> a -> b
$ forall a. [a] -> Vector a
V.fromList [ [Pair] -> Value
A.object [ Key
"AttributeName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
a
                                          , Key
"KeyType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text -> Value
A.String Text
"HASH")
                                          ]
                               ]

    toJSON (HashAndRange Text
hash Text
range)
        = Array -> Value
A.Array forall a b. (a -> b) -> a -> b
$ forall a. [a] -> Vector a
V.fromList [ [Pair] -> Value
A.object [ Key
"AttributeName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
hash
                                          , Key
"KeyType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text -> Value
A.String Text
"HASH")
                                          ]
                               , [Pair] -> Value
A.object [ Key
"AttributeName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
range
                                          , Key
"KeyType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text -> Value
A.String Text
"RANGE")
                                          ]
                               ]

instance A.FromJSON KeySchema where
    parseJSON :: Value -> Parser KeySchema
parseJSON (A.Array Array
v) =
        case forall a. Vector a -> Int
V.length Array
v of
            Int
1 -> do Object
obj <- forall a. FromJSON a => Value -> Parser a
A.parseJSON (Array
v forall a. Vector a -> Int -> a
V.! Int
0)
                    Text
kt <- Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"KeyType"
                    if Text
kt forall a. Eq a => a -> a -> Bool
/= (Text
"HASH" :: T.Text)
                        then forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"With only one key, the type must be HASH"
                        else Text -> KeySchema
HashOnly forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"AttributeName"

            Int
2 -> do Object
hash <- forall a. FromJSON a => Value -> Parser a
A.parseJSON (Array
v forall a. Vector a -> Int -> a
V.! Int
0)
                    Object
range <- forall a. FromJSON a => Value -> Parser a
A.parseJSON (Array
v forall a. Vector a -> Int -> a
V.! Int
1)
                    Text
hkt <- Object
hash forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"KeyType"
                    Text
rkt <- Object
range forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"KeyType"
                    if Text
hkt forall a. Eq a => a -> a -> Bool
/= (Text
"HASH" :: T.Text) Bool -> Bool -> Bool
|| Text
rkt forall a. Eq a => a -> a -> Bool
/= (Text
"RANGE" :: T.Text)
                        then forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"With two keys, one must be HASH and the other RANGE"
                        else Text -> Text -> KeySchema
HashAndRange forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
hash forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"AttributeName"
                                          forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
range forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"AttributeName"
            Int
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Key schema must have one or two entries"
    parseJSON Value
_ = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Key schema must be an array"

-- | This determines which attributes are projected into a secondary index.
data Projection = ProjectKeysOnly
                | ProjectAll
                | ProjectInclude [T.Text]
    deriving Int -> Projection -> String -> String
[Projection] -> String -> String
Projection -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [Projection] -> String -> String
$cshowList :: [Projection] -> String -> String
show :: Projection -> String
$cshow :: Projection -> String
showsPrec :: Int -> Projection -> String -> String
$cshowsPrec :: Int -> Projection -> String -> String
Show
instance A.ToJSON Projection where
    toJSON :: Projection -> Value
toJSON Projection
ProjectKeysOnly    = [Pair] -> Value
A.object [ Key
"ProjectionType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text
"KEYS_ONLY" :: T.Text) ]
    toJSON Projection
ProjectAll         = [Pair] -> Value
A.object [ Key
"ProjectionType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text
"ALL" :: T.Text) ]
    toJSON (ProjectInclude [Text]
a) = [Pair] -> Value
A.object [ Key
"ProjectionType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= (Text
"INCLUDE" :: T.Text)
                                         , Key
"NonKeyAttributes" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [Text]
a
                                         ]
instance A.FromJSON Projection where
    parseJSON :: Value -> Parser Projection
parseJSON (A.Object Object
o) = do
        Text
ty <- (Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ProjectionType") :: A.Parser T.Text
        case Text
ty of
            Text
"KEYS_ONLY" -> forall (m :: * -> *) a. Monad m => a -> m a
return Projection
ProjectKeysOnly
            Text
"ALL" -> forall (m :: * -> *) a. Monad m => a -> m a
return Projection
ProjectAll
            Text
"INCLUDE" -> [Text] -> Projection
ProjectInclude forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"NonKeyAttributes"
            Text
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Invalid projection type"
    parseJSON Value
_ = forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Projection must be an object"

-- | Describes a single local secondary index. The KeySchema MUST
-- share the same hash key attribute as the parent table, only the
-- range key can differ.
data LocalSecondaryIndex
    = LocalSecondaryIndex {
        LocalSecondaryIndex -> Text
localIndexName  :: T.Text
      , LocalSecondaryIndex -> KeySchema
localKeySchema  :: KeySchema
      , LocalSecondaryIndex -> Projection
localProjection :: Projection
      }
    deriving (Int -> LocalSecondaryIndex -> String -> String
[LocalSecondaryIndex] -> String -> String
LocalSecondaryIndex -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [LocalSecondaryIndex] -> String -> String
$cshowList :: [LocalSecondaryIndex] -> String -> String
show :: LocalSecondaryIndex -> String
$cshow :: LocalSecondaryIndex -> String
showsPrec :: Int -> LocalSecondaryIndex -> String -> String
$cshowsPrec :: Int -> LocalSecondaryIndex -> String -> String
Show, forall x. Rep LocalSecondaryIndex x -> LocalSecondaryIndex
forall x. LocalSecondaryIndex -> Rep LocalSecondaryIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LocalSecondaryIndex x -> LocalSecondaryIndex
$cfrom :: forall x. LocalSecondaryIndex -> Rep LocalSecondaryIndex x
Generic)
instance A.ToJSON LocalSecondaryIndex where
    toJSON :: LocalSecondaryIndex -> Value
toJSON = forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
A.genericToJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
5
instance A.FromJSON LocalSecondaryIndex where
    parseJSON :: Value -> Parser LocalSecondaryIndex
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
5

-- | This is returned by AWS to describe the local secondary index.
data LocalSecondaryIndexStatus
    = LocalSecondaryIndexStatus {
        LocalSecondaryIndexStatus -> Text
locStatusIndexName      :: T.Text
      , LocalSecondaryIndexStatus -> Integer
locStatusIndexSizeBytes :: Integer
      , LocalSecondaryIndexStatus -> Integer
locStatusItemCount      :: Integer
      , LocalSecondaryIndexStatus -> KeySchema
locStatusKeySchema      :: KeySchema
      , LocalSecondaryIndexStatus -> Projection
locStatusProjection     :: Projection
      }
    deriving (Int -> LocalSecondaryIndexStatus -> String -> String
[LocalSecondaryIndexStatus] -> String -> String
LocalSecondaryIndexStatus -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [LocalSecondaryIndexStatus] -> String -> String
$cshowList :: [LocalSecondaryIndexStatus] -> String -> String
show :: LocalSecondaryIndexStatus -> String
$cshow :: LocalSecondaryIndexStatus -> String
showsPrec :: Int -> LocalSecondaryIndexStatus -> String -> String
$cshowsPrec :: Int -> LocalSecondaryIndexStatus -> String -> String
Show, forall x.
Rep LocalSecondaryIndexStatus x -> LocalSecondaryIndexStatus
forall x.
LocalSecondaryIndexStatus -> Rep LocalSecondaryIndexStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep LocalSecondaryIndexStatus x -> LocalSecondaryIndexStatus
$cfrom :: forall x.
LocalSecondaryIndexStatus -> Rep LocalSecondaryIndexStatus x
Generic)
instance A.FromJSON LocalSecondaryIndexStatus where
    parseJSON :: Value -> Parser LocalSecondaryIndexStatus
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
9

-- | The target provisioned throughput you are requesting for the table or global secondary index.
data ProvisionedThroughput
    = ProvisionedThroughput {
        ProvisionedThroughput -> Int
readCapacityUnits  :: Int
      , ProvisionedThroughput -> Int
writeCapacityUnits :: Int
      }
    deriving (Int -> ProvisionedThroughput -> String -> String
[ProvisionedThroughput] -> String -> String
ProvisionedThroughput -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [ProvisionedThroughput] -> String -> String
$cshowList :: [ProvisionedThroughput] -> String -> String
show :: ProvisionedThroughput -> String
$cshow :: ProvisionedThroughput -> String
showsPrec :: Int -> ProvisionedThroughput -> String -> String
$cshowsPrec :: Int -> ProvisionedThroughput -> String -> String
Show, forall x. Rep ProvisionedThroughput x -> ProvisionedThroughput
forall x. ProvisionedThroughput -> Rep ProvisionedThroughput x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProvisionedThroughput x -> ProvisionedThroughput
$cfrom :: forall x. ProvisionedThroughput -> Rep ProvisionedThroughput x
Generic)
instance A.ToJSON ProvisionedThroughput where
    toJSON :: ProvisionedThroughput -> Value
toJSON = forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
A.genericToJSON Options
capitalizeOpt
instance A.FromJSON ProvisionedThroughput where
    parseJSON :: Value -> Parser ProvisionedThroughput
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON Options
capitalizeOpt

-- | This is returned by AWS as the status of the throughput for a table or global secondary index.
data ProvisionedThroughputStatus
    = ProvisionedThroughputStatus {
        ProvisionedThroughputStatus -> UTCTime
statusLastDecreaseDateTime   :: UTCTime
      , ProvisionedThroughputStatus -> UTCTime
statusLastIncreaseDateTime   :: UTCTime
      , ProvisionedThroughputStatus -> Int
statusNumberOfDecreasesToday :: Int
      , ProvisionedThroughputStatus -> Int
statusReadCapacityUnits      :: Int
      , ProvisionedThroughputStatus -> Int
statusWriteCapacityUnits     :: Int
      }
    deriving (Int -> ProvisionedThroughputStatus -> String -> String
[ProvisionedThroughputStatus] -> String -> String
ProvisionedThroughputStatus -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [ProvisionedThroughputStatus] -> String -> String
$cshowList :: [ProvisionedThroughputStatus] -> String -> String
show :: ProvisionedThroughputStatus -> String
$cshow :: ProvisionedThroughputStatus -> String
showsPrec :: Int -> ProvisionedThroughputStatus -> String -> String
$cshowsPrec :: Int -> ProvisionedThroughputStatus -> String -> String
Show, forall x.
Rep ProvisionedThroughputStatus x -> ProvisionedThroughputStatus
forall x.
ProvisionedThroughputStatus -> Rep ProvisionedThroughputStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ProvisionedThroughputStatus x -> ProvisionedThroughputStatus
$cfrom :: forall x.
ProvisionedThroughputStatus -> Rep ProvisionedThroughputStatus x
Generic)
instance A.FromJSON ProvisionedThroughputStatus where
    parseJSON :: Value -> Parser ProvisionedThroughputStatus
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Throughput status must be an object" forall a b. (a -> b) -> a -> b
$ \Object
o ->
        UTCTime
-> UTCTime -> Int -> Int -> Int -> ProvisionedThroughputStatus
ProvisionedThroughputStatus
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Scientific -> UTCTime
convertToUTCTime forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"LastDecreaseDateTime" forall a. Parser (Maybe a) -> a -> Parser a
.!= Scientific
0)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Scientific -> UTCTime
convertToUTCTime forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"LastIncreaseDateTime" forall a. Parser (Maybe a) -> a -> Parser a
.!= Scientific
0)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"NumberOfDecreasesToday" forall a. Parser (Maybe a) -> a -> Parser a
.!= Int
0
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ReadCapacityUnits"
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"WriteCapacityUnits"

-- | Describes a global secondary index.
data GlobalSecondaryIndex
    = GlobalSecondaryIndex {
        GlobalSecondaryIndex -> Text
globalIndexName             :: T.Text
      , GlobalSecondaryIndex -> KeySchema
globalKeySchema             :: KeySchema
      , GlobalSecondaryIndex -> Projection
globalProjection            :: Projection
      , GlobalSecondaryIndex -> ProvisionedThroughput
globalProvisionedThroughput :: ProvisionedThroughput
      }
    deriving (Int -> GlobalSecondaryIndex -> String -> String
[GlobalSecondaryIndex] -> String -> String
GlobalSecondaryIndex -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [GlobalSecondaryIndex] -> String -> String
$cshowList :: [GlobalSecondaryIndex] -> String -> String
show :: GlobalSecondaryIndex -> String
$cshow :: GlobalSecondaryIndex -> String
showsPrec :: Int -> GlobalSecondaryIndex -> String -> String
$cshowsPrec :: Int -> GlobalSecondaryIndex -> String -> String
Show, forall x. Rep GlobalSecondaryIndex x -> GlobalSecondaryIndex
forall x. GlobalSecondaryIndex -> Rep GlobalSecondaryIndex x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GlobalSecondaryIndex x -> GlobalSecondaryIndex
$cfrom :: forall x. GlobalSecondaryIndex -> Rep GlobalSecondaryIndex x
Generic)
instance A.ToJSON GlobalSecondaryIndex where
    toJSON :: GlobalSecondaryIndex -> Value
toJSON = forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
A.genericToJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
6
instance A.FromJSON GlobalSecondaryIndex where
    parseJSON :: Value -> Parser GlobalSecondaryIndex
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
6

-- | This is returned by AWS to describe the status of a global secondary index.
data GlobalSecondaryIndexStatus
    = GlobalSecondaryIndexStatus {
        GlobalSecondaryIndexStatus -> Text
gStatusIndexName             :: T.Text
      , GlobalSecondaryIndexStatus -> Integer
gStatusIndexSizeBytes        :: Integer
      , GlobalSecondaryIndexStatus -> Text
gStatusIndexStatus           :: T.Text
      , GlobalSecondaryIndexStatus -> Integer
gStatusItemCount             :: Integer
      , GlobalSecondaryIndexStatus -> KeySchema
gStatusKeySchema             :: KeySchema
      , GlobalSecondaryIndexStatus -> Projection
gStatusProjection            :: Projection
      , GlobalSecondaryIndexStatus -> ProvisionedThroughputStatus
gStatusProvisionedThroughput :: ProvisionedThroughputStatus
      }
    deriving (Int -> GlobalSecondaryIndexStatus -> String -> String
[GlobalSecondaryIndexStatus] -> String -> String
GlobalSecondaryIndexStatus -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [GlobalSecondaryIndexStatus] -> String -> String
$cshowList :: [GlobalSecondaryIndexStatus] -> String -> String
show :: GlobalSecondaryIndexStatus -> String
$cshow :: GlobalSecondaryIndexStatus -> String
showsPrec :: Int -> GlobalSecondaryIndexStatus -> String -> String
$cshowsPrec :: Int -> GlobalSecondaryIndexStatus -> String -> String
Show, forall x.
Rep GlobalSecondaryIndexStatus x -> GlobalSecondaryIndexStatus
forall x.
GlobalSecondaryIndexStatus -> Rep GlobalSecondaryIndexStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GlobalSecondaryIndexStatus x -> GlobalSecondaryIndexStatus
$cfrom :: forall x.
GlobalSecondaryIndexStatus -> Rep GlobalSecondaryIndexStatus x
Generic)
instance A.FromJSON GlobalSecondaryIndexStatus where
    parseJSON :: Value -> Parser GlobalSecondaryIndexStatus
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
7

-- | This is used to request a change in the provisioned throughput of
-- a global secondary index as part of an 'UpdateTable' operation.
data GlobalSecondaryIndexUpdate
    = GlobalSecondaryIndexUpdate {
        GlobalSecondaryIndexUpdate -> Text
gUpdateIndexName             :: T.Text
      , GlobalSecondaryIndexUpdate -> ProvisionedThroughput
gUpdateProvisionedThroughput :: ProvisionedThroughput
      }
    deriving (Int -> GlobalSecondaryIndexUpdate -> String -> String
[GlobalSecondaryIndexUpdate] -> String -> String
GlobalSecondaryIndexUpdate -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [GlobalSecondaryIndexUpdate] -> String -> String
$cshowList :: [GlobalSecondaryIndexUpdate] -> String -> String
show :: GlobalSecondaryIndexUpdate -> String
$cshow :: GlobalSecondaryIndexUpdate -> String
showsPrec :: Int -> GlobalSecondaryIndexUpdate -> String -> String
$cshowsPrec :: Int -> GlobalSecondaryIndexUpdate -> String -> String
Show, forall x.
Rep GlobalSecondaryIndexUpdate x -> GlobalSecondaryIndexUpdate
forall x.
GlobalSecondaryIndexUpdate -> Rep GlobalSecondaryIndexUpdate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GlobalSecondaryIndexUpdate x -> GlobalSecondaryIndexUpdate
$cfrom :: forall x.
GlobalSecondaryIndexUpdate -> Rep GlobalSecondaryIndexUpdate x
Generic)
instance A.ToJSON GlobalSecondaryIndexUpdate where
    toJSON :: GlobalSecondaryIndexUpdate -> Value
toJSON GlobalSecondaryIndexUpdate
gi = [Pair] -> Value
A.object [Key
"Update" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
A.genericToJSON (Int -> Options
dropOpt Int
7) GlobalSecondaryIndexUpdate
gi]

-- | This describes the table and is the return value from AWS for all
-- the table-related commands.
data TableDescription
    = TableDescription {
        TableDescription -> Text
rTableName              :: T.Text
      , TableDescription -> Integer
rTableSizeBytes         :: Integer
      , TableDescription -> Text
rTableStatus            :: T.Text -- ^ one of CREATING, UPDATING, DELETING, ACTIVE
      , TableDescription -> Maybe UTCTime
rCreationDateTime       :: Maybe UTCTime
      , TableDescription -> Integer
rItemCount              :: Integer
      , TableDescription -> [AttributeDefinition]
rAttributeDefinitions   :: [AttributeDefinition]
      , TableDescription -> Maybe KeySchema
rKeySchema              :: Maybe KeySchema
      , TableDescription -> ProvisionedThroughputStatus
rProvisionedThroughput  :: ProvisionedThroughputStatus
      , TableDescription -> [LocalSecondaryIndexStatus]
rLocalSecondaryIndexes  :: [LocalSecondaryIndexStatus]
      , TableDescription -> [GlobalSecondaryIndexStatus]
rGlobalSecondaryIndexes :: [GlobalSecondaryIndexStatus]
      }
    deriving (Int -> TableDescription -> String -> String
[TableDescription] -> String -> String
TableDescription -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [TableDescription] -> String -> String
$cshowList :: [TableDescription] -> String -> String
show :: TableDescription -> String
$cshow :: TableDescription -> String
showsPrec :: Int -> TableDescription -> String -> String
$cshowsPrec :: Int -> TableDescription -> String -> String
Show, forall x. Rep TableDescription x -> TableDescription
forall x. TableDescription -> Rep TableDescription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TableDescription x -> TableDescription
$cfrom :: forall x. TableDescription -> Rep TableDescription x
Generic)

instance A.FromJSON TableDescription where
    parseJSON :: Value -> Parser TableDescription
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Table must be an object" forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Object
t <- case (forall v. Key -> KeyMap v -> Maybe v
KM.lookup Key
"Table" Object
o, forall v. Key -> KeyMap v -> Maybe v
KM.lookup Key
"TableDescription" Object
o) of
                (Just (A.Object Object
t), Maybe Value
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return Object
t
                (Maybe Value
_, Just (A.Object Object
t)) -> forall (m :: * -> *) a. Monad m => a -> m a
return Object
t
                (Maybe Value, Maybe Value)
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Table description must have key 'Table' or 'TableDescription'"
        Text
-> Integer
-> Text
-> Maybe UTCTime
-> Integer
-> [AttributeDefinition]
-> Maybe KeySchema
-> ProvisionedThroughputStatus
-> [LocalSecondaryIndexStatus]
-> [GlobalSecondaryIndexStatus]
-> TableDescription
TableDescription forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
t forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"TableName"
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"TableSizeBytes"
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"TableStatus"
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Scientific -> UTCTime
convertToUTCTime forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
t forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"CreationDateTime")
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ItemCount"
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"AttributeDefinitions" forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"KeySchema"
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ProvisionedThroughput"
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"LocalSecondaryIndexes" forall a. Parser (Maybe a) -> a -> Parser a
.!= []
                         forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
t forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"GlobalSecondaryIndexes" forall a. Parser (Maybe a) -> a -> Parser a
.!= []

{- Can't derive these instances onto the return values
instance ResponseConsumer r TableDescription where
    type ResponseMetadata TableDescription = DyMetadata
    responseConsumer _ _ _ = ddbResponseConsumer
instance AsMemoryResponse TableDescription where
    type MemoryResponse TableDescription = TableDescription
    loadToMemory = return
-}

-------------------------------------------------------------------------------
--- Commands
-------------------------------------------------------------------------------

data CreateTable = CreateTable {
      CreateTable -> Text
createTableName              :: T.Text
    , CreateTable -> [AttributeDefinition]
createAttributeDefinitions   :: [AttributeDefinition]
    -- ^ only attributes appearing in a key must be listed here
    , CreateTable -> KeySchema
createKeySchema              :: KeySchema
    , CreateTable -> ProvisionedThroughput
createProvisionedThroughput  :: ProvisionedThroughput
    , CreateTable -> [LocalSecondaryIndex]
createLocalSecondaryIndexes  :: [LocalSecondaryIndex]
    -- ^ at most 5 local secondary indices are allowed
    , CreateTable -> [GlobalSecondaryIndex]
createGlobalSecondaryIndexes :: [GlobalSecondaryIndex]
    } deriving (Int -> CreateTable -> String -> String
[CreateTable] -> String -> String
CreateTable -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [CreateTable] -> String -> String
$cshowList :: [CreateTable] -> String -> String
show :: CreateTable -> String
$cshow :: CreateTable -> String
showsPrec :: Int -> CreateTable -> String -> String
$cshowsPrec :: Int -> CreateTable -> String -> String
Show, forall x. Rep CreateTable x -> CreateTable
forall x. CreateTable -> Rep CreateTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateTable x -> CreateTable
$cfrom :: forall x. CreateTable -> Rep CreateTable x
Generic)

createTable :: T.Text -- ^ Table name
            -> [AttributeDefinition]
            -> KeySchema
            -> ProvisionedThroughput
            -> CreateTable
createTable :: Text
-> [AttributeDefinition]
-> KeySchema
-> ProvisionedThroughput
-> CreateTable
createTable Text
tn [AttributeDefinition]
ad KeySchema
ks ProvisionedThroughput
p = Text
-> [AttributeDefinition]
-> KeySchema
-> ProvisionedThroughput
-> [LocalSecondaryIndex]
-> [GlobalSecondaryIndex]
-> CreateTable
CreateTable Text
tn [AttributeDefinition]
ad KeySchema
ks ProvisionedThroughput
p [] []

instance A.ToJSON CreateTable where
    toJSON :: CreateTable -> Value
toJSON CreateTable
ct = [Pair] -> Value
A.object forall a b. (a -> b) -> a -> b
$ [Pair]
m forall a. [a] -> [a] -> [a]
++ [Pair]
lindex forall a. [a] -> [a] -> [a]
++ [Pair]
gindex
        where
            m :: [Pair]
m = [ Key
"TableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CreateTable -> Text
createTableName CreateTable
ct
                , Key
"AttributeDefinitions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CreateTable -> [AttributeDefinition]
createAttributeDefinitions CreateTable
ct
                , Key
"KeySchema" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CreateTable -> KeySchema
createKeySchema CreateTable
ct
                , Key
"ProvisionedThroughput" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CreateTable -> ProvisionedThroughput
createProvisionedThroughput CreateTable
ct
                ]
            -- AWS will error with 500 if (LocalSecondaryIndexes : []) is present in the JSON
            lindex :: [Pair]
lindex = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null (CreateTable -> [LocalSecondaryIndex]
createLocalSecondaryIndexes CreateTable
ct)
                        then []
                        else [ Key
"LocalSecondaryIndexes" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CreateTable -> [LocalSecondaryIndex]
createLocalSecondaryIndexes CreateTable
ct ]
            gindex :: [Pair]
gindex = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null (CreateTable -> [GlobalSecondaryIndex]
createGlobalSecondaryIndexes CreateTable
ct)
                        then []
                        else [ Key
"GlobalSecondaryIndexes" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CreateTable -> [GlobalSecondaryIndex]
createGlobalSecondaryIndexes CreateTable
ct ]

--instance A.ToJSON CreateTable where
--    toJSON = A.genericToJSON $ dropOpt 6


-- | ServiceConfiguration: 'DdbConfiguration'
instance SignQuery CreateTable where
    type ServiceConfiguration CreateTable = DdbConfiguration
    signQuery :: forall queryType.
CreateTable
-> ServiceConfiguration CreateTable queryType
-> SignatureData
-> SignedQuery
signQuery = forall a qt.
ToJSON a =>
ByteString
-> a -> DdbConfiguration qt -> SignatureData -> SignedQuery
ddbSignQuery ByteString
"CreateTable"

newtype CreateTableResult = CreateTableResult { CreateTableResult -> TableDescription
ctStatus :: TableDescription }
    deriving (Int -> CreateTableResult -> String -> String
[CreateTableResult] -> String -> String
CreateTableResult -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [CreateTableResult] -> String -> String
$cshowList :: [CreateTableResult] -> String -> String
show :: CreateTableResult -> String
$cshow :: CreateTableResult -> String
showsPrec :: Int -> CreateTableResult -> String -> String
$cshowsPrec :: Int -> CreateTableResult -> String -> String
Show, Value -> Parser [CreateTableResult]
Value -> Parser CreateTableResult
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [CreateTableResult]
$cparseJSONList :: Value -> Parser [CreateTableResult]
parseJSON :: Value -> Parser CreateTableResult
$cparseJSON :: Value -> Parser CreateTableResult
A.FromJSON)
-- ResponseConsumer and AsMemoryResponse can't be derived
instance ResponseConsumer r CreateTableResult where
    type ResponseMetadata CreateTableResult = DdbResponse
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata CreateTableResult)
-> HTTPResponseConsumer CreateTableResult
responseConsumer Request
_ r
_ = forall a. FromJSON a => IORef DdbResponse -> HTTPResponseConsumer a
ddbResponseConsumer
instance AsMemoryResponse CreateTableResult where
    type MemoryResponse CreateTableResult = TableDescription
    loadToMemory :: CreateTableResult
-> ResourceT IO (MemoryResponse CreateTableResult)
loadToMemory = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. CreateTableResult -> TableDescription
ctStatus

instance Transaction CreateTable CreateTableResult

data DescribeTable
    = DescribeTable {
        DescribeTable -> Text
dTableName :: T.Text
      }
    deriving (Int -> DescribeTable -> String -> String
[DescribeTable] -> String -> String
DescribeTable -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [DescribeTable] -> String -> String
$cshowList :: [DescribeTable] -> String -> String
show :: DescribeTable -> String
$cshow :: DescribeTable -> String
showsPrec :: Int -> DescribeTable -> String -> String
$cshowsPrec :: Int -> DescribeTable -> String -> String
Show, forall x. Rep DescribeTable x -> DescribeTable
forall x. DescribeTable -> Rep DescribeTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeTable x -> DescribeTable
$cfrom :: forall x. DescribeTable -> Rep DescribeTable x
Generic)
instance A.ToJSON DescribeTable where
    toJSON :: DescribeTable -> Value
toJSON = forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
A.genericToJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
1

-- | ServiceConfiguration: 'DdbConfiguration'
instance SignQuery DescribeTable where
    type ServiceConfiguration DescribeTable = DdbConfiguration
    signQuery :: forall queryType.
DescribeTable
-> ServiceConfiguration DescribeTable queryType
-> SignatureData
-> SignedQuery
signQuery = forall a qt.
ToJSON a =>
ByteString
-> a -> DdbConfiguration qt -> SignatureData -> SignedQuery
ddbSignQuery ByteString
"DescribeTable"

newtype DescribeTableResult = DescribeTableResult { DescribeTableResult -> TableDescription
dtStatus :: TableDescription }
    deriving (Int -> DescribeTableResult -> String -> String
[DescribeTableResult] -> String -> String
DescribeTableResult -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [DescribeTableResult] -> String -> String
$cshowList :: [DescribeTableResult] -> String -> String
show :: DescribeTableResult -> String
$cshow :: DescribeTableResult -> String
showsPrec :: Int -> DescribeTableResult -> String -> String
$cshowsPrec :: Int -> DescribeTableResult -> String -> String
Show, Value -> Parser [DescribeTableResult]
Value -> Parser DescribeTableResult
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [DescribeTableResult]
$cparseJSONList :: Value -> Parser [DescribeTableResult]
parseJSON :: Value -> Parser DescribeTableResult
$cparseJSON :: Value -> Parser DescribeTableResult
A.FromJSON)
-- ResponseConsumer can't be derived
instance ResponseConsumer r DescribeTableResult where
    type ResponseMetadata DescribeTableResult = DdbResponse
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata DescribeTableResult)
-> HTTPResponseConsumer DescribeTableResult
responseConsumer Request
_ r
_ = forall a. FromJSON a => IORef DdbResponse -> HTTPResponseConsumer a
ddbResponseConsumer
instance AsMemoryResponse DescribeTableResult where
    type MemoryResponse DescribeTableResult = TableDescription
    loadToMemory :: DescribeTableResult
-> ResourceT IO (MemoryResponse DescribeTableResult)
loadToMemory = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. DescribeTableResult -> TableDescription
dtStatus

instance Transaction DescribeTable DescribeTableResult

data UpdateTable
    = UpdateTable {
        UpdateTable -> Text
updateTableName                   :: T.Text
      , UpdateTable -> ProvisionedThroughput
updateProvisionedThroughput       :: ProvisionedThroughput
      , UpdateTable -> [GlobalSecondaryIndexUpdate]
updateGlobalSecondaryIndexUpdates :: [GlobalSecondaryIndexUpdate]
      }
    deriving (Int -> UpdateTable -> String -> String
[UpdateTable] -> String -> String
UpdateTable -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [UpdateTable] -> String -> String
$cshowList :: [UpdateTable] -> String -> String
show :: UpdateTable -> String
$cshow :: UpdateTable -> String
showsPrec :: Int -> UpdateTable -> String -> String
$cshowsPrec :: Int -> UpdateTable -> String -> String
Show, forall x. Rep UpdateTable x -> UpdateTable
forall x. UpdateTable -> Rep UpdateTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateTable x -> UpdateTable
$cfrom :: forall x. UpdateTable -> Rep UpdateTable x
Generic)
instance A.ToJSON UpdateTable where
    toJSON :: UpdateTable -> Value
toJSON UpdateTable
a = [Pair] -> Value
A.object
        forall a b. (a -> b) -> a -> b
$ Key
"TableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UpdateTable -> Text
updateTableName UpdateTable
a
        forall a. a -> [a] -> [a]
: Key
"ProvisionedThroughput" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= UpdateTable -> ProvisionedThroughput
updateProvisionedThroughput UpdateTable
a
        forall a. a -> [a] -> [a]
: case UpdateTable -> [GlobalSecondaryIndexUpdate]
updateGlobalSecondaryIndexUpdates UpdateTable
a of
            [] -> []
            [GlobalSecondaryIndexUpdate]
l -> [ Key
"GlobalSecondaryIndexUpdates" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [GlobalSecondaryIndexUpdate]
l ]

-- | ServiceConfiguration: 'DdbConfiguration'
instance SignQuery UpdateTable where
    type ServiceConfiguration UpdateTable = DdbConfiguration
    signQuery :: forall queryType.
UpdateTable
-> ServiceConfiguration UpdateTable queryType
-> SignatureData
-> SignedQuery
signQuery = forall a qt.
ToJSON a =>
ByteString
-> a -> DdbConfiguration qt -> SignatureData -> SignedQuery
ddbSignQuery ByteString
"UpdateTable"

newtype UpdateTableResult = UpdateTableResult { UpdateTableResult -> TableDescription
uStatus :: TableDescription }
    deriving (Int -> UpdateTableResult -> String -> String
[UpdateTableResult] -> String -> String
UpdateTableResult -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [UpdateTableResult] -> String -> String
$cshowList :: [UpdateTableResult] -> String -> String
show :: UpdateTableResult -> String
$cshow :: UpdateTableResult -> String
showsPrec :: Int -> UpdateTableResult -> String -> String
$cshowsPrec :: Int -> UpdateTableResult -> String -> String
Show, Value -> Parser [UpdateTableResult]
Value -> Parser UpdateTableResult
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [UpdateTableResult]
$cparseJSONList :: Value -> Parser [UpdateTableResult]
parseJSON :: Value -> Parser UpdateTableResult
$cparseJSON :: Value -> Parser UpdateTableResult
A.FromJSON)
-- ResponseConsumer can't be derived
instance ResponseConsumer r UpdateTableResult where
    type ResponseMetadata UpdateTableResult = DdbResponse
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata UpdateTableResult)
-> HTTPResponseConsumer UpdateTableResult
responseConsumer Request
_ r
_ = forall a. FromJSON a => IORef DdbResponse -> HTTPResponseConsumer a
ddbResponseConsumer
instance AsMemoryResponse UpdateTableResult where
    type MemoryResponse UpdateTableResult = TableDescription
    loadToMemory :: UpdateTableResult
-> ResourceT IO (MemoryResponse UpdateTableResult)
loadToMemory = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. UpdateTableResult -> TableDescription
uStatus

instance Transaction UpdateTable UpdateTableResult

data DeleteTable
    = DeleteTable {
        DeleteTable -> Text
deleteTableName :: T.Text
      }
    deriving (Int -> DeleteTable -> String -> String
[DeleteTable] -> String -> String
DeleteTable -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [DeleteTable] -> String -> String
$cshowList :: [DeleteTable] -> String -> String
show :: DeleteTable -> String
$cshow :: DeleteTable -> String
showsPrec :: Int -> DeleteTable -> String -> String
$cshowsPrec :: Int -> DeleteTable -> String -> String
Show, forall x. Rep DeleteTable x -> DeleteTable
forall x. DeleteTable -> Rep DeleteTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteTable x -> DeleteTable
$cfrom :: forall x. DeleteTable -> Rep DeleteTable x
Generic)
instance A.ToJSON DeleteTable where
    toJSON :: DeleteTable -> Value
toJSON = forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
A.genericToJSON forall a b. (a -> b) -> a -> b
$ Int -> Options
dropOpt Int
6

-- | ServiceConfiguration: 'DdbConfiguration'
instance SignQuery DeleteTable where
    type ServiceConfiguration DeleteTable = DdbConfiguration
    signQuery :: forall queryType.
DeleteTable
-> ServiceConfiguration DeleteTable queryType
-> SignatureData
-> SignedQuery
signQuery = forall a qt.
ToJSON a =>
ByteString
-> a -> DdbConfiguration qt -> SignatureData -> SignedQuery
ddbSignQuery ByteString
"DeleteTable"

newtype DeleteTableResult = DeleteTableResult { DeleteTableResult -> TableDescription
dStatus :: TableDescription }
    deriving (Int -> DeleteTableResult -> String -> String
[DeleteTableResult] -> String -> String
DeleteTableResult -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [DeleteTableResult] -> String -> String
$cshowList :: [DeleteTableResult] -> String -> String
show :: DeleteTableResult -> String
$cshow :: DeleteTableResult -> String
showsPrec :: Int -> DeleteTableResult -> String -> String
$cshowsPrec :: Int -> DeleteTableResult -> String -> String
Show, Value -> Parser [DeleteTableResult]
Value -> Parser DeleteTableResult
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [DeleteTableResult]
$cparseJSONList :: Value -> Parser [DeleteTableResult]
parseJSON :: Value -> Parser DeleteTableResult
$cparseJSON :: Value -> Parser DeleteTableResult
A.FromJSON)
-- ResponseConsumer can't be derived
instance ResponseConsumer r DeleteTableResult where
    type ResponseMetadata DeleteTableResult = DdbResponse
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata DeleteTableResult)
-> HTTPResponseConsumer DeleteTableResult
responseConsumer Request
_ r
_ = forall a. FromJSON a => IORef DdbResponse -> HTTPResponseConsumer a
ddbResponseConsumer
instance AsMemoryResponse DeleteTableResult where
    type MemoryResponse DeleteTableResult = TableDescription
    loadToMemory :: DeleteTableResult
-> ResourceT IO (MemoryResponse DeleteTableResult)
loadToMemory = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. DeleteTableResult -> TableDescription
dStatus

instance Transaction DeleteTable DeleteTableResult

-- | TODO: currently this does not support restarting a cutoff query because of size.
data ListTables = ListTables
    deriving (Int -> ListTables -> String -> String
[ListTables] -> String -> String
ListTables -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [ListTables] -> String -> String
$cshowList :: [ListTables] -> String -> String
show :: ListTables -> String
$cshow :: ListTables -> String
showsPrec :: Int -> ListTables -> String -> String
$cshowsPrec :: Int -> ListTables -> String -> String
Show)
instance A.ToJSON ListTables where
    toJSON :: ListTables -> Value
toJSON ListTables
_ = [Pair] -> Value
A.object []
-- | ServiceConfiguration: 'DdbConfiguration'
instance SignQuery ListTables where
    type ServiceConfiguration ListTables = DdbConfiguration
    signQuery :: forall queryType.
ListTables
-> ServiceConfiguration ListTables queryType
-> SignatureData
-> SignedQuery
signQuery = forall a qt.
ToJSON a =>
ByteString
-> a -> DdbConfiguration qt -> SignatureData -> SignedQuery
ddbSignQuery ByteString
"ListTables"

newtype ListTablesResult
    = ListTablesResult {
        ListTablesResult -> [Text]
tableNames :: [T.Text]
      }
    deriving (Int -> ListTablesResult -> String -> String
[ListTablesResult] -> String -> String
ListTablesResult -> String
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [ListTablesResult] -> String -> String
$cshowList :: [ListTablesResult] -> String -> String
show :: ListTablesResult -> String
$cshow :: ListTablesResult -> String
showsPrec :: Int -> ListTablesResult -> String -> String
$cshowsPrec :: Int -> ListTablesResult -> String -> String
Show, forall x. Rep ListTablesResult x -> ListTablesResult
forall x. ListTablesResult -> Rep ListTablesResult x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTablesResult x -> ListTablesResult
$cfrom :: forall x. ListTablesResult -> Rep ListTablesResult x
Generic)
instance A.FromJSON ListTablesResult where
    parseJSON :: Value -> Parser ListTablesResult
parseJSON = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
A.genericParseJSON Options
capitalizeOpt
instance ResponseConsumer r ListTablesResult where
    type ResponseMetadata ListTablesResult = DdbResponse
    responseConsumer :: Request
-> r
-> IORef (ResponseMetadata ListTablesResult)
-> HTTPResponseConsumer ListTablesResult
responseConsumer Request
_ r
_ = forall a. FromJSON a => IORef DdbResponse -> HTTPResponseConsumer a
ddbResponseConsumer
instance AsMemoryResponse ListTablesResult where
    type MemoryResponse ListTablesResult = [T.Text]
    loadToMemory :: ListTablesResult -> ResourceT IO (MemoryResponse ListTablesResult)
loadToMemory = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. ListTablesResult -> [Text]
tableNames

instance Transaction ListTables ListTablesResult