Search documentation of jhn_stdlib

# jhn_typeid (jhn_stdlib v5.10.3)

View Source

A UUID library based on: TypeID Specification (Version 0.3.0) https://github.com/jetify-com/typeid/tree/main/spec

A library for generating typeids.

Functions for encoding/decoding UUIDs are provided for completness and testing purposes and the select few occations they are actually needed.

A decoded typeid is represented as a map:

* human (default for decode): UUID format with human readbable timestamp

`#{prefix => <<"oid">>, uuid => #{timestamp => <<"2024-09-30T08:15:06.266Z">>, version => 7, random => 486766668076239088766}}`

* uuid: Standard encoded UUIDv7 format

`#{prefix => <<"oid">>, uuid => <<"019241ff-581a-7069-a33e-999d70b4ec7e">>}`

* hex: Non-standard encoded UUIDv7 hex format without dashes

`#{prefix => <<"oid">>, uuid => <<"019241ff581a7069a33e999d70b4ec7e">>}`

# Summary

## Types

format_opt/0
prefix/0
return_type/0
typeid/0

## Functions

decode(Id)

Generates the an TypeId as an iolist.

decode(Id, Opts)

Generates the an TypeId as an iolist.

encode(Id)

Encodes the an TypeId as an iolist.

encode(Id, Opts)

Encodes the an TypeId with the format determined by the Opts.

gen()

Generates the an TypeId as a binary.

gen(Prefix)

Generates the an TypeId as an iolist.

gen(Prefix, Opts)

Generates the an TypeId with the format determined by the Opts.

is_valid_prefix(P)

Verifies that a binary is a valid prefix for a typeid

# Types

# format_opt/0

    -type format_opt() :: hex | uuid | human.

# prefix/0

    -type prefix() :: atom() | list() | binary().

# return_type/0

    -type return_type() :: iolist | binary | list | typeid.

# typeid/0

    -type typeid() :: #{prefix => atom() | list() | binary(), uuid => binary()}.

# Functions

# decode(Id)

    -spec decode(binary()) -> map().

Generates the an TypeId as an iolist.

Equivalent of decode(TypeIdMap, []).

# decode(Id, Opts)

    -spec decode(binary(), [format_opt()]) -> map().

Generates the an TypeId as an iolist.

Equivalent of decode(TypeIdMap, []).

# encode(Id)

    -spec encode(map()) -> iolist().

Encodes the an TypeId as an iolist.

Equivalent of encode(TypeIdMap).

# encode(Id, Opts)

    -spec encode(map(), [return_type()]) -> iolist() | list() | binary() | map().

Encodes the an TypeId with the format determined by the Opts.

Options: iolist -> an iolist is returned list -> a list is returned typeid -> a typeid map is returned

# gen()

    -spec gen() -> binary().

Generates the an TypeId as a binary.

Equivalent of `gen(<<>>)`.

# gen(Prefix)

    -spec gen(prefix()) -> binary().

Generates the an TypeId as an iolist.

Equivalent of gen(Prefix, []).

# gen(Prefix, Opts)

    -spec gen(prefix(), [return_type()]) -> iolist() | list() | binary() | map().

Generates the an TypeId with the format determined by the Opts.

Options: iolist -> an iolist is returned list -> a list is returned typeid -> a typeid map is returned

# is_valid_prefix(P)

    -spec is_valid_prefix(binary()) -> boolean().

Verifies that a binary is a valid prefix for a typeid