mirror of
https://github.com/higherkindness/mu-haskell.git
synced 2024-09-11 14:36:01 +03:00
Add Avro Seed example 🌱 (#108)
Co-authored-by: Alejandro Serrano <trupill@gmail.com>
This commit is contained in:
parent
f6ddd6eed3
commit
52bd07a121
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"[haskell]": {
|
||||
"editor.defaultFormatter": "vigoo.stylish-haskell"
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
{-# language FunctionalDependencies #-}
|
||||
{-# language GADTs #-}
|
||||
{-# language KindSignatures #-}
|
||||
{-# language LambdaCase #-}
|
||||
{-# language ScopedTypeVariables #-}
|
||||
{-# language TypeApplications #-}
|
||||
{-# language TypeOperators #-}
|
||||
@ -31,6 +32,8 @@ as values in the schema type.
|
||||
module Mu.Schema.Optics (
|
||||
-- * Build a term
|
||||
record
|
||||
, record1
|
||||
, _U0, _Next, _U1, _U2, _U3
|
||||
-- * Re-exported for convenience.
|
||||
, module Optics.Core
|
||||
) where
|
||||
@ -52,6 +55,7 @@ instance {-# OVERLAPS #-}
|
||||
r r where
|
||||
labelOptic = lens (\(TRecord r) -> runIdentity $ fieldLensGet (Proxy @fieldName) r)
|
||||
(\(TRecord r) x -> TRecord $ fieldLensSet (Proxy @fieldName) r (Identity x))
|
||||
|
||||
instance {-# OVERLAPPABLE #-}
|
||||
(FieldLabel w sch args fieldName r, t ~ w r)
|
||||
=> LabelOptic fieldName A_Lens
|
||||
@ -64,21 +68,43 @@ instance {-# OVERLAPPABLE #-}
|
||||
record :: BuildRecord w sch args r => r -> Term w sch ('DRecord name args)
|
||||
record values = TRecord $ buildR values
|
||||
|
||||
record1 :: BuildRecord1 w sch arg r => r -> Term w sch ('DRecord name '[arg])
|
||||
record1 value = TRecord $ buildR1 value
|
||||
|
||||
class BuildRecord1 (w :: Type -> Type)
|
||||
(sch :: Schema Symbol Symbol)
|
||||
(arg :: FieldDef Symbol Symbol)
|
||||
(r :: Type) | w sch arg -> r where
|
||||
buildR1 :: r -> NP (Field w sch) '[arg]
|
||||
|
||||
instance {-# OVERLAPPABLE #-} (Functor w, TypeLabel w sch t1 r1)
|
||||
=> BuildRecord1 w sch ('FieldDef x1 t1) (w r1) where
|
||||
buildR1 v = Field (typeLensSet <$> v) :* Nil
|
||||
|
||||
instance {-# OVERLAPS #-} (TypeLabel Identity sch t1 r1)
|
||||
=> BuildRecord1 Identity sch ('FieldDef x1 t1) r1 where
|
||||
buildR1 v = Field (typeLensSet <$> Identity v) :* Nil
|
||||
|
||||
class BuildRecord (w :: Type -> Type)
|
||||
(sch :: Schema Symbol Symbol)
|
||||
(args :: [FieldDef Symbol Symbol])
|
||||
(r :: Type) | w sch args -> r where
|
||||
buildR :: r -> NP (Field w sch) args
|
||||
|
||||
instance BuildRecord w sch '[] () where
|
||||
buildR _ = Nil
|
||||
instance (Functor w, TypeLabel w sch t1 r1)
|
||||
=> BuildRecord w sch '[ 'FieldDef x1 t1 ] (w r1) where
|
||||
buildR v = Field (typeLensSet <$> v) :* Nil
|
||||
instance (Functor w, TypeLabel w sch t1 r1, TypeLabel w sch t2 r2)
|
||||
|
||||
instance {-# OVERLAPPABLE #-} (Functor w, TypeLabel w sch t1 r1, TypeLabel w sch t2 r2)
|
||||
=> BuildRecord w sch '[ 'FieldDef x1 t1, 'FieldDef x2 t2 ] (w r1, w r2) where
|
||||
buildR (v1, v2) = Field (typeLensSet <$> v1)
|
||||
:* Field (typeLensSet <$> v2) :* Nil
|
||||
instance (Functor w, TypeLabel w sch t1 r1, TypeLabel w sch t2 r2, TypeLabel w sch t3 r3)
|
||||
|
||||
instance {-# OVERLAPS #-} (TypeLabel Identity sch t1 r1, TypeLabel Identity sch t2 r2)
|
||||
=> BuildRecord Identity sch '[ 'FieldDef x1 t1, 'FieldDef x2 t2 ] (r1, r2) where
|
||||
buildR (v1, v2) = Field (typeLensSet <$> Identity v1)
|
||||
:* Field (typeLensSet <$> Identity v2) :* Nil
|
||||
|
||||
instance {-# OVERLAPPABLE #-} (Functor w, TypeLabel w sch t1 r1, TypeLabel w sch t2 r2, TypeLabel w sch t3 r3)
|
||||
=> BuildRecord w sch
|
||||
'[ 'FieldDef x1 t1, 'FieldDef x2 t2, 'FieldDef x3 t3 ]
|
||||
(w r1, w r2, w r3) where
|
||||
@ -86,6 +112,12 @@ instance (Functor w, TypeLabel w sch t1 r1, TypeLabel w sch t2 r2, TypeLabel w s
|
||||
:* Field (typeLensSet <$> v2)
|
||||
:* Field (typeLensSet <$> v3) :* Nil
|
||||
|
||||
instance {-# OVERLAPS #-} (TypeLabel Identity sch t1 r1, TypeLabel Identity sch t2 r2, TypeLabel Identity sch t3 r3)
|
||||
=> BuildRecord Identity sch
|
||||
'[ 'FieldDef x1 t1, 'FieldDef x2 t2, 'FieldDef x3 t3 ] (r1, r2, r3) where
|
||||
buildR (v1, v2, v3) = Field (typeLensSet <$> Identity v1)
|
||||
:* Field (typeLensSet <$> Identity v2)
|
||||
:* Field (typeLensSet <$> Identity v3) :* Nil
|
||||
|
||||
class FieldLabel (w :: Type -> Type)
|
||||
(sch :: Schema Symbol Symbol)
|
||||
@ -118,23 +150,32 @@ class TypeLabel w (sch :: Schema Symbol Symbol) (t :: FieldType Symbol) (r :: Ty
|
||||
instance TypeLabel w sch ('TPrimitive t) t where
|
||||
typeLensGet (FPrimitive x) = x
|
||||
typeLensSet = FPrimitive
|
||||
|
||||
instance (r ~ (sch :/: t)) => TypeLabel w sch ('TSchematic t) (Term w sch r) where
|
||||
typeLensGet (FSchematic x) = x
|
||||
typeLensSet = FSchematic
|
||||
|
||||
instance (TypeLabel w sch o r', r ~ Maybe r')
|
||||
=> TypeLabel w sch ('TOption o) r where
|
||||
typeLensGet (FOption x) = typeLensGet <$> x
|
||||
typeLensSet new = FOption (typeLensSet <$> new)
|
||||
|
||||
instance (TypeLabel w sch o r', r ~ [r'])
|
||||
=> TypeLabel w sch ('TList o) r where
|
||||
typeLensGet (FList x) = typeLensGet <$> x
|
||||
typeLensSet new = FList (typeLensSet <$> new)
|
||||
|
||||
instance ( TypeLabel w sch k k', TypeLabel w sch v v'
|
||||
, r ~ Map k' v', Ord k', Ord (FieldValue w sch k) )
|
||||
=> TypeLabel w sch ('TMap k v) r where
|
||||
typeLensGet (FMap x) = mapKeys typeLensGet (typeLensGet <$> x)
|
||||
typeLensSet new = FMap (mapKeys typeLensSet (typeLensSet <$> new))
|
||||
|
||||
instance (r ~ NS (FieldValue w sch) choices)
|
||||
=> TypeLabel w sch ('TUnion choices) r where
|
||||
typeLensGet (FUnion x) = x
|
||||
typeLensSet = FUnion
|
||||
|
||||
instance (EnumLabel choices choiceName, r ~ ())
|
||||
=> LabelOptic choiceName A_Prism
|
||||
(Term w sch ('DEnum name choices))
|
||||
@ -161,3 +202,28 @@ instance {-# OVERLAPPABLE #-} EnumLabel rest c
|
||||
enumPrismBuild p = S (enumPrismBuild p)
|
||||
enumPrismMatch _ (Z _) = Nothing
|
||||
enumPrismMatch p (S x) = enumPrismMatch p x
|
||||
|
||||
_U0 :: forall w (sch :: Schema') x xs r. TypeLabel w sch x r
|
||||
=> Prism' (NS (FieldValue w sch) (x ': xs)) r
|
||||
_U0 = prism' (Z . typeLensSet)
|
||||
(\case (Z x) -> Just $ typeLensGet x
|
||||
(S _) -> Nothing)
|
||||
|
||||
_Next :: forall w (sch :: Schema') x xs.
|
||||
Prism' (NS (FieldValue w sch) (x ': xs))
|
||||
(NS (FieldValue w sch) xs)
|
||||
_Next = prism' S
|
||||
(\case (Z _) -> Nothing
|
||||
(S x) -> Just x)
|
||||
|
||||
_U1 :: forall w (sch :: Schema') a b xs r. TypeLabel w sch b r
|
||||
=> Prism' (NS (FieldValue w sch) (a ': b ': xs)) r
|
||||
_U1 = _Next % _U0
|
||||
|
||||
_U2 :: forall w (sch :: Schema') a b c xs r. TypeLabel w sch c r
|
||||
=> Prism' (NS (FieldValue w sch) (a ': b ': c ': xs)) r
|
||||
_U2 = _Next % _U1
|
||||
|
||||
_U3 :: forall w (sch :: Schema') a b c d xs r. TypeLabel w sch d r
|
||||
=> Prism' (NS (FieldValue w sch) (a ': b ': c ': d ': xs)) r
|
||||
_U3 = _Next % _U2
|
||||
|
@ -13,7 +13,8 @@ in {
|
||||
mu-example-health-check-avro = hnPkgs.mu-example-health-check-avro.components.all;
|
||||
mu-example-health-check-protobuf = hnPkgs.mu-example-health-check-protobuf.components.all;
|
||||
mu-example-route-guide = hnPkgs.mu-example-route-guide.components.all;
|
||||
mu-example-seed = hnPkgs.mu-example-seed.components.all;
|
||||
mu-example-seed-avro = hnPkgs.mu-example-seed-avro.components.all;
|
||||
mu-example-seed-protobuf = hnPkgs.mu-example-seed-protobuf.components.all;
|
||||
mu-example-todolist = hnPkgs.mu-example-todolist.components.all;
|
||||
mu-example-with-persistent = hnPkgs.mu-example-with-persistent.components.all;
|
||||
mu-grpc-common = hnPkgs.mu-grpc-common.components.library;
|
||||
|
@ -1,18 +1,14 @@
|
||||
cabal-version: >=1.10
|
||||
-- Initial package description 'mu-haskell.cabal' generated by 'cabal
|
||||
-- init'. For further documentation, see
|
||||
-- http://haskell.org/cabal/users-guide/
|
||||
|
||||
name: mu-example-health-check-avro
|
||||
version: 0.1.0.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
-- bug-reports:
|
||||
bug-reports: https://github.com/higherkindness/mu-haskell/issues
|
||||
license: Apache-2.0
|
||||
license-file: LICENSE
|
||||
author: Alejandro Serrano, Flavio Corpa
|
||||
maintainer: alejandro.serrano@47deg.com
|
||||
copyright: Copyright © 2019-2020 47 Degrees. <http://47deg.com>
|
||||
copyright: Copyright © 2020 47 Degrees. <http://47deg.com>
|
||||
category: Network
|
||||
build-type: Simple
|
||||
data-files: healthcheck.avdl
|
||||
@ -20,11 +16,15 @@ data-files: healthcheck.avdl
|
||||
executable health-server-avro
|
||||
main-is: Server.hs
|
||||
other-modules: Definition
|
||||
build-depends: base >=4.12 && <5, text,
|
||||
mu-schema, mu-rpc, mu-avro,
|
||||
mu-grpc-server,
|
||||
stm, stm-containers,
|
||||
conduit, stm-conduit,
|
||||
build-depends: base >=4.12 && <5
|
||||
, text
|
||||
, mu-schema
|
||||
, mu-rpc
|
||||
, mu-avro
|
||||
, mu-grpc-server
|
||||
, stm
|
||||
, stm-conduit
|
||||
, stm-containers,
|
||||
deferred-folds
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
@ -33,9 +33,12 @@ executable health-server-avro
|
||||
executable health-client-tyapps-avro
|
||||
main-is: ClientTyApps.hs
|
||||
other-modules: Definition
|
||||
build-depends: base >=4.12 && <5, text,
|
||||
mu-schema, mu-rpc, mu-avro,
|
||||
mu-grpc-client, conduit
|
||||
build-depends: base >=4.12 && <5
|
||||
, text
|
||||
, mu-schema
|
||||
, mu-rpc
|
||||
, mu-avro
|
||||
, mu-grpc-client
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
ghc-options: -Wall
|
||||
@ -43,9 +46,12 @@ executable health-client-tyapps-avro
|
||||
executable health-client-record-avro
|
||||
main-is: ClientRecord.hs
|
||||
other-modules: Definition
|
||||
build-depends: base >=4.12 && <5, text,
|
||||
mu-schema, mu-rpc, mu-avro,
|
||||
mu-grpc-client, conduit
|
||||
build-depends: base >=4.12 && <5
|
||||
, text
|
||||
, mu-schema
|
||||
, mu-rpc
|
||||
, mu-avro
|
||||
, mu-grpc-client
|
||||
hs-source-dirs: src
|
||||
default-language: Haskell2010
|
||||
ghc-options: -Wall
|
||||
|
@ -8,10 +8,8 @@
|
||||
{-# language TypeOperators #-}
|
||||
module Main where
|
||||
|
||||
import Data.Conduit
|
||||
import qualified Data.Conduit.Combinators as C
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics (Generic)
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics (Generic)
|
||||
import System.Environment
|
||||
|
||||
import Mu.GRpc.Client.Record
|
||||
@ -64,11 +62,3 @@ update client who newstatus = do
|
||||
putStrLn ("UNARY: Was setting successful? " <> show r)
|
||||
rstatus <- check client hcm
|
||||
putStrLn ("UNARY: Checked the status of " <> who <> ". Obtained: " <> show rstatus)
|
||||
|
||||
{-
|
||||
watching :: HealthCall -> String -> IO ()
|
||||
watching client who = do
|
||||
let hcm = HealthCheckMsg (T.pack who)
|
||||
stream <- watch client hcm
|
||||
runConduit $ stream .| C.mapM_ print
|
||||
-}
|
||||
|
@ -7,9 +7,7 @@
|
||||
{-# language TypeOperators #-}
|
||||
module Main where
|
||||
|
||||
import Data.Conduit
|
||||
import qualified Data.Conduit.Combinators as C
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text as T
|
||||
import System.Environment
|
||||
|
||||
import Mu.GRpc.Client.TyApps
|
||||
@ -23,7 +21,6 @@ main = do -- Setup the client
|
||||
-- Execute command
|
||||
args <- getArgs
|
||||
case args of
|
||||
-- ["watch" , who] -> watching client who
|
||||
["simple", who] -> simple client who
|
||||
["update", who] -> update client who "SERVING"
|
||||
["update", who, newstatus] -> update client who newstatus
|
||||
@ -53,11 +50,3 @@ update client who newstatus = do
|
||||
rstatus :: GRpcReply ServerStatusMsg
|
||||
<- gRpcCall @'MsgAvro @HealthCheckService @"check" client hcm
|
||||
putStrLn ("UNARY: Checked the status of " <> who <> ". Obtained: " <> show rstatus)
|
||||
|
||||
{-
|
||||
watching :: GrpcClient -> String -> IO ()
|
||||
watching client who = do
|
||||
let hcm = HealthCheckMsg (T.pack who)
|
||||
replies <- gRpcCall @'MsgAvro @HealthCheckService @"watch" client hcm
|
||||
runConduit $ replies .| C.mapM_ (print :: GRpcReply ServerStatusMsg -> IO ())
|
||||
-}
|
||||
|
@ -21,7 +21,7 @@ import Mu.Quasi.Avro
|
||||
import Mu.Schema
|
||||
|
||||
#if __GHCIDE__
|
||||
avdl "HealthCheckSchema" "HealthCheckService" "examples/health-check" "healthcheck.proto"
|
||||
avdl "HealthCheckSchema" "HealthCheckService" "examples/health-check/avro" "healthcheck.avdl"
|
||||
#else
|
||||
avdl "HealthCheckSchema" "HealthCheckService" "." "healthcheck.avdl"
|
||||
#endif
|
||||
|
@ -5,14 +5,12 @@
|
||||
module Main where
|
||||
|
||||
import Control.Concurrent.STM
|
||||
import Data.Conduit
|
||||
import qualified Data.Conduit.Combinators as C
|
||||
import Data.Conduit.TMChan
|
||||
import Data.Functor.Identity
|
||||
import Data.Maybe (fromMaybe)
|
||||
import qualified Data.Text as T
|
||||
import Data.Maybe (fromMaybe)
|
||||
import qualified Data.Text as T
|
||||
import DeferredFolds.UnfoldlM
|
||||
import qualified StmContainers.Map as M
|
||||
import qualified StmContainers.Map as M
|
||||
|
||||
import Mu.GRpc.Server
|
||||
import Mu.Server
|
||||
@ -71,7 +69,7 @@ cleanAll_ m = alwaysOk $ do
|
||||
putStrLn "cleanAll"
|
||||
atomically $ M.reset m
|
||||
|
||||
{-
|
||||
{- Note: no "streams" in avro
|
||||
watch_ :: StatusUpdates
|
||||
-> HealthCheckMsg
|
||||
-> ConduitT ServerStatusMsg Void ServerErrorIO ()
|
||||
|
@ -13,14 +13,14 @@
|
||||
{-# language TypeOperators #-}
|
||||
module Definition where
|
||||
|
||||
import Data.Text as T
|
||||
import Data.Text as T
|
||||
import GHC.Generics
|
||||
|
||||
import Mu.Quasi.GRpc
|
||||
import Mu.Schema
|
||||
|
||||
#if __GHCIDE__
|
||||
grpc "HealthCheckSchema" id "examples/health-check/healthcheck.proto"
|
||||
grpc "HealthCheckSchema" id "examples/health-check/protobuf/healthcheck.proto"
|
||||
#else
|
||||
grpc "HealthCheckSchema" id "healthcheck.proto"
|
||||
#endif
|
||||
|
@ -1,11 +1,11 @@
|
||||
# Seed RPC example
|
||||
# Seed RPC example with Avro!
|
||||
|
||||
## Execution
|
||||
|
||||
Running the server:
|
||||
|
||||
```bash
|
||||
stack run seed-server
|
||||
stack run mu-example-seed-avro
|
||||
```
|
||||
|
||||
[comment]: # (Start Copyright)
|
||||
@ -13,6 +13,6 @@ stack run seed-server
|
||||
|
||||
Mu is designed and developed by 47 Degrees
|
||||
|
||||
Copyright (C) 2019-2020 47 Degrees. <http://47deg.com>
|
||||
Copyright © 2020 47 Degrees. <http://47deg.com>
|
||||
|
||||
[comment]: # (End Copyright)
|
1
examples/seed/avro/hie.yaml
Normal file
1
examples/seed/avro/hie.yaml
Normal file
@ -0,0 +1 @@
|
||||
cradle: { stack: { component: "mu-example-seed-avro:exe:seed-server" } }
|
30
examples/seed/avro/mu-example-seed-avro.cabal
Normal file
30
examples/seed/avro/mu-example-seed-avro.cabal
Normal file
@ -0,0 +1,30 @@
|
||||
name: mu-example-seed-avro
|
||||
version: 0.1.0.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
homepage: https://github.com/higherkindness/mu-haskell/examples/seed/avro#readme
|
||||
license: Apache-2.0
|
||||
license-file: LICENSE
|
||||
author: Flavio Corpa
|
||||
maintainer: flavio.corpa@47deg.com
|
||||
copyright: Copyright © 2020 47 Degrees. <http://47deg.com>
|
||||
category: Web
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
extra-source-files: README.md
|
||||
data-files: seed.avdl
|
||||
|
||||
executable mu-example-seed-avro
|
||||
hs-source-dirs: src
|
||||
main-is: Main.hs
|
||||
other-modules: Schema
|
||||
default-language: Haskell2010
|
||||
build-depends: base >= 4.12 && < 5
|
||||
, monad-logger
|
||||
, mu-avro
|
||||
, mu-schema
|
||||
, mu-rpc
|
||||
, mu-optics
|
||||
, mu-grpc-server
|
||||
, text
|
||||
ghc-options: -Wall -fprint-potential-instances
|
25
examples/seed/avro/seed.avdl
Normal file
25
examples/seed/avro/seed.avdl
Normal file
@ -0,0 +1,25 @@
|
||||
@namespace("example.seed.server.protocol.avro")
|
||||
protocol Service {
|
||||
record Person {
|
||||
string name;
|
||||
int age;
|
||||
}
|
||||
|
||||
error NotFoundError {
|
||||
string message;
|
||||
}
|
||||
|
||||
error DuplicatedPersonError {
|
||||
string message;
|
||||
}
|
||||
|
||||
record PeopleRequest {
|
||||
string name;
|
||||
}
|
||||
|
||||
record PeopleResponse {
|
||||
union { Person, NotFoundError, DuplicatedPersonError } result;
|
||||
}
|
||||
|
||||
example.seed.server.protocol.avro.PeopleResponse getPerson(example.seed.server.protocol.avro.PeopleRequest request);
|
||||
}
|
41
examples/seed/avro/src/Main.hs
Normal file
41
examples/seed/avro/src/Main.hs
Normal file
@ -0,0 +1,41 @@
|
||||
{-# language DataKinds #-}
|
||||
{-# language DuplicateRecordFields #-}
|
||||
{-# language FlexibleContexts #-}
|
||||
{-# language OverloadedLabels #-}
|
||||
{-# language OverloadedStrings #-}
|
||||
{-# language PartialTypeSignatures #-}
|
||||
{-# language TypeOperators #-}
|
||||
{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Control.Monad.Logger
|
||||
import Data.Int
|
||||
import Data.Functor.Identity
|
||||
import Mu.GRpc.Server
|
||||
import Mu.Schema
|
||||
import Mu.Schema.Optics
|
||||
import Mu.Server
|
||||
|
||||
import Schema
|
||||
|
||||
type Person = Term Identity SeedSchema (SeedSchema :/: "Person")
|
||||
type PeopleRequest = Term Identity SeedSchema (SeedSchema :/: "PeopleRequest")
|
||||
type PeopleResponse = Term Identity SeedSchema (SeedSchema :/: "PeopleResponse")
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "running seed application"
|
||||
runGRpcAppTrans msgAvro 8080 runStderrLoggingT server
|
||||
|
||||
-- Server implementation
|
||||
-- https://github.com/higherkindness/mu/blob/master/modules/examples/seed/server/modules/process/src/main/scala/example/seed/server/process/ProtoPeopleServiceHandler.scala
|
||||
|
||||
server :: (MonadServer m, MonadLogger m) => ServerT Identity PeopleService m _
|
||||
server = Server (getPerson :<|>: H0)
|
||||
|
||||
evolvePerson :: PeopleRequest -> PeopleResponse
|
||||
evolvePerson req = record1 (review _U0 $ record (req ^. #name, 18 :: Int32))
|
||||
|
||||
getPerson :: Monad m => PeopleRequest -> m PeopleResponse
|
||||
getPerson = pure . evolvePerson
|
21
examples/seed/avro/src/Schema.hs
Normal file
21
examples/seed/avro/src/Schema.hs
Normal file
@ -0,0 +1,21 @@
|
||||
{-# language CPP #-}
|
||||
{-# language DataKinds #-}
|
||||
{-# language DeriveAnyClass #-}
|
||||
{-# language DeriveGeneric #-}
|
||||
{-# language DuplicateRecordFields #-}
|
||||
{-# language FlexibleContexts #-}
|
||||
{-# language FlexibleInstances #-}
|
||||
{-# language MultiParamTypeClasses #-}
|
||||
{-# language PolyKinds #-}
|
||||
{-# language TemplateHaskell #-}
|
||||
{-# language TypeFamilies #-}
|
||||
{-# language TypeOperators #-}
|
||||
module Schema where
|
||||
|
||||
import Mu.Quasi.Avro
|
||||
|
||||
#if __GHCIDE__
|
||||
avdl "SeedSchema" "PeopleService" "examples/seed/avro" "seed.avdl"
|
||||
#else
|
||||
avdl "SeedSchema" "PeopleService" "." "seed.avdl"
|
||||
#endif
|
17
examples/seed/avro/stack.yaml
Normal file
17
examples/seed/avro/stack.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
resolver: lts-14.22
|
||||
allow-newer: true
|
||||
extra-deps:
|
||||
# mu
|
||||
- mu-schema-0.1.0.0
|
||||
- mu-rpc-0.1.0.0
|
||||
- mu-optics-0.1.0.0
|
||||
- mu-avro-0.1.0.0
|
||||
- mu-grpc-server-0.1.0.1
|
||||
- compendium-client-0.1.0.1
|
||||
# dependencies of mu
|
||||
- http2-client-0.9.0.0
|
||||
- http2-grpc-types-0.5.0.0
|
||||
- http2-grpc-proto3-wire-0.1.0.0
|
||||
- warp-grpc-0.3.0.0
|
||||
- proto3-wire-1.1.0
|
||||
- language-protobuf-1.0.1
|
@ -1 +0,0 @@
|
||||
cradle: { stack: { component: "mu-example-seed:exe:seed-server" } }
|
3
examples/seed/protobuf/.gitignore
vendored
Normal file
3
examples/seed/protobuf/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.stack-work/
|
||||
stack*.yaml.lock
|
||||
*~
|
202
examples/seed/protobuf/LICENSE
Normal file
202
examples/seed/protobuf/LICENSE
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright © 2019-2020 47 Degrees. <http://47deg.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
18
examples/seed/protobuf/README.md
Normal file
18
examples/seed/protobuf/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Seed RPC example with Protobuf
|
||||
|
||||
## Execution
|
||||
|
||||
Running the server:
|
||||
|
||||
```bash
|
||||
stack run mu-example-seed-protobuf
|
||||
```
|
||||
|
||||
[comment]: # (Start Copyright)
|
||||
# Copyright
|
||||
|
||||
Mu is designed and developed by 47 Degrees
|
||||
|
||||
Copyright © 2020 47 Degrees. <http://47deg.com>
|
||||
|
||||
[comment]: # (End Copyright)
|
2
examples/seed/protobuf/Setup.hs
Normal file
2
examples/seed/protobuf/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
1
examples/seed/protobuf/hie.yaml
Normal file
1
examples/seed/protobuf/hie.yaml
Normal file
@ -0,0 +1 @@
|
||||
cradle: { stack: { component: "mu-example-seed-protobuf:exe:seed-server" } }
|
@ -1,8 +1,8 @@
|
||||
name: mu-example-seed
|
||||
name: mu-example-seed-protobuf
|
||||
version: 0.1.0.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
homepage: https://github.com/higherkindness/mu-haskell/examples/seed#readme
|
||||
homepage: https://github.com/higherkindness/mu-haskell/examples/seed/protobuf#readme
|
||||
license: Apache-2.0
|
||||
license-file: LICENSE
|
||||
author: Flavio Corpa
|
@ -38,7 +38,7 @@ server :: (MonadServer m, MonadLogger m) => ServerT Maybe PeopleService m _
|
||||
server = Server (getPerson :<|>: getPersonStream :<|>: H0)
|
||||
|
||||
evolvePerson :: PeopleRequest -> PeopleResponse
|
||||
evolvePerson req = record (Just $ record (req ^. #name, Just 18))
|
||||
evolvePerson req = record1 (Just $ record (req ^. #name, Just 18))
|
||||
|
||||
getPerson :: Monad m => PeopleRequest -> m PeopleResponse
|
||||
getPerson = pure . evolvePerson
|
@ -13,7 +13,7 @@ module Schema where
|
||||
import Mu.Quasi.GRpc
|
||||
|
||||
#if __GHCIDE__
|
||||
grpc "SeedSchema" id "examples/seed/seed.proto"
|
||||
grpc "SeedSchema" id "examples/seed/protobuf/seed.proto"
|
||||
#else
|
||||
grpc "SeedSchema" id "seed.proto"
|
||||
#endif
|
@ -26,7 +26,7 @@ get :: GRpcConnection PersistentService 'MsgProtoBuf -> String -> IO ()
|
||||
get client idPerson = do
|
||||
let req = readMaybe idPerson
|
||||
putStrLn $ "GET: is there some person with id: " ++ idPerson ++ "?"
|
||||
response <- (client ^. #getPerson) (record req)
|
||||
response <- (client ^. #getPerson) (record1 req)
|
||||
putStrLn $ "GET: response was: " ++ show response
|
||||
|
||||
add :: GRpcConnection PersistentService 'MsgProtoBuf -> String -> String -> IO ()
|
||||
|
@ -15,7 +15,8 @@ packages:
|
||||
- examples/health-check/avro
|
||||
- examples/health-check/protobuf
|
||||
- examples/route-guide
|
||||
- examples/seed
|
||||
- examples/seed/avro
|
||||
- examples/seed/protobuf
|
||||
- examples/todolist
|
||||
- examples/with-persistent
|
||||
- compendium-client
|
||||
|
@ -15,7 +15,8 @@ packages:
|
||||
- examples/health-check/avro
|
||||
- examples/health-check/protobuf
|
||||
- examples/route-guide
|
||||
- examples/seed
|
||||
- examples/seed/avro
|
||||
- examples/seed/protobuf
|
||||
- examples/todolist
|
||||
- examples/with-persistent
|
||||
- compendium-client
|
||||
|
@ -55,7 +55,7 @@ stack*.yaml.lock
|
||||
{-# START_FILE README.md #-}
|
||||
# {{name}}
|
||||
|
||||
{-# START_FILE {{name}}.proto #-}
|
||||
{-# START_FILE {{name}}.avdl #-}
|
||||
@namespace("{{name}}")
|
||||
protocol Service {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user