packages feed

json-spec-elm 0.4.0.7 → 0.5.0.1

raw patch · 3 files changed

+44/−56 lines, 3 filesdep ~basedep ~containersdep ~elm-syntaxPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, containers, elm-syntax, json-spec, mtl, process, text

API changes (from Hackage documentation)

- Data.JsonSpec.Elm: instance (Data.JsonSpec.Elm.SumDef left, Data.JsonSpec.Elm.SumDef right) => Data.JsonSpec.Elm.SumDef ('Data.JsonSpec.Spec.JsonEither left right)
- Data.JsonSpec.Elm: instance (GHC.Internal.TypeLits.KnownSymbol name, Data.JsonSpec.Elm.SumDef ('Data.JsonSpec.Spec.JsonEither left right)) => Data.JsonSpec.Elm.HasDef '(name, 'Data.JsonSpec.Spec.JsonEither left right)
- Data.JsonSpec.Elm: instance (TypeError ...) => Data.JsonSpec.Elm.HasType ('Data.JsonSpec.Spec.JsonEither left right)
+ Data.JsonSpec.Elm: instance (Data.JsonSpec.Elm.SumDef a, Data.JsonSpec.Elm.SumDef ('Data.JsonSpec.Spec.JsonEither as)) => Data.JsonSpec.Elm.SumDef ('Data.JsonSpec.Spec.JsonEither (a : as))
+ Data.JsonSpec.Elm: instance (GHC.Internal.TypeLits.KnownSymbol name, Data.JsonSpec.Elm.SumDef ('Data.JsonSpec.Spec.JsonEither branches)) => Data.JsonSpec.Elm.HasDef '(name, 'Data.JsonSpec.Spec.JsonEither branches)
+ Data.JsonSpec.Elm: instance (TypeError ...) => Data.JsonSpec.Elm.HasType ('Data.JsonSpec.Spec.JsonEither branches)
+ Data.JsonSpec.Elm: instance Data.JsonSpec.Elm.SumDef ('Data.JsonSpec.Spec.JsonEither '[])

Files

README.md view
@@ -35,21 +35,15 @@                  , '( "sumType1"                     , Named "SumTypeWithCustomConstructorNames"                         ( JsonEither-                            ( JsonEither-                                (Named "IntConstructor" JsonInt)-                                (Named "StringConstructor" JsonString)-                            )-                            (Named "FloatConstructor" JsonNum)+                           '[ Named "IntConstructor" JsonInt+                            , Named "StringConstructor" JsonString+                            , Named "FloatConstructor" JsonNum+                            ]                         )                     )                  , '( "sumType2"                     , Named "SumTypeWithAutomaticConstructorNames"-                        ( JsonEither-                            ( JsonEither-                                JsonInt-                                JsonString-                            )-                            JsonNum+                        ( JsonEither '[JsonInt, JsonString, JsonNum]                         )                     )                  ]
json-spec-elm.cabal view
@@ -1,6 +1,6 @@ cabal-version:       3.0 name:                json-spec-elm-version:             0.4.0.7+version:             0.5.0.1 synopsis:            Elm code generate for `json-spec`. description:                               Produce elm types, encoders, and decoders from a@@ -21,11 +21,11 @@  common dependencies   build-depends:-    , base                 >= 4.17.2.1 && < 4.22-    , containers           >= 0.6.7    && < 0.8-    , elm-syntax           >= 0.3.2.0  && < 0.4-    , json-spec            >= 0.3.0.0  && < 1.3-    , text                 >= 2.0.2    && < 2.2+    , base                 >= 4.19.2.0 && < 4.22+    , containers           >= 0.6.8    && < 0.8+    , elm-syntax           >= 0.3.3.0  && < 0.4+    , json-spec            >= 1.3.0.0  && < 1.4+    , text                 >= 2.1.1    && < 2.2  common warnings   ghc-options:@@ -47,7 +47,7 @@     -Wunused-packages   build-depends:     , bound                >= 2.0.7 && < 2.1-    , mtl                  >= 2.2.2 && < 2.4+    , mtl                  >= 2.3.1 && < 2.4  flag compile-elm   description:@@ -67,7 +67,7 @@       , directory            >= 1.3.7.1  && < 1.4       , hspec                >= 2.11.1   && < 2.12       , prettyprinter        >= 1.7.1    && < 1.8-      , process              >= 1.6.16.0 && < 1.7+      , process              >= 1.6.25.0 && < 1.7       , unordered-containers >= 0.2.19.1 && < 0.3   else     type: exitcode-stdio-1.0
src/Data/JsonSpec/Elm.hs view
@@ -72,13 +72,11 @@     The specification      > Named "MySumType"-    >   ( JsonEither-    >       (Named "AnInt" JsonInt)-    >       ( JsonEither-    >           JsonFloat -- note the omitted name-    >           ( Named "AString" JsonString)-    >       )-    >   )+    >   ( JsonEither '[+    >       Named "AnInt" JsonInt,+    >       JsonFloat,  -- note the omitted name+    >       Named "AString" JsonString+    >   ])      will produce the Elm type @@ -439,10 +437,10 @@     encoderOf = do       defs @def       encoderOf @(JsonLet more spec)-instance {- HasType (JsonEither left right) -}+instance {- HasType (JsonEither branches) -}     (TypeError AnonSumTypeError)   =>-    HasType (JsonEither left right)+    HasType (JsonEither branches)   where     typeOf = error "undefinable"     decoderOf = error "undefinable"@@ -468,25 +466,25 @@  class HasDef (def :: (Symbol, Specification)) where   defs :: Definitions ()-instance {- HasDef '(name, JsonEither left right) -}+instance {- HasDef '(name, JsonEither branches) -}     ( KnownSymbol name-    , SumDef (JsonEither left right)+    , SumDef (JsonEither branches)     )   =>-    HasDef '(name, JsonEither left right)+    HasDef '(name, JsonEither branches)   where     defs = do-        branches <- sumDef @(JsonEither left right)+        branches_ <- sumDef @(JsonEither branches)         let           constructors :: [(Constructor, [Scope Int Type Void])]           constructors =             [ ( Name.Constructor (constructorName conName n)               , [Scope type_]               )-            | (n, (conName, type_)) <- zip [1..] branches+            | (n, (conName, type_)) <- zip [1..] branches_             ]-        decoders <- sumDecoders @(JsonEither left right)-        encoders <- sumEncoders @(JsonEither left right)+        decoders <- sumDecoders @(JsonEither branches)+        encoders <- sumEncoders @(JsonEither branches)         tell . Set.fromList $           [ Def.Type (localName name) 0 constructors           , Def.Constant@@ -628,23 +626,27 @@   sumDef :: forall v. Definitions [(Maybe Text, Type v)]   sumDecoders :: Definitions [(Maybe Text, Expression Void)]   sumEncoders :: Definitions [(Maybe Text, Expression Void)]-instance {- SumDef (JsonEither left right) -}-    (SumDef left, SumDef right)+instance SumDef (JsonEither '[]) where+  sumDef = pure []+  sumDecoders = pure []+  sumEncoders = pure []+instance {- SumDef (JsonEither (a ': as)) -}+    (SumDef a, SumDef (JsonEither as))   =>-    SumDef (JsonEither left right)+    SumDef (JsonEither (a ': as))   where     sumDef = do-      left <- sumDef @left-      right <- sumDef @right-      pure $ left ++ right+      aDef <- sumDef @a+      asDef <- sumDef @(JsonEither as)+      pure $ aDef ++ asDef     sumDecoders = do-      left <- sumDecoders @left-      right <- sumDecoders @right-      pure (left ++ right)+      aDec <- sumDecoders @a+      asDec <- sumDecoders @(JsonEither as)+      pure (aDec ++ asDec)     sumEncoders = do-      left <- sumEncoders @left-      right <- sumEncoders @right-      pure (left ++ right)+      aEnc <- sumEncoders @a+      asEnc <- sumEncoders @(JsonEither as)+      pure (aEnc ++ asEnc) instance {- SumDef (JsonLet '[ '(name, def) ] (JsonRef name)) -}     ( HasType def     , KnownSymbol name@@ -774,15 +776,7 @@     :$$: Lits.Text ""     :$$: Lits.Text "> JsonLet"     :$$: Lits.Text ">   '[ '( \"MySum\""-    :$$: Lits.Text ">       , JsonEither"-    :$$: Lits.Text ">           ( JsonEither"-    :$$: Lits.Text ">               JsonInt"-    :$$: Lits.Text ">               JsonString"-    :$$: Lits.Text ">           )"-    :$$: Lits.Text ">           ( JsonEither"-    :$$: Lits.Text ">               JsonFloat"-    :$$: Lits.Text ">               JsonBool"-    :$$: Lits.Text ">           )"+    :$$: Lits.Text ">       , JsonEither '[JsonInt, JsonString, JsonFloat, JsonBool]"     :$$: Lits.Text ">       )"     :$$: Lits.Text ">    ]"     :$$: Lits.Text ">    (JsonRef \"MySum\")"