{-# LANGUAGE TemplateHaskell #-}

module Hasura.RQL.Types.Common
  ( RelName (..),
    relNameToTxt,
    fromRemoteRelationship,
    RelType (..),
    relTypeToTxt,
    OID (..),
    FieldName (..),
    Fields,
    InsertOrder (..),
    ToAesonPairs (..),
    InpValInfo (..),
    SystemDefined (..),
    isSystemDefined,
    SQLGenCtx (..),
    successMsg,
    InputWebhook (..),
    ResolvedWebhook (..),
    resolveWebhook,
    Timeout (..),
    defaultActionTimeoutSecs,
    UrlConf (..),
    resolveUrlConf,
    getEnv,
    SourceName (..),
    defaultSource,
    sourceNameToText,
    JsonAggSelect (..),
    MetricsConfig (..),
    emptyMetricsConfig,
    PGConnectionParams (..),
    getPGConnectionStringFromParams,
    getConnOptionsFromConnParams,
    Comment (..),
    commentToMaybeText,
    commentFromMaybeText,
    EnvRecord (..),
    ApolloFederationConfig (..),
    ApolloFederationVersion (..),
    isApolloFedV1enabled,
  )
where

import Autodocodec (HasCodec (codec), dimapCodec)
import Data.Aeson
import Data.Aeson qualified as J
import Data.Aeson.Casing
import Data.Aeson.TH
import Data.Aeson.Types (prependFailure, typeMismatch)
import Data.Bifunctor (bimap)
import Data.Environment qualified as Env
import Data.Scientific (toBoundedInteger)
import Data.Text qualified as T
import Data.Text.Extended
import Data.Text.NonEmpty
import Data.URL.Template
import Database.PG.Query qualified as Q
import Hasura.Base.Error
import Hasura.Base.ErrorValue qualified as ErrorValue
import Hasura.Base.ToErrorValue
import Hasura.EncJSON
import Hasura.GraphQL.Schema.Options qualified as Options
import Hasura.Incremental (Cacheable)
import Hasura.Prelude
import Hasura.RQL.DDL.Headers ()
import Language.GraphQL.Draft.Syntax qualified as G
import Language.Haskell.TH.Syntax qualified as TH
import Network.URI
import PostgreSQL.Binary.Decoding qualified as PD

newtype RelName = RelName {RelName -> NonEmptyText
getRelTxt :: NonEmptyText}
  deriving
    ( Int -> RelName -> ShowS
[RelName] -> ShowS
RelName -> String
(Int -> RelName -> ShowS)
-> (RelName -> String) -> ([RelName] -> ShowS) -> Show RelName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RelName] -> ShowS
$cshowList :: [RelName] -> ShowS
show :: RelName -> String
$cshow :: RelName -> String
showsPrec :: Int -> RelName -> ShowS
$cshowsPrec :: Int -> RelName -> ShowS
Show,
      RelName -> RelName -> Bool
(RelName -> RelName -> Bool)
-> (RelName -> RelName -> Bool) -> Eq RelName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RelName -> RelName -> Bool
$c/= :: RelName -> RelName -> Bool
== :: RelName -> RelName -> Bool
$c== :: RelName -> RelName -> Bool
Eq,
      Eq RelName
Eq RelName
-> (RelName -> RelName -> Ordering)
-> (RelName -> RelName -> Bool)
-> (RelName -> RelName -> Bool)
-> (RelName -> RelName -> Bool)
-> (RelName -> RelName -> Bool)
-> (RelName -> RelName -> RelName)
-> (RelName -> RelName -> RelName)
-> Ord RelName
RelName -> RelName -> Bool
RelName -> RelName -> Ordering
RelName -> RelName -> RelName
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 :: RelName -> RelName -> RelName
$cmin :: RelName -> RelName -> RelName
max :: RelName -> RelName -> RelName
$cmax :: RelName -> RelName -> RelName
>= :: RelName -> RelName -> Bool
$c>= :: RelName -> RelName -> Bool
> :: RelName -> RelName -> Bool
$c> :: RelName -> RelName -> Bool
<= :: RelName -> RelName -> Bool
$c<= :: RelName -> RelName -> Bool
< :: RelName -> RelName -> Bool
$c< :: RelName -> RelName -> Bool
compare :: RelName -> RelName -> Ordering
$ccompare :: RelName -> RelName -> Ordering
$cp1Ord :: Eq RelName
Ord,
      Int -> RelName -> Int
RelName -> Int
(Int -> RelName -> Int) -> (RelName -> Int) -> Hashable RelName
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: RelName -> Int
$chash :: RelName -> Int
hashWithSalt :: Int -> RelName -> Int
$chashWithSalt :: Int -> RelName -> Int
Hashable,
      Value -> Parser [RelName]
Value -> Parser RelName
(Value -> Parser RelName)
-> (Value -> Parser [RelName]) -> FromJSON RelName
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [RelName]
$cparseJSONList :: Value -> Parser [RelName]
parseJSON :: Value -> Parser RelName
$cparseJSON :: Value -> Parser RelName
FromJSON,
      FromJSONKeyFunction [RelName]
FromJSONKeyFunction RelName
FromJSONKeyFunction RelName
-> FromJSONKeyFunction [RelName] -> FromJSONKey RelName
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [RelName]
$cfromJSONKeyList :: FromJSONKeyFunction [RelName]
fromJSONKey :: FromJSONKeyFunction RelName
$cfromJSONKey :: FromJSONKeyFunction RelName
FromJSONKey,
      [RelName] -> Value
[RelName] -> Encoding
RelName -> Value
RelName -> Encoding
(RelName -> Value)
-> (RelName -> Encoding)
-> ([RelName] -> Value)
-> ([RelName] -> Encoding)
-> ToJSON RelName
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [RelName] -> Encoding
$ctoEncodingList :: [RelName] -> Encoding
toJSONList :: [RelName] -> Value
$ctoJSONList :: [RelName] -> Value
toEncoding :: RelName -> Encoding
$ctoEncoding :: RelName -> Encoding
toJSON :: RelName -> Value
$ctoJSON :: RelName -> Value
ToJSON,
      ToJSONKeyFunction [RelName]
ToJSONKeyFunction RelName
ToJSONKeyFunction RelName
-> ToJSONKeyFunction [RelName] -> ToJSONKey RelName
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [RelName]
$ctoJSONKeyList :: ToJSONKeyFunction [RelName]
toJSONKey :: ToJSONKeyFunction RelName
$ctoJSONKey :: ToJSONKeyFunction RelName
ToJSONKey,
      RelName -> PrepArg
(RelName -> PrepArg) -> ToPrepArg RelName
forall a. (a -> PrepArg) -> ToPrepArg a
toPrepVal :: RelName -> PrepArg
$ctoPrepVal :: RelName -> PrepArg
Q.ToPrepArg,
      Maybe ByteString -> Either Text RelName
(Maybe ByteString -> Either Text RelName) -> FromCol RelName
forall a. (Maybe ByteString -> Either Text a) -> FromCol a
fromCol :: Maybe ByteString -> Either Text RelName
$cfromCol :: Maybe ByteString -> Either Text RelName
Q.FromCol,
      (forall x. RelName -> Rep RelName x)
-> (forall x. Rep RelName x -> RelName) -> Generic RelName
forall x. Rep RelName x -> RelName
forall x. RelName -> Rep RelName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RelName x -> RelName
$cfrom :: forall x. RelName -> Rep RelName x
Generic,
      RelName -> ()
(RelName -> ()) -> NFData RelName
forall a. (a -> ()) -> NFData a
rnf :: RelName -> ()
$crnf :: RelName -> ()
NFData,
      Eq RelName
Eq RelName
-> (Accesses -> RelName -> RelName -> Bool) -> Cacheable RelName
Accesses -> RelName -> RelName -> Bool
forall a. Eq a -> (Accesses -> a -> a -> Bool) -> Cacheable a
unchanged :: Accesses -> RelName -> RelName -> Bool
$cunchanged :: Accesses -> RelName -> RelName -> Bool
$cp1Cacheable :: Eq RelName
Cacheable
    )

instance ToTxt RelName where
  toTxt :: RelName -> Text
toTxt = RelName -> Text
relNameToTxt

relNameToTxt :: RelName -> Text
relNameToTxt :: RelName -> Text
relNameToTxt = NonEmptyText -> Text
unNonEmptyText (NonEmptyText -> Text)
-> (RelName -> NonEmptyText) -> RelName -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RelName -> NonEmptyText
getRelTxt

fromRemoteRelationship :: RelName -> FieldName
fromRemoteRelationship :: RelName -> FieldName
fromRemoteRelationship = Text -> FieldName
FieldName (Text -> FieldName) -> (RelName -> Text) -> RelName -> FieldName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RelName -> Text
relNameToTxt

data RelType
  = ObjRel
  | ArrRel
  deriving (Int -> RelType -> ShowS
[RelType] -> ShowS
RelType -> String
(Int -> RelType -> ShowS)
-> (RelType -> String) -> ([RelType] -> ShowS) -> Show RelType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RelType] -> ShowS
$cshowList :: [RelType] -> ShowS
show :: RelType -> String
$cshow :: RelType -> String
showsPrec :: Int -> RelType -> ShowS
$cshowsPrec :: Int -> RelType -> ShowS
Show, RelType -> RelType -> Bool
(RelType -> RelType -> Bool)
-> (RelType -> RelType -> Bool) -> Eq RelType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RelType -> RelType -> Bool
$c/= :: RelType -> RelType -> Bool
== :: RelType -> RelType -> Bool
$c== :: RelType -> RelType -> Bool
Eq, (forall x. RelType -> Rep RelType x)
-> (forall x. Rep RelType x -> RelType) -> Generic RelType
forall x. Rep RelType x -> RelType
forall x. RelType -> Rep RelType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RelType x -> RelType
$cfrom :: forall x. RelType -> Rep RelType x
Generic, Typeable RelType
DataType
Constr
Typeable RelType
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> RelType -> c RelType)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c RelType)
-> (RelType -> Constr)
-> (RelType -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c RelType))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RelType))
-> ((forall b. Data b => b -> b) -> RelType -> RelType)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> RelType -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> RelType -> r)
-> (forall u. (forall d. Data d => d -> u) -> RelType -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> RelType -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> RelType -> m RelType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> RelType -> m RelType)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> RelType -> m RelType)
-> Data RelType
RelType -> DataType
RelType -> Constr
(forall b. Data b => b -> b) -> RelType -> RelType
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RelType -> c RelType
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RelType
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> RelType -> u
forall u. (forall d. Data d => d -> u) -> RelType -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RelType -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RelType -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RelType -> m RelType
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RelType -> m RelType
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RelType
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RelType -> c RelType
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RelType)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RelType)
$cArrRel :: Constr
$cObjRel :: Constr
$tRelType :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> RelType -> m RelType
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RelType -> m RelType
gmapMp :: (forall d. Data d => d -> m d) -> RelType -> m RelType
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> RelType -> m RelType
gmapM :: (forall d. Data d => d -> m d) -> RelType -> m RelType
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> RelType -> m RelType
gmapQi :: Int -> (forall d. Data d => d -> u) -> RelType -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> RelType -> u
gmapQ :: (forall d. Data d => d -> u) -> RelType -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> RelType -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RelType -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> RelType -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RelType -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> RelType -> r
gmapT :: (forall b. Data b => b -> b) -> RelType -> RelType
$cgmapT :: (forall b. Data b => b -> b) -> RelType -> RelType
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RelType)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RelType)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c RelType)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c RelType)
dataTypeOf :: RelType -> DataType
$cdataTypeOf :: RelType -> DataType
toConstr :: RelType -> Constr
$ctoConstr :: RelType -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RelType
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c RelType
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RelType -> c RelType
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> RelType -> c RelType
$cp1Data :: Typeable RelType
Data)

