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

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

-- | Revision 1 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 MetadataV1 = MetadataV1
  { MetadataV1 -> Maybe PlaceholderArray
metaV1Functions :: Maybe PlaceholderArray,
    MetadataV1 -> Maybe PlaceholderArray
metaV1RemoteSchemas :: Maybe PlaceholderArray,
    MetadataV1 -> PlaceholderArray
metaV1Tables :: PlaceholderArray
  }
  deriving stock (Int -> MetadataV1 -> ShowS
[MetadataV1] -> ShowS
MetadataV1 -> String
(Int -> MetadataV1 -> ShowS)
-> (MetadataV1 -> String)
-> ([MetadataV1] -> ShowS)
-> Show MetadataV1
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MetadataV1 -> ShowS
showsPrec :: Int -> MetadataV1 -> ShowS
$cshow :: MetadataV1 -> String
show :: MetadataV1 -> String
$cshowList :: [MetadataV1] -> ShowS
showList :: [MetadataV1] -> ShowS
Show, MetadataV1 -> MetadataV1 -> Bool
(MetadataV1 -> MetadataV1 -> Bool)
-> (MetadataV1 -> MetadataV1 -> Bool) -> Eq MetadataV1
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetadataV1 -> MetadataV1 -> Bool
== :: MetadataV1 -> MetadataV1 -> Bool
$c/= :: MetadataV1 -> MetadataV1 -> Bool
/= :: MetadataV1 -> MetadataV1 -> Bool
Eq, (forall x. MetadataV1 -> Rep MetadataV1 x)
-> (forall x. Rep MetadataV1 x -> MetadataV1) -> Generic MetadataV1
forall x. Rep MetadataV1 x -> MetadataV1
forall x. MetadataV1 -> Rep MetadataV1 x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. MetadataV1 -> Rep MetadataV1 x
from :: forall x. MetadataV1 -> Rep MetadataV1 x
$cto :: forall x. Rep MetadataV1 x -> MetadataV1
to :: forall x. Rep MetadataV1 x -> MetadataV1
Generic)
  deriving (Value -> Parser [MetadataV1]
Value -> Parser MetadataV1
(Value -> Parser MetadataV1)
-> (Value -> Parser [MetadataV1]) -> FromJSON MetadataV1
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser MetadataV1
parseJSON :: Value -> Parser MetadataV1
$cparseJSONList :: Value -> Parser [MetadataV1]
parseJSONList :: Value -> Parser [MetadataV1]
FromJSON, [MetadataV1] -> Value
[MetadataV1] -> Encoding
MetadataV1 -> Value
MetadataV1 -> Encoding
(MetadataV1 -> Value)
-> (MetadataV1 -> Encoding)
-> ([MetadataV1] -> Value)
-> ([MetadataV1] -> Encoding)
-> ToJSON MetadataV1
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: MetadataV1 -> Value
toJSON :: MetadataV1 -> Value
$ctoEncoding :: MetadataV1 -> Encoding
toEncoding :: MetadataV1 -> Encoding
$ctoJSONList :: [MetadataV1] -> Value
toJSONList :: [MetadataV1] -> Value
$ctoEncodingList :: [MetadataV1] -> Encoding
toEncodingList :: [MetadataV1] -> Encoding
ToJSON, Typeable MetadataV1
Typeable MetadataV1
-> (Proxy MetadataV1 -> Declare (Definitions Schema) NamedSchema)
-> ToSchema MetadataV1
Proxy MetadataV1 -> Declare (Definitions Schema) NamedSchema
forall a.
Typeable a
-> (Proxy a -> Declare (Definitions Schema) NamedSchema)
-> ToSchema a
$cdeclareNamedSchema :: Proxy MetadataV1 -> Declare (Definitions Schema) NamedSchema
declareNamedSchema :: Proxy MetadataV1 -> Declare (Definitions Schema) NamedSchema
OpenApi.ToSchema) via (Autodocodec MetadataV1)

instance HasCodec MetadataV1 where
  codec :: JSONCodec MetadataV1
codec =
    Text -> ObjectCodec MetadataV1 MetadataV1 -> JSONCodec MetadataV1
forall input output.
Text -> ObjectCodec input output -> ValueCodec input output
object Text
"MetadataV1"
      (ObjectCodec MetadataV1 MetadataV1 -> JSONCodec MetadataV1)
-> ObjectCodec MetadataV1 MetadataV1 -> JSONCodec MetadataV1
forall a b. (a -> b) -> a -> b
$ Maybe PlaceholderArray
-> Maybe PlaceholderArray -> PlaceholderArray -> MetadataV1
MetadataV1
      (Maybe PlaceholderArray
 -> Maybe PlaceholderArray -> PlaceholderArray -> MetadataV1)
-> Codec Object MetadataV1 (Maybe Scientific)
-> Codec
     Object
     MetadataV1
     (Maybe PlaceholderArray
      -> Maybe PlaceholderArray -> PlaceholderArray -> MetadataV1)
forall a b.
a -> Codec Object MetadataV1 b -> Codec Object MetadataV1 a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Integer -> Codec Object MetadataV1 (Maybe Scientific)
forall a. Integer -> ObjectCodec a (Maybe Scientific)
optionalVersionField Integer
1
      Codec
  Object
  MetadataV1
  (Maybe PlaceholderArray
   -> Maybe PlaceholderArray -> PlaceholderArray -> MetadataV1)
-> Codec Object MetadataV1 (Maybe PlaceholderArray)
-> Codec
     Object
     MetadataV1
     (Maybe PlaceholderArray -> PlaceholderArray -> MetadataV1)
forall a b.
Codec Object MetadataV1 (a -> b)
-> Codec Object MetadataV1 a -> Codec Object MetadataV1 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)
-> (MetadataV1 -> Maybe PlaceholderArray)
-> Codec Object MetadataV1 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV1 -> Maybe PlaceholderArray
metaV1Functions
        Codec
  Object
  MetadataV1
  (Maybe PlaceholderArray -> PlaceholderArray -> MetadataV1)
-> Codec Object MetadataV1 (Maybe PlaceholderArray)
-> Codec Object MetadataV1 (PlaceholderArray -> MetadataV1)
forall a b.
Codec Object MetadataV1 (a -> b)
-> Codec Object MetadataV1 a -> Codec Object MetadataV1 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)
-> (MetadataV1 -> Maybe PlaceholderArray)
-> Codec Object MetadataV1 (Maybe PlaceholderArray)
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV1 -> Maybe PlaceholderArray
metaV1RemoteSchemas
        Codec Object MetadataV1 (PlaceholderArray -> MetadataV1)
-> Codec Object MetadataV1 PlaceholderArray
-> ObjectCodec MetadataV1 MetadataV1
forall a b.
Codec Object MetadataV1 (a -> b)
-> Codec Object MetadataV1 a -> Codec Object MetadataV1 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
-> (MetadataV1 -> PlaceholderArray)
-> Codec Object MetadataV1 PlaceholderArray
forall oldInput output newInput.
ObjectCodec oldInput output
-> (newInput -> oldInput) -> ObjectCodec newInput output
.= MetadataV1 -> PlaceholderArray
metaV1Tables