-- | Helpers used in the implementations of 'metadataToOrdJSON' and
-- 'metadataToDTO'
module Hasura.RQL.Types.Metadata.Serialization
  ( actionMetadataToOrdJSONList,
    allowlistToOrdJSONList,
    apiLimitsToOrdJSON,
    backendConfigsToOrdJSON,
    openTelemetryConfigToOrdJSON,
    cronTriggersToOrdJSONList,
    customTypesToOrdJSON,
    endpointsToOrdJSONList,
    inheritedRolesToOrdJSONList,
    introspectionDisabledRolesToOrdJSON,
    metricsConfigToOrdJSON,
    networkConfigToOrdJSON,
    queryCollectionsToOrdJSONList,
    remoteSchemasToOrdJSONList,
    sourcesToOrdJSONList,
  )
where

import Data.Aeson (ToJSON (..))
import Data.Aeson qualified as J
import Data.Aeson.Ordered qualified as AO
import Data.HashMap.Strict.InsOrd.Extended qualified as InsOrdHashMap
import Data.Text.Extended qualified as T
import Data.Vector qualified as Vector
import Hasura.Function.Cache (emptyFunctionConfig)
import Hasura.Function.Metadata (FunctionMetadata (..))
import Hasura.LogicalModel.Metadata (LogicalModelMetadata (..))
import Hasura.NativeQuery.Metadata (NativeQueryMetadata (..))
import Hasura.Prelude
import Hasura.RQL.Types.Action
  ( ActionDefinition (..),
    ActionDefinitionInput,
    ActionMetadata (..),
    ActionPermissionMetadata (..),
    ActionType (..),
    ArgumentDefinition (..),
  )
import Hasura.RQL.Types.Allowlist (AllowlistEntry (..), MetadataAllowlist)
import Hasura.RQL.Types.ApiLimit (ApiLimit, emptyApiLimit)
import Hasura.RQL.Types.Backend (Backend, defaultTriggerOnReplication)
import Hasura.RQL.Types.BackendTag (HasTag (backendTag), reify)
import Hasura.RQL.Types.Column (ColumnValues)
import Hasura.RQL.Types.Common (Comment, MetricsConfig, RemoteRelationshipG (..), commentToMaybeText, defaultActionTimeoutSecs, emptyMetricsConfig)
import Hasura.RQL.Types.CustomTypes
  ( CustomTypes (..),
    EnumTypeDefinition (..),
    GraphQLType (..),
    InputObjectFieldDefinition (..),
    InputObjectTypeDefinition (..),
    ObjectFieldDefinition (..),
    ObjectTypeDefinition (..),
    ScalarTypeDefinition (..),
    emptyCustomTypes,
  )
import Hasura.RQL.Types.Endpoint (EndpointMetadata (..))
import Hasura.RQL.Types.EventTrigger (EventTriggerConf (..))
import Hasura.RQL.Types.GraphqlSchemaIntrospection (SetGraphqlIntrospectionOptions)
import Hasura.RQL.Types.Metadata.Common
  ( Actions,
    BackendConfigWrapper (..),
    BackendSourceMetadata (..),
    ComputedFieldMetadata (..),
    CronTriggers,
    Endpoints,
    InheritedRoles,
    RemoteSchemaMetadata,
    RemoteSchemas,
    SourceMetadata (..),
    Sources,
    getSourceName,
  )
import Hasura.RQL.Types.OpenTelemetry
  ( OpenTelemetryConfig (..),
    emptyOpenTelemetryConfig,
  )
import Hasura.RQL.Types.Permission
  ( AllowedRootFields (..),
    DelPerm (..),
    DelPermDef,
    InsPerm (..),
    InsPermDef,
    PermDef (..),
    SelPerm (..),
    SelPermDef,
    UpdPerm (..),
    UpdPermDef,
    unPermDefPermission,
  )
import Hasura.RQL.Types.QueryCollection (CreateCollection (..), QueryCollections)
import Hasura.RQL.Types.Relationships.Local (RelDef (..))
import Hasura.RQL.Types.Roles (InheritedRole, Role (..))
import Hasura.RQL.Types.ScheduledTrigger (CronTriggerMetadata (..), defaultSTRetryConf)
import Hasura.RQL.Types.SourceCustomization (emptySourceCustomization)
import Hasura.RemoteSchema.Metadata
  ( RemoteSchemaDef (..),
    RemoteSchemaMetadataG (..),
    RemoteSchemaPermissionMetadata (..),
  )
import Hasura.SQL.AnyBackend qualified as AB
import Hasura.SQL.BackendMap (BackendMap)
import Hasura.SQL.BackendMap qualified as BackendMap
import Hasura.StoredProcedure.Metadata (StoredProcedureMetadata (..))
import Hasura.Table.Cache (emptyTableConfig)
import Hasura.Table.Metadata (TableMetadata (..))
import Language.GraphQL.Draft.Syntax qualified as G
import Network.Types.Extended (Network, emptyNetwork)

sourcesToOrdJSONList :: Sources -> AO.Array
sourcesToOrdJSONList :: Sources -> Array
sourcesToOrdJSONList Sources
sources =
  [Value] -> Array
forall a. [a] -> Vector a
Vector.fromList
    ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ (BackendSourceMetadata -> Value)
-> [BackendSourceMetadata] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map BackendSourceMetadata -> Value
sourceMetaToOrdJSON
    ([BackendSourceMetadata] -> [Value])
-> [BackendSourceMetadata] -> [Value]
forall a b. (a -> b) -> a -> b
$ (BackendSourceMetadata -> SourceName)
-> [BackendSourceMetadata] -> [BackendSourceMetadata]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn BackendSourceMetadata -> SourceName
getSourceName
    ([BackendSourceMetadata] -> [BackendSourceMetadata])
-> [BackendSourceMetadata] -> [BackendSourceMetadata]
forall a b. (a -> b) -> a -> b
$ Sources -> [BackendSourceMetadata]
forall k v. InsOrdHashMap k v -> [v]
InsOrdHashMap.elems Sources
sources
  where
    sourceMetaToOrdJSON :: BackendSourceMetadata -> AO.Value
    sourceMetaToOrdJSON :: BackendSourceMetadata -> Value
sourceMetaToOrdJSON (BackendSourceMetadata AnyBackend SourceMetadata
exists) =
      forall (c :: BackendType -> Constraint) (i :: BackendType -> *) r.
AllBackendsSatisfy c =>
AnyBackend i -> (forall (b :: BackendType). c b => i b -> r) -> r
AB.dispatchAnyBackend @Backend AnyBackend SourceMetadata
exists ((forall (b :: BackendType).
  Backend b =>
  SourceMetadata b -> Value)
 -> Value)
-> (forall (b :: BackendType).
    Backend b =>
    SourceMetadata b -> Value)
-> Value
forall a b. (a -> b) -> a -> b
$ \(SourceMetadata SourceName
_smName BackendSourceKind b
_smKind Tables b
_smTables Functions b
_smFunctions NativeQueries b
_smNativeQueries StoredProcedures b
_smStoredProcedures LogicalModels b
_smLogicalModels SourceConnConfiguration b
_smConfiguration Maybe QueryTagsConfig
_smQueryTags SourceCustomization
_smCustomization Maybe (HealthCheckConfig b)
_smHealthCheckConfig :: SourceMetadata b) ->
        let sourceNamePair :: (Text, Value)
sourceNamePair = (Text
"name", SourceName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered SourceName
_smName)
            sourceKindPair :: (Text, Value)
sourceKindPair = (Text
"kind", BackendSourceKind b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered BackendSourceKind b
_smKind)
            tablesPair :: (Text, Value)
tablesPair = (Text
"tables", [Value] -> Value
AO.array ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ (TableMetadata b -> Value) -> [TableMetadata b] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map TableMetadata b -> Value
forall (b :: BackendType). Backend b => TableMetadata b -> Value
tableMetaToOrdJSON ([TableMetadata b] -> [Value]) -> [TableMetadata b] -> [Value]
forall a b. (a -> b) -> a -> b
$ (TableMetadata b -> TableName b)
-> [TableMetadata b] -> [TableMetadata b]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn TableMetadata b -> TableName b
forall (b :: BackendType). TableMetadata b -> TableName b
_tmTable ([TableMetadata b] -> [TableMetadata b])
-> [TableMetadata b] -> [TableMetadata b]
forall a b. (a -> b) -> a -> b
$ Tables b -> [TableMetadata b]
forall k v. InsOrdHashMap k v -> [v]
InsOrdHashMap.elems Tables b
_smTables)
            functionsPair :: Maybe (Text, Value)
functionsPair = Text
-> (FunctionMetadata b -> Value)
-> (FunctionMetadata b -> FunctionName b)
-> Functions b
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort Text
"functions" FunctionMetadata b -> Value
forall (b :: BackendType). Backend b => FunctionMetadata b -> Value
functionMetadataToOrdJSON FunctionMetadata b -> FunctionName b
forall (b :: BackendType). FunctionMetadata b -> FunctionName b
_fmFunction Functions b
_smFunctions
            nativeQueriesPair :: Maybe (Text, Value)
nativeQueriesPair = Text
-> (NativeQueryMetadata b -> Value)
-> (NativeQueryMetadata b -> NativeQueryName)
-> [NativeQueryMetadata b]
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort Text
"native_queries" NativeQueryMetadata b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered NativeQueryMetadata b -> NativeQueryName
forall (b :: BackendType). NativeQueryMetadata b -> NativeQueryName
_nqmRootFieldName (NativeQueries b -> [NativeQueryMetadata b]
forall k v. InsOrdHashMap k v -> [v]
InsOrdHashMap.elems NativeQueries b
_smNativeQueries)
            storedProceduresPair :: Maybe (Text, Value)
storedProceduresPair = Text
-> (StoredProcedureMetadata b -> Value)
-> (StoredProcedureMetadata b -> FunctionName b)
-> [StoredProcedureMetadata b]
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort Text
"stored_procedures" StoredProcedureMetadata b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered StoredProcedureMetadata b -> FunctionName b
forall (b :: BackendType).
StoredProcedureMetadata b -> FunctionName b
_spmStoredProcedure (StoredProcedures b -> [StoredProcedureMetadata b]
forall k v. InsOrdHashMap k v -> [v]
InsOrdHashMap.elems StoredProcedures b
_smStoredProcedures)
            logicalModelsPair :: Maybe (Text, Value)
logicalModelsPair = Text
-> (LogicalModelMetadata b -> Value)
-> (LogicalModelMetadata b -> LogicalModelName)
-> [LogicalModelMetadata b]
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort Text
"logical_models" LogicalModelMetadata b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered LogicalModelMetadata b -> LogicalModelName
forall (b :: BackendType).
LogicalModelMetadata b -> LogicalModelName
_lmmName (LogicalModels b -> [LogicalModelMetadata b]
forall k v. InsOrdHashMap k v -> [v]
InsOrdHashMap.elems LogicalModels b
_smLogicalModels)
            configurationPair :: [(Text, Value)]
configurationPair = [(Text
"configuration", SourceConnConfiguration b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered SourceConnConfiguration b
_smConfiguration)]
            queryTagsConfigPair :: [(Text, Value)]
queryTagsConfigPair = [(Text, Value)]
-> (QueryTagsConfig -> [(Text, Value)])
-> Maybe QueryTagsConfig
-> [(Text, Value)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\QueryTagsConfig
queryTagsConfig -> [(Text
"query_tags", QueryTagsConfig -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered QueryTagsConfig
queryTagsConfig)]) Maybe QueryTagsConfig
_smQueryTags

            customizationPair :: [(Text, Value)]
customizationPair =
              Bool -> [()]
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (SourceCustomization
_smCustomization SourceCustomization -> SourceCustomization -> Bool
forall a. Eq a => a -> a -> Bool
/= SourceCustomization
emptySourceCustomization)
                [()] -> [(Text, Value)] -> [(Text, Value)]
forall a b. [a] -> [b] -> [b]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [(Text
"customization", SourceCustomization -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered SourceCustomization
_smCustomization)]
            healthCheckPair :: [(Text, Value)]
healthCheckPair = [(Text, Value)]
-> (HealthCheckConfig b -> [(Text, Value)])
-> Maybe (HealthCheckConfig b)
-> [(Text, Value)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\HealthCheckConfig b
healthCheckConfig -> [(Text
"health_check", HealthCheckConfig b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered HealthCheckConfig b
healthCheckConfig)]) Maybe (HealthCheckConfig b)
_smHealthCheckConfig
         in [(Text, Value)] -> Value
AO.object
              ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [(Text, Value)
sourceNamePair, (Text, Value)
sourceKindPair, (Text, Value)
tablesPair]
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> Maybe (Text, Value) -> [(Text, Value)]
forall a. Maybe a -> [a]
maybeToList Maybe (Text, Value)
functionsPair
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> Maybe (Text, Value) -> [(Text, Value)]
forall a. Maybe a -> [a]
maybeToList Maybe (Text, Value)
nativeQueriesPair
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> Maybe (Text, Value) -> [(Text, Value)]
forall a. Maybe a -> [a]
maybeToList Maybe (Text, Value)
storedProceduresPair
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> Maybe (Text, Value) -> [(Text, Value)]
forall a. Maybe a -> [a]
maybeToList Maybe (Text, Value)
logicalModelsPair
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
configurationPair
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
queryTagsConfigPair
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
customizationPair
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
healthCheckPair

    tableMetaToOrdJSON :: (Backend b) => TableMetadata b -> AO.Value
    tableMetaToOrdJSON :: forall (b :: BackendType). Backend b => TableMetadata b -> Value
tableMetaToOrdJSON
      ( TableMetadata
          TableName b
table
          Bool
isEnum
          TableConfig b
config
          Relationships (ObjRelDef b)
objectRelationships
          Relationships (ArrRelDef b)
arrayRelationships
          ComputedFields b
computedFields
          RemoteRelationships
remoteRelationships
          Permissions (InsPermDef b)
insertPermissions
          Permissions (SelPermDef b)
selectPermissions
          Permissions (UpdPermDef b)
updatePermissions
          Permissions (DelPermDef b)
deletePermissions
          EventTriggers b
eventTriggers
          Maybe ApolloFederationConfig
enableApolloFed
          Maybe LogicalModelName
logicalModel
        ) =
        [(Text, Value)] -> Value
AO.object
          ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [(Text
"table", TableName b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered TableName b
table)]
          [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
            [ Maybe (Text, Value)
isEnumPair,
              Maybe (Text, Value)
configPair,
              Maybe (Text, Value)
objectRelationshipsPair,
              Maybe (Text, Value)
arrayRelationshipsPair,
              Maybe (Text, Value)
computedFieldsPair,
              Maybe (Text, Value)
remoteRelationshipsPair,
              Maybe (Text, Value)
insertPermissionsPair,
              Maybe (Text, Value)
selectPermissionsPair,
              Maybe (Text, Value)
updatePermissionsPair,
              Maybe (Text, Value)
deletePermissionsPair,
              Maybe (Text, Value)
eventTriggersPair,
              Maybe (Text, Value)
apolloFedConfigPair,
              Maybe (Text, Value)
logicalModelPair
            ]
        where
          isEnumPair :: Maybe (Text, Value)
isEnumPair = if Bool
isEnum then (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"is_enum", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
isEnum) else Maybe (Text, Value)
forall a. Maybe a
Nothing
          apolloFedConfigPair :: Maybe (Text, Value)
apolloFedConfigPair = (ApolloFederationConfig -> (Text, Value))
-> Maybe ApolloFederationConfig -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\ApolloFederationConfig
afConfig -> (Text
"apollo_federation_config", ApolloFederationConfig -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ApolloFederationConfig
afConfig)) Maybe ApolloFederationConfig
enableApolloFed
          configPair :: Maybe (Text, Value)
configPair =
            if TableConfig b
config TableConfig b -> TableConfig b -> Bool
forall a. Eq a => a -> a -> Bool
== TableConfig b
forall (b :: BackendType). TableConfig b
emptyTableConfig
              then Maybe (Text, Value)
forall a. Maybe a
Nothing
              else (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"configuration", TableConfig b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered TableConfig b
config)
          objectRelationshipsPair :: Maybe (Text, Value)
objectRelationshipsPair =
            Text
-> (ObjRelDef b -> Value)
-> (ObjRelDef b -> RelName)
-> Relationships (ObjRelDef b)
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"object_relationships"
              ObjRelDef b -> Value
forall a. ToJSON a => RelDef a -> Value
relDefToOrdJSON
              ObjRelDef b -> RelName
forall a. RelDef a -> RelName
_rdName
              Relationships (ObjRelDef b)
objectRelationships
          arrayRelationshipsPair :: Maybe (Text, Value)
arrayRelationshipsPair =
            Text
-> (ArrRelDef b -> Value)
-> (ArrRelDef b -> RelName)
-> Relationships (ArrRelDef b)
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"array_relationships"
              ArrRelDef b -> Value
forall a. ToJSON a => RelDef a -> Value
relDefToOrdJSON
              ArrRelDef b -> RelName
forall a. RelDef a -> RelName
_rdName
              Relationships (ArrRelDef b)
arrayRelationships
          computedFieldsPair :: Maybe (Text, Value)
computedFieldsPair =
            Text
-> (ComputedFieldMetadata b -> Value)
-> (ComputedFieldMetadata b -> ComputedFieldName)
-> ComputedFields b
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"computed_fields"
              ComputedFieldMetadata b -> Value
forall (b :: BackendType).
Backend b =>
ComputedFieldMetadata b -> Value
computedFieldMetaToOrdJSON
              ComputedFieldMetadata b -> ComputedFieldName
forall (b :: BackendType).
ComputedFieldMetadata b -> ComputedFieldName
_cfmName
              ComputedFields b
computedFields
          remoteRelationshipsPair :: Maybe (Text, Value)
remoteRelationshipsPair =
            Text
-> (RemoteRelationshipG RemoteRelationshipDefinition -> Value)
-> (RemoteRelationshipG RemoteRelationshipDefinition -> RelName)
-> RemoteRelationships
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"remote_relationships"
              RemoteRelationshipG RemoteRelationshipDefinition -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered
              RemoteRelationshipG RemoteRelationshipDefinition -> RelName
forall definition. RemoteRelationshipG definition -> RelName
_rrName
              RemoteRelationships
remoteRelationships
          insertPermissionsPair :: Maybe (Text, Value)
insertPermissionsPair =
            Text
-> (InsPermDef b -> Value)
-> (InsPermDef b -> RoleName)
-> Permissions (InsPermDef b)
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"insert_permissions"
              InsPermDef b -> Value
forall (b :: BackendType). Backend b => InsPermDef b -> Value
insPermDefToOrdJSON
              InsPermDef b -> RoleName
forall (b :: BackendType) (perm :: BackendType -> *).
PermDef b perm -> RoleName
_pdRole
              Permissions (InsPermDef b)
insertPermissions
          selectPermissionsPair :: Maybe (Text, Value)
selectPermissionsPair =
            Text
-> (SelPermDef b -> Value)
-> (SelPermDef b -> RoleName)
-> Permissions (SelPermDef b)
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"select_permissions"
              SelPermDef b -> Value
forall (b :: BackendType). Backend b => SelPermDef b -> Value
selPermDefToOrdJSON
              SelPermDef b -> RoleName
