Skip to content

Commit 9224cb0

Browse files
committedJan 16, 2025··
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 <[email protected]>
1 parent 44d7648 commit 9224cb0

23 files changed

+712
-45
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Represents the default implementation of the <see cref="IInputDataModelDefinitionBuilder"/> interface
18+
/// </summary>
19+
public class InputDataModelDefinitionBuilder
20+
: IInputDataModelDefinitionBuilder
21+
{
22+
23+
/// <summary>
24+
/// Gets the <see cref="InputDataModelDefinition"/> to configure
25+
/// </summary>
26+
protected InputDataModelDefinition Input { get; } = new();
27+
28+
/// <inheritdoc/>
29+
public virtual IInputDataModelDefinitionBuilder From(object expression)
30+
{
31+
ArgumentNullException.ThrowIfNull(expression);
32+
this.Input.From = expression;
33+
return this;
34+
}
35+
36+
/// <inheritdoc/>
37+
public virtual IInputDataModelDefinitionBuilder WithSchema(Action<ISchemaDefinitionBuilder> setup)
38+
{
39+
ArgumentNullException.ThrowIfNull(setup);
40+
var builder = new SchemaDefinitionBuilder();
41+
setup(builder);
42+
this.Input.Schema = builder.Build();
43+
return this;
44+
}
45+
46+
/// <inheritdoc/>
47+
public virtual InputDataModelDefinition Build() => this.Input;
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="InputDataModelDefinition"/>s
18+
/// </summary>
19+
public interface IInputDataModelDefinitionBuilder
20+
{
21+
22+
/// <summary>
23+
/// Configures the input data schema
24+
/// </summary>
25+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the input data schema</param>
26+
/// <returns>The configured <see cref="IInputDataModelDefinitionBuilder"/></returns>
27+
IInputDataModelDefinitionBuilder WithSchema(Action<ISchemaDefinitionBuilder> setup);
28+
29+
/// <summary>
30+
/// Configures the runtime expression used to filter the input data
31+
/// </summary>
32+
/// <param name="expression">The runtime expression used to filter the input data</param>
33+
/// <returns>The configured <see cref="IInputDataModelDefinitionBuilder"/></returns>
34+
IInputDataModelDefinitionBuilder From(object expression);
35+
36+
/// <summary>
37+
/// Builds the configured <see cref="InputDataModelDefinition"/>
38+
/// </summary>
39+
/// <returns>A new <see cref="InputDataModelDefinition"/></returns>
40+
InputDataModelDefinition Build();
41+
42+
}

‎src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenTaskDefinitionBuilder.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public interface IListenTaskDefinitionBuilder
2525
/// </summary>
2626
/// <param name="setup">An <see cref="Action{T}"/> used to setup the task's listener target</param>
2727
/// <returns>The configured <see cref="IListenTaskDefinitionBuilder"/></returns>
28-
IListenTaskDefinitionBuilder To(Action<IListenerTargetDefinitionBuilder> setup);
28+
IListenTaskDefinitionBuilder To(Action<IListenerDefinitionBuilder> setup);
29+
30+
/// <summary>
31+
/// Configures the iterator used to process each consumed event
32+
/// </summary>
33+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the <see cref="SubscriptionIteratorDefinition"/> to use</param>
34+
/// <returns>The configured <see cref="IListenTaskDefinitionBuilder"/></returns>
35+
IListenTaskDefinitionBuilder Foreach(Action<ISubscriptionIteratorDefinitionBuilder> setup);
2936

3037
}

