diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index b869555..c8c494a 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -45,7 +45,7 @@ jobs: ${{ runner.os }}-cargo-build- - name: Build the project - run: cargo build --workspace --all-targets + run: cargo build --workspace --all-targets --features "serde/derive" - name: Run tests run: cargo test --workspace --all-targets diff --git a/Cargo.lock b/Cargo.lock index 98b1290..e21af0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,7 +107,7 @@ dependencies = [ [[package]] name = "serverless_workflow_builders" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.3" dependencies = [ "serde_json", "serde_yaml", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "serverless_workflow_core" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.3" dependencies = [ "serde", "serde_derive", diff --git a/builders/Cargo.toml b/builders/Cargo.toml index ea0c1f0..5315040 100644 --- a/builders/Cargo.toml +++ b/builders/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serverless_workflow_builders" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.3" edition = "2021" authors = ["The Serverless Workflow Authors "] description = "Contains services used to build ServerlessWorkflow workflow definitions programatically" @@ -12,6 +12,6 @@ keywords = ["serverless-workflow", "sdk", "builders"] categories = ["config", "parsing", "data-structures", "api-bindings"] [dependencies] -serverless_workflow_core = { path = "../core", version = "1.0.0-alpha6" } +serverless_workflow_core = { path = "../core", version = "1.0.0-alpha6.3" } serde_json = "1.0" serde_yaml = "0.9" \ No newline at end of file diff --git a/builders/src/lib.rs b/builders/src/lib.rs index f955bfd..e110667 100644 --- a/builders/src/lib.rs +++ b/builders/src/lib.rs @@ -3,7 +3,7 @@ pub mod services; #[cfg(test)] mod unit_tests { - use serverless_workflow_core::models::any::*; + use serde_json::Value; use serverless_workflow_core::models::duration::*; use serverless_workflow_core::models::error::OneOfErrorDefinitionOrReference; use crate::services::workflow::WorkflowBuilder; @@ -33,16 +33,16 @@ mod unit_tests { let password = "fake-password"; let call_task_name = "call-task"; let call_function_name = "fake-function"; - let call_task_with: HashMap = vec![ - ("key1".to_string(), AnyValue::String("value1".to_string())), - ("key2".to_string(), AnyValue::String("value2".to_string()))] + let call_task_with: HashMap = vec![ + ("key1".to_string(), Value::String("value1".to_string())), + ("key2".to_string(), Value::String("value2".to_string()))] .into_iter() .collect(); let do_task_name = "do-task"; let emit_task_name = "emit-task"; - let emit_event_attributes: HashMap = vec![ - ("key1".to_string(), AnyValue::String("value1".to_string())), - ("key2".to_string(), AnyValue::String("value2".to_string()))] + let emit_event_attributes: HashMap = vec![ + ("key1".to_string(), Value::String("value1".to_string())), + ("key2".to_string(), Value::String("value2".to_string()))] .into_iter() .collect(); let for_task_name = "for-task"; @@ -53,7 +53,7 @@ mod unit_tests { let listen_task_name = "listen-task"; let raise_task_name = "raise-task-name"; let raise_error_type = "error-type"; - let raise_error_status = AnyValue::Int16(400); + let raise_error_status = json!(400); let raise_error_title = "error-title"; let raise_error_detail = "error-detail"; let raise_error_instance = "error-instance"; @@ -82,11 +82,11 @@ mod unit_tests { let workflow_namespace = "workflow-namespace"; let workflow_name = "workflow-name"; let workflow_version = "workflow-version"; - let workflow_input = AnyValue::Json(json!({"hello": "world"})); + let workflow_input = json!({"hello": "world"}); let set_task_name = "set-task-name"; - let set_task_variables : HashMap = vec![ - ("var1-name".to_string(), AnyValue::String("var1-value".to_string())), - ("var2-name".to_string(), AnyValue::UInt64(69))] + let set_task_variables : HashMap = vec![ + ("var1-name".to_string(), json!("var1-value".to_string())), + ("var2-name".to_string(), json!(69))] .into_iter() .collect(); let switch_task_name = "switch-task-name"; @@ -95,9 +95,9 @@ mod unit_tests { let switch_case_then = "continue"; let try_task_name = "try-task-name"; let catch_when = "catch-when"; - let catch_errors_attributes: HashMap = vec![ - ("var1-name".to_string(), AnyValue::String("var1-value".to_string())), - ("var2-name".to_string(), AnyValue::UInt64(69))] + let catch_errors_attributes: HashMap = vec![ + ("var1-name".to_string(), json!("var1-value".to_string())), + ("var2-name".to_string(), json!(69))] .into_iter() .collect(); let retry_except_when = "retry-except-when"; @@ -154,7 +154,7 @@ mod unit_tests { task.listen() .to(|e|{ e.one() - .with("key", AnyValue::String("value".to_string())); + .with("key", Value::String("value".to_string())); }); }) .do_(raise_task_name, |task| { diff --git a/builders/src/services/task.rs b/builders/src/services/task.rs index 24f6003..a0e3017 100644 --- a/builders/src/services/task.rs +++ b/builders/src/services/task.rs @@ -1,12 +1,17 @@ use crate::services::authentication::*; -use serverless_workflow_core::models::any::*; +use crate::services::timeout::*; +use serde_json::Value; use serverless_workflow_core::models::duration::*; use serverless_workflow_core::models::error::*; use serverless_workflow_core::models::event::*; +use serverless_workflow_core::models::input::*; use serverless_workflow_core::models::map::*; +use serverless_workflow_core::models::output::*; use serverless_workflow_core::models::resource::*; use serverless_workflow_core::models::retry::*; +use serverless_workflow_core::models::schema::*; use serverless_workflow_core::models::task::*; +use serverless_workflow_core::models::timeout::*; use std::collections::HashMap; /// Represents the service used to build TaskDefinitions @@ -211,6 +216,39 @@ pub enum TaskDefinitionBuilder{ Wait(WaitTaskDefinitionBuilder) } +/// Defines functionnality common to all TaskDefinitionBuilder implementations +pub trait TaskDefinitionBuilderBase { + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self; + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self; + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder); + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder); + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder); + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder); + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self; + + /// Builds the configured TaskDefinition + fn build(self) -> TaskDefinition; + +} + /// Represents the service used to build CallTaskDefinitions pub struct CalltaskDefinitionBuilder{ task: CallTaskDefinition @@ -223,7 +261,7 @@ impl CalltaskDefinitionBuilder { } /// Adds a new argument to call the function with - pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{ + pub fn with(&mut self, name: &str, value: Value) -> &mut Self{ if self.task.with.is_none(){ self.task.with = Some(HashMap::new()); } @@ -234,13 +272,71 @@ impl CalltaskDefinitionBuilder { } /// Sets the arguments to call the function with - pub fn with_arguments(&mut self, arguments: HashMap) -> &mut Self{ + pub fn with_arguments(&mut self, arguments: HashMap) -> &mut Self{ self.task.with = Some(arguments); self } + +} +impl TaskDefinitionBuilderBase for CalltaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } /// Builds the configures CallTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Call(self.task) } @@ -266,9 +362,67 @@ impl DoTaskDefinitionBuilder { self.task.do_.add(name.to_string(), task); self } + +} +impl TaskDefinitionBuilderBase for DoTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configures DoTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Do(self.task) } @@ -285,8 +439,66 @@ impl EmitTaskDefinitionBuilder { Self { task: EmitTaskDefinition::new(EventEmissionDefinition::new(event)) } } +} +impl TaskDefinitionBuilderBase for EmitTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configures DoTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Emit(self.task) } @@ -331,8 +543,66 @@ impl ForTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for ForTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configured ForTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::For(self.task) } @@ -359,8 +629,66 @@ impl ForkTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for ForkTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configured ForkTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Fork(self.task) } @@ -387,8 +715,75 @@ impl ListenTaskDefinitionBuilder{ self } + /// Configures the iterator used to process the consumed events + pub fn foreach(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut SubscriptionIteratorDefinitionBuilder){ + let mut builder = SubscriptionIteratorDefinitionBuilder::new(); + setup(&mut builder); + self.task.foreach = Some(builder.build()); + self + } + +} +impl TaskDefinitionBuilderBase for ListenTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds the configured ListenTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Listen(self.task) } @@ -396,6 +791,7 @@ impl ListenTaskDefinitionBuilder{ /// Represents the service used to build RaiseTaskDefinitions pub struct RaiseTaskDefinitionBuilder{ + common: TaskDefinitionFields, builder: Option, reference: Option } @@ -403,7 +799,7 @@ impl RaiseTaskDefinitionBuilder{ /// Initializes a new RaiseTaskDefinitionBuilder pub fn new() -> Self{ - Self { builder: None, reference: None } + Self { common: TaskDefinitionFields::new(), builder: None, reference: None } } /// Sets the error to raise @@ -423,8 +819,66 @@ impl RaiseTaskDefinitionBuilder{ self.reference = Some(reference.to_string()); } +} +impl TaskDefinitionBuilderBase for RaiseTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.common.then = Some(directive.to_string()); + self + } + /// Builds the configured RaiseTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ let mut task = RaiseTaskDefinition::default(); if let Some(builder) = self.builder { let error = builder.build(); @@ -436,6 +890,7 @@ impl RaiseTaskDefinitionBuilder{ else{ panic!("The error to raise must be configured"); } + task.common = self.common; TaskDefinition::Raise(task) } @@ -443,13 +898,14 @@ impl RaiseTaskDefinitionBuilder{ /// Represents the service used to build RunTaskDefinitions pub struct RunTaskDefinitionBuilder{ + common: TaskDefinitionFields, builder : Option } impl RunTaskDefinitionBuilder{ /// Initializes a new RunTaskDefinitionBuilder pub fn new() -> Self{ - Self{ builder: None } + Self{ common: TaskDefinitionFields::new(), builder: None } } /// Configures the task to run the specified container @@ -496,15 +952,74 @@ impl RunTaskDefinitionBuilder{ } } +} +impl TaskDefinitionBuilderBase for RunTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.common.then = Some(directive.to_string()); + self + } + /// Builds the configured RunTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ if let Some(builder) = self.builder { - let process = match builder { + let mut process = match builder { ProcessDefinitionBuilder::Container(builder) => builder.build(), ProcessDefinitionBuilder::Script(builder) => builder.build(), ProcessDefinitionBuilder::Shell(builder) => builder.build(), ProcessDefinitionBuilder::Workflow(builder) => builder.build() }; + process.common = self.common; TaskDefinition::Run(process) } else{ @@ -526,22 +1041,80 @@ impl SetTaskDefinitionBuilder{ } /// Sets the specified variable - pub fn variable(&mut self, name: &str, value: AnyValue) -> &mut Self{ + pub fn variable(&mut self, name: &str, value: Value) -> &mut Self{ self.task.set.insert(name.to_string(), value); self } /// Configures the task to set the specified variables - pub fn variables(&mut self, variables: HashMap) -> &mut Self{ + pub fn variables(&mut self, variables: HashMap) -> &mut Self{ self.task.set = variables; self } +} +impl TaskDefinitionBuilderBase for SetTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds a new SetTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Set(self.task) } - + } /// Represents the service used to build SwitchTaskDefinitions @@ -565,8 +1138,66 @@ impl SwitchTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for SwitchTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds a new SwitchTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Switch(self.task) } @@ -601,8 +1232,66 @@ impl TryTaskDefinitionBuilder{ self } +} +impl TaskDefinitionBuilderBase for TryTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } + /// Builds a new TryTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Try(self.task) } @@ -618,9 +1307,67 @@ impl WaitTaskDefinitionBuilder { pub fn new(duration: OneOfDurationOrIso8601Expression) -> Self{ Self { task: WaitTaskDefinition::new(duration) } } + +} +impl TaskDefinitionBuilderBase for WaitTaskDefinitionBuilder{ + + /// Configures the task to build to run only if the specified condition matches + fn if_(&mut self, condition: &str) -> &mut Self{ + self.task.common.if_ = Some(condition.to_string()); + self + } + + /// Sets the task's timeout + fn with_timeout_reference(&mut self, reference: &str) -> &mut Self{ + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Reference(reference.to_string())); + self + } + + /// Sets the task's timeout + fn with_timeout(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TimeoutDefinitionBuilder){ + let mut builder = TimeoutDefinitionBuilder::new(); + setup(&mut builder); + let timeout = builder.build(); + self.task.common.timeout = Some(OneOfTimeoutDefinitionOrReference::Timeout(timeout)); + self + } + + /// Configures the task's input + fn with_input(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut InputDataModelDefinitionBuilder){ + let mut builder = InputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.input = Some(builder.build()); + self + } + + /// Configures the task's output + fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.output = Some(builder.build()); + self + } + + /// Configures the task's export + fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.task.common.export = Some(builder.build()); + self + } + + /// Configures the task to build to then execute the specified flow directive + fn then(&mut self, directive: &str) -> &mut Self{ + self.task.common.then = Some(directive.to_string()); + self + } /// Builds the configures DoTaskDefinition - pub fn build(self) -> TaskDefinition{ + fn build(self) -> TaskDefinition{ TaskDefinition::Wait(self.task) } @@ -638,13 +1385,13 @@ impl EventDefinitionBuilder{ } /// Adds a new attribute to the event - pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{ + pub fn with(&mut self, name: &str, value: Value) -> &mut Self{ self.event.with.insert(name.to_string(), value); self } /// Sets the event's attributes - pub fn with_attributes(&mut self, attributes: HashMap) -> &mut Self{ + pub fn with_attributes(&mut self, attributes: HashMap) -> &mut Self{ self.event.with = attributes; self } @@ -814,7 +1561,7 @@ impl EventFilterDefinitionBuilder{ } /// Adds a new attribute to filter events by - pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{ + pub fn with(&mut self, name: &str, value: Value) -> &mut Self{ if self.filter.with.is_none(){ self.filter.with = Some(HashMap::new()); } @@ -825,7 +1572,7 @@ impl EventFilterDefinitionBuilder{ } /// Sets a name/value mapping of the attributes to filter events by - pub fn with_attributes(&mut self, attributes: HashMap) -> &mut Self{ + pub fn with_attributes(&mut self, attributes: HashMap) -> &mut Self{ self.filter.with = Some(attributes); self } @@ -837,6 +1584,63 @@ impl EventFilterDefinitionBuilder{ } +/// Represents the service used to build SubscriptionIteratorDefinitions +pub struct SubscriptionIteratorDefinitionBuilder{ + iterator: SubscriptionIteratorDefinition +} +impl SubscriptionIteratorDefinitionBuilder{ + + /// Initializes a new SubscriptionIteratorDefinitionBuilder + pub fn new() -> Self{ + Self { iterator: SubscriptionIteratorDefinition::new() } + } + + /// Sets the name of the variable used to store the item being enumerated + pub fn with_item(&mut self, variable: &str) -> &mut Self{ + self.iterator.item = Some(variable.to_string()); + self + } + + /// Sets the name of the variable used to store the index of the item being enumerated + pub fn at(&mut self, variable: &str) -> &mut Self{ + self.iterator.at = Some(variable.to_string()); + self + } + + /// Configures the tasks to run for each consumd event/message + pub fn do_(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut TaskDefinitionMapBuilder){ + let mut builder = TaskDefinitionMapBuilder::new(); + setup(& mut builder); + self.iterator.do_ = Some(builder.build()); + self + } + + /// Configures the data each iteration outputs + pub fn with_output(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.iterator.output = Some(builder.build()); + self + } + + /// Configures the data exported with each iteration + pub fn with_export(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut OutputDataModelDefinitionBuilder){ + let mut builder = OutputDataModelDefinitionBuilder::new(); + setup(&mut builder); + self.iterator.export = Some(builder.build()); + self + } + + /// Buils the configures SubscriptionIteratorDefinition + pub fn build(self) -> SubscriptionIteratorDefinition{ + self.iterator + } + +} + /// Represents the service used to build ErrorDefinition pub struct ErrorDefinitionBuilder{ error: ErrorDefinition @@ -855,7 +1659,7 @@ impl ErrorDefinitionBuilder{ } /// Sets the error's status - pub fn with_status(&mut self, status: AnyValue) -> &mut Self{ + pub fn with_status(&mut self, status: Value) -> &mut Self{ self.error.status = status; self } @@ -1148,7 +1952,7 @@ impl WorkflowProcessDefinitionBuilder{ } /// Sets the input of the workflow to run - pub fn with_input(&mut self, input: AnyValue) -> &mut Self{ + pub fn with_input(&mut self, input: Value) -> &mut Self{ self.process.input = Some(input); self } @@ -1347,7 +2151,7 @@ impl ErrroFilterDefinitionBuilder{ } /// Adds a new attribute filter - pub fn with(&mut self, name: &str, value: AnyValue) -> &mut Self{ + pub fn with(&mut self, name: &str, value: Value) -> &mut Self{ if self.filter.with.is_none(){ self.filter.with = Some(HashMap::new()); } @@ -1358,7 +2162,7 @@ impl ErrroFilterDefinitionBuilder{ } /// Sets a name/value mapping of the attributes to filter errors by - pub fn with_attributes(&mut self, attributes: HashMap) -> &mut Self{ + pub fn with_attributes(&mut self, attributes: HashMap) -> &mut Self{ self.filter.with = Some(attributes); self } @@ -1658,4 +2462,100 @@ impl JitterDefinitionBuilder{ self.jitter } +} + +/// Represents the service used to build InputDataModelDefinitions +pub struct InputDataModelDefinitionBuilder{ + input : InputDataModelDefinition +} +impl InputDataModelDefinitionBuilder{ + + /// Initializes a new InputDataModelDefinitionBuilder + pub fn new() -> Self{ + Self{ input: InputDataModelDefinition::default() } + } + + /// Configures the input schema + pub fn with_schema(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut SchemaDefinitionBuilder){ + let mut builder = SchemaDefinitionBuilder::new(); + setup(&mut builder); + self.input.schema = Some(builder.build()); + self + } + + /// Configures the expression used to filter the input + pub fn from(&mut self, expression: Value) -> &mut Self{ + self.input.from = Some(expression); + self + } + + /// Builds the configured InputDataModelDefinition + pub fn build(self) -> InputDataModelDefinition{ + self.input + } + +} + +/// Represents the service used to build OutputDataModelDefinitions +pub struct OutputDataModelDefinitionBuilder{ + output : OutputDataModelDefinition +} +impl OutputDataModelDefinitionBuilder{ + + /// Initializes a new OutputDataModelDefinitionBuilder + pub fn new() -> Self{ + Self{ output: OutputDataModelDefinition::default() } + } + + /// Sets a runtime expression, if any, used to output specific data to the scope data + pub fn as_(&mut self, expression: Value) -> &mut Self{ + self.output.as_ = Some(expression); + self + } + + /// Builds the configured OutputDataModelDefinition + pub fn build(self) -> OutputDataModelDefinition{ + self.output + } + +} + +/// Represents the service used to build SchemaDefinitions +pub struct SchemaDefinitionBuilder{ + schema: SchemaDefinition +} +impl SchemaDefinitionBuilder{ + + /// Initializes a new SchemaDefinitionBuilder + pub fn new() -> Self{ + Self { schema: SchemaDefinition::default() } + } + + /// Sets the schema format + pub fn with_format(&mut self, format: &str) -> &mut Self{ + self.schema.format = format.to_string(); + self + } + + /// Sets the schema resource + pub fn with_resource(&mut self, setup: F) -> &mut Self + where F: FnOnce(&mut ExternalResourceDefinitionBuilder){ + let mut builder = ExternalResourceDefinitionBuilder::new(); + setup(&mut builder); + self.schema.resource = Some(builder.build()); + self + } + + /// Sets the schema document + pub fn with_document(&mut self, document: Value) -> &mut Self{ + self.schema.document = Some(document); + self + } + + /// Builds the configured SchemaDefinition + pub fn build(self) -> SchemaDefinition{ + self.schema + } + } \ No newline at end of file diff --git a/core/Cargo.toml b/core/Cargo.toml index 6a30ded..589be9d 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serverless_workflow_core" -version = "1.0.0-alpha6" +version = "1.0.0-alpha6.3" edition = "2021" authors = ["The Serverless Workflow Authors "] description = "Contains Serverless Workflow DSL models" diff --git a/core/src/lib.rs b/core/src/lib.rs index 749c030..36532e9 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -16,14 +16,20 @@ mod unit_tests { let title = Some("fake-title".to_string()); let summary = Some("fake-summary".to_string()); let document = WorkflowDefinitionMetadata::new(namespace, name, version, title.clone(), summary.clone(), None); + let mut call_task = CallTaskDefinition::new("http", None, Some(true)); + call_task.common.then = Some("continue".to_string()); + let do_task = DoTaskDefinition::new(Map::from(vec![("set".to_string(), TaskDefinition::Wait(WaitTaskDefinition::new(OneOfDurationOrIso8601Expression::Duration(Duration::from_milliseconds(200)))))])); let mut workflow = WorkflowDefinition::new(document); workflow.do_ = Map::new(); - workflow.do_.add("callTask".to_string(), TaskDefinition::Call(CallTaskDefinition::new("http", None, Some(true)))); - workflow.do_.add("doTask".to_string(), TaskDefinition::Do(DoTaskDefinition::new(Map::from(vec![("set".to_string(), TaskDefinition::Wait(WaitTaskDefinition::new(OneOfDurationOrIso8601Expression::Duration(Duration::default()))))])))); + workflow.do_.add("callTask".to_string(), TaskDefinition::Call(call_task)); + workflow.do_.add("doTask".to_string(), TaskDefinition::Do(do_task)); let json_serialization_result = serde_json::to_string_pretty(&workflow); let yaml_serialization_result = serde_yaml::to_string(&workflow); assert!(json_serialization_result.is_ok(), "JSON Serialization failed: {:?}", json_serialization_result.err()); assert!(yaml_serialization_result.is_ok(), "YAML Serialization failed: {:?}", yaml_serialization_result.err()); + if let Result::Ok(yaml) = yaml_serialization_result{ + println!("{}", yaml) + } assert_eq!(workflow.document.namespace, namespace); assert_eq!(workflow.document.name, name); assert_eq!(workflow.document.version, version); diff --git a/core/src/models/any.rs b/core/src/models/any.rs deleted file mode 100644 index 2a974d4..0000000 --- a/core/src/models/any.rs +++ /dev/null @@ -1,31 +0,0 @@ -use serde_derive::{Deserialize, Serialize}; -use serde_json::Value as JsonValue; -use serde_yaml::Value as YamlValue; - -/// Represents any possible value -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(untagged)] -pub enum AnyValue { - String(String), - Bool(bool), - Int8(i8), - Int16(i16), - Int32(i32), - Int64(i64), - UInt8(u8), - UInt16(u16), - UInt32(u32), - UInt64(u64), - Float32(f32), - Float64(f64), - Vec(Vec), - HashMap(std::collections::HashMap), - Json(JsonValue), - Yaml(YamlValue) -} -impl Default for AnyValue { - fn default() -> Self { - // Choose a default variant. For example, default to an empty Uri. - AnyValue::String(String::new()) - } -} \ No newline at end of file diff --git a/core/src/models/error.rs b/core/src/models/error.rs index ee8686f..946fc63 100644 --- a/core/src/models/error.rs +++ b/core/src/models/error.rs @@ -1,5 +1,5 @@ use serde_derive::{Deserialize, Serialize}; -use crate::models::any::*; +use serde_json::Value; /// Represents the definition an error to raise #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] @@ -15,7 +15,7 @@ pub struct ErrorDefinition{ /// Gets/sets the status code produced by the described error #[serde(rename = "status")] - pub status: AnyValue, + pub status: Value, /// Gets/sets a human-readable explanation specific to this occurrence of the error. #[serde(rename = "detail", skip_serializing_if = "Option::is_none")] @@ -29,7 +29,7 @@ pub struct ErrorDefinition{ impl ErrorDefinition{ /// Initializes a new ErrorDefinition - pub fn new(type_: &str, title: &str, status: AnyValue, detail: Option, instance: Option) -> Self{ + pub fn new(type_: &str, title: &str, status: Value, detail: Option, instance: Option) -> Self{ Self { type_: type_.to_string(), title: title.to_string(), diff --git a/core/src/models/event.rs b/core/src/models/event.rs index fac9c82..8e69434 100644 --- a/core/src/models/event.rs +++ b/core/src/models/event.rs @@ -1,6 +1,6 @@ use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; use std::collections::HashMap; -use crate::models::any::*; /// Represents the configuration of an event consumption strategy #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] @@ -30,7 +30,7 @@ pub struct EventFilterDefinition{ /// Gets/sets a name/value mapping of the attributes filtered events must define. Supports both regular expressions and runtime expressions #[serde(rename = "with", skip_serializing_if = "Option::is_none")] - pub with : Option>, + pub with : Option>, /// Gets/sets a name/definition mapping of the correlation to attempt when filtering events. #[serde(rename = "correlate", skip_serializing_if = "Option::is_none")] @@ -66,11 +66,11 @@ pub struct EventDefinition{ /// Gets/sets a key/value mapping of the attributes of the configured event #[serde(rename = "with")] - pub with: HashMap + pub with: HashMap } impl EventDefinition { - pub fn new(with: HashMap) -> Self{ + pub fn new(with: HashMap) -> Self{ Self{ with } diff --git a/core/src/models/input.rs b/core/src/models/input.rs index 5099d4d..0fd4efa 100644 --- a/core/src/models/input.rs +++ b/core/src/models/input.rs @@ -1,5 +1,5 @@ use serde_derive::{Deserialize, Serialize}; -use crate::models::any::*; +use serde_json::Value; use crate::models::schema::*; /// Represents the definition of an input data model @@ -12,6 +12,6 @@ pub struct InputDataModelDefinition{ /// Gets/sets a runtime expression, if any, used to build the workflow or task input data based on both input and scope data #[serde(rename = "from", skip_serializing_if = "Option::is_none")] - pub from : Option + pub from : Option } \ No newline at end of file diff --git a/core/src/models/map.rs b/core/src/models/map.rs index 44e0d16..ac08657 100644 --- a/core/src/models/map.rs +++ b/core/src/models/map.rs @@ -1,10 +1,9 @@ use serde::{Serialize, Deserialize}; -use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; use std::hash::Hash; /// Represents an ordered key/value map array -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)] #[serde(bound( serialize = "TKey: Serialize, TValue: Serialize", deserialize = "TKey: for<'d> Deserialize<'d> + Eq + Hash + Clone + PartialEq, TValue: for<'d> Deserialize<'d> + Clone + PartialEq" diff --git a/core/src/models/mod.rs b/core/src/models/mod.rs index 8abb65b..557475d 100644 --- a/core/src/models/mod.rs +++ b/core/src/models/mod.rs @@ -1,4 +1,3 @@ -pub mod any; pub mod authentication; pub mod catalog; pub mod duration; diff --git a/core/src/models/output.rs b/core/src/models/output.rs index 0afbc25..bf90c44 100644 --- a/core/src/models/output.rs +++ b/core/src/models/output.rs @@ -1,5 +1,5 @@ use serde_derive::{Deserialize, Serialize}; -use crate::models::any::*; +use serde_json::Value; use crate::models::schema::*; /// Represents the definition of an output data model @@ -12,6 +12,6 @@ pub struct OutputDataModelDefinition{ /// Gets/sets a runtime expression, if any, used to output specific data to the scope data #[serde(rename = "as", skip_serializing_if = "Option::is_none")] - pub as_: Option + pub as_: Option } \ No newline at end of file diff --git a/core/src/models/schema.rs b/core/src/models/schema.rs index d8d310c..2998af1 100644 --- a/core/src/models/schema.rs +++ b/core/src/models/schema.rs @@ -1,5 +1,5 @@ use serde_derive::{Deserialize, Serialize}; -use crate::models::any::*; +use serde_json::Value; use crate::models::resource::*; /// Provvides the default schema format @@ -32,6 +32,6 @@ pub struct SchemaDefinition{ /// Gets/sets the inline definition of the schema to use. Required if has not been set. #[serde(rename = "document", skip_serializing_if = "Option::is_none")] - pub document : Option + pub document : Option } \ No newline at end of file diff --git a/core/src/models/task.rs b/core/src/models/task.rs index 553a9ee..544de34 100644 --- a/core/src/models/task.rs +++ b/core/src/models/task.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use serde_derive::{Deserialize, Serialize}; -use crate::models::any::*; +use serde_json::Value; use crate::models::duration::*; use crate::models::event::*; use crate::models::error::*; @@ -9,6 +9,9 @@ use crate::models::input::*; use crate::models::resource::*; use crate::models::retry::*; +use super::output::OutputDataModelDefinition; +use super::timeout::OneOfTimeoutDefinitionOrReference; + /// Enumerates all supported task types pub struct TaskType; impl TaskType { @@ -82,11 +85,66 @@ pub enum TaskDefinition{ } /// A trait that all task definitions must implement -pub trait TypedTaskDefinition { +pub trait TaskDefinitionBase { /// Gets the task's type fn task_type(&self) -> &str; } +/// Holds the fields common to all tasks +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct TaskDefinitionFields{ + + /// Gets/sets a runtime expression, if any, used to determine whether or not the execute the task in the current context + #[serde(rename = "if", skip_serializing_if = "Option::is_none")] + pub if_: Option, + + /// Gets/sets the definition, if any, of the task's input data + #[serde(rename = "input", skip_serializing_if = "Option::is_none")] + pub input: Option, + + /// Gets/sets the definition, if any, of the task's output data + #[serde(rename = "output", skip_serializing_if = "Option::is_none")] + pub output: Option, + + /// Gets/sets the optional configuration for exporting data within the task's context + #[serde(rename = "export", skip_serializing_if = "Option::is_none")] + pub export: Option, + + /// Gets/sets the task's timeout, if any + #[serde(rename = "timeout", skip_serializing_if = "Option::is_none")] + pub timeout: Option, + + /// Gets/sets the flow directive to be performed upon completion of the task + #[serde(rename = "then", skip_serializing_if = "Option::is_none")] + pub then: Option, + + /// Gets/sets a key/value mapping of additional information associated with the task + #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")] + pub metadata: Option> + +} +impl Default for TaskDefinitionFields{ + fn default() -> Self { + TaskDefinitionFields::new() + } +} +impl TaskDefinitionFields{ + + /// Initializes a new TaskDefinitionFields + pub fn new() -> Self{ + Self { + if_: None, + input: None, + output: None, + export: None, + timeout: None, + then: None, + metadata: None + } + } + +} + /// Represents the definition of a task used to call a predefined function #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] pub struct CallTaskDefinition{ @@ -97,26 +155,34 @@ pub struct CallTaskDefinition{ /// Gets/sets a key/value mapping of the call's arguments, if any #[serde(rename = "with", skip_serializing_if = "Option::is_none")] - pub with: Option>, + pub with: Option>, /// Gets/sets a boolean indicating whether or not to wait for the called function to return. Defaults to true #[serde(rename = "await", skip_serializing_if = "Option::is_none")] - pub await_: Option + pub await_: Option, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for CallTaskDefinition { +impl TaskDefinitionBase for CallTaskDefinition { fn task_type(&self) -> &str { TaskType::CALL } } impl CallTaskDefinition { - pub fn new(call: &str, with: Option>, await_: Option) -> Self{ + + /// Initializes a new CalltaskDefinition + pub fn new(call: &str, with: Option>, await_: Option) -> Self{ Self { call: call.to_string(), with, - await_ + await_, + common: TaskDefinitionFields::new() } } + } /// Represents the configuration of a task that is composed of multiple subtasks to run sequentially @@ -125,20 +191,28 @@ pub struct DoTaskDefinition{ /// Gets/sets a name/definition mapping of the subtasks to perform sequentially #[serde(rename = "do")] - pub do_: Map + pub do_: Map, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for DoTaskDefinition { +impl TaskDefinitionBase for DoTaskDefinition { fn task_type(&self) -> &str { TaskType::DO } } impl DoTaskDefinition { + + /// Initializes a new CalltaskDefinition pub fn new(do_: Map) -> Self{ Self { - do_ + do_, + common: TaskDefinitionFields::new() } } + } /// Represents the configuration of a task used to emit an event @@ -147,18 +221,24 @@ pub struct EmitTaskDefinition{ /// Gets/sets the configuration of an event's emission #[serde(rename = "emit")] - pub emit: EventEmissionDefinition + pub emit: EventEmissionDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields, } -impl TypedTaskDefinition for EmitTaskDefinition { +impl TaskDefinitionBase for EmitTaskDefinition { fn task_type(&self) -> &str { TaskType::EMIT } } impl EmitTaskDefinition { + /// Initializes a new EmitTaskDefinition pub fn new(emit: EventEmissionDefinition) -> Self{ Self { - emit + emit, + common: TaskDefinitionFields::new() } } } @@ -196,20 +276,26 @@ pub struct ForTaskDefinition{ /// Gets/sets the tasks to perform for each item in the collection #[serde(rename = "do")] - pub do_: Map + pub do_: Map, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for ForTaskDefinition { +impl TaskDefinitionBase for ForTaskDefinition { fn task_type(&self) -> &str { TaskType::FOR } } impl ForTaskDefinition { + /// Initializes a new ForTaskDefinition pub fn new(for_: ForLoopDefinition, do_: Map, while_: Option) -> Self{ Self { for_, while_, - do_ + do_, + common: TaskDefinitionFields::new() } } } @@ -252,18 +338,24 @@ pub struct ForkTaskDefinition{ /// Gets/sets the configuration of the branches to perform concurrently #[serde(rename = "fork")] - pub fork: BranchingDefinition + pub fork: BranchingDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for ForkTaskDefinition { +impl TaskDefinitionBase for ForkTaskDefinition { fn task_type(&self) -> &str { TaskType::FORK } } impl ForkTaskDefinition { + /// Initializes a new ForkTaskDefinition pub fn new(fork: BranchingDefinition) -> Self{ Self { - fork + fork, + common: TaskDefinitionFields::new() } } } @@ -296,18 +388,29 @@ pub struct ListenTaskDefinition{ /// Gets/sets the configuration of the listener to use #[serde(rename = "listen")] - pub listen: ListenerDefinition + pub listen: ListenerDefinition, + + ///Gets/sets the configuration of the iterator, if any, for processing each consumed event + #[serde(rename = "foreach")] + pub foreach: Option, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for ListenTaskDefinition { +impl TaskDefinitionBase for ListenTaskDefinition { fn task_type(&self) -> &str { TaskType::LISTEN } } impl ListenTaskDefinition { + /// Initializes a new ListenTaskDefinition pub fn new(listen: ListenerDefinition) -> Self{ Self { - listen + listen, + foreach: None, + common: TaskDefinitionFields::new() } } } @@ -318,13 +421,18 @@ pub struct ListenerDefinition{ /// Gets/sets the listener's target #[serde(rename = "to")] - pub to: EventConsumptionStrategyDefinition + pub to: EventConsumptionStrategyDefinition, + + /// Gets/sets a string that specifies how events are read during the listen operation + #[serde(rename = "read")] + pub read: Option } impl ListenerDefinition { pub fn new(to: EventConsumptionStrategyDefinition) -> Self{ Self{ - to + to, + read: None } } } @@ -335,18 +443,24 @@ pub struct RaiseTaskDefinition{ /// Gets/sets the definition of the error to raise #[serde(rename = "raise")] - pub raise: RaiseErrorDefinition + pub raise: RaiseErrorDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for RaiseTaskDefinition { +impl TaskDefinitionBase for RaiseTaskDefinition { fn task_type(&self) -> &str { TaskType::RAISE } } impl RaiseTaskDefinition { + /// Initializes a new RaiseTaskDefinition pub fn new(raise: RaiseErrorDefinition) -> Self{ Self{ - raise + raise, + common: TaskDefinitionFields::new() } } } @@ -375,18 +489,24 @@ pub struct RunTaskDefinition{ /// Gets/sets the configuration of the process to execute #[serde(rename = "run")] - pub run: ProcessTypeDefinition + pub run: ProcessTypeDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for RunTaskDefinition { +impl TaskDefinitionBase for RunTaskDefinition { fn task_type(&self) -> &str { TaskType::RUN } } impl RunTaskDefinition { + /// Initializes a new RunTaskDefinition pub fn new(run: ProcessTypeDefinition) -> Self{ Self { - run + run, + common: TaskDefinitionFields::new() } } } @@ -617,11 +737,11 @@ pub struct WorkflowProcessDefinition{ /// Gets/sets the data, if any, to pass as input to the workflow to execute. The value should be validated against the target workflow's input schema, if specified #[serde(rename = "input", skip_serializing_if = "Option::is_none")] - pub input: Option + pub input: Option } impl WorkflowProcessDefinition { - pub fn new(namespace: &str, name: &str, version: &str, input: Option) -> Self{ + pub fn new(namespace: &str, name: &str, version: &str, input: Option) -> Self{ Self { namespace: namespace.to_string(), name: name.to_string(), @@ -637,18 +757,24 @@ pub struct SetTaskDefinition{ /// Gets/sets the data to set #[serde(rename = "set")] - pub set: HashMap + pub set: HashMap, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for SetTaskDefinition { +impl TaskDefinitionBase for SetTaskDefinition { fn task_type(&self) -> &str { TaskType::SET } } impl SetTaskDefinition { + /// Initializes a new SetTaskDefinition pub fn new() -> Self{ Self { - set: HashMap::new() + set: HashMap::new(), + common: TaskDefinitionFields::new() } } } @@ -659,18 +785,24 @@ pub struct SwitchTaskDefinition{ /// Gets/sets the definition of the switch to use #[serde(rename = "switch")] - pub switch: Map + pub switch: Map, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for SwitchTaskDefinition { +impl TaskDefinitionBase for SwitchTaskDefinition { fn task_type(&self) -> &str { TaskType::SWITCH } } impl SwitchTaskDefinition { + /// Initializes a new SwitchTaskDefinition pub fn new() -> Self{ Self { - switch: Map::new() + switch: Map::new(), + common: TaskDefinitionFields::new() } } } @@ -699,21 +831,29 @@ pub struct TryTaskDefinition{ /// Gets/sets the object used to define the errors to catch #[serde(rename = "catch")] - pub catch: ErrorCatcherDefinition + pub catch: ErrorCatcherDefinition, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for TryTaskDefinition { +impl TaskDefinitionBase for TryTaskDefinition { fn task_type(&self) -> &str { TaskType::TRY } } impl TryTaskDefinition { + + /// Initializes a new TryTaskDefintion pub fn new(try_: Map, catch: ErrorCatcherDefinition) -> Self{ Self { try_, - catch + catch, + common: TaskDefinitionFields::new() } } + } /// Represents the configuration of a concept used to catch errors @@ -752,7 +892,7 @@ pub struct ErrorFilterDefinition{ /// Gets/sets a key/value mapping of the properties errors to filter must define #[serde(rename = "with", skip_serializing_if = "Option::is_none")] - pub with: Option> + pub with: Option> } @@ -762,18 +902,60 @@ pub struct WaitTaskDefinition{ /// Gets/sets the amount of time to wait before resuming workflow #[serde(rename = "duration")] - pub duration: OneOfDurationOrIso8601Expression + pub duration: OneOfDurationOrIso8601Expression, + + /// Gets/sets the task's common fields + #[serde(flatten)] + pub common: TaskDefinitionFields } -impl TypedTaskDefinition for WaitTaskDefinition { +impl TaskDefinitionBase for WaitTaskDefinition { fn task_type(&self) -> &str { TaskType::WAIT } } impl WaitTaskDefinition { + + /// Initializes a new WaitTaskDefinition pub fn new(duration: OneOfDurationOrIso8601Expression) -> Self{ Self { - duration + duration, + common: TaskDefinitionFields::new() } } + +} + +/// Represents the definition of the iterator used to process each event or message consumed by a subscription +#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] +pub struct SubscriptionIteratorDefinition{ + + /// Gets the name of the variable used to store the current item being enumerated + #[serde(rename = "item")] + pub item: Option, + + /// Gets the name of the variable used to store the index of the current item being enumerated + #[serde(rename = "at")] + pub at: Option, + + /// Gets the tasks to perform for each consumed item + #[serde(rename = "do")] + pub do_: Option>, + + /// Gets/sets an object, if any, used to customize the item's output and to document its schema. + #[serde(rename = "output", skip_serializing_if = "Option::is_none")] + pub output: Option, + + /// Gets/sets an object, if any, used to customize the content of the workflow context. + #[serde(rename = "export", skip_serializing_if = "Option::is_none")] + pub export: Option + +} +impl SubscriptionIteratorDefinition{ + + /// Initializes a new SubscriptionIteratorDefinition + pub fn new() -> Self{ + SubscriptionIteratorDefinition::default() + } + } \ No newline at end of file diff --git a/core/src/models/workflow.rs b/core/src/models/workflow.rs index 6e5eff2..8493c7e 100644 --- a/core/src/models/workflow.rs +++ b/core/src/models/workflow.rs @@ -1,6 +1,6 @@ use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; use std::collections::HashMap; -use crate::models::any::*; use crate::models::authentication::*; use crate::models::catalog::*; use crate::models::duration::*; @@ -80,7 +80,7 @@ pub struct WorkflowDefinition{ /// Gets/sets a key/value mapping, if any, of additional information associated with the workflow #[serde(rename = "metadata", skip_serializing_if = "Option::is_none")] - pub metadata: Option> + pub metadata: Option> } impl WorkflowDefinition { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy