Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- toElmTypeRefWith :: ElmOptions -> EType -> Text
- toElmDecoderRefWith :: ElmOptions -> EType -> Text
- toElmEncoderRefWith :: ElmOptions -> EType -> Text
- data ElmOptions = ElmOptions {
- urlPrefix :: UrlPrefix
- elmTypeAlterations :: EType -> EType
- elmAlterations :: ETypeDef -> ETypeDef
- emptyResponseElmTypes :: [EType]
- stringElmTypes :: [EType]
- data UrlPrefix
- type Namespace = [String]
- defElmOptions :: ElmOptions
- defElmImports :: Text
- generateElmModuleWith :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => ElmOptions -> Namespace -> Text -> FilePath -> [DefineElm] -> Proxy api -> IO ()
- generateElmModule :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => Namespace -> Text -> FilePath -> [DefineElm] -> Proxy api -> IO ()
- generateElmForAPI :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => Proxy api -> [Text]
- generateElmForAPIWith :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => ElmOptions -> Proxy api -> [Text]
- i :: Int
- generateElmForRequest :: ElmOptions -> Req EType -> Doc
- mkTypeSignature :: ElmOptions -> Req EType -> Doc
- elmHeaderArg :: HeaderArg EType -> Doc
- elmCaptureArg :: Segment EType -> Doc
- elmQueryArg :: QueryArg EType -> Doc
- elmBodyArg :: Doc
- isNotCookie :: HeaderArg f -> Bool
- mkArgs :: ElmOptions -> Req EType -> Doc
- mkLetParams :: ElmOptions -> Req EType -> Maybe Doc
- mkRequest :: ElmOptions -> Req EType -> Doc
- renderDecoderName :: EType -> Doc
- mkUrl :: ElmOptions -> [Segment EType] -> Doc
- mkQueryParams :: Req EType -> Doc
- isEmptyType :: ElmOptions -> EType -> Bool
- isElmStringType :: ElmOptions -> EType -> Bool
- isElmMaybeStringType :: ElmOptions -> EType -> Bool
- isElmMaybeType :: EType -> Bool
- isElmListOfMaybeBoolType :: EType -> Bool
- docToText :: Doc -> Text
- stext :: Text -> Doc
- elmRecord :: [Doc] -> Doc
- elmList :: [Doc] -> Doc
- elmListOfMaybes :: [Doc] -> Doc
Documentation
toElmTypeRefWith :: ElmOptions -> EType -> Text Source #
toElmDecoderRefWith :: ElmOptions -> EType -> Text Source #
toElmEncoderRefWith :: ElmOptions -> EType -> Text Source #
data ElmOptions Source #
Options to configure how code is generated.
ElmOptions | |
|
defElmOptions :: ElmOptions Source #
Default options for generating Elm code.
The default options are:
{ urlPrefix = Static "" , elmAlterations = Elm.defaultTypeAlterations , emptyResponseElmTypes = [ getType (Proxy :: Proxy ()) ] , stringElmTypes = [ getType (Proxy :: Proxy String) , getType (Proxy :: Proxy T.Text) ] }
defElmImports :: Text Source #
Default imports required by generated Elm code.
You probably want to include this at the top of your generated Elm module.
The default required imports are:
import Json.Decode import Json.Encode exposing (Value) -- The following module comes from bartavelle/json-helpers import Json.Helpers exposing (..) import Dict exposing (Dict) import Set import Http import String import Url.Builder
generateElmModuleWith :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => ElmOptions -> Namespace -> Text -> FilePath -> [DefineElm] -> Proxy api -> IO () Source #
Helper to generate a complete Elm module given a list of Elm type definitions and an API.
generateElmModule :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => Namespace -> Text -> FilePath -> [DefineElm] -> Proxy api -> IO () Source #
Calls generateElmModuleWith with defElmOptions
.
generateElmForAPI :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => Proxy api -> [Text] Source #
Generate Elm code for the API with default options.
Returns a list of Elm functions to query your Servant API from Elm.
You could spit these out to a file and call them from your Elm code, but you
would be better off creating a Spec
with the result and using specsToDir
,
which handles the module name for you.
generateElmForAPIWith :: (HasForeign LangElm EType api, GenerateList EType (Foreign EType api)) => ElmOptions -> Proxy api -> [Text] Source #
Generate Elm code for the API with custom options.
generateElmForRequest :: ElmOptions -> Req EType -> Doc Source #
Generate an Elm function for one endpoint.
mkTypeSignature :: ElmOptions -> Req EType -> Doc Source #
elmBodyArg :: Doc Source #
isNotCookie :: HeaderArg f -> Bool Source #
mkLetParams :: ElmOptions -> Req EType -> Maybe Doc Source #
renderDecoderName :: EType -> Doc Source #
isEmptyType :: ElmOptions -> EType -> Bool Source #
Determines whether we construct an Elm function that expects an empty response body.
isElmStringType :: ElmOptions -> EType -> Bool Source #
Determines whether we call toString
on URL captures and query params of
this type in Elm.
isElmMaybeStringType :: ElmOptions -> EType -> Bool Source #
Determines whether a type is 'Maybe a' where a
is something akin to a String
.
isElmMaybeType :: EType -> Bool Source #
isElmListOfMaybeBoolType :: EType -> Bool Source #
elmListOfMaybes :: [Doc] -> Doc Source #