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(..)
|
||||
, 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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue