{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE RecordWildCards #-}
-- Name shadowing is really helpful for writing some custom traversals
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

module Unison.Sync.Types
  ( -- * Misc. types
    Base64Bytes (..),
    RepoInfo (..),
    Path (..),
    pathRepoInfo,
    pathCodebasePath,

    -- ** Entity types
    Entity (..),
    TermComponent (..),
    DeclComponent (..),
    Patch (..),
    PatchDiff (..),
    Namespace (..),
    NamespaceDiff (..),
    Causal (..),
    LocalIds (..),
    entityDependencies,
    EntityType (..),

    -- *** Entity Traversals
    entityHashes_,
    patchOldHashes_,
    patchNewHashes_,
    patchDiffHashes_,
    namespaceDiffHashes_,
    causalHashes_,

    -- * Request/response types

    -- ** Get causal hash by path
    GetCausalHashByPathRequest (..),
    GetCausalHashByPathResponse (..),

    -- ** Download entities
    DownloadEntitiesRequest (..),
    DownloadEntitiesResponse (..),
    DownloadEntitiesError (..),

    -- ** Upload entities
    UploadEntitiesRequest (..),
    UploadEntitiesResponse (..),
    UploadEntitiesError (..),

    -- * Common/shared error types
    HashMismatchForEntity (..),
    InvalidParentage (..),
    NeedDependencies (..),
    EntityValidationError (..),
  )
where

import Control.Lens (both, traverseOf)
import Data.Aeson
import Data.Aeson qualified as Aeson
import Data.Aeson.Types qualified as Aeson
import Data.Bifoldable
import Data.Bitraversable
import Data.ByteArray.Encoding (Base (Base64), convertFromBase, convertToBase)
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.Map.NonEmpty (NEMap)
import Data.Set qualified as Set
import Data.Set.NonEmpty (NESet)
import Data.Text qualified as Text
import Data.Text.Encoding qualified as Text
import U.Codebase.Sqlite.Branch.Format (LocalBranchBytes (..))
import Unison.Hash32 (Hash32)
import Unison.Hash32.Orphans.Aeson ()
import Unison.Prelude
import Unison.Share.API.Hash (HashJWT)
import Unison.Util.Set qualified as Set

------------------------------------------------------------------------------------------------------------------------
-- Misc. types

-- | A newtype for JSON encoding binary data.
newtype Base64Bytes = Base64Bytes ByteString

instance ToJSON Base64Bytes where
  toJSON :: Base64Bytes -> Value
toJSON (Base64Bytes ByteString
bytes) = Text -> Value
String (Text -> Value) -> (ByteString -> Text) -> ByteString -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Text.decodeUtf8 (ByteString -> Value) -> ByteString -> Value
forall a b. (a -> b) -> a -> b
$ Base -> ByteString -> ByteString
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
Base -> bin -> bout
convertToBase Base
Base64 ByteString
bytes

instance FromJSON Base64Bytes where
  parseJSON :: Value -> Parser Base64Bytes
parseJSON = String
-> (Text -> Parser Base64Bytes) -> Value -> Parser Base64Bytes
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"Base64" \Text
txt -> do
    (String -> Parser Base64Bytes)
-> (ByteString -> Parser Base64Bytes)
-> Either String ByteString
-> Parser Base64Bytes
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> Parser Base64Bytes
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (Base64Bytes -> Parser Base64Bytes
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Base64Bytes -> Parser Base64Bytes)
-> (ByteString -> Base64Bytes) -> ByteString -> Parser Base64Bytes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Base64Bytes
Base64Bytes) (Either String ByteString -> Parser Base64Bytes)
-> Either String ByteString -> Parser Base64Bytes
forall a b. (a -> b) -> a -> b
$ Base -> ByteString -> Either String ByteString
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
Base -> bin -> Either String bout
convertFromBase Base
Base64 (Text -> ByteString
Text.encodeUtf8 Text
txt)

newtype RepoInfo = RepoInfo {RepoInfo -> Text
unRepoInfo :: Text}
  deriving newtype (Int -> RepoInfo -> ShowS
[RepoInfo] -> ShowS
RepoInfo -> String
(Int -> RepoInfo -> ShowS)
-> (RepoInfo -> String) -> ([RepoInfo] -> ShowS) -> Show RepoInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RepoInfo -> ShowS
showsPrec :: Int -> RepoInfo -> ShowS
$cshow :: RepoInfo -> String
show :: RepoInfo -> String
$cshowList :: [RepoInfo] -> ShowS
showList :: [RepoInfo] -> ShowS
Show, RepoInfo -> RepoInfo -> Bool
(RepoInfo -> RepoInfo -> Bool)
-> (RepoInfo -> RepoInfo -> Bool) -> Eq RepoInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RepoInfo -> RepoInfo -> Bool
== :: RepoInfo -> RepoInfo -> Bool
$c/= :: RepoInfo -> RepoInfo -> Bool
/= :: RepoInfo -> RepoInfo -> Bool
Eq, Eq RepoInfo
Eq RepoInfo =>
(RepoInfo -> RepoInfo -> Ordering)
-> (RepoInfo -> RepoInfo -> Bool)
-> (RepoInfo -> RepoInfo -> Bool)
-> (RepoInfo -> RepoInfo -> Bool)
-> (RepoInfo -> RepoInfo -> Bool)
-> (RepoInfo -> RepoInfo -> RepoInfo)
-> (RepoInfo -> RepoInfo -> RepoInfo)
-> Ord RepoInfo
RepoInfo -> RepoInfo -> Bool
RepoInfo -> RepoInfo -> Ordering
RepoInfo -> RepoInfo -> RepoInfo
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RepoInfo -> RepoInfo -> Ordering
compare :: RepoInfo -> RepoInfo -> Ordering
$c< :: RepoInfo -> RepoInfo -> Bool
< :: RepoInfo -> RepoInfo -> Bool
$c<= :: RepoInfo -> RepoInfo -> Bool
<= :: RepoInfo -> RepoInfo -> Bool
$c> :: RepoInfo -> RepoInfo -> Bool
> :: RepoInfo -> RepoInfo -> Bool
$c>= :: RepoInfo -> RepoInfo -> Bool
>= :: RepoInfo -> RepoInfo -> Bool
$cmax :: RepoInfo -> RepoInfo -> RepoInfo
max :: RepoInfo -> RepoInfo -> RepoInfo
$cmin :: RepoInfo -> RepoInfo -> RepoInfo
min :: RepoInfo -> RepoInfo -> RepoInfo
Ord, [RepoInfo] -> Value
[RepoInfo] -> Encoding
RepoInfo -> Value
RepoInfo -> Encoding
(RepoInfo -> Value)
-> (RepoInfo -> Encoding)
-> ([RepoInfo] -> Value)
-> ([RepoInfo] -> Encoding)
-> ToJSON RepoInfo
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: RepoInfo -> Value
toJSON :: RepoInfo -> Value
$ctoEncoding :: RepoInfo -> Encoding
toEncoding :: RepoInfo -> Encoding
$ctoJSONList :: [RepoInfo] -> Value
toJSONList :: [RepoInfo] -> Value
$ctoEncodingList :: [RepoInfo] -> Encoding
toEncodingList :: [RepoInfo] -> Encoding
ToJSON, Value -> Parser [RepoInfo]
Value -> Parser RepoInfo
(Value -> Parser RepoInfo)
-> (Value -> Parser [RepoInfo]) -> FromJSON RepoInfo
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser RepoInfo
parseJSON :: Value -> Parser RepoInfo
$cparseJSONList :: Value -> Parser [RepoInfo]
parseJSONList :: Value -> Parser [RepoInfo]
FromJSON)

data Path = Path
  { -- This is a nonempty list, where we require the first segment to be the repo name / user name / whatever,
    -- which we need on the server side as an implementation detail of how we're representing different users' codebases.

    -- This could be relaxed in some other share implementation that allows access to the "root" of the shared codebase.
    -- Our share implementation doesn't have a root, just a collection of sub-roots, one per user or (eventually) organization.
    Path -> NonEmpty Text
pathSegments :: NonEmpty Text
  }
  deriving stock (Int -> Path -> ShowS
[Path] -> ShowS
Path -> String
(Int -> Path -> ShowS)
-> (Path -> String) -> ([Path] -> ShowS) -> Show Path
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Path -> ShowS
showsPrec :: Int -> Path -> ShowS
$cshow :: Path -> String
show :: Path -> String
$cshowList :: [Path] -> ShowS
showList :: [Path] -> ShowS
Show, Path -> Path -> Bool
(Path -> Path -> Bool) -> (Path -> Path -> Bool) -> Eq Path
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Path -> Path -> Bool
== :: Path -> Path -> Bool
$c/= :: Path -> Path -> Bool
/= :: Path -> Path -> Bool
Eq, Eq Path
Eq Path =>
(Path -> Path -> Ordering)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Bool)
-> (Path -> Path -> Path)
-> (Path -> Path -> Path)
-> Ord Path
Path -> Path -> Bool
Path -> Path -> Ordering
Path -> Path -> Path
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Path -> Path -> Ordering
compare :: Path -> Path -> Ordering
$c< :: Path -> Path -> Bool
< :: Path -> Path -> Bool
$c<= :: Path -> Path -> Bool
<= :: Path -> Path -> Bool
$c> :: Path -> Path -> Bool
> :: Path -> Path -> Bool
$c>= :: Path -> Path -> Bool
>= :: Path -> Path -> Bool
$cmax :: Path -> Path -> Path
max :: Path -> Path -> Path
$cmin :: Path -> Path -> Path
min :: Path -> Path -> Path
Ord)

-- | Convert a path like arya.public.mystuff to a "repo info" by treating the first segment as a user handle.
pathRepoInfo :: Path -> RepoInfo
pathRepoInfo :: Path -> RepoInfo
pathRepoInfo (Path (Text
p :| [Text]
_)) = Text -> RepoInfo
RepoInfo (Char -> Text -> Text
Text.cons Char
'@' Text
p)

pathCodebasePath :: Path -> [Text]
pathCodebasePath :: Path -> [Text]
pathCodebasePath (Path (Text
_ :| [Text]
ps)) = [Text]
ps

instance ToJSON Path where
  toJSON :: Path -> Value
toJSON (Path NonEmpty Text
segments) =
    [Pair] -> Value
object
      [ Key
"path" Key -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= NonEmpty Text
segments
      ]

instance FromJSON Path where
  parseJSON :: Value -> Parser Path
parseJSON = String -> (Object -> Parser Path) -> Value -> Parser Path
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Path" \Object
obj -> do
    NonEmpty Text
pathSegments <- Object
obj Object -> Key -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"path"
    pure Path {NonEmpty Text
$sel:pathSegments:Path :: NonEmpty Text
pathSegments :: NonEmpty Text
..}

------------------------------------------------------------------------------------------------------------------------
-- Entity types