forall (b :: BackendType) (perm :: BackendType -> *).
PermDef b perm -> RoleName
_pdRole
              Permissions (SelPermDef b)
selectPermissions
          updatePermissionsPair :: Maybe (Text, Value)
updatePermissionsPair =
            Text
-> (UpdPermDef b -> Value)
-> (UpdPermDef b -> RoleName)
-> Permissions (UpdPermDef b)
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"update_permissions"
              UpdPermDef b -> Value
forall (b :: BackendType). Backend b => UpdPermDef b -> Value
updPermDefToOrdJSON
              UpdPermDef b -> RoleName
forall (b :: BackendType) (perm :: BackendType -> *).
PermDef b perm -> RoleName
_pdRole
              Permissions (UpdPermDef b)
updatePermissions
          deletePermissionsPair :: Maybe (Text, Value)
deletePermissionsPair =
            Text
-> (DelPermDef b -> Value)
-> (DelPermDef b -> RoleName)
-> Permissions (DelPermDef b)
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"delete_permissions"
              DelPermDef b -> Value
forall (b :: BackendType). Backend b => DelPermDef b -> Value
delPermDefToOrdJSON
              DelPermDef b -> RoleName
forall (b :: BackendType) (perm :: BackendType -> *).
PermDef b perm -> RoleName
_pdRole
              Permissions (DelPermDef b)
deletePermissions
          eventTriggersPair :: Maybe (Text, Value)
eventTriggersPair =
            Text
-> (EventTriggerConf b -> Value)
-> (EventTriggerConf b -> TriggerName)
-> EventTriggers b
-> Maybe (Text, Value)
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort
              Text
"event_triggers"
              EventTriggerConf b -> Value
forall (b :: BackendType). Backend b => EventTriggerConf b -> Value
eventTriggerConfToOrdJSON
              EventTriggerConf b -> TriggerName
forall (b :: BackendType). EventTriggerConf b -> TriggerName
etcName
              EventTriggers b
eventTriggers
          logicalModelPair :: Maybe (Text, Value)
logicalModelPair = (Text
"logical_model",) (Value -> (Text, Value))
-> (LogicalModelName -> Value) -> LogicalModelName -> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LogicalModelName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered (LogicalModelName -> (Text, Value))
-> Maybe LogicalModelName -> Maybe (Text, Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe LogicalModelName
logicalModel

          relDefToOrdJSON :: (ToJSON a) => RelDef a -> AO.Value
          relDefToOrdJSON :: forall a. ToJSON a => RelDef a -> Value
relDefToOrdJSON (RelDef RelName
name a
using Maybe Text
comment) =
            [(Text, Value)] -> Value
AO.object
              ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", RelName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RelName
name),
                  (Text
"using", a -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered a
using)
                ]
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair Maybe Text
comment]

          computedFieldMetaToOrdJSON :: (Backend b) => ComputedFieldMetadata b -> AO.Value
          computedFieldMetaToOrdJSON :: forall (b :: BackendType).
Backend b =>
ComputedFieldMetadata b -> Value
computedFieldMetaToOrdJSON (ComputedFieldMetadata ComputedFieldName
name ComputedFieldDefinition b
definition Comment
comment) =
            [(Text, Value)] -> Value
AO.object
              ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", ComputedFieldName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ComputedFieldName
name),
                  (Text
"definition", ComputedFieldDefinition b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ComputedFieldDefinition b
definition)
                ]
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Comment -> Maybe (Text, Value)
commentToMaybeOrdPair Comment
comment]

          insPermDefToOrdJSON :: forall b. (Backend b) => InsPermDef b -> AO.Value
          insPermDefToOrdJSON :: forall (b :: BackendType). Backend b => InsPermDef b -> Value
insPermDefToOrdJSON = (InsPerm b -> Value) -> PermDef b InsPerm -> Value
forall (a :: BackendType -> *) (b :: BackendType).
(a b -> Value) -> PermDef b a -> Value
permDefToOrdJSON InsPerm b -> Value
insPermToOrdJSON
            where
              insPermToOrdJSON :: InsPerm b -> Value
insPermToOrdJSON (InsPerm BoolExp b
check Maybe (ColumnValues b Value)
set Maybe (PermColSpec b)
columns Bool
backendOnly Maybe (ValidateInput InputWebhook)
validateInput) =
                let columnsPair :: Maybe (Text, Value)
columnsPair = (Text
"columns",) (Value -> (Text, Value))
-> (PermColSpec b -> Value) -> PermColSpec b -> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PermColSpec b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered (PermColSpec b -> (Text, Value))
-> Maybe (PermColSpec b) -> Maybe (Text, Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (PermColSpec b)
columns
                    backendOnlyPair :: Maybe (Text, Value)
backendOnlyPair =
                      if Bool
backendOnly
                        then (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"backend_only", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
backendOnly)
                        else Maybe (Text, Value)
forall a. Maybe a
Nothing
                    validateInputPair :: Maybe (Text, Value)
validateInputPair = ((Text
"validate_input",) (Value -> (Text, Value))
-> (ValidateInput InputWebhook -> Value)
-> ValidateInput InputWebhook
-> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValidateInput InputWebhook -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) (ValidateInput InputWebhook -> (Text, Value))
-> Maybe (ValidateInput InputWebhook) -> Maybe (Text, Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (ValidateInput InputWebhook)
validateInput
                 in [(Text, Value)] -> Value
AO.object
                      ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [(Text
"check", BoolExp b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered BoolExp b
check)]
                      [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [forall (b :: BackendType).
Backend b =>
Maybe (ColumnValues b Value) -> Maybe (Text, Value)
maybeSetToMaybeOrdPair @b Maybe (ColumnValues b Value)
set, Maybe (Text, Value)
columnsPair, Maybe (Text, Value)
backendOnlyPair, Maybe (Text, Value)
validateInputPair]

          selPermDefToOrdJSON :: (Backend b) => SelPermDef b -> AO.Value
          selPermDefToOrdJSON :: forall (b :: BackendType). Backend b => SelPermDef b -> Value
selPermDefToOrdJSON = (SelPerm b -> Value) -> PermDef b SelPerm -> Value
forall (a :: BackendType -> *) (b :: BackendType).
(a b -> Value) -> PermDef b a -> Value
permDefToOrdJSON SelPerm b -> Value
forall {b :: BackendType}. Backend b => SelPerm b -> Value
selPermToOrdJSON
            where
              selPermToOrdJSON :: SelPerm b -> Value
selPermToOrdJSON (SelPerm PermColSpec b
columns BoolExp b
fltr Maybe Int
limit Bool
allowAgg [ComputedFieldName]
computedFieldsPerm AllowedRootFields QueryRootFieldType
allowedQueryRootFieldTypes AllowedRootFields SubscriptionRootFieldType
allowedSubscriptionRootFieldTypes) =
                [(Text, Value)] -> Value
AO.object
                  ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
                    [ Maybe (Text, Value)
columnsPair,
                      Maybe (Text, Value)
computedFieldsPermPair,
                      Maybe (Text, Value)
filterPair,
                      Maybe (Text, Value)
limitPair,
                      Maybe (Text, Value)
allowAggPair,
                      Maybe (Text, Value)
allowedQueryRootFieldsPair,
                      Maybe (Text, Value)
allowedSubscriptionRootFieldsPair
                    ]
                where
                  columnsPair :: Maybe (Text, Value)
columnsPair = (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"columns", PermColSpec b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered PermColSpec b
columns)
                  computedFieldsPermPair :: Maybe (Text, Value)
computedFieldsPermPair = Text
-> (ComputedFieldName -> Value)
-> [ComputedFieldName]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"computed_fields" ComputedFieldName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered [ComputedFieldName]
computedFieldsPerm
                  filterPair :: Maybe (Text, Value)
filterPair = (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"filter", BoolExp b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered BoolExp b
fltr)
                  limitPair :: Maybe (Text, Value)
limitPair = Text -> (Int -> Value) -> Maybe Int -> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"limit" Int -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe Int
limit
                  allowAggPair :: Maybe (Text, Value)
allowAggPair =
                    if Bool
allowAgg
                      then (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"allow_aggregations", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
allowAgg)
                      else Maybe (Text, Value)
forall a. Maybe a
Nothing
                  allowedQueryRootFieldsPair :: Maybe (Text, Value)
allowedQueryRootFieldsPair =
                    case AllowedRootFields QueryRootFieldType
allowedQueryRootFieldTypes of
                      AllowedRootFields QueryRootFieldType
ARFAllowAllRootFields -> Maybe (Text, Value)
forall a. Maybe a
Nothing
                      ARFAllowConfiguredRootFields HashSet QueryRootFieldType
configuredRootFields ->
                        (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"query_root_fields", HashSet QueryRootFieldType -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered HashSet QueryRootFieldType
configuredRootFields)
                  allowedSubscriptionRootFieldsPair :: Maybe (Text, Value)
allowedSubscriptionRootFieldsPair =
                    case AllowedRootFields SubscriptionRootFieldType
allowedSubscriptionRootFieldTypes of
                      AllowedRootFields SubscriptionRootFieldType
ARFAllowAllRootFields -> Maybe (Text, Value)
forall a. Maybe a
Nothing
                      ARFAllowConfiguredRootFields HashSet SubscriptionRootFieldType
configuredRootFields ->
                        (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"subscription_root_fields", HashSet SubscriptionRootFieldType -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered HashSet SubscriptionRootFieldType
configuredRootFields)

          updPermDefToOrdJSON :: forall b. (Backend b) => UpdPermDef b -> AO.Value
          updPermDefToOrdJSON :: forall (b :: BackendType). Backend b => UpdPermDef b -> Value
updPermDefToOrdJSON = (UpdPerm b -> Value) -> PermDef b UpdPerm -> Value
forall (a :: BackendType -> *) (b :: BackendType).
(a b -> Value) -> PermDef b a -> Value
permDefToOrdJSON UpdPerm b -> Value
updPermToOrdJSON
            where
              updPermToOrdJSON :: UpdPerm b -> Value
updPermToOrdJSON (UpdPerm PermColSpec b
columns Maybe (ColumnValues b Value)
set BoolExp b
fltr Maybe (BoolExp b)
check Bool
backendOnly Maybe (ValidateInput InputWebhook)
validateInput) =
                let backendOnlyPair :: Maybe (Text, Value)
backendOnlyPair =
                      if Bool
backendOnly
                        then (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"backend_only", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
backendOnly)
                        else Maybe (Text, Value)
forall a. Maybe a
Nothing
                    validateInputPair :: Maybe (Text, Value)
validateInputPair = ((Text
"validate_input",) (Value -> (Text, Value))
-> (ValidateInput InputWebhook -> Value)
-> ValidateInput InputWebhook
-> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValidateInput InputWebhook -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) (ValidateInput InputWebhook -> (Text, Value))
-> Maybe (ValidateInput InputWebhook) -> Maybe (Text, Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (ValidateInput InputWebhook)
validateInput
                 in [(Text, Value)] -> Value
AO.object
                      ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"columns", PermColSpec b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered PermColSpec b
columns),
                          (Text
"filter", BoolExp b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered BoolExp b
fltr),
                          (Text
"check", Maybe (BoolExp b) -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe (BoolExp b)
check)
                        ]
                      [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [forall (b :: BackendType).
Backend b =>
Maybe (ColumnValues b Value) -> Maybe (Text, Value)
maybeSetToMaybeOrdPair @b Maybe (ColumnValues b Value)
set, Maybe (Text, Value)
backendOnlyPair, Maybe (Text, Value)
validateInputPair]

          delPermDefToOrdJSON :: (Backend b) => DelPermDef b -> AO.Value
          delPermDefToOrdJSON :: forall (b :: BackendType). Backend b => DelPermDef b -> Value
delPermDefToOrdJSON = (DelPerm b -> Value) -> PermDef b DelPerm -> Value
forall (a :: BackendType -> *) (b :: BackendType).
(a b -> Value) -> PermDef b a -> Value
permDefToOrdJSON DelPerm b -> Value
forall {b :: BackendType}. Backend b => DelPerm b -> Value
delPermToOrdJSON
            where
              delPermToOrdJSON :: DelPerm b -> Value
delPermToOrdJSON (DelPerm BoolExp b
filter' Bool
backendOnly Maybe (ValidateInput InputWebhook)
validateInput) =
                let backendOnlyPair :: Maybe (Text, Value)
backendOnlyPair =
                      if Bool
backendOnly
                        then (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"backend_only", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
backendOnly)
                        else Maybe (Text, Value)
forall a. Maybe a
Nothing
                    validateInputPair :: Maybe (Text, Value)
validateInputPair = ((Text
"validate_input",) (Value -> (Text, Value))
-> (ValidateInput InputWebhook -> Value)
-> ValidateInput InputWebhook
-> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValidateInput InputWebhook -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) (ValidateInput InputWebhook -> (Text, Value))
-> Maybe (ValidateInput InputWebhook) -> Maybe (Text, Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (ValidateInput InputWebhook)
validateInput
                 in [(Text, Value)] -> Value
AO.object
                      ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"filter", BoolExp b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered BoolExp b
filter')
                        ]
                      [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe (Text, Value)
backendOnlyPair, Maybe (Text, Value)
validateInputPair]

          permDefToOrdJSON :: (a b -> AO.Value) -> PermDef b a -> AO.Value
          permDefToOrdJSON :: forall (a :: BackendType -> *) (b :: BackendType).
(a b -> Value) -> PermDef b a -> Value
permDefToOrdJSON a b -> Value
permToOrdJSON (PermDef RoleName
role PermDefPermission b a
permission Maybe Text
comment) =
            [(Text, Value)] -> Value
AO.object
              ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"role", RoleName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RoleName
role),
                  (Text
"permission", a b -> Value
permToOrdJSON (PermDefPermission b a -> a b
forall (b :: BackendType) (perm :: BackendType -> *).
PermDefPermission b perm -> perm b
unPermDefPermission PermDefPermission b a
permission))
                ]
              [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair Maybe Text
comment]

          eventTriggerConfToOrdJSON :: forall b. (Backend b) => EventTriggerConf b -> AO.Value
          eventTriggerConfToOrdJSON :: forall (b :: BackendType). Backend b => EventTriggerConf b -> Value
eventTriggerConfToOrdJSON (EventTriggerConf TriggerName
name TriggerOpsDef b
definition Maybe InputWebhook
webhook Maybe Text
webhookFromEnv RetryConf
retryConf Maybe [HeaderConf]
headers Maybe RequestTransform
reqTransform Maybe MetadataResponseTransform
respTransform Maybe AutoTriggerLogCleanupConfig
cleanupConfig TriggerOnReplication
triggerOnReplication) =
            let triggerOnReplicationMaybe :: Maybe TriggerOnReplication
triggerOnReplicationMaybe =
                  case forall (b :: BackendType).
Backend b =>
Maybe (XEventTriggers b, TriggerOnReplication)
defaultTriggerOnReplication @b of
                    Just (XEventTriggers b
_, TriggerOnReplication
defTOR) -> if TriggerOnReplication
triggerOnReplication TriggerOnReplication -> TriggerOnReplication -> Bool
forall a. Eq a => a -> a -> Bool
== TriggerOnReplication
defTOR then Maybe TriggerOnReplication
forall a. Maybe a
Nothing else TriggerOnReplication -> Maybe TriggerOnReplication
forall a. a -> Maybe a
Just TriggerOnReplication
triggerOnReplication
                    Maybe (XEventTriggers b, TriggerOnReplication)
Nothing -> TriggerOnReplication -> Maybe TriggerOnReplication
forall a. a -> Maybe a
Just TriggerOnReplication
triggerOnReplication
             in [(Text, Value)] -> Value
AO.object
                  ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", TriggerName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered TriggerName
name),
                      (Text
"definition", TriggerOpsDef b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered TriggerOpsDef b
definition),
                      (Text
"retry_conf", RetryConf -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RetryConf
retryConf)
                    ]
                  [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
                    [ Text
-> (InputWebhook -> Value)
-> Maybe InputWebhook
-> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"webhook" InputWebhook -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe InputWebhook
webhook,
                      Text -> (Text -> Value) -> Maybe Text -> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"webhook_from_env" Text -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe Text
webhookFromEnv,
                      Maybe [HeaderConf]
headers Maybe [HeaderConf]
-> ([HeaderConf] -> Maybe (Text, Value)) -> Maybe (Text, Value)
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text
-> (HeaderConf -> Value) -> [HeaderConf] -> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"headers" HeaderConf -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered,
                      (RequestTransform -> (Text, Value))
-> Maybe RequestTransform -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
"request_transform",) (Value -> (Text, Value))
-> (RequestTransform -> Value) -> RequestTransform -> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequestTransform -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) Maybe RequestTransform
reqTransform,
                      (MetadataResponseTransform -> (Text, Value))
-> Maybe MetadataResponseTransform -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
"response_transform",) (Value -> (Text, Value))
-> (MetadataResponseTransform -> Value)
-> MetadataResponseTransform
-> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetadataResponseTransform -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) Maybe MetadataResponseTransform
respTransform,
                      Text
-> (AutoTriggerLogCleanupConfig -> Value)
-> Maybe AutoTriggerLogCleanupConfig
-> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"cleanup_config" AutoTriggerLogCleanupConfig -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe AutoTriggerLogCleanupConfig
cleanupConfig,
                      Text
-> (TriggerOnReplication -> Value)
-> Maybe TriggerOnReplication
-> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"trigger_on_replication" TriggerOnReplication -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe TriggerOnReplication
triggerOnReplicationMaybe
                    ]

    functionMetadataToOrdJSON :: (Backend b) => FunctionMetadata b -> AO.Value
    functionMetadataToOrdJSON :: forall (b :: BackendType). Backend b => FunctionMetadata b -> Value
functionMetadataToOrdJSON FunctionMetadata {[FunctionPermissionInfo]
Maybe Text
FunctionName b
FunctionConfig b
_fmFunction :: forall (b :: BackendType). FunctionMetadata b -> FunctionName b
_fmFunction :: FunctionName b
_fmConfiguration :: FunctionConfig b
_fmPermissions :: [FunctionPermissionInfo]
_fmComment :: Maybe Text
_fmConfiguration :: forall (b :: BackendType). FunctionMetadata b -> FunctionConfig b
_fmPermissions :: forall (b :: BackendType).
FunctionMetadata b -> [FunctionPermissionInfo]
_fmComment :: forall (b :: BackendType). FunctionMetadata b -> Maybe Text
..} =
      let confKeyPair :: [(Text, Value)]
confKeyPair =
            if FunctionConfig b
_fmConfiguration FunctionConfig b -> FunctionConfig b -> Bool
forall a. Eq a => a -> a -> Bool
== FunctionConfig b
forall (b :: BackendType). FunctionConfig b
emptyFunctionConfig
              then []
              else (Text, Value) -> [(Text, Value)]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text
"configuration", FunctionConfig b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered FunctionConfig b
_fmConfiguration)
          permissionsKeyPair :: [(Text, Value)]
permissionsKeyPair =
            if [FunctionPermissionInfo] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FunctionPermissionInfo]
_fmPermissions
              then []
              else (Text, Value) -> [(Text, Value)]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text
"permissions", [FunctionPermissionInfo] -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered [FunctionPermissionInfo]
_fmPermissions)
          commentKeyPair :: [(Text, Value)]
commentKeyPair =
            if Maybe Text -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Text
