Gaiia.GlobalID (Gaiia v0.2.0)

Copy Markdown View Source

Encode and decode Gaiia Global IDs.

Global IDs combine a snake_cased type name with a Base58-encoded UUID, separated by an underscore: account_8rnXNuR5sKP5uNwoPL41Zp.

Summary

Functions

Decodes a Global ID into a tuple of {type, uuid}.

Encodes a type name and UUID into a Global ID.

Converts a type name and UUID to a Global ID. Alias for encode/2.

Decodes a short UUID back to a standard UUID string.

Encodes a UUID to a 22-character Base58 short UUID.

Extracts the UUID from a Global ID.

Extracts the type name from a Global ID.

Functions

decode(global_id)

@spec decode(String.t()) :: {String.t(), String.t()}

Decodes a Global ID into a tuple of {type, uuid}.

Examples

iex> Gaiia.GlobalID.decode("account_8rnXNuR5sKP5uNwoPL41Zp")
{"account", "3c3b1978-6a68-4a13-bdc2-2d51c8ef7519"}

encode(type_name, uuid_str)

@spec encode(String.t(), String.t()) :: String.t()

Encodes a type name and UUID into a Global ID.

Examples

iex> Gaiia.GlobalID.encode("Account", "3c3b1978-6a68-4a13-bdc2-2d51c8ef7519")
"account_8rnXNuR5sKP5uNwoPL41Zp"

from_uuid(type_name, uuid_str)

@spec from_uuid(String.t(), String.t()) :: String.t()

Converts a type name and UUID to a Global ID. Alias for encode/2.

Examples

iex> Gaiia.GlobalID.from_uuid("Account", "3c3b1978-6a68-4a13-bdc2-2d51c8ef7519")
"account_8rnXNuR5sKP5uNwoPL41Zp"

short_to_uuid(short_id)

@spec short_to_uuid(String.t()) :: String.t()

Decodes a short UUID back to a standard UUID string.

Examples

iex> Gaiia.GlobalID.short_to_uuid("8rnXNuR5sKP5uNwoPL41Zp")
"3c3b1978-6a68-4a13-bdc2-2d51c8ef7519"

short_uuid(uuid_str)

@spec short_uuid(String.t()) :: String.t()

Encodes a UUID to a 22-character Base58 short UUID.

Examples

iex> Gaiia.GlobalID.short_uuid("3c3b1978-6a68-4a13-bdc2-2d51c8ef7519")
"8rnXNuR5sKP5uNwoPL41Zp"

to_uuid(global_id)

@spec to_uuid(String.t()) :: String.t()

Extracts the UUID from a Global ID.

Examples

iex> Gaiia.GlobalID.to_uuid("account_8rnXNuR5sKP5uNwoPL41Zp")
"3c3b1978-6a68-4a13-bdc2-2d51c8ef7519"

type(global_id)

@spec type(String.t()) :: String.t()

Extracts the type name from a Global ID.

Examples

iex> Gaiia.GlobalID.type("account_8rnXNuR5sKP5uNwoPL41Zp")
"account"