data Entity text noSyncHash hash
  = TC (TermComponent text hash)
  | DC (DeclComponent text hash)
  | P (Patch text noSyncHash hash)
  | PD (PatchDiff text noSyncHash hash)
  | N (Namespace text hash)
  | ND (NamespaceDiff text hash)
  | C (Causal hash)
  deriving stock (Int -> Entity text noSyncHash hash -> ShowS
[Entity text noSyncHash hash] -> ShowS
Entity text noSyncHash hash -> String
(Int -> Entity text noSyncHash hash -> ShowS)
-> (Entity text noSyncHash hash -> String)
-> ([Entity text noSyncHash hash] -> ShowS)
-> Show (Entity text noSyncHash hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text noSyncHash hash.
(Show text, Show noSyncHash, Show hash) =>
Int -> Entity text noSyncHash hash -> ShowS
forall text noSyncHash hash.
(Show text, Show noSyncHash, Show hash) =>
[Entity text noSyncHash hash] -> ShowS
forall text noSyncHash hash.
(Show text, Show noSyncHash, Show hash) =>
Entity text noSyncHash hash -> String
$cshowsPrec :: forall text noSyncHash hash.
(Show text, Show noSyncHash, Show hash) =>
Int -> Entity text noSyncHash hash -> ShowS
showsPrec :: Int -> Entity text noSyncHash hash -> ShowS
$cshow :: forall text noSyncHash hash.
(Show text, Show noSyncHash, Show hash) =>
Entity text noSyncHash hash -> String
show :: Entity text noSyncHash hash -> String
$cshowList :: forall text noSyncHash hash.
(Show text, Show noSyncHash, Show hash) =>
[Entity text noSyncHash hash] -> ShowS
showList :: [Entity text noSyncHash hash] -> ShowS
Show, Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
(Entity text noSyncHash hash
 -> Entity text noSyncHash hash -> Bool)
-> (Entity text noSyncHash hash
    -> Entity text noSyncHash hash -> Bool)
-> Eq (Entity text noSyncHash hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text noSyncHash hash.
(Eq text, Eq noSyncHash, Eq hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
$c== :: forall text noSyncHash hash.
(Eq text, Eq noSyncHash, Eq hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
== :: Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
$c/= :: forall text noSyncHash hash.
(Eq text, Eq noSyncHash, Eq hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
/= :: Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
Eq, Eq (Entity text noSyncHash hash)
Eq (Entity text noSyncHash hash) =>
(Entity text noSyncHash hash
 -> Entity text noSyncHash hash -> Ordering)
-> (Entity text noSyncHash hash
    -> Entity text noSyncHash hash -> Bool)
-> (Entity text noSyncHash hash
    -> Entity text noSyncHash hash -> Bool)
-> (Entity text noSyncHash hash
    -> Entity text noSyncHash hash -> Bool)
-> (Entity text noSyncHash hash
    -> Entity text noSyncHash hash -> Bool)
-> (Entity text noSyncHash hash
    -> Entity text noSyncHash hash -> Entity text noSyncHash hash)
-> (Entity text noSyncHash hash
    -> Entity text noSyncHash hash -> Entity text noSyncHash hash)
-> Ord (Entity text noSyncHash hash)
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Ordering
Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Entity text noSyncHash hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Eq (Entity text noSyncHash hash)
forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Ordering
forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Entity text noSyncHash hash
$ccompare :: forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Ordering
compare :: Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Ordering
$c< :: forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
< :: Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
$c<= :: forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
<= :: Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
$c> :: forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
> :: Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
$c>= :: forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
>= :: Entity text noSyncHash hash -> Entity text noSyncHash hash -> Bool
$cmax :: forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Entity text noSyncHash hash
max :: Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Entity text noSyncHash hash
$cmin :: forall text noSyncHash hash.
(Ord text, Ord noSyncHash, Ord hash) =>
Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Entity text noSyncHash hash
min :: Entity text noSyncHash hash
-> Entity text noSyncHash hash -> Entity text noSyncHash hash
Ord)

instance (ToJSON text, ToJSON noSyncHash, ToJSON hash) => ToJSON (Entity text noSyncHash hash) where
  toJSON :: Entity text noSyncHash hash -> Value
toJSON = \case
    TC TermComponent text hash
tc -> EntityType -> TermComponent text hash -> Value
forall a. ToJSON a => EntityType -> a -> Value
go EntityType
TermComponentType TermComponent text hash
tc
    DC DeclComponent text hash
dc -> EntityType -> DeclComponent text hash -> Value
forall a. ToJSON a => EntityType -> a -> Value
go EntityType
DeclComponentType DeclComponent text hash
dc
    P Patch text noSyncHash hash
patch -> EntityType -> Patch text noSyncHash hash -> Value
forall a. ToJSON a => EntityType -> a -> Value
go EntityType
PatchType Patch text noSyncHash hash
patch
    PD PatchDiff text noSyncHash hash
patch -> EntityType -> PatchDiff text noSyncHash hash -> Value
forall a. ToJSON a => EntityType -> a -> Value
go EntityType
PatchDiffType PatchDiff text noSyncHash hash
patch
    N Namespace text hash
ns -> EntityType -> Namespace text hash -> Value
forall a. ToJSON a => EntityType -> a -> Value
go EntityType
NamespaceType Namespace text hash
ns
    ND NamespaceDiff text hash
ns -> EntityType -> NamespaceDiff text hash -> Value
forall a. ToJSON a => EntityType -> a -> Value
go EntityType
NamespaceDiffType NamespaceDiff text hash
ns
    C Causal hash
causal -> EntityType -> Causal hash -> Value
forall a. ToJSON a => EntityType -> a -> Value
go EntityType
CausalType Causal hash
causal
    where
      go :: (ToJSON a) => EntityType -> a -> Aeson.Value
      go :: forall a. ToJSON a => EntityType -> a -> Value
go EntityType
typ a
obj = [Pair] -> Value
object [Key
"type" Key -> EntityType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= EntityType
typ, Key
"object" Key -> a -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= a
obj]

instance (FromJSON text, FromJSON noSyncHash, FromJSON hash, Ord hash) => FromJSON (Entity text noSyncHash hash) where
  parseJSON :: Value -> Parser (Entity text noSyncHash hash)
parseJSON = String
-> (Object -> Parser (Entity text noSyncHash hash))
-> Value
-> Parser (Entity text noSyncHash hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Entity" \Object
obj ->
    Object
obj Object -> Key -> Parser EntityType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" Parser EntityType
-> (EntityType -> Parser (Entity text noSyncHash hash))
-> Parser (Entity text noSyncHash hash)
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      EntityType
TermComponentType -> TermComponent text hash -> Entity text noSyncHash hash
forall text noSyncHash hash.
TermComponent text hash -> Entity text noSyncHash hash
TC (TermComponent text hash -> Entity text noSyncHash hash)
-> Parser (TermComponent text hash)
-> Parser (Entity text noSyncHash hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (TermComponent text hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"object"
      EntityType
DeclComponentType -> DeclComponent text hash -> Entity text noSyncHash hash
forall text noSyncHash hash.
DeclComponent text hash -> Entity text noSyncHash hash
DC (DeclComponent text hash -> Entity text noSyncHash hash)
-> Parser (DeclComponent text hash)
-> Parser (Entity text noSyncHash hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (DeclComponent text hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"object"
      EntityType
PatchType -> Patch text noSyncHash hash -> Entity text noSyncHash hash
forall text noSyncHash hash.
Patch text noSyncHash hash -> Entity text noSyncHash hash
P (Patch text noSyncHash hash -> Entity text noSyncHash hash)
-> Parser (Patch text noSyncHash hash)
-> Parser (Entity text noSyncHash hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Patch text noSyncHash hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"object"
      EntityType
PatchDiffType -> PatchDiff text noSyncHash hash -> Entity text noSyncHash hash
forall text noSyncHash hash.
PatchDiff text noSyncHash hash -> Entity text noSyncHash hash
PD (PatchDiff text noSyncHash hash -> Entity text noSyncHash hash)
-> Parser (PatchDiff text noSyncHash hash)
-> Parser (Entity text noSyncHash hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (PatchDiff text noSyncHash hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"object"
      EntityType
NamespaceType -> Namespace text hash -> Entity text noSyncHash hash
forall text noSyncHash hash.
Namespace text hash -> Entity text noSyncHash hash
N (Namespace text hash -> Entity text noSyncHash hash)
-> Parser (Namespace text hash)
-> Parser (Entity text noSyncHash hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Namespace text hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"object"
      EntityType
NamespaceDiffType -> NamespaceDiff text hash -> Entity text noSyncHash hash
forall text noSyncHash hash.
NamespaceDiff text hash -> Entity text noSyncHash hash
ND (NamespaceDiff text hash -> Entity text noSyncHash hash)
-> Parser (NamespaceDiff text hash)
-> Parser (Entity text noSyncHash hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (NamespaceDiff text hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"object"
      EntityType
CausalType -> Causal hash -> Entity text noSyncHash hash
forall text noSyncHash hash.
Causal hash -> Entity text noSyncHash hash
C (Causal hash -> Entity text noSyncHash hash)
-> Parser (Causal hash) -> Parser (Entity text noSyncHash hash)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Causal hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"object"

entityHashes_ :: (Applicative m, Ord hash') => (hash -> m hash') -> Entity text noSyncHash hash -> m (Entity text noSyncHash hash')
entityHashes_ :: forall (m :: * -> *) hash' hash text noSyncHash.
(Applicative m, Ord hash') =>
(hash -> m hash')
-> Entity text noSyncHash hash -> m (Entity text noSyncHash hash')
entityHashes_ hash -> m hash'
f = \case
  TC TermComponent text hash
tc -> TermComponent text hash' -> Entity text noSyncHash hash'
forall text noSyncHash hash.
TermComponent text hash -> Entity text noSyncHash hash
TC (TermComponent text hash' -> Entity text noSyncHash hash')
-> m (TermComponent text hash') -> m (Entity text noSyncHash hash')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (text -> m text)
-> (hash -> m hash')
-> TermComponent text hash
-> m (TermComponent text hash')
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c)
-> (b -> f d) -> TermComponent a b -> f (TermComponent c d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse text -> m text
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure hash -> m hash'
f TermComponent text hash
tc
  DC DeclComponent text hash
dc -> DeclComponent text hash' -> Entity text noSyncHash hash'
forall text noSyncHash hash.
DeclComponent text hash -> Entity text noSyncHash hash
DC (DeclComponent text hash' -> Entity text noSyncHash hash')
-> m (DeclComponent text hash') -> m (Entity text noSyncHash hash')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (text -> m text)
-> (hash -> m hash')
-> DeclComponent text hash
-> m (DeclComponent text hash')
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c)
-> (b -> f d) -> DeclComponent a b -> f (DeclComponent c d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse text -> m text
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure hash -> m hash'
f DeclComponent text hash
dc
  P Patch text noSyncHash hash
patch -> Patch text noSyncHash hash' -> Entity text noSyncHash hash'
forall text noSyncHash hash.
Patch text noSyncHash hash -> Entity text noSyncHash hash
P (Patch text noSyncHash hash' -> Entity text noSyncHash hash')
-> m (Patch text noSyncHash hash')
-> m (Entity text noSyncHash hash')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (hash -> m hash')
-> Patch text noSyncHash hash -> m (Patch text noSyncHash hash')
forall (m :: * -> *) newHash newHash' text oldHash.
Applicative m =>
(newHash -> m newHash')
-> Patch text oldHash newHash -> m (Patch text oldHash newHash')
patchNewHashes_ hash -> m hash'
f Patch text noSyncHash hash
patch
  PD PatchDiff text noSyncHash hash
patch -> PatchDiff text noSyncHash hash' -> Entity text noSyncHash hash'
forall text noSyncHash hash.
PatchDiff text noSyncHash hash -> Entity text noSyncHash hash
PD (PatchDiff text noSyncHash hash' -> Entity text noSyncHash hash')
-> m (PatchDiff text noSyncHash hash')
-> m (Entity text noSyncHash hash')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (hash -> m hash')
-> PatchDiff text noSyncHash hash
-> m (PatchDiff text noSyncHash hash')
forall (m :: * -> *) hash hash' text noSyncHash.
Applicative m =>
(hash -> m hash')
-> PatchDiff text noSyncHash hash
-> m (PatchDiff text noSyncHash hash')
patchDiffHashes_ hash -> m hash'
f PatchDiff text noSyncHash hash
patch
  N Namespace text hash
ns -> Namespace text hash' -> Entity text noSyncHash hash'
forall text noSyncHash hash.
Namespace text hash -> Entity text noSyncHash hash
N (Namespace text hash' -> Entity text noSyncHash hash')
-> m (Namespace text hash') -> m (Entity text noSyncHash hash')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (text -> m text)
-> (hash -> m hash')
-> Namespace text hash
-> m (Namespace text hash')
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Namespace a b -> f (Namespace c d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse text -> m text
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure hash -> m hash'
f Namespace text hash
ns
  ND NamespaceDiff text hash
ns -> NamespaceDiff text hash' -> Entity text noSyncHash hash'
forall text noSyncHash hash.
NamespaceDiff text hash -> Entity text noSyncHash hash
ND (NamespaceDiff text hash' -> Entity text noSyncHash hash')
-> m (NamespaceDiff text hash') -> m (Entity text noSyncHash hash')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (hash -> m hash')
-> NamespaceDiff text hash -> m (NamespaceDiff text hash')
forall (m :: * -> *) hash hash' text.
Applicative m =>
(hash -> m hash')
-> NamespaceDiff text hash -> m (NamespaceDiff text hash')
namespaceDiffHashes_ hash -> m hash'
f NamespaceDiff text hash
ns
  C Causal hash
causal -> Causal hash' -> Entity text noSyncHash hash'
forall text noSyncHash hash.
Causal hash -> Entity text noSyncHash hash
C (Causal hash' -> Entity text noSyncHash hash')
-> m (Causal hash') -> m (Entity text noSyncHash hash')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (hash -> m hash') -> Causal hash -> m (Causal hash')
forall (m :: * -> *) hash' hash.
(Applicative m, Ord hash') =>
(hash -> m hash') -> Causal hash -> m (Causal hash')
causalHashes_ hash -> m hash'
f Causal hash
causal

-- | Get the direct dependencies of an entity (which are actually sync'd).
--
-- FIXME use generic-lens here? (typed @hash)
entityDependencies :: (Ord hash) => Entity text noSyncHash hash -> Set hash
entityDependencies :: forall hash text noSyncHash.
Ord hash =>
Entity text noSyncHash hash -> Set hash
entityDependencies = \case
  TC (TermComponent [(LocalIds text hash, ByteString)]
terms) -> (((LocalIds text hash, ByteString) -> Set hash)
 -> [(LocalIds text hash, ByteString)] -> Set hash)
-> [(LocalIds text hash, ByteString)]
-> ((LocalIds text hash, ByteString) -> Set hash)
-> Set hash
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((LocalIds text hash, ByteString) -> Set hash)
-> [(LocalIds text hash, ByteString)] -> Set hash
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap [(LocalIds text hash, ByteString)]
terms \(LocalIds {[hash]
hashes :: [hash]
$sel:hashes:LocalIds :: forall text hash. LocalIds text hash -> [hash]
hashes}, ByteString
_term) -> [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
hashes
  DC (DeclComponent [(LocalIds text hash, ByteString)]
decls) -> (((LocalIds text hash, ByteString) -> Set hash)
 -> [(LocalIds text hash, ByteString)] -> Set hash)
-> [(LocalIds text hash, ByteString)]
-> ((LocalIds text hash, ByteString) -> Set hash)
-> Set hash
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((LocalIds text hash, ByteString) -> Set hash)
-> [(LocalIds text hash, ByteString)] -> Set hash
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap [(LocalIds text hash, ByteString)]
decls \(LocalIds {[hash]
$sel:hashes:LocalIds :: forall text hash. LocalIds text hash -> [hash]
hashes :: [hash]
hashes}, ByteString
_decl) -> [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
hashes
  P Patch {[hash]
newHashLookup :: [hash]
$sel:newHashLookup:Patch :: forall text oldHash newHash.
Patch text oldHash newHash -> [newHash]
newHashLookup} -> [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
newHashLookup
  PD PatchDiff {hash
parent :: hash
$sel:parent:PatchDiff :: forall text oldHash hash. PatchDiff text oldHash hash -> hash
parent, [hash]
newHashLookup :: [hash]
$sel:newHashLookup:PatchDiff :: forall text oldHash hash. PatchDiff text oldHash hash -> [hash]
newHashLookup} -> hash -> Set hash -> Set hash
forall a. Ord a => a -> Set a -> Set a
Set.insert hash
parent ([hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
newHashLookup)
  N Namespace {[hash]
defnLookup :: [hash]
$sel:defnLookup:Namespace :: forall text hash. Namespace text hash -> [hash]
defnLookup, [hash]
patchLookup :: [hash]
$sel:patchLookup:Namespace :: forall text hash. Namespace text hash -> [hash]
patchLookup, [(hash, hash)]
childLookup :: [(hash, hash)]
$sel:childLookup:Namespace :: forall text hash. Namespace text hash -> [(hash, hash)]
childLookup} ->
    [Set hash] -> Set hash
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
      [ [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
defnLookup,
        [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
patchLookup,
        ((hash, hash) -> Set hash) -> [(hash, hash)] -> Set hash
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(hash
namespaceHash, hash
causalHash) -> [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash
namespaceHash, hash
causalHash]) [(hash, hash)]
childLookup
      ]
  ND NamespaceDiff {hash
parent :: hash
$sel:parent:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> hash
parent, [hash]
defnLookup :: [hash]
$sel:defnLookup:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> [hash]
defnLookup, [hash]
patchLookup :: [hash]
$sel:patchLookup:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> [hash]
patchLookup, [(hash, hash)]
childLookup :: [(hash, hash)]
$sel:childLookup:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> [(hash, hash)]
childLookup} ->
    [Set hash] -> Set hash
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions
      [ hash -> Set hash
forall a. a -> Set a
Set.singleton hash
parent,
        [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
defnLookup,
        [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash]
patchLookup,
        ((hash, hash) -> Set hash) -> [(hash, hash)] -> Set hash
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(hash
namespaceHash, hash
causalHash) -> [hash] -> Set hash
forall a. Ord a => [a] -> Set a
Set.fromList [hash
namespaceHash, hash
causalHash]) [(hash, hash)]
childLookup
      ]
  C Causal {hash
namespaceHash :: hash
$sel:namespaceHash:Causal :: forall hash. Causal hash -> hash
namespaceHash, Set hash
parents :: Set hash
$sel:parents:Causal :: forall hash. Causal hash -> Set hash
parents} -> hash -> Set hash -> Set hash
forall a. Ord a => a -> Set a -> Set a
Set.insert hash
namespaceHash Set hash
parents

data TermComponent text hash = TermComponent [(LocalIds text hash, ByteString)]
  deriving stock (Int -> TermComponent text hash -> ShowS
[TermComponent text hash] -> ShowS
TermComponent text hash -> String
(Int -> TermComponent text hash -> ShowS)
-> (TermComponent text hash -> String)
-> ([TermComponent text hash] -> ShowS)
-> Show (TermComponent text hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text hash.
(Show text, Show hash) =>
Int -> TermComponent text hash -> ShowS
forall text hash.
(Show text, Show hash) =>
[TermComponent text hash] -> ShowS
forall text hash.
(Show text, Show hash) =>
TermComponent text hash -> String
$cshowsPrec :: forall text hash.
(Show text, Show hash) =>
Int -> TermComponent text hash -> ShowS
showsPrec :: Int -> TermComponent text hash -> ShowS
$cshow :: forall text hash.
(Show text, Show hash) =>
TermComponent text hash -> String
show :: TermComponent text hash -> String
$cshowList :: forall text hash.
(Show text, Show hash) =>
[TermComponent text hash] -> ShowS
showList :: [TermComponent text hash] -> ShowS
Show, TermComponent text hash -> TermComponent text hash -> Bool
(TermComponent text hash -> TermComponent text hash -> Bool)
-> (TermComponent text hash -> TermComponent text hash -> Bool)
-> Eq (TermComponent text hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text hash.
(Eq text, Eq hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
$c== :: forall text hash.
(Eq text, Eq hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
== :: TermComponent text hash -> TermComponent text hash -> Bool
$c/= :: forall text hash.
(Eq text, Eq hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
/= :: TermComponent text hash -> TermComponent text hash -> Bool
Eq, (forall a b.
 (a -> b) -> TermComponent text a -> TermComponent text b)
-> (forall a b. a -> TermComponent text b -> TermComponent text a)
-> Functor (TermComponent text)
forall a b. a -> TermComponent text b -> TermComponent text a
forall a b.
(a -> b) -> TermComponent text a -> TermComponent text b
forall text a b. a -> TermComponent text b -> TermComponent text a
forall text a b.
(a -> b) -> TermComponent text a -> TermComponent text b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall text a b.
(a -> b) -> TermComponent text a -> TermComponent text b
fmap :: forall a b.
(a -> b) -> TermComponent text a -> TermComponent text b
$c<$ :: forall text a b. a -> TermComponent text b -> TermComponent text a
<$ :: forall a b. a -> TermComponent text b -> TermComponent text a
Functor, Eq (TermComponent text hash)
Eq (TermComponent text hash) =>
(TermComponent text hash -> TermComponent text hash -> Ordering)
-> (TermComponent text hash -> TermComponent text hash -> Bool)
-> (TermComponent text hash -> TermComponent text hash -> Bool)
-> (TermComponent text hash -> TermComponent text hash -> Bool)
-> (TermComponent text hash -> TermComponent text hash -> Bool)
-> (TermComponent text hash
    -> TermComponent text hash -> TermComponent text hash)
-> (TermComponent text hash
    -> TermComponent text hash -> TermComponent text hash)
-> Ord (TermComponent text hash)
TermComponent text hash -> TermComponent text hash -> Bool
TermComponent text hash -> TermComponent text hash -> Ordering
TermComponent text hash
-> TermComponent text hash -> TermComponent text hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text hash.
(Ord text, Ord hash) =>
Eq (TermComponent text hash)
forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash -> TermComponent text hash -> Ordering
forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash
-> TermComponent text hash -> TermComponent text hash
$ccompare :: forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash -> TermComponent text hash -> Ordering
compare :: TermComponent text hash -> TermComponent text hash -> Ordering
$c< :: forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
< :: TermComponent text hash -> TermComponent text hash -> Bool
$c<= :: forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
<= :: TermComponent text hash -> TermComponent text hash -> Bool
$c> :: forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
> :: TermComponent text hash -> TermComponent text hash -> Bool
$c>= :: forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash -> TermComponent text hash -> Bool
>= :: TermComponent text hash -> TermComponent text hash -> Bool
$cmax :: forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash
-> TermComponent text hash -> TermComponent text hash
max :: TermComponent text hash
-> TermComponent text hash -> TermComponent text hash
$cmin :: forall text hash.
(Ord text, Ord hash) =>
TermComponent text hash
-> TermComponent text hash -> TermComponent text hash
min :: TermComponent text hash
-> TermComponent text hash -> TermComponent text hash
Ord)

instance Bifoldable TermComponent where
  bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> TermComponent a b -> m
bifoldMap = (a -> m) -> (b -> m) -> TermComponent a b -> m
forall (t :: * -> * -> *) m a b.
(Bitraversable t, Monoid m) =>
(a -> m) -> (b -> m) -> t a b -> m
bifoldMapDefault

instance Bifunctor TermComponent where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> TermComponent a c -> TermComponent b d
bimap = (a -> b) -> (c -> d) -> TermComponent a c -> TermComponent b d
forall (t :: * -> * -> *) a b c d.
Bitraversable t =>
(a -> b) -> (c -> d) -> t a c -> t b d
bimapDefault

instance Bitraversable TermComponent where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c)
-> (b -> f d) -> TermComponent a b -> f (TermComponent c d)
bitraverse a -> f c
f b -> f d
g (TermComponent [(LocalIds a b, ByteString)]
xs) =
    [(LocalIds c d, ByteString)] -> TermComponent c d
forall text hash.
[(LocalIds text hash, ByteString)] -> TermComponent text hash
TermComponent ([(LocalIds c d, ByteString)] -> TermComponent c d)
-> f [(LocalIds c d, ByteString)] -> f (TermComponent c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f c)
-> (b -> f d)
-> [(LocalIds a b, ByteString)]
-> f [(LocalIds c d, ByteString)]
forall (f :: * -> *) a a' b b'.
Applicative f =>
(a -> f a')
-> (b -> f b')
-> [(LocalIds a b, ByteString)]
-> f [(LocalIds a' b', ByteString)]
bitraverseComponents a -> f c
f b -> f d
g [(LocalIds a b, ByteString)]
xs

instance (ToJSON text, ToJSON hash) => ToJSON (TermComponent text hash) where
  toJSON :: TermComponent text hash -> Value
toJSON (TermComponent [(LocalIds text hash, ByteString)]
components) =
    [Pair] -> Value
object
      [ Key
"terms" Key -> [Value] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= ((LocalIds text hash, ByteString) -> Value
forall text hash.
(ToJSON text, ToJSON hash) =>
(LocalIds text hash, ByteString) -> Value
encodeComponentPiece ((LocalIds text hash, ByteString) -> Value)
-> [(LocalIds text hash, ByteString)] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(LocalIds text hash, ByteString)]
components)
      ]

instance (FromJSON text, FromJSON hash) => FromJSON (TermComponent text hash) where
  parseJSON :: Value -> Parser (TermComponent text hash)
parseJSON = String
-> (Object -> Parser (TermComponent text hash))
-> Value
-> Parser (TermComponent text hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"TermComponent" \Object
obj -> do
    [Value]
pieces <- Object
obj Object -> Key -> Parser [Value]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"terms"
    [(LocalIds text hash, ByteString)]
terms <- (Value -> Parser (LocalIds text hash, ByteString))
-> [Value] -> Parser [(LocalIds text hash, ByteString)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Value -> Parser (LocalIds text hash, ByteString)
forall text hash.
(FromJSON text, FromJSON hash) =>
Value -> Parser (LocalIds text hash, ByteString)
decodeComponentPiece [Value]
pieces
    pure ([(LocalIds text hash, ByteString)] -> TermComponent text hash
forall text hash.
[(LocalIds text hash, ByteString)] -> TermComponent text hash
TermComponent [(LocalIds text hash, ByteString)]
terms)

bitraverseComponents ::
  (Applicative f) =>
  (a -> f a') ->
  (b -> f b') ->
  [(LocalIds a b, ByteString)] ->
  f [(LocalIds a' b', ByteString)]
bitraverseComponents :: forall (f :: * -> *) a a' b b'.
Applicative f =>
(a -> f a')
-> (b -> f b')
-> [(LocalIds a b, ByteString)]
-> f [(LocalIds a' b', ByteString)]
bitraverseComponents a -> f a'
f b -> f b'
g =
  ((LocalIds a b, ByteString) -> f (LocalIds a' b', ByteString))
-> [(LocalIds a b, ByteString)] -> f [(LocalIds a' b', ByteString)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (((LocalIds a b, ByteString) -> f (LocalIds a' b', ByteString))
 -> [(LocalIds a b, ByteString)]
 -> f [(LocalIds a' b', ByteString)])
-> ((LocalIds a b -> f (LocalIds a' b'))
    -> (LocalIds a b, ByteString) -> f (LocalIds a' b', ByteString))
-> (LocalIds a b -> f (LocalIds a' b'))
-> [(LocalIds a b, ByteString)]
-> f [(LocalIds a' b', ByteString)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LocalIds a b -> f (LocalIds a' b'))
-> (LocalIds a b, ByteString) -> f (LocalIds a' b', ByteString)
forall {f :: * -> *} {t} {a} {t}.
Functor f =>
(t -> f a) -> (t, t) -> f (a, t)
_1 ((LocalIds a b -> f (LocalIds a' b'))
 -> [(LocalIds a b, ByteString)]
 -> f [(LocalIds a' b', ByteString)])
-> (LocalIds a b -> f (LocalIds a' b'))
-> [(LocalIds a b, ByteString)]
-> f [(LocalIds a' b', ByteString)]
forall a b. (a -> b) -> a -> b
$ (a -> f a') -> (b -> f b') -> LocalIds a b -> f (LocalIds a' b')
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> LocalIds a b -> f (LocalIds c d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse a -> f a'
f b -> f b'
g
  where
    _1 :: (t -> f a) -> (t, t) -> f (a, t)
_1 t -> f a
f (t
l, t
r) = (,t
r) (a -> (a, t)) -> f a -> f (a, t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t -> f a
f t
l

encodeComponentPiece :: (ToJSON text, ToJSON hash) => (LocalIds text hash, ByteString) -> Value
encodeComponentPiece :: forall text hash.
(ToJSON text, ToJSON hash) =>
(LocalIds text hash, ByteString) -> Value
encodeComponentPiece (LocalIds text hash
localIDs, ByteString
bytes) =
  [Pair] -> Value
object
    [ Key
"local_ids" Key -> LocalIds text hash -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= LocalIds text hash
localIDs,
      Key
"bytes" Key -> Base64Bytes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= ByteString -> Base64Bytes
Base64Bytes ByteString
bytes
    ]

decodeComponentPiece :: (FromJSON text, FromJSON hash) => Value -> Aeson.Parser (LocalIds text hash, ByteString)
decodeComponentPiece :: forall text hash.
(FromJSON text, FromJSON hash) =>
Value -> Parser (LocalIds text hash, ByteString)
decodeComponentPiece = String
-> (Object -> Parser (LocalIds text hash, ByteString))
-> Value
-> Parser (LocalIds text hash, ByteString)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Component Piece" \Object
obj -> do
  LocalIds text hash
localIDs <- Object
obj Object -> Key -> Parser (LocalIds text hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"local_ids"
  Base64Bytes ByteString
bytes <- Object
obj Object -> Key -> Parser Base64Bytes
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"bytes"
  (LocalIds text hash, ByteString)
-> Parser (LocalIds text hash, ByteString)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LocalIds text hash
localIDs, ByteString
bytes)

data DeclComponent text hash = DeclComponent [(LocalIds text hash, ByteString)]
  deriving stock (Int -> DeclComponent text hash -> ShowS
[DeclComponent text hash] -> ShowS
DeclComponent text hash -> String
(Int -> DeclComponent text hash -> ShowS)
-> (DeclComponent text hash -> String)
-> ([DeclComponent text hash] -> ShowS)
-> Show (DeclComponent text hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text hash.
(Show text, Show hash) =>
Int -> DeclComponent text hash -> ShowS
forall text hash.
(Show text, Show hash) =>
[DeclComponent text hash] -> ShowS
forall text hash.
(Show text, Show hash) =>
DeclComponent text hash -> String
$cshowsPrec :: forall text hash.
(Show text, Show hash) =>
Int -> DeclComponent text hash -> ShowS
showsPrec :: Int -> DeclComponent text hash -> ShowS
$cshow :: forall text hash.
(Show text, Show hash) =>
DeclComponent text hash -> String
show :: DeclComponent text hash -> String
$cshowList :: forall text hash.
(Show text, Show hash) =>
[DeclComponent text hash] -> ShowS
showList :: [DeclComponent text hash] -> ShowS
Show, DeclComponent text hash -> DeclComponent text hash -> Bool
(DeclComponent text hash -> DeclComponent text hash -> Bool)
-> (DeclComponent text hash -> DeclComponent text hash -> Bool)
-> Eq (DeclComponent text hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text hash.
(Eq text, Eq hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
$c== :: forall text hash.
(Eq text, Eq hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
== :: DeclComponent text hash -> DeclComponent text hash -> Bool
$c/= :: forall text hash.
(Eq text, Eq hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
/= :: DeclComponent text hash -> DeclComponent text hash -> Bool
Eq, (forall a b.
 (a -> b) -> DeclComponent text a -> DeclComponent text b)
-> (forall a b. a -> DeclComponent text b -> DeclComponent text a)
-> Functor (DeclComponent text)
forall a b. a -> DeclComponent text b -> DeclComponent text a
forall a b.
(a -> b) -> DeclComponent text a -> DeclComponent text b
forall text a b. a -> DeclComponent text b -> DeclComponent text a
forall text a b.
(a -> b) -> DeclComponent text a -> DeclComponent text b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall text a b.
(a -> b) -> DeclComponent text a -> DeclComponent text b
fmap :: forall a b.
(a -> b) -> DeclComponent text a -> DeclComponent text b
$c<$ :: forall text a b. a -> DeclComponent text b -> DeclComponent text a
<$ :: forall a b. a -> DeclComponent text b -> DeclComponent text a
Functor, Eq (DeclComponent text hash)
Eq (DeclComponent text hash) =>
(DeclComponent text hash -> DeclComponent text hash -> Ordering)
-> (DeclComponent text hash -> DeclComponent text hash -> Bool)
-> (DeclComponent text hash -> DeclComponent text hash -> Bool)
-> (DeclComponent text hash -> DeclComponent text hash -> Bool)
-> (DeclComponent text hash -> DeclComponent text hash -> Bool)
-> (DeclComponent text hash
    -> DeclComponent text hash -> DeclComponent text hash)
-> (DeclComponent text hash
    -> DeclComponent text hash -> DeclComponent text hash)
-> Ord (DeclComponent text hash)
DeclComponent text hash -> DeclComponent text hash -> Bool
DeclComponent text hash -> DeclComponent text hash -> Ordering
DeclComponent text hash
-> DeclComponent text hash -> DeclComponent text hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text hash.
(Ord text, Ord hash) =>
Eq (DeclComponent text hash)
forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash -> DeclComponent text hash -> Ordering
forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash
-> DeclComponent text hash -> DeclComponent text hash
$ccompare :: forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash -> DeclComponent text hash -> Ordering
compare :: DeclComponent text hash -> DeclComponent text hash -> Ordering
$c< :: forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
< :: DeclComponent text hash -> DeclComponent text hash -> Bool
$c<= :: forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
<= :: DeclComponent text hash -> DeclComponent text hash -> Bool
$c> :: forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
> :: DeclComponent text hash -> DeclComponent text hash -> Bool
$c>= :: forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash -> DeclComponent text hash -> Bool
>= :: DeclComponent text hash -> DeclComponent text hash -> Bool
$cmax :: forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash
-> DeclComponent text hash -> DeclComponent text hash
max :: DeclComponent text hash
-> DeclComponent text hash -> DeclComponent text hash
$cmin :: forall text hash.
(Ord text, Ord hash) =>
DeclComponent text hash
-> DeclComponent text hash -> DeclComponent text hash
min :: DeclComponent text hash
-> DeclComponent text hash -> DeclComponent text hash
Ord)

instance Bifoldable DeclComponent where
  bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> DeclComponent a b -> m
bifoldMap = (a -> m) -> (b -> m) -> DeclComponent a b -> m
forall (t :: * -> * -> *) m a b.
(Bitraversable t, Monoid m) =>
(a -> m) -> (b -> m) -> t a b -> m
bifoldMapDefault

instance Bifunctor DeclComponent where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> DeclComponent a c -> DeclComponent b d
bimap = (a -> b) -> (c -> d) -> DeclComponent a c -> DeclComponent b d
forall (t :: * -> * -> *) a b c d.
Bitraversable t =>
(a -> b) -> (c -> d) -> t a c -> t b d
bimapDefault

instance Bitraversable DeclComponent where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c)
-> (b -> f d) -> DeclComponent a b -> f (DeclComponent c d)
bitraverse a -> f c
f b -> f d
g (DeclComponent [(LocalIds a b, ByteString)]
xs) =
    [(LocalIds c d, ByteString)] -> DeclComponent c d
forall text hash.
[(LocalIds text hash, ByteString)] -> DeclComponent text hash
DeclComponent ([(LocalIds c d, ByteString)] -> DeclComponent c d)
-> f [(LocalIds c d, ByteString)] -> f (DeclComponent c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f c)
-> (b -> f d)
-> [(LocalIds a b, ByteString)]
-> f [(LocalIds c d, ByteString)]
forall (f :: * -> *) a a' b b'.
Applicative f =>
(a -> f a')
-> (b -> f b')
-> [(LocalIds a b, ByteString)]
-> f [(LocalIds a' b', ByteString)]
bitraverseComponents a -> f c
f b -> f d
g [(LocalIds a b, ByteString)]
xs

instance (ToJSON text, ToJSON hash) => ToJSON (DeclComponent text hash) where
  toJSON :: DeclComponent text hash -> Value
toJSON (DeclComponent [(LocalIds text hash, ByteString)]
components) =
    [Pair] -> Value
object
      [ Key
"decls" Key -> [Value] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= ((LocalIds text hash, ByteString) -> Value
forall text hash.
(ToJSON text, ToJSON hash) =>
(LocalIds text hash, ByteString) -> Value
encodeComponentPiece ((LocalIds text hash, ByteString) -> Value)
-> [(LocalIds text hash, ByteString)] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(LocalIds text hash, ByteString)]
components)
      ]

instance (FromJSON text, FromJSON hash) => FromJSON (DeclComponent text hash) where
  parseJSON :: Value -> Parser (DeclComponent text hash)
parseJSON = String
-> (Object -> Parser (DeclComponent text hash))
-> Value
-> Parser (DeclComponent text hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"DeclComponent" \Object
obj -> do
    [Value]
pieces <- Object
obj Object -> Key -> Parser [Value]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"decls"
    [(LocalIds text hash, ByteString)]
terms <- (Value -> Parser (LocalIds text hash, ByteString))
-> [Value] -> Parser [(LocalIds text hash, ByteString)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Value -> Parser (LocalIds text hash, ByteString)
forall text hash.
(FromJSON text, FromJSON hash) =>
Value -> Parser (LocalIds text hash, ByteString)
decodeComponentPiece [Value]
pieces
    pure ([(LocalIds text hash, ByteString)] -> DeclComponent text hash
forall text hash.
[(LocalIds text hash, ByteString)] -> DeclComponent text hash
DeclComponent [(LocalIds text hash, ByteString)]
terms)

data LocalIds text hash = LocalIds
  { forall text hash. LocalIds text hash -> [text]
texts :: [text],
    forall text hash. LocalIds text hash -> [hash]
hashes :: [hash]
  }
  deriving stock (Int -> LocalIds text hash -> ShowS
[LocalIds text hash] -> ShowS
LocalIds text hash -> String
(Int -> LocalIds text hash -> ShowS)
-> (LocalIds text hash -> String)
-> ([LocalIds text hash] -> ShowS)
-> Show (LocalIds text hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text hash.
(Show text, Show hash) =>
Int -> LocalIds text hash -> ShowS
forall text hash.
(Show text, Show hash) =>
[LocalIds text hash] -> ShowS
forall text hash.
(Show text, Show hash) =>
LocalIds text hash -> String
$cshowsPrec :: forall text hash.
(Show text, Show hash) =>
Int -> LocalIds text hash -> ShowS
showsPrec :: Int -> LocalIds text hash -> ShowS
$cshow :: forall text hash.
(Show text, Show hash) =>
LocalIds text hash -> String
show :: LocalIds text hash -> String
$cshowList :: forall text hash.
(Show text, Show hash) =>
[LocalIds text hash] -> ShowS
showList :: [LocalIds text hash] -> ShowS
Show, LocalIds text hash -> LocalIds text hash -> Bool
(LocalIds text hash -> LocalIds text hash -> Bool)
-> (LocalIds text hash -> LocalIds text hash -> Bool)
-> Eq (LocalIds text hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text hash.
(Eq text, Eq hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
$c== :: forall text hash.
(Eq text, Eq hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
== :: LocalIds text hash -> LocalIds text hash -> Bool
$c/= :: forall text hash.
(Eq text, Eq hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
/= :: LocalIds text hash -> LocalIds text hash -> Bool
Eq, (forall a b. (a -> b) -> LocalIds text a -> LocalIds text b)
-> (forall a b. a -> LocalIds text b -> LocalIds text a)
-> Functor (LocalIds text)
forall a b. a -> LocalIds text b -> LocalIds text a
forall a b. (a -> b) -> LocalIds text a -> LocalIds text b
forall text a b. a -> LocalIds text b -> LocalIds text a
forall text a b. (a -> b) -> LocalIds text a -> LocalIds text b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall text a b. (a -> b) -> LocalIds text a -> LocalIds text b
fmap :: forall a b. (a -> b) -> LocalIds text a -> LocalIds text b
$c<$ :: forall text a b. a -> LocalIds text b -> LocalIds text a
<$ :: forall a b. a -> LocalIds text b -> LocalIds text a
Functor, Eq (LocalIds text hash)
Eq (LocalIds text hash) =>
(LocalIds text hash -> LocalIds text hash -> Ordering)
-> (LocalIds text hash -> LocalIds text hash -> Bool)
-> (LocalIds text hash -> LocalIds text hash -> Bool)
-> (LocalIds text hash -> LocalIds text hash -> Bool)
-> (LocalIds text hash -> LocalIds text hash -> Bool)
-> (LocalIds text hash -> LocalIds text hash -> LocalIds text hash)
-> (LocalIds text hash -> LocalIds text hash -> LocalIds text hash)
-> Ord (LocalIds text hash)
LocalIds text hash -> LocalIds text hash -> Bool
LocalIds text hash -> LocalIds text hash -> Ordering
LocalIds text hash -> LocalIds text hash -> LocalIds text hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text hash. (Ord text, Ord hash) => Eq (LocalIds text hash)
forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> Ordering
forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> LocalIds text hash
$ccompare :: forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> Ordering
compare :: LocalIds text hash -> LocalIds text hash -> Ordering
$c< :: forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
< :: LocalIds text hash -> LocalIds text hash -> Bool
$c<= :: forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
<= :: LocalIds text hash -> LocalIds text hash -> Bool
$c> :: forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
> :: LocalIds text hash -> LocalIds text hash -> Bool
$c>= :: forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> Bool
>= :: LocalIds text hash -> LocalIds text hash -> Bool
$cmax :: forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> LocalIds text hash
max :: LocalIds text hash -> LocalIds text hash -> LocalIds text hash
$cmin :: forall text hash.
(Ord text, Ord hash) =>
LocalIds text hash -> LocalIds text hash -> LocalIds text hash
min :: LocalIds text hash -> LocalIds text hash -> LocalIds text hash
Ord)

instance Bifoldable LocalIds where
  bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> LocalIds a b -> m
bifoldMap = (a -> m) -> (b -> m) -> LocalIds a b -> m
forall (t :: * -> * -> *) m a b.
(Bitraversable t, Monoid m) =>
(a -> m) -> (b -> m) -> t a b -> m
bifoldMapDefault

instance Bifunctor LocalIds where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> LocalIds a c -> LocalIds b d
bimap = (a -> b) -> (c -> d) -> LocalIds a c -> LocalIds b d
forall (t :: * -> * -> *) a b c d.
Bitraversable t =>
(a -> b) -> (c -> d) -> t a c -> t b d
bimapDefault

instance Bitraversable LocalIds where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> LocalIds a b -> f (LocalIds c d)
bitraverse a -> f c
f b -> f d
g (LocalIds [a]
texts [b]
hashes) =
    [c] -> [d] -> LocalIds c d
forall text hash. [text] -> [hash] -> LocalIds text hash
LocalIds ([c] -> [d] -> LocalIds c d) -> f [c] -> f ([d] -> LocalIds c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f c) -> [a] -> f [c]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse a -> f c
f [a]
texts f ([d] -> LocalIds c d) -> f [d] -> f (LocalIds c d)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (b -> f d) -> [b] -> f [d]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse b -> f d
g [b]
hashes

instance (ToJSON text, ToJSON hash) => ToJSON (LocalIds text hash) where
  toJSON :: LocalIds text hash -> Value
toJSON (LocalIds [text]
texts [hash]
hashes) =
    [Pair] -> Value
object
      [ Key
"texts" Key -> [text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [text]
texts,
        Key
"hashes" Key -> [hash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [hash]
hashes
      ]

instance (FromJSON text, FromJSON hash) => FromJSON (LocalIds text hash) where
  parseJSON :: Value -> Parser (LocalIds text hash)
parseJSON = String
-> (Object -> Parser (LocalIds text hash))
-> Value
-> Parser (LocalIds text hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"LocalIds" \Object
obj -> do
    [text]
texts <- Object
obj Object -> Key -> Parser [text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"texts"
    [hash]
hashes <- Object
obj Object -> Key -> Parser [hash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hashes"
    pure LocalIds {[text]
[hash]
$sel:hashes:LocalIds :: [hash]
$sel:texts:LocalIds :: [text]
texts :: [text]
hashes :: [hash]
..}

data Patch text oldHash newHash = Patch
  { forall text oldHash newHash. Patch text oldHash newHash -> [text]
textLookup :: [text],
    forall text oldHash newHash.
Patch text oldHash newHash -> [oldHash]
oldHashLookup :: [oldHash],
    forall text oldHash newHash.
Patch text oldHash newHash -> [newHash]
newHashLookup :: [newHash],
    forall text oldHash newHash.
Patch text oldHash newHash -> ByteString
bytes :: ByteString
  }
  deriving stock (Int -> Patch text oldHash newHash -> ShowS
[Patch text oldHash newHash] -> ShowS
Patch text oldHash newHash -> String
(Int -> Patch text oldHash newHash -> ShowS)
-> (Patch text oldHash newHash -> String)
-> ([Patch text oldHash newHash] -> ShowS)
-> Show (Patch text oldHash newHash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text oldHash newHash.
(Show text, Show oldHash, Show newHash) =>
Int -> Patch text oldHash newHash -> ShowS
forall text oldHash newHash.
(Show text, Show oldHash, Show newHash) =>
[Patch text oldHash newHash] -> ShowS
forall text oldHash newHash.
(Show text, Show oldHash, Show newHash) =>
Patch text oldHash newHash -> String
$cshowsPrec :: forall text oldHash newHash.
(Show text, Show oldHash, Show newHash) =>
Int -> Patch text oldHash newHash -> ShowS
showsPrec :: Int -> Patch text oldHash newHash -> ShowS
$cshow :: forall text oldHash newHash.
(Show text, Show oldHash, Show newHash) =>
Patch text oldHash newHash -> String
show :: Patch text oldHash newHash -> String
$cshowList :: forall text oldHash newHash.
(Show text, Show oldHash, Show newHash) =>
[Patch text oldHash newHash] -> ShowS
showList :: [Patch text oldHash newHash] -> ShowS
Show, Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
(Patch text oldHash newHash -> Patch text oldHash newHash -> Bool)
-> (Patch text oldHash newHash
    -> Patch text oldHash newHash -> Bool)
-> Eq (Patch text oldHash newHash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text oldHash newHash.
(Eq text, Eq oldHash, Eq newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
$c== :: forall text oldHash newHash.
(Eq text, Eq oldHash, Eq newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
== :: Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
$c/= :: forall text oldHash newHash.
(Eq text, Eq oldHash, Eq newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
/= :: Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
Eq, Eq (Patch text oldHash newHash)
Eq (Patch text oldHash newHash) =>
(Patch text oldHash newHash
 -> Patch text oldHash newHash -> Ordering)
-> (Patch text oldHash newHash
    -> Patch text oldHash newHash -> Bool)
-> (Patch text oldHash newHash
    -> Patch text oldHash newHash -> Bool)
-> (Patch text oldHash newHash
    -> Patch text oldHash newHash -> Bool)
-> (Patch text oldHash newHash
    -> Patch text oldHash newHash -> Bool)
-> (Patch text oldHash newHash
    -> Patch text oldHash newHash -> Patch text oldHash newHash)
-> (Patch text oldHash newHash
    -> Patch text oldHash newHash -> Patch text oldHash newHash)
-> Ord (Patch text oldHash newHash)
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
Patch text oldHash newHash
-> Patch text oldHash newHash -> Ordering
Patch text oldHash newHash
-> Patch text oldHash newHash -> Patch text oldHash newHash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Eq (Patch text oldHash newHash)
forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash
-> Patch text oldHash newHash -> Ordering
forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash
-> Patch text oldHash newHash -> Patch text oldHash newHash
$ccompare :: forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash
-> Patch text oldHash newHash -> Ordering
compare :: Patch text oldHash newHash
-> Patch text oldHash newHash -> Ordering
$c< :: forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
< :: Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
$c<= :: forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
<= :: Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
$c> :: forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
> :: Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
$c>= :: forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
>= :: Patch text oldHash newHash -> Patch text oldHash newHash -> Bool
$cmax :: forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash
-> Patch text oldHash newHash -> Patch text oldHash newHash
max :: Patch text oldHash newHash
-> Patch text oldHash newHash -> Patch text oldHash newHash
$cmin :: forall text oldHash newHash.
(Ord text, Ord oldHash, Ord newHash) =>
Patch text oldHash newHash
-> Patch text oldHash newHash -> Patch text oldHash newHash
min :: Patch text oldHash newHash
-> Patch text oldHash newHash -> Patch text oldHash newHash
Ord)

instance (ToJSON text, ToJSON oldHash, ToJSON newHash) => ToJSON (Patch text oldHash newHash) where
  toJSON :: Patch text oldHash newHash -> Value
toJSON (Patch [text]
textLookup [oldHash]
oldHashLookup [newHash]
newHashLookup ByteString
bytes) =
    [Pair] -> Value
object
      [ Key
"text_lookup" Key -> [text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [text]
textLookup,
        Key
"optional_hash_lookup" Key -> [oldHash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [oldHash]
oldHashLookup,
        Key
"hash_lookup" Key -> [newHash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [newHash]
newHashLookup,
        Key
"bytes" Key -> Base64Bytes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= ByteString -> Base64Bytes
Base64Bytes ByteString
bytes
      ]

instance (FromJSON text, FromJSON oldHash, FromJSON newHash) => FromJSON (Patch text oldHash newHash) where
  parseJSON :: Value -> Parser (Patch text oldHash newHash)
parseJSON = String
-> (Object -> Parser (Patch text oldHash newHash))
-> Value
-> Parser (Patch text oldHash newHash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Patch" \Object
obj -> do
    [text]
textLookup <- Object
obj Object -> Key -> Parser [text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text_lookup"
    [oldHash]
oldHashLookup <- Object
obj Object -> Key -> Parser [oldHash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"optional_hash_lookup"
    [newHash]
newHashLookup <- Object
obj Object -> Key -> Parser [newHash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hash_lookup"
    Base64Bytes ByteString
bytes <- Object
obj Object -> Key -> Parser Base64Bytes
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"bytes"
    Patch text oldHash newHash -> Parser (Patch text oldHash newHash)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Patch {[text]
[oldHash]
[newHash]
ByteString
$sel:newHashLookup:Patch :: [newHash]
$sel:textLookup:Patch :: [text]
$sel:oldHashLookup:Patch :: [oldHash]
$sel:bytes:Patch :: ByteString
textLookup :: [text]
oldHashLookup :: [oldHash]
newHashLookup :: [newHash]
bytes :: ByteString
..}

patchOldHashes_ :: (Applicative m) => (oldHash -> m oldHash') -> Patch text oldHash newHash -> m (Patch text oldHash' newHash)
patchOldHashes_ :: forall (m :: * -> *) oldHash oldHash' text newHash.
Applicative m =>
(oldHash -> m oldHash')
-> Patch text oldHash newHash -> m (Patch text oldHash' newHash)
patchOldHashes_ oldHash -> m oldHash'
f (Patch {[oldHash]
[text]
[newHash]
ByteString
$sel:newHashLookup:Patch :: forall text oldHash newHash.
Patch text oldHash newHash -> [newHash]
$sel:textLookup:Patch :: forall text oldHash newHash. Patch text oldHash newHash -> [text]
$sel:oldHashLookup:Patch :: forall text oldHash newHash.
Patch text oldHash newHash -> [oldHash]
$sel:bytes:Patch :: forall text oldHash newHash.
Patch text oldHash newHash -> ByteString
textLookup :: [text]
oldHashLookup :: [oldHash]
newHashLookup :: [newHash]
bytes :: ByteString
..}) = do
  [oldHash']
oldHashLookup <- (oldHash -> m oldHash') -> [oldHash] -> m [oldHash']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse oldHash -> m oldHash'
f [oldHash]
oldHashLookup
  pure (Patch {[oldHash']
[text]
[newHash]
ByteString
$sel:newHashLookup:Patch :: [newHash]
$sel:textLookup:Patch :: [text]
$sel:oldHashLookup:Patch :: [oldHash']
$sel:bytes:Patch :: ByteString
textLookup :: [text]
newHashLookup :: [newHash]
bytes :: ByteString
oldHashLookup :: [oldHash']
..})

patchNewHashes_ :: (Applicative m) => (newHash -> m newHash') -> Patch text oldHash newHash -> m (Patch text oldHash newHash')
patchNewHashes_ :: forall (m :: * -> *) newHash newHash' text oldHash.
Applicative m =>
(newHash -> m newHash')
-> Patch text oldHash newHash -> m (Patch text oldHash newHash')
patchNewHashes_ newHash -> m newHash'
f (Patch {[newHash]
[text]
[oldHash]
ByteString
$sel:newHashLookup:Patch :: forall text oldHash newHash.
Patch text oldHash newHash -> [newHash]
$sel:textLookup:Patch :: forall text oldHash newHash. Patch text oldHash newHash -> [text]
$sel:oldHashLookup:Patch :: forall text oldHash newHash.
Patch text oldHash newHash -> [oldHash]
$sel:bytes:Patch :: forall text oldHash newHash.
Patch text oldHash newHash -> ByteString
textLookup :: [text]
oldHashLookup :: [oldHash]
newHashLookup :: [newHash]
bytes :: ByteString
..}) = do
  [newHash']
newHashLookup <- (newHash -> m newHash') -> [newHash] -> m [newHash']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse newHash -> m newHash'
f [newHash]
newHashLookup
  pure (Patch {[newHash']
[text]
[oldHash]
ByteString
$sel:newHashLookup:Patch :: [newHash']
$sel:textLookup:Patch :: [text]
$sel:oldHashLookup:Patch :: [oldHash]
$sel:bytes:Patch :: ByteString
textLookup :: [text]
oldHashLookup :: [oldHash]
bytes :: ByteString
newHashLookup :: [newHash']
..})

data PatchDiff text oldHash hash = PatchDiff
  { forall text oldHash hash. PatchDiff text oldHash hash -> hash
parent :: hash,
    forall text oldHash hash. PatchDiff text oldHash hash -> [text]
textLookup :: [text],
    forall text oldHash hash. PatchDiff text oldHash hash -> [oldHash]
oldHashLookup :: [oldHash],
    forall text oldHash hash. PatchDiff text oldHash hash -> [hash]
newHashLookup :: [hash],
    forall text oldHash hash. PatchDiff text oldHash hash -> ByteString
bytes :: ByteString
  }
  deriving stock (PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
(PatchDiff text oldHash hash
 -> PatchDiff text oldHash hash -> Bool)
-> (PatchDiff text oldHash hash
    -> PatchDiff text oldHash hash -> Bool)
-> Eq (PatchDiff text oldHash hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text oldHash hash.
(Eq hash, Eq text, Eq oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
$c== :: forall text oldHash hash.
(Eq hash, Eq text, Eq oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
== :: PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
$c/= :: forall text oldHash hash.
(Eq hash, Eq text, Eq oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
/= :: PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
Eq, Eq (PatchDiff text oldHash hash)
Eq (PatchDiff text oldHash hash) =>
(PatchDiff text oldHash hash
 -> PatchDiff text oldHash hash -> Ordering)
-> (PatchDiff text oldHash hash
    -> PatchDiff text oldHash hash -> Bool)
-> (PatchDiff text oldHash hash
    -> PatchDiff text oldHash hash -> Bool)
-> (PatchDiff text oldHash hash
    -> PatchDiff text oldHash hash -> Bool)
-> (PatchDiff text oldHash hash
    -> PatchDiff text oldHash hash -> Bool)
-> (PatchDiff text oldHash hash
    -> PatchDiff text oldHash hash -> PatchDiff text oldHash hash)
-> (PatchDiff text oldHash hash
    -> PatchDiff text oldHash hash -> PatchDiff text oldHash hash)
-> Ord (PatchDiff text oldHash hash)
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> Ordering
PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> PatchDiff text oldHash hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
Eq (PatchDiff text oldHash hash)
forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> Ordering
forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> PatchDiff text oldHash hash
$ccompare :: forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> Ordering
compare :: PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> Ordering
$c< :: forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
< :: PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
$c<= :: forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
<= :: PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
$c> :: forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
> :: PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
$c>= :: forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
>= :: PatchDiff text oldHash hash -> PatchDiff text oldHash hash -> Bool
$cmax :: forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> PatchDiff text oldHash hash
max :: PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> PatchDiff text oldHash hash
$cmin :: forall text oldHash hash.
(Ord hash, Ord text, Ord oldHash) =>
PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> PatchDiff text oldHash hash
min :: PatchDiff text oldHash hash
-> PatchDiff text oldHash hash -> PatchDiff text oldHash hash
Ord, Int -> PatchDiff text oldHash hash -> ShowS
[PatchDiff text oldHash hash] -> ShowS
PatchDiff text oldHash hash -> String
(Int -> PatchDiff text oldHash hash -> ShowS)
-> (PatchDiff text oldHash hash -> String)
-> ([PatchDiff text oldHash hash] -> ShowS)
-> Show (PatchDiff text oldHash hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text oldHash hash.
(Show hash, Show text, Show oldHash) =>
Int -> PatchDiff text oldHash hash -> ShowS
forall text oldHash hash.
(Show hash, Show text, Show oldHash) =>
[PatchDiff text oldHash hash] -> ShowS
forall text oldHash hash.
(Show hash, Show text, Show oldHash) =>
PatchDiff text oldHash hash -> String
$cshowsPrec :: forall text oldHash hash.
(Show hash, Show text, Show oldHash) =>
Int -> PatchDiff text oldHash hash -> ShowS
showsPrec :: Int -> PatchDiff text oldHash hash -> ShowS
$cshow :: forall text oldHash hash.
(Show hash, Show text, Show oldHash) =>
PatchDiff text oldHash hash -> String
show :: PatchDiff text oldHash hash -> String
$cshowList :: forall text oldHash hash.
(Show hash, Show text, Show oldHash) =>
[PatchDiff text oldHash hash] -> ShowS
showList :: [PatchDiff text oldHash hash] -> ShowS
Show)

instance (ToJSON text, ToJSON oldHash, ToJSON hash) => ToJSON (PatchDiff text oldHash hash) where
  toJSON :: PatchDiff text oldHash hash -> Value
toJSON (PatchDiff hash
parent [text]
textLookup [oldHash]
oldHashLookup [hash]
newHashLookup ByteString
bytes) =
    [Pair] -> Value
object
      [ Key
"parent" Key -> hash -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= hash
parent,
        Key
"text_lookup" Key -> [text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [text]
textLookup,
        Key
"optional_hash_lookup" Key -> [oldHash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [oldHash]
oldHashLookup,
        Key
"hash_lookup" Key -> [hash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [hash]
newHashLookup,
        Key
"bytes" Key -> Base64Bytes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= ByteString -> Base64Bytes
Base64Bytes ByteString
bytes
      ]

instance (FromJSON text, FromJSON oldHash, FromJSON hash) => FromJSON (PatchDiff text oldHash hash) where
  parseJSON :: Value -> Parser (PatchDiff text oldHash hash)
parseJSON = String
-> (Object -> Parser (PatchDiff text oldHash hash))
-> Value
-> Parser (PatchDiff text oldHash hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"PatchDiff" \Object
obj -> do
    hash
parent <- Object
obj Object -> Key -> Parser hash
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parent"
    [text]
textLookup <- Object
obj Object -> Key -> Parser [text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text_lookup"
    [oldHash]
oldHashLookup <- Object
obj Object -> Key -> Parser [oldHash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"optional_hash_lookup"
    [hash]
newHashLookup <- Object
obj Object -> Key -> Parser [hash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hash_lookup"
    Base64Bytes ByteString
bytes <- Object
obj Object -> Key -> Parser Base64Bytes
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"bytes"
    PatchDiff text oldHash hash -> Parser (PatchDiff text oldHash hash)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PatchDiff {hash
[text]
[oldHash]
[hash]
ByteString
$sel:parent:PatchDiff :: hash
$sel:newHashLookup:PatchDiff :: [hash]
$sel:textLookup:PatchDiff :: [text]
$sel:oldHashLookup:PatchDiff :: [oldHash]
$sel:bytes:PatchDiff :: ByteString
parent :: hash
textLookup :: [text]
oldHashLookup :: [oldHash]
newHashLookup :: [hash]
bytes :: ByteString
..}

patchDiffHashes_ :: (Applicative m) => (hash -> m hash') -> PatchDiff text noSyncHash hash -> m (PatchDiff text noSyncHash hash')
patchDiffHashes_ :: forall (m :: * -> *) hash hash' text noSyncHash.
Applicative m =>
(hash -> m hash')
-> PatchDiff text noSyncHash hash
-> m (PatchDiff text noSyncHash hash')
patchDiffHashes_ hash -> m hash'
f (PatchDiff {hash
[hash]
[text]
[noSyncHash]
ByteString
$sel:parent:PatchDiff :: forall text oldHash hash. PatchDiff text oldHash hash -> hash
$sel:newHashLookup:PatchDiff :: forall text oldHash hash. PatchDiff text oldHash hash -> [hash]
$sel:textLookup:PatchDiff :: forall text oldHash hash. PatchDiff text oldHash hash -> [text]
$sel:oldHashLookup:PatchDiff :: forall text oldHash hash. PatchDiff text oldHash hash -> [oldHash]
$sel:bytes:PatchDiff :: forall text oldHash hash. PatchDiff text oldHash hash -> ByteString
parent :: hash
textLookup :: [text]
oldHashLookup :: [noSyncHash]
newHashLookup :: [hash]
bytes :: ByteString
..}) = do
  hash'
parent <- hash -> m hash'
f hash
parent
  [hash']
newHashLookup <- (hash -> m hash') -> [hash] -> m [hash']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse hash -> m hash'
f [hash]
newHashLookup
  pure (PatchDiff {hash'
[hash']
[text]
[noSyncHash]
ByteString
$sel:parent:PatchDiff :: hash'
$sel:newHashLookup:PatchDiff :: [hash']
$sel:textLookup:PatchDiff :: [text]
$sel:oldHashLookup:PatchDiff :: [noSyncHash]
$sel:bytes:PatchDiff :: ByteString
textLookup :: [text]
oldHashLookup :: [noSyncHash]
bytes :: ByteString
parent :: hash'
newHashLookup :: [hash']
..})

data Namespace text hash = Namespace
  { forall text hash. Namespace text hash -> [text]
textLookup :: [text],
    forall text hash. Namespace text hash -> [hash]
defnLookup :: [hash],
    forall text hash. Namespace text hash -> [hash]
patchLookup :: [hash],
    forall text hash. Namespace text hash -> [(hash, hash)]
childLookup :: [(hash, hash)], -- (namespace hash, causal hash)
    forall text hash. Namespace text hash -> LocalBranchBytes
bytes :: LocalBranchBytes
  }
  deriving stock (Namespace text hash -> Namespace text hash -> Bool
(Namespace text hash -> Namespace text hash -> Bool)
-> (Namespace text hash -> Namespace text hash -> Bool)
-> Eq (Namespace text hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text hash.
(Eq text, Eq hash) =>
Namespace text hash -> Namespace text hash -> Bool
$c== :: forall text hash.
(Eq text, Eq hash) =>
Namespace text hash -> Namespace text hash -> Bool
== :: Namespace text hash -> Namespace text hash -> Bool
$c/= :: forall text hash.
(Eq text, Eq hash) =>
Namespace text hash -> Namespace text hash -> Bool
/= :: Namespace text hash -> Namespace text hash -> Bool
Eq, (forall a b. (a -> b) -> Namespace text a -> Namespace text b)
-> (forall a b. a -> Namespace text b -> Namespace text a)
-> Functor (Namespace text)
forall a b. a -> Namespace text b -> Namespace text a
forall a b. (a -> b) -> Namespace text a -> Namespace text b
forall text a b. a -> Namespace text b -> Namespace text a
forall text a b. (a -> b) -> Namespace text a -> Namespace text b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall text a b. (a -> b) -> Namespace text a -> Namespace text b
fmap :: forall a b. (a -> b) -> Namespace text a -> Namespace text b
$c<$ :: forall text a b. a -> Namespace text b -> Namespace text a
<$ :: forall a b. a -> Namespace text b -> Namespace text a
Functor, Eq (Namespace text hash)
Eq (Namespace text hash) =>
(Namespace text hash -> Namespace text hash -> Ordering)
-> (Namespace text hash -> Namespace text hash -> Bool)
-> (Namespace text hash -> Namespace text hash -> Bool)
-> (Namespace text hash -> Namespace text hash -> Bool)
-> (Namespace text hash -> Namespace text hash -> Bool)
-> (Namespace text hash
    -> Namespace text hash -> Namespace text hash)
-> (Namespace text hash
    -> Namespace text hash -> Namespace text hash)
-> Ord (Namespace text hash)
Namespace text hash -> Namespace text hash -> Bool
Namespace text hash -> Namespace text hash -> Ordering
Namespace text hash -> Namespace text hash -> Namespace text hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text hash. (Ord text, Ord hash) => Eq (Namespace text hash)
forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Bool
forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Ordering
forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Namespace text hash
$ccompare :: forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Ordering
compare :: Namespace text hash -> Namespace text hash -> Ordering
$c< :: forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Bool
< :: Namespace text hash -> Namespace text hash -> Bool
$c<= :: forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Bool
<= :: Namespace text hash -> Namespace text hash -> Bool
$c> :: forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Bool
> :: Namespace text hash -> Namespace text hash -> Bool
$c>= :: forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Bool
>= :: Namespace text hash -> Namespace text hash -> Bool
$cmax :: forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Namespace text hash
max :: Namespace text hash -> Namespace text hash -> Namespace text hash
$cmin :: forall text hash.
(Ord text, Ord hash) =>
Namespace text hash -> Namespace text hash -> Namespace text hash
min :: Namespace text hash -> Namespace text hash -> Namespace text hash
Ord, Int -> Namespace text hash -> ShowS
[Namespace text hash] -> ShowS
Namespace text hash -> String
(Int -> Namespace text hash -> ShowS)
-> (Namespace text hash -> String)
-> ([Namespace text hash] -> ShowS)
-> Show (Namespace text hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text hash.
(Show text, Show hash) =>
Int -> Namespace text hash -> ShowS
forall text hash.
(Show text, Show hash) =>
[Namespace text hash] -> ShowS
forall text hash.
(Show text, Show hash) =>
Namespace text hash -> String
$cshowsPrec :: forall text hash.
(Show text, Show hash) =>
Int -> Namespace text hash -> ShowS
showsPrec :: Int -> Namespace text hash -> ShowS
$cshow :: forall text hash.
(Show text, Show hash) =>
Namespace text hash -> String
show :: Namespace text hash -> String
$cshowList :: forall text hash.
(Show text, Show hash) =>
[Namespace text hash] -> ShowS
showList :: [Namespace text hash] -> ShowS
Show)

instance Bifoldable Namespace where
  bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> Namespace a b -> m
bifoldMap = (a -> m) -> (b -> m) -> Namespace a b -> m
forall (t :: * -> * -> *) m a b.
(Bitraversable t, Monoid m) =>
(a -> m) -> (b -> m) -> t a b -> m
bifoldMapDefault

instance Bifunctor Namespace where
  bimap :: forall a b c d.
(a -> b) -> (c -> d) -> Namespace a c -> Namespace b d
bimap = (a -> b) -> (c -> d) -> Namespace a c -> Namespace b d
forall (t :: * -> * -> *) a b c d.
Bitraversable t =>
(a -> b) -> (c -> d) -> t a c -> t b d
bimapDefault

instance Bitraversable Namespace where
  bitraverse :: forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> Namespace a b -> f (Namespace c d)
bitraverse a -> f c
f b -> f d
g (Namespace [a]
tl [b]
dl [b]
pl [(b, b)]
cl LocalBranchBytes
b) =
    [c] -> [d] -> [d] -> [(d, d)] -> LocalBranchBytes -> Namespace c d
forall text hash.
[text]
-> [hash]
-> [hash]
-> [(hash, hash)]
-> LocalBranchBytes
-> Namespace text hash
Namespace
      ([c]
 -> [d] -> [d] -> [(d, d)] -> LocalBranchBytes -> Namespace c d)
-> f [c]
-> f ([d] -> [d] -> [(d, d)] -> LocalBranchBytes -> Namespace c d)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> f c) -> [a] -> f [c]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse a -> f c
f [a]
tl
      f ([d] -> [d] -> [(d, d)] -> LocalBranchBytes -> Namespace c d)
-> f [d]
-> f ([d] -> [(d, d)] -> LocalBranchBytes -> Namespace c d)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (b -> f d) -> [b] -> f [d]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse b -> f d
g [b]
dl
      f ([d] -> [(d, d)] -> LocalBranchBytes -> Namespace c d)
-> f [d] -> f ([(d, d)] -> LocalBranchBytes -> Namespace c d)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (b -> f d) -> [b] -> f [d]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse b -> f d
g [b]
pl
      f ([(d, d)] -> LocalBranchBytes -> Namespace c d)
-> f [(d, d)] -> f (LocalBranchBytes -> Namespace c d)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((b, b) -> f (d, d)) -> [(b, b)] -> f [(d, d)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse ((b -> f d) -> (b -> f d) -> (b, b) -> f (d, d)
forall (f :: * -> *) a c b d.
Applicative f =>
(a -> f c) -> (b -> f d) -> (a, b) -> f (c, d)
forall (t :: * -> * -> *) (f :: * -> *) a c b d.
(Bitraversable t, Applicative f) =>
(a -> f c) -> (b -> f d) -> t a b -> f (t c d)
bitraverse b -> f d
g b -> f d
g) [(b, b)]
cl
      f (LocalBranchBytes -> Namespace c d)
-> f LocalBranchBytes -> f (Namespace c d)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LocalBranchBytes -> f LocalBranchBytes
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LocalBranchBytes
b

instance (ToJSON text, ToJSON hash) => ToJSON (Namespace text hash) where
  toJSON :: Namespace text hash -> Value
toJSON (Namespace [text]
textLookup [hash]
defnLookup [hash]
patchLookup [(hash, hash)]
childLookup (LocalBranchBytes ByteString
bytes)) =
    [Pair] -> Value
object
      [ Key
"text_lookup" Key -> [text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [text]
textLookup,
        Key
"defn_lookup" Key -> [hash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [hash]
defnLookup,
        Key
"patch_lookup" Key -> [hash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [hash]
patchLookup,
        Key
"child_lookup" Key -> [(hash, hash)] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [(hash, hash)]
childLookup,
        Key
"bytes" Key -> Base64Bytes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= ByteString -> Base64Bytes
Base64Bytes ByteString
bytes
      ]

instance (FromJSON text, FromJSON hash) => FromJSON (Namespace text hash) where
  parseJSON :: Value -> Parser (Namespace text hash)
parseJSON = String
-> (Object -> Parser (Namespace text hash))
-> Value
-> Parser (Namespace text hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Namespace" \Object
obj -> do
    [text]
textLookup <- Object
obj Object -> Key -> Parser [text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text_lookup"
    [hash]
defnLookup <- Object
obj Object -> Key -> Parser [hash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"defn_lookup"
    [hash]
patchLookup <- Object
obj Object -> Key -> Parser [hash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"patch_lookup"
    [(hash, hash)]
childLookup <- Object
obj Object -> Key -> Parser [(hash, hash)]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"child_lookup"
    Base64Bytes ByteString
bytes <- Object
obj Object -> Key -> Parser Base64Bytes
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"bytes"
    Namespace text hash -> Parser (Namespace text hash)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Namespace {$sel:bytes:Namespace :: LocalBranchBytes
bytes = ByteString -> LocalBranchBytes
LocalBranchBytes ByteString
bytes, [text]
[hash]
[(hash, hash)]
$sel:defnLookup:Namespace :: [hash]
$sel:patchLookup:Namespace :: [hash]
$sel:childLookup:Namespace :: [(hash, hash)]
$sel:textLookup:Namespace :: [text]
textLookup :: [text]
defnLookup :: [hash]
patchLookup :: [hash]
childLookup :: [(hash, hash)]
..}

data NamespaceDiff text hash = NamespaceDiff
  { forall text hash. NamespaceDiff text hash -> hash
parent :: hash,
    forall text hash. NamespaceDiff text hash -> [text]
textLookup :: [text],
    forall text hash. NamespaceDiff text hash -> [hash]
defnLookup :: [hash],
    forall text hash. NamespaceDiff text hash -> [hash]
patchLookup :: [hash],
    forall text hash. NamespaceDiff text hash -> [(hash, hash)]
childLookup :: [(hash, hash)], -- (namespace hash, causal hash)
    forall text hash. NamespaceDiff text hash -> LocalBranchBytes
bytes :: LocalBranchBytes
  }
  deriving stock (NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
(NamespaceDiff text hash -> NamespaceDiff text hash -> Bool)
-> (NamespaceDiff text hash -> NamespaceDiff text hash -> Bool)
-> Eq (NamespaceDiff text hash)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall text hash.
(Eq hash, Eq text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
$c== :: forall text hash.
(Eq hash, Eq text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
== :: NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
$c/= :: forall text hash.
(Eq hash, Eq text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
/= :: NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
Eq, Eq (NamespaceDiff text hash)
Eq (NamespaceDiff text hash) =>
(NamespaceDiff text hash -> NamespaceDiff text hash -> Ordering)
-> (NamespaceDiff text hash -> NamespaceDiff text hash -> Bool)
-> (NamespaceDiff text hash -> NamespaceDiff text hash -> Bool)
-> (NamespaceDiff text hash -> NamespaceDiff text hash -> Bool)
-> (NamespaceDiff text hash -> NamespaceDiff text hash -> Bool)
-> (NamespaceDiff text hash
    -> NamespaceDiff text hash -> NamespaceDiff text hash)
-> (NamespaceDiff text hash
    -> NamespaceDiff text hash -> NamespaceDiff text hash)
-> Ord (NamespaceDiff text hash)
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
NamespaceDiff text hash -> NamespaceDiff text hash -> Ordering
NamespaceDiff text hash
-> NamespaceDiff text hash -> NamespaceDiff text hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall text hash.
(Ord hash, Ord text) =>
Eq (NamespaceDiff text hash)
forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Ordering
forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash
-> NamespaceDiff text hash -> NamespaceDiff text hash
$ccompare :: forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Ordering
compare :: NamespaceDiff text hash -> NamespaceDiff text hash -> Ordering
$c< :: forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
< :: NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
$c<= :: forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
<= :: NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
$c> :: forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
> :: NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
$c>= :: forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
>= :: NamespaceDiff text hash -> NamespaceDiff text hash -> Bool
$cmax :: forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash
-> NamespaceDiff text hash -> NamespaceDiff text hash
max :: NamespaceDiff text hash
-> NamespaceDiff text hash -> NamespaceDiff text hash
$cmin :: forall text hash.
(Ord hash, Ord text) =>
NamespaceDiff text hash
-> NamespaceDiff text hash -> NamespaceDiff text hash
min :: NamespaceDiff text hash
-> NamespaceDiff text hash -> NamespaceDiff text hash
Ord, Int -> NamespaceDiff text hash -> ShowS
[NamespaceDiff text hash] -> ShowS
NamespaceDiff text hash -> String
(Int -> NamespaceDiff text hash -> ShowS)
-> (NamespaceDiff text hash -> String)
-> ([NamespaceDiff text hash] -> ShowS)
-> Show (NamespaceDiff text hash)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall text hash.
(Show hash, Show text) =>
Int -> NamespaceDiff text hash -> ShowS
forall text hash.
(Show hash, Show text) =>
[NamespaceDiff text hash] -> ShowS
forall text hash.
(Show hash, Show text) =>
NamespaceDiff text hash -> String
$cshowsPrec :: forall text hash.
(Show hash, Show text) =>
Int -> NamespaceDiff text hash -> ShowS
showsPrec :: Int -> NamespaceDiff text hash -> ShowS
$cshow :: forall text hash.
(Show hash, Show text) =>
NamespaceDiff text hash -> String
show :: NamespaceDiff text hash -> String
$cshowList :: forall text hash.
(Show hash, Show text) =>
[NamespaceDiff text hash] -> ShowS
showList :: [NamespaceDiff text hash] -> ShowS
Show)

instance (ToJSON text, ToJSON hash) => ToJSON (NamespaceDiff text hash) where
  toJSON :: NamespaceDiff text hash -> Value
toJSON (NamespaceDiff hash
parent [text]
textLookup [hash]
defnLookup [hash]
patchLookup [(hash, hash)]
childLookup (LocalBranchBytes ByteString
bytes)) =
    [Pair] -> Value
object
      [ Key
"parent" Key -> hash -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= hash
parent,
        Key
"text_lookup" Key -> [text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [text]
textLookup,
        Key
"defn_lookup" Key -> [hash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [hash]
defnLookup,
        Key
"patch_lookup" Key -> [hash] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [hash]
patchLookup,
        Key
"child_lookup" Key -> [(hash, hash)] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= [(hash, hash)]
childLookup,
        Key
"bytes" Key -> Base64Bytes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= ByteString -> Base64Bytes
Base64Bytes ByteString
bytes
      ]

instance (FromJSON text, FromJSON hash) => FromJSON (NamespaceDiff text hash) where
  parseJSON :: Value -> Parser (NamespaceDiff text hash)
parseJSON = String
-> (Object -> Parser (NamespaceDiff text hash))
-> Value
-> Parser (NamespaceDiff text hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"NamespaceDiff" \Object
obj -> do
    hash
parent <- Object
obj Object -> Key -> Parser hash
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parent"
    [text]
textLookup <- Object
obj Object -> Key -> Parser [text]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"text_lookup"
    [hash]
defnLookup <- Object
obj Object -> Key -> Parser [hash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"defn_lookup"
    [hash]
patchLookup <- Object
obj Object -> Key -> Parser [hash]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"patch_lookup"
    [(hash, hash)]
childLookup <- Object
obj Object -> Key -> Parser [(hash, hash)]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"child_lookup"
    Base64Bytes ByteString
bytes <- Object
obj Object -> Key -> Parser Base64Bytes
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"bytes"
    NamespaceDiff text hash -> Parser (NamespaceDiff text hash)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NamespaceDiff {$sel:bytes:NamespaceDiff :: LocalBranchBytes
bytes = ByteString -> LocalBranchBytes
LocalBranchBytes ByteString
bytes, hash
[text]
[hash]
[(hash, hash)]
$sel:parent:NamespaceDiff :: hash
$sel:defnLookup:NamespaceDiff :: [hash]
$sel:patchLookup:NamespaceDiff :: [hash]
$sel:childLookup:NamespaceDiff :: [(hash, hash)]
$sel:textLookup:NamespaceDiff :: [text]
parent :: hash
textLookup :: [text]
defnLookup :: [hash]
patchLookup :: [hash]
childLookup :: [(hash, hash)]
..}

namespaceDiffHashes_ :: (Applicative m) => (hash -> m hash') -> NamespaceDiff text hash -> m (NamespaceDiff text hash')
namespaceDiffHashes_ :: forall (m :: * -> *) hash hash' text.
Applicative m =>
(hash -> m hash')
-> NamespaceDiff text hash -> m (NamespaceDiff text hash')
namespaceDiffHashes_ hash -> m hash'
f (NamespaceDiff {hash
[hash]
[text]
[(hash, hash)]
LocalBranchBytes
$sel:parent:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> hash
$sel:defnLookup:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> [hash]
$sel:patchLookup:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> [hash]
$sel:childLookup:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> [(hash, hash)]
$sel:textLookup:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> [text]
$sel:bytes:NamespaceDiff :: forall text hash. NamespaceDiff text hash -> LocalBranchBytes
parent :: hash
textLookup :: [text]
defnLookup :: [hash]
patchLookup :: [hash]
childLookup :: [(hash, hash)]
bytes :: LocalBranchBytes
..}) = do
  hash'
parent <- hash -> m hash'
f hash
parent
  [hash']
defnLookup <- (hash -> m hash') -> [hash] -> m [hash']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse hash -> m hash'
f [hash]
defnLookup
  [hash']
patchLookup <- (hash -> m hash') -> [hash] -> m [hash']
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse hash -> m hash'
f [hash]
patchLookup
  [(hash', hash')]
childLookup <- LensLike m [(hash, hash)] [(hash', hash')] hash hash'
-> LensLike m [(hash, hash)] [(hash', hash')] hash hash'
forall (f :: * -> *) s t a b.
LensLike f s t a b -> LensLike f s t a b
traverseOf (((hash, hash) -> m (hash', hash'))
-> [(hash, hash)] -> m [(hash', hash')]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (((hash, hash) -> m (hash', hash'))
 -> [(hash, hash)] -> m [(hash', hash')])
-> ((hash -> m hash') -> (hash, hash) -> m (hash', hash'))
-> LensLike m [(hash, hash)] [(hash', hash')] hash hash'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (hash -> m hash') -> (hash, hash) -> m (hash', hash')
Traversal (hash, hash) (hash', hash') hash hash'
forall (r :: * -> * -> *) a b.
Bitraversable r =>
Traversal (r a a) (r b b) a b
both) hash -> m hash'
f [(hash, hash)]
childLookup
  pure (NamespaceDiff {hash'
[hash']
[text]
[(hash', hash')]
LocalBranchBytes
$sel:parent:NamespaceDiff :: hash'
$sel:defnLookup:NamespaceDiff :: [hash']
$sel:patchLookup:NamespaceDiff :: [hash']
$sel:childLookup:NamespaceDiff :: [(hash', hash')]
$sel:textLookup:NamespaceDiff :: [text]
$sel:bytes:NamespaceDiff :: LocalBranchBytes
textLookup :: [text]
bytes :: LocalBranchBytes
parent :: hash'
defnLookup :: [hash']
patchLookup :: [hash']
childLookup :: [(hash', hash')]
..})

-- Client _may_ choose not to download the namespace entity in the future, but
-- we still send them the hash/hashjwt.
data Causal hash = Causal
  { forall hash. Causal hash -> hash
namespaceHash :: hash,
    forall hash. Causal hash -> Set hash
parents :: Set hash
  }
  deriving stock (Causal hash -> Causal hash -> Bool
(Causal hash -> Causal hash -> Bool)
-> (Causal hash -> Causal hash -> Bool) -> Eq (Causal hash)
forall hash. Eq hash => Causal hash -> Causal hash -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall hash. Eq hash => Causal hash -> Causal hash -> Bool
== :: Causal hash -> Causal hash -> Bool
$c/= :: forall hash. Eq hash => Causal hash -> Causal hash -> Bool
/= :: Causal hash -> Causal hash -> Bool
Eq, Eq (Causal hash)
Eq (Causal hash) =>
(Causal hash -> Causal hash -> Ordering)
-> (Causal hash -> Causal hash -> Bool)
-> (Causal hash -> Causal hash -> Bool)
-> (Causal hash -> Causal hash -> Bool)
-> (Causal hash -> Causal hash -> Bool)
-> (Causal hash -> Causal hash -> Causal hash)
-> (Causal hash -> Causal hash -> Causal hash)
-> Ord (Causal hash)
Causal hash -> Causal hash -> Bool
Causal hash -> Causal hash -> Ordering
Causal hash -> Causal hash -> Causal hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall hash. Ord hash => Eq (Causal hash)
forall hash. Ord hash => Causal hash -> Causal hash -> Bool
forall hash. Ord hash => Causal hash -> Causal hash -> Ordering
forall hash. Ord hash => Causal hash -> Causal hash -> Causal hash
$ccompare :: forall hash. Ord hash => Causal hash -> Causal hash -> Ordering
compare :: Causal hash -> Causal hash -> Ordering
$c< :: forall hash. Ord hash => Causal hash -> Causal hash -> Bool
< :: Causal hash -> Causal hash -> Bool
$c<= :: forall hash. Ord hash => Causal hash -> Causal hash -> Bool
<= :: Causal hash -> Causal hash -> Bool
$c> :: forall hash. Ord hash => Causal hash -> Causal hash -> Bool
> :: Causal hash -> Causal hash -> Bool
$c>= :: forall hash. Ord hash => Causal hash -> Causal hash -> Bool
>= :: Causal hash -> Causal hash -> Bool
$cmax :: forall hash. Ord hash => Causal hash -> Causal hash -> Causal hash
max :: Causal hash -> Causal hash -> Causal hash
$cmin :: forall hash. Ord hash => Causal hash -> Causal hash -> Causal hash
min :: Causal hash -> Causal hash -> Causal hash
Ord, Int -> Causal hash -> ShowS
[Causal hash] -> ShowS
Causal hash -> String
(Int -> Causal hash -> ShowS)
-> (Causal hash -> String)
-> ([Causal hash] -> ShowS)
-> Show (Causal hash)
forall hash. Show hash => Int -> Causal hash -> ShowS
forall hash. Show hash => [Causal hash] -> ShowS
forall hash. Show hash => Causal hash -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall hash. Show hash => Int -> Causal hash -> ShowS
showsPrec :: Int -> Causal hash -> ShowS
$cshow :: forall hash. Show hash => Causal hash -> String
show :: Causal hash -> String
$cshowList :: forall hash. Show hash => [Causal hash] -> ShowS
showList :: [Causal hash] -> ShowS
Show)

causalHashes_ :: (Applicative m, Ord hash') => (hash -> m hash') -> Causal hash -> m (Causal hash')
causalHashes_ :: forall (m :: * -> *) hash' hash.
(Applicative m, Ord hash') =>
(hash -> m hash') -> Causal hash -> m (Causal hash')
causalHashes_ hash -> m hash'
f (Causal {hash
Set hash
$sel:namespaceHash:Causal :: forall hash. Causal hash -> hash
$sel:parents:Causal :: forall hash. Causal hash -> Set hash
namespaceHash :: hash
parents :: Set hash
..}) = do
  hash'
namespaceHash <- hash -> m hash'
f hash
namespaceHash
  Set hash'
parents <- (hash -> m hash') -> Set hash -> m (Set hash')
forall (f :: * -> *) b a.
(Applicative f, Ord b) =>
(a -> f b) -> Set a -> f (Set b)
Set.traverse hash -> m hash'
f Set hash
parents
  pure (Causal {hash'
Set hash'
$sel:namespaceHash:Causal :: hash'
$sel:parents:Causal :: Set hash'
namespaceHash :: hash'
parents :: Set hash'
..})

instance (ToJSON hash) => ToJSON (Causal hash) where
  toJSON :: Causal hash -> Value
toJSON (Causal hash
namespaceHash Set hash
parents) =
    [Pair] -> Value
object
      [ Key
"namespace_hash" Key -> hash -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= hash
namespaceHash,
        Key
"parents" Key -> Set hash -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Set hash
parents
      ]

instance (FromJSON hash, Ord hash) => FromJSON (Causal hash) where
  parseJSON :: Value -> Parser (Causal hash)
parseJSON = String
-> (Object -> Parser (Causal hash))
-> Value
-> Parser (Causal hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Causal" \Object
obj -> do
    hash
namespaceHash <- Object
obj Object -> Key -> Parser hash
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"namespace_hash"
    Set hash
parents <- Object
obj Object -> Key -> Parser (Set hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parents"
    pure Causal {hash
Set hash
$sel:namespaceHash:Causal :: hash
$sel:parents:Causal :: Set hash
namespaceHash :: hash
parents :: Set hash
..}

data EntityType
  = TermComponentType
  | DeclComponentType
  | PatchType
  | PatchDiffType
  | NamespaceType
  | NamespaceDiffType
  | CausalType
  deriving stock (EntityType -> EntityType -> Bool
(EntityType -> EntityType -> Bool)
-> (EntityType -> EntityType -> Bool) -> Eq EntityType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EntityType -> EntityType -> Bool
== :: EntityType -> EntityType -> Bool
$c/= :: EntityType -> EntityType -> Bool
/= :: EntityType -> EntityType -> Bool
Eq, Eq EntityType
Eq EntityType =>
(EntityType -> EntityType -> Ordering)
-> (EntityType -> EntityType -> Bool)
-> (EntityType -> EntityType -> Bool)
-> (EntityType -> EntityType -> Bool)
-> (EntityType -> EntityType -> Bool)
-> (EntityType -> EntityType -> EntityType)
-> (EntityType -> EntityType -> EntityType)
-> Ord EntityType
EntityType -> EntityType -> Bool
EntityType -> EntityType -> Ordering
EntityType -> EntityType -> EntityType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EntityType -> EntityType -> Ordering
compare :: EntityType -> EntityType -> Ordering
$c< :: EntityType -> EntityType -> Bool
< :: EntityType -> EntityType -> Bool
$c<= :: EntityType -> EntityType -> Bool
<= :: EntityType -> EntityType -> Bool
$c> :: EntityType -> EntityType -> Bool
> :: EntityType -> EntityType -> Bool
$c>= :: EntityType -> EntityType -> Bool
>= :: EntityType -> EntityType -> Bool
$cmax :: EntityType -> EntityType -> EntityType
max :: EntityType -> EntityType -> EntityType
$cmin :: EntityType -> EntityType -> EntityType
min :: EntityType -> EntityType -> EntityType
Ord, Int -> EntityType -> ShowS
[EntityType] -> ShowS
EntityType -> String
(Int -> EntityType -> ShowS)
-> (EntityType -> String)
-> ([EntityType] -> ShowS)
-> Show EntityType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EntityType -> ShowS
showsPrec :: Int -> EntityType -> ShowS
$cshow :: EntityType -> String
show :: EntityType -> String
$cshowList :: [EntityType] -> ShowS
showList :: [EntityType] -> ShowS
Show)

instance ToJSON EntityType where
  toJSON :: EntityType -> Value
toJSON =
    Text -> Value
String (Text -> Value) -> (EntityType -> Text) -> EntityType -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
      EntityType
TermComponentType -> Text
"term_component"
      EntityType
DeclComponentType -> Text
"decl_component"
      EntityType
PatchType -> Text
"patch"
      EntityType
PatchDiffType -> Text
"patch_diff"
      EntityType
NamespaceType -> Text
"namespace"
      EntityType
NamespaceDiffType -> Text
"namespace_diff"
      EntityType
CausalType -> Text
"causal"

instance FromJSON EntityType where
  parseJSON :: Value -> Parser EntityType
parseJSON = String -> (Text -> Parser EntityType) -> Value -> Parser EntityType
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"EntityType" \case
    Text
"term_component" -> EntityType -> Parser EntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EntityType
TermComponentType
    Text
"decl_component" -> EntityType -> Parser EntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EntityType
DeclComponentType
    Text
"patch" -> EntityType -> Parser EntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EntityType
PatchType
    Text
"patch_diff" -> EntityType -> Parser EntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EntityType
PatchDiffType
    Text
"namespace" -> EntityType -> Parser EntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EntityType
NamespaceType
    Text
"namespace_diff" -> EntityType -> Parser EntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EntityType
NamespaceDiffType
    Text
"causal" -> EntityType -> Parser EntityType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure EntityType
CausalType
    Text
t -> Text -> Parser EntityType
forall (m :: * -> *) a. MonadFail m => Text -> m a
failText (Text -> Parser EntityType) -> Text -> Parser EntityType
forall a b. (a -> b) -> a -> b
$ Text
"Unexpected entity type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t

------------------------------------------------------------------------------------------------------------------------
-- Request/response types

------------------------------------------------------------------------------------------------------------------------
-- Get causal hash by path

newtype GetCausalHashByPathRequest = GetCausalHashByPathRequest
  { GetCausalHashByPathRequest -> Path
path :: Path
  }
  deriving stock (Int -> GetCausalHashByPathRequest -> ShowS
[GetCausalHashByPathRequest] -> ShowS
GetCausalHashByPathRequest -> String
(Int -> GetCausalHashByPathRequest -> ShowS)
-> (GetCausalHashByPathRequest -> String)
-> ([GetCausalHashByPathRequest] -> ShowS)
-> Show GetCausalHashByPathRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCausalHashByPathRequest -> ShowS
showsPrec :: Int -> GetCausalHashByPathRequest -> ShowS
$cshow :: GetCausalHashByPathRequest -> String
show :: GetCausalHashByPathRequest -> String
$cshowList :: [GetCausalHashByPathRequest] -> ShowS
showList :: [GetCausalHashByPathRequest] -> ShowS
Show, GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
(GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool)
-> (GetCausalHashByPathRequest
    -> GetCausalHashByPathRequest -> Bool)
-> Eq GetCausalHashByPathRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
== :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
$c/= :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
/= :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
Eq, Eq GetCausalHashByPathRequest
Eq GetCausalHashByPathRequest =>
(GetCausalHashByPathRequest
 -> GetCausalHashByPathRequest -> Ordering)
-> (GetCausalHashByPathRequest
    -> GetCausalHashByPathRequest -> Bool)
-> (GetCausalHashByPathRequest
    -> GetCausalHashByPathRequest -> Bool)
-> (GetCausalHashByPathRequest
    -> GetCausalHashByPathRequest -> Bool)
-> (GetCausalHashByPathRequest
    -> GetCausalHashByPathRequest -> Bool)
-> (GetCausalHashByPathRequest
    -> GetCausalHashByPathRequest -> GetCausalHashByPathRequest)
-> (GetCausalHashByPathRequest
    -> GetCausalHashByPathRequest -> GetCausalHashByPathRequest)
-> Ord GetCausalHashByPathRequest
GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> Ordering
GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> GetCausalHashByPathRequest
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> Ordering
compare :: GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> Ordering
$c< :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
< :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
$c<= :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
<= :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
$c> :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
> :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
$c>= :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
>= :: GetCausalHashByPathRequest -> GetCausalHashByPathRequest -> Bool
$cmax :: GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> GetCausalHashByPathRequest
max :: GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> GetCausalHashByPathRequest
$cmin :: GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> GetCausalHashByPathRequest
min :: GetCausalHashByPathRequest
-> GetCausalHashByPathRequest -> GetCausalHashByPathRequest
Ord)

instance ToJSON GetCausalHashByPathRequest where
  toJSON :: GetCausalHashByPathRequest -> Value
toJSON (GetCausalHashByPathRequest Path
path) =
    [Pair] -> Value
object
      [ Key
"path" Key -> Path -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Path
path
      ]

instance FromJSON GetCausalHashByPathRequest where
  parseJSON :: Value -> Parser GetCausalHashByPathRequest
parseJSON = String
-> (Object -> Parser GetCausalHashByPathRequest)
-> Value
-> Parser GetCausalHashByPathRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"GetCausalHashByPathRequest" \Object
obj -> do
    Path
path <- Object
obj Object -> Key -> Parser Path
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"path"
    pure GetCausalHashByPathRequest {Path
$sel:path:GetCausalHashByPathRequest :: Path
path :: Path
..}

data GetCausalHashByPathResponse
  = GetCausalHashByPathSuccess (Maybe HashJWT)
  | GetCausalHashByPathNoReadPermission Path
  | GetCausalHashByPathUserNotFound
  | GetCausalHashByPathInvalidRepoInfo Text RepoInfo
  deriving stock (Int -> GetCausalHashByPathResponse -> ShowS
[GetCausalHashByPathResponse] -> ShowS
GetCausalHashByPathResponse -> String
(Int -> GetCausalHashByPathResponse -> ShowS)
-> (GetCausalHashByPathResponse -> String)
-> ([GetCausalHashByPathResponse] -> ShowS)
-> Show GetCausalHashByPathResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GetCausalHashByPathResponse -> ShowS
showsPrec :: Int -> GetCausalHashByPathResponse -> ShowS
$cshow :: GetCausalHashByPathResponse -> String
show :: GetCausalHashByPathResponse -> String
$cshowList :: [GetCausalHashByPathResponse] -> ShowS
showList :: [GetCausalHashByPathResponse] -> ShowS
Show, GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
(GetCausalHashByPathResponse
 -> GetCausalHashByPathResponse -> Bool)
-> (GetCausalHashByPathResponse
    -> GetCausalHashByPathResponse -> Bool)
-> Eq GetCausalHashByPathResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
== :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
$c/= :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
/= :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
Eq, Eq GetCausalHashByPathResponse
Eq GetCausalHashByPathResponse =>
(GetCausalHashByPathResponse
 -> GetCausalHashByPathResponse -> Ordering)
-> (GetCausalHashByPathResponse
    -> GetCausalHashByPathResponse -> Bool)
-> (GetCausalHashByPathResponse
    -> GetCausalHashByPathResponse -> Bool)
-> (GetCausalHashByPathResponse
    -> GetCausalHashByPathResponse -> Bool)
-> (GetCausalHashByPathResponse
    -> GetCausalHashByPathResponse -> Bool)
-> (GetCausalHashByPathResponse
    -> GetCausalHashByPathResponse -> GetCausalHashByPathResponse)
-> (GetCausalHashByPathResponse
    -> GetCausalHashByPathResponse -> GetCausalHashByPathResponse)
-> Ord GetCausalHashByPathResponse
GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> Ordering
GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> GetCausalHashByPathResponse
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> Ordering
compare :: GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> Ordering
$c< :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
< :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
$c<= :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
<= :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
$c> :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
> :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
$c>= :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
>= :: GetCausalHashByPathResponse -> GetCausalHashByPathResponse -> Bool
$cmax :: GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> GetCausalHashByPathResponse
max :: GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> GetCausalHashByPathResponse
$cmin :: GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> GetCausalHashByPathResponse
min :: GetCausalHashByPathResponse
-> GetCausalHashByPathResponse -> GetCausalHashByPathResponse
Ord)

instance ToJSON GetCausalHashByPathResponse where
  toJSON :: GetCausalHashByPathResponse -> Value
toJSON = \case
    GetCausalHashByPathSuccess Maybe HashJWT
hashJWT -> Text -> Maybe HashJWT -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"success" Maybe HashJWT
hashJWT
    GetCausalHashByPathNoReadPermission Path
path -> Text -> Path -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"no_read_permission" Path
path
    GetCausalHashByPathResponse
GetCausalHashByPathUserNotFound -> Text -> () -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"user_not_found" ()
    GetCausalHashByPathInvalidRepoInfo Text
msg RepoInfo
repoInfo -> Text -> (Text, RepoInfo) -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"invalid_repo_info" (Text
msg, RepoInfo
repoInfo)

instance FromJSON GetCausalHashByPathResponse where
  parseJSON :: Value -> Parser GetCausalHashByPathResponse
parseJSON = String
-> (Object -> Parser GetCausalHashByPathResponse)
-> Value
-> Parser GetCausalHashByPathResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"GetCausalHashByPathResponse" \Object
obj -> do
    Object
obj Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" Parser Value
-> (Value -> Parser GetCausalHashByPathResponse)
-> Parser GetCausalHashByPathResponse
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String
-> (Text -> Parser GetCausalHashByPathResponse)
-> Value
-> Parser GetCausalHashByPathResponse
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"type" \case
      Text
"success" -> Maybe HashJWT -> GetCausalHashByPathResponse
GetCausalHashByPathSuccess (Maybe HashJWT -> GetCausalHashByPathResponse)
-> Parser (Maybe HashJWT) -> Parser GetCausalHashByPathResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Maybe HashJWT)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"no_read_permission" -> Path -> GetCausalHashByPathResponse
GetCausalHashByPathNoReadPermission (Path -> GetCausalHashByPathResponse)
-> Parser Path -> Parser GetCausalHashByPathResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser Path
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"user_not_found" -> GetCausalHashByPathResponse -> Parser GetCausalHashByPathResponse
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure GetCausalHashByPathResponse
GetCausalHashByPathUserNotFound
      Text
"invalid_repo_info" -> (Text -> RepoInfo -> GetCausalHashByPathResponse)
-> (Text, RepoInfo) -> GetCausalHashByPathResponse
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> RepoInfo -> GetCausalHashByPathResponse
GetCausalHashByPathInvalidRepoInfo ((Text, RepoInfo) -> GetCausalHashByPathResponse)
-> Parser (Text, RepoInfo) -> Parser GetCausalHashByPathResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Text, RepoInfo)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
t -> Text -> Parser GetCausalHashByPathResponse
forall (m :: * -> *) a. MonadFail m => Text -> m a
failText (Text -> Parser GetCausalHashByPathResponse)
-> Text -> Parser GetCausalHashByPathResponse
forall a b. (a -> b) -> a -> b
$ Text
"Unexpected GetCausalHashByPathResponse type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t

------------------------------------------------------------------------------------------------------------------------
-- Download entities

data DownloadEntitiesRequest = DownloadEntitiesRequest
  { DownloadEntitiesRequest -> RepoInfo
repoInfo :: RepoInfo,
    DownloadEntitiesRequest -> NESet HashJWT
hashes :: NESet HashJWT
  }
  deriving stock (Int -> DownloadEntitiesRequest -> ShowS
[DownloadEntitiesRequest] -> ShowS
DownloadEntitiesRequest -> String
(Int -> DownloadEntitiesRequest -> ShowS)
-> (DownloadEntitiesRequest -> String)
-> ([DownloadEntitiesRequest] -> ShowS)
-> Show DownloadEntitiesRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DownloadEntitiesRequest -> ShowS
showsPrec :: Int -> DownloadEntitiesRequest -> ShowS
$cshow :: DownloadEntitiesRequest -> String
show :: DownloadEntitiesRequest -> String
$cshowList :: [DownloadEntitiesRequest] -> ShowS
showList :: [DownloadEntitiesRequest] -> ShowS
Show, DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
(DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool)
-> (DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool)
-> Eq DownloadEntitiesRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
== :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
$c/= :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
/= :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
Eq, Eq DownloadEntitiesRequest
Eq DownloadEntitiesRequest =>
(DownloadEntitiesRequest -> DownloadEntitiesRequest -> Ordering)
-> (DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool)
-> (DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool)
-> (DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool)
-> (DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool)
-> (DownloadEntitiesRequest
    -> DownloadEntitiesRequest -> DownloadEntitiesRequest)
-> (DownloadEntitiesRequest
    -> DownloadEntitiesRequest -> DownloadEntitiesRequest)
-> Ord DownloadEntitiesRequest
DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
DownloadEntitiesRequest -> DownloadEntitiesRequest -> Ordering
DownloadEntitiesRequest
-> DownloadEntitiesRequest -> DownloadEntitiesRequest
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Ordering
compare :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Ordering
$c< :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
< :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
$c<= :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
<= :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
$c> :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
> :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
$c>= :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
>= :: DownloadEntitiesRequest -> DownloadEntitiesRequest -> Bool
$cmax :: DownloadEntitiesRequest
-> DownloadEntitiesRequest -> DownloadEntitiesRequest
max :: DownloadEntitiesRequest
-> DownloadEntitiesRequest -> DownloadEntitiesRequest
$cmin :: DownloadEntitiesRequest
-> DownloadEntitiesRequest -> DownloadEntitiesRequest
min :: DownloadEntitiesRequest
-> DownloadEntitiesRequest -> DownloadEntitiesRequest
Ord)

instance ToJSON DownloadEntitiesRequest where
  toJSON :: DownloadEntitiesRequest -> Value
toJSON (DownloadEntitiesRequest RepoInfo
repoInfo NESet HashJWT
hashes) =
    [Pair] -> Value
object
      [ Key
"repo_info" Key -> RepoInfo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= RepoInfo
repoInfo,
        Key
"hashes" Key -> NESet HashJWT -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= NESet HashJWT
hashes
      ]

instance FromJSON DownloadEntitiesRequest where
  parseJSON :: Value -> Parser DownloadEntitiesRequest
parseJSON = String
-> (Object -> Parser DownloadEntitiesRequest)
-> Value
-> Parser DownloadEntitiesRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"DownloadEntitiesRequest" \Object
obj -> do
    RepoInfo
repoInfo <-
      Object
obj Object -> Key -> Parser RepoInfo
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"repo_info" Parser RepoInfo -> Parser RepoInfo -> Parser RepoInfo
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> do
        -- Back-compat by converting old 'repo_name' fields into the new 'repo_info' format.
        Text
repoName <- Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"repo_name"
        RepoInfo -> Parser RepoInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RepoInfo -> Parser RepoInfo)
-> (Text -> RepoInfo) -> Text -> Parser RepoInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> RepoInfo
RepoInfo (Text -> Parser RepoInfo) -> Text -> Parser RepoInfo
forall a b. (a -> b) -> a -> b
$ Text
"@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
repoName
    NESet HashJWT
hashes <- Object
obj Object -> Key -> Parser (NESet HashJWT)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hashes"
    pure DownloadEntitiesRequest {NESet HashJWT
RepoInfo
$sel:repoInfo:DownloadEntitiesRequest :: RepoInfo
$sel:hashes:DownloadEntitiesRequest :: NESet HashJWT
repoInfo :: RepoInfo
hashes :: NESet HashJWT
..}

data DownloadEntitiesResponse
  = DownloadEntitiesSuccess (NEMap Hash32 (Entity Text Hash32 HashJWT))
  | DownloadEntitiesFailure DownloadEntitiesError

data DownloadEntitiesError
  = DownloadEntitiesNoReadPermission RepoInfo
  | -- | msg, repoInfo
    DownloadEntitiesInvalidRepoInfo Text RepoInfo
  | -- | userHandle
    DownloadEntitiesUserNotFound Text
  | -- | project shorthand
    DownloadEntitiesProjectNotFound Text
  | DownloadEntitiesEntityValidationFailure EntityValidationError
  deriving stock (DownloadEntitiesError -> DownloadEntitiesError -> Bool
(DownloadEntitiesError -> DownloadEntitiesError -> Bool)
-> (DownloadEntitiesError -> DownloadEntitiesError -> Bool)
-> Eq DownloadEntitiesError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DownloadEntitiesError -> DownloadEntitiesError -> Bool
== :: DownloadEntitiesError -> DownloadEntitiesError -> Bool
$c/= :: DownloadEntitiesError -> DownloadEntitiesError -> Bool
/= :: DownloadEntitiesError -> DownloadEntitiesError -> Bool
Eq, Int -> DownloadEntitiesError -> ShowS
[DownloadEntitiesError] -> ShowS
DownloadEntitiesError -> String
(Int -> DownloadEntitiesError -> ShowS)
-> (DownloadEntitiesError -> String)
-> ([DownloadEntitiesError] -> ShowS)
-> Show DownloadEntitiesError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DownloadEntitiesError -> ShowS
showsPrec :: Int -> DownloadEntitiesError -> ShowS
$cshow :: DownloadEntitiesError -> String
show :: DownloadEntitiesError -> String
$cshowList :: [DownloadEntitiesError] -> ShowS
showList :: [DownloadEntitiesError] -> ShowS
Show)

instance ToJSON DownloadEntitiesResponse where
  toJSON :: DownloadEntitiesResponse -> Value
toJSON = \case
    DownloadEntitiesSuccess NEMap Hash32 (Entity Text Hash32 HashJWT)
entities -> Text -> NEMap Hash32 (Entity Text Hash32 HashJWT) -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"success" NEMap Hash32 (Entity Text Hash32 HashJWT)
entities
    DownloadEntitiesFailure (DownloadEntitiesNoReadPermission RepoInfo
repoInfo) -> Text -> RepoInfo -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"no_read_permission" RepoInfo
repoInfo
    DownloadEntitiesFailure (DownloadEntitiesInvalidRepoInfo Text
msg RepoInfo
repoInfo) -> Text -> (Text, RepoInfo) -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"invalid_repo_info" (Text
msg, RepoInfo
repoInfo)
    DownloadEntitiesFailure (DownloadEntitiesUserNotFound Text
userHandle) -> Text -> Text -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"user_not_found" Text
userHandle
    DownloadEntitiesFailure (DownloadEntitiesProjectNotFound Text
projectShorthand) -> Text -> Text -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"project_not_found" Text
projectShorthand
    DownloadEntitiesFailure (DownloadEntitiesEntityValidationFailure EntityValidationError
err) -> Text -> EntityValidationError -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"entity_validation_failure" EntityValidationError
err

instance FromJSON DownloadEntitiesResponse where
  parseJSON :: Value -> Parser DownloadEntitiesResponse
parseJSON = String
-> (Object -> Parser DownloadEntitiesResponse)
-> Value
-> Parser DownloadEntitiesResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"DownloadEntitiesResponse" \Object
obj ->
    Object
obj Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" Parser Value
-> (Value -> Parser DownloadEntitiesResponse)
-> Parser DownloadEntitiesResponse
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String
-> (Text -> Parser DownloadEntitiesResponse)
-> Value
-> Parser DownloadEntitiesResponse
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"type" \case
      Text
"success" -> NEMap Hash32 (Entity Text Hash32 HashJWT)
-> DownloadEntitiesResponse
DownloadEntitiesSuccess (NEMap Hash32 (Entity Text Hash32 HashJWT)
 -> DownloadEntitiesResponse)
-> Parser (NEMap Hash32 (Entity Text Hash32 HashJWT))
-> Parser DownloadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (NEMap Hash32 (Entity Text Hash32 HashJWT))
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"no_read_permission" -> DownloadEntitiesError -> DownloadEntitiesResponse
DownloadEntitiesFailure (DownloadEntitiesError -> DownloadEntitiesResponse)
-> (RepoInfo -> DownloadEntitiesError)
-> RepoInfo
-> DownloadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RepoInfo -> DownloadEntitiesError
DownloadEntitiesNoReadPermission (RepoInfo -> DownloadEntitiesResponse)
-> Parser RepoInfo -> Parser DownloadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser RepoInfo
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"invalid_repo_info" -> DownloadEntitiesError -> DownloadEntitiesResponse
DownloadEntitiesFailure (DownloadEntitiesError -> DownloadEntitiesResponse)
-> ((Text, RepoInfo) -> DownloadEntitiesError)
-> (Text, RepoInfo)
-> DownloadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> RepoInfo -> DownloadEntitiesError)
-> (Text, RepoInfo) -> DownloadEntitiesError
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> RepoInfo -> DownloadEntitiesError
DownloadEntitiesInvalidRepoInfo ((Text, RepoInfo) -> DownloadEntitiesResponse)
-> Parser (Text, RepoInfo) -> Parser DownloadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (Text, RepoInfo)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"user_not_found" -> DownloadEntitiesError -> DownloadEntitiesResponse
DownloadEntitiesFailure (DownloadEntitiesError -> DownloadEntitiesResponse)
-> (Text -> DownloadEntitiesError)
-> Text
-> DownloadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> DownloadEntitiesError
DownloadEntitiesUserNotFound (Text -> DownloadEntitiesResponse)
-> Parser Text -> Parser DownloadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"project_not_found" -> DownloadEntitiesError -> DownloadEntitiesResponse
DownloadEntitiesFailure (DownloadEntitiesError -> DownloadEntitiesResponse)
-> (Text -> DownloadEntitiesError)
-> Text
-> DownloadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> DownloadEntitiesError
DownloadEntitiesProjectNotFound (Text -> DownloadEntitiesResponse)
-> Parser Text -> Parser DownloadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
t -> Text -> Parser DownloadEntitiesResponse
forall (m :: * -> *) a. MonadFail m => Text -> m a
failText (Text -> Parser DownloadEntitiesResponse)
-> Text -> Parser DownloadEntitiesResponse
forall a b. (a -> b) -> a -> b
$ Text
"Unexpected DownloadEntitiesResponse type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t

-- | The ways in which validating an entity may fail.
data EntityValidationError
  = EntityHashMismatch EntityType HashMismatchForEntity
  | UnsupportedEntityType Hash32 EntityType
  | InvalidByteEncoding Hash32 EntityType Text {- decoding err msg -}
  | HashResolutionFailure Hash32
  deriving stock (Int -> EntityValidationError -> ShowS
[EntityValidationError] -> ShowS
EntityValidationError -> String
(Int -> EntityValidationError -> ShowS)
-> (EntityValidationError -> String)
-> ([EntityValidationError] -> ShowS)
-> Show EntityValidationError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EntityValidationError -> ShowS
showsPrec :: Int -> EntityValidationError -> ShowS
$cshow :: EntityValidationError -> String
show :: EntityValidationError -> String
$cshowList :: [EntityValidationError] -> ShowS
showList :: [EntityValidationError] -> ShowS
Show, EntityValidationError -> EntityValidationError -> Bool
(EntityValidationError -> EntityValidationError -> Bool)
-> (EntityValidationError -> EntityValidationError -> Bool)
-> Eq EntityValidationError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EntityValidationError -> EntityValidationError -> Bool
== :: EntityValidationError -> EntityValidationError -> Bool
$c/= :: EntityValidationError -> EntityValidationError -> Bool
/= :: EntityValidationError -> EntityValidationError -> Bool
Eq, Eq EntityValidationError
Eq EntityValidationError =>
(EntityValidationError -> EntityValidationError -> Ordering)
-> (EntityValidationError -> EntityValidationError -> Bool)
-> (EntityValidationError -> EntityValidationError -> Bool)
-> (EntityValidationError -> EntityValidationError -> Bool)
-> (EntityValidationError -> EntityValidationError -> Bool)
-> (EntityValidationError
    -> EntityValidationError -> EntityValidationError)
-> (EntityValidationError
    -> EntityValidationError -> EntityValidationError)
-> Ord EntityValidationError
EntityValidationError -> EntityValidationError -> Bool
EntityValidationError -> EntityValidationError -> Ordering
EntityValidationError
-> EntityValidationError -> EntityValidationError
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: EntityValidationError -> EntityValidationError -> Ordering
compare :: EntityValidationError -> EntityValidationError -> Ordering
$c< :: EntityValidationError -> EntityValidationError -> Bool
< :: EntityValidationError -> EntityValidationError -> Bool
$c<= :: EntityValidationError -> EntityValidationError -> Bool
<= :: EntityValidationError -> EntityValidationError -> Bool
$c> :: EntityValidationError -> EntityValidationError -> Bool
> :: EntityValidationError -> EntityValidationError -> Bool
$c>= :: EntityValidationError -> EntityValidationError -> Bool
>= :: EntityValidationError -> EntityValidationError -> Bool
$cmax :: EntityValidationError
-> EntityValidationError -> EntityValidationError
max :: EntityValidationError
-> EntityValidationError -> EntityValidationError
$cmin :: EntityValidationError
-> EntityValidationError -> EntityValidationError
min :: EntityValidationError
-> EntityValidationError -> EntityValidationError
Ord)
  deriving anyclass (Show EntityValidationError
Typeable EntityValidationError
(Typeable EntityValidationError, Show EntityValidationError) =>
(EntityValidationError -> SomeException)
-> (SomeException -> Maybe EntityValidationError)
-> (EntityValidationError -> String)
-> Exception EntityValidationError
SomeException -> Maybe EntityValidationError
EntityValidationError -> String
EntityValidationError -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: EntityValidationError -> SomeException
toException :: EntityValidationError -> SomeException
$cfromException :: SomeException -> Maybe EntityValidationError
fromException :: SomeException -> Maybe EntityValidationError
$cdisplayException :: EntityValidationError -> String
displayException :: EntityValidationError -> String
Exception)

instance ToJSON EntityValidationError where
  toJSON :: EntityValidationError -> Value
toJSON = \case
    EntityHashMismatch EntityType
typ HashMismatchForEntity
mismatch -> Text -> Value -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"mismatched_hash" ([Pair] -> Value
object [Key
"type" Key -> EntityType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= EntityType
typ, Key
"mismatch" Key -> HashMismatchForEntity -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= HashMismatchForEntity
mismatch])
    UnsupportedEntityType Hash32
hash EntityType
typ -> Text -> Value -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"unsupported_entity_type" ([Pair] -> Value
object [Key
"hash" Key -> Hash32 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Hash32
hash, Key
"type" Key -> EntityType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= EntityType
typ])
    InvalidByteEncoding Hash32
hash EntityType
typ Text
errMsg -> Text -> Value -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"invalid_byte_encoding" ([Pair] -> Value
object [Key
"hash" Key -> Hash32 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Hash32
hash, Key
"type" Key -> EntityType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= EntityType
typ, Key
"error" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Text
errMsg])
    HashResolutionFailure Hash32
hash -> Text -> Hash32 -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"hash_resolution_failure" Hash32
hash

instance FromJSON EntityValidationError where
  parseJSON :: Value -> Parser EntityValidationError
parseJSON = String
-> (Object -> Parser EntityValidationError)
-> Value
-> Parser EntityValidationError
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"EntityValidationError" \Object
obj ->
    Object
obj Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" Parser Value
-> (Value -> Parser EntityValidationError)
-> Parser EntityValidationError
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String
-> (Text -> Parser EntityValidationError)
-> Value
-> Parser EntityValidationError
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"type" \case
      Text
"mismatched_hash" -> do
        EntityType
typ <- Object
obj Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload" Parser Object -> (Object -> Parser EntityType) -> Parser EntityType
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser EntityType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type")
        HashMismatchForEntity
mismatch <- Object
obj Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload" Parser Object
-> (Object -> Parser HashMismatchForEntity)
-> Parser HashMismatchForEntity
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser HashMismatchForEntity
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"mismatch")
        pure (EntityType -> HashMismatchForEntity -> EntityValidationError
EntityHashMismatch EntityType
typ HashMismatchForEntity
mismatch)
      Text
"unsupported_entity_type" -> do
        Hash32
hash <- Object
obj Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload" Parser Object -> (Object -> Parser Hash32) -> Parser Hash32
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser Hash32
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hash")
        EntityType
typ <- Object
obj Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload" Parser Object -> (Object -> Parser EntityType) -> Parser EntityType
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser EntityType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type")
        pure (Hash32 -> EntityType -> EntityValidationError
UnsupportedEntityType Hash32
hash EntityType
typ)
      Text
"invalid_byte_encoding" -> do
        Hash32
hash <- Object
obj Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload" Parser Object -> (Object -> Parser Hash32) -> Parser Hash32
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser Hash32
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hash")
        EntityType
typ <- Object
obj Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload" Parser Object -> (Object -> Parser EntityType) -> Parser EntityType
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser EntityType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type")
        Text
errMsg <- Object
obj Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload" Parser Object -> (Object -> Parser Text) -> Parser Text
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"error")
        pure (Hash32 -> EntityType -> Text -> EntityValidationError
InvalidByteEncoding Hash32
hash EntityType
typ Text
errMsg)
      Text
t -> Text -> Parser EntityValidationError
forall (m :: * -> *) a. MonadFail m => Text -> m a
failText (Text -> Parser EntityValidationError)
-> Text -> Parser EntityValidationError
forall a b. (a -> b) -> a -> b
$ Text
"Unexpected EntityValidationError type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t

------------------------------------------------------------------------------------------------------------------------
-- Upload entities

data UploadEntitiesRequest = UploadEntitiesRequest
  { UploadEntitiesRequest -> RepoInfo
repoInfo :: RepoInfo,
    UploadEntitiesRequest -> NEMap Hash32 (Entity Text Hash32 Hash32)
entities :: NEMap Hash32 (Entity Text Hash32 Hash32)
  }
  deriving stock (Int -> UploadEntitiesRequest -> ShowS
[UploadEntitiesRequest] -> ShowS
UploadEntitiesRequest -> String
(Int -> UploadEntitiesRequest -> ShowS)
-> (UploadEntitiesRequest -> String)
-> ([UploadEntitiesRequest] -> ShowS)
-> Show UploadEntitiesRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UploadEntitiesRequest -> ShowS
showsPrec :: Int -> UploadEntitiesRequest -> ShowS
$cshow :: UploadEntitiesRequest -> String
show :: UploadEntitiesRequest -> String
$cshowList :: [UploadEntitiesRequest] -> ShowS
showList :: [UploadEntitiesRequest] -> ShowS
Show, UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
(UploadEntitiesRequest -> UploadEntitiesRequest -> Bool)
-> (UploadEntitiesRequest -> UploadEntitiesRequest -> Bool)
-> Eq UploadEntitiesRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
== :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
$c/= :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
/= :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
Eq, Eq UploadEntitiesRequest
Eq UploadEntitiesRequest =>
(UploadEntitiesRequest -> UploadEntitiesRequest -> Ordering)
-> (UploadEntitiesRequest -> UploadEntitiesRequest -> Bool)
-> (UploadEntitiesRequest -> UploadEntitiesRequest -> Bool)
-> (UploadEntitiesRequest -> UploadEntitiesRequest -> Bool)
-> (UploadEntitiesRequest -> UploadEntitiesRequest -> Bool)
-> (UploadEntitiesRequest
    -> UploadEntitiesRequest -> UploadEntitiesRequest)
-> (UploadEntitiesRequest
    -> UploadEntitiesRequest -> UploadEntitiesRequest)
-> Ord UploadEntitiesRequest
UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
UploadEntitiesRequest -> UploadEntitiesRequest -> Ordering
UploadEntitiesRequest
-> UploadEntitiesRequest -> UploadEntitiesRequest
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UploadEntitiesRequest -> UploadEntitiesRequest -> Ordering
compare :: UploadEntitiesRequest -> UploadEntitiesRequest -> Ordering
$c< :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
< :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
$c<= :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
<= :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
$c> :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
> :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
$c>= :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
>= :: UploadEntitiesRequest -> UploadEntitiesRequest -> Bool
$cmax :: UploadEntitiesRequest
-> UploadEntitiesRequest -> UploadEntitiesRequest
max :: UploadEntitiesRequest
-> UploadEntitiesRequest -> UploadEntitiesRequest
$cmin :: UploadEntitiesRequest
-> UploadEntitiesRequest -> UploadEntitiesRequest
min :: UploadEntitiesRequest
-> UploadEntitiesRequest -> UploadEntitiesRequest
Ord)

instance ToJSON UploadEntitiesRequest where
  toJSON :: UploadEntitiesRequest -> Value
toJSON (UploadEntitiesRequest RepoInfo
repoInfo NEMap Hash32 (Entity Text Hash32 Hash32)
entities) =
    [Pair] -> Value
object
      [ Key
"repo_info" Key -> RepoInfo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= RepoInfo
repoInfo,
        Key
"entities" Key -> NEMap Hash32 (Entity Text Hash32 Hash32) -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= NEMap Hash32 (Entity Text Hash32 Hash32)
entities
      ]

instance FromJSON UploadEntitiesRequest where
  parseJSON :: Value -> Parser UploadEntitiesRequest
parseJSON = String
-> (Object -> Parser UploadEntitiesRequest)
-> Value
-> Parser UploadEntitiesRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"UploadEntitiesRequest" \Object
obj -> do
    RepoInfo
repoInfo <-
      Object
obj Object -> Key -> Parser RepoInfo
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"repo_info" Parser RepoInfo -> Parser RepoInfo -> Parser RepoInfo
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> do
        -- Back-compat by converting old 'repo_name' fields into the new 'repo_info' format.
        Text
repoName <- Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"repo_name"
        RepoInfo -> Parser RepoInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RepoInfo -> Parser RepoInfo)
-> (Text -> RepoInfo) -> Text -> Parser RepoInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> RepoInfo
RepoInfo (Text -> Parser RepoInfo) -> Text -> Parser RepoInfo
forall a b. (a -> b) -> a -> b
$ Text
"@" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
repoName
    NEMap Hash32 (Entity Text Hash32 Hash32)
entities <- Object
obj Object -> Key -> Parser (NEMap Hash32 (Entity Text Hash32 Hash32))
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"entities"
    pure UploadEntitiesRequest {NEMap Hash32 (Entity Text Hash32 Hash32)
RepoInfo
$sel:repoInfo:UploadEntitiesRequest :: RepoInfo
$sel:entities:UploadEntitiesRequest :: NEMap Hash32 (Entity Text Hash32 Hash32)
repoInfo :: RepoInfo
entities :: NEMap Hash32 (Entity Text Hash32 Hash32)
..}

data UploadEntitiesResponse
  = UploadEntitiesSuccess
  | UploadEntitiesFailure UploadEntitiesError
  deriving stock (Int -> UploadEntitiesResponse -> ShowS
[UploadEntitiesResponse] -> ShowS
UploadEntitiesResponse -> String
(Int -> UploadEntitiesResponse -> ShowS)
-> (UploadEntitiesResponse -> String)
-> ([UploadEntitiesResponse] -> ShowS)
-> Show UploadEntitiesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UploadEntitiesResponse -> ShowS
showsPrec :: Int -> UploadEntitiesResponse -> ShowS
$cshow :: UploadEntitiesResponse -> String
show :: UploadEntitiesResponse -> String
$cshowList :: [UploadEntitiesResponse] -> ShowS
showList :: [UploadEntitiesResponse] -> ShowS
Show, UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
(UploadEntitiesResponse -> UploadEntitiesResponse -> Bool)
-> (UploadEntitiesResponse -> UploadEntitiesResponse -> Bool)
-> Eq UploadEntitiesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
== :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
$c/= :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
/= :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
Eq, Eq UploadEntitiesResponse
Eq UploadEntitiesResponse =>
(UploadEntitiesResponse -> UploadEntitiesResponse -> Ordering)
-> (UploadEntitiesResponse -> UploadEntitiesResponse -> Bool)
-> (UploadEntitiesResponse -> UploadEntitiesResponse -> Bool)
-> (UploadEntitiesResponse -> UploadEntitiesResponse -> Bool)
-> (UploadEntitiesResponse -> UploadEntitiesResponse -> Bool)
-> (UploadEntitiesResponse
    -> UploadEntitiesResponse -> UploadEntitiesResponse)
-> (UploadEntitiesResponse
    -> UploadEntitiesResponse -> UploadEntitiesResponse)
-> Ord UploadEntitiesResponse
UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
UploadEntitiesResponse -> UploadEntitiesResponse -> Ordering
UploadEntitiesResponse
-> UploadEntitiesResponse -> UploadEntitiesResponse
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UploadEntitiesResponse -> UploadEntitiesResponse -> Ordering
compare :: UploadEntitiesResponse -> UploadEntitiesResponse -> Ordering
$c< :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
< :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
$c<= :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
<= :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
$c> :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
> :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
$c>= :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
>= :: UploadEntitiesResponse -> UploadEntitiesResponse -> Bool
$cmax :: UploadEntitiesResponse
-> UploadEntitiesResponse -> UploadEntitiesResponse
max :: UploadEntitiesResponse
-> UploadEntitiesResponse -> UploadEntitiesResponse
$cmin :: UploadEntitiesResponse
-> UploadEntitiesResponse -> UploadEntitiesResponse
min :: UploadEntitiesResponse
-> UploadEntitiesResponse -> UploadEntitiesResponse
Ord)

data UploadEntitiesError
  = UploadEntitiesError'EntityValidationFailure EntityValidationError
  | UploadEntitiesError'HashMismatchForEntity HashMismatchForEntity
  | -- | msg, repoInfo
    UploadEntitiesError'InvalidRepoInfo Text RepoInfo
  | UploadEntitiesError'NeedDependencies (NeedDependencies Hash32)
  | UploadEntitiesError'NoWritePermission RepoInfo
  | -- | project shorthand
    UploadEntitiesError'ProjectNotFound Text
  | -- | userHandle
    UploadEntitiesError'UserNotFound Text
  deriving stock (Int -> UploadEntitiesError -> ShowS
[UploadEntitiesError] -> ShowS
UploadEntitiesError -> String
(Int -> UploadEntitiesError -> ShowS)
-> (UploadEntitiesError -> String)
-> ([UploadEntitiesError] -> ShowS)
-> Show UploadEntitiesError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> UploadEntitiesError -> ShowS
showsPrec :: Int -> UploadEntitiesError -> ShowS
$cshow :: UploadEntitiesError -> String
show :: UploadEntitiesError -> String
$cshowList :: [UploadEntitiesError] -> ShowS
showList :: [UploadEntitiesError] -> ShowS
Show, UploadEntitiesError -> UploadEntitiesError -> Bool
(UploadEntitiesError -> UploadEntitiesError -> Bool)
-> (UploadEntitiesError -> UploadEntitiesError -> Bool)
-> Eq UploadEntitiesError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: UploadEntitiesError -> UploadEntitiesError -> Bool
== :: UploadEntitiesError -> UploadEntitiesError -> Bool
$c/= :: UploadEntitiesError -> UploadEntitiesError -> Bool
/= :: UploadEntitiesError -> UploadEntitiesError -> Bool
Eq, Eq UploadEntitiesError
Eq UploadEntitiesError =>
(UploadEntitiesError -> UploadEntitiesError -> Ordering)
-> (UploadEntitiesError -> UploadEntitiesError -> Bool)
-> (UploadEntitiesError -> UploadEntitiesError -> Bool)
-> (UploadEntitiesError -> UploadEntitiesError -> Bool)
-> (UploadEntitiesError -> UploadEntitiesError -> Bool)
-> (UploadEntitiesError
    -> UploadEntitiesError -> UploadEntitiesError)
-> (UploadEntitiesError
    -> UploadEntitiesError -> UploadEntitiesError)
-> Ord UploadEntitiesError
UploadEntitiesError -> UploadEntitiesError -> Bool
UploadEntitiesError -> UploadEntitiesError -> Ordering
UploadEntitiesError -> UploadEntitiesError -> UploadEntitiesError
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: UploadEntitiesError -> UploadEntitiesError -> Ordering
compare :: UploadEntitiesError -> UploadEntitiesError -> Ordering
$c< :: UploadEntitiesError -> UploadEntitiesError -> Bool
< :: UploadEntitiesError -> UploadEntitiesError -> Bool
$c<= :: UploadEntitiesError -> UploadEntitiesError -> Bool
<= :: UploadEntitiesError -> UploadEntitiesError -> Bool
$c> :: UploadEntitiesError -> UploadEntitiesError -> Bool
> :: UploadEntitiesError -> UploadEntitiesError -> Bool
$c>= :: UploadEntitiesError -> UploadEntitiesError -> Bool
>= :: UploadEntitiesError -> UploadEntitiesError -> Bool
$cmax :: UploadEntitiesError -> UploadEntitiesError -> UploadEntitiesError
max :: UploadEntitiesError -> UploadEntitiesError -> UploadEntitiesError
$cmin :: UploadEntitiesError -> UploadEntitiesError -> UploadEntitiesError
min :: UploadEntitiesError -> UploadEntitiesError -> UploadEntitiesError
Ord)

data HashMismatchForEntity = HashMismatchForEntity
  { HashMismatchForEntity -> Hash32
supplied :: Hash32,
    HashMismatchForEntity -> Hash32
computed :: Hash32
  }
  deriving stock (Int -> HashMismatchForEntity -> ShowS
[HashMismatchForEntity] -> ShowS
HashMismatchForEntity -> String
(Int -> HashMismatchForEntity -> ShowS)
-> (HashMismatchForEntity -> String)
-> ([HashMismatchForEntity] -> ShowS)
-> Show HashMismatchForEntity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HashMismatchForEntity -> ShowS
showsPrec :: Int -> HashMismatchForEntity -> ShowS
$cshow :: HashMismatchForEntity -> String
show :: HashMismatchForEntity -> String
$cshowList :: [HashMismatchForEntity] -> ShowS
showList :: [HashMismatchForEntity] -> ShowS
Show, HashMismatchForEntity -> HashMismatchForEntity -> Bool
(HashMismatchForEntity -> HashMismatchForEntity -> Bool)
-> (HashMismatchForEntity -> HashMismatchForEntity -> Bool)
-> Eq HashMismatchForEntity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
== :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
$c/= :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
/= :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
Eq, Eq HashMismatchForEntity
Eq HashMismatchForEntity =>
(HashMismatchForEntity -> HashMismatchForEntity -> Ordering)
-> (HashMismatchForEntity -> HashMismatchForEntity -> Bool)
-> (HashMismatchForEntity -> HashMismatchForEntity -> Bool)
-> (HashMismatchForEntity -> HashMismatchForEntity -> Bool)
-> (HashMismatchForEntity -> HashMismatchForEntity -> Bool)
-> (HashMismatchForEntity
    -> HashMismatchForEntity -> HashMismatchForEntity)
-> (HashMismatchForEntity
    -> HashMismatchForEntity -> HashMismatchForEntity)
-> Ord HashMismatchForEntity
HashMismatchForEntity -> HashMismatchForEntity -> Bool
HashMismatchForEntity -> HashMismatchForEntity -> Ordering
HashMismatchForEntity
-> HashMismatchForEntity -> HashMismatchForEntity
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: HashMismatchForEntity -> HashMismatchForEntity -> Ordering
compare :: HashMismatchForEntity -> HashMismatchForEntity -> Ordering
$c< :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
< :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
$c<= :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
<= :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
$c> :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
> :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
$c>= :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
>= :: HashMismatchForEntity -> HashMismatchForEntity -> Bool
$cmax :: HashMismatchForEntity
-> HashMismatchForEntity -> HashMismatchForEntity
max :: HashMismatchForEntity
-> HashMismatchForEntity -> HashMismatchForEntity
$cmin :: HashMismatchForEntity
-> HashMismatchForEntity -> HashMismatchForEntity
min :: HashMismatchForEntity
-> HashMismatchForEntity -> HashMismatchForEntity
Ord)

instance ToJSON UploadEntitiesResponse where
  toJSON :: UploadEntitiesResponse -> Value
toJSON = \case
    UploadEntitiesResponse
UploadEntitiesSuccess -> Text -> Value -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"success" (Object -> Value
Object Object
forall a. Monoid a => a
mempty)
    UploadEntitiesFailure (UploadEntitiesError'EntityValidationFailure EntityValidationError
err) ->
      Text -> EntityValidationError -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"entity_validation_failure" EntityValidationError
err
    UploadEntitiesFailure (UploadEntitiesError'HashMismatchForEntity HashMismatchForEntity
mismatch) ->
      Text -> HashMismatchForEntity -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"hash_mismatch_for_entity" HashMismatchForEntity
mismatch
    UploadEntitiesFailure (UploadEntitiesError'InvalidRepoInfo Text
msg RepoInfo
repoInfo) ->
      Text -> (Text, RepoInfo) -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"invalid_repo_info" (Text
msg, RepoInfo
repoInfo)
    UploadEntitiesFailure (UploadEntitiesError'NeedDependencies NeedDependencies Hash32
nd) -> Text -> NeedDependencies Hash32 -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"need_dependencies" NeedDependencies Hash32
nd
    UploadEntitiesFailure (UploadEntitiesError'NoWritePermission RepoInfo
repoInfo) -> Text -> RepoInfo -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"no_write_permission" RepoInfo
repoInfo
    UploadEntitiesFailure (UploadEntitiesError'ProjectNotFound Text
projectShorthand) ->
      Text -> Text -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"project_not_found" Text
projectShorthand
    UploadEntitiesFailure (UploadEntitiesError'UserNotFound Text
userHandle) -> Text -> Text -> Value
forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
"user_not_found" Text
userHandle

instance FromJSON UploadEntitiesResponse where
  parseJSON :: Value -> Parser UploadEntitiesResponse
parseJSON = String
-> (Object -> Parser UploadEntitiesResponse)
-> Value
-> Parser UploadEntitiesResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"UploadEntitiesResponse" \Object
obj ->
    Object
obj Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" Parser Value
-> (Value -> Parser UploadEntitiesResponse)
-> Parser UploadEntitiesResponse
forall a b. Parser a -> (a -> Parser b) -> Parser b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String
-> (Text -> Parser UploadEntitiesResponse)
-> Value
-> Parser UploadEntitiesResponse
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"type" \case
      Text
"success" -> UploadEntitiesResponse -> Parser UploadEntitiesResponse
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure UploadEntitiesResponse
UploadEntitiesSuccess
      Text
"entity_validation_failure" -> UploadEntitiesError -> UploadEntitiesResponse
UploadEntitiesFailure (UploadEntitiesError -> UploadEntitiesResponse)
-> (EntityValidationError -> UploadEntitiesError)
-> EntityValidationError
-> UploadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EntityValidationError -> UploadEntitiesError
UploadEntitiesError'EntityValidationFailure (EntityValidationError -> UploadEntitiesResponse)
-> Parser EntityValidationError -> Parser UploadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser EntityValidationError
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"need_dependencies" -> UploadEntitiesError -> UploadEntitiesResponse
UploadEntitiesFailure (UploadEntitiesError -> UploadEntitiesResponse)
-> (NeedDependencies Hash32 -> UploadEntitiesError)
-> NeedDependencies Hash32
-> UploadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NeedDependencies Hash32 -> UploadEntitiesError
UploadEntitiesError'NeedDependencies (NeedDependencies Hash32 -> UploadEntitiesResponse)
-> Parser (NeedDependencies Hash32)
-> Parser UploadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser (NeedDependencies Hash32)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"no_write_permission" -> UploadEntitiesError -> UploadEntitiesResponse
UploadEntitiesFailure (UploadEntitiesError -> UploadEntitiesResponse)
-> (RepoInfo -> UploadEntitiesError)
-> RepoInfo
-> UploadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RepoInfo -> UploadEntitiesError
UploadEntitiesError'NoWritePermission (RepoInfo -> UploadEntitiesResponse)
-> Parser RepoInfo -> Parser UploadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser RepoInfo
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"hash_mismatch_for_entity" ->
        UploadEntitiesError -> UploadEntitiesResponse
UploadEntitiesFailure (UploadEntitiesError -> UploadEntitiesResponse)
-> (HashMismatchForEntity -> UploadEntitiesError)
-> HashMismatchForEntity
-> UploadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMismatchForEntity -> UploadEntitiesError
UploadEntitiesError'HashMismatchForEntity (HashMismatchForEntity -> UploadEntitiesResponse)
-> Parser HashMismatchForEntity -> Parser UploadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser HashMismatchForEntity
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"invalid_repo_info" -> do
        (Text
msg, RepoInfo
repoInfo) <- Object
obj Object -> Key -> Parser (Text, RepoInfo)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
        UploadEntitiesResponse -> Parser UploadEntitiesResponse
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UploadEntitiesError -> UploadEntitiesResponse
UploadEntitiesFailure (Text -> RepoInfo -> UploadEntitiesError
UploadEntitiesError'InvalidRepoInfo Text
msg RepoInfo
repoInfo))
      Text
"user_not_found" -> UploadEntitiesError -> UploadEntitiesResponse
UploadEntitiesFailure (UploadEntitiesError -> UploadEntitiesResponse)
-> (Text -> UploadEntitiesError) -> Text -> UploadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> UploadEntitiesError
UploadEntitiesError'UserNotFound (Text -> UploadEntitiesResponse)
-> Parser Text -> Parser UploadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
"project_not_found" -> UploadEntitiesError -> UploadEntitiesResponse
UploadEntitiesFailure (UploadEntitiesError -> UploadEntitiesResponse)
-> (Text -> UploadEntitiesError) -> Text -> UploadEntitiesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> UploadEntitiesError
UploadEntitiesError'ProjectNotFound (Text -> UploadEntitiesResponse)
-> Parser Text -> Parser UploadEntitiesResponse
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"payload"
      Text
t -> Text -> Parser UploadEntitiesResponse
forall (m :: * -> *) a. MonadFail m => Text -> m a
failText (Text -> Parser UploadEntitiesResponse)
-> Text -> Parser UploadEntitiesResponse
forall a b. (a -> b) -> a -> b
$ Text
"Unexpected UploadEntitiesResponse type: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t

instance ToJSON HashMismatchForEntity where
  toJSON :: HashMismatchForEntity -> Value
toJSON (HashMismatchForEntity Hash32
supplied Hash32
computed) =
    [Pair] -> Value
object
      [ Key
"supplied" Key -> Hash32 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Hash32
supplied,
        Key
"computed" Key -> Hash32 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Hash32
computed
      ]

instance FromJSON HashMismatchForEntity where
  parseJSON :: Value -> Parser HashMismatchForEntity
parseJSON =
    String
-> (Object -> Parser HashMismatchForEntity)
-> Value
-> Parser HashMismatchForEntity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"HashMismatchForEntity" \Object
obj ->
      Hash32 -> Hash32 -> HashMismatchForEntity
HashMismatchForEntity
        (Hash32 -> Hash32 -> HashMismatchForEntity)
-> Parser Hash32 -> Parser (Hash32 -> HashMismatchForEntity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj
          Object -> Key -> Parser Hash32
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"supplied"
        Parser (Hash32 -> HashMismatchForEntity)
-> Parser Hash32 -> Parser HashMismatchForEntity
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
obj
          Object -> Key -> Parser Hash32
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"computed"

data InvalidParentage = InvalidParentage {InvalidParentage -> Hash32
parent :: Hash32, InvalidParentage -> Hash32
child :: Hash32}
  deriving stock (Int -> InvalidParentage -> ShowS
[InvalidParentage] -> ShowS
InvalidParentage -> String
(Int -> InvalidParentage -> ShowS)
-> (InvalidParentage -> String)
-> ([InvalidParentage] -> ShowS)
-> Show InvalidParentage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InvalidParentage -> ShowS
showsPrec :: Int -> InvalidParentage -> ShowS
$cshow :: InvalidParentage -> String
show :: InvalidParentage -> String
$cshowList :: [InvalidParentage] -> ShowS
showList :: [InvalidParentage] -> ShowS
Show)

instance ToJSON InvalidParentage where
  toJSON :: InvalidParentage -> Value
toJSON (InvalidParentage Hash32
parent Hash32
child) = [Pair] -> Value
object [Key
"parent" Key -> Hash32 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Hash32
parent, Key
"child" Key -> Hash32 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Hash32
child]

instance FromJSON InvalidParentage where
  parseJSON :: Value -> Parser InvalidParentage
parseJSON =
    String
-> (Object -> Parser InvalidParentage)
-> Value
-> Parser InvalidParentage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"InvalidParentage" \Object
o -> Hash32 -> Hash32 -> InvalidParentage
InvalidParentage (Hash32 -> Hash32 -> InvalidParentage)
-> Parser Hash32 -> Parser (Hash32 -> InvalidParentage)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Hash32
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parent" Parser (Hash32 -> InvalidParentage)
-> Parser Hash32 -> Parser InvalidParentage
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Hash32
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"child"

------------------------------------------------------------------------------------------------------------------------
-- Common/shared error types

data NeedDependencies hash = NeedDependencies
  { forall hash. NeedDependencies hash -> NESet hash
missingDependencies :: NESet hash
  }
  deriving stock (Int -> NeedDependencies hash -> ShowS
[NeedDependencies hash] -> ShowS
NeedDependencies hash -> String
(Int -> NeedDependencies hash -> ShowS)
-> (NeedDependencies hash -> String)
-> ([NeedDependencies hash] -> ShowS)
-> Show (NeedDependencies hash)
forall hash. Show hash => Int -> NeedDependencies hash -> ShowS
forall hash. Show hash => [NeedDependencies hash] -> ShowS
forall hash. Show hash => NeedDependencies hash -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall hash. Show hash => Int -> NeedDependencies hash -> ShowS
showsPrec :: Int -> NeedDependencies hash -> ShowS
$cshow :: forall hash. Show hash => NeedDependencies hash -> String
show :: NeedDependencies hash -> String
$cshowList :: forall hash. Show hash => [NeedDependencies hash] -> ShowS
showList :: [NeedDependencies hash] -> ShowS
Show, NeedDependencies hash -> NeedDependencies hash -> Bool
(NeedDependencies hash -> NeedDependencies hash -> Bool)
-> (NeedDependencies hash -> NeedDependencies hash -> Bool)
-> Eq (NeedDependencies hash)
forall hash.
Eq hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall hash.
Eq hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
== :: NeedDependencies hash -> NeedDependencies hash -> Bool
$c/= :: forall hash.
Eq hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
/= :: NeedDependencies hash -> NeedDependencies hash -> Bool
Eq, Eq (NeedDependencies hash)
Eq (NeedDependencies hash) =>
(NeedDependencies hash -> NeedDependencies hash -> Ordering)
-> (NeedDependencies hash -> NeedDependencies hash -> Bool)
-> (NeedDependencies hash -> NeedDependencies hash -> Bool)
-> (NeedDependencies hash -> NeedDependencies hash -> Bool)
-> (NeedDependencies hash -> NeedDependencies hash -> Bool)
-> (NeedDependencies hash
    -> NeedDependencies hash -> NeedDependencies hash)
-> (NeedDependencies hash
    -> NeedDependencies hash -> NeedDependencies hash)
-> Ord (NeedDependencies hash)
NeedDependencies hash -> NeedDependencies hash -> Bool
NeedDependencies hash -> NeedDependencies hash -> Ordering
NeedDependencies hash
-> NeedDependencies hash -> NeedDependencies hash
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall hash. Ord hash => Eq (NeedDependencies hash)
forall hash.
Ord hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
forall hash.
Ord hash =>
NeedDependencies hash -> NeedDependencies hash -> Ordering
forall hash.
Ord hash =>
NeedDependencies hash
-> NeedDependencies hash -> NeedDependencies hash
$ccompare :: forall hash.
Ord hash =>
NeedDependencies hash -> NeedDependencies hash -> Ordering
compare :: NeedDependencies hash -> NeedDependencies hash -> Ordering
$c< :: forall hash.
Ord hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
< :: NeedDependencies hash -> NeedDependencies hash -> Bool
$c<= :: forall hash.
Ord hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
<= :: NeedDependencies hash -> NeedDependencies hash -> Bool
$c> :: forall hash.
Ord hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
> :: NeedDependencies hash -> NeedDependencies hash -> Bool
$c>= :: forall hash.
Ord hash =>
NeedDependencies hash -> NeedDependencies hash -> Bool
>= :: NeedDependencies hash -> NeedDependencies hash -> Bool
$cmax :: forall hash.
Ord hash =>
NeedDependencies hash
-> NeedDependencies hash -> NeedDependencies hash
max :: NeedDependencies hash
-> NeedDependencies hash -> NeedDependencies hash
$cmin :: forall hash.
Ord hash =>
NeedDependencies hash
-> NeedDependencies hash -> NeedDependencies hash
min :: NeedDependencies hash
-> NeedDependencies hash -> NeedDependencies hash
Ord)

instance (ToJSON hash) => ToJSON (NeedDependencies hash) where
  toJSON :: NeedDependencies hash -> Value
toJSON (NeedDependencies NESet hash
missingDependencies) =
    [Pair] -> Value
object [Key
"missing_dependencies" Key -> NESet hash -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= NESet hash
missingDependencies]

instance (FromJSON hash, Ord hash) => FromJSON (NeedDependencies hash) where
  parseJSON :: Value -> Parser (NeedDependencies hash)
parseJSON = String
-> (Object -> Parser (NeedDependencies hash))
-> Value
-> Parser (NeedDependencies hash)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"NeedDependencies" \Object
obj -> do
    NESet hash
missingDependencies <- Object
obj Object -> Key -> Parser (NESet hash)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"missing_dependencies"
    pure NeedDependencies {NESet hash
$sel:missingDependencies:NeedDependencies :: NESet hash
missingDependencies :: NESet hash
..}

------------------------------------------------------------------------------------------------------------------------
-- Misc. helpers

failText :: (MonadFail m) => Text -> m a
failText :: forall (m :: * -> *) a. MonadFail m => Text -> m a
failText = String -> m a
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m a) -> (Text -> String) -> Text -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
Text.unpack

jsonUnion :: (ToJSON a) => Text -> a -> Value
jsonUnion :: forall a. ToJSON a => Text -> a -> Value
jsonUnion Text
typeName a
val =
  [Pair] -> Value
Aeson.object
    [ Key
"type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= Text -> Value
String Text
typeName,
      Key
"payload" Key -> a -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
.= a
val
    ]