Alternative ATProto PDS implementation

prototype actor_store

+5 -6
src/actor_store/actor_store_reader.rs
··· 3 3 4 4 use super::{ 5 5 ActorStoreTransactor, actor_store_resources::ActorStoreResources, db::ActorDb, 6 - preference::PreferenceReader, record::RecordReader, 6 + preference::PreferenceReader, record::RecordReader, repo::RepoReader, 7 7 }; 8 8 use crate::SigningKey; 9 9 ··· 15 15 pub(crate) record: RecordReader, 16 16 /// Preference reader. 17 17 pub(crate) pref: PreferenceReader, 18 - /// RepoReader placeholder - will be implemented later. 19 - pub(crate) repo: (), // Placeholder for RepoReader 18 + /// RepoReader 19 + pub(crate) repo: RepoReader, 20 20 /// Function to get keypair. 21 21 keypair_fn: Box<dyn Fn() -> Result<Arc<SigningKey>> + Send + Sync>, 22 22 /// Database connection. ··· 43 43 // Initial keypair call as in TypeScript implementation 44 44 let _ = keypair_fn(); 45 45 46 - // For now, we use a placeholder for RepoReader 47 - // Real implementation will need to be added later 48 - let repo = (); 46 + // Create repo reader 47 + let repo = RepoReader::new(db.clone(), resources.blobstore(did.clone())); 49 48 50 49 Self { 51 50 did,
+8 -1
src/actor_store/actor_store_transactor.rs
··· 34 34 35 35 let record = RecordTransactor::new(db.clone(), blobstore.clone()); 36 36 let pref = PreferenceTransactor::new(db.clone()); 37 - let repo = RepoTransactor::new(db, blobstore, did, keypair, resources.background_queue); 37 + let repo = RepoTransactor::new( 38 + db, 39 + blobstore, 40 + did, 41 + keypair, 42 + resources.background_queue, 43 + None, 44 + ); 38 45 39 46 Self { record, repo, pref } 40 47 }
+1 -1
src/actor_store/actor_store_writer.rs
··· 1 1 use std::sync::Arc; 2 2 3 - use super::resources::ActorStoreResources; 3 + use super::{ActorDb, ActorStoreResources}; 4 4 use crate::SigningKey; 5 5 6 6 pub(crate) struct ActorStoreWriter {
+4
src/actor_store/blob/mod.rs
··· 2 2 3 3 mod background; 4 4 mod reader; 5 + mod store; 5 6 mod transactor; 6 7 7 8 pub(crate) use background::BackgroundQueue; 8 9 pub(crate) use reader::BlobReader; 10 + pub(crate) use store::BlobStore; 11 + pub(crate) use store::BlobStorePlaceholder; 12 + pub(crate) use store::BlobStream; 9 13 pub(crate) use transactor::BlobTransactor;
+5 -22
src/actor_store/blob/reader.rs
··· 7 7 use atrium_repo::Cid; 8 8 use sqlx::Row; 9 9 10 - use crate::{ 11 - actor_store::ActorDb, 12 - repo::types::{BlobStore, BlobStoreTrait, BlobStream}, 13 - }; 10 + use crate::actor_store::ActorDb; 11 + 12 + use super::{BlobStore, BlobStorePlaceholder, BlobStream}; 14 13 15 14 /// Reader for blob data in the actor store. 16 15 pub(crate) struct BlobReader { 17 16 /// Database connection. 18 17 pub db: ActorDb, 19 18 /// BlobStore. 20 - pub blobstore: BlobStore, 19 + pub blobstore: BlobStorePlaceholder, 21 20 } 22 21 23 22 impl BlobReader { 24 23 /// Create a new blob reader. 25 - pub(crate) fn new(db: ActorDb, blobstore: BlobStore) -> Self { 24 + pub(crate) fn new(db: ActorDb, blobstore: BlobStorePlaceholder) -> Self { 26 25 Self { db, blobstore } 27 26 } 28 27 ··· 94 93 &self, 95 94 cid: &Cid, 96 95 ) -> Result<Option<StatusAttrData>> { 97 - // const res = await this.db.db 98 - // .selectFrom('blob') 99 - // .select('takedownRef') 100 - // .where('cid', '=', cid.toString()) 101 - // .executeTakeFirst() 102 - // if (!res) return null 103 - // return res.takedownRef 104 - // ? { applied: true, ref: res.takedownRef } 105 - // : { applied: false } 106 96 let cid_str = cid.to_string(); 107 97 let result = sqlx::query!(r#"SELECT takedownRef FROM blob WHERE cid = ?"#, cid_str) 108 98 .fetch_optional(&self.db.pool) ··· 145 135 146 136 /// Get blobs referenced by a record. 147 137 pub(crate) async fn get_blobs_for_record(&self, record_uri: &str) -> Result<Vec<String>> { 148 - // const res = await this.db.db 149 - // .selectFrom('blob') 150 - // .innerJoin('record_blob', 'record_blob.blobCid', 'blob.cid') 151 - // .where('recordUri', '=', recordUri) 152 - // .select('blob.cid') 153 - // .execute() 154 - // return res.map((row) => row.cid) 155 138 let blobs = sqlx::query!( 156 139 r#"SELECT blob.cid FROM blob INNER JOIN record_blob ON record_blob.blobCid = blob.cid WHERE recordUri = ?"#, 157 140 record_uri
+3 -8
src/actor_store/blob/transactor.rs
··· 8 8 use atrium_repo::Cid; 9 9 use futures::FutureExt; 10 10 use futures::future::BoxFuture; 11 + use rsky_repo::types::{PreparedBlobRef, WriteOpAction}; 11 12 use uuid::Uuid; 12 13 13 - use super::{BackgroundQueue, BlobReader}; 14 - use crate::{ 15 - actor_store::ActorDb, 16 - repo::{ 17 - block_map::sha256_raw_to_cid, 18 - types::{BlobStore, BlobStoreTrait as _, PreparedBlobRef, PreparedWrite, WriteOpAction}, 19 - }, 20 - }; 14 + use super::{BackgroundQueue, BlobReader, BlobStore}; 15 + use crate::actor_store::{ActorDb, PreparedWrite, blob::BlobStore as _}; 21 16 22 17 /// Blob metadata for a newly uploaded blob. 23 18 #[derive(Debug, Clone)]
+2
src/actor_store/mod.rs
··· 8 8 mod blob; 9 9 mod db; 10 10 mod preference; 11 + mod prepared_write; 11 12 mod record; 12 13 mod repo; 13 14 ··· 17 18 pub(crate) use actor_store_transactor::ActorStoreTransactor; 18 19 pub(crate) use actor_store_writer::ActorStoreWriter; 19 20 pub(crate) use db::ActorDb; 21 + pub(crate) use prepared_write::PreparedWrite;
+1
src/actor_store/repo/reader.rs
··· 2 2 3 3 use anyhow::Result; 4 4 use atrium_repo::Cid; 5 + use rsky_repo::storage::readable_blockstore::ReadableBlockstore as _; 5 6 6 7 use super::sql_repo_reader::SqlRepoReader; 7 8 use crate::{
-1
src/main.rs
··· 11 11 mod mmap; 12 12 mod oauth; 13 13 mod plc; 14 - mod repo; 15 14 mod storage; 16 15 #[cfg(test)] 17 16 mod tests;