mmzk-typeid-0.2.0.0: A TypeID implementation for Haskell
LicenseMIT
Maintainermmzk1526@outlook.com
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.TypeID

Description

An implementation of the typeid specification: https://github.com/jetpack-io/typeid.

Synopsis

Data types

data TypeID Source #

The constructor is not exposed to the public API to prevent generating invalid TypeIDs.

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

Instances details
Show TypeID Source # 
Instance details

Defined in Data.TypeID.Internal

Eq TypeID Source # 
Instance details

Defined in Data.TypeID.Internal

Methods

(==) :: TypeID -> TypeID -> Bool #

(/=) :: TypeID -> TypeID -> Bool #

Ord TypeID Source # 
Instance details

Defined in Data.TypeID.Internal

IDConv TypeID Source #

Conversion between TypeID and StringTextByteString.

Instance details

Defined in Data.TypeID.Internal

IDType TypeID Source #

Get the prefix, UUID, and timestamp of a TypeID.

Instance details

Defined in Data.TypeID.Internal

FromJSON TypeID Source # 
Instance details

Defined in Data.TypeID.Internal

FromJSONKey TypeID Source # 
Instance details

Defined in Data.TypeID.Internal

ToJSON TypeID Source # 
Instance details

Defined in Data.TypeID.Internal

ToJSONKey TypeID Source # 
Instance details

Defined in Data.TypeID.Internal

getPrefix :: IDType a => a -> Text Source #

Get the prefix of the identifier.

getUUID :: IDType a => a -> UUID Source #

Get the UUID suffix of the identifier.

getTime :: IDType a => a -> Word64 Source #

Get the timestamp of the identifier.

TypeID generation

nil :: TypeID Source #

Deprecated: Use nilTypeID instead.

The nil TypeID.

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.

genTypeIDs :: Text -> Word16 -> IO [TypeID] Source #

Generate n TypeIDs from a prefix.

It tries its best to generate TypeIDs at the same timestamp, but it may not be possible if we are asking too many UUIDs at the same time.

It is guaranteed that the first 32768 TypeIDs are generated at the same timestamp.

decorate :: Text -> UUID -> Either TypeIDError TypeID Source #

Deprecated: Use decorateTypeID instead.

Obtain a TypeID from a prefix and a UUID.

decorateTypeID :: Text -> UUID -> Either TypeIDError TypeID Source #

Obtain a TypeID from a prefix and a UUID.

Prefix validation

checkPrefix :: Text -> Maybe TypeIDError Source #

Check if the given prefix is a valid TypeID prefix.

Encoding & decoding (class methods)

id2String :: IDConv a => a -> String Source #

Pretty-print the identifier to a String.

id2Text :: IDConv a => a -> Text Source #

Pretty-print the identifier to a strict Text.

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)

toString :: TypeID -> String Source #

Pretty-print a TypeID. It is id2String with concrete type.

toText :: TypeID -> Text Source #

Pretty-print a TypeID to strict Text. It is id2Text with concrete type.

toByteString :: TypeID -> ByteString Source #

Pretty-print a TypeID to lazy ByteString. It is id2ByteString with concrete type.

parseString :: String -> Either TypeIDError TypeID Source #

Parse a TypeID from its String representation. It is string2ID with concrete type.

parseText :: Text -> Either TypeIDError TypeID Source #

Parse a TypeID from its string representation as a strict Text. It is text2ID with concrete type.

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 #

Deprecated: Use parseText and decorate instead

Parse a TypeID from the given prefix and the string representation of a suffix as a strict Text.

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.