Various fixes to COBs
* Use the existing conventions for passing a signer to functions. * Allow replacing git refs when updating cobs. * Fix the parsing of a cob id. Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
80401f89ae
commit
08811b4b87
|
|
@ -48,19 +48,19 @@ impl<Author> Create<Author> {
|
||||||
///
|
///
|
||||||
/// The `args` are the metadata for this [`CollaborativeObject`]. See
|
/// The `args` are the metadata for this [`CollaborativeObject`]. See
|
||||||
/// [`Create`] for further information.
|
/// [`Create`] for further information.
|
||||||
pub fn create<S, Signer, Author, Resource>(
|
pub fn create<S, G, Author, Resource>(
|
||||||
storage: &S,
|
storage: &S,
|
||||||
signer: Signer,
|
signer: &G,
|
||||||
resource: &Resource,
|
resource: &Resource,
|
||||||
identifier: &S::Identifier,
|
identifier: &S::Identifier,
|
||||||
args: Create<Author>,
|
args: Create<Author>,
|
||||||
) -> Result<CollaborativeObject, error::Create>
|
) -> Result<CollaborativeObject, error::Create>
|
||||||
where
|
where
|
||||||
S: Store,
|
S: Store,
|
||||||
|
G: crypto::Signer,
|
||||||
Author: Identity,
|
Author: Identity,
|
||||||
Author::Identifier: Clone + PartialEq,
|
Author::Identifier: Clone + PartialEq,
|
||||||
Resource: Identity,
|
Resource: Identity,
|
||||||
Signer: crypto::Signer,
|
|
||||||
{
|
{
|
||||||
let Create {
|
let Create {
|
||||||
author,
|
author,
|
||||||
|
|
@ -81,7 +81,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
let init_change = storage
|
let init_change = storage
|
||||||
.create(content, resource.content_id(), &signer, args.create_spec())
|
.create(content, resource.content_id(), signer, args.create_spec())
|
||||||
.map_err(error::Create::from)?;
|
.map_err(error::Create::from)?;
|
||||||
|
|
||||||
let history = History::new_from_root(
|
let history = History::new_from_root(
|
||||||
|
|
|
||||||
|
|
@ -42,19 +42,19 @@ pub struct Update<Author> {
|
||||||
///
|
///
|
||||||
/// The `args` are the metadata for this [`CollaborativeObject`]
|
/// The `args` are the metadata for this [`CollaborativeObject`]
|
||||||
/// udpate. See [`Update`] for further information.
|
/// udpate. See [`Update`] for further information.
|
||||||
pub fn update<S, Signer, Resource, Author>(
|
pub fn update<S, G, Resource, Author>(
|
||||||
storage: &S,
|
storage: &S,
|
||||||
signer: Signer,
|
signer: &G,
|
||||||
resource: &Resource,
|
resource: &Resource,
|
||||||
identifier: &S::Identifier,
|
identifier: &S::Identifier,
|
||||||
args: Update<Author>,
|
args: Update<Author>,
|
||||||
) -> Result<CollaborativeObject, error::Update>
|
) -> Result<CollaborativeObject, error::Update>
|
||||||
where
|
where
|
||||||
S: Store,
|
S: Store,
|
||||||
|
G: crypto::Signer,
|
||||||
Author: Identity,
|
Author: Identity,
|
||||||
Author::Identifier: Clone + PartialEq,
|
Author::Identifier: Clone + PartialEq,
|
||||||
Resource: Identity,
|
Resource: Identity,
|
||||||
Signer: crypto::Signer,
|
|
||||||
{
|
{
|
||||||
let Update {
|
let Update {
|
||||||
author,
|
author,
|
||||||
|
|
@ -86,7 +86,7 @@ where
|
||||||
let change = storage.create(
|
let change = storage.create(
|
||||||
content,
|
content,
|
||||||
resource.content_id(),
|
resource.content_id(),
|
||||||
&signer,
|
signer,
|
||||||
change::Create {
|
change::Create {
|
||||||
tips: object.tips().iter().cloned().collect(),
|
tips: object.tips().iter().cloned().collect(),
|
||||||
contents: changes.clone(),
|
contents: changes.clone(),
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ fn roundtrip() {
|
||||||
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
||||||
let cob = create(
|
let cob = create(
|
||||||
&storage,
|
&storage,
|
||||||
signer,
|
&signer,
|
||||||
&proj,
|
&proj,
|
||||||
&proj.identifier(),
|
&proj.identifier(),
|
||||||
Create {
|
Create {
|
||||||
|
|
@ -54,7 +54,7 @@ fn list_cobs() {
|
||||||
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
||||||
let issue_1 = create(
|
let issue_1 = create(
|
||||||
&storage,
|
&storage,
|
||||||
signer.clone(),
|
&signer,
|
||||||
&proj,
|
&proj,
|
||||||
&proj.identifier(),
|
&proj.identifier(),
|
||||||
Create {
|
Create {
|
||||||
|
|
@ -68,7 +68,7 @@ fn list_cobs() {
|
||||||
|
|
||||||
let issue_2 = create(
|
let issue_2 = create(
|
||||||
&storage,
|
&storage,
|
||||||
signer,
|
&signer,
|
||||||
&proj,
|
&proj,
|
||||||
&proj.identifier(),
|
&proj.identifier(),
|
||||||
Create {
|
Create {
|
||||||
|
|
@ -103,7 +103,7 @@ fn update_cob() {
|
||||||
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
||||||
let cob = create(
|
let cob = create(
|
||||||
&storage,
|
&storage,
|
||||||
signer.clone(),
|
&signer,
|
||||||
&proj,
|
&proj,
|
||||||
&proj.identifier(),
|
&proj.identifier(),
|
||||||
Create {
|
Create {
|
||||||
|
|
@ -121,7 +121,7 @@ fn update_cob() {
|
||||||
|
|
||||||
let updated = update(
|
let updated = update(
|
||||||
&storage,
|
&storage,
|
||||||
signer,
|
&signer,
|
||||||
&proj,
|
&proj,
|
||||||
&proj.identifier(),
|
&proj.identifier(),
|
||||||
Update {
|
Update {
|
||||||
|
|
@ -161,7 +161,7 @@ fn traverse_cobs() {
|
||||||
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
|
||||||
let cob = create(
|
let cob = create(
|
||||||
&storage,
|
&storage,
|
||||||
terry_signer,
|
&terry_signer,
|
||||||
&terry_proj,
|
&terry_proj,
|
||||||
&terry_proj.identifier(),
|
&terry_proj.identifier(),
|
||||||
Create {
|
Create {
|
||||||
|
|
@ -183,7 +183,7 @@ fn traverse_cobs() {
|
||||||
|
|
||||||
let updated = update(
|
let updated = update(
|
||||||
&storage,
|
&storage,
|
||||||
neil_signer,
|
&neil_signer,
|
||||||
&neil_proj,
|
&neil_proj,
|
||||||
&neil_proj.identifier(),
|
&neil_proj.identifier(),
|
||||||
Update {
|
Update {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,11 @@ pub use cob::{
|
||||||
use radicle_cob as cob;
|
use radicle_cob as cob;
|
||||||
use radicle_git_ext::Oid;
|
use radicle_git_ext::Oid;
|
||||||
|
|
||||||
|
pub use radicle_cob::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
identity::{project::Identity, Did},
|
identity::{project::Identity, Did},
|
||||||
|
node::NodeId,
|
||||||
storage::git::Repository,
|
storage::git::Repository,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -21,6 +24,20 @@ pub struct Author {
|
||||||
did: Did,
|
did: Did,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Did> for Author {
|
||||||
|
fn from(did: Did) -> Self {
|
||||||
|
Self { did }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<NodeId> for Author {
|
||||||
|
fn from(node_id: NodeId) -> Self {
|
||||||
|
Self {
|
||||||
|
did: Did::from(node_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl identity::Identity for Author {
|
impl identity::Identity for Author {
|
||||||
type Identifier = String;
|
type Identifier = String;
|
||||||
|
|
||||||
|
|
@ -47,14 +64,14 @@ impl identity::Identity for Author {
|
||||||
///
|
///
|
||||||
/// The `args` are the metadata for this [`CollaborativeObject`]
|
/// The `args` are the metadata for this [`CollaborativeObject`]
|
||||||
/// udpate. See [`Update`] for further information.
|
/// udpate. See [`Update`] for further information.
|
||||||
pub fn create<S>(
|
pub fn create<G>(
|
||||||
repository: &Repository,
|
repository: &Repository,
|
||||||
signer: S,
|
signer: &G,
|
||||||
project: &Identity<Oid>,
|
project: &Identity<Oid>,
|
||||||
args: Create<Author>,
|
args: Create<Author>,
|
||||||
) -> Result<CollaborativeObject, error::Create>
|
) -> Result<CollaborativeObject, error::Create>
|
||||||
where
|
where
|
||||||
S: crypto::Signer,
|
G: crypto::Signer,
|
||||||
{
|
{
|
||||||
let namespace = *signer.public_key();
|
let namespace = *signer.public_key();
|
||||||
cob::create(repository, signer, project, &namespace, args)
|
cob::create(repository, signer, project, &namespace, args)
|
||||||
|
|
@ -103,14 +120,14 @@ pub fn list(
|
||||||
///
|
///
|
||||||
/// The `args` are the metadata for this [`CollaborativeObject`]
|
/// The `args` are the metadata for this [`CollaborativeObject`]
|
||||||
/// udpate. See [`Update`] for further information.
|
/// udpate. See [`Update`] for further information.
|
||||||
pub fn update<S>(
|
pub fn update<G>(
|
||||||
repository: &Repository,
|
repository: &Repository,
|
||||||
signer: S,
|
signer: &G,
|
||||||
project: &Identity<Oid>,
|
project: &Identity<Oid>,
|
||||||
args: Update<Author>,
|
args: Update<Author>,
|
||||||
) -> Result<CollaborativeObject, error::Update>
|
) -> Result<CollaborativeObject, error::Update>
|
||||||
where
|
where
|
||||||
S: crypto::Signer,
|
G: crypto::Signer,
|
||||||
{
|
{
|
||||||
let namespace = *signer.public_key();
|
let namespace = *signer.public_key();
|
||||||
cob::update(repository, signer, project, &namespace, args)
|
cob::update(repository, signer, project, &namespace, args)
|
||||||
|
|
|
||||||
|
|
@ -151,9 +151,9 @@ pub mod refs {
|
||||||
let (_refs, _cobs, typename, mut object_id) = cob.non_empty_components();
|
let (_refs, _cobs, typename, mut object_id) = cob.non_empty_components();
|
||||||
let object_id = object_id
|
let object_id = object_id
|
||||||
.next()
|
.next()
|
||||||
.and_then(|oid| oid.parse::<cob::ObjectId>().ok())?;
|
.and_then(|oid| oid.parse::<git2::Oid>().ok())?;
|
||||||
let typename = typename.parse::<cob::TypeName>().ok()?;
|
let typename = typename.parse::<cob::TypeName>().ok()?;
|
||||||
Some((typename, object_id))
|
Some((typename, object_id.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ pub use storage::git::Storage;
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub use crypto::{Signer, Verified};
|
pub use crypto::{PublicKey, Signer, Verified};
|
||||||
pub use identity::{Doc, Id};
|
pub use identity::{Did, Doc, Id};
|
||||||
pub use node::NodeId;
|
pub use node::NodeId;
|
||||||
pub use profile::Profile;
|
pub use profile::Profile;
|
||||||
pub use storage::BranchName;
|
pub use storage::{BranchName, ReadRepository, ReadStorage, WriteRepository, WriteStorage};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -771,7 +771,7 @@ impl cob::object::Storage for Repository {
|
||||||
self.backend.reference(
|
self.backend.reference(
|
||||||
git::refs::storage::cob(identifier, typename, object_id).as_str(),
|
git::refs::storage::cob(identifier, typename, object_id).as_str(),
|
||||||
(*change.id()).into(),
|
(*change.id()).into(),
|
||||||
false,
|
true,
|
||||||
&format!(
|
&format!(
|
||||||
"Updating collaborative object '{}/{}' with new change {}",
|
"Updating collaborative object '{}/{}' with new change {}",
|
||||||
typename,
|
typename,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue