From 9224cb0e28a9964cb0899435ec087516d28bc3c8 Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Thu, 16 Jan 2025 16:27:03 +0100 Subject: [PATCH 1/2] feat(Core): Add the SubscriptionIteratorDefinition model feat(Core): Add a new `Read` property to the `ListenerDefinition` model feat(Builders): Add a `ISubscriptionIteratorDefinitionBuilder` and default implementation feat(Builders): Add a new `IInputDataModelBuilder` service and default implementation feat(Builders): Add a new `IOutputDataModelBuilder` service and default implementation feat(Builders): Add a new `ISchemaDefinitionBuilder` service and default implementation feat(Builders): Updated the `ITaskDefinitionBuilder` service and default implementation by adding methods to configure the task's input, output and export clauses Signed-off-by: Charles d'Avernas --- .../InputDataModelDefinitionBuilder.cs | 49 ++++++++++++ .../IInputDataModelDefinitionBuilder.cs | 42 ++++++++++ .../IListenTaskDefinitionBuilder.cs | 9 ++- .../Interfaces/IListenerDefinitionBuilder.cs | 11 +-- .../IOutputDataModelDefinitionBuilder.cs | 42 ++++++++++ .../Interfaces/ISchemaDefinitionBuilder.cs | 49 ++++++++++++ .../ISubscriptionIteratorDefinitionBuilder.cs | 63 +++++++++++++++ .../Interfaces/ITaskDefinitionBuilder.cs | 33 ++++++-- .../Interfaces/IWorkflowDefinitionBuilder.cs | 14 ++++ .../ListenTaskDefinitionBuilder.cs | 30 ++++---- .../ListenerDefinitionBuilder.cs | 28 ++++--- ...h2AuthenticationClientDefinitionBuilder.cs | 4 +- .../OutputDataModelDefinitionBuilder.cs | 49 ++++++++++++ .../SchemaDefinitionBuilder.cs | 57 ++++++++++++++ .../SubscriptionIteratorDefinitionBuilder.cs | 77 +++++++++++++++++++ .../TaskDefinitionBuilder.cs | 48 ++++++++++++ .../WorkflowDefinitionBuilder.cs | 30 ++++++++ src/ServerlessWorkflow.Sdk/EventReadMode.cs | 46 +++++++++++ .../Models/AsyncApiMessageDefinition.cs | 2 +- .../Models/AsyncApiSubscriptionDefinition.cs | 6 ++ .../Models/ListenerDefinition.cs | 7 ++ .../Models/SubscriptionIteratorDefinition.cs | 55 +++++++++++++ .../Models/Tasks/ListenTaskDefinition.cs | 6 ++ 23 files changed, 712 insertions(+), 45 deletions(-) create mode 100644 src/ServerlessWorkflow.Sdk.Builders/InputDataModelDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IInputDataModelDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOutputDataModelDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISchemaDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISubscriptionIteratorDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/OutputDataModelDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/SchemaDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk.Builders/SubscriptionIteratorDefinitionBuilder.cs create mode 100644 src/ServerlessWorkflow.Sdk/EventReadMode.cs create mode 100644 src/ServerlessWorkflow.Sdk/Models/SubscriptionIteratorDefinition.cs diff --git a/src/ServerlessWorkflow.Sdk.Builders/InputDataModelDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/InputDataModelDefinitionBuilder.cs new file mode 100644 index 0000000..589a4fb --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/InputDataModelDefinitionBuilder.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class InputDataModelDefinitionBuilder + : IInputDataModelDefinitionBuilder +{ + + /// + /// Gets the to configure + /// + protected InputDataModelDefinition Input { get; } = new(); + + /// + public virtual IInputDataModelDefinitionBuilder From(object expression) + { + ArgumentNullException.ThrowIfNull(expression); + this.Input.From = expression; + return this; + } + + /// + public virtual IInputDataModelDefinitionBuilder WithSchema(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new SchemaDefinitionBuilder(); + setup(builder); + this.Input.Schema = builder.Build(); + return this; + } + + /// + public virtual InputDataModelDefinition Build() => this.Input; + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IInputDataModelDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IInputDataModelDefinitionBuilder.cs new file mode 100644 index 0000000..1be73a4 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IInputDataModelDefinitionBuilder.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IInputDataModelDefinitionBuilder +{ + + /// + /// Configures the input data schema + /// + /// An used to configure the input data schema + /// The configured + IInputDataModelDefinitionBuilder WithSchema(Action setup); + + /// + /// Configures the runtime expression used to filter the input data + /// + /// The runtime expression used to filter the input data + /// The configured + IInputDataModelDefinitionBuilder From(object expression); + + /// + /// Builds the configured + /// + /// A new + InputDataModelDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs index 0975bd7..5850ec8 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs @@ -25,6 +25,13 @@ public interface IListenTaskDefinitionBuilder /// /// An used to setup the task's listener target /// The configured - IListenTaskDefinitionBuilder To(Action setup); + IListenTaskDefinitionBuilder To(Action setup); + + /// + /// Configures the iterator used to process each consumed event + /// + /// An used to configure the to use + /// The configured + IListenTaskDefinitionBuilder Foreach(Action setup); } diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs index b30dbd1..9fd072c 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs @@ -17,19 +17,20 @@ namespace ServerlessWorkflow.Sdk.Builders; /// Defines the fundamentals of a service used to build s /// public interface IListenerDefinitionBuilder + : IListenerTargetDefinitionBuilder { /// - /// Configures the + /// Configures how to read consumed events /// - /// - /// - IListenerDefinitionBuilder To(Action setup); + /// Specifies how consumed events should be read. See s + /// The configured + IListenerDefinitionBuilder Read(string readMode); /// /// Builds the configured /// /// A new - ListenerDefinition Build(); + new ListenerDefinition Build(); } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOutputDataModelDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOutputDataModelDefinitionBuilder.cs new file mode 100644 index 0000000..464deb5 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IOutputDataModelDefinitionBuilder.cs @@ -0,0 +1,42 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface IOutputDataModelDefinitionBuilder +{ + + /// + /// Configures the output data schema + /// + /// An used to configure the output data schema + /// The configured + IOutputDataModelDefinitionBuilder WithSchema(Action setup); + + /// + /// Configures the runtime expression used to filter the data to output + /// + /// The runtime expression used to filter the data to output + /// The configured + IOutputDataModelDefinitionBuilder As(object expression); + + /// + /// Builds the configured + /// + /// A new + OutputDataModelDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISchemaDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISchemaDefinitionBuilder.cs new file mode 100644 index 0000000..bacc732 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISchemaDefinitionBuilder.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ISchemaDefinitionBuilder +{ + + /// + /// Sets the schema format + /// + /// The schema format + /// The configured + ISchemaDefinitionBuilder WithFormat(string format); + + /// + /// Sets the schema's + /// + /// An used to configure the schema's + /// The configured + ISchemaDefinitionBuilder WithResource(Action setup); + + /// + /// Sets the schema document + /// + /// The schema document + /// The configured + ISchemaDefinitionBuilder WithDocument(object document); + + /// + /// Builds the configured + /// + /// A new + SchemaDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISubscriptionIteratorDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISubscriptionIteratorDefinitionBuilder.cs new file mode 100644 index 0000000..8ded995 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ISubscriptionIteratorDefinitionBuilder.cs @@ -0,0 +1,63 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Defines the fundamentals of a service used to build s +/// +public interface ISubscriptionIteratorDefinitionBuilder +{ + + /// + /// Sets the name of the variable used to store the item being enumerated + /// + /// The name of the variable used to store the item being enumerated + /// The configured + ISubscriptionIteratorDefinitionBuilder Item(string item); + + /// + /// Sets the name of the variable used to store the index of the item being enumerated + /// + /// The name of the variable used to store the index of the item being enumerated + /// The configured + ISubscriptionIteratorDefinitionBuilder At(string at); + + /// + /// Sets the tasks to execute for each event or message consumed + /// + /// An used to configure the tasks to execute for each event or message consumed + /// The configured + ISubscriptionIteratorDefinitionBuilder Do(Action setup); + + /// + /// Configures the output data of each item + /// + /// An used to configure the output data + /// The configured + ISubscriptionIteratorDefinitionBuilder Output(Action setup); + + /// + /// Configures the data exported by each item + /// + /// An used to configure the exported data + /// The configured + ISubscriptionIteratorDefinitionBuilder Export(Action setup); + + /// + /// Builds the configured + /// + /// A new + SubscriptionIteratorDefinition Build(); + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs index bc4b32a..b7dac41 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs @@ -44,26 +44,47 @@ public interface ITaskDefinitionBuilder TBuilder If(string condition); /// - /// Sets the workflow's timeout + /// Sets the task's timeout /// - /// The name of the workflow's timeout + /// The name of the task's timeout /// The configured TBuilder WithTimeout(string name); /// - /// Sets the workflow's timeout + /// Sets the task's timeout /// - /// The workflow's timeout + /// The task's timeout /// The configured TBuilder WithTimeout(TimeoutDefinition timeout); /// - /// Sets the workflow's timeout + /// Sets the task's timeout /// - /// An used to setup the workflow's timeout + /// An used to setup the task's timeout /// The configured TBuilder WithTimeout(Action setup); + /// + /// Sets the task's input data + /// + /// An used to configure the task's input + /// The configured + TBuilder WithInput(Action setup); + + /// + /// Sets the task's output data + /// + /// An used to configure the task's output + /// The configured + TBuilder WithOutput(Action setup); + + /// + /// Sets the data exported by the task + /// + /// An used to configure the data exported by the task + /// The configured + TBuilder WithExport(Action setup); + /// /// Configures the task to build to then execute the specified flow directive /// diff --git a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs index 7a6cfc5..ed94f05 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs @@ -98,6 +98,20 @@ public interface IWorkflowDefinitionBuilder /// The configured IWorkflowDefinitionBuilder WithTimeout(Action setup); + /// + /// Sets the workflow's input data + /// + /// An used to configure the workflow's input + /// The configured + IWorkflowDefinitionBuilder WithInput(Action setup); + + /// + /// Sets the workflow's output data + /// + /// An used to configure the workflow's output + /// The configured + IWorkflowDefinitionBuilder WithOutput(Action setup); + /// /// Uses the specified authentication policy /// diff --git a/src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs index 3512aa0..3893e1f 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs @@ -21,31 +21,31 @@ public class ListenTaskDefinitionBuilder { /// - /// Gets/sets the task's listener configuration + /// Gets/sets the to configure /// - protected ListenerDefinition? Listener { get; set; } + protected ListenTaskDefinition Task { get; } = new() { Listen = null! }; /// - public virtual IListenTaskDefinitionBuilder To(Action setup) + public virtual IListenTaskDefinitionBuilder To(Action setup) { - var builder = new ListenerTargetDefinitionBuilder(); + ArgumentNullException.ThrowIfNull(setup); + var builder = new ListenerDefinitionBuilder(); setup(builder); - var target = builder.Build(); - this.Listener = new() - { - To = target - }; + this.Task.Listen = builder.Build(); return this; } /// - public override ListenTaskDefinition Build() + public virtual IListenTaskDefinitionBuilder Foreach(Action setup) { - if (this.Listener == null) throw new NullReferenceException("The listener must be set"); - return this.Configure(new() - { - Listen = this.Listener - }); + ArgumentNullException.ThrowIfNull(setup); + var builder = new SubscriptionIteratorDefinitionBuilder(); + setup(builder); + this.Task.Foreach = builder.Build(); + return this; } + /// + public override ListenTaskDefinition Build() => this.Configure(this.Task); + } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs index 850af66..7c82737 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs @@ -16,33 +16,31 @@ namespace ServerlessWorkflow.Sdk.Builders; /// /// Represents the default implementation of the interface /// -/// The listener's target -public class ListenerDefinitionBuilder(EventConsumptionStrategyDefinition? target = null) - : IListenerDefinitionBuilder +/// The listener's target +public class ListenerDefinitionBuilder(EventConsumptionStrategyDefinition? to = null) + : ListenerTargetDefinitionBuilder, IListenerDefinitionBuilder { /// - /// Gets/sets the listener's target + /// Gets/sets the to configure /// - protected EventConsumptionStrategyDefinition? Target { get; set; } = target; + protected ListenerDefinition Listener { get; } = new() { To = to! }; /// - public virtual IListenerDefinitionBuilder To(Action setup) + public virtual IListenerDefinitionBuilder Read(string readMode) { - var builder = new ListenerTargetDefinitionBuilder(); - setup(builder); - this.Target = builder.Build(); + ArgumentException.ThrowIfNullOrWhiteSpace(readMode); + this.Listener.Read = readMode; return this; } /// - public virtual ListenerDefinition Build() + public virtual new ListenerDefinition Build() { - if (this.Target == null) throw new NullReferenceException("The listener's target must be set"); - return new() - { - To = this.Target - }; + var to = base.Build(); + if (to == null) throw new NullReferenceException("The listener's target must be set"); + this.Listener.To = to; + return this.Listener; } } \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs index de4ddb0..41e5ba2 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs @@ -43,7 +43,7 @@ public class OAuth2AuthenticationClientDefinitionBuilder /// public virtual IOAuth2AuthenticationClientDefinitionBuilder WithId(string id) { - ArgumentException.ThrowIfNullOrEmpty(id); + ArgumentException.ThrowIfNullOrWhiteSpace(id); this.Id = id; return this; } @@ -51,7 +51,7 @@ public virtual IOAuth2AuthenticationClientDefinitionBuilder WithId(string id) /// public virtual IOAuth2AuthenticationClientDefinitionBuilder WithSecret(string secret) { - ArgumentException.ThrowIfNullOrEmpty(secret); + ArgumentException.ThrowIfNullOrWhiteSpace(secret); this.Secret = secret; return this; } diff --git a/src/ServerlessWorkflow.Sdk.Builders/OutputDataModelDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/OutputDataModelDefinitionBuilder.cs new file mode 100644 index 0000000..0e39803 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/OutputDataModelDefinitionBuilder.cs @@ -0,0 +1,49 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class OutputDataModelDefinitionBuilder + : IOutputDataModelDefinitionBuilder +{ + + /// + /// Gets the to configure + /// + protected OutputDataModelDefinition Output { get; } = new(); + + /// + public virtual IOutputDataModelDefinitionBuilder As(object expression) + { + ArgumentNullException.ThrowIfNull(expression); + this.Output.As = expression; + return this; + } + + /// + public virtual IOutputDataModelDefinitionBuilder WithSchema(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new SchemaDefinitionBuilder(); + setup(builder); + this.Output.Schema = builder.Build(); + return this; + } + + /// + public virtual OutputDataModelDefinition Build() => this.Output; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/SchemaDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/SchemaDefinitionBuilder.cs new file mode 100644 index 0000000..40e71bc --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/SchemaDefinitionBuilder.cs @@ -0,0 +1,57 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class SchemaDefinitionBuilder + : ISchemaDefinitionBuilder +{ + + /// + /// Gets the to configure + /// + protected SchemaDefinition Schema { get; } = new(); + + /// + public virtual ISchemaDefinitionBuilder WithFormat(string format) + { + ArgumentException.ThrowIfNullOrWhiteSpace(format); + this.Schema.Format = format; + return this; + } + + /// + public virtual ISchemaDefinitionBuilder WithResource(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new ExternalResourceDefinitionBuilder(); + setup(builder); + this.Schema.Resource = builder.Build(); + return this; + } + + /// + public virtual ISchemaDefinitionBuilder WithDocument(object document) + { + ArgumentNullException.ThrowIfNull(document); + this.Schema.Document = document; + return this; + } + + /// + public virtual SchemaDefinition Build() => this.Schema; + +} diff --git a/src/ServerlessWorkflow.Sdk.Builders/SubscriptionIteratorDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/SubscriptionIteratorDefinitionBuilder.cs new file mode 100644 index 0000000..40954c9 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk.Builders/SubscriptionIteratorDefinitionBuilder.cs @@ -0,0 +1,77 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Builders; + +/// +/// Represents the default implementation of the interface +/// +public class SubscriptionIteratorDefinitionBuilder + : ISubscriptionIteratorDefinitionBuilder +{ + + /// + /// Gets the to configure + /// + protected SubscriptionIteratorDefinition Iterator { get; } = new(); + + /// + public virtual ISubscriptionIteratorDefinitionBuilder Item(string item) + { + ArgumentException.ThrowIfNullOrWhiteSpace(item); + this.Iterator.Item = item; + return this; + } + + /// + public virtual ISubscriptionIteratorDefinitionBuilder At(string at) + { + ArgumentException.ThrowIfNullOrWhiteSpace(at); + this.Iterator.At = at; + return this; + } + + /// + public virtual ISubscriptionIteratorDefinitionBuilder Do(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new TaskDefinitionMapBuilder(); + setup(builder); + this.Iterator.Do = builder.Build(); + return this; + } + + /// + public virtual ISubscriptionIteratorDefinitionBuilder Output(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new OutputDataModelDefinitionBuilder(); + setup(builder); + this.Iterator.Output = builder.Build(); + return this; + } + + /// + public virtual ISubscriptionIteratorDefinitionBuilder Export(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new OutputDataModelDefinitionBuilder(); + setup(builder); + this.Iterator.Export = builder.Build(); + return this; + } + + /// + public virtual SubscriptionIteratorDefinition Build() => this.Iterator; + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs index 3e0834b..697e67b 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs @@ -34,6 +34,21 @@ public abstract class TaskDefinitionBuilder /// protected OneOf? Timeout { get; set; } + /// + /// Gets/sets the task's input data, if any + /// + protected InputDataModelDefinition? Input { get; set; } + + /// + /// Gets/sets the task's output data, if any + /// + protected OutputDataModelDefinition? Output { get; set; } + + /// + /// Gets/sets the task's export data, if any + /// + protected OutputDataModelDefinition? Export { get; set; } + /// /// Gets/sets the flow directive, if any, used to then execute /// @@ -73,6 +88,36 @@ public virtual TBuilder WithTimeout(Action setup) return (TBuilder)(object)this; } + /// + public virtual TBuilder WithInput(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new InputDataModelDefinitionBuilder(); + setup(builder); + this.Input = builder.Build(); + return (TBuilder)(object)this; + } + + /// + public virtual TBuilder WithOutput(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new OutputDataModelDefinitionBuilder(); + setup(builder); + this.Output = builder.Build(); + return (TBuilder)(object)this; + } + + /// + public virtual TBuilder WithExport(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new OutputDataModelDefinitionBuilder(); + setup(builder); + this.Export = builder.Build(); + return (TBuilder)(object)this; + } + /// public virtual TBuilder Then(string directive) { @@ -95,6 +140,9 @@ protected virtual TDefinition Configure(TDefinition definition) else definition.TimeoutReference = this.Timeout.T2Value; } definition.Then = this.ThenDirective; + definition.Input = this.Input; + definition.Output = this.Output; + definition.Export = this.Export; return definition; } diff --git a/src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs b/src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs index 4a41a88..96995be 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs +++ b/src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs @@ -63,6 +63,16 @@ public class WorkflowDefinitionBuilder /// protected OneOf? Timeout { get; set; } + /// + /// Gets/sets the workflow's input data, if any + /// + protected InputDataModelDefinition? Input { get; set; } + + /// + /// Gets/sets the workflow's output data, if any + /// + protected OutputDataModelDefinition? Output { get; set; } + /// /// Gets/sets a name/value mapping of the workflow's reusable components /// @@ -166,6 +176,26 @@ public virtual IWorkflowDefinitionBuilder WithTimeout(Action + public virtual IWorkflowDefinitionBuilder WithInput(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new InputDataModelDefinitionBuilder(); + setup(builder); + this.Input = builder.Build(); + return this; + } + + /// + public virtual IWorkflowDefinitionBuilder WithOutput(Action setup) + { + ArgumentNullException.ThrowIfNull(setup); + var builder = new OutputDataModelDefinitionBuilder(); + setup(builder); + this.Output = builder.Build(); + return this; + } + /// public virtual IWorkflowDefinitionBuilder UseAuthentication(string name, AuthenticationPolicyDefinition authentication) { diff --git a/src/ServerlessWorkflow.Sdk/EventReadMode.cs b/src/ServerlessWorkflow.Sdk/EventReadMode.cs new file mode 100644 index 0000000..6da631b --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/EventReadMode.cs @@ -0,0 +1,46 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk; + +/// +/// Enumerates all supported event read modes +/// +public static class EventReadMode +{ + + /// + /// Indicates that only the data of consumed events should be read + /// + public const string Data = "data"; + /// + /// Indicates that the whole event envelope should be read, including context attributes + /// + public const string Envelope = "envelope"; + /// + /// Indicates that the event's raw data should be read, without additional transformation (i.e. deserialization) + /// + public const string Raw = "raw"; + + /// + /// Gets a new containing all supported event read modes + /// + /// A new containing all supported event read modes + public static IEnumerable AsEnumerable() + { + yield return Data; + yield return Envelope; + yield return Raw; + } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/AsyncApiMessageDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/AsyncApiMessageDefinition.cs index 79d1e43..5a1a91e 100644 --- a/src/ServerlessWorkflow.Sdk/Models/AsyncApiMessageDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/AsyncApiMessageDefinition.cs @@ -32,4 +32,4 @@ public record AsyncApiMessageDefinition [DataMember(Name = "headers", Order = 2), JsonPropertyName("headers"), JsonPropertyOrder(2), YamlMember(Alias = "headers", Order = 2)] public virtual object? Headers { get; set; } -} \ No newline at end of file +} diff --git a/src/ServerlessWorkflow.Sdk/Models/AsyncApiSubscriptionDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/AsyncApiSubscriptionDefinition.cs index cda244e..6866115 100644 --- a/src/ServerlessWorkflow.Sdk/Models/AsyncApiSubscriptionDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/AsyncApiSubscriptionDefinition.cs @@ -33,4 +33,10 @@ public record AsyncApiSubscriptionDefinition [DataMember(Name = "consume", Order = 2), JsonPropertyName("consume"), JsonPropertyOrder(2), YamlMember(Alias = "consume", Order = 2)] public required virtual AsyncApiSubscriptionLifetimeDefinition Consume { get; set; } + /// + /// Gets/sets the configuration of the iterator, if any, used to process each consumed message + /// + [DataMember(Name = "foreach", Order = 3), JsonPropertyName("foreach"), JsonPropertyOrder(3), YamlMember(Alias = "foreach", Order = 3)] + public virtual SubscriptionIteratorDefinition? Foreach { get; set; } + } diff --git a/src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs index d90a198..f1178ad 100644 --- a/src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs @@ -27,4 +27,11 @@ public record ListenerDefinition [DataMember(Name = "to", Order = 1), JsonPropertyName("to"), JsonPropertyOrder(1), YamlMember(Alias = "to", Order = 1)] public required virtual EventConsumptionStrategyDefinition To { get; set; } + /// + /// Gets/sets a string that specifies how events are read during the listen operation + /// See . Defaults to + /// + [DataMember(Name = "read", Order = 1), JsonPropertyName("read"), JsonPropertyOrder(1), YamlMember(Alias = "read", Order = 1)] + public virtual string? Read { get; set; } + } diff --git a/src/ServerlessWorkflow.Sdk/Models/SubscriptionIteratorDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/SubscriptionIteratorDefinition.cs new file mode 100644 index 0000000..0c4b7f9 --- /dev/null +++ b/src/ServerlessWorkflow.Sdk/Models/SubscriptionIteratorDefinition.cs @@ -0,0 +1,55 @@ +// Copyright © 2024-Present The Serverless Workflow Specification Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"), +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace ServerlessWorkflow.Sdk.Models; + +/// +/// Represents the definition of a subscription iterator, used to configure the processing of each event or message consumed by a subscription +/// +[DataContract] +public record SubscriptionIteratorDefinition +{ + + /// + /// Gets/sets the name of the variable used to store the item being enumerated. + /// Defaults to `item` + /// + [DataMember(Name = "item", Order = 1), JsonPropertyName("item"), JsonPropertyOrder(1), YamlMember(Alias = "item", Order = 1)] + public virtual string? Item { get; set; } + + /// + /// Gets/sets the name of the variable used to store the index of the item being enumerates + /// Defaults to `index` + /// + [DataMember(Name = "at", Order = 2), JsonPropertyName("at"), JsonPropertyOrder(2), YamlMember(Alias = "at", Order = 2)] + public virtual string? At { get; set; } + + /// + /// Gets/sets the tasks to run for each consumed event or message + /// + [DataMember(Name = "do", Order = 3), JsonPropertyName("do"), JsonPropertyOrder(3), YamlMember(Alias = "do", Order = 3)] + public virtual Map? Do { get; set; } + + /// + /// Gets/sets the definition, if any, of the data to output for each iteration + /// + [DataMember(Name = "output", Order = 4), JsonPropertyName("output"), JsonPropertyOrder(4), YamlMember(Alias = "output", Order = 4)] + public virtual OutputDataModelDefinition? Output { get; set; } + + /// + /// Gets/sets the definition, if any, of the data to export for each iteration + /// + [DataMember(Name = "export", Order = 5), JsonPropertyName("export"), JsonPropertyOrder(5), YamlMember(Alias = "export", Order = 5)] + public virtual OutputDataModelDefinition? Export { get; set; } + +} \ No newline at end of file diff --git a/src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs b/src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs index 96fabd8..88bc273 100644 --- a/src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs +++ b/src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs @@ -32,4 +32,10 @@ public record ListenTaskDefinition [DataMember(Name = "listen", Order = 1), JsonPropertyName("listen"), JsonPropertyOrder(1), YamlMember(Alias = "listen", Order = 1)] public required virtual ListenerDefinition Listen { get; set; } + /// + /// Gets/sets the configuration of the iterator, if any, used to process each consumed event + /// + [DataMember(Name = "foreach", Order = 2), JsonPropertyName("foreach"), JsonPropertyOrder(2), YamlMember(Alias = "foreach", Order = 2)] + public virtual SubscriptionIteratorDefinition? Foreach { get; set; } + } From bfabec1993fceddb5ec54022bc096fbd652de26d Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Thu, 16 Jan 2025 16:30:31 +0100 Subject: [PATCH 2/2] fix(Solution): Update solution project versions Signed-off-by: Charles d'Avernas --- .../ServerlessWorkflow.Sdk.Builders.csproj | 2 +- src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj | 2 +- src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj index 91e28bf..7851940 100644 --- a/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj +++ b/src/ServerlessWorkflow.Sdk.Builders/ServerlessWorkflow.Sdk.Builders.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha6.3 + alpha6.4 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj index a9bbfd2..48b8d8b 100644 --- a/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj +++ b/src/ServerlessWorkflow.Sdk.IO/ServerlessWorkflow.Sdk.IO.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha6.3 + alpha6.4 $(VersionPrefix) $(VersionPrefix) en diff --git a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj index f4b68a3..45c2a32 100644 --- a/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj +++ b/src/ServerlessWorkflow.Sdk/ServerlessWorkflow.Sdk.csproj @@ -5,7 +5,7 @@ enable enable 1.0.0 - alpha6.3 + alpha6.4 $(VersionPrefix) $(VersionPrefix) en