packages feed

ngx-export-tools-extra 1.2.2 → 1.2.3

raw patch · 3 files changed

+31/−15 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ NgxExport.Tools.EDE: extraEDEFilters :: HashMap Id Term
- NgxExport.Tools.EDE: renderEDETemplateWith :: (ByteString -> Maybe Value) -> ByteString -> ByteString -> IO ByteString
+ NgxExport.Tools.EDE: renderEDETemplateWith :: (ByteString -> Maybe Value) -> HashMap Id Term -> ByteString -> ByteString -> IO ByteString

Files

Changelog.md view
@@ -1,6 +1,13 @@+### 1.2.3++- In module *NgxExport.Tools.EDE*, custom EDE filters are now passed into+  function *renderEDETemplateWith*. The collection of custom EDE filters with+  *b64* and *uenc* filters is now exported from the module by name+  *extraEDEFilters*.+ ### 1.2.2 -- Added Cabal constraint *resolv > 0.2.0.1* to fix memory leaks in module+- Added Cabal constraint *resolv ≥ 0.2.0.1* to fix memory leaks in module   *NgxExport.Tools.Resolve*.  ### 1.2.1
NgxExport/Tools/EDE.hs view
@@ -3,7 +3,7 @@ ----------------------------------------------------------------------------- -- | -- Module      :  NgxExport.Tools.EDE--- Copyright   :  (c) Alexey Radkov 2020-2022+-- Copyright   :  (c) Alexey Radkov 2020-2023 -- License     :  BSD-style -- -- Maintainer  :  alexey.radkov@gmail.com@@ -19,7 +19,8 @@ module NgxExport.Tools.EDE (     -- * Rendering JSON objects using EDE templates     -- $renderingEDETemplates-                            renderEDETemplate+                            extraEDEFilters+                           ,renderEDETemplate                            ,renderEDETemplateWith                            ,renderEDETemplateFromFreeValue                            ) where@@ -174,8 +175,8 @@ -- language. There are many filters shipped with EDE, but /b64/ and /uenc/ were -- defined in this module. ----- * __/b64/__ encodes a JSON object using /base64url/ encoding--- * __/uenc/__ encodes a JSON object using /URL encoding/ rules+-- * __/b64/__ encodes an Aeson's 'Value' using /base64url/ encoding,+-- * __/uenc/__ encodes an Aeson's 'Value' using /URL encoding/ rules. -- -- So, basically, we used /renderEDETemplate/ to decompose POSTed JSON objects -- and then /rewrite/ requests to other locations where the URL path after@@ -233,8 +234,15 @@ ngxExportSimpleServiceTyped 'compileEDETemplates ''InputTemplates     SingleShotService -filters :: HashMap Id Term-filters = HM.fromList+-- | A small collection of custom EDE filters.+--+-- The collection is used in 'renderEDETemplate' and contains the following+-- /polymorphic/ filters:+--+--   * __/b64/__ encodes a 'Value' using /base64url/ encoding,+--   * __/uenc/__ encodes a 'Value' using /URL encoding/ rules.+extraEDEFilters :: HashMap Id Term+extraEDEFilters = HM.fromList     ["b64"  @: applyToValue encodeBase64     ,"uenc" @: applyToValue (T.decodeUtf8 . urlEncode False)     ]@@ -250,18 +258,19 @@ renderEDETemplate :: L.ByteString       -- ^ JSON object                   -> ByteString         -- ^ Key to find the EDE template                   -> IO L.ByteString-renderEDETemplate = renderEDETemplateWith decode+renderEDETemplate = renderEDETemplateWith decode extraEDEFilters --- | Renders an EDE template with a custom decoding function.+-- | Renders an EDE template with custom decoding function and filters. ----- This function can be used for templating from any configuration language--- which is translatable to Aeson's 'Value'.+-- Choice of the decoding function makes EDE available for templating from any+-- configuration language that maps to the Aeson's 'Value'. renderEDETemplateWith     :: (L.ByteString -> Maybe Value)    -- ^ Decoding function+    -> HashMap Id Term                  -- ^ Collection of extra filters     -> L.ByteString                     -- ^ JSON object     -> ByteString                       -- ^ Key to find the EDE template     -> IO L.ByteString-renderEDETemplateWith fdec v k = do+renderEDETemplateWith fdec flt v k = do     tpls <- readIORef templates     case HM.lookup k tpls of         Nothing -> throwIO $ EDERenderError $@@ -272,7 +281,7 @@                 Nothing -> throwIO $ EDERenderError $                     "Failed to decode value '" ++ C8L.unpack v ++ "'"                 Just obj ->-                    case renderWith filters tpl obj of+                    case renderWith flt tpl obj of                         Failure msg -> throwIO $ EDERenderError $ showPlain msg                         Success r -> return $ LT.encodeUtf8 r     where showPlain = show .@@ -290,7 +299,7 @@ -- Accepts a JSON object attached after the search key and a vertical bar such -- as /key|$hs_json/. renderEDETemplateFromFreeValue-    :: ByteString           -- ^ Key to find the EDE template, and JSON object+    :: ByteString           -- ^ Key to find the EDE template | JSON object     -> IO L.ByteString renderEDETemplateFromFreeValue = uncurry (flip renderEDETemplate) .     second (L.fromStrict . C8.tail) . C8.break (== '|')
ngx-export-tools-extra.cabal view
@@ -1,5 +1,5 @@ name:                       ngx-export-tools-extra-version:                    1.2.2+version:                    1.2.3 synopsis:                   More extra tools for Nginx haskell module description:                More extra tools for         <https://github.com/lyokha/nginx-haskell-module Nginx haskell module>.