Skip to content

Commit

Permalink
Rounding out types & breaking up modules
Browse files Browse the repository at this point in the history
  • Loading branch information
expede committed Jan 30, 2024
1 parent 21af73e commit f417565
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 127 deletions.
24 changes: 14 additions & 10 deletions src/ability/crud/any.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
use crate::{
ability::traits::Command,
proof::{checkable::Checkable, parentless::Parentless, same::CheckSame},
proof::{
parentless::NoParents,
same::{CheckSame, OptionalFieldErr},
},
};
use serde::{Deserialize, Serialize};
use url::Url;

// NOTE no resolved or awaiting variants, because this cannot be executed, and all fields are optional already!

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AnyBuilder {
pub struct Builder {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub uri: Option<Url>,
}

impl Command for AnyBuilder {
impl Command for Builder {
const COMMAND: &'static str = "crud/*";
}

impl Checkable for AnyBuilder {
type Heirarchy = Parentless<AnyBuilder>;
}
impl NoParents for Builder {}

impl CheckSame for AnyBuilder {
type Error = ();
fn check_same(&self, _proof: &Self) -> Result<(), Self::Error> {
Ok(())
impl CheckSame for Builder {
type Error = OptionalFieldErr;
fn check_same(&self, proof: &Self) -> Result<(), Self::Error> {
self.uri.check_same(&proof.uri)
}
}
2 changes: 1 addition & 1 deletion src/ability/crud/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl TryFrom<Ipld> for Create {
}

impl Checkable for Create {
type Heirarchy = Parentful<Create>;
type Hierarchy = Parentful<Create>;
}

impl CheckSame for Create {
Expand Down
2 changes: 1 addition & 1 deletion src/ability/crud/destroy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl TryFrom<Ipld> for Destroy {
}

impl Checkable for Destroy {
type Heirarchy = Parentful<Destroy>;
type Hierarchy = Parentful<Destroy>;
}

impl CheckSame for Destroy {
Expand Down
8 changes: 4 additions & 4 deletions src/ability/crud/mutate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::any;
use crate::{
ability::traits::Command,
proof::{checkable::Checkable, parentful::Parentful, parents::CheckParents, same::CheckSame},
Expand All @@ -6,11 +7,10 @@ use libipld_core::{ipld::Ipld, serde as ipld_serde};
use serde::{Deserialize, Serialize};
use url::Url;

use super::any::AnyBuilder;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MutateBuilder {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub uri: Option<Url>,
}

Expand All @@ -33,7 +33,7 @@ impl TryFrom<Ipld> for MutateBuilder {
}

impl Checkable for MutateBuilder {
type Heirarchy = Parentful<MutateBuilder>;
type Hierarchy = Parentful<MutateBuilder>;
}

impl CheckSame for MutateBuilder {
Expand All @@ -45,7 +45,7 @@ impl CheckSame for MutateBuilder {

// TODO note to self, this is effectively a partial order
impl CheckParents for MutateBuilder {
type Parents = AnyBuilder;
type Parents = any::Builder;
type ParentError = ();

fn check_parents(&self, _proof: &Self::Parents) -> Result<(), Self::ParentError> {
Expand Down
4 changes: 2 additions & 2 deletions src/ability/crud/parents.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::{any::AnyBuilder, mutate::MutateBuilder};
use super::{any, mutate::MutateBuilder};
use crate::proof::same::CheckSame;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub enum Mutable {
Mutate(MutateBuilder),
Any(AnyBuilder),
Any(any::Builder),
}

impl CheckSame for Mutable {
Expand Down
7 changes: 3 additions & 4 deletions src/ability/crud/read.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::any;
use crate::{
ability::traits::Command,
proof::{checkable::Checkable, parentful::Parentful, parents::CheckParents, same::CheckSame},
Expand All @@ -7,8 +8,6 @@ use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use url::Url;

use super::any::AnyBuilder;

// Read is its own builder
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -39,7 +38,7 @@ impl TryFrom<Ipld> for Read {
}

impl Checkable for Read {
type Heirarchy = Parentful<Read>;
type Hierarchy = Parentful<Read>;
}

impl CheckSame for Read {
Expand All @@ -50,7 +49,7 @@ impl CheckSame for Read {
}

impl CheckParents for Read {
type Parents = AnyBuilder;
type Parents = any::Builder;
type ParentError = ();
fn check_parents(&self, other: &Self::Parents) -> Result<(), Self::ParentError> {
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/ability/crud/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl TryFrom<Ipld> for UpdateBuilder {
}

impl Checkable for UpdateBuilder {
type Heirarchy = Parentful<UpdateBuilder>;
type Hierarchy = Parentful<UpdateBuilder>;
}

impl CheckSame for UpdateBuilder {
Expand Down
8 changes: 3 additions & 5 deletions src/ability/msg/any.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
ability::traits::Command,
proof::{checkable::Checkable, parentless::Parentless, same::CheckSame},
proof::{parentless::NoParents, same::CheckSame},
};
use libipld_core::{error::SerdeError, ipld::Ipld, serde as ipld_serde};
use serde::{Deserialize, Serialize};
Expand All @@ -13,7 +13,7 @@ pub struct Any {
}

impl Command for Any {
const COMMAND: &'static str = "msg";
const COMMAND: &'static str = "msg/*";
}

impl From<Any> for Ipld {
Expand All @@ -30,9 +30,7 @@ impl TryFrom<Ipld> for Any {
}
}

impl Checkable for Any {
type Heirarchy = Parentless<Any>;
}
impl NoParents for Any {}

impl CheckSame for Any {
type Error = ();
Expand Down
40 changes: 18 additions & 22 deletions src/ability/msg/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,12 @@ pub struct Receive {
pub from: Option<Url>,
}

// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
// #[serde(deny_unknown_fields)]
// pub struct MsgReceiveDeferrable {
// to: Deferrable<Url>,
// from: Deferrable<Url>,
// }

impl Command for Receive {
const COMMAND: &'static str = "msg/send";
}

impl From<Receive> for Ipld {
fn from(receive: Receive) -> Self {
receive.into()
}
}

impl TryFrom<Ipld> for Receive {
type Error = SerdeError;

fn try_from(ipld: Ipld) -> Result<Self, Self::Error> {
ipld_serde::from_ipld(ipld)
}
}

impl Checkable for Receive {
type Heirarchy = Parentful<Receive>;
type Hierarchy = Parentful<Receive>;
}

impl CheckSame for Receive {
Expand All @@ -58,3 +37,20 @@ impl CheckParents for Receive {
self.from.check_same(&proof.from).map_err(|_| ())
}
}

////////////


impl From<Receive> for Ipld {
fn from(receive: Receive) -> Self {
receive.into()
}
}

impl TryFrom<Ipld> for Receive {
type Error = SerdeError;

fn try_from(ipld: Ipld) -> Result<Self, Self::Error> {
ipld_serde::from_ipld(ipld)
}
}
Loading

0 comments on commit f417565

Please sign in to comment.