1- {-# LANGUAGE AllowAmbiguousTypes #-}
2- {-# LANGUAGE BangPatterns #-}
3- {-# LANGUAGE DataKinds #-}
4- {-# LANGUAGE DuplicateRecordFields #-}
5- {-# LANGUAGE FlexibleContexts #-}
6- {-# LANGUAGE FlexibleInstances #-}
7- {-# LANGUAGE GADTs #-}
8- {-# LANGUAGE MultiParamTypeClasses #-}
9- {-# LANGUAGE NoImplicitPrelude #-}
10- {-# LANGUAGE OverloadedStrings #-}
11- {-# LANGUAGE PolyKinds #-}
12- {-# LANGUAGE ScopedTypeVariables #-}
13- {-# LANGUAGE TypeApplications #-}
14- {-# LANGUAGE TypeOperators #-}
15- {-# LANGUAGE UndecidableInstances #-}
16- {-# OPTIONS_GHC -fno-warn-orphans #-}
1+ {-# language AllowAmbiguousTypes #-}
2+ {-# language BangPatterns #-}
3+ {-# language DataKinds #-}
4+ {-# language DuplicateRecordFields #-}
5+ {-# language FlexibleContexts #-}
6+ {-# language FlexibleInstances #-}
7+ {-# language GADTs #-}
8+ {-# language MultiParamTypeClasses #-}
9+ {-# language OverloadedStrings #-}
10+ {-# language PolyKinds #-}
11+ {-# language ScopedTypeVariables #-}
12+ {-# language TypeApplications #-}
13+ {-# language TypeOperators #-}
14+ {-# language UndecidableInstances #-}
15+ {-# options_ghc -fno-warn-orphans #-}
1716module Servant.To.Elm where
1817
19- import Protolude hiding (Type , functionName , moduleName )
20-
2118import qualified Bound
2219import qualified Data.Aeson as Aeson
2320import qualified Data.Char as Char
21+ import Data.Proxy
22+ import Data.String
23+ import Data.Text (Text )
2424import qualified Data.Text as Text
25+ import qualified Data.Text.Encoding as Text
26+ import Data.Void
27+ import GHC.TypeLits
2528import qualified Network.HTTP.Types as HTTP
2629import Servant.API ((:<|>) , (:>) )
2730import qualified Servant.API as Servant
28- import qualified Servant.Multipart as Servant
2931import qualified Servant.API.Modifiers as Servant
32+ import qualified Servant.Multipart as Servant
3033
3134import Language.Elm.Definition (Definition )
3235import qualified Language.Elm.Definition as Definition
@@ -49,7 +52,7 @@ elmEndpointDefinition urlBase moduleName endpoint =
4952 (Name. Qualified moduleName functionName)
5053 0
5154 (Bound. toScope $ vacuous $ elmTypeSig)
52- (panic " expression not closed" <$> lambdaArgs argNames elmLambdaBody)
55+ (error " expression not closed" <$> lambdaArgs argNames elmLambdaBody)
5356 where
5457 functionName =
5558 case _functionName endpoint of
@@ -162,7 +165,7 @@ elmEndpointDefinition urlBase moduleName endpoint =
162165 Expression. App
163166 " Http.request"
164167 (Expression. Record
165- [ (" method" , Expression. String $ toS $ _method endpoint)
168+ [ (" method" , Expression. String $ Text. decodeUtf8 $ _method endpoint)
166169 , (" headers" , elmHeaders)
167170 , (" url" , elmUrl)
168171 , (" body" , elmBody)
@@ -325,7 +328,7 @@ elmEndpointDefinition urlBase moduleName endpoint =
325328 , Bound. toScope $
326329 case _returnType endpoint of
327330 Nothing ->
328- panic " elmRequest: No return type" -- TODO?
331+ error " elmRequest: No return type" -- TODO?
329332
330333 Just (Left Servant. NoContent ) ->
331334 Expression. if_ (Expression. apps (" Basics.==" ) [pure $ Bound. B 1 , Expression. String " " ])
@@ -367,15 +370,15 @@ elmEndpointDefinition urlBase moduleName endpoint =
367370
368371 headerArgName :: Int -> Text
369372 headerArgName i =
370- " header" <> show i
373+ " header" <> fromString ( show i)
371374
372375 capturedArgName :: Int -> Text
373376 capturedArgName i =
374- " capture" <> show i
377+ " capture" <> fromString ( show i)
375378
376379 paramArgName :: Int -> Text
377380 paramArgName i =
378- " param" <> show i
381+ " param" <> fromString ( show i)
379382
380383-------------------------------------------------------------------------------
381384-- * Endpoints
@@ -460,7 +463,7 @@ instance (KnownSymbol symbol, HasElmEncoder Text a, HasElmEndpoints api)
460463 }
461464 where
462465 str =
463- toS $ symbolVal $ Proxy @ symbol
466+ fromString $ symbolVal $ Proxy @ symbol
464467
465468instance (KnownSymbol symbol , HasElmEncoder Text a , HasElmEndpoints api )
466469 => HasElmEndpoints (Servant. CaptureAll symbol a :> api ) where
@@ -473,15 +476,15 @@ instance (KnownSymbol symbol, HasElmEncoder Text a, HasElmEndpoints api)
473476 }
474477 where
475478 str =
476- toS $ symbolVal $ Proxy @ symbol
479+ fromString $ symbolVal $ Proxy @ symbol
477480
478481instance (Servant. ReflectMethod method , HasElmDecoder Aeson. Value a , list ~ '[Servant. JSON ])
479482 => HasElmEndpoints (Servant. Verb method 200 list a ) where
480483 elmEndpoints' prefix =
481484 [ prefix
482485 { _method = method
483486 , _returnType = Just $ Right $ makeDecoder @ Aeson. Value @ a
484- , _functionName = Text. toLower (toS method) : _functionName prefix
487+ , _functionName = Text. toLower (Text. decodeUtf8 method) : _functionName prefix
485488 }
486489 ]
487490 where
@@ -493,7 +496,7 @@ instance Servant.ReflectMethod method => HasElmEndpoints (Servant.Verb method 20
493496 [ prefix
494497 { _method = method
495498 , _returnType = Just $ Left Servant. NoContent
496- , _functionName = Text. toLower (toS method) : _functionName prefix
499+ , _functionName = Text. toLower (Text. decodeUtf8 method) : _functionName prefix
497500 }
498501 ]
499502 where
@@ -509,7 +512,7 @@ instance
509512 elmEndpoints' prefix =
510513 elmEndpoints' @ api prefix
511514 { _headers = _headers prefix <>
512- [ ( toS $ symbolVal $ Proxy @ symbol
515+ [ ( fromString $ symbolVal $ Proxy @ symbol
513516 , makeEncoder @ (Servant. RequiredArgument mods Text ) @ (Servant. RequiredArgument mods a )
514517 , case Servant. sbool @ (Servant. FoldRequired mods ) of
515518 Servant. STrue ->
@@ -532,7 +535,7 @@ instance
532535 { _url = (_url prefix)
533536 { _queryString =
534537 _queryString (_url prefix) <>
535- [ ( toS $ symbolVal $ Proxy @ symbol
538+ [ ( fromString $ symbolVal $ Proxy @ symbol
536539 , case Servant. sbool @ (Servant. FoldRequired mods ) of
537540 Servant. STrue ->
538541 Required
@@ -552,7 +555,7 @@ instance (KnownSymbol symbol, HasElmEncoder Text a, HasElmEndpoints api)
552555 { _url = (_url prefix)
553556 { _queryString =
554557 _queryString (_url prefix) <>
555- [ ( toS $ symbolVal $ Proxy @ symbol
558+ [ ( fromString $ symbolVal $ Proxy @ symbol
556559 , List
557560 , makeEncoder @ Text @ a
558561 )
@@ -567,7 +570,7 @@ instance (KnownSymbol symbol, HasElmEndpoints api)
567570 { _url = (_url prefix)
568571 { _queryString =
569572 _queryString (_url prefix) <>
570- [ ( toS $ symbolVal $ Proxy @ symbol
573+ [ ( fromString $ symbolVal $ Proxy @ symbol
571574 , Flag
572575 , Encoder " Basics.identity" " Basics.Bool"
573576 )
@@ -599,7 +602,7 @@ instance (KnownSymbol path, HasElmEndpoints api) => HasElmEndpoints (path :> api
599602 }
600603 where
601604 path =
602- toS $ symbolVal $ Proxy @ path
605+ fromString $ symbolVal $ Proxy @ path
603606
604607instance HasElmEndpoints api => HasElmEndpoints (Servant. RemoteHost :> api ) where
605608 elmEndpoints' = elmEndpoints' @ api
0 commit comments