docs: added documentation pages for experimental features (#5671)

* docs: added documentation pages for experimental features

* fix content lint issues

* fixed lint errors

* added migration step

* added workflows introduction

* add installation guides

* added installation guides for modules + generated workflows reference

* added missing workflows reference link

* Added warning message for experimental features

* fix note
This commit is contained in:
Shahed Nasser
2023-11-27 16:49:12 +00:00
committed by GitHub
parent cf0939aab2
commit cdc1da5df7
148 changed files with 14225 additions and 435 deletions

View File

@@ -0,0 +1,133 @@
---
displayed_sidebar: workflowsSidebar
slug: /references/workflows/createStep
sidebar_label: createStep
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# createStep - Workflows Reference
This documentation provides a reference to the `createStep` . It belongs to the `@medusajs/workflows-sdk` package.
This function creates a [StepFunction](../types/StepFunction.mdx) that can be used as a step in a workflow constructed by the [createWorkflow](createWorkflow.mdx) function.
## Example
```ts
import {
createStep,
StepResponse,
StepExecutionContext,
WorkflowData
} from "@medusajs/workflows-sdk"
interface CreateProductInput {
title: string
}
export const createProductStep = createStep(
"createProductStep",
async function (
input: CreateProductInput,
context
) {
const productService = context.container.resolve(
"productService"
)
const product = await productService.create(input)
return new StepResponse({
product
}, {
product_id: product.id
})
},
async function (
input,
context
) {
const productService = context.container.resolve(
"productService"
)
await productService.delete(input.product_id)
}
)
```
## Type Parameters
<ParameterTypes parameters={[
{
"name": "TInvokeInput",
"type": "`object`",
"description": "The type of the expected input parameter to the invocation function.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "TInvokeResultOutput",
"type": "`object`",
"description": "The type of the expected output parameter of the invocation function.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "TInvokeResultCompensateInput",
"type": "`object`",
"description": "The type of the expected input parameter to the compensation function.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Parameters
<ParameterTypes parameters={[
{
"name": "name",
"type": "`string`",
"description": "The name of the step.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "invokeFn",
"type": "[InvokeFn](../types/InvokeFn.mdx)&#60;TInvokeInput, TInvokeResultOutput, TInvokeResultCompensateInput&#62;",
"description": "An invocation function that will be executed when the workflow is executed. The function must return an instance of [StepResponse](../classes/StepResponse.mdx). The constructor of [StepResponse](../classes/StepResponse.mdx) accepts the output of the step as a first argument, and optionally as a second argument the data to be passed to the compensation function as a parameter.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "compensateFn",
"type": "[CompensateFn](../types/CompensateFn.mdx)&#60;TInvokeResultCompensateInput&#62;",
"description": "A compensation function that's executed if an error occurs in the workflow. It's used to roll-back actions when errors occur. It accepts as a parameter the second argument passed to the constructor of the [StepResponse](../classes/StepResponse.mdx) instance returned by the invocation function. If the invocation function doesn't pass the second argument to `StepResponse` constructor, the compensation function receives the first argument passed to the `StepResponse` constructor instead.",
"optional": true,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Returns
<ParameterTypes parameters={[
{
"name": "StepFunction",
"type": "[StepFunction](../types/StepFunction.mdx)&#60;TInvokeInput, TInvokeResultOutput&#62;",
"optional": false,
"defaultValue": "",
"description": "A step function to be used in a workflow.",
"expandable": false,
"children": []
}
]} />

View File

@@ -0,0 +1,130 @@
---
displayed_sidebar: workflowsSidebar
slug: /references/workflows/createWorkflow
sidebar_label: createWorkflow
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# createWorkflow - Workflows Reference
This documentation provides a reference to the `createWorkflow` . It belongs to the `@medusajs/workflows-sdk` package.
This function creates a workflow with the provided name and a constructor function.
The constructor function builds the workflow from steps created by the [createStep](createStep.mdx) function.
The returned workflow is an exported workflow of type [ReturnWorkflow](../types/ReturnWorkflow.mdx), meaning it's not executed right away. To execute it,
invoke the exported workflow, then run its `run` method.
## Example
```ts
import { createWorkflow } from "@medusajs/workflows-sdk"
import { MedusaRequest, MedusaResponse, Product } from "@medusajs/medusa"
import {
createProductStep,
getProductStep,
createPricesStep
} from "./steps"
interface WorkflowInput {
title: string
}
const myWorkflow = createWorkflow<
WorkflowInput,
Product
>("my-workflow", (input) => {
// Everything here will be executed and resolved later
// during the execution. Including the data access.
const product = createProductStep(input)
const prices = createPricesStep(product)
return getProductStep(product.id)
}
)
export async function GET(
req: MedusaRequest,
res: MedusaResponse
) {
const { result: product } = await myWorkflow(req.scope)
.run({
input: {
title: "Shirt"
}
})
res.json({
product
})
}
```
## Type Parameters
<ParameterTypes parameters={[
{
"name": "TData",
"type": "`object`",
"description": "The type of the input passed to the composer function.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "TResult",
"type": "`object`",
"description": "The type of the output returned by the composer function.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "THooks",
"type": "`Record<string, Function>`",
"description": "The type of hooks defined in the workflow.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Parameters
<ParameterTypes parameters={[
{
"name": "name",
"type": "`string`",
"description": "The name of the workflow.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "composer",
"type": "(`input`: [WorkflowData](../types/WorkflowData.mdx)&#60;TData&#62;) => `void` \\| [WorkflowData](../types/WorkflowData.mdx)&#60;TResult&#62; \\| &#123; [K in string \\| number \\| symbol]: WorkflowDataProperties&#60;TResult[K]&#62; \\| WorkflowData&#60;TResult[K]&#62; &#125;",
"description": "The constructor function that is executed when the `run` method in [ReturnWorkflow](../types/ReturnWorkflow.mdx) is used. The function can't be an arrow function or an asynchronus function. It also can't directly manipulate data. You'll have to use the [transform](transform.mdx) function if you need to directly manipulate data.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Returns
<ParameterTypes parameters={[
{
"name": "ReturnWorkflow",
"type": "[ReturnWorkflow](../types/ReturnWorkflow.mdx)&#60;TData, TResult, THooks&#62;",
"optional": false,
"defaultValue": "",
"description": "The created workflow. You can later execute the workflow by invoking it, then using its `run` method.",
"expandable": false,
"children": []
}
]} />

View File

@@ -0,0 +1,89 @@
---
displayed_sidebar: workflowsSidebar
slug: /references/workflows/parallelize
sidebar_label: parallelize
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# parallelize - Workflows Reference
This documentation provides a reference to the `parallelize` . It belongs to the `@medusajs/workflows-sdk` package.
This function is used to run multiple steps in parallel. The result of each step will be returned as part of the result array.
## Example
```ts
import {
createWorkflow,
parallelize
} from "@medusajs/workflows-sdk"
import {
createProductStep,
getProductStep,
createPricesStep,
attachProductToSalesChannelStep
} from "./steps"
interface WorkflowInput {
title: string
}
const myWorkflow = createWorkflow<
WorkflowInput,
Product
>("my-workflow", (input) => {
const product = createProductStep(input)
const [prices, productSalesChannel] = parallelize(
createPricesStep(product),
attachProductToSalesChannelStep(product)
)
const id = product.id
return getProductStep(product.id)
}
)
## Type Parameters
<ParameterTypes parameters={[
{
"name": "TResult",
"type": "[WorkflowDataProperties](../types/WorkflowDataProperties.mdx)&#60;unknown&#62;[]",
"description": "The type of the expected result.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Parameters
<ParameterTypes parameters={[
{
"name": "steps",
"type": "`TResult`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Returns
<ParameterTypes parameters={[
{
"name": "TResult",
"type": "`TResult`",
"optional": false,
"defaultValue": "",
"description": "The step results. The results are ordered in the array by the order they're passed in the function's parameter.",
"expandable": false,
"children": []
}
]} />

View File

@@ -0,0 +1,114 @@
---
displayed_sidebar: workflowsSidebar
slug: /references/workflows/transform
sidebar_label: transform
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# transform - Workflows Reference
This documentation provides a reference to the `transform` . It belongs to the `@medusajs/workflows-sdk` package.
This function transforms the output of other utility functions.
For example, if you're using the value(s) of some step(s) as an input to a later step. As you can't directly manipulate data in the workflow constructor function passed to [createWorkflow](createWorkflow.mdx),
the `transform` function provides access to the runtime value of the step(s) output so that you can manipulate them.
Another example is if you're using the runtime value of some step(s) as the output of a workflow.
If you're also retrieving the output of a hook and want to check if its value is set, you must use a workflow to get the runtime value of that hook.
## Example
```ts
import {
createWorkflow,
transform
} from "@medusajs/workflows-sdk"
import { step1, step2 } from "./steps"
type WorkflowInput = {
name: string
}
type WorkflowOutput = {
message: string
}
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>
("hello-world", (input) => {
const str1 = step1(input)
const str2 = step2(input)
return transform({
str1,
str2
}, (input) => ({
message: `${input.str1}${input.str2}`
}))
})
```
## Type Parameters
<ParameterTypes parameters={[
{
"name": "T",
"type": "`object` \\| [WorkflowDataProperties](../types/WorkflowDataProperties.mdx)&#60;unknown&#62;",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "RFinal",
"type": "`object`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Parameters
<ParameterTypes parameters={[
{
"name": "values",
"type": "`T`",
"description": "The output(s) of other step functions.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "func",
"type": "[[Func1](../types/Func1.mdx)&#60;T, RFinal&#62;]",
"description": "The transform function used to perform action on the runtime values of the provided `values`.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Returns
<ParameterTypes parameters={[
{
"name": "WorkflowData",
"type": "[WorkflowData](../types/WorkflowData.mdx)&#60;RFinal&#62;",
"optional": false,
"defaultValue": "",
"description": "There's no expected value to be returned by the `transform` function.",
"expandable": false,
"children": []
}
]} />