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

import Autodocodec (Autodocodec (Autodocodec), HasCodec (codec), object, optionalField, requiredField, (.=))
import Autodocodec.OpenAPI ()
import Data.Aeson (FromJSON, ToJSON)
import Data.OpenApi qualified as OpenApi
import Hasura.Metadata.DTO.Placeholder (PlaceholderArray)
import Hasura.Metadata.DTO.Utils (optionalVersionField)
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
showList :: [MetadataV1] -> ShowS
$cshowList :: [MetadataV1] -> ShowS
show :: MetadataV1 -> String
$cshow :: MetadataV1 -> String
showsPrec :: Int -> MetadataV1 -> ShowS
$cshowsPrec :: Int -> MetadataV1 -> ShowS
Show, MetadataV1 -> MetadataV1 -> Bool
(MetadataV1 -> MetadataV1 -> Bool)
-> (MetadataV1 -> MetadataV1 -> Bool) -> Eq MetadataV1
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetadataV1 -> MetadataV1 -> Bool
$c/= :: MetadataV1 -> MetadataV1 -> Bool
== :: MetadataV1 -> MetadataV1 -> Bool
$c== :: 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
$cto :: forall x. Rep MetadataV1 x -> MetadataV1
$cfrom :: forall x. MetadataV1 -> Rep MetadataV1 x
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
parseJSONList :: Value -> Parser [MetadataV1]
$cparseJSONList :: Value -> Parser [MetadataV1]
parseJSON :: Value -> Parser MetadataV1
$cparseJSON :: 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
toEncodingList :: [MetadataV1] -> Encoding
$ctoEncodingList :: [MetadataV1] -> Encoding
toJSONList :: [MetadataV1] -> Value
$ctoJSONList :: [MetadataV1] -> Value
toEncoding :: MetadataV1 -> Encoding
$ctoEncoding :: MetadataV1 -> Encoding
toJSON :: MetadataV1 -> Value
$ctoJSON :: MetadataV1 -> Value
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
declareNamedSchema :: Proxy MetadataV1 -> Declare (Definitions Schema) NamedSchema
$cdeclareNamedSchema :: Proxy MetadataV1 -> Declare (Definitions Schema) NamedSchema
$cp1ToSchema :: Typeable MetadataV1
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 (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 (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 (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 (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