Repository

Struct Repository 

Source
pub struct Repository<S> { /* private fields */ }
Expand description

An ATProtocol user repository.

This is a convenience data structure that is cheap to construct and intended to be used in an on-demand manner rather than as a long-lived data structure.

For example, to open an existing repository and query a single record:

// N.B: This will not verify the contents of the repository, so this should only
// be used with data from a trusted source.
let mut repo = Repository::open(&mut bs, root).await.unwrap();
let post = repo.get::<bsky::feed::Post>(rkey).await.unwrap();

drop(repo); // We're done using the repository at this point.

Reference: https://atproto.com/specs/repository

Implementations§

Source§

impl<R: AsyncBlockStoreRead> Repository<R>

Source

pub async fn open(db: R, root: Cid) -> Result<Self, Error>

Open a pre-existing instance of a user repository. This is a cheap operation that simply reads out the root commit from a repository (without verifying its signature!)

Source

pub fn root(&self) -> Cid

Returns the current root cid.

Source

pub fn commit(&self) -> Commit

Returns the latest commit in the repository.

Source

pub fn tree(&mut self) -> Tree<&mut R>

Open the merkle search tree for the latest commit.

This API is for advanced usage. Typically you will want to use the convenience APIs offered by this struct instead. Any modifications to the tree will not automatically be reflected by this Repository.

Source

pub async fn get<C: Collection>( &mut self, rkey: RecordKey, ) -> Result<Option<C::Record>, Error>

Returns the specified record from the repository, or None if it does not exist.

Source

pub async fn get_raw<T: DeserializeOwned>( &mut self, key: &str, ) -> Result<Option<T>, Error>

Returns the contents of the specified record from the repository, or None if it does not exist.

Source

pub async fn get_raw_cid<T: DeserializeOwned>( &mut self, cid: Cid, ) -> Result<Option<T>, Error>

Returns the contents of a specified record from the repository, or None if it does not exist.

Caution: This is a potentially expensive operation that will iterate through the entire MST. This is done for security reasons; a particular CID cannot be proven to originate from this repository if it is not present in the MST.

Typically if you have a record’s CID, you should also have its key (e.g. from a firehose commit). If you have the key, you should always prefer to use Repository::get_raw as it is both much faster and secure.

If you’re absolutely certain you want to look up a record by its CID and the repository comes from a trusted source, you can elide the enumeration by accessing the backing storage directly.

Source

pub async fn export(&mut self) -> Result<impl Iterator<Item = Cid>, Error>

Export a list of all CIDs in the repository.

Source

pub async fn export_into( &mut self, bs: impl AsyncBlockStoreWrite, ) -> Result<(), Error>

Export all CIDs in the repository into a blockstore.

Source

pub async fn extract<C: Collection>( &mut self, rkey: RecordKey, ) -> Result<impl Iterator<Item = Cid>, Error>

Extract the CIDs associated with a particular record.

If the record does not exist in this repository, the CIDs returned will point to the node in the merkle search tree that would’ve contained the record.

This can be used to collect the blocks needed to broadcast a record out on the firehose, for example.

Source

pub async fn extract_into<C: Collection>( &mut self, rkey: RecordKey, bs: impl AsyncBlockStoreWrite, ) -> Result<(), Error>

Extract the CIDs associated with a particular record into a blockstore.

Source

pub async fn extract_raw( &mut self, key: &str, ) -> Result<impl Iterator<Item = Cid>, Error>

Extract the CIDs associated with a particular record.

Source

pub async fn extract_raw_into( &mut self, key: &str, bs: impl AsyncBlockStoreWrite, ) -> Result<(), Error>

Extract the CIDs associated with a particular record into a blockstore.

Source§

impl<S: AsyncBlockStoreRead + AsyncBlockStoreWrite> Repository<S>

Source

pub async fn create(db: S, did: Did) -> Result<RepoBuilder<S>, Error>

Build a new user repository.

Source

pub async fn add<C: Collection>( &mut self, rkey: RecordKey, record: C::Record, ) -> Result<(CommitBuilder<'_, S>, Cid), Error>

Add a new record to this repository.

Source

pub async fn add_raw<'a, T: Serialize>( &'a mut self, key: &str, data: T, ) -> Result<(CommitBuilder<'a, S>, Cid), Error>

Add a new raw record to this repository.

Source

pub async fn update<C: Collection>( &mut self, rkey: RecordKey, record: C::Record, ) -> Result<(CommitBuilder<'_, S>, Cid), Error>

Update an existing record in the repository.

Source

pub async fn update_raw<'a, T: Serialize>( &'a mut self, key: &str, data: T, ) -> Result<(CommitBuilder<'a, S>, Cid), Error>

Update an existing record in the repository with raw data.

Source

pub async fn delete<C: Collection>( &mut self, rkey: RecordKey, ) -> Result<CommitBuilder<'_, S>, Error>

Delete an existing record in the repository.

Source

pub async fn delete_raw<'a>( &'a mut self, key: &str, ) -> Result<CommitBuilder<'a, S>, Error>

Delete an existing record in the repository.

Trait Implementations§

Source§

impl<S: Debug> Debug for Repository<S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Repository<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Repository<S>
where S: RefUnwindSafe,

§

impl<S> Send for Repository<S>
where S: Send,

§

impl<S> Sync for Repository<S>
where S: Sync,

§

impl<S> Unpin for Repository<S>
where S: Unpin,

§

impl<S> UnwindSafe for Repository<S>
where S: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.