module Ecluse.Core.Snapshot (
Snapshot (..),
ContentDigest,
digestBytes,
digestFromContext,
) where
import Crypto.Hash (Context, SHA256, hashFinalize)
import Data.ByteArray qualified as BA
data Snapshot a = Snapshot
{ forall a. Snapshot a -> ContentDigest
snapshotDigest :: ContentDigest
, forall a. Snapshot a -> a
snapshotValue :: a
}
deriving stock (Snapshot a -> Snapshot a -> Bool
(Snapshot a -> Snapshot a -> Bool)
-> (Snapshot a -> Snapshot a -> Bool) -> Eq (Snapshot a)
forall a. Eq a => Snapshot a -> Snapshot a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Snapshot a -> Snapshot a -> Bool
== :: Snapshot a -> Snapshot a -> Bool
$c/= :: forall a. Eq a => Snapshot a -> Snapshot a -> Bool
/= :: Snapshot a -> Snapshot a -> Bool
Eq, Int -> Snapshot a -> ShowS
[Snapshot a] -> ShowS
Snapshot a -> String
(Int -> Snapshot a -> ShowS)
-> (Snapshot a -> String)
-> ([Snapshot a] -> ShowS)
-> Show (Snapshot a)
forall a. Show a => Int -> Snapshot a -> ShowS
forall a. Show a => [Snapshot a] -> ShowS
forall a. Show a => Snapshot a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Snapshot a -> ShowS
showsPrec :: Int -> Snapshot a -> ShowS
$cshow :: forall a. Show a => Snapshot a -> String
show :: Snapshot a -> String
$cshowList :: forall a. Show a => [Snapshot a] -> ShowS
showList :: [Snapshot a] -> ShowS
Show, (forall a b. (a -> b) -> Snapshot a -> Snapshot b)
-> (forall a b. a -> Snapshot b -> Snapshot a) -> Functor Snapshot
forall a b. a -> Snapshot b -> Snapshot a
forall a b. (a -> b) -> Snapshot a -> Snapshot b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Snapshot a -> Snapshot b
fmap :: forall a b. (a -> b) -> Snapshot a -> Snapshot b
$c<$ :: forall a b. a -> Snapshot b -> Snapshot a
<$ :: forall a b. a -> Snapshot b -> Snapshot a
Functor, (forall m. Monoid m => Snapshot m -> m)
-> (forall m a. Monoid m => (a -> m) -> Snapshot a -> m)
-> (forall m a. Monoid m => (a -> m) -> Snapshot a -> m)
-> (forall a b. (a -> b -> b) -> b -> Snapshot a -> b)
-> (forall a b. (a -> b -> b) -> b -> Snapshot a -> b)
-> (forall b a. (b -> a -> b) -> b -> Snapshot a -> b)
-> (forall b a. (b -> a -> b) -> b -> Snapshot a -> b)
-> (forall a. (a -> a -> a) -> Snapshot a -> a)
-> (forall a. (a -> a -> a) -> Snapshot a -> a)
-> (forall a. Snapshot a -> [a])
-> (forall a. Snapshot a -> Bool)
-> (forall a. Snapshot a -> Int)
-> (forall a. Eq a => a -> Snapshot a -> Bool)
-> (forall a. Ord a => Snapshot a -> a)
-> (forall a. Ord a => Snapshot a -> a)
-> (forall a. Num a => Snapshot a -> a)
-> (forall a. Num a => Snapshot a -> a)
-> Foldable Snapshot
forall a. Eq a => a -> Snapshot a -> Bool
forall a. Num a => Snapshot a -> a
forall a. Ord a => Snapshot a -> a
forall m. Monoid m => Snapshot m -> m
forall a. Snapshot a -> Bool
forall a. Snapshot a -> Int
forall a. Snapshot a -> [a]
forall a. (a -> a -> a) -> Snapshot a -> a
forall m a. Monoid m => (a -> m) -> Snapshot a -> m
forall b a. (b -> a -> b) -> b -> Snapshot a -> b
forall a b. (a -> b -> b) -> b -> Snapshot a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Snapshot m -> m
fold :: forall m. Monoid m => Snapshot m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Snapshot a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Snapshot a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Snapshot a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Snapshot a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Snapshot a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Snapshot a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Snapshot a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Snapshot a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Snapshot a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Snapshot a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Snapshot a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Snapshot a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Snapshot a -> a
foldr1 :: forall a. (a -> a -> a) -> Snapshot a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Snapshot a -> a
foldl1 :: forall a. (a -> a -> a) -> Snapshot a -> a
$ctoList :: forall a. Snapshot a -> [a]
toList :: forall a. Snapshot a -> [a]
$cnull :: forall a. Snapshot a -> Bool
null :: forall a. Snapshot a -> Bool
$clength :: forall a. Snapshot a -> Int
length :: forall a. Snapshot a -> Int
$celem :: forall a. Eq a => a -> Snapshot a -> Bool
elem :: forall a. Eq a => a -> Snapshot a -> Bool
$cmaximum :: forall a. Ord a => Snapshot a -> a
maximum :: forall a. Ord a => Snapshot a -> a
$cminimum :: forall a. Ord a => Snapshot a -> a
minimum :: forall a. Ord a => Snapshot a -> a
$csum :: forall a. Num a => Snapshot a -> a
sum :: forall a. Num a => Snapshot a -> a
$cproduct :: forall a. Num a => Snapshot a -> a
product :: forall a. Num a => Snapshot a -> a
Foldable, Functor Snapshot
Foldable Snapshot
(Functor Snapshot, Foldable Snapshot) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Snapshot a -> f (Snapshot b))
-> (forall (f :: * -> *) a.
Applicative f =>
Snapshot (f a) -> f (Snapshot a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Snapshot a -> m (Snapshot b))
-> (forall (m :: * -> *) a.
Monad m =>
Snapshot (m a) -> m (Snapshot a))
-> Traversable Snapshot
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Snapshot (m a) -> m (Snapshot a)
forall (f :: * -> *) a.
Applicative f =>
Snapshot (f a) -> f (Snapshot a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Snapshot a -> m (Snapshot b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Snapshot a -> f (Snapshot b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Snapshot a -> f (Snapshot b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Snapshot a -> f (Snapshot b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Snapshot (f a) -> f (Snapshot a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Snapshot (f a) -> f (Snapshot a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Snapshot a -> m (Snapshot b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Snapshot a -> m (Snapshot b)
$csequence :: forall (m :: * -> *) a. Monad m => Snapshot (m a) -> m (Snapshot a)
sequence :: forall (m :: * -> *) a. Monad m => Snapshot (m a) -> m (Snapshot a)
Traversable)
newtype ContentDigest = ContentDigest ByteString
deriving stock (ContentDigest -> ContentDigest -> Bool
(ContentDigest -> ContentDigest -> Bool)
-> (ContentDigest -> ContentDigest -> Bool) -> Eq ContentDigest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ContentDigest -> ContentDigest -> Bool
== :: ContentDigest -> ContentDigest -> Bool
$c/= :: ContentDigest -> ContentDigest -> Bool
/= :: ContentDigest -> ContentDigest -> Bool
Eq, Eq ContentDigest
Eq ContentDigest =>
(ContentDigest -> ContentDigest -> Ordering)
-> (ContentDigest -> ContentDigest -> Bool)
-> (ContentDigest -> ContentDigest -> Bool)
-> (ContentDigest -> ContentDigest -> Bool)
-> (ContentDigest -> ContentDigest -> Bool)
-> (ContentDigest -> ContentDigest -> ContentDigest)
-> (ContentDigest -> ContentDigest -> ContentDigest)
-> Ord ContentDigest
ContentDigest -> ContentDigest -> Bool
ContentDigest -> ContentDigest -> Ordering
ContentDigest -> ContentDigest -> ContentDigest
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 :: ContentDigest -> ContentDigest -> Ordering
compare :: ContentDigest -> ContentDigest -> Ordering
$c< :: ContentDigest -> ContentDigest -> Bool
< :: ContentDigest -> ContentDigest -> Bool
$c<= :: ContentDigest -> ContentDigest -> Bool
<= :: ContentDigest -> ContentDigest -> Bool
$c> :: ContentDigest -> ContentDigest -> Bool
> :: ContentDigest -> ContentDigest -> Bool
$c>= :: ContentDigest -> ContentDigest -> Bool
>= :: ContentDigest -> ContentDigest -> Bool
$cmax :: ContentDigest -> ContentDigest -> ContentDigest
max :: ContentDigest -> ContentDigest -> ContentDigest
$cmin :: ContentDigest -> ContentDigest -> ContentDigest
min :: ContentDigest -> ContentDigest -> ContentDigest
Ord, Int -> ContentDigest -> ShowS
[ContentDigest] -> ShowS
ContentDigest -> String
(Int -> ContentDigest -> ShowS)
-> (ContentDigest -> String)
-> ([ContentDigest] -> ShowS)
-> Show ContentDigest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ContentDigest -> ShowS
showsPrec :: Int -> ContentDigest -> ShowS
$cshow :: ContentDigest -> String
show :: ContentDigest -> String
$cshowList :: [ContentDigest] -> ShowS
showList :: [ContentDigest] -> ShowS
Show)
digestBytes :: ContentDigest -> ByteString
digestBytes :: ContentDigest -> ByteString
digestBytes (ContentDigest ByteString
bytes) = ByteString
bytes
digestFromContext :: Context SHA256 -> ContentDigest
digestFromContext :: Context SHA256 -> ContentDigest
digestFromContext = ByteString -> ContentDigest
ContentDigest (ByteString -> ContentDigest)
-> (Context SHA256 -> ByteString)
-> Context SHA256
-> ContentDigest
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Digest SHA256 -> ByteString
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
BA.convert (Digest SHA256 -> ByteString)
-> (Context SHA256 -> Digest SHA256)
-> Context SHA256
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context SHA256 -> Digest SHA256
forall a. HashAlgorithm a => Context a -> Digest a
hashFinalize