From 2bdf2d8d36b52c82c3156f05aaef7d28cacbfb43 Mon Sep 17 00:00:00 2001 From: "saimanohar.veeravajhula" Date: Mon, 19 Feb 2024 15:07:00 +0530 Subject: [PATCH] fix/complex-type --- lib/namma-dsl/src/NammaDSL/App.hs | 2 +- lib/namma-dsl/src/NammaDSL/DSL/Parser/Storage.hs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/namma-dsl/src/NammaDSL/App.hs b/lib/namma-dsl/src/NammaDSL/App.hs index ab269476..acc78cf1 100644 --- a/lib/namma-dsl/src/NammaDSL/App.hs +++ b/lib/namma-dsl/src/NammaDSL/App.hs @@ -18,7 +18,7 @@ import System.FilePath import System.Process (readProcess) version :: String -version = "1.0.9" +version = "1.1.0" data FileState = NEW | CHANGED | UNCHANGED | NOT_EXIST deriving (Eq, Show) diff --git a/lib/namma-dsl/src/NammaDSL/DSL/Parser/Storage.hs b/lib/namma-dsl/src/NammaDSL/DSL/Parser/Storage.hs index dcf18294..f63720cc 100644 --- a/lib/namma-dsl/src/NammaDSL/DSL/Parser/Storage.hs +++ b/lib/namma-dsl/src/NammaDSL/DSL/Parser/Storage.hs @@ -14,6 +14,7 @@ import Data.Aeson.Lens (key, _Array, _Object, _Value) import qualified Data.ByteString as BS import qualified Data.ByteString.UTF8 as BSU import Data.Char (toUpper) +import Data.List (isPrefixOf) import qualified Data.List as L import qualified Data.List.Extra as L import Data.List.Split (split, splitOn, splitWhen, whenElt) @@ -664,8 +665,9 @@ parseFields moduleName excludedList dataList enumList definedTypes impObj obj = Nothing -> error "Error Parsing Fields" beamFieldsWithExtractors :: String -> Maybe Object -> String -> String -> [TypeObject] -> [String] -> [(String, String, [String])] -beamFieldsWithExtractors moduleName beamFieldObj fieldName haskellType definedTypes extractorFuncs = - case findIfComplexType haskellType of +beamFieldsWithExtractors moduleName beamFieldObj fieldName haskellType definedTypes extractorFuncs = do + let haskellType' = extractType haskellType + case findIfComplexType haskellType' of Just (TypeObject _ (_nm, (arrOfFields, _))) -> foldl (\acc (nm, tpp) -> acc ++ beamFieldsWithExtractors moduleName beamFieldObj (fieldName ++ capitalise nm) tpp definedTypes (qualified nm : extractorFuncs)) [] arrOfFields Nothing -> @@ -679,6 +681,12 @@ beamFieldsWithExtractors moduleName beamFieldObj fieldName haskellType definedTy findIfComplexType :: String -> Maybe TypeObject findIfComplexType tpp = find (\(TypeObject _ (nm, (arrOfFields, _))) -> (nm == tpp || tpp == "Domain.Types." ++ moduleName ++ "." ++ nm) && all (\(k, _) -> k /= "enum") arrOfFields) definedTypes + extractType :: String -> String + extractType str = + if "Maybe" `isPrefixOf` str + then drop 6 str + else str + makeTF :: Object -> String -> TransformerFunction makeTF impObj func = TransformerFunction