Skip to main content

Catalog

Struct Catalog 

Source
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

Source

pub fn new() -> Self

An empty catalog.

Source

pub fn insert(&mut self, doc: &LexiconDoc) -> Result<(), SchemaError>

Adds one parsed lexicon document.

Source

pub fn from_documents<'a>( docs: impl IntoIterator<Item = &'a LexiconDoc>, ) -> Result<Self, SchemaError>

Builds a catalog from parsed documents.

Source

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.

Source

pub fn defines_record(&self, collection: &str) -> bool

Whether this catalog holds a record definition for a collection.

Source

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.

Source

pub fn lookup(&self, document: &str, name: &str) -> Option<&Def>

One definition, by document id and definition name.

Source

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.

Source

pub fn record_collections(&self) -> Vec<&str>

Every collection this catalog defines a record for.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Catalog

Source§

fn clone(&self) -> Catalog

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Catalog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Catalog

Source§

fn default() -> Catalog

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more