module Hasura.Metadata.DTO.MetadataV2 (MetadataV2 (..)) where

import Autodocodec (Autodocodec (Autodocodec), HasCodec (codec), object, optionalField, requiredField, (.=))
import Autodocodec.Extended (versionField)
import Autodocodec.OpenAPI ()
import Data.Aeson (FromJSON, ToJSON)
import Data.OpenApi qualified as OpenApi
import Hasura.Metadata.DTO.Placeholder (PlaceholderArray, PlaceholderObject)
import Hasura.Prelude

-- | Revision 2 of the Metadata export format. Note that values of the types,
-- 'PlaceholderArray' and 'PlaceholderObject' are placeholders that will
-- eventually be expanded to represent more detail.
data MetadataV2 = MetadataV2
  { MetadataV2 -> Maybe PlaceholderArray
metaV2Actions :: Maybe PlaceholderArray,
    MetadataV2 -> Maybe PlaceholderArray
metaV2Allowlist :: Maybe PlaceholderArray,
    MetadataV2 -> Maybe PlaceholderArray
metaV2CronTriggers :: Maybe PlaceholderArray,
    MetadataV2 -> Maybe PlaceholderObject
metaV2CustomTypes :: Maybe PlaceholderObject,
    MetadataV2 -> Maybe PlaceholderArray
metaV2Functions :: Maybe PlaceholderArray,
    MetadataV2 -> Maybe PlaceholderArray
metaV2QueryCollections :: Maybe PlaceholderArray,
    MetadataV2 -> Maybe PlaceholderArray
metaV2RemoteSchemas :: Maybe PlaceholderArray,
    MetadataV2 -> PlaceholderArray
metaV2Tables :: PlaceholderArray
  }
  deriving stock (Int -> MetadataV2 -> ShowS
[MetadataV2] -> ShowS
MetadataV2 -> String
(Int -> MetadataV2 -> ShowS)
-> (MetadataV2 -> String)
-> ([MetadataV2] -> ShowS)
-> Show MetadataV2
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MetadataV2 -> ShowS
showsPrec :: Int -> MetadataV2 -> ShowS
$cshow :: MetadataV2 -> String
show :: MetadataV2 -> String
$cshowList :: [MetadataV2] -> ShowS
showList :: [MetadataV2] -> ShowS
Show, MetadataV2 -> MetadataV2 -> Bool
(MetadataV2 -> MetadataV2 -> Bool)
-> (MetadataV2 -> MetadataV2 -> Bool) -> Eq MetadataV2
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetadataV2 -> MetadataV2 -> Bool
== :: MetadataV2 -> MetadataV2 -> Bool
$c/= :: MetadataV2 -> MetadataV2 -> Bool
/= :: MetadataV2 -> MetadataV2 -> Bool
Eq, (forall x. MetadataV2 -> Rep MetadataV2 x)
-> (forall x. Rep MetadataV2 x -> MetadataV2) -> Generic MetadataV2
forall x. Rep MetadataV2 x -> MetadataV2
forall x. MetadataV2 -> Rep MetadataV2 x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MetadataV2 -> Rep MetadataV2 x
from :: forall x. MetadataV2 -> Rep MetadataV2 x
$cto :: forall x. Rep MetadataV2 x -> MetadataV2
to :: forall x. Rep MetadataV2 x -> MetadataV2
Generic)
  deriving (Value -> Parser [MetadataV2]
Value -> Parser MetadataV2
(Value -> Parser MetadataV2)
-> (Value -> Parser [MetadataV2]) -> FromJSON MetadataV2
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser MetadataV2
parseJSON :: Value -> Parser MetadataV2
$cparseJSONList :: Value -> Parser [MetadataV2]
parseJSONList :: Value -> Parser [MetadataV2]
FromJSON, [MetadataV2] -> Value
[MetadataV2] -> Encoding
MetadataV2 -> Value
MetadataV2 -> Encoding
(MetadataV2 -> Value)
-> (MetadataV2 -> Encoding)
-> ([MetadataV2] -> Value)
-> ([MetadataV2] -> Encoding)
-> ToJSON MetadataV2
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: MetadataV2 -> Value
toJSON :: MetadataV2 -> Value
$ctoEncoding :: MetadataV2 -> Encoding
toEncoding :: MetadataV2 -> Encoding
$ctoJSONList :: [MetadataV2] -> Value
toJSONList :: [MetadataV2] -> Value
$ctoEncodingList :: [MetadataV2] -> Encoding
toEncodingList :: [MetadataV2] -> Encoding
ToJSON, Typeable MetadataV2
Typeable MetadataV2
-> (Proxy MetadataV2 -> Declare (Definitions Schema) NamedSchema)
-> ToSchema MetadataV2
Proxy MetadataV2 -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a
-> (Proxy a -> Declare (Definitions Schema) NamedSchema)
-> ToSchema a
$cdeclareNamedSchema :: Proxy MetadataV2 -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy MetadataV2 -> Declare (Definitions Schema) NamedSchema
OpenApi.ToSchema) via (Autodocodec MetadataV2)

instance HasCodec MetadataV2 where
  codec :: JSONCodec MetadataV2
codec =
    Text -> ObjectCodec MetadataV2 MetadataV2 -> JSONCodec MetadataV2
forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
object Text
"MetadataV2"
      (ObjectCodec MetadataV2 MetadataV2 -> JSONCodec MetadataV2)
