UXID (UXID v0.0.3) View Source

UXIDs are identifiers which:

  • describe the resource (to help in debugging and investigation)
  • work well with copy and paste (double clicking should select the entire ID)
  • can be shortened for low cardinality resources
  • are very unlikely to collide
  • are secure against enumeration attacks
  • can be generated by application code (not tied to the datastore)
  • are K-sortable (lexicographically sortable by time - works well with datastore indexing)
  • do not require any coordination (human or automated) at startup, or generation

Many of the concepts of Stripe IDs have been used in this library.

Link to this section Summary

Types

An error string returned by the library if generation fails

Options for generating a UXID

t()

A UXID struct

A UXID represented as a String

Functions

Decodes a UXID from a string.

Returns an encoded UXID string along with response status.

Returns an unwrapped encoded UXID string or raises on error.

Returns a new UXID struct. This is useful for development.

Link to this section Types

Specs

error_string() :: String.t()

An error string returned by the library if generation fails

Specs

option() :: {:time, integer()} | {:rand_size, integer()} | {:prefix, String.t()}

Options for generating a UXID

Specs

options() :: [option()]

Specs

t() :: %UXID{
  encoded: String.t() | nil,
  prefix: String.t() | nil,
  rand: binary() | nil,
  rand_encoded: String.t() | nil,
  rand_size: pos_integer() | nil,
  string: String.t() | nil,
  time: pos_integer() | nil,
  time_encoded: String.t() | nil
}

A UXID struct

Specs

uxid_string() :: String.t()

A UXID represented as a String

Link to this section Functions

Decodes a UXID from a string.

Specs

generate(opts :: options()) :: {:ok, uxid_string()} | {:error, error_string()}

Returns an encoded UXID string along with response status.

Specs

generate!(opts :: options()) :: uxid_string()

Returns an unwrapped encoded UXID string or raises on error.

Specs

new(opts :: options()) :: {:ok, t()} | {:error, error_string()}

Returns a new UXID struct. This is useful for development.