feat(apb): restructured, added target and server

target is about addressing, and server has traits for barebones outbox
and inbox. these come from upub
This commit is contained in:
əlemi 2024-04-11 00:27:17 +02:00
parent 4c2eb7b990
commit a9229adec8
Signed by: alemi
GPG key ID: A4895B84D311642C
22 changed files with 83 additions and 31 deletions

View file

@ -18,6 +18,7 @@ chrono = { version = "0.4", features = ["serde"] }
thiserror = "1"
paste = "1.0"
tracing = "0.1"
async-trait = "0.1"
serde_json = { version = "1", optional = true }
sea-orm = { version = "0.12", optional = true }
reqwest = { version = "0.12", features = ["json"], optional = true }

View file

@ -93,34 +93,35 @@ pub(crate) use macros::{strenum, getter, setter};
mod node;
pub use node::Node;
mod link;
pub use link::{Link, LinkMut, LinkType};
pub mod server;
pub mod target;
mod key;
pub use key::{PublicKey, PublicKeyMut};
mod base;
pub use base::{Base, BaseMut, BaseType};
mod object;
pub use object::{
Object, ObjectMut, ObjectType,
activity::{
Activity, ActivityMut, ActivityType,
accept::{Accept, AcceptMut, AcceptType},
ignore::{Ignore, IgnoreMut, IgnoreType},
intransitive::{IntransitiveActivity, IntransitiveActivityMut, IntransitiveActivityType},
offer::{Offer, OfferMut, OfferType},
reject::{Reject, RejectMut, RejectType},
mod types;
pub use types::{
base::{Base, BaseMut, BaseType},
link::{Link, LinkMut, LinkType},
object::{
Object, ObjectMut, ObjectType,
activity::{
Activity, ActivityMut, ActivityType,
accept::{Accept, AcceptMut, AcceptType},
ignore::{Ignore, IgnoreMut, IgnoreType},
intransitive::{IntransitiveActivity, IntransitiveActivityMut, IntransitiveActivityType},
offer::{Offer, OfferMut, OfferType},
reject::{Reject, RejectMut, RejectType},
},
actor::{Actor, ActorMut, ActorType},
collection::{
Collection, CollectionMut, CollectionType,
page::{CollectionPage, CollectionPageMut}
},
document::{Document, DocumentMut, DocumentType},
place::{Place, PlaceMut},
// profile::Profile,
relationship::{Relationship, RelationshipMut},
tombstone::{Tombstone, TombstoneMut},
},
actor::{Actor, ActorMut, ActorType},
collection::{
Collection, CollectionMut, CollectionType,
page::{CollectionPage, CollectionPageMut}
},
document::{Document, DocumentMut, DocumentType},
place::{Place, PlaceMut},
// profile::Profile,
relationship::{Relationship, RelationshipMut},
tombstone::{Tombstone, TombstoneMut},
};

29
apb/src/server.rs Normal file
View file

@ -0,0 +1,29 @@
#[async_trait::async_trait]
pub trait Outbox {
type Object: crate::Object;
type Activity: crate::Activity;
type Error: std::error::Error;
async fn create_note(&self, uid: String, object: Self::Object) -> Result<String, Self::Error>;
async fn create(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
async fn like(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
async fn follow(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
async fn accept(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
async fn reject(&self, _uid: String, _activity: Self::Activity) -> Result<String, Self::Error>;
async fn undo(&self, uid: String, activity: Self::Activity) -> Result<String, Self::Error>;
}
#[async_trait::async_trait]
pub trait Inbox {
type Activity: crate::Activity;
type Error: std::error::Error;
async fn create(&self, activity: Self::Activity) -> Result<(), Self::Error>;
async fn like(&self, activity: Self::Activity) -> Result<(), Self::Error>;
async fn follow(&self, activity: Self::Activity) -> Result<(), Self::Error>;
async fn accept(&self, activity: Self::Activity) -> Result<(), Self::Error>;
async fn reject(&self, activity: Self::Activity) -> Result<(), Self::Error>;
async fn undo(&self, activity: Self::Activity) -> Result<(), Self::Error>;
async fn delete(&self, activity: Self::Activity) -> Result<(), Self::Error>;
async fn update(&self, activity: Self::Activity) -> Result<(), Self::Error>;
}

18
apb/src/target.rs Normal file
View file

@ -0,0 +1,18 @@
use crate::{Object, Link};
pub const PUBLIC : &str = "https://www.w3.org/ns/activitystreams#Public";
pub trait Addressed : Object {
fn addressed(&self) -> Vec<String>;
}
#[cfg(feature = "unstructured")]
impl Addressed for serde_json::Value {
fn addressed(&self) -> Vec<String> {
let mut to : Vec<String> = self.to().map(|x| x.href().to_string()).collect();
to.append(&mut self.bto().map(|x| x.href().to_string()).collect());
to.append(&mut self.cc().map(|x| x.href().to_string()).collect());
to.append(&mut self.bcc().map(|x| x.href().to_string()).collect());
to
}
}

View file

@ -5,7 +5,7 @@ crate::strenum! {
};
}
pub trait Link : super::Base {
pub trait Link : crate::Base {
fn href(&self) -> &str;
fn rel(&self) -> Option<&str> { None }
fn link_media_type(&self) -> Option<&str> { None } // also in obj
@ -16,7 +16,7 @@ pub trait Link : super::Base {
fn link_preview(&self) -> Option<&str> { None } // also in obj
}
pub trait LinkMut : super::BaseMut {
pub trait LinkMut : crate::BaseMut {
fn set_href(self, href: &str) -> Self;
fn set_rel(self, val: Option<&str>) -> Self;
fn set_link_media_type(self, val: Option<&str>) -> Self; // also in obj

3
apb/src/types/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod base;
pub mod link;
pub mod object;

View file

@ -4,7 +4,7 @@ pub mod intransitive;
pub mod offer;
pub mod reject;
use crate::{Node, object::{Object, ObjectMut}};
use crate::{Node, Object, ObjectMut};
use accept::AcceptType;
use reject::RejectType;
use offer::OfferType;

View file

@ -1,6 +1,6 @@
use crate::Node;
use super::{Object, ObjectMut, super::key::PublicKey};
use crate::{Object, ObjectMut, PublicKey};
crate::strenum! {
pub enum ActorType {

View file

@ -1,7 +1,7 @@
pub mod page;
pub use page::CollectionPage;
use crate::{Node, Object, object::ObjectMut};
use crate::{Node, Object, ObjectMut};
crate::strenum! {
pub enum CollectionType {

View file

@ -7,7 +7,7 @@ pub mod place;
pub mod profile;
pub mod relationship;
use super::{Base, BaseMut, Link, Node};
use crate::{Base, BaseMut, Link, Node};
use actor::{Actor, ActorType};
use document::{Document, DocumentType};