module Hasura.RQL.Types.HealthCheck
  ( HealthCheckConfig (..),
    HealthCheckTestSql (..),
    HealthCheckInterval (..),
    HealthCheckRetries (..),
    HealthCheckRetryInterval (..),
    HealthCheckTimeout (..),
    defaultHealthCheckTestSql,
    healthCheckConfigCodec,
  )
where

import Autodocodec hiding (object, (.=))
import Autodocodec qualified as AC
import Data.Aeson.Extended
import Data.Aeson.Types (parseFail)
import Hasura.Prelude
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendTag (backendPrefix)
import Hasura.RQL.Types.HealthCheckImplementation (HealthCheckImplementation (HealthCheckImplementation, _hciDefaultTest, _hciTestCodec))

newtype HealthCheckTestSql = HealthCheckTestSql
  { HealthCheckTestSql -> Text
_hctSql :: Text
  }
  deriving (HealthCheckTestSql -> HealthCheckTestSql -> Bool
(HealthCheckTestSql -> HealthCheckTestSql -> Bool)
-> (HealthCheckTestSql -> HealthCheckTestSql -> Bool)
-> Eq HealthCheckTestSql
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HealthCheckTestSql -> HealthCheckTestSql -> Bool
== :: HealthCheckTestSql -> HealthCheckTestSql -> Bool
$c/= :: HealthCheckTestSql -> HealthCheckTestSql -> Bool
/= :: HealthCheckTestSql -> HealthCheckTestSql -> Bool
Eq, (forall x. HealthCheckTestSql -> Rep HealthCheckTestSql x)
-> (forall x. Rep HealthCheckTestSql x -> HealthCheckTestSql)
-> Generic HealthCheckTestSql
forall x. Rep HealthCheckTestSql x -> HealthCheckTestSql
forall x. HealthCheckTestSql -> Rep HealthCheckTestSql x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HealthCheckTestSql -> Rep HealthCheckTestSql x
from :: forall x. HealthCheckTestSql -> Rep HealthCheckTestSql x
$cto :: forall x. Rep HealthCheckTestSql x -> HealthCheckTestSql
to :: forall x. Rep HealthCheckTestSql x -> HealthCheckTestSql
Generic, Int -> HealthCheckTestSql -> ShowS
[HealthCheckTestSql] -> ShowS
HealthCheckTestSql -> String
(Int -> HealthCheckTestSql -> ShowS)
-> (HealthCheckTestSql -> String)
-> ([HealthCheckTestSql] -> ShowS)
-> Show HealthCheckTestSql
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HealthCheckTestSql -> ShowS
showsPrec :: Int -> HealthCheckTestSql -> ShowS
$cshow :: HealthCheckTestSql -> String
show :: HealthCheckTestSql -> String
$cshowList :: [HealthCheckTestSql] -> ShowS
showList :: [HealthCheckTestSql] -> ShowS
Show, Eq HealthCheckTestSql
Eq HealthCheckTestSql
-> (Int -> HealthCheckTestSql -> Int)
-> (HealthCheckTestSql -> Int)
-> Hashable HealthCheckTestSql
Int -> HealthCheckTestSql -> Int
HealthCheckTestSql -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
$chashWithSalt :: Int -> HealthCheckTestSql -> Int
hashWithSalt :: Int -> HealthCheckTestSql -> Int
$chash :: HealthCheckTestSql -> Int
hash :: HealthCheckTestSql -> Int
Hashable, HealthCheckTestSql -> ()
(HealthCheckTestSql -> ()) -> NFData HealthCheckTestSql
forall a. (a -> ()) -> NFData a
$crnf :: HealthCheckTestSql -> ()
rnf :: HealthCheckTestSql -> ()
NFData)

instance HasCodec HealthCheckTestSql where
  codec :: JSONCodec HealthCheckTestSql
codec =
    Text
-> ObjectCodec HealthCheckTestSql HealthCheckTestSql
-> JSONCodec HealthCheckTestSql
forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
AC.object Text
"HealthCheckTestSql"
      (ObjectCodec HealthCheckTestSql HealthCheckTestSql
 -> JSONCodec HealthCheckTestSql)
-> ObjectCodec HealthCheckTestSql HealthCheckTestSql
-> JSONCodec HealthCheckTestSql
forall a b. (a -> b) -> a -> b
$ Text -> HealthCheckTestSql
HealthCheckTestSql
      (Text -> HealthCheckTestSql)
-> Codec Object HealthCheckTestSql Text
-> ObjectCodec HealthCheckTestSql HealthCheckTestSql
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Text -> ObjectCodec Text Text
forall output.
HasCodec output =>
Text -> output -> ObjectCodec output output
optionalFieldWithDefault' Text
"sql" Text
defaultTestSql
      ObjectCodec Text Text
