feat(workflows): Workflow DX (#5607)

This commit is contained in:
Carlos R. L. Rodrigues
2023-11-22 17:23:39 +00:00
committed by GitHub
parent 2850e9a772
commit 9f9db39698
22 changed files with 2768 additions and 16 deletions

View File

@@ -70,7 +70,7 @@ export class WorkflowManager {
static register(
workflowId: string,
flow: TransactionStepsDefinition | OrchestratorBuilder,
flow: TransactionStepsDefinition | OrchestratorBuilder | undefined,
handlers: WorkflowHandler,
requiredModules?: Set<string>,
optionalModules?: Set<string>
@@ -78,19 +78,22 @@ export class WorkflowManager {
const finalFlow = flow instanceof OrchestratorBuilder ? flow.build() : flow
if (WorkflowManager.workflows.has(workflowId)) {
const areStepsEqual =
JSON.stringify(finalFlow) ===
JSON.stringify(WorkflowManager.workflows.get(workflowId)!.flow_)
const areStepsEqual = finalFlow
? JSON.stringify(finalFlow) ===
JSON.stringify(WorkflowManager.workflows.get(workflowId)!.flow_)
: true
if (!areStepsEqual) {
throw new Error(`Workflow with id "${workflowId}" and step definition already exists.`)
throw new Error(
`Workflow with id "${workflowId}" and step definition already exists.`
)
}
}
WorkflowManager.workflows.set(workflowId, {
id: workflowId,
flow_: finalFlow,
orchestrator: new TransactionOrchestrator(workflowId, finalFlow),
flow_: finalFlow!,
orchestrator: new TransactionOrchestrator(workflowId, finalFlow ?? {}),
handler: WorkflowManager.buildHandlers(handlers),
handlers_: handlers,
requiredModules,