{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      : Data.KindID.Internal
-- License     : MIT
-- Maintainer  : mmzk1526@outlook.com
-- Portability : GHC
--
module Data.KindID.Internal where

import           Control.Monad
import           Control.Monad.IO.Class
import           Data.Aeson.Types hiding (String)
import           Data.Binary
import           Data.ByteString.Lazy (ByteString)
import           Data.Data (Data)
import           Data.Hashable
import           Data.Proxy
import           Data.KindID.Class
import           Data.Text (Text)
import qualified Data.Text as T
import           Data.Typeable (Typeable)
import           Data.TypeID.Class
import           Data.TypeID.Error
import           Data.TypeID.Internal (TypeID'(..))
import qualified Data.TypeID.Internal as TID
import           Data.UUID.Types.Internal (UUID(..))
import qualified Data.TypeID.V1.Unsafe as V1
import qualified Data.TypeID.V4.Unsafe as V4
import qualified Data.TypeID.V5.Unsafe as V5
import qualified Data.TypeID.V7.Unsafe as V7
import qualified Data.UUID.V7 as V7
import           Data.UUID.Versions
import           Foreign
import           GHC.TypeLits (symbolVal)

-- | A TypeID with the prefix encoded at type level.
--
-- It is dubbed 'Data.KindID.V7.KindID' because the prefix here is a data kind
-- rather than a type.
newtype KindID' (version :: UUIDVersion) prefix = KindID' UUID
  deriving (KindID' version prefix -> KindID' version prefix -> Bool
(KindID' version prefix -> KindID' version prefix -> Bool)
-> (KindID' version prefix -> KindID' version prefix -> Bool)
-> Eq (KindID' version prefix)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
$c== :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
== :: KindID' version prefix -> KindID' version prefix -> Bool
$c/= :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
/= :: KindID' version prefix -> KindID' version prefix -> Bool
Eq, Eq (KindID' version prefix)
Eq (KindID' version prefix)
-> (KindID' version prefix -> KindID' version prefix -> Ordering)
-> (KindID' version prefix -> KindID' version prefix -> Bool)
-> (KindID' version prefix -> KindID' version prefix -> Bool)
-> (KindID' version prefix -> KindID' version prefix -> Bool)
-> (KindID' version prefix -> KindID' version prefix -> Bool)
-> (KindID' version prefix
    -> KindID' version prefix -> KindID' version prefix)
-> (KindID' version prefix
    -> KindID' version prefix -> KindID' version prefix)
-> Ord (KindID' version prefix)
KindID' version prefix -> KindID' version prefix -> Bool
KindID' version prefix -> KindID' version prefix -> Ordering
KindID' version prefix
-> KindID' version prefix -> KindID' version prefix
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 (version :: UUIDVersion) k (prefix :: k).
Eq (KindID' version prefix)
forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Ordering
forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix
-> KindID' version prefix -> KindID' version prefix
$ccompare :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Ordering
compare :: KindID' version prefix -> KindID' version prefix -> Ordering
$c< :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
< :: KindID' version prefix -> KindID' version prefix -> Bool
$c<= :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
<= :: KindID' version prefix -> KindID' version prefix -> Bool
$c> :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
> :: KindID' version prefix -> KindID' version prefix -> Bool
$c>= :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix -> KindID' version prefix -> Bool
>= :: KindID' version prefix -> KindID' version prefix -> Bool
$cmax :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix
-> KindID' version prefix -> KindID' version prefix
max :: KindID' version prefix
-> KindID' version prefix -> KindID' version prefix
$cmin :: forall (version :: UUIDVersion) k (prefix :: k).
KindID' version prefix
-> KindID' version prefix -> KindID' version prefix
min :: KindID' version prefix
-> KindID' version prefix -> KindID' version prefix
Ord, Typeable (KindID' version prefix)
Typeable (KindID' version prefix)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> KindID' version prefix
    -> c (KindID' version prefix))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (KindID' version prefix))
-> (KindID' version prefix -> Constr)
-> (KindID' version prefix -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d))
    -> Maybe (c (KindID' version prefix)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (KindID' version prefix)))
-> ((forall b. Data b => b -> b)
    -> KindID' version prefix -> KindID' version prefix)
-> (forall r r'.
    (r -> r' -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> KindID' version prefix
    -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> KindID' version prefix
    -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> KindID' version prefix -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> KindID' version prefix -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> KindID' version prefix -> m (KindID' version prefix))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> KindID' version prefix -> m (KindID' version prefix))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> KindID' version prefix -> m (KindID' version prefix))
-> Data (KindID' version prefix)
KindID' version prefix -> Constr
KindID' version prefix -> DataType
(forall b. Data b => b -> b)
-> KindID' version prefix -> KindID' version prefix
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> KindID' version prefix -> u
forall u.
(forall d. Data d => d -> u) -> KindID' version prefix -> [u]
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
forall {version :: UUIDVersion} {k} {prefix :: k}.
(Typeable prefix, Typeable k, Typeable version) =>
Typeable (KindID' version prefix)
forall (version :: UUIDVersion) k (prefix :: k).
(Typeable prefix, Typeable k, Typeable version) =>
KindID' version prefix -> Constr
forall (version :: UUIDVersion) k (prefix :: k).
(Typeable prefix, Typeable k, Typeable version) =>
KindID' version prefix -> DataType
forall (version :: UUIDVersion) k (prefix :: k).
(Typeable prefix, Typeable k, Typeable version) =>
(forall b. Data b => b -> b)
-> KindID' version prefix -> KindID' version prefix
forall (version :: UUIDVersion) k (prefix :: k) u.
(Typeable prefix, Typeable k, Typeable version) =>
Int -> (forall d. Data d => d -> u) -> KindID' version prefix -> u
forall (version :: UUIDVersion) k (prefix :: k) u.
(Typeable prefix, Typeable k, Typeable version) =>
(forall d. Data d => d -> u) -> KindID' version prefix -> [u]
forall (version :: UUIDVersion) k (prefix :: k) r r'.
(Typeable prefix, Typeable k, Typeable version) =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
forall (version :: UUIDVersion) k (prefix :: k) r r'.
(Typeable prefix, Typeable k, Typeable version) =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
forall (version :: UUIDVersion) k (prefix :: k) (m :: * -> *).
(Typeable prefix, Typeable k, Typeable version, Monad m) =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
forall (version :: UUIDVersion) k (prefix :: k) (m :: * -> *).
(Typeable prefix, Typeable k, Typeable version, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
forall (version :: UUIDVersion) k (prefix :: k) (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (KindID' version prefix)
forall (version :: UUIDVersion) k (prefix :: k) (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> KindID' version prefix
-> c (KindID' version prefix)
forall (version :: UUIDVersion) k (prefix :: k) (t :: * -> *)
       (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (KindID' version prefix))
forall (version :: UUIDVersion) k (prefix :: k) (t :: * -> * -> *)
       (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (KindID' version prefix))
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (KindID' version prefix)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> KindID' version prefix
-> c (KindID' version prefix)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (KindID' version prefix))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (KindID' version prefix))
$cgfoldl :: forall (version :: UUIDVersion) k (prefix :: k) (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> KindID' version prefix
-> c (KindID' version prefix)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> KindID' version prefix
-> c (KindID' version prefix)
$cgunfold :: forall (version :: UUIDVersion) k (prefix :: k) (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (KindID' version prefix)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (KindID' version prefix)
$ctoConstr :: forall (version :: UUIDVersion) k (prefix :: k).
(Typeable prefix, Typeable k, Typeable version) =>
KindID' version prefix -> Constr
toConstr :: KindID' version prefix -> Constr
$cdataTypeOf :: forall (version :: UUIDVersion) k (prefix :: k).
(Typeable prefix, Typeable k, Typeable version) =>
KindID' version prefix -> DataType
dataTypeOf :: KindID' version prefix -> DataType
$cdataCast1 :: forall (version :: UUIDVersion) k (prefix :: k) (t :: * -> *)
       (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (KindID' version prefix))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (KindID' version prefix))
$cdataCast2 :: forall (version :: UUIDVersion) k (prefix :: k) (t :: * -> * -> *)
       (c :: * -> *).
(Typeable prefix, Typeable k, Typeable version, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (KindID' version prefix))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (KindID' version prefix))
$cgmapT :: forall (version :: UUIDVersion) k (prefix :: k).
(Typeable prefix, Typeable k, Typeable version) =>
(forall b. Data b => b -> b)
-> KindID' version prefix -> KindID' version prefix
gmapT :: (forall b. Data b => b -> b)
-> KindID' version prefix -> KindID' version prefix
$cgmapQl :: forall (version :: UUIDVersion) k (prefix :: k) r r'.
(Typeable prefix, Typeable k, Typeable version) =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
$cgmapQr :: forall (version :: UUIDVersion) k (prefix :: k) r r'.
(Typeable prefix, Typeable k, Typeable version) =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> KindID' version prefix
-> r
$cgmapQ :: forall (version :: UUIDVersion) k (prefix :: k) u.
(Typeable prefix, Typeable k, Typeable version) =>
(forall d. Data d => d -> u) -> KindID' version prefix -> [u]
gmapQ :: forall u.
(forall d. Data d => d -> u) -> KindID' version prefix -> [u]
$cgmapQi :: forall (version :: UUIDVersion) k (prefix :: k) u.
(Typeable prefix, Typeable k, Typeable version) =>
Int -> (forall d. Data d => d -> u) -> KindID' version prefix -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> KindID' version prefix -> u
$cgmapM :: forall (version :: UUIDVersion) k (prefix :: k) (m :: * -> *).
(Typeable prefix, Typeable k, Typeable version, Monad m) =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
$cgmapMp :: forall (version :: UUIDVersion) k (prefix :: k) (m :: * -> *).
(Typeable prefix, Typeable k, Typeable version, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
$cgmapMo :: forall (version :: UUIDVersion) k (prefix :: k) (m :: * -> *).
(Typeable prefix, Typeable k, Typeable version, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> KindID' version prefix -> m (KindID' version prefix)
Data, Typeable)

instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => Show (KindID' version prefix) where
    show :: KindID' version prefix -> String
    show :: KindID' version prefix -> String
show = KindID' version prefix -> String
forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> String
toString
    {-# INLINE show #-}

instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => Read (KindID' version prefix) where
    readsPrec :: Int -> String -> [(KindID' version prefix, String)]
    readsPrec :: Int -> ReadS (KindID' version prefix)
readsPrec Int
_ String
str = case String -> Either TypeIDError (TypeID' version, String)
forall (version :: UUIDVersion).
String -> Either TypeIDError (TypeID' version, String)
TID.parseStringS String
str of
      Left TypeIDError
_           -> []
      Right (TypeID' version
tid, String
nks) -> case TypeID' version -> Maybe (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> Maybe (KindID' version prefix)
fromTypeID TypeID' version
tid of
        Maybe (KindID' version prefix)
Nothing  -> []
        Just KindID' version prefix
kid -> [(KindID' version prefix
kid, String
nks)]
    {-# INLINE readsPrec #-}

instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => ToJSON (KindID' version prefix) where
    toJSON :: KindID' version prefix -> Value
    toJSON :: KindID' version prefix -> Value
toJSON = Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value)
-> (KindID' version prefix -> Text)
-> KindID' version prefix
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> Text
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> Text
toText
    {-# INLINE toJSON #-}

instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => FromJSON (KindID' version prefix) where
    parseJSON :: Value -> Parser (KindID' version prefix)
    parseJSON :: Value -> Parser (KindID' version prefix)
parseJSON Value
str = do
      Text
s <- Value -> Parser Text
forall a. FromJSON a => Value -> Parser a
parseJSON Value
str
      case Text -> Either TypeIDError (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> Either TypeIDError (KindID' version prefix)
parseText Text
s of
        Left TypeIDError
err  -> String -> Parser (KindID' version prefix)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser (KindID' version prefix))
-> String -> Parser (KindID' version prefix)
forall a b. (a -> b) -> a -> b
$ TypeIDError -> String
forall a. Show a => a -> String
show TypeIDError
err
        Right KindID' version prefix
kid -> KindID' version prefix -> Parser (KindID' version prefix)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KindID' version prefix
kid
    {-# INLINE parseJSON #-}

instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => ToJSONKey (KindID' version prefix) where
    toJSONKey :: ToJSONKeyFunction (KindID' version prefix)
    toJSONKey :: ToJSONKeyFunction (KindID' version prefix)
toJSONKey = (KindID' version prefix -> Text)
-> ToJSONKeyFunction (KindID' version prefix)
forall a. (a -> Text) -> ToJSONKeyFunction a
toJSONKeyText KindID' version prefix -> Text
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> Text
toText
    {-# INLINE toJSONKey #-}

instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => FromJSONKey (KindID' version prefix) where
    fromJSONKey :: FromJSONKeyFunction (KindID' version prefix)
    fromJSONKey :: FromJSONKeyFunction (KindID' version prefix)
fromJSONKey = (Text -> Parser (KindID' version prefix))
-> FromJSONKeyFunction (KindID' version prefix)
forall a. (Text -> Parser a) -> FromJSONKeyFunction a
FromJSONKeyTextParser \Text
t -> case Text -> Either TypeIDError (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> Either TypeIDError (KindID' version prefix)
parseText Text
t of
      Left TypeIDError
err  -> String -> Parser (KindID' version prefix)
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser (KindID' version prefix))
-> String -> Parser (KindID' version prefix)
forall a b. (a -> b) -> a -> b
$ TypeIDError -> String
forall a. Show a => a -> String
show TypeIDError
err
      Right KindID' version prefix
kid -> KindID' version prefix -> Parser (KindID' version prefix)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KindID' version prefix
kid
    {-# INLINE fromJSONKey #-}

-- | See The 'Binary' instance of 'TypeID''.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => Binary (KindID' version prefix) where
    put :: KindID' version prefix -> Put
    put :: KindID' version prefix -> Put
put = TypeID' version -> Put
forall t. Binary t => t -> Put
put (TypeID' version -> Put)
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
    {-# INLINE put #-}

    get :: Get (KindID' version prefix)
    get :: Get (KindID' version prefix)
get = do
      TypeID' version
tid <- Get (TypeID' version)
forall t. Binary t => Get t
get :: Get (TypeID' version)
      case TypeID' version -> Maybe (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> Maybe (KindID' version prefix)
fromTypeID TypeID' version
tid of
        Maybe (KindID' version prefix)
Nothing  -> String -> Get (KindID' version prefix)
forall a. String -> Get a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Binary: Prefix mismatch"
        Just KindID' version prefix
kid -> KindID' version prefix -> Get (KindID' version prefix)
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KindID' version prefix
kid
    {-# INLINE get #-}

-- | Similar to the 'Binary' instance, but the 'UUID' is stored in host endian.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => Storable (KindID' version prefix) where
    sizeOf :: KindID' version prefix -> Int
    sizeOf :: KindID' version prefix -> Int
sizeOf = TypeID' version -> Int
forall a. Storable a => a -> Int
sizeOf (TypeID' version -> Int)
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
    {-# INLINE sizeOf #-}

    alignment :: KindID' version prefix -> Int
    alignment :: KindID' version prefix -> Int
alignment = TypeID' version -> Int
forall a. Storable a => a -> Int
alignment (TypeID' version -> Int)
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
    {-# INLINE alignment #-}

    peek :: Ptr (KindID' version prefix) -> IO (KindID' version prefix)
    peek :: Ptr (KindID' version prefix) -> IO (KindID' version prefix)
peek Ptr (KindID' version prefix)
ptr = do
      TypeID' version
tid <- Ptr (TypeID' version) -> IO (TypeID' version)
forall a. Storable a => Ptr a -> IO a
peek (Ptr (TypeID' version) -> IO (TypeID' version))
-> Ptr (TypeID' version) -> IO (TypeID' version)
forall a b. (a -> b) -> a -> b
$ Ptr (KindID' version prefix) -> Ptr (TypeID' version)
forall a b. Ptr a -> Ptr b
castPtr Ptr (KindID' version prefix)
ptr :: IO (TypeID' version)
      case TypeID' version -> Maybe (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> Maybe (KindID' version prefix)
fromTypeID TypeID' version
tid of
        Maybe (KindID' version prefix)
Nothing  -> String -> IO (KindID' version prefix)
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Storable: Prefix mismatch"
        Just KindID' version prefix
kid -> KindID' version prefix -> IO (KindID' version prefix)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KindID' version prefix
kid
    {-# INLINE peek #-}

    poke :: Ptr (KindID' version prefix) -> KindID' version prefix -> IO ()
    poke :: Ptr (KindID' version prefix) -> KindID' version prefix -> IO ()
poke Ptr (KindID' version prefix)
ptr = Ptr (TypeID' version) -> TypeID' version -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr (KindID' version prefix) -> Ptr (TypeID' version)
forall a b. Ptr a -> Ptr b
castPtr Ptr (KindID' version prefix)
ptr) (TypeID' version -> IO ())
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
    {-# INLINE poke #-}

instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => Hashable (KindID' version prefix) where
    hashWithSalt :: Int -> KindID' version prefix -> Int
    hashWithSalt :: Int -> KindID' version prefix -> Int
hashWithSalt Int
salt = Int -> TypeID' version -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (TypeID' version -> Int)
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
    {-# INLINE hashWithSalt #-}

-- | Get the prefix, 'UUID', and timestamp of a 'KindID''.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => IDType (KindID' version prefix) where
    getPrefix :: KindID' version prefix -> Text
    getPrefix :: KindID' version prefix -> Text
getPrefix KindID' version prefix
_ = String -> Text
T.pack (Proxy (PrefixSymbol prefix) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(PrefixSymbol prefix)))
    {-# INLINE getPrefix #-}

    getUUID :: KindID' version prefix -> UUID
    getUUID :: KindID' version prefix -> UUID
getUUID (KindID' UUID
uuid) = UUID
uuid
    {-# INLINE getUUID #-}

    getTime :: KindID' version prefix -> Word64
    getTime :: KindID' version prefix -> Word64
getTime = UUID -> Word64
V7.getTime (UUID -> Word64)
-> (KindID' version prefix -> UUID)
-> KindID' version prefix
-> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> UUID
forall a. IDType a => a -> UUID
getUUID
    {-# INLINE getTime #-}

-- | Conversion between 'KindID'' and 'String'/'Text'/'ByteString'.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => IDConv (KindID' version prefix) where
    string2ID :: String -> Either TypeIDError (KindID' version prefix)
    string2ID :: String -> Either TypeIDError (KindID' version prefix)
string2ID = String -> Either TypeIDError (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
String -> Either TypeIDError (KindID' version prefix)
parseString
    {-# INLINE string2ID #-}

    text2ID :: Text -> Either TypeIDError (KindID' version prefix)
    text2ID :: Text -> Either TypeIDError (KindID' version prefix)
text2ID = Text -> Either TypeIDError (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> Either TypeIDError (KindID' version prefix)
parseText
    {-# INLINE text2ID #-}

    byteString2ID :: ByteString -> Either TypeIDError (KindID' version prefix)
    byteString2ID :: ByteString -> Either TypeIDError (KindID' version prefix)
byteString2ID = ByteString -> Either TypeIDError (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
ByteString -> Either TypeIDError (KindID' version prefix)
parseByteString
    {-# INLINE byteString2ID #-}

    id2String :: KindID' version prefix -> String
    id2String :: KindID' version prefix -> String
id2String = KindID' version prefix -> String
forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> String
toString
    {-# INLINE id2String #-}

    id2Text :: KindID' version prefix -> Text
    id2Text :: KindID' version prefix -> Text
id2Text = KindID' version prefix -> Text
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> Text
toText
    {-# INLINE id2Text #-}

    id2ByteString :: KindID' version prefix -> ByteString
    id2ByteString :: KindID' version prefix -> ByteString
id2ByteString = KindID' version prefix -> ByteString
forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> ByteString
toByteString
    {-# INLINE id2ByteString #-}

    unsafeString2ID :: String -> KindID' version prefix
    unsafeString2ID :: String -> KindID' version prefix
unsafeString2ID = String -> KindID' version prefix
forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
String -> KindID' version prefix
unsafeParseString
    {-# INLINE unsafeString2ID #-}

    unsafeText2ID :: Text -> KindID' version prefix
    unsafeText2ID :: Text -> KindID' version prefix
unsafeText2ID = Text -> KindID' version prefix
forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> KindID' version prefix
unsafeParseText
    {-# INLINE unsafeText2ID #-}

    unsafeByteString2ID :: ByteString -> KindID' version prefix
    unsafeByteString2ID :: ByteString -> KindID' version prefix
unsafeByteString2ID = ByteString -> KindID' version prefix
forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
ByteString -> KindID' version prefix
unsafeParseByteString
    {-# INLINE unsafeByteString2ID #-}

-- | Generate 'Data.KindID.V7.KindID's.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => IDGen (KindID' 'V7 prefix) where
    type IDGenPrefix (KindID' 'V7 prefix) = 'Nothing

    type IDGenReq (KindID' 'V7 prefix) r = r

    genID_ :: MonadIO m => Proxy (KindID' 'V7 prefix) -> m (KindID' 'V7 prefix)
    genID_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V7 prefix) -> m (KindID' 'V7 prefix)
genID_ Proxy (KindID' 'V7 prefix)
_ = m (KindID' 'V7 prefix)
forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V7 prefix)
genKindID
    {-# INLINE genID_ #-}

    genID'_ :: MonadIO m => Proxy (KindID' 'V7 prefix) -> m (KindID' 'V7 prefix)
    genID'_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V7 prefix) -> m (KindID' 'V7 prefix)
genID'_ Proxy (KindID' 'V7 prefix)
_ = m (KindID' 'V7 prefix)
forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V7 prefix)
genKindID'
    {-# INLINE genID'_ #-}

    genIDs_ :: MonadIO m
            => Proxy (KindID' 'V7 prefix) -> Word16 -> m [KindID' 'V7 prefix]
    genIDs_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V7 prefix) -> Word16 -> m [KindID' 'V7 prefix]
genIDs_ Proxy (KindID' 'V7 prefix)
_ = Word16 -> m [KindID' 'V7 prefix]
forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
Word16 -> m [KindID' 'V7 prefix]
genKindIDs
    {-# INLINE genIDs_ #-}

    decorate_ :: Proxy (KindID' 'V7 prefix) -> UUID -> KindID' 'V7 prefix
    decorate_ :: Proxy (KindID' 'V7 prefix) -> UUID -> KindID' 'V7 prefix
decorate_ Proxy (KindID' 'V7 prefix)
_ = UUID -> KindID' 'V7 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
UUID -> KindID' version prefix
decorateKindID
    {-# INLINE decorate_ #-}

    checkID_ :: Proxy (KindID' 'V7 prefix)
             -> KindID' 'V7 prefix
             -> Maybe TypeIDError
    checkID_ :: Proxy (KindID' 'V7 prefix)
-> KindID' 'V7 prefix -> Maybe TypeIDError
checkID_ Proxy (KindID' 'V7 prefix)
_ = KindID' 'V7 prefix -> Maybe TypeIDError
forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V7 prefix -> Maybe TypeIDError
checkKindID
    {-# INLINE checkID_ #-}

    checkIDWithEnv_ :: MonadIO m
                    => Proxy (KindID' 'V7 prefix)
                    -> KindID' 'V7 prefix
                    -> m (Maybe TypeIDError)
    checkIDWithEnv_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V7 prefix)
-> KindID' 'V7 prefix -> m (Maybe TypeIDError)
checkIDWithEnv_ Proxy (KindID' 'V7 prefix)
_ = KindID' 'V7 prefix -> m (Maybe TypeIDError)
forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
KindID' 'V7 prefix -> m (Maybe TypeIDError)
checkKindIDWithEnv
    {-# INLINE checkIDWithEnv_ #-}

-- | Generate 'KindID'' ''V1's.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => IDGen (KindID' 'V1 prefix) where
    type IDGenPrefix (KindID' 'V1 prefix) = 'Nothing

    type IDGenReq (KindID' 'V1 prefix) r = r

    genID_ :: MonadIO m => Proxy (KindID' 'V1 prefix) -> m (KindID' 'V1 prefix)
    genID_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V1 prefix) -> m (KindID' 'V1 prefix)
genID_ Proxy (KindID' 'V1 prefix)
_ = m (KindID' 'V1 prefix)
forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V1 prefix)
genKindIDV1
    {-# INLINE genID_ #-}

    genIDs_ :: MonadIO m
            => Proxy (KindID' 'V1 prefix) -> Word16 -> m [KindID' 'V1 prefix]
    genIDs_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V1 prefix) -> Word16 -> m [KindID' 'V1 prefix]
genIDs_ Proxy (KindID' 'V1 prefix)
_ Word16
n
      = (UUID -> KindID' 'V1 prefix) -> [UUID] -> [KindID' 'V1 prefix]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap UUID -> KindID' 'V1 prefix
forall {k} (version :: UUIDVersion) (prefix :: k).
UUID -> KindID' version prefix
KindID' ([UUID] -> [KindID' 'V1 prefix])
-> m [UUID] -> m [KindID' 'V1 prefix]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> m UUID -> m [UUID]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
n) (IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
TID.nextUUID)
    {-# INLINE genIDs_ #-}

    decorate_ :: Proxy (KindID' 'V1 prefix) -> UUID -> KindID' 'V1 prefix
    decorate_ :: Proxy (KindID' 'V1 prefix) -> UUID -> KindID' 'V1 prefix
decorate_ Proxy (KindID' 'V1 prefix)
_ = UUID -> KindID' 'V1 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
UUID -> KindID' version prefix
decorateKindID
    {-# INLINE decorate_ #-}

    checkID_ :: Proxy (KindID' 'V1 prefix)
             -> KindID' 'V1 prefix
             -> Maybe TypeIDError
    checkID_ :: Proxy (KindID' 'V1 prefix)
-> KindID' 'V1 prefix -> Maybe TypeIDError
checkID_ Proxy (KindID' 'V1 prefix)
_ = KindID' 'V1 prefix -> Maybe TypeIDError
forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V1 prefix -> Maybe TypeIDError
checkKindIDV1
    {-# INLINE checkID_ #-}

-- | Generate 'KindID'' ''V4's.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => IDGen (KindID' 'V4 prefix) where
    type IDGenPrefix (KindID' 'V4 prefix) = 'Nothing

    type IDGenReq (KindID' 'V4 prefix) r = r

    genID_ :: MonadIO m => Proxy (KindID' 'V4 prefix) -> m (KindID' 'V4 prefix)
    genID_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V4 prefix) -> m (KindID' 'V4 prefix)
genID_ Proxy (KindID' 'V4 prefix)
_ = m (KindID' 'V4 prefix)
forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V4 prefix)
genKindIDV4
    {-# INLINE genID_ #-}

    genID'_ :: MonadIO m => Proxy (KindID' 'V4 prefix) -> m (KindID' 'V4 prefix)
    genID'_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V4 prefix) -> m (KindID' 'V4 prefix)
genID'_ Proxy (KindID' 'V4 prefix)
_ = m (KindID' 'V4 prefix)
forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V4 prefix)
genKindIDV4'
    {-# INLINE genID'_ #-}

    genIDs_ :: MonadIO m
            => Proxy (KindID' 'V4 prefix) -> Word16 -> m [KindID' 'V4 prefix]
    genIDs_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V4 prefix) -> Word16 -> m [KindID' 'V4 prefix]
genIDs_ Proxy (KindID' 'V4 prefix)
p Word16
n = Int -> m (KindID' 'V4 prefix) -> m [KindID' 'V4 prefix]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
n) (Proxy (KindID' 'V4 prefix)
-> GenFunc
     (IDGenPrefix (KindID' 'V4 prefix))
     (IDGenReq (KindID' 'V4 prefix) (m (KindID' 'V4 prefix)))
forall a (m :: * -> *).
(IDGen a, MonadIO m) =>
Proxy a -> GenFunc (IDGenPrefix a) (IDGenReq a (m a))
forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V4 prefix)
-> GenFunc
     (IDGenPrefix (KindID' 'V4 prefix))
     (IDGenReq (KindID' 'V4 prefix) (m (KindID' 'V4 prefix)))
genID_ Proxy (KindID' 'V4 prefix)
p)
    {-# INLINE genIDs_ #-}

    decorate_ :: Proxy (KindID' 'V4 prefix) -> UUID -> KindID' 'V4 prefix
    decorate_ :: Proxy (KindID' 'V4 prefix) -> UUID -> KindID' 'V4 prefix
decorate_ Proxy (KindID' 'V4 prefix)
_ = UUID -> KindID' 'V4 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
UUID -> KindID' version prefix
decorateKindID
    {-# INLINE decorate_ #-}

    checkID_ :: Proxy (KindID' 'V4 prefix)
             -> KindID' 'V4 prefix
             -> Maybe TypeIDError
    checkID_ :: Proxy (KindID' 'V4 prefix)
-> KindID' 'V4 prefix -> Maybe TypeIDError
checkID_ Proxy (KindID' 'V4 prefix)
_ = KindID' 'V4 prefix -> Maybe TypeIDError
forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V4 prefix -> Maybe TypeIDError
checkKindIDV4
    {-# INLINE checkID_ #-}

-- | Generate 'KindID'' ''V5's.
instance (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
  => IDGen (KindID' 'V5 prefix) where
    type IDGenPrefix (KindID' 'V5 prefix) = 'Nothing

    type IDGenReq (KindID' 'V5 prefix) r = UUID -> [Word8] -> r

    genID_ :: MonadIO m
           => Proxy (KindID' 'V5 prefix)
           -> UUID
           -> [Word8]
           -> m (KindID' 'V5 prefix)
    genID_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V5 prefix)
-> UUID -> [Word8] -> m (KindID' 'V5 prefix)
genID_ Proxy (KindID' 'V5 prefix)
_ = (KindID' 'V5 prefix -> m (KindID' 'V5 prefix)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (KindID' 'V5 prefix -> m (KindID' 'V5 prefix))
-> ([Word8] -> KindID' 'V5 prefix)
-> [Word8]
-> m (KindID' 'V5 prefix)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) (([Word8] -> KindID' 'V5 prefix)
 -> [Word8] -> m (KindID' 'V5 prefix))
-> (UUID -> [Word8] -> KindID' 'V5 prefix)
-> UUID
-> [Word8]
-> m (KindID' 'V5 prefix)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> [Word8] -> KindID' 'V5 prefix
forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
UUID -> [Word8] -> KindID' 'V5 prefix
genKindIDV5
    {-# INLINE genID_ #-}

    genIDs_ :: MonadIO m
            => Proxy (KindID' 'V5 prefix)
            -> UUID
            -> [Word8]
            -> Word16
            -> m [KindID' 'V5 prefix]
    genIDs_ :: forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V5 prefix)
-> UUID -> [Word8] -> Word16 -> m [KindID' 'V5 prefix]
genIDs_ Proxy (KindID' 'V5 prefix)
p UUID
ns [Word8]
obj Word16
n = Int -> m (KindID' 'V5 prefix) -> m [KindID' 'V5 prefix]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM (Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
n) (Proxy (KindID' 'V5 prefix)
-> GenFunc
     (IDGenPrefix (KindID' 'V5 prefix))
     (IDGenReq (KindID' 'V5 prefix) (m (KindID' 'V5 prefix)))
forall a (m :: * -> *).
(IDGen a, MonadIO m) =>
Proxy a -> GenFunc (IDGenPrefix a) (IDGenReq a (m a))
forall (m :: * -> *).
MonadIO m =>
Proxy (KindID' 'V5 prefix)
-> GenFunc
     (IDGenPrefix (KindID' 'V5 prefix))
     (IDGenReq (KindID' 'V5 prefix) (m (KindID' 'V5 prefix)))
genID_ Proxy (KindID' 'V5 prefix)
p UUID
ns [Word8]
obj)
    {-# INLINE genIDs_ #-}

    decorate_ :: Proxy (KindID' 'V5 prefix) -> UUID -> KindID' 'V5 prefix
    decorate_ :: Proxy (KindID' 'V5 prefix) -> UUID -> KindID' 'V5 prefix
decorate_ Proxy (KindID' 'V5 prefix)
_ = UUID -> KindID' 'V5 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
UUID -> KindID' version prefix
decorateKindID
    {-# INLINE decorate_ #-}

    checkID_ :: Proxy (KindID' 'V5 prefix)
             -> KindID' 'V5 prefix
             -> Maybe TypeIDError
    checkID_ :: Proxy (KindID' 'V5 prefix)
-> KindID' 'V5 prefix -> Maybe TypeIDError
checkID_ Proxy (KindID' 'V5 prefix)
_ = KindID' 'V5 prefix -> Maybe TypeIDError
forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V5 prefix -> Maybe TypeIDError
checkKindIDV5
    {-# INLINE checkID_ #-}

-- | Generate a new 'Data.KindID.V7.KindID' from a prefix.
--
-- It throws a 'TypeIDError' if the prefix does not match the specification,
-- namely if it's longer than 63 characters or if it contains characters other
-- than lowercase latin letters.
genKindID :: forall prefix m
           . ( ToPrefix prefix
             , ValidPrefix (PrefixSymbol prefix)
             , MonadIO m )
          => m (KindID' 'V7 prefix)
genKindID :: forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V7 prefix)
genKindID = TypeID' 'V7 -> KindID' 'V7 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID
        (TypeID' 'V7 -> KindID' 'V7 prefix)
-> m (TypeID' 'V7) -> m (KindID' 'V7 prefix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> m (TypeID' 'V7)
forall (m :: * -> *). MonadIO m => Text -> m (TypeID' 'V7)
V7.unsafeGenTypeID (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(PrefixSymbol prefix) Proxy (PrefixSymbol prefix)
forall {k} (t :: k). Proxy t
Proxy)
{-# INLINE genKindID #-}

-- | Generate a new 'Data.KindID.V7.KindID' from a prefix based on stateless
-- 'UUID'v7.
--
-- See the documentation of 'V7.genUUID'' for more information.
genKindID' :: forall prefix m
            . ( ToPrefix prefix
              , ValidPrefix (PrefixSymbol prefix)
              , MonadIO m )
           => m (KindID' 'V7 prefix)
genKindID' :: forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V7 prefix)
genKindID' = (TypeID' 'V7 -> KindID' 'V7 prefix)
-> m (TypeID' 'V7) -> m (KindID' 'V7 prefix)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TypeID' 'V7 -> KindID' 'V7 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (m (TypeID' 'V7) -> m (KindID' 'V7 prefix))
-> (String -> m (TypeID' 'V7)) -> String -> m (KindID' 'V7 prefix)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m (TypeID' 'V7)
forall (m :: * -> *). MonadIO m => Text -> m (TypeID' 'V7)
V7.unsafeGenTypeID' (Text -> m (TypeID' 'V7))
-> (String -> Text) -> String -> m (TypeID' 'V7)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
           (String -> m (KindID' 'V7 prefix))
-> String -> m (KindID' 'V7 prefix)
forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(PrefixSymbol prefix) Proxy (PrefixSymbol prefix)
forall {k} (t :: k). Proxy t
Proxy
{-# INLINE genKindID' #-}

-- | Generate a list of 'Data.KindID.V7.KindID's from a prefix.
--
-- It tries its best to generate 'Data.KindID.V7.KindID's at the same timestamp,
-- but it may not be possible if we are asking too many 'UUID's at the same
-- time.
--
-- It is guaranteed that the first 32768 'Data.KindID.V7.KindID's are generated
-- at the same timestamp.
genKindIDs :: forall prefix m
            . ( ToPrefix prefix
              , ValidPrefix (PrefixSymbol prefix)
              , MonadIO m )
           => Word16 -> m [KindID' 'V7 prefix]
genKindIDs :: forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
Word16 -> m [KindID' 'V7 prefix]
genKindIDs Word16
n = ([TypeID' 'V7] -> [KindID' 'V7 prefix])
-> m [TypeID' 'V7] -> m [KindID' 'V7 prefix]
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TypeID' 'V7 -> KindID' 'V7 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (TypeID' 'V7 -> KindID' 'V7 prefix)
-> [TypeID' 'V7] -> [KindID' 'V7 prefix]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (m [TypeID' 'V7] -> m [KindID' 'V7 prefix])
-> (String -> m [TypeID' 'V7]) -> String -> m [KindID' 'V7 prefix]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Word16 -> m [TypeID' 'V7])
-> Word16 -> Text -> m [TypeID' 'V7]
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> Word16 -> m [TypeID' 'V7]
forall (m :: * -> *).
MonadIO m =>
Text -> Word16 -> m [TypeID' 'V7]
V7.unsafeGenTypeIDs Word16
n (Text -> m [TypeID' 'V7])
-> (String -> Text) -> String -> m [TypeID' 'V7]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
             (String -> m [KindID' 'V7 prefix])
-> String -> m [KindID' 'V7 prefix]
forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(PrefixSymbol prefix) Proxy (PrefixSymbol prefix)
forall {k} (t :: k). Proxy t
Proxy
{-# INLINE genKindIDs #-}

-- | Generate a new 'KindID'' ''V1' from a prefix.
--
-- It throws a 'TypeIDError' if the prefix does not match the specification,
-- namely if it's longer than 63 characters or if it contains characters other
-- than lowercase latin letters.
genKindIDV1 :: forall prefix m
           . ( ToPrefix prefix
             , ValidPrefix (PrefixSymbol prefix)
             , MonadIO m )
          => m (KindID' 'V1 prefix)
genKindIDV1 :: forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V1 prefix)
genKindIDV1 = (TypeID' 'V1 -> KindID' 'V1 prefix)
-> m (TypeID' 'V1) -> m (KindID' 'V1 prefix)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TypeID' 'V1 -> KindID' 'V1 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (m (TypeID' 'V1) -> m (KindID' 'V1 prefix))
-> (String -> m (TypeID' 'V1)) -> String -> m (KindID' 'V1 prefix)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m (TypeID' 'V1)
forall (m :: * -> *). MonadIO m => Text -> m (TypeID' 'V1)
V1.unsafeGenTypeID (Text -> m (TypeID' 'V1))
-> (String -> Text) -> String -> m (TypeID' 'V1)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
            (String -> m (KindID' 'V1 prefix))
-> String -> m (KindID' 'V1 prefix)
forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(PrefixSymbol prefix) Proxy (PrefixSymbol prefix)
forall {k} (t :: k). Proxy t
Proxy
{-# INLINE genKindIDV1 #-}

-- | Generate a new 'KindID'' ''V4' from a prefix.
--
-- It throws a 'TypeIDError' if the prefix does not match the specification,
-- namely if it's longer than 63 characters or if it contains characters other
-- than lowercase latin letters.
genKindIDV4 :: forall prefix m
             . ( ToPrefix prefix
             , ValidPrefix (PrefixSymbol prefix)
             , MonadIO m )
            => m (KindID' 'V4 prefix)
genKindIDV4 :: forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V4 prefix)
genKindIDV4 = (TypeID' 'V4 -> KindID' 'V4 prefix)
-> m (TypeID' 'V4) -> m (KindID' 'V4 prefix)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TypeID' 'V4 -> KindID' 'V4 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (m (TypeID' 'V4) -> m (KindID' 'V4 prefix))
-> (String -> m (TypeID' 'V4)) -> String -> m (KindID' 'V4 prefix)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m (TypeID' 'V4)
forall (m :: * -> *). MonadIO m => Text -> m (TypeID' 'V4)
V4.unsafeGenTypeID (Text -> m (TypeID' 'V4))
-> (String -> Text) -> String -> m (TypeID' 'V4)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
            (String -> m (KindID' 'V4 prefix))
-> String -> m (KindID' 'V4 prefix)
forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(PrefixSymbol prefix) Proxy (PrefixSymbol prefix)
forall {k} (t :: k). Proxy t
Proxy
{-# INLINE genKindIDV4 #-}

-- | Generate a new 'KindID'' ''V4' from a prefix with insecure 'UUID'v4.
genKindIDV4' :: forall prefix m
              . ( ToPrefix prefix
                , ValidPrefix (PrefixSymbol prefix)
                , MonadIO m )
             => m (KindID' 'V4 prefix)
genKindIDV4' :: forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
m (KindID' 'V4 prefix)
genKindIDV4' = (TypeID' 'V4 -> KindID' 'V4 prefix)
-> m (TypeID' 'V4) -> m (KindID' 'V4 prefix)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TypeID' 'V4 -> KindID' 'V4 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (m (TypeID' 'V4) -> m (KindID' 'V4 prefix))
-> (String -> m (TypeID' 'V4)) -> String -> m (KindID' 'V4 prefix)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> m (TypeID' 'V4)
forall (m :: * -> *). MonadIO m => Text -> m (TypeID' 'V4)
V4.unsafeGenTypeID' (Text -> m (TypeID' 'V4))
-> (String -> Text) -> String -> m (TypeID' 'V4)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
             (String -> m (KindID' 'V4 prefix))
-> String -> m (KindID' 'V4 prefix)
forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(PrefixSymbol prefix) Proxy (PrefixSymbol prefix)
forall {k} (t :: k). Proxy t
Proxy
{-# INLINE genKindIDV4' #-}

-- | Generate a new 'KindID'' ''V5' from a namespace and an object.
genKindIDV5 :: forall prefix
             . ( ToPrefix prefix
               , ValidPrefix (PrefixSymbol prefix))
            => UUID
            -> [Word8]
            -> KindID' 'V5 prefix
genKindIDV5 :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
UUID -> [Word8] -> KindID' 'V5 prefix
genKindIDV5 UUID
ns [Word8]
obj
  = TypeID' 'V5 -> KindID' 'V5 prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (TypeID' 'V5 -> KindID' 'V5 prefix)
-> (String -> TypeID' 'V5) -> String -> KindID' 'V5 prefix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> [Word8] -> TypeID' 'V5) -> [Word8] -> Text -> TypeID' 'V5
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Text -> UUID -> [Word8] -> TypeID' 'V5
`V5.unsafeGenTypeID` UUID
ns) [Word8]
obj (Text -> TypeID' 'V5) -> (String -> Text) -> String -> TypeID' 'V5
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
  (String -> KindID' 'V5 prefix) -> String -> KindID' 'V5 prefix
forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal @(PrefixSymbol prefix) Proxy (PrefixSymbol prefix)
forall {k} (t :: k). Proxy t
Proxy
{-# INLINE genKindIDV5 #-}

-- | Obtain a 'KindID'' from a prefix and a 'UUID'.
decorateKindID :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
               => UUID -> KindID' version prefix
decorateKindID :: forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
UUID -> KindID' version prefix
decorateKindID = UUID -> KindID' version prefix
forall {k} (version :: UUIDVersion) (prefix :: k).
UUID -> KindID' version prefix
KindID'
{-# INLINE decorateKindID #-}

-- | Convert a 'KindID'' to a 'TypeID''.
toTypeID :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
         => KindID' version prefix -> TypeID' version
toTypeID :: forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID KindID' version prefix
kid = Text -> UUID -> TypeID' version
forall (version :: UUIDVersion). Text -> UUID -> TypeID' version
TID.TypeID' (KindID' version prefix -> Text
forall a. IDType a => a -> Text
getPrefix KindID' version prefix
kid) (KindID' version prefix -> UUID
forall a. IDType a => a -> UUID
getUUID KindID' version prefix
kid)
{-# INLINE toTypeID #-}

-- | Convert a 'TypeID'' to a 'KindID''. If the actual prefix does not match
-- with the expected one as defined by the type, it returns @Nothing@.
fromTypeID :: forall version prefix
            . (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
           => TypeID' version -> Maybe (KindID' version prefix)
fromTypeID :: forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> Maybe (KindID' version prefix)
fromTypeID TypeID' version
tid = do
  Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (String -> Text
T.pack (Proxy (PrefixSymbol prefix) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(PrefixSymbol prefix))) Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== TypeID' version -> Text
forall a. IDType a => a -> Text
getPrefix TypeID' version
tid)
  KindID' version prefix -> Maybe (KindID' version prefix)
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (KindID' version prefix -> Maybe (KindID' version prefix))
-> KindID' version prefix -> Maybe (KindID' version prefix)
forall a b. (a -> b) -> a -> b
$ UUID -> KindID' version prefix
forall {k} (version :: UUIDVersion) (prefix :: k).
UUID -> KindID' version prefix
KindID' (TypeID' version -> UUID
forall a. IDType a => a -> UUID
getUUID TypeID' version
tid)
{-# INLINE fromTypeID #-}

-- | Pretty-print a 'KindID''. It is 'id2String' with concrete type.
toString :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
         => KindID' version prefix -> String
toString :: forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> String
toString = TypeID' version -> String
forall (version :: UUIDVersion). TypeID' version -> String
TID.toString (TypeID' version -> String)
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
{-# INLINE toString #-}

-- | Pretty-print a 'KindID'' to strict 'Text'. It is 'id2Text' with concrete
-- type.
toText :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
       => KindID' version prefix -> Text
toText :: forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> Text
toText = TypeID' version -> Text
forall (version :: UUIDVersion). TypeID' version -> Text
TID.toText (TypeID' version -> Text)
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
{-# INLINE toText #-}

-- | Pretty-print a 'KindID'' to lazy 'ByteString'. It is 'id2ByteString' with
-- concrete type.
toByteString :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
             => KindID' version prefix -> ByteString
toByteString :: forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> ByteString
toByteString = TypeID' version -> ByteString
forall (version :: UUIDVersion). TypeID' version -> ByteString
TID.toByteString (TypeID' version -> ByteString)
-> (KindID' version prefix -> TypeID' version)
-> KindID' version prefix
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' version prefix -> TypeID' version
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
{-# INLINE toByteString #-}

-- | Parse a 'KindID'' from its 'String' representation. It is 'parseString'
-- with concrete type.
parseString :: forall version prefix
             . (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
            => String -> Either TypeIDError (KindID' version prefix)
parseString :: forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
String -> Either TypeIDError (KindID' version prefix)
parseString String
str = do
  TypeID' version
tid <- String -> Either TypeIDError (TypeID' version)
forall (version :: UUIDVersion).
String -> Either TypeIDError (TypeID' version)
TID.parseString String
str
  case TypeID' version -> Maybe (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> Maybe (KindID' version prefix)
fromTypeID TypeID' version
tid of
    Maybe (KindID' version prefix)
Nothing  -> TypeIDError -> Either TypeIDError (KindID' version prefix)
forall a b. a -> Either a b
Left (TypeIDError -> Either TypeIDError (KindID' version prefix))
-> TypeIDError -> Either TypeIDError (KindID' version prefix)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> TypeIDError
TypeIDErrorPrefixMismatch
                       (String -> Text
T.pack (Proxy (PrefixSymbol prefix) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(PrefixSymbol prefix))))
                       (TypeID' version -> Text
forall a. IDType a => a -> Text
getPrefix TypeID' version
tid)
    Just KindID' version prefix
kid -> KindID' version prefix
-> Either TypeIDError (KindID' version prefix)
forall a. a -> Either TypeIDError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KindID' version prefix
kid
{-# INLINE parseString #-}

-- | Parse a 'KindID'' from its string representation as a strict 'Text'. It is
-- 'parseText' with concrete type.
parseText :: forall version prefix
           . (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
          => Text -> Either TypeIDError (KindID' version prefix)
parseText :: forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> Either TypeIDError (KindID' version prefix)
parseText Text
str = do
  TypeID' version
tid <- Text -> Either TypeIDError (TypeID' version)
forall (version :: UUIDVersion).
Text -> Either TypeIDError (TypeID' version)
TID.parseText Text
str
  case TypeID' version -> Maybe (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> Maybe (KindID' version prefix)
fromTypeID TypeID' version
tid of
    Maybe (KindID' version prefix)
Nothing  -> TypeIDError -> Either TypeIDError (KindID' version prefix)
forall a b. a -> Either a b
Left (TypeIDError -> Either TypeIDError (KindID' version prefix))
-> TypeIDError -> Either TypeIDError (KindID' version prefix)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> TypeIDError
TypeIDErrorPrefixMismatch
                       (String -> Text
T.pack (Proxy (PrefixSymbol prefix) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(PrefixSymbol prefix))))
                       (TypeID' version -> Text
forall a. IDType a => a -> Text
getPrefix TypeID' version
tid)
    Just KindID' version prefix
kid -> KindID' version prefix
-> Either TypeIDError (KindID' version prefix)
forall a. a -> Either TypeIDError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KindID' version prefix
kid
{-# INLINE parseText #-}

-- | Parse a 'KindID'' from its string representation as a lazy 'ByteString'. It
-- is 'parseByteString' with concrete type.
parseByteString :: forall version prefix
                 . (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                => ByteString -> Either TypeIDError (KindID' version prefix)
parseByteString :: forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
ByteString -> Either TypeIDError (KindID' version prefix)
parseByteString ByteString
str = do
  TypeID' version
tid <- ByteString -> Either TypeIDError (TypeID' version)
forall (version :: UUIDVersion).
ByteString -> Either TypeIDError (TypeID' version)
TID.parseByteString ByteString
str
  case TypeID' version -> Maybe (KindID' version prefix)
forall {k} (version :: UUIDVersion) (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> Maybe (KindID' version prefix)
fromTypeID TypeID' version
tid of
    Maybe (KindID' version prefix)
Nothing  -> TypeIDError -> Either TypeIDError (KindID' version prefix)
forall a b. a -> Either a b
Left (TypeIDError -> Either TypeIDError (KindID' version prefix))
-> TypeIDError -> Either TypeIDError (KindID' version prefix)
forall a b. (a -> b) -> a -> b
$ Text -> Text -> TypeIDError
TypeIDErrorPrefixMismatch
                       (String -> Text
T.pack (Proxy (PrefixSymbol prefix) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(PrefixSymbol prefix))))
                       (TypeID' version -> Text
forall a. IDType a => a -> Text
getPrefix TypeID' version
tid)
    Just KindID' version prefix
kid -> KindID' version prefix
-> Either TypeIDError (KindID' version prefix)
forall a. a -> Either TypeIDError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KindID' version prefix
kid
{-# INLINE parseByteString #-}

-- | Parse a 'KindID'' from its 'String' representation, throwing an error when
-- the parsing fails. It is 'string2IDM' with concrete type.
parseStringM :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m)
             => String -> m (KindID' version prefix)
parseStringM :: forall {k} (prefix :: k) (m :: * -> *) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
String -> m (KindID' version prefix)
parseStringM = String -> m (KindID' version prefix)
forall a (m :: * -> *). (IDConv a, MonadIO m) => String -> m a
forall (m :: * -> *).
MonadIO m =>
String -> m (KindID' version prefix)
string2IDM
{-# INLINE parseStringM #-}

-- | Parse a 'KindID'' from its string representation as a strict 'Text',
-- throwing an error when the parsing fails. It is 'text2IDM' with concrete
-- type.
parseTextM :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m)
           => Text -> m (KindID' version prefix)
parseTextM :: forall {k} (prefix :: k) (m :: * -> *) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
Text -> m (KindID' version prefix)
parseTextM = Text -> m (KindID' version prefix)
forall a (m :: * -> *). (IDConv a, MonadIO m) => Text -> m a
forall (m :: * -> *).
MonadIO m =>
Text -> m (KindID' version prefix)
text2IDM
{-# INLINE parseTextM #-}

-- | Parse a 'KindID'' from its string representation as a lazy 'ByteString',
-- throwing an error when the parsing fails. It is 'byteString2IDM' with
-- concrete type.
parseByteStringM :: ( ToPrefix prefix
                    , ValidPrefix (PrefixSymbol prefix)
                    , MonadIO m )
                 => ByteString
                 -> m (KindID' version prefix)
parseByteStringM :: forall {k} (prefix :: k) (m :: * -> *) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
ByteString -> m (KindID' version prefix)
parseByteStringM = ByteString -> m (KindID' version prefix)
forall a (m :: * -> *). (IDConv a, MonadIO m) => ByteString -> m a
forall (m :: * -> *).
MonadIO m =>
ByteString -> m (KindID' version prefix)
byteString2IDM
{-# INLINE parseByteStringM #-}

-- | Check if the prefix is valid and the suffix 'UUID' has the correct v7
-- version and variant.
checkKindID :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
            => KindID' 'V7 prefix -> Maybe TypeIDError
checkKindID :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V7 prefix -> Maybe TypeIDError
checkKindID = TypeID' 'V7 -> Maybe TypeIDError
TID.checkTypeID (TypeID' 'V7 -> Maybe TypeIDError)
-> (KindID' 'V7 prefix -> TypeID' 'V7)
-> KindID' 'V7 prefix
-> Maybe TypeIDError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' 'V7 prefix -> TypeID' 'V7
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
{-# INLINE checkKindID #-}

-- | Similar to 'checkKindID', but also checks if the suffix 'UUID' is
-- generated in the past.
checkKindIDWithEnv :: ( ToPrefix prefix
                      , ValidPrefix (PrefixSymbol prefix)
                      , MonadIO m )
                   => KindID' 'V7 prefix -> m (Maybe TypeIDError)
checkKindIDWithEnv :: forall {k} (prefix :: k) (m :: * -> *).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix), MonadIO m) =>
KindID' 'V7 prefix -> m (Maybe TypeIDError)
checkKindIDWithEnv = TypeID' 'V7 -> m (Maybe TypeIDError)
forall (m :: * -> *).
MonadIO m =>
TypeID' 'V7 -> m (Maybe TypeIDError)
TID.checkTypeIDWithEnv (TypeID' 'V7 -> m (Maybe TypeIDError))
-> (KindID' 'V7 prefix -> TypeID' 'V7)
-> KindID' 'V7 prefix
-> m (Maybe TypeIDError)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' 'V7 prefix -> TypeID' 'V7
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
{-# INLINE checkKindIDWithEnv #-}

-- | Check if the prefix is valid and the suffix 'UUID' has the correct v1
-- version and variant.
checkKindIDV1 :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
              => KindID' 'V1 prefix -> Maybe TypeIDError
checkKindIDV1 :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V1 prefix -> Maybe TypeIDError
checkKindIDV1 = TypeID' 'V1 -> Maybe TypeIDError
TID.checkTypeIDV1 (TypeID' 'V1 -> Maybe TypeIDError)
-> (KindID' 'V1 prefix -> TypeID' 'V1)
-> KindID' 'V1 prefix
-> Maybe TypeIDError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' 'V1 prefix -> TypeID' 'V1
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
{-# INLINE checkKindIDV1 #-}

-- | Check if the prefix is valid and the suffix 'UUID' has the correct v4
-- version and variant.
checkKindIDV4 :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
              => KindID' 'V4 prefix -> Maybe TypeIDError
checkKindIDV4 :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V4 prefix -> Maybe TypeIDError
checkKindIDV4 = TypeID' 'V4 -> Maybe TypeIDError
TID.checkTypeIDV4 (TypeID' 'V4 -> Maybe TypeIDError)
-> (KindID' 'V4 prefix -> TypeID' 'V4)
-> KindID' 'V4 prefix
-> Maybe TypeIDError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' 'V4 prefix -> TypeID' 'V4
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID
{-# INLINE checkKindIDV4 #-}

-- | Check if the prefix is valid and the suffix 'UUID' has the correct v5
-- version and variant.
checkKindIDV5 :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
              => KindID' 'V5 prefix -> Maybe TypeIDError
checkKindIDV5 :: forall {k} (prefix :: k).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' 'V5 prefix -> Maybe TypeIDError
checkKindIDV5 = TypeID' 'V5 -> Maybe TypeIDError
TID.checkTypeIDV5 (TypeID' 'V5 -> Maybe TypeIDError)
-> (KindID' 'V5 prefix -> TypeID' 'V5)
-> KindID' 'V5 prefix
-> Maybe TypeIDError
forall b c a. (b -> c) -> (a -> b) -> a -> c
. KindID' 'V5 prefix -> TypeID' 'V5
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
KindID' version prefix -> TypeID' version
toTypeID

-- | Convert a 'TypeID'' to a 'KindID''. If the actual prefix does not match
-- with the expected one as defined by the type, it does not complain and
-- produces a wrong 'KindID''.
unsafeFromTypeID :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                 => TypeID' version -> KindID' version prefix
unsafeFromTypeID :: forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID TypeID' version
tid = UUID -> KindID' version prefix
forall {k} (version :: UUIDVersion) (prefix :: k).
UUID -> KindID' version prefix
KindID' (TypeID' version -> UUID
forall a. IDType a => a -> UUID
getUUID TypeID' version
tid)
{-# INLINE unsafeFromTypeID #-}

-- | Parse a 'KindID'' from its 'String' representation, but does not behave
-- correctly when parsing fails.
--
-- More specifically, if the prefix does not match, it will not complain and
-- produce the wrong 'KindID''. If there are other parse errors, it will crash.
unsafeParseString :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                  => String -> KindID' version prefix
unsafeParseString :: forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
String -> KindID' version prefix
unsafeParseString = TypeID' version -> KindID' version prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (TypeID' version -> KindID' version prefix)
-> (String -> TypeID' version) -> String -> KindID' version prefix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> TypeID' version
forall (version :: UUIDVersion). String -> TypeID' version
TID.unsafeParseString
{-# INLINE unsafeParseString #-}

-- | Parse a 'KindID'' from its string representation as a strict 'Text', but
-- does not behave correctly when parsing fails.
--
-- More specifically, if the prefix does not match, it will not complain and
-- produce the wrong 'KindID''. If there are other parse errors, it will crash.
unsafeParseText :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                => Text -> KindID' version prefix
unsafeParseText :: forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
Text -> KindID' version prefix
unsafeParseText = TypeID' version -> KindID' version prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (TypeID' version -> KindID' version prefix)
-> (Text -> TypeID' version) -> Text -> KindID' version prefix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TypeID' version
forall (version :: UUIDVersion). Text -> TypeID' version
TID.unsafeParseText
{-# INLINE unsafeParseText #-}

-- | Parse a 'KindID'' from its string representation as a lazy 'ByteString', but
-- does not behave correctly when parsing fails.
--
-- More specifically, if the prefix does not match, it will not complain and
-- produce the wrong 'KindID''. If there are other parse errors, it will crash.
unsafeParseByteString :: (ToPrefix prefix, ValidPrefix (PrefixSymbol prefix))
                      => ByteString -> KindID' version prefix
unsafeParseByteString :: forall k (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
ByteString -> KindID' version prefix
unsafeParseByteString = TypeID' version -> KindID' version prefix
forall {k} (prefix :: k) (version :: UUIDVersion).
(ToPrefix prefix, ValidPrefix (PrefixSymbol prefix)) =>
TypeID' version -> KindID' version prefix
unsafeFromTypeID (TypeID' version -> KindID' version prefix)
-> (ByteString -> TypeID' version)
-> ByteString
-> KindID' version prefix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> TypeID' version
forall (version :: UUIDVersion). ByteString -> TypeID' version
TID.unsafeParseByteString
{-# INLINE unsafeParseByteString #-}