-> (HealthCheckTestSql -> Text)
-> Codec Object HealthCheckTestSql Text
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
AC..= HealthCheckTestSql -> Text
_hctSql

instance ToJSON HealthCheckTestSql where
  toJSON :: HealthCheckTestSql -> Value
toJSON = Options -> HealthCheckTestSql -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON {omitNothingFields :: Bool
omitNothingFields = Bool
True}

instance FromJSON HealthCheckTestSql where
  parseJSON :: Value -> Parser HealthCheckTestSql
parseJSON = String
-> (Object -> Parser HealthCheckTestSql)
-> Value
-> Parser HealthCheckTestSql
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Object" ((Object -> Parser HealthCheckTestSql)
 -> Value -> Parser HealthCheckTestSql)
-> (Object -> Parser HealthCheckTestSql)
-> Value
-> Parser HealthCheckTestSql
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    Text -> HealthCheckTestSql
HealthCheckTestSql (Text -> HealthCheckTestSql)
-> Parser Text -> Parser HealthCheckTestSql
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"sql" Parser (Maybe Text) -> Text -> Parser Text
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
defaultTestSql

defaultHealthCheckTestSql :: HealthCheckTestSql
defaultHealthCheckTestSql :: HealthCheckTestSql
defaultHealthCheckTestSql = Text -> HealthCheckTestSql
HealthCheckTestSql Text
defaultTestSql

defaultTestSql :: Text
defaultTestSql :: Text
defaultTestSql = Text
"SELECT 1"

newtype HealthCheckInterval = HealthCheckInterval {HealthCheckInterval -> Seconds
unHealthCheckInterval :: Seconds}
  deriving (HealthCheckInterval -> HealthCheckInterval -> Bool
(HealthCheckInterval -> HealthCheckInterval -> Bool)
-> (HealthCheckInterval -> HealthCheckInterval -> Bool)
-> Eq HealthCheckInterval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HealthCheckInterval -> HealthCheckInterval -> Bool
== :: HealthCheckInterval -> HealthCheckInterval -> Bool
$c/= :: HealthCheckInterval -> HealthCheckInterval -> Bool
/= :: HealthCheckInterval -> HealthCheckInterval -> Bool
Eq, (forall x. HealthCheckInterval -> Rep HealthCheckInterval x)
-> (forall x. Rep HealthCheckInterval x -> HealthCheckInterval)
-> Generic HealthCheckInterval
forall x. Rep HealthCheckInterval x -> HealthCheckInterval
forall x. HealthCheckInterval -> Rep HealthCheckInterval x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HealthCheckInterval -> Rep HealthCheckInterval x
from :: forall x. HealthCheckInterval -> Rep HealthCheckInterval x
$cto :: forall x. Rep HealthCheckInterval x -> HealthCheckInterval
to :: forall x. Rep HealthCheckInterval x -> HealthCheckInterval
Generic, Int -> HealthCheckInterval -> ShowS
[HealthCheckInterval] -> ShowS
HealthCheckInterval -> String
(Int -> HealthCheckInterval -> ShowS)
-> (HealthCheckInterval -> String)
-> ([HealthCheckInterval] -> ShowS)
-> Show HealthCheckInterval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HealthCheckInterval -> ShowS
showsPrec :: Int -> HealthCheckInterval -> ShowS
$cshow :: HealthCheckInterval -> String
show :: HealthCheckInterval -> String
$cshowList :: [HealthCheckInterval] -> ShowS
showList :: [HealthCheckInterval] -> ShowS
Show, [HealthCheckInterval] -> Value
[HealthCheckInterval] -> Encoding
HealthCheckInterval -> Value
HealthCheckInterval -> Encoding
(HealthCheckInterval -> Value)
-> (HealthCheckInterval -> Encoding)
-> ([HealthCheckInterval] -> Value)
-> ([HealthCheckInterval] -> Encoding)
-> ToJSON HealthCheckInterval
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: HealthCheckInterval -> Value
toJSON :: HealthCheckInterval -> Value
$ctoEncoding :: HealthCheckInterval -> Encoding
toEncoding :: HealthCheckInterval -> Encoding
$ctoJSONList :: [HealthCheckInterval] -> Value
toJSONList :: [HealthCheckInterval] -> Value
$ctoEncodingList :: [HealthCheckInterval] -> Encoding
toEncodingList :: [HealthCheckInterval] -> Encoding
ToJSON, Value -> Parser [HealthCheckInterval]
Value -> Parser HealthCheckInterval
(Value -> Parser HealthCheckInterval)
-> (Value -> Parser [HealthCheckInterval])
-> FromJSON HealthCheckInterval
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser HealthCheckInterval
parseJSON :: Value -> Parser HealthCheckInterval
$cparseJSONList :: Value -> Parser [HealthCheckInterval]
parseJSONList :: Value -> Parser [HealthCheckInterval]
FromJSON)

