Skip to main content
Skip to main content

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

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

Tobject | WorkflowDataRequired
RFinalobjectRequired

Parameters

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

Returns

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