Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
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.
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]'.
TransformErrorBundle | |
|
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.
RequestTransformCtx | |
|
Instances
ToJSON RequestTransformCtx Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class 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.
ResponseTransformCtx | |
|
data TemplatingEngine Source #
Available templating engines.
Instances
Textual transformation template.
Template | |
|
Instances
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 parseJSON :: Value -> Parser Version parseJSONList :: Value -> Parser [Version] | |
ToJSON Version Source # | |
Defined in Hasura.RQL.DDL.Webhook.Transform.Class 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.
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