@calmo/task-runner 1.2.1 → 1.2.2

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 (39) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/coverage/coverage-final.json +5 -2
  3. package/coverage/index.html +21 -21
  4. package/coverage/lcov-report/index.html +21 -21
  5. package/coverage/lcov-report/src/EventBus.ts.html +337 -0
  6. package/coverage/{TaskGraphValidator.ts.html → lcov-report/src/TaskGraphValidator.ts.html} +10 -10
  7. package/coverage/lcov-report/src/TaskRunner.ts.html +409 -0
  8. package/coverage/lcov-report/src/WorkflowExecutor.ts.html +400 -0
  9. package/coverage/lcov-report/src/contracts/RunnerEvents.ts.html +217 -0
  10. package/coverage/lcov-report/src/contracts/index.html +116 -0
  11. package/coverage/lcov-report/src/index.html +161 -0
  12. package/coverage/lcov.info +189 -140
  13. package/coverage/src/EventBus.ts.html +337 -0
  14. package/coverage/{lcov-report → src}/TaskGraphValidator.ts.html +10 -10
  15. package/coverage/src/TaskRunner.ts.html +409 -0
  16. package/coverage/src/WorkflowExecutor.ts.html +400 -0
  17. package/coverage/src/contracts/RunnerEvents.ts.html +217 -0
  18. package/coverage/src/contracts/index.html +116 -0
  19. package/coverage/src/index.html +161 -0
  20. package/dist/EventBus.d.ts +26 -0
  21. package/dist/EventBus.js +56 -0
  22. package/dist/EventBus.js.map +1 -0
  23. package/dist/TaskRunner.d.ts +3 -36
  24. package/dist/TaskRunner.js +7 -95
  25. package/dist/TaskRunner.js.map +1 -1
  26. package/dist/WorkflowExecutor.d.ts +23 -0
  27. package/dist/WorkflowExecutor.js +89 -0
  28. package/dist/WorkflowExecutor.js.map +1 -0
  29. package/dist/contracts/RunnerEvents.d.ts +36 -0
  30. package/dist/contracts/RunnerEvents.js +2 -0
  31. package/dist/contracts/RunnerEvents.js.map +1 -0
  32. package/package.json +1 -1
  33. package/src/EventBus.ts +84 -0
  34. package/src/TaskRunner.ts +10 -161
  35. package/src/WorkflowExecutor.ts +105 -0
  36. package/src/contracts/RunnerEvents.ts +44 -0
  37. package/test-report.xml +41 -37
  38. package/coverage/TaskRunner.ts.html +0 -862
  39. package/coverage/lcov-report/TaskRunner.ts.html +0 -862
@@ -0,0 +1,116 @@
1
+
2
+ <!doctype html>
3
+ <html lang="en">
4
+
5
+ <head>
6
+ <title>Code coverage report for src/contracts</title>
7
+ <meta charset="utf-8" />
8
+ <link rel="stylesheet" href="../../prettify.css" />
9
+ <link rel="stylesheet" href="../../base.css" />
10
+ <link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
11
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
12
+ <style type='text/css'>
13
+ .coverage-summary .sorter {
14
+ background-image: url(../../sort-arrow-sprite.png);
15
+ }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <div class='wrapper'>
21
+ <div class='pad1'>
22
+ <h1><a href="../../index.html">All files</a> src/contracts</h1>
23
+ <div class='clearfix'>
24
+
25
+ <div class='fl pad1y space-right2'>
26
+ <span class="strong">0% </span>
27
+ <span class="quiet">Statements</span>
28
+ <span class='fraction'>0/0</span>
29
+ </div>
30
+
31
+
32
+ <div class='fl pad1y space-right2'>
33
+ <span class="strong">0% </span>
34
+ <span class="quiet">Branches</span>
35
+ <span class='fraction'>0/0</span>
36
+ </div>
37
+
38
+
39
+ <div class='fl pad1y space-right2'>
40
+ <span class="strong">0% </span>
41
+ <span class="quiet">Functions</span>
42
+ <span class='fraction'>0/0</span>
43
+ </div>
44
+
45
+
46
+ <div class='fl pad1y space-right2'>
47
+ <span class="strong">0% </span>
48
+ <span class="quiet">Lines</span>
49
+ <span class='fraction'>0/0</span>
50
+ </div>
51
+
52
+
53
+ </div>
54
+ <p class="quiet">
55
+ Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
+ </p>
57
+ <template id="filterTemplate">
58
+ <div class="quiet">
59
+ Filter:
60
+ <input type="search" id="fileSearch">
61
+ </div>
62
+ </template>
63
+ </div>
64
+ <div class='status-line low'></div>
65
+ <div class="pad1">
66
+ <table class="coverage-summary">
67
+ <thead>
68
+ <tr>
69
+ <th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
70
+ <th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
71
+ <th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
72
+ <th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
73
+ <th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
74
+ <th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
75
+ <th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
76
+ <th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
77
+ <th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
78
+ <th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
79
+ </tr>
80
+ </thead>
81
+ <tbody><tr>
82
+ <td class="file empty" data-value="RunnerEvents.ts"><a href="RunnerEvents.ts.html">RunnerEvents.ts</a></td>
83
+ <td data-value="0" class="pic empty">
84
+ <div class="chart"><div class="cover-fill" style="width: 0%"></div><div class="cover-empty" style="width: 100%"></div></div>
85
+ </td>
86
+ <td data-value="0" class="pct empty">0%</td>
87
+ <td data-value="0" class="abs empty">0/0</td>
88
+ <td data-value="0" class="pct empty">0%</td>
89
+ <td data-value="0" class="abs empty">0/0</td>
90
+ <td data-value="0" class="pct empty">0%</td>
91
+ <td data-value="0" class="abs empty">0/0</td>
92
+ <td data-value="0" class="pct empty">0%</td>
93
+ <td data-value="0" class="abs empty">0/0</td>
94
+ </tr>
95
+
96
+ </tbody>
97
+ </table>
98
+ </div>
99
+ <div class='push'></div><!-- for sticky footer -->
100
+ </div><!-- /wrapper -->
101
+ <div class='footer quiet pad2 space-top1 center small'>
102
+ Code coverage generated by
103
+ <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
104
+ at 2026-01-18T05:44:30.758Z
105
+ </div>
106
+ <script src="../../prettify.js"></script>
107
+ <script>
108
+ window.onload = function () {
109
+ prettyPrint();
110
+ };
111
+ </script>
112
+ <script src="../../sorter.js"></script>
113
+ <script src="../../block-navigation.js"></script>
114
+ </body>
115
+ </html>
116
+
@@ -0,0 +1,161 @@
1
+
2
+ <!doctype html>
3
+ <html lang="en">
4
+
5
+ <head>
6
+ <title>Code coverage report for src</title>
7
+ <meta charset="utf-8" />
8
+ <link rel="stylesheet" href="../prettify.css" />
9
+ <link rel="stylesheet" href="../base.css" />
10
+ <link rel="shortcut icon" type="image/x-icon" href="../favicon.png" />
11
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
12
+ <style type='text/css'>
13
+ .coverage-summary .sorter {
14
+ background-image: url(../sort-arrow-sprite.png);
15
+ }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <div class='wrapper'>
21
+ <div class='pad1'>
22
+ <h1><a href="../index.html">All files</a> src</h1>
23
+ <div class='clearfix'>
24
+
25
+ <div class='fl pad1y space-right2'>
26
+ <span class="strong">100% </span>
27
+ <span class="quiet">Statements</span>
28
+ <span class='fraction'>131/131</span>
29
+ </div>
30
+
31
+
32
+ <div class='fl pad1y space-right2'>
33
+ <span class="strong">100% </span>
34
+ <span class="quiet">Branches</span>
35
+ <span class='fraction'>51/51</span>
36
+ </div>
37
+
38
+
39
+ <div class='fl pad1y space-right2'>
40
+ <span class="strong">100% </span>
41
+ <span class="quiet">Functions</span>
42
+ <span class='fraction'>22/22</span>
43
+ </div>
44
+
45
+
46
+ <div class='fl pad1y space-right2'>
47
+ <span class="strong">100% </span>
48
+ <span class="quiet">Lines</span>
49
+ <span class='fraction'>128/128</span>
50
+ </div>
51
+
52
+
53
+ </div>
54
+ <p class="quiet">
55
+ Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
+ </p>
57
+ <template id="filterTemplate">
58
+ <div class="quiet">
59
+ Filter:
60
+ <input type="search" id="fileSearch">
61
+ </div>
62
+ </template>
63
+ </div>
64
+ <div class='status-line high'></div>
65
+ <div class="pad1">
66
+ <table class="coverage-summary">
67
+ <thead>
68
+ <tr>
69
+ <th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
70
+ <th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
71
+ <th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
72
+ <th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
73
+ <th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
74
+ <th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
75
+ <th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
76
+ <th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
77
+ <th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
78
+ <th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
79
+ </tr>
80
+ </thead>
81
+ <tbody><tr>
82
+ <td class="file high" data-value="EventBus.ts"><a href="EventBus.ts.html">EventBus.ts</a></td>
83
+ <td data-value="100" class="pic high">
84
+ <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
85
+ </td>
86
+ <td data-value="100" class="pct high">100%</td>
87
+ <td data-value="15" class="abs high">15/15</td>
88
+ <td data-value="100" class="pct high">100%</td>
89
+ <td data-value="8" class="abs high">8/8</td>
90
+ <td data-value="100" class="pct high">100%</td>
91
+ <td data-value="4" class="abs high">4/4</td>
92
+ <td data-value="100" class="pct high">100%</td>
93
+ <td data-value="15" class="abs high">15/15</td>
94
+ </tr>
95
+
96
+ <tr>
97
+ <td class="file high" data-value="TaskGraphValidator.ts"><a href="TaskGraphValidator.ts.html">TaskGraphValidator.ts</a></td>
98
+ <td data-value="100" class="pic high">
99
+ <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
100
+ </td>
101
+ <td data-value="100" class="pct high">100%</td>
102
+ <td data-value="43" class="abs high">43/43</td>
103
+ <td data-value="100" class="pct high">100%</td>
104
+ <td data-value="16" class="abs high">16/16</td>
105
+ <td data-value="100" class="pct high">100%</td>
106
+ <td data-value="3" class="abs high">3/3</td>
107
+ <td data-value="100" class="pct high">100%</td>
108
+ <td data-value="42" class="abs high">42/42</td>
109
+ </tr>
110
+
111
+ <tr>
112
+ <td class="file high" data-value="TaskRunner.ts"><a href="TaskRunner.ts.html">TaskRunner.ts</a></td>
113
+ <td data-value="100" class="pic high">
114
+ <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
115
+ </td>
116
+ <td data-value="100" class="pct high">100%</td>
117
+ <td data-value="30" class="abs high">30/30</td>
118
+ <td data-value="100" class="pct high">100%</td>
119
+ <td data-value="7" class="abs high">7/7</td>
120
+ <td data-value="100" class="pct high">100%</td>
121
+ <td data-value="6" class="abs high">6/6</td>
122
+ <td data-value="100" class="pct high">100%</td>
123
+ <td data-value="29" class="abs high">29/29</td>
124
+ </tr>
125
+
126
+ <tr>
127
+ <td class="file high" data-value="WorkflowExecutor.ts"><a href="WorkflowExecutor.ts.html">WorkflowExecutor.ts</a></td>
128
+ <td data-value="100" class="pic high">
129
+ <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
130
+ </td>
131
+ <td data-value="100" class="pct high">100%</td>
132
+ <td data-value="43" class="abs high">43/43</td>
133
+ <td data-value="100" class="pct high">100%</td>
134
+ <td data-value="20" class="abs high">20/20</td>
135
+ <td data-value="100" class="pct high">100%</td>
136
+ <td data-value="9" class="abs high">9/9</td>
137
+ <td data-value="100" class="pct high">100%</td>
138
+ <td data-value="42" class="abs high">42/42</td>
139
+ </tr>
140
+
141
+ </tbody>
142
+ </table>
143
+ </div>
144
+ <div class='push'></div><!-- for sticky footer -->
145
+ </div><!-- /wrapper -->
146
+ <div class='footer quiet pad2 space-top1 center small'>
147
+ Code coverage generated by
148
+ <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
149
+ at 2026-01-18T05:44:30.758Z
150
+ </div>
151
+ <script src="../prettify.js"></script>
152
+ <script>
153
+ window.onload = function () {
154
+ prettyPrint();
155
+ };
156
+ </script>
157
+ <script src="../sorter.js"></script>
158
+ <script src="../block-navigation.js"></script>
159
+ </body>
160
+ </html>
161
+
@@ -0,0 +1,26 @@
1
+ import { RunnerEventListener, RunnerEventPayloads } from "./contracts/RunnerEvents.js";
2
+ /**
3
+ * Manages event subscriptions and emissions for the TaskRunner.
4
+ * @template TContext The shape of the shared context object.
5
+ */
6
+ export declare class EventBus<TContext> {
7
+ private listeners;
8
+ /**
9
+ * Subscribe to an event.
10
+ * @param event The event name.
11
+ * @param callback The callback to execute when the event is emitted.
12
+ */
13
+ on<K extends keyof RunnerEventPayloads<TContext>>(event: K, callback: RunnerEventListener<TContext, K>): void;
14
+ /**
15
+ * Unsubscribe from an event.
16
+ * @param event The event name.
17
+ * @param callback The callback to remove.
18
+ */
19
+ off<K extends keyof RunnerEventPayloads<TContext>>(event: K, callback: RunnerEventListener<TContext, K>): void;
20
+ /**
21
+ * Emit an event to all subscribers.
22
+ * @param event The event name.
23
+ * @param data The payload for the event.
24
+ */
25
+ emit<K extends keyof RunnerEventPayloads<TContext>>(event: K, data: RunnerEventPayloads<TContext>[K]): void;
26
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Manages event subscriptions and emissions for the TaskRunner.
3
+ * @template TContext The shape of the shared context object.
4
+ */
5
+ export class EventBus {
6
+ listeners = {};
7
+ /**
8
+ * Subscribe to an event.
9
+ * @param event The event name.
10
+ * @param callback The callback to execute when the event is emitted.
11
+ */
12
+ on(event, callback) {
13
+ if (!this.listeners[event]) {
14
+ // Type assertion needed because TypeScript cannot verify that the generic K
15
+ // matches the specific key in the mapped type during assignment.
16
+ this.listeners[event] = new Set();
17
+ }
18
+ // Type assertion needed to tell TS that this specific Set matches the callback type
19
+ this.listeners[event].add(callback);
20
+ }
21
+ /**
22
+ * Unsubscribe from an event.
23
+ * @param event The event name.
24
+ * @param callback The callback to remove.
25
+ */
26
+ off(event, callback) {
27
+ if (this.listeners[event]) {
28
+ this.listeners[event].delete(callback);
29
+ }
30
+ }
31
+ /**
32
+ * Emit an event to all subscribers.
33
+ * @param event The event name.
34
+ * @param data The payload for the event.
35
+ */
36
+ emit(event, data) {
37
+ const listeners = this.listeners[event];
38
+ if (listeners) {
39
+ for (const listener of listeners) {
40
+ try {
41
+ const result = listener(data);
42
+ if (result instanceof Promise) {
43
+ result.catch((error) => {
44
+ console.error(`Error in event listener for ${String(event)}:`, error);
45
+ });
46
+ }
47
+ }
48
+ catch (error) {
49
+ // Prevent listener errors from bubbling up
50
+ console.error(`Error in event listener for ${String(event)}:`, error);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ //# sourceMappingURL=EventBus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventBus.js","sourceRoot":"","sources":["../src/EventBus.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACX,SAAS,GAA0B,EAAE,CAAC;IAE9C;;;;OAIG;IACI,EAAE,CACP,KAAQ,EACR,QAA0C;QAE1C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,4EAA4E;YAC5E,iEAAiE;YACjE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,EAAyC,CAAC;QAC3E,CAAC;QACD,oFAAoF;QACnF,IAAI,CAAC,SAAS,CAAC,KAAK,CAA2C,CAAC,GAAG,CAClE,QAAQ,CACT,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,GAAG,CACR,KAAQ,EACR,QAA0C;QAE1C,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,SAAS,CAAC,KAAK,CAA2C,CAAC,MAAM,CACrE,QAAQ,CACT,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,IAAI,CACT,KAAQ,EACR,IAAsC;QAEtC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAEzB,CAAC;QACd,IAAI,SAAS,EAAE,CAAC;YACd,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAC9B,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;wBAC9B,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;4BACrB,OAAO,CAAC,KAAK,CACX,+BAA+B,MAAM,CAAC,KAAK,CAAC,GAAG,EAC/C,KAAK,CACN,CAAC;wBACJ,CAAC,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,2CAA2C;oBAC3C,OAAO,CAAC,KAAK,CACX,+BAA+B,MAAM,CAAC,KAAK,CAAC,GAAG,EAC/C,KAAK,CACN,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -1,33 +1,7 @@
1
1
  import { TaskStep } from "./TaskStep.js";
2
2
  import { TaskResult } from "./TaskResult.js";
3
- /**
4
- * Define the payload for every possible event in the lifecycle.
5
- */
6
- export interface RunnerEventPayloads<TContext> {
7
- workflowStart: {
8
- context: TContext;
9
- steps: TaskStep<TContext>[];
10
- };
11
- workflowEnd: {
12
- context: TContext;
13
- results: Map<string, TaskResult>;
14
- };
15
- taskStart: {
16
- step: TaskStep<TContext>;
17
- };
18
- taskEnd: {
19
- step: TaskStep<TContext>;
20
- result: TaskResult;
21
- };
22
- taskSkipped: {
23
- step: TaskStep<TContext>;
24
- result: TaskResult;
25
- };
26
- }
27
- /**
28
- * A generic listener type that maps the event key to its specific payload.
29
- */
30
- export type RunnerEventListener<TContext, K extends keyof RunnerEventPayloads<TContext>> = (data: RunnerEventPayloads<TContext>[K]) => void | Promise<void>;
3
+ import { RunnerEventPayloads, RunnerEventListener } from "./contracts/RunnerEvents.js";
4
+ export { RunnerEventPayloads, RunnerEventListener };
31
5
  /**
32
6
  * The main class that orchestrates the execution of a list of tasks
33
7
  * based on their dependencies, with support for parallel execution.
@@ -35,8 +9,7 @@ export type RunnerEventListener<TContext, K extends keyof RunnerEventPayloads<TC
35
9
  */
36
10
  export declare class TaskRunner<TContext> {
37
11
  private context;
38
- private running;
39
- private listeners;
12
+ private eventBus;
40
13
  private validator;
41
14
  /**
42
15
  * @param context The shared context object to be passed to each task.
@@ -54,12 +27,6 @@ export declare class TaskRunner<TContext> {
54
27
  * @param callback The callback to remove.
55
28
  */
56
29
  off<K extends keyof RunnerEventPayloads<TContext>>(event: K, callback: RunnerEventListener<TContext, K>): void;
57
- /**
58
- * Emit an event to all subscribers.
59
- * @param event The event name.
60
- * @param data The payload for the event.
61
- */
62
- private emit;
63
30
  /**
64
31
  * Executes a list of tasks, respecting their dependencies and running
65
32
  * independent tasks in parallel.
@@ -1,4 +1,6 @@
1
1
  import { TaskGraphValidator } from "./TaskGraphValidator.js";
2
+ import { EventBus } from "./EventBus.js";
3
+ import { WorkflowExecutor } from "./WorkflowExecutor.js";
2
4
  /**
3
5
  * The main class that orchestrates the execution of a list of tasks
4
6
  * based on their dependencies, with support for parallel execution.
@@ -6,8 +8,7 @@ import { TaskGraphValidator } from "./TaskGraphValidator.js";
6
8
  */
7
9
  export class TaskRunner {
8
10
  context;
9
- running = new Set();
10
- listeners = {};
11
+ eventBus = new EventBus();
11
12
  validator = new TaskGraphValidator();
12
13
  /**
13
14
  * @param context The shared context object to be passed to each task.
@@ -21,13 +22,7 @@ export class TaskRunner {
21
22
  * @param callback The callback to execute when the event is emitted.
22
23
  */
23
24
  on(event, callback) {
24
- if (!this.listeners[event]) {
25
- // Type assertion needed because TypeScript cannot verify that the generic K
26
- // matches the specific key in the mapped type during assignment.
27
- this.listeners[event] = new Set();
28
- }
29
- // Type assertion needed to tell TS that this specific Set matches the callback type
30
- this.listeners[event].add(callback);
25
+ this.eventBus.on(event, callback);
31
26
  }
32
27
  /**
33
28
  * Unsubscribe from an event.
@@ -35,28 +30,7 @@ export class TaskRunner {
35
30
  * @param callback The callback to remove.
36
31
  */
37
32
  off(event, callback) {
38
- if (this.listeners[event]) {
39
- this.listeners[event].delete(callback);
40
- }
41
- }
42
- /**
43
- * Emit an event to all subscribers.
44
- * @param event The event name.
45
- * @param data The payload for the event.
46
- */
47
- emit(event, data) {
48
- const listeners = this.listeners[event];
49
- if (listeners) {
50
- for (const listener of listeners) {
51
- try {
52
- listener(data);
53
- }
54
- catch (error) {
55
- // Prevent listener errors from bubbling up
56
- console.error(`Error in event listener for ${String(event)}:`, error);
57
- }
58
- }
59
- }
33
+ this.eventBus.off(event, callback);
60
34
  }
61
35
  /**
62
36
  * Executes a list of tasks, respecting their dependencies and running
@@ -108,70 +82,8 @@ export class TaskRunner {
108
82
  // Combine them to satisfy both legacy tests (checking for legacy message) and new requirements (clear details)
109
83
  throw new Error(`${legacyMessage} | ${detailedMessage}`);
110
84
  }
111
- this.emit("workflowStart", { context: this.context, steps });
112
- const results = new Map();
113
- const executingPromises = new Set();
114
- // Helper to process pending steps and launch ready ones
115
- const processPendingSteps = () => {
116
- const pendingSteps = steps.filter((step) => !results.has(step.name) && !this.running.has(step.name));
117
- // 1. Identify and mark skipped tasks
118
- for (const step of pendingSteps) {
119
- const deps = step.dependencies ?? [];
120
- const failedDep = deps.find((dep) => results.has(dep) && results.get(dep)?.status !== "success");
121
- if (failedDep) {
122
- const result = {
123
- status: "skipped",
124
- message: `Skipped due to failed dependency: ${failedDep}`,
125
- };
126
- results.set(step.name, result);
127
- this.emit("taskSkipped", { step, result });
128
- }
129
- }
130
- // Re-filter pending steps as some might have been skipped above
131
- const readySteps = steps.filter((step) => {
132
- if (results.has(step.name) || this.running.has(step.name))
133
- return false;
134
- const deps = step.dependencies ?? [];
135
- return deps.every((dep) => results.has(dep) && results.get(dep)?.status === "success");
136
- });
137
- // 2. Launch ready tasks
138
- for (const step of readySteps) {
139
- this.running.add(step.name);
140
- this.emit("taskStart", { step });
141
- const taskPromise = (async () => {
142
- try {
143
- const result = await step.run(this.context);
144
- results.set(step.name, result);
145
- }
146
- catch (e) {
147
- results.set(step.name, {
148
- status: "failure",
149
- error: e instanceof Error ? e.message : String(e),
150
- });
151
- }
152
- finally {
153
- this.running.delete(step.name);
154
- const result = results.get(step.name);
155
- this.emit("taskEnd", { step, result });
156
- }
157
- })();
158
- // Wrap the task promise to ensure we can track it in the Set
159
- const trackedPromise = taskPromise.then(() => {
160
- executingPromises.delete(trackedPromise);
161
- });
162
- executingPromises.add(trackedPromise);
163
- }
164
- };
165
- // Initial check to start independent tasks
166
- processPendingSteps();
167
- while (results.size < steps.length && executingPromises.size > 0) {
168
- // Wait for the next task to finish
169
- await Promise.race(executingPromises);
170
- // After a task finishes, check for new work
171
- processPendingSteps();
172
- }
173
- this.emit("workflowEnd", { context: this.context, results });
174
- return results;
85
+ const executor = new WorkflowExecutor(this.context, this.eventBus);
86
+ return executor.execute(steps);
175
87
  }
176
88
  }
177
89
  //# sourceMappingURL=TaskRunner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../src/TaskRunner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AA6C7D;;;;GAIG;AACH,MAAM,OAAO,UAAU;IAQD;IAPZ,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5B,SAAS,GAA0B,EAAE,CAAC;IACtC,SAAS,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAE7C;;OAEG;IACH,YAAoB,OAAiB;QAAjB,YAAO,GAAP,OAAO,CAAU;IAAG,CAAC;IAEzC;;;;OAIG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";
2
+ import { TaskResult } from "./TaskResult.js";
3
+ import { EventBus } from "./EventBus.js";
4
+ /**
5
+ * Handles the execution of the workflow steps.
6
+ * @template TContext The shape of the shared context object.
7
+ */
8
+ export declare class WorkflowExecutor<TContext> {
9
+ private context;
10
+ private eventBus;
11
+ private running;
12
+ /**
13
+ * @param context The shared context object.
14
+ * @param eventBus The event bus to emit events.
15
+ */
16
+ constructor(context: TContext, eventBus: EventBus<TContext>);
17
+ /**
18
+ * Executes the given steps.
19
+ * @param steps The list of steps to execute.
20
+ * @returns A Promise that resolves to a map of task results.
21
+ */
22
+ execute(steps: TaskStep<TContext>[]): Promise<Map<string, TaskResult>>;
23
+ }