Skip to content

Commit

Permalink
fix(wf): cleanup input after the first step
Browse files Browse the repository at this point in the history
  • Loading branch information
mav-rik committed Oct 2, 2023
1 parent c2f8bc3 commit 192561f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/event-wf/src/event-wf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export function resumeWfContext(
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
*/
export function useWFContext<T extends TEmpty>() {
return useEventContext<TWFContextStore & T, TWFEventData>('CLI')
return useEventContext<TWFContextStore & T, TWFEventData>('WF')
}
19 changes: 16 additions & 3 deletions packages/event-wf/src/wf-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TWooksHandler, TWooksOptions, Wooks, WooksAdapterBase } from 'wooks'
import { createWfContext, resumeWfContext } from './event-wf'
import { createWfContext, resumeWfContext, useWFContext } from './event-wf'
import { TConsoleBase } from '@prostojs/logger'
import { TEventOptions } from '@wooksjs/event-core'
import { Step, TFlowOutput, TStepHandler, TWorkflowSchema, createStep, TWorkflowSpy } from '@prostojs/wf'
Expand Down Expand Up @@ -76,6 +76,19 @@ export class WooksWf<T> extends WooksAdapterBase {
null
if (handlers && handlers.length) {
let result: TFlowOutput<T, I> = {} as TFlowOutput<T, I>
let firstStep = true
const _spy: TWorkflowSpy<T, I> = (...args) => {
if (spy) {
spy(...args)
}
if (firstStep && args[0] === 'step') {
// cleanup input after the first step
firstStep = false
restoreCtx()
const { store } = useWFContext()
store('event').set('input', undefined)
}
}
try {
for (const handler of handlers) {
restoreCtx()
Expand All @@ -86,10 +99,10 @@ export class WooksWf<T> extends WooksAdapterBase {
}
restoreCtx()
if (resume) {
result = await this.wf.resume<I>(id, { context: inputContext, indexes }, input as I, spy)
result = await this.wf.resume<I>(id, { context: inputContext, indexes }, input as I, _spy)
break
} else {
result = await this.wf.start<I>(id, inputContext, input, spy)
result = await this.wf.start<I>(id, inputContext, input, _spy)
break
}
}
Expand Down

0 comments on commit 192561f

Please sign in to comment.