atproto_lexicon/source
Lexicon source specs and network resolution.
A Spec names where a lexicon (or a family of lexicons) comes from:
a local file glob, an exact NSID, an NSID wildcard prefix, or a direct
at-uri. resolve walks the NSID/at-uri resolution chain described in
at-record’s ROADMAP (“codegen: official-method client generation”):
NSID authority -> DNS _lexicon.<domain> TXT (via DoH) -> DID -> PDS
-> com.atproto.lexicon.schema record(s).
Every network call goes through one injected Send function, mirroring
atproto_client’s transport-agnostic Client without depending on that
package: this one stays standalone. LocalGlob specs are not resolved
here at all (no filesystem access in this module); a caller resolving a
local-glob spec does so itself and never calls resolve for it.
Types
One resolved lexicon schema: the NSID it was fetched for, the DID whose repo it lives in, the record’s content CID (for pin provenance), and the schema itself, already validated by an AST decode/encode round trip.
pub type FetchedRecord {
FetchedRecord(
nsid: String,
did: String,
cid: String,
doc: ast.LexiconDoc,
)
}
Constructors
-
FetchedRecord( nsid: String, did: String, cid: String, doc: ast.LexiconDoc, )
pub type NetworkConfig {
NetworkConfig(doh_endpoint: String, plc_directory: String)
}
Constructors
-
NetworkConfig(doh_endpoint: String, plc_directory: String)
pub type ResolveError {
LocalSpecUnsupported(pattern: String)
TransportFailed(reason: String)
BadStatus(status: Int, body: String)
DecodeFailed(reason: String)
InvalidNsid(nsid: String)
InvalidAtUri(raw: String)
AuthorityNotPublished(domain: String)
UnsupportedDidMethod(did: String)
PdsEndpointMissing(did: String)
SchemaInvalid(nsid: String, errors: List(decoding.DecodeError))
SchemaRoundTripMismatch(nsid: String)
}
Constructors
-
LocalSpecUnsupported(pattern: String)resolveonly handles the network-resolvable spec kinds; aLocalGlobspec has nothing to resolve over the network. -
TransportFailed(reason: String) -
BadStatus(status: Int, body: String) -
DecodeFailed(reason: String) -
InvalidNsid(nsid: String) -
InvalidAtUri(raw: String) -
AuthorityNotPublished(domain: String)No usable
_lexicon.<domain>TXT record: either the DNS answer was missing/empty, or present but carried no parseabledid=value. Both mean the same thing to a caller: fall back to the local tier. This is the expected, non-exceptional outcome forcom.atproto.*today (see the ROADMAP coverage caveat). -
UnsupportedDidMethod(did: String) -
PdsEndpointMissing(did: String) -
SchemaInvalid(nsid: String, errors: List(decoding.DecodeError))The fetched record’s
valuefailed to decode as a lexicon document. -
SchemaRoundTripMismatch(nsid: String)The document decoded, but re-encoding it did not reproduce the original JSON: the AST lost fidelity on this schema.
The injectable transport: one function from a bit-array request to a bit-array response (or a transport-level error string). Callers choose the backend (erlang httpc, JS fetch, a test stub).
pub type Send =
fn(request.Request(BitArray)) -> Result(
response.Response(BitArray),
String,
)
pub type Spec {
LocalGlob(pattern: String)
NsidExact(nsid: String)
NsidWildcard(prefix: String)
AtUri(uri: String)
}
Constructors
-
LocalGlob(pattern: String) -
NsidExact(nsid: String) -
NsidWildcard(prefix: String) -
AtUri(uri: String)
pub type SpecError {
EmptySpec
}
Constructors
-
EmptySpec
Values
pub const default_doh_endpoint: String
pub fn default_network_config() -> NetworkConfig
pub const default_plc_directory: String
pub fn describe(error: ResolveError) -> String
pub fn parse_at_uri(
raw: String,
) -> Result(#(String, String, String), ResolveError)
at://<did>/<collection>/<rkey>, exposed for callers (the pinned cache
needs the rkey/nsid out of an AtUri spec offline, without resolving).
pub fn parse_spec(input: String) -> Result(Spec, SpecError)
Parse the string forms: at://... -> AtUri, <nsid-authority>.* ->
NsidWildcard (trailing .* only), a bare valid NSID -> NsidExact,
anything else (a path, a **/* glob, a bare filename) -> LocalGlob.
The only rejected input is empty/whitespace-only text: everything else
has a spec it can degrade to.
pub fn resolve(
send: fn(request.Request(BitArray)) -> Result(
response.Response(BitArray),
String,
),
spec: Spec,
network: NetworkConfig,
) -> Result(List(FetchedRecord), ResolveError)
Resolve a spec to its schema(s). LocalGlob specs are rejected: this
module never touches the filesystem.