Skip to content

Commit

Permalink
fix/complex-type
Browse files Browse the repository at this point in the history
  • Loading branch information
vsaimanohar committed Feb 19, 2024
1 parent 03633b6 commit 2bdf2d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/namma-dsl/src/NammaDSL/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 10 additions & 2 deletions lib/namma-dsl/src/NammaDSL/DSL/Parser/Storage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ->
Expand All @@ -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
Expand Down

0 comments on commit 2bdf2d8

Please sign in to comment.