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 :: IDType a => a -> Text
- getUUID :: IDType a => a -> UUID
- getTime :: IDType a => a -> Word64
- nil :: TypeID
- nilTypeID :: TypeID
- genTypeID :: Text -> IO TypeID
- genTypeIDs :: Text -> Word16 -> IO [TypeID]
- decorate :: Text -> UUID -> Either TypeIDError TypeID
- decorateTypeID :: Text -> UUID -> Either TypeIDError TypeID
- checkPrefix :: Text -> Maybe TypeIDError
- id2String :: IDConv a => a -> String
- id2Text :: IDConv a => a -> Text
- id2ByteString :: IDConv a => a -> ByteString
- string2ID :: IDConv a => String -> Either TypeIDError a
- text2ID :: IDConv a => Text -> Either TypeIDError a
- byteString2ID :: IDConv a => ByteString -> Either TypeIDError a
- 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
. However, this
behaviour will be changed in the next major version as it is not useful. By
then, the Show
instance will be the same as toString
.
Instances
Show TypeID Source # | |
Eq TypeID Source # | |
Ord TypeID Source # | |
IDConv TypeID Source # | Conversion between |
Defined in Data.TypeID.Internal | |
IDType TypeID Source # | |
FromJSON TypeID Source # | |
Defined in Data.TypeID.Internal | |
FromJSONKey TypeID Source # | |
Defined in Data.TypeID.Internal | |
ToJSON TypeID Source # | |
ToJSONKey TypeID Source # | |
Defined in Data.TypeID.Internal |
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.
decorateTypeID :: Text -> UUID -> Either TypeIDError TypeID Source #
Prefix validation
checkPrefix :: Text -> Maybe TypeIDError Source #
Check if the given prefix is a valid TypeID prefix.
Encoding & decoding (class methods)
id2ByteString :: IDConv a => a -> ByteString Source #
Pretty-print the identifier to a lazy ByteString
.
string2ID :: IDConv a => String -> Either TypeIDError a Source #
Parse the identifier from its String
representation.
text2ID :: IDConv a => Text -> Either TypeIDError a Source #
Parse the identifier from its string representation as a strict Text
.
byteString2ID :: IDConv a => ByteString -> Either TypeIDError a Source #
Parse the identifier from its string representation as a lazy
ByteString
.
Encoding & decoding (TypeID
-specific)
toByteString :: TypeID -> ByteString Source #
Pretty-print a TypeID
to lazy ByteString
. It is id2ByteString
with
concrete type.
parseString :: String -> Either TypeIDError TypeID Source #
parseByteString :: ByteString -> Either TypeIDError TypeID Source #
Parse a TypeID
from its string representation as a lazy ByteString
. It
is byteString2ID
with concrete type.
parseStringWithPrefix :: Text -> String -> Either TypeIDError TypeID Source #
Deprecated: Use parseString
and decorate
instead
Parse a TypeID
from the given prefix and the String
representation of a
suffix.
parseTextWithPrefix :: Text -> Text -> Either TypeIDError TypeID Source #
parseByteStringWithPrefix :: Text -> ByteString -> Either TypeIDError TypeID Source #
Deprecated: Use parseByteString
and decorate
instead
Parse a TypeID
from the given prefix and the string representation of a
suffix as a lazy ByteString
.