fix: steps to return undefined and still chain the config method (#12255)
Fixes: FRMW-2946
This commit is contained in:
1 parent
38710c116e
commit
c2fe3f1520
4 files changed
+36
-33
No files matched your search
@@ -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" })
|
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(
|
const workflow = createWorkflow(
|
||||||
"sub-workflow",
|
"sub-workflow",
|
||||||
function (input: WorkflowData<{ outsideWorkflowData: string }>) {
|
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(
|
return new WorkflowResponse(
|
||||||
{ r: somethingHook.getResult(), step3: step3() },
|
{ r: somethingHook.getResult(), step3: step3() },
|
||||||
{ hooks: [somethingHook] }
|
{ hooks: [somethingHook] }
|
||||||
|
|||||||
@@ -852,7 +852,7 @@ describe("Workflow composer", function () {
|
|||||||
)
|
)
|
||||||
const step4 = createStep(
|
const step4 = createStep(
|
||||||
"step4",
|
"step4",
|
||||||
mockStep4Fn as unknown as StepFunction<never, never>,
|
mockStep4Fn as unknown as StepFunction<never, StepResponse<void>>,
|
||||||
step4CompensationFn
|
step4CompensationFn
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -923,7 +923,7 @@ describe("Workflow composer", function () {
|
|||||||
)
|
)
|
||||||
const step4 = createStep(
|
const step4 = createStep(
|
||||||
"step4",
|
"step4",
|
||||||
mockStep4Fn as unknown as StepFunction<never, never>,
|
mockStep4Fn as unknown as StepFunction<never, StepResponse<void>>,
|
||||||
step4CompensationFn
|
step4CompensationFn
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -2002,14 +2002,10 @@ describe("Workflow composer", function () {
|
|||||||
mockStep3Fn as unknown as StepFunction<never, StepResponse<string>>,
|
mockStep3Fn as unknown as StepFunction<never, StepResponse<string>>,
|
||||||
step3CompensationFn
|
step3CompensationFn
|
||||||
)
|
)
|
||||||
const step4 = createStep(
|
const step4 = createStep("step4", mockStep4Fn, step4CompensationFn)
|
||||||
"step4",
|
|
||||||
mockStep4Fn as unknown as StepFunction<never, never>,
|
|
||||||
step4CompensationFn
|
|
||||||
)
|
|
||||||
|
|
||||||
const workflow = createWorkflow("workflow1", function (input) {
|
const workflow = createWorkflow("workflow1", function (input) {
|
||||||
const [step1Res] = parallelize(step1(), step2(), step3(), step4())
|
const [step1Res] = parallelize(step1(), step2(), step3(), step4({}))
|
||||||
return new WorkflowResponse(step1Res)
|
return new WorkflowResponse(step1Res)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -2058,33 +2054,17 @@ describe("Workflow composer", function () {
|
|||||||
throw new Error("An error occured in step 4.")
|
throw new Error("An error occured in step 4.")
|
||||||
})
|
})
|
||||||
|
|
||||||
const step1 = createStep(
|
const step1 = createStep("step1", mockStep1Fn, step1CompensationFn)
|
||||||
"step1",
|
const step2 = createStep("step2", mockStep2Fn, step2CompensationFn)
|
||||||
mockStep1Fn as unknown as StepFunction<never, StepResponse<string>>,
|
const step3 = createStep("step3", mockStep3Fn, step3CompensationFn)
|
||||||
step1CompensationFn
|
const step4 = createStep("step4", mockStep4Fn, step4CompensationFn)
|
||||||
)
|
|
||||||
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 workflow = createWorkflow("workflow1", function (input) {
|
const workflow = createWorkflow("workflow1", function (input) {
|
||||||
const [step1Res] = parallelize(
|
const [step1Res] = parallelize(
|
||||||
step1().config({ name: "newStep1Name" }),
|
step1({}).config({ name: "newStep1Name" }),
|
||||||
step2(),
|
step2({}),
|
||||||
step3(),
|
step3({}),
|
||||||
step4()
|
step4({})
|
||||||
)
|
)
|
||||||
return new WorkflowResponse(step1Res)
|
return new WorkflowResponse(step1Res)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ type ConvertHooksToFunctions<THooks extends any[]> = THooks extends [
|
|||||||
? ConvertHookToObject<A> & ConvertHooksToFunctions<R>
|
? ConvertHookToObject<A> & ConvertHooksToFunctions<R>
|
||||||
: {}
|
: {}
|
||||||
|
|
||||||
|
export type Void = { " $$type": "void" }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A step function to be used in a workflow.
|
* A step function to be used in a workflow.
|
||||||
*
|
*
|
||||||
@@ -62,7 +64,9 @@ export type StepFunction<
|
|||||||
> = (KeysOfUnion<TInput> extends []
|
> = (KeysOfUnion<TInput> extends []
|
||||||
? // Function that doesn't expect any input
|
? // 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
|
: // function that expects an input object
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user