git.iko.soy/haskell-servant/servant-elm
on c26b074 help sign in
17 files changed+31−55
since splitsnapshots
unifiedsplit
.github/workflows/build.yaml−5 servant-elm.cabal+1−1 src/Servant/Elm/Internal/Generate.hs+11−25 stack.yaml−4 test/Common.hs+1−1 test/elm-sources/getBooksByIdSource.elm+2−3 test/elm-sources/getBooksByTitleSource.elm+3−3 test/elm-sources/getBooksSource.elm+1−1 test/elm-sources/getNothingSource.elm+2−2 test/elm-sources/getOneSource.elm+1−1 test/elm-sources/getOneWithDynamicUrlSource.elm+1−1 test/elm-sources/getPolymorphicData.elm+1−1 test/elm-sources/getWithaheaderSource.elm+1−1 test/elm-sources/getWitharesponseheaderSource.elm+1−1 test/elm-sources/postBooksSource.elm+2−2 test/elm-sources/postTwoSource.elm+1−1 test/elm-sources/putNothingSource.elm+2−2
.github/workflows/build.yaml−5
@@ -17,11 +17,6 @@ jobs:
1717 steps:
1818 - uses: actions/checkout@v3
1919
20− - name: Install Nix
21− uses: cachix/install-nix-action@v20
22− with:
23− nix_path: nixpkgs=channel:nixos-unstable
24−
2520 - name: Cache
2621 uses: actions/cache@v3
2722 env:
servant-elm.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-elm
2−version: 0.7.3
2+version: 0.7.2
33synopsis: Automatically derive Elm functions to query servant webservices.
44description: Please see README.md
55homepage: http://github.com/mattjbray/servant-elm#readme
src/Servant/Elm/Internal/Generate.hs+11−25
@@ -53,22 +53,16 @@ data ElmOptions = ElmOptions
5353 argument.
5454 -}
5555 urlPrefix :: UrlPrefix
56− , elmTypeAlterations :: (EType -> EType)
56+ , elmTypeAlterations :: (EType -> EType)
5757 -- ^ Alterations to perform on ETypes before code generation.
5858 , elmAlterations :: (ETypeDef -> ETypeDef)
5959 -- ^ Alterations to perform on ETypeDefs before code generation.
60− , elmToString :: (EType -> Text)
60+ , elmToString :: (EType -> Text)
6161 -- ^ Elm functions creating a string from a given type.
6262 , emptyResponseElmTypes :: [EType]
6363 -- ^ Types that represent an empty Http response.
6464 , stringElmTypes :: [EType]
6565 -- ^ Types that represent a String.
66− , expectJsonMethod :: Text
67− -- ^ The function to use for JSON responses.
68− , expectStringMethod :: Text
69− -- ^ The function to use for string responses.
70− , httpErrorType :: Text
71− -- ^ The type to use for Http errors.
7266 }
7367
7468
@@ -92,9 +86,6 @@ The default options are:
9286> , stringElmTypes =
9387> [ getType (Proxy :: Proxy String)
9488> , getType (Proxy :: Proxy T.Text) ]
95−> , expectJsonMethod = "Http.expectJson"
96−> , expectStringMethod = "Http.expectString"
97−> , httpErrorType = "Http.Error"
9889> }
9990-}
10091defElmOptions :: ElmOptions
@@ -110,9 +101,6 @@ defElmOptions = ElmOptions
110101 [ toElmType (Proxy :: Proxy String)
111102 , toElmType (Proxy :: Proxy T.Text)
112103 ]
113− , expectJsonMethod = "Http.expectJson"
114− , expectStringMethod = "Http.expectString"
115− , httpErrorType = "Http.Error"
116104 }
117105
118106
@@ -131,7 +119,6 @@ The default required imports are:
131119> import Set
132120> import Http
133121> import String
134−> import Url
135122> import Url.Builder
136123-}
137124defElmImports :: Text
@@ -145,7 +132,6 @@ defElmImports =
145132 , "import Set"
146133 , "import Http"
147134 , "import String"
148− , "import Url"
149135 , "import Url.Builder"
150136 ]
151137
@@ -259,7 +245,7 @@ generateElmForRequest opts request =
259245 fnName =
260246 request ^. F.reqFuncName . to (replace . F.camelCase) . to stext
261247
262− replace = T.replace "-" "" . T.replace "." "" . T.replace " " ""
248+ replace = T.replace "-" "" . T.replace "." ""
263249
264250 typeSignature =
265251 mkTypeSignature opts request
@@ -321,7 +307,7 @@ mkTypeSignature opts request =
321307 toMsgType :: Maybe Doc
322308 toMsgType = do
323309 result <- fmap elmTypeRef $ request ^. F.reqReturnType
324− Just ("(Result" <+> stext (httpErrorType opts) <+> parens result <+> "-> msg)")
310+ Just ("(Result Http.Error " <+> parens result <+> " -> msg)")
325311
326312 returnType :: Maybe Doc
327313 returnType = do
@@ -339,7 +325,7 @@ elmCaptureArg segment =
339325 "capture_" <>
340326 F.captureArg segment ^. F.argName . to (stext . replace . F.unPathSegment)
341327 where
342− replace = T.replace "-" "_" . T.replace " " "_"
328+ replace = T.replace "-" "_"
343329
344330
345331elmQueryArg :: F.QueryArg EType -> Doc
@@ -513,11 +499,11 @@ mkRequest opts request =
513499 | isEmptyType opts $ (elmTypeAlterations opts) elmTypeExpr
514500 -- let elmConstructor = T.pack (renderElm elmTypeExpr)
515501 ->
516− stext (expectStringMethod opts) <> line <+> indent i "(\\x -> case x of" <> line <+>
502+ "Http.expectString " <> line <+> indent i "(\\x -> case x of" <> line <+>
517503 indent i "Err e -> toMsg (Err e)" <> line <+>
518504 indent i "Ok _ -> toMsg (Ok ()))"
519505 Just elmTypeExpr ->
520− stext (expectJsonMethod opts) <+> "toMsg" <+> renderDecoderName ((elmTypeAlterations opts) elmTypeExpr)
506+ "Http.expectJson toMsg" <+> renderDecoderName ((elmTypeAlterations opts) elmTypeExpr)
521507 Nothing -> error "mkHttpRequest: no reqReturnType?"
522508 -- case request ^. F.reqReturnType of
523509 -- Just elmTypeExpr | isEmptyType opts elmTypeExpr ->
@@ -575,9 +561,9 @@ mkUrl opts segments =
575561 F.Cap arg ->
576562 let
577563 toStringSrc =
578− toString opts (elmTypeAlterations opts (maybeOf (arg ^. F.argType)))
564+ toString opts (maybeOf (arg ^. F.argType))
579565 in
580− "Url.percentEncode " <> pipeRight [elmCaptureArg s, toStringSrc]
566+ pipeRight [elmCaptureArg s, toStringSrc]
581567
582568
583569mkQueryParams
@@ -595,7 +581,7 @@ response body.
595581-}
596582isEmptyType :: ElmOptions -> EType -> Bool
597583isEmptyType opts elmTypeExpr =
598− (elmTypeAlterations opts elmTypeExpr) `elem` emptyResponseElmTypes opts
584+ elmTypeExpr `elem` emptyResponseElmTypes opts
599585
600586
601587{- | Determines whether we call `toString` on URL captures and query params of
@@ -603,7 +589,7 @@ this type in Elm.
603589-}
604590isElmStringType :: ElmOptions -> EType -> Bool
605591isElmStringType opts elmTypeExpr =
606− (elmTypeAlterations opts elmTypeExpr) `elem` stringElmTypes opts
592+ elmTypeExpr `elem` stringElmTypes opts
607593
608594{- | Determines whether a type is 'Maybe a' where 'a' is something akin to a 'String'.
609595-}
stack.yaml−4
@@ -3,7 +3,3 @@ packages:
33- '.'
44flags: {}
55extra-package-dbs: []
6−nix:
7− enable: true
8− packages:
9− - zlib
test/Common.hs+1−1
@@ -27,7 +27,7 @@ type TestApi =
2727 :> Capture "id" Int
2828 :> Get '[JSON] Book
2929 :<|> "books"
30− :> Capture "title space" Text
30+ :> Capture "title" Text
3131 :> Get '[JSON] Book
3232 :<|> "books"
3333 :> QueryFlag "published"
test/elm-sources/getBooksByIdSource.elm+2−3
@@ -8,7 +8,7 @@ type Book = Book
88jsonDecBook : Json.Decode.Decoder Book
99jsonDecBook = Debug.todo ""
1010
11−getBooksById : Int -> (Result Http.Error (Book) -> msg) -> Cmd msg
11+getBooksById : Int -> (Result Http.Error (Book) -> msg) -> Cmd msg
1212getBooksById capture_id toMsg =
1313 let
1414 params =
@@ -24,8 +24,7 @@ getBooksById capture_id toMsg =
2424 , url =
2525 Url.Builder.crossOrigin ""
2626 [ "books"
27− , Url.percentEncode (capture_id
28− |> String.fromInt)
27+ , (capture_id |> String.fromInt)
2928 ]
3029 params
3130 , body =
test/elm-sources/getBooksByTitleSource.elm+3−3
@@ -7,8 +7,8 @@ import Json.Decode as J
77type alias Book = {}
88jsonDecBook = J.succeed {}
99
10−getBooksByTitlespace : String -> (Result Http.Error (Book) -> msg) -> Cmd msg
11−getBooksByTitlespace capture_title_space toMsg =
10+getBooksByTitle : String -> (Result Http.Error (Book) -> msg) -> Cmd msg
11+getBooksByTitle capture_title toMsg =
1212 let
1313 params =
1414 List.filterMap identity
@@ -23,7 +23,7 @@ getBooksByTitlespace capture_title_space toMsg =
2323 , url =
2424 Url.Builder.crossOrigin ""
2525 [ "books"
26− , Url.percentEncode (capture_title_space)
26+ , (capture_title)
2727 ]
2828 params
2929 , body =
test/elm-sources/getBooksSource.elm+1−1
@@ -9,7 +9,7 @@ type alias Book = {}
99
1010jsonDecBook = J.succeed {}
1111
12−getBooks : Bool -> (Maybe String) -> (Maybe Int) -> String -> (List (Maybe Bool)) -> (Result Http.Error ((List Book)) -> msg) -> Cmd msg
12+getBooks : Bool -> (Maybe String) -> (Maybe Int) -> String -> (List (Maybe Bool)) -> (Result Http.Error ((List Book)) -> msg) -> Cmd msg
1313getBooks query_published query_sort query_year query_category query_filters toMsg =
1414 let
1515 params =
test/elm-sources/getNothingSource.elm+2−2
@@ -4,7 +4,7 @@ import Http
44import Url.Builder
55
66
7−getNothing : (Result Http.Error (()) -> msg) -> Cmd msg
7+getNothing : (Result Http.Error (()) -> msg) -> Cmd msg
88getNothing toMsg =
99 let
1010 params =
@@ -25,7 +25,7 @@ getNothing toMsg =
2525 , body =
2626 Http.emptyBody
2727 , expect =
28− Http.expectString
28+ Http.expectString
2929 (\x -> case x of
3030 Err e -> toMsg (Err e)
3131 Ok _ -> toMsg (Ok ()))
test/elm-sources/getOneSource.elm+1−1
@@ -5,7 +5,7 @@ import Json.Decode exposing (..)
55import Url.Builder
66
77
8−getOne : (Result Http.Error (Int) -> msg) -> Cmd msg
8+getOne : (Result Http.Error (Int) -> msg) -> Cmd msg
99getOne toMsg =
1010 let
1111 params =
test/elm-sources/getOneWithDynamicUrlSource.elm+1−1
@@ -5,7 +5,7 @@ import Url.Builder
55import Json.Decode exposing (..)
66
77
8−getOne : String -> (Result Http.Error (Int) -> msg) -> Cmd msg
8+getOne : String -> (Result Http.Error (Int) -> msg) -> Cmd msg
99getOne urlBase toMsg =
1010 let
1111 params =
test/elm-sources/getPolymorphicData.elm+1−1
@@ -14,7 +14,7 @@ jsonDecSomeRecord : Json.Decode.Decoder SomeRecord
1414jsonDecSomeRecord = Debug.todo "finish"
1515
1616
17−getPolymorphicData : (Result Http.Error ((PolymorphicData (List String) SomeRecord)) -> msg) -> Cmd msg
17+getPolymorphicData : (Result Http.Error ((PolymorphicData (List String) SomeRecord)) -> msg) -> Cmd msg
1818getPolymorphicData toMsg =
1919 let
2020 params =
test/elm-sources/getWithaheaderSource.elm+1−1
@@ -5,7 +5,7 @@ import Url.Builder
55import Json.Decode exposing (..)
66
77
8−getWithaheader : (Maybe String) -> (Maybe Int) -> String -> Int -> (Result Http.Error (String) -> msg) -> Cmd msg
8+getWithaheader : (Maybe String) -> (Maybe Int) -> String -> Int -> (Result Http.Error (String) -> msg) -> Cmd msg
99getWithaheader header_myStringHeader header_MyIntHeader header_MyRequiredStringHeader header_MyRequiredIntHeader toMsg =
1010 let
1111 params =
test/elm-sources/getWitharesponseheaderSource.elm+1−1
@@ -5,7 +5,7 @@ import Url.Builder
55import Json.Decode exposing (..)
66
77
8−getWitharesponseheader : (Result Http.Error (String) -> msg) -> Cmd msg
8+getWitharesponseheader : (Result Http.Error (String) -> msg) -> Cmd msg
99getWitharesponseheader toMsg =
1010 let
1111 params =
test/elm-sources/postBooksSource.elm+2−2
@@ -7,7 +7,7 @@ import Json.Encode as Enc
77type alias Book = {}
88jsonEncBook = \b -> Enc.object []
99
10−postBooks : Book -> (Result Http.Error (()) -> msg) -> Cmd msg
10+postBooks : Book -> (Result Http.Error (()) -> msg) -> Cmd msg
1111postBooks body toMsg =
1212 let
1313 params =
@@ -28,7 +28,7 @@ postBooks body toMsg =
2828 , body =
2929 Http.jsonBody (jsonEncBook body)
3030 , expect =
31− Http.expectString
31+ Http.expectString
3232 (\x -> case x of
3333 Err e -> toMsg (Err e)
3434 Ok _ -> toMsg (Ok ()))
test/elm-sources/postTwoSource.elm+1−1
@@ -6,7 +6,7 @@ import Json.Encode
66import Url.Builder
77
88
9−postTwo : String -> (Result Http.Error ((Maybe Int)) -> msg) -> Cmd msg
9+postTwo : String -> (Result Http.Error ((Maybe Int)) -> msg) -> Cmd msg
1010postTwo body toMsg =
1111 let
1212 params =
test/elm-sources/putNothingSource.elm+2−2
@@ -4,7 +4,7 @@ import Http
44import Url.Builder
55
66
7−putNothing : (Result Http.Error (()) -> msg) -> Cmd msg
7+putNothing : (Result Http.Error (()) -> msg) -> Cmd msg
88putNothing toMsg =
99 let
1010 params =
@@ -25,7 +25,7 @@ putNothing toMsg =
2525 , body =
2626 Http.emptyBody
2727 , expect =
28− Http.expectString
28+ Http.expectString
2929 (\x -> case x of
3030 Err e -> toMsg (Err e)
3131 Ok _ -> toMsg (Ok ()))