grapesy-etcd 0.1.0 → 0.2.0
raw patch · 5 files changed
+103/−124 lines, 5 filesdep +exceptionsdep −grapesy-etcddep ~grapesydep ~proto-lens-protobuf-typesdep ~proto-lens-runtime
Dependencies added: exceptions
Dependencies removed: grapesy-etcd
Dependency ranges changed: grapesy, proto-lens-protobuf-types, proto-lens-runtime
Files
- CHANGELOG.md +4/−0
- app/Client.hs +0/−48
- grapesy-etcd.cabal +59/−65
- src/Network/GRPC/Etcd/Client/Simple.hs +26/−0
- src/Proto/API/Etcd.hs +14/−11
CHANGELOG.md view
@@ -1,5 +1,9 @@ # ChangeLog for grapesy-etc +## 0.2.0++* Add `Network.GRPC.Etcd.Client.Simple` with functions for `put`, `range` and `get`.+ ## 0.1.0 * Initial version of grapesy-etc client. Contains full bindings to the etcdv3 spec as defined in
− app/Client.hs
@@ -1,48 +0,0 @@-module Client (main) where--import Network.GRPC.Client-import Network.GRPC.Client.StreamType.IO-import Network.GRPC.Common-import Network.GRPC.Common.NextElem qualified as NextElem-import Network.GRPC.Common.Protobuf--import Proto.API.Etcd--{-------------------------------------------------------------------------------- Call some methods of the Etcd service--------------------------------------------------------------------------------}--range :: Connection -> IO ()-range conn = do- let req = defMessage- & #key .~ "foo"- resp <- nonStreaming conn (rpc @(Protobuf KV "range")) req- print resp--put :: Connection -> IO ()-put conn = do- let req = defMessage- & #key .~ "foo"- resp <- nonStreaming conn (rpc @(Protobuf KV "put")) req- print resp--watch :: Connection -> IO ()-watch conn = do- let req = defMessage- & #createRequest .~ (defMessage & #key .~ "foo")- biDiStreaming conn (rpc @(Protobuf Watch "watch")) $ \send recv -> do- NextElem.forM_ (replicate 5 req) send- NextElem.whileNext_ recv print--main :: IO ()-main =- withConnection def server $ \conn -> do- putStrLn "-------------- Range --------------"- range conn- put conn- watch conn-- where- server :: Server- server = ServerInsecure $ Address "127.0.0.1" 2379 Nothing---}
grapesy-etcd.cabal view
@@ -1,86 +1,80 @@-cabal-version: 2.2-name: grapesy-etcd-version: 0.1.0-synopsis: grapesy-etcd - GRPC interface to etcd-author: IOG-copyright: 2025 IOG-license: Apache-2.0+cabal-version: 2.2+name: grapesy-etcd+version: 0.2.0+synopsis: grapesy-etcd - GRPC interface to etcd+author: IOG+copyright: 2025 IOG+license: Apache-2.0 license-files: LICENSE NOTICE+ extra-source-files:- README.md CHANGELOG.md+ README.md -extra-source-files: proto/etcd/api/etcdserverpb/rpc.proto- proto/etcd/api/authpb/auth.proto- proto/etcd/api/mvccpb/kv.proto- proto/etcd/api/versionpb/version.proto- proto/gogoproto/gogo.proto- proto/google/api/annotations.proto- proto/google/api/http.proto- proto/protoc-gen-openapiv2/options/annotations.proto- proto/protoc-gen-openapiv2/options/openapiv2.proto+extra-source-files:+ proto/etcd/api/authpb/auth.proto+ proto/etcd/api/etcdserverpb/rpc.proto+ proto/etcd/api/mvccpb/kv.proto+ proto/etcd/api/versionpb/version.proto+ proto/gogoproto/gogo.proto+ proto/google/api/annotations.proto+ proto/google/api/http.proto+ proto/protoc-gen-openapiv2/options/annotations.proto+ proto/protoc-gen-openapiv2/options/openapiv2.proto custom-setup setup-depends:- base >= 4.14 && < 5- , Cabal >= 3.0 && < 4- , proto-lens-setup >= 0.4 && < 0.5-+ , base >=4.14 && <5+ , Cabal >=3.0 && <4+ , proto-lens-setup >=0.4 && <0.5 common lang- build-depends: base >= 4.14 && < 5- default-language: GHC2021- ghc-options: -Wall-+ build-depends: base >=4.14 && <5+ default-language: GHC2021+ ghc-options: -Wall -Wmissing-import-lists default-extensions:- DataKinds- LambdaCase- OverloadedLabels- OverloadedStrings- TypeFamilies+ DataKinds+ LambdaCase+ OverloadedLabels+ OverloadedStrings+ TypeFamilies library import: lang hs-source-dirs: src build-tool-depends: proto-lens-protoc:proto-lens-protoc- build-depends:- , grapesy >= 1.0- , proto-lens-runtime >= 0.7 - , proto-lens-protobuf-types >= 0.7 + , exceptions+ , grapesy >=1.0 && <1.1+ , proto-lens-protobuf-types >=0.7 && <0.8+ , proto-lens-runtime >=0.7 && <0.8+ exposed-modules:- Proto.API.Etcd- other-modules:- Proto.Etcd.Api.Authpb.Auth- Proto.Etcd.Api.Etcdserverpb.Rpc- Proto.Etcd.Api.Mvccpb.Kv- Proto.Etcd.Api.Versionpb.Version- Proto.Gogoproto.Gogo- Proto.Google.Api.Annotations- Proto.Google.Api.Http- Proto.ProtocGenOpenapiv2.Options.Annotations- Proto.ProtocGenOpenapiv2.Options.Openapiv2- Paths_grapesy_etcd- autogen-modules:- Proto.Etcd.Api.Authpb.Auth- Proto.Etcd.Api.Etcdserverpb.Rpc- Proto.Etcd.Api.Mvccpb.Kv- Proto.Etcd.Api.Versionpb.Version- Proto.Gogoproto.Gogo- Proto.Google.Api.Annotations- Proto.Google.Api.Http- Proto.ProtocGenOpenapiv2.Options.Annotations- Proto.ProtocGenOpenapiv2.Options.Openapiv2- Paths_grapesy_etcd+ Network.GRPC.Etcd.Client.Simple+ Proto.API.Etcd -executable grapesy-etc-example- import: lang- main-is: Client.hs- hs-source-dirs: app- ghc-options: -main-is Client- build-depends: grapesy-etcd+ other-modules:+ Paths_grapesy_etcd+ Proto.Etcd.Api.Authpb.Auth+ Proto.Etcd.Api.Etcdserverpb.Rpc+ Proto.Etcd.Api.Mvccpb.Kv+ Proto.Etcd.Api.Versionpb.Version+ Proto.Gogoproto.Gogo+ Proto.Google.Api.Annotations+ Proto.Google.Api.Http+ Proto.ProtocGenOpenapiv2.Options.Annotations+ Proto.ProtocGenOpenapiv2.Options.Openapiv2 - build-depends:- , grapesy+ autogen-modules:+ Proto.Etcd.Api.Authpb.Auth+ Proto.Etcd.Api.Etcdserverpb.Rpc+ Proto.Etcd.Api.Mvccpb.Kv+ Proto.Etcd.Api.Versionpb.Version+ Proto.Gogoproto.Gogo+ Proto.Google.Api.Annotations+ Proto.Google.Api.Http+ Proto.ProtocGenOpenapiv2.Options.Annotations+ Proto.ProtocGenOpenapiv2.Options.Openapiv2+ Paths_grapesy_etcd
+ src/Network/GRPC/Etcd/Client/Simple.hs view
@@ -0,0 +1,26 @@+{-# OPTIONS_GHC -Wno-orphans #-}++module Network.GRPC.Etcd.Client.Simple (+ put,+ range,+ watch,+) where++import Control.Monad.Catch (MonadMask)+import Control.Monad.IO.Class (MonadIO)+import Network.GRPC.Client (Connection, rpc)+import Network.GRPC.Client.StreamType.IO (biDiStreaming, nonStreaming)+import Network.GRPC.Common.NextElem qualified as NextElem+import Network.GRPC.Common.Protobuf (Proto, Protobuf)+import Proto.API.Etcd (KV, PutRequest, PutResponse, RangeRequest, RangeResponse, Watch, WatchRequest, WatchResponse)++put :: (MonadIO m) => (MonadMask m) => Connection -> Proto PutRequest -> m (Proto PutResponse)+put conn = nonStreaming conn (rpc @(Protobuf KV "put"))++range :: (MonadIO m) => (MonadMask m) => Connection -> Proto RangeRequest -> m (Proto RangeResponse)+range conn = nonStreaming conn (rpc @(Protobuf KV "range"))++watch :: (MonadIO m) => (MonadMask m) => Connection -> [Proto WatchRequest] -> (Proto WatchResponse -> m ()) -> m ()+watch conn reqs resp = biDiStreaming conn (rpc @(Protobuf Watch "watch")) $ \send recv -> do+ NextElem.forM_ reqs send+ NextElem.whileNext_ recv resp
src/Proto/API/Etcd.hs view
@@ -1,23 +1,26 @@ {-# OPTIONS_GHC -Wno-orphans #-} module Proto.API.Etcd (- module Proto.Etcd.Api.Etcdserverpb.Rpc- ) where--import Network.GRPC.Common-import Network.GRPC.Common.Protobuf+ module Proto.Etcd.Api.Etcdserverpb.Rpc,+) where -import Proto.Etcd.Api.Etcdserverpb.Rpc+import Network.GRPC.Common (+ NoMetadata,+ RequestMetadata,+ ResponseInitialMetadata,+ ResponseTrailingMetadata,+ )+import Network.GRPC.Common.Protobuf (Protobuf)+import Proto.Etcd.Api.Etcdserverpb.Rpc (KV, PutRequest, PutResponse, RangeRequest, RangeResponse, Watch, WatchRequest, WatchResponse) {------------------------------------------------------------------------------- Metadata -------------------------------------------------------------------------------} -type instance RequestMetadata (Protobuf KV meth) = NoMetadata-type instance ResponseInitialMetadata (Protobuf KV meth) = NoMetadata+type instance RequestMetadata (Protobuf KV meth) = NoMetadata+type instance ResponseInitialMetadata (Protobuf KV meth) = NoMetadata type instance ResponseTrailingMetadata (Protobuf KV meth) = NoMetadata --type instance RequestMetadata (Protobuf Watch meth) = NoMetadata-type instance ResponseInitialMetadata (Protobuf Watch meth) = NoMetadata+type instance RequestMetadata (Protobuf Watch meth) = NoMetadata+type instance ResponseInitialMetadata (Protobuf Watch meth) = NoMetadata type instance ResponseTrailingMetadata (Protobuf Watch meth) = NoMetadata