instance NFData RelType

instance Hashable RelType

instance Cacheable RelType

instance ToJSON RelType where
  toJSON :: RelType -> Value
toJSON = Text -> Value
String (Text -> Value) -> (RelType -> Text) -> RelType -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RelType -> Text
relTypeToTxt

instance FromJSON RelType where
  parseJSON :: Value -> Parser RelType
parseJSON (String Text
"object") = RelType -> Parser RelType
forall (m :: * -> *) a. Monad m => a -> m a
return RelType
ObjRel
  parseJSON (String Text
"array") = RelType -> Parser RelType
forall (m :: * -> *) a. Monad m => a -> m a
return RelType
ArrRel
  parseJSON Value
_ = String -> Parser RelType
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"expecting either 'object' or 'array' for rel_type"

instance Q.FromCol RelType where
  fromCol :: Maybe ByteString -> Either Text RelType
fromCol Maybe ByteString
bs = (Value RelType -> Maybe ByteString -> Either Text RelType)
-> Maybe ByteString -> Value RelType -> Either Text RelType
forall a b c. (a -> b -> c) -> b -> a -> c
flip Value RelType -> Maybe ByteString -> Either Text RelType
forall a. Value a -> Maybe ByteString -> Either Text a
Q.fromColHelper Maybe ByteString
bs (Value RelType -> Either Text RelType)
-> Value RelType -> Either Text RelType
forall a b. (a -> b) -> a -> b
$
    (Text -> Maybe RelType) -> Value RelType
forall a. (Text -> Maybe a) -> Value a
PD.enum ((Text -> Maybe RelType) -> Value RelType)
-> (Text -> Maybe RelType) -> Value RelType
forall a b. (a -> b) -> a -> b
$ \case
      Text
"object" -> RelType -> Maybe RelType
forall a. a -> Maybe a
Just RelType
ObjRel
      Text
"array" -> RelType -> Maybe RelType
forall a. a -> Maybe a
Just RelType
ArrRel
      Text
_ -> Maybe RelType
forall a. Maybe a
Nothing

relTypeToTxt :: RelType -> Text
relTypeToTxt :: RelType -> Text
relTypeToTxt RelType
ObjRel = Text
"object"
relTypeToTxt RelType
ArrRel = Text
"array"

data JsonAggSelect
  = JASMultipleRows
  | JASSingleObject
  deriving (Int -> JsonAggSelect -> ShowS
[JsonAggSelect] -> ShowS
JsonAggSelect -> String
(Int -> JsonAggSelect -> ShowS)
-> (JsonAggSelect -> String)
-> ([JsonAggSelect] -> ShowS)
-> Show JsonAggSelect
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JsonAggSelect] -> ShowS
$cshowList :: [JsonAggSelect] -> ShowS
show :: JsonAggSelect -> String
$cshow :: JsonAggSelect -> String
showsPrec :: Int -> JsonAggSelect -> ShowS
$cshowsPrec :: Int -> JsonAggSelect -> ShowS
Show, JsonAggSelect -> JsonAggSelect -> Bool
(JsonAggSelect -> JsonAggSelect -> Bool)
-> (JsonAggSelect -> JsonAggSelect -> Bool) -> Eq JsonAggSelect
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JsonAggSelect -> JsonAggSelect -> Bool
$c/= :: JsonAggSelect -> JsonAggSelect -> Bool
== :: JsonAggSelect -> JsonAggSelect -> Bool
$c== :: JsonAggSelect -> JsonAggSelect -> Bool
Eq, (forall x. JsonAggSelect -> Rep JsonAggSelect x)
-> (forall x. Rep JsonAggSelect x -> JsonAggSelect)
-> Generic JsonAggSelect
forall x. Rep JsonAggSelect x -> JsonAggSelect
forall x. JsonAggSelect -> Rep JsonAggSelect x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JsonAggSelect x -> JsonAggSelect
$cfrom :: forall x. JsonAggSelect -> Rep JsonAggSelect x
Generic)

instance Hashable JsonAggSelect

instance ToJSON JsonAggSelect where
  toJSON :: JsonAggSelect -> Value
toJSON = \case
    JsonAggSelect
JASMultipleRows -> Value
"multiple_rows"
    JsonAggSelect
JASSingleObject -> Value
"single_row"

data InsertOrder = BeforeParent | AfterParent
  deriving (Int -> InsertOrder -> ShowS
[InsertOrder] -> ShowS
InsertOrder -> String
(Int -> InsertOrder -> ShowS)
-> (InsertOrder -> String)
-> ([InsertOrder] -> ShowS)
-> Show InsertOrder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InsertOrder] -> ShowS
$cshowList :: [InsertOrder] -> ShowS
show :: InsertOrder -> String
$cshow :: InsertOrder -> String
showsPrec :: Int -> InsertOrder -> ShowS
$cshowsPrec :: Int -> InsertOrder -> ShowS
Show, InsertOrder -> InsertOrder -> Bool
(InsertOrder -> InsertOrder -> Bool)
-> (InsertOrder -> InsertOrder -> Bool) -> Eq InsertOrder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InsertOrder -> InsertOrder -> Bool
$c/= :: InsertOrder -> InsertOrder -> Bool
== :: InsertOrder -> InsertOrder -> Bool
$c== :: InsertOrder -> InsertOrder -> Bool
Eq, (forall x. InsertOrder -> Rep InsertOrder x)
-> (forall x. Rep InsertOrder x -> InsertOrder)
-> Generic InsertOrder
forall x. Rep InsertOrder x -> InsertOrder
forall x. InsertOrder -> Rep InsertOrder x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InsertOrder x -> InsertOrder
$cfrom :: forall x. InsertOrder -> Rep InsertOrder x
Generic)

instance NFData InsertOrder

instance Hashable InsertOrder

instance Cacheable InsertOrder

instance FromJSON InsertOrder where
  parseJSON :: Value -> Parser InsertOrder
parseJSON (String Text
t)
    | Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"before_parent" = InsertOrder -> Parser InsertOrder
forall (f :: * -> *) a. Applicative f => a -> f a
pure InsertOrder
BeforeParent
    | Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"after_parent" = InsertOrder -> Parser InsertOrder
forall (f :: * -> *) a. Applicative f => a -> f a
pure InsertOrder
AfterParent
  parseJSON Value
_ =
    String -> Parser InsertOrder
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"insertion_order should be 'before_parent' or 'after_parent'"

instance ToJSON InsertOrder where
  toJSON :: InsertOrder -> Value
toJSON = \case
    InsertOrder
BeforeParent -> Text -> Value
String Text
"before_parent"
    InsertOrder
AfterParent -> Text -> Value
String Text
"after_parent"

-- | Postgres OIDs. <https://www.postgresql.org/docs/12/datatype-oid.html>
newtype OID = OID {OID -> Int
unOID :: Int}
  deriving (Int -> OID -> ShowS
[OID] -> ShowS
OID -> String
(Int -> OID -> ShowS)
-> (OID -> String) -> ([OID] -> ShowS) -> Show OID
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OID] -> ShowS
$cshowList :: [OID] -> ShowS
show :: OID -> String
$cshow :: OID -> String
showsPrec :: Int -> OID -> ShowS
$cshowsPrec :: Int -> OID -> ShowS
Show, OID -> OID -> Bool
(OID -> OID -> Bool) -> (OID -> OID -> Bool) -> Eq OID
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OID -> OID -> Bool
$c/= :: OID -> OID -> Bool
== :: OID -> OID -> Bool
$c== :: OID -> OID -> Bool
Eq, OID -> ()
(OID -> ()) -> NFData OID
forall a. (a -> ()) -> NFData a
rnf :: OID -> ()
$crnf :: OID -> ()
NFData, Int -> OID -> Int
OID -> Int
(Int -> OID -> Int) -> (OID -> Int) -> Hashable OID
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: OID -> Int
$chash :: OID -> Int
hashWithSalt :: Int -> OID -> Int
$chashWithSalt :: Int -> OID -> Int
Hashable, [OID] -> Value
[OID] -> Encoding
OID -> Value
OID -> Encoding
(OID -> Value)
-> (OID -> Encoding)
-> ([OID] -> Value)
-> ([OID] -> Encoding)
-> ToJSON OID
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [OID] -> Encoding
$ctoEncodingList :: [OID] -> Encoding
toJSONList :: [OID] -> Value
$ctoJSONList :: [OID] -> Value
toEncoding :: OID -> Encoding
$ctoEncoding :: OID -> Encoding
toJSON :: OID -> Value
$ctoJSON :: OID -> Value
ToJSON, Value -> Parser [OID]
Value -> Parser OID
(Value -> Parser OID) -> (Value -> Parser [OID]) -> FromJSON OID
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [OID]
$cparseJSONList :: Value -> Parser [OID]
parseJSON :: Value -> Parser OID
$cparseJSON :: Value -> Parser OID
FromJSON, Maybe ByteString -> Either Text OID
(Maybe ByteString -> Either Text OID) -> FromCol OID
forall a. (Maybe ByteString -> Either Text a) -> FromCol a
fromCol :: Maybe ByteString -> Either Text OID
$cfromCol :: Maybe ByteString -> Either Text OID
Q.FromCol, Eq OID
Eq OID -> (Accesses -> OID -> OID -> Bool) -> Cacheable OID
Accesses -> OID -> OID -> Bool
forall a. Eq a -> (Accesses -> a -> a -> Bool) -> Cacheable a
unchanged :: Accesses -> OID -> OID -> Bool
$cunchanged :: Accesses -> OID -> OID -> Bool
$cp1Cacheable :: Eq OID
Cacheable)

newtype FieldName = FieldName {FieldName -> Text
getFieldNameTxt :: Text}
  deriving
    ( Int -> FieldName -> ShowS
[FieldName] -> ShowS
FieldName -> String
(Int -> FieldName -> ShowS)
-> (FieldName -> String)
-> ([FieldName] -> ShowS)
-> Show FieldName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldName] -> ShowS
$cshowList :: [FieldName] -> ShowS
show :: FieldName -> String
$cshow :: FieldName -> String
showsPrec :: Int -> FieldName -> ShowS
$cshowsPrec :: Int -> FieldName -> ShowS
Show,
      FieldName -> FieldName -> Bool
