@n8n/engine 0.16.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/auth/action-token.d.ts +7 -0
  2. package/dist/auth/action-token.js +30 -0
  3. package/dist/auth/action-token.js.map +1 -0
  4. package/dist/auth/authenticate.d.ts +4 -0
  5. package/dist/auth/authenticate.js +30 -0
  6. package/dist/auth/authenticate.js.map +1 -0
  7. package/dist/auth/identity-token.d.ts +12 -0
  8. package/dist/auth/identity-token.js +45 -0
  9. package/dist/auth/identity-token.js.map +1 -0
  10. package/dist/auth/identity.types.d.ts +7 -0
  11. package/dist/auth/identity.types.js +3 -0
  12. package/dist/auth/identity.types.js.map +1 -0
  13. package/dist/auth/index.d.ts +5 -0
  14. package/dist/auth/index.js +17 -0
  15. package/dist/auth/index.js.map +1 -0
  16. package/dist/auth/shared-secret-token.d.ts +12 -0
  17. package/dist/auth/shared-secret-token.js +44 -0
  18. package/dist/auth/shared-secret-token.js.map +1 -0
  19. package/dist/build.tsbuildinfo +1 -1
  20. package/dist/common/index.d.ts +1 -0
  21. package/dist/common/index.js +3 -1
  22. package/dist/common/index.js.map +1 -1
  23. package/dist/common/json.schema.d.ts +3 -0
  24. package/dist/common/json.schema.js +13 -0
  25. package/dist/common/json.schema.js.map +1 -0
  26. package/dist/database/create-stores.d.ts +5 -2
  27. package/dist/database/create-stores.js +6 -2
  28. package/dist/database/create-stores.js.map +1 -1
  29. package/dist/database/entities/workflow-execution.entity.d.ts +2 -4
  30. package/dist/database/entities/workflow-execution.entity.js +3 -14
  31. package/dist/database/entities/workflow-execution.entity.js.map +1 -1
  32. package/dist/database/entities/workflow-step-execution.entity.d.ts +2 -2
  33. package/dist/database/entities/workflow-step-execution.entity.js +7 -3
  34. package/dist/database/entities/workflow-step-execution.entity.js.map +1 -1
  35. package/dist/database/index.d.ts +2 -0
  36. package/dist/database/index.js +3 -1
  37. package/dist/database/index.js.map +1 -1
  38. package/dist/database/migrations/1778529600000-CreateWorkflowExecution.js +1 -1
  39. package/dist/database/migrations/1784890100000-CreateWorkflowStepExecution.js +13 -2
  40. package/dist/database/migrations/1784890100000-CreateWorkflowStepExecution.js.map +1 -1
  41. package/dist/database/typeorm-execution-store.d.ts +1 -3
  42. package/dist/database/typeorm-execution-store.js +1 -2
  43. package/dist/database/typeorm-execution-store.js.map +1 -1
  44. package/dist/database/typeorm-execution-view-store.d.ts +10 -0
  45. package/dist/database/typeorm-execution-view-store.js +49 -0
  46. package/dist/database/typeorm-execution-view-store.js.map +1 -0
  47. package/dist/database/typeorm-step-store.d.ts +7 -6
  48. package/dist/database/typeorm-step-store.js +63 -14
  49. package/dist/database/typeorm-step-store.js.map +1 -1
  50. package/dist/dependencies/external-dependencies.d.ts +3 -0
  51. package/dist/execution/batch-step.d.ts +8 -0
  52. package/dist/execution/batch-step.js +28 -0
  53. package/dist/execution/batch-step.js.map +1 -0
  54. package/dist/execution/completion.d.ts +2 -0
  55. package/dist/execution/completion.js +21 -0
  56. package/dist/execution/completion.js.map +1 -0
  57. package/dist/execution/execution-query.service.d.ts +7 -0
  58. package/dist/execution/execution-query.service.js +17 -0
  59. package/dist/execution/execution-query.service.js.map +1 -0
  60. package/dist/execution/execution-start-handler.d.ts +3 -1
  61. package/dist/execution/execution-start-handler.js +13 -2
  62. package/dist/execution/execution-start-handler.js.map +1 -1
  63. package/dist/execution/execution-store.d.ts +5 -7
  64. package/dist/execution/execution-store.js.map +1 -1
  65. package/dist/execution/execution-view-store.d.ts +26 -0
  66. package/dist/execution/execution-view-store.js +3 -0
  67. package/dist/execution/execution-view-store.js.map +1 -0
  68. package/dist/execution/execution.types.d.ts +14 -0
  69. package/dist/execution/execution.types.js +6 -1
  70. package/dist/execution/execution.types.js.map +1 -1
  71. package/dist/execution/index.d.ts +5 -2
  72. package/dist/execution/index.js +5 -1
  73. package/dist/execution/index.js.map +1 -1
  74. package/dist/execution/iteration-mapping.d.ts +14 -0
  75. package/dist/execution/iteration-mapping.js +48 -0
  76. package/dist/execution/iteration-mapping.js.map +1 -0
  77. package/dist/execution/loop-ledger.d.ts +7 -0
  78. package/dist/execution/loop-ledger.js +39 -0
  79. package/dist/execution/loop-ledger.js.map +1 -0
  80. package/dist/execution/settlement.d.ts +6 -4
  81. package/dist/execution/settlement.js +73 -17
  82. package/dist/execution/settlement.js.map +1 -1
  83. package/dist/execution/start-execution.service.d.ts +3 -3
  84. package/dist/execution/start-execution.service.js +6 -4
  85. package/dist/execution/start-execution.service.js.map +1 -1
  86. package/dist/execution/step-ready-handler.d.ts +11 -2
  87. package/dist/execution/step-ready-handler.js +66 -13
  88. package/dist/execution/step-ready-handler.js.map +1 -1
  89. package/dist/execution/step-settled-handler.d.ts +4 -3
  90. package/dist/execution/step-settled-handler.js +52 -30
  91. package/dist/execution/step-settled-handler.js.map +1 -1
  92. package/dist/execution/step-store.d.ts +9 -13
  93. package/dist/execution/step-store.js.map +1 -1
  94. package/dist/execution/store-loop-reader.d.ts +4 -0
  95. package/dist/execution/store-loop-reader.js +48 -0
  96. package/dist/execution/store-loop-reader.js.map +1 -0
  97. package/dist/graph/graph-validation.error.d.ts +3 -0
  98. package/dist/graph/graph-validation.error.js +11 -0
  99. package/dist/graph/graph-validation.error.js.map +1 -0
  100. package/dist/graph/index.d.ts +6 -2
  101. package/dist/graph/index.js +9 -2
  102. package/dist/graph/index.js.map +1 -1
  103. package/dist/graph/loops.d.ts +10 -0
  104. package/dist/graph/loops.js +172 -0
  105. package/dist/graph/loops.js.map +1 -0
  106. package/dist/graph/validate-executable-graph.d.ts +1 -3
  107. package/dist/graph/validate-executable-graph.js +13 -18
  108. package/dist/graph/validate-executable-graph.js.map +1 -1
  109. package/dist/graph/workflow-graph.d.ts +4 -0
  110. package/dist/graph/workflow-graph.js +7 -0
  111. package/dist/graph/workflow-graph.js.map +1 -1
  112. package/dist/index.d.ts +14 -7
  113. package/dist/index.js +19 -12
  114. package/dist/index.js.map +1 -1
  115. package/dist/lifecycle-events/batching-lifecycle-event-publisher.d.ts +26 -0
  116. package/dist/lifecycle-events/batching-lifecycle-event-publisher.js +121 -0
  117. package/dist/lifecycle-events/batching-lifecycle-event-publisher.js.map +1 -0
  118. package/dist/lifecycle-events/index.d.ts +6 -0
  119. package/dist/lifecycle-events/index.js +15 -0
  120. package/dist/lifecycle-events/index.js.map +1 -0
  121. package/dist/lifecycle-events/lifecycle-event-publisher.d.ts +6 -0
  122. package/dist/lifecycle-events/lifecycle-event-publisher.js +8 -0
  123. package/dist/lifecycle-events/lifecycle-event-publisher.js.map +1 -0
  124. package/dist/lifecycle-events/lifecycle-event.schema.d.ts +339 -0
  125. package/dist/lifecycle-events/lifecycle-event.schema.js +39 -0
  126. package/dist/lifecycle-events/lifecycle-event.schema.js.map +1 -0
  127. package/dist/lifecycle-events/lifecycle-event.types.d.ts +4 -0
  128. package/dist/lifecycle-events/lifecycle-event.types.js +3 -0
  129. package/dist/lifecycle-events/lifecycle-event.types.js.map +1 -0
  130. package/dist/logging/console-logger.d.ts +2 -0
  131. package/dist/logging/console-logger.js +18 -0
  132. package/dist/logging/console-logger.js.map +1 -0
  133. package/dist/logging/index.d.ts +2 -0
  134. package/dist/logging/index.js +6 -0
  135. package/dist/logging/index.js.map +1 -0
  136. package/dist/logging/logger.types.d.ts +6 -0
  137. package/dist/logging/logger.types.js +3 -0
  138. package/dist/logging/logger.types.js.map +1 -0
  139. package/dist/queue/in-memory-work-queue.d.ts +3 -0
  140. package/dist/queue/in-memory-work-queue.js +7 -2
  141. package/dist/queue/in-memory-work-queue.js.map +1 -1
  142. package/dist/runtime/create-engine-runtime.d.ts +20 -0
  143. package/dist/runtime/create-engine-runtime.js +38 -0
  144. package/dist/runtime/create-engine-runtime.js.map +1 -0
  145. package/dist/runtime/index.d.ts +2 -0
  146. package/dist/runtime/index.js +6 -0
  147. package/dist/runtime/index.js.map +1 -0
  148. package/dist/serve.js +25 -34
  149. package/dist/serve.js.map +1 -1
  150. package/dist/server/api.types.d.ts +25 -0
  151. package/dist/server/api.types.js +3 -0
  152. package/dist/server/api.types.js.map +1 -0
  153. package/dist/server/create-engine-server.d.ts +9 -7
  154. package/dist/server/create-engine-server.js +4 -8
  155. package/dist/server/create-engine-server.js.map +1 -1
  156. package/dist/server/error-response.d.ts +7 -0
  157. package/dist/server/error-response.js +12 -0
  158. package/dist/server/error-response.js.map +1 -0
  159. package/dist/server/index.d.ts +3 -0
  160. package/dist/server/index.js +3 -1
  161. package/dist/server/index.js.map +1 -1
  162. package/dist/server/routes/workflow-executions.d.ts +2 -2
  163. package/dist/server/routes/workflow-executions.handlers.d.ts +4 -0
  164. package/dist/server/routes/workflow-executions.handlers.js +68 -0
  165. package/dist/server/routes/workflow-executions.handlers.js.map +1 -0
  166. package/dist/server/routes/workflow-executions.js +16 -21
  167. package/dist/server/routes/workflow-executions.js.map +1 -1
  168. package/dist/testing/start-engine-server.d.ts +1 -1
  169. package/dist/testing/start-engine-server.js.map +1 -1
  170. package/package.json +10 -7
