Skip to content

Commit dce821b

Browse files
authored
Merge branch 'main' into fix-component-references
2 parents 2eb0bac + c4daa76 commit dce821b

File tree

2 files changed

+75
-35
lines changed

2 files changed

+75
-35
lines changed

dsl-reference.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,17 +1590,17 @@ Represents the definition of the parameters that control the randomness or varia
15901590

15911591
### Input
15921592

1593-
Documents the structure - and optionally configures the filtering of - workflow/task input data.
1593+
Documents the structure - and optionally configures the transformation of - workflow/task input data.
15941594

15951595
It's crucial for authors to document the schema of input data whenever feasible. This documentation empowers consuming applications to provide contextual auto-suggestions when handling runtime expressions.
15961596

1597-
When set, runtimes must validate input data against the defined schema, unless defined otherwise.
1597+
When set, runtimes must validate raw input data against the defined schema before applying transformations, unless defined otherwise.
15981598

15991599
#### Properties
16001600

16011601
| Property | Type | Required | Description |
16021602
|----------|:----:|:--------:|-------------|
1603-
| schema | [`schema`](#schema) | `no` | The [`schema`](#schema) used to describe and validate input data.<br>*Even though the schema is not required, it is strongly encouraged to document it, whenever feasible.* |
1603+
| schema | [`schema`](#schema) | `no` | The [`schema`](#schema) used to describe and validate raw input data.<br>*Even though the schema is not required, it is strongly encouraged to document it, whenever feasible.* |
16041604
| from | `string`<br>`object` | `no` | A [runtime expression](dsl.md#runtime-expressions), if any, used to filter and/or mutate the workflow/task input. |
16051605

16061606
#### Examples
@@ -1611,9 +1611,16 @@ schema:
16111611
document:
16121612
type: object
16131613
properties:
1614-
petId:
1615-
type: string
1616-
required: [ petId ]
1614+
order:
1615+
type: object
1616+
required: [ pet ]
1617+
properties:
1618+
pet:
1619+
type: object
1620+
required: [ id ]
1621+
properties:
1622+
id:
1623+
type: string
16171624
from: .order.pet
16181625
```
16191626

@@ -1623,7 +1630,7 @@ Documents the structure - and optionally configures the transformations of - wor
16231630

16241631
It's crucial for authors to document the schema of output data whenever feasible. This documentation empowers consuming applications to provide contextual auto-suggestions when handling runtime expressions.
16251632

1626-
When set, runtimes must validate output data against the defined schema, unless defined otherwise.
1633+
When set, runtimes must validate output data against the defined schema after applying transformations, unless defined otherwise.
16271634

16281635
#### Properties
16291636

@@ -1646,16 +1653,13 @@ output:
16461653
required: [ petId ]
16471654
as:
16481655
petId: '${ .pet.id }'
1649-
export:
1650-
as:
1651-
'.petList += [ $task.output ]'
16521656
```
16531657

16541658
### Export
16551659

1656-
Certain task needs to set the workflow context to save the task output for later usage. Users set the content of the context through a runtime expression. The result of the expression is the new value of the context. The expression is evaluated against the existing context.
1660+
Certain task needs to set the workflow context to save the task output for later usage. Users set the content of the context through a runtime expression. The result of the expression is the new value of the context. The expression is evaluated against the transformed task output.
16571661

1658-
Optionally, the context might have an associated schema.
1662+
Optionally, the context might have an associated schema which is validated against the result of the expression.
16591663

16601664
#### Properties
16611665

@@ -1669,13 +1673,13 @@ Optionally, the context might have an associated schema.
16691673
Merge the task output into the current context.
16701674

16711675
```yaml
1672-
as: '.+$output'
1676+
as: '$context+.'
16731677
```
16741678

16751679
Replace the context with the task output.
16761680

16771681
```yaml
1678-
as: $output
1682+
as: '.'
16791683
```
16801684

16811685
### Schema

dsl.md

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,98 +181,134 @@ Once the task has been executed, different things can happen:
181181

182182
### Data Flow
183183

184-
In Serverless Workflow DSL, data flow management is crucial to ensure that the right data is passed between tasks and to the workflow itself.
184+
In Serverless Workflow DSL, data flow management is crucial to ensure that the right data is passed between tasks and to the workflow itself.
185185

186186
Here's how data flows through a workflow based on various transformation stages:
187187

188-
1. **Transform Workflow Input**
188+
1. **Validate Workflow Input**
189+
Before the workflow starts, the input data provided to the workflow can be validated against the `input.schema` property to ensure it conforms to the expected structure.
190+
The execution only proceeds if the input is valid. Otherwise, it will fault with a [ValidationError (https://serverlessworkflow.io/spec/1.0.0/errors/validation)](dsl-reference.md#error).
191+
192+
2. **Transform Workflow Input**
189193
Before the workflow starts, the input data provided to the workflow can be transformed to ensure only relevant data in the expected format is passed into the workflow context. This can be done using the top level `input.from` expression. It evaluates on the raw workflow input and defaults to the identity expression which leaves the input unchanged. This step allows the workflow to start with a clean and focused dataset, reducing potential overhead and complexity in subsequent tasks. The result of this expression will set as the initial value for the `$context` runtime expression argument and be passed to the first task.
190194

191195
*Example: If the workflow receives a JSON object as input, a transformation can be applied to remove unnecessary fields and retain only those that are required for the workflow's execution.*
192196

193-
2. **Transform First Task Input**
194-
The input data for the first task can be transformed to match the specific requirements of that task. This ensures that the first task receives only the data required to perform its operations. This can be done using the task's `input.from` expression. It evaluates the transformed workflow input and defaults to the identity expression, which leaves the input unchanged. The result of this expression will be set as the `$input` runtime expression argument and be passed to the task. This transformed input will be evaluated against any runtime expressions used within the task definition.
197+
After workflow input validation and transformation, the transformed input is passed as the raw input to the first task.
198+
199+
3. **Validate Task Input**
200+
Before a task executes, its raw input can be validated against the `input.schema` property to ensure it conforms to the expected structure.
201+
The execution only proceeds if the input is valid. Otherwise, it will fault with a [ValidationError (https://serverlessworkflow.io/spec/1.0.0/errors/validation)](dsl-reference.md#error).
195202

196-
*Example: If the first task is a function call that only needs a subset of the workflow input, a transformation can be applied to provide only those fields needed for the function to execute.*
203+
4. **Transform Task Input**
204+
The input data for the task can be transformed to match the specific requirements of that task. This ensures that the task receives only the data required to perform its operations. This can be done using the task's `input.from` expression. It evaluates the raw task input (i.e., the transformed workflow input for the first task or the transformed output of the previous task) and defaults to the identity expression, which leaves the input unchanged. The result of this expression will be set as the `$input` runtime expression argument and be passed to the task. This transformed input will be evaluated against any runtime expressions used within the task definition.
197205

198-
3. **Transform First Task Output**
199-
After completing the first task, its output can be transformed before passing it to the next task or storing it in the workflow context. Transformations are applied using the `output.as` runtime expression. It evaluates the raw task output and defaults to the identity expression, which leaves the output unchanged. Its result will be input for the next task. To update the context, one uses the `export.as` runtime expression. It evaluates the raw output and defaults to the expression that returns the existing context. The result of this runtime expression replaces the workflow's current context and the content of the `$context` runtime expression argument. This helps manage the data flow and keep the context clean by removing any unnecessary data produced by the task.
206+
*Example: If the task is a function call that only needs a subset of the workflow input, a transformation can be applied to provide only those fields needed for the function to execute.*
200207

201-
*Example: If the first task returns a large dataset, a transformation can be applied to retain only the relevant results needed for subsequent tasks.*
208+
5. **Transform Task Output**
209+
After completing the task, its output can be transformed before passing it to the next task or storing it in the workflow context. Transformations are applied using the `output.as` runtime expression. It evaluates the raw task output and defaults to the identity expression, which leaves the output unchanged. Its result will be input for the next task.
202210

203-
4. **Transform Last Task Input**
204-
Before the last task in the workflow executes, its input data can be transformed to ensure it receives only the necessary information. This can be done using the task's `input.from` expression. It evaluates the transformed workflow input and defaults to the identity expression, which leaves the input unchanged. The result of this expression will be set as the `$input` runtime expression argument and be passed to the task. This transformed input will be evaluated against any runtime expressions used within the task definition. This step is crucial for ensuring the final task has all the required data to complete the workflow successfully.
211+
*Example: If the task returns a large dataset, a transformation can be applied to retain only the relevant results needed for subsequent tasks.*
205212

206-
*Example: If the last task involves generating a report, the input transformation can ensure that only the data required for the report generation is passed to the task.*
213+
6. **Validate Task Output**
214+
After `output.as` is evaluated, the transformed task output is validated against the `output.schema` property to ensure it conforms to the expected structure. The execution only proceeds if the output is valid. Otherwise, it will fault with a [ValidationError (https://serverlessworkflow.io/spec/1.0.0/errors/validation)](dsl-reference.md#error).
207215

208-
5. **Transform Last Task Output**
209-
After the last task completes, its output can be transformed before it is considered the workflow output. Transformations are applied using the `output.as` runtime expression. It evaluates the raw task output and defaults to the identity expression, which leaves the output unchanged. Its result will be passed to the workflow `output.as` runtime expression. This ensures that the workflow produces a clean and relevant output, free from any extraneous data that might have been generated during the task execution.
216+
7. **Update Workflow Context**
217+
To update the context, one uses the `export.as` runtime expression. It evaluates the transformed task output and defaults to the expression that returns the existing context. The result of this runtime expression replaces the workflow's current context and the content of the `$context` runtime expression argument. This helps manage the data flow and keep the context clean by removing any unnecessary data produced by the task.
210218

211-
*Example: If the last task outputs various statistics, a transformation can be applied to retain only the key metrics that are relevant to the stakeholders.*
219+
8. **Validate Exported Context**
220+
After the context is updated, the exported context is validated against the `export.schema` property to ensure it conforms to the expected structure. The execution only proceeds if the exported context is valid. Otherwise, it will fault with a [ValidationError (https://serverlessworkflow.io/spec/1.0.0/errors/validation)](dsl-reference.md#error).
212221

213-
6. **Transform Workflow Output**
214-
Finally, the overall workflow output can be transformed before it is returned to the caller or stored. Transformations are applied using the `output.as` runtime expression. It evaluates the last task's output and defaults to the identity expression, which leaves the output unchanged. This step ensures that the final output of the workflow is concise and relevant, containing only the necessary information that needs to be communicated or recorded.
222+
9. **Continue Workflow**
223+
After the context is updated, the workflow continues to the next task in the sequence. The transformed output of the previous task is passed as the raw input to the next task, and the data flow cycle repeats.
224+
If no more tasks are defined, the transformed output is passed to the workflow output transformation step.
225+
226+
10. **Transform Workflow Output**
227+
Finally, the overall workflow output can be transformed before it is returned to the caller or stored. Transformations are applied using the `output.as` runtime expression. It evaluates the last task's transformed output and defaults to the identity expression, which leaves the output unchanged. This step ensures that the final output of the workflow is concise and relevant, containing only the necessary information that needs to be communicated or recorded.
215228

216229
*Example: If the workflow's final output is a summary report, a transformation can ensure that the report contains only the most important summaries and conclusions, excluding any intermediate data.*
217230

231+
11. **Validate Workflow Output**
232+
After `output.as` is evaluated, the transformed workflow output is validated against the `output.schema` property to ensure it conforms to the expected structure. The execution only proceeds if the output is valid. Otherwise, it will fault with a [ValidationError (https://serverlessworkflow.io/spec/1.0.0/errors/validation)](dsl-reference.md#error).
233+
218234
By applying transformations at these strategic points, Serverless Workflow DSL ensures that data flows through the workflow in a controlled and efficient manner, maintaining clarity and relevance at each execution stage. This approach helps manage complex workflows and ensures that each task operates with the precise data required, leading to more predictable and reliable workflow outcomes.
219235

220236
Visually, this can be represented as follows:
221237

222238
```mermaid
223239
flowchart TD
224240
241+
subgraph Legend
242+
legend_data{{Data}}
243+
legend_schema[\Schema/]
244+
legend_transformation[Transformation]
245+
legend_arg([Runtime Argument])
246+
end
247+
225248
initial_context_arg([<code>$context</code>])
226249
context_arg([<code>$context</code>])
227250
input_arg([<code>$input</code>])
228251
output_arg([<code>$output</code>])
229252
230253
workflow_raw_input{{Raw Workflow Input}}
254+
workflow_input_schema[\Workflow: <code>input.schema</code>/]
231255
workflow_input_from[Workflow: <code>input.from</code>]
232256
workflow_transformed_input{{Transformed Workflow Input}}
233257
234258
task_raw_input{{Raw Task Input}}
259+
task_input_schema[\Task: <code>input.schema</code>/]
235260
task_input_from[Task: <code>input.from</code>]
236261
task_transformed_input{{Transformed Task Input}}
237262
task_definition[Task definition]
238263
task_raw_output{{Raw Task output}}
239264
task_output_as[Task: <code>output.as</code>]
240265
task_transformed_output{{Transformed Task output}}
266+
task_output_schema[\Task: <code>output.schema</code>/]
241267
task_export_as[Task: <code>export.as</code>]
268+
task_export_schema[\Task: <code>export.schema</code>/]
269+
270+
new_context{{New execution context}}
242271
243272
workflow_raw_output{{Raw Workflow Output}}
244273
workflow_output_as[Workflow: <code>output.as</code>]
245274
workflow_transformed_output{{Transformed Workflow Output}}
275+
workflow_output_schema[\Workflow: <code>output.schema</code>/]
246276
247-
workflow_raw_input --> workflow_input_from
277+
workflow_raw_input -- Validated by --> workflow_input_schema
278+
workflow_input_schema -- Passed to --> workflow_input_from
248279
workflow_input_from -- Produces --> workflow_transformed_input
249280
workflow_transformed_input -- Set as --> initial_context_arg
250281
workflow_transformed_input -- Passed to --> task_raw_input
251282
252283
subgraph Task
253284
254-
task_raw_input -- Passed to --> task_input_from
285+
task_raw_input -- Validated by --> task_input_schema
286+
task_input_schema -- Passed to --> task_input_from
255287
task_input_from -- Produces --> task_transformed_input
256288
task_transformed_input -- Set as --> input_arg
257289
task_transformed_input -- Passed to --> task_definition
258290
259291
task_definition -- Execution produces --> task_raw_output
260292
task_raw_output -- Passed to --> task_output_as
261293
task_output_as -- Produces --> task_transformed_output
262-
task_output_as -- Set as --> output_arg
263-
task_transformed_output -- Passed to --> task_export_as
294+
task_transformed_output -- Set as --> output_arg
295+
task_transformed_output -- Validated by --> task_output_schema
296+
task_output_schema -- Passed to --> task_export_as
297+
task_export_as -- Produces --> new_context
298+
new_context -- Validated by --> task_export_schema
264299
end
265300
266301
task_transformed_output -- Passed as raw input to --> next_task
267302
268303
subgraph next_task [Next Task]
269304
end
270305
271-
task_export_as -- Result set as --> context_arg
306+
new_context -- set as --> context_arg
272307
273308
next_task -- Transformed output becomes --> workflow_raw_output
274309
workflow_raw_output -- Passed to --> workflow_output_as
275310
workflow_output_as -- Produces --> workflow_transformed_output
311+
workflow_transformed_output -- Validated by --> workflow_output_schema
276312
```
277313

278314
### Runtime Expressions

0 commit comments

Comments
 (0)