diff --git a/Cargo.lock b/Cargo.lock index e7927028539d9..453248b5390c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11406,7 +11406,6 @@ dependencies = [ name = "turborepo-analytics" version = "0.1.0" dependencies = [ - "async-trait", "futures 0.3.30", "thiserror", "tokio", @@ -11421,7 +11420,6 @@ name = "turborepo-api-client" version = "0.1.0" dependencies = [ "anyhow", - "async-trait", "chrono", "http", "lazy_static", @@ -11814,7 +11812,6 @@ dependencies = [ name = "turborepo-telemetry" version = "0.1.0" dependencies = [ - "async-trait", "chrono", "config", "futures 0.3.30", diff --git a/crates/turborepo-analytics/Cargo.toml b/crates/turborepo-analytics/Cargo.toml index c74e17f54fd2f..e774443b9c545 100644 --- a/crates/turborepo-analytics/Cargo.toml +++ b/crates/turborepo-analytics/Cargo.toml @@ -10,7 +10,6 @@ license = "MPL-2.0" workspace = true [dependencies] -async-trait = { workspace = true } futures.workspace = true thiserror = { workspace = true } tokio = { workspace = true, features = ["full", "time"] } diff --git a/crates/turborepo-analytics/src/lib.rs b/crates/turborepo-analytics/src/lib.rs index dd721c70a6060..56486432f8f44 100644 --- a/crates/turborepo-analytics/src/lib.rs +++ b/crates/turborepo-analytics/src/lib.rs @@ -184,7 +184,6 @@ mod tests { time::Duration, }; - use async_trait::async_trait; use tokio::{ select, sync::{mpsc, mpsc::UnboundedReceiver}, @@ -207,7 +206,6 @@ mod tests { } } - #[async_trait] impl AnalyticsClient for DummyClient { async fn record_analytics( &self, diff --git a/crates/turborepo-api-client/Cargo.toml b/crates/turborepo-api-client/Cargo.toml index 4ddd001403dba..2e28f3a877d56 100644 --- a/crates/turborepo-api-client/Cargo.toml +++ b/crates/turborepo-api-client/Cargo.toml @@ -20,7 +20,6 @@ workspace = true [dependencies] anyhow = { workspace = true } -async-trait = { workspace = true } chrono = { workspace = true, features = ["serde"] } lazy_static = { workspace = true } regex = { workspace = true } diff --git a/crates/turborepo-api-client/src/analytics.rs b/crates/turborepo-api-client/src/analytics.rs index 11ffbc1903b47..d073b637c7f3e 100644 --- a/crates/turborepo-api-client/src/analytics.rs +++ b/crates/turborepo-api-client/src/analytics.rs @@ -1,19 +1,18 @@ -use async_trait::async_trait; +use std::future::Future; + use reqwest::Method; pub use turborepo_vercel_api::{AnalyticsEvent, CacheEvent, CacheSource}; use crate::{retry, APIAuth, APIClient, Error}; -#[async_trait] pub trait AnalyticsClient { - async fn record_analytics( + fn record_analytics( &self, api_auth: &APIAuth, events: Vec, - ) -> Result<(), Error>; + ) -> impl Future> + Send; } -#[async_trait] impl AnalyticsClient for APIClient { #[tracing::instrument(skip_all)] async fn record_analytics( diff --git a/crates/turborepo-api-client/src/lib.rs b/crates/turborepo-api-client/src/lib.rs index 6c32430e0b644..136e1e49fdb51 100644 --- a/crates/turborepo-api-client/src/lib.rs +++ b/crates/turborepo-api-client/src/lib.rs @@ -2,9 +2,8 @@ #![feature(error_generic_member_access)] #![deny(clippy::all)] -use std::{backtrace::Backtrace, env}; +use std::{backtrace::Backtrace, env, future::Future}; -use async_trait::async_trait; use lazy_static::lazy_static; use regex::Regex; pub use reqwest::Response; @@ -31,37 +30,47 @@ lazy_static! { Regex::new(r"(?i)(?:^|,) *authorization *(?:,|$)").unwrap(); } -#[async_trait] pub trait Client { - async fn get_user(&self, token: &str) -> Result; - async fn get_teams(&self, token: &str) -> Result; - async fn get_team(&self, token: &str, team_id: &str) -> Result>; + fn get_user(&self, token: &str) -> impl Future> + Send; + fn get_teams(&self, token: &str) -> impl Future> + Send; + fn get_team( + &self, + token: &str, + team_id: &str, + ) -> impl Future>> + Send; fn add_ci_header(request_builder: RequestBuilder) -> RequestBuilder; - async fn get_spaces(&self, token: &str, team_id: Option<&str>) -> Result; - async fn verify_sso_token(&self, token: &str, token_name: &str) -> Result; - async fn handle_403(response: Response) -> Error; + fn get_spaces( + &self, + token: &str, + team_id: Option<&str>, + ) -> impl Future> + Send; + fn verify_sso_token( + &self, + token: &str, + token_name: &str, + ) -> impl Future> + Send; + fn handle_403(response: Response) -> impl Future + Send; fn make_url(&self, endpoint: &str) -> Result; } -#[async_trait] pub trait CacheClient { - async fn get_artifact( + fn get_artifact( &self, hash: &str, token: &str, team_id: Option<&str>, team_slug: Option<&str>, method: Method, - ) -> Result>; - async fn fetch_artifact( + ) -> impl Future>> + Send; + fn fetch_artifact( &self, hash: &str, token: &str, team_id: Option<&str>, team_slug: Option<&str>, - ) -> Result>; + ) -> impl Future>> + Send; #[allow(clippy::too_many_arguments)] - async fn put_artifact( + fn put_artifact( &self, hash: &str, artifact_body: &[u8], @@ -70,26 +79,28 @@ pub trait CacheClient { token: &str, team_id: Option<&str>, team_slug: Option<&str>, - ) -> Result<()>; - async fn artifact_exists( + ) -> impl Future> + Send; + fn artifact_exists( &self, hash: &str, token: &str, team_id: Option<&str>, team_slug: Option<&str>, - ) -> Result>; - async fn get_caching_status( + ) -> impl Future>> + Send; + fn get_caching_status( &self, token: &str, team_id: Option<&str>, team_slug: Option<&str>, - ) -> Result; + ) -> impl Future> + Send; } -#[async_trait] pub trait TokenClient { - async fn get_metadata(&self, token: &str) -> Result; - async fn delete_token(&self, token: &str) -> Result<()>; + fn get_metadata( + &self, + token: &str, + ) -> impl Future> + Send; + fn delete_token(&self, token: &str) -> impl Future> + Send; } #[derive(Clone)] @@ -113,7 +124,6 @@ pub fn is_linked(api_auth: &Option) -> bool { .map_or(false, |api_auth| api_auth.is_linked()) } -#[async_trait] impl Client for APIClient { async fn get_user(&self, token: &str) -> Result { let url = self.make_url("/v2/user")?; @@ -262,7 +272,6 @@ impl Client for APIClient { } } -#[async_trait] impl CacheClient for APIClient { async fn get_artifact( &self, @@ -414,7 +423,6 @@ impl CacheClient for APIClient { } } -#[async_trait] impl TokenClient for APIClient { async fn get_metadata(&self, token: &str) -> Result { let endpoint = "/v5/user/tokens/current"; @@ -464,9 +472,9 @@ impl TokenClient for APIClient { message: body.error.message, }); } - return Err(Error::ForbiddenToken { + Err(Error::ForbiddenToken { url: self.make_url(endpoint)?.to_string(), - }); + }) } _ => Err(response.error_for_status().unwrap_err().into()), } @@ -516,9 +524,9 @@ impl TokenClient for APIClient { message: body.error.message, }); } - return Err(Error::ForbiddenToken { + Err(Error::ForbiddenToken { url: self.make_url(endpoint)?.to_string(), - }); + }) } _ => Err(response.error_for_status().unwrap_err().into()), } diff --git a/crates/turborepo-api-client/src/telemetry.rs b/crates/turborepo-api-client/src/telemetry.rs index 8e9a60fb853f8..e3f0466b39d9f 100644 --- a/crates/turborepo-api-client/src/telemetry.rs +++ b/crates/turborepo-api-client/src/telemetry.rs @@ -1,4 +1,5 @@ -use async_trait::async_trait; +use std::future::Future; + use reqwest::Method; use turborepo_vercel_api::telemetry::TelemetryEvent; @@ -6,17 +7,15 @@ use crate::{retry, AnonAPIClient, Error}; const TELEMETRY_ENDPOINT: &str = "/api/turborepo/v1/events"; -#[async_trait] pub trait TelemetryClient { - async fn record_telemetry( + fn record_telemetry( &self, events: Vec, telemetry_id: &str, session_id: &str, - ) -> Result<(), Error>; + ) -> impl Future> + Send; } -#[async_trait] impl TelemetryClient for AnonAPIClient { async fn record_telemetry( &self, diff --git a/crates/turborepo-auth/src/auth/login.rs b/crates/turborepo-auth/src/auth/login.rs index 08ca92baf2bb3..b27cfcb534e12 100644 --- a/crates/turborepo-auth/src/auth/login.rs +++ b/crates/turborepo-auth/src/auth/login.rs @@ -200,7 +200,6 @@ mod tests { } } - #[async_trait] impl Client for MockApiClient { async fn get_user(&self, token: &str) -> turborepo_api_client::Result { if token.is_empty() { @@ -269,7 +268,6 @@ mod tests { } } - #[async_trait] impl TokenClient for MockApiClient { async fn get_metadata( &self, @@ -301,7 +299,6 @@ mod tests { } } - #[async_trait] impl CacheClient for MockApiClient { async fn get_artifact( &self, diff --git a/crates/turborepo-auth/src/auth/logout.rs b/crates/turborepo-auth/src/auth/logout.rs index b5aa77c3e40aa..7b4c4de020194 100644 --- a/crates/turborepo-auth/src/auth/logout.rs +++ b/crates/turborepo-auth/src/auth/logout.rs @@ -82,7 +82,6 @@ impl LogoutOptions { mod tests { use std::backtrace::Backtrace; - use async_trait::async_trait; use reqwest::{RequestBuilder, Response}; use tempfile::tempdir; use turbopath::AbsoluteSystemPathBuf; @@ -100,7 +99,6 @@ mod tests { pub succeed_delete_request: bool, } - #[async_trait] impl Client for MockApiClient { async fn get_user(&self, _token: &str) -> turborepo_api_client::Result { unimplemented!("get_user") @@ -143,7 +141,6 @@ mod tests { } } - #[async_trait] impl TokenClient for MockApiClient { async fn delete_token(&self, _token: &str) -> turborepo_api_client::Result<()> { if self.succeed_delete_request { diff --git a/crates/turborepo-auth/src/auth/sso.rs b/crates/turborepo-auth/src/auth/sso.rs index eeca53e29ab78..7f626fe7fc9e8 100644 --- a/crates/turborepo-auth/src/auth/sso.rs +++ b/crates/turborepo-auth/src/auth/sso.rs @@ -191,7 +191,6 @@ mod tests { } } - #[async_trait] impl Client for MockApiClient { async fn get_user(&self, token: &str) -> turborepo_api_client::Result { if token.is_empty() { @@ -267,7 +266,6 @@ mod tests { } } - #[async_trait] impl TokenClient for MockApiClient { async fn get_metadata( &self, @@ -298,7 +296,6 @@ mod tests { } } - #[async_trait] impl CacheClient for MockApiClient { async fn get_artifact( &self, diff --git a/crates/turborepo-auth/src/lib.rs b/crates/turborepo-auth/src/lib.rs index 74461d8ae0273..6a157e9ae16b4 100644 --- a/crates/turborepo-auth/src/lib.rs +++ b/crates/turborepo-auth/src/lib.rs @@ -266,7 +266,6 @@ fn is_token_active(metadata: &ResponseTokenMetadata, current_time: u128) -> bool mod tests { use std::backtrace::Backtrace; - use async_trait::async_trait; use reqwest::{Method, Response}; use tempfile::tempdir; use turbopath::AbsoluteSystemPathBuf; @@ -396,7 +395,6 @@ mod tests { pub response: MockCachingResponse, } - #[async_trait] impl CacheClient for MockCacheClient { async fn get_artifact( &self, diff --git a/crates/turborepo-telemetry/Cargo.toml b/crates/turborepo-telemetry/Cargo.toml index ac256775e9184..ab81ee991ea7d 100644 --- a/crates/turborepo-telemetry/Cargo.toml +++ b/crates/turborepo-telemetry/Cargo.toml @@ -16,7 +16,6 @@ test-case = { workspace = true } turborepo-vercel-api-mock = { workspace = true } [dependencies] -async-trait = { workspace = true } chrono = { workspace = true, features = ["serde"] } config = { version = "0.13.4", default-features = false, features = ["json"] } futures = { workspace = true } diff --git a/crates/turborepo-telemetry/src/lib.rs b/crates/turborepo-telemetry/src/lib.rs index a0bfe1c99fe75..64633ea7f8d47 100644 --- a/crates/turborepo-telemetry/src/lib.rs +++ b/crates/turborepo-telemetry/src/lib.rs @@ -256,7 +256,6 @@ mod tests { time::Duration, }; - use async_trait::async_trait; use tokio::{ select, sync::{mpsc, mpsc::UnboundedReceiver}, @@ -281,7 +280,6 @@ mod tests { } } - #[async_trait] impl TelemetryClient for DummyClient { async fn record_telemetry( &self,