Latch.AtURI (latch v0.3.0)

Copy Markdown

at-uris are used to reference individual records within a repository, identified by did or handle. This module implements the restricted grammar used in Lexicons.

The anatomy of an at-uri

at://did:plc:ewvi7nxzyoun6zhxrhs64oiz/app.bsky.feed.post/3k2u5kbfqzf2k
__/  ______________________________/ ______________/ __________/
 |                 |                         |               |
 scheme         authority                collection       record key
(always "at")  (DID or handle           (NSID  the     (rkey  e.g.
               whose repo this is)        lexicon type)   a TID)

https://atproto.com/specs/at-uri-scheme

Summary

Functions

Create and validate an AtURI struct.

Same as new/3 but raises on invalid inputs.

Parse an at-uri string into an AtURI struct and validate against the spec.

Turns an AtURI struct into a proper at-uri string.

Types

t()

@type t() :: %Latch.AtURI{
  authority: String.t(),
  collection: String.t() | nil,
  rkey: String.t() | nil
}

Functions

new(authority, collection \\ nil, rkey \\ nil)

@spec new(String.t(), String.t() | nil, String.t() | nil) ::
  {:ok, t()}
  | {:error,
     :invalid_authority
     | :invalid_collection
     | :invalid_rkey
     | :missing_collection}

Create and validate an AtURI struct.

Examples

iex> Latch.AtURI.new("did:plc:bvraa6gajy4tfr3eh2sisdkr", "site.standard.publication", "3mope7jyypk22")
{:ok, %Latch.AtURI{authority: "did:plc:bvraa6gajy4tfr3eh2sisdkr", collection: "site.standard.publication", rkey: "3mope7jyypk22"}}

new!(authority, collection \\ nil, rkey \\ nil)

@spec new!(String.t(), String.t() | nil, String.t() | nil) :: t()

Same as new/3 but raises on invalid inputs.

Examples

iex> Latch.AtURI.new!("did:plc:bvraa6gajy4tfr3eh2sisdkr", "site.standard.publication", "3mope7jyypk22")
%Latch.AtURI{authority: "did:plc:bvraa6gajy4tfr3eh2sisdkr", collection: "site.standard.publication", rkey: "3mope7jyypk22"}

parse(arg1)

@spec parse(String.t()) ::
  {:ok, t()}
  | {:error,
     :invalid_structure
     | :invalid_scheme
     | :invalid_authority
     | :invalid_collection
     | :invalid_rkey}

Parse an at-uri string into an AtURI struct and validate against the spec.

Examples

iex> Latch.AtURI.parse("at://did:plc:ewvi7nxzyoun6zhxrhs64oiz/app.bsky.feed.post/3k2u5kbfqzf2k")
{:ok, %Latch.AtURI{authority: "did:plc:ewvi7nxzyoun6zhxrhs64oiz", collection: "app.bsky.feed.post", rkey: "3k2u5kbfqzf2k"}}

to_string(at_uri)

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

Turns an AtURI struct into a proper at-uri string.

Examples

iex> at_uri = Latch.AtURI.new!("did:plc:bvraa6gajy4tfr3eh2sisdkr", "site.standard.publication", "3mope7jyypk22")
iex> Latch.AtURI.to_string(at_uri)
"at://did:plc:bvraa6gajy4tfr3eh2sisdkr/site.standard.publication/3mope7jyypk22"