chore: reorganize docs apps (#7228)

* reorganize docs apps

* add README

* fix directory

* add condition for old docs
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-05-03 17:36:38 +03:00
1 parent 224ebb2154
commit 4fe28f5a95
6187 files changed
+601447 -598226

No files matched your search

@@ -0,0 +1,66 @@
---
slug: /references/workflows/createStep
sidebar_label: createStep
---
import { TypeList } from "docs-ui"
# createStep - Workflows API Reference
This documentation provides a reference to the `createStep` . It belongs to the `@medusajs/workflows-sdk` package.
This function creates a [StepFunction](../../types/workflows.StepFunction/page.mdx) that can be used as a step in a workflow constructed by the [createWorkflow](../workflows.createWorkflow/page.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
<TypeList types={[{"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":[]}]} sectionTitle="createStep"/>
## Parameters
<TypeList types={[{"name":"nameOrConfig","type":"`string` \\| `object` & Omit&#60;TransactionStepsDefinition, \"next\" \\| \"uuid\" \\| \"action\"&#62;","description":"The name of the step or its configuration.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"invokeFn","type":"InvokeFn&#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/workflows.StepResponse/page.mdx). The constructor of [StepResponse](../../classes/workflows.StepResponse/page.mdx)\naccepts 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&#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.\nIt accepts as a parameter the second argument passed to the constructor of the [StepResponse](../../classes/workflows.StepResponse/page.mdx) instance returned by the invocation function. If the\ninvocation function doesn't pass the second argument to `StepResponse` constructor, the compensation function receives the first argument\npassed to the `StepResponse` constructor instead.","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createStep"/>
## Returns
<TypeList types={[{"name":"StepFunction","type":"[StepFunction](../../types/workflows.StepFunction/page.mdx)&#60;TInvokeInput, TInvokeResultOutput&#62;","optional":false,"defaultValue":"","description":"A step function to be used in a workflow.","expandable":false,"children":[]}]} sectionTitle="createStep"/>
@@ -0,0 +1,72 @@
---
slug: /references/workflows/createWorkflow
sidebar_label: createWorkflow
---
import { TypeList } from "docs-ui"
# createWorkflow - Workflows API 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](../workflows.createStep/page.mdx) function.
The returned workflow is an exported workflow of type [ReturnWorkflow](../../types/workflows.ReturnWorkflow/page.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
<TypeList types={[{"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":[]}]} sectionTitle="createWorkflow"/>
## Parameters
<TypeList types={[{"name":"nameOrConfig","type":"`string` \\| `object` & `TransactionModelOptions`","description":"The name of the workflow or its configuration.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"composer","type":"(`input`: [WorkflowData](../../types/workflows.WorkflowData/page.mdx)&#60;TData&#62;) => `void` \\| [WorkflowData](../../types/workflows.WorkflowData/page.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/workflows.ReturnWorkflow/page.mdx) is used.\nThe function can't be an arrow function or an asynchronus function. It also can't directly manipulate data.\nYou'll have to use the [transform](../workflows.transform/page.mdx) function if you need to directly manipulate data.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createWorkflow"/>
## Returns
<TypeList types={[{"name":"ReturnWorkflow","type":"[ReturnWorkflow](../../types/workflows.ReturnWorkflow/page.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":[]}]} sectionTitle="createWorkflow"/>
@@ -0,0 +1,59 @@
---
slug: /references/workflows/parallelize
sidebar_label: parallelize
---
import { TypeList } from "docs-ui"
# parallelize - Workflows API 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
<TypeList types={[{"name":"TResult","type":"[WorkflowData](../../types/workflows.WorkflowData/page.mdx)[]","description":"The type of the expected result.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="parallelize"/>
## Parameters
<TypeList types={[{"name":"steps","type":"TResult","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="parallelize"/>
## Returns
<TypeList types={[{"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":[]}]} sectionTitle="parallelize"/>
@@ -0,0 +1,65 @@
---
slug: /references/workflows/transform
sidebar_label: transform
---
import { TypeList } from "docs-ui"
# transform - Workflows API 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](../workflows.createWorkflow/page.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
<TypeList types={[{"name":"T","type":"`object` \\| [WorkflowData](../../types/workflows.WorkflowData/page.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"RFinal","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="transform"/>
## Parameters
<TypeList types={[{"name":"values","type":"T","description":"The output(s) of other step functions.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"func","type":"[Func1&#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":[]}]} sectionTitle="transform"/>
## Returns
<TypeList types={[{"name":"WorkflowData","type":"[WorkflowData](../../types/workflows.WorkflowData/page.mdx)&#60;RFinal&#62;","optional":false,"defaultValue":"","description":"There's no expected value to be returned by the `transform` function.","expandable":false,"children":[]}]} sectionTitle="transform"/>