@@ -1,14 +1,14 @@
1
1
  import { type AdmittanceService } from '../admittance';
2
- import type { JsonObject } from '../common';
3
2
  import { type WorkflowGraph } from '../graph';
4
3
  import type { OrchestrationMessage, WorkQueue } from '../queue';
5
4
  import type { ExecutionStore } from './execution-store';
6
- import type { ExecutionMode } from './execution.types';
5
+ import type { ExecutionMode, TriggerOutputs } from './execution.types';
7
6
  export interface StartExecutionRequest {
8
7
  workflowId: string;
9
8
  graph: WorkflowGraph;
10
- triggerPayload?: JsonObject | null;
9
+ triggerOutputs?: TriggerOutputs | null;
11
10
  mode?: ExecutionMode;
11
+ executionId: string;
12
12
  }
13
13
  export interface StartExecutionResult {
14
14
  executionId: string;
@@ -20,18 +20,20 @@ class StartExecutionService {
20
20
  if (!decision.accept) {
21
21
  throw new admittance_1.AdmittanceRejectedError(decision.reason);
22
22
  }
23
- const { id } = await this.executionStore.createExecution({
23
+ const { executionId } = request;
24
+ await this.executionStore.createExecution({
25
+ id: executionId,
24
26
  workflowId: request.workflowId,
25
27
  status: 'queued',
26
28
  mode: request.mode ?? 'production',
27
29
  graph: request.graph,
28
- triggerPayload: request.triggerPayload ?? null,
30
+ triggerOutputs: request.triggerOutputs ?? null,
29
31
  });
30
32
  await this.workQueue.publish({
31
33
  type: 'execution:enqueued',
32
- executionId: id,
34
+ executionId,
33
35
  });
34
- return { executionId: id };
36
+ return { executionId };
35
37
  }
36
38
  }
37
39
  exports.StartExecutionService = StartExecutionService;
@@ -1 +1 @@
1
- {"version":3,"file":"start-execution.service.js","sourceRoot":"","sources":["../../src/execution/start-execution.service.ts"],"names":[],"mappings":";;;AAAA,8CAAgF;AAEhF,oCAAuE;AAgBvE;IAEmB,UAAU;IACV,cAAc;IACd,SAAS;IACT,aAAa;IAJ/B,YACkB,UAA6B,EAC7B,cAA8B,EAC9B,SAA0C,EAC1C,aAAa,GAAmC,+BAAuB;0BAHvE,UAAU;8BACV,cAAc;yBACd,SAAS;6BACT,aAAa;IAC5B,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,OAA8B;QAGzC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAElC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QACpF,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,IAAI,oCAAuB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACpD,CAAC;QAED,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC;YACxD,UAAU,EAAE,OAAO,CAAC,UAAU;YAE9B,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,YAAY;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,IAAI;SAC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CAAC;YAC5B,IAAI,EAAE,oBAAoB;YAC1B,WAAW;SACX,CAAC,CAAC;QAEH,OAAO,EAAE,WAAW,EAAE,CAAC;IACxB,CAAC;CACD"}
@@ -1,15 +1,24 @@
1
1
  import type { ExternalDependencies } from '../dependencies';
2
+ import { type GraphEdge, type WorkflowLoop } from '../graph';
3
+ import type { LifecycleEventPublisher } from '../lifecycle-events';
2
4
  import type { OrchestrationMessage, StepReadyEvent, WorkQueue } from '../queue';
3
5
  import type { ExecutionStore } from './execution-store';
4
- import type { StepStore } from './step-store';
6
+ import { type StepKey } from './execution.types';
7
+ import type { StepRecord, StepStore } from './step-store';
5
8
  export declare class StepReadyHandler {
6
9
  private readonly executionStore;
7
10
  private readonly stepStore;
8
11
  private readonly orchestrationQueue;
9
12
  private readonly dependencies;
10
- constructor(executionStore: ExecutionStore, stepStore: StepStore, orchestrationQueue: WorkQueue<OrchestrationMessage>, dependencies: ExternalDependencies);
13
+ private readonly lifecycleEventPublisher;
14
+ constructor(executionStore: ExecutionStore, stepStore: StepStore, orchestrationQueue: WorkQueue<OrchestrationMessage>, dependencies: ExternalDependencies, lifecycleEventPublisher: LifecycleEventPublisher);
11
15
  handle(event: StepReadyEvent): Promise<void>;
12
16
  private runStep;
17
+ private runBatchNode;
13
18
  private gatherInputs;
14
19
  private executorFor;
15
20
  }
21
+ export declare function resolveInputReads(incomingEdges: GraphEdge[], loops: WorkflowLoop[], step: Pick<StepRecord, 'id' | 'nodeId' | 'iteration'>, terminalIterations: Map<string, number>): Array<{
22
+ edge: GraphEdge;
23
+ key: StepKey;
24
+ }>;
@@ -1,19 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StepReadyHandler = void 0;
4
+ exports.resolveInputReads = resolveInputReads;
4
5
  const common_1 = require("../common");
6
+ const graph_1 = require("../graph");
7
+ const batch_step_1 = require("./batch-step");
5
8
  const execution_types_1 = require("./execution.types");
9
+ const iteration_mapping_1 = require("./iteration-mapping");
10
+ const loop_ledger_1 = require("./loop-ledger");
11
+ const store_loop_reader_1 = require("./store-loop-reader");
6
12
  const validate_step_context_1 = require("./validate-step-context");
7
13
  class StepReadyHandler {
8
14
  executionStore;
9
15
  stepStore;
10
16
  orchestrationQueue;
11
17
  dependencies;
12
- constructor(executionStore, stepStore, orchestrationQueue, dependencies) {
18
+ lifecycleEventPublisher;
19
+ constructor(executionStore, stepStore, orchestrationQueue, dependencies, lifecycleEventPublisher) {
13
20
  this.executionStore = executionStore;
14
21
  this.stepStore = stepStore;
15
22
  this.orchestrationQueue = orchestrationQueue;
16
23
  this.dependencies = dependencies;
24
+ this.lifecycleEventPublisher = lifecycleEventPublisher;
17
25
  }
18
26
  async handle(event) {
19
27
  const step = await this.stepStore.claimStep(event.stepId);
@@ -21,16 +29,19 @@ class StepReadyHandler {
21
29
  return;
22
30
  const execution = await this.executionStore.loadExecution(event.executionId);
23
31
  const node = (0, validate_step_context_1.validateStepContext)(step, execution);
24
- const executor = this.executorFor(step, node);
32
+ const executor = node.type === 'batch' ? undefined : this.executorFor(step, node);
25
33
  if (execution.status !== 'running') {
26
34
  return;
27
35
  }
36
+ this.lifecycleEventPublisher.publish({ type: 'step:started', ...stepEventFields(step, node) });
28
37
  const inputs = await this.gatherInputs(execution, step);
29
38
  let run;
30
39
  try {
31
40
  run = {
32
41
  ok: true,
33
- outputs: await this.runStep(step, execution, node, inputs, executor),
42
+ outputs: executor
43
+ ? await this.runStep(step, execution, node, inputs, executor)
44
+ : await this.runBatchNode(step, execution, node),
34
45
  };
35
46
  }
36
47
  catch (error) {
@@ -41,6 +52,9 @@ class StepReadyHandler {
41
52
  : await this.stepStore.failStep(event.stepId, toStepError(run.error));
42
53
  if (!recorded)
43
54
  return;
55
+ this.lifecycleEventPublisher.publish(run.ok
56
+ ? { type: 'step:completed', ...stepEventFields(step, node), outputs: run.outputs }
57
+ : { type: 'step:failed', ...stepEventFields(step, node) });
44
58
  await this.orchestrationQueue.publish({
45
59
  type: 'step:settled',
46
60
  executionId: event.executionId,
@@ -56,21 +70,38 @@ class StepReadyHandler {
56
70
  stepId: step.id,
57
71
  workflowId: execution.workflowId,
58
72
  mode: execution.mode,
73
+ iteration: step.iteration,
59
74
  },
60
75
  });
61
76
  return outputs;
62
77
  }
78
+ async runBatchNode(step, execution, node) {
79
+ if (!(0, graph_1.isBatchStepConfig)(node.config)) {
80
+ throw new common_1.UnexpectedError(`step ${step.id} runs batch node ${step.nodeId}, whose config has no whole batch size of at least 1`);
81
+ }
82
+ const loops = (0, graph_1.deriveLoops)(execution.graph);
83
+ const loop = loops.find((l) => l.batchNodeId === step.nodeId);
84
+ if (!loop) {
85
+ throw new common_1.UnexpectedError(`step ${step.id} runs batch node ${step.nodeId}, which heads no loop in the execution graph`);
86
+ }
87
+ const terminalIterations = await (0, loop_ledger_1.loadTerminalIterations)(this.stepStore, execution.id, (0, loop_ledger_1.exitSourcesInto)(execution.graph, loops, [step.nodeId]));
88
+ const reader = (0, store_loop_reader_1.createStoreLoopReader)(this.stepStore, execution.id, loops, loop, terminalIterations);
89
+ return await (0, batch_step_1.runBatchStep)(node.config, step.iteration, reader);
90
+ }
63
91
  async gatherInputs(execution, step) {
64
92
  const incomingEdges = execution.graph.edges.filter((edge) => edge.to === step.nodeId);
65
93
  if (incomingEdges.length === 0) {
66
94
  throw new common_1.UnexpectedError(`step ${step.id} runs node ${step.nodeId}, which has no predecessor in the execution graph`);
67
95
  }
68
- validateIncomingEdges(incomingEdges, step);
69
- const predecessorNodeIds = [...new Set(incomingEdges.map((edge) => edge.from))];
70
- const predecessorSteps = await this.stepStore.loadStepsByNodeIds(execution.id, predecessorNodeIds);
71
- const inputs = Array.from({ length: Math.max(...incomingEdges.map((edge) => edge.inputIndex)) + 1 }, () => null);
72
- for (const edge of incomingEdges) {
73
- inputs[edge.inputIndex] = readEdgeValue(edge, predecessorSteps, step);
96
+ const loops = (0, graph_1.deriveLoops)(execution.graph);
97
+ const terminalIterations = await (0, loop_ledger_1.loadTerminalIterations)(this.stepStore, execution.id, (0, loop_ledger_1.exitSourcesInto)(execution.graph, loops, [step.nodeId]));
98
+ const reads = resolveInputReads(incomingEdges, loops, step, terminalIterations);
99
+ const rows = await this.stepStore.loadStepsByKeys(execution.id, [
100
+ ...new Map(reads.map(({ key }) => [(0, execution_types_1.stepKeyId)(key), key])).values(),
101
+ ]);
102
+ const inputs = Array.from({ length: Math.max(...reads.map(({ edge }) => edge.inputIndex)) + 1 }, () => null);
103
+ for (const { edge, key } of reads) {
104
+ inputs[edge.inputIndex] = readEdgeValue(edge, key, step, rows);
74
105
  }
75
106
  return inputs;
76
107
  }
@@ -86,17 +117,29 @@ class StepReadyHandler {
86
117
  }
87
118
  }
88
119
  exports.StepReadyHandler = StepReadyHandler;
89
- function validateIncomingEdges(incomingEdges, step) {
120
+ function resolveInputReads(incomingEdges, loops, step, terminalIterations) {
121
+ const reads = incomingEdges.flatMap((edge) => {
122
+ const source = (0, iteration_mapping_1.sourceRow)(edge, (0, iteration_mapping_1.classifyEdge)(edge, loops), step, terminalIterations.get(edge.from));
123
+ if (source.kind === 'row')
124
+ return [{ edge, key: source.key }];
125
+ if (source.kind === 'none')
126
+ return [];
127
+ throw new common_1.UnexpectedError(`step ${step.id} reads node ${edge.from} across a loop that has not ended`);
128
+ });
129
+ if (reads.length === 0) {
130
+ throw new common_1.UnexpectedError(`step ${step.id} runs node ${step.nodeId}, which no edge reaches at iteration ${step.iteration}`);
131
+ }
90
132
  const filledSlots = new Set();
91
- for (const edge of incomingEdges) {
133
+ for (const { edge } of reads) {
92
134
  if (filledSlots.has(edge.inputIndex)) {
93
135
  throw new common_1.UnexpectedError(`step ${step.id} runs node ${step.nodeId}, which has more than one edge into input slot ${edge.inputIndex}; validated graphs have at most one edge per input slot`);
94
136
  }
95
137
  filledSlots.add(edge.inputIndex);
96
138
  }
139
+ return reads;
97
140
  }
98
- function readEdgeValue(edge, predecessorSteps, step) {
99
- const row = predecessorSteps[edge.from];
141
+ function readEdgeValue(edge, source, step, rows) {
142
+ const row = rows[(0, execution_types_1.stepKeyId)(source)];
100
143
  if (!row || !(0, execution_types_1.isSettledStatus)(row.status)) {
101
144
  throw new common_1.UnexpectedError(`step ${step.id} reads node ${edge.from}, whose step has not settled`);
102
145
  }
@@ -104,6 +147,16 @@ function readEdgeValue(edge, predecessorSteps, step) {
104
147
  return null;
105
148
  return row.outputs?.[edge.outputIndex] ?? null;
106
149
  }
150
+ function stepEventFields(step, node) {
151
+ return {
152
+ executionId: step.executionId,
153
+ stepId: step.id,
154
+ nodeId: step.nodeId,
155
+ nodeName: node.name,
156
+ iteration: step.iteration,
157
+ at: new Date().toISOString(),
158
+ };
159
+ }
107
160
  function toStepError(error) {
108
161
  if (error instanceof Error) {
109
162
  return { name: error.name, message: error.message, stack: error.stack };
@@ -1 +1 @@
1
- {"version":3,"file":"step-ready-handler.js","sourceRoot":"","sources":["../../src/execution/step-ready-handler.ts"],"names":[],"mappings":";;;AAAA,sCAAgF;AAKhF,uDAAoE;AAEpE,mEAA8D;AAW9D;IAEmB,cAAc;IACd,SAAS;IACT,kBAAkB;IAClB,YAAY;IAJ9B,YACkB,cAA8B,EAC9B,SAAoB,EACpB,kBAAmD,EACnD,YAAkC;8BAHlC,cAAc;yBACd,SAAS;kCACT,kBAAkB;4BAClB,YAAY;IAC3B,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,KAAqB;QAEjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI;YAAE,OAAO;QAOlB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC7E,MAAM,IAAI,GAAG,IAAA,2CAAmB,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,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KAAK,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACzE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAClD,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { LifecycleEventPublisher } from '../lifecycle-events';
1
2
  import type { OrchestrationMessage, StepMessage, StepSettledEvent, WorkQueue } from '../queue';
2
3
  import type { ExecutionStore } from './execution-store';
3
4
  import type { StepStore } from './step-store';
@@ -6,12 +7,12 @@ export declare class StepSettledHandler {
6
7
  private readonly stepStore;
7
8
  private readonly stepQueue;
8
9
  private readonly orchestrationQueue;
9
- constructor(executionStore: ExecutionStore, stepStore: StepStore, stepQueue: WorkQueue<StepMessage>, orchestrationQueue: WorkQueue<OrchestrationMessage>);
10
+ private readonly lifecycleEventPublisher;
11
+ constructor(executionStore: ExecutionStore, stepStore: StepStore, stepQueue: WorkQueue<StepMessage>, orchestrationQueue: WorkQueue<OrchestrationMessage>, lifecycleEventPublisher: LifecycleEventPublisher);
10
12
  handle(event: StepSettledEvent): Promise<void>;
11
13
  private failExecution;
12
14
  private planSuccessors;
13
- private loadDecisionSteps;
14
15
  private announceCreatedSteps;
15
16
  private finishExecutionIfDone;
16
- private reachableNodeCount;
17
+ private reachableNodeIds;
17
18
  }
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StepSettledHandler = void 0;
4
4
  const common_1 = require("../common");
5
5
  const graph_1 = require("../graph");
6
+ const completion_1 = require("./completion");
7
+ const execution_types_1 = require("./execution.types");
8
+ const loop_ledger_1 = require("./loop-ledger");
6
9
  const settlement_1 = require("./settlement");
7
10
  const validate_step_context_1 = require("./validate-step-context");
8
11
  class StepSettledHandler {
@@ -10,11 +13,13 @@ class StepSettledHandler {
10
13
  stepStore;
11
14
  stepQueue;
12
15
  orchestrationQueue;
13
- constructor(executionStore, stepStore, stepQueue, orchestrationQueue) {
16
+ lifecycleEventPublisher;
17
+ constructor(executionStore, stepStore, stepQueue, orchestrationQueue, lifecycleEventPublisher) {
14
18
  this.executionStore = executionStore;
15
19
  this.stepStore = stepStore;
16
20
  this.stepQueue = stepQueue;
17
21
  this.orchestrationQueue = orchestrationQueue;
22
+ this.lifecycleEventPublisher = lifecycleEventPublisher;
18
23
  }
19
24
  async handle(event) {
20
25
  const [step, execution] = await Promise.all([
@@ -23,7 +28,7 @@ class StepSettledHandler {
23
28
  ]);
24
29
  (0, validate_step_context_1.validateStepContext)(step, execution);
25
30
  if (step.status === 'failed') {
26
- await this.failExecution(execution.id);
31
+ await this.failExecution(execution);
27
32
  return;
28
33
  }
29
34
  if (execution.status !== 'running')
@@ -31,44 +36,45 @@ class StepSettledHandler {
31
36
  let queued = 0;
32
37
  if (step.status === 'completed' || step.status === 'skipped') {
33
38
  if (await this.stepStore.hasFailedSteps(execution.id)) {
34
- await this.failExecution(execution.id);
39
+ await this.failExecution(execution);
35
40
  return;
36
41
  }
37
- const steps = await this.loadDecisionSteps(execution, step.nodeId);
38
- queued = await this.planSuccessors(execution, step.nodeId, steps);
42
+ queued = await this.planSuccessors(execution, step);
39
43
  }
40
44
  if (queued > 0)
41
45
  return;
42
46
  await this.finishExecutionIfDone(execution);
43
47
  }
44
- async failExecution(executionId) {
45
- await this.executionStore.finishExecution(executionId, 'failed');
46
- await this.stepStore.cancelQueuedSteps(executionId);
48
+ async failExecution(execution) {
49
+ const finished = await this.executionStore.finishExecution(execution.id, 'failed');
50
+ if (finished) {
51
+ this.lifecycleEventPublisher.publish({
52
+ type: 'execution:failed',
53
+ executionId: execution.id,
54
+ workflowId: execution.workflowId,
55
+ at: new Date().toISOString(),
56
+ });
57
+ }
58
+ await this.stepStore.cancelQueuedSteps(execution.id);
47
59
  }
48
- async planSuccessors(execution, nodeId, steps) {
49
- const { toQueue, toSkip } = (0, settlement_1.decideSuccessors)(execution.graph, nodeId, steps);
60
+ async planSuccessors(execution, step) {
61
+ const loops = (0, graph_1.deriveLoops)(execution.graph);
62
+ const candidates = (0, graph_1.getSuccessorNodeIds)(execution.graph, step.nodeId);
63
+ const terminalIterations = await (0, loop_ledger_1.loadTerminalIterations)(this.stepStore, execution.id, (0, loop_ledger_1.exitSourcesInto)(execution.graph, loops, candidates));
64
+ const steps = await this.stepStore.loadStepSummariesByKeys(execution.id, (0, settlement_1.decisionKeys)(execution.graph, loops, step, terminalIterations));
65
+ const { toQueue, toSkip } = (0, settlement_1.decideSuccessors)(execution.graph, loops, step, steps, terminalIterations);
50
66
  if (toQueue.length === 0 && toSkip.length === 0)
51
67
  return 0;
52
68
  const created = await this.stepStore.createSteps(execution.id, [
53
- ...toQueue.map((id) => ({ nodeId: id, status: 'queued' })),
54
- ...toSkip.map((id) => ({ nodeId: id, status: 'skipped' })),
69
+ ...toQueue.map((key) => ({ ...key, status: 'queued' })),
70
+ ...toSkip.map((key) => ({ ...key, status: 'skipped' })),
55
71
  ]);
56
- return await this.announceCreatedSteps(execution.id, created, new Set(toQueue));
57
- }
58
- async loadDecisionSteps(execution, nodeId) {
59
- const successors = (0, graph_1.getSuccessorNodeIds)(execution.graph, nodeId);
60
- const nodeIds = [
61
- ...new Set([
62
- ...successors,
63
- ...successors.flatMap((id) => (0, graph_1.getPredecessorNodeIds)(execution.graph, id)),
64
- ]),
65
- ];
66
- return await this.stepStore.loadStepSummaries(execution.id, nodeIds);
72
+ return await this.announceCreatedSteps(execution.id, created, new Set(toQueue.map(execution_types_1.stepKeyId)));
67
73
  }
68
- async announceCreatedSteps(executionId, created, queuedNodeIds) {
74
+ async announceCreatedSteps(executionId, created, queuedKeys) {
69
75
  let queued = 0;
70
- for (const { id: stepId, nodeId } of created) {
71
- if (queuedNodeIds.has(nodeId)) {
76
+ for (const { id: stepId, ...key } of created) {
77
+ if (queuedKeys.has((0, execution_types_1.stepKeyId)(key))) {
72
78
  queued += 1;
73
79
  await this.stepQueue.publish({ type: 'step:ready', executionId, stepId });
74
80
  }
@@ -79,18 +85,34 @@ class StepSettledHandler {
79
85
  return queued;
80
86
  }
81
87
  async finishExecutionIfDone(execution) {
88
+ const reachable = this.reachableNodeIds(execution);
89
+ const loops = (0, graph_1.deriveLoops)(execution.graph);
90
+ const terminalIterations = await (0, loop_ledger_1.loadTerminalIterations)(this.stepStore, execution.id, loops
91
+ .filter((loop) => reachable.has(loop.batchNodeId))
92
+ .map((loop) => loop.batchNodeId));
93
+ const expected = (0, completion_1.countExpectedSettledSteps)(loops, reachable, terminalIterations);
94
+ if (expected === undefined)
95
+ return;
82
96
  const settled = await this.stepStore.countSettledSteps(execution.id);
83
- if (settled < this.reachableNodeCount(execution))
97
+ if (settled < expected)
84
98
  return;
85
99
  const failed = await this.stepStore.hasFailedSteps(execution.id);
86
- await this.executionStore.finishExecution(execution.id, failed ? 'failed' : 'completed');
100
+ const finished = await this.executionStore.finishExecution(execution.id, failed ? 'failed' : 'completed');
101
+ if (finished) {
102
+ this.lifecycleEventPublisher.publish({
103
+ type: failed ? 'execution:failed' : 'execution:completed',
104
+ executionId: execution.id,
105
+ workflowId: execution.workflowId,
106
+ at: new Date().toISOString(),
107
+ });
108
+ }
87
109
  }
88
- reachableNodeCount(execution) {
110
+ reachableNodeIds(execution) {
89
111
  const trigger = (0, graph_1.findTriggerNode)(execution.graph);
90
112
  if (!trigger) {
91
113
  throw new common_1.UnexpectedError(`Execution ${execution.id} has no trigger node in its graph`);
92
114
  }
93
- return 1 + (0, graph_1.getDescendantNodeIds)(execution.graph, trigger.id).length;
115
+ return new Set([trigger.id, ...(0, graph_1.getDescendantNodeIds)(execution.graph, trigger.id)]);
94
116
  }
95
117
  }
96
118
  exports.StepSettledHandler = StepSettledHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"step-settled-handler.js","sourceRoot":"","sources":["../../src/execution/step-settled-handler.ts"],"names":[],"mappings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EAAE,GAAG,IAAA,4BAAoB,EAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC;CACD"}
@@ -1,7 +1,7 @@
1
- import type { JsonValue } from '../common';
2
- import type { StepSlots, StepStatus } from './execution.types';
1
+ import type { StepError, StepKey, StepKeyId, StepSlots, StepStatus } from './execution.types';
3
2
  export type NewStepRecord = {
4
3
  nodeId: string;
4
+ iteration: number;
5
5
  } & ({
6
6
  status: Extract<StepStatus, 'queued' | 'skipped'>;
7
7
  outputs?: never;
@@ -9,23 +9,18 @@ export type NewStepRecord = {
9
9
  status: Extract<StepStatus, 'completed'>;
10
10
  outputs: StepSlots;
11
11
  });
12
- export interface StepError {
13
- name: string;
14
- message: string;
15
- stack?: string;
16
- details?: JsonValue;
17
- }
18
12
  export interface StepRecord {
19
13
  id: string;
20
14
  executionId: string;
21
15
  nodeId: string;
16
+ iteration: number;
22
17
  status: StepStatus;
23
18
  outputs: StepSlots | null;
24
- error: StepError | null;
25
19
  }
26
20
  export interface StepSummary {
27
21
  id: string;
28
22
  nodeId: string;
23
+ iteration: number;
29
24
  status: StepStatus;
30
25
  filledOutputSlots: boolean[];
31
26
  }
@@ -36,15 +31,16 @@ export declare class StepNotFoundError extends Error {
36
31
  export interface StepStore {
37
32
  createSteps(executionId: string, records: NewStepRecord[]): Promise<Array<{
38
33
  id: string;
39
- nodeId: string;
40
- }>>;
34
+ } & StepKey>>;
41
35
  loadStep(id: string): Promise<StepRecord>;
42
36
  claimStep(id: string): Promise<StepRecord | null>;
43
37
  completeStep(id: string, outputs: StepSlots): Promise<boolean>;
44
38
  failStep(id: string, error: StepError): Promise<boolean>;
45
39
  cancelQueuedSteps(executionId: string): Promise<void>;
46
- loadStepsByNodeIds(executionId: string, nodeIds: string[]): Promise<Record<string, StepRecord>>;
47
- loadStepSummaries(executionId: string, nodeIds: string[]): Promise<Record<string, StepSummary>>;
40
+ loadStepsByKeys(executionId: string, keys: StepKey[]): Promise<Record<StepKeyId, StepRecord>>;
41
+ loadStepSummariesByKeys(executionId: string, keys: StepKey[]): Promise<Record<StepKeyId, StepSummary>>;
42
+ loadLatestStepSummaries(executionId: string, nodeIds: string[]): Promise<Record<string, StepSummary>>;
43
+ loadAllSteps(executionId: string): Promise<StepRecord[]>;
48
44
  countSettledSteps(executionId: string): Promise<number>;
49
45
  hasFailedSteps(executionId: string): Promise<boolean>;
50
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"step-store.js","sourceRoot":"","sources":["../../src/execution/step-store.ts"],"names":[],"mappings":";;;AA0DA,uBAA+B,SAAQ,KAAK;IACtB,MAAM;IAA3B,YAAqB,MAAc;QAClC,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;sBADf,MAAM;QAE1B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD"}
1
+ {"version":3,"file":"step-store.js","sourceRoot":"","sources":["../../src/execution/step-store.ts"],"names":[],"mappings":";;;AA8CA,uBAA+B,SAAQ,KAAK;IACtB,MAAM;IAA3B,YAAqB,MAAc;QAClC,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;sBADf,MAAM;QAE1B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ import type { WorkflowLoop } from '../graph';
2
+ import type { LoopReader } from './batch-step';
3
+ import type { StepStore } from './step-store';
4
+ export declare function createStoreLoopReader(stepStore: StepStore, executionId: string, loops: WorkflowLoop[], loop: WorkflowLoop, terminalIterations: Map<string, number>): LoopReader;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStoreLoopReader = createStoreLoopReader;
4
+ const common_1 = require("../common");
5
+ const execution_types_1 = require("./execution.types");
6
+ const iteration_mapping_1 = require("./iteration-mapping");
7
+ function createStoreLoopReader(stepStore, executionId, loops, loop, terminalIterations) {
8
+ if (loop.entryEdges.length > 1 || loop.backEdges.length > 1) {
9
+ throw new common_1.UnexpectedError(`batch node ${loop.batchNodeId} has ${loop.entryEdges.length} entry edges and ${loop.backEdges.length} back-edges; validated loops have at most one of each`);
10
+ }
11
+ const [entryEdge] = loop.entryEdges;
12
+ const [backEdge] = loop.backEdges;
13
+ return {
14
+ async readOriginalItems() {
15
+ if (!entryEdge)
16
+ return null;
17
+ const source = (0, iteration_mapping_1.sourceRow)(entryEdge, (0, iteration_mapping_1.classifyEdge)(entryEdge, loops), { nodeId: loop.batchNodeId, iteration: 0 }, terminalIterations.get(entryEdge.from));
18
+ if (source.kind !== 'row') {
19
+ throw new common_1.UnexpectedError(`batch node ${loop.batchNodeId} reads ${entryEdge.from}, which has no step to read`);
20
+ }
21
+ const steps = await stepStore.loadStepsByKeys(executionId, [source.key]);
22
+ const step = steps[(0, execution_types_1.stepKeyId)(source.key)];
23
+ if (!step) {
24
+ throw new common_1.UnexpectedError(`batch node ${loop.batchNodeId} reads ${entryEdge.from} at iteration ${source.key.iteration}, which has no step`);
25
+ }
26
+ return step.outputs?.[entryEdge.outputIndex] ?? null;
27
+ },
28
+ async readArrivals(iteration) {
29
+ if (!backEdge)
30
+ return [];
31
+ if (iteration === 0)
32
+ return [];
33
+ const keys = Array.from({ length: iteration }, (_, index) => ({
34
+ nodeId: backEdge.from,
35
+ iteration: index,
36
+ }));
37
+ const steps = await stepStore.loadStepsByKeys(executionId, keys);
38
+ return keys.map((key) => {
39
+ const step = steps[(0, execution_types_1.stepKeyId)(key)];
40
+ if (!step) {
41
+ throw new common_1.UnexpectedError(`batch node ${loop.batchNodeId} reads ${backEdge.from} at iteration ${key.iteration}, which has no step`);
42
+ }
43
+ return step.outputs?.[backEdge.outputIndex] ?? null;
44
+ });
45
+ },
46
+ };
47
+ }
48
+ //# sourceMappingURL=store-loop-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-loop-reader.js","sourceRoot":"","sources":["../../src/execution/store-loop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raphValidationError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphValidationError = void 0;
4
+ class GraphValidationError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'GraphValidationError';
8
+ }
9
+ }
10
+ exports.GraphValidationError = GraphValidationError;
11
+ //# sourceMappingURL=graph-validation.error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-validation.error.js","sourceRoot":"","sources":["../../src/graph/graph-validation.error.ts"],"names":[],"mappings":";;;AACA,0BAAkC,SAAQ,KAAK;IAC9C,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACpC,CAAC;CACD"}
@@ -1,3 +1,7 @@
1
- export type { GraphEdge, GraphNode, StepConfig, StepType, WorkflowGraph, } from './workflow-graph';
1
+ export { isBatchStepConfig } from './workflow-graph';
2
+ export type { BatchStepConfig, GraphEdge, GraphNode, StepConfig, StepType, WorkflowGraph, } from './workflow-graph';
2
3
  export { findTriggerNode, getDescendantNodeIds, getPredecessorNodeIds, getSuccessorNodeIds, } from './workflow-graph-queries';
3
- export { GraphValidationError, validateExecutableGraph } from './validate-executable-graph';
4
+ export { GraphValidationError } from './graph-validation.error';
5
+ export { MAX_SLOT_INDEX, validateExecutableGraph } from './validate-executable-graph';
6
+ export { deriveLoops, validateLoops } from './loops';
7
+ export type { WorkflowLoop } from './loops';