diff --git a/demo-client/Demo/Client/API/Core/Greeter.hs b/demo-client/Demo/Client/API/Core/Greeter.hs index 6747ce41..8448324c 100644 --- a/demo-client/Demo/Client/API/Core/Greeter.hs +++ b/demo-client/Demo/Client/API/Core/Greeter.hs @@ -11,8 +11,9 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr -import Demo.Common.API -import Demo.Common.Logging +import Demo.Client.Util.Logging + +import Proto.API.Helloworld {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs b/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs index bb5a1708..9351f02e 100644 --- a/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs +++ b/demo-client/Demo/Client/API/Core/NoFinal/Greeter.hs @@ -6,7 +6,7 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Demo.Common.API +import Proto.API.Helloworld {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/Core/RouteGuide.hs b/demo-client/Demo/Client/API/Core/RouteGuide.hs index 9819dde1..1ba01ec9 100644 --- a/demo-client/Demo/Client/API/Core/RouteGuide.hs +++ b/demo-client/Demo/Client/API/Core/RouteGuide.hs @@ -6,8 +6,9 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Demo.Common.API -import Demo.Common.Logging +import Demo.Client.Util.Logging + +import Proto.API.RouteGuide {------------------------------------------------------------------------------- RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs index 3f368469..51479639 100644 --- a/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/Conduit/RouteGuide.hs @@ -14,8 +14,9 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr -import Demo.Common.API -import Demo.Common.Logging +import Demo.Client.Util.Logging + +import Proto.API.RouteGuide {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs index 11d8e34d..ceb07513 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Greeter.hs @@ -8,8 +8,9 @@ import Network.GRPC.Client.StreamType.IO import Network.GRPC.Common.NextElem qualified as NextElem import Network.GRPC.Common.Protobuf -import Demo.Common.API -import Demo.Common.Logging +import Demo.Client.Util.Logging + +import Proto.API.Helloworld {------------------------------------------------------------------------------- helloworld.Greeter diff --git a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs index 3f49b4f1..b1ffe930 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/Ping.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/Ping.hs @@ -1,13 +1,12 @@ module Demo.Client.API.StreamType.IO.Ping (ping) where -import Data.ByteString.Lazy.Char8 qualified as Lazy - import Network.GRPC.Client import Network.GRPC.Client.StreamType.IO +import Network.GRPC.Common.Protobuf -import Demo.Common.API +import Proto.API.Ping -ping :: Connection -> Lazy.ByteString -> IO () +ping :: Connection -> Proto PingMessage -> IO () ping conn msg = do pong <- nonStreaming conn (rpc @Ping) msg - Lazy.putStrLn pong + print pong diff --git a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs index 37e28f18..1974db34 100644 --- a/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs +++ b/demo-client/Demo/Client/API/StreamType/IO/RouteGuide.hs @@ -15,8 +15,9 @@ import Network.GRPC.Common.Protobuf import Demo.Client.Util.DelayOr (DelayOr) import Demo.Client.Util.DelayOr qualified as DelayOr -import Demo.Common.API -import Demo.Common.Logging +import Demo.Client.Util.Logging + +import Proto.API.RouteGuide {------------------------------------------------------------------------------- routeguide.RouteGuide diff --git a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs index ea979bec..1955d0f1 100644 --- a/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs +++ b/demo-client/Demo/Client/API/StreamType/MonadStack/Greeter.hs @@ -13,8 +13,9 @@ import Network.GRPC.Client.StreamType.CanCallRPC import Network.GRPC.Common.NextElem qualified as NextElem import Network.GRPC.Common.Protobuf -import Demo.Common.API -import Demo.Common.Logging qualified as Logging +import Demo.Client.Util.Logging qualified as Logging + +import Proto.API.Helloworld {------------------------------------------------------------------------------- Example custom monad diff --git a/demo-client/Demo/Client/Cmdline.hs b/demo-client/Demo/Client/Cmdline.hs index ec0832a1..74ab23fb 100644 --- a/demo-client/Demo/Client/Cmdline.hs +++ b/demo-client/Demo/Client/Cmdline.hs @@ -16,7 +16,6 @@ module Demo.Client.Cmdline ( import Prelude -import Data.ByteString.Lazy qualified as Lazy (ByteString) import Data.Foldable (asum) import Data.Int import Data.Kind @@ -35,7 +34,11 @@ import Network.GRPC.Common.Protobuf import Paths_grapesy import Demo.Client.Util.DelayOr (DelayOr(..)) -import Demo.Common.API + +import Proto.API.Helloworld +import Proto.API.Ping +import Proto.API.RouteGuide +import Text.Read (readMaybe) {------------------------------------------------------------------------------- Definition @@ -75,7 +78,7 @@ data SMethod :: Type -> Type where SRecordRoute :: [DelayOr (Proto Point)] -> SMethod RecordRoute SRouteChat :: [DelayOr (Proto RouteNote)] -> SMethod RouteChat - SPing :: Lazy.ByteString -> SMethod Ping + SPing :: Proto PingMessage -> SMethod Ping deriving stock instance Show (SMethod rpc) @@ -249,7 +252,7 @@ parseSomeMethod = Opt.subparser $ mconcat [ Opt.many (parseDelayOr $ parseRouteNote) , sub "ping" "Ping.ping" $ SomeMethod . SPing <$> - Opt.argument Opt.str (Opt.metavar "MSG") + Opt.argument parsePingMessage (Opt.metavar "NUM") ] {------------------------------------------------------------------------------- @@ -324,6 +327,15 @@ parseRouteNote = & #location .~ location & #message .~ message +parsePingMessage :: Opt.ReadM (Proto PingMessage) +parsePingMessage = Opt.str >>= aux + where + aux :: String -> Opt.ReadM (Proto PingMessage) + aux str = + case readMaybe str of + Nothing -> fail $ "Could not parse ping ID " ++ show str + Just pid -> return $ defMessage & #id .~ pid + {------------------------------------------------------------------------------- Internal auxiliary -------------------------------------------------------------------------------} diff --git a/demo-common/Demo/Common/Logging.hs b/demo-client/Demo/Client/Util/Logging.hs similarity index 93% rename from demo-common/Demo/Common/Logging.hs rename to demo-client/Demo/Client/Util/Logging.hs index 7e329aff..8b1939b8 100644 --- a/demo-common/Demo/Common/Logging.hs +++ b/demo-client/Demo/Client/Util/Logging.hs @@ -1,4 +1,4 @@ -module Demo.Common.Logging ( +module Demo.Client.Util.Logging ( threadSafeTracer , logMsg ) where diff --git a/demo-server/Demo/Server/Service/Greeter.hs b/demo-server/Demo/Server/Service/Greeter.hs index 43fa4851..48098b22 100644 --- a/demo-server/Demo/Server/Service/Greeter.hs +++ b/demo-server/Demo/Server/Service/Greeter.hs @@ -13,7 +13,7 @@ import Network.GRPC.Server import Network.GRPC.Server.Protobuf import Network.GRPC.Server.StreamType -import Demo.Common.API +import Proto.API.Helloworld {------------------------------------------------------------------------------- Top-level diff --git a/demo-server/Demo/Server/Service/Ping.hs b/demo-server/Demo/Server/Service/Ping.hs index 71503aa4..212c99e2 100644 --- a/demo-server/Demo/Server/Service/Ping.hs +++ b/demo-server/Demo/Server/Service/Ping.hs @@ -1,16 +1,17 @@ -module Demo.Server.Service.Ping (handlers) where +{-# LANGUAGE OverloadedLabels #-} -import Data.ByteString.Lazy qualified as Lazy (ByteString) +module Demo.Server.Service.Ping (handlers) where +import Network.GRPC.Common.Protobuf import Network.GRPC.Server.StreamType -import Demo.Common.API +import Proto.API.Ping handlers :: Methods IO '[Ping] handlers = Method (mkNonStreaming handlePing) $ NoMoreMethods -handlePing :: Lazy.ByteString -> IO Lazy.ByteString -handlePing = return +handlePing :: Proto PingMessage -> IO (Proto PongMessage) +handlePing ping = return $ defMessage & #id .~ (ping ^. #id) diff --git a/demo-server/Demo/Server/Service/RouteGuide.hs b/demo-server/Demo/Server/Service/RouteGuide.hs index 29489325..03cc6866 100644 --- a/demo-server/Demo/Server/Service/RouteGuide.hs +++ b/demo-server/Demo/Server/Service/RouteGuide.hs @@ -8,6 +8,7 @@ module Demo.Server.Service.RouteGuide ( ) where import Control.Monad.IO.Class +import Control.Monad.Trans.Reader import Control.Monad.Trans.State (StateT, evalStateT) import Control.Monad.Trans.State qualified as State import Data.Map qualified as Map @@ -21,10 +22,10 @@ import Network.GRPC.Server import Network.GRPC.Server.Protobuf import Network.GRPC.Server.StreamType -import Demo.Common.API import Demo.Server.Aux.RouteGuide import Demo.Server.Cmdline -import Control.Monad.Trans.Reader + +import Proto.API.RouteGuide {------------------------------------------------------------------------------- Custom handler monad diff --git a/demo-server/Main.hs b/demo-server/Main.hs index 95d246cf..4eced14d 100644 --- a/demo-server/Main.hs +++ b/demo-server/Main.hs @@ -12,14 +12,16 @@ import Network.GRPC.Server.Protobuf import Network.GRPC.Server.Run import Network.GRPC.Server.StreamType +import Paths_grapesy + import Demo.Server.Cmdline import Demo.Server.Service.Greeter qualified as Greeter import Demo.Server.Service.Ping qualified as Ping import Demo.Server.Service.RouteGuide qualified as RouteGuide -import Demo.Common.API - -import Paths_grapesy +import Proto.API.Helloworld +import Proto.API.Ping +import Proto.API.RouteGuide {------------------------------------------------------------------------------- All services diff --git a/grapesy.cabal b/grapesy.cabal index ed18f34e..6a11227b 100644 --- a/grapesy.cabal +++ b/grapesy.cabal @@ -177,7 +177,6 @@ library Paths_grapesy Proto.OrcaLoadReport - Proto.OrcaLoadReport_Fields Control.Monad.XIO autogen-modules: @@ -316,8 +315,11 @@ test-suite test-grapesy Paths_grapesy + Proto.API.Interop + Proto.API.Ping Proto.Empty Proto.Messages + Proto.Ping Proto.Test autogen-modules: Paths_grapesy @@ -359,7 +361,6 @@ executable demo-client , common-executable-flags hs-source-dirs: demo-client - demo-common proto main-is: Main.hs @@ -374,16 +375,16 @@ executable demo-client Demo.Client.API.StreamType.MonadStack.Greeter Demo.Client.Cmdline Demo.Client.Util.DelayOr - - Demo.Common.API - Demo.Common.Logging + Demo.Client.Util.Logging Paths_grapesy + Proto.API.Helloworld + Proto.API.Ping + Proto.API.RouteGuide Proto.Helloworld - Proto.Helloworld_Fields + Proto.Ping Proto.RouteGuide - Proto.RouteGuide_Fields autogen-modules: Paths_grapesy build-depends: @@ -412,7 +413,6 @@ executable demo-server , common-executable-flags hs-source-dirs: demo-server - demo-common proto main-is: Main.hs @@ -423,13 +423,12 @@ executable demo-server Demo.Server.Service.Ping Demo.Server.Service.RouteGuide - Demo.Common.API - Demo.Common.Logging - + Proto.API.Helloworld + Proto.API.Ping + Proto.API.RouteGuide Proto.Helloworld - Proto.Helloworld_Fields + Proto.Ping Proto.RouteGuide - Proto.RouteGuide_Fields Paths_grapesy autogen-modules: @@ -442,7 +441,6 @@ executable demo-server , aeson >= 1.5 && < 2.3 , bytestring >= 0.10 && < 0.13 , containers >= 0.6 && < 0.8 - , contra-tracer >= 0.2 && < 0.3 , exceptions >= 0.10 && < 0.11 , network >= 3.1 && < 3.3 , optparse-applicative >= 0.16 && < 0.19 @@ -493,7 +491,6 @@ test-suite grapesy-interop main-is: Main.hs other-modules: - Interop.API Interop.Client Interop.Client.Common Interop.Client.Connect @@ -532,9 +529,11 @@ test-suite grapesy-interop Paths_grapesy - Proto.Ping + Proto.API.Interop + Proto.API.Ping Proto.Empty Proto.Messages + Proto.Ping Proto.Test autogen-modules: Paths_grapesy diff --git a/interop/Interop/Client/Common.hs b/interop/Interop/Client/Common.hs index 3e8da05c..a6b4d856 100644 --- a/interop/Interop/Client/Common.hs +++ b/interop/Interop/Client/Common.hs @@ -19,12 +19,14 @@ import Data.ByteString qualified as BS.Strict import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Common.Compression qualified as Compr +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Util.Exceptions import Interop.Util.Messages +import Proto.API.Interop + {------------------------------------------------------------------------------- Config -------------------------------------------------------------------------------} diff --git a/interop/Interop/Client/Ping.hs b/interop/Interop/Client/Ping.hs index 3739f607..110cbdac 100644 --- a/interop/Interop/Client/Ping.hs +++ b/interop/Interop/Client/Ping.hs @@ -10,12 +10,11 @@ import Network.GRPC.Client.StreamType.IO import Network.GRPC.Common import Network.GRPC.Common.Protobuf -import Proto.Ping - -import Interop.API import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Ping + ping :: Cmdline -> IO () ping cmdline = withConnection def (testServer cmdline) $ \conn -> diff --git a/interop/Interop/Client/TestCase/CancelAfterBegin.hs b/interop/Interop/Client/TestCase/CancelAfterBegin.hs index ba14513c..f65fb76a 100644 --- a/interop/Interop/Client/TestCase/CancelAfterBegin.hs +++ b/interop/Interop/Client/TestCase/CancelAfterBegin.hs @@ -3,11 +3,12 @@ module Interop.Client.TestCase.CancelAfterBegin (runTest) where import Network.GRPC.Client import Network.GRPC.Common -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | -- -- This is not really testing anything about the server, but rather about how diff --git a/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs b/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs index 9bde7695..3c138391 100644 --- a/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs +++ b/interop/Interop/Client/TestCase/CancelAfterFirstResponse.hs @@ -2,13 +2,15 @@ module Interop.Client.TestCase.CancelAfterFirstResponse (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions import Interop.Client.Common (mkStreamingOutputCallRequest) +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs b/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs index 2bbd9ed6..fec43731 100644 --- a/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs +++ b/interop/Interop/Client/TestCase/ClientCompressedStreaming.hs @@ -2,14 +2,16 @@ module Interop.Client.TestCase.ClientCompressedStreaming (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ClientCompressedUnary.hs b/interop/Interop/Client/TestCase/ClientCompressedUnary.hs index 92e10178..26b394bb 100644 --- a/interop/Interop/Client/TestCase/ClientCompressedUnary.hs +++ b/interop/Interop/Client/TestCase/ClientCompressedUnary.hs @@ -6,11 +6,12 @@ import Network.GRPC.Client import Network.GRPC.Common import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ClientStreaming.hs b/interop/Interop/Client/TestCase/ClientStreaming.hs index 6c50cb2f..64d536fe 100644 --- a/interop/Interop/Client/TestCase/ClientStreaming.hs +++ b/interop/Interop/Client/TestCase/ClientStreaming.hs @@ -2,13 +2,15 @@ module Interop.Client.TestCase.ClientStreaming (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions import Interop.Util.Messages +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/CustomMetadata.hs b/interop/Interop/Client/TestCase/CustomMetadata.hs index 745ec7d3..a567298f 100644 --- a/interop/Interop/Client/TestCase/CustomMetadata.hs +++ b/interop/Interop/Client/TestCase/CustomMetadata.hs @@ -7,13 +7,15 @@ import Data.ByteString qualified as Strict (ByteString) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | -- -- For both UnaryCall and FullDuplexCall, the reference server (at least some) diff --git a/interop/Interop/Client/TestCase/EmptyStream.hs b/interop/Interop/Client/TestCase/EmptyStream.hs index a0135810..00a054b0 100644 --- a/interop/Interop/Client/TestCase/EmptyStream.hs +++ b/interop/Interop/Client/TestCase/EmptyStream.hs @@ -5,10 +5,11 @@ import Control.Monad import Network.GRPC.Client import Network.GRPC.Common -import Interop.API import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/EmptyUnary.hs b/interop/Interop/Client/TestCase/EmptyUnary.hs index f430378e..724f48b1 100644 --- a/interop/Interop/Client/TestCase/EmptyUnary.hs +++ b/interop/Interop/Client/TestCase/EmptyUnary.hs @@ -4,14 +4,16 @@ import Data.Proxy import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Spec -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/LargeUnary.hs b/interop/Interop/Client/TestCase/LargeUnary.hs index ca39dceb..19f149cb 100644 --- a/interop/Interop/Client/TestCase/LargeUnary.hs +++ b/interop/Interop/Client/TestCase/LargeUnary.hs @@ -3,12 +3,14 @@ module Interop.Client.TestCase.LargeUnary (runTest) where import Network.GRPC.Client import Network.GRPC.Client.StreamType.IO import Network.GRPC.Common +import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/PingPong.hs b/interop/Interop/Client/TestCase/PingPong.hs index 28a709f4..4a4ce766 100644 --- a/interop/Interop/Client/TestCase/PingPong.hs +++ b/interop/Interop/Client/TestCase/PingPong.hs @@ -4,12 +4,14 @@ import Control.Monad import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs b/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs index 076f96d9..6e0f5512 100644 --- a/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs +++ b/interop/Interop/Client/TestCase/ServerCompressedStreaming.hs @@ -4,13 +4,14 @@ import Data.Maybe (isJust) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions -import Network.GRPC.Spec + +import Proto.API.Interop -- | runTest :: Cmdline -> IO () diff --git a/interop/Interop/Client/TestCase/ServerCompressedUnary.hs b/interop/Interop/Client/TestCase/ServerCompressedUnary.hs index 881f10de..0fee743e 100644 --- a/interop/Interop/Client/TestCase/ServerCompressedUnary.hs +++ b/interop/Interop/Client/TestCase/ServerCompressedUnary.hs @@ -4,16 +4,18 @@ import Data.Maybe (isJust) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Spec -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions import Interop.Util.Messages +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/ServerStreaming.hs b/interop/Interop/Client/TestCase/ServerStreaming.hs index 9b9d2b06..b37c6c3d 100644 --- a/interop/Interop/Client/TestCase/ServerStreaming.hs +++ b/interop/Interop/Client/TestCase/ServerStreaming.hs @@ -3,11 +3,12 @@ module Interop.Client.TestCase.ServerStreaming (runTest) where import Network.GRPC.Client import Network.GRPC.Common -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/SpecialStatusMessage.hs b/interop/Interop/Client/TestCase/SpecialStatusMessage.hs index 964a4806..c9e03824 100644 --- a/interop/Interop/Client/TestCase/SpecialStatusMessage.hs +++ b/interop/Interop/Client/TestCase/SpecialStatusMessage.hs @@ -6,13 +6,15 @@ import Data.Text (Text) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = do diff --git a/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs b/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs index ee91afa8..ae9e05e3 100644 --- a/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs +++ b/interop/Interop/Client/TestCase/StatusCodeAndMessage.hs @@ -6,13 +6,15 @@ import Data.Text (Text) import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Spec -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = do diff --git a/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs b/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs index 69944a83..772a8cc6 100644 --- a/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs +++ b/interop/Interop/Client/TestCase/TimeoutOnSleepingServer.hs @@ -2,13 +2,15 @@ module Interop.Client.TestCase.TimeoutOnSleepingServer (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf -import Interop.API import Interop.Client.Common import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/UnimplementedMethod.hs b/interop/Interop/Client/TestCase/UnimplementedMethod.hs index 6ae6b700..bb413ef8 100644 --- a/interop/Interop/Client/TestCase/UnimplementedMethod.hs +++ b/interop/Interop/Client/TestCase/UnimplementedMethod.hs @@ -2,13 +2,15 @@ module Interop.Client.TestCase.UnimplementedMethod (runTest) where import Network.GRPC.Client import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Client.StreamType.IO -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Client/TestCase/UnimplementedService.hs b/interop/Interop/Client/TestCase/UnimplementedService.hs index 20354bda..437f9920 100644 --- a/interop/Interop/Client/TestCase/UnimplementedService.hs +++ b/interop/Interop/Client/TestCase/UnimplementedService.hs @@ -5,11 +5,12 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Client.StreamType.IO -import Interop.API import Interop.Client.Connect import Interop.Cmdline import Interop.Util.Exceptions +import Proto.API.Interop + -- | runTest :: Cmdline -> IO () runTest cmdline = diff --git a/interop/Interop/Server.hs b/interop/Interop/Server.hs index 652655e7..f1f5a805 100644 --- a/interop/Interop/Server.hs +++ b/interop/Interop/Server.hs @@ -13,7 +13,6 @@ import Network.GRPC.Server.Protobuf import Network.GRPC.Server.Run import Network.GRPC.Server.StreamType -import Interop.API import Interop.Cmdline import Interop.Server.PingService.Ping qualified as Ping @@ -23,6 +22,9 @@ import Interop.Server.TestService.StreamingInputCall qualified as StreamingInpu import Interop.Server.TestService.StreamingOutputCall qualified as StreamingOutputCall import Interop.Server.TestService.UnaryCall qualified as UnaryCall +import Proto.API.Interop +import Proto.API.Ping + {------------------------------------------------------------------------------- Handlers diff --git a/interop/Interop/Server/Common.hs b/interop/Interop/Server/Common.hs index c1bfda02..aa89027e 100644 --- a/interop/Interop/Server/Common.hs +++ b/interop/Interop/Server/Common.hs @@ -10,12 +10,14 @@ module Interop.Server.Common ( import Control.Exception import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Util.Exceptions +import Proto.API.Interop + {------------------------------------------------------------------------------- Dealing with the test-suite's message types -------------------------------------------------------------------------------} diff --git a/interop/Interop/Server/TestService/EmptyCall.hs b/interop/Interop/Server/TestService/EmptyCall.hs index 0c275ef0..7b531a74 100644 --- a/interop/Interop/Server/TestService/EmptyCall.hs +++ b/interop/Interop/Server/TestService/EmptyCall.hs @@ -1,6 +1,8 @@ module Interop.Server.TestService.EmptyCall (handle) where -import Interop.API +import Network.GRPC.Common.Protobuf + +import Proto.API.Interop -- | Handle @TestService.EmptyCall@ -- diff --git a/interop/Interop/Server/TestService/FullDuplexCall.hs b/interop/Interop/Server/TestService/FullDuplexCall.hs index 8cc0ee09..0df59c78 100644 --- a/interop/Interop/Server/TestService/FullDuplexCall.hs +++ b/interop/Interop/Server/TestService/FullDuplexCall.hs @@ -1,12 +1,14 @@ module Interop.Server.TestService.FullDuplexCall (handle) where import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server -import Interop.API import Interop.Server.Common import Interop.Server.TestService.StreamingOutputCall qualified as StreamingOutputCall +import Proto.API.Interop + -- | Handle @TestService.FullDuplexCall@ -- -- diff --git a/interop/Interop/Server/TestService/StreamingInputCall.hs b/interop/Interop/Server/TestService/StreamingInputCall.hs index ffcae8ea..d501774a 100644 --- a/interop/Interop/Server/TestService/StreamingInputCall.hs +++ b/interop/Interop/Server/TestService/StreamingInputCall.hs @@ -5,12 +5,14 @@ module Interop.Server.TestService.StreamingInputCall (handle) where import Data.ByteString qualified as BS.Strict import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Server.Common +import Proto.API.Interop + -- | Handle @TestService.StreamingInputCall@ -- -- diff --git a/interop/Interop/Server/TestService/StreamingOutputCall.hs b/interop/Interop/Server/TestService/StreamingOutputCall.hs index 3d4e22ec..b468d9f2 100644 --- a/interop/Interop/Server/TestService/StreamingOutputCall.hs +++ b/interop/Interop/Server/TestService/StreamingOutputCall.hs @@ -7,12 +7,14 @@ import Control.Concurrent import Control.Monad import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Util.Messages +import Proto.API.Interop + -- | Handle @TestService.StreamingOutputCall@ -- -- diff --git a/interop/Interop/Server/TestService/UnaryCall.hs b/interop/Interop/Server/TestService/UnaryCall.hs index 39602d2c..4e7aff1e 100644 --- a/interop/Interop/Server/TestService/UnaryCall.hs +++ b/interop/Interop/Server/TestService/UnaryCall.hs @@ -3,14 +3,16 @@ module Interop.Server.TestService.UnaryCall (handle) where import Network.GRPC.Common +import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem import Network.GRPC.Server import Network.GRPC.Spec -import Interop.API import Interop.Server.Common import Interop.Util.Messages +import Proto.API.Interop + -- | Handle @TestService.UnaryCall@ -- -- This is not implemented using the Protobuf communication patterns because diff --git a/interop/Interop/Util/Messages.hs b/interop/Interop/Util/Messages.hs index f38152cc..f410e1a3 100644 --- a/interop/Interop/Util/Messages.hs +++ b/interop/Interop/Util/Messages.hs @@ -12,9 +12,12 @@ import Data.ByteString qualified as BS.Strict import Data.ByteString qualified as Strict (ByteString) import Data.ByteString.Char8 qualified as BS.Strict.Char8 -import Interop.API +import Network.GRPC.Common.Protobuf + import Interop.Util.Exceptions +import Proto.API.Interop + {------------------------------------------------------------------------------- BoolValue -------------------------------------------------------------------------------} diff --git a/demo-common/Demo/Common/API.hs b/proto/Proto/API/Helloworld.hs similarity index 60% rename from demo-common/Demo/Common/API.hs rename to proto/Proto/API/Helloworld.hs index d7de4aab..394b8ea8 100644 --- a/demo-common/Demo/Common/API.hs +++ b/proto/Proto/API/Helloworld.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -Wno-orphans #-} -module Demo.Common.API ( +module Proto.API.Helloworld ( -- * Greeter SayHello , SayHelloStreamReply @@ -10,18 +10,8 @@ module Demo.Common.API ( -- ** Metadata , SayHelloMetadata(..) - -- * RouteGuide - , GetFeature - , ListFeatures - , RecordRoute - , RouteChat - - -- * Ping - , Ping - -- * Re-exports , module Proto.Helloworld - , module Proto.RouteGuide ) where import Control.Monad.Catch @@ -32,8 +22,6 @@ import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Proto.Helloworld -import Proto.RouteGuide -import Network.GRPC.Common.Binary {------------------------------------------------------------------------------- Greeter @@ -73,27 +61,4 @@ instance ParseMetadata SayHelloMetadata where [md] | customMetadataName md == "initial-md" -> return $ SayHelloMetadata $ Just (customMetadataValue md) _otherwise -> - throwM $ UnexpectedMetadata headers - -{------------------------------------------------------------------------------- - RouteGuide --------------------------------------------------------------------------------} - -type GetFeature = Protobuf RouteGuide "getFeature" -type ListFeatures = Protobuf RouteGuide "listFeatures" -type RecordRoute = Protobuf RouteGuide "recordRoute" -type RouteChat = Protobuf RouteGuide "routeChat" - -type instance RequestMetadata (Protobuf RouteGuide meth) = NoMetadata -type instance ResponseInitialMetadata (Protobuf RouteGuide meth) = NoMetadata -type instance ResponseTrailingMetadata (Protobuf RouteGuide meth) = NoMetadata - -{------------------------------------------------------------------------------- - Ping --------------------------------------------------------------------------------} - -type Ping = RawRpc "Ping" "ping" - -type instance RequestMetadata (RawRpc "Ping" meth) = NoMetadata -type instance ResponseInitialMetadata (RawRpc "Ping" meth) = NoMetadata -type instance ResponseTrailingMetadata (RawRpc "Ping" meth) = NoMetadata + throwM $ UnexpectedMetadata headers \ No newline at end of file diff --git a/interop/Interop/API.hs b/proto/Proto/API/Interop.hs similarity index 91% rename from interop/Interop/API.hs rename to proto/Proto/API/Interop.hs index 61d89a87..f4e30d81 100644 --- a/interop/Interop/API.hs +++ b/proto/Proto/API/Interop.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -Wno-orphans #-} -module Interop.API ( +module Proto.API.Interop ( -- * TestService -- ** Endpoints @@ -20,14 +20,9 @@ module Interop.API ( -- * UnimplementedService , UnimplementedServiceCall - -- * PingService - , Ping - -- * Re-exports - , module Network.GRPC.Common.Protobuf , module Proto.Empty , module Proto.Messages - , module Proto.Ping , module Proto.Test ) where @@ -40,7 +35,6 @@ import Network.GRPC.Common.Protobuf import Proto.Empty import Proto.Messages -import Proto.Ping import Proto.Test {------------------------------------------------------------------------------- @@ -183,13 +177,3 @@ type UnimplementedServiceCall = Protobuf UnimplementedService "unimplementedCall type instance RequestMetadata (Protobuf UnimplementedService meth) = NoMetadata type instance ResponseInitialMetadata (Protobuf UnimplementedService meth) = NoMetadata type instance ResponseTrailingMetadata (Protobuf UnimplementedService meth) = NoMetadata - -{------------------------------------------------------------------------------- - Ping service --------------------------------------------------------------------------------} - -type Ping = Protobuf PingService "ping" - -type instance RequestMetadata (Protobuf PingService meth) = NoMetadata -type instance ResponseInitialMetadata (Protobuf PingService meth) = NoMetadata -type instance ResponseTrailingMetadata (Protobuf PingService meth) = NoMetadata diff --git a/proto/Proto/API/Ping.hs b/proto/Proto/API/Ping.hs new file mode 100644 index 00000000..ff06e955 --- /dev/null +++ b/proto/Proto/API/Ping.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -Wno-orphans #-} + +module Proto.API.Ping ( + Ping + + -- * Re-exports + , module Proto.Ping +) where + +import Network.GRPC.Common +import Network.GRPC.Common.Protobuf + +import Proto.Ping + +{------------------------------------------------------------------------------- + Ping +-------------------------------------------------------------------------------} + +type Ping = Protobuf PingService "ping" + +type instance RequestMetadata (Protobuf PingService meth) = NoMetadata +type instance ResponseInitialMetadata (Protobuf PingService meth) = NoMetadata +type instance ResponseTrailingMetadata (Protobuf PingService meth) = NoMetadata diff --git a/proto/Proto/API/RouteGuide.hs b/proto/Proto/API/RouteGuide.hs new file mode 100644 index 00000000..bed16497 --- /dev/null +++ b/proto/Proto/API/RouteGuide.hs @@ -0,0 +1,30 @@ +{-# OPTIONS_GHC -Wno-orphans #-} + +module Proto.API.RouteGuide ( + -- * RouteGuide + GetFeature + , ListFeatures + , RecordRoute + , RouteChat + + -- * Re-exports + , module Proto.RouteGuide + ) where + +import Network.GRPC.Common +import Network.GRPC.Common.Protobuf + +import Proto.RouteGuide + +{------------------------------------------------------------------------------- + RouteGuide +-------------------------------------------------------------------------------} + +type GetFeature = Protobuf RouteGuide "getFeature" +type ListFeatures = Protobuf RouteGuide "listFeatures" +type RecordRoute = Protobuf RouteGuide "recordRoute" +type RouteChat = Protobuf RouteGuide "routeChat" + +type instance RequestMetadata (Protobuf RouteGuide meth) = NoMetadata +type instance ResponseInitialMetadata (Protobuf RouteGuide meth) = NoMetadata +type instance ResponseTrailingMetadata (Protobuf RouteGuide meth) = NoMetadata diff --git a/test-grapesy/Test/Sanity/Interop.hs b/test-grapesy/Test/Sanity/Interop.hs index 4b0772bc..c94fe9d2 100644 --- a/test-grapesy/Test/Sanity/Interop.hs +++ b/test-grapesy/Test/Sanity/Interop.hs @@ -15,7 +15,7 @@ import Test.Tasty.HUnit import Network.GRPC.Client qualified as Client import Network.GRPC.Client.Binary qualified as Client.Binary -import Network.GRPC.Client.StreamType.IO.Binary qualified as Client.Binary +import Network.GRPC.Client.StreamType.IO qualified as Client import Network.GRPC.Common import Network.GRPC.Common.Protobuf import Network.GRPC.Common.StreamElem qualified as StreamElem @@ -24,8 +24,8 @@ import Network.GRPC.Server.Binary qualified as Server.Binary import Network.GRPC.Server.StreamType qualified as Server import Network.GRPC.Spec -import Proto.Messages -import Proto.Test +import Proto.API.Interop +import Proto.API.Ping import Test.Driver.ClientServer @@ -53,28 +53,28 @@ tests = testGroup "Test.Sanity.Interop" [ even if the first failed with a gRPC exception -------------------------------------------------------------------------------} -type Ping = RawRpc "test" "ping" - test_callAfterException :: IO () test_callAfterException = testClientServer $ ClientServerTest { config = def , client = simpleTestClient $ \conn -> do - resp1 <- ping conn 0 + resp1 <- ping conn $ defMessage & #id .~ 0 case resp1 of Left _ -> return () Right _ -> assertFailure "Expected gRPC exception" - resp2 <- ping conn 1 + resp2 <- ping conn $ defMessage & #id .~ 1 case resp2 of Left _ -> assertFailure "Expected pong" - Right i -> assertEqual "pong" i 1 + Right i -> assertEqual "pong" i (defMessage & #id .~ 1) , server = [ Server.someRpcHandler $ Server.mkRpcHandler @Ping $ \call -> do - i :: Word <- Server.Binary.recvFinalInput call - if i > 0 then - Server.Binary.sendFinalOutput call (i, NoMetadata) + pingMsg <- Server.recvFinalInput call + if pingMsg ^. #id > 0 then do + let pongMsg :: Proto PongMessage + pongMsg = defMessage & #id .~ (pingMsg ^. #id) + Server.sendFinalOutput call (pongMsg, NoMetadata) else Server.sendGrpcException call $ GrpcException { grpcError = GrpcInvalidArgument @@ -84,8 +84,11 @@ test_callAfterException = ] } where - ping :: Client.Connection -> Word -> IO (Either SomeException Word) - ping conn = try . Client.Binary.nonStreaming conn (Client.rpc @Ping) + ping :: + Client.Connection + -> Proto PingMessage + -> IO (Either SomeException (Proto PongMessage)) + ping conn = try . Client.nonStreaming conn (Client.rpc @Ping) {------------------------------------------------------------------------------- @empty_unary@ @@ -93,8 +96,6 @@ test_callAfterException = -------------------------------------------------------------------------------} -type EmptyCall = Protobuf TestService "emptyCall" - -- | Test that the empty message has an empty encoding -- -- This test fails if we unconditionally compress (the /compressed/ form of the @@ -133,8 +134,6 @@ test_emptyUnary = -------------------------------------------------------------------------------} -type StreamingOutputCall = Protobuf TestService "streamingOutputCall" - -- | Test that we can enable and disable compression per message test_serverCompressedStreaming :: IO () test_serverCompressedStreaming = @@ -188,7 +187,7 @@ test_serverCompressedStreaming = Server.sendOutputWithEnvelope call $ StreamElem (envelope, response) -- No further output - Server.sendTrailers call NoMetadata + Server.sendTrailers call def verifyOutputs :: ( Maybe (InboundEnvelope, Proto StreamingOutputCallResponse) @@ -278,10 +277,6 @@ test_cancellation_server = Internal: we don't care about metadata in these tests -------------------------------------------------------------------------------} -type instance RequestMetadata (Protobuf TestService meth) = NoMetadata -type instance ResponseInitialMetadata (Protobuf TestService meth) = NoMetadata -type instance ResponseTrailingMetadata (Protobuf TestService meth) = NoMetadata - type instance RequestMetadata (RawRpc "test" meth) = NoMetadata type instance ResponseInitialMetadata (RawRpc "test" meth) = NoMetadata type instance ResponseTrailingMetadata (RawRpc "test" meth) = NoMetadata