Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup proto inception #213

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 +10,8 @@ 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::error::Error;
use crate::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1};

#[derive(Clone)]
pub struct Client<T>(T);
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,6 +1,6 @@
use crate::client::TonicClient;
use crate::dapr::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;
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
4 changes: 2 additions & 2 deletions examples/src/bindings/input.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/src/invoke/grpc/server.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
2 changes: 1 addition & 1 deletion examples/src/jobs/jobs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

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};
Expand Down
2 changes: 1 addition & 1 deletion examples/src/pubsub/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading