diff --git a/servant-foreign/src/Servant/Foreign.hs b/servant-foreign/src/Servant/Foreign.hs index 78e85a7b..70728a06 100644 --- a/servant-foreign/src/Servant/Foreign.hs +++ b/servant-foreign/src/Servant/Foreign.hs @@ -21,8 +21,6 @@ module Servant.Foreign , HeaderArg(..) , ArgType(..) , Req - , CommonGeneratorOptions(..) - , defCommonGeneratorOptions , toValidFunctionName , captureArg , defReq @@ -60,41 +58,6 @@ import GHC.Exts (Constraint) import GHC.TypeLits import Servant.API --- | This structure is used by specific implementations to let you --- customize the output -data CommonGeneratorOptions = CommonGeneratorOptions - { - functionNameBuilder :: FunctionName -> String -- ^ function generating function names - , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it) - , successCallback :: String -- ^ name of the callback parameter when the request was successful - , errorCallback :: String -- ^ name of the callback parameter when the request reported an error - , moduleName :: String -- ^ namespace on which we define the foreign function (empty mean local var) - , urlPrefix :: String -- ^ a prefix we should add to the Url in the codegen - } - --- | Default options. --- --- @ --- > defCommonGeneratorOptions = CommonGeneratorOptions --- > { functionNameBuilder = camelCase --- > , requestBody = "body" --- > , successCallback = "onSuccess" --- > , errorCallback = "onError" --- > , moduleName = "" --- > , urlPrefix = "" --- > } --- @ -defCommonGeneratorOptions :: CommonGeneratorOptions -defCommonGeneratorOptions = CommonGeneratorOptions - { - functionNameBuilder = camelCase - , requestBody = "body" - , successCallback = "onSuccess" - , errorCallback = "onError" - , moduleName = "" - , urlPrefix = "" - } - -- | Function name builder that simply concat each part together concatCase :: FunctionName -> String concatCase = concat @@ -233,7 +196,6 @@ defReq :: Req defReq = Req defUrl "GET" [] False [] type family Elem (a :: *) (ls::[*]) :: Constraint where - Elem a '[] = 'False ~ 'True Elem a (a ': list) = () Elem a (b ': list) = Elem a list diff --git a/servant-js/src/Servant/JS/Internal.hs b/servant-js/src/Servant/JS/Internal.hs index 5363a58b..e502f49a 100644 --- a/servant-js/src/Servant/JS/Internal.hs +++ b/servant-js/src/Servant/JS/Internal.hs @@ -1,5 +1,7 @@ module Servant.JS.Internal ( JavaScriptGenerator + , CommonGeneratorOptions(..) + , defCommonGeneratorOptions , AjaxReq , jsSegments , segmentToStr @@ -12,9 +14,7 @@ module Servant.JS.Internal , (:<|>)(..) , (:>) , defReq - , defCommonGeneratorOptions , reqHeaders - , CommonGeneratorOptions(..) , HasForeign(..) , HeaderArg(..) , concatCase @@ -39,6 +39,41 @@ type AjaxReq = Req -- generators are available in this package. type JavaScriptGenerator = [Req] -> String +-- | This structure is used by specific implementations to let you +-- customize the output +data CommonGeneratorOptions = CommonGeneratorOptions + { + functionNameBuilder :: FunctionName -> String -- ^ function generating function names + , requestBody :: String -- ^ name used when a user want to send the request body (to let you redefine it) + , successCallback :: String -- ^ name of the callback parameter when the request was successful + , errorCallback :: String -- ^ name of the callback parameter when the request reported an error + , moduleName :: String -- ^ namespace on which we define the foreign function (empty mean local var) + , urlPrefix :: String -- ^ a prefix we should add to the Url in the codegen + } + +-- | Default options. +-- +-- @ +-- > defCommonGeneratorOptions = CommonGeneratorOptions +-- > { functionNameBuilder = camelCase +-- > , requestBody = "body" +-- > , successCallback = "onSuccess" +-- > , errorCallback = "onError" +-- > , moduleName = "" +-- > , urlPrefix = "" +-- > } +-- @ +defCommonGeneratorOptions :: CommonGeneratorOptions +defCommonGeneratorOptions = CommonGeneratorOptions + { + functionNameBuilder = camelCase + , requestBody = "body" + , successCallback = "onSuccess" + , errorCallback = "onError" + , moduleName = "" + , urlPrefix = "" + } + jsSegments :: [Segment] -> String jsSegments [] = "" jsSegments [x] = "/" ++ segmentToStr x False