License | MIT |
---|---|
Maintainer | mmzk1526@outlook.com |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
An implementation of the typeid specification: https://github.com/jetpack-io/typeid.
Synopsis
- data TypeID
- getPrefix :: TypeID -> Text
- getUUID :: TypeID -> UUID
- getTime :: TypeID -> Word64
- data TypeIDError
- genTypeID :: Text -> IO TypeID
- genTypeIDs :: Text -> Word16 -> IO [TypeID]
- nil :: TypeID
- decorate :: Text -> UUID -> Either TypeIDError TypeID
- checkPrefix :: Text -> Maybe TypeIDError
- toString :: TypeID -> String
- toText :: TypeID -> Text
- toByteString :: TypeID -> ByteString
- parseString :: String -> Either TypeIDError TypeID
- parseText :: Text -> Either TypeIDError TypeID
- parseByteString :: ByteString -> Either TypeIDError TypeID
- parseStringWithPrefix :: Text -> String -> Either TypeIDError TypeID
- parseTextWithPrefix :: Text -> Text -> Either TypeIDError TypeID
- parseByteStringWithPrefix :: Text -> ByteString -> Either TypeIDError TypeID
Data types
The constructor is not exposed to the public API to prevent generating
invalid TypeID
s.
Note that the Show
instance is for debugging purposes only. To pretty-print
a TypeID
, use toString
, toText
or toByteString
.
data TypeIDError Source #
Errors from parsing a TypeID
.
TypeIDErrorPrefixTooLong Int | |
TypeIDExtraSeparator | |
TypeIDErrorPrefixInvalidChar Char | |
TypeIDErrorAlreadyHasPrefix Text | |
TypeIDErrorPrefixMismatch Text Text | |
TypeIDErrorUUIDError |
Instances
Exception TypeIDError Source # | |
Defined in Data.TypeID.Internal | |
Show TypeIDError Source # | |
Defined in Data.TypeID.Internal showsPrec :: Int -> TypeIDError -> ShowS # show :: TypeIDError -> String # showList :: [TypeIDError] -> ShowS # | |
Eq TypeIDError Source # | |
Defined in Data.TypeID.Internal (==) :: TypeIDError -> TypeIDError -> Bool # (/=) :: TypeIDError -> TypeIDError -> Bool # | |
Ord TypeIDError Source # | |
Defined in Data.TypeID.Internal compare :: TypeIDError -> TypeIDError -> Ordering # (<) :: TypeIDError -> TypeIDError -> Bool # (<=) :: TypeIDError -> TypeIDError -> Bool # (>) :: TypeIDError -> TypeIDError -> Bool # (>=) :: TypeIDError -> TypeIDError -> Bool # max :: TypeIDError -> TypeIDError -> TypeIDError # min :: TypeIDError -> TypeIDError -> TypeIDError # |
TypeID generation
genTypeID :: Text -> IO TypeID Source #
Generate a new TypeID
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.
Prefix validation
checkPrefix :: Text -> Maybe TypeIDError Source #
Check if the given prefix is a valid TypeID prefix.
Encoding & decoding
toByteString :: TypeID -> ByteString Source #
Pretty-print a TypeID
to lazy ByteString
.
parseString :: String -> Either TypeIDError TypeID Source #
parseByteString :: ByteString -> Either TypeIDError TypeID Source #
Parse a TypeID
from its string representation as a lazy ByteString
.
parseStringWithPrefix :: Text -> String -> Either TypeIDError TypeID Source #
parseTextWithPrefix :: Text -> Text -> Either TypeIDError TypeID Source #
parseByteStringWithPrefix :: Text -> ByteString -> Either TypeIDError TypeID Source #
Parse a TypeID
from the given prefix and the string representation of a
suffix as a lazy ByteString
.