From 61a0e4f3cfcac9d9bbc65a75955a72dea78b590d Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 3 Mar 2025 12:20:21 +0200 Subject: [PATCH] chore(workflows-sdk): fix examples in TSDocs (#11689) --- .../src/utils/composer/create-step.ts | 23 +++++++++++-------- .../src/utils/composer/create-workflow.ts | 12 ++++------ .../src/utils/composer/parallelize.ts | 15 ++++++------ .../workflows-sdk/src/utils/composer/when.ts | 2 +- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/core/workflows-sdk/src/utils/composer/create-step.ts b/packages/core/workflows-sdk/src/utils/composer/create-step.ts index b5f0f2697d..bdf58d6c5f 100644 --- a/packages/core/workflows-sdk/src/utils/composer/create-step.ts +++ b/packages/core/workflows-sdk/src/utils/composer/create-step.ts @@ -334,21 +334,21 @@ function wrapConditionalStep( * createStep, * StepResponse * } from "@medusajs/framework/workflows-sdk" - * + * * interface CreateProductInput { * title: string * } - * + * * export const createProductStep = createStep( * "createProductStep", * async function ( * input: CreateProductInput, - * context + * { container } * ) { - * const productService = context.container.resolve( - * "productService" + * const productModuleService = container.resolve( + * "product" * ) - * const product = await productService.createProducts(input) + * const product = await productModuleService.createProducts(input) * return new StepResponse({ * product * }, { @@ -357,12 +357,15 @@ function wrapConditionalStep( * }, * async function ( * input, - * context + * { container } * ) { - * const productService = context.container.resolve( - * "productService" + * if (!input) { + * return + * } + * const productModuleService = container.resolve( + * "product" * ) - * await productService.deleteProducts(input.product_id) + * await productModuleService.deleteProducts([input.product_id]) * } * ) */ diff --git a/packages/core/workflows-sdk/src/utils/composer/create-workflow.ts b/packages/core/workflows-sdk/src/utils/composer/create-workflow.ts index 329b79ba78..58f5134ed3 100644 --- a/packages/core/workflows-sdk/src/utils/composer/create-workflow.ts +++ b/packages/core/workflows-sdk/src/utils/composer/create-workflow.ts @@ -46,25 +46,23 @@ global[OrchestrationUtils.SymbolMedusaWorkflowComposerContext] = null * import { * createProductStep, * getProductStep, - * createPricesStep * } from "./steps" - * + * * interface WorkflowInput { * title: string * } - * + * * const myWorkflow = createWorkflow( * "my-workflow", * (input: WorkflowInput) => { * // Everything here will be executed and resolved later * // during the execution. Including the data access. - * + * * const product = createProductStep(input) - * const prices = createPricesStep(product) * return new WorkflowResponse(getProductStep(product.id)) * } * ) - * + * * export async function GET( * req: MedusaRequest, * res: MedusaResponse @@ -75,7 +73,7 @@ global[OrchestrationUtils.SymbolMedusaWorkflowComposerContext] = null * title: "Shirt" * } * }) - * + * * res.json({ * product * }) diff --git a/packages/core/workflows-sdk/src/utils/composer/parallelize.ts b/packages/core/workflows-sdk/src/utils/composer/parallelize.ts index ef0f4f7e41..3ddf4e20b3 100644 --- a/packages/core/workflows-sdk/src/utils/composer/parallelize.ts +++ b/packages/core/workflows-sdk/src/utils/composer/parallelize.ts @@ -16,27 +16,28 @@ import { OrchestrationUtils } from "@medusajs/utils" * } from "@medusajs/framework/workflows-sdk" * import { * createProductStep, - * getProductStep, * createPricesStep, * attachProductToSalesChannelStep * } from "./steps" - * + * * interface WorkflowInput { * title: string * } - * + * * const myWorkflow = createWorkflow( * "my-workflow", * (input: WorkflowInput) => { * const product = createProductStep(input) - * + * * const [prices, productSalesChannel] = parallelize( * createPricesStep(product), * attachProductToSalesChannelStep(product) * ) - * - * const id = product.id - * return new WorkflowResponse(getProductStep(product.id)) + * + * return new WorkflowResponse({ + * prices, + * productSalesChannel + * }) * } * ) */ diff --git a/packages/core/workflows-sdk/src/utils/composer/when.ts b/packages/core/workflows-sdk/src/utils/composer/when.ts index 46c1371315..1924ebc5cf 100644 --- a/packages/core/workflows-sdk/src/utils/composer/when.ts +++ b/packages/core/workflows-sdk/src/utils/composer/when.ts @@ -36,7 +36,7 @@ type ThenFunc = any>( * } from "@medusajs/framework/workflows-sdk" * // step imports... * - * const workflow = createWorkflow( + * export const workflow = createWorkflow( * "workflow", * function (input: { * is_active: boolean