Skip to content

Commit

Permalink
fix: adapt to recent gRPC interface updates (#84)
Browse files Browse the repository at this point in the history
* `BasinMetadata` renamed to `BasinInfo`
* `ListStream` returns `StreamInfo`s instead of just string names
* `ReconfigureBasinResponse` includes `BasinConfig`
  • Loading branch information
shikhar authored Nov 26, 2024
1 parent d697575 commit 35cf031
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion proto
Submodule proto updated 1 files
+32 −10 s2/v1alpha/s2.proto
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl Client {
pub async fn create_basin(
&self,
req: types::CreateBasinRequest,
) -> Result<types::BasinMetadata, ClientError> {
) -> Result<types::BasinInfo, ClientError> {
self.inner
.send(CreateBasinServiceRequest::new(
self.inner.account_service_client(),
Expand Down Expand Up @@ -407,7 +407,7 @@ impl Client {
pub async fn reconfigure_basin(
&self,
req: types::ReconfigureBasinRequest,
) -> Result<(), ClientError> {
) -> Result<types::BasinConfig, ClientError> {
self.inner
.send_retryable(ReconfigureBasinServiceRequest::new(
self.inner.account_service_client(),
Expand Down
8 changes: 4 additions & 4 deletions src/service/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl CreateBasinServiceRequest {

impl ServiceRequest for CreateBasinServiceRequest {
type ApiRequest = api::CreateBasinRequest;
type Response = types::BasinMetadata;
type Response = types::BasinInfo;
type ApiResponse = api::CreateBasinResponse;
const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::IdempotencyUnknown;

Expand Down Expand Up @@ -176,7 +176,7 @@ impl ReconfigureBasinServiceRequest {

impl ServiceRequest for ReconfigureBasinServiceRequest {
type ApiRequest = api::ReconfigureBasinRequest;
type Response = ();
type Response = types::BasinConfig;
type ApiResponse = api::ReconfigureBasinResponse;
const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::Idempotent;

Expand All @@ -194,8 +194,8 @@ impl ServiceRequest for ReconfigureBasinServiceRequest {

fn parse_response(
&self,
_resp: tonic::Response<Self::ApiResponse>,
resp: tonic::Response<Self::ApiResponse>,
) -> Result<Self::Response, types::ConvertError> {
Ok(())
resp.into_inner().try_into()
}
}
57 changes: 43 additions & 14 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,16 @@ impl std::fmt::Display for BasinState {
#[sync_docs]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct BasinMetadata {
pub struct BasinInfo {
pub name: String,
pub scope: String,
pub cell: String,
pub state: BasinState,
}

impl From<BasinMetadata> for api::BasinMetadata {
fn from(value: BasinMetadata) -> Self {
let BasinMetadata {
impl From<BasinInfo> for api::BasinInfo {
fn from(value: BasinInfo) -> Self {
let BasinInfo {
name,
scope,
cell,
Expand All @@ -356,10 +356,10 @@ impl From<BasinMetadata> for api::BasinMetadata {
}
}

impl TryFrom<api::BasinMetadata> for BasinMetadata {
impl TryFrom<api::BasinInfo> for BasinInfo {
type Error = ConvertError;
fn try_from(value: api::BasinMetadata) -> Result<Self, Self::Error> {
let api::BasinMetadata {
fn try_from(value: api::BasinInfo) -> Result<Self, Self::Error> {
let api::BasinInfo {
name,
scope,
cell,
Expand All @@ -374,12 +374,12 @@ impl TryFrom<api::BasinMetadata> for BasinMetadata {
}
}

impl TryFrom<api::CreateBasinResponse> for BasinMetadata {
impl TryFrom<api::CreateBasinResponse> for BasinInfo {
type Error = ConvertError;
fn try_from(value: api::CreateBasinResponse) -> Result<Self, Self::Error> {
let api::CreateBasinResponse { basin } = value;
let basin = basin.ok_or("missing basin metadata")?;
basin.try_into()
let api::CreateBasinResponse { info } = value;
let info = info.ok_or("missing basin info")?;
info.try_into()
}
}

Expand Down Expand Up @@ -437,17 +437,37 @@ impl TryFrom<ListStreamsRequest> for api::ListStreamsRequest {
}
}

#[sync_docs]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct StreamInfo {
pub name: String,
pub created_at: u32,
pub deleted_at: Option<u32>,
}

impl From<api::StreamInfo> for StreamInfo {
fn from(value: api::StreamInfo) -> Self {
Self {
name: value.name,
created_at: value.created_at,
deleted_at: value.deleted_at,
}
}
}

#[sync_docs]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct ListStreamsResponse {
pub streams: Vec<String>,
pub streams: Vec<StreamInfo>,
pub has_more: bool,
}

impl From<api::ListStreamsResponse> for ListStreamsResponse {
fn from(value: api::ListStreamsResponse) -> Self {
let api::ListStreamsResponse { streams, has_more } = value;
let streams = streams.into_iter().map(Into::into).collect();
Self { streams, has_more }
}
}
Expand Down Expand Up @@ -563,7 +583,7 @@ impl TryFrom<ListBasinsRequest> for api::ListBasinsRequest {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct ListBasinsResponse {
pub basins: Vec<BasinMetadata>,
pub basins: Vec<BasinInfo>,
pub has_more: bool,
}

Expand All @@ -575,7 +595,7 @@ impl TryFrom<api::ListBasinsResponse> for ListBasinsResponse {
basins: basins
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<BasinMetadata>, ConvertError>>()?,
.collect::<Result<Vec<BasinInfo>, ConvertError>>()?,
has_more,
})
}
Expand Down Expand Up @@ -735,6 +755,15 @@ impl TryFrom<ReconfigureStreamRequest> for api::ReconfigureStreamRequest {
}
}

impl TryFrom<api::ReconfigureBasinResponse> for BasinConfig {
type Error = ConvertError;
fn try_from(value: api::ReconfigureBasinResponse) -> Result<Self, Self::Error> {
let api::ReconfigureBasinResponse { config } = value;
let config = config.ok_or("missing basin config")?;
config.try_into()
}
}

impl From<api::CheckTailResponse> for u64 {
fn from(value: api::CheckTailResponse) -> Self {
let api::CheckTailResponse { next_seq_num } = value;
Expand Down

0 comments on commit 35cf031

Please sign in to comment.