_fmComment
              then []
              else (Text, Value) -> [(Text, Value)]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text
"comment", Maybe Text -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe Text
_fmComment)
       in [(Text, Value)] -> Value
AO.object ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [(Text
"function", FunctionName b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered FunctionName b
_fmFunction)] [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
confKeyPair [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
permissionsKeyPair [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
commentKeyPair

remoteSchemasToOrdJSONList :: RemoteSchemas -> Maybe AO.Array
remoteSchemasToOrdJSONList :: RemoteSchemas -> Maybe Array
remoteSchemasToOrdJSONList = (RemoteSchemaMetadata -> Value)
-> (RemoteSchemaMetadata -> RemoteSchemaName)
-> RemoteSchemas
-> Maybe Array
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort RemoteSchemaMetadata -> Value
remoteSchemaQToOrdJSON RemoteSchemaMetadata -> RemoteSchemaName
forall r. RemoteSchemaMetadataG r -> RemoteSchemaName
_rsmName
  where
    remoteSchemaQToOrdJSON :: RemoteSchemaMetadata -> AO.Value
    remoteSchemaQToOrdJSON :: RemoteSchemaMetadata -> Value
remoteSchemaQToOrdJSON (RemoteSchemaMetadata RemoteSchemaName
name RemoteSchemaDef
definition Maybe Text
comment [RemoteSchemaPermissionMetadata]
permissions SchemaRemoteRelationships RemoteRelationshipDefinition
relationships) =
      [(Text, Value)] -> Value
AO.object
        ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", RemoteSchemaName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RemoteSchemaName
name),
            (Text
"definition", RemoteSchemaDef -> Value
remoteSchemaDefToOrdJSON RemoteSchemaDef
definition)
          ]
        [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
          [ Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair Maybe Text
comment,
            Text
-> (RemoteSchemaPermissionMetadata -> Value)
-> [RemoteSchemaPermissionMetadata]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair
              Text
"permissions"
              RemoteSchemaPermissionMetadata -> Value
permsToMaybeOrdJSON
              [RemoteSchemaPermissionMetadata]
permissions,
            Text
-> (RemoteSchemaTypeRelationships RemoteRelationshipDefinition
    -> Value)
-> SchemaRemoteRelationships RemoteRelationshipDefinition
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair
              Text
"remote_relationships"
              RemoteSchemaTypeRelationships RemoteRelationshipDefinition -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered
              SchemaRemoteRelationships RemoteRelationshipDefinition
relationships
          ]
      where
        permsToMaybeOrdJSON :: RemoteSchemaPermissionMetadata -> AO.Value
        permsToMaybeOrdJSON :: RemoteSchemaPermissionMetadata -> Value
permsToMaybeOrdJSON (RemoteSchemaPermissionMetadata RoleName
role RemoteSchemaPermissionDefinition
defn Maybe Text
permComment) =
          [(Text, Value)] -> Value
AO.object
            ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"role", RoleName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RoleName
role),
                (Text
"definition", RemoteSchemaPermissionDefinition -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RemoteSchemaPermissionDefinition
defn)
              ]
            [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair Maybe Text
permComment]

        remoteSchemaDefToOrdJSON :: RemoteSchemaDef -> AO.Value
        remoteSchemaDefToOrdJSON :: RemoteSchemaDef -> Value
remoteSchemaDefToOrdJSON (RemoteSchemaDef Maybe InputWebhook
url Maybe Text
urlFromEnv Maybe [HeaderConf]
headers Bool
frwrdClientHdrs Maybe Int
timeout Maybe RemoteSchemaCustomization
customization) =
          [(Text, Value)] -> Value
AO.object
            ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
              [ Text -> Maybe InputWebhook -> Maybe (Text, Value)
forall {a}. ToJSON a => Text -> Maybe a -> Maybe (Text, Value)
maybeToPair Text
"url" Maybe InputWebhook
url,
                Text -> Maybe Text -> Maybe (Text, Value)
forall {a}. ToJSON a => Text -> Maybe a -> Maybe (Text, Value)
maybeToPair Text
"url_from_env" Maybe Text
urlFromEnv,
                Text -> Maybe Int -> Maybe (Text, Value)
forall {a}. ToJSON a => Text -> Maybe a -> Maybe (Text, Value)
maybeToPair Text
"timeout_seconds" Maybe Int
timeout,
                Text -> Maybe RemoteSchemaCustomization -> Maybe (Text, Value)
forall {a}. ToJSON a => Text -> Maybe a -> Maybe (Text, Value)
maybeToPair Text
"customization" Maybe RemoteSchemaCustomization
customization,
                Maybe [HeaderConf]
headers Maybe [HeaderConf]
-> ([HeaderConf] -> Maybe (Text, Value)) -> Maybe (Text, Value)
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text
-> (HeaderConf -> Value) -> [HeaderConf] -> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"headers" HeaderConf -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered
              ]
            [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text
"forward_client_headers", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
frwrdClientHdrs) | Bool
frwrdClientHdrs]
          where
            maybeToPair :: Text -> Maybe a -> Maybe (Text, Value)
maybeToPair Text
n = Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
n a -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered

backendConfigsToOrdJSON :: BackendMap BackendConfigWrapper -> Maybe AO.Value
backendConfigsToOrdJSON :: BackendMap BackendConfigWrapper -> Maybe Value
backendConfigsToOrdJSON = (BackendMap BackendConfigWrapper -> Bool)
-> (BackendMap BackendConfigWrapper -> Value)
-> BackendMap BackendConfigWrapper
-> Maybe Value
forall a b. (a -> Bool) -> (a -> b) -> a -> Maybe b
ifNotEmpty (BackendMap BackendConfigWrapper
-> BackendMap BackendConfigWrapper -> Bool
forall a. Eq a => a -> a -> Bool
== BackendMap BackendConfigWrapper
forall a. Monoid a => a
mempty) BackendMap BackendConfigWrapper -> Value
configsToOrdJSON
  where
    configsToOrdJSON :: BackendMap BackendConfigWrapper -> AO.Value
    configsToOrdJSON :: BackendMap BackendConfigWrapper -> Value
configsToOrdJSON BackendMap BackendConfigWrapper
backendConfigs' =
      [(Text, Value)] -> Value