instance HasCodec HealthCheckInterval where
  codec :: JSONCodec HealthCheckInterval
codec = (Seconds -> HealthCheckInterval)
-> (HealthCheckInterval -> Seconds)
-> Codec Value Seconds Seconds
-> JSONCodec HealthCheckInterval
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Seconds -> HealthCheckInterval
HealthCheckInterval HealthCheckInterval -> Seconds
unHealthCheckInterval Codec Value Seconds Seconds
forall value. HasCodec value => JSONCodec value
codec

newtype HealthCheckRetries = HealthCheckRetries {HealthCheckRetries -> Int
unHealthCheckRetries :: Int}
  deriving (HealthCheckRetries -> HealthCheckRetries -> Bool
(HealthCheckRetries -> HealthCheckRetries -> Bool)
-> (HealthCheckRetries -> HealthCheckRetries -> Bool)
-> Eq HealthCheckRetries
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HealthCheckRetries -> HealthCheckRetries -> Bool
== :: HealthCheckRetries -> HealthCheckRetries -> Bool
$c/= :: HealthCheckRetries -> HealthCheckRetries -> Bool
/= :: HealthCheckRetries -> HealthCheckRetries -> Bool
Eq, (forall x. HealthCheckRetries -> Rep HealthCheckRetries x)
-> (forall x. Rep HealthCheckRetries x -> HealthCheckRetries)
-> Generic HealthCheckRetries
forall x. Rep HealthCheckRetries x -> HealthCheckRetries
forall x. HealthCheckRetries -> Rep HealthCheckRetries x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HealthCheckRetries -> Rep HealthCheckRetries x
from :: forall x. HealthCheckRetries -> Rep HealthCheckRetries x
$cto :: forall x. Rep HealthCheckRetries x -> HealthCheckRetries
to :: forall x. Rep HealthCheckRetries x -> HealthCheckRetries
Generic, Int -> HealthCheckRetries -> ShowS
[HealthCheckRetries] -> ShowS
HealthCheckRetries -> String
(Int -> HealthCheckRetries -> ShowS)
-> (HealthCheckRetries -> String)
-> ([HealthCheckRetries] -> ShowS)
-> Show HealthCheckRetries
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HealthCheckRetries -> ShowS
showsPrec :: Int -> HealthCheckRetries -> ShowS
$cshow :: HealthCheckRetries -> String
show :: HealthCheckRetries -> String
$cshowList :: [HealthCheckRetries] -> ShowS
showList :: [HealthCheckRetries] -> ShowS
Show, Value -> Parser [HealthCheckRetries]
Value -> Parser HealthCheckRetries
(Value -> Parser HealthCheckRetries)
-> (Value -> Parser [HealthCheckRetries])
-> FromJSON HealthCheckRetries
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser HealthCheckRetries
parseJSON :: Value -> Parser HealthCheckRetries
$cparseJSONList :: Value -> Parser [HealthCheckRetries]
parseJSONList :: Value -> Parser [HealthCheckRetries]
FromJSON, [HealthCheckRetries] -> Value
[HealthCheckRetries] -> Encoding
HealthCheckRetries -> Value
HealthCheckRetries -> Encoding
(HealthCheckRetries -> Value)
-> (HealthCheckRetries -> Encoding)
-> ([HealthCheckRetries] -> Value)
-> ([HealthCheckRetries] -> Encoding)
-> ToJSON HealthCheckRetries
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: HealthCheckRetries -> Value
toJSON :: HealthCheckRetries -> Value
$ctoEncoding :: HealthCheckRetries -> Encoding
toEncoding :: HealthCheckRetries -> Encoding
$ctoJSONList :: [HealthCheckRetries] -> Value
toJSONList :: [HealthCheckRetries] -> Value
$ctoEncodingList :: [HealthCheckRetries] -> Encoding
toEncodingList :: [HealthCheckRetries] -> Encoding
ToJSON)

instance HasCodec HealthCheckRetries where
  codec :: JSONCodec HealthCheckRetries
codec = (Int -> HealthCheckRetries)
-> (HealthCheckRetries -> Int)
-> Codec Value Int Int
-> JSONCodec HealthCheckRetries
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Int -> HealthCheckRetries
HealthCheckRetries HealthCheckRetries -> Int
unHealthCheckRetries Codec Value Int Int
forall value. HasCodec value => JSONCodec value
codec

