pub struct Catalog {
pub(crate) documents: BTreeMap<String, BTreeMap<String, Def>>,
}Expand description
A set of lexicon documents that can resolve refs between themselves.
Fields§
§documents: BTreeMap<String, BTreeMap<String, Def>>Implementations§
Source§impl Catalog
impl Catalog
Sourcepub fn insert(&mut self, doc: &LexiconDoc) -> Result<(), SchemaError>
pub fn insert(&mut self, doc: &LexiconDoc) -> Result<(), SchemaError>
Adds one parsed lexicon document.
Sourcepub fn from_documents<'a>(
docs: impl IntoIterator<Item = &'a LexiconDoc>,
) -> Result<Self, SchemaError>
pub fn from_documents<'a>( docs: impl IntoIterator<Item = &'a LexiconDoc>, ) -> Result<Self, SchemaError>
Builds a catalog from parsed documents.
Sourcepub fn embedded() -> &'static Self
pub fn embedded() -> &'static Self
The catalog of the documents this deployment embeds.
Built once and shared. Failure is a defect in a document this binary
was compiled from, so it is reported as an empty catalog rather than
panicking at an arbitrary first write; the unit tests in this module
and in didbot-lexicon are what actually catch it.
Sourcepub fn defines_record(&self, collection: &str) -> bool
pub fn defines_record(&self, collection: &str) -> bool
Whether this catalog holds a record definition for a collection.
Sourcepub fn record_key(&self, collection: &str) -> Option<&str>
pub fn record_key(&self, collection: &str) -> Option<&str>
The record key strategy a collection’s main definition declares.
None when this catalog has no record definition for the collection.
The string is returned exactly as the document wrote it, because
deciding which strategies are supported belongs to the store that has
to honour them; see didbot-pds’s records::resolve_key.
Sourcepub fn lookup(&self, document: &str, name: &str) -> Option<&Def>
pub fn lookup(&self, document: &str, name: &str) -> Option<&Def>
One definition, by document id and definition name.
Sourcepub fn resolve(&self, from: &str, reference: &str) -> Option<(String, &Def)>
pub fn resolve(&self, from: &str, reference: &str) -> Option<(String, &Def)>
Resolves a ref string written inside from.
Three forms, all of them in the specification: #name is local to the
document doing the referring, nsid#name names a definition in
another, and a bare nsid names that document’s main.
Sourcepub fn record_collections(&self) -> Vec<&str>
pub fn record_collections(&self) -> Vec<&str>
Every collection this catalog defines a record for.
Sourcepub fn method(&self, nsid: &str) -> Option<&Method>
pub fn method(&self, nsid: &str) -> Option<&Method>
One method definition, by NSID.
None when this catalog holds no such document, or when the
document’s main is a record rather than a method.
Sourcepub fn validate_output(&self, nsid: &str, body: &Value) -> MethodOutput
pub fn validate_output(&self, nsid: &str, body: &Value) -> MethodOutput
Checks a JSON response body against the output schema nsid declares.
The whole reason this exists: a response is a value with a schema, the schema is written down in a document somebody else maintains, and a server that checks its own output against a struct it wrote from reading that document is checking its reading rather than the document.
MethodOutput::Unchecked is not a pass. It says the document
declares no JSON schema for this method’s response — a CAR file, a
blob — and a caller that wants coverage has to say what it checks
instead.
Sourcepub fn validate_input(&self, nsid: &str, body: &Value) -> MethodOutput
pub fn validate_input(&self, nsid: &str, body: &Value) -> MethodOutput
Checks a JSON request body against the input schema nsid declares.
The other direction, and it is worth checking too: a request this server’s own tests compose is one a client would have to be able to compose, so a fixture that quietly stopped satisfying the document would make every response checked against it prove nothing.
Sourcepub fn validate_record(
&self,
collection: &str,
record: &Value,
) -> Result<(), InvalidRecord>
pub fn validate_record( &self, collection: &str, record: &Value, ) -> Result<(), InvalidRecord>
Checks a record against the collection’s main record definition.
The collection must be one this catalog defines; see
validate_with, which is what decides that a record arriving over
the wire has a schema at all.