Skip to content

Commit 072d5e4

Browse files
authored
Merge pull request #77 from serverlessworkflow/feat-subscription-iterator
Add the `SubscriptionIteratorDefinition` model
2 parents 44d7648 + bfabec1 commit 072d5e4

26 files changed

+715
-48
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+
}

Diff for: 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
}

Diff for: 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+
}

Diff for: 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>

Diff for: 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>

0 commit comments

Comments
 (0)