(FieldName -> FieldName -> Bool)
-> (FieldName -> FieldName -> Bool) -> Eq FieldName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldName -> FieldName -> Bool
$c/= :: FieldName -> FieldName -> Bool
== :: FieldName -> FieldName -> Bool
$c== :: FieldName -> FieldName -> Bool
Eq,
      Eq FieldName
Eq FieldName
-> (FieldName -> FieldName -> Ordering)
-> (FieldName -> FieldName -> Bool)
-> (FieldName -> FieldName -> Bool)
-> (FieldName -> FieldName -> Bool)
-> (FieldName -> FieldName -> Bool)
-> (FieldName -> FieldName -> FieldName)
-> (FieldName -> FieldName -> FieldName)
-> Ord FieldName
FieldName -> FieldName -> Bool
FieldName -> FieldName -> Ordering
FieldName -> FieldName -> FieldName
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 :: FieldName -> FieldName -> FieldName
$cmin :: FieldName -> FieldName -> FieldName
max :: FieldName -> FieldName -> FieldName
$cmax :: FieldName -> FieldName -> FieldName
>= :: FieldName -> FieldName -> Bool
$c>= :: FieldName -> FieldName -> Bool
> :: FieldName -> FieldName -> Bool
$c> :: FieldName -> FieldName -> Bool
<= :: FieldName -> FieldName -> Bool
$c<= :: FieldName -> FieldName -> Bool
< :: FieldName -> FieldName -> Bool
$c< :: FieldName -> FieldName -> Bool
compare :: FieldName -> FieldName -> Ordering
$ccompare :: FieldName -> FieldName -> Ordering
$cp1Ord :: Eq FieldName
Ord,
      Int -> FieldName -> Int
FieldName -> Int
(Int -> FieldName -> Int)
-> (FieldName -> Int) -> Hashable FieldName
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: FieldName -> Int
$chash :: FieldName -> Int
hashWithSalt :: Int -> FieldName -> Int
$chashWithSalt :: Int -> FieldName -> Int
Hashable,
      Value -> Parser [FieldName]
Value -> Parser FieldName
(Value -> Parser FieldName)
-> (Value -> Parser [FieldName]) -> FromJSON FieldName
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [FieldName]
$cparseJSONList :: Value -> Parser [FieldName]
parseJSON :: Value -> Parser FieldName
$cparseJSON :: Value -> Parser FieldName
FromJSON,
      [FieldName] -> Value
[FieldName] -> Encoding
FieldName -> Value
FieldName -> Encoding
(FieldName -> Value)
-> (FieldName -> Encoding)
-> ([FieldName] -> Value)
-> ([FieldName] -> Encoding)
-> ToJSON FieldName
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [FieldName] -> Encoding
$ctoEncodingList :: [FieldName] -> Encoding
toJSONList :: [FieldName] -> Value
$ctoJSONList :: [FieldName] -> Value
toEncoding :: FieldName -> Encoding
$ctoEncoding :: FieldName -> Encoding
toJSON :: FieldName -> Value
$ctoJSON :: FieldName -> Value
ToJSON,
      FromJSONKeyFunction [FieldName]
FromJSONKeyFunction FieldName
FromJSONKeyFunction FieldName
-> FromJSONKeyFunction [FieldName] -> FromJSONKey FieldName
forall a.
FromJSONKeyFunction a -> FromJSONKeyFunction [a] -> FromJSONKey a
fromJSONKeyList :: FromJSONKeyFunction [FieldName]
$cfromJSONKeyList :: FromJSONKeyFunction [FieldName]
fromJSONKey :: FromJSONKeyFunction FieldName
$cfromJSONKey :: FromJSONKeyFunction FieldName
FromJSONKey,
      ToJSONKeyFunction [FieldName]
ToJSONKeyFunction FieldName
ToJSONKeyFunction FieldName
-> ToJSONKeyFunction [FieldName] -> ToJSONKey FieldName
forall a.
ToJSONKeyFunction a -> ToJSONKeyFunction [a] -> ToJSONKey a
toJSONKeyList :: ToJSONKeyFunction [FieldName]
$ctoJSONKeyList :: ToJSONKeyFunction [FieldName]
toJSONKey :: ToJSONKeyFunction FieldName
$ctoJSONKey :: ToJSONKeyFunction FieldName
ToJSONKey,
      Typeable FieldName
DataType
Constr
Typeable FieldName
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> FieldName -> c FieldName)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c FieldName)
-> (FieldName -> Constr)
-> (FieldName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c FieldName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FieldName))
-> ((forall b. Data b => b -> b) -> FieldName -> FieldName)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> FieldName -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> FieldName -> r)
-> (forall u. (forall d. Data d => d -> u) -> FieldName -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> FieldName -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> FieldName -> m FieldName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FieldName -> m FieldName)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> FieldName -> m FieldName)
-> Data FieldName
FieldName -> DataType
FieldName -> Constr
(forall b. Data b => b -> b) -> FieldName -> FieldName
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FieldName -> c FieldName
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FieldName
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FieldName -> u
forall u. (forall d. Data d => d -> u) -> FieldName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FieldName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FieldName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FieldName -> m FieldName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FieldName -> m FieldName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FieldName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FieldName -> c FieldName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FieldName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FieldName)
$cFieldName :: Constr
$tFieldName :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> FieldName -> m FieldName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FieldName -> m FieldName
gmapMp :: (forall d. Data d => d -> m d) -> FieldName -> m FieldName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FieldName -> m FieldName
gmapM :: (forall d. Data d => d -> m d) -> FieldName -> m FieldName
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FieldName -> m FieldName
gmapQi :: Int -> (forall d. Data d => d -> u) -> FieldName -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FieldName -> u
gmapQ :: (forall d. Data d => d -> u) -> FieldName -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FieldName -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FieldName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FieldName -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FieldName -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FieldName -> r
gmapT :: (forall b. Data b => b -> b) -> FieldName -> FieldName
$cgmapT :: (forall b. Data b => b -> b) -> FieldName -> FieldName
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FieldName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FieldName)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c FieldName)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FieldName)
dataTypeOf :: FieldName -> DataType
$cdataTypeOf :: FieldName -> DataType
toConstr :: FieldName -> Constr
$ctoConstr :: FieldName -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FieldName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FieldName
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FieldName -> c FieldName
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FieldName -> c FieldName
$cp1Data :: Typeable FieldName
Data,
      (forall x. FieldName -> Rep FieldName x)
-> (forall x. Rep FieldName x -> FieldName) -> Generic FieldName
forall x. Rep FieldName x -> FieldName
forall x. FieldName -> Rep FieldName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FieldName x -> FieldName
$cfrom :: forall x. FieldName -> Rep FieldName x
Generic,
      String -> FieldName
(String -> FieldName) -> IsString FieldName
forall a. (String -> a) -> IsString a
fromString :: String -> FieldName
$cfromString :: String -> FieldName
IsString,
      FieldName -> ()
(FieldName -> ()) -> NFData FieldName
forall a. (a -> ()) -> NFData a
rnf :: FieldName -> ()
$crnf :: FieldName -> ()
NFData,
      Eq FieldName
Eq FieldName
-> (Accesses -> FieldName -> FieldName -> Bool)
-> Cacheable FieldName
Accesses -> FieldName -> FieldName -> Bool
forall a. Eq a -> (Accesses -> a -> a -> Bool) -> Cacheable a
unchanged :: Accesses -> FieldName -> FieldName -> Bool
$cunchanged :: Accesses -> FieldName -> FieldName -> Bool
$cp1Cacheable :: Eq FieldName
Cacheable,
      b -> FieldName -> FieldName
NonEmpty FieldName -> FieldName
FieldName -> FieldName -> FieldName
(FieldName -> FieldName -> FieldName)
-> (NonEmpty FieldName -> FieldName)
-> (forall b. Integral b => b -> FieldName -> FieldName)
-> Semigroup FieldName
forall b. Integral b => b -> FieldName -> FieldName
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> FieldName -> FieldName
$cstimes :: forall b. Integral b => b -> FieldName -> FieldName
sconcat :: NonEmpty FieldName -> FieldName
$csconcat :: NonEmpty FieldName -> FieldName
<> :: FieldName -> FieldName -> FieldName
$c<> :: FieldName -> FieldName -> FieldName
Semigroup
    )

instance ToTxt FieldName where
  toTxt :: FieldName -> Text
toTxt (FieldName Text
c) = Text
c

-- The field name here is the GraphQL alias, i.e, the name with which the field
-- should appear in the response
type Fields a = [(FieldName, a)]

class ToAesonPairs a where
  toAesonPairs :: (KeyValue v) => a -> [v]

data SourceName
  = SNDefault
  | SNName NonEmptyText
  deriving (Int -> SourceName -> ShowS
[SourceName] -> ShowS
SourceName -> String
(Int -> SourceName -> ShowS)
-> (SourceName -> String)
-> ([SourceName] -> ShowS)
-> Show SourceName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceName] -> ShowS
$cshowList :: [SourceName] -> ShowS
show :: SourceName -> String
$cshow :: SourceName -> String
showsPrec :: Int -> SourceName -> ShowS
$cshowsPrec :: Int -> SourceName -> ShowS
Show, SourceName -> SourceName -> Bool
(SourceName -> SourceName -> Bool)
-> (SourceName -> SourceName -> Bool) -> Eq SourceName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceName -> SourceName -> Bool
$c/= :: SourceName -> SourceName -> Bool
== :: SourceName -> SourceName -> Bool
$c== :: SourceName -> SourceName -> Bool
Eq, Eq SourceName
Eq SourceName
-> (SourceName -> SourceName -> Ordering)
-> (SourceName -> SourceName -> Bool)
-> (SourceName -> SourceName -> Bool)
-> (SourceName -> SourceName -> Bool)
-> (SourceName -> SourceName -> Bool)
-> (SourceName -> SourceName -> SourceName)
-> (SourceName -> SourceName -> SourceName)
-> Ord SourceName
SourceName -> SourceName -> Bool
SourceName -> SourceName -> Ordering
SourceName -> SourceName -> SourceName
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 :: SourceName -> SourceName -> SourceName
$cmin :: SourceName -> SourceName -> SourceName
max :: SourceName -> SourceName -> SourceName
$cmax :: SourceName -> SourceName -> SourceName
>= :: SourceName -> SourceName -> Bool
$c>= :: SourceName -> SourceName -> Bool
> :: SourceName -> SourceName -> Bool
$c> :: SourceName -> SourceName -> Bool
<= :: SourceName -> SourceName -> Bool
$c<= :: SourceName -> SourceName -> Bool
< :: SourceName -> SourceName -> Bool
$c< :: SourceName -> SourceName -> Bool
compare :: SourceName -> SourceName -> Ordering
$ccompare :: SourceName -> SourceName -> Ordering
$cp1Ord :: Eq SourceName
Ord, (forall x. SourceName -> Rep SourceName x)
-> (forall x. Rep SourceName x -> SourceName) -> Generic SourceName
forall x. Rep SourceName x -> SourceName
forall x. SourceName -> Rep SourceName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceName x -> SourceName
$cfrom :: forall x. SourceName -> Rep SourceName x
Generic)

