Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Prefer Avro.Schema over Type (deprecated) (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavio Corpa authored Feb 28, 2020
1 parent 4da4da4 commit aef6ff8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions adapter/avro/src/Mu/Adapter/Avro.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ instance ( ToSchema Identity sch sty t
-- HasAvroSchema instances

class HasAvroSchema' x where
schema' :: [ASch.TypeName] -> Tagged x ASch.Type
schema' :: [ASch.TypeName] -> Tagged x ASch.Schema

instance HasAvroSchema' (Term f sch t)
=> A.HasAvroSchema (Term f sch t) where
Expand Down Expand Up @@ -153,7 +153,7 @@ instance HasAvroSchema' (FieldValue f sch v)
where iSchema = unTagged $ schema' @(FieldValue f sch v) visited

class HasAvroSchemaUnion (f :: k -> *) (xs :: [k]) where
schemaU :: Proxy f -> Proxy xs -> [ASch.TypeName] -> NonEmpty ASch.Type
schemaU :: Proxy f -> Proxy xs -> [ASch.TypeName] -> NonEmpty ASch.Schema
instance HasAvroSchema' (f v) => HasAvroSchemaUnion f '[v] where
schemaU _ _ visited = vSchema :| []
where vSchema = unTagged (schema' @(f v) visited)
Expand Down Expand Up @@ -224,15 +224,15 @@ instance (HasAvroSchema' (FieldValue f sch v), A.FromAvro (FieldValue f sch v))
fromAvro v = FMap . M.mapKeys (FPrimitive . T.unpack) <$> A.fromAvro v

class FromAvroEnum (vs :: [ChoiceDef fn]) where
fromAvroEnum :: AVal.Value ASch.Type -> Int -> A.Result (NS Proxy vs)
fromAvroEnum :: AVal.Value ASch.Schema -> Int -> A.Result (NS Proxy vs)
instance FromAvroEnum '[] where
fromAvroEnum v _ = A.badValue v "element not found"
instance FromAvroEnum vs => FromAvroEnum (v ': vs) where
fromAvroEnum _ 0 = return (Z Proxy)
fromAvroEnum v n = S <$> fromAvroEnum v (n-1)

class FromAvroUnion f sch choices where
fromAvroU :: ASch.Type -> AVal.Value ASch.Type -> ASch.Result (NS (FieldValue f sch) choices)
fromAvroU :: ASch.Schema -> AVal.Value ASch.Schema -> ASch.Result (NS (FieldValue f sch) choices)
instance FromAvroUnion f sch '[] where
fromAvroU _ v = A.badValue v "union choice not found"
instance (A.FromAvro (FieldValue f sch u), FromAvroUnion f sch us)
Expand All @@ -244,7 +244,7 @@ instance (A.FromAvro (FieldValue f sch u), FromAvroUnion f sch us)
= S <$> fromAvroU branch v

class FromAvroFields f sch (fs :: [FieldDef Symbol Symbol]) where
fromAvroF :: HM.HashMap T.Text (AVal.Value ASch.Type) -> A.Result (NP (Field f sch) fs)
fromAvroF :: HM.HashMap T.Text (AVal.Value ASch.Schema) -> A.Result (NP (Field f sch) fs)
instance FromAvroFields f sch '[] where
fromAvroF _ = return Nil
instance (Applicative f, KnownName name, A.FromAvro (FieldValue f sch t), FromAvroFields f sch fs)
Expand Down Expand Up @@ -299,7 +299,7 @@ instance (HasAvroSchema' (FieldValue Identity sch v), A.ToAvro (FieldValue Ident
toAvro (FMap v) = A.toAvro $ M.mapKeys (\(FPrimitive k) -> k) v

class ToAvroUnion sch choices where
toAvroU :: NS (FieldValue Identity sch) choices -> (ASch.Type, AVal.Value ASch.Type)
toAvroU :: NS (FieldValue Identity sch) choices -> (ASch.Schema, AVal.Value ASch.Schema)
instance ToAvroUnion sch '[] where
toAvroU _ = error "ToAvro in an empty union"
instance forall sch u us.
Expand All @@ -318,7 +318,7 @@ instance (KnownName u, ToAvroEnum us)
toAvroE (S v) = let (n, t) = toAvroE v in (n + 1, t)

class ToAvroFields sch (fs :: [FieldDef Symbol Symbol]) where
toAvroF :: NP (Field Identity sch) fs -> HM.HashMap T.Text (AVal.Value ASch.Type)
toAvroF :: NP (Field Identity sch) fs -> HM.HashMap T.Text (AVal.Value ASch.Schema)
instance ToAvroFields sch '[] where
toAvroF _ = HM.empty
instance (KnownName name, A.ToAvro (FieldValue Identity sch t), ToAvroFields sch fs)
Expand Down
2 changes: 1 addition & 1 deletion grpc/common/mu-grpc-common.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: mu-grpc-common
version: 0.2.0.0
synopsis: gRPC for Mu, common modules for client and server
description: Use @mu-grpc-server@ or @mu-grpc-client@
description: Use @mu-grpc-server@ or @mu-grpc-client@ (the common parts).
license: Apache-2.0
license-file: LICENSE
author: Alejandro Serrano, Flavio Corpa
Expand Down

0 comments on commit aef6ff8

Please sign in to comment.