newtype HealthCheckRetryInterval = HealthCheckRetryInterval {HealthCheckRetryInterval -> Seconds
unHealthCheckRetryInterval :: Seconds}
  deriving (HealthCheckRetryInterval -> HealthCheckRetryInterval -> Bool
(HealthCheckRetryInterval -> HealthCheckRetryInterval -> Bool)
-> (HealthCheckRetryInterval -> HealthCheckRetryInterval -> Bool)
-> Eq HealthCheckRetryInterval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HealthCheckRetryInterval -> HealthCheckRetryInterval -> Bool
== :: HealthCheckRetryInterval -> HealthCheckRetryInterval -> Bool
$c/= :: HealthCheckRetryInterval -> HealthCheckRetryInterval -> Bool
/= :: HealthCheckRetryInterval -> HealthCheckRetryInterval -> Bool
Eq, (forall x.
 HealthCheckRetryInterval -> Rep HealthCheckRetryInterval x)
-> (forall x.
    Rep HealthCheckRetryInterval x -> HealthCheckRetryInterval)
-> Generic HealthCheckRetryInterval
forall x.
Rep HealthCheckRetryInterval x -> HealthCheckRetryInterval
forall x.
HealthCheckRetryInterval -> Rep HealthCheckRetryInterval x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x.
HealthCheckRetryInterval -> Rep HealthCheckRetryInterval x
from :: forall x.
HealthCheckRetryInterval -> Rep HealthCheckRetryInterval x
$cto :: forall x.
Rep HealthCheckRetryInterval x -> HealthCheckRetryInterval
to :: forall x.
Rep HealthCheckRetryInterval x -> HealthCheckRetryInterval
Generic, Int -> HealthCheckRetryInterval -> ShowS
[HealthCheckRetryInterval] -> ShowS
HealthCheckRetryInterval -> String
(Int -> HealthCheckRetryInterval -> ShowS)
-> (HealthCheckRetryInterval -> String)
-> ([HealthCheckRetryInterval] -> ShowS)
-> Show HealthCheckRetryInterval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HealthCheckRetryInterval -> ShowS
showsPrec :: Int -> HealthCheckRetryInterval -> ShowS
$cshow :: HealthCheckRetryInterval -> String
show :: HealthCheckRetryInterval -> String
$cshowList :: [HealthCheckRetryInterval] -> ShowS
showList :: [HealthCheckRetryInterval] -> ShowS
Show, [HealthCheckRetryInterval] -> Value
[HealthCheckRetryInterval] -> Encoding
HealthCheckRetryInterval -> Value
HealthCheckRetryInterval -> Encoding
(HealthCheckRetryInterval -> Value)
-> (HealthCheckRetryInterval -> Encoding)
-> ([HealthCheckRetryInterval] -> Value)
-> ([HealthCheckRetryInterval] -> Encoding)
-> ToJSON HealthCheckRetryInterval
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: HealthCheckRetryInterval -> Value
toJSON :: HealthCheckRetryInterval -> Value
$ctoEncoding :: HealthCheckRetryInterval -> Encoding
toEncoding :: HealthCheckRetryInterval -> Encoding
$ctoJSONList :: [HealthCheckRetryInterval] -> Value
toJSONList :: [HealthCheckRetryInterval] -> Value
$ctoEncodingList :: [HealthCheckRetryInterval] -> Encoding
toEncodingList :: [HealthCheckRetryInterval] -> Encoding
ToJSON, Value -> Parser [HealthCheckRetryInterval]
Value -> Parser HealthCheckRetryInterval
(Value -> Parser HealthCheckRetryInterval)
-> (Value -> Parser [HealthCheckRetryInterval])
-> FromJSON HealthCheckRetryInterval
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser HealthCheckRetryInterval
parseJSON :: Value -> Parser HealthCheckRetryInterval
$cparseJSONList :: Value -> Parser [HealthCheckRetryInterval]
parseJSONList :: Value -> Parser [HealthCheckRetryInterval]
FromJSON)

instance HasCodec HealthCheckRetryInterval where
  codec :: JSONCodec HealthCheckRetryInterval
codec = (Seconds -> HealthCheckRetryInterval)
-> (HealthCheckRetryInterval -> Seconds)
-> Codec Value Seconds Seconds
-> JSONCodec HealthCheckRetryInterval
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Seconds -> HealthCheckRetryInterval
HealthCheckRetryInterval HealthCheckRetryInterval -> Seconds
unHealthCheckRetryInterval Codec Value Seconds Seconds
forall value. HasCodec value => JSONCodec value
codec