instance FromJSON SourceName where
  parseJSON :: Value -> Parser SourceName
parseJSON = String -> (Text -> Parser SourceName) -> Value -> Parser SourceName
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"String" ((Text -> Parser SourceName) -> Value -> Parser SourceName)
-> (Text -> Parser SourceName) -> Value -> Parser SourceName
forall a b. (a -> b) -> a -> b
$ \case
    Text
"default" -> SourceName -> Parser SourceName
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceName
SNDefault
    Text
t -> NonEmptyText -> SourceName
SNName (NonEmptyText -> SourceName)
-> Parser NonEmptyText -> Parser SourceName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser NonEmptyText
forall a. FromJSON a => Value -> Parser a
parseJSON (Text -> Value
String Text
t)

instance HasCodec SourceName where
  codec :: JSONCodec SourceName
codec = (NonEmptyText -> SourceName)
-> (SourceName -> NonEmptyText)
-> Codec Value NonEmptyText NonEmptyText
-> JSONCodec SourceName
forall oldOutput newOutput newInput oldInput context.
(oldOutput -> newOutput)
-> (newInput -> oldInput)
-> Codec context oldInput oldOutput
-> Codec context newInput newOutput
dimapCodec NonEmptyText -> SourceName
dec SourceName -> NonEmptyText
enc Codec Value NonEmptyText NonEmptyText
nonEmptyTextCodec
    where
      dec :: NonEmptyText -> SourceName
dec NonEmptyText
t
        | NonEmptyText
t NonEmptyText -> NonEmptyText -> Bool
forall a. Eq a => a -> a -> Bool
== NonEmptyText
defaultSourceName = SourceName
SNDefault
        | Bool
otherwise = NonEmptyText -> SourceName
SNName NonEmptyText
t

      enc :: SourceName -> NonEmptyText
enc SourceName
SNDefault = NonEmptyText
defaultSourceName
      enc (SNName NonEmptyText
t) = NonEmptyText
t

sourceNameToText :: SourceName -> Text
sourceNameToText :: SourceName -> Text
sourceNameToText = \case
  SourceName
SNDefault -> NonEmptyText -> Text
unNonEmptyText NonEmptyText
defaultSourceName
  SNName NonEmptyText
t -> NonEmptyText -> Text
unNonEmptyText NonEmptyText
t

instance ToJSON SourceName where
  toJSON :: SourceName -> Value
toJSON = Text -> Value
String (Text -> Value) -> (SourceName -> Text) -> SourceName -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceName -> Text
sourceNameToText

instance ToTxt SourceName where
  toTxt :: SourceName -> Text
toTxt = SourceName -> Text
sourceNameToText

instance ToErrorValue SourceName where
  toErrorValue :: SourceName -> ErrorMessage
toErrorValue = \case
    SourceName
SNDefault -> ErrorMessage
"default"
    SNName NonEmptyText
t -> Text -> ErrorMessage
ErrorValue.squote (NonEmptyText -> Text
unNonEmptyText NonEmptyText
t)

instance ToJSONKey SourceName

instance Hashable SourceName

instance NFData SourceName

instance Cacheable SourceName

defaultSource :: SourceName
defaultSource :: SourceName
defaultSource = SourceName
SNDefault

defaultSourceName :: NonEmptyText
defaultSourceName :: NonEmptyText
defaultSourceName = Text -> NonEmptyText
mkNonEmptyTextUnsafe Text
"default"

data InpValInfo = InpValInfo
  { InpValInfo -> Maybe Description
_iviDesc :: Maybe G.Description,
    InpValInfo -> Name
_iviName :: G.Name,
    InpValInfo -> Maybe (Value Void)
_iviDefVal :: Maybe (G.Value Void),
    InpValInfo -> GType
_iviType :: G.GType
  }
  deriving (Int -> InpValInfo -> ShowS
[InpValInfo] -> ShowS
InpValInfo -> String
(Int -> InpValInfo -> ShowS)
-> (InpValInfo -> String)
-> ([InpValInfo] -> ShowS)
-> Show InpValInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InpValInfo] -> ShowS
$cshowList :: [InpValInfo] -> ShowS
show :: InpValInfo -> String
$cshow :: InpValInfo -> String
showsPrec :: Int -> InpValInfo -> ShowS
$cshowsPrec :: Int -> InpValInfo -> ShowS
Show, InpValInfo -> InpValInfo -> Bool
(InpValInfo -> InpValInfo -> Bool)
-> (InpValInfo -> InpValInfo -> Bool) -> Eq InpValInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InpValInfo -> InpValInfo -> Bool
$c/= :: InpValInfo -> InpValInfo -> Bool
== :: InpValInfo -> InpValInfo -> Bool
$c== :: InpValInfo -> InpValInfo -> Bool
Eq, InpValInfo -> Q Exp
InpValInfo -> Q (TExp InpValInfo)
(InpValInfo -> Q Exp)
-> (InpValInfo -> Q (TExp InpValInfo)) -> Lift InpValInfo
forall t. (t -> Q Exp) -> (t -> Q (TExp t)) -> Lift t
liftTyped :: InpValInfo -> Q (TExp InpValInfo)
$cliftTyped :: InpValInfo -> Q (TExp InpValInfo)
lift :: InpValInfo -> Q Exp
$clift :: InpValInfo -> Q Exp
TH.Lift, (forall x. InpValInfo -> Rep InpValInfo x)
-> (forall x. Rep InpValInfo x -> InpValInfo) -> Generic InpValInfo
forall x. Rep InpValInfo x -> InpValInfo
forall x. InpValInfo -> Rep InpValInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InpValInfo x -> InpValInfo
$cfrom :: forall x. InpValInfo -> Rep InpValInfo x
Generic)

instance Cacheable InpValInfo

newtype SystemDefined = SystemDefined {SystemDefined -> Bool
unSystemDefined :: Bool}
  deriving (Int -> SystemDefined -> ShowS
[SystemDefined] -> ShowS
SystemDefined -> String
(Int -> SystemDefined -> ShowS)
-> (SystemDefined -> String)
-> ([SystemDefined] -> ShowS)
-> Show SystemDefined
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SystemDefined] -> ShowS
$cshowList :: [SystemDefined] -> ShowS
show :: SystemDefined -> String
$cshow :: SystemDefined -> String
showsPrec :: Int -> SystemDefined -> ShowS
$cshowsPrec :: Int -> SystemDefined -> ShowS
Show, SystemDefined -> SystemDefined -> Bool
(SystemDefined -> SystemDefined -> Bool)
-> (SystemDefined -> SystemDefined -> Bool) -> Eq SystemDefined
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SystemDefined -> SystemDefined -> Bool
$c/= :: SystemDefined -> SystemDefined -> Bool
== :: SystemDefined -> SystemDefined -> Bool
$c== :: SystemDefined -> SystemDefined -> Bool
Eq, Value -> Parser [SystemDefined]
Value -> Parser SystemDefined
(Value -> Parser SystemDefined)
-> (Value -> Parser [SystemDefined]) -> FromJSON SystemDefined
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [SystemDefined]
$cparseJSONList :: Value -> Parser [SystemDefined]
parseJSON :: Value -> Parser SystemDefined
$cparseJSON :: Value -> Parser SystemDefined
FromJSON, [SystemDefined] -> Value
[SystemDefined] -> Encoding
SystemDefined -> Value
SystemDefined -> Encoding
(SystemDefined -> Value)
-> (SystemDefined -> Encoding)
-> ([SystemDefined] -> Value)
-> ([SystemDefined] -> Encoding)
-> ToJSON SystemDefined
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [SystemDefined] -> Encoding
$ctoEncodingList :: [SystemDefined] -> Encoding
toJSONList :: [SystemDefined] -> Value
$ctoJSONList :: [SystemDefined] -> Value
toEncoding :: SystemDefined -> Encoding
$ctoEncoding :: SystemDefined -> Encoding
toJSON :: SystemDefined -> Value
$ctoJSON :: SystemDefined -> Value
ToJSON, SystemDefined -> PrepArg
(SystemDefined -> PrepArg) -> ToPrepArg SystemDefined
forall a. (a -> PrepArg) -> ToPrepArg a
toPrepVal :: SystemDefined -> PrepArg
$ctoPrepVal :: SystemDefined -> PrepArg
Q.ToPrepArg, SystemDefined -> ()
(SystemDefined -> ()) -> NFData SystemDefined
forall a. (a -> ()) -> NFData a
rnf :: SystemDefined -> ()
$crnf :: SystemDefined -> ()
NFData, Eq SystemDefined
Eq SystemDefined
-> (Accesses -> SystemDefined -> SystemDefined -> Bool)
-> Cacheable SystemDefined
Accesses -> SystemDefined -> SystemDefined -> Bool
forall a. Eq a -> (Accesses -> a -> a -> Bool) -> Cacheable a
unchanged :: Accesses -> SystemDefined -> SystemDefined -> Bool
$cunchanged :: Accesses -> SystemDefined -> SystemDefined -> Bool
$cp1Cacheable :: Eq SystemDefined
Cacheable)

isSystemDefined :: SystemDefined -> Bool
isSystemDefined :: SystemDefined -> Bool
isSystemDefined = SystemDefined -> Bool
unSystemDefined

data SQLGenCtx = SQLGenCtx
  { SQLGenCtx -> StringifyNumbers
stringifyNum :: Options.StringifyNumbers,
    SQLGenCtx -> DangerouslyCollapseBooleans
dangerousBooleanCollapse :: Options.DangerouslyCollapseBooleans,
    SQLGenCtx -> OptimizePermissionFilters
optimizePermissionFilters :: Options.OptimizePermissionFilters
  }
  deriving (Int -> SQLGenCtx -> ShowS
[SQLGenCtx] -> ShowS
SQLGenCtx -> String
(Int -> SQLGenCtx -> ShowS)
-> (SQLGenCtx -> String)
-> ([SQLGenCtx] -> ShowS)
-> Show SQLGenCtx
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SQLGenCtx] -> ShowS
$cshowList :: [SQLGenCtx] -> ShowS
show :: SQLGenCtx -> String
$cshow :: SQLGenCtx -> String
showsPrec :: Int -> SQLGenCtx -> ShowS
$cshowsPrec :: Int -> SQLGenCtx -> ShowS
Show, SQLGenCtx -> SQLGenCtx -> Bool
(SQLGenCtx -> SQLGenCtx -> Bool)
-> (SQLGenCtx -> SQLGenCtx -> Bool) -> Eq SQLGenCtx
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SQLGenCtx -> SQLGenCtx -> Bool
$c/= :: SQLGenCtx -> SQLGenCtx -> Bool
== :: SQLGenCtx -> SQLGenCtx -> Bool
$c== :: SQLGenCtx -> SQLGenCtx -> Bool
Eq)

successMsg :: EncJSON
successMsg :: EncJSON
successMsg = Builder -> EncJSON
encJFromBuilder Builder
"{\"message\":\"success\"}"

newtype ResolvedWebhook = ResolvedWebhook {ResolvedWebhook -> Text
unResolvedWebhook :: Text}
  deriving (Int -> ResolvedWebhook -> ShowS
[ResolvedWebhook] -> ShowS
ResolvedWebhook -> String
(Int -> ResolvedWebhook -> ShowS)
-> (ResolvedWebhook -> String)
-> ([ResolvedWebhook] -> ShowS)
-> Show ResolvedWebhook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResolvedWebhook] -> ShowS
$cshowList :: [ResolvedWebhook] -> ShowS
show :: ResolvedWebhook -> String
$cshow :: ResolvedWebhook -> String
showsPrec :: Int -> ResolvedWebhook -> ShowS
$cshowsPrec :: Int -> ResolvedWebhook -> ShowS
Show, ResolvedWebhook -> ResolvedWebhook -> Bool
(ResolvedWebhook -> ResolvedWebhook -> Bool)
-> (ResolvedWebhook -> ResolvedWebhook -> Bool)
-> Eq ResolvedWebhook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResolvedWebhook -> ResolvedWebhook -> Bool
$c/= :: ResolvedWebhook -> ResolvedWebhook -> Bool
== :: ResolvedWebhook -> ResolvedWebhook -> Bool
$c== :: ResolvedWebhook -> ResolvedWebhook -> Bool
Eq, Value -> Parser [ResolvedWebhook]
Value -> Parser ResolvedWebhook
(Value -> Parser ResolvedWebhook)
-> (Value -> Parser [ResolvedWebhook]) -> FromJSON ResolvedWebhook
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [ResolvedWebhook]
$cparseJSONList :: Value -> Parser [ResolvedWebhook]
parseJSON :: Value -> Parser ResolvedWebhook
$cparseJSON :: Value -> Parser ResolvedWebhook
FromJSON, [ResolvedWebhook] -> Value
[ResolvedWebhook] -> Encoding
ResolvedWebhook -> Value
ResolvedWebhook -> Encoding
(ResolvedWebhook -> Value)
-> (ResolvedWebhook -> Encoding)
-> ([ResolvedWebhook] -> Value)
-> ([ResolvedWebhook] -> Encoding)
-> ToJSON ResolvedWebhook
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ResolvedWebhook] -> Encoding
$ctoEncodingList :: [ResolvedWebhook] -> Encoding
toJSONList :: [ResolvedWebhook] -> Value
$ctoJSONList :: [ResolvedWebhook] -> Value
toEncoding :: ResolvedWebhook -> Encoding
$ctoEncoding :: ResolvedWebhook -> Encoding
toJSON :: ResolvedWebhook -> Value
$ctoJSON :: ResolvedWebhook -> Value
ToJSON, Int -> ResolvedWebhook -> Int
ResolvedWebhook -> Int
(Int -> ResolvedWebhook -> Int)
-> (ResolvedWebhook -> Int) -> Hashable ResolvedWebhook
forall a. (Int -> a -> Int) -> (a -> Int) -> Hashable a
hash :: ResolvedWebhook -> Int
$chash :: ResolvedWebhook -> Int
hashWithSalt :: Int -> ResolvedWebhook -> Int
$chashWithSalt :: Int -> ResolvedWebhook -> Int
Hashable, ResolvedWebhook -> Text
(ResolvedWebhook -> Text) -> ToTxt ResolvedWebhook
forall a. (a -> Text) -> ToTxt a
toTxt :: ResolvedWebhook -> Text
$ctoTxt :: ResolvedWebhook -> Text
ToTxt, (forall x. ResolvedWebhook -> Rep ResolvedWebhook x)
-> (forall x. Rep ResolvedWebhook x -> ResolvedWebhook)
-> Generic ResolvedWebhook
forall x. Rep ResolvedWebhook x -> ResolvedWebhook
forall x. ResolvedWebhook -> Rep ResolvedWebhook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResolvedWebhook x -> ResolvedWebhook
$cfrom :: forall x. ResolvedWebhook -> Rep ResolvedWebhook x
Generic)

instance NFData ResolvedWebhook

instance Cacheable ResolvedWebhook

newtype InputWebhook = InputWebhook {InputWebhook -> URLTemplate
unInputWebhook :: URLTemplate}
  deriving (Int -> InputWebhook -> ShowS
[InputWebhook] -> ShowS
InputWebhook -> String
(Int -> InputWebhook -> ShowS)
-> (InputWebhook -> String)
-> ([InputWebhook] -> ShowS)
-> Show InputWebhook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InputWebhook] -> ShowS
$cshowList :: [InputWebhook] -> ShowS
show :: InputWebhook -> String
$cshow :: InputWebhook -> String
showsPrec :: Int -> InputWebhook -> ShowS
$cshowsPrec :: Int -> InputWebhook -> ShowS
Show, InputWebhook -> InputWebhook -> Bool
(InputWebhook -> InputWebhook -> Bool)
-> (InputWebhook -> InputWebhook -> Bool) -> Eq InputWebhook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InputWebhook -> InputWebhook -> Bool
$c/= :: InputWebhook -> InputWebhook -> Bool
== :: InputWebhook -> InputWebhook -> Bool
$c== :: InputWebhook -> InputWebhook -> Bool
Eq, (forall x. InputWebhook -> Rep InputWebhook x)
-> (forall x. Rep InputWebhook x -> InputWebhook)
-> Generic InputWebhook
forall x. Rep InputWebhook x -> InputWebhook
forall x. InputWebhook -> Rep InputWebhook x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InputWebhook x -> InputWebhook
$cfrom :: forall x. InputWebhook -> Rep InputWebhook x
Generic)

instance NFData InputWebhook

instance Cacheable InputWebhook

instance Hashable InputWebhook

instance ToJSON InputWebhook where
  toJSON :: InputWebhook -> Value
toJSON = Text -> Value
String (Text -> Value) -> (InputWebhook -> Text) -> InputWebhook -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. URLTemplate -> Text
printURLTemplate (URLTemplate -> Text)
-> (InputWebhook -> URLTemplate) -> InputWebhook -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InputWebhook -> URLTemplate
unInputWebhook

instance FromJSON InputWebhook where
  parseJSON :: Value -> Parser InputWebhook
parseJSON = String
-> (Text -> Parser InputWebhook) -> Value -> Parser InputWebhook
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"String" ((Text -> Parser InputWebhook) -> Value -> Parser InputWebhook)
-> (Text -> Parser InputWebhook) -> Value -> Parser InputWebhook
forall a b. (a -> b) -> a -> b
$ \Text
t ->
    case Text -> Either String URLTemplate
parseURLTemplate Text
t of
      Left String
e -> String -> Parser InputWebhook
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser InputWebhook) -> String -> Parser InputWebhook
forall a b. (a -> b) -> a -> b
$ String
"Parsing URL template failed: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
e
      Right URLTemplate
v -> InputWebhook -> Parser InputWebhook
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputWebhook -> Parser InputWebhook)
-> InputWebhook -> Parser InputWebhook
forall a b. (a -> b) -> a -> b
$ URLTemplate -> InputWebhook
InputWebhook URLTemplate
v

instance Q.FromCol InputWebhook where
  fromCol :: Maybe ByteString -> Either Text InputWebhook
fromCol Maybe ByteString
bs = do
    Either String URLTemplate
urlTemplate <- Text -> Either String URLTemplate
parseURLTemplate (Text -> Either String URLTemplate)
-> Either Text Text -> Either Text (Either String URLTemplate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ByteString -> Either Text Text
forall a. FromCol a => Maybe ByteString -> Either Text a
Q.fromCol Maybe ByteString
bs
    (String -> Text)
-> (URLTemplate -> InputWebhook)
-> Either String URLTemplate
-> Either Text InputWebhook
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (\String
e -> Text
"Parsing URL template failed: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack String
e) URLTemplate -> InputWebhook
InputWebhook Either String URLTemplate
urlTemplate

resolveWebhook :: QErrM m => Env.Environment -> InputWebhook -> m ResolvedWebhook
resolveWebhook :: Environment -> InputWebhook -> m ResolvedWebhook
resolveWebhook Environment
env (InputWebhook URLTemplate
urlTemplate) = do
  let eitherRenderedTemplate :: Either String Text
eitherRenderedTemplate = Environment -> URLTemplate -> Either String Text
renderURLTemplate Environment
env URLTemplate
urlTemplate
  (String -> m ResolvedWebhook)
-> (Text -> m ResolvedWebhook)
-> Either String Text
-> m ResolvedWebhook
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
    (Code -> Text -> m ResolvedWebhook
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
Unexpected (Text -> m ResolvedWebhook)
-> (String -> Text) -> String -> m ResolvedWebhook
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack)
    (ResolvedWebhook -> m ResolvedWebhook
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ResolvedWebhook -> m ResolvedWebhook)
-> (Text -> ResolvedWebhook) -> Text -> m ResolvedWebhook
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ResolvedWebhook
ResolvedWebhook)
    Either String Text
eitherRenderedTemplate

newtype Timeout = Timeout {Timeout -> Int
unTimeout :: Int}
  deriving (Int -> Timeout -> ShowS
[Timeout] -> ShowS
Timeout -> String
(Int -> Timeout -> ShowS)
-> (Timeout -> String) -> ([Timeout] -> ShowS) -> Show Timeout
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Timeout] -> ShowS
$cshowList :: [Timeout] -> ShowS
show :: Timeout -> String
$cshow :: Timeout -> String
showsPrec :: Int -> Timeout -> ShowS
$cshowsPrec :: Int -> Timeout -> ShowS
Show, Timeout -> Timeout -> Bool
(Timeout -> Timeout -> Bool)
-> (Timeout -> Timeout -> Bool) -> Eq Timeout
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Timeout -> Timeout -> Bool
$c/= :: Timeout -> Timeout -> Bool
== :: Timeout -> Timeout -> Bool
$c== :: Timeout -> Timeout -> Bool
Eq, [Timeout] -> Value
[Timeout] -> Encoding
Timeout -> Value
Timeout -> Encoding
(Timeout -> Value)
-> (Timeout -> Encoding)
-> ([Timeout] -> Value)
-> ([Timeout] -> Encoding)
-> ToJSON Timeout
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Timeout] -> Encoding
$ctoEncodingList :: [Timeout] -> Encoding
toJSONList :: [Timeout] -> Value
$ctoJSONList :: [Timeout] -> Value
toEncoding :: Timeout -> Encoding
$ctoEncoding :: Timeout -> Encoding
toJSON :: Timeout -> Value
$ctoJSON :: Timeout -> Value
ToJSON, (forall x. Timeout -> Rep Timeout x)
-> (forall x. Rep Timeout x -> Timeout) -> Generic Timeout
forall x. Rep Timeout x -> Timeout
forall x. Timeout -> Rep Timeout x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Timeout x -> Timeout
$cfrom :: forall x. Timeout -> Rep Timeout x
Generic, Timeout -> ()
(Timeout -> ()) -> NFData Timeout
forall a. (a -> ()) -> NFData a
rnf :: Timeout -> ()
$crnf :: Timeout -> ()
NFData, Eq Timeout
Eq Timeout
-> (Accesses -> Timeout -> Timeout -> Bool) -> Cacheable Timeout
Accesses -> Timeout -> Timeout -> Bool
forall a. Eq a -> (Accesses -> a -> a -> Bool) -> Cacheable a
unchanged :: Accesses -> Timeout -> Timeout -> Bool
$cunchanged :: Accesses -> Timeout -> Timeout -> Bool
$cp1Cacheable :: Eq Timeout
Cacheable)

