{-# OPTIONS_GHC -Wno-orphans #-}
module Hasura.RQL.DDL.Webhook.Transform.Method
(
Method (..),
TransformFn (..),
TransformCtx (..),
MethodTransformFn (..),
)
where
import Data.Validation
import Hasura.Prelude
import Hasura.RQL.DDL.Webhook.Transform.Class
( TemplatingEngine,
Transform (..),
TransformErrorBundle (..),
)
import Hasura.RQL.DDL.Webhook.Transform.Request (RequestTransformCtx)
import Hasura.RQL.Types.Webhook.Transform.Method (Method (..), MethodTransformFn (..), TransformCtx (..), TransformFn (..))
instance Transform Method where
transform :: forall (m :: * -> *).
MonadError TransformErrorBundle m =>
TransformFn Method -> TransformCtx Method -> Method -> m Method
transform (MethodTransformFn_ MethodTransformFn
fn) (TransformCtx RequestTransformCtx
reqCtx) = MethodTransformFn -> RequestTransformCtx -> Method -> m Method
forall (m :: * -> *).
MonadError TransformErrorBundle m =>
MethodTransformFn -> RequestTransformCtx -> Method -> m Method
applyMethodTransformFn MethodTransformFn
fn RequestTransformCtx
reqCtx
validate :: TemplatingEngine
-> TransformFn Method -> Validation TransformErrorBundle ()
validate TemplatingEngine
engine (MethodTransformFn_ MethodTransformFn
fn) = TemplatingEngine
-> MethodTransformFn -> Validation TransformErrorBundle ()
validateMethodTransformFn TemplatingEngine
engine MethodTransformFn
fn
applyMethodTransformFn ::
(MonadError TransformErrorBundle m) =>
MethodTransformFn ->
RequestTransformCtx ->
Method ->
m Method
applyMethodTransformFn :: forall (m :: * -> *).
MonadError TransformErrorBundle m =>
MethodTransformFn -> RequestTransformCtx -> Method -> m Method
applyMethodTransformFn MethodTransformFn
fn RequestTransformCtx
_context Method
_oldMethod = case MethodTransformFn
fn of
Replace Method
newMethod -> Method -> m Method
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Method
newMethod
validateMethodTransformFn ::
TemplatingEngine ->
MethodTransformFn ->
Validation TransformErrorBundle ()
validateMethodTransformFn :: TemplatingEngine
-> MethodTransformFn -> Validation TransformErrorBundle ()
validateMethodTransformFn TemplatingEngine
_engine = \case
Replace Method
_method -> () -> Validation TransformErrorBundle ()
forall a. a -> Validation TransformErrorBundle a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()