AO.object ([(Text, Value)] -> Value)
-> ([(Text, Value)] -> [(Text, Value)]) -> [(Text, Value)] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Text, Value) -> Text) -> [(Text, Value)] -> [(Text, Value)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (Text, Value) -> Text
forall a b. (a, b) -> a
fst ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ AnyBackend BackendConfigWrapper -> (Text, Value)
backendConfigToOrdJSON (AnyBackend BackendConfigWrapper -> (Text, Value))
-> [AnyBackend BackendConfigWrapper] -> [(Text, Value)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> BackendMap BackendConfigWrapper
-> [AnyBackend BackendConfigWrapper]
forall (i :: BackendType -> *). BackendMap i -> [AnyBackend i]
BackendMap.elems BackendMap BackendConfigWrapper
backendConfigs'

    backendConfigToOrdJSON :: AB.AnyBackend BackendConfigWrapper -> (Text, AO.Value)
    backendConfigToOrdJSON :: AnyBackend BackendConfigWrapper -> (Text, Value)
backendConfigToOrdJSON AnyBackend BackendConfigWrapper
backendConfig =
      forall (c :: BackendType -> Constraint) (i :: BackendType -> *) r.
AllBackendsSatisfy c =>
AnyBackend i -> (forall (b :: BackendType). c b => i b -> r) -> r
AB.dispatchAnyBackend @Backend AnyBackend BackendConfigWrapper
backendConfig ((forall (b :: BackendType).
  Backend b =>
  BackendConfigWrapper b -> (Text, Value))
 -> (Text, Value))
-> (forall (b :: BackendType).
    Backend b =>
    BackendConfigWrapper b -> (Text, Value))
-> (Text, Value)
forall a b. (a -> b) -> a -> b
$ \((BackendConfigWrapper BackendConfig b
backendConfig') :: BackendConfigWrapper b) ->
        let backendTypeStr :: Text
backendTypeStr = BackendType -> Text
forall a. ToTxt a => a -> Text
T.toTxt (BackendType -> Text) -> BackendType -> Text
forall a b. (a -> b) -> a -> b
$ BackendTag b -> BackendType
forall (b :: BackendType). BackendTag b -> BackendType
reify (BackendTag b -> BackendType) -> BackendTag b -> BackendType
forall a b. (a -> b) -> a -> b
$ forall (b :: BackendType). HasTag b => BackendTag b
backendTag @b
            val :: Value
val = BackendConfig b -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered BackendConfig b
backendConfig'
         in (Text
backendTypeStr, Value
val)

openTelemetryConfigToOrdJSON :: OpenTelemetryConfig -> Maybe AO.Value
openTelemetryConfigToOrdJSON :: OpenTelemetryConfig -> Maybe Value
openTelemetryConfigToOrdJSON = (OpenTelemetryConfig -> Bool)
-> (OpenTelemetryConfig -> Value)
-> OpenTelemetryConfig
-> Maybe Value
forall a b. (a -> Bool) -> (a -> b) -> a -> Maybe b
ifNotEmpty (OpenTelemetryConfig -> OpenTelemetryConfig -> Bool
forall a. Eq a => a -> a -> Bool
== OpenTelemetryConfig
emptyOpenTelemetryConfig) OpenTelemetryConfig -> Value
configToOrdJSON
  where
    configToOrdJSON :: OpenTelemetryConfig -> AO.Value
    configToOrdJSON :: OpenTelemetryConfig -> Value
configToOrdJSON (OpenTelemetryConfig OtelStatus
status Set OtelDataType
enabledDataTypes OtelExporterConfig
exporterOtlp OtelBatchSpanProcessorConfig
batchSpanProcessor) =
      [(Text, Value)] -> Value
AO.object
        [ (Text
"status", OtelStatus -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered OtelStatus
status),
          (Text
"data_types", Set OtelDataType -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Set OtelDataType
enabledDataTypes),
          (Text
"exporter_otlp", OtelExporterConfig -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered OtelExporterConfig
exporterOtlp),
          (Text
"batch_span_processor", OtelBatchSpanProcessorConfig -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered OtelBatchSpanProcessorConfig
batchSpanProcessor)
        ]

inheritedRolesToOrdJSONList :: InheritedRoles -> Maybe AO.Array
inheritedRolesToOrdJSONList :: InheritedRoles -> Maybe Array
inheritedRolesToOrdJSONList = (InheritedRole -> Value)
-> (InheritedRole -> RoleName) -> InheritedRoles -> Maybe Array
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort InheritedRole -> Value
inheritedRolesQToOrdJSON InheritedRole -> RoleName
_rRoleName
  where
    inheritedRolesQToOrdJSON :: InheritedRole -> AO.Value
    inheritedRolesQToOrdJSON :: InheritedRole -> Value
inheritedRolesQToOrdJSON (Role RoleName
roleName ParentRoles
roleSet) =
      [(Text, Value)] -> Value
AO.object
        [ (Text
"role_name", RoleName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RoleName
roleName),
          (Text
"role_set", ParentRoles -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ParentRoles
roleSet)
        ]

queryCollectionsToOrdJSONList :: QueryCollections -> Maybe AO.Array
queryCollectionsToOrdJSONList :: QueryCollections -> Maybe Array
queryCollectionsToOrdJSONList = (CreateCollection -> Value)
-> (CreateCollection -> CollectionName)
-> QueryCollections
-> Maybe Array
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort CreateCollection -> Value
createCollectionToOrdJSON CreateCollection -> CollectionName
_ccName
  where
    createCollectionToOrdJSON :: CreateCollection -> AO.Value
    createCollectionToOrdJSON :: CreateCollection -> Value
createCollectionToOrdJSON (CreateCollection CollectionName
name CollectionDef
definition Maybe Text
comment) =
      [(Text, Value)] -> Value
AO.object
        ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", CollectionName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered CollectionName
name),
            (Text
"definition", CollectionDef -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered CollectionDef
definition)
          ]
        [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair Maybe Text
comment]

allowlistToOrdJSONList :: MetadataAllowlist -> Maybe AO.Array
allowlistToOrdJSONList :: MetadataAllowlist -> Maybe Array
allowlistToOrdJSONList = (AllowlistEntry -> Value)
-> (AllowlistEntry -> CollectionName)
-> MetadataAllowlist
-> Maybe Array
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort (Value -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered (Value -> Value)
-> (AllowlistEntry -> Value) -> AllowlistEntry -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToJSON a => a -> Value
toJSON @AllowlistEntry) AllowlistEntry -> CollectionName
aeCollection

apiLimitsToOrdJSON :: ApiLimit -> Maybe AO.Value
apiLimitsToOrdJSON :: ApiLimit -> Maybe Value
apiLimitsToOrdJSON ApiLimit
apiLimits
  | ApiLimit
apiLimits ApiLimit -> ApiLimit -> Bool
forall a. Eq a => a -> a -> Bool
== ApiLimit
emptyApiLimit = Maybe Value
forall a. Maybe a
Nothing
  | Bool
otherwise = Value -> Maybe Value
forall a. a -> Maybe a
Just (Value -> Maybe Value) -> Value -> Maybe Value
forall a b. (a -> b) -> a -> b
$ ApiLimit -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ApiLimit
apiLimits

cronTriggersToOrdJSONList :: CronTriggers -> Maybe AO.Array
cronTriggersToOrdJSONList :: CronTriggers -> Maybe Array
cronTriggersToOrdJSONList = (CronTriggerMetadata -> Value)
-> (CronTriggerMetadata -> TriggerName)
-> CronTriggers
-> Maybe Array
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort CronTriggerMetadata -> Value
crontriggerQToOrdJSON CronTriggerMetadata -> TriggerName
ctName
  where
    crontriggerQToOrdJSON :: CronTriggerMetadata -> AO.Value
    crontriggerQToOrdJSON :: CronTriggerMetadata -> Value
crontriggerQToOrdJSON
      (CronTriggerMetadata TriggerName
name InputWebhook
webhook CronSchedule
schedule Maybe Value
payload STRetryConf
retryConf [HeaderConf]
headers Bool
includeInMetadata Maybe Text
comment Maybe RequestTransform
reqTransform Maybe MetadataResponseTransform
respTransform) =
        [(Text, Value)] -> Value
AO.object
          ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", TriggerName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered TriggerName
name),
              (Text
"webhook", InputWebhook -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered InputWebhook
webhook),
              (Text
"schedule", CronSchedule -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered CronSchedule
schedule),
              (Text
"include_in_metadata", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
includeInMetadata)
            ]
          [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
            [ Text -> (Value -> Value) -> Maybe Value -> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"payload" Value -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe Value
payload,
              Text
-> (STRetryConf -> Value)
-> Maybe STRetryConf
-> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"retry_conf" STRetryConf -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered (STRetryConf -> Maybe STRetryConf
maybeRetryConfiguration STRetryConf
retryConf),
              Text
-> ([HeaderConf] -> Value)
-> Maybe [HeaderConf]
-> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"headers" [HeaderConf] -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ([HeaderConf] -> Maybe [HeaderConf]
forall {t :: * -> *} {a}. Foldable t => t a -> Maybe (t a)
maybeHeader [HeaderConf]
headers),
              Text -> (Text -> Value) -> Maybe Text -> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"comment" Text -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe Text
comment,
              (RequestTransform -> (Text, Value))
-> Maybe RequestTransform -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
"request_transform",) (Value -> (Text, Value))
-> (RequestTransform -> Value) -> RequestTransform -> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequestTransform -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) Maybe RequestTransform
reqTransform,
              (MetadataResponseTransform -> (Text, Value))
-> Maybe MetadataResponseTransform -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
"response_transform",) (Value -> (Text, Value))
-> (MetadataResponseTransform -> Value)
-> MetadataResponseTransform
-> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetadataResponseTransform -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) Maybe MetadataResponseTransform
respTransform
            ]
        where
          maybeRetryConfiguration :: STRetryConf -> Maybe STRetryConf
maybeRetryConfiguration STRetryConf
retryConfig
            | STRetryConf
retryConfig STRetryConf -> STRetryConf -> Bool
forall a. Eq a => a -> a -> Bool
== STRetryConf
defaultSTRetryConf = Maybe STRetryConf
forall a. Maybe a
Nothing
            | Bool
otherwise = STRetryConf -> Maybe STRetryConf
forall a. a -> Maybe a
Just STRetryConf
retryConfig

          maybeHeader :: t a -> Maybe (t a)
maybeHeader t a
headerConfig
            | t a -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t a
headerConfig = Maybe (t a)
forall a. Maybe a
Nothing
            | Bool
otherwise = t a -> Maybe (t a)
forall a. a -> Maybe a
Just t a
headerConfig

customTypesToOrdJSON :: CustomTypes -> Maybe AO.Object
customTypesToOrdJSON :: CustomTypes -> Maybe Object
customTypesToOrdJSON customTypes :: CustomTypes
customTypes@(CustomTypes [InputObjectTypeDefinition]
inpObjs [ObjectTypeDefinition]
objs [ScalarTypeDefinition]
scalars [EnumTypeDefinition]
enums)
  | CustomTypes
customTypes CustomTypes -> CustomTypes -> Bool
forall a. Eq a => a -> a -> Bool
== CustomTypes
emptyCustomTypes = Maybe Object
forall a. Maybe a
Nothing
  | Bool
otherwise =
      Object -> Maybe Object
forall a. a -> Maybe a
Just
        (Object -> Maybe Object)
-> ([Maybe (Text, Value)] -> Object)
-> [Maybe (Text, Value)]
-> Maybe Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, Value)] -> Object
AO.fromList
        ([(Text, Value)] -> Object)
-> ([Maybe (Text, Value)] -> [(Text, Value)])
-> [Maybe (Text, Value)]
-> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
        ([Maybe (Text, Value)] -> Maybe Object)
-> [Maybe (Text, Value)] -> Maybe Object
forall a b. (a -> b) -> a -> b
$ [ Text
-> (InputObjectTypeDefinition -> Value)
-> [InputObjectTypeDefinition]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"input_objects" InputObjectTypeDefinition -> Value
inputObjectToOrdJSON [InputObjectTypeDefinition]
inpObjs,
            Text
-> (ObjectTypeDefinition -> Value)
-> [ObjectTypeDefinition]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"objects" ObjectTypeDefinition -> Value
objectTypeToOrdJSON [ObjectTypeDefinition]
objs,
            Text
-> (ScalarTypeDefinition -> Value)
-> [ScalarTypeDefinition]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"scalars" ScalarTypeDefinition -> Value
scalarTypeToOrdJSON [ScalarTypeDefinition]
scalars,
            Text
-> (EnumTypeDefinition -> Value)
-> [EnumTypeDefinition]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"enums" EnumTypeDefinition -> Value
enumTypeToOrdJSON [EnumTypeDefinition]
enums
          ]
  where
    inputObjectToOrdJSON :: InputObjectTypeDefinition -> AO.Value
    inputObjectToOrdJSON :: InputObjectTypeDefinition -> Value
inputObjectToOrdJSON (InputObjectTypeDefinition InputObjectTypeName
tyName Maybe Description
descM NonEmpty InputObjectFieldDefinition
fields) =
      [(Text, Value)] -> Value
AO.object
        ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", InputObjectTypeName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered InputObjectTypeName
