# Serverless Workflow DSL ## Table of Contents - [Abstract](#abstract) - [Motivation](#motivation) - [Priority of Constituencies](#priority-of-constituencies) - [Design](#design) - [Concepts](#concepts) + [Workflow](#workflow) - [Status Phases](#status-phases) - [Lifecycle Events](#lifecycle-events) + [Workflow Lifecycle Events](#workflow-lifecycle-events) + [Task Lifecycle Events](#task-lifecycle-events) - [Components](#components) + [Task](#task) - [Scheduling](#scheduling) + [Event-Driven Scheduling](#event-driven-scheduling) + [Task Flow](#task-flow) + [Data Flow](#data-flow) + [Runtime Expressions](#runtime-expressions) - [Arguments](#runtime-expression-arguments) + [Fault Tolerance](#fault-tolerance) + [Timeouts](#timeouts) + [Catalogs](#catalogs) + [File Structure](#file-structure) + [Default Catalog](#default-catalog) + [Using Cataloged Functions](#using-cataloged-functions) + [Interoperability](#interoperability) - [Supported Protocols](#supported-protocols) - [Custom and Non-Standard Interactions](#custom-and-non-standard-interactions) + [Creating a Custom Function](#creating-a-custom-function) + [Using a Custom Function](#using-a-custom-function) + [Publishing a Custom Function](#publishing-a-custom-function) + [Events](#events) + [Extensions](#extensions) + [External Resources](#external-resources) + [Authentication](#authentication) ## Abstract This document proposes the creation of a Domain Specific Language (DSL) called Serverless Workflow, tailored for building platform agnostic workflows. Serverless Workflow aims to simplify the orchestration of complex processes across diverse environments, providing developers with a unified syntax and set of tools for defining and executing serverless workflows. ## Motivation Serverless computing has gained popularity for its ability to abstract away infrastructure management tasks, enabling developers to focus on application logic. However, orchestrating serverless workflows across multiple environments often involves dealing with disparate tools and platforms, leading to complexity and inefficiency. Serverless Workflow addresses this challenge by providing a DSL specifically designed for serverless workflow orchestration. By abstracting away the underlying infrastructure complexities and offering a modular and extensible framework, Serverless Workflow aims to streamline the development, deployment, and management of serverless workflows. ## Priority of Constituencies Inspired by the [Priority of Constituencies](https://www.w3.org/TR/2024/NOTE-design-principles-20240718/#priority-of-constituencies) principle from the W3C Design Principles, the Serverless Workflow DSL prioritizes the following constituencies (collectively referred to as "users"): - Authors: people authoring and reading workflows - Operators: people running and operating a runtime implementation of the specification - Implementors: people implementing a specification compliant runtime - Specifications writers: people working on the specifications of Serverless Workflow If a trade-off needs to be made, always put author's needs above all. Similarly, when beginning to design an API, be sure to understand and document the user needs that the API aims to address. Author needs come before the needs of operators, which come before the needs of runtime implementors, which come before the needs of specification writers, which come before theoretical purity. Like all principles, this isn’t absolute. Ease of operations affects the perceived reliability of authors' workflows. Implementors have to prioritize finite engineering resources, which affects how features reach authors. Specification writers also have finite resources, and theoretical concerns reflect the underlying needs of all of these groups. ## Design The Serverless Workflow DSL is crafted with a design philosophy that prioritizes clarity, expressiveness, and ease of use. Its foundation lies in linguistic fluency, emphasizing readability and comprehension. By adopting a fluent style, the DSL promotes intuitive understanding through natural language constructs. Verbs are employed in the imperative tense to denote actions, enhancing clarity and directness in expressing workflow logic. This imperative approach empowers developers to articulate their intentions succinctly and effectively. The DSL also embraces the principle of implicit default behaviors, sparing authors from unnecessary repetition and enhancing the conciseness of workflow definitions. For instance, default settings alleviate the burden of explicitly defining every detail, streamlining the workflow design process. Furthermore, the DSL allows both inline declaration of components or the creation of reusable elements, granting flexibility in workflow composition. This flexibility allows developers to seamlessly integrate inline task definitions without imposing rigid structural requirements. Moreover, the DSL eschews strong-typed enumerations wherever feasible, fostering extensibility and adaptability across different runtime environments. While maintaining portability is crucial, the DSL prioritizes customization options for extensions and runtimes, enabling tailored implementations to suit diverse use cases. Additionally, the DSL favors universally understood terms over technical jargon, enhancing accessibility and comprehension for a broader audience. - Embrace linguistic fluency for enhanced readability and understanding. - Utilize imperative verbs to convey actions directly and clearly. - Employ implicit default behaviors to reduce redundancy and streamline workflow definitions. - Enable the declaration and effortless import of shared components by supporting external references - Encourage the declaration of components inline for situations where reusability is unnecessary, prioritizing ease of use in such cases. - Prioritize flexibility over strong-typed enumerations for enhanced extensibility. - Opt for universally understood terms to improve accessibility and comprehension. ## Concepts ### Workflow A Serverless Workflow is a sequence of specific [tasks](dsl-reference.md#tasks) that are executed in a defined order. By default, this order follows the declaration sequence within the workflow definition. Workflows are designed to automate processes and orchestrate various serverless functions and services. Workflows can be triggered in different ways: upon request, scheduled using CRON expressions, or initiated upon correlation with specific events. Additionally, workflows may optionally accept inputs and produce outputs, allowing for data processing and transformation within the workflow execution. #### Status Phases Both workflows and tasks in the Serverless Workflow DSL can exist in several phases, each indicating the current state of the workflow/task execution. These phases include: | Phase | Description | | --- | --- | | `pending` | The workflow/task has been initiated and is pending execution. | | `running` | The workflow/task is currently in progress. | | `waiting` | The workflow/task execution is temporarily paused, awaiting either inbound event(s) or a specified time interval as defined by a [`wait`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#wait) task. | | `suspended` | The workflow/task execution has been manually paused by a user and will remain halted until explicitly resumed. | | `cancelled` | The workflow/task execution has been terminated before completion. | | `faulted` | The workflow/task execution has encountered an error. | | `completed` | The workflow/task ran to completion. | Additionally, the flow of execution within a workflow can be controlled using [directives*](dsl-reference.md#flow-directive), which provide instructions to the workflow engine on how to manage and handle specific aspects of workflow execution. \**To learn more about flow directives and how they can be utilized to control the execution and behavior of workflows, please refer to [Flow Directives](dsl-reference.md#flow-directive).* #### Lifecycle Events Lifecycle [cloud events](https://github.com/cloudevents/spec) standardize notifications for key state changes in workflows and tasks—such as start, suspend, resume, cancel, fault, complete, and status change. These events carry consistent information like IDs, status transitions, timestamps, and relevant metadata, enabling users to reliably respond to updates, enhancing interoperability and simplifying integration across different implementations. Runtimes are expected to publish these events upon state changes. While using the [HTTP protocol binding](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md) with [structured content mode](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md#32-structured-content-mode) is recommended, other transports adhering to the [CloudEvents](https://github.com/cloudevents/spec) specification may be used. ##### Workflow Lifecycle Events | Type | Data | Required | Description | |:----:|:----:|:--------:|:------------| |
`io.serverlessworkflow.workflow.started.v1`| [`workflowStartedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-started-event) | `yes` | Notifies about the start of a workflow. | |
`io.serverlessworkflow.workflow.suspended.v1`| [`workflowSupsendedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-suspended-event) | `yes` | Notifies about suspending a workflow execution. | |
`io.serverlessworkflow.workflow.resumed.v1`| [`workflowResumedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-resumed-event) | `yes` | Notifies about resuming a workflow execution. | |
`io.serverlessworkflow.workflow.correlation-started.v1`| [`workflowCorrelationStartedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-correlation-started-event) | `yes` | Notifies about a workflow starting to correlate events. | |
`io.serverlessworkflow.workflow.correlation-completed.v1`| [`workflowCorrelationCompletedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-correlation-completed-event) | `yes` | Notifies about a workflow completing an event correlation. | |
`io.serverlessworkflow.workflow.cancelled.v1`| [`workflowCancelledEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-cancelled-event) | `yes` | Notifies about the cancellation of a workflow execution. | |
`io.serverlessworkflow.workflow.faulted.v1`| [`workflowFaultedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-faulted-event) | `yes` | Notifies about a workflow being faulted. | |
`io.serverlessworkflow.workflow.completed.v1`| [`workflowCompletedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-completed-event) | `yes` |Notifies about the completion of a workflow execution. | |
`io.serverlessworkflow.workflow.status-changed.v1`| [`workflowStatusChangedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#workflow-status-changed-event) | `no` |Notifies about the change of a workflow's status phase. | > [!NOTE] > The `io.serverlessworkflow.workflow.status-changed.v1` event is an optional convenience event that notifies consumers solely about a workflow’s status changes, without carrying extra data. It is typically used by consumers who only need to track or report status updates (and not details like faults or outputs). Its use is optional because it requires runtimes to publish an additional event for each necessary lifecycle change. ##### Task Lifecycle Events | Type | Data | Required | Description | |:----:|:----:|:--------:|:------------| |
`io.serverlessworkflow.task.created.v1`| [`taskCreatedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-created-event) | `yes` | Notifies about the creation of a task. | |
`io.serverlessworkflow.task.started.v1`| [`taskStartedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-started-event) | `yes` | Notifies about the start of a task. | |
`io.serverlessworkflow.task.suspended.v1`| [`taskSuspendedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-suspended-event) | `yes` | Notifies about suspending a task's execution. | |
`io.serverlessworkflow.task.resumed.v1`| [`taskResumedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-resumed-event) | `yes` | Notifies about resuming a task's execution. | |
`io.serverlessworkflow.task.retried.v1`| [`taskRetriedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-retried-event) | `yes` | Notifies about retrying a task's execution. | |
`io.serverlessworkflow.task.cancelled.v1`| [`taskCancelledEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-cancelled-event) | `yes` | Notifies about the cancellation of a task's execution. | |
`io.serverlessworkflow.task.faulted.v1`| [`taskFaultedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-faulted-event) | `yes` | Notifies about a task being faulted. | |
`io.serverlessworkflow.task.completed.v1`| [`taskCompletedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-completed-event) | `yes` | Notifies about the completion of a task's execution. | |
`io.serverlessworkflow.task.status-changed.v1`| [`taskStatusChangedEvent`](https://github.com/serverlessworkflow/specification/blob/main/dsl-reference.md#task-status-changed-event) | `no` | Notifies about the change of a task's status phase. | > [!NOTE] > The `io.serverlessworkflow.task.status-changed.v1` event is an optional convenience event that notifies consumers solely about a task's status changes, without carrying extra data. It is typically used by consumers who only need to track or report status updates (and not details like faults or outputs). Its use is optional because it requires runtimes to publish an additional event for each necessary lifecycle change. #### Components Serverless Workflow DSL allows for defining reusable components that can be referenced across the workflow. These include: - [Authentications](dsl-reference.md#authentication) - [Errors](dsl-reference.md#error) - [Extensions](dsl-reference.md#extension) - [Functions](dsl-reference.md#task) - [Retries](dsl-reference.md#retry) - [Secrets](#secret) ##### Task [Tasks](dsl-reference.md#tasks) are the fundamental computing units of a workflow. They define the different types of actions that a workflow can perform, including the ability to mutate their input and output data. Tasks can also write to and modify the context data, enabling complex and dynamic workflow behaviors. The Serverless Workflow DSL defines several default [task](dsl-reference.md#tasks) types that runtimes **must** implement: - [Call](dsl-reference.md#call), used to call services and/or functions. - [Do](dsl-reference.md#do), used to define one or more subtasks to perform in sequence. - [Emit](dsl-reference.md#emit), used to emit [events](dsl-reference.md#event). - [For](dsl-reference.md#for), used to iterate over a collection of items, and conditionally perform a task for each of them. - [Fork](dsl-reference.md#fork), used to define one or more two subtasks to perform in parallel. - [Listen](dsl-reference.md#listen), used to listen for an [event](dsl-reference.md#event) or more. - [Raise](dsl-reference.md#raise), used to raise an [error](dsl-reference.md#error) and potentially fault the [workflow](dsl-reference.md#workflow). - [Run](dsl-reference.md#run), used to run a [container](dsl-reference.md#container-process), a [script](dsl-reference.md#script-process), a [shell](dsl-reference.md#shell-process) command or even another [workflow](dsl-reference.md#workflow-process). - [Set](dsl-reference.md#set), used to dynamically set the [workflow](dsl-reference.md#workflow)'s data during the its execution. - [Switch](dsl-reference.md#switch), used to dynamically select and execute one of multiple alternative paths based on specified conditions - [Try](dsl-reference.md#try), used to attempt executing a specified [task](dsl-reference.md#task), and to handle any resulting [errors](dsl-reference.md#error) gracefully, allowing the [workflow](dsl-reference.md#workflow) to continue without interruption. - [Wait](dsl-reference.md#wait), used to pause or wait for a specified duration before proceeding to the next task. To ensure they conform to the DSL, runtimes **should** pass all the feature conformance test scenarios defined in the [ctk](ctk/README.md). ##### Secret Secrets are sensitive information required by a workflow to securely access protected resources or services. They provide a way to securely store and manage credentials, tokens, or other sensitive data used during workflow execution. Runtime **must** implement a mechanism capable of providing the workflow with the data contained within the defined secrets. If a workflow attempts to access a secret to which it does not have access rights or which does not exist, runtimes **must** raise an error with type `https://serverlessworkflow.io/spec/1.0.0/errors/authorization` and status `403`. #### Scheduling Workflow scheduling in ServerlessWorkflow allows developers to specify when and how their workflows should be executed, ensuring timely response to events and efficient resource utilization. It offers four key properties: `every`, `cron`, `after`, and `on`. - The `every` property defines the interval for workflow execution, ensuring periodic runs regardless of the previous run's status. - With `cron`, developers can use CRON expressions to schedule workflow execution at specific times or intervals. - `after` specifies a delay duration before restarting the workflow after completion. - `on` enables event-driven scheduling, triggering workflow execution based on specified events. See the [DSL reference](dsl-reference.md#schedule) for more details about workflow scheduling. ##### Event-driven scheduling ###### Input of event-driven scheduled workflows In event-driven scheduled workflows, the input is structured as an array containing the events that trigger the execution of the workflow. This array serves as a vital resource, providing workflow authors access to all relevant data associated with each triggering event. When an event activates the workflow, it populates this array with one or more occurrences, allowing authors to process multiple events simultaneously as needed. Authors can reference individual events within the array using syntax such as $workflow.input[index], where index indicates the event's position, starting from 0. For instance, $workflow.input[0] refers to the first event, while $workflow.input[1] refers to the second. This structure allows for easy access to specific event details, and if multiple events are received at once, authors can iterate through the array to handle each one appropriately. This flexibility ensures that workflows can respond effectively to various conditions and triggers, enhancing their overall responsiveness and functionality. ###### Distinguishing event-driven scheduling from start `listen` Tasks While both `schedule.on` and a start listener task enable event-driven execution of workflows, they serve distinct purposes and have different implications: - **`schedule.on`**: This property defines when a new workflow instance should be created based on an external event. When an event matches the criteria specified in `schedule.on`, a new workflow instance is initiated. The critical point here is that `schedule.on` solely manages the creation of new workflow instances. Any faults or timeouts related to the scheduling process are typically invisible to the user and do not impact the workflow instance. - **Start `listen` task**: A start listener task defines a task that must be undertaken after a new workflow instance has been created. This task listens for specific events and begins processing once the instance is active. The critical difference is that a start listener task operates within an already instantiated workflow. If a start listener task experiences a timeout or fault, it can cause the entire workflow instance to fail or behave unexpectedly, directly impacting the flow's execution and outcome. While `schedule.on` is concerned with *when* a new workflow instance should be initiated, a start listener task deals with *what* should happen once the instance is active. This distinction is crucial because it influences how errors and timeouts are handled—`schedule.on` faults are typically invisible and do not affect the workflow, whereas start listener task failures can directly and potentially severely impact the workflow instance they belong to. ### Task Flow A workflow begins with the first task defined. Once the task has been executed, different things can happen: - `continue`: the task ran to completion, and the next task, if any, should be executed. The task to run next is implicitly the next in declaration order, or explicitly defined by the `then` property of the executed task. If the executed task is the last task, then the workflow's execution gracefully ends. - `fault`: the task raised an uncaught error, which abruptly halts the workflow's execution and makes it transition to `faulted` [status phase](#status-phases). - `end`: the task explicitly and gracefully ends the workflow's execution. > [!WARNING] > Flow directives may only redirect to tasks declared within their own scope. In other words, they cannot target tasks at a different depth. ### Data Flow In Serverless Workflow DSL, data flow management is crucial to ensure that the right data is passed between tasks and to the workflow itself. Here's how data flows through a workflow based on various transformation stages: 1. **Validate Workflow Input** 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. 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). 2. **Transform Workflow Input** 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 `$input` runtime expression argument and be passed to the first task. *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.* After workflow input validation and transformation, the transformed input is passed as the raw input to the first task. 3. **Validate Task Input** Before a task executes, its raw input can be validated against the `input.schema` property to ensure it conforms to the expected structure. 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). 4. **Transform Task Input** 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. *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.* 5. **Transform Task Output** 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. *Example: If the task returns a large dataset, a transformation can be applied to retain only the relevant results needed for subsequent tasks.* 6. **Validate Task Output** 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). 7. **Update Workflow Context** 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. 8. **Validate Exported Context** 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). 9. **Continue Workflow** 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. If no more tasks are defined, the transformed output is passed to the workflow output transformation step. 10. **Transform Workflow Output** 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. *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.* 11. **Validate Workflow Output** 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). 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. Visually, this can be represented as follows: ```mermaid flowchart TD subgraph Legend legend_data{{Data}} legend_schema[\Schema/] legend_transformation[Transformation] legend_arg([Runtime Argument]) end initial_context_arg([
$context])
context_arg([$context])
input_arg([$input])
output_arg([$output])
workflow_raw_input{{Raw Workflow Input}}
workflow_input_schema[\Workflow: input.schema/]
workflow_input_from[Workflow: input.from]
workflow_transformed_input{{Transformed Workflow Input}}
task_raw_input{{Raw Task Input}}
task_if[Task: if]
task_input_schema[\Task: input.schema/]
task_input_from[Task: input.from]
task_transformed_input{{Transformed Task Input}}
task_definition[Task definition]
task_raw_output{{Raw Task output}}
task_output_as[Task: output.as]
task_transformed_output{{Transformed Task output}}
task_output_schema[\Task: output.schema/]
task_export_as[Task: export.as]
task_export_schema[\Task: export.schema/]
new_context{{New execution context}}
workflow_raw_output{{Raw Workflow Output}}
workflow_output_as[Workflow: output.as]
workflow_transformed_output{{Transformed Workflow Output}}
workflow_output_schema[\Workflow: output.schema/]
workflow_raw_input -- Validated by --> workflow_input_schema
workflow_input_schema -- Passed to --> workflow_input_from
workflow_input_from -- Produces --> workflow_transformed_input
workflow_transformed_input -- Set as --> initial_context_arg
workflow_transformed_input -- Passed to --> task_raw_input
subgraph Task
task_raw_input -- Passed to --> task_if
task_if -- Validated by --> task_input_schema
task_input_schema -- Passed to --> task_input_from
task_input_from -- Produces --> task_transformed_input
task_transformed_input -- Set as --> input_arg
task_transformed_input -- Passed to --> task_definition
task_definition -- Execution produces --> task_raw_output
task_raw_output -- Passed to --> task_output_as
task_output_as -- Produces --> task_transformed_output
task_transformed_output -- Set as --> output_arg
task_transformed_output -- Validated by --> task_output_schema
task_output_schema -- Passed to --> task_export_as
task_export_as -- Produces --> new_context
new_context -- Validated by --> task_export_schema
end
task_transformed_output -- Passed as raw input to --> next_task
subgraph next_task [Next Task]
end
new_context -- set as --> context_arg
next_task -- Transformed output becomes --> workflow_raw_output
workflow_raw_output -- Passed to --> workflow_output_as
workflow_output_as -- Produces --> workflow_transformed_output
workflow_transformed_output -- Validated by --> workflow_output_schema
```
### Runtime Expressions
Runtime expressions serve as dynamic elements that enable flexible and adaptable workflow behaviors. These expressions provide a means to evaluate conditions, transform data, and make decisions during the execution of workflows.
Runtime expressions allow for the incorporation of variables, functions, and operators to create logic that responds to changing conditions and input data. These expressions can range from simple comparisons, such as checking if a variable meets a certain condition, to complex computations and transformations involving multiple variables and data sources.
One key aspect of runtime expressions is their ability to adapt to runtime data and context. This means that expressions can access and manipulate data generated during the execution of a workflow, enabling dynamic decision-making and behavior based on real-time information.
Runtime expressions in Serverless Workflow can be evaluated using either the default `strict` mode or the `loose` mode. In `strict` mode, all expressions must be properly identified with `${}` syntax. Conversely, in `loose` mode, expressions are evaluated more liberally, allowing for a wider range of input formats. While `strict` mode ensures strict adherence to syntax rules, `loose` mode offers flexibility, allowing evaluation even if the syntax is not perfectly formed.
All runtimes **must** support the default runtime expression language, which is [`jq`](https://jqlang.github.io/jq/).
Runtimes **may** optionally support other runtime expression languages, which authors can specifically use by adequately configuring the workflow. See [`evaluate.language`](dsl-reference.md#evaluate) for more details.
CloudFlows defines [several arguments](#runtime-expression-arguments) that runtimes **must** provide during the evaluation of runtime expressions.
When the evaluation of an expression fails, runtimes **must** raise an error with type `https://serverlessworkflow.io/spec/1.0.0/errors/expression` and status `400`.
#### Runtime expression arguments
| Name | Type | Description |
|:-----|:----:|:------------|
| context | `map` | The workflow's context data. |
| input | `any` | The task's transformed input. |
| output | `any` | The task's transformed output. |
| secrets | `map` | A key/value map of the workflow secrets.