From 8c49a30faa431b8b56a4b4926e7dae56b1311fea Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 28 May 2023 08:13:08 +0200 Subject: Completed untested Flattening implementation --- src/Data/JLD/Flattening/Global.hs | 7 +++++++ src/Data/JLD/Flattening/NodeMap.hs | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 src/Data/JLD/Flattening/Global.hs (limited to 'src/Data/JLD/Flattening') diff --git a/src/Data/JLD/Flattening/Global.hs b/src/Data/JLD/Flattening/Global.hs new file mode 100644 index 0000000..591d3ad --- /dev/null +++ b/src/Data/JLD/Flattening/Global.hs @@ -0,0 +1,7 @@ +module Data.JLD.Flattening.Global (JLDFlatteningT) where + +import Data.JLD.Prelude + +import Data.JLD.Error (JLDError) + +type JLDFlatteningT e m = ExceptT (JLDError e) m diff --git a/src/Data/JLD/Flattening/NodeMap.hs b/src/Data/JLD/Flattening/NodeMap.hs index 919aec7..65db9ab 100644 --- a/src/Data/JLD/Flattening/NodeMap.hs +++ b/src/Data/JLD/Flattening/NodeMap.hs @@ -2,8 +2,9 @@ module Data.JLD.Flattening.NodeMap (NodeMap, BNMParams (..), buildNodeMap, merge import Data.JLD.Prelude -import Data.JLD.Control.Monad.RES (REST, execREST, withErrorRES') +import Data.JLD.Control.Monad.RES (REST, runREST, withErrorRES') import Data.JLD.Error (JLDError (..)) +import Data.JLD.Flattening.Global (JLDFlatteningT) import Data.JLD.Model.IRI (isBlankIri) import Data.JLD.Model.Keyword (Keyword (..), isKeywordLike, isNotKeyword) import Data.JLD.Model.NodeMap (NodeMap, PropertyMap) @@ -12,7 +13,7 @@ import Data.JLD.Model.NodeObject (isNodeObject) import Data.JLD.Util (valueIsScalar, valueToArray, valueToNonNullArray) import Control.Monad.Except (MonadError (..)) -import Data.Aeson (Array, Key, Object, Value (..)) +import Data.Aeson (Array, Object, Value (..)) import Data.Aeson.Key qualified as K (toText) import Data.Aeson.KeyMap qualified as KM (filterWithKey, insert, lookup, member, singleton) import Data.Foldable.WithIndex (FoldableWithIndex (..), iforM_) @@ -85,7 +86,10 @@ bnmBuildNodeMap value paramsFn = do , bnmParamsActiveSubject = bnmEnvActiveSubject , bnmParamsActiveProperty = bnmEnvActiveProperty } - (nodeMap', list) <- buildNodeMap value params + (nodeMap', list) <- + buildNodeMap value params |> runExceptT >=> \case + Left err -> throwError <| Left err + Right a -> pure a bnmModifyNodeMap <| const nodeMap' pure list @@ -269,10 +273,12 @@ buildNodeMap' element = case element of -- _ -> pure () -buildNodeMap :: Monad m => Value -> (BNMParams -> BNMParams) -> m (NodeMap, Maybe Array) +buildNodeMap :: Monad m => Value -> (BNMParams -> BNMParams) -> JLDFlatteningT e m (NodeMap, Maybe Array) buildNodeMap document paramsFn = do - BNMState{..} <- buildNodeMap' document |> execREST env st - pure (bnmStateNodeMap, bnmStateList) + (result, BNMState{..}) <- buildNodeMap' document |> runREST env st + case result of + Left (Left err) -> throwError err + _ -> pure (bnmStateNodeMap, bnmStateList) where BNMParams{..} = paramsFn -- cgit v1.2.3-70-g09d2