From ba592794ded32532ce87228220b27814e9c48754 Mon Sep 17 00:00:00 2001 From: mikeee Date: Mon, 19 Aug 2024 21:18:41 +0100 Subject: [PATCH 1/2] fix: cleanup proto inception Signed-off-by: mikeee --- dapr/src/appcallback.rs | 24 ++++++------ dapr/src/client.rs | 50 ++++++++++++------------- dapr/src/lib.rs | 23 +++++++----- dapr/src/server/actor/context_client.rs | 2 +- dapr/src/server/appcallbackalpha.rs | 4 +- 5 files changed, 53 insertions(+), 50 deletions(-) diff --git a/dapr/src/appcallback.rs b/dapr/src/appcallback.rs index 87675ee..5b9edac 100644 --- a/dapr/src/appcallback.rs +++ b/dapr/src/appcallback.rs @@ -1,37 +1,37 @@ -use crate::dapr; -use crate::dapr::proto::runtime::v1::app_callback_server::AppCallback; -use crate::dapr::proto::{common, runtime}; use std::collections::HashMap; + use tonic::{Code, Request, Response, Status}; +use crate::proto::{common, runtime, runtime::v1::app_callback_server::AppCallback}; + /// InvokeRequest is the message to invoke a method with the data. -pub type InvokeRequest = dapr::proto::common::v1::InvokeRequest; +pub type InvokeRequest = common::v1::InvokeRequest; /// InvokeResponse is the response message inclduing data and its content type /// from app callback. -pub type InvokeResponse = dapr::proto::common::v1::InvokeResponse; +pub type InvokeResponse = common::v1::InvokeResponse; /// ListTopicSubscriptionsResponse is the message including the list of the subscribing topics. -pub type ListTopicSubscriptionsResponse = dapr::proto::runtime::v1::ListTopicSubscriptionsResponse; +pub type ListTopicSubscriptionsResponse = runtime::v1::ListTopicSubscriptionsResponse; /// TopicSubscription represents a topic and it's metadata (session id etc.) -pub type TopicSubscription = dapr::proto::runtime::v1::TopicSubscription; +pub type TopicSubscription = runtime::v1::TopicSubscription; /// TopicEventRequest message is compatiable with CloudEvent spec v1.0. -pub type TopicEventRequest = dapr::proto::runtime::v1::TopicEventRequest; +pub type TopicEventRequest = runtime::v1::TopicEventRequest; /// TopicEventResponse is response from app on published message -pub type TopicEventResponse = dapr::proto::runtime::v1::TopicEventResponse; +pub type TopicEventResponse = runtime::v1::TopicEventResponse; /// ListInputBindingsResponse is the message including the list of input bindings. -pub type ListInputBindingsResponse = dapr::proto::runtime::v1::ListInputBindingsResponse; +pub type ListInputBindingsResponse = runtime::v1::ListInputBindingsResponse; /// BindingEventRequest represents input bindings event. -pub type BindingEventRequest = dapr::proto::runtime::v1::BindingEventRequest; +pub type BindingEventRequest = runtime::v1::BindingEventRequest; /// BindingEventResponse includes operations to save state or /// send data to output bindings optionally. -pub type BindingEventResponse = dapr::proto::runtime::v1::BindingEventResponse; +pub type BindingEventResponse = runtime::v1::BindingEventResponse; impl ListTopicSubscriptionsResponse { /// Create `ListTopicSubscriptionsResponse` with a topic. diff --git a/dapr/src/client.rs b/dapr/src/client.rs index 0c34249..47e4a00 100644 --- a/dapr/src/client.rs +++ b/dapr/src/client.rs @@ -10,7 +10,7 @@ use tonic::codegen::tokio_stream; use tonic::{transport::Channel as TonicChannel, Request}; use tonic::{Status, Streaming}; -use crate::dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; +use crate::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; use crate::error::Error; #[derive(Clone)] @@ -603,6 +603,13 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient { Ok(dapr_v1::dapr_client::DaprClient::connect(addr).await?) } + async fn publish_event(&mut self, request: PublishEventRequest) -> Result<(), Error> { + self.publish_event(Request::new(request)) + .await? + .into_inner(); + Ok(()) + } + async fn invoke_service( &mut self, request: InvokeServiceRequest, @@ -623,13 +630,6 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient { .into_inner()) } - async fn publish_event(&mut self, request: PublishEventRequest) -> Result<(), Error> { - self.publish_event(Request::new(request)) - .await? - .into_inner(); - Ok(()) - } - async fn get_secret(&mut self, request: GetSecretRequest) -> Result { Ok(self.get_secret(Request::new(request)).await?.into_inner()) } @@ -648,6 +648,11 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient { Ok(self.get_state(Request::new(request)).await?.into_inner()) } + async fn save_state(&mut self, request: SaveStateRequest) -> Result<(), Error> { + self.save_state(Request::new(request)).await?.into_inner(); + Ok(()) + } + async fn query_state_alpha1( &mut self, request: QueryStateRequest, @@ -658,11 +663,6 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient { .into_inner()) } - async fn save_state(&mut self, request: SaveStateRequest) -> Result<(), Error> { - self.save_state(Request::new(request)).await?.into_inner(); - Ok(()) - } - async fn delete_state(&mut self, request: DeleteStateRequest) -> Result<(), Error> { self.delete_state(Request::new(request)).await?.into_inner(); Ok(()) @@ -875,39 +875,39 @@ pub type UnsubscribeConfigurationResponse = dapr_v1::UnsubscribeConfigurationRes pub type TonicClient = dapr_v1::dapr_client::DaprClient; /// Encryption gRPC request -pub type EncryptRequest = crate::dapr::proto::runtime::v1::EncryptRequest; +pub type EncryptRequest = crate::proto::runtime::v1::EncryptRequest; /// Decrypt gRPC request -pub type DecryptRequest = crate::dapr::proto::runtime::v1::DecryptRequest; +pub type DecryptRequest = crate::proto::runtime::v1::DecryptRequest; /// Encryption request options -pub type EncryptRequestOptions = crate::dapr::proto::runtime::v1::EncryptRequestOptions; +pub type EncryptRequestOptions = crate::proto::runtime::v1::EncryptRequestOptions; /// Decryption request options -pub type DecryptRequestOptions = crate::dapr::proto::runtime::v1::DecryptRequestOptions; +pub type DecryptRequestOptions = crate::proto::runtime::v1::DecryptRequestOptions; /// The basic job structure -pub type Job = crate::dapr::proto::runtime::v1::Job; +pub type Job = crate::proto::runtime::v1::Job; /// A request to schedule a job -pub type ScheduleJobRequest = crate::dapr::proto::runtime::v1::ScheduleJobRequest; +pub type ScheduleJobRequest = crate::proto::runtime::v1::ScheduleJobRequest; /// A response from a schedule job request -pub type ScheduleJobResponse = crate::dapr::proto::runtime::v1::ScheduleJobResponse; +pub type ScheduleJobResponse = crate::proto::runtime::v1::ScheduleJobResponse; /// A request to get a job -pub type GetJobRequest = crate::dapr::proto::runtime::v1::GetJobRequest; +pub type GetJobRequest = crate::proto::runtime::v1::GetJobRequest; /// A response from a get job request -pub type GetJobResponse = crate::dapr::proto::runtime::v1::GetJobResponse; +pub type GetJobResponse = crate::proto::runtime::v1::GetJobResponse; /// A request to delete a job -pub type DeleteJobRequest = crate::dapr::proto::runtime::v1::DeleteJobRequest; +pub type DeleteJobRequest = crate::proto::runtime::v1::DeleteJobRequest; /// A response from a delete job request -pub type DeleteJobResponse = crate::dapr::proto::runtime::v1::DeleteJobResponse; +pub type DeleteJobResponse = crate::proto::runtime::v1::DeleteJobResponse; -type StreamPayload = crate::dapr::proto::common::v1::StreamPayload; +type StreamPayload = crate::proto::common::v1::StreamPayload; impl From<(K, Vec)> for common_v1::StateItem where K: Into, diff --git a/dapr/src/lib.rs b/dapr/src/lib.rs index 7f8b53a..384ca64 100644 --- a/dapr/src/lib.rs +++ b/dapr/src/lib.rs @@ -13,17 +13,20 @@ pub mod appcallback; /// Module containing the 'Client' implementation. pub mod client; /// Module importing the Dapr runtime implementation. -pub mod dapr { - pub mod proto { - pub mod common { - pub mod v1 { - include!("dapr/dapr.proto.common.v1.rs"); - } +pub mod proto { + /// Module containing the common implementations. + + pub mod common { + /// Module containing the v1 implementations. + pub mod v1 { + include!("dapr/dapr.proto.common.v1.rs"); } - pub mod runtime { - pub mod v1 { - include!("dapr/dapr.proto.runtime.v1.rs"); - } + } + /// Module containing the runtime implementations. + pub mod runtime { + /// Module containing the v1 implementations. + pub mod v1 { + include!("dapr/dapr.proto.runtime.v1.rs"); } } } diff --git a/dapr/src/server/actor/context_client.rs b/dapr/src/server/actor/context_client.rs index 4d30d96..08d72d8 100644 --- a/dapr/src/server/actor/context_client.rs +++ b/dapr/src/server/actor/context_client.rs @@ -1,5 +1,5 @@ use crate::client::TonicClient; -use crate::dapr::proto::runtime::v1 as dapr_v1; +use crate::proto::runtime::v1 as dapr_v1; use crate::error::Error as DaprError; use prost_types::Any; use std::collections::HashMap; diff --git a/dapr/src/server/appcallbackalpha.rs b/dapr/src/server/appcallbackalpha.rs index 3a604f0..2e91a34 100644 --- a/dapr/src/server/appcallbackalpha.rs +++ b/dapr/src/server/appcallbackalpha.rs @@ -2,8 +2,8 @@ use std::collections::HashMap; use tonic::{Code, Request, Response, Status}; -use crate::dapr::proto::runtime; -use crate::dapr::proto::runtime::v1::app_callback_alpha_server::AppCallbackAlpha; +use crate::proto::runtime; +use crate::proto::runtime::v1::app_callback_alpha_server::AppCallbackAlpha; pub struct AppCallbackServiceAlpha { pub job_handlers: HashMap>, From 5f958291a931b153af1a7c16ba5f4f6c2d86c224 Mon Sep 17 00:00:00 2001 From: mikeee Date: Mon, 19 Aug 2024 21:30:10 +0100 Subject: [PATCH 2/2] refactor!: remove proto inception Signed-off-by: mikeee --- dapr/src/client.rs | 2 +- dapr/src/server/actor/context_client.rs | 2 +- examples/src/bindings/input.rs | 4 ++-- examples/src/invoke/grpc/server.rs | 2 +- examples/src/jobs/jobs.rs | 2 +- examples/src/pubsub/subscriber.rs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dapr/src/client.rs b/dapr/src/client.rs index 47e4a00..dca4673 100644 --- a/dapr/src/client.rs +++ b/dapr/src/client.rs @@ -10,8 +10,8 @@ use tonic::codegen::tokio_stream; use tonic::{transport::Channel as TonicChannel, Request}; use tonic::{Status, Streaming}; -use crate::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; use crate::error::Error; +use crate::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1}; #[derive(Clone)] pub struct Client(T); diff --git a/dapr/src/server/actor/context_client.rs b/dapr/src/server/actor/context_client.rs index 08d72d8..29027bb 100644 --- a/dapr/src/server/actor/context_client.rs +++ b/dapr/src/server/actor/context_client.rs @@ -1,6 +1,6 @@ use crate::client::TonicClient; -use crate::proto::runtime::v1 as dapr_v1; use crate::error::Error as DaprError; +use crate::proto::runtime::v1 as dapr_v1; use prost_types::Any; use std::collections::HashMap; use std::time::Duration; diff --git a/examples/src/bindings/input.rs b/examples/src/bindings/input.rs index f305fd6..9d102b5 100644 --- a/examples/src/bindings/input.rs +++ b/examples/src/bindings/input.rs @@ -1,7 +1,7 @@ use tonic::{transport::Server, Request, Response, Status}; -use dapr::dapr::proto::common::v1::{InvokeRequest, InvokeResponse}; -use dapr::dapr::proto::runtime::v1::{ +use dapr::proto::common::v1::{InvokeRequest, InvokeResponse}; +use dapr::proto::runtime::v1::{ app_callback_server::{AppCallback, AppCallbackServer}, BindingEventRequest, BindingEventResponse, ListInputBindingsResponse, ListTopicSubscriptionsResponse, TopicEventRequest, TopicEventResponse, diff --git a/examples/src/invoke/grpc/server.rs b/examples/src/invoke/grpc/server.rs index 1f5bd00..7a28706 100644 --- a/examples/src/invoke/grpc/server.rs +++ b/examples/src/invoke/grpc/server.rs @@ -1,6 +1,6 @@ use dapr::{ appcallback::*, - dapr::proto::runtime::v1::app_callback_server::{AppCallback, AppCallbackServer}, + proto::runtime::v1::app_callback_server::{AppCallback, AppCallbackServer}, }; use tonic::{transport::Server, Request, Response, Status}; diff --git a/examples/src/jobs/jobs.rs b/examples/src/jobs/jobs.rs index 6f724e1..c2d7d38 100644 --- a/examples/src/jobs/jobs.rs +++ b/examples/src/jobs/jobs.rs @@ -2,7 +2,7 @@ use std::time::Duration; use base64::prelude::*; use dapr::client::JobBuilder; -use dapr::dapr::proto::runtime::v1::{ +use dapr::proto::runtime::v1::{ app_callback_alpha_server::AppCallbackAlphaServer, JobEventRequest, JobEventResponse, }; use dapr::server::appcallbackalpha::{AppCallbackServiceAlpha, JobHandlerMethod}; diff --git a/examples/src/pubsub/subscriber.rs b/examples/src/pubsub/subscriber.rs index 3383041..5716cf8 100644 --- a/examples/src/pubsub/subscriber.rs +++ b/examples/src/pubsub/subscriber.rs @@ -2,7 +2,7 @@ use dapr_macros::topic; use tonic::transport::Server; use dapr::serde::{Deserialize, Serialize}; -use dapr::{appcallback::*, dapr::proto::runtime::v1::app_callback_server::AppCallbackServer}; +use dapr::{appcallback::*, proto::runtime::v1::app_callback_server::AppCallbackServer}; #[derive(Serialize, Deserialize, Debug)] struct Order {