packages feed

servant-to-elm 0.3.1.0 → 0.4.0.0

raw patch · 3 files changed

+52/−40 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Servant.To.Elm: instance Language.Haskell.To.Elm.HasElmDecoder Data.Aeson.Types.Internal.Value Servant.API.ContentTypes.NoContent
- Servant.To.Elm: instance Language.Haskell.To.Elm.HasElmType Servant.API.ContentTypes.NoContent
- Servant.To.Elm: instance forall k1 (method :: k1) a (list :: [*]) (status :: GHC.Types.Nat). (Servant.API.Verbs.ReflectMethod method, Language.Haskell.To.Elm.HasElmDecoder Data.Aeson.Types.Internal.Value a, list Data.Type.Equality.~ '[Servant.API.ContentTypes.JSON]) => Servant.To.Elm.HasElmEndpoints (Servant.API.Verbs.Verb method status list a)
+ Servant.To.Elm: instance forall k1 (method :: k1) (list :: [*]) a. Servant.API.Verbs.ReflectMethod method => Servant.To.Elm.HasElmEndpoints (Servant.API.Verbs.Verb method 204 list a)
+ Servant.To.Elm: instance forall k1 (method :: k1) a (list :: [*]). (Servant.API.Verbs.ReflectMethod method, Language.Haskell.To.Elm.HasElmDecoder Data.Aeson.Types.Internal.Value a, list Data.Type.Equality.~ '[Servant.API.ContentTypes.JSON]) => Servant.To.Elm.HasElmEndpoints (Servant.API.Verbs.Verb method 200 list a)
- Servant.To.Elm: Endpoint :: URL -> Method -> [(Text, Encoder, Bool)] -> Maybe (Expression Void, Encoder) -> Maybe Decoder -> [Text] -> Endpoint
+ Servant.To.Elm: Endpoint :: URL -> Method -> [(Text, Encoder, Bool)] -> Maybe (Expression Void, Encoder) -> Maybe (Either NoContent Decoder) -> [Text] -> Endpoint
- Servant.To.Elm: [$sel:_returnType:Endpoint] :: Endpoint -> Maybe Decoder
+ Servant.To.Elm: [$sel:_returnType:Endpoint] :: Endpoint -> Maybe (Either NoContent Decoder)

Files

CHANGELOG.md view
@@ -2,6 +2,10 @@  ## Unreleased changes +## 0.4.0.0++- Make endpoints that return NoContent (HTTP status code 204) return `()` on the Elm side, and remove instances for the `NoContent` type+ ## 0.3.1.0  - Update to `elm-syntax-0.2.0.0`, adding simplification of the generated definitions.
servant-to-elm.cabal view
@@ -7,7 +7,7 @@ -- hash: 9bc8ea51733447a3197fbc2ff1b7df7f9e35bd30ad2a262087efea102701806b  name:           servant-to-elm-version:        0.3.1.0+version:        0.4.0.0 synopsis:       Automatically generate Elm clients for Servant APIs description:    Please see the README on GitHub at <https://github.com/folq/servant-to-elm#readme> category:       Servant, API, Elm, Compiler
src/Servant/To/Elm.hs view
@@ -100,7 +100,15 @@     elmReturnType =       let         type_ =-          maybe "Basics.()" _decodedType $ _returnType endpoint+          case _returnType endpoint of+            Nothing ->+              "Basics.()"++            Just (Left Servant.NoContent) ->+              "Basics.()"++            Just (Right decoder) ->+              _decodedType decoder       in       Type.App         "Cmd.Cmd"@@ -109,14 +117,6 @@           [Type.tuple "Http.Error" (Type.App "Maybe.Maybe" $ Type.Record [("metadata", "Http.Metadata"), ("body", "String.String")]), type_]         ) -    elmReturnDecoder =-      case _returnType endpoint of-        Nothing ->-          panic "elmRequest: No return type" -- TODO?--        Just ret ->-          vacuous $ _decoder ret-     numberedPathSegments =       go 0 $ _path $ _url endpoint       where@@ -322,26 +322,30 @@               )             , ( Pattern.Con "Http.GoodStatus_" [Pattern.Var 0, Pattern.Var 1]               , Bound.toScope $-                if fmap _decodedType (_returnType endpoint) == Just (elmType @Servant.NoContent) then-                  Expression.if_ (Expression.apps ("Basics.==") [pure $ Bound.B 1, Expression.String ""])-                    (Expression.App "Result.Ok" "NoContent.NoContent")-                    (Expression.App "Result.Err" $-                      Expression.tuple-                        (Expression.App "Http.BadBody" $ Expression.String "Expected the response body to be empty")-                        (Expression.App "Maybe.Just" $ Expression.Record [("metadata", pure $ Bound.B 0), ("body", pure $ Bound.B 1)])-                    )+                case _returnType endpoint of+                  Nothing ->+                    panic "elmRequest: No return type" -- TODO? -                else-                  Expression.apps "Result.mapError"-                    [ Expression.Lam $ Bound.toScope $-                      Expression.tuple-                        (Expression.App "Http.BadBody" $-                          Expression.App "Json.Decode.errorToString" $-                          pure $ Bound.B ()-                        )-                        (Expression.App "Maybe.Just" $ Expression.Record [("metadata", pure $ Bound.F $ Bound.B 0), ("body", pure $ Bound.F $ Bound.B 1)])-                    , Expression.apps "Json.Decode.decodeString" [elmReturnDecoder, pure $ Bound.B 1]-                    ]+                  Just (Left Servant.NoContent) ->+                    Expression.if_ (Expression.apps ("Basics.==") [pure $ Bound.B 1, Expression.String ""])+                      (Expression.App "Result.Ok" "Basics.()")+                      (Expression.App "Result.Err" $+                        Expression.tuple+                          (Expression.App "Http.BadBody" $ Expression.String "Expected the response body to be empty")+                          (Expression.App "Maybe.Just" $ Expression.Record [("metadata", pure $ Bound.B 0), ("body", pure $ Bound.B 1)])+                      )++                  Just (Right elmReturnDecoder) ->+                    Expression.apps "Result.mapError"+                      [ Expression.Lam $ Bound.toScope $+                        Expression.tuple+                          (Expression.App "Http.BadBody" $+                            Expression.App "Json.Decode.errorToString" $+                            pure $ Bound.B ()+                          )+                          (Expression.App "Maybe.Just" $ Expression.Record [("metadata", pure $ Bound.F $ Bound.B 0), ("body", pure $ Bound.F $ Bound.B 1)])+                      , Expression.apps "Json.Decode.decodeString" [vacuous $ _decoder elmReturnDecoder, pure $ Bound.B 1]+                      ]               )             ]         ]@@ -404,7 +408,7 @@   , _method :: HTTP.Method   , _headers :: [(Text, Encoder, Bool)]   , _body :: Maybe (Expression Void, Encoder)-  , _returnType :: Maybe Decoder+  , _returnType :: Maybe (Either Servant.NoContent Decoder)   , _functionName :: [Text]   } @@ -471,11 +475,11 @@           toS $ symbolVal $ Proxy @symbol  instance (Servant.ReflectMethod method, HasElmDecoder Aeson.Value a, list ~ '[Servant.JSON])-  => HasElmEndpoints (Servant.Verb method status list a) where+  => HasElmEndpoints (Servant.Verb method 200 list a) where     elmEndpoints' prefix =       [ prefix         { _method = method-        , _returnType = Just $ makeDecoder @Aeson.Value @a+        , _returnType = Just $ Right $ makeDecoder @Aeson.Value @a         , _functionName = Text.toLower (toS method) : _functionName prefix         }       ]@@ -483,6 +487,18 @@         method =           Servant.reflectMethod $ Proxy @method +instance Servant.ReflectMethod method => HasElmEndpoints (Servant.Verb method 204 list a) where+    elmEndpoints' prefix =+      [ prefix+        { _method = method+        , _returnType = Just $ Left Servant.NoContent+        , _functionName = Text.toLower (toS method) : _functionName prefix+        }+      ]+      where+        method =+          Servant.reflectMethod $ Proxy @method+ instance   ( Servant.SBoolI (Servant.FoldRequired mods)   , KnownSymbol symbol@@ -607,14 +623,6 @@  ------------------------------------------------------------------------------- -- Orphans--instance HasElmType Servant.NoContent where-  elmDefinition =-    Just $ Definition.Type "NoContent.NoContent" [("NoContent", [])]--instance HasElmDecoder Aeson.Value Servant.NoContent where-  elmDecoder =-    Expression.App "Json.Decode.succeed" "NoContent.NoContent"  instance HasElmType (Servant.MultipartData tag) where   elmType =