From b1964a038468e348d0aac74c9bc4bab52696f01b Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 17 Jul 2024 15:19:51 +0300 Subject: [PATCH] docs: remove type arguments passed to createWorkflow (#8161) --- .../workflows/advanced-example/page.mdx | 16 ++----- .../workflows/compensation-function/page.mdx | 11 ++--- .../workflows/conditions/page.mdx | 6 +-- .../constructor-constraints/page.mdx | 48 ++++++++----------- .../workflows/long-running-workflow/page.mdx | 11 ++--- .../workflows/parallel-steps/page.mdx | 12 ++--- .../workflows/retry-failed-steps/page.mdx | 11 ++--- .../workflows/workflow-timeout/page.mdx | 11 +---- www/apps/book/app/basics/workflows/page.mdx | 18 ++----- .../auth/create-actor-type/page.mdx | 21 +++----- .../marketplace/examples/vendors/page.mdx | 29 +++-------- 11 files changed, 62 insertions(+), 132 deletions(-) diff --git a/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx b/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx index 070d67f8b3..25445ac0c1 100644 --- a/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/advanced-example/page.mdx @@ -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 -} - -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) diff --git a/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx b/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx index 4e80bc3cf1..52f9bb368f 100644 --- a/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/compensation-function/page.mdx @@ -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() diff --git a/www/apps/book/app/advanced-development/workflows/conditions/page.mdx b/www/apps/book/app/advanced-development/workflows/conditions/page.mdx index 81a60ee519..98ceb43197 100644 --- a/www/apps/book/app/advanced-development/workflows/conditions/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/conditions/page.mdx @@ -35,9 +35,9 @@ type WorkflowInput = { is_active: boolean } -const workflow = createWorkflow - - ("workflow", function (input) { +const workflow = createWorkflow( + "workflow", + function (input: WorkflowInput) { const result = when( input, (input) => { diff --git a/www/apps/book/app/advanced-development/workflows/constructor-constraints/page.mdx b/www/apps/book/app/advanced-development/workflows/constructor-constraints/page.mdx index b8088f728d..0592611de5 100644 --- a/www/apps/book/app/advanced-development/workflows/constructor-constraints/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/constructor-constraints/page.mdx @@ -12,20 +12,18 @@ This chapter lists some constraints to keep in mind when defining a workflow or The function passed to the `createWorkflow` can’t 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 can’t 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 }) diff --git a/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx b/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx index f548a37076..2b1301ea2a 100644 --- a/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/long-running-workflow/page.mdx @@ -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() diff --git a/www/apps/book/app/advanced-development/workflows/parallel-steps/page.mdx b/www/apps/book/app/advanced-development/workflows/parallel-steps/page.mdx index d774d442f9..cd9ed6d167 100644 --- a/www/apps/book/app/advanced-development/workflows/parallel-steps/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/parallel-steps/page.mdx @@ -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( diff --git a/www/apps/book/app/advanced-development/workflows/retry-failed-steps/page.mdx b/www/apps/book/app/advanced-development/workflows/retry-failed-steps/page.mdx index 00f9c9f059..c232d5740a 100644 --- a/www/apps/book/app/advanced-development/workflows/retry-failed-steps/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/retry-failed-steps/page.mdx @@ -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 { diff --git a/www/apps/book/app/advanced-development/workflows/workflow-timeout/page.mdx b/www/apps/book/app/advanced-development/workflows/workflow-timeout/page.mdx index b82c148b26..a586ea8895 100644 --- a/www/apps/book/app/advanced-development/workflows/workflow-timeout/page.mdx +++ b/www/apps/book/app/advanced-development/workflows/workflow-timeout/page.mdx @@ -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 () { diff --git a/www/apps/book/app/basics/workflows/page.mdx b/www/apps/book/app/basics/workflows/page.mdx index 5315f2b0c6..b90e5962b1 100644 --- a/www/apps/book/app/basics/workflows/page.mdx +++ b/www/apps/book/app/basics/workflows/page.mdx @@ -60,13 +60,9 @@ import { // ... -type WorkflowOutput = { - message: string -} - -const myWorkflow = createWorkflow( +const myWorkflow = createWorkflow( "hello-world", - function (input) { + function (input: WorkflowInput) { const str1 = step1() // to pass input const str2 = step2(input) @@ -227,9 +223,9 @@ Each step in the workflow receives as a second parameter a `context` object. The For example: export const highlights = [ - ["15", "resolve", "Resolve the Product Module's main service."], + ["11", "resolve", "Resolve the Product Module's main service."], [ - "15", + "11", "ModuleRegistrationName.PRODUCT", "The resource registration name imported from `@medusajs/modules-sdk`.", ], @@ -244,10 +240,6 @@ import { import { IProductModuleService } from "@medusajs/types" import { ModuleRegistrationName } from "@medusajs/utils" -type WorkflowOutput = { - count: number -} - const step1 = createStep("step-1", async (_, context) => { const productModuleService: IProductModuleService = context.container.resolve(ModuleRegistrationName.PRODUCT) @@ -257,7 +249,7 @@ const step1 = createStep("step-1", async (_, context) => { return new StepResponse(count) }) -const myWorkflow = createWorkflow( +const myWorkflow = createWorkflow( "product-count", function () { const count = step1() diff --git a/www/apps/resources/app/commerce-modules/auth/create-actor-type/page.mdx b/www/apps/resources/app/commerce-modules/auth/create-actor-type/page.mdx index a2499993fc..7080cca3e2 100644 --- a/www/apps/resources/app/commerce-modules/auth/create-actor-type/page.mdx +++ b/www/apps/resources/app/commerce-modules/auth/create-actor-type/page.mdx @@ -37,10 +37,10 @@ Start by creating a workflow that does two things: For example, create the file `src/workflows/create-manager.ts`. with the following content: export const workflowHighlights = [ - ["27", "createManagerStep", "Thi step creates a manager."], - ["44", "createManagerWorkflow", "The workflow used to create a manager and set its auth identity's actor type."], - ["53", "setAuthAppMetadataStep", "Set the actor type of the manager's associated auth identity."], - ["55", '"manager"', "The actor type of the manager."] + ["20", "createManagerStep", "Thi step creates a manager."], + ["37", "createManagerWorkflow", "The workflow used to create a manager and set its auth identity's actor type."], + ["44", "setAuthAppMetadataStep", "Set the actor type of the manager's associated auth identity."], + ["46", '"manager"', "The actor type of the manager."] ] ```ts title="src/workflows/create-manager.ts" highlights={workflowHighlights} @@ -63,13 +63,6 @@ type CreateManagerWorkflowInput = { authIdentityId: string } -type CreateManagerWorkflowOutput = { - id: string - first_name: string - last_name: string - email: string -} - const createManagerStep = createStep( "create-manager-step", async ({ @@ -87,11 +80,9 @@ const createManagerStep = createStep( } ) -const createManagerWorkflow = createWorkflow< - CreateManagerWorkflowInput, CreateManagerWorkflowOutput ->( +const createManagerWorkflow = createWorkflow( "create-manager", - function (input) { + function (input: CreateManagerWorkflowInput) { const manager = createManagerStep({ manager: input.manager, }) diff --git a/www/apps/resources/app/recipes/marketplace/examples/vendors/page.mdx b/www/apps/resources/app/recipes/marketplace/examples/vendors/page.mdx index 1151895c99..c35959d646 100644 --- a/www/apps/resources/app/recipes/marketplace/examples/vendors/page.mdx +++ b/www/apps/resources/app/recipes/marketplace/examples/vendors/page.mdx @@ -274,7 +274,7 @@ This is the first step that creates the vendor admin and returns it. Then, create the workflow at `src/workflows/marketplace/create-vendor-admin/index.ts` with the following content: export const vendorAdminWorkflowHighlights = [ - ["33", "setAuthAppMetadataStep", "Step is imported from `@medusajs/core-flows`."] + ["24", "setAuthAppMetadataStep", "Step is imported from `@medusajs/core-flows`."] ] ```ts title="src/workflows/marketplace/create-vendor-admin/index.ts" highlights={vendorAdminWorkflowHighlights} @@ -294,18 +294,9 @@ export type CreateVendorAdminWorkflowInput = { authIdentityId: string } -type CreateVendorAdminWorkflowOutput = { - id: string - first_name: string - last_name: string - email: string -} - -const createVendorAdminWorkflow = createWorkflow< - CreateVendorAdminWorkflowInput, CreateVendorAdminWorkflowOutput ->( +const createVendorAdminWorkflow = createWorkflow( "create-vendor-admin", - function (input) { + function (input: CreateVendorAdminWorkflowInput) { const vendorAdmin = createVendorAdminStep({ admin: input.admin, }) @@ -1100,26 +1091,18 @@ Finally, create the workflow at the file `src/workflows/marketplace/create-vendo ```ts title="src/workflows/marketplace/create-vendor-orders/index.ts" collapsibleLines="1-7" expandMoreLabel="Show Imports" import { createWorkflow, transform } from "@medusajs/workflows-sdk" -import { OrderDTO } from "@medusajs/types" import retrieveCartStep from "./steps/retrieve-cart" import groupVendorItemsStep from "./steps/group-vendor-items" import createParentOrderStep from "./steps/create-parent-order" -import createVendorOrdersStep, { VendorOrder } from "./steps/create-vendor-orders" +import createVendorOrdersStep from "./steps/create-vendor-orders" type WorkflowInput = { cart_id: string } -type WorkflowOutput = { - parent_order: OrderDTO - vendor_orders: VendorOrder[] -} - -const createVendorOrdersWorkflow = createWorkflow< - WorkflowInput, WorkflowOutput ->( +const createVendorOrdersWorkflow = createWorkflow( "create-vendor-order", - (input) => { + (input: WorkflowInput) => { const { cart } = retrieveCartStep(input) const { order } = createParentOrderStep(input)