use std::time::Duration;
#[derive(Debug)]
pub struct ServiceModel {
pub package: String,
pub service: String,
pub source_file: String,
pub default_task_queue: Option<String>,
pub workflows: Vec<WorkflowModel>,
pub signals: Vec<SignalModel>,
pub queries: Vec<QueryModel>,
pub updates: Vec<UpdateModel>,
pub activities: Vec<ActivityModel>,
}
#[derive(Debug)]
pub struct WorkflowModel {
pub rpc_method: String,
pub registered_name: String,
pub input_type: ProtoType,
pub output_type: ProtoType,
pub task_queue: Option<String>,
pub id_expression: Option<Vec<IdTemplateSegment>>,
pub id_reuse_policy: Option<IdReusePolicy>,
pub execution_timeout: Option<Duration>,
pub run_timeout: Option<Duration>,
pub task_timeout: Option<Duration>,
pub aliases: Vec<String>,
pub attached_signals: Vec<SignalRef>,
pub attached_queries: Vec<QueryRef>,
pub attached_updates: Vec<UpdateRef>,
}
#[derive(Debug, Clone)]
pub struct SignalRef {
pub rpc_method: String,
pub start: bool,
}
#[derive(Debug, Clone)]
pub struct QueryRef {
pub rpc_method: String,
}
#[derive(Debug, Clone)]
pub struct UpdateRef {
pub rpc_method: String,
pub start: bool,
pub validate: Option<bool>,
}
#[derive(Debug)]
pub struct SignalModel {
pub rpc_method: String,
pub registered_name: String,
pub input_type: ProtoType,
pub output_type: ProtoType,
}
#[derive(Debug)]
pub struct QueryModel {
pub rpc_method: String,
pub registered_name: String,
pub input_type: ProtoType,
pub output_type: ProtoType,
}
#[derive(Debug)]
pub struct UpdateModel {
pub rpc_method: String,
pub registered_name: String,
pub input_type: ProtoType,
pub output_type: ProtoType,
pub validate: bool,
}
#[derive(Debug)]
pub struct ActivityModel {
pub rpc_method: String,
pub registered_name: String,
pub input_type: ProtoType,
pub output_type: ProtoType,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProtoType {
pub full_name: String,
pub is_empty: bool,
}
impl ProtoType {
pub fn new(full_name: impl Into<String>) -> Self {
let full_name = full_name.into();
let normalised = full_name
.strip_prefix('.')
.unwrap_or(&full_name)
.to_string();
let is_empty = normalised == "google.protobuf.Empty";
Self {
full_name: normalised,
is_empty,
}
}
pub fn rust_name(&self) -> &str {
if self.is_empty {
return "()";
}
self.full_name.rsplit('.').next().unwrap_or(&self.full_name)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IdTemplateSegment {
Literal(String),
Field(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IdReusePolicy {
AllowDuplicate,
AllowDuplicateFailedOnly,
RejectDuplicate,
TerminateIfRunning,
}
impl IdReusePolicy {
pub fn rust_variant(self) -> &'static str {
match self {
Self::AllowDuplicate => "AllowDuplicate",
Self::AllowDuplicateFailedOnly => "AllowDuplicateFailedOnly",
Self::RejectDuplicate => "RejectDuplicate",
Self::TerminateIfRunning => "TerminateIfRunning",
}
}
}