ocaml-export 0.3.0.0 → 0.4.0.0
raw patch · 7 files changed
+77/−18 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ OCaml.BuckleScript.Internal.Module: data HaskellTypeName (name :: Symbol) a
+ OCaml.BuckleScript.Internal.Module: instance forall k (a :: k) (b :: GHC.Types.Symbol) (typSymbol :: GHC.Types.Symbol). OCaml.BuckleScript.Internal.Module.HasEmbeddedFile' (OCaml.BuckleScript.Internal.Module.OCamlTypeInFile a b) => OCaml.BuckleScript.Internal.Module.HasEmbeddedFile' (OCaml.BuckleScript.Internal.Module.HaskellTypeName typSymbol (OCaml.BuckleScript.Internal.Module.OCamlTypeInFile a b))
+ OCaml.BuckleScript.Internal.Module: instance forall k (a :: k) (b :: GHC.Types.Symbol) (typSymbol :: GHC.Types.Symbol). OCaml.BuckleScript.Internal.Module.HasOCamlType (OCaml.BuckleScript.Internal.Module.OCamlTypeInFile a b) => OCaml.BuckleScript.Internal.Module.HasOCamlType' 2 (OCaml.BuckleScript.Internal.Module.HaskellTypeName typSymbol (OCaml.BuckleScript.Internal.Module.OCamlTypeInFile a b))
+ OCaml.BuckleScript.Internal.Package: instance forall k (a :: k) (b :: GHC.Types.Symbol) (typName :: GHC.Types.Symbol). OCaml.BuckleScript.Internal.Package.HasOCamlTypeMetaData' (OCaml.BuckleScript.Internal.Module.OCamlTypeInFile a b) => OCaml.BuckleScript.Internal.Package.HasOCamlTypeMetaData'' 2 (OCaml.BuckleScript.Internal.Module.HaskellTypeName typName (OCaml.BuckleScript.Internal.Module.OCamlTypeInFile a b))
+ OCaml.BuckleScript.Internal.Spec: instance (Test.QuickCheck.Arbitrary.ADT.ToADTArbitrary b, Data.Aeson.Types.ToJSON.ToJSON b) => OCaml.BuckleScript.Internal.Spec.HasMkGoldenFiles' 3 (OCaml.BuckleScript.Internal.Module.HaskellTypeName a (OCaml.BuckleScript.Internal.Module.OCamlTypeInFile b c))
+ OCaml.BuckleScript.Types: instance OCaml.BuckleScript.Types.OCamlType Data.ByteString.Internal.ByteString
+ OCaml.Export: data HaskellTypeName (name :: Symbol) a
- OCaml.BuckleScript.Internal.Spec: type OCamlSpecAPI (modules :: [Symbol]) (subModules :: [Symbol]) typ = ConcatSymbols (Insert (TypeName typ) (Append modules subModules)) (ReqBody '[JSON] [typ] :> Post '[JSON] [typ])
+ OCaml.BuckleScript.Internal.Spec: type OCamlSpecAPI (modules :: [Symbol]) (subModules :: [Symbol]) typ (mType :: Maybe Symbol) = ConcatSymbols (Insert mType (TypeName typ) (Append modules subModules)) (ReqBody '[JSON] [typ] :> Post '[JSON] [typ])
Files
- ocaml-export.cabal +13/−10
- src/OCaml/BuckleScript/Internal/Module.hs +14/−0
- src/OCaml/BuckleScript/Internal/Package.hs +3/−0
- src/OCaml/BuckleScript/Internal/Spec.hs +13/−7
- src/OCaml/BuckleScript/Types.hs +5/−1
- src/OCaml/Export.hs +1/−0
- test/File.hs +28/−0
ocaml-export.cabal view
@@ -1,9 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.17.1.+-- This file has been generated from package.yaml by hpack version 0.20.0. -- -- see: https://github.com/sol/hpack+--+-- hash: 40f5121d1f5a9609c07abe6a6714c0fc77ffb415335597665276c30c9da23d60 name: ocaml-export-version: 0.3.0.0+version: 0.4.0.0 synopsis: Convert Haskell types in OCaml types description: README.md category: Web@@ -26,23 +28,23 @@ src ghc-options: -Wall build-depends:- base >= 4.7 && < 5+ QuickCheck , aeson+ , base >=4.7 && <5 , bytestring , containers , directory , file-embed , filepath , formatting- , hspec-golden-aeson >= 0.4.0.0+ , hspec-golden-aeson >=0.4.0.0 , mtl- , split- , QuickCheck , quickcheck-arbitrary-adt , servant , servant-server- , text+ , split , template-haskell+ , text , time , typelits-witnesses , wl-pprint-text@@ -68,8 +70,9 @@ test ghc-options: -Wall build-depends:- base+ QuickCheck , aeson+ , base , bytestring , constraints , containers@@ -79,17 +82,16 @@ , hspec-golden-aeson , ocaml-export , process- , QuickCheck , quickcheck-arbitrary-adt , servant , servant-server , template-haskell , text , time+ , typelits-witnesses , wai , wai-extra , warp- , typelits-witnesses other-modules: Dependency File@@ -100,4 +102,5 @@ Sum SumApp Util+ Paths_ocaml_export default-language: Haskell2010
src/OCaml/BuckleScript/Internal/Module.hs view
@@ -25,6 +25,7 @@ OCamlModule , OCamlSubModule , OCamlTypeInFile+ , HaskellTypeName , EmbeddedOCamlFiles (..) @@ -95,6 +96,10 @@ data OCamlTypeInFile a (filePath :: Symbol) deriving Typeable +-- | In case Generic is not derived, manually provide the type name+-- user is responsible for making sure it is correct. otherwise it+-- may lead to a compile error.+data HaskellTypeName (name :: Symbol) a -- ============================================== -- Data Types@@ -127,6 +132,7 @@ type family (HasOCamlTypeFlag a) :: Nat where HasOCamlTypeFlag (OCamlSubModule a :> b) = 4 HasOCamlTypeFlag (a :> b) = 3+ HasOCamlTypeFlag (HaskellTypeName a (OCamlTypeInFile b c)) = 2 HasOCamlTypeFlag (OCamlTypeInFile a b) = 2 HasOCamlTypeFlag a = 1 @@ -148,6 +154,11 @@ mkInterface' _ Proxy options fileMap = (mkInterface (Proxy :: Proxy a) options fileMap) <> (mkInterface (Proxy :: Proxy b) options fileMap) mkSpec' _ Proxy options modules url goldendir fileMap = (mkSpec (Proxy :: Proxy a) options modules url goldendir fileMap) <> (mkSpec (Proxy :: Proxy b) options modules url goldendir fileMap) +instance (HasOCamlType (OCamlTypeInFile a b)) => HasOCamlType' 2 (HaskellTypeName typSymbol (OCamlTypeInFile a b)) where+ mkType' _ Proxy options interface fileMap = (mkType (Proxy :: Proxy (OCamlTypeInFile a b)) options interface fileMap)+ mkInterface' _ Proxy options fileMap = (mkInterface (Proxy :: Proxy (OCamlTypeInFile a b)) options fileMap)+ mkSpec' _ Proxy options modules url goldendir fileMap = (mkSpec (Proxy :: Proxy (OCamlTypeInFile a b)) options modules url goldendir fileMap)+ instance (OCamlType a, Typeable a) => HasOCamlType' 2 (OCamlTypeInFile a b) where mkType' _ Proxy _options _ fileMap = do let typeName = tyConName . typeRepTyCon $ typeRep (Proxy :: Proxy a)@@ -218,6 +229,9 @@ instance (HasEmbeddedFile' a, HasEmbeddedFile' b) => HasEmbeddedFile' (a :> b) where mkFiles' includeInterface includeSpec Proxy = (<>) <$> mkFiles' includeInterface includeSpec (Proxy :: Proxy a) <*> mkFiles' includeInterface includeSpec (Proxy :: Proxy b)++instance (HasEmbeddedFile' (OCamlTypeInFile a b)) => HasEmbeddedFile' (HaskellTypeName typSymbol (OCamlTypeInFile a b)) where+ mkFiles' includeInterface includeSpec Proxy = mkFiles' includeInterface includeSpec (Proxy :: Proxy (OCamlTypeInFile a b)) instance (Typeable a, KnownSymbol b) => HasEmbeddedFile' (OCamlTypeInFile a b) where mkFiles' includeInterface includeSpec Proxy = do
src/OCaml/BuckleScript/Internal/Package.hs view
@@ -229,6 +229,7 @@ type family (HasOCamlTypeMetaDataFlag a) :: Nat where HasOCamlTypeMetaDataFlag (OCamlSubModule a :> b) = 4 HasOCamlTypeMetaDataFlag (a :> b) = 3+ HasOCamlTypeMetaDataFlag (HaskellTypeName a (OCamlTypeInFile b c)) = 2 HasOCamlTypeMetaDataFlag (OCamlTypeInFile a b) = 2 HasOCamlTypeMetaDataFlag a = 1 @@ -248,6 +249,8 @@ instance (HasOCamlTypeMetaData' a, HasOCamlTypeMetaData' b) => HasOCamlTypeMetaData'' 3 (a :> b) where mkOCamlTypeMetaData'' _ modul subModul Proxy = (mkOCamlTypeMetaData' modul subModul (Proxy :: Proxy a)) <> (mkOCamlTypeMetaData' modul subModul (Proxy :: Proxy b)) +instance (HasOCamlTypeMetaData' (OCamlTypeInFile a b)) => HasOCamlTypeMetaData'' 2 (HaskellTypeName typName (OCamlTypeInFile a b)) where+ mkOCamlTypeMetaData'' _ modul subModul Proxy = (mkOCamlTypeMetaData' modul subModul (Proxy :: Proxy (OCamlTypeInFile a b))) instance (Typeable a) => HasOCamlTypeMetaData'' 2 (OCamlTypeInFile a b) where mkOCamlTypeMetaData'' _ modul subModul Proxy =
src/OCaml/BuckleScript/Internal/Spec.hs view
@@ -105,6 +105,7 @@ HasMkGoldenFilesFlag ((OCamlModule a :> b) :<|> c) = 6 HasMkGoldenFilesFlag (OCamlModule a :> b) = 5 HasMkGoldenFilesFlag (OCamlSubModule a :> b) = 4+ HasMkGoldenFilesFlag (HaskellTypeName a (OCamlTypeInFile b c)) = 3 HasMkGoldenFilesFlag (OCamlTypeInFile a b) = 3 HasMkGoldenFilesFlag (a :> b) = 2 HasMkGoldenFilesFlag a = 1@@ -126,6 +127,9 @@ instance (HasMkGoldenFiles a) => HasMkGoldenFiles' 4 (OCamlSubModule subModule :> a) where mkGoldenFiles' _ Proxy size fp = mkGoldenFiles (Proxy :: Proxy a) size fp +instance (ToADTArbitrary b, ToJSON b) => HasMkGoldenFiles' 3 (HaskellTypeName a (OCamlTypeInFile b c)) where+ mkGoldenFiles' _ Proxy size fp = mkGoldenFileForType size (Proxy :: Proxy b) fp+ instance (ToADTArbitrary a, ToJSON a) => HasMkGoldenFiles' 3 (OCamlTypeInFile a b) where mkGoldenFiles' _ Proxy size fp = mkGoldenFileForType size (Proxy :: Proxy a) fp @@ -151,12 +155,13 @@ type family MkOCamlSpecAPI' modules subModules api :: * where MkOCamlSpecAPI' modules subModules ((OCamlSubModule restSubModules) :> a) = MkOCamlSpecAPI' modules (Append subModules '[restSubModules]) a MkOCamlSpecAPI' modules subModules (a :> b) = MkOCamlSpecAPI' modules subModules a :<|> MkOCamlSpecAPI' modules subModules b- MkOCamlSpecAPI' modules subModules (OCamlTypeInFile api _typeFilePath) = OCamlSpecAPI modules subModules api- MkOCamlSpecAPI' modules subModules api = OCamlSpecAPI modules subModules api+ MkOCamlSpecAPI' modules subModules (HaskellTypeName name (OCamlTypeInFile api _typeFilePath)) = OCamlSpecAPI modules subModules api ('Just name)+ MkOCamlSpecAPI' modules subModules (OCamlTypeInFile api _typeFilePath) = OCamlSpecAPI modules subModules api 'Nothing+ MkOCamlSpecAPI' modules subModules api = OCamlSpecAPI modules subModules api 'Nothing -- | A servant route for a testing an OCaml type's encoder and decoder-type OCamlSpecAPI (modules :: [Symbol]) (subModules :: [Symbol]) typ =- ConcatSymbols (Insert (TypeName typ) (Append modules subModules)) (ReqBody '[JSON] [typ] :> Post '[JSON] [typ])+type OCamlSpecAPI (modules :: [Symbol]) (subModules :: [Symbol]) typ (mType :: Maybe Symbol) =+ ConcatSymbols (Insert mType (TypeName typ) (Append modules subModules)) (ReqBody '[JSON] [typ] :> Post '[JSON] [typ]) class OCamlModuleTypeCount api where ocamlModuleTypeCount :: Proxy api -> Int@@ -235,9 +240,10 @@ Length (x ': xs) = 1 + Length xs -- | Insert type into type level list-type family Insert a xs where- Insert a '[] = a ': '[]- Insert a (x ': xs) = x ': (Insert a xs)+type family Insert a b xs where+ Insert ('Just a) b '[] = a ': '[]+ Insert 'Nothing b '[] = b ': '[]+ Insert a b (x ': xs) = x ': (Insert a b xs) -- | Concat a Symbol the end of a list of Symbols. type family ConcatSymbols xs rhs :: * where
src/OCaml/BuckleScript/Types.hs view
@@ -68,7 +68,8 @@ -- aeson import Data.Aeson (ToJSON, FromJSON)-+-- bytestring+import Data.ByteString (ByteString) -- text import Data.Text (Text) import qualified Data.Text as T@@ -284,6 +285,9 @@ toOCamlType _ = OCamlPrimitive OUnit instance OCamlType Text where+ toOCamlType _ = OCamlPrimitive OString++instance OCamlType ByteString where toOCamlType _ = OCamlPrimitive OString instance OCamlType Day where
src/OCaml/Export.hs view
@@ -14,6 +14,7 @@ , OCamlModule , OCamlSubModule , OCamlTypeInFile+ , HaskellTypeName , PackageOptions (..) , defaultPackageOptions
test/File.hs view
@@ -26,6 +26,7 @@ :> OCamlTypeInFile Business "test/ocaml/Business" :> OCamlTypeInFile (Wrapper TypeParameterRef0 TypeParameterRef1) "test/ocaml/Wrapper" :> AutoDependingOnManual+ :> HaskellTypeName "NonGenericType" (OCamlTypeInFile NonGenericType "test/ocaml/NonGenericType") ) data Person = Person@@ -92,3 +93,30 @@ arbitrary = AutoDependingOnManual <$> arbitrary <*> arbitrary instance ToADTArbitrary AutoDependingOnManual++data NonGenericType =+ NonGenericType+ { ngA :: String+ , ngB :: Int+ } deriving (Show, Eq)++instance ToJSON NonGenericType where+ toJSON ng = object [ "ngA" .= ngA ng, "ngB" .= ngB ng]++instance FromJSON NonGenericType where+ parseJSON = withObject "NonGenericType" $ \o ->+ NonGenericType <$> o .: "ngA" <*> o .: "ngB"++instance ToADTArbitrary NonGenericType where+ toADTArbitrarySingleton Proxy =+ ADTArbitrarySingleton "File" "NonGenericType"+ <$> (ConstructorArbitraryPair "NonGenericType" <$> (NonGenericType <$> arbitrary <*> arbitrary))++ toADTArbitrary Proxy =+ ADTArbitrary "File" "NonGenericType"+ <$> sequence+ [ ConstructorArbitraryPair "NonGenericType" <$> (NonGenericType <$> arbitrary <*> arbitrary)+ ]++instance OCamlType NonGenericType where+ toOCamlType _ = typeableToOCamlType (Proxy :: Proxy NonGenericType)