instance FromJSON Timeout where
  parseJSON :: Value -> Parser Timeout
parseJSON = String -> (Scientific -> Parser Timeout) -> Value -> Parser Timeout
forall a. String -> (Scientific -> Parser a) -> Value -> Parser a
withScientific String
"Timeout" ((Scientific -> Parser Timeout) -> Value -> Parser Timeout)
-> (Scientific -> Parser Timeout) -> Value -> Parser Timeout
forall a b. (a -> b) -> a -> b
$ \Scientific
t -> do
    Int
timeout <- Maybe Int -> Parser Int -> Parser Int
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
onNothing (Scientific -> Maybe Int
forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger Scientific
t) (Parser Int -> Parser Int) -> Parser Int -> Parser Int
forall a b. (a -> b) -> a -> b
$ String -> Parser Int
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (Scientific -> String
forall a. Show a => a -> String
show Scientific
t String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" is out of bounds")
    case Int
timeout Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 of
      Bool
True -> Timeout -> Parser Timeout
forall (m :: * -> *) a. Monad m => a -> m a
return (Timeout -> Parser Timeout) -> Timeout -> Parser Timeout
forall a b. (a -> b) -> a -> b
$ Int -> Timeout
Timeout Int
timeout
      Bool
False -> String -> Parser Timeout
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"timeout value cannot be negative"

defaultActionTimeoutSecs :: Timeout
defaultActionTimeoutSecs :: Timeout
defaultActionTimeoutSecs = Int -> Timeout
Timeout Int
30

-- | See API reference here:
--   https://hasura.io/docs/latest/graphql/core/api-reference/syntax-defs.html#pgconnectionparameters
data PGConnectionParams = PGConnectionParams
  { PGConnectionParams -> Text
_pgcpHost :: Text,
    PGConnectionParams -> Text
_pgcpUsername :: Text,
    PGConnectionParams -> Maybe Text
_pgcpPassword :: Maybe Text,
    PGConnectionParams -> Int
_pgcpPort :: Int,
    PGConnectionParams -> Text
_pgcpDatabase :: Text
  }
  deriving (Int -> PGConnectionParams -> ShowS
[PGConnectionParams] -> ShowS
PGConnectionParams -> String
(Int -> PGConnectionParams -> ShowS)
-> (PGConnectionParams -> String)
-> ([PGConnectionParams] -> ShowS)
-> Show PGConnectionParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PGConnectionParams] -> ShowS
$cshowList :: [PGConnectionParams] -> ShowS
show :: PGConnectionParams -> String
$cshow :: PGConnectionParams -> String
showsPrec :: Int -> PGConnectionParams -> ShowS
$cshowsPrec :: Int -> PGConnectionParams -> ShowS
Show, PGConnectionParams -> PGConnectionParams -> Bool
(PGConnectionParams -> PGConnectionParams -> Bool)
-> (PGConnectionParams -> PGConnectionParams -> Bool)
-> Eq PGConnectionParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PGConnectionParams -> PGConnectionParams -> Bool
$c/= :: PGConnectionParams -> PGConnectionParams -> Bool
== :: PGConnectionParams -> PGConnectionParams -> Bool
$c== :: PGConnectionParams -> PGConnectionParams -> Bool
Eq, (forall x. PGConnectionParams -> Rep PGConnectionParams x)
-> (forall x. Rep PGConnectionParams x -> PGConnectionParams)
-> Generic PGConnectionParams
forall x. Rep PGConnectionParams x -> PGConnectionParams
forall x. PGConnectionParams -> Rep PGConnectionParams x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PGConnectionParams x -> PGConnectionParams
$cfrom :: forall x. PGConnectionParams -> Rep PGConnectionParams x
Generic)

instance NFData PGConnectionParams

instance Cacheable PGConnectionParams

instance Hashable PGConnectionParams

$(deriveToJSON hasuraJSON {omitNothingFields = True} ''PGConnectionParams)

instance FromJSON PGConnectionParams where
  parseJSON :: Value -> Parser PGConnectionParams
parseJSON = String
-> (Object -> Parser PGConnectionParams)
-> Value
-> Parser PGConnectionParams
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PGConnectionParams" ((Object -> Parser PGConnectionParams)
 -> Value -> Parser PGConnectionParams)
-> (Object -> Parser PGConnectionParams)
-> Value
-> Parser PGConnectionParams
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    Text -> Text -> Maybe Text -> Int -> Text -> PGConnectionParams
PGConnectionParams
      (Text -> Text -> Maybe Text -> Int -> Text -> PGConnectionParams)
-> Parser Text
-> Parser (Text -> Maybe Text -> Int -> Text -> PGConnectionParams)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"host"
      Parser (Text -> Maybe Text -> Int -> Text -> PGConnectionParams)
-> Parser Text
-> Parser (Maybe Text -> Int -> Text -> PGConnectionParams)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"username"
      Parser (Maybe Text -> Int -> Text -> PGConnectionParams)
-> Parser (Maybe Text)
-> Parser (Int -> Text -> PGConnectionParams)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"password"
      Parser (Int -> Text -> PGConnectionParams)
-> Parser Int -> Parser (Text -> PGConnectionParams)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"port"
      Parser (Text -> PGConnectionParams)
-> Parser Text -> Parser PGConnectionParams
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"database"

data UrlConf
  = -- | the database connection string
    UrlValue InputWebhook
  | -- | the name of environment variable containing the connection string
    UrlFromEnv T.Text
  | -- | the minimum required `connection parameters` to construct a valid connection string
    UrlFromParams PGConnectionParams
  deriving (Int -> UrlConf -> ShowS
[UrlConf] -> ShowS
UrlConf -> String
(Int -> UrlConf -> ShowS)
-> (UrlConf -> String) -> ([UrlConf] -> ShowS) -> Show UrlConf
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UrlConf] -> ShowS
$cshowList :: [UrlConf] -> ShowS
show :: UrlConf -> String
$cshow :: UrlConf -> String
showsPrec :: Int -> UrlConf -> ShowS
$cshowsPrec :: Int -> UrlConf -> ShowS
Show, UrlConf -> UrlConf -> Bool
(UrlConf -> UrlConf -> Bool)
-> (UrlConf -> UrlConf -> Bool) -> Eq UrlConf
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UrlConf -> UrlConf -> Bool
$c/= :: UrlConf -> UrlConf -> Bool
== :: UrlConf -> UrlConf -> Bool
$c== :: UrlConf -> UrlConf -> Bool
Eq, (forall x. UrlConf -> Rep UrlConf x)
-> (forall x. Rep UrlConf x -> UrlConf) -> Generic UrlConf
forall x. Rep UrlConf x -> UrlConf
forall x. UrlConf -> Rep UrlConf x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UrlConf x -> UrlConf
$cfrom :: forall x. UrlConf -> Rep UrlConf x
Generic)

instance NFData UrlConf

instance Cacheable UrlConf

instance Hashable UrlConf

instance ToJSON UrlConf where
  toJSON :: UrlConf -> Value
toJSON (UrlValue InputWebhook
w) = InputWebhook -> Value
forall a. ToJSON a => a -> Value
toJSON InputWebhook
w
  toJSON (UrlFromEnv Text
wEnv) = [Pair] -> Value
object [Key
"from_env" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
wEnv]
  toJSON (UrlFromParams PGConnectionParams
wParams) = [Pair] -> Value
object [Key
"connection_parameters" Key -> PGConnectionParams -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= PGConnectionParams
wParams]

instance FromJSON UrlConf where
  parseJSON :: Value -> Parser UrlConf
parseJSON (Object Object
o) = do
    Maybe UrlConf
mFromEnv <- ((Maybe Text -> Maybe UrlConf)
-> Parser (Maybe Text) -> Parser (Maybe UrlConf)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Maybe Text -> Maybe UrlConf)
 -> Parser (Maybe Text) -> Parser (Maybe UrlConf))
-> ((Text -> UrlConf) -> Maybe Text -> Maybe UrlConf)
-> (Text -> UrlConf)
-> Parser (Maybe Text)
-> Parser (Maybe UrlConf)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> UrlConf) -> Maybe Text -> Maybe UrlConf
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) Text -> UrlConf
UrlFromEnv (Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"from_env")
    Maybe UrlConf
mFromParams <- ((Maybe PGConnectionParams -> Maybe UrlConf)
-> Parser (Maybe PGConnectionParams) -> Parser (Maybe UrlConf)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Maybe PGConnectionParams -> Maybe UrlConf)
 -> Parser (Maybe PGConnectionParams) -> Parser (Maybe UrlConf))
-> ((PGConnectionParams -> UrlConf)
    -> Maybe PGConnectionParams -> Maybe UrlConf)
-> (PGConnectionParams -> UrlConf)
-> Parser (Maybe PGConnectionParams)
-> Parser (Maybe UrlConf)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PGConnectionParams -> UrlConf)
-> Maybe PGConnectionParams -> Maybe UrlConf
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) PGConnectionParams -> UrlConf
UrlFromParams (Object
o Object -> Key -> Parser (Maybe PGConnectionParams)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"connection_parameters")
    case (Maybe UrlConf
mFromEnv, Maybe UrlConf
mFromParams) of
      (Just UrlConf
fromEnv, Maybe UrlConf
Nothing) -> UrlConf -> Parser UrlConf
forall (f :: * -> *) a. Applicative f => a -> f a
pure UrlConf
fromEnv
      (Maybe UrlConf
Nothing, Just UrlConf
fromParams) -> UrlConf -> Parser UrlConf
forall (f :: * -> *) a. Applicative f => a -> f a
pure UrlConf
fromParams
      (Just UrlConf
_, Just UrlConf
_) -> String -> Parser UrlConf
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser UrlConf) -> String -> Parser UrlConf
forall a b. (a -> b) -> a -> b
$ ShowS
commonJSONParseErrorMessage String
"Only one of "
      (Maybe UrlConf
Nothing, Maybe UrlConf
Nothing) -> String -> Parser UrlConf
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser UrlConf) -> String -> Parser UrlConf
forall a b. (a -> b) -> a -> b
$ ShowS
commonJSONParseErrorMessage String
"Either "
    where
      -- NOTE(Sam): Maybe this could be put with other string manipulation utils
      -- helper to apply `dquote` for values of type `String`
      dquoteStr :: String -> String
      dquoteStr :: ShowS