newtype HealthCheckTimeout = HealthCheckTimeout {HealthCheckTimeout -> Seconds
unHealthCheckTimeout :: Seconds}
  deriving (HealthCheckTimeout -> HealthCheckTimeout -> Bool
(HealthCheckTimeout -> HealthCheckTimeout -> Bool)
-> (HealthCheckTimeout -> HealthCheckTimeout -> Bool)
-> Eq HealthCheckTimeout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HealthCheckTimeout -> HealthCheckTimeout -> Bool
== :: HealthCheckTimeout -> HealthCheckTimeout -> Bool
$c/= :: HealthCheckTimeout -> HealthCheckTimeout -> Bool
/= :: HealthCheckTimeout -> HealthCheckTimeout -> Bool
Eq, (forall x. HealthCheckTimeout -> Rep HealthCheckTimeout x)
-> (forall x. Rep HealthCheckTimeout x -> HealthCheckTimeout)
-> Generic HealthCheckTimeout
forall x. Rep HealthCheckTimeout x -> HealthCheckTimeout
forall x. HealthCheckTimeout -> Rep HealthCheckTimeout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HealthCheckTimeout -> Rep HealthCheckTimeout x
from :: forall x. HealthCheckTimeout -> Rep HealthCheckTimeout x
$cto :: forall x. Rep HealthCheckTimeout x -> HealthCheckTimeout
to :: forall x. Rep HealthCheckTimeout x -> HealthCheckTimeout
Generic, Int -> HealthCheckTimeout -> ShowS
[HealthCheckTimeout] -> ShowS
HealthCheckTimeout -> String
(Int -> HealthCheckTimeout -> ShowS)
-> (HealthCheckTimeout -> String)
-> ([HealthCheckTimeout] -> ShowS)
-> Show HealthCheckTimeout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HealthCheckTimeout -> ShowS
showsPrec :: Int -> HealthCheckTimeout -> ShowS
$cshow :: HealthCheckTimeout -> String
show :: HealthCheckTimeout -> String
$cshowList :: [HealthCheckTimeout] -> ShowS
showList :: [HealthCheckTimeout] -> ShowS
Show, Value -> Parser [HealthCheckTimeout]
Value -> Parser HealthCheckTimeout
(Value -> Parser HealthCheckTimeout)
-> (Value -> Parser [HealthCheckTimeout])
-> FromJSON HealthCheckTimeout
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser HealthCheckTimeout
parseJSON :: Value -> Parser HealthCheckTimeout
$cparseJSONList :: Value -> Parser [HealthCheckTimeout]
parseJSONList :: Value -> Parser [HealthCheckTimeout]
FromJSON, [HealthCheckTimeout] -> Value
[HealthCheckTimeout] -> Encoding
HealthCheckTimeout -> Value
HealthCheckTimeout -> Encoding
(HealthCheckTimeout -> Value)
-> (HealthCheckTimeout -> Encoding)
-> ([HealthCheckTimeout] -> Value)
-> ([HealthCheckTimeout] -> Encoding)
-> ToJSON HealthCheckTimeout
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: HealthCheckTimeout -> Value
toJSON :: HealthCheckTimeout -> Value
$ctoEncoding :: HealthCheckTimeout -> Encoding
toEncoding :: HealthCheckTimeout -> Encoding
$ctoJSONList :: [HealthCheckTimeout] -> Value
toJSONList :: [HealthCheckTimeout] -> Value
$ctoEncodingList :: [HealthCheckTimeout] -> Encoding
toEncodingList :: [HealthCheckTimeout] -> Encoding
ToJSON)

instance HasCodec HealthCheckTimeout where
  codec :: JSONCodec HealthCheckTimeout
codec = (Seconds -> HealthCheckTimeout)
-> (HealthCheckTimeout -> Seconds)
-> Codec Value Seconds Seconds
-> JSONCodec HealthCheckTimeout
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec Seconds -> HealthCheckTimeout
HealthCheckTimeout HealthCheckTimeout -> Seconds
unHealthCheckTimeout Codec Value Seconds Seconds
forall value. HasCodec value => JSONCodec value
codec

data HealthCheckConfig b = HealthCheckConfig
  { forall (b :: BackendType). HealthCheckConfig b -> HealthCheckTest b
_hccTest :: HealthCheckTest b,
    forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckInterval
_hccInterval :: HealthCheckInterval,
    forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckRetries
_hccRetries :: HealthCheckRetries,
    forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckRetryInterval
_hccRetryInterval :: HealthCheckRetryInterval,
    forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckTimeout
_hccTimeout :: HealthCheckTimeout
  }
  deriving ((forall x. HealthCheckConfig b -> Rep (HealthCheckConfig b) x)
-> (forall x. Rep (HealthCheckConfig b) x -> HealthCheckConfig b)
-> Generic (HealthCheckConfig b)
forall x. Rep (HealthCheckConfig b) x -> HealthCheckConfig b
forall x. HealthCheckConfig b -> Rep (HealthCheckConfig b) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (b :: BackendType) x.
Rep (HealthCheckConfig b) x -> HealthCheckConfig b
forall (b :: BackendType) x.
HealthCheckConfig b -> Rep (HealthCheckConfig b) x
$cfrom :: forall (b :: BackendType) x.
HealthCheckConfig b -> Rep (HealthCheckConfig b) x
from :: forall x. HealthCheckConfig b -> Rep (HealthCheckConfig b) x
$cto :: forall (b :: BackendType) x.
Rep (HealthCheckConfig b) x -> HealthCheckConfig b
to :: forall x. Rep (HealthCheckConfig b) x -> HealthCheckConfig b
Generic)

