aeson-typescript 0.4.1.0 → 0.4.2.0
raw patch · 12 files changed
+33/−296 lines, 12 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- README.md +1/−1
- aeson-typescript.cabal +2/−8
- dev/Live.hs +0/−77
- dev/Live2.hs +0/−28
- dev/Live3.hs +0/−27
- dev/Live4.hs +0/−33
- dev/Live5.hs +0/−80
- dev/Live6.hs +0/−39
- src/Data/Aeson/TypeScript/Instances.hs +1/−1
- test/TestBoilerplate.hs +12/−2
- test/Util/Aeson.hs +13/−0
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Change log +## 0.4.2.0++* Fix TypeScript (A.KeyMap a) instance+ ## 0.4.1.0 * Add TypeScript Int16
README.md view
@@ -29,7 +29,7 @@ Now we can use the newly created instances. ```haskell->>> putStrLn $ formatTSDeclarations $ getTypeScriptDeclaration (Proxy :: Proxy (D T))+>>> putStrLn $ formatTSDeclarations $ getTypeScriptDeclarations (Proxy :: Proxy (D T)) type D<T> = "nullary" | IUnary<T> | IProduct<T> | IRecord<T>;
aeson-typescript.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: aeson-typescript-version: 0.4.1.0+version: 0.4.2.0 synopsis: Generate TypeScript definition files from your ADTs description: Please see the README on Github at <https://github.com/codedownio/aeson-typescript#readme> category: Text, Web, JSON@@ -83,6 +83,7 @@ UntaggedTagSingleConstructors UnwrapUnaryRecords Util+ Util.Aeson Data.Aeson.TypeScript.Formatting Data.Aeson.TypeScript.Instances Data.Aeson.TypeScript.Internal@@ -93,17 +94,10 @@ Data.Aeson.TypeScript.TypeManipulation Data.Aeson.TypeScript.Types Data.Aeson.TypeScript.Util- Live- Live2- Live3- Live4- Live5- Live6 Paths_aeson_typescript hs-source-dirs: test src- dev ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N build-depends: aeson
− dev/Live.hs
@@ -1,77 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE QuasiQuotes #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE NamedFieldPuns #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE TypeFamilyDependencies #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}--module Live where--import Data.Aeson as A-import Data.Aeson.TypeScript.Recursive-import Data.Aeson.TypeScript.TH-import Data.Function-import Data.Functor.Identity-import Data.Kind-import Data.Map-import Data.Proxy-import Data.String.Interpolate-import qualified Data.Text as T-import Prelude hiding (Double)---instance TypeScript Identity where getTypeScriptType _ = "any"--data SingleDE = SingleDE-instance TypeScript SingleDE where getTypeScriptType _ = [i|"single"|]--data K8SDE = K8SDE-instance TypeScript K8SDE where getTypeScriptType _ = [i|"k8s"|]--data SingleNodeEnvironment = SingleNodeEnvironment- deriving (Eq, Show)-instance TypeScript SingleNodeEnvironment where getTypeScriptType _ = [i|"single_node_env"|]--data K8SEnvironment = K8SEnvironment- deriving (Eq, Show)-instance TypeScript K8SEnvironment where getTypeScriptType _ = [i|"k8s_env"|]--data Nullable (c :: Type -> Type) x-data Exposed x-type family Columnar (f :: Type -> Type) x where- Columnar Exposed x = Exposed x- Columnar Identity x = x- Columnar (Nullable c) x = Columnar c (Maybe x)- Columnar f x = f x--type family DeployEnvironment env = result | result -> env where- DeployEnvironment SingleNodeEnvironment = SingleDE- DeployEnvironment K8SEnvironment = K8SDE- DeployEnvironment T = ()---- * The main type--data UserT env f = User {- _userDeployEnv :: Columnar f (DeployEnvironment env)- }--data Complex3 k = Complex3 {- bulkCommandNoArgKeys :: Map T.Text k- } deriving (Show)---deriveTypeScript' A.defaultOptions ''UserT (defaultExtraTypeScriptOptions { typeFamiliesToMapToTypeScript = [''DeployEnvironment] })--main :: IO ()-main = getTypeScriptDeclarationsRecursively (Proxy :: Proxy (UserT T Identity))- & formatTSDeclarations- & putStrLn
− dev/Live2.hs
@@ -1,28 +0,0 @@-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE TypeFamilyDependencies #-}--module Live2 where--import Data.Aeson as A-import Data.Aeson.TypeScript.TH-import Data.Function-import Data.Proxy-- -data TestT a = TestT {- listOfA :: [a]- , maybeA :: Maybe a- }-$(deriveTypeScript A.defaultOptions ''TestT)--main :: IO ()-main = getTypeScriptDeclarations (Proxy :: Proxy (TestT Int))- & formatTSDeclarations- & putStrLn
− dev/Live3.hs
@@ -1,27 +0,0 @@-{-# LANGUAGE TypeApplications #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE TypeFamilyDependencies #-}--module Live3 where--import Data.Aeson as A-import Data.Aeson.TypeScript.TH-import Data.Function-import Data.Proxy---data Test = TestBlah {x :: Int, y :: Bool}--$(deriveTypeScript (A.defaultOptions { A.tagSingleConstructors = True }) ''Test)--main :: IO ()-main = getTypeScriptDeclarations (Proxy @Test)- & formatTSDeclarations- & putStrLn
− dev/Live4.hs
@@ -1,33 +0,0 @@-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TypeApplications #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE TypeFamilyDependencies #-}--module Live4 where--import Data.Aeson as A-import Data.Aeson.TypeScript.Recursive-import Data.Aeson.TypeScript.TH-import Data.Function-import Data.Proxy-import TestBoilerplate---type family DeployEnvironment2 env = result | result -> env-type instance DeployEnvironment2 SingleNodeEnvironment = SingleDE-type instance DeployEnvironment2 K8SEnvironment = K8SDE-type instance DeployEnvironment2 T = ()-newtype Simple env = Simple (DeployEnvironment2 env)-$(deriveTypeScript' A.defaultOptions ''Simple (defaultExtraTypeScriptOptions { typeFamiliesToMapToTypeScript = [''DeployEnvironment2] }))--main :: IO ()-main = getTypeScriptDeclarationsRecursively (Proxy @(Simple T))- & formatTSDeclarations- & putStrLn
− dev/Live5.hs
@@ -1,80 +0,0 @@-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TypeApplications #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE TypeInType #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE TypeFamilyDependencies #-}-{-# LANGUAGE DeriveGeneric #-}--module Live5 where--import Data.Aeson as A-import Data.Aeson.TypeScript.Recursive-import Data.Aeson.TypeScript.TH-import Data.Function-import Data.Kind as Kind-import Data.Proxy-import qualified Data.Text as T-import Data.Typeable-import Data.Void-import GHC.Generics-import TestBoilerplate----- data From = FromServer | FromClient--- data MethodType = Notification | Request---- data Method (f :: From) (t :: MethodType) where--- Login :: Method 'FromClient 'Request--- ReportClick :: Method 'FromClient 'Notification---- instance TypeScript Login where getTypeScriptType _ = "asdf"--- instance TypeScript ReportClick where getTypeScriptType _ = "fdsa"---- data LoginParams = LoginParams {--- loginUsername :: T.Text--- , loginPassword :: T.Text--- }--- $(deriveJSONAndTypeScript A.defaultOptions ''LoginParams)----- data ReportClickParams = ReportClickParams {--- reportClickX :: Int--- , reportClickY :: Int--- }--- $(deriveJSONAndTypeScript A.defaultOptions ''ReportClickParams)---- type family MessageParams (m :: Method f t) :: Kind.Type where--- MessageParams 'Login = LoginParams--- MessageParams 'ReportClick = ReportClickParams---- data SMethod (m :: Method f t) where--- SLogin :: SMethod 'Login--- SReportClick :: SMethod 'ReportClick---- data RequestMessage (m :: Method f 'Request) =--- RequestMessage {--- _id :: T.Text--- , _method :: SMethod m--- , _params :: MessageParams m--- }---- data LoginResult = LoginResult { profilePicture :: T.Text }--- $(deriveJSONAndTypeScript A.defaultOptions ''LoginResult)---- type family ResponseResult (m :: Method f 'Request) :: Kind.Type where--- ResponseResult 'Login = LoginResult--- ResponseResult _ = Void---- deriveTypeScript' A.defaultOptions ''RequestMessage (ExtraTypeScriptOptions [''MessageParams])---- -- main :: IO ()--- -- main = getTypeScriptDeclarationsRecursively (Proxy @(RequestMessage (Method FromClient Request)))--- -- & formatTSDeclarations--- -- & putStrLn
− dev/Live6.hs
@@ -1,39 +0,0 @@-{-# LANGUAGE UndecidableInstances #-}-{-# LANGUAGE TypeApplications #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE ConstraintKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE TypeInType #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE TypeFamilyDependencies #-}-{-# LANGUAGE DeriveGeneric #-}--module Live6 where--import Data.Aeson as A-import Data.Aeson.TypeScript.TH-import Data.Function-import Data.Map-import Data.Proxy-import Data.Text---data Complex a = Product Int a | Unary Int deriving Eq--data Complex2 a = Product2 Int a--data Complex3 k = Complex3 {- bulkCommandNoArgKeys :: Map Text k- } deriving (Show)-$(deriveTypeScript defaultOptions ''Complex3)--main :: IO ()--- main = printThing (Proxy @(BulkCommandNoArg Int))-main = printThing (Proxy @(Complex3 Double))--printThing x = getTypeScriptDeclarations x- & formatTSDeclarations- & putStrLn
src/Data/Aeson/TypeScript/Instances.hs view
@@ -136,7 +136,7 @@ #if MIN_VERSION_aeson(2,0,0) instance (TypeScript a) => TypeScript (A.KeyMap a) where- getTypeScriptType _ = [i|{[k]?: #{getTypeScriptType (Proxy :: Proxy a)}}|]+ getTypeScriptType _ = [i|{[k: string]: #{getTypeScriptType (Proxy :: Proxy a)}}|] getParentTypes _ = L.nub [TSType (Proxy :: Proxy a)] #endif
test/TestBoilerplate.hs view
@@ -25,6 +25,7 @@ import Language.Haskell.TH hiding (Type) import Test.Hspec import Util+import Util.Aeson data Unit = Unit data OneFieldRecordless = OneFieldRecordless Int@@ -35,6 +36,7 @@ data TwoConstructor = Con1 { con1String :: String } | Con2 { con2String :: String, con2Int :: Int } data Complex a = Nullary | Unary Int | Product String Char a | Record { testOne :: Int, testTwo :: Bool, testThree :: Complex a} deriving Eq data Optional = Optional {optionalInt :: Maybe Int}+data AesonTypes = AesonTypes { aesonValue :: A.Value, aesonObject :: A.Object } -- * For testing type families @@ -74,6 +76,7 @@ deriveInstances ''TwoConstructor deriveInstances ''Complex deriveInstances ''Optional+ deriveInstances ''AesonTypes typesAndValues :: Exp <- [e|[(getTypeScriptType (Proxy :: Proxy Unit), A.encode Unit) @@ -95,10 +98,16 @@ , (getTypeScriptType (Proxy :: Proxy (Complex Int)), A.encode (Unary 42 :: Complex Int)) , (getTypeScriptType (Proxy :: Proxy (Complex Int)), A.encode (Product "asdf" 'g' 42 :: Complex Int)) , (getTypeScriptType (Proxy :: Proxy (Complex Int)), A.encode ((Record { testOne = 3, testTwo = True, testThree = Product "test" 'A' 123}) :: Complex Int))+ , (getTypeScriptType (Proxy :: Proxy Optional), A.encode (Optional { optionalInt = Nothing }))- , (getTypeScriptType (Proxy :: Proxy Optional), A.encode (Optional { optionalInt = Just 1 }))]- |]+ , (getTypeScriptType (Proxy :: Proxy Optional), A.encode (Optional { optionalInt = Just 1 })) + , (getTypeScriptType (Proxy :: Proxy AesonTypes), A.encode (AesonTypes {+ aesonValue = A.object [("foo" :: A.Key, A.Number 42)]+ , aesonObject = aesonFromList [("foo", A.Number 42)]+ }))+ ]|]+ declarations :: Exp <- [e|getTypeScriptDeclarations (Proxy :: Proxy Unit) <> getTypeScriptDeclarations (Proxy :: Proxy OneFieldRecordless) <> getTypeScriptDeclarations (Proxy :: Proxy OneField)@@ -108,6 +117,7 @@ <> getTypeScriptDeclarations (Proxy :: Proxy TwoConstructor) <> getTypeScriptDeclarations (Proxy :: Proxy (Complex T)) <> getTypeScriptDeclarations (Proxy :: Proxy Optional)+ <> getTypeScriptDeclarations (Proxy :: Proxy AesonTypes) |] tests <- [d|tests :: SpecWith ()
+ test/Util/Aeson.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE CPP #-}++module Util.Aeson where++#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as KM++aesonFromList = KM.fromList+#else+import Data.HashMap.Strict as HM++aesonFromList = HM.fromList+#endif