Latch. AtURI
(latch v0.4.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)
Summary
Types
Functions
@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"}}
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"}
@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"}}
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"