Move `Change` from `radicle-crdt` to `radicle`

Where it belongs.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-12-01 15:17:03 +01:00
parent f6e8a18b15
commit e8a2432f9d
No known key found for this signature in database
9 changed files with 25 additions and 40 deletions

2
Cargo.lock generated
View File

@ -2249,12 +2249,10 @@ version = "0.1.0"
dependencies = [ dependencies = [
"fastrand", "fastrand",
"num-traits", "num-traits",
"olpc-cjson",
"quickcheck", "quickcheck",
"quickcheck_macros", "quickcheck_macros",
"radicle-crypto", "radicle-crypto",
"serde", "serde",
"serde_json",
"tempfile", "tempfile",
] ]

View File

@ -9,10 +9,8 @@ test = ["fastrand", "quickcheck"]
[dependencies] [dependencies]
fastrand = { version = "1.8.0", optional = true } fastrand = { version = "1.8.0", optional = true }
num-traits = { version = "0.2.15", default-features = false, features = ["std"] } num-traits = { version = "0.2.15", default-features = false, features = ["std"] }
olpc-cjson = { version = "0.1.1" }
quickcheck = { version = "1", optional = true } quickcheck = { version = "1", optional = true }
serde = { version = "1" } serde = { version = "1" }
serde_json = { version = "1" }
[dependencies.radicle-crypto] [dependencies.radicle-crypto]
path = "../radicle-crypto" path = "../radicle-crypto"

View File

@ -2,7 +2,6 @@
#![allow(clippy::bool_assert_comparison)] #![allow(clippy::bool_assert_comparison)]
#![allow(clippy::collapsible_else_if)] #![allow(clippy::collapsible_else_if)]
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
pub mod change;
pub mod clock; pub mod clock;
pub mod gmap; pub mod gmap;
pub mod lwwmap; pub mod lwwmap;
@ -16,7 +15,6 @@ pub mod test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
pub use change::*;
pub use clock::Lamport; pub use clock::Lamport;
pub use gmap::GMap; pub use gmap::GMap;
pub use lwwmap::LWWMap; pub use lwwmap::LWWMap;

View File

@ -68,6 +68,7 @@ impl<T: Bounded> Bounded for Max<T> {
#[allow(clippy::derive_ord_xor_partial_ord)] #[allow(clippy::derive_ord_xor_partial_ord)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, Serialize, Deserialize)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Min<T>(pub T); pub struct Min<T>(pub T);
impl<T> Default for Min<T> impl<T> Default for Min<T>

View File

@ -1,9 +1,11 @@
pub mod change;
pub mod common; pub mod common;
pub mod issue; pub mod issue;
pub mod patch; pub mod patch;
pub mod store; pub mod store;
pub mod thread; pub mod thread;
pub use change::{Actor, ActorId, Change, ChangeId};
pub use cob::{ pub use cob::{
identity, object::collaboration::error, CollaborativeObject, Contents, Create, Entry, History, identity, object::collaboration::error, CollaborativeObject, Contents, Create, Entry, History,
ObjectId, TypeName, Update, ObjectId, TypeName, Update,

View File

@ -1,11 +1,10 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use radicle_crdt::clock;
use radicle_crdt::clock::Lamport;
use radicle_crypto::{PublicKey, Signer}; use radicle_crypto::{PublicKey, Signer};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::clock;
use crate::clock::Lamport;
/// Identifies a change. /// Identifies a change.
pub type ChangeId = (Lamport, ActorId); pub type ChangeId = (Lamport, ActorId);
/// The author of a change. /// The author of a change.
@ -33,19 +32,6 @@ impl<A> Change<A> {
} }
} }
impl<A: Serialize> Change<A> {
/// Serialize the change into a byte string.
pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut serializer =
serde_json::Serializer::with_formatter(&mut buf, olpc_cjson::CanonicalFormatter::new());
self.serialize(&mut serializer).unwrap();
buf
}
}
impl<'de, A: Deserialize<'de>> Change<A> { impl<'de, A: Deserialize<'de>> Change<A> {
/// Deserialize a change from a byte string. /// Deserialize a change from a byte string.
pub fn decode(bytes: &'de [u8]) -> Result<Self, serde_json::Error> { pub fn decode(bytes: &'de [u8]) -> Result<Self, serde_json::Error> {

View File

@ -2,20 +2,21 @@ use std::ops::{ControlFlow, Deref};
use std::str::FromStr; use std::str::FromStr;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use radicle_crdt as crdt;
use radicle_crdt::clock; use radicle_crdt::clock;
use radicle_crdt::{ChangeId, LWWReg, LWWSet, Max, Semilattice}; use radicle_crdt::{LWWReg, LWWSet, Max, Semilattice};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
use crate::cob;
use crate::cob::common::{Author, Reaction, Tag}; use crate::cob::common::{Author, Reaction, Tag};
use crate::cob::thread; use crate::cob::thread;
use crate::cob::thread::{CommentId, Thread}; use crate::cob::thread::{CommentId, Thread};
use crate::cob::{store, ObjectId, TypeName}; use crate::cob::{store, ChangeId, ObjectId, TypeName};
use crate::crypto::{PublicKey, Signer}; use crate::crypto::{PublicKey, Signer};
use crate::storage::git as storage; use crate::storage::git as storage;
pub type Change = crdt::Change<Action>; /// Issue change.
pub type Change = crate::cob::Change<Action>;
/// Type name of an issue. /// Type name of an issue.
pub static TYPENAME: Lazy<TypeName> = pub static TYPENAME: Lazy<TypeName> =
@ -175,7 +176,7 @@ impl Issue {
} }
} }
Action::Thread { action } => { Action::Thread { action } => {
self.thread.apply([crdt::Change { self.thread.apply([cob::Change {
action, action,
author: change.author, author: change.author,
clock: change.clock, clock: change.clock,

View File

@ -6,17 +6,17 @@ use std::ops::Range;
use std::str::FromStr; use std::str::FromStr;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use radicle_crdt as crdt;
use radicle_crdt::clock; use radicle_crdt::clock;
use radicle_crdt::{ActorId, ChangeId, GMap, LWWReg, LWWSet, Max, Redactable, Semilattice}; use radicle_crdt::{GMap, LWWReg, LWWSet, Max, Redactable, Semilattice};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
use crate::cob;
use crate::cob::common::{Author, Tag, Timestamp}; use crate::cob::common::{Author, Tag, Timestamp};
use crate::cob::thread; use crate::cob::thread;
use crate::cob::thread::CommentId; use crate::cob::thread::CommentId;
use crate::cob::thread::Thread; use crate::cob::thread::Thread;
use crate::cob::{store, ObjectId, TypeName}; use crate::cob::{store, ActorId, ChangeId, ObjectId, TypeName};
use crate::crypto::{PublicKey, Signer}; use crate::crypto::{PublicKey, Signer};
use crate::git; use crate::git;
use crate::prelude::*; use crate::prelude::*;
@ -30,7 +30,7 @@ pub static TYPENAME: Lazy<TypeName> =
Lazy::new(|| FromStr::from_str("xyz.radicle.patch").expect("type name is valid")); Lazy::new(|| FromStr::from_str("xyz.radicle.patch").expect("type name is valid"));
/// Patch change. /// Patch change.
pub type Change = crdt::Change<Action>; pub type Change = crate::cob::Change<Action>;
/// Identifier for a patch. /// Identifier for a patch.
pub type PatchId = ObjectId; pub type PatchId = ObjectId;
@ -306,7 +306,7 @@ impl Patch {
// TODO(cloudhead): Make sure we can deal with redacted revisions which are added // TODO(cloudhead): Make sure we can deal with redacted revisions which are added
// to out of order, like in the `Merge` case. // to out of order, like in the `Merge` case.
if let Some(Redactable::Present(revision)) = self.revisions.get_mut(&revision) { if let Some(Redactable::Present(revision)) = self.revisions.get_mut(&revision) {
revision.discussion.apply([crdt::Change { revision.discussion.apply([cob::Change {
action, action,
author: change.author, author: change.author,
clock: change.clock, clock: change.clock,
@ -786,13 +786,13 @@ mod test {
use std::str::FromStr; use std::str::FromStr;
use std::{array, iter}; use std::{array, iter};
use crdt::test::{assert_laws, WeightedGenerator}; use radicle_crdt::test::{assert_laws, WeightedGenerator};
use crdt::{Actor, ActorId};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use quickcheck::{Arbitrary, TestResult}; use quickcheck::{Arbitrary, TestResult};
use super::*; use super::*;
use crate::cob::change::{Actor, ActorId};
use crate::crypto::test::signer::MockSigner; use crate::crypto::test::signer::MockSigner;
use crate::test; use crate::test;

View File

@ -8,15 +8,16 @@ use once_cell::sync::Lazy;
use radicle_crdt as crdt; use radicle_crdt as crdt;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::cob;
use crate::cob::common::{Reaction, Timestamp}; use crate::cob::common::{Reaction, Timestamp};
use crate::cob::store; use crate::cob::store;
use crate::cob::{History, TypeName}; use crate::cob::{ActorId, Change, ChangeId, History, TypeName};
use crate::crypto::Signer; use crate::crypto::Signer;
use crdt::clock::Lamport; use crdt::clock::Lamport;
use crdt::lwwset::LWWSet; use crdt::lwwset::LWWSet;
use crdt::redactable::Redactable; use crdt::redactable::Redactable;
use crdt::{ActorId, Change, ChangeId, Semilattice}; use crdt::Semilattice;
/// Type name of a thread. /// Type name of a thread.
pub static TYPENAME: Lazy<TypeName> = pub static TYPENAME: Lazy<TypeName> =
@ -244,13 +245,13 @@ impl Thread {
/// An object that can be used to create and sign changes. /// An object that can be used to create and sign changes.
pub struct Actor<G> { pub struct Actor<G> {
inner: crdt::Actor<G, Action>, inner: cob::Actor<G, Action>,
} }
impl<G: Default + Signer> Default for Actor<G> { impl<G: Default + Signer> Default for Actor<G> {
fn default() -> Self { fn default() -> Self {
Self { Self {
inner: crdt::Actor::new(G::default()), inner: cob::Actor::new(G::default()),
} }
} }
} }
@ -258,7 +259,7 @@ impl<G: Default + Signer> Default for Actor<G> {
impl<G: Signer> Actor<G> { impl<G: Signer> Actor<G> {
pub fn new(signer: G) -> Self { pub fn new(signer: G) -> Self {
Self { Self {
inner: crdt::Actor::new(signer), inner: cob::Actor::new(signer),
} }
} }
@ -282,7 +283,7 @@ impl<G: Signer> Actor<G> {
} }
impl<G> Deref for Actor<G> { impl<G> Deref for Actor<G> {
type Target = crdt::Actor<G, Action>; type Target = cob::Actor<G, Action>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.inner &self.inner