diff --git a/README.md b/README.md index 2b7dabad..d0f6bf28 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ There are three PureScript libraries which can interface with Aeson through Pure Enable this on the Haskell side with `Language.PureScript.Bridge.SumType.jsonHelpers`. -* see `./test/RoundTripJsonHelpers` for example + +* this library is demonstrated by the `example`; see `./example/readme.md`. +* see `./test/RoundTripJsonHelpers` for an additional example * sample Dhall config (for [spago-legacy](https://github.com/purescript/spago-legacy)): ``` , json-helpers = @@ -55,18 +57,16 @@ Enable this on the Haskell side with `Language.PureScript.Bridge.SumType.jsonHel , version = "486db9ee62882baa42cca24f556848c5f6bec565" } ``` - #### [`purescript-argonaut-aeson-generic >=0.4.1`](https://pursuit.purescript.org/packages/purescript-argonaut-aeson-generic/0.4.1) ([GitHub](https://github.com/coot/purescript-argonaut-aeson-generic)) Enable this on the Haskell side with `Language.PureScript.Bridge.SumType.argonautAesonGeneric`. -This library is demonstrated by the `example`; see `./example/readme.md`. - **TODO**: [resolve incompatibility between Argonaut and Aeson](https://github.com/purescript-contrib/purescript-argonaut-codecs/issues/115) **Additional requirement**: [`peterbecich/purescript-argonaut-codecs`](https://github.com/peterbecich/purescript-argonaut-codecs.git) * commit `04abb3eb24a4deafe125be0eb23e2786c642e66b` -* see `./test/RoundTripArgonautAesonGeneric` for example +* this library is demonstrated by the `example`; see `./example/readme.md`. +* see `./test/RoundTripArgonautAesonGeneric` for additional example * note that some types have been disabled from the `RoundTripArgonautAesonGeneric` test * `RoundTripJsonHelpers` tests more types * the types tested can be expanded when the incompatibility issue is resolved diff --git a/example/app/GeneratePurescript.hs b/example/app/GeneratePurescript.hs index f1f1c817..a4e7e5a3 100644 --- a/example/app/GeneratePurescript.hs +++ b/example/app/GeneratePurescript.hs @@ -4,10 +4,21 @@ import Control.Lens import Data.Text (pack) import Language.PureScript.Bridge +import ArgonautTypes +import JsonHelpersTypes import qualified MyLib -import Types +import Types (myBridge) -- https://discourse.purescript.org/t/latest-and-greatest-haskell-purescript-serialization/1640/6 main :: IO () main = do - writePSTypesWith "src" (buildBridge myBridge) myTypes + writePSTypesWithNamespace + (Just . PackageName $ pack "Argonaut") + "src" + (buildBridge myBridge) + myArgonautTypes + writePSTypesWithNamespace + (Just . PackageName $ pack "JsonHelpers") + "src" + (buildBridge myBridge) + myJsonHelpersTypes diff --git a/example/app/Main.hs b/example/app/Main.hs index ec75a1b1..e7270986 100644 --- a/example/app/Main.hs +++ b/example/app/Main.hs @@ -7,6 +7,4 @@ import qualified MyLib (main) import Types main :: IO () -main = do - writePSTypesWith "src" (buildBridge myBridge) myTypes - MyLib.main +main = MyLib.main diff --git a/example/example.cabal b/example/example.cabal index 18ce0ec7..7654fa47 100644 --- a/example/example.cabal +++ b/example/example.cabal @@ -9,7 +9,7 @@ build-type: Simple extra-source-files: CHANGELOG.md library - exposed-modules: MyLib, Types + exposed-modules: MyLib, Types, ArgonautTypes, JsonHelpersTypes hs-source-dirs: src build-depends: base >=4.8 && <5 , aeson >= 1.5.5.0 diff --git a/example/readme.md b/example/readme.md index 5c426845..a9d787f6 100644 --- a/example/readme.md +++ b/example/readme.md @@ -1,11 +1,18 @@ # PureScript Bridge example -This project demonstrates the libraries PureScript Bridge and [`purescript-argonaut-aeson-generic`](https://pursuit.purescript.org/packages/purescript-argonaut-aeson-generic) ([GitHub](https://github.com/coot/purescript-argonaut-aeson-generic)) - -It does not use [`input-output-hk/purescript-bridge-json-helpers`](https://github.com/input-output-hk/purescript-bridge-json-helpers.git). -To demonstrate this library in the example, more work is needed in `Main.purs`. - -The Haskell type `Foo`, in `src/Types.hs`, is generated for PureScript by PureScript Bridge. Some of values in `Foo` are randomly generated every time the page is loaded. `purescript-argonaut-aeson-generic` is used to decode and encode this payload, client-side. The client modifies some of the payload's values and sends it back to the server. +This project demonstrates: +- PureScript Bridge +- [`purescript-argonaut-aeson-generic`](https://pursuit.purescript.org/packages/purescript-argonaut-aeson-generic) ([GitHub](https://github.com/coot/purescript-argonaut-aeson-generic)) +- [`input-output-hk/purescript-bridge-json-helpers`](https://github.com/input-output-hk/purescript-bridge-json-helpers.git) + +The Haskell type `Foo`, in `src/Types.hs`, is generated for PureScript by PureScript Bridge. Some of values in `Foo` are randomly generated every time the page is loaded. + +On page load, the client: +- requests a `Foo` from the server +- decodes this value using `purescript-argonaut-aeson-generic` +- modifies some of the values +- encodes this with `purescript-argonaut-aeson-generic`, and sends it back to the server +- repeats these steps, encoding and decoding instead with `json-helpers` # Dependencies ## Nix diff --git a/example/spago.dhall b/example/spago.dhall index cab1af2e..1e45e169 100644 --- a/example/spago.dhall +++ b/example/spago.dhall @@ -11,6 +11,8 @@ , "control" , "effect" , "either" + , "tuples" + , "json-helpers" , "foldable-traversable" , "foreign-generic" , "foreign-object" diff --git a/example/src/Types.purs b/example/src/Argonaut/Types.purs similarity index 99% rename from example/src/Types.purs rename to example/src/Argonaut/Types.purs index 72032c06..fa6134b7 100644 --- a/example/src/Types.purs +++ b/example/src/Argonaut/Types.purs @@ -1,5 +1,5 @@ -- File auto generated by purescript-bridge! -- -module Types where +module Argonaut.Types where import Prelude @@ -26,17 +26,17 @@ import Type.Proxy (Proxy(Proxy)) newtype Baz = Baz { _bazMessage :: String } - - -instance Show Baz where - show a = genericShow a - instance EncodeJson Baz where encodeJson = defer \_ -> genericEncodeAeson Argonaut.defaultOptions instance DecodeJson Baz where decodeJson = defer \_ -> genericDecodeAeson Argonaut.defaultOptions + + +instance Show Baz where + show a = genericShow a + derive instance Generic Baz _ derive instance Newtype Baz _ @@ -62,17 +62,17 @@ newtype Foo = Foo , _fooTestData :: TestData } - - -instance Show Foo where - show a = genericShow a - instance EncodeJson Foo where encodeJson = defer \_ -> genericEncodeAeson Argonaut.defaultOptions instance DecodeJson Foo where decodeJson = defer \_ -> genericDecodeAeson Argonaut.defaultOptions + + +instance Show Foo where + show a = genericShow a + derive instance Generic Foo _ derive instance Newtype Foo _ @@ -110,17 +110,17 @@ fooTestData = _Newtype <<< prop (Proxy :: _"_fooTestData") newtype Bar a = Bar a - - -instance (Show a) => Show (Bar a) where - show a = genericShow a - instance (EncodeJson a) => EncodeJson (Bar a) where encodeJson = defer \_ -> genericEncodeAeson Argonaut.defaultOptions instance (DecodeJson a, DecodeJsonField a) => DecodeJson (Bar a) where decodeJson = defer \_ -> genericDecodeAeson Argonaut.defaultOptions + + +instance (Show a) => Show (Bar a) where + show a = genericShow a + derive instance Generic (Bar a) _ derive instance Newtype (Bar a) _ @@ -138,17 +138,17 @@ data TestSum | Int Int | Number Number - - -instance Show TestSum where - show a = genericShow a - instance EncodeJson TestSum where encodeJson = defer \_ -> genericEncodeAeson Argonaut.defaultOptions instance DecodeJson TestSum where decodeJson = defer \_ -> genericDecodeAeson Argonaut.defaultOptions + + +instance Show TestSum where + show a = genericShow a + derive instance Generic TestSum _ -------------------------------------------------------------------------------- @@ -179,17 +179,17 @@ data TestData = TMaybe (Maybe TestSum) | TEither String - - -instance Show TestData where - show a = genericShow a - instance EncodeJson TestData where encodeJson = defer \_ -> genericEncodeAeson Argonaut.defaultOptions instance DecodeJson TestData where decodeJson = defer \_ -> genericDecodeAeson Argonaut.defaultOptions + + +instance Show TestData where + show a = genericShow a + derive instance Generic TestData _ -------------------------------------------------------------------------------- diff --git a/example/src/ArgonautTypes.hs b/example/src/ArgonautTypes.hs new file mode 100644 index 00000000..1bbe1747 --- /dev/null +++ b/example/src/ArgonautTypes.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE TypeApplications #-} + +module ArgonautTypes where + +import Language.PureScript.Bridge (Language (Haskell), + argonautAesonGeneric, mkSumType) +import Language.PureScript.Bridge.SumType (SumType) +import Language.PureScript.Bridge.TypeParameters (A) +import Types + +myArgonautTypes :: [SumType 'Haskell] +myArgonautTypes = + [ argonautAesonGeneric . additionalInstances $ mkSumType @Baz + , argonautAesonGeneric . additionalInstances $ mkSumType @Foo + , argonautAesonGeneric . additionalInstances $ mkSumType @(Bar A) + , argonautAesonGeneric . additionalInstances $ mkSumType @TestSum + , argonautAesonGeneric . additionalInstances $ mkSumType @TestData + ] diff --git a/example/src/JsonHelpers/Types.purs b/example/src/JsonHelpers/Types.purs new file mode 100644 index 00000000..5c5d6b63 --- /dev/null +++ b/example/src/JsonHelpers/Types.purs @@ -0,0 +1,246 @@ +-- File auto generated by purescript-bridge! -- +module JsonHelpers.Types where + +import Prelude + +import Control.Lazy (defer) +import Data.Argonaut (encodeJson, jsonNull) +import Data.Argonaut.Aeson.Decode.Generic (genericDecodeAeson) +import Data.Argonaut.Aeson.Encode.Generic (genericEncodeAeson) +import Data.Argonaut.Aeson.Options (defaultOptions) as Argonaut +import Data.Argonaut.Decode.Aeson ((), (), ()) +import Data.Argonaut.Decode.Aeson as D +import Data.Argonaut.Decode.Class (class DecodeJson, class DecodeJsonField, decodeJson) +import Data.Argonaut.Decode.Class as Argonaut +import Data.Argonaut.Encode.Aeson ((>$<), (>/\<)) +import Data.Argonaut.Encode.Aeson as E +import Data.Argonaut.Encode.Class (class EncodeJson, encodeJson) +import Data.Argonaut.Encode.Class as Argonaut +import Data.Either (Either) +import Data.Generic.Rep (class Generic) +import Data.Lens (Iso', Lens', Prism', iso, lens, prism') +import Data.Lens.Iso.Newtype (_Newtype) +import Data.Lens.Record (prop) +import Data.Map +import Data.Map as Map +import Data.Maybe (Maybe(..)) +import Data.Newtype (class Newtype, unwrap) +import Data.Show.Generic (genericShow) +import Data.Tuple.Nested ((/\)) +import Foreign.Object (Object) +import Type.Proxy (Proxy(Proxy)) + +newtype Baz = Baz { _bazMessage :: String } + +instance EncodeJson Baz where + encodeJson = defer \_ -> E.encode $ unwrap >$< (E.record + { _bazMessage: E.value :: _ String }) + +instance DecodeJson Baz where + decodeJson = defer \_ -> D.decode $ (Baz <$> D.record "Baz" { _bazMessage: D.value :: _ String }) + + + +instance Show Baz where + show a = genericShow a + +derive instance Generic Baz _ + +derive instance Newtype Baz _ + +-------------------------------------------------------------------------------- + +_Baz :: Iso' Baz {_bazMessage :: String} +_Baz = _Newtype + +bazMessage :: Lens' Baz String +bazMessage = _Newtype <<< prop (Proxy :: _"_bazMessage") + +-------------------------------------------------------------------------------- + +newtype Foo = Foo + { _fooMessage :: String + , _fooE :: Either String Int + , _fooNumber :: Int + , _fooList :: Array Int + , _fooMap :: Object Int + , _fooBaz :: Baz + , _fooTestSum :: TestSum + , _fooTestData :: TestData + } + +instance EncodeJson Foo where + encodeJson = defer \_ -> E.encode $ unwrap >$< (E.record + { _fooMessage: E.value :: _ String + , _fooE: (E.either E.value E.value) :: _ (Either String Int) + , _fooNumber: E.value :: _ Int + , _fooList: E.value :: _ (Array Int) + , _fooMap: E.value :: _ (Object Int) + , _fooBaz: E.value :: _ Baz + , _fooTestSum: E.value :: _ TestSum + , _fooTestData: E.value :: _ TestData + }) + +instance DecodeJson Foo where + decodeJson = defer \_ -> D.decode $ (Foo <$> D.record "Foo" + { _fooMessage: D.value :: _ String + , _fooE: (D.either D.value D.value) :: _ (Either String Int) + , _fooNumber: D.value :: _ Int + , _fooList: D.value :: _ (Array Int) + , _fooMap: D.value :: _ (Object Int) + , _fooBaz: D.value :: _ Baz + , _fooTestSum: D.value :: _ TestSum + , _fooTestData: D.value :: _ TestData + }) + + + +instance Show Foo where + show a = genericShow a + +derive instance Generic Foo _ + +derive instance Newtype Foo _ + +-------------------------------------------------------------------------------- + +_Foo :: Iso' Foo {_fooMessage :: String, _fooE :: Either String Int, _fooNumber :: Int, _fooList :: Array Int, _fooMap :: Object Int, _fooBaz :: Baz, _fooTestSum :: TestSum, _fooTestData :: TestData} +_Foo = _Newtype + +fooMessage :: Lens' Foo String +fooMessage = _Newtype <<< prop (Proxy :: _"_fooMessage") + +fooE :: Lens' Foo (Either String Int) +fooE = _Newtype <<< prop (Proxy :: _"_fooE") + +fooNumber :: Lens' Foo Int +fooNumber = _Newtype <<< prop (Proxy :: _"_fooNumber") + +fooList :: Lens' Foo (Array Int) +fooList = _Newtype <<< prop (Proxy :: _"_fooList") + +fooMap :: Lens' Foo (Object Int) +fooMap = _Newtype <<< prop (Proxy :: _"_fooMap") + +fooBaz :: Lens' Foo Baz +fooBaz = _Newtype <<< prop (Proxy :: _"_fooBaz") + +fooTestSum :: Lens' Foo TestSum +fooTestSum = _Newtype <<< prop (Proxy :: _"_fooTestSum") + +fooTestData :: Lens' Foo TestData +fooTestData = _Newtype <<< prop (Proxy :: _"_fooTestData") + +-------------------------------------------------------------------------------- + +newtype Bar a = Bar a + +instance (EncodeJson a) => EncodeJson (Bar a) where + encodeJson = defer \_ -> E.encode $ unwrap >$< E.value + +instance (DecodeJson a, DecodeJsonField a) => DecodeJson (Bar a) where + decodeJson = defer \_ -> D.decode $ (Bar <$> D.value) + + + +instance (Show a) => Show (Bar a) where + show a = genericShow a + +derive instance Generic (Bar a) _ + +derive instance Newtype (Bar a) _ + +-------------------------------------------------------------------------------- + +_Bar :: forall a. Iso' (Bar a) a +_Bar = _Newtype + +-------------------------------------------------------------------------------- + +data TestSum + = Nullary + | Bool Boolean + | Int Int + | Number Number + +instance EncodeJson TestSum where + encodeJson = defer \_ -> case _ of + Nullary -> encodeJson { tag: "Nullary", contents: jsonNull } + Bool a -> E.encodeTagged "Bool" a E.value + Int a -> E.encodeTagged "Int" a E.value + Number a -> E.encodeTagged "Number" a E.value + +instance DecodeJson TestSum where + decodeJson = defer \_ -> D.decode + $ D.sumType "TestSum" $ Map.fromFoldable + [ "Nullary" /\ pure Nullary + , "Bool" /\ D.content (Bool <$> D.value) + , "Int" /\ D.content (Int <$> D.value) + , "Number" /\ D.content (Number <$> D.value) + ] + + + +instance Show TestSum where + show a = genericShow a + +derive instance Generic TestSum _ + +-------------------------------------------------------------------------------- + +_Nullary :: Prism' TestSum Unit +_Nullary = prism' (const Nullary) case _ of + Nullary -> Just unit + _ -> Nothing + +_Bool :: Prism' TestSum Boolean +_Bool = prism' Bool case _ of + (Bool a) -> Just a + _ -> Nothing + +_Int :: Prism' TestSum Int +_Int = prism' Int case _ of + (Int a) -> Just a + _ -> Nothing + +_Number :: Prism' TestSum Number +_Number = prism' Number case _ of + (Number a) -> Just a + _ -> Nothing + +-------------------------------------------------------------------------------- + +data TestData + = TMaybe (Maybe TestSum) + | TEither String + +instance EncodeJson TestData where + encodeJson = defer \_ -> case _ of + TMaybe a -> E.encodeTagged "TMaybe" a (E.maybe E.value) + TEither a -> E.encodeTagged "TEither" a E.value + +instance DecodeJson TestData where + decodeJson = defer \_ -> D.decode + $ D.sumType "TestData" $ Map.fromFoldable + [ "TMaybe" /\ D.content (TMaybe <$> (D.maybe D.value)) + , "TEither" /\ D.content (TEither <$> D.value) + ] + + + +instance Show TestData where + show a = genericShow a + +derive instance Generic TestData _ + +-------------------------------------------------------------------------------- + +_TMaybe :: Prism' TestData (Maybe TestSum) +_TMaybe = prism' TMaybe case _ of + (TMaybe a) -> Just a + _ -> Nothing + +_TEither :: Prism' TestData String +_TEither = prism' TEither case _ of + (TEither a) -> Just a + _ -> Nothing diff --git a/example/src/JsonHelpersTypes.hs b/example/src/JsonHelpersTypes.hs new file mode 100644 index 00000000..9bcff2a5 --- /dev/null +++ b/example/src/JsonHelpersTypes.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE TypeApplications #-} + +module JsonHelpersTypes where + +import Language.PureScript.Bridge (Language (Haskell), jsonHelpers, + mkSumType) +import Language.PureScript.Bridge.SumType (SumType) +import Language.PureScript.Bridge.TypeParameters (A) +import Types + +myJsonHelpersTypes :: [SumType 'Haskell] +myJsonHelpersTypes = + [ jsonHelpers . additionalInstances $ mkSumType @Baz + , jsonHelpers . additionalInstances $ mkSumType @Foo + , jsonHelpers . additionalInstances $ mkSumType @(Bar A) + , jsonHelpers . additionalInstances $ mkSumType @TestSum + , jsonHelpers . additionalInstances $ mkSumType @TestData + ] diff --git a/example/src/Main.purs b/example/src/Main.purs index 7d87f06f..b8237719 100644 --- a/example/src/Main.purs +++ b/example/src/Main.purs @@ -7,6 +7,8 @@ import Affjax.ResponseFormat (json) import Affjax.Web (get, post_) import Data.Argonaut.Aeson.Decode.Generic (genericDecodeAeson) import Data.Argonaut.Aeson.Encode.Generic (genericEncodeAeson) +import Data.Argonaut.Decode (JsonDecodeError, decodeJson, parseJson, printJsonDecodeError) +import Data.Argonaut.Encode (encodeJson) import Data.Argonaut.Aeson.Options (defaultOptions) import Data.Argonaut.Decode.Error (JsonDecodeError, printJsonDecodeError) import Data.Either (Either(Left, Right)) @@ -20,7 +22,7 @@ import Effect.Class (liftEffect) import Effect.Console (log) import Foreign.Object (empty) import Foreign.Object as Object -import Types (Baz(Baz), Foo(Foo), TestData(..), TestSum(..), fooMessage, fooNumber, fooList, fooMap, fooTestSum, fooTestData) +import Argonaut.Types (Baz(Baz), Foo(Foo), TestData(..), TestSum(..), fooMessage, fooNumber, fooList, fooMap, fooTestSum, fooTestData) testFoo = Foo { _fooMessage: "foo" @@ -35,31 +37,58 @@ testFoo = Foo main :: Effect Unit main = log "Hello, PureScript!" *> launchAff_ do - -- request a Foo + -- request a Foo; decode with ArgonautAesonGeneric fooResponse <- get json "/foo" for_ fooResponse \fooPayload -> do - -- Note this example is only for argonaut-aeson-generics. - -- This can be replaced with json-helpers here. + liftEffect $ log $ "Decode and Encode with ArgonautAesoGeneric" let - efoo :: Either JsonDecodeError Foo - efoo = genericDecodeAeson defaultOptions fooPayload.body - case efoo of + eArgonautDecodedFoo :: Either JsonDecodeError Foo + eArgonautDecodedFoo = genericDecodeAeson defaultOptions fooPayload.body + case eArgonautDecodedFoo of Left e -> liftEffect $ log $ "Error decoding Foo: " <> printJsonDecodeError e Right _ -> pure unit - for_ efoo \foo -> do + for_ eArgonautDecodedFoo \argonautDecodedFoo -> do liftEffect do - log $ "Foo message: " <> (view fooMessage foo) - log $ "Foo number: " <> (show $ view fooNumber foo) - log $ "Foo list length: " <> (show (length $ view fooList foo :: Int)) - log $ "Foo map size: " <> (show (Object.size $ view fooMap foo :: Int)) - log $ "Foo test sum: " <> show (view fooTestSum foo) - log $ "Foo test data: " <> show (view fooTestData foo) + log $ "Foo message: " <> (view fooMessage argonautDecodedFoo) + log $ "Foo number: " <> (show $ view fooNumber argonautDecodedFoo) + log $ "Foo list length: " <> (show (length $ view fooList argonautDecodedFoo :: Int)) + log $ "Foo map size: " <> (show (Object.size $ view fooMap argonautDecodedFoo :: Int)) + log $ "Foo test sum: " <> show (view fooTestSum argonautDecodedFoo) + log $ "Foo test data: " <> show (view fooTestData argonautDecodedFoo) let -- modify the Foo received and send it back - foo' = set fooMessage "Hola" + modifiedFoo = set fooMessage "Hello from ArgonautAesonGeneric" $ over fooNumber (_+1) $ over fooList (\l -> l <> l) $ over fooMap (\o -> Object.insert "abc" 123 o) - $ foo - response = Just $ RequestBody.json $ genericEncodeAeson defaultOptions foo' + $ argonautDecodedFoo + response = Just $ RequestBody.json $ genericEncodeAeson defaultOptions modifiedFoo + post_ "/foo" response + + -- request a Foo; decode with JsonHelpers + fooResponse <- get json "/foo" + for_ fooResponse \fooPayload -> do + liftEffect $ log $ "Decode and Encode with JsonHelpers" + let + eJsonHelpersDecodedFoo :: Either JsonDecodeError Foo + eJsonHelpersDecodedFoo = decodeJson fooPayload.body + case eJsonHelpersDecodedFoo of + Left e -> liftEffect $ log $ "Error decoding Foo: " <> printJsonDecodeError e + Right _ -> pure unit + for_ eJsonHelpersDecodedFoo \jsonHelpersFoo -> do + liftEffect do + log $ "Foo message: " <> (view fooMessage jsonHelpersFoo) + log $ "Foo number: " <> (show $ view fooNumber jsonHelpersFoo) + log $ "Foo list length: " <> (show (length $ view fooList jsonHelpersFoo :: Int)) + log $ "Foo map size: " <> (show (Object.size $ view fooMap jsonHelpersFoo :: Int)) + log $ "Foo test sum: " <> show (view fooTestSum jsonHelpersFoo) + log $ "Foo test data: " <> show (view fooTestData jsonHelpersFoo) + let + -- modify the Foo received and send it back + modifiedFoo = set fooMessage "Hello from JsonHelpers" + $ over fooNumber (_+1) + $ over fooList (\l -> l <> l) + $ over fooMap (\o -> Object.insert "abc" 123 o) + $ jsonHelpersFoo + response = Just $ RequestBody.json $ encodeJson modifiedFoo post_ "/foo" response diff --git a/example/src/Types.hs b/example/src/Types.hs index bee8ef81..0a31f57b 100644 --- a/example/src/Types.hs +++ b/example/src/Types.hs @@ -21,8 +21,8 @@ import Data.Typeable (Typeable) import GHC.Generics (Generic) import Language.PureScript.Bridge (BridgePart, Language (Haskell), argonautAesonGeneric, - defaultBridge, genericShow, lenses, - mkSumType) + defaultBridge, genericShow, + jsonHelpers, lenses, mkSumType) import Language.PureScript.Bridge.PSTypes () import Language.PureScript.Bridge.SumType (SumType) import Language.PureScript.Bridge.TypeParameters (A) @@ -112,21 +112,7 @@ data Bar a = Bar a makeLenses ''Bar +additionalInstances = lenses . genericShow + myBridge :: BridgePart myBridge = defaultBridge - -additionalInstances = lenses - . genericShow - . argonautAesonGeneric - -- . jsonHelpers - -- To use json-helpers with the example, more work is needed - -- in Main.purs - -myTypes :: [SumType 'Haskell] -myTypes = - [ additionalInstances $ mkSumType @Baz - , additionalInstances $ mkSumType @Foo - , additionalInstances $ mkSumType @(Bar A) - , additionalInstances $ mkSumType @TestSum - , additionalInstances $ mkSumType @TestData - ]