diff --git a/radicle-cli/src/commands/id.rs b/radicle-cli/src/commands/id.rs index 2b70f293..9625cbdb 100644 --- a/radicle-cli/src/commands/id.rs +++ b/radicle-cli/src/commands/id.rs @@ -7,6 +7,7 @@ use anyhow::{anyhow, Context}; use radicle::cob::identity::{self, IdentityMut, Revision, RevisionId}; use radicle::identity::{doc, Doc, Identity, PayloadError, RawDoc, Visibility}; use radicle::node::device::Device; +use radicle::node::NodeId; use radicle::prelude::{Did, RepoId}; use radicle::storage::refs; use radicle::storage::{ReadRepository, ReadStorage as _, WriteRepository}; @@ -731,7 +732,7 @@ fn update( signer: &Device, ) -> anyhow::Result where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, G: crypto::signature::Signer, { if let Some((title, description)) = edit_title_description(title, description)? { diff --git a/radicle-cli/src/commands/inbox.rs b/radicle-cli/src/commands/inbox.rs index 8edfcb60..4b91adec 100644 --- a/radicle-cli/src/commands/inbox.rs +++ b/radicle-cli/src/commands/inbox.rs @@ -12,7 +12,7 @@ use radicle::issue::cache::Issues as _; use radicle::node::notifications; use radicle::node::notifications::*; use radicle::patch::cache::Patches as _; -use radicle::prelude::{Profile, RepoId}; +use radicle::prelude::{NodeId, Profile, RepoId}; use radicle::storage::{BranchName, ReadRepository, ReadStorage}; use radicle::{cob, git, Storage}; @@ -261,7 +261,7 @@ fn list_repo<'a, R: ReadStorage>( profile: &Profile, ) -> anyhow::Result>> where - ::Repository: cob::Store, + ::Repository: cob::Store, { let mut table = term::Table::new(term::TableOptions { spacing: 3, diff --git a/radicle-cli/src/commands/issue.rs b/radicle-cli/src/commands/issue.rs index 9332ace7..4a853d19 100644 --- a/radicle-cli/src/commands/issue.rs +++ b/radicle-cli/src/commands/issue.rs @@ -13,6 +13,7 @@ use radicle::cob::{issue, thread}; use radicle::crypto; use radicle::issue::cache::Issues as _; use radicle::node::device::Device; +use radicle::node::NodeId; use radicle::prelude::{Did, RepoId}; use radicle::profile; use radicle::storage; @@ -815,7 +816,7 @@ fn open( profile: &Profile, ) -> anyhow::Result<()> where - R: ReadRepository + WriteRepository + cob::Store, + R: ReadRepository + WriteRepository + cob::Store, G: crypto::signature::Signer, { let (title, description) = if let (Some(t), Some(d)) = (title.as_ref(), description.as_ref()) { @@ -849,7 +850,7 @@ fn edit<'a, 'g, R, G>( signer: &Device, ) -> anyhow::Result> where - R: WriteRepository + ReadRepository + cob::Store, + R: WriteRepository + ReadRepository + cob::Store, G: crypto::signature::Signer, { let id = id.resolve(&repo.backend)?; @@ -891,7 +892,7 @@ where } /// Get a comment from the user, by prompting. -pub fn prompt_comment( +pub fn prompt_comment>( message: Message, reply_to: Option, issue: &issue::Issue, diff --git a/radicle-cli/src/commands/job.rs b/radicle-cli/src/commands/job.rs index ce6f1f7a..a8b36194 100644 --- a/radicle-cli/src/commands/job.rs +++ b/radicle-cli/src/commands/job.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, Context as _}; use radicle::cob::job::{JobStore, Reason, State}; use radicle::crypto; use radicle::node::device::Device; -use radicle::node::Handle; +use radicle::node::{Handle, NodeId}; use radicle::storage::{WriteRepository, WriteStorage}; use radicle::{cob, Node}; @@ -269,7 +269,7 @@ fn trigger( quiet: bool, ) -> anyhow::Result<()> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, G: crypto::signature::Signer, { let commit = commit.resolve(&repo.backend)?; @@ -289,7 +289,7 @@ fn start( signer: &Device, ) -> anyhow::Result<()> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, G: crypto::signature::Signer, { let job_id = job_id.resolve(&repo.backend)?; @@ -301,7 +301,9 @@ where } // TODO: This should use the COB cache for performance. -fn list(store: &JobStore) -> anyhow::Result<()> { +fn list>( + store: &JobStore, +) -> anyhow::Result<()> { if store.is_empty()? { term::print(term::format::italic("Nothing to show.")); return Ok(()); @@ -343,7 +345,7 @@ fn list(store: &JobStore) -> anyhow::Result< Ok(()) } -fn show( +fn show>( job_id: &Rev, store: &JobStore, repo: &radicle::storage::git::Repository, @@ -366,7 +368,7 @@ fn finish( signer: &Device, ) -> anyhow::Result<()> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, G: crypto::signature::Signer, { let job_id = job_id.resolve(&repo.backend)?; diff --git a/radicle-cli/src/terminal/cob.rs b/radicle-cli/src/terminal/cob.rs index ba628757..d43f932c 100644 --- a/radicle-cli/src/terminal/cob.rs +++ b/radicle-cli/src/terminal/cob.rs @@ -3,6 +3,7 @@ use radicle::{ self, cache::{MigrateCallback, MigrateProgress}, }, + prelude::NodeId, profile, storage::ReadRepository, Profile, @@ -61,7 +62,7 @@ pub fn patches<'a, R>( repository: &'a R, ) -> Result, cob::cache::StoreReader>, anyhow::Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { profile.patches(repository).map_err(with_hint) } @@ -72,7 +73,7 @@ pub fn patches_mut<'a, R>( repository: &'a R, ) -> Result, cob::cache::StoreWriter>, anyhow::Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { profile.patches_mut(repository).map_err(with_hint) } @@ -83,7 +84,7 @@ pub fn issues<'a, R>( repository: &'a R, ) -> Result, cob::cache::StoreReader>, anyhow::Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { profile.issues(repository).map_err(with_hint) } @@ -94,7 +95,7 @@ pub fn issues_mut<'a, R>( repository: &'a R, ) -> Result, cob::cache::StoreWriter>, anyhow::Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { profile.issues_mut(repository).map_err(with_hint) } diff --git a/radicle-cob/Cargo.toml b/radicle-cob/Cargo.toml index 97847c72..18bfcb63 100644 --- a/radicle-cob/Cargo.toml +++ b/radicle-cob/Cargo.toml @@ -55,4 +55,4 @@ qcheck-macros = { version = "1", default-features = false } [dev-dependencies.radicle-crypto] path = "../radicle-crypto" version = "0" -features = ["test"] +features = ["test", "radicle-git-ext"] diff --git a/radicle-cob/src/object/collaboration/create.rs b/radicle-cob/src/object/collaboration/create.rs index ce16d6d6..c2a2b5ea 100644 --- a/radicle-cob/src/object/collaboration/create.rs +++ b/radicle-cob/src/object/collaboration/create.rs @@ -1,7 +1,6 @@ // Copyright © 2022 The Radicle Link Contributors use nonempty::NonEmpty; -use radicle_crypto::PublicKey; use crate::Embed; use crate::Evaluate; @@ -58,7 +57,7 @@ pub fn create( signer: &G, resource: Option, related: Vec, - identifier: &PublicKey, + identifier: &S::Namespace, args: Create, ) -> Result, error::Create> where diff --git a/radicle-cob/src/object/collaboration/remove.rs b/radicle-cob/src/object/collaboration/remove.rs index 9bcbde69..0b0a798d 100644 --- a/radicle-cob/src/object/collaboration/remove.rs +++ b/radicle-cob/src/object/collaboration/remove.rs @@ -1,7 +1,5 @@ // Copyright © 2022 The Radicle Link Contributors -use radicle_crypto::PublicKey; - use crate::{ObjectId, Store, TypeName}; use super::error; @@ -17,7 +15,7 @@ use super::error; /// type. pub fn remove( storage: &S, - identifier: &PublicKey, + identifier: &S::Namespace, typename: &TypeName, oid: &ObjectId, ) -> Result<(), error::Remove> diff --git a/radicle-cob/src/object/collaboration/update.rs b/radicle-cob/src/object/collaboration/update.rs index 706197d5..3c6a7c43 100644 --- a/radicle-cob/src/object/collaboration/update.rs +++ b/radicle-cob/src/object/collaboration/update.rs @@ -3,7 +3,6 @@ use std::iter; use git_ext::Oid; use nonempty::NonEmpty; -use radicle_crypto::PublicKey; use crate::{ change, change_graph::ChangeGraph, history::EntryId, CollaborativeObject, Embed, Evaluate, @@ -61,7 +60,7 @@ pub fn update( signer: &G, resource: Option, related: Vec, - identifier: &PublicKey, + identifier: &S::Namespace, args: Update, ) -> Result, error::Update> where diff --git a/radicle-cob/src/object/storage.rs b/radicle-cob/src/object/storage.rs index c8a11928..6779f5a5 100644 --- a/radicle-cob/src/object/storage.rs +++ b/radicle-cob/src/object/storage.rs @@ -4,7 +4,6 @@ use std::{collections::BTreeMap, error::Error}; use git_ext::ref_format::RefString; use git_ext::Oid; -use radicle_crypto::PublicKey; use crate::change::EntryId; use crate::{ObjectId, TypeName}; @@ -59,6 +58,8 @@ pub trait Storage { type UpdateError: Error + Send + Sync + 'static; type RemoveError: Error + Send + Sync + 'static; + type Namespace; + /// Get all references which point to a head of the change graph for a /// particular object fn objects( @@ -74,7 +75,7 @@ pub trait Storage { /// Update a ref to a particular collaborative object fn update( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &TypeName, object_id: &ObjectId, entry: &EntryId, @@ -83,7 +84,7 @@ pub trait Storage { /// Remove a ref to a particular collaborative object fn remove( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &TypeName, object_id: &ObjectId, ) -> Result<(), Self::RemoveError>; diff --git a/radicle-cob/src/test/storage.rs b/radicle-cob/src/test/storage.rs index 10762309..887e131e 100644 --- a/radicle-cob/src/test/storage.rs +++ b/radicle-cob/src/test/storage.rs @@ -1,6 +1,6 @@ use std::{collections::BTreeMap, convert::TryFrom as _}; -use radicle_crypto::PublicKey; +use radicle_git_ext::ref_format::{refname, Component}; use tempfile::TempDir; use crate::{ @@ -105,6 +105,8 @@ impl object::Storage for Storage { type UpdateError = git2::Error; type RemoveError = git2::Error; + type Namespace = crypto::PublicKey; + fn objects( &self, typename: &crate::TypeName, @@ -148,12 +150,16 @@ impl object::Storage for Storage { fn update( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &crate::TypeName, object_id: &ObjectId, entry: &change::EntryId, ) -> Result<(), Self::UpdateError> { - let name = format!("refs/rad/{}/cobs/{}/{}", identifier, typename, object_id); + let name = refname!("refs/rad") + .join(Component::from(namespace)) + .join(refname!("cobs")) + .join::(typename.into()) + .join::(object_id.into()); self.raw .reference(&name, (*entry).into(), true, "new change")?; Ok(()) @@ -161,11 +167,15 @@ impl object::Storage for Storage { fn remove( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &crate::TypeName, object_id: &ObjectId, ) -> Result<(), Self::RemoveError> { - let name = format!("refs/rad/{}/cobs/{}/{}", identifier, typename, object_id); + let name = refname!("refs/rad") + .join(Component::from(namespace)) + .join(refname!("cobs")) + .join::(typename.into()) + .join::(object_id.into()); self.raw.find_reference(&name)?.delete()?; Ok(()) diff --git a/radicle-node/src/worker/fetch.rs b/radicle-node/src/worker/fetch.rs index bf9bb3bc..fa2df3bc 100644 --- a/radicle-node/src/worker/fetch.rs +++ b/radicle-node/src/worker/fetch.rs @@ -8,6 +8,7 @@ use localtime::LocalTime; use radicle::cob::TypedId; use radicle::crypto::PublicKey; use radicle::identity::DocAt; +use radicle::prelude::NodeId; use radicle::prelude::RepoId; use radicle::storage::refs::RefsAt; use radicle::storage::{ @@ -299,7 +300,7 @@ fn cache_cobs( cache: &mut C, ) -> Result<(), error::Cache> where - S: ReadRepository + cob::Store, + S: ReadRepository + cob::Store, C: cob::cache::Update + cob::cache::Update, C: cob::cache::Remove + cob::cache::Remove, { diff --git a/radicle-remote-helper/src/lib.rs b/radicle-remote-helper/src/lib.rs index 6c2d60a2..b24a4ed0 100644 --- a/radicle-remote-helper/src/lib.rs +++ b/radicle-remote-helper/src/lib.rs @@ -13,6 +13,7 @@ use std::{env, fmt, io}; use thiserror::Error; +use radicle::prelude::NodeId; use radicle::storage::git::transport::local::{Url, UrlError}; use radicle::storage::{ReadRepository, WriteStorage}; use radicle::{cob, profile}; @@ -262,7 +263,7 @@ pub(crate) fn warn(s: impl fmt::Display) { } /// Get the patch store. -pub(crate) fn patches<'a, R: ReadRepository + cob::Store>( +pub(crate) fn patches<'a, R: ReadRepository + cob::Store>( profile: &Profile, repo: &'a R, ) -> Result, cob::cache::StoreReader>, list::Error> { diff --git a/radicle-remote-helper/src/list.rs b/radicle-remote-helper/src/list.rs index e4713089..fef535d1 100644 --- a/radicle-remote-helper/src/list.rs +++ b/radicle-remote-helper/src/list.rs @@ -4,6 +4,7 @@ use thiserror::Error; use radicle::cob; use radicle::git; +use radicle::prelude::NodeId; use radicle::storage::git::transport::local::Url; use radicle::storage::ReadRepository; use radicle::Profile; @@ -34,7 +35,7 @@ pub enum Error { } /// List refs for fetching (`git fetch` and `git ls-remote`). -pub fn for_fetch( +pub fn for_fetch + 'static>( url: &Url, profile: &Profile, stored: &R, @@ -83,7 +84,7 @@ pub fn for_push(profile: &Profile, stored: &R) -> Result<(), } /// List canonical patch references. These are magic refs that can be used to pull patch updates. -fn patch_refs( +fn patch_refs + 'static>( profile: &Profile, stored: &R, ) -> Result<(), Error> { diff --git a/radicle/src/cob/identity.rs b/radicle/src/cob/identity.rs index 49f6090f..f3383c59 100644 --- a/radicle/src/cob/identity.rs +++ b/radicle/src/cob/identity.rs @@ -11,6 +11,7 @@ use thiserror::Error; use crate::identity::doc::Doc; use crate::node::device::Device; +use crate::node::NodeId; use crate::{ cob, cob::{ @@ -192,13 +193,14 @@ impl Identity { } } - pub fn initialize<'a, R: WriteRepository + cob::Store, G>( + pub fn initialize<'a, R, G>( doc: &Doc, store: &'a R, signer: &Device, ) -> Result, cob::store::Error> where G: crypto::signature::Signer, + R: WriteRepository + cob::Store, { let mut store = cob::store::Store::open(store)?; let (id, identity) = Transaction::::initial( @@ -227,7 +229,7 @@ impl Identity { } /// Get a proposal mutably. - pub fn get_mut<'a, R: WriteRepository + cob::Store>( + pub fn get_mut<'a, R: WriteRepository + cob::Store>( id: &ObjectId, repo: &'a R, ) -> Result, store::Error> { @@ -248,7 +250,7 @@ impl Identity { Self::get(&oid, repo).map_err(RepositoryError::from) } - pub fn load_mut( + pub fn load_mut>( repo: &R, ) -> Result, RepositoryError> { let oid = repo.identity_root()?; @@ -892,7 +894,7 @@ impl fmt::Debug for IdentityMut<'_, R> { impl IdentityMut<'_, R> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, { /// Reload the identity data from storage. pub fn reload(&mut self) -> Result<(), store::Error> { diff --git a/radicle/src/cob/issue.rs b/radicle/src/cob/issue.rs index 9dc209f4..b351dce1 100644 --- a/radicle/src/cob/issue.rs +++ b/radicle/src/cob/issue.rs @@ -17,6 +17,7 @@ use crate::cob::thread::{Comment, CommentId, Thread}; use crate::cob::{op, store, ActorId, Embed, EntryId, ObjectId, TypeName}; use crate::identity::doc::DocError; use crate::node::device::Device; +use crate::node::NodeId; use crate::prelude::{Did, Doc, ReadRepository, RepoId}; use crate::storage::{HasRepoId, RepositoryError, WriteRepository}; @@ -589,7 +590,7 @@ impl std::fmt::Debug for IssueMut<'_, '_, R, C> { impl IssueMut<'_, '_, R, C> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, C: cob::cache::Update, { /// Reload the issue data from storage. @@ -792,7 +793,7 @@ impl IssueCounts { impl<'a, R> Issues<'a, R> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { /// Open an issues store. pub fn open(repository: &'a R) -> Result { @@ -805,7 +806,7 @@ where impl<'a, R> Issues<'a, R> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, { /// Create a new issue. pub fn create<'g, G, C>( diff --git a/radicle/src/cob/issue/cache.rs b/radicle/src/cob/issue/cache.rs index e13f0b91..3e759982 100644 --- a/radicle/src/cob/issue/cache.rs +++ b/radicle/src/cob/issue/cache.rs @@ -10,6 +10,7 @@ use crate::cob::cache::{Remove, StoreReader, StoreWriter, Update}; use crate::cob::store; use crate::cob::{Embed, Label, ObjectId, TypeName, Uri}; use crate::node::device::Device; +use crate::node::NodeId; use crate::prelude::{Did, RepoId}; use crate::storage::{HasRepoId, ReadRepository, RepositoryError, SignRepository, WriteRepository}; @@ -107,7 +108,7 @@ impl<'a, R, C> Cache, C> { signer: &Device, ) -> Result, super::Error> where - R: ReadRepository + WriteRepository + cob::Store, + R: ReadRepository + WriteRepository + cob::Store, G: crypto::signature::Signer, C: Update, { @@ -127,7 +128,7 @@ impl<'a, R, C> Cache, C> { pub fn remove(&mut self, id: &IssueId, signer: &Device) -> Result<(), super::Error> where G: crypto::signature::Signer, - R: ReadRepository + SignRepository + cob::Store, + R: ReadRepository + SignRepository + cob::Store, C: Remove, { self.store.remove(id, signer)?; @@ -199,7 +200,7 @@ impl<'a, R, C> Cache, C> { impl<'a, R> Cache, cache::NoCache> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { /// Get a `Cache` that does no write-through modifications and /// uses the [`super::Issues`] store for all reads and writes. diff --git a/radicle/src/cob/job.rs b/radicle/src/cob/job.rs index d5a43975..0901e1d9 100644 --- a/radicle/src/cob/job.rs +++ b/radicle/src/cob/job.rs @@ -21,6 +21,7 @@ use crate::cob::{EntryId, ObjectId, TypeName}; use crate::crypto::ssh::ExtendedSignature; use crate::git; use crate::node::device::Device; +use crate::node::NodeId; use crate::prelude::ReadRepository; use crate::storage::{Oid, WriteRepository}; @@ -315,7 +316,7 @@ impl std::fmt::Debug for JobMut<'_, '_, R> { impl JobMut<'_, '_, R> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, { /// Reload the COB from storage. pub fn reload(&mut self) -> Result<(), store::Error> { @@ -397,7 +398,7 @@ impl<'a, R> Deref for JobStore<'a, R> { impl<'a, R> JobStore<'a, R> where - R: WriteRepository + ReadRepository + cob::Store, + R: WriteRepository + ReadRepository + cob::Store, { pub fn open(repository: &'a R) -> Result { let raw = store::Store::open(repository)?; diff --git a/radicle/src/cob/patch.rs b/radicle/src/cob/patch.rs index 5cc0fb9b..ee40f3ba 100644 --- a/radicle/src/cob/patch.rs +++ b/radicle/src/cob/patch.rs @@ -1976,7 +1976,7 @@ pub struct PatchMut<'a, 'g, R, C> { impl<'a, 'g, R, C> PatchMut<'a, 'g, R, C> where C: cob::cache::Update, - R: ReadRepository + SignRepository + cob::Store, + R: ReadRepository + SignRepository + cob::Store, { pub fn new(id: ObjectId, patch: Patch, cache: &'g mut Cache, C>) -> Self { Self { @@ -2507,7 +2507,7 @@ where impl<'a, R> Patches<'a, R> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { /// Open a patches store. pub fn open(repository: &'a R) -> Result { @@ -2590,7 +2590,7 @@ where impl<'a, R> Patches<'a, R> where - R: ReadRepository + SignRepository + cob::Store, + R: ReadRepository + SignRepository + cob::Store, { /// Open a new patch. pub fn create<'g, C, G>( diff --git a/radicle/src/cob/patch/cache.rs b/radicle/src/cob/patch/cache.rs index 30529909..ea10869d 100644 --- a/radicle/src/cob/patch/cache.rs +++ b/radicle/src/cob/patch/cache.rs @@ -15,8 +15,8 @@ use crate::prelude::RepoId; use crate::storage::{HasRepoId, ReadRepository, RepositoryError, SignRepository, WriteRepository}; use super::{ - ByRevision, MergeTarget, Patch, PatchCounts, PatchId, PatchMut, Revision, RevisionId, State, - Status, + ByRevision, MergeTarget, NodeId, Patch, PatchCounts, PatchId, PatchMut, Revision, RevisionId, + State, Status, }; /// A set of read-only methods for a [`Patch`] store. @@ -119,7 +119,7 @@ impl<'a, R, C> Cache, C> { signer: &Device, ) -> Result, super::Error> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, G: crypto::signature::Signer, C: Update, { @@ -149,7 +149,7 @@ impl<'a, R, C> Cache, C> { signer: &Device, ) -> Result, super::Error> where - R: WriteRepository + cob::Store, + R: WriteRepository + cob::Store, G: crypto::signature::Signer, C: Update, { @@ -170,7 +170,7 @@ impl<'a, R, C> Cache, C> { pub fn remove(&mut self, id: &PatchId, signer: &Device) -> Result<(), super::Error> where G: crypto::signature::Signer, - R: ReadRepository + SignRepository + cob::Store, + R: ReadRepository + SignRepository + cob::Store, C: Remove, { self.store.remove(id, signer)?; @@ -276,7 +276,7 @@ where impl<'a, R> Cache, cache::NoCache> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { /// Get a `Cache` that does no write-through modifications and /// uses the [`super::Patches`] store for all reads and writes. @@ -488,7 +488,7 @@ impl Iterator for NoCacheIter<'_> { impl Patches for Cache, cache::NoCache> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { type Error = super::Error; type Iter<'b> diff --git a/radicle/src/cob/store.rs b/radicle/src/cob/store.rs index b6deabfa..ddaf8bd1 100644 --- a/radicle/src/cob/store.rs +++ b/radicle/src/cob/store.rs @@ -174,7 +174,7 @@ where impl<'a, T, R> Store<'a, T, R> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, T: CobWithType, { /// Open a new generic store. @@ -190,7 +190,7 @@ where impl Store<'_, T, R> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, T: Cob + cob::Evaluate, { pub fn transaction( @@ -204,7 +204,7 @@ where impl Store<'_, T, R> where - R: ReadRepository + SignRepository + cob::Store, + R: ReadRepository + SignRepository + cob::Store, T: Cob + cob::Evaluate, T::Action: Serialize, { @@ -423,7 +423,7 @@ where Self: From, G: crypto::signature::Signer, F: FnOnce(&mut Tx, &R) -> Result<(), Error>, - R: ReadRepository + SignRepository + cob::Store, + R: ReadRepository + SignRepository + cob::Store, T::Action: Serialize + Clone, { let mut tx = Tx::from(Transaction::default()); @@ -487,7 +487,7 @@ where signer: &Device, ) -> Result<(T, EntryId), Error> where - R: ReadRepository + SignRepository + cob::Store, + R: ReadRepository + SignRepository + cob::Store, T::Action: Serialize + Clone, G: crypto::signature::Signer, { diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index d3a27409..c69ebc26 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -605,7 +605,7 @@ impl Home { repository: &'a R, ) -> Result, cob::cache::StoreReader>, Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { let db = self.cobs_db()?; let store = cob::issue::Issues::open(repository)?; @@ -621,7 +621,7 @@ impl Home { repository: &'a R, ) -> Result, cob::cache::StoreWriter>, Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { let db = self.cobs_db_mut()?; let store = cob::issue::Issues::open(repository)?; @@ -637,7 +637,7 @@ impl Home { repository: &'a R, ) -> Result, cob::cache::StoreReader>, Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { let db = self.cobs_db()?; let store = cob::patch::Patches::open(repository)?; @@ -653,7 +653,7 @@ impl Home { repository: &'a R, ) -> Result, cob::cache::StoreWriter>, Error> where - R: ReadRepository + cob::Store, + R: ReadRepository + cob::Store, { let db = self.cobs_db_mut()?; let store = cob::patch::Patches::open(repository)?; diff --git a/radicle/src/storage/git/cob.rs b/radicle/src/storage/git/cob.rs index 79287b17..a3bcce14 100644 --- a/radicle/src/storage/git/cob.rs +++ b/radicle/src/storage/git/cob.rs @@ -11,20 +11,18 @@ use storage::RepositoryError; use storage::SignRepository; use storage::ValidateRepository; +use crate::git; use crate::git::*; use crate::identity; use crate::identity::doc::DocError; use crate::node::device::Device; +use crate::node::NodeId; use crate::storage; use crate::storage::Error; use crate::storage::{ git::{Remote, Remotes, Validations}, ReadRepository, Verified, }; -use crate::{ - git, identity, - identity::{doc::DocError, PublicKey}, -}; use super::{RemoteId, Repository}; @@ -92,6 +90,8 @@ impl cob::object::Storage for Repository { type UpdateError = git2::Error; type RemoveError = git2::Error; + type Namespace = NodeId; + fn objects( &self, typename: &cob::TypeName, @@ -146,13 +146,13 @@ impl cob::object::Storage for Repository { fn update( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &cob::TypeName, object_id: &cob::ObjectId, entry: &cob::EntryId, ) -> Result<(), Self::UpdateError> { self.backend.reference( - git::refs::storage::cob(identifier, typename, object_id).as_str(), + git::refs::storage::cob(namespace, typename, object_id).as_str(), (*entry).into(), true, &format!( @@ -166,13 +166,13 @@ impl cob::object::Storage for Repository { fn remove( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &cob::TypeName, object_id: &cob::ObjectId, ) -> Result<(), Self::RemoveError> { let mut reference = self .backend - .find_reference(git::refs::storage::cob(identifier, typename, object_id).as_str())?; + .find_reference(git::refs::storage::cob(namespace, typename, object_id).as_str())?; reference.delete() } @@ -377,6 +377,8 @@ impl cob::object::Storage for DraftStore<'_, R> { type UpdateError = git2::Error; type RemoveError = git2::Error; + type Namespace = NodeId; + fn objects( &self, typename: &cob::TypeName, @@ -421,13 +423,13 @@ impl cob::object::Storage for DraftStore<'_, R> { fn update( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &cob::TypeName, object_id: &cob::ObjectId, entry: &cob::history::EntryId, ) -> Result<(), Self::UpdateError> { self.repo.raw().reference( - git::refs::storage::draft::cob(identifier, typename, object_id).as_str(), + git::refs::storage::draft::cob(namespace, typename, object_id).as_str(), (*entry).into(), true, &format!( @@ -441,12 +443,12 @@ impl cob::object::Storage for DraftStore<'_, R> { fn remove( &self, - identifier: &PublicKey, + namespace: &Self::Namespace, typename: &cob::TypeName, object_id: &cob::ObjectId, ) -> Result<(), Self::RemoveError> { let mut reference = self.repo.raw().find_reference( - git::refs::storage::draft::cob(identifier, typename, object_id).as_str(), + git::refs::storage::draft::cob(namespace, typename, object_id).as_str(), )?; reference.delete() diff --git a/radicle/src/test/storage.rs b/radicle/src/test/storage.rs index 4b00f888..116d9cc9 100644 --- a/radicle/src/test/storage.rs +++ b/radicle/src/test/storage.rs @@ -364,6 +364,8 @@ impl radicle_cob::object::Storage for MockRepository { type UpdateError = Infallible; type RemoveError = Infallible; + type Namespace = crypto::PublicKey; + fn objects( &self, _typename: &radicle_cob::TypeName, @@ -384,7 +386,7 @@ impl radicle_cob::object::Storage for MockRepository { fn update( &self, - _identifier: &radicle_crypto::PublicKey, + _namespace: &Self::Namespace, _typename: &radicle_cob::TypeName, _object_id: &radicle_cob::ObjectId, _entry: &radicle_cob::EntryId, @@ -394,7 +396,7 @@ impl radicle_cob::object::Storage for MockRepository { fn remove( &self, - _identifier: &radicle_crypto::PublicKey, + _namespace: &Self::Namespace, _typename: &radicle_cob::TypeName, _object_id: &radicle_cob::ObjectId, ) -> Result<(), Self::RemoveError> {