purescript-bridge 0.3.1.1 → 0.3.2.0
raw patch · 3 files changed
+36/−19 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Language.PureScript.Bridge: doBridge :: TypeBridge -> TypeInfo -> TypeInfo
Files
- README.md +10/−3
- purescript-bridge.cabal +1/−1
- src/Language/PureScript/Bridge.hs +25/−15
README.md view
@@ -3,6 +3,10 @@ Translate your Haskell types to PureScript types. It should in theory work for almost all Haskell types, including type constructors! You just have to instantiate it with dummy parameters from e.g. "Language.PureScript.Bridge.TypeParameters". +Data type translation is fully and easily customizable by providing your own `TypeBridge` instances!++## JSON encoding / decoding+ For compatible JSON representations you should be using [aeson](http://hackage.haskell.org/package/aeson)'s generic encoding/decoding with default options and `gAesonEncodeJson` and `gAesonDecodeJson` from the [purescript-argonaut-codecs](https://github.com/purescript-contrib/purescript-argonaut-codecs) package, (Data.Argonaut.Aeson).@@ -11,12 +15,15 @@ In the meantime, you can find the PR [here](https://github.com/purescript-contrib/purescript-argonaut-codecs/pull/12). ++## Documentation + Usage of this library is documented in [`Language.Purescript.Bridge`](http://hackage.haskell.org/package/purescript-bridge/docs/Language-PureScript-Bridge.html). All you should need to get started is: [`writePSTypes`](http://hackage.haskell.org/package/purescript-bridge/docs/Language-PureScript-Bridge.html#writePSTypes). -You can customize data type translation by providing your own `TypeBridge`.+## Status -This library is at a really early stage. It works for my use case at the moment and I will fix bugs when they come along.+This library is at a quite early stage. It works for my use case at the moment and I will fix bugs when they come along. Also PRs for more PureScript `TypeInfo` definitions and bridges are very welcome! -Expect bugs - especially for more advanced use cases!+Expect bugs - especially for more advanced use cases. Although I have tested the most advanced one already with no issues, bugs always creep in.
purescript-bridge.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.3.1.1+version: 0.3.2.0 -- A short (one-line) description of the package. synopsis: Generate PureScript data types from Haskell data types
src/Language/PureScript/Bridge.hs view
@@ -2,26 +2,27 @@ module Language.PureScript.Bridge ( bridgeSumType , defaultBridge+ , doBridge , module Bridge , writePSTypes ) where -import qualified Data.Text as T-import qualified Data.Text.IO as T+import qualified Data.Text as T+import qualified Data.Text.IO as T -import Language.PureScript.Bridge.SumType as Bridge-import Language.PureScript.Bridge.TypeInfo as Bridge-import Language.PureScript.Bridge.Tuple as Bridge-import Language.PureScript.Bridge.Primitives as Bridge-import Language.PureScript.Bridge.Printer as Bridge+import Language.PureScript.Bridge.Primitives as Bridge+import Language.PureScript.Bridge.Printer as Bridge+import Language.PureScript.Bridge.SumType as Bridge+import Language.PureScript.Bridge.Tuple as Bridge+import Language.PureScript.Bridge.TypeInfo as Bridge -import Control.Applicative-import qualified Data.Map as M-import Data.Maybe+import Control.Applicative+import qualified Data.Map as M+import Data.Maybe -- | Your entry point to this library and quite likely all you will need. -- Make sure all your types derive Generic and Typeable.@@ -57,6 +58,14 @@ -- == Real world usage example: -- A real world use case of this library can be found <https://github.com/gonimo/gonimo-back/blob/master/src/MkFrontendTypes.hs here>. --+-- With custom bridges defined <https://github.com/gonimo/gonimo-back/blob/master/src/Gonimo/TypeBridges.hs here> and+-- custom PS types defined <https://github.com/gonimo/gonimo-back/blob/master/src/Gonimo/PSTypes.hs here>.+--+-- Parts of the generated output can be found <https://github.com/gonimo/gonimo-front/blob/master/src/Gonimo/Types.purs here>.+--+-- Note how 'Secret' and 'Key'+-- get translated according to our custom rules, with correct imports and everything. Also the formatting is quite nice, I think - would you have guessed that this code was generated?+-- -- == /WARNING/: -- This function overwrites files - make backups or use version control! writePSTypes :: TypeBridge -> FilePath -> [SumType] -> IO ()@@ -75,11 +84,12 @@ where fixedT= t { typeParameters = map fixTypeParameters (typeParameters t)} -{--|- -- Optimistically and recursively translate types: If the passed TypeBridge returns Nothing,- -- then the original TypeInfo is returned with the typePackage field cleared.- -- You don't need to call this function directly, just use bridgeSumType with your TypeBridge---}+-- | Translate types optimistically: If the passed 'TypeBridge' returns 'Nothing',+-- then the original 'TypeInfo' is returned with the 'typePackage' field cleared.+--+-- This function also recurses into all 'typeParameters' of the passed 'TypeInfo'.+--+-- You typically don't need to call this function directly, just use 'bridgeSumType' with your 'TypeBridge'. doBridge :: TypeBridge -> TypeInfo -> TypeInfo doBridge br info = let translated = info { typePackage = "" }