The com.atproto.lexicon.schema record type: publishing lexicons as
atproto records.
A lexicon document is stored in the com.atproto.lexicon.schema
collection with the lexicon's NSID as the record key, giving it the
AT-URI at://<did>/com.atproto.lexicon.schema/<nsid>.
This module wraps the document in a struct and validates it against the
meta-rules lexicons must follow (beyond the per-node checks
Lexicon.Parser already performs): lexicon version 1, an NSID id
with no fragment, at most one primary definition per file, record defs
carrying a key, and refs not pointing at refs/unions/tokens.
Examples
{:ok, schema} = Exosphere.Lexicon.Schema.new(%{
"lexicon" => 1,
"id" => "com.example.post",
"defs" => %{
"main" => %{
"type" => "record",
"key" => "tid",
"record" => %{
"type" => "object",
"properties" => %{"text" => %{"type" => "string"}}
}
}
}
})
schema.record_key
#=> "com.example.post"
Exosphere.Lexicon.publish(session, pds_url, did, schema)
Summary
Functions
The collection NSID lexicon records live in.
Decode a fetched com.atproto.lexicon.schema record value (the "value"
of a com.atproto.repo.getRecord response).
Build a Lexicon.Schema from a lexicon document map (string or atom
keys), validating it against the lexicon meta-rules.
The record key for this schema: the lexicon NSID itself.
Encode to the wire record map, including $type.
Validate a raw lexicon document against the lexicon meta-rules.
Types
@type t() :: %Exosphere.Lexicon.Schema{ defs: %{optional(String.t()) => map()}, description: String.t() | nil, id: String.t(), lexicon: 1, parsed: Exosphere.Lexicon.Parser.lexicon() | nil }
Functions
@spec collection() :: String.t()
The collection NSID lexicon records live in.
Decode a fetched com.atproto.lexicon.schema record value (the "value"
of a com.atproto.repo.getRecord response).
Build a Lexicon.Schema from a lexicon document map (string or atom
keys), validating it against the lexicon meta-rules.
Returns {:ok, schema} or {:error, [{path, message}]}.
The record key for this schema: the lexicon NSID itself.
Encode to the wire record map, including $type.
Validate a raw lexicon document against the lexicon meta-rules.
Lexicon.Parser checks the per-node structure (types, record shape,
union refs); this adds the document-level rules: one primary def per
lexicon, record defs require a key, refs never target refs/unions/
tokens, and id must be a simple NSID. Returns a list of
{path, message} errors (empty when valid).