Browse Source

run format, use new entitystore stuffs

master
Puck Meerburg 9 months ago
parent
commit
9456889a6a

+ 0
- 1
activitypub/Cargo.toml View File

@@ -6,7 +6,6 @@ authors = ["Puck Meerburg <puck@puckipedia.com>"]
[dependencies]
serde_json = "1.0"
jsonld = { path = "../../jsonld-rs" }
diesel = { version = "~1.2", features = ["postgres"] }
kroeg-tap = { path = "../tap" }
futures-await = "0.1"
openssl = "0.10"

+ 2
- 2
activitypub/src/handlers/auto_create.rs View File

@@ -109,13 +109,13 @@ impl<T: EntityStore + 'static> MessageHandler<T> for AutomaticCreateHandler {

match object_type(&elem) {
ObjectType::Activity => {
return Either::A(future::ok((context, store, root)))
return Either::A(future::ok((context, store, root)));
}
ObjectType::ImproperActivity => {
return Either::A(future::err((
AutomaticCreateError::ImproperActivity.into(),
store,
)))
)));
}
ObjectType::Object => {}
}

+ 4
- 4
activitypub/src/handlers/client_create.rs View File

@@ -113,10 +113,10 @@ impl<T: EntityStore + 'static> MessageHandler<T> for ClientCreateHandler {
let item = StoreItem::parse(
&id,
json!({
"@id": id,
"@type": [as2!(OrderedCollection)],
as2!(partOf): [{"@id": elem.id()}]
}),
"@id": id,
"@type": [as2!(OrderedCollection)],
as2!(partOf): [{"@id": elem.id()}]
}),
)
.unwrap();


+ 19
- 16
activitypub/src/handlers/create_actor.rs View File

@@ -164,23 +164,26 @@ impl<T: EntityStore + 'static> MessageHandler<T> for CreateActorHandler {
Some(elem) if elem.main().types.contains(&as2!(Person).to_owned()) => {
Either::A(future::ok((Some(elem), store)))
}
Some(elem) if elem.main().types.contains(&as2!(Create).to_owned()) => match &elem.main()[as2!(object)] as &[Pointer] {
[Pointer::Id(obj)] => {
Either::B(store.get(obj.to_owned(), false).map(|(item, store)| {
(
item.and_then(|f| {
if f.main().types.contains(&as2!(Person).to_owned()) {
Some(f)
} else {
None
}
}),
store,
)
}))
Some(elem) if elem.main().types.contains(&as2!(Create).to_owned()) => {
match &elem.main()[as2!(object)] as &[Pointer] {
[Pointer::Id(obj)] => Either::B(
store.get(obj.to_owned(), false).map(|(item, store)| {
(
item.and_then(|f| {
if f.main().types.contains(&as2!(Person).to_owned())
{
Some(f)
} else {
None
}
}),
store,
)
}),
),
_ => return Either::A(future::ok((context, store, root))),
}
_ => return Either::A(future::ok((context, store, root))),
},
}

_ => return Either::A(future::ok((context, store, root))),
}

+ 1
- 1
activitypub/src/handlers/server_create.rs View File

@@ -61,7 +61,7 @@ impl<T: EntityStore + 'static> MessageHandler<T> for ServerCreateHandler {
return Either::A(future::err((
ServerCreateError::MissingObject.into(),
store,
)))
)));
}
};


+ 3
- 1
activitypub/src/handlers/verify_required.rs View File

@@ -95,7 +95,9 @@ impl<T: EntityStore + 'static> MessageHandler<T> for VerifyRequiredEventsHandler
// If the actor is authorized on the same origin, but different actor, this is probably spoofing. While there is no way to
// re-retrieve the data from the remote origin, there's no reason for this situation to ever occur. Let's just error out.
[Pointer::Id(actor)]
if actor == &subject || (!same_origin(actor, &subject) && same_origin(actor, val.id())) =>
if actor == &subject
|| (!same_origin(actor, &subject)
&& same_origin(actor, val.id())) =>
{
future::ok((Some((actor.to_owned(), val)), store))
}

+ 0
- 1
activitypub/src/lib.rs View File

@@ -3,7 +3,6 @@
#[macro_use]
extern crate kroeg_tap;

extern crate diesel;
extern crate futures_await as futures;
extern crate jsonld;
extern crate openssl;

+ 6
- 3
activitypub/src/test.rs View File

@@ -14,7 +14,10 @@ impl EntityStore for TestStore {
type GetFuture = FutureResult<(Option<StoreItem>, Self), (Self::Error, Self)>;
type StoreFuture = FutureResult<(StoreItem, Self), (Self::Error, Self)>;
type ReadCollectionFuture = FutureResult<(CollectionPointer, Self), (Self::Error, Self)>;
type ReadCollectionInverseFuture = FutureResult<(CollectionPointer, Self), (Self::Error, Self)>;
type FindCollectionFuture = FutureResult<(CollectionPointer, Self), (Self::Error, Self)>;
type WriteCollectionFuture = FutureResult<Self, (Self::Error, Self)>;
type RemoveCollectionFuture = FutureResult<Self, (Self::Error, Self)>;
type QueryFuture = FutureResult<(Vec<Vec<String>>, Self), (Self::Error, Self)>;

fn get(mut self, path: String, local: bool) -> Self::GetFuture {
@@ -53,11 +56,11 @@ impl EntityStore for TestStore {
))
}

fn find_collection(self, _path: String, _item: String) -> Self::ReadCollectionFuture {
fn find_collection(self, _path: String, _item: String) -> Self::FindCollectionFuture {
unimplemented!();
}

fn read_collection_inverse(self, _item: String) -> Self::ReadCollectionFuture {
fn read_collection_inverse(self, _item: String) -> Self::ReadCollectionInverseFuture {
unimplemented!();
}

@@ -75,7 +78,7 @@ impl EntityStore for TestStore {
ok(self)
}

fn remove_collection(mut self, path: String, item: String) -> Self::WriteCollectionFuture {
fn remove_collection(mut self, path: String, item: String) -> Self::RemoveCollectionFuture {
println!("store: remove collection {}, item {}", path, item);
if let None = self.items.get(&path) {
return ok(self);

+ 85
- 20
tap/src/entitystore.rs View File

@@ -15,42 +15,47 @@ pub trait EntityStore: Debug + Send + Sized + 'static {
/// the `StoreItem`
type Error: Error + Send + Sync + 'static;

// ---

/// The `Future` that is returned when `get`ting a `StoreItem`.
type GetFuture: Future<Item = (Option<StoreItem>, Self), Error = (Self::Error, Self)>
+ 'static
+ Send;

/// The `Future` that is returned when `put`ting a `StoreItem`.
type StoreFuture: Future<Item = (StoreItem, Self), Error = (Self::Error, Self)> + 'static + Send;

/// The `Future` that is returned when reading the collection data.
type ReadCollectionFuture: Future<Item = (CollectionPointer, Self), Error = (Self::Error, Self)>
+ 'static
+ Send;

/// The `Future` that is returned when writing into a collection.
type WriteCollectionFuture: Future<Item = Self, Error = (Self::Error, Self)> + 'static + Send;

/// The `Future` that is returned when querying the database.
type QueryFuture: Future<Item = (Vec<Vec<String>>, Self), Error = (Self::Error, Self)>
+ 'static
+ Send;

/// Gets a single `StoreItem` from the store. Missing entities are no error,
/// but instead returns a `None`.
fn get(self, path: String, local: bool) -> Self::GetFuture;

// ---

/// The `Future` that is returned when `put`ting a `StoreItem`.
type StoreFuture: Future<Item = (StoreItem, Self), Error = (Self::Error, Self)> + 'static + Send;

/// Stores a single `StoreItem` into the store.
///
/// To delete an Entity, set its type to as:Tombstone. This may
/// instantly remove it, or queue it for possible future deletion.
fn put(self, path: String, item: StoreItem) -> Self::StoreFuture;

// -----

/// The `Future` that is returned when querying the database.
type QueryFuture: Future<Item = (Vec<Vec<String>>, Self), Error = (Self::Error, Self)>
+ 'static
+ Send;

/// Queries the entire store for a specific set of parameters.
/// The return value is a list for every result in the database that matches the query.
/// The array elements are in numeric order of the placeholders.
fn query(self, query: Vec<QuadQuery>) -> Self::QueryFuture;

// -----

/// The `Future` that is returned when reading the collection data.
type ReadCollectionFuture: Future<Item = (CollectionPointer, Self), Error = (Self::Error, Self)>
+ 'static
+ Send;

/// Reads N amount of items from the collection corresponding to a specific ID. If a cursor is passed,
/// it can be used to paginate.
fn read_collection(
@@ -60,17 +65,41 @@ pub trait EntityStore: Debug + Send + Sized + 'static {
cursor: Option<String>,
) -> Self::ReadCollectionFuture;

// -----

type FindCollectionFuture: Future<Item = (CollectionPointer, Self), Error = (Self::Error, Self)>
+ 'static
+ Send;

/// Finds an item in a collection. The result will contain cursors to just before and after the item, if it exists.
fn find_collection(self, path: String, item: String) -> Self::ReadCollectionFuture;
fn find_collection(self, path: String, item: String) -> Self::FindCollectionFuture;

/// Finds all the collections containing a specific object.
fn read_collection_inverse(self, item: String) -> Self::ReadCollectionFuture;
// -----

/// The `Future` that is returned when writing into a collection.
type WriteCollectionFuture: Future<Item = Self, Error = (Self::Error, Self)> + 'static + Send;

/// Inserts an item into the back of the collection.
fn insert_collection(self, path: String, item: String) -> Self::WriteCollectionFuture;

// -----

type ReadCollectionInverseFuture: Future<
Item = (CollectionPointer, Self),
Error = (Self::Error, Self),
>
+ 'static
+ Send;

/// Finds all the collections containing a specific object.
fn read_collection_inverse(self, item: String) -> Self::ReadCollectionInverseFuture;

// -----

type RemoveCollectionFuture: Future<Item = Self, Error = (Self::Error, Self)> + 'static + Send;

/// Removes an item from the collection.
fn remove_collection(self, path: String, item: String) -> Self::WriteCollectionFuture;
fn remove_collection(self, path: String, item: String) -> Self::RemoveCollectionFuture;
}

#[derive(Debug)]
@@ -101,3 +130,39 @@ pub trait QueueStore: Debug + Send + Sized + 'static {

fn add(self, event: String, data: String) -> Self::MarkFuture;
}

impl QueueItem for () {
fn event(&self) -> &str {
panic!();
}

fn data(&self) -> &str {
panic!();
}
}

use futures::future;
use std::num::ParseIntError;
impl QueueStore for () {
type Item = ();
type Error = ParseIntError;
type GetItemFuture =
Box<Future<Item = (Option<Self::Item>, Self), Error = (Self::Error, Self)> + Send>;
type MarkFuture = Box<Future<Item = Self, Error = (Self::Error, Self)> + Send>;

fn get_item(self) -> Self::GetItemFuture {
Box::new(future::ok((None, ())))
}

fn mark_success(self, item: Self::Item) -> Self::MarkFuture {
Box::new(future::ok(()))
}

fn mark_failure(self, item: Self::Item) -> Self::MarkFuture {
Box::new(future::ok(()))
}

fn add(self, event: String, data: String) -> Self::MarkFuture {
Box::new(future::ok(()))
}
}

Loading…
Cancel
Save