Skip to main content

Crate didbot_schema

Crate didbot_schema 

Source
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 format keyword 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 $type that 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.
IntegerSchema
An integer schema and everything that constrains it.
InvalidRecord
Why a record does not satisfy its lexicon.
Method
A query, procedure, subscription or permission-set definition.
ObjectSchema
An object schema: its properties and which of them are required or nullable.
StringSchema
A string schema and everything that constrains it.

Enums§

Def
One definition in a document.
MethodOutput
What checking a body against a method’s declared schema found.
Schema
One schema node.
SchemaError
Why a lexicon document could not be turned into a schema tree.
ShapeError
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 defs as main.

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 ref into 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.