Skip to content

Commit

Permalink
style: Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
cvauclair committed Dec 4, 2024
1 parent 9f832d9 commit 4b1b01e
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 77 deletions.
5 changes: 4 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use futures::{stream, StreamExt, TryStreamExt};
use ipfs::IpfsClient;
use kg_core::ids;
use kg_core::pb::grc20;
use kg_node::kg::{self, entity::{Entity, EntityNode}};
use kg_node::kg::{
self,
entity::{Entity, EntityNode},
};
use kg_node::ops::conversions;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
Expand Down
10 changes: 4 additions & 6 deletions core/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait FromTriples: Sized {
type Error;

fn from_triples(
id: Grc20Id,
id: Grc20Id,
triples: impl IntoIterator<Item = grc20::Triple>,
) -> Result<Self, Self::Error>;
}
Expand All @@ -22,8 +22,6 @@ pub trait ToOps {
pub trait FromOps: Sized {
type Error;

fn from_ops(
id: Grc20Id,
ops: impl IntoIterator<Item = grc20::Op>,
) -> Result<Self, Self::Error>;
}
fn from_ops(id: Grc20Id, ops: impl IntoIterator<Item = grc20::Op>)
-> Result<Self, Self::Error>;
}
16 changes: 6 additions & 10 deletions core/src/graph_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@ pub struct InvalidGraphUri(String);

impl GraphUri {
pub fn from_id_str(id: &str) -> Self {
Self {
id: id.to_string(),
}
Self { id: id.to_string() }
}

pub fn from_id(id: Grc20Id) -> Self {
Self {
id: id.to_string(),
}
Self { id: id.to_string() }
}

pub fn to_id(&self) -> Grc20Id {
Grc20Id(self.id.clone())
}

pub fn from_uri(uri: &str) -> Result<Self, InvalidGraphUri> {
if !uri.starts_with("graph://") {
Err(InvalidGraphUri(uri.to_string()))
} else {
} else {
Ok(Self {
id: uri.replace("graph://", ""),
})
Expand All @@ -46,4 +42,4 @@ impl GraphUri {
pub fn is_valid(uri: &str) -> bool {
uri.starts_with("graph://")
}
}
}
1 change: 0 additions & 1 deletion core/src/ids/system_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub const NUMBER: &str = "SrhnoheQWdZMxvdgynGXiK";
// │ │ │ │ │ │
// └─────────────────────┘ └────────────────────┘ └──────────────────────┘


/// Relation type. This is the entity representing the Join between the
/// the Collection and the Entity
pub const RELATION: &str = "AKDxovGvZaPSWnmKnSoZJY";
Expand Down
4 changes: 2 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub mod conversion;
pub mod blocks;
pub mod conversion;
pub mod graph_uri;
pub mod ids;
pub mod models;
pub mod pb;
pub mod relation;
pub mod graph_uri;

pub use ids::network_ids;
pub use ids::system_ids;
8 changes: 6 additions & 2 deletions core/src/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ pub enum RelationConversionError {
impl FromTriples for Relation {
type Error = RelationConversionError;

fn from_triples(id: Grc20Id, triples: impl IntoIterator<Item = grc20::Triple>) -> Result<Self, Self::Error> {
fn from_triples(
id: Grc20Id,
triples: impl IntoIterator<Item = grc20::Triple>,
) -> Result<Self, Self::Error> {
let relation = triples
.into_iter()
.try_fold::<_, _, Result<RelationBuilder, Self::Error>>(
Expand All @@ -120,7 +123,8 @@ impl FromTriples for Relation {
..
} if attribute == system_ids::TYPES
&& r#type == grc20::ValueType::Url as i32
&& value == GraphUri::from_id_str(system_ids::RELATION_TYPE).to_string() =>
&& value
== GraphUri::from_id_str(system_ids::RELATION_TYPE).to_string() =>
{
Ok(builder)
}
Expand Down
74 changes: 31 additions & 43 deletions node/src/bootstrap/bootstrap_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,40 +176,32 @@ const SCHEMA_TYPES: &[(&str, &[&str])] = &[
const TYPES: &[(&str, &[&str])] = &[(network_ids::ETHEREUM, &[system_ids::NETWORK_TYPE])];

pub fn name_ops() -> impl Iterator<Item = grc20::Triple> {
NAMES
.iter()
.map(|(id, name)| grc20::Triple {
entity: id.to_string(),
attribute: system_ids::NAME.to_string(),
value: Some(grc20::Value {
r#type: grc20::ValueType::Text as i32,
value: name.to_string(),
}),
})
NAMES.iter().map(|(id, name)| grc20::Triple {
entity: id.to_string(),
attribute: system_ids::NAME.to_string(),
value: Some(grc20::Value {
r#type: grc20::ValueType::Text as i32,
value: name.to_string(),
}),
})
}

pub fn attribute_ops() -> impl Iterator<Item = grc20::Triple> {
ATTRIBUTES
.iter()
.flat_map(|(attribute_id, _)| {
create_relationship(attribute_id, system_ids::ATTRIBUTE, system_ids::TYPES, None)
})
ATTRIBUTES.iter().flat_map(|(attribute_id, _)| {
create_relationship(attribute_id, system_ids::ATTRIBUTE, system_ids::TYPES, None)
})
}

pub fn attribute_value_type_ops() -> impl Iterator<Item = grc20::Triple> {
ATTRIBUTES
.iter()
.flat_map(|(attribute_id, value_type_id)| {
create_relationship(attribute_id, value_type_id, system_ids::VALUE_TYPE, None)
})
ATTRIBUTES.iter().flat_map(|(attribute_id, value_type_id)| {
create_relationship(attribute_id, value_type_id, system_ids::VALUE_TYPE, None)
})
}

pub fn type_ops() -> impl Iterator<Item = grc20::Triple> {
SCHEMA_TYPES
.iter()
.flat_map(|(type_id, _)| {
create_relationship(type_id, system_ids::SCHEMA_TYPE, system_ids::TYPES, None)
})
SCHEMA_TYPES.iter().flat_map(|(type_id, _)| {
create_relationship(type_id, system_ids::SCHEMA_TYPE, system_ids::TYPES, None)
})
}

pub fn root_space_type() -> impl Iterator<Item = grc20::Triple> {
Expand All @@ -222,27 +214,23 @@ pub fn root_space_type() -> impl Iterator<Item = grc20::Triple> {
}

pub fn type_schema_ops() -> impl Iterator<Item = grc20::Triple> {
SCHEMA_TYPES
.iter()
.flat_map(|(type_id, attributes)| {
attributes
.iter()
.flat_map(|attribute_id| {
create_relationship(type_id, attribute_id, system_ids::ATTRIBUTES, None)
})
.collect::<Vec<_>>()
})
SCHEMA_TYPES.iter().flat_map(|(type_id, attributes)| {
attributes
.iter()
.flat_map(|attribute_id| {
create_relationship(type_id, attribute_id, system_ids::ATTRIBUTES, None)
})
.collect::<Vec<_>>()
})
}

pub fn entities_types_ops() -> impl Iterator<Item = grc20::Triple> {
TYPES
.iter()
.flat_map(|(entity_id, types_ids)| {
types_ids
.iter()
.flat_map(|type_id| create_relationship(entity_id, type_id, system_ids::TYPES, None))
.collect::<Vec<_>>()
})
TYPES.iter().flat_map(|(entity_id, types_ids)| {
types_ids
.iter()
.flat_map(|type_id| create_relationship(entity_id, type_id, system_ids::TYPES, None))
.collect::<Vec<_>>()
})
}

pub fn bootstrap() -> impl Iterator<Item = grc20::Op> {
Expand Down
2 changes: 1 addition & 1 deletion node/src/bootstrap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod bootstrap_root;
mod bootstrap_templates;
pub mod constants;

pub use bootstrap_root::bootstrap;
pub use bootstrap_root::bootstrap;
4 changes: 1 addition & 3 deletions node/src/ops/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ pub fn group_ops(ops: Vec<grc20::Op>) -> EntityOps {
attribute,
value: Some(grc20::Value { r#type, value }),
}),
) if attribute == system_ids::TYPES
&& *r#type == grc20::ValueType::Url as i32 =>
{
) if attribute == system_ids::TYPES && *r#type == grc20::ValueType::Url as i32 => {
// If triple sets the type, set the type of the entity op batch
let entry = entity_ops.entry(entity.clone()).or_insert((
Vec::new(),
Expand Down
17 changes: 9 additions & 8 deletions node/src/ops/create_relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ impl CreateRelationBuilder {
value: Some(grc20::Value { r#type, .. }),
..
}),
) if attribute == system_ids::TYPES
&& *r#type == grc20::ValueType::Url as i32 =>
{
) if attribute == system_ids::TYPES && *r#type == grc20::ValueType::Url as i32 => {
false
}

Expand All @@ -143,10 +141,11 @@ impl CreateRelationBuilder {
..
}),
) if attribute == system_ids::RELATION_FROM_ATTRIBUTE
&& *r#type == grc20::ValueType::Url as i32
&& *r#type == grc20::ValueType::Url as i32
&& GraphUri::is_valid(value) =>
{
self.from_entity_id = Some(GraphUri::from_uri(value).expect("Uri should be valid").id);
self.from_entity_id =
Some(GraphUri::from_uri(value).expect("Uri should be valid").id);
false
}

Expand All @@ -162,7 +161,8 @@ impl CreateRelationBuilder {
&& *r#type == grc20::ValueType::Url as i32
&& GraphUri::is_valid(value) =>
{
self.to_entity_id = Some(GraphUri::from_uri(value).expect("Uri should be valid").id);
self.to_entity_id =
Some(GraphUri::from_uri(value).expect("Uri should be valid").id);
false
}

Expand All @@ -175,10 +175,11 @@ impl CreateRelationBuilder {
..
}),
) if attribute == system_ids::RELATION_TYPE_ATTRIBUTE
&& *r#type == grc20::ValueType::Url as i32
&& *r#type == grc20::ValueType::Url as i32
&& GraphUri::is_valid(value) =>
{
self.relation_type_id = Some(GraphUri::from_uri(value).expect("Uri should be valid").id);
self.relation_type_id =
Some(GraphUri::from_uri(value).expect("Uri should be valid").id);
false
}

Expand Down

0 comments on commit 4b1b01e

Please sign in to comment.