CommonGeneratorOptions moved to servant-js
This commit is contained in:
parent
6fa4b55c94
commit
7ff9e52a50
2 changed files with 37 additions and 40 deletions
|
@ -21,8 +21,6 @@ module Servant.Foreign
|
||||||
, HeaderArg(..)
|
, HeaderArg(..)
|
||||||
, ArgType(..)
|
, ArgType(..)
|
||||||
, Req
|
, Req
|
||||||
, CommonGeneratorOptions(..)
|
|
||||||
, defCommonGeneratorOptions
|
|
||||||
, toValidFunctionName
|
, toValidFunctionName
|
||||||
, captureArg
|
, captureArg
|
||||||
, defReq
|
, defReq
|
||||||
|
@ -60,41 +58,6 @@ import GHC.Exts (Constraint)
|
||||||
import GHC.TypeLits
|
import GHC.TypeLits
|
||||||
import Servant.API
|
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
|
-- | Function name builder that simply concat each part together
|
||||||
concatCase :: FunctionName -> String
|
concatCase :: FunctionName -> String
|
||||||
concatCase = concat
|
concatCase = concat
|
||||||
|
@ -233,7 +196,6 @@ defReq :: Req
|
||||||
defReq = Req defUrl "GET" [] False []
|
defReq = Req defUrl "GET" [] False []
|
||||||
|
|
||||||
type family Elem (a :: *) (ls::[*]) :: Constraint where
|
type family Elem (a :: *) (ls::[*]) :: Constraint where
|
||||||
Elem a '[] = 'False ~ 'True
|
|
||||||
Elem a (a ': list) = ()
|
Elem a (a ': list) = ()
|
||||||
Elem a (b ': list) = Elem a list
|
Elem a (b ': list) = Elem a list
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
module Servant.JS.Internal
|
module Servant.JS.Internal
|
||||||
( JavaScriptGenerator
|
( JavaScriptGenerator
|
||||||
|
, CommonGeneratorOptions(..)
|
||||||
|
, defCommonGeneratorOptions
|
||||||
, AjaxReq
|
, AjaxReq
|
||||||
, jsSegments
|
, jsSegments
|
||||||
, segmentToStr
|
, segmentToStr
|
||||||
|
@ -12,9 +14,7 @@ module Servant.JS.Internal
|
||||||
, (:<|>)(..)
|
, (:<|>)(..)
|
||||||
, (:>)
|
, (:>)
|
||||||
, defReq
|
, defReq
|
||||||
, defCommonGeneratorOptions
|
|
||||||
, reqHeaders
|
, reqHeaders
|
||||||
, CommonGeneratorOptions(..)
|
|
||||||
, HasForeign(..)
|
, HasForeign(..)
|
||||||
, HeaderArg(..)
|
, HeaderArg(..)
|
||||||
, concatCase
|
, concatCase
|
||||||
|
@ -39,6 +39,41 @@ type AjaxReq = Req
|
||||||
-- generators are available in this package.
|
-- generators are available in this package.
|
||||||
type JavaScriptGenerator = [Req] -> String
|
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 :: [Segment] -> String
|
||||||
jsSegments [] = ""
|
jsSegments [] = ""
|
||||||
jsSegments [x] = "/" ++ segmentToStr x False
|
jsSegments [x] = "/" ++ segmentToStr x False
|
||||||
|
|
Loading…
Reference in a new issue