Atex.Lexicon.Resolver (atex v0.9.1)

View Source

Resolves published AT Protocol Lexicon schemas by NSID.

Implements the Lexicon publication and resolution specification, which uses DNS TXT records to locate the atproto repository that hosts a given NSID's schema, then fetches the record directly from the repository's PDS.

Per the specification, DNS resolution is not hierarchical: if the TXT record for the exact authority domain is not found, resolution fails immediately without traversing the DNS hierarchy.

Error returns

resolve/1 returns {:error, reason} on failure. Possible reasons:

  • :invalid_nsid - the given string is not a valid NSID.
  • :dns_resolution_failed - no valid did=<did> TXT record was found for the authority domain.
  • :did_resolution_failed - the DID from DNS could not be resolved to a DID document.
  • :no_pds_endpoint - the DID document does not contain a valid PDS service endpoint.
  • :record_not_found - the PDS has no lexicon record for the given NSID.
  • :invalid_record - the PDS returned a response that could not be interpreted as a lexicon record.
  • Any transport-level error from Req.

Summary

Functions

Resolves the lexicon schema for the given NSID.

Functions

resolve(nsid)

@spec resolve(String.t()) ::
  {:ok, map()}
  | {:error,
     :invalid_nsid
     | :dns_resolution_failed
     | :did_resolution_failed
     | :no_pds_endpoint
     | :record_not_found
     | :invalid_record
     | any()}

Resolves the lexicon schema for the given NSID.

Performs DNS-based authority lookup followed by an atproto record fetch to retrieve the raw lexicon JSON map.

Parameters

  • nsid - A valid AT Protocol NSID string.

Examples

iex> Atex.Lexicon.Resolver.resolve("app.bsky.feed.post")
{:ok, %{"lexicon" => 1, "id" => "app.bsky.feed.post", "defs" => %{...}}}

iex> Atex.Lexicon.Resolver.resolve("not.valid!")
{:error, :invalid_nsid}