fix: steps to return undefined and still chain the config method (#12255)
Fixes: FRMW-2946
This commit is contained in:
5
.changeset/popular-windows-agree.md
Normal file
5
.changeset/popular-windows-agree.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/workflows-sdk": patch
|
||||
---
|
||||
|
||||
fix: steps to return undefined and still chain the config method
|
||||
@@ -21,6 +21,14 @@ const step3 = createStep("step3", async function (_, context) {
|
||||
return new StepResponse({ step3: "step3" })
|
||||
})
|
||||
|
||||
const step4 = createStep("step4", async function (_, context) {
|
||||
return new StepResponse<undefined | { id: number }>({ id: 1 })
|
||||
})
|
||||
|
||||
const step5 = createStep("step5", async function (_, context) {
|
||||
return new StepResponse(void 0)
|
||||
})
|
||||
|
||||
const workflow = createWorkflow(
|
||||
"sub-workflow",
|
||||
function (input: WorkflowData<{ outsideWorkflowData: string }>) {
|
||||
@@ -37,6 +45,12 @@ const workflow = createWorkflow(
|
||||
}
|
||||
)
|
||||
|
||||
const step4Result = step4().config({ name: "foo" })
|
||||
step4Result
|
||||
|
||||
const step5Result = step5().config({ name: "foo" })
|
||||
step5Result
|
||||
|
||||
return new WorkflowResponse(
|
||||
{ r: somethingHook.getResult(), step3: step3() },
|
||||
{ hooks: [somethingHook] }
|
||||
|
||||
@@ -852,7 +852,7 @@ describe("Workflow composer", function () {
|
||||
)
|
||||
const step4 = createStep(
|
||||
"step4",
|
||||
mockStep4Fn as unknown as StepFunction<never, never>,
|
||||
mockStep4Fn as unknown as StepFunction<never, StepResponse<void>>,
|
||||
step4CompensationFn
|
||||
)
|
||||
|
||||
@@ -923,7 +923,7 @@ describe("Workflow composer", function () {
|
||||
)
|
||||
const step4 = createStep(
|
||||
"step4",
|
||||
mockStep4Fn as unknown as StepFunction<never, never>,
|
||||
mockStep4Fn as unknown as StepFunction<never, StepResponse<void>>,
|
||||
step4CompensationFn
|
||||
)
|
||||
|
||||
@@ -2002,14 +2002,10 @@ describe("Workflow composer", function () {
|
||||
mockStep3Fn as unknown as StepFunction<never, StepResponse<string>>,
|
||||
step3CompensationFn
|
||||
)
|
||||
const step4 = createStep(
|
||||
"step4",
|
||||
mockStep4Fn as unknown as StepFunction<never, never>,
|
||||
step4CompensationFn
|
||||
)
|
||||
const step4 = createStep("step4", mockStep4Fn, step4CompensationFn)
|
||||
|
||||
const workflow = createWorkflow("workflow1", function (input) {
|
||||
const [step1Res] = parallelize(step1(), step2(), step3(), step4())
|
||||
const [step1Res] = parallelize(step1(), step2(), step3(), step4({}))
|
||||
return new WorkflowResponse(step1Res)
|
||||
})
|
||||
|
||||
@@ -2058,33 +2054,17 @@ describe("Workflow composer", function () {
|
||||
throw new Error("An error occured in step 4.")
|
||||
})
|
||||
|
||||
const step1 = createStep(
|
||||
"step1",
|
||||
mockStep1Fn as unknown as StepFunction<never, StepResponse<string>>,
|
||||
step1CompensationFn
|
||||
)
|
||||
const step2 = createStep(
|
||||
"step2",
|
||||
mockStep2Fn as unknown as StepFunction<never, StepResponse<string>>,
|
||||
step2CompensationFn
|
||||
)
|
||||
const step3 = createStep(
|
||||
"step3",
|
||||
mockStep3Fn as unknown as StepFunction<never, StepResponse<string>>,
|
||||
step3CompensationFn
|
||||
)
|
||||
const step4 = createStep(
|
||||
"step4",
|
||||
mockStep4Fn as unknown as StepFunction<never, never>,
|
||||
step4CompensationFn
|
||||
)
|
||||
const step1 = createStep("step1", mockStep1Fn, step1CompensationFn)
|
||||
const step2 = createStep("step2", mockStep2Fn, step2CompensationFn)
|
||||
const step3 = createStep("step3", mockStep3Fn, step3CompensationFn)
|
||||
const step4 = createStep("step4", mockStep4Fn, step4CompensationFn)
|
||||
|
||||
const workflow = createWorkflow("workflow1", function (input) {
|
||||
const [step1Res] = parallelize(
|
||||
step1().config({ name: "newStep1Name" }),
|
||||
step2(),
|
||||
step3(),
|
||||
step4()
|
||||
step1({}).config({ name: "newStep1Name" }),
|
||||
step2({}),
|
||||
step3({}),
|
||||
step4({})
|
||||
)
|
||||
return new WorkflowResponse(step1Res)
|
||||
})
|
||||
|
||||
@@ -50,6 +50,8 @@ type ConvertHooksToFunctions<THooks extends any[]> = THooks extends [
|
||||
? ConvertHookToObject<A> & ConvertHooksToFunctions<R>
|
||||
: {}
|
||||
|
||||
export type Void = { " $$type": "void" }
|
||||
|
||||
/**
|
||||
* A step function to be used in a workflow.
|
||||
*
|
||||
@@ -62,7 +64,9 @@ export type StepFunction<
|
||||
> = (KeysOfUnion<TInput> extends []
|
||||
? // Function that doesn't expect any input
|
||||
{
|
||||
(): WorkflowData<TOutput> & StepFunctionReturnConfig<TOutput>
|
||||
(): TOutput & {} extends never
|
||||
? WorkflowData<Void> & StepFunctionReturnConfig<TOutput>
|
||||
: WorkflowData<TOutput> & StepFunctionReturnConfig<TOutput>
|
||||
}
|
||||
: // function that expects an input object
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user