docs: use tooling convention across docs (#10512)
This commit is contained in:
1 parent
7c76ee24cb
commit
3409953c4f
76 files changed
+283
-265
No files matched your search
@@ -24,7 +24,7 @@ Your workflow isn't reusable by other applications. Use a step that performs wha
|
||||
|
||||
## How to Expose a Hook in a Workflow?
|
||||
|
||||
To expose a hook in your workflow, use the `createHook` function imported from `@medusajs/framework/workflows-sdk`.
|
||||
To expose a hook in your workflow, use `createHook` from the Workflows SDK.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn how to execute an action based on a condition in a workflow using the when-then utility.
|
||||
In this chapter, you'll learn how to execute an action based on a condition in a workflow using when-then from the Workflows SDK.
|
||||
|
||||
## Why If-Conditions Aren't Allowed in Workflows?
|
||||
|
||||
@@ -14,15 +14,13 @@ At that point, variables in the workflow don't have any values. They only do whe
|
||||
|
||||
So, you can't use an if-condition that checks a variable's value, as the condition will be evaluated when Medusa creates the internal representation of the workflow, rather than during execution.
|
||||
|
||||
Instead, use the when-then utility.
|
||||
Instead, use when-then from the Workflows SDK.
|
||||
|
||||
---
|
||||
|
||||
## What is the When-Then Utility?
|
||||
|
||||
The when-then utility functions execute an action if a condition is satisfied.
|
||||
|
||||
The `when` function accepts as a parameter a function that returns a boolean value, and the `then` function is chained to `when`. `then` accepts as a parameter a function that's executed if `when`'s parameter function returns a `true` value.
|
||||
when-then from the Workflows SDK executes an action if a condition is satisfied. The `when` function accepts as a parameter a function that returns a boolean value, and the `then` function is chained to `when`. `then` accepts as a parameter a function that's executed if `when`'s parameter function returns a `true` value.
|
||||
|
||||
For example:
|
||||
|
||||
@@ -70,7 +68,7 @@ In this code snippet, you execute the `isActiveStep` only if the `input.is_activ
|
||||
|
||||
### When Parameters
|
||||
|
||||
`when` utility is a function imported from `@medusajs/framework/workflows-sdk`. It accepts the following parameters:
|
||||
`when` accepts the following parameters:
|
||||
|
||||
1. The first parameter is either an object or the workflow's input. This data is passed as a parameter to the function in `when`'s second parameter.
|
||||
2. The second parameter is a function that returns a boolean indicating whether to execute the action in `then`.
|
||||
|
||||
@@ -38,7 +38,7 @@ Learn more about why you can't manipulate variables [in this chapter](../variabl
|
||||
|
||||
</Note>
|
||||
|
||||
Instead, use the `transform` utility function imported from `@medusajs/framework/workflows-sdk`:
|
||||
Instead, use `transform` from the Workflows SDK:
|
||||
|
||||
export const highlights = [
|
||||
["9", "", "Don't manipulate variables directly."],
|
||||
@@ -132,7 +132,7 @@ Learn more about why you can't use if-conditions [in this chapter](../conditions
|
||||
|
||||
</Note>
|
||||
|
||||
Instead, use the when-then utility function imported from `@medusajs/framework/workflows-sdk`:
|
||||
Instead, use when-then from the Workflows SDK:
|
||||
|
||||
```ts
|
||||
// Don't
|
||||
|
||||
@@ -49,11 +49,11 @@ The object has an `input` property to pass input to the workflow.
|
||||
|
||||
## Preparing Input Data
|
||||
|
||||
If you need to perform some data manipulation to prepare the other workflow's input data, use the `transform` utility function imported from `@medusajs/framework/workflows-sdk`.
|
||||
If you need to perform some data manipulation to prepare the other workflow's input data, use `transform` from the Workflows SDK.
|
||||
|
||||
<Note>
|
||||
|
||||
Learn about the transform utility in [this chapter](../variable-manipulation/page.mdx).
|
||||
Learn about transform in [this chapter](../variable-manipulation/page.mdx).
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -105,11 +105,11 @@ In this example, you use the `transform` function to prepend `Hello` to the titl
|
||||
|
||||
## Run Workflow Conditionally
|
||||
|
||||
To run a workflow in another based on a condition, use the when-then utility functions imported from `@medusajs/framework/workflows-sdk`.
|
||||
To run a workflow in another based on a condition, use when-then from the Workflows SDK.
|
||||
|
||||
<Note>
|
||||
|
||||
Learn about the when-then utility in [this chapter](../conditions/page.mdx).
|
||||
Learn about when-then in [this chapter](../conditions/page.mdx).
|
||||
|
||||
</Note>
|
||||
|
||||
@@ -152,4 +152,4 @@ const workflow = createWorkflow(
|
||||
)
|
||||
```
|
||||
|
||||
In this example, you use the `when` utility to run the `createProductsWorkflow` only if `should_create` (passed in the `input`) is enabled.
|
||||
In this example, you use when-then to run the `createProductsWorkflow` only if `should_create` (passed in the `input`) is enabled.
|
||||
@@ -30,7 +30,7 @@ You implement all custom flows within workflows, then execute them from [API rou
|
||||
|
||||
### 1. Create the Steps
|
||||
|
||||
A workflow is made of a series of steps. A step is created using the `createStep` utility function imported from `@medusajs/framework/workflows-sdk`.
|
||||
A workflow is made of a series of steps. A step is created using `createStep` from the Workflows SDK.
|
||||
|
||||
Create the file `src/workflows/hello-world.ts` with the following content:
|
||||
|
||||
@@ -245,7 +245,7 @@ export const highlights = [
|
||||
[
|
||||
"11",
|
||||
`"product"`,
|
||||
"The resource registration name imported from `@medusajs/framework/utils`.",
|
||||
"The resource registration name.",
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ In this chapter, you’ll learn how to run workflow steps in parallel.
|
||||
|
||||
## parallelize Utility Function
|
||||
|
||||
If your workflow has steps that don’t rely on one another’s results, run them in parallel using the `parallelize` utility function imported from the `@medusajs/framework/workflows-sdk`.
|
||||
If your workflow has steps that don’t rely on one another’s results, run them in parallel using `parallelize` from the Workflows SDK.
|
||||
|
||||
The workflow waits until all steps passed to the `parallelize` function finish executing before continuing to the next step.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
In this chapter, you'll learn how to use the `transform` utility to manipulate variables in a workflow.
|
||||
In this chapter, you'll learn how to use `transform` from the Workflows SDK to manipulate variables in a workflow.
|
||||
|
||||
## Why Variable Manipulation isn't Allowed in Workflows
|
||||
|
||||
@@ -14,13 +14,13 @@ At that point, variables in the workflow don't have any values. They only do whe
|
||||
|
||||
So, you can only pass variables as parameters to steps. But, in a workflow, you can't change a variable's value or, if the variable is an array, loop over its items.
|
||||
|
||||
Instead, use the transform utility.
|
||||
Instead, use `transform` from the Workflows SDK.
|
||||
|
||||
---
|
||||
|
||||
## What is the transform Utility?
|
||||
|
||||
The `transform` utility function creates a new variable as the result of manipulating other variables.
|
||||
`transform` creates a new variable as the result of manipulating other variables.
|
||||
|
||||
For example, consider you have two strings as the output of two steps:
|
||||
|
||||
@@ -62,7 +62,7 @@ const myWorkflow = createWorkflow(
|
||||
)
|
||||
```
|
||||
|
||||
The `transform` utility function is imported from `@medusajs/framework/workflows-sdk`. It accepts two parameters:
|
||||
`transform` accepts two parameters:
|
||||
|
||||
1. The first parameter is an object of variables to manipulate. The object is passed as a parameter to `transform`'s second parameter function.
|
||||
2. The second parameter is the function performing the variable manipulation.
|
||||
@@ -111,7 +111,7 @@ const myWorkflow = createWorkflow(
|
||||
|
||||
This workflow receives an `items` array in its input.
|
||||
|
||||
You use the `transform` utility to create an `ids` variable, which is an array of strings holding the `id` of each item in the `items` array.
|
||||
You use `transform` to create an `ids` variable, which is an array of strings holding the `id` of each item in the `items` array.
|
||||
|
||||
You then pass the `ids` variable as a parameter to the `doSomethingStep`.
|
||||
|
||||
@@ -144,7 +144,7 @@ In this workflow, `today` is only evaluated when the workflow is executed.
|
||||
|
||||
### Transform Evaluation
|
||||
|
||||
The transform utility's value is only evaluated if you pass its output to a step or in the workflow response.
|
||||
`transform`'s value is only evaluated if you pass its output to a step or in the workflow response.
|
||||
|
||||
For example, if you have the following workflow:
|
||||
|
||||
@@ -166,9 +166,9 @@ Since `str`'s value isn't used as a step's input or passed to `WorkflowResponse`
|
||||
|
||||
### Data Validation
|
||||
|
||||
The `transform` utility should only be used to perform variable or data manipulation.
|
||||
`transform` should only be used to perform variable or data manipulation.
|
||||
|
||||
If you want to perform some validation on the data, use a step or the [when-then utility](../conditions/page.mdx) instead.
|
||||
If you want to perform some validation on the data, use a step or [when-then](../conditions/page.mdx) instead.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
Reference in new issue
Block a user