docs: remove type arguments passed to createWorkflow (#8161)

This commit is contained in:
Shahed Nasser
2024-07-17 13:19:51 +01:00
committed by GitHub
parent e5c66fa670
commit b1964a0384
11 changed files with 62 additions and 132 deletions
@@ -205,23 +205,17 @@ With the steps ready, you'll create the workflow that runs these steps to update
Change the content of `src/workflows/update-product-erp/index.ts` to the following:
```ts title="src/workflows/update-product-erp/index.ts" collapsibleLines="1-6" expandButtonLabel="Show Imports"
```ts title="src/workflows/update-product-erp/index.ts" collapsibleLines="1-5" expandButtonLabel="Show Imports"
import { createWorkflow } from "@medusajs/workflows-sdk"
import { UpsertProductDTO, ProductDTO } from "@medusajs/types"
import { UpsertProductDTO } from "@medusajs/types"
import updateProduct from "./steps/update-product"
import updateErp from "./steps/update-erp"
export type UpdateProductAndErpWorkflowInput = UpsertProductDTO
type WorkflowOutput = {
product: ProductDTO
erpData: Record<string, unknown>
}
const updateProductAndErpWorkflow = createWorkflow<
UpdateProductAndErpWorkflowInput,
WorkflowOutput
>("update-product-and-erp", function (input) {
const updateProductAndErpWorkflow = createWorkflow(
"update-product-and-erp",
function (input: UpdateProductAndErpWorkflowInput) {
const product = updateProduct(input)
const erpData = updateErp(input)
@@ -62,14 +62,9 @@ import {
// ...
type WorkflowOutput = {
message: string
}
const myWorkflow = createWorkflow<
{},
WorkflowOutput
>("hello-world", function (input) {
const myWorkflow = createWorkflow(
"hello-world",
function (input) {
const str1 = step1()
step2()
@@ -35,9 +35,9 @@ type WorkflowInput = {
is_active: boolean
}
const workflow = createWorkflow
<WorkflowInput, any>
("workflow", function (input) {
const workflow = createWorkflow(
"workflow",
function (input: WorkflowInput) {
const result = when(
input,
(input) => {
@@ -12,20 +12,18 @@ This chapter lists some constraints to keep in mind when defining a workflow or
The function passed to the `createWorkflow` cant be an async function:
```ts highlights={[["5", "async", "Function can't be async."], ["13", "", "Correct way of defining the function."]]}
```ts highlights={[["4", "async", "Function can't be async."], ["11", "", "Correct way of defining the function."]]}
// Don't
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>("hello-world", async function (input) {
const myWorkflow = createWorkflow(
"hello-world",
async function (input: WorkflowInput) {
// ...
})
// Do
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>("hello-world", function (input) {
const myWorkflow = createWorkflow(
"hello-world",
function (input: WorkflowInput) {
// ...
})
```
@@ -35,16 +33,15 @@ const myWorkflow = createWorkflow<
Since the constructor function only defines how the workflow works, you cant directly manipulate data within the function. Instead, use the `transform` function:
export const highlights = [
["10", "", "Don't manipulate data directly."],
["22", "transform", "Use the `transform` function to manipulate data."]
["9", "", "Don't manipulate data directly."],
["20", "transform", "Use the `transform` function to manipulate data."]
]
```ts highlights={highlights}
// Don't
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>("hello-world", function (input) {
const myWorkflow = createWorkflow(
"hello-world",
function (input: WorkflowInput) {
const str1 = step1(input)
const str2 = step2(input)
@@ -54,10 +51,9 @@ const myWorkflow = createWorkflow<
})
// Do
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>("hello-world", function (input) {
const myWorkflow = createWorkflow(
"hello-world",
function (input: WorkflowInput) {
const str1 = step1(input)
const str2 = step2(input)
@@ -81,20 +77,18 @@ You can't use if-conditions in a workflow. Instead, use the when-then utility fu
```ts
// Don't
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>("hello-world", function (input) {
const myWorkflow = createWorkflow(
"hello-world",
function (input: WorkflowInput) {
if (input.is_active) {
// perform an action
}
})
// Do (explained in the next chapter)
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>("hello-world", function (input) {
const myWorkflow = createWorkflow(
"hello-world",
function (input: WorkflowInput) {
when(input, (input) => {
return input.is_active
})
@@ -47,14 +47,9 @@ const step3 = createStep("step-3", async () => {
return new StepResponse("Finished three steps")
})
type WorkflowOutput = {
message: string
}
const myWorkflow = createWorkflow<
{},
WorkflowOutput
>("hello-world", function () {
const myWorkflow = createWorkflow(
"hello-world",
function () {
step1()
step2()
const message = step3()
@@ -15,8 +15,8 @@ The workflow waits until all steps passed to the `parallelize` function finish e
For example:
export const highlights = [
["23", "[prices, productSalesChannel]", "The result of the steps. `prices` is the result of `createPricesStep`, and `productSalesChannel` is the result of `attachProductToSalesChannelStep`."],
["23", "parallelize", "Run the steps passed as parameters in parallel."],
["21", "[prices, productSalesChannel]", "The result of the steps. `prices` is the result of `createPricesStep`, and `productSalesChannel` is the result of `attachProductToSalesChannelStep`."],
["21", "parallelize", "Run the steps passed as parameters in parallel."],
]
```ts highlights={highlights} collapsibleLines="1-12" expandButtonLabel="Show Imports"
@@ -24,7 +24,6 @@ import {
createWorkflow,
parallelize,
} from "@medusajs/workflows-sdk"
import { ProductDTO } from "@medusajs/types"
import {
createProductStep,
getProductStep,
@@ -36,10 +35,9 @@ interface WorkflowInput {
title: string
}
const myWorkflow = createWorkflow<
WorkflowInput,
ProductDTO
>("my-workflow", (input) => {
const myWorkflow = createWorkflow(
"my-workflow",
(input: WorkflowInput) => {
const product = createProductStep(input)
const [prices, productSalesChannel] = parallelize(
@@ -32,14 +32,9 @@ const step1 = createStep(
}
)
type WorkflowOutput = {
message: string
}
const myWorkflow = createWorkflow<
{},
WorkflowOutput
>("hello-world", function () {
const myWorkflow = createWorkflow(
"hello-world",
function () {
const str1 = step1()
return {
@@ -20,7 +20,7 @@ Timeout doesn't stop the execution of a running step. The timeout only affects t
For example:
```ts title="src/workflows/hello-world.ts" highlights={[["22"]]} collapsibleLines="1-16" expandButtonLabel="Show More"
```ts title="src/workflows/hello-world.ts" highlights={[["15"]]} collapsibleLines="1-12" expandButtonLabel="Show More"
import {
createStep,
createWorkflow,
@@ -33,14 +33,7 @@ const step1 = createStep(
}
)
type WorkflowOutput = {
message: string
}
const myWorkflow = createWorkflow<
{},
WorkflowOutput
>({
const myWorkflow = createWorkflow({
name: "hello-world",
timeout: 2, // 2 seconds
}, function () {