-> ObjectCodec MetadataV2 MetadataV2 -> JSONCodec MetadataV2
forall a b. (a -> b) -> a -> b
$ Maybe PlaceholderArray
-> Maybe PlaceholderArray
-> Maybe PlaceholderArray
-> Maybe PlaceholderObject
-> Maybe PlaceholderArray
-> Maybe PlaceholderArray
-> Maybe PlaceholderArray
-> PlaceholderArray
-> MetadataV2
MetadataV2
      (Maybe PlaceholderArray
 -> Maybe PlaceholderArray
 -> Maybe PlaceholderArray
 -> Maybe PlaceholderObject
 -> Maybe PlaceholderArray
 -> Maybe PlaceholderArray
 -> Maybe PlaceholderArray
 -> PlaceholderArray
 -> MetadataV2)
-> Codec Object MetadataV2 Scientific
-> Codec
     Object
     MetadataV2
     (Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderObject
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> PlaceholderArray
      -> MetadataV2)
forall a b.
a -> Codec Object MetadataV2 b -> Codec Object MetadataV2 a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Integer -> Codec Object MetadataV2 Scientific
forall a. Integer -> ObjectCodec a Scientific
versionField Integer
2
      Codec
  Object
  MetadataV2
  (Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderObject
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> PlaceholderArray
   -> MetadataV2)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
-> Codec
     Object
     MetadataV2
     (Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderObject
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> PlaceholderArray
      -> MetadataV2)
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalField Text
"actions" Text
"action definitions which extend Hasura's schema with custom business logic using custom queries and mutations"
      ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
-> (MetadataV2 -> Maybe PlaceholderArray)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> Maybe PlaceholderArray
metaV2Actions
        Codec
  Object
  MetadataV2
  (Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderObject
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> PlaceholderArray
   -> MetadataV2)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
-> Codec
     Object
     MetadataV2
     (Maybe PlaceholderArray
      -> Maybe PlaceholderObject
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> PlaceholderArray
      -> MetadataV2)
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalField Text
"allowlist" Text
"safe GraphQL operations - when allow lists are enabled only these operations are allowed"
      ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
-> (MetadataV2 -> Maybe PlaceholderArray)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> Maybe PlaceholderArray
metaV2Allowlist
        Codec
  Object
  MetadataV2
  (Maybe PlaceholderArray
   -> Maybe PlaceholderObject
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> PlaceholderArray
   -> MetadataV2)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
-> Codec
     Object
     MetadataV2
     (Maybe PlaceholderObject
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> PlaceholderArray
      -> MetadataV2)
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalField Text
"cron_triggers" Text
"reliably trigger HTTP endpoints to run custom business logic periodically based on a cron schedule"
      ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
-> (MetadataV2 -> Maybe PlaceholderArray)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> Maybe PlaceholderArray
metaV2CronTriggers
        Codec
  Object
  MetadataV2
  (Maybe PlaceholderObject
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> PlaceholderArray
   -> MetadataV2)
-> Codec Object MetadataV2 (Maybe PlaceholderObject)
-> Codec
     Object
     MetadataV2
     (Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> Maybe PlaceholderArray
      -> PlaceholderArray
      -> MetadataV2)
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec (Maybe PlaceholderObject) (Maybe PlaceholderObject)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalField Text
"custom_types" Text
"custom type definitions"
      ObjectCodec (Maybe PlaceholderObject) (Maybe PlaceholderObject)
-> (MetadataV2 -> Maybe PlaceholderObject)
-> Codec Object MetadataV2 (Maybe PlaceholderObject)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> Maybe PlaceholderObject
metaV2CustomTypes
        Codec
  Object
  MetadataV2
  (Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> Maybe PlaceholderArray
   -> PlaceholderArray
   -> MetadataV2)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
-> Codec
     Object
     MetadataV2
     (Maybe PlaceholderArray
      -> Maybe PlaceholderArray -> PlaceholderArray -> MetadataV2)
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalField Text
"functions" Text
"user-defined SQL functions"
      ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
-> (MetadataV2 -> Maybe PlaceholderArray)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> Maybe PlaceholderArray
metaV2Functions
        Codec
  Object
  MetadataV2
  (Maybe PlaceholderArray
   -> Maybe PlaceholderArray -> PlaceholderArray -> MetadataV2)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
-> Codec
     Object
     MetadataV2
     (Maybe PlaceholderArray -> PlaceholderArray -> MetadataV2)
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalField Text
"query_collections" Text
"group queries using query collections"
      ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
-> (MetadataV2 -> Maybe PlaceholderArray)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> Maybe PlaceholderArray
metaV2QueryCollections
        Codec
  Object
  MetadataV2
  (Maybe PlaceholderArray -> PlaceholderArray -> MetadataV2)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
-> Codec Object MetadataV2 (PlaceholderArray -> MetadataV2)
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text
-> Text
-> ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec (Maybe output) (Maybe output)
optionalField Text
"remote_schemas" Text
"merge remote GraphQL schemas and provide a unified GraphQL API"
      ObjectCodec (Maybe PlaceholderArray) (Maybe PlaceholderArray)
-> (MetadataV2 -> Maybe PlaceholderArray)
-> Codec Object MetadataV2 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> Maybe PlaceholderArray
metaV2RemoteSchemas
        Codec Object MetadataV2 (PlaceholderArray -> MetadataV2)
-> Codec Object MetadataV2 PlaceholderArray
-> ObjectCodec MetadataV2 MetadataV2
forall a b.
Codec Object MetadataV2 (a -> b)
-> Codec Object MetadataV2 a -> Codec Object MetadataV2 b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> Text -> ObjectCodec PlaceholderArray PlaceholderArray
forall output.
HasCodec output =>
Text -> Text -> ObjectCodec output output
requiredField Text
"tables" Text
"configured database tables"
      ObjectCodec PlaceholderArray PlaceholderArray
-> (MetadataV2 -> PlaceholderArray)
-> Codec Object MetadataV2 PlaceholderArray
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV2 -> PlaceholderArray
metaV2Tables