aeson-typescript-0.1.0.0: src/Data/Aeson/TypeScript/Types.hs
{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, RecordWildCards, ScopedTypeVariables, ExistentialQuantification, PolyKinds #-}
module Data.Aeson.TypeScript.Types where
import Control.Monad
import Control.Monad.Writer
import Control.Monad.Writer.Lazy
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as A
import Data.Data
import Data.Monoid
import Data.Proxy
import Data.String
import Data.String.Interpolate.IsString
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Language.Haskell.TH
import Language.Haskell.TH.Datatype
-- | The typeclass that defines how a type is turned into TypeScript.
class TypeScript a where
getTypeScriptDeclarations :: Proxy a -> [TSDeclaration]
-- ^ Get the declaration(s) needed for this type.
getTypeScriptDeclarations _ = []
getTypeScriptType :: Proxy a -> String
-- ^ Get the type as a string.
getTypeScriptOptional :: Proxy a -> Bool
-- ^ Get a flag representing whether this type is optional.
getTypeScriptOptional _ = False
data TSDeclaration = TSInterfaceDeclaration { interfaceName :: String
, interfaceGenericVariables :: [String]
, interfaceMembers :: [TSField] }
| TSTypeAlternatives { typeName :: String
, typeGenericVariables :: [String]
, alternativeTypes :: [String]}
deriving (Show, Eq)
data TSField = TSField { fieldOptional :: Bool
, fieldName :: String
, fieldType :: String } deriving (Show, Eq)
newtype TSString a = TSString { unpackTSString :: String } deriving Show
instance IsString (TSString a) where
fromString x = TSString x
-- * Formatting options
data FormattingOptions = FormattingOptions {
numIndentSpaces :: Int
-- ^ How many spaces to indent TypeScript blocks
}
defaultFormattingOptions = FormattingOptions 2
-- | Convenience typeclass class you can use to "attach" a set of Aeson encoding options to a type.
class HasJSONOptions a where
getJSONOptions :: (Proxy a) -> A.Options