Exosphere.ATProto.AtUri (Exosphere v0.3.0)

Copy Markdown View Source

AT URI (at://) parsing and validation.

AT URIs reference repositories, collections, and records, for example:

at://did:plc:44ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk26

This module parses the restricted "well-behaved" form used in Lexicon records (see the AT URI spec):

"at://" AUTHORITY [ "/" COLLECTION [ "/" RKEY ] ] [ "#" FRAGMENT ]

where the authority is a DID or handle, the collection is an NSID, and the record key is a valid record key.

Examples

iex> Exosphere.ATProto.AtUri.parse("at://alice.example.com/app.bsky.feed.post/3jwdwj2ctlk26")
{:ok, %Exosphere.ATProto.AtUri{authority: "alice.example.com", collection: "app.bsky.feed.post", rkey: "3jwdwj2ctlk26", fragment: nil}}

iex> Exosphere.ATProto.AtUri.parse("https://example.com")
{:error, :invalid_scheme}

Summary

Functions

Parse an AT URI string into an %Exosphere.ATProto.AtUri{} struct.

Render an %Exosphere.ATProto.AtUri{} struct back to its string form.

Validate an AT URI string.

Types

error()

@type error() ::
  :invalid_scheme
  | :too_long
  | :invalid_authority
  | :invalid_collection
  | :invalid_rkey
  | :rkey_without_collection
  | :invalid_fragment
  | :invalid_at_uri

t()

@type t() :: %Exosphere.ATProto.AtUri{
  authority: String.t(),
  collection: String.t() | nil,
  fragment: String.t() | nil,
  rkey: String.t() | nil
}

Functions

parse(uri)

@spec parse(String.t()) :: {:ok, t()} | {:error, error()}

Parse an AT URI string into an %Exosphere.ATProto.AtUri{} struct.

to_string(uri)

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

Render an %Exosphere.ATProto.AtUri{} struct back to its string form.

valid?(uri)

@spec valid?(String.t()) :: boolean()

Validate an AT URI string.