chore: move ModuleRegistrationName to utils (#7911)

This commit is contained in:
Carlos R. L. Rodrigues
2024-07-03 06:30:56 -03:00
committed by GitHub
parent 46f15b4909
commit a7844efd09
339 changed files with 7203 additions and 7620 deletions
+24 -28
View File
@@ -25,10 +25,7 @@ A workflow is made of a series of steps. A step is created using the `createStep
Create the file `src/workflows/hello-world.ts` with the following content:
```ts title="src/workflows/hello-world.ts"
import {
createStep,
StepResponse,
} from "@medusajs/workflows-sdk"
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
const step1 = createStep("step-1", async () => {
return new StepResponse(`Hello from step one!`)
@@ -44,12 +41,9 @@ type WorkflowInput = {
name: string
}
const step2 = createStep(
"step-2",
async ({ name }: WorkflowInput) => {
return new StepResponse(`Hello ${name} from step two!`)
}
)
const step2 = createStep("step-2", async ({ name }: WorkflowInput) => {
return new StepResponse(`Hello ${name} from step two!`)
})
```
### 2. Create a Workflow
@@ -68,21 +62,20 @@ type WorkflowOutput = {
message: string
}
const myWorkflow = createWorkflow<
WorkflowInput,
WorkflowOutput
>("hello-world", function (input) {
const str1 = step1()
// to pass input
const str2 = step2(input)
const myWorkflow = createWorkflow<WorkflowInput, WorkflowOutput>(
"hello-world",
function (input) {
const str1 = step1()
// to pass input
const str2 = step2(input)
return {
message: str1,
return {
message: str1,
}
}
})
)
export default myWorkflow
```
This creates a `hello-world` workflow. When you create a workflow, its constructed but not executed yet.
@@ -226,7 +219,11 @@ For example:
export const highlights = [
["15", "resolve", "Resolve the Product Module's main service."],
["15", "ModuleRegistrationName.PRODUCT", "The resource registration name imported from `@medusajs/modules-sdk`."]
[
"15",
"ModuleRegistrationName.PRODUCT",
"The resource registration name imported from `@medusajs/modules-sdk`.",
],
]
```ts title="src/workflows/product-count.ts" highlights={highlights} collapsibleLines="1-12" expandButtonLabel="Show Imports"
@@ -236,18 +233,17 @@ import {
createWorkflow,
} from "@medusajs/workflows-sdk"
import { IProductModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ModuleRegistrationName } from "@medusajs/utils"
type WorkflowOutput = {
count: number
}
const step1 = createStep("step-1", async (_, context) => {
const productModuleService: IProductModuleService =
context.container.resolve(ModuleRegistrationName.PRODUCT)
return new StepResponse(
(await productModuleService.listAndCount())[1]
const productModuleService: IProductModuleService = context.container.resolve(
ModuleRegistrationName.PRODUCT
)
return new StepResponse((await productModuleService.listAndCount())[1])
})
const myWorkflow = createWorkflow<unknown, WorkflowOutput>(
@@ -264,4 +260,4 @@ const myWorkflow = createWorkflow<unknown, WorkflowOutput>(
export default myWorkflow
```
In the step, you resolve the Product Module's main service and use it to retrieve the product count.
In the step, you resolve the Product Module's main service and use it to retrieve the product count.