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>
impl<R: AsyncBlockStoreRead> Repository<R>
Sourcepub async fn open(db: R, root: Cid) -> Result<Self, Error>
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!)
Sourcepub fn tree(&mut self) -> Tree<&mut R>
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.
Sourcepub async fn get<C: Collection>(
&mut self,
rkey: RecordKey,
) -> Result<Option<C::Record>, Error>
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.
Sourcepub async fn get_raw<T: DeserializeOwned>(
&mut self,
key: &str,
) -> Result<Option<T>, Error>
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.
Sourcepub async fn get_raw_cid<T: DeserializeOwned>(
&mut self,
cid: Cid,
) -> Result<Option<T>, Error>
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.
Sourcepub async fn export(&mut self) -> Result<impl Iterator<Item = Cid>, Error>
pub async fn export(&mut self) -> Result<impl Iterator<Item = Cid>, Error>
Export a list of all CIDs in the repository.
Sourcepub async fn export_into(
&mut self,
bs: impl AsyncBlockStoreWrite,
) -> Result<(), Error>
pub async fn export_into( &mut self, bs: impl AsyncBlockStoreWrite, ) -> Result<(), Error>
Export all CIDs in the repository into a blockstore.
Sourcepub async fn extract<C: Collection>(
&mut self,
rkey: RecordKey,
) -> Result<impl Iterator<Item = Cid>, Error>
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.
Sourcepub async fn extract_into<C: Collection>(
&mut self,
rkey: RecordKey,
bs: impl AsyncBlockStoreWrite,
) -> Result<(), Error>
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.
Sourcepub async fn extract_raw(
&mut self,
key: &str,
) -> Result<impl Iterator<Item = Cid>, Error>
pub async fn extract_raw( &mut self, key: &str, ) -> Result<impl Iterator<Item = Cid>, Error>
Extract the CIDs associated with a particular record.
Sourcepub async fn extract_raw_into(
&mut self,
key: &str,
bs: impl AsyncBlockStoreWrite,
) -> Result<(), Error>
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>
impl<S: AsyncBlockStoreRead + AsyncBlockStoreWrite> Repository<S>
Sourcepub async fn create(db: S, did: Did) -> Result<RepoBuilder<S>, Error>
pub async fn create(db: S, did: Did) -> Result<RepoBuilder<S>, Error>
Build a new user repository.
Sourcepub async fn add<C: Collection>(
&mut self,
rkey: RecordKey,
record: C::Record,
) -> Result<(CommitBuilder<'_, S>, Cid), Error>
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.
Sourcepub async fn add_raw<'a, T: Serialize>(
&'a mut self,
key: &str,
data: T,
) -> Result<(CommitBuilder<'a, S>, Cid), Error>
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.
Sourcepub async fn update<C: Collection>(
&mut self,
rkey: RecordKey,
record: C::Record,
) -> Result<(CommitBuilder<'_, S>, Cid), Error>
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.
Sourcepub async fn update_raw<'a, T: Serialize>(
&'a mut self,
key: &str,
data: T,
) -> Result<(CommitBuilder<'a, S>, Cid), Error>
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.
Sourcepub async fn delete<C: Collection>(
&mut self,
rkey: RecordKey,
) -> Result<CommitBuilder<'_, S>, Error>
pub async fn delete<C: Collection>( &mut self, rkey: RecordKey, ) -> Result<CommitBuilder<'_, S>, Error>
Delete an existing record in the repository.
Sourcepub async fn delete_raw<'a>(
&'a mut self,
key: &str,
) -> Result<CommitBuilder<'a, S>, Error>
pub async fn delete_raw<'a>( &'a mut self, key: &str, ) -> Result<CommitBuilder<'a, S>, Error>
Delete an existing record in the repository.