dquoteStr = Text -> String
T.unpack (Text -> String) -> (String -> Text) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
forall t. ToTxt t => t -> Text
dquote (Text -> Text) -> (String -> Text) -> String -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack

      -- helper for formatting error messages within this instance
      commonJSONParseErrorMessage :: String -> String
      commonJSONParseErrorMessage :: ShowS
commonJSONParseErrorMessage String
strToBePrepended =
        String
strToBePrepended String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShowS
dquoteStr String
"from_env" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" or "
          String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShowS
dquoteStr String
"connection_parameters"
          String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" should be provided"
  parseJSON t :: Value
t@(String Text
_) =
    case (Value -> Result InputWebhook
forall a. FromJSON a => Value -> Result a
fromJSON Value
t) of
      Error String
s -> String -> Parser UrlConf
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
s
      Success InputWebhook
a -> UrlConf -> Parser UrlConf
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UrlConf -> Parser UrlConf) -> UrlConf -> Parser UrlConf
forall a b. (a -> b) -> a -> b
$ InputWebhook -> UrlConf
UrlValue InputWebhook
a
  parseJSON Value
_ = String -> Parser UrlConf
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"one of string or object must be provided for url/webhook"

getConnOptionsFromConnParams :: PGConnectionParams -> Q.ConnOptions
getConnOptionsFromConnParams :: PGConnectionParams -> ConnOptions
getConnOptionsFromConnParams PGConnectionParams {Int
Maybe Text
Text
_pgcpDatabase :: Text
_pgcpPort :: Int
_pgcpPassword :: Maybe Text
_pgcpUsername :: Text
_pgcpHost :: Text
_pgcpDatabase :: PGConnectionParams -> Text
_pgcpPort :: PGConnectionParams -> Int
_pgcpPassword :: PGConnectionParams -> Maybe Text
_pgcpUsername :: PGConnectionParams -> Text
_pgcpHost :: PGConnectionParams -> Text
..} =
  ConnOptions :: String
-> Int -> String -> String -> String -> Maybe String -> ConnOptions
Q.ConnOptions
    { connHost :: String
connHost = Text -> String
T.unpack Text
_pgcpHost,
      connUser :: String
connUser = Text -> String
T.unpack Text
_pgcpUsername,
      connPort :: Int
connPort = Int
_pgcpPort,
      connDatabase :: String
connDatabase = Text -> String
T.unpack Text
_pgcpDatabase,
      connPassword :: String
connPassword = Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" Maybe Text
_pgcpPassword,
      connOptions :: Maybe String
connOptions = Maybe String
forall a. Maybe a
Nothing
    }

-- | Construct a Postgres connection URI as a String from 'PGConnectionParams'.
--
-- NOTE: This function takes care to properly escape all URI components, as
-- Postgres requires that a connection URI is percent-encoded if it includes
-- symbols with "special meaning".
--
-- See the @libpq@ documentation for details: https://www.postgresql.org/docs/13/libpq-connect.html#id-1.7.3.8.3.6
getPGConnectionStringFromParams :: PGConnectionParams -> String
getPGConnectionStringFromParams :: PGConnectionParams -> String
getPGConnectionStringFromParams PGConnectionParams {Int
Maybe Text
Text
_pgcpDatabase :: Text
_pgcpPort :: Int
_pgcpPassword :: Maybe Text
_pgcpUsername :: Text
_pgcpHost :: Text
_pgcpDatabase :: PGConnectionParams -> Text
_pgcpPort :: PGConnectionParams -> Int
_pgcpPassword :: PGConnectionParams -> Maybe Text
_pgcpUsername :: PGConnectionParams -> Text
_pgcpHost :: PGConnectionParams -> Text
..} =
  let uriAuth :: URIAuth
uriAuth =
        URIAuth -> URIAuth
rectifyAuth (URIAuth -> URIAuth) -> URIAuth -> URIAuth
forall a b. (a -> b) -> a -> b
$
          URIAuth :: String -> String -> String -> URIAuth
URIAuth
            { uriUserInfo :: String
uriUserInfo = Text -> Maybe Text -> String
getURIAuthUserInfo Text
_pgcpUsername Maybe Text
_pgcpPassword,
              uriRegName :: String
uriRegName = Text -> String
unpackEscape Text
_pgcpHost,
              uriPort :: String
uriPort = Int -> String
forall a. Show a => a -> String
show Int
_pgcpPort
            }
      pgConnectionURI :: URI
pgConnectionURI =
        URI -> URI
rectify (URI -> URI) -> URI -> URI
forall a b. (a -> b) -> a -> b
$
          URI :: String -> Maybe URIAuth -> String -> String -> String -> URI
URI
            { uriScheme :: String
uriScheme = String
"postgresql",
              uriAuthority :: Maybe URIAuth
uriAuthority = URIAuth -> Maybe URIAuth
forall a. a -> Maybe a
Just URIAuth
uriAuth,
              uriPath :: String
uriPath = String
"/" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
unpackEscape Text
_pgcpDatabase,
              uriQuery :: String
uriQuery = String
"",
              uriFragment :: String
uriFragment = String
""
            }
   in ShowS -> URI -> ShowS
uriToString ShowS
forall a. a -> a
id URI
pgConnectionURI ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String
"" -- NOTE: this is done because uriToString returns a value of type ShowS
  where
    -- Helper to manage proper escaping in URI components.
    unpackEscape :: Text -> String
unpackEscape = (Char -> Bool) -> ShowS
escapeURIString Char -> Bool
isUnescapedInURIComponent ShowS -> (Text -> String) -> Text -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack

    -- Construct the 'URIAuth' 'uriUserInfo' component string from a username
    -- and optional password provided by 'PGConnectionParams'.
    getURIAuthUserInfo :: Text -> Maybe Text -> String
    getURIAuthUserInfo :: Text -> Maybe Text -> String
getURIAuthUserInfo Text
username Maybe Text
mPassword = case Maybe Text
mPassword of
      Maybe Text
Nothing -> Text -> String
unpackEscape Text
username
      Just Text
password -> Text -> String
unpackEscape Text
username String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
":" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
unpackEscape Text
password

resolveUrlConf :: MonadError QErr m => Env.Environment -> UrlConf -> m Text
resolveUrlConf :: Environment -> UrlConf -> m Text
resolveUrlConf Environment
env = \case
  UrlValue InputWebhook
v -> ResolvedWebhook -> Text
unResolvedWebhook (ResolvedWebhook -> Text) -> m ResolvedWebhook -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Environment -> InputWebhook -> m ResolvedWebhook
forall (m :: * -> *).
QErrM m =>
Environment -> InputWebhook -> m ResolvedWebhook
resolveWebhook Environment
env InputWebhook
v
  UrlFromEnv Text
envVar -> Environment -> Text -> m Text
forall (m :: * -> *). QErrM m => Environment -> Text -> m Text
getEnv Environment
env Text
envVar
  UrlFromParams PGConnectionParams
connParams ->
    Text -> m Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> m Text) -> (String -> Text) -> String -> m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> m Text) -> String -> m Text
forall a b. (a -> b) -> a -> b
$ PGConnectionParams -> String
getPGConnectionStringFromParams PGConnectionParams
connParams

getEnv :: QErrM m => Env.Environment -> Text -> m Text
getEnv :: Environment -> Text -> m Text
getEnv Environment
env Text
k = do
  let mEnv :: Maybe String
mEnv = Environment -> String -> Maybe String
Env.lookupEnv Environment
env (Text -> String
T.unpack Text
k)
  case Maybe String
mEnv of
    Maybe String
Nothing -> Code -> Text -> m Text
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotFound (Text -> m Text) -> Text -> m Text
forall a b. (a -> b) -> a -> b
$ Text
"environment variable '" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
k Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"' not set"
    Just String
envVal -> Text -> m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Text
T.pack String
envVal)

-- | Various user-controlled configuration for metrics used by Pro
data MetricsConfig = MetricsConfig
  { -- | should the query-variables be logged and analyzed for metrics
    MetricsConfig -> Bool
_mcAnalyzeQueryVariables :: Bool,
    -- | should the response-body be analyzed for empty and null responses
    MetricsConfig -> Bool
_mcAnalyzeResponseBody :: Bool
  }
  deriving (Int -> MetricsConfig -> ShowS
[MetricsConfig] -> ShowS
MetricsConfig -> String
(Int -> MetricsConfig -> ShowS)
-> (MetricsConfig -> String)
-> ([MetricsConfig] -> ShowS)
-> Show MetricsConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricsConfig] -> ShowS
$cshowList :: [MetricsConfig] -> ShowS
show :: MetricsConfig -> String
$cshow :: MetricsConfig -> String
showsPrec :: Int -> MetricsConfig -> ShowS
$cshowsPrec :: Int -> MetricsConfig -> ShowS
Show, MetricsConfig -> MetricsConfig -> Bool
(MetricsConfig -> MetricsConfig -> Bool)
-> (MetricsConfig -> MetricsConfig -> Bool) -> Eq MetricsConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricsConfig -> MetricsConfig -> Bool
$c/= :: MetricsConfig -> MetricsConfig -> Bool
== :: MetricsConfig -> MetricsConfig -> Bool
$c== :: MetricsConfig -> MetricsConfig -> Bool
Eq, (forall x. MetricsConfig -> Rep MetricsConfig x)
-> (forall x. Rep MetricsConfig x -> MetricsConfig)
-> Generic MetricsConfig
forall x. Rep MetricsConfig x -> MetricsConfig
forall x. MetricsConfig -> Rep MetricsConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricsConfig x -> MetricsConfig
$cfrom :: forall x. MetricsConfig -> Rep MetricsConfig x
Generic)

$(deriveJSON (aesonPrefix snakeCase) ''MetricsConfig)

emptyMetricsConfig :: MetricsConfig
emptyMetricsConfig :: MetricsConfig
emptyMetricsConfig = Bool -> Bool -> MetricsConfig
MetricsConfig Bool
False Bool
False

data Comment
  = -- | Automatically generate a comment (derive it from DB comments, or a sensible default describing the source of the data)
    Automatic
  | -- | The user's explicitly provided comment, or explicitly no comment (ie. leave it blank, do not autogenerate one)
    Explicit (Maybe NonEmptyText)
  deriving (Comment -> Comment -> Bool
(Comment -> Comment -> Bool)
-> (Comment -> Comment -> Bool) -> Eq Comment
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Comment -> Comment -> Bool
$c/= :: Comment -> Comment -> Bool
== :: Comment -> Comment -> Bool
$c== :: Comment -> Comment -> Bool
Eq, Int -> Comment -> ShowS
[Comment] -> ShowS
Comment -> String
(Int -> Comment -> ShowS)
-> (Comment -> String) -> ([Comment] -> ShowS) -> Show Comment
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Comment] -> ShowS
$cshowList :: [Comment] -> ShowS
show :: Comment -> String
$cshow :: Comment -> String
showsPrec :: Int -> Comment -> ShowS
$cshowsPrec :: Int -> Comment -> ShowS
Show, (forall x. Comment -> Rep Comment x)
-> (forall x. Rep Comment x -> Comment) -> Generic Comment
forall x. Rep Comment x -> Comment
forall x. Comment -> Rep Comment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Comment x -> Comment
$cfrom :: forall x. Comment -> Rep Comment x
Generic)

