Expand description
Lexicon schemas, as a typed tree a record can be checked against, and the identifiers and string formats the check reads.
didbot-lexicon embeds the documents and checks that they are well
formed. Validating a record also needs the identifier validators — DIDs,
handles, TIDs, record keys, at:// URIs — so the schema model lives here,
beside them. It builds for wasm32-unknown-unknown, so a browser checks a
record with the same code the store runs; validate_with is the whole
of what a write’s shape must satisfy.
§What this covers
The Lexicon specification’s type system: object, array, string, integer,
boolean, bytes, cid-link, blob, unknown, ref, union, and every constraint
those carry. Method and MethodOutput carry a query’s or
procedure’s own parameters, input and output on top of that, so
Catalog::validate_input and Catalog::validate_output check an
XRPC body the same way validate_with checks a record.
§Unrecognised things are carried, not refused
Two rules, both from the specification, both about forward compatibility,
and both easy to get backwards. An object property no schema declares is
preserved rather than rejected — a client written against a newer
version of a lexicon must be able to write through an older server without
silently losing fields. And a type this build has never heard of parses
to Schema::Unrecognised and accepts anything, for the same reason
crate::format::StringFormat::parse shrugs at an unknown format: the
Lexicon language grows, and a server that treated growth as corruption
would break on a schema change it did not author.
knownValues is likewise advisory and never enforced. It is the
specification’s way of writing down an open set — the exact opposite of
enum, which is closed and is enforced.
Re-exports§
pub use aturi::AtUri;pub use aturi::AtUriError;pub use record_key::validate_record_key;pub use record_key::RecordKeyError;pub use record_key::MAX_RECORD_KEY_LENGTH;
Modules§
- aturi
at://URIs: the names records answer to.- check 🔒
- Checking one JSON value against one
Schema. - format
- The string formats a Lexicon
formatkeyword can name. - record_
key - Record keys: the last segment of an
at://URI, and the name a record is stored under in its collection. - shape 🔒
- The shape rules a record meets before it is stored: a collection that
could name a lexicon, a
$typethat agrees with it, a body the atproto data model can encode, and the lexicon itself when one is held. - tid
- Timestamp identifiers: the sortable keys this server mints records under.
Structs§
- Catalog
- A set of lexicon documents that can resolve refs between themselves.
- Integer
Schema - An integer schema and everything that constrains it.
- Invalid
Record - Why a record does not satisfy its lexicon.
- Method
- A
query,procedure,subscriptionorpermission-setdefinition. - Object
Schema - An object schema: its properties and which of them are required or nullable.
- String
Schema - A string schema and everything that constrains it.
Enums§
- Def
- One definition in a document.
- Method
Output - What checking a body against a method’s declared schema found.
- Schema
- One schema node.
- Schema
Error - Why a lexicon document could not be turned into a schema tree.
- Shape
Error - Why a record’s shape is refused.
- Stance
- Which of the specification’s three validation stances to take for one write.
Constants§
- FIELD_
ONLY_ 🔒TYPES - Types that are field types only, and are not definitions.
- MAX_
SCHEMA_ DEPTH - How deep a schema may nest before the walk gives up.
- PRIMARY_
TYPES 🔒 - Types that may only appear under
defsasmain.
Functions§
- integer 🔒
- Reads a keyword as a signed integer.
- parse_
def 🔒 - Parses one definition.
- parse_
method 🔒 - Parses a method definition’s schemas.
- parse_
object 🔒 - Parses the body of an object schema.
- parse_
schema 🔒 - Parses one schema node.
- schema_
is_ held - Whether this server holds a lexicon that defines
collection’s record. - size 🔒
- Reads a keyword as a non-negative size.
- split_
ref 🔒 - Splits a
refinto the document it names and the definition inside it. - strings 🔒
- Reads a keyword as a list of strings.
- validate_
collection - The first of
validate_with’s rules, on its own. - validate_
shape - The shape rules under the optimistic stance, which is the one this server takes when a caller says nothing. Authorship is not a property of the bytes, so no rule here is about who may write.
- validate_
with - Checks a record against the collection it is being written to.