fix(workflows-sdk): fix step name config used before default (#12926)
This commit is contained in:
1 parent
bccf1bb689
commit
1bd455bc7b
5 files changed
+49
-4
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/workflows-sdk": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(workflows-sdk): step config name before default step
|
||||||
@@ -1408,6 +1408,41 @@ describe("Workflow composer", function () {
|
|||||||
expect(logStepFn).toHaveBeenCalledTimes(0)
|
expect(logStepFn).toHaveBeenCalledTimes(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should run same step multiple times", async () => {
|
||||||
|
const log = createStep("log", async (input: number) => {
|
||||||
|
return new StepResponse(input)
|
||||||
|
})
|
||||||
|
|
||||||
|
const sameStepWorkflow = createWorkflow("fake-workflow", () => {
|
||||||
|
const a = log(1).config({ name: "aaaa" })
|
||||||
|
const b = log(2) // without config on purpose
|
||||||
|
const c = log(3).config({ name: "cccc" })
|
||||||
|
return new WorkflowResponse([a, b, c])
|
||||||
|
})
|
||||||
|
|
||||||
|
const sameStepWorkflow2 = createWorkflow("fake-workflow-2", () => {
|
||||||
|
const a = log(1)
|
||||||
|
const b = log(2).config({ name: "bbbb" })
|
||||||
|
const c = log(3).config({ name: "cccc" })
|
||||||
|
return new WorkflowResponse([a, b, c])
|
||||||
|
})
|
||||||
|
|
||||||
|
const sameStepWorkflow3 = createWorkflow("fake-workflow-3", () => {
|
||||||
|
const a = log(1).config({ name: "aaaa" })
|
||||||
|
const b = log(2).config({ name: "bbbb" })
|
||||||
|
const c = log(3)
|
||||||
|
return new WorkflowResponse([a, b, c])
|
||||||
|
})
|
||||||
|
|
||||||
|
const { result } = await sameStepWorkflow().run()
|
||||||
|
const { result: result2 } = await sameStepWorkflow2().run()
|
||||||
|
const { result: result3 } = await sameStepWorkflow3().run()
|
||||||
|
|
||||||
|
expect(result).toEqual([1, 2, 3])
|
||||||
|
expect(result2).toEqual([1, 2, 3])
|
||||||
|
expect(result3).toEqual([1, 2, 3])
|
||||||
|
})
|
||||||
|
|
||||||
it("should skip steps until the named step in case of permanent failure", async () => {
|
it("should skip steps until the named step in case of permanent failure", async () => {
|
||||||
const logStepFn = jest.fn(async ({ input }: { input: object }) => {
|
const logStepFn = jest.fn(async ({ input }: { input: object }) => {
|
||||||
return new StepResponse("done and returned")
|
return new StepResponse("done and returned")
|
||||||
|
|||||||
@@ -143,9 +143,9 @@ export function applyStep<
|
|||||||
|
|
||||||
this.isAsync ||= !!(stepConfig.async || stepConfig.compensateAsync)
|
this.isAsync ||= !!(stepConfig.async || stepConfig.compensateAsync)
|
||||||
|
|
||||||
if (!this.handlers.has(stepName)) {
|
this.overriddenHandler.set(stepName, this.handlers.get(stepName)!)
|
||||||
this.handlers.set(stepName, handler)
|
|
||||||
}
|
this.handlers.set(stepName, handler)
|
||||||
|
|
||||||
const ret = {
|
const ret = {
|
||||||
__type: OrchestrationUtils.SymbolWorkflowStep,
|
__type: OrchestrationUtils.SymbolWorkflowStep,
|
||||||
@@ -177,7 +177,7 @@ export function applyStep<
|
|||||||
newConfig.nested ||= newConfig.async
|
newConfig.nested ||= newConfig.async
|
||||||
}
|
}
|
||||||
|
|
||||||
delete localConfig.name
|
delete newConfig.name
|
||||||
|
|
||||||
const handler = createStepHandler.bind(this)({
|
const handler = createStepHandler.bind(this)({
|
||||||
stepName: newStepName,
|
stepName: newStepName,
|
||||||
@@ -188,6 +188,9 @@ export function applyStep<
|
|||||||
|
|
||||||
wrapAsyncHandler(newConfig, handler)
|
wrapAsyncHandler(newConfig, handler)
|
||||||
|
|
||||||
|
this.handlers.set(stepName, this.overriddenHandler.get(stepName)!)
|
||||||
|
this.overriddenHandler.delete(stepName)
|
||||||
|
|
||||||
this.handlers.set(newStepName, handler)
|
this.handlers.set(newStepName, handler)
|
||||||
|
|
||||||
this.flow.replaceAction(stepConfig.uuid!, newStepName, newConfig)
|
this.flow.replaceAction(stepConfig.uuid!, newStepName, newConfig)
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ export function createWorkflow<TData, TResult, THooks extends any[]>(
|
|||||||
flow: WorkflowManager.getEmptyTransactionDefinition(),
|
flow: WorkflowManager.getEmptyTransactionDefinition(),
|
||||||
isAsync: false,
|
isAsync: false,
|
||||||
handlers,
|
handlers,
|
||||||
|
overriddenHandler: new Map(),
|
||||||
hooks_: {
|
hooks_: {
|
||||||
declared: [],
|
declared: [],
|
||||||
registered: [],
|
registered: [],
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ export type CreateWorkflowComposerContext = {
|
|||||||
flow: OrchestratorBuilder
|
flow: OrchestratorBuilder
|
||||||
isAsync: boolean
|
isAsync: boolean
|
||||||
handlers: WorkflowHandler
|
handlers: WorkflowHandler
|
||||||
|
overriddenHandler: WorkflowHandler
|
||||||
stepBinder: <TOutput = unknown>(
|
stepBinder: <TOutput = unknown>(
|
||||||
fn: StepFunctionResult
|
fn: StepFunctionResult
|
||||||
) => WorkflowData<TOutput>
|
) => WorkflowData<TOutput>
|
||||||
|
|||||||
Reference in new issue
Block a user