instance NFData Comment

instance Cacheable Comment

instance Hashable Comment

instance FromJSON Comment where
  parseJSON :: Value -> Parser Comment
parseJSON = \case
    Value
Null -> Comment -> Parser Comment
forall (f :: * -> *) a. Applicative f => a -> f a
pure Comment
Automatic
    String Text
text -> Comment -> Parser Comment
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Comment -> Parser Comment)
-> (Maybe NonEmptyText -> Comment)
-> Maybe NonEmptyText
-> Parser Comment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe NonEmptyText -> Comment
Explicit (Maybe NonEmptyText -> Parser Comment)
-> Maybe NonEmptyText -> Parser Comment
forall a b. (a -> b) -> a -> b
$ Text -> Maybe NonEmptyText
mkNonEmptyText Text
text
    Value
val -> String -> Parser Comment -> Parser Comment
forall a. String -> Parser a -> Parser a
prependFailure String
"parsing Comment failed, " (String -> Value -> Parser Comment
forall a. String -> Value -> Parser a
typeMismatch String
"String or Null" Value
val)

instance ToJSON Comment where
  toJSON :: Comment -> Value
toJSON Comment
Automatic = Value
Null
  toJSON (Explicit (Just NonEmptyText
value)) = Text -> Value
String (NonEmptyText -> Text
forall t. ToTxt t => t -> Text
toTxt NonEmptyText
value)
  toJSON (Explicit Maybe NonEmptyText
Nothing) = Text -> Value
String Text
""

commentToMaybeText :: Comment -> Maybe Text
commentToMaybeText :: Comment -> Maybe Text
commentToMaybeText Comment
Automatic = Maybe Text
forall a. Maybe a
Nothing
commentToMaybeText (Explicit Maybe NonEmptyText
Nothing) = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
""
commentToMaybeText (Explicit (Just NonEmptyText
val)) = Text -> Maybe Text
forall a. a -> Maybe a
Just (NonEmptyText -> Text
forall t. ToTxt t => t -> Text
toTxt NonEmptyText
val)

commentFromMaybeText :: Maybe Text -> Comment
commentFromMaybeText :: Maybe Text -> Comment
commentFromMaybeText Maybe Text
Nothing = Comment
Automatic
commentFromMaybeText (Just Text
val) = Maybe NonEmptyText -> Comment
Explicit (Maybe NonEmptyText -> Comment) -> Maybe NonEmptyText -> Comment
forall a b. (a -> b) -> a -> b
$ Text -> Maybe NonEmptyText
mkNonEmptyText Text
val

-- | We use the following type, after we resolve the env var.
-- | This will store both the env var name and the resolved value.
data EnvRecord a = EnvRecord
  { EnvRecord a -> Text
_envVarName :: Text,
    EnvRecord a -> a
_envVarValue :: a
  }
  deriving (Int -> EnvRecord a -> ShowS
[EnvRecord a] -> ShowS
EnvRecord a -> String
(Int -> EnvRecord a -> ShowS)
-> (EnvRecord a -> String)
-> ([EnvRecord a] -> ShowS)
-> Show (EnvRecord a)
forall a. Show a => Int -> EnvRecord a -> ShowS
forall a. Show a => [EnvRecord a] -> ShowS
forall a. Show a => EnvRecord a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnvRecord a] -> ShowS
$cshowList :: forall a. Show a => [EnvRecord a] -> ShowS
show :: EnvRecord a -> String
$cshow :: forall a. Show a => EnvRecord a -> String
showsPrec :: Int -> EnvRecord a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> EnvRecord a -> ShowS
Show, EnvRecord a -> EnvRecord a -> Bool
(EnvRecord a -> EnvRecord a -> Bool)
-> (EnvRecord a -> EnvRecord a -> Bool) -> Eq (EnvRecord a)
forall a. Eq a => EnvRecord a -> EnvRecord a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnvRecord a -> EnvRecord a -> Bool
$c/= :: forall a. Eq a => EnvRecord a -> EnvRecord a -> Bool
== :: EnvRecord a -> EnvRecord a -> Bool
$c== :: forall a. Eq a => EnvRecord a -> EnvRecord a -> Bool
Eq, (forall x. EnvRecord a -> Rep (EnvRecord a) x)
-> (forall x. Rep (EnvRecord a) x -> EnvRecord a)
-> Generic (EnvRecord a)
forall x. Rep (EnvRecord a) x -> EnvRecord a
forall x. EnvRecord a -> Rep (EnvRecord a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (EnvRecord a) x -> EnvRecord a
forall a x. EnvRecord a -> Rep (EnvRecord a) x
$cto :: forall a x. Rep (EnvRecord a) x -> EnvRecord a
$cfrom :: forall a x. EnvRecord a -> Rep (EnvRecord a) x
Generic)

instance NFData a => NFData (EnvRecord a)

instance Cacheable a => Cacheable (EnvRecord a)

instance Hashable a => Hashable (EnvRecord a)

instance (ToJSON a) => ToJSON (EnvRecord a) where
  toJSON :: EnvRecord a -> Value
toJSON (EnvRecord Text
envVar a
_envValue) = [Pair] -> Value
object [Key
"env_var" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
envVar]

instance (FromJSON a) => FromJSON (EnvRecord a)

data ApolloFederationVersion = V1 deriving (Int -> ApolloFederationVersion -> ShowS
[ApolloFederationVersion] -> ShowS
ApolloFederationVersion -> String
(Int -> ApolloFederationVersion -> ShowS)
-> (ApolloFederationVersion -> String)
-> ([ApolloFederationVersion] -> ShowS)
-> Show ApolloFederationVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApolloFederationVersion] -> ShowS
$cshowList :: [ApolloFederationVersion] -> ShowS
show :: ApolloFederationVersion -> String
$cshow :: ApolloFederationVersion -> String
showsPrec :: Int -> ApolloFederationVersion -> ShowS
$cshowsPrec :: Int -> ApolloFederationVersion -> ShowS
Show, ApolloFederationVersion -> ApolloFederationVersion -> Bool
(ApolloFederationVersion -> ApolloFederationVersion -> Bool)
-> (ApolloFederationVersion -> ApolloFederationVersion -> Bool)
-> Eq ApolloFederationVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApolloFederationVersion -> ApolloFederationVersion -> Bool
$c/= :: ApolloFederationVersion -> ApolloFederationVersion -> Bool
== :: ApolloFederationVersion -> ApolloFederationVersion -> Bool
$c== :: ApolloFederationVersion -> ApolloFederationVersion -> Bool
Eq, (forall x.
 ApolloFederationVersion -> Rep ApolloFederationVersion x)
-> (forall x.
    Rep ApolloFederationVersion x -> ApolloFederationVersion)
-> Generic ApolloFederationVersion
forall x. Rep ApolloFederationVersion x -> ApolloFederationVersion
forall x. ApolloFederationVersion -> Rep ApolloFederationVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApolloFederationVersion x -> ApolloFederationVersion
$cfrom :: forall x. ApolloFederationVersion -> Rep ApolloFederationVersion x
Generic)

instance Cacheable ApolloFederationVersion

instance ToJSON ApolloFederationVersion where
  toJSON :: ApolloFederationVersion -> Value
toJSON ApolloFederationVersion
V1 = Text -> Value
J.String Text
"v1"

instance FromJSON ApolloFederationVersion where
  parseJSON :: Value -> Parser ApolloFederationVersion
parseJSON = String
-> (Text -> Parser ApolloFederationVersion)
-> Value
-> Parser ApolloFederationVersion
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"ApolloFederationVersion" ((Text -> Parser ApolloFederationVersion)
 -> Value -> Parser ApolloFederationVersion)
-> (Text -> Parser ApolloFederationVersion)
-> Value
-> Parser ApolloFederationVersion
forall a b. (a -> b) -> a -> b
$
    \case
      Text
"v1" -> ApolloFederationVersion -> Parser ApolloFederationVersion
forall (f :: * -> *) a. Applicative f => a -> f a
pure ApolloFederationVersion
V1
      Text
_ -> String -> Parser ApolloFederationVersion
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"enable takes the version of apollo federation. Supported value is v1 only."

instance NFData ApolloFederationVersion

data ApolloFederationConfig = ApolloFederationConfig
  { ApolloFederationConfig -> ApolloFederationVersion
enable :: ApolloFederationVersion
  }
  deriving (Int -> ApolloFederationConfig -> ShowS
[ApolloFederationConfig] -> ShowS
ApolloFederationConfig -> String
(Int -> ApolloFederationConfig -> ShowS)
-> (ApolloFederationConfig -> String)
-> ([ApolloFederationConfig] -> ShowS)
-> Show ApolloFederationConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApolloFederationConfig] -> ShowS
$cshowList :: [ApolloFederationConfig] -> ShowS
show :: ApolloFederationConfig -> String
$cshow :: ApolloFederationConfig -> String
showsPrec :: Int -> ApolloFederationConfig -> ShowS
$cshowsPrec :: Int -> ApolloFederationConfig -> ShowS
Show, ApolloFederationConfig -> ApolloFederationConfig -> Bool
(ApolloFederationConfig -> ApolloFederationConfig -> Bool)
-> (ApolloFederationConfig -> ApolloFederationConfig -> Bool)
-> Eq ApolloFederationConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApolloFederationConfig -> ApolloFederationConfig -> Bool
$c/= :: ApolloFederationConfig -> ApolloFederationConfig -> Bool
== :: ApolloFederationConfig -> ApolloFederationConfig -> Bool
$c== :: ApolloFederationConfig -> ApolloFederationConfig -> Bool
Eq, (forall x. ApolloFederationConfig -> Rep ApolloFederationConfig x)
-> (forall x.
    Rep ApolloFederationConfig x -> ApolloFederationConfig)
-> Generic ApolloFederationConfig
forall x. Rep ApolloFederationConfig x -> ApolloFederationConfig
forall x. ApolloFederationConfig -> Rep ApolloFederationConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApolloFederationConfig x -> ApolloFederationConfig
$cfrom :: forall x. ApolloFederationConfig -> Rep ApolloFederationConfig x
Generic)

instance Cacheable ApolloFederationConfig

instance ToJSON ApolloFederationConfig

instance FromJSON ApolloFederationConfig

instance NFData ApolloFederationConfig

isApolloFedV1enabled :: Maybe ApolloFederationConfig -> Bool
isApolloFedV1enabled :: Maybe ApolloFederationConfig -> Bool
isApolloFedV1enabled = Maybe ApolloFederationConfig -> Bool
forall a. Maybe a -> Bool
isJust