Skip to content

Commit

Permalink
Partial value mapping with changes around extra type argument (#48)
Browse files Browse the repository at this point in the history
* Added missing module declarations. #37

* Process only those modules that are reachable from exposed ones. Remove package path from module names. #21

* Renaming concepts based on review feedback. #41

* Moved Advanced module up a level. #43

* Removed unused unindent function.

* Moved name to SDK.

* Added missing module to SDK.

* Partial implementation of value mapping.

* Ignore all generated JS.

* Change extra arg position and naming. #46, #25

* Change extra arg position and naming. #46, #25

* Removed remaining references to extra. #5

* Change extra arg position. #46, #25, #5

* Added more coverage. #46, #25, #5

* Changes suggested in the PR. #46, #25, #5
  • Loading branch information
AttilaMihaly authored Apr 2, 2020
1 parent 7504e78 commit 3cb978a
Show file tree
Hide file tree
Showing 23 changed files with 1,272 additions and 1,138 deletions.
2 changes: 1 addition & 1 deletion cli/src/Morphir/Elm/CLI.elm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ update msg model =
let
result =
Frontend.packageDefinitionFromSource packageInfo sourceFiles
|> Result.map Package.eraseDefinitionExtra
|> Result.map Package.eraseDefinitionAttributes
in
( model, result |> encodeResult (Encode.list encodeError) (Package.encodeDefinition (\_ -> Encode.null)) |> packageDefinitionFromSourceResult )

Expand Down
4 changes: 2 additions & 2 deletions cli/src/Morphir/Elm/DaprCLI.elm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ update msg model =
packageDefResult : Result Frontend.Errors (Package.Definition ())
packageDefResult =
Frontend.packageDefinitionFromSource pkgInfo sourceFiles
|> Result.map Package.eraseDefinitionExtra
|> Result.map Package.eraseDefinitionAttributes

result =
packageDefResult
Expand Down Expand Up @@ -138,7 +138,7 @@ daprSource pkgPath pkgDef =
case acsCtrlModDef.value of
{ types, values } ->
Dict.remove (Name.fromString "app") types
|> Dict.map (\_ acsCtrlTypeDef -> AccessControlled.map Type.eraseExtra acsCtrlTypeDef)
|> Dict.map (\_ acsCtrlTypeDef -> AccessControlled.map Type.eraseAttributes acsCtrlTypeDef)
|> Dict.toList

Private ->
Expand Down
6 changes: 3 additions & 3 deletions src/Morphir/Elm/Backend/Codec/DecoderGen.elm
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ constructorDecoder isSingle ( ctorName, fields ) =
else
[ "$type" ]
in
Record (fields |> List.map ctorFieldToRecField) ()
Record () (fields |> List.map ctorFieldToRecField)
|> typeToDecoder ctorName topLevelFieldNames


typeToDecoder : Name -> List String -> Type () -> Expression
typeToDecoder typeName topLevelFieldNames tpe =
case tpe of
Reference fqName typeParams _ ->
Reference _ fqName typeParams ->
case fqName of
FQName _ _ [ "string" ] ->
FunctionOrValue decoderModuleName "string"
Expand Down Expand Up @@ -149,7 +149,7 @@ typeToDecoder typeName topLevelFieldNames tpe =
[]
("decoder" ++ (name |> Name.toTitleCase))

Record fields _ ->
Record _ fields ->
let
mapFunc : Expression
mapFunc =
Expand Down
6 changes: 3 additions & 3 deletions src/Morphir/Elm/Backend/Codec/EncoderGen.elm
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ typeDefToEncoder typeName typeDef =
typeToEncoder : Bool -> List Name -> Type () -> Expression
typeToEncoder fwdNames varName tpe =
case tpe of
Reference fqName typeArgs _ ->
Reference _ fqName typeArgs ->
case fqName of
FQName _ _ [ "int" ] ->
elmJsonEncoderApplication
Expand Down Expand Up @@ -202,7 +202,7 @@ typeToEncoder fwdNames varName tpe =
([ "encode" ] ++ names |> Name.toCamelCase |> FunctionOrValue [])
(varPathToExpr varName)

Record fields _ ->
Record _ fields ->
let
namesToFwd name =
if fwdNames then
Expand Down Expand Up @@ -284,7 +284,7 @@ constructorToRecord ( _, types ) =
types
|> List.map (\t -> Field (Tuple.first t) (Tuple.second t))
in
record fields ()
record () fields


customTypeTopExpr : Expression -> Expression
Expand Down
37 changes: 16 additions & 21 deletions src/Morphir/Elm/Backend/Dapr/StatefulApp.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import Morphir.IR.AccessControlled as AccessControlled exposing (AccessControlle
import Morphir.IR.FQName exposing (FQName(..))
import Morphir.IR.Name as Name exposing (Name, toCamelCase)
import Morphir.IR.Path exposing (Path)
import Morphir.IR.Type as Type exposing (Definition(..), Field, Type(..), eraseExtra)
import Morphir.IR.Type as Type exposing (Definition(..), Field, Type(..), eraseAttributes)


gen : Path -> Name -> Type () -> List ( Name, AccessControlled (Type.Definition ()) ) -> Maybe File
gen fullAppPath appName appType otherTypeDefs =
case appType of
Reference (FQName [ [ "morphir" ], [ "s", "d", "k" ] ] [ [ "stateful", "app" ] ] [ "stateful", "app" ]) (keyType :: cmdType :: stateType :: eventType :: []) _ ->
Reference _ (FQName [ [ "morphir" ], [ "s", "d", "k" ] ] [ [ "stateful", "app" ] ] [ "stateful", "app" ]) (keyType :: cmdType :: stateType :: eventType :: []) ->
let
moduleDef : Module
moduleDef =
Expand Down Expand Up @@ -237,7 +237,7 @@ msgDecoderDecl keyType stateType cmdType =
Ok (( typeName, typeDef ) :: []) ->
DecoderGen.typeDefToDecoder
typeName
(typeDef |> AccessControlled.map eraseExtra)
(typeDef |> AccessControlled.map eraseAttributes)

_ ->
emptyDecl
Expand Down Expand Up @@ -329,7 +329,7 @@ encodeStateEventDecl keyType stateType eventType =
in
case morphirTypeDef of
Ok (( typeName, typeDef ) :: []) ->
EncoderGen.typeDefToEncoder typeName (typeDef |> AccessControlled.map eraseExtra)
EncoderGen.typeDefToEncoder typeName (typeDef |> AccessControlled.map eraseAttributes)

_ ->
emptyDecl
Expand Down Expand Up @@ -553,22 +553,22 @@ subscriptions =
morphirToElmTypeDef : Type () -> TypeAnnotation
morphirToElmTypeDef tpe =
case tpe of
Variable name _ ->
Variable _ name ->
name |> Name.toCamelCase |> GenericType

Reference (FQName _ _ [ "bool" ]) [] _ ->
Reference _ (FQName _ _ [ "bool" ]) [] ->
Typed (( [], "Bool" ) |> Utils.emptyRangeNode) []

Reference (FQName _ _ [ "int" ]) [] _ ->
Reference _ (FQName _ _ [ "int" ]) [] ->
Typed (( [], "Int" ) |> Utils.emptyRangeNode) []

Reference (FQName _ _ [ "float" ]) [] _ ->
Reference _ (FQName _ _ [ "float" ]) [] ->
Typed (( [], "Float" ) |> Utils.emptyRangeNode) []

Reference (FQName _ _ [ "string" ]) [] _ ->
Reference _ (FQName _ _ [ "string" ]) [] ->
Typed (( [], "String" ) |> Utils.emptyRangeNode) []

Reference (FQName pkgPath modPath tpeName) types _ ->
Reference _ (FQName pkgPath modPath tpeName) types ->
let
moduleName : ModuleName
moduleName =
Expand All @@ -588,7 +588,7 @@ morphirToElmTypeDef tpe =
(( moduleName, typeName ) |> Utils.emptyRangeNode)
innerTypes

Type.Record fields _ ->
Type.Record _ fields ->
let
morphirToElmField : Field () -> ( Node String, Node TypeAnnotation )
morphirToElmField field =
Expand Down Expand Up @@ -664,26 +664,21 @@ emptyFuncImpl =

test : Type ()
test =
Reference
Reference ()
(FQName [ [ "morphir" ] ] [ [ "s", "d", "k" ], [ "stateful", "app" ] ] [ "stateful", "app" ])
[ Reference
[ Reference ()
(FQName [] [ [ "morphir" ], [ "sdk" ] ] [ "Int" ])
[]
()
, Reference
, Reference ()
(FQName [] [ [ "morphir" ], [ "sdk" ] ] [ "Int" ])
[]
()
, Reference
, Reference ()
(FQName [] [ [ "morphir" ], [ "sdk" ] ] [ "Int" ])
[]
()
, Reference
, Reference ()
(FQName [] [ [ "morphir" ], [ "sdk" ] ] [ "Int" ])
[]
()
]
()


testRun : Maybe String
Expand Down
Loading

0 comments on commit 3cb978a

Please sign in to comment.