deriving instance (Backend b) => Eq (HealthCheckConfig b)

deriving instance (Backend b) => Show (HealthCheckConfig b)

instance (Backend b) => ToJSON (HealthCheckConfig b) where
  toJSON :: HealthCheckConfig b -> Value
toJSON = Options -> HealthCheckConfig b -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
genericToJSON Options
hasuraJSON {omitNothingFields :: Bool
omitNothingFields = Bool
True}

instance (Backend b) => FromJSON (HealthCheckConfig b) where
  parseJSON :: Value -> Parser (HealthCheckConfig b)
parseJSON = case forall (b :: BackendType).
Backend b =>
Maybe (HealthCheckImplementation (HealthCheckTest b))
healthCheckImplementation @b of
    Just (HealthCheckImplementation {JSONCodec (HealthCheckTest b)
HealthCheckTest b
_hciDefaultTest :: forall healthCheckTest.
HealthCheckImplementation healthCheckTest -> healthCheckTest
_hciTestCodec :: forall healthCheckTest.
HealthCheckImplementation healthCheckTest
-> JSONCodec healthCheckTest
_hciDefaultTest :: HealthCheckTest b
_hciTestCodec :: JSONCodec (HealthCheckTest b)
..}) ->
      String
-> (Object -> Parser (HealthCheckConfig b))
-> Value
-> Parser (HealthCheckConfig b)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Object" ((Object -> Parser (HealthCheckConfig b))
 -> Value -> Parser (HealthCheckConfig b))
-> (Object -> Parser (HealthCheckConfig b))
-> Value
-> Parser (HealthCheckConfig b)
forall a b. (a -> b) -> a -> b
$ \Object
o ->
        HealthCheckTest b
-> HealthCheckInterval
-> HealthCheckRetries
-> HealthCheckRetryInterval
-> HealthCheckTimeout
-> HealthCheckConfig b
forall (b :: BackendType).
HealthCheckTest b
-> HealthCheckInterval
-> HealthCheckRetries
-> HealthCheckRetryInterval
-> HealthCheckTimeout
-> HealthCheckConfig b
HealthCheckConfig
          (HealthCheckTest b
 -> HealthCheckInterval
 -> HealthCheckRetries
 -> HealthCheckRetryInterval
 -> HealthCheckTimeout
 -> HealthCheckConfig b)