‎src/ServerlessWorkflow.Sdk.Builders/Interfaces/IListenerDefinitionBuilder.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ namespace ServerlessWorkflow.Sdk.Builders;
1717
/// Defines the fundamentals of a service used to build <see cref="ListenerDefinition"/>s
1818
/// </summary>
1919
public interface IListenerDefinitionBuilder
20+
: IListenerTargetDefinitionBuilder
2021
{
2122

2223
/// <summary>
23-
/// Configures the
24+
/// Configures how to read consumed events
2425
/// </summary>
25-
/// <param name="setup"></param>
26-
/// <returns></returns>
27-
IListenerDefinitionBuilder To(Action<IListenerTargetDefinitionBuilder> setup);
26+
/// <param name="readMode">Specifies how consumed events should be read. See <see cref="EventReadMode"/>s</param>
27+
/// <returns>The configured <see cref="IListenerDefinitionBuilder"/></returns>
28+
IListenerDefinitionBuilder Read(string readMode);
2829

2930
/// <summary>
3031
/// Builds the configured <see cref="ListenerDefinition"/>
3132
/// </summary>
3233
/// <returns>A new <see cref="ListenerDefinition"/></returns>
33-
ListenerDefinition Build();
34+
new ListenerDefinition Build();
3435

3536
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="OutputDataModelDefinition"/>s
18+
/// </summary>
19+
public interface IOutputDataModelDefinitionBuilder
20+
{
21+
22+
/// <summary>
23+
/// Configures the output data schema
24+
/// </summary>
25+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the output data schema</param>
26+
/// <returns>The configured <see cref="IOutputDataModelDefinitionBuilder"/></returns>
27+
IOutputDataModelDefinitionBuilder WithSchema(Action<ISchemaDefinitionBuilder> setup);
28+
29+
/// <summary>
30+
/// Configures the runtime expression used to filter the data to output
31+
/// </summary>
32+
/// <param name="expression">The runtime expression used to filter the data to output</param>
33+
/// <returns>The configured <see cref="IOutputDataModelDefinitionBuilder"/></returns>
34+
IOutputDataModelDefinitionBuilder As(object expression);
35+
36+
/// <summary>
37+
/// Builds the configured <see cref="OutputDataModelDefinition"/>
38+
/// </summary>
39+
/// <returns>A new <see cref="OutputDataModelDefinition"/></returns>
40+
OutputDataModelDefinition Build();
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="SchemaDefinition"/>s
18+
/// </summary>
19+
public interface ISchemaDefinitionBuilder
20+
{
21+
22+
/// <summary>
23+
/// Sets the schema format
24+
/// </summary>
25+
/// <param name="format">The schema format</param>
26+
/// <returns>The configured <see cref="ISchemaDefinitionBuilder"/></returns>
27+
ISchemaDefinitionBuilder WithFormat(string format);
28+
29+
/// <summary>
30+
/// Sets the schema's <see cref="ExternalResourceDefinition"/>
31+
/// </summary>
32+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the schema's <see cref="ExternalResourceDefinition"/></param>
33+
/// <returns>The configured <see cref="ISchemaDefinitionBuilder"/></returns>
34+
ISchemaDefinitionBuilder WithResource(Action<IExternalResourceDefinitionBuilder> setup);
35+
36+
/// <summary>
37+
/// Sets the schema document
38+
/// </summary>
39+
/// <param name="document">The schema document</param>
40+
/// <returns>The configured <see cref="ISchemaDefinitionBuilder"/></returns>
41+
ISchemaDefinitionBuilder WithDocument(object document);
42+
43+
/// <summary>
44+
/// Builds the configured <see cref="SchemaDefinition"/>
45+
/// </summary>
46+
/// <returns>A new <see cref="SchemaDefinition"/></returns>
47+
SchemaDefinition Build();
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Defines the fundamentals of a service used to build <see cref="SubscriptionIteratorDefinition"/>s
18+
/// </summary>
19+
public interface ISubscriptionIteratorDefinitionBuilder
20+
{
21+
22+
/// <summary>
23+
/// Sets the name of the variable used to store the item being enumerated
24+
/// </summary>
25+
/// <param name="item">The name of the variable used to store the item being enumerated</param>
26+
/// <returns>The configured <see cref="ISubscriptionIteratorDefinitionBuilder"/></returns>
27+
ISubscriptionIteratorDefinitionBuilder Item(string item);
28+
29+
/// <summary>
30+
/// Sets the name of the variable used to store the index of the item being enumerated
31+
/// </summary>
32+
/// <param name="at">The name of the variable used to store the index of the item being enumerated</param>
33+
/// <returns>The configured <see cref="ISubscriptionIteratorDefinitionBuilder"/></returns>
34+
ISubscriptionIteratorDefinitionBuilder At(string at);
35+
36+
/// <summary>
37+
/// Sets the tasks to execute for each event or message consumed
38+
/// </summary>
39+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the tasks to execute for each event or message consumed</param>
40+
/// <returns>The configured <see cref="ISubscriptionIteratorDefinitionBuilder"/></returns>
41+
ISubscriptionIteratorDefinitionBuilder Do(Action<ITaskDefinitionMapBuilder> setup);
42+
43+
/// <summary>
44+
/// Configures the output data of each item
45+
/// </summary>
46+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the output data</param>
47+
/// <returns>The configured <see cref="ISubscriptionIteratorDefinitionBuilder"/></returns>
48+
ISubscriptionIteratorDefinitionBuilder Output(Action<IOutputDataModelDefinitionBuilder> setup);
49+
50+
/// <summary>
51+
/// Configures the data exported by each item
52+
/// </summary>
53+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the exported data</param>
54+
/// <returns>The configured <see cref="ISubscriptionIteratorDefinitionBuilder"/></returns>
55+
ISubscriptionIteratorDefinitionBuilder Export(Action<IOutputDataModelDefinitionBuilder> setup);
56+
57+
/// <summary>
58+
/// Builds the configured <see cref="SubscriptionIteratorDefinition"/>
59+
/// </summary>
60+
/// <returns>A new <see cref="SubscriptionIteratorDefinition"/></returns>
61+
SubscriptionIteratorDefinition Build();
62+
63+
}

‎src/ServerlessWorkflow.Sdk.Builders/Interfaces/ITaskDefinitionBuilder.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,47 @@ public interface ITaskDefinitionBuilder<TBuilder>
4444
TBuilder If(string condition);
4545

4646
/// <summary>
47-
/// Sets the workflow's timeout
47+
/// Sets the task's timeout
4848
/// </summary>
49-
/// <param name="name">The name of the workflow's timeout</param>
49+
/// <param name="name">The name of the task's timeout</param>
5050
/// <returns>The configured <see cref="ITaskDefinitionBuilder{TBuilder}"/></returns>
5151
TBuilder WithTimeout(string name);
5252

5353
/// <summary>
54-
/// Sets the workflow's timeout
54+
/// Sets the task's timeout
5555
/// </summary>
56-
/// <param name="timeout">The workflow's timeout</param>
56+
/// <param name="timeout">The task's timeout</param>
5757
/// <returns>The configured <see cref="ITaskDefinitionBuilder{TBuilder}"/></returns>
5858
TBuilder WithTimeout(TimeoutDefinition timeout);
5959

6060
/// <summary>
61-
/// Sets the workflow's timeout
61+
/// Sets the task's timeout
6262
/// </summary>
63-
/// <param name="setup">An <see cref="Action{T}"/> used to setup the workflow's timeout</param>
63+
/// <param name="setup">An <see cref="Action{T}"/> used to setup the task's timeout</param>
6464
/// <returns>The configured <see cref="ITaskDefinitionBuilder{TBuilder}"/></returns>
6565
TBuilder WithTimeout(Action<ITimeoutDefinitionBuilder> setup);
6666

67+
/// <summary>
68+
/// Sets the task's input data
69+
/// </summary>
70+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the task's input</param>
71+
/// <returns>The configured <see cref="ITaskDefinitionBuilder{TBuilder}"/></returns>
72+
TBuilder WithInput(Action<IInputDataModelDefinitionBuilder> setup);
73+
74+
/// <summary>
75+
/// Sets the task's output data
76+
/// </summary>
77+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the task's output</param>
78+
/// <returns>The configured <see cref="ITaskDefinitionBuilder{TBuilder}"/></returns>
79+
TBuilder WithOutput(Action<IOutputDataModelDefinitionBuilder> setup);
80+
81+
/// <summary>
82+
/// Sets the data exported by the task
83+
/// </summary>
84+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the data exported by the task</param>
85+
/// <returns>The configured <see cref="ITaskDefinitionBuilder{TBuilder}"/></returns>
86+
TBuilder WithExport(Action<IOutputDataModelDefinitionBuilder> setup);
87+
6788
/// <summary>
6889
/// Configures the task to build to then execute the specified flow directive
6990
/// </summary>

‎src/ServerlessWorkflow.Sdk.Builders/Interfaces/IWorkflowDefinitionBuilder.cs

+14
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ public interface IWorkflowDefinitionBuilder
9898
/// <returns>The configured <see cref="IWorkflowDefinitionBuilder"/></returns>
9999
IWorkflowDefinitionBuilder WithTimeout(Action<ITimeoutDefinitionBuilder> setup);
100100

101+
/// <summary>
102+
/// Sets the workflow's input data
103+
/// </summary>
104+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the workflow's input</param>
105+
/// <returns>The configured <see cref="IWorkflowDefinitionBuilder"/></returns>
106+
IWorkflowDefinitionBuilder WithInput(Action<IInputDataModelDefinitionBuilder> setup);
107+
108+
/// <summary>
109+
/// Sets the workflow's output data
110+
/// </summary>
111+
/// <param name="setup">An <see cref="Action{T}"/> used to configure the workflow's output</param>
112+
/// <returns>The configured <see cref="IWorkflowDefinitionBuilder"/></returns>
113+
IWorkflowDefinitionBuilder WithOutput(Action<IOutputDataModelDefinitionBuilder> setup);
114+
101115
/// <summary>
102116
/// Uses the specified authentication policy
103117
/// </summary>

‎src/ServerlessWorkflow.Sdk.Builders/ListenTaskDefinitionBuilder.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ public class ListenTaskDefinitionBuilder
2121
{
2222

2323
/// <summary>
24-
/// Gets/sets the task's listener configuration
24+
/// Gets/sets the <see cref="ListenTaskDefinition"/> to configure
2525
/// </summary>
26-
protected ListenerDefinition? Listener { get; set; }
26+
protected ListenTaskDefinition Task { get; } = new() { Listen = null! };
2727

2828
/// <inheritdoc/>
29-
public virtual IListenTaskDefinitionBuilder To(Action<IListenerTargetDefinitionBuilder> setup)
29+
public virtual IListenTaskDefinitionBuilder To(Action<IListenerDefinitionBuilder> setup)
3030
{
31-
var builder = new ListenerTargetDefinitionBuilder();
31+
ArgumentNullException.ThrowIfNull(setup);
32+
var builder = new ListenerDefinitionBuilder();
3233
setup(builder);
33-
var target = builder.Build();
34-
this.Listener = new()
35-
{
36-
To = target
37-
};
34+
this.Task.Listen = builder.Build();
3835
return this;
3936
}
4037

4138
/// <inheritdoc/>
42-
public override ListenTaskDefinition Build()
39+
public virtual IListenTaskDefinitionBuilder Foreach(Action<ISubscriptionIteratorDefinitionBuilder> setup)
4340
{
44-
if (this.Listener == null) throw new NullReferenceException("The listener must be set");
45-
return this.Configure(new()
46-
{
47-
Listen = this.Listener
48-
});
41+
ArgumentNullException.ThrowIfNull(setup);
42+
var builder = new SubscriptionIteratorDefinitionBuilder();
43+
setup(builder);
44+
this.Task.Foreach = builder.Build();
45+
return this;
4946
}
5047

48+
/// <inheritdoc/>
49+
public override ListenTaskDefinition Build() => this.Configure(this.Task);
50+
5151
}

‎src/ServerlessWorkflow.Sdk.Builders/ListenerDefinitionBuilder.cs

+13-15
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,31 @@ namespace ServerlessWorkflow.Sdk.Builders;
1616
/// <summary>
1717
/// Represents the default implementation of the <see cref="IListenerDefinitionBuilder"/> interface
1818
/// </summary>
19-
/// <param name="target">The listener's target</param>
20-
public class ListenerDefinitionBuilder(EventConsumptionStrategyDefinition? target = null)
21-
: IListenerDefinitionBuilder
19+
/// <param name="to">The listener's target</param>
20+
public class ListenerDefinitionBuilder(EventConsumptionStrategyDefinition? to = null)
21+
: ListenerTargetDefinitionBuilder, IListenerDefinitionBuilder
2222
{
2323

2424
/// <summary>
25-
/// Gets/sets the listener's target
25+
/// Gets/sets the <see cref="ListenerDefinition"/> to configure
2626
/// </summary>
27-
protected EventConsumptionStrategyDefinition? Target { get; set; } = target;
27+
protected ListenerDefinition Listener { get; } = new() { To = to! };
2828

2929
/// <inheritdoc/>
30-
public virtual IListenerDefinitionBuilder To(Action<IListenerTargetDefinitionBuilder> setup)
30+
public virtual IListenerDefinitionBuilder Read(string readMode)
3131
{
32-
var builder = new ListenerTargetDefinitionBuilder();
33-
setup(builder);
34-
this.Target = builder.Build();
32+
ArgumentException.ThrowIfNullOrWhiteSpace(readMode);
33+
this.Listener.Read = readMode;
3534
return this;
3635
}
3736

3837
/// <inheritdoc/>
39-
public virtual ListenerDefinition Build()
38+
public virtual new ListenerDefinition Build()
4039
{
41-
if (this.Target == null) throw new NullReferenceException("The listener's target must be set");
42-
return new()
43-
{
44-
To = this.Target
45-
};
40+
var to = base.Build();
41+
if (to == null) throw new NullReferenceException("The listener's target must be set");
42+
this.Listener.To = to;
43+
return this.Listener;
4644
}
4745

4846
}

‎src/ServerlessWorkflow.Sdk.Builders/OAuth2AuthenticationClientDefinitionBuilder.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public class OAuth2AuthenticationClientDefinitionBuilder
4343
/// <inheritdoc/>
4444
public virtual IOAuth2AuthenticationClientDefinitionBuilder WithId(string id)
4545
{
46-
ArgumentException.ThrowIfNullOrEmpty(id);
46+
ArgumentException.ThrowIfNullOrWhiteSpace(id);
4747
this.Id = id;
4848
return this;
4949
}
5050

5151
/// <inheritdoc/>
5252
public virtual IOAuth2AuthenticationClientDefinitionBuilder WithSecret(string secret)
5353
{
54-
ArgumentException.ThrowIfNullOrEmpty(secret);
54+
ArgumentException.ThrowIfNullOrWhiteSpace(secret);
5555
this.Secret = secret;
5656
return this;
5757
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Represents the default implementation of the <see cref="IOutputDataModelDefinitionBuilder"/> interface
18+
/// </summary>
19+
public class OutputDataModelDefinitionBuilder
20+
: IOutputDataModelDefinitionBuilder
21+
{
22+
23+
/// <summary>
24+
/// Gets the <see cref="OutputDataModelDefinition"/> to configure
25+
/// </summary>
26+
protected OutputDataModelDefinition Output { get; } = new();
27+
28+
/// <inheritdoc/>
29+
public virtual IOutputDataModelDefinitionBuilder As(object expression)
30+
{
31+
ArgumentNullException.ThrowIfNull(expression);
32+
this.Output.As = expression;
33+
return this;
34+
}
35+
36+
/// <inheritdoc/>
37+
public virtual IOutputDataModelDefinitionBuilder WithSchema(Action<ISchemaDefinitionBuilder> setup)
38+
{
39+
ArgumentNullException.ThrowIfNull(setup);
40+
var builder = new SchemaDefinitionBuilder();
41+
setup(builder);
42+
this.Output.Schema = builder.Build();
43+
return this;
44+
}
45+
46+
/// <inheritdoc/>
47+
public virtual OutputDataModelDefinition Build() => this.Output;
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Represents the default implementation of the <see cref="ISchemaDefinitionBuilder"/> interface
18+
/// </summary>
19+
public class SchemaDefinitionBuilder
20+
: ISchemaDefinitionBuilder
21+
{
22+
23+
/// <summary>
24+
/// Gets the <see cref="SchemaDefinition"/> to configure
25+
/// </summary>
26+
protected SchemaDefinition Schema { get; } = new();
27+
28+
/// <inheritdoc/>
29+
public virtual ISchemaDefinitionBuilder WithFormat(string format)
30+
{
31+
ArgumentException.ThrowIfNullOrWhiteSpace(format);
32+
this.Schema.Format = format;
33+
return this;
34+
}
35+
36+
/// <inheritdoc/>
37+
public virtual ISchemaDefinitionBuilder WithResource(Action<IExternalResourceDefinitionBuilder> setup)
38+
{
39+
ArgumentNullException.ThrowIfNull(setup);
40+
var builder = new ExternalResourceDefinitionBuilder();
41+
setup(builder);
42+
this.Schema.Resource = builder.Build();
43+
return this;
44+
}
45+
46+
/// <inheritdoc/>
47+
public virtual ISchemaDefinitionBuilder WithDocument(object document)
48+
{
49+
ArgumentNullException.ThrowIfNull(document);
50+
this.Schema.Document = document;
51+
return this;
52+
}
53+
54+
/// <inheritdoc/>
55+
public virtual SchemaDefinition Build() => this.Schema;
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Builders;
15+
16+
/// <summary>
17+
/// Represents the default implementation of the <see cref="ISubscriptionIteratorDefinitionBuilder"/> interface
18+
/// </summary>
19+
public class SubscriptionIteratorDefinitionBuilder
20+
: ISubscriptionIteratorDefinitionBuilder
21+
{
22+
23+
/// <summary>
24+
/// Gets the <see cref="SubscriptionIteratorDefinition"/> to configure
25+
/// </summary>
26+
protected SubscriptionIteratorDefinition Iterator { get; } = new();
27+
28+
/// <inheritdoc/>
29+
public virtual ISubscriptionIteratorDefinitionBuilder Item(string item)
30+
{
31+
ArgumentException.ThrowIfNullOrWhiteSpace(item);
32+
this.Iterator.Item = item;
33+
return this;
34+
}
35+
36+
/// <inheritdoc/>
37+
public virtual ISubscriptionIteratorDefinitionBuilder At(string at)
38+
{
39+
ArgumentException.ThrowIfNullOrWhiteSpace(at);
40+
this.Iterator.At = at;
41+
return this;
42+
}
43+
44+
/// <inheritdoc/>
45+
public virtual ISubscriptionIteratorDefinitionBuilder Do(Action<ITaskDefinitionMapBuilder> setup)
46+
{
47+
ArgumentNullException.ThrowIfNull(setup);
48+
var builder = new TaskDefinitionMapBuilder();
49+
setup(builder);
50+
this.Iterator.Do = builder.Build();
51+
return this;
52+
}
53+
54+
/// <inheritdoc/>
55+
public virtual ISubscriptionIteratorDefinitionBuilder Output(Action<IOutputDataModelDefinitionBuilder> setup)
56+
{
57+
ArgumentNullException.ThrowIfNull(setup);
58+
var builder = new OutputDataModelDefinitionBuilder();
59+
setup(builder);
60+
this.Iterator.Output = builder.Build();
61+
return this;
62+
}
63+
64+
/// <inheritdoc/>
65+
public virtual ISubscriptionIteratorDefinitionBuilder Export(Action<IOutputDataModelDefinitionBuilder> setup)
66+
{
67+
ArgumentNullException.ThrowIfNull(setup);
68+
var builder = new OutputDataModelDefinitionBuilder();
69+
setup(builder);
70+
this.Iterator.Export = builder.Build();
71+
return this;
72+
}
73+
74+
/// <inheritdoc/>
75+
public virtual SubscriptionIteratorDefinition Build() => this.Iterator;
76+
77+
}

‎src/ServerlessWorkflow.Sdk.Builders/TaskDefinitionBuilder.cs

+48
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ public abstract class TaskDefinitionBuilder<TBuilder, TDefinition>
3434
/// </summary>
3535
protected OneOf<TimeoutDefinition, string>? Timeout { get; set; }
3636

37+
/// <summary>
38+
/// Gets/sets the task's input data, if any
39+
/// </summary>
40+
protected InputDataModelDefinition? Input { get; set; }
41+
42+
/// <summary>
43+
/// Gets/sets the task's output data, if any
44+
/// </summary>
45+
protected OutputDataModelDefinition? Output { get; set; }
46+
47+
/// <summary>
48+
/// Gets/sets the task's export data, if any
49+
/// </summary>
50+
protected OutputDataModelDefinition? Export { get; set; }
51+
3752
/// <summary>
3853
/// Gets/sets the flow directive, if any, used to then execute
3954
/// </summary>
@@ -73,6 +88,36 @@ public virtual TBuilder WithTimeout(Action<ITimeoutDefinitionBuilder> setup)
7388
return (TBuilder)(object)this;
7489
}
7590

91+
/// <inheritdoc/>
92+
public virtual TBuilder WithInput(Action<IInputDataModelDefinitionBuilder> setup)
93+
{
94+
ArgumentNullException.ThrowIfNull(setup);
95+
var builder = new InputDataModelDefinitionBuilder();
96+
setup(builder);
97+
this.Input = builder.Build();
98+
return (TBuilder)(object)this;
99+
}
100+
101+
/// <inheritdoc/>
102+
public virtual TBuilder WithOutput(Action<IOutputDataModelDefinitionBuilder> setup)
103+
{
104+
ArgumentNullException.ThrowIfNull(setup);
105+
var builder = new OutputDataModelDefinitionBuilder();
106+
setup(builder);
107+
this.Output = builder.Build();
108+
return (TBuilder)(object)this;
109+
}
110+
111+
/// <inheritdoc/>
112+
public virtual TBuilder WithExport(Action<IOutputDataModelDefinitionBuilder> setup)
113+
{
114+
ArgumentNullException.ThrowIfNull(setup);
115+
var builder = new OutputDataModelDefinitionBuilder();
116+
setup(builder);
117+
this.Export = builder.Build();
118+
return (TBuilder)(object)this;
119+
}
120+
76121
/// <inheritdoc/>
77122
public virtual TBuilder Then(string directive)
78123
{
@@ -95,6 +140,9 @@ protected virtual TDefinition Configure(TDefinition definition)
95140
else definition.TimeoutReference = this.Timeout.T2Value;
96141
}
97142
definition.Then = this.ThenDirective;
143+
definition.Input = this.Input;
144+
definition.Output = this.Output;
145+
definition.Export = this.Export;
98146
return definition;
99147
}
100148

‎src/ServerlessWorkflow.Sdk.Builders/WorkflowDefinitionBuilder.cs

+30
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ public class WorkflowDefinitionBuilder
6363
/// </summary>
6464
protected OneOf<TimeoutDefinition, string>? Timeout { get; set; }
6565

66+
/// <summary>
67+
/// Gets/sets the workflow's input data, if any
68+
/// </summary>
69+
protected InputDataModelDefinition? Input { get; set; }
70+
71+
/// <summary>
72+
/// Gets/sets the workflow's output data, if any
73+
/// </summary>
74+
protected OutputDataModelDefinition? Output { get; set; }
75+
6676
/// <summary>
6777
/// Gets/sets a name/value mapping of the workflow's reusable components
6878
/// </summary>
@@ -166,6 +176,26 @@ public virtual IWorkflowDefinitionBuilder WithTimeout(Action<ITimeoutDefinitionB
166176
return this;
167177
}
168178

179+
/// <inheritdoc/>
180+
public virtual IWorkflowDefinitionBuilder WithInput(Action<IInputDataModelDefinitionBuilder> setup)
181+
{
182+
ArgumentNullException.ThrowIfNull(setup);
183+
var builder = new InputDataModelDefinitionBuilder();
184+
setup(builder);
185+
this.Input = builder.Build();
186+
return this;
187+
}
188+
189+
/// <inheritdoc/>
190+
public virtual IWorkflowDefinitionBuilder WithOutput(Action<IOutputDataModelDefinitionBuilder> setup)
191+
{
192+
ArgumentNullException.ThrowIfNull(setup);
193+
var builder = new OutputDataModelDefinitionBuilder();
194+
setup(builder);
195+
this.Output = builder.Build();
196+
return this;
197+
}
198+
169199
/// <inheritdoc/>
170200
public virtual IWorkflowDefinitionBuilder UseAuthentication(string name, AuthenticationPolicyDefinition authentication)
171201
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk;
15+
16+
/// <summary>
17+
/// Enumerates all supported event read modes
18+
/// </summary>
19+
public static class EventReadMode
20+
{
21+
22+
/// <summary>
23+
/// Indicates that only the data of consumed events should be read
24+
/// </summary>
25+
public const string Data = "data";
26+
/// <summary>
27+
/// Indicates that the whole event envelope should be read, including context attributes
28+
/// </summary>
29+
public const string Envelope = "envelope";
30+
/// <summary>
31+
/// Indicates that the event's raw data should be read, without additional transformation (i.e. deserialization)
32+
/// </summary>
33+
public const string Raw = "raw";
34+
35+
/// <summary>
36+
/// Gets a new <see cref="IEnumerable{T}"/> containing all supported event read modes
37+
/// </summary>
38+
/// <returns>A new <see cref="IEnumerable{T}"/> containing all supported event read modes</returns>
39+
public static IEnumerable<string> AsEnumerable()
40+
{
41+
yield return Data;
42+
yield return Envelope;
43+
yield return Raw;
44+
}
45+
46+
}

‎src/ServerlessWorkflow.Sdk/Models/AsyncApiMessageDefinition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ public record AsyncApiMessageDefinition
3232
[DataMember(Name = "headers", Order = 2), JsonPropertyName("headers"), JsonPropertyOrder(2), YamlMember(Alias = "headers", Order = 2)]
3333
public virtual object? Headers { get; set; }
3434

35-
}
35+
}

‎src/ServerlessWorkflow.Sdk/Models/AsyncApiSubscriptionDefinition.cs

+6
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ public record AsyncApiSubscriptionDefinition
3333
[DataMember(Name = "consume", Order = 2), JsonPropertyName("consume"), JsonPropertyOrder(2), YamlMember(Alias = "consume", Order = 2)]
3434
public required virtual AsyncApiSubscriptionLifetimeDefinition Consume { get; set; }
3535

36+
/// <summary>
37+
/// Gets/sets the configuration of the iterator, if any, used to process each consumed message
38+
/// </summary>
39+
[DataMember(Name = "foreach", Order = 3), JsonPropertyName("foreach"), JsonPropertyOrder(3), YamlMember(Alias = "foreach", Order = 3)]
40+
public virtual SubscriptionIteratorDefinition? Foreach { get; set; }
41+
3642
}

‎src/ServerlessWorkflow.Sdk/Models/ListenerDefinition.cs

+7
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ public record ListenerDefinition
2727
[DataMember(Name = "to", Order = 1), JsonPropertyName("to"), JsonPropertyOrder(1), YamlMember(Alias = "to", Order = 1)]
2828
public required virtual EventConsumptionStrategyDefinition To { get; set; }
2929

30+
/// <summary>
31+
/// Gets/sets a string that specifies how events are read during the listen operation<para></para>
32+
/// See <see cref="EventReadMode"/>. Defaults to <see cref="EventReadMode.Data"/>
33+
/// </summary>
34+
[DataMember(Name = "read", Order = 1), JsonPropertyName("read"), JsonPropertyOrder(1), YamlMember(Alias = "read", Order = 1)]
35+
public virtual string? Read { get; set; }
36+
3037
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright © 2024-Present The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"),
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
namespace ServerlessWorkflow.Sdk.Models;
15+
16+
/// <summary>
17+
/// Represents the definition of a subscription iterator, used to configure the processing of each event or message consumed by a subscription
18+
/// </summary>
19+
[DataContract]
20+
public record SubscriptionIteratorDefinition
21+
{
22+
23+
/// <summary>
24+
/// Gets/sets the name of the variable used to store the item being enumerated.<para></para>
25+
/// Defaults to `item`
26+
/// </summary>
27+
[DataMember(Name = "item", Order = 1), JsonPropertyName("item"), JsonPropertyOrder(1), YamlMember(Alias = "item", Order = 1)]
28+
public virtual string? Item { get; set; }
29+
30+
/// <summary>
31+
/// Gets/sets the name of the variable used to store the index of the item being enumerates<para></para>
32+
/// Defaults to `index`
33+
/// </summary>
34+
[DataMember(Name = "at", Order = 2), JsonPropertyName("at"), JsonPropertyOrder(2), YamlMember(Alias = "at", Order = 2)]
35+
public virtual string? At { get; set; }
36+
37+
/// <summary>
38+
/// Gets/sets the tasks to run for each consumed event or message
39+
/// </summary>
40+
[DataMember(Name = "do", Order = 3), JsonPropertyName("do"), JsonPropertyOrder(3), YamlMember(Alias = "do", Order = 3)]
41+
public virtual Map<string, TaskDefinition>? Do { get; set; }
42+
43+
/// <summary>
44+
/// Gets/sets the definition, if any, of the data to output for each iteration
45+
/// </summary>
46+
[DataMember(Name = "output", Order = 4), JsonPropertyName("output"), JsonPropertyOrder(4), YamlMember(Alias = "output", Order = 4)]
47+
public virtual OutputDataModelDefinition? Output { get; set; }
48+
49+
/// <summary>
50+
/// Gets/sets the definition, if any, of the data to export for each iteration
51+
/// </summary>
52+
[DataMember(Name = "export", Order = 5), JsonPropertyName("export"), JsonPropertyOrder(5), YamlMember(Alias = "export", Order = 5)]
53+
public virtual OutputDataModelDefinition? Export { get; set; }
54+
55+
}

‎src/ServerlessWorkflow.Sdk/Models/Tasks/ListenTaskDefinition.cs

+6
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ public record ListenTaskDefinition
3232
[DataMember(Name = "listen", Order = 1), JsonPropertyName("listen"), JsonPropertyOrder(1), YamlMember(Alias = "listen", Order = 1)]
3333
public required virtual ListenerDefinition Listen { get; set; }
3434

35+
/// <summary>
36+
/// Gets/sets the configuration of the iterator, if any, used to process each consumed event
37+
/// </summary>
38+
[DataMember(Name = "foreach", Order = 2), JsonPropertyName("foreach"), JsonPropertyOrder(2), YamlMember(Alias = "foreach", Order = 2)]
39+
public virtual SubscriptionIteratorDefinition? Foreach { get; set; }
40+
3541
}

0 commit comments

Comments
 (0)
Please sign in to comment.