Learning Resources

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, 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#

Code
1import {2  createWorkflow,3  transform4} from "@medusajs/workflows-sdk"5import { step1, step2 } from "./steps"6
7type WorkflowInput = {8  name: string9}10
11type WorkflowOutput = {12  message: string13}14
15const myWorkflow = createWorkflow<16    WorkflowInput,17    WorkflowOutput18  >19  ("hello-world", (input) => {20    const str1 = step1(input)21    const str2 = step2(input)22
23    return transform({24      str1,25      str226    }, (input) => ({27      message: `${input.str1}${input.str2}`28    }))29})

Type Parameters#

Tobject | WorkflowDataOptional
RFinalobjectOptional

Parameters#

valuesT
The output(s) of other step functions.
func[Func1<T, RFinal>]
The transform function used to perform action on the runtime values of the provided values.

Returns#

WorkflowDataWorkflowData<RFinal>
There's no expected value to be returned by the transform function.
Was this page helpful?