tyName),
            (Text
"fields", [Value] -> Value
AO.array ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ (InputObjectFieldDefinition -> Value)
-> [InputObjectFieldDefinition] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map InputObjectFieldDefinition -> Value
fieldDefinitionToOrdJSON ([InputObjectFieldDefinition] -> [Value])
-> [InputObjectFieldDefinition] -> [Value]
forall a b. (a -> b) -> a -> b
$ NonEmpty InputObjectFieldDefinition -> [InputObjectFieldDefinition]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty InputObjectFieldDefinition
fields)
          ]
        [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Description -> Maybe (Text, Value)
maybeDescriptionToMaybeOrdPair Maybe Description
descM]
      where
        fieldDefinitionToOrdJSON :: InputObjectFieldDefinition -> AO.Value
        fieldDefinitionToOrdJSON :: InputObjectFieldDefinition -> Value
fieldDefinitionToOrdJSON (InputObjectFieldDefinition InputObjectFieldName
fieldName Maybe Description
fieldDescM GraphQLType
ty) =
          [(Text, Value)] -> Value
AO.object
            ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", InputObjectFieldName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered InputObjectFieldName
fieldName),
                (Text
"type", GraphQLType -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered GraphQLType
ty)
              ]
            [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Description -> Maybe (Text, Value)
maybeDescriptionToMaybeOrdPair Maybe Description
fieldDescM]

    objectTypeToOrdJSON :: ObjectTypeDefinition -> AO.Value
    objectTypeToOrdJSON :: ObjectTypeDefinition -> Value
objectTypeToOrdJSON (ObjectTypeDefinition ObjectTypeName
tyName Maybe Description
descM NonEmpty (ObjectFieldDefinition GraphQLType)
fields [TypeRelationshipDefinition]
rels) =
      [(Text, Value)] -> Value
AO.object
        ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", ObjectTypeName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ObjectTypeName
tyName),
            (Text
"fields", [Value] -> Value
AO.array ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ (ObjectFieldDefinition GraphQLType -> Value)
-> [ObjectFieldDefinition GraphQLType] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map ObjectFieldDefinition GraphQLType -> Value
fieldDefinitionToOrdJSON ([ObjectFieldDefinition GraphQLType] -> [Value])
-> [ObjectFieldDefinition GraphQLType] -> [Value]
forall a b. (a -> b) -> a -> b
$ NonEmpty (ObjectFieldDefinition GraphQLType)
-> [ObjectFieldDefinition GraphQLType]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty (ObjectFieldDefinition GraphQLType)
fields)
          ]
        [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
          [ Maybe Description -> Maybe (Text, Value)
maybeDescriptionToMaybeOrdPair Maybe Description
descM,
            Text
-> (TypeRelationshipDefinition -> Value)
-> [TypeRelationshipDefinition]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"relationships" TypeRelationshipDefinition -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered [TypeRelationshipDefinition]
rels
          ]
      where
        fieldDefinitionToOrdJSON :: ObjectFieldDefinition GraphQLType -> AO.Value
        fieldDefinitionToOrdJSON :: ObjectFieldDefinition GraphQLType -> Value
fieldDefinitionToOrdJSON (ObjectFieldDefinition ObjectFieldName
fieldName Maybe Value
argsValM Maybe Description
fieldDescM GraphQLType
ty) =
          [(Text, Value)] -> Value
AO.object
            ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", ObjectFieldName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ObjectFieldName
fieldName),
                (Text
"type", GraphQLType -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered GraphQLType
ty)
              ]
            [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
              [ (Text
"arguments",) (Value -> (Text, Value))
-> (Value -> Value) -> Value -> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered (Value -> (Text, Value)) -> Maybe Value -> Maybe (Text, Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Value
argsValM,
                Maybe Description -> Maybe (Text, Value)
maybeDescriptionToMaybeOrdPair Maybe Description
fieldDescM
              ]

    scalarTypeToOrdJSON :: ScalarTypeDefinition -> AO.Value
    scalarTypeToOrdJSON :: ScalarTypeDefinition -> Value
scalarTypeToOrdJSON (ScalarTypeDefinition Name
tyName Maybe Description
descM) =
      [(Text, Value)] -> Value
AO.object
        ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [(Text
"name", Name -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Name
tyName)]
        [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Description -> Maybe (Text, Value)
maybeDescriptionToMaybeOrdPair Maybe Description
descM]

    enumTypeToOrdJSON :: EnumTypeDefinition -> AO.Value
    enumTypeToOrdJSON :: EnumTypeDefinition -> Value
enumTypeToOrdJSON (EnumTypeDefinition EnumTypeName
tyName Maybe Description
descM NonEmpty EnumValueDefinition
values) =
      [(Text, Value)] -> Value
AO.object
        ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", EnumTypeName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered EnumTypeName
tyName),
            (Text
"values", NonEmpty EnumValueDefinition -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered NonEmpty EnumValueDefinition
values)
          ]
        [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Description -> Maybe (Text, Value)
maybeDescriptionToMaybeOrdPair Maybe Description
descM]

endpointsToOrdJSONList :: Endpoints -> Maybe AO.Array
endpointsToOrdJSONList :: Endpoints -> Maybe Array
endpointsToOrdJSONList = (CreateEndpoint -> Value)
-> (CreateEndpoint -> EndpointUrl) -> Endpoints -> Maybe Array
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort CreateEndpoint -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered CreateEndpoint -> EndpointUrl
forall query. EndpointMetadata query -> EndpointUrl
_ceUrl

introspectionDisabledRolesToOrdJSON :: SetGraphqlIntrospectionOptions -> Maybe AO.Value
introspectionDisabledRolesToOrdJSON :: SetGraphqlIntrospectionOptions -> Maybe Value
introspectionDisabledRolesToOrdJSON = (SetGraphqlIntrospectionOptions -> Bool)
-> (SetGraphqlIntrospectionOptions -> Value)
-> SetGraphqlIntrospectionOptions
-> Maybe Value
forall a b. (a -> Bool) -> (a -> b) -> a -> Maybe b
ifNotEmpty (SetGraphqlIntrospectionOptions
-> SetGraphqlIntrospectionOptions -> Bool
forall a. Eq a => a -> a -> Bool
== SetGraphqlIntrospectionOptions
forall a. Monoid a => a
mempty) SetGraphqlIntrospectionOptions -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered

metricsConfigToOrdJSON :: MetricsConfig -> Maybe AO.Value
metricsConfigToOrdJSON :: MetricsConfig -> Maybe Value
metricsConfigToOrdJSON = (MetricsConfig -> Bool)
-> (MetricsConfig -> Value) -> MetricsConfig -> Maybe Value
forall a b. (a -> Bool) -> (a -> b) -> a -> Maybe b
ifNotEmpty (MetricsConfig -> MetricsConfig -> Bool
forall a. Eq a => a -> a -> Bool
== MetricsConfig
emptyMetricsConfig) MetricsConfig -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered

networkConfigToOrdJSON :: Network -> Maybe AO.Value
networkConfigToOrdJSON :: Network -> Maybe Value
networkConfigToOrdJSON = (Network -> Bool) -> (Network -> Value) -> Network -> Maybe Value
forall a b. (a -> Bool) -> (a -> b) -> a -> Maybe b
ifNotEmpty (Network -> Network -> Bool
forall a. Eq a => a -> a -> Bool
== Network
emptyNetwork) Network -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered

actionMetadataToOrdJSONList :: Actions -> Maybe AO.Array
actionMetadataToOrdJSONList :: Actions -> Maybe Array
actionMetadataToOrdJSONList = (ActionMetadata -> Value)
-> (ActionMetadata -> ActionName) -> Actions -> Maybe Array
forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort ActionMetadata -> Value
actionMetadataToOrdJSON ActionMetadata -> ActionName
_amName
  where
    actionMetadataToOrdJSON :: ActionMetadata -> AO.Value
    actionMetadataToOrdJSON :: ActionMetadata -> Value
actionMetadataToOrdJSON (ActionMetadata ActionName
name Maybe Text
comment ActionDefinitionInput
definition [ActionPermissionMetadata]
permissions) =
      [(Text, Value)] -> Value
AO.object
        ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", ActionName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ActionName
name),
            (Text
"definition", ActionDefinitionInput -> Value
actionDefinitionToOrdJSON ActionDefinitionInput
definition)
          ]
        [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
          [ Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair Maybe Text
comment,
            Text
-> (ActionPermissionMetadata -> Value)
-> [ActionPermissionMetadata]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"permissions" ActionPermissionMetadata -> Value
permToOrdJSON [ActionPermissionMetadata]
permissions
          ]
      where
        argDefinitionToOrdJSON :: ArgumentDefinition GraphQLType -> AO.Value
        argDefinitionToOrdJSON :: ArgumentDefinition GraphQLType -> Value
argDefinitionToOrdJSON (ArgumentDefinition ArgumentName
argName GraphQLType
ty Maybe Description
descM) =
          [(Text, Value)] -> Value
AO.object
            ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"name", ArgumentName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ArgumentName
argName),
                (Text
"type", GraphQLType -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered GraphQLType
ty)
              ]
            [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Text
-> (Description -> Value)
-> Maybe Description
-> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"description" Description -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Maybe Description
descM]

        actionDefinitionToOrdJSON :: ActionDefinitionInput -> AO.Value
        actionDefinitionToOrdJSON :: ActionDefinitionInput -> Value
actionDefinitionToOrdJSON
          ( ActionDefinition
              [ArgumentDefinition GraphQLType]
args
              GraphQLType
outputType
              ActionType
actionType
              [HeaderConf]
headers
              Bool
frwrdClientHdrs
              Timeout
timeout
              InputWebhook
handler
              Maybe RequestTransform
requestTransform
              Maybe MetadataResponseTransform
responseTransform
            ) =
            let typeAndKind :: [(Text, Value)]
typeAndKind = case ActionType
actionType of
                  ActionType
ActionQuery -> [(Text
"type", String -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered (String
"query" :: String))]
                  ActionMutation ActionMutationKind
kind ->
                    [ (Text
"type", String -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered (String
"mutation" :: String)),
                      (Text
"kind", ActionMutationKind -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered ActionMutationKind
kind)
                    ]
             in [(Text, Value)] -> Value
AO.object
                  ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [ (Text
"handler", InputWebhook -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered InputWebhook
handler),
                      (Text
"output_type", GraphQLType -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered GraphQLType
outputType)
                    ]
                  [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text
"forward_client_headers", Bool -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Bool
frwrdClientHdrs) | Bool
frwrdClientHdrs]
                  [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
                    [ Text
-> (HeaderConf -> Value) -> [HeaderConf] -> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"headers" HeaderConf -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered [HeaderConf]
headers,
                      Text
-> (ArgumentDefinition GraphQLType -> Value)
-> [ArgumentDefinition GraphQLType]
-> Maybe (Text, Value)
forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
"arguments" ArgumentDefinition GraphQLType -> Value
argDefinitionToOrdJSON [ArgumentDefinition GraphQLType]
args,
                      (RequestTransform -> (Text, Value))
-> Maybe RequestTransform -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
"request_transform",) (Value -> (Text, Value))
-> (RequestTransform -> Value) -> RequestTransform -> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RequestTransform -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) Maybe RequestTransform
requestTransform,
                      (MetadataResponseTransform -> (Text, Value))
-> Maybe MetadataResponseTransform -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
"response_transform",) (Value -> (Text, Value))
-> (MetadataResponseTransform -> Value)
-> MetadataResponseTransform
-> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetadataResponseTransform -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered) Maybe MetadataResponseTransform
responseTransform
                    ]
                  [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)]
typeAndKind
                  [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Value)] -> [(Text, Value)] -> Bool -> [(Text, Value)]
forall a. a -> a -> Bool -> a
bool [(Text
"timeout", Timeout -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Timeout
timeout)] [(Text, Value)]
forall a. Monoid a => a
mempty (Timeout
timeout Timeout -> Timeout -> Bool
forall a. Eq a => a -> a -> Bool
== Timeout
defaultActionTimeoutSecs)

        permToOrdJSON :: ActionPermissionMetadata -> AO.Value
        permToOrdJSON :: ActionPermissionMetadata -> Value
permToOrdJSON (ActionPermissionMetadata RoleName
role Maybe Text
permComment) =
          [(Text, Value)] -> Value
AO.object ([(Text, Value)] -> Value) -> [(Text, Value)] -> Value
forall a b. (a -> b) -> a -> b
$ [(Text
"role", RoleName -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered RoleName
role)] [(Text, Value)] -> [(Text, Value)] -> [(Text, Value)]
forall a. Semigroup a => a -> a -> a
<> [Maybe (Text, Value)] -> [(Text, Value)]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair Maybe Text
permComment]

ifNotEmpty :: (a -> Bool) -> (a -> b) -> a -> Maybe b
ifNotEmpty :: forall a b. (a -> Bool) -> (a -> b) -> a -> Maybe b
ifNotEmpty a -> Bool
isEmpty a -> b
f a
x
  | a -> Bool
isEmpty a
x = Maybe b
forall a. Maybe a
Nothing
  | Bool
otherwise = b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> b -> Maybe b
forall a b. (a -> b) -> a -> b
$ a -> b
f a
x

-- | Sort list before encoding to JSON value
listToMaybeOrdPairSort ::
  (Foldable t, Ord b) =>
  Text ->
  (a -> AO.Value) ->
  (a -> b) ->
  t a ->
  Maybe (Text, AO.Value)
listToMaybeOrdPairSort :: forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
Text -> (a -> Value) -> (a -> b) -> t a -> Maybe (Text, Value)
listToMaybeOrdPairSort Text
name a -> Value
f a -> b
sortF t a
ta = case t a -> [a]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList t a
ta of
  [] -> Maybe (Text, Value)
forall a. Maybe a
Nothing
  [a]
list -> (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just ((Text, Value) -> Maybe (Text, Value))
-> (Text, Value) -> Maybe (Text, Value)
forall a b. (a -> b) -> a -> b
$ (Text
name,) (Value -> (Text, Value)) -> Value -> (Text, Value)
forall a b. (a -> b) -> a -> b
$ [Value] -> Value
AO.array ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ (a -> Value) -> [a] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map a -> Value
f ([a] -> [Value]) -> [a] -> [Value]
forall a b. (a -> b) -> a -> b
$ (a -> b) -> [a] -> [a]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn a -> b
sortF [a]
list

-- | Sort list before encoding to JSON array (not value)
listToMaybeArraySort ::
  (Foldable t, Ord b) =>
  (a -> AO.Value) ->
  (a -> b) ->
  t a ->
  Maybe AO.Array
listToMaybeArraySort :: forall (t :: * -> *) b a.
(Foldable t, Ord b) =>
(a -> Value) -> (a -> b) -> t a -> Maybe Array
listToMaybeArraySort a -> Value
f a -> b
sortF t a
ta = case t a -> [a]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList t a
ta of
  [] -> Maybe Array
forall a. Maybe a
Nothing
  [a]
list -> Array -> Maybe Array
forall a. a -> Maybe a
Just (Array -> Maybe Array) -> Array -> Maybe Array
forall a b. (a -> b) -> a -> b
$ [Value] -> Array
forall a. [a] -> Vector a
Vector.fromList ([Value] -> Array) -> [Value] -> Array
forall a b. (a -> b) -> a -> b
$ (a -> Value) -> [a] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map a -> Value
f ([a] -> [Value]) -> [a] -> [Value]
forall a b. (a -> b) -> a -> b
$ (a -> b) -> [a] -> [a]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn a -> b
sortF [a]
list

listToMaybeOrdPair ::
  (Foldable t) =>
  Text ->
  (a -> AO.Value) ->
  t a ->
  Maybe (Text, AO.Value)
listToMaybeOrdPair :: forall (t :: * -> *) a.
Foldable t =>
Text -> (a -> Value) -> t a -> Maybe (Text, Value)
listToMaybeOrdPair Text
name a -> Value
f t a
ta = case t a -> [a]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList t a
ta of
  [] -> Maybe (Text, Value)
forall a. Maybe a
Nothing
  [a]
list -> (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just ((Text, Value) -> Maybe (Text, Value))
-> (Text, Value) -> Maybe (Text, Value)
forall a b. (a -> b) -> a -> b
$ (Text
name,) (Value -> (Text, Value)) -> Value -> (Text, Value)
forall a b. (a -> b) -> a -> b
$ [Value] -> Value
AO.array ([Value] -> Value) -> [Value] -> Value
forall a b. (a -> b) -> a -> b
$ (a -> Value) -> [a] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map a -> Value
f [a]
list

maybeSetToMaybeOrdPair :: (Backend b) => Maybe (ColumnValues b J.Value) -> Maybe (Text, AO.Value)
maybeSetToMaybeOrdPair :: forall (b :: BackendType).
Backend b =>
Maybe (ColumnValues b Value) -> Maybe (Text, Value)
maybeSetToMaybeOrdPair Maybe (HashMap (Column b) Value)
set =
  Maybe (HashMap (Column b) Value)
set Maybe (HashMap (Column b) Value)
-> (HashMap (Column b) Value -> Maybe (Text, Value))
-> Maybe (Text, Value)
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \HashMap (Column b) Value
colVals ->
    if HashMap (Column b) Value
colVals HashMap (Column b) Value -> HashMap (Column b) Value -> Bool
forall a. Eq a => a -> a -> Bool
== HashMap (Column b) Value
forall a. Monoid a => a
mempty
      then Maybe (Text, Value)
forall a. Maybe a
Nothing
      else (Text, Value) -> Maybe (Text, Value)
forall a. a -> Maybe a
Just (Text
"set", HashMap (Column b) Value -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered HashMap (Column b) Value
colVals)

maybeDescriptionToMaybeOrdPair :: Maybe G.Description -> Maybe (Text, AO.Value)
maybeDescriptionToMaybeOrdPair :: Maybe Description -> Maybe (Text, Value)
maybeDescriptionToMaybeOrdPair = Text
-> (Description -> Value)
-> Maybe Description
-> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"description" Description -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered

maybeCommentToMaybeOrdPair :: Maybe Text -> Maybe (Text, AO.Value)
maybeCommentToMaybeOrdPair :: Maybe Text -> Maybe (Text, Value)
maybeCommentToMaybeOrdPair = Text -> (Text -> Value) -> Maybe Text -> Maybe (Text, Value)
forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
"comment" Text -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered

maybeAnyToMaybeOrdPair :: Text -> (a -> AO.Value) -> Maybe a -> Maybe (Text, AO.Value)
maybeAnyToMaybeOrdPair :: forall a. Text -> (a -> Value) -> Maybe a -> Maybe (Text, Value)
maybeAnyToMaybeOrdPair Text
name a -> Value
f = (a -> (Text, Value)) -> Maybe a -> Maybe (Text, Value)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Text
name,) (Value -> (Text, Value)) -> (a -> Value) -> a -> (Text, Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Value
f)

commentToMaybeOrdPair :: Comment -> Maybe (Text, AO.Value)
commentToMaybeOrdPair :: Comment -> Maybe (Text, Value)
commentToMaybeOrdPair Comment
comment = (\Text
val -> (Text
"comment", Text -> Value
forall a. ToJSON a => a -> Value
AO.toOrdered Text
val)) (Text -> (Text, Value)) -> Maybe Text -> Maybe (Text, Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Comment -> Maybe Text
commentToMaybeText Comment
comment