| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasura.RQL.DDL.Webhook.Transform.Class
Description
The Transform typeclass with various types and helper functions
for evaluating transformations.
Synopsis
- class Transform a where
- data TransformFn a :: Type
- transform :: MonadError TransformErrorBundle m => TransformFn a -> RequestTransformCtx -> a -> m a
- validate :: TemplatingEngine -> TransformFn a -> Validation TransformErrorBundle ()
- newtype TransformErrorBundle = TransformErrorBundle {
- tebMessages :: [Value]
- throwErrorBundle :: MonadError TransformErrorBundle m => Text -> Maybe Value -> m a
- data RequestTransformCtx = RequestTransformCtx {
- rtcBaseUrl :: Maybe Value
- rtcBody :: Value
- rtcSessionVariables :: Value
- rtcQueryParams :: Maybe Value
- rtcEngine :: TemplatingEngine
- rtcFunctions :: HashMap Text (Value -> Either CustomFunctionError Value)
- mkReqTransformCtx :: Text -> Maybe SessionVariables -> TemplatingEngine -> Request -> RequestTransformCtx
- data ResponseTransformCtx = ResponseTransformCtx {
- responseTransformBody :: Value
- responseTransformReqCtx :: Value
- responseTransformFunctions :: HashMap Text (Value -> Either CustomFunctionError Value)
- responseTransformEngine :: TemplatingEngine
- data TemplatingEngine = Kriti
- newtype Template = Template {
- unTemplate :: Text
- runRequestTemplateTransform :: Template -> RequestTransformCtx -> Either TransformErrorBundle Value
- validateRequestTemplateTransform :: TemplatingEngine -> Template -> Either TransformErrorBundle ()
- validateRequestTemplateTransform' :: TemplatingEngine -> Template -> Validation TransformErrorBundle ()
- runResponseTemplateTransform :: Template -> ResponseTransformCtx -> Either TransformErrorBundle Value
- data Version
- newtype UnescapedTemplate = UnescapedTemplate {
- getUnescapedTemplate :: Text
- wrapUnescapedTemplate :: UnescapedTemplate -> Template
- runUnescapedRequestTemplateTransform :: RequestTransformCtx -> UnescapedTemplate -> Either TransformErrorBundle ByteString
- runUnescapedRequestTemplateTransform' :: RequestTransformCtx -> UnescapedTemplate -> Validation TransformErrorBundle ByteString
- validateRequestUnescapedTemplateTransform :: TemplatingEngine -> UnescapedTemplate -> Either TransformErrorBundle ()
- validateRequestUnescapedTemplateTransform' :: TemplatingEngine -> UnescapedTemplate -> Validation TransformErrorBundle ()
- runUnescapedResponseTemplateTransform :: ResponseTransformCtx -> UnescapedTemplate -> Either TransformErrorBundle ByteString
- runUnescapedResponseTemplateTransform' :: ResponseTransformCtx -> UnescapedTemplate -> Validation TransformErrorBundle ByteString
- encodeScalar :: MonadError TransformErrorBundle m => Value -> m ByteString
Documentation
class Transform a where Source #
Transform describes how to reify a defunctionalized transformation for
a particular request field.
Associated Types
data TransformFn a :: Type Source #
The associated type 'TransformFn a' is the defunctionalized version of some transformation that should be applied to a given request field.
In most cases it is some variation on a piece of template text describing the transformation.
Methods
transform :: MonadError TransformErrorBundle m => TransformFn a -> RequestTransformCtx -> a -> m a Source #
transform is a function which takes TransformFn of a and reifies
it into a function of the form:
ReqTransformCtx -> a -> m a
validate :: TemplatingEngine -> TransformFn a -> Validation TransformErrorBundle () Source #
Validate a TransformFn of a.
Instances
newtype TransformErrorBundle Source #
We use collect all transformation failures as a '[J.Value]'.
Constructors
| TransformErrorBundle | |
Fields
| |
Instances
throwErrorBundle :: MonadError TransformErrorBundle m => Text -> Maybe Value -> m a Source #
A helper function for serializing transformation errors to JSON.
data RequestTransformCtx Source #
Common context that is made available to all request transformations.
Constructors
| RequestTransformCtx | |
Fields
| |
Instances
| ToJSON RequestTransformCtx Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class Methods toJSON :: RequestTransformCtx -> Value toEncoding :: RequestTransformCtx -> Encoding toJSONList :: [RequestTransformCtx] -> Value toEncodingList :: [RequestTransformCtx] -> Encoding | |
mkReqTransformCtx :: Text -> Maybe SessionVariables -> TemplatingEngine -> Request -> RequestTransformCtx Source #
A smart constructor for constructing the RequestTransformCtx
XXX: This function makes internal usage of decodeUtf8, which throws an
impure exception when the supplied ByteString cannot be decoded into valid
UTF8 text!
data ResponseTransformCtx Source #
Common context that is made available to all response transformations.
Constructors
| ResponseTransformCtx | |
Fields
| |
data TemplatingEngine Source #
Available templating engines.
Constructors
| Kriti |
Instances
Textual transformation template.
Constructors
| Template | |
Fields
| |
Instances
| Eq Template Source # | |
| Ord Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| Show Template Source # | |
| Generic Template Source # | |
| NFData Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| Hashable Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| FromJSONKey Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| FromJSON Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| ToJSONKey Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| ToJSON Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class Methods toEncoding :: Template -> Encoding toJSONList :: [Template] -> Value toEncodingList :: [Template] -> Encoding | |
| Cacheable Template Source # | |
| type Rep Template Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
runRequestTemplateTransform :: Template -> RequestTransformCtx -> Either TransformErrorBundle Value Source #
A helper function for executing transformations from a Template
and a RequestTransformCtx.
NOTE: This and all related funtions are hard-coded to Kriti at the
moment. When we add additional template engines this function will
need to take a TemplatingEngine parameter.
validateRequestTemplateTransform :: TemplatingEngine -> Template -> Either TransformErrorBundle () Source #
validateRequestTemplateTransform' :: TemplatingEngine -> Template -> Validation TransformErrorBundle () Source #
runResponseTemplateTransform :: Template -> ResponseTransformCtx -> Either TransformErrorBundle Value Source #
A helper function for executing transformations from a Template
and a ResponseTransformCtx.
NOTE: This and all related funtions are hard-coded to Kriti at the
moment. When we add additional template engines this function will
need to take a TemplatingEngine parameter.
RequestTransform Versioning
Instances
| Eq Version Source # | |
| Show Version Source # | |
| Generic Version Source # | |
| NFData Version Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| Hashable Version Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| FromJSON Version Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class | |
| ToJSON Version Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class Methods toEncoding :: Version -> Encoding toJSONList :: [Version] -> Value toEncodingList :: [Version] -> Encoding | |
| Cacheable Version Source # | |
| type Rep Version Source # | |
newtype UnescapedTemplate Source #
Validated textual transformation template /for string interpolation only/.
This is necessary due to Kriti not distinguishing between string literals and string templates.
Constructors
| UnescapedTemplate | |
Fields
| |
Instances
wrapUnescapedTemplate :: UnescapedTemplate -> Template Source #
Wrap an UnescapedTemplate with escaped double quotes.
runUnescapedRequestTemplateTransform :: RequestTransformCtx -> UnescapedTemplate -> Either TransformErrorBundle ByteString Source #
A helper function for executing Kriti transformations from a
UnescapedTemplate and a RequestTrasformCtx.
The difference from runRequestTemplateTransform is that this
function will wrap the template text in double quotes before
running Kriti.
runUnescapedRequestTemplateTransform' :: RequestTransformCtx -> UnescapedTemplate -> Validation TransformErrorBundle ByteString Source #
Run a Kriti transformation with an unescaped template in
Validation instead of Either.
validateRequestUnescapedTemplateTransform :: TemplatingEngine -> UnescapedTemplate -> Either TransformErrorBundle () Source #
validateRequestUnescapedTemplateTransform' :: TemplatingEngine -> UnescapedTemplate -> Validation TransformErrorBundle () Source #
runUnescapedResponseTemplateTransform :: ResponseTransformCtx -> UnescapedTemplate -> Either TransformErrorBundle ByteString Source #
Run an UnescapedTemplate with a ResponseTransformCtx.
runUnescapedResponseTemplateTransform' :: ResponseTransformCtx -> UnescapedTemplate -> Validation TransformErrorBundle ByteString Source #
Run an UnescapedTemplate with a ResponseTransformCtx in Validation.
encodeScalar :: MonadError TransformErrorBundle m => Value -> m ByteString Source #
Encode a JSON Scalar Value as a ByteString.
If a non-Scalar value is provided, will return a TrnasformErrorBundle