-> Parser (HealthCheckTest b)
-> Parser
     (HealthCheckInterval
      -> HealthCheckRetries
      -> HealthCheckRetryInterval
      -> HealthCheckTimeout
      -> HealthCheckConfig b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o
          Object -> Key -> Parser (Maybe (HealthCheckTest b))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"test"
          Parser (Maybe (HealthCheckTest b))
-> HealthCheckTest b -> Parser (HealthCheckTest b)
forall a. Parser (Maybe a) -> a -> Parser a
.!= HealthCheckTest b
_hciDefaultTest
          Parser
  (HealthCheckInterval
   -> HealthCheckRetries
   -> HealthCheckRetryInterval
   -> HealthCheckTimeout
   -> HealthCheckConfig b)
-> Parser HealthCheckInterval
-> Parser
     (HealthCheckRetries
      -> HealthCheckRetryInterval
      -> HealthCheckTimeout
      -> HealthCheckConfig b)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o
          Object -> Key -> Parser HealthCheckInterval
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"interval"
          Parser
  (HealthCheckRetries
   -> HealthCheckRetryInterval
   -> HealthCheckTimeout
   -> HealthCheckConfig b)
-> Parser HealthCheckRetries
-> Parser
     (HealthCheckRetryInterval
      -> HealthCheckTimeout -> HealthCheckConfig b)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o
          Object -> Key -> Parser (Maybe HealthCheckRetries)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"retries"
          Parser (Maybe HealthCheckRetries)
-> HealthCheckRetries -> Parser HealthCheckRetries
forall a. Parser (Maybe a) -> a -> Parser a
.!= HealthCheckRetries
defaultRetries
          Parser
  (HealthCheckRetryInterval
   -> HealthCheckTimeout -> HealthCheckConfig b)
-> Parser HealthCheckRetryInterval
-> Parser (HealthCheckTimeout -> HealthCheckConfig b)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o
          Object -> Key -> Parser (Maybe HealthCheckRetryInterval)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"retry_interval"
          Parser (Maybe HealthCheckRetryInterval)
-> HealthCheckRetryInterval -> Parser HealthCheckRetryInterval
forall a. Parser (Maybe a) -> a -> Parser a
.!= HealthCheckRetryInterval
defaultRetryInterval
          Parser (HealthCheckTimeout -> HealthCheckConfig b)
-> Parser HealthCheckTimeout -> Parser (HealthCheckConfig b)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o
          Object -> Key -> Parser (Maybe HealthCheckTimeout)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"timeout"
          Parser (Maybe HealthCheckTimeout)
-> HealthCheckTimeout -> Parser HealthCheckTimeout
forall a. Parser (Maybe a) -> a -> Parser a
.!= HealthCheckTimeout
defaultTimeout
    Maybe (HealthCheckImplementation (HealthCheckTest b))
Nothing -> \Value
_ ->
      String -> Parser (HealthCheckConfig b)
forall a. String -> Parser a
parseFail
        String
"cannot deserialize health check config because backend does not implement health checks"

healthCheckConfigCodec ::
  forall b.
  (Backend b) =>
  HealthCheckImplementation (HealthCheckTest b) ->
  JSONCodec (HealthCheckConfig b)
healthCheckConfigCodec :: forall (b :: BackendType).
Backend b =>
HealthCheckImplementation (HealthCheckTest b)
-> JSONCodec (HealthCheckConfig b)
healthCheckConfigCodec (HealthCheckImplementation {JSONCodec (HealthCheckTest b)
HealthCheckTest b
_hciDefaultTest :: forall healthCheckTest.
HealthCheckImplementation healthCheckTest -> healthCheckTest
_hciTestCodec :: forall healthCheckTest.
HealthCheckImplementation healthCheckTest
-> JSONCodec healthCheckTest
_hciDefaultTest :: HealthCheckTest b
_hciTestCodec :: JSONCodec (HealthCheckTest b)
..}) =
  Text
-> ObjectCodec (HealthCheckConfig b) (HealthCheckConfig b)
-> ValueCodec (HealthCheckConfig b) (HealthCheckConfig b)
forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
AC.object (forall (b :: BackendType). HasTag b => Text
backendPrefix @b Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"HealthCheckConfig")
    (ObjectCodec (HealthCheckConfig b) (HealthCheckConfig b)
 -> ValueCodec (HealthCheckConfig b) (HealthCheckConfig b))
-> ObjectCodec (HealthCheckConfig b) (HealthCheckConfig b)
-> ValueCodec (HealthCheckConfig b) (HealthCheckConfig b)
forall a b. (a -> b) -> a -> b
$ HealthCheckTest b
-> HealthCheckInterval
-> HealthCheckRetries
-> HealthCheckRetryInterval
-> HealthCheckTimeout
-> HealthCheckConfig b
forall (b :: BackendType).
HealthCheckTest b
-> HealthCheckInterval
-> HealthCheckRetries
-> HealthCheckRetryInterval
-> HealthCheckTimeout
-> HealthCheckConfig b
HealthCheckConfig
    (HealthCheckTest b
 -> HealthCheckInterval
 -> HealthCheckRetries
 -> HealthCheckRetryInterval
 -> HealthCheckTimeout
 -> HealthCheckConfig b)
-> Codec Object (HealthCheckConfig b) (HealthCheckTest b)
-> Codec
     Object
     (HealthCheckConfig b)
     (HealthCheckInterval
      -> HealthCheckRetries
      -> HealthCheckRetryInterval
      -> HealthCheckTimeout
      -> HealthCheckConfig b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> JSONCodec (HealthCheckTest b)
-> HealthCheckTest b
-> ObjectCodec (HealthCheckTest b) (HealthCheckTest b)
forall output.
Eq output =>
Text -> JSONCodec output -> output -> ObjectCodec output output
optionalFieldWithOmittedDefaultWith' Text
"test" JSONCodec (HealthCheckTest b)
_hciTestCodec HealthCheckTest b
_hciDefaultTest
    ObjectCodec (HealthCheckTest b) (HealthCheckTest b)
-> (HealthCheckConfig b -> HealthCheckTest b)
-> Codec Object (HealthCheckConfig b) (HealthCheckTest b)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
AC..= HealthCheckConfig b -> HealthCheckTest b
forall (b :: BackendType). HealthCheckConfig b -> HealthCheckTest b
_hccTest
      Codec
  Object
  (HealthCheckConfig b)
  (HealthCheckInterval
   -> HealthCheckRetries
   -> HealthCheckRetryInterval
   -> HealthCheckTimeout
   -> HealthCheckConfig b)
-> Codec Object (HealthCheckConfig b) HealthCheckInterval
-> Codec
     Object
     (HealthCheckConfig b)
     (HealthCheckRetries
      -> HealthCheckRetryInterval
      -> HealthCheckTimeout
      -> HealthCheckConfig b)
forall a b.
Codec Object (HealthCheckConfig b) (a -> b)
-> Codec Object (HealthCheckConfig b) a
-> Codec Object (HealthCheckConfig b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> ObjectCodec HealthCheckInterval HealthCheckInterval
forall output. HasCodec output => Text -> ObjectCodec output output
requiredField' Text
"interval"
    ObjectCodec HealthCheckInterval HealthCheckInterval
-> (HealthCheckConfig b -> HealthCheckInterval)
-> Codec Object (HealthCheckConfig b) HealthCheckInterval
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
AC..= HealthCheckConfig b -> HealthCheckInterval
forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckInterval
_hccInterval
      Codec
  Object
  (HealthCheckConfig b)
  (HealthCheckRetries
   -> HealthCheckRetryInterval
   -> HealthCheckTimeout
   -> HealthCheckConfig b)
-> Codec Object (HealthCheckConfig b) HealthCheckRetries
-> Codec
     Object
     (HealthCheckConfig b)
     (HealthCheckRetryInterval
      -> HealthCheckTimeout -> HealthCheckConfig b)
forall a b.
Codec Object (HealthCheckConfig b) (a -> b)
-> Codec Object (HealthCheckConfig b) a
-> Codec Object (HealthCheckConfig b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> HealthCheckRetries
-> ObjectCodec HealthCheckRetries HealthCheckRetries
forall output.
(Eq output, HasCodec output) =>
Text -> output -> ObjectCodec output output
optionalFieldWithOmittedDefault' Text
"retries" HealthCheckRetries
defaultRetries
    ObjectCodec HealthCheckRetries HealthCheckRetries
-> (HealthCheckConfig b -> HealthCheckRetries)
-> Codec Object (HealthCheckConfig b) HealthCheckRetries
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
AC..= HealthCheckConfig b -> HealthCheckRetries
forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckRetries
_hccRetries
      Codec
  Object
  (HealthCheckConfig b)
  (HealthCheckRetryInterval
   -> HealthCheckTimeout -> HealthCheckConfig b)
-> Codec Object (HealthCheckConfig b) HealthCheckRetryInterval
-> Codec
     Object
     (HealthCheckConfig b)
     (HealthCheckTimeout -> HealthCheckConfig b)
forall a b.
Codec Object (HealthCheckConfig b) (a -> b)
-> Codec Object (HealthCheckConfig b) a
-> Codec Object (HealthCheckConfig b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> HealthCheckRetryInterval
-> ObjectCodec HealthCheckRetryInterval HealthCheckRetryInterval
forall output.
(Eq output, HasCodec output) =>
Text -> output -> ObjectCodec output output
optionalFieldWithOmittedDefault' Text
"retry_interval" HealthCheckRetryInterval
defaultRetryInterval
    ObjectCodec HealthCheckRetryInterval HealthCheckRetryInterval
-> (HealthCheckConfig b -> HealthCheckRetryInterval)
-> Codec Object (HealthCheckConfig b) HealthCheckRetryInterval
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
AC..= HealthCheckConfig b -> HealthCheckRetryInterval
forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckRetryInterval
_hccRetryInterval
      Codec
  Object
  (HealthCheckConfig b)
  (HealthCheckTimeout -> HealthCheckConfig b)
-> Codec Object (HealthCheckConfig b) HealthCheckTimeout
-> ObjectCodec (HealthCheckConfig b) (HealthCheckConfig b)
forall a b.
Codec Object (HealthCheckConfig b) (a -> b)
-> Codec Object (HealthCheckConfig b) a
-> Codec Object (HealthCheckConfig b) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> HealthCheckTimeout
-> ObjectCodec HealthCheckTimeout HealthCheckTimeout
forall output.
(Eq output, HasCodec output) =>
Text -> output -> ObjectCodec output output
optionalFieldWithOmittedDefault' Text
"timeout" HealthCheckTimeout
defaultTimeout
    ObjectCodec HealthCheckTimeout HealthCheckTimeout
-> (HealthCheckConfig b -> HealthCheckTimeout)
-> Codec Object (HealthCheckConfig b) HealthCheckTimeout
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
AC..= HealthCheckConfig b -> HealthCheckTimeout
forall (b :: BackendType).
HealthCheckConfig b -> HealthCheckTimeout
_hccTimeout

defaultRetries :: HealthCheckRetries
defaultRetries :: HealthCheckRetries
defaultRetries = Int -> HealthCheckRetries
HealthCheckRetries Int
3

defaultRetryInterval :: HealthCheckRetryInterval
defaultRetryInterval :: HealthCheckRetryInterval
defaultRetryInterval = Seconds -> HealthCheckRetryInterval
HealthCheckRetryInterval Seconds
10

defaultTimeout :: HealthCheckTimeout
defaultTimeout :: HealthCheckTimeout
defaultTimeout = Seconds -> HealthCheckTimeout
HealthCheckTimeout Seconds
10