Skip to content

Commit

Permalink
fix: cleanup proto inception
Browse files Browse the repository at this point in the history
Signed-off-by: mikeee <[email protected]>
  • Loading branch information
mikeee committed Aug 19, 2024
1 parent 2c0aa5a commit ba59279
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 50 deletions.
24 changes: 12 additions & 12 deletions dapr/src/appcallback.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
50 changes: 25 additions & 25 deletions dapr/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -603,6 +603,13 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient<TonicChannel> {
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,
Expand All @@ -623,13 +630,6 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient<TonicChannel> {
.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<GetSecretResponse, Error> {
Ok(self.get_secret(Request::new(request)).await?.into_inner())
}
Expand All @@ -648,6 +648,11 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient<TonicChannel> {
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,
Expand All @@ -658,11 +663,6 @@ impl DaprInterface for dapr_v1::dapr_client::DaprClient<TonicChannel> {
.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(())
Expand Down Expand Up @@ -875,39 +875,39 @@ pub type UnsubscribeConfigurationResponse = dapr_v1::UnsubscribeConfigurationRes
pub type TonicClient = dapr_v1::dapr_client::DaprClient<TonicChannel>;

/// 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<K> From<(K, Vec<u8>)> for common_v1::StateItem
where
K: Into<String>,
Expand Down
23 changes: 13 additions & 10 deletions dapr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dapr/src/server/actor/context_client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions dapr/src/server/appcallbackalpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Box<dyn JobHandlerMethod + Send + Sync + 'static>>,
Expand Down

0 comments on commit ba59279

Please sign in to comment.