Skip to content

Commit

Permalink
CLI: update to latest codegen, add message-attempt support (and more)
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-onelson committed Dec 20, 2024
1 parent 4e4da58 commit 0be5bcd
Show file tree
Hide file tree
Showing 15 changed files with 541 additions and 93 deletions.
1 change: 1 addition & 0 deletions svix-cli/src/cli_types/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl From<ApplicationListOptions> for api::ApplicationListOptions {
Self {
limit,
iterator,

order: order.map(Into::into),
}
}
Expand Down
3 changes: 2 additions & 1 deletion svix-cli/src/cli_types/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl From<EndpointListOptions> for api::EndpointListOptions {
Self {
limit,
iterator,

order: order.map(Into::into),
}
}
}

#[derive(Args, Clone)]
pub struct EndpointStatsOptions {
/// Filter the range to data ending by this date
Expand All @@ -42,6 +42,7 @@ pub struct EndpointStatsOptions {
pub after: Option<DateTime<Utc>>,
}

#[allow(deprecated)]
impl From<EndpointStatsOptions> for api::EndpointStatsOptions {
fn from(EndpointStatsOptions { after, before }: EndpointStatsOptions) -> Self {
Self {
Expand Down
29 changes: 23 additions & 6 deletions svix-cli/src/cli_types/event_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::cli_types::Ordering;
use clap::Args;
use svix::api;

Expand All @@ -9,14 +10,13 @@ pub struct EventTypeListOptions {
/// The iterator returned from a prior invocation
#[arg(long)]
pub iterator: Option<String>,
// FIXME: This is missing from the Rust lib
// /// The sorting order of the returned items
// #[arg(long)]
// pub order: Option<Ordering>,
/// When `true` archived (deleted but not expunged) items are included in the response
/// The sorting order of the returned items
#[arg(long)]
pub order: Option<Ordering>,
/// When `true` archived (deleted but not expunged) items are included in the response.
#[arg(long)]
pub include_archived: Option<bool>,
/// When `true` the full item (including the schema) is included in the response
/// When `true` the full item (including the schema) is included in the response.
#[arg(long)]
pub with_content: Option<bool>,
}
Expand All @@ -26,15 +26,32 @@ impl From<EventTypeListOptions> for api::EventTypeListOptions {
EventTypeListOptions {
limit,
iterator,
order,
include_archived,
with_content,
}: EventTypeListOptions,
) -> Self {
Self {
limit,
iterator,

order: order.map(Into::into),
include_archived,
with_content,
}
}
}

// FIXME: need to get the options happening in the SDK for this
// #[derive(Args, Clone)]
// pub struct EventTypeDeleteOptions {
// /// By default event types are archived when "deleted". Passing this to `true` deletes them entirely.
// #[arg(long)]
// pub expunge: Option<bool>,
// }
//
// impl From<EventTypeDeleteOptions> for api::EventTypeDeleteOptions {
// fn from(EventTypeDeleteOptions { expunge }: EventTypeDeleteOptions) -> Self {
// Self { expunge }
// }
// }
10 changes: 5 additions & 5 deletions svix-cli/src/cli_types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ pub struct MessageListOptions {
/// The iterator returned from a prior invocation
#[arg(long)]
pub iterator: Option<String>,
/// Filter response based on the channel
/// Filter response based on the channel.
#[arg(long)]
pub channel: Option<String>,
/// Only include items created before a certain date
/// Only include items created before a certain date.
#[arg(long)]
pub before: Option<DateTime<Utc>>,
/// Only include items created after a certain date
/// Only include items created after a certain date.
#[arg(long)]
pub after: Option<DateTime<Utc>>,
/// When `true` message payloads are included in the response
/// When `true` message payloads are included in the response.
#[arg(long)]
pub with_content: Option<bool>,
/// Filter messages matching the provided tag
/// Filter messages matching the provided tag.
#[arg(long)]
pub tag: Option<String>,
/// Filter response based on the event type
Expand Down
250 changes: 250 additions & 0 deletions svix-cli/src/cli_types/message_attempt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
use chrono::{DateTime, Utc};
use clap::Args;
use svix::api;
use svix::api::{MessageStatus, StatusCodeClass};

#[derive(Args, Clone)]
pub struct MessageAttemptListByEndpointOptions {
/// Limit the number of returned items
#[arg(long)]
pub limit: Option<i32>,
/// The iterator returned from a prior invocation
#[arg(long)]
pub iterator: Option<String>,
/// Filter response based on the status of the attempt: Success (0), Pending (1), Failed (2), or Sending (3)
#[arg(long)]
pub status: Option<MessageStatus>,
/// Filter response based on the HTTP status code
#[arg(long)]
pub status_code_class: Option<StatusCodeClass>,
/// Filter response based on the channel
#[arg(long)]
pub channel: Option<String>,
/// Filter response based on the tag
#[arg(long)]
pub tag: Option<String>,
/// Only include items created before a certain date
#[arg(long)]
pub before: Option<DateTime<Utc>>,
/// Only include items created after a certain date
#[arg(long)]
pub after: Option<DateTime<Utc>>,
/// When `true` attempt content is included in the response
#[arg(long)]
pub with_content: Option<bool>,
/// When `true`, the message information is included in the response
#[arg(long)]
pub with_msg: Option<bool>,
/// Filter response based on the event type
#[arg(long)]
pub event_types: Option<Vec<String>>,
}

impl From<MessageAttemptListByEndpointOptions> for api::MessageAttemptListByEndpointOptions {
fn from(
MessageAttemptListByEndpointOptions {
limit,
iterator,
status,
status_code_class,
channel,
tag,
before,
after,
with_content,
with_msg,
event_types,
}: MessageAttemptListByEndpointOptions,
) -> Self {
Self {
limit,
iterator,
status,
status_code_class,
channel,
tag,
before: before.map(|dt| dt.to_rfc3339()),
after: after.map(|dt| dt.to_rfc3339()),
with_content,
with_msg,
event_types,
}
}
}

#[derive(Args, Clone)]
pub struct MessageAttemptCountByEndpointOptions {
/// Filter response based on the status of the attempt: Success (0), Pending (1), Failed (2), or Sending (3)
#[arg(long)]
pub status: Option<MessageStatus>,
/// Filter response based on the HTTP status code
#[arg(long)]
pub status_code_class: Option<StatusCodeClass>,
/// Filter response based on the channel
#[arg(long)]
pub channel: Option<String>,
/// Filter response based on the tag
#[arg(long)]
pub tag: Option<String>,
/// Only include items created before a certain date
#[arg(long)]
pub before: Option<DateTime<Utc>>,
/// Only include items created after a certain date
#[arg(long)]
pub after: Option<DateTime<Utc>>,
/// Filter response based on the event type
#[arg(long)]
pub event_types: Option<Vec<String>>,
}

#[derive(Args, Clone)]
pub struct MessageAttemptListByMsgOptions {
/// Limit the number of returned items
#[arg(long)]
pub limit: Option<i32>,
/// The iterator returned from a prior invocation
#[arg(long)]
pub iterator: Option<String>,
/// Filter response based on the status of the attempt: Success (0), Pending (1), Failed (2), or Sending (3)
#[arg(long)]
pub status: Option<MessageStatus>,
/// Filter response based on the HTTP status code
#[arg(long)]
pub status_code_class: Option<StatusCodeClass>,
/// Filter response based on the channel
#[arg(long)]
pub channel: Option<String>,
/// Filter response based on the tag
#[arg(long)]
pub tag: Option<String>,
/// Filter the attempts based on the attempted endpoint
#[arg(long)]
pub endpoint_id: Option<String>,
/// Only include items created before a certain date
#[arg(long)]
pub before: Option<DateTime<Utc>>,
/// Only include items created after a certain date
#[arg(long)]
pub after: Option<DateTime<Utc>>,
/// When `true` attempt content is included in the response
#[arg(long)]
pub with_content: Option<bool>,
/// Filter response based on the event type
#[arg(long)]
pub event_types: Option<Vec<String>>,
}

impl From<MessageAttemptListByMsgOptions> for api::MessageAttemptListByMsgOptions {
fn from(
MessageAttemptListByMsgOptions {
limit,
iterator,
status,
status_code_class,
channel,
tag,
endpoint_id,
before,
after,
with_content,
event_types,
}: MessageAttemptListByMsgOptions,
) -> Self {
Self {
limit,
iterator,
status,
status_code_class,
channel,
tag,
endpoint_id,
before: before.map(|dt| dt.to_rfc3339()),
after: after.map(|dt| dt.to_rfc3339()),
with_content,
event_types,
}
}
}

#[derive(Args, Clone)]
pub struct MessageAttemptListAttemptedMessagesOptions {
/// Limit the number of returned items
#[arg(long)]
pub limit: Option<i32>,
/// The iterator returned from a prior invocation
#[arg(long)]
pub iterator: Option<String>,
/// Filter response based on the channel
#[arg(long)]
pub channel: Option<String>,
/// Filter response based on the message tags
#[arg(long)]
pub tag: Option<String>,
/// Filter response based on the status of the attempt: Success (0), Pending (1), Failed (2), or Sending (3)
#[arg(long)]
pub status: Option<MessageStatus>,
/// Only include items created before a certain date
#[arg(long)]
pub before: Option<DateTime<Utc>>,
/// Only include items created after a certain date
#[arg(long)]
pub after: Option<DateTime<Utc>>,
/// When `true` message payloads are included in the response
#[arg(long)]
pub with_content: Option<bool>,
/// Filter response based on the event type
#[arg(long)]
pub event_types: Option<Vec<String>>,
}

impl From<MessageAttemptListAttemptedMessagesOptions>
for api::MessageAttemptListAttemptedMessagesOptions
{
fn from(
MessageAttemptListAttemptedMessagesOptions {
limit,
iterator,
channel,
tag,
status,
before,
after,
with_content,
event_types,
}: MessageAttemptListAttemptedMessagesOptions,
) -> Self {
Self {
limit,
iterator,
channel,
tag,
status,
before: before.map(|dt| dt.to_rfc3339()),
after: after.map(|dt| dt.to_rfc3339()),
with_content,
event_types,
}
}
}

#[derive(Args, Clone)]
pub struct MessageAttemptListAttemptedDestinationsOptions {
/// Limit the number of returned items
#[arg(long)]
pub limit: Option<i32>,
/// The iterator returned from a prior invocation
#[arg(long)]
pub iterator: Option<String>,
}

impl From<MessageAttemptListAttemptedDestinationsOptions>
for api::MessageAttemptListAttemptedDestinationsOptions
{
fn from(
MessageAttemptListAttemptedDestinationsOptions {
limit,iterator,
}: MessageAttemptListAttemptedDestinationsOptions,
) -> Self {
Self { limit, iterator }
}
}
1 change: 1 addition & 0 deletions svix-cli/src/cli_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod endpoint;
pub mod event_type;
pub mod integration;
pub mod message;
pub mod message_attempt;

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum Ordering {
Expand Down
8 changes: 3 additions & 5 deletions svix-cli/src/cmds/api/application.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::cli_types::application::ApplicationListOptions;
use crate::cli_types::PostOptions;
use crate::json::JsonOf;
use clap::{Args, Subcommand};
use colored_json::ColorMode;
use svix::api::{ApplicationIn, ApplicationPatch};

use crate::{
cli_types::{application::ApplicationListOptions, PostOptions},
json::JsonOf,
};

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down
Loading

0 comments on commit 0be5bcd

Please sign in to comment.