From 101de0cc08a70f744becd00398abac2611bcc473 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 6 Apr 2024 18:04:14 +0200 Subject: [PATCH] fix(apb): proper feature gating, dict->unstructured --- apb/Cargo.toml | 19 +++--- apb/src/base.rs | 14 ++-- apb/src/key.rs | 9 ++- apb/src/link.rs | 34 ++++----- apb/src/macros.rs | 33 +++++---- apb/src/node.rs | 8 +-- apb/src/object/activity/mod.rs | 34 ++++----- apb/src/object/actor.rs | 64 ++++++++--------- apb/src/object/collection/mod.rs | 34 ++++----- apb/src/object/collection/page.rs | 16 +++-- apb/src/object/document.rs | 10 +-- apb/src/object/mod.rs | 110 +++++++++++++++--------------- apb/src/object/profile.rs | 3 +- apb/src/object/relationship.rs | 1 + apb/src/object/tombstone.rs | 1 + 15 files changed, 205 insertions(+), 185 deletions(-) diff --git a/apb/Cargo.toml b/apb/Cargo.toml index 9c6b202d..70879f5e 100644 --- a/apb/Cargo.toml +++ b/apb/Cargo.toml @@ -9,15 +9,16 @@ edition = "2021" [dependencies] chrono = { version = "0.4", features = ["serde"] } -thiserror = "1.0" -serde_json = { version = "1.0", optional = true } -reqwest = { version = "0.12", features = ["json"], optional = true } -paste = "1.0.14" +thiserror = "1" +paste = "1.0" +tracing = "0.1" +serde_json = { version = "1", optional = true } sea-orm = { version = "0.12", optional = true } -tracing = "0.1.40" +reqwest = { version = "0.12", features = ["json"], optional = true } [features] -default = ["fetch", "dict", "orm"] -fetch = ["dep:reqwest"] -dict = ["dep:serde_json"] -orm = ["dep:sea-orm"] +default = [] +orm = ["dep:sea-orm"] +fetch = ["dep:reqwest"] +unstructured = ["dep:serde_json"] +# TODO eventually also make a structured base? diff --git a/apb/src/base.rs b/apb/src/base.rs index 50370030..c9065cdf 100644 --- a/apb/src/base.rs +++ b/apb/src/base.rs @@ -1,6 +1,6 @@ -use crate::{getter, setter, strenum, LinkType, ObjectType}; +use crate::{LinkType, ObjectType}; -strenum! { +crate::strenum! { pub enum BaseType { ; Object(ObjectType), @@ -30,12 +30,14 @@ impl Base for String { } } +#[cfg(feature = "unstructured")] impl Base for serde_json::Value { - getter! { id -> &str } - getter! { base_type -> type BaseType } + crate::getter! { id -> &str } + crate::getter! { base_type -> type BaseType } } +#[cfg(feature = "unstructured")] impl BaseMut for serde_json::Value { - setter! { id -> &str } - setter! { base_type -> type BaseType } + crate::setter! { id -> &str } + crate::setter! { base_type -> type BaseType } } diff --git a/apb/src/key.rs b/apb/src/key.rs index 470a4536..4c249f4c 100644 --- a/apb/src/key.rs +++ b/apb/src/key.rs @@ -1,8 +1,5 @@ // TODO technically this is not part of ActivityStreams -use crate::{getter, setter}; - - pub trait PublicKey : super::Base { fn owner(&self) -> Option<&str> { None } fn public_key_pem(&self) -> &str; @@ -13,16 +10,18 @@ pub trait PublicKeyMut : super::BaseMut { fn set_public_key_pem(self, val: &str) -> Self; } +#[cfg(feature = "unstructured")] impl PublicKey for serde_json::Value { - getter! { owner -> &str } + crate::getter! { owner -> &str } fn public_key_pem(&self) -> &str { self.get("publicKeyPem").unwrap().as_str().unwrap() } } +#[cfg(feature = "unstructured")] impl PublicKeyMut for serde_json::Value { - setter! { owner -> &str } + crate::setter! { owner -> &str } fn set_public_key_pem(mut self, val: &str) -> Self { self.as_object_mut().unwrap().insert( diff --git a/apb/src/link.rs b/apb/src/link.rs index 19bd284f..6991e155 100644 --- a/apb/src/link.rs +++ b/apb/src/link.rs @@ -1,6 +1,4 @@ -use crate::{getter, setter, strenum}; - -strenum! { +crate::strenum! { pub enum LinkType { Link, Mention; @@ -35,6 +33,7 @@ impl Link for String { } } +#[cfg(feature = "unstructured")] impl Link for serde_json::Value { // TODO this can fail, but it should never do! fn href(&self) -> &str { @@ -51,15 +50,16 @@ impl Link for serde_json::Value { } } - getter! { rel -> &str } - getter! { link_media_type::mediaType -> &str } - getter! { link_name::name -> &str } - getter! { hreflang -> &str } - getter! { height -> u64 } - getter! { width -> u64 } - getter! { link_preview::preview -> &str } + crate::getter! { rel -> &str } + crate::getter! { link_media_type::mediaType -> &str } + crate::getter! { link_name::name -> &str } + crate::getter! { hreflang -> &str } + crate::getter! { height -> u64 } + crate::getter! { width -> u64 } + crate::getter! { link_preview::preview -> &str } } +#[cfg(feature = "unstructured")] impl LinkMut for serde_json::Value { // TODO this can fail, but it should never do! fn set_href(mut self, href: &str) -> Self { @@ -76,11 +76,11 @@ impl LinkMut for serde_json::Value { self } - setter! { rel -> &str } - setter! { link_media_type::mediaType -> &str } - setter! { link_name::name -> &str } - setter! { hreflang -> &str } - setter! { height -> u64 } - setter! { width -> u64 } - setter! { link_preview::preview -> &str } + crate::setter! { rel -> &str } + crate::setter! { link_media_type::mediaType -> &str } + crate::setter! { link_name::name -> &str } + crate::setter! { hreflang -> &str } + crate::setter! { height -> u64 } + crate::setter! { width -> u64 } + crate::setter! { link_preview::preview -> &str } } diff --git a/apb/src/macros.rs b/apb/src/macros.rs index 071a5b26..3350a7b4 100644 --- a/apb/src/macros.rs +++ b/apb/src/macros.rs @@ -1,15 +1,15 @@ -use super::Node; - #[derive(Debug, thiserror::Error)] #[error("invalid type value")] pub struct TypeValueError; +#[cfg(feature = "orm")] impl From for sea_orm::sea_query::ValueTypeErr { fn from(_: TypeValueError) -> Self { sea_orm::sea_query::ValueTypeErr } } +#[cfg(feature = "orm")] impl From for sea_orm::TryGetError { fn from(_: TypeValueError) -> Self { sea_orm::TryGetError::Null("value is not a valid type".into()) @@ -54,12 +54,14 @@ macro_rules! strenum { } } + #[cfg(feature = "orm")] impl From<$enum_name> for sea_orm::Value { fn from(value: $enum_name) -> sea_orm::Value { sea_orm::Value::String(Some(Box::new(value.as_ref().to_string()))) } } + #[cfg(feature = "orm")] impl sea_orm::sea_query::ValueType for $enum_name { fn try_from(v: sea_orm::Value) -> Result { match v { @@ -82,6 +84,7 @@ macro_rules! strenum { } } + #[cfg(feature = "orm")] impl sea_orm::TryGetable for $enum_name { fn try_get_by(res: &sea_orm::prelude::QueryResult, index: I) -> Result { let x : String = res.try_get_by(index)?; @@ -302,24 +305,25 @@ macro_rules! setter { }; } -pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: super::Node) { +#[cfg(feature = "unstructured")] +pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: crate::Node) { match node { - super::Node::Object(x) => { + crate::Node::Object(x) => { set_maybe_value( obj, key, Some(*x), ); }, - super::Node::Link(l) => { + crate::Node::Link(l) => { set_maybe_value( obj, key, Some(serde_json::Value::String(l.href().to_string())), ); }, - super::Node::Array(_) => { + crate::Node::Array(_) => { set_maybe_value( obj, key, Some(serde_json::Value::Array(node.into_iter().collect())), ); }, - super::Node::Empty => { + crate::Node::Empty => { set_maybe_value( obj, key, None, ); @@ -327,6 +331,7 @@ pub fn set_maybe_node(obj: &mut serde_json::Value, key: &str, node: super::Node< } } +#[cfg(feature = "unstructured")] pub fn set_maybe_value(obj: &mut serde_json::Value, key: &str, value: Option) { if let Some(map) = obj.as_object_mut() { match value { @@ -338,35 +343,37 @@ pub fn set_maybe_value(obj: &mut serde_json::Value, key: &str, value: Option); + fn insert_node(&mut self, k: &str, v: crate::Node); fn insert_str(&mut self, k: &str, v: Option<&str>); fn insert_float(&mut self, k: &str, f: Option); fn insert_timestr(&mut self, k: &str, t: Option>); } +#[cfg(feature = "unstructured")] impl InsertValue for serde_json::Map { - fn insert_node(&mut self, k: &str, node: Node) { + fn insert_node(&mut self, k: &str, node: crate::Node) { match node { - Node::Object(x) => { + crate::Node::Object(x) => { self.insert( k.to_string(), *x, ); }, - Node::Array(ref _arr) => { + crate::Node::Array(ref _arr) => { self.insert( k.to_string(), serde_json::Value::Array(node.into_iter().collect()), ); }, - Node::Link(l) => { + crate::Node::Link(l) => { self.insert( k.to_string(), serde_json::Value::String(l.href().to_string()), ); }, - Node::Empty => {}, + crate::Node::Empty => {}, }; } diff --git a/apb/src/node.rs b/apb/src/node.rs index 7fd59a08..9da45078 100644 --- a/apb/src/node.rs +++ b/apb/src/node.rs @@ -80,7 +80,7 @@ impl Node { } } -#[cfg(feature = "dict")] +#[cfg(feature = "unstructured")] impl Node { pub fn link(uri: String) -> Self { Node::Link(Box::new(uri)) @@ -133,7 +133,7 @@ impl Node { } } -#[cfg(feature = "dict")] +#[cfg(feature = "unstructured")] impl From> for Node { fn from(value: Option<&str>) -> Self { match value { @@ -143,14 +143,14 @@ impl From> for Node { } } -#[cfg(feature = "dict")] +#[cfg(feature = "unstructured")] impl From<&str> for Node { fn from(value: &str) -> Self { Node::Link(Box::new(value.to_string())) } } -#[cfg(feature = "dict")] +#[cfg(feature = "unstructured")] impl From for Node { fn from(value: serde_json::Value) -> Self { match value { diff --git a/apb/src/object/activity/mod.rs b/apb/src/object/activity/mod.rs index d0a7b60a..1386178c 100644 --- a/apb/src/object/activity/mod.rs +++ b/apb/src/object/activity/mod.rs @@ -4,14 +4,14 @@ pub mod intransitive; pub mod offer; pub mod reject; -use crate::{Node, object::{Object, ObjectMut}, getter, setter, strenum}; +use crate::{Node, object::{Object, ObjectMut}}; use accept::AcceptType; use reject::RejectType; use offer::OfferType; use intransitive::IntransitiveActivityType; use ignore::IgnoreType; -strenum! { +crate::strenum! { pub enum ActivityType { Activity, Add, @@ -60,22 +60,24 @@ pub trait ActivityMut : ObjectMut { fn set_instrument(self, val: Node) -> Self; } +#[cfg(feature = "unstructured")] impl Activity for serde_json::Value { - getter! { activity_type -> type ActivityType } - getter! { actor -> node Self::Actor } - getter! { object -> node ::Object } - getter! { target -> node ::Object } - getter! { result -> node ::Object } - getter! { origin -> node ::Object } - getter! { instrument -> node ::Object } + crate::getter! { activity_type -> type ActivityType } + crate::getter! { actor -> node Self::Actor } + crate::getter! { object -> node ::Object } + crate::getter! { target -> node ::Object } + crate::getter! { result -> node ::Object } + crate::getter! { origin -> node ::Object } + crate::getter! { instrument -> node ::Object } } +#[cfg(feature = "unstructured")] impl ActivityMut for serde_json::Value { - setter! { activity_type -> type ActivityType } - setter! { actor -> node Self::Actor } - setter! { object -> node ::Object } - setter! { target -> node ::Object } - setter! { result -> node ::Object } - setter! { origin -> node ::Object } - setter! { instrument -> node ::Object } + crate::setter! { activity_type -> type ActivityType } + crate::setter! { actor -> node Self::Actor } + crate::setter! { object -> node ::Object } + crate::setter! { target -> node ::Object } + crate::setter! { result -> node ::Object } + crate::setter! { origin -> node ::Object } + crate::setter! { instrument -> node ::Object } } diff --git a/apb/src/object/actor.rs b/apb/src/object/actor.rs index 4077aa59..5a931c07 100644 --- a/apb/src/object/actor.rs +++ b/apb/src/object/actor.rs @@ -1,8 +1,8 @@ -use crate::{Node, getter, setter, strenum}; +use crate::Node; use super::{Object, ObjectMut, super::key::PublicKey}; -strenum! { +crate::strenum! { pub enum ActorType { Application, Group, @@ -18,12 +18,12 @@ pub trait Actor : Object { fn preferred_username(&self) -> Option<&str> { None } fn inbox(&self) -> Node; fn outbox(&self) -> Node; - fn following(&self) -> Node { todo!() } - fn followers(&self) -> Node { todo!() } - fn liked(&self) -> Node { todo!() } - fn streams(&self) -> Node { todo!() } - fn endpoints(&self) -> Option> { None } - fn public_key(&self) -> Node { todo!() } + fn following(&self) -> Node { Node::Empty } + fn followers(&self) -> Node { Node::Empty } + fn liked(&self) -> Node { Node::Empty } + fn streams(&self) -> Node { Node::Empty } + fn endpoints(&self) -> Node { Node::Empty } + fn public_key(&self) -> Node { Node::Empty } // idk about this? everyone has it but AP doesn't mention it fn discoverable(&self) -> Option { None } } @@ -39,45 +39,47 @@ pub trait ActorMut : ObjectMut { fn set_followers(self, val: Node) -> Self; fn set_liked(self, val: Node) -> Self; fn set_streams(self, val: Node) -> Self; - fn set_endpoints(self, val: Option>) -> Self; + fn set_endpoints(self, val: Node) -> Self; // TODO it's more complex than this! fn set_public_key(self, val: Node) -> Self; fn set_discoverable(self, val: Option) -> Self; } +#[cfg(feature = "unstructured")] impl Actor for serde_json::Value { type PublicKey = serde_json::Value; - getter! { actor_type -> type ActorType } - getter! { preferred_username::preferredUsername -> &str } - getter! { inbox -> node Self::Collection } - getter! { outbox -> node Self::Collection } - getter! { following -> node Self::Collection } - getter! { followers -> node Self::Collection } - getter! { liked -> node Self::Collection } - getter! { streams -> node Self::Collection } - getter! { public_key::publicKey -> node Self::PublicKey } - getter! { discoverable -> bool } + crate::getter! { actor_type -> type ActorType } + crate::getter! { preferred_username::preferredUsername -> &str } + crate::getter! { inbox -> node Self::Collection } + crate::getter! { outbox -> node Self::Collection } + crate::getter! { following -> node Self::Collection } + crate::getter! { followers -> node Self::Collection } + crate::getter! { liked -> node Self::Collection } + crate::getter! { streams -> node Self::Collection } + crate::getter! { public_key::publicKey -> node Self::PublicKey } + crate::getter! { discoverable -> bool } - fn endpoints(&self) -> Option> { + fn endpoints(&self) -> Node<::Object> { todo!() } } +#[cfg(feature = "unstructured")] impl ActorMut for serde_json::Value { type PublicKey = serde_json::Value; - setter! { actor_type -> type ActorType } - setter! { preferred_username::preferredUsername -> &str } - setter! { inbox -> node Self::Collection } - setter! { outbox -> node Self::Collection } - setter! { following -> node Self::Collection } - setter! { followers -> node Self::Collection } - setter! { liked -> node Self::Collection } - setter! { streams -> node Self::Collection } - setter! { public_key::publicKey -> node Self::PublicKey } - setter! { discoverable -> bool } + crate::setter! { actor_type -> type ActorType } + crate::setter! { preferred_username::preferredUsername -> &str } + crate::setter! { inbox -> node Self::Collection } + crate::setter! { outbox -> node Self::Collection } + crate::setter! { following -> node Self::Collection } + crate::setter! { followers -> node Self::Collection } + crate::setter! { liked -> node Self::Collection } + crate::setter! { streams -> node Self::Collection } + crate::setter! { public_key::publicKey -> node Self::PublicKey } + crate::setter! { discoverable -> bool } - fn set_endpoints(mut self, _val: Option>) -> Self { + fn set_endpoints(mut self, _val: Node<::Object>) -> Self { self.as_object_mut().unwrap().insert("endpoints".to_string(), serde_json::Value::Object(serde_json::Map::default())); self } diff --git a/apb/src/object/collection/mod.rs b/apb/src/object/collection/mod.rs index 877bf5ce..06abac7f 100644 --- a/apb/src/object/collection/mod.rs +++ b/apb/src/object/collection/mod.rs @@ -1,9 +1,9 @@ pub mod page; pub use page::CollectionPage; -use crate::{Node, Object, object::ObjectMut, getter, setter, strenum}; +use crate::{Node, Object, object::ObjectMut}; -strenum! { +crate::strenum! { pub enum CollectionType { Collection, CollectionPage, @@ -37,26 +37,28 @@ pub trait CollectionMut : ObjectMut { fn set_ordered_items(self, val: Node) -> Self; } +#[cfg(feature = "unstructured")] impl Collection for serde_json::Value { type CollectionPage = serde_json::Value; - getter! { collection_type -> type CollectionType } - getter! { total_items::totalItems -> u64 } - getter! { current -> node Self::CollectionPage } - getter! { first -> node Self::CollectionPage } - getter! { last -> node Self::CollectionPage } - getter! { items -> node ::Object } - getter! { ordered_items::orderedItems -> node ::Object } + crate::getter! { collection_type -> type CollectionType } + crate::getter! { total_items::totalItems -> u64 } + crate::getter! { current -> node Self::CollectionPage } + crate::getter! { first -> node Self::CollectionPage } + crate::getter! { last -> node Self::CollectionPage } + crate::getter! { items -> node ::Object } + crate::getter! { ordered_items::orderedItems -> node ::Object } } +#[cfg(feature = "unstructured")] impl CollectionMut for serde_json::Value { type CollectionPage = serde_json::Value; - setter! { collection_type -> type CollectionType } - setter! { total_items::totalItems -> u64 } - setter! { current -> node Self::CollectionPage } - setter! { first -> node Self::CollectionPage } - setter! { last -> node Self::CollectionPage } - setter! { items -> node ::Object } - setter! { ordered_items::orderedItems -> node ::Object } + crate::setter! { collection_type -> type CollectionType } + crate::setter! { total_items::totalItems -> u64 } + crate::setter! { current -> node Self::CollectionPage } + crate::setter! { first -> node Self::CollectionPage } + crate::setter! { last -> node Self::CollectionPage } + crate::setter! { items -> node ::Object } + crate::setter! { ordered_items::orderedItems -> node ::Object } } diff --git a/apb/src/object/collection/page.rs b/apb/src/object/collection/page.rs index ad581e1c..a7b13617 100644 --- a/apb/src/object/collection/page.rs +++ b/apb/src/object/collection/page.rs @@ -1,4 +1,4 @@ -use crate::{Node, getter, setter}; +use crate::Node; pub trait CollectionPage : super::Collection { fn part_of(&self) -> Node { Node::Empty } @@ -12,14 +12,16 @@ pub trait CollectionPageMut : super::CollectionMut { fn set_prev(self, val: Node) -> Self; } +#[cfg(feature = "unstructured")] impl CollectionPage for serde_json::Value { - getter! { part_of::partOf -> node Self::Collection } - getter! { next -> node Self::CollectionPage } - getter! { prev -> node Self::CollectionPage } + crate::getter! { part_of::partOf -> node Self::Collection } + crate::getter! { next -> node Self::CollectionPage } + crate::getter! { prev -> node Self::CollectionPage } } +#[cfg(feature = "unstructured")] impl CollectionPageMut for serde_json::Value { - setter! { part_of::partOf -> node Self::Collection } - setter! { next -> node Self::CollectionPage } - setter! { prev -> node Self::CollectionPage } + crate::setter! { part_of::partOf -> node Self::Collection } + crate::setter! { next -> node Self::CollectionPage } + crate::setter! { prev -> node Self::CollectionPage } } diff --git a/apb/src/object/document.rs b/apb/src/object/document.rs index 7878847f..85ec2869 100644 --- a/apb/src/object/document.rs +++ b/apb/src/object/document.rs @@ -1,6 +1,4 @@ -use crate::{getter, setter, strenum}; - -strenum! { +crate::strenum! { pub enum DocumentType { Document, Audio, @@ -19,10 +17,12 @@ pub trait DocumentMut : super::ObjectMut { } +#[cfg(feature = "unstructured")] impl Document for serde_json::Value { - getter! { document_type -> type DocumentType } + crate::getter! { document_type -> type DocumentType } } +#[cfg(feature = "unstructured")] impl DocumentMut for serde_json::Value { - setter! { document_type -> type DocumentType } + crate::setter! { document_type -> type DocumentType } } diff --git a/apb/src/object/mod.rs b/apb/src/object/mod.rs index 90b7145a..739855f2 100644 --- a/apb/src/object/mod.rs +++ b/apb/src/object/mod.rs @@ -7,8 +7,6 @@ pub mod place; pub mod profile; pub mod relationship; -use crate::{getter, setter, strenum}; - use super::{Base, BaseMut, Link, Node}; use actor::{Actor, ActorType}; @@ -16,7 +14,7 @@ use document::{Document, DocumentType}; use activity::ActivityType; use collection::{Collection, CollectionType}; -strenum! { +crate::strenum! { pub enum ObjectType { Object, Article, @@ -106,6 +104,7 @@ pub trait ObjectMut : BaseMut { fn set_duration(self, val: Option<&str>) -> Self; // TODO how to parse xsd:duration ? } +#[cfg(feature = "unstructured")] impl Object for serde_json::Value { type Link = serde_json::Value; type Actor = serde_json::Value; @@ -113,32 +112,32 @@ impl Object for serde_json::Value { type Document = serde_json::Value; type Collection = serde_json::Value; - getter! { object_type -> type ObjectType } - getter! { attachment -> node ::Object } - getter! { attributed_to::attributedTo -> node Self::Actor } - getter! { audience -> node Self::Actor } - getter! { content -> &str } - getter! { name -> &str } - getter! { end_time::endTime -> chrono::DateTime } - getter! { generator -> node Self::Actor } - getter! { icon -> node Self::Document } - getter! { image -> node Self::Document } - getter! { in_reply_to::inReplyTo -> node ::Object } - getter! { location -> node ::Object } - getter! { preview -> node ::Object } - getter! { published -> chrono::DateTime } - getter! { replies -> node Self::Collection } - getter! { start_time::startTime -> chrono::DateTime } - getter! { summary -> &str } - getter! { tag -> node ::Object } - getter! { updated -> chrono::DateTime } - getter! { to -> node Self::Link } - getter! { bto -> node Self::Link } - getter! { cc -> node Self::Link } - getter! { bcc -> node Self::Link } - getter! { media_type -> &str } - getter! { duration -> &str } - getter! { url -> node Self::Link } + crate::getter! { object_type -> type ObjectType } + crate::getter! { attachment -> node ::Object } + crate::getter! { attributed_to::attributedTo -> node Self::Actor } + crate::getter! { audience -> node Self::Actor } + crate::getter! { content -> &str } + crate::getter! { name -> &str } + crate::getter! { end_time::endTime -> chrono::DateTime } + crate::getter! { generator -> node Self::Actor } + crate::getter! { icon -> node Self::Document } + crate::getter! { image -> node Self::Document } + crate::getter! { in_reply_to::inReplyTo -> node ::Object } + crate::getter! { location -> node ::Object } + crate::getter! { preview -> node ::Object } + crate::getter! { published -> chrono::DateTime } + crate::getter! { replies -> node Self::Collection } + crate::getter! { start_time::startTime -> chrono::DateTime } + crate::getter! { summary -> &str } + crate::getter! { tag -> node ::Object } + crate::getter! { updated -> chrono::DateTime } + crate::getter! { to -> node Self::Link } + crate::getter! { bto -> node Self::Link } + crate::getter! { cc -> node Self::Link } + crate::getter! { bcc -> node Self::Link } + crate::getter! { media_type -> &str } + crate::getter! { duration -> &str } + crate::getter! { url -> node Self::Link } // TODO Mastodon doesn't use a "context" field on the object but makes up a new one!! fn context(&self) -> Node<::Object> { @@ -152,6 +151,7 @@ impl Object for serde_json::Value { } } +#[cfg(feature = "unstructured")] impl ObjectMut for serde_json::Value { type Link = serde_json::Value; type Actor = serde_json::Value; @@ -159,32 +159,32 @@ impl ObjectMut for serde_json::Value { type Document = serde_json::Value; type Collection = serde_json::Value; - setter! { object_type -> type ObjectType } - setter! { attachment -> node ::Object } - setter! { attributed_to::attributedTo -> node Self::Actor } - setter! { audience -> node Self::Actor } - setter! { content -> &str } - setter! { name -> &str } - setter! { end_time::endTime -> chrono::DateTime } - setter! { generator -> node Self::Actor } - setter! { icon -> node Self::Document } - setter! { image -> node Self::Document } - setter! { in_reply_to::inReplyTo -> node ::Object } - setter! { location -> node ::Object } - setter! { preview -> node ::Object } - setter! { published -> chrono::DateTime } - setter! { replies -> node Self::Collection } - setter! { start_time::startTime -> chrono::DateTime } - setter! { summary -> &str } - setter! { tag -> node ::Object } - setter! { updated -> chrono::DateTime } - setter! { to -> node Self::Link } - setter! { bto -> node Self::Link} - setter! { cc -> node Self::Link } - setter! { bcc -> node Self::Link } - setter! { media_type -> &str } - setter! { duration -> &str } - setter! { url -> node Self::Link } + crate::setter! { object_type -> type ObjectType } + crate::setter! { attachment -> node ::Object } + crate::setter! { attributed_to::attributedTo -> node Self::Actor } + crate::setter! { audience -> node Self::Actor } + crate::setter! { content -> &str } + crate::setter! { name -> &str } + crate::setter! { end_time::endTime -> chrono::DateTime } + crate::setter! { generator -> node Self::Actor } + crate::setter! { icon -> node Self::Document } + crate::setter! { image -> node Self::Document } + crate::setter! { in_reply_to::inReplyTo -> node ::Object } + crate::setter! { location -> node ::Object } + crate::setter! { preview -> node ::Object } + crate::setter! { published -> chrono::DateTime } + crate::setter! { replies -> node Self::Collection } + crate::setter! { start_time::startTime -> chrono::DateTime } + crate::setter! { summary -> &str } + crate::setter! { tag -> node ::Object } + crate::setter! { updated -> chrono::DateTime } + crate::setter! { to -> node Self::Link } + crate::setter! { bto -> node Self::Link} + crate::setter! { cc -> node Self::Link } + crate::setter! { bcc -> node Self::Link } + crate::setter! { media_type -> &str } + crate::setter! { duration -> &str } + crate::setter! { url -> node Self::Link } // TODO Mastodon doesn't use a "context" field on the object but makes up a new one!! fn set_context(mut self, ctx: Node<::Object>) -> Self { diff --git a/apb/src/object/profile.rs b/apb/src/object/profile.rs index 2099b1e4..bb3dc46a 100644 --- a/apb/src/object/profile.rs +++ b/apb/src/object/profile.rs @@ -1,8 +1,9 @@ pub trait Profile : super::Object { // not a Node because it's always embedded and one - fn describes(&self) -> Option { None:: } + fn describes(&self) -> crate::Node { crate::Node::Empty } } +#[cfg(feature = "unstructured")] impl Profile for serde_json::Value { } diff --git a/apb/src/object/relationship.rs b/apb/src/object/relationship.rs index eba5d149..0b387abd 100644 --- a/apb/src/object/relationship.rs +++ b/apb/src/object/relationship.rs @@ -14,6 +14,7 @@ pub trait RelationshipMut : super::ObjectMut { fn set_relationship_object(self, val: Node) -> Self; } +#[cfg(feature = "unstructured")] impl Relationship for serde_json::Value { // ... TODO } diff --git a/apb/src/object/tombstone.rs b/apb/src/object/tombstone.rs index fa38ddfb..97faf7c6 100644 --- a/apb/src/object/tombstone.rs +++ b/apb/src/object/tombstone.rs @@ -8,6 +8,7 @@ pub trait TombstoneMut : super::ObjectMut { fn set_deleted(self, val: Option>) -> Self; } +#[cfg(feature = "unstructured")] impl Tombstone for serde_json::Value { // ... TODO }