chore: bump deps, drop async_trait where possible

This commit is contained in:
əlemi 2024-09-19 15:56:22 +02:00
parent 095e3e7716
commit 52b93ba539
Signed by: alemi
GPG key ID: A4895B84D311642C
18 changed files with 372 additions and 382 deletions

677
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -34,7 +34,7 @@ tracing-subscriber = "0.3"
clap = { version = "4.5", features = ["derive"] }
signal-hook = "0.3"
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
tokio = { version = "1.35", features = ["full"] } # TODO slim this down
tokio = { version = "1.40", features = ["full"] } # TODO slim this down
sea-orm = { version = "1.0", features = ["sqlx-sqlite", "sqlx-postgres", "runtime-tokio-rustls"] }
futures = "0.3"

View file

@ -226,7 +226,6 @@ impl worker::StopToken for CancellationToken {
}
}
#[sea_orm::prelude::async_trait::async_trait] // ahahaha we avoid this???
impl routes::ShutdownToken for CancellationToken {
async fn event(mut self) {
self.0.changed().await.warn_failed("cancellation token channel closed, stopping...");

View file

@ -16,7 +16,7 @@ upub = { path = "../core" }
tracing = "0.1"
serde_json = "1"
sha256 = "1.5"
uuid = { version = "1.8", features = ["v4"] }
uuid = { version = "1.10", features = ["v4"] }
chrono = { version = "0.4", features = ["serde"] }
openssl = "0.10" # TODO handle pubkeys with a smaller crate
clap = { version = "4.5", features = ["derive"] }

View file

@ -1,6 +1,6 @@
[package]
name = "upub"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = [ "alemi <me@alemi.dev>" ]
description = "core inner workings of upub"
@ -20,10 +20,10 @@ hmac = "0.12"
openssl = "0.10" # TODO handle pubkeys with a smaller crate
base64 = "0.22"
chrono = { version = "0.4", features = ["serde"] }
uuid = { version = "1.8", features = ["v4"] }
uuid = { version = "1.10", features = ["v4"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_default = "0.1"
serde_default = "0.2"
serde-inline-default = "0.2"
toml = "0.8"
uriproxy = { path = "../../utils/uriproxy" }

View file

@ -1,12 +1,10 @@
use sea_orm::{ConnectionTrait, PaginatorTrait};
#[async_trait::async_trait]
pub trait AnyQuery {
async fn any(self, db: &impl ConnectionTrait) -> Result<bool, sea_orm::DbErr>;
}
#[async_trait::async_trait]
impl<T : sea_orm::EntityTrait> AnyQuery for sea_orm::Select<T>
where
T::Model : Sync,
@ -17,7 +15,6 @@ where
}
}
#[async_trait::async_trait]
impl<T : sea_orm::SelectorTrait + Send + Sync> AnyQuery for sea_orm::Selector<T> {
async fn any(self, db: &impl ConnectionTrait) -> Result<bool, sea_orm::DbErr> {
Ok(self.count(db).await? > 0)

View file

@ -3,7 +3,6 @@ use std::collections::{hash_map::Entry, HashMap};
use sea_orm::{ConnectionTrait, DbErr, EntityTrait, FromQueryResult, ModelTrait, QueryFilter};
use super::RichActivity;
#[async_trait::async_trait]
pub trait BatchFillable: Sized {
async fn with_batched<E>(self, tx: &impl ConnectionTrait) -> Result<Self, DbErr>
where
@ -13,7 +12,6 @@ pub trait BatchFillable: Sized {
}
#[async_trait::async_trait]
impl BatchFillable for Vec<RichActivity> {
// TODO 3 iterations... can we make it in less passes?
async fn with_batched<E>(mut self, tx: &impl ConnectionTrait) -> Result<Self, DbErr>
@ -47,7 +45,6 @@ impl BatchFillable for Vec<RichActivity> {
}
}
#[async_trait::async_trait]
impl BatchFillable for RichActivity {
async fn with_batched<E>(mut self, tx: &impl ConnectionTrait) -> Result<Self, DbErr>
where
@ -117,12 +114,10 @@ use crate::selector::rich::{RichHashtag, RichMention};
}
}
#[async_trait::async_trait]
pub trait BatchFillableAcceptor<B> {
async fn accept(&mut self, batch: B, tx: &impl ConnectionTrait) -> Result<(), DbErr>;
}
#[async_trait::async_trait]
impl BatchFillableAcceptor<Vec<crate::model::attachment::Model>> for super::RichActivity {
async fn accept(&mut self, batch: Vec<crate::model::attachment::Model>, _tx: &impl ConnectionTrait) -> Result<(), DbErr> {
self.attachments = Some(batch);
@ -130,7 +125,6 @@ use crate::selector::rich::{RichHashtag, RichMention};
}
}
#[async_trait::async_trait]
impl BatchFillableAcceptor<Vec<crate::model::hashtag::Model>> for super::RichActivity {
async fn accept(&mut self, batch: Vec<crate::model::hashtag::Model>, _tx: &impl ConnectionTrait) -> Result<(), DbErr> {
self.hashtags = Some(batch.into_iter().map(|x| RichHashtag { hash: x }).collect());
@ -138,7 +132,6 @@ use crate::selector::rich::{RichHashtag, RichMention};
}
}
#[async_trait::async_trait]
impl BatchFillableAcceptor<Vec<crate::model::mention::Model>> for super::RichActivity {
async fn accept(&mut self, batch: Vec<crate::model::mention::Model>, tx: &impl ConnectionTrait) -> Result<(), DbErr> {
// TODO batch load users from mentions rather than doing for loop

View file

@ -5,13 +5,11 @@ use sea_orm::{ActiveValue::{NotSet, Set}, ColumnTrait, ConnectionTrait, DbErr, E
use crate::traits::fetch::Fetcher;
#[async_trait::async_trait]
pub trait Addresser {
async fn deliver(&self, to: Vec<String>, aid: &str, from: &str, tx: &impl ConnectionTrait) -> Result<(), DbErr>;
async fn address(&self, (activity, object): (Option<&crate::model::activity::Model>, Option<&crate::model::object::Model>), tx: &impl ConnectionTrait) -> Result<(), DbErr>;
async fn address(&self, activity: Option<&crate::model::activity::Model>, object: Option<&crate::model::object::Model>, tx: &impl ConnectionTrait) -> Result<(), DbErr>;
}
#[async_trait::async_trait]
impl Addresser for crate::Context {
async fn deliver(&self, to: Vec<String>, aid: &str, from: &str, tx: &impl ConnectionTrait) -> Result<(), DbErr> {
let to = expand_addressing(to, None, tx).await?;
@ -56,7 +54,7 @@ impl Addresser for crate::Context {
Ok(())
}
async fn address(&self, (activity, object): (Option<&crate::model::activity::Model>, Option<&crate::model::object::Model>), tx: &impl ConnectionTrait) -> Result<(), DbErr> {
async fn address(&self, activity: Option<&crate::model::activity::Model>, object: Option<&crate::model::object::Model>, tx: &impl ConnectionTrait) -> Result<(), DbErr> {
match (activity, object) {
(None, None) => Ok(()),
(Some(activity), None) => {

View file

@ -2,7 +2,6 @@ use sea_orm::{ActiveValue::{NotSet, Set}, DbErr, EntityTrait};
use crate::ext::JsonVec;
#[async_trait::async_trait]
pub trait Administrable {
async fn register_user(
&self,
@ -15,7 +14,6 @@ pub trait Administrable {
) -> Result<(), DbErr>;
}
#[async_trait::async_trait]
impl Administrable for crate::Context {
async fn register_user(
&self,

View file

@ -396,7 +396,7 @@ impl Fetcher for crate::Context {
}
let activity_model = self.insert_activity(activity, tx).await?;
self.address((Some(&activity_model), None), tx).await?;
self.address(Some(&activity_model), None, tx).await?;
Ok(activity_model)
}
@ -458,17 +458,15 @@ async fn resolve_object_r(ctx: &crate::Context, object: serde_json::Value, depth
}
let object_model = ctx.insert_object(object, tx).await?;
ctx.address((None, Some(&object_model)), tx).await?;
ctx.address(None, Some(&object_model), tx).await?;
Ok(object_model)
}
#[async_trait::async_trait]
pub trait Fetchable : Sync + Send {
async fn fetch(&mut self, ctx: &crate::Context) -> Result<&mut Self, RequestError>;
}
#[async_trait::async_trait]
impl Fetchable for apb::Node<serde_json::Value> {
async fn fetch(&mut self, ctx: &crate::Context) -> Result<&mut Self, RequestError> {
if let apb::Node::Link(uri) = self {

View file

@ -15,13 +15,11 @@ pub enum NormalizerError {
DbErr(#[from] sea_orm::DbErr),
}
#[async_trait::async_trait]
pub trait Normalizer {
async fn insert_object(&self, obj: impl apb::Object, tx: &impl ConnectionTrait) -> Result<crate::model::object::Model, NormalizerError>;
async fn insert_activity(&self, act: impl apb::Activity, tx: &impl ConnectionTrait) -> Result<crate::model::activity::Model, NormalizerError>;
}
#[async_trait::async_trait]
impl Normalizer for crate::Context {
async fn insert_object(&self, object: impl apb::Object, tx: &impl ConnectionTrait) -> Result<crate::model::object::Model, NormalizerError> {

View file

@ -29,12 +29,10 @@ pub enum ProcessorError {
PullError(#[from] crate::traits::fetch::RequestError),
}
#[async_trait::async_trait]
pub trait Processor {
async fn process(&self, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError>;
}
#[async_trait::async_trait]
impl Processor for crate::Context {
async fn process(&self, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> {
// TODO we could process Links and bare Objects maybe, but probably out of AP spec?
@ -80,7 +78,7 @@ pub async fn create(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
let object_model = ctx.insert_object(object_node, tx).await?;
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), Some(&object_model)), tx).await?;
ctx.address(Some(&activity_model), Some(&object_model), tx).await?;
for uid in notified {
if !ctx.is_local(&uid) { continue }
@ -126,7 +124,7 @@ pub async fn like(ctx: &crate::Context, activity: impl apb::Activity, tx: &Datab
if likes_local_object {
activity_model.to.0.push(obj.attributed_to.clone().unwrap_or_default());
}
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
// TODO check that object author is in this like addressing!!! otherwise skip notification
if let Some(ref attributed_to) = obj.attributed_to {
@ -167,7 +165,7 @@ pub async fn dislike(ctx: &crate::Context, activity: impl apb::Activity, tx: &Da
// dislikes without addressing are "silent dislikes", process them but dont store activity
if !activity.addressed().is_empty() {
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
// TODO check that object author is in this like addressing!!! otherwise skip notification
if let Some(ref attributed_to) = obj.attributed_to {
@ -192,7 +190,7 @@ pub async fn follow(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
.ok_or(ProcessorError::Incomplete)?;
let target_actor = ctx.fetch_user(activity.object().id()?, tx).await?;
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
if ctx.is_local(&target_actor.id) {
crate::Query::notify(activity_model.internal, target_actor.internal)
@ -256,7 +254,7 @@ pub async fn accept(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
}
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
if ctx.is_local(&follow_activity.actor) {
if let Some(actor_internal) = crate::model::actor::Entity::ap_to_internal(&follow_activity.actor, tx).await? {
@ -315,7 +313,7 @@ pub async fn reject(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
}
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
// TODO most software doesn't show this, but i think instead we should?? if someone rejects it's
// better to know it clearly rather than not knowing if it got lost and maybe retry (being more
@ -347,7 +345,7 @@ pub async fn delete(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
// so that also remote "secret" deletes dont get stored
if !activity.addressed().is_empty() {
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
}
// TODO we should delete notifications from CREATEs related to objects we deleted
tracing::debug!("deleted '{oid}'");
@ -406,7 +404,7 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
// remote documents change, there's the "updated" field, just want the most recent version
if ctx.is_local(&actor_id) {
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
}
tracing::debug!("{} updated {}", actor_id, oid);
@ -493,7 +491,7 @@ pub async fn undo(ctx: &crate::Context, activity: impl apb::Activity, tx: &Datab
// so that also remote "secret" undos dont get stored
if !activity.addressed().is_empty() {
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
}
if let Some(internal) = crate::model::activity::Entity::ap_to_internal(undone_activity.id()?, tx).await? {
@ -569,7 +567,7 @@ pub async fn announce(ctx: &crate::Context, activity: impl apb::Activity, tx: &D
// idk!!!!
if actor.actor_type == apb::ActorType::Person || ctx.is_local(&actor.id) {
let activity_model = ctx.insert_activity(activity, tx).await?;
ctx.address((Some(&activity_model), None), tx).await?;
ctx.address(Some(&activity_model), None, tx).await?;
if let Some(ref attributed_to) = object.attributed_to {
if ctx.is_local(attributed_to) {

View file

@ -20,7 +20,7 @@ serde_json = "1"
upub = { path = "../core/" }
jrd = "0.1"
tracing = "0.1"
tokio = { version = "1.35", features = ["full"] } # TODO slim this down
tokio = { version = "1.40", features = ["full"] } # TODO slim this down
reqwest = { version = "0.12", features = ["json"] }
axum = "0.7"
tower-http = { version = "0.5", features = ["cors", "trace"] }

View file

@ -62,7 +62,6 @@ impl Identity {
pub struct AuthIdentity(pub Identity);
#[axum::async_trait]
impl<S> FromRequestParts<S> for AuthIdentity
where
upub::Context: FromRef<S>,

View file

@ -59,7 +59,6 @@ pub async fn serve(ctx: upub::Context, bind: String, shutdown: impl ShutdownToke
Ok(())
}
#[axum::async_trait]
pub trait ShutdownToken: Sync + Send + 'static {
async fn event(self);
}

View file

@ -18,7 +18,7 @@ serde_json = "1"
sea-orm = "1.0"
regex = "1.10"
chrono = { version = "0.4", features = ["serde"] }
tokio = { version = "1.35", features = ["full"] } # TODO slim this down
tokio = { version = "1.40", features = ["full"] } # TODO slim this down
reqwest = { version = "0.12", features = ["json"] }
apb = { path = "../../apb", features = ["unstructured", "orm", "activitypub-fe", "activitypub-counters", "litepub", "ostatus", "toot"] }
mdhtml = { path = "../../utils/mdhtml/" }

View file

@ -29,14 +29,12 @@ pub enum JobError {
pub type JobResult<T> = Result<T, JobError>;
#[async_trait::async_trait]
pub trait JobDispatcher : Sized {
async fn poll(&self, filter: Option<model::job::JobType>) -> JobResult<Option<model::job::Model>>;
async fn lock(&self, job_internal: i64) -> JobResult<bool>;
async fn run(self, concurrency: usize, poll_interval: u64, job_filter: Option<model::job::JobType>, stop: impl crate::StopToken);
}
#[async_trait::async_trait]
impl JobDispatcher for Context {
async fn poll(&self, filter: Option<model::job::JobType>) -> JobResult<Option<model::job::Model>> {
let mut s = model::job::Entity::find()

View file

@ -12,7 +12,7 @@ repository = "https://git.alemi.dev/upub.git"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
lazy_static = "1.4"
lazy_static = "1.5"
cookie = "0.18"
base64 = "0.22"
tracing = "0.1"
@ -21,9 +21,9 @@ tracing-subscriber-wasm = "0.1"
console_error_panic_hook = "0.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_default = "0.1"
serde_default = "0.2"
serde-inline-default = "0.2"
dashmap = "5.5"
dashmap = "6.1"
leptos = { version = "0.6", features = ["csr", "tracing"] }
leptos_router = { version = "0.6", features = ["csr"] }
leptos-use = { version = "0.10", features = ["serde"] }
@ -34,6 +34,6 @@ mdhtml = { path = "../utils/mdhtml/" }
futures = "0.3.30"
chrono = { version = "0.4", features = ["serde"] }
jrd = "0.1"
tld = "2.35"
tld = "2.36"
web-sys = { version = "0.3", features = ["Screen"] }
regex = "1.10.5"
regex = "1.10.6"