module Servant.TypeScript.Types where
import Control.Lens
import Data.Aeson.TypeScript.Recursive
import Data.Aeson.TypeScript.TH
import Data.String.Interpolate
import qualified Data.Text as T
import Servant.Foreign.Internal as FI
import qualified Servant.TypeScript.GetFunctions as GetFunctions
import Servant.TypeScript.Util
data LangTS
instance (TypeScript a) => HasForeignType LangTS T.Text a where
typeFor :: Proxy LangTS -> Proxy Text -> Proxy a -> Text
typeFor Proxy LangTS
_proxyLang Proxy Text
_proxyFtype Proxy a
proxyA = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Proxy a -> String
forall k (a :: k). TypeScript a => Proxy a -> String
getTypeScriptType Proxy a
proxyA
data LangTSDecls
instance (TypeScript a) => HasForeignType LangTSDecls [TSDeclaration] a where
typeFor :: Proxy LangTSDecls
-> Proxy [TSDeclaration] -> Proxy a -> [TSDeclaration]
typeFor Proxy LangTSDecls
_proxyLang Proxy [TSDeclaration]
_proxyFtype Proxy a
proxyA = Proxy a -> [TSDeclaration]
forall k (a :: k). TypeScript a => Proxy a -> [TSDeclaration]
getTypeScriptDeclarationsRecursively Proxy a
proxyA
data ServantTypeScriptOptions = ServantTypeScriptOptions {
:: [TSType]
, ServantTypeScriptOptions -> Req Text -> String
getFileKey :: Req T.Text -> FilePath
, ServantTypeScriptOptions -> Req Text -> Text
getFunctionName :: Req T.Text -> T.Text
, ServantTypeScriptOptions
-> (Req Text -> Text) -> [Req Text] -> Text
getFunctions :: (Req T.Text -> T.Text) -> [Req T.Text] -> T.Text
}
defaultServantTypeScriptOptions :: ServantTypeScriptOptions
defaultServantTypeScriptOptions :: ServantTypeScriptOptions
defaultServantTypeScriptOptions = ServantTypeScriptOptions :: [TSType]
-> (Req Text -> String)
-> (Req Text -> Text)
-> ((Req Text -> Text) -> [Req Text] -> Text)
-> ServantTypeScriptOptions
ServantTypeScriptOptions {
extraTypes :: [TSType]
extraTypes = []
, getFileKey :: Req Text -> String
getFileKey = String -> Req Text -> String
forall a b. a -> b -> a
const String
"client.ts"
, getFunctionName :: Req Text -> Text
getFunctionName = \Req Text
req -> case Req Text
req Req Text -> Getting [Text] (Req Text) [Text] -> [Text]
forall s a. s -> Getting a s a -> a
^. ((FunctionName -> Const [Text] FunctionName)
-> Req Text -> Const [Text] (Req Text)
forall ftype. Lens' (Req ftype) FunctionName
reqFuncName ((FunctionName -> Const [Text] FunctionName)
-> Req Text -> Const [Text] (Req Text))
-> (([Text] -> Const [Text] [Text])
-> FunctionName -> Const [Text] FunctionName)
-> Getting [Text] (Req Text) [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Text] -> Const [Text] [Text])
-> FunctionName -> Const [Text] FunctionName
Iso' FunctionName [Text]
_FunctionName) of
(Text
method:[Text]
xs) -> [Text] -> Text
toCamelList ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ (Text -> Text) -> [Text] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
snakeToCamel (Text
methodText -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
xs)
[Text]
_ -> String -> Text
forall a. HasCallStack => String -> a
error [i|Case not handled in getFunctionName: '#{req}'|]
, getFunctions :: (Req Text -> Text) -> [Req Text] -> Text
getFunctions = (Req Text -> Text) -> [Req Text] -> Text
GetFunctions.getFunctions
}