@workglow/task-graph 0.0.52
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.
- package/LICENSE +201 -0
- package/README.md +1280 -0
- package/dist/browser.d.ts +7 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +2842 -0
- package/dist/browser.js.map +33 -0
- package/dist/bun.d.ts +7 -0
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +2843 -0
- package/dist/bun.js.map +33 -0
- package/dist/common.d.ts +33 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/node.d.ts +7 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +2842 -0
- package/dist/node.js.map +33 -0
- package/dist/storage/TaskGraphRepository.d.ts +92 -0
- package/dist/storage/TaskGraphRepository.d.ts.map +1 -0
- package/dist/storage/TaskGraphTabularRepository.d.ts +73 -0
- package/dist/storage/TaskGraphTabularRepository.d.ts.map +1 -0
- package/dist/storage/TaskOutputRepository.d.ts +93 -0
- package/dist/storage/TaskOutputRepository.d.ts.map +1 -0
- package/dist/storage/TaskOutputTabularRepository.d.ts +84 -0
- package/dist/storage/TaskOutputTabularRepository.d.ts.map +1 -0
- package/dist/task/ArrayTask.d.ts +72 -0
- package/dist/task/ArrayTask.d.ts.map +1 -0
- package/dist/task/ConditionalTask.d.ts +278 -0
- package/dist/task/ConditionalTask.d.ts.map +1 -0
- package/dist/task/GraphAsTask.d.ts +79 -0
- package/dist/task/GraphAsTask.d.ts.map +1 -0
- package/dist/task/GraphAsTaskRunner.d.ts +36 -0
- package/dist/task/GraphAsTaskRunner.d.ts.map +1 -0
- package/dist/task/ITask.d.ts +144 -0
- package/dist/task/ITask.d.ts.map +1 -0
- package/dist/task/ITaskRunner.d.ts +36 -0
- package/dist/task/ITaskRunner.d.ts.map +1 -0
- package/dist/task/JobQueueFactory.d.ts +23 -0
- package/dist/task/JobQueueFactory.d.ts.map +1 -0
- package/dist/task/JobQueueTask.d.ts +65 -0
- package/dist/task/JobQueueTask.d.ts.map +1 -0
- package/dist/task/Task.d.ts +334 -0
- package/dist/task/Task.d.ts.map +1 -0
- package/dist/task/TaskError.d.ts +66 -0
- package/dist/task/TaskError.d.ts.map +1 -0
- package/dist/task/TaskEvents.d.ts +40 -0
- package/dist/task/TaskEvents.d.ts.map +1 -0
- package/dist/task/TaskJSON.d.ts +82 -0
- package/dist/task/TaskJSON.d.ts.map +1 -0
- package/dist/task/TaskQueueRegistry.d.ts +69 -0
- package/dist/task/TaskQueueRegistry.d.ts.map +1 -0
- package/dist/task/TaskRegistry.d.ts +31 -0
- package/dist/task/TaskRegistry.d.ts.map +1 -0
- package/dist/task/TaskRunner.d.ts +99 -0
- package/dist/task/TaskRunner.d.ts.map +1 -0
- package/dist/task/TaskTypes.d.ts +68 -0
- package/dist/task/TaskTypes.d.ts.map +1 -0
- package/dist/task-graph/Conversions.d.ts +28 -0
- package/dist/task-graph/Conversions.d.ts.map +1 -0
- package/dist/task-graph/Dataflow.d.ts +73 -0
- package/dist/task-graph/Dataflow.d.ts.map +1 -0
- package/dist/task-graph/DataflowEvents.d.ts +34 -0
- package/dist/task-graph/DataflowEvents.d.ts.map +1 -0
- package/dist/task-graph/ITaskGraph.d.ts +38 -0
- package/dist/task-graph/ITaskGraph.d.ts.map +1 -0
- package/dist/task-graph/IWorkflow.d.ts +13 -0
- package/dist/task-graph/IWorkflow.d.ts.map +1 -0
- package/dist/task-graph/TaskGraph.d.ts +230 -0
- package/dist/task-graph/TaskGraph.d.ts.map +1 -0
- package/dist/task-graph/TaskGraphEvents.d.ts +54 -0
- package/dist/task-graph/TaskGraphEvents.d.ts.map +1 -0
- package/dist/task-graph/TaskGraphRunner.d.ts +202 -0
- package/dist/task-graph/TaskGraphRunner.d.ts.map +1 -0
- package/dist/task-graph/TaskGraphScheduler.d.ts +56 -0
- package/dist/task-graph/TaskGraphScheduler.d.ts.map +1 -0
- package/dist/task-graph/Workflow.d.ts +155 -0
- package/dist/task-graph/Workflow.d.ts.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +59 -0
- package/src/storage/README.md +61 -0
- package/src/task/ConditionalTask.README.md +268 -0
- package/src/task/README.md +251 -0
- package/src/task-graph/README.md +142 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { DataPortSchema } from "@workglow/util";
|
|
7
|
+
import type { IExecuteContext } from "./ITask";
|
|
8
|
+
import { Task } from "./Task";
|
|
9
|
+
import type { TaskConfig, TaskInput, TaskOutput, TaskTypeName } from "./TaskTypes";
|
|
10
|
+
/**
|
|
11
|
+
* A predicate function that evaluates whether a branch condition is met.
|
|
12
|
+
* Receives the task's input data and returns true if the branch should be active.
|
|
13
|
+
*
|
|
14
|
+
* @template Input - The input type for the conditional task
|
|
15
|
+
* @param input - The input data to evaluate
|
|
16
|
+
* @returns true if the branch condition is met, false otherwise
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Simple numeric comparison
|
|
21
|
+
* const isHighValue: ConditionFn<{ value: number }> = (input) => input.value > 100;
|
|
22
|
+
*
|
|
23
|
+
* // String equality check
|
|
24
|
+
* const isAdmin: ConditionFn<{ role: string }> = (input) => input.role === "admin";
|
|
25
|
+
*
|
|
26
|
+
* // Complex boolean logic
|
|
27
|
+
* const isEligible: ConditionFn<{ age: number; verified: boolean }> = (input) =>
|
|
28
|
+
* input.age >= 18 && input.verified;
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export type ConditionFn<Input> = (input: Input) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for a single branch in a ConditionalTask.
|
|
34
|
+
*
|
|
35
|
+
* Each branch represents a possible path through the conditional logic.
|
|
36
|
+
* When the condition evaluates to true, the branch becomes active and
|
|
37
|
+
* its output port will receive the task's input data.
|
|
38
|
+
*
|
|
39
|
+
* @template Input - The input type for the conditional task
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const highValueBranch: BranchConfig<{ amount: number }> = {
|
|
44
|
+
* id: "high",
|
|
45
|
+
* condition: (input) => input.amount > 1000,
|
|
46
|
+
* outputPort: "highValue"
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export interface BranchConfig<Input> {
|
|
51
|
+
/** Unique identifier for this branch within the task */
|
|
52
|
+
readonly id: string;
|
|
53
|
+
/** Predicate function that determines if this branch is active */
|
|
54
|
+
readonly condition: ConditionFn<Input>;
|
|
55
|
+
/** Name of the output port that will receive data when this branch is active */
|
|
56
|
+
readonly outputPort: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration interface for ConditionalTask.
|
|
60
|
+
*
|
|
61
|
+
* Extends the base TaskConfig with conditional-specific options including
|
|
62
|
+
* branch definitions, default branch handling, and execution mode.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const config: ConditionalTaskConfig = {
|
|
67
|
+
* id: "router",
|
|
68
|
+
* branches: [
|
|
69
|
+
* { id: "premium", condition: (i) => i.tier === "premium", outputPort: "premium" },
|
|
70
|
+
* { id: "standard", condition: (i) => i.tier === "standard", outputPort: "standard" },
|
|
71
|
+
* ],
|
|
72
|
+
* defaultBranch: "standard",
|
|
73
|
+
* exclusive: true, // Only first matching branch activates
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export interface ConditionalTaskConfig extends TaskConfig {
|
|
78
|
+
/**
|
|
79
|
+
* Array of branch configurations defining the conditional logic.
|
|
80
|
+
* Branches are evaluated in order. In exclusive mode, only the first
|
|
81
|
+
* matching branch activates. In non-exclusive mode, all matching
|
|
82
|
+
* branches activate.
|
|
83
|
+
*/
|
|
84
|
+
readonly branches: BranchConfig<any>[];
|
|
85
|
+
/**
|
|
86
|
+
* ID of the branch to activate if no conditions match.
|
|
87
|
+
* Must correspond to an existing branch ID. If not specified
|
|
88
|
+
* and no conditions match, no branches will be active.
|
|
89
|
+
*/
|
|
90
|
+
readonly defaultBranch?: string;
|
|
91
|
+
/**
|
|
92
|
+
* When true (default), only the first matching branch activates (switch/case behavior).
|
|
93
|
+
* When false, all matching branches activate (multi-path routing).
|
|
94
|
+
*
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
readonly exclusive?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A task that evaluates conditions to determine which downstream paths are active.
|
|
101
|
+
*
|
|
102
|
+
* ConditionalTask implements conditional branching within a task graph, similar to
|
|
103
|
+
* if/then/else or switch/case statements. It evaluates configured conditions against
|
|
104
|
+
* its input and selectively enables output ports for active branches while disabling
|
|
105
|
+
* dataflows to inactive branches.
|
|
106
|
+
*
|
|
107
|
+
* ## Key Features
|
|
108
|
+
*
|
|
109
|
+
* - **Condition-based routing**: Route data to different downstream tasks based on input values
|
|
110
|
+
* - **Exclusive mode**: Act as a switch/case where only the first matching branch activates
|
|
111
|
+
* - **Multi-path mode**: Enable multiple branches simultaneously when conditions match
|
|
112
|
+
* - **Default branch**: Specify a fallback branch when no conditions match
|
|
113
|
+
* - **Disabled propagation**: Inactive branches result in DISABLED status for downstream tasks
|
|
114
|
+
*
|
|
115
|
+
* ## Execution Modes
|
|
116
|
+
*
|
|
117
|
+
* ### Exclusive Mode (default)
|
|
118
|
+
* In exclusive mode (`exclusive: true`), the task behaves like a switch statement.
|
|
119
|
+
* Branches are evaluated in order, and only the first matching branch becomes active.
|
|
120
|
+
* This is useful for mutually exclusive paths.
|
|
121
|
+
*
|
|
122
|
+
* ### Multi-Path Mode
|
|
123
|
+
* In multi-path mode (`exclusive: false`), all branches whose conditions evaluate
|
|
124
|
+
* to true become active simultaneously. This enables fan-out patterns where the
|
|
125
|
+
* same input triggers multiple downstream processing paths.
|
|
126
|
+
*
|
|
127
|
+
* ## Output Behavior
|
|
128
|
+
*
|
|
129
|
+
* For each active branch, the task passes through its entire input to that branch's
|
|
130
|
+
* output port. Inactive branches receive no data, and their outgoing dataflows are
|
|
131
|
+
* set to DISABLED status, which cascades to downstream tasks that have no other
|
|
132
|
+
* active inputs.
|
|
133
|
+
*
|
|
134
|
+
* @template Input - The input type for the task
|
|
135
|
+
* @template Output - The output type for the task
|
|
136
|
+
* @template Config - The configuration type (must extend ConditionalTaskConfig)
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* // Simple if/else routing based on a numeric threshold
|
|
141
|
+
* const thresholdRouter = new ConditionalTask(
|
|
142
|
+
* {},
|
|
143
|
+
* {
|
|
144
|
+
* branches: [
|
|
145
|
+
* { id: "high", condition: (i) => i.value > 100, outputPort: "highPath" },
|
|
146
|
+
* { id: "low", condition: (i) => i.value <= 100, outputPort: "lowPath" },
|
|
147
|
+
* ],
|
|
148
|
+
* }
|
|
149
|
+
* );
|
|
150
|
+
*
|
|
151
|
+
* // Switch/case style routing based on string enum
|
|
152
|
+
* const statusRouter = new ConditionalTask(
|
|
153
|
+
* {},
|
|
154
|
+
* {
|
|
155
|
+
* branches: [
|
|
156
|
+
* { id: "active", condition: (i) => i.status === "active", outputPort: "active" },
|
|
157
|
+
* { id: "pending", condition: (i) => i.status === "pending", outputPort: "pending" },
|
|
158
|
+
* { id: "inactive", condition: (i) => i.status === "inactive", outputPort: "inactive" },
|
|
159
|
+
* ],
|
|
160
|
+
* defaultBranch: "inactive",
|
|
161
|
+
* exclusive: true,
|
|
162
|
+
* }
|
|
163
|
+
* );
|
|
164
|
+
*
|
|
165
|
+
* // Multi-path fan-out for parallel processing
|
|
166
|
+
* const fanOut = new ConditionalTask(
|
|
167
|
+
* {},
|
|
168
|
+
* {
|
|
169
|
+
* branches: [
|
|
170
|
+
* { id: "log", condition: () => true, outputPort: "logger" },
|
|
171
|
+
* { id: "process", condition: () => true, outputPort: "processor" },
|
|
172
|
+
* { id: "archive", condition: (i) => i.shouldArchive, outputPort: "archiver" },
|
|
173
|
+
* ],
|
|
174
|
+
* exclusive: false, // All matching branches activate
|
|
175
|
+
* }
|
|
176
|
+
* );
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare class ConditionalTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends ConditionalTaskConfig = ConditionalTaskConfig> extends Task<Input, Output, Config> {
|
|
180
|
+
/** Task type identifier for serialization and registry lookup */
|
|
181
|
+
static type: TaskTypeName;
|
|
182
|
+
/** Category for UI organization and filtering */
|
|
183
|
+
static category: string;
|
|
184
|
+
/** Human-readable title for display in UIs */
|
|
185
|
+
static title: string;
|
|
186
|
+
/** This task has dynamic schemas that change based on branch configuration */
|
|
187
|
+
static hasDynamicSchemas: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Set of branch IDs that are currently active after execution.
|
|
190
|
+
* Populated during execute() and used by the graph runner to
|
|
191
|
+
* determine which dataflows should be enabled vs disabled.
|
|
192
|
+
*/
|
|
193
|
+
activeBranches: Set<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Evaluates branch conditions and determines which branches are active.
|
|
196
|
+
* Only active branches will have their output ports populated.
|
|
197
|
+
*
|
|
198
|
+
* @param input - The input data to evaluate conditions against
|
|
199
|
+
* @param context - Execution context with signal and progress callback
|
|
200
|
+
* @returns Output with active branch data and metadata
|
|
201
|
+
*/
|
|
202
|
+
execute(input: Input, context: IExecuteContext): Promise<Output | undefined>;
|
|
203
|
+
/**
|
|
204
|
+
* Builds the output object with data routed to active branch ports.
|
|
205
|
+
* Each active branch's output port receives the full input data.
|
|
206
|
+
*
|
|
207
|
+
* @param input - The input data to pass through to active branches
|
|
208
|
+
* @returns Output object with active branch ports populated
|
|
209
|
+
*/
|
|
210
|
+
protected buildOutput(input: Input): Output;
|
|
211
|
+
/**
|
|
212
|
+
* Checks if a specific branch is currently active.
|
|
213
|
+
*
|
|
214
|
+
* @param branchId - The ID of the branch to check
|
|
215
|
+
* @returns true if the branch is active, false otherwise
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* await conditionalTask.run({ value: 150 });
|
|
220
|
+
* if (conditionalTask.isBranchActive("high")) {
|
|
221
|
+
* console.log("High value path was taken");
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
isBranchActive(branchId: string): boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Gets the set of currently active branch IDs.
|
|
228
|
+
* Returns a new Set to prevent external modification.
|
|
229
|
+
*
|
|
230
|
+
* @returns Set of active branch IDs
|
|
231
|
+
*/
|
|
232
|
+
getActiveBranches(): Set<string>;
|
|
233
|
+
/**
|
|
234
|
+
* Gets a map of output port names to their active status.
|
|
235
|
+
* Useful for inspecting which output ports will have data.
|
|
236
|
+
*
|
|
237
|
+
* @returns Map of output port name to boolean active status
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const portStatus = conditionalTask.getPortActiveStatus();
|
|
242
|
+
* for (const [port, isActive] of portStatus) {
|
|
243
|
+
* console.log(`Port ${port}: ${isActive ? "active" : "inactive"}`);
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
getPortActiveStatus(): Map<string, boolean>;
|
|
248
|
+
/**
|
|
249
|
+
* Generates the output schema dynamically based on configured branches.
|
|
250
|
+
* Each branch's output port is defined as an object type that will
|
|
251
|
+
* receive the pass-through input data when active.
|
|
252
|
+
*
|
|
253
|
+
* @returns JSON Schema for the task's output
|
|
254
|
+
*/
|
|
255
|
+
static outputSchema(): DataPortSchema;
|
|
256
|
+
/**
|
|
257
|
+
* Instance method to get output schema with branch-specific ports.
|
|
258
|
+
* Dynamically generates properties based on the configured branches.
|
|
259
|
+
*
|
|
260
|
+
* @returns JSON Schema for the task's output including branch ports
|
|
261
|
+
*/
|
|
262
|
+
outputSchema(): DataPortSchema;
|
|
263
|
+
/**
|
|
264
|
+
* Returns schema indicating the task accepts any input.
|
|
265
|
+
* ConditionalTask passes through its input to active branches,
|
|
266
|
+
* so it doesn't constrain the input type.
|
|
267
|
+
*
|
|
268
|
+
* @returns Schema that accepts any input
|
|
269
|
+
*/
|
|
270
|
+
static inputSchema(): DataPortSchema;
|
|
271
|
+
/**
|
|
272
|
+
* Instance method returning schema that accepts any input.
|
|
273
|
+
*
|
|
274
|
+
* @returns Schema that accepts any input
|
|
275
|
+
*/
|
|
276
|
+
inputSchema(): DataPortSchema;
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=ConditionalTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionalTask.d.ts","sourceRoot":"","sources":["../../src/task/ConditionalTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMnF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,WAAW,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,YAAY,CAAC,KAAK;IACjC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,kEAAkE;IAClE,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;IAEvC,gFAAgF;IAChF,QAAQ,CAA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AC,MAAM,CAAC;IAIvC;;;;;;;;;;;;;OAaG;IACI,mBAAmB,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAelD;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,IAAI,cAAc;IAerC;;;;;OAKG;IACH,YAAY,IAAI,cAAc;IA0B9B;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,IAAI,cAAc;IAQpC;;;;OAIG;IACH,WAAW,IAAI,cAAc;CAO9B"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { DataPortSchema } from "@workglow/util";
|
|
7
|
+
import { SchemaNode } from "@workglow/util";
|
|
8
|
+
import { TaskGraph } from "../task-graph/TaskGraph";
|
|
9
|
+
import { CompoundMergeStrategy } from "../task-graph/TaskGraphRunner";
|
|
10
|
+
import { GraphAsTaskRunner } from "./GraphAsTaskRunner";
|
|
11
|
+
import { Task } from "./Task";
|
|
12
|
+
import type { JsonTaskItem, TaskGraphItemJson } from "./TaskJSON";
|
|
13
|
+
import { type TaskConfig, type TaskInput, type TaskOutput, type TaskTypeName } from "./TaskTypes";
|
|
14
|
+
export interface GraphAsTaskConfig extends TaskConfig {
|
|
15
|
+
subGraph?: TaskGraph;
|
|
16
|
+
compoundMerge?: CompoundMergeStrategy;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A task that contains a subgraph of tasks
|
|
20
|
+
*/
|
|
21
|
+
export declare class GraphAsTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends GraphAsTaskConfig = GraphAsTaskConfig> extends Task<Input, Output, Config> {
|
|
22
|
+
static type: TaskTypeName;
|
|
23
|
+
static category: string;
|
|
24
|
+
static compoundMerge: CompoundMergeStrategy;
|
|
25
|
+
/** This task has dynamic schemas that change based on the subgraph structure */
|
|
26
|
+
static hasDynamicSchemas: boolean;
|
|
27
|
+
constructor(input?: Partial<Input>, config?: Partial<Config>);
|
|
28
|
+
_runner: GraphAsTaskRunner<Input, Output, Config>;
|
|
29
|
+
/**
|
|
30
|
+
* Task runner for handling the task execution
|
|
31
|
+
*/
|
|
32
|
+
get runner(): GraphAsTaskRunner<Input, Output, Config>;
|
|
33
|
+
get compoundMerge(): CompoundMergeStrategy;
|
|
34
|
+
get cacheable(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Override inputSchema to compute it dynamically from the subgraph at runtime
|
|
37
|
+
* The input schema is the union of all unconnected inputs from starting nodes
|
|
38
|
+
* (nodes with zero incoming connections)
|
|
39
|
+
*/
|
|
40
|
+
inputSchema(): DataPortSchema;
|
|
41
|
+
protected _inputSchemaNode: SchemaNode | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the compiled input schema
|
|
44
|
+
*/
|
|
45
|
+
protected getInputSchemaNode(type: TaskTypeName): SchemaNode;
|
|
46
|
+
/**
|
|
47
|
+
* Calculates the depth (longest path from any starting node) for each task in the graph
|
|
48
|
+
* @returns A map of task IDs to their depths
|
|
49
|
+
*/
|
|
50
|
+
private calculateNodeDepths;
|
|
51
|
+
/**
|
|
52
|
+
* Override outputSchema to compute it dynamically from the subgraph at runtime
|
|
53
|
+
* The output schema depends on the compoundMerge strategy and the nodes at the last level
|
|
54
|
+
*/
|
|
55
|
+
outputSchema(): DataPortSchema;
|
|
56
|
+
/**
|
|
57
|
+
* Resets input data to defaults
|
|
58
|
+
*/
|
|
59
|
+
resetInputData(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Regenerates the subtask graph and emits a "regenerate" event
|
|
62
|
+
*
|
|
63
|
+
* Subclasses should override this method to implement the actual graph
|
|
64
|
+
* regeneration logic, but all they need to do is call this method to
|
|
65
|
+
* emit the "regenerate" event.
|
|
66
|
+
*/
|
|
67
|
+
regenerateGraph(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Serializes the task and its subtasks into a format that can be stored
|
|
70
|
+
* @returns The serialized task and subtasks
|
|
71
|
+
*/
|
|
72
|
+
toJSON(): TaskGraphItemJson;
|
|
73
|
+
/**
|
|
74
|
+
* Converts the task to a JSON format suitable for dependency tracking
|
|
75
|
+
* @returns The task and subtasks in JSON thats easier for humans to read
|
|
76
|
+
*/
|
|
77
|
+
toDependencyJSON(): JsonTaskItem;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=GraphAsTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphAsTask.d.ts","sourceRoot":"","sources":["../../src/task/GraphAsTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAiB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAkB,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACvC;AAED;;GAEG;AACH,qBAAa,WAAW,CACtB,KAAK,SAAS,SAAS,GAAG,SAAS,EACnC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,MAAM,SAAS,iBAAiB,GAAG,iBAAiB,CACpD,SAAQ,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IAKnC,OAAc,IAAI,EAAE,YAAY,CAAiB;IACjD,OAAc,QAAQ,EAAE,MAAM,CAAY;IAC1C,OAAc,aAAa,EAAE,qBAAqB,CAAkB;IAEpE,gFAAgF;IAChF,OAAc,iBAAiB,EAAE,OAAO,CAAQ;gBAMpC,KAAK,GAAE,OAAO,CAAC,KAAK,CAAM,EAAE,MAAM,GAAE,OAAO,CAAC,MAAM,CAAM;IAa5D,OAAO,EAAE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1D;;OAEG;IACH,IAAa,MAAM,IAAI,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAK9D;IAMD,IAAW,aAAa,IAAI,qBAAqB,CAEhD;IAED,IAAW,SAAS,IAAI,OAAO,CAM9B;IAMD;;;;OAIG;IACI,WAAW,IAAI,cAAc;IAsDpC,SAAS,CAAC,gBAAgB,EAAE,UAAU,GAAG,SAAS,CAAC;IACnD;;OAEG;cACgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU;IAoBrE;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IA0B3B;;;OAGG;IACa,YAAY,IAAI,cAAc;IA2E9C;;OAEG;IACI,cAAc,IAAI,IAAI;IAgB7B;;;;;;OAMG;IACI,eAAe,IAAI,IAAI;IAS9B;;;OAGG;IACI,MAAM,IAAI,iBAAiB;IAalC;;;OAGG;IACI,gBAAgB,IAAI,YAAY;CAUxC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { GraphResultArray } from "../task-graph/TaskGraphRunner";
|
|
7
|
+
import { GraphAsTask } from "./GraphAsTask";
|
|
8
|
+
import { TaskRunner } from "./TaskRunner";
|
|
9
|
+
import { TaskConfig, TaskInput, TaskOutput } from "./TaskTypes";
|
|
10
|
+
export declare class GraphAsTaskRunner<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends TaskConfig = TaskConfig> extends TaskRunner<Input, Output, Config> {
|
|
11
|
+
task: GraphAsTask<Input, Output, Config>;
|
|
12
|
+
/**
|
|
13
|
+
* Protected method to execute a task subgraph by delegating back to the task itself.
|
|
14
|
+
*/
|
|
15
|
+
protected executeTaskChildren(input: Input): Promise<GraphResultArray<Output>>;
|
|
16
|
+
/**
|
|
17
|
+
* Protected method for reactive execution delegation
|
|
18
|
+
*
|
|
19
|
+
* Note: Reactive execution doesn't accept input parameters by design.
|
|
20
|
+
* It works with the graph's internal state and dataflow connections.
|
|
21
|
+
* Tasks in the subgraph will use their existing runInputData (from defaults
|
|
22
|
+
* or previous execution) combined with dataflow connections.
|
|
23
|
+
*/
|
|
24
|
+
protected executeTaskChildrenReactive(): Promise<GraphResultArray<Output>>;
|
|
25
|
+
protected handleDisable(): Promise<void>;
|
|
26
|
+
private fixInput;
|
|
27
|
+
/**
|
|
28
|
+
* Execute the task
|
|
29
|
+
*/
|
|
30
|
+
protected executeTask(input: Input): Promise<Output | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Execute the task reactively
|
|
33
|
+
*/
|
|
34
|
+
executeTaskReactive(input: Input, output: Output): Promise<Output>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=GraphAsTaskRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphAsTaskRunner.d.ts","sourceRoot":"","sources":["../../src/task/GraphAsTaskRunner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhE,qBAAa,iBAAiB,CAC5B,KAAK,SAAS,SAAS,GAAG,SAAS,EACnC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,MAAM,SAAS,UAAU,GAAG,UAAU,CACtC,SAAQ,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IACjC,IAAI,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjD;;OAEG;cACa,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAepF;;;;;;;OAOG;cACa,2BAA2B,IAAI,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;cAIhE,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAW9C,OAAO,CAAC,QAAQ;IAehB;;OAEG;cACa,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IActE;;OAEG;IACU,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAahF"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { DataPortSchema, EventEmitter } from "@workglow/util";
|
|
7
|
+
import { TaskOutputRepository } from "../storage/TaskOutputRepository";
|
|
8
|
+
import { ITaskGraph } from "../task-graph/ITaskGraph";
|
|
9
|
+
import { IWorkflow } from "../task-graph/IWorkflow";
|
|
10
|
+
import type { TaskGraph } from "../task-graph/TaskGraph";
|
|
11
|
+
import { CompoundMergeStrategy } from "../task-graph/TaskGraphRunner";
|
|
12
|
+
import { TaskError } from "./TaskError";
|
|
13
|
+
import type { TaskEventListener, TaskEventListeners, TaskEventParameters, TaskEvents } from "./TaskEvents";
|
|
14
|
+
import type { JsonTaskItem, TaskGraphItemJson } from "./TaskJSON";
|
|
15
|
+
import { TaskRunner } from "./TaskRunner";
|
|
16
|
+
import type { Provenance, TaskConfig, TaskInput, TaskOutput, TaskStatus } from "./TaskTypes";
|
|
17
|
+
/**
|
|
18
|
+
* Context for task execution
|
|
19
|
+
*/
|
|
20
|
+
export interface IExecuteContext {
|
|
21
|
+
signal: AbortSignal;
|
|
22
|
+
nodeProvenance: Provenance;
|
|
23
|
+
updateProgress: (progress: number, message?: string, ...args: any[]) => Promise<void>;
|
|
24
|
+
own: <T extends ITask | ITaskGraph | IWorkflow>(i: T) => T;
|
|
25
|
+
}
|
|
26
|
+
export type IExecuteReactiveContext = Pick<IExecuteContext, "own">;
|
|
27
|
+
/**
|
|
28
|
+
* Configuration for running a task
|
|
29
|
+
*/
|
|
30
|
+
export interface IRunConfig {
|
|
31
|
+
nodeProvenance?: Provenance;
|
|
32
|
+
outputCache?: TaskOutputRepository | boolean;
|
|
33
|
+
updateProgress?: (task: ITask, progress: number, message?: string, ...args: any[]) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Interface for task static property metadata
|
|
37
|
+
*
|
|
38
|
+
* ==== These should be overriden by every new Task class ====
|
|
39
|
+
*/
|
|
40
|
+
export interface ITaskStaticProperties {
|
|
41
|
+
readonly type: string;
|
|
42
|
+
readonly category?: string;
|
|
43
|
+
readonly title?: string;
|
|
44
|
+
readonly description?: string;
|
|
45
|
+
readonly cacheable: boolean;
|
|
46
|
+
readonly hasDynamicSchemas: boolean;
|
|
47
|
+
readonly inputSchema: () => DataPortSchema;
|
|
48
|
+
readonly outputSchema: () => DataPortSchema;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Interface for task execution logic
|
|
52
|
+
* These methods define how tasks are executed and should be implemented by Task subclasses
|
|
53
|
+
*/
|
|
54
|
+
export interface ITaskExecution<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput> {
|
|
55
|
+
execute(input: Input, context: IExecuteContext): Promise<Output | undefined>;
|
|
56
|
+
executeReactive(input: Input, output: Output, context: IExecuteReactiveContext): Promise<Output | undefined>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Interface for task lifecycle management
|
|
60
|
+
* These methods define how tasks are run and are usually delegated to a TaskRunner
|
|
61
|
+
*/
|
|
62
|
+
export interface ITaskLifecycle<Input extends TaskInput, Output extends TaskOutput, Config extends TaskConfig> {
|
|
63
|
+
run(overrides?: Partial<Input>): Promise<Output>;
|
|
64
|
+
runReactive(overrides?: Partial<Input>): Promise<Output>;
|
|
65
|
+
get runner(): TaskRunner<Input, Output, Config>;
|
|
66
|
+
abort(): void;
|
|
67
|
+
disable(): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Interface for task input/output operations
|
|
71
|
+
*/
|
|
72
|
+
export interface ITaskIO<Input extends TaskInput> {
|
|
73
|
+
defaults: Record<string, any>;
|
|
74
|
+
runInputData: Record<string, any>;
|
|
75
|
+
runOutputData: Record<string, any>;
|
|
76
|
+
inputSchema(): DataPortSchema;
|
|
77
|
+
outputSchema(): DataPortSchema;
|
|
78
|
+
get type(): string;
|
|
79
|
+
get category(): string;
|
|
80
|
+
get title(): string;
|
|
81
|
+
setDefaults(defaults: Record<string, any>): void;
|
|
82
|
+
resetInputData(): void;
|
|
83
|
+
setInput(input: Record<string, any>): void;
|
|
84
|
+
addInput(overrides: Record<string, any> | undefined): boolean;
|
|
85
|
+
validateInput(input: Record<string, any>): Promise<boolean>;
|
|
86
|
+
get cacheable(): boolean;
|
|
87
|
+
narrowInput(input: Record<string, any>): Promise<Record<string, any>>;
|
|
88
|
+
}
|
|
89
|
+
export interface ITaskInternalGraph {
|
|
90
|
+
subGraph: TaskGraph;
|
|
91
|
+
hasChildren(): boolean;
|
|
92
|
+
regenerateGraph(): void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Interface for task event handling
|
|
96
|
+
*/
|
|
97
|
+
export interface ITaskEvents {
|
|
98
|
+
get events(): EventEmitter<TaskEventListeners>;
|
|
99
|
+
on<Event extends TaskEvents>(name: Event, fn: TaskEventListener<Event>): void;
|
|
100
|
+
off<Event extends TaskEvents>(name: Event, fn: TaskEventListener<Event>): void;
|
|
101
|
+
once<Event extends TaskEvents>(name: Event, fn: TaskEventListener<Event>): void;
|
|
102
|
+
waitOn<Event extends TaskEvents>(name: Event): Promise<TaskEventParameters<Event>>;
|
|
103
|
+
emit<Event extends TaskEvents>(name: Event, ...args: TaskEventParameters<Event>): void;
|
|
104
|
+
subscribe<Event extends TaskEvents>(name: Event, fn: TaskEventListener<Event>): () => void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Interface for task serialization
|
|
108
|
+
*/
|
|
109
|
+
export interface ITaskSerialization {
|
|
110
|
+
getProvenance(): Provenance;
|
|
111
|
+
toJSON(): JsonTaskItem | TaskGraphItemJson;
|
|
112
|
+
toDependencyJSON(): JsonTaskItem;
|
|
113
|
+
id(): unknown;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Interface for task configuration and state
|
|
117
|
+
*/
|
|
118
|
+
export interface ITaskState<Config extends TaskConfig = TaskConfig> {
|
|
119
|
+
readonly config: Config;
|
|
120
|
+
status: TaskStatus;
|
|
121
|
+
progress: number;
|
|
122
|
+
createdAt: Date;
|
|
123
|
+
startedAt?: Date;
|
|
124
|
+
completedAt?: Date;
|
|
125
|
+
error?: TaskError;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Main task interface that combines all the specialized interfaces
|
|
129
|
+
*/
|
|
130
|
+
export interface ITask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends TaskConfig = TaskConfig> extends ITaskState<Config>, ITaskIO<Input>, ITaskEvents, ITaskLifecycle<Input, Output, Config>, ITaskExecution<Input, Output>, ITaskSerialization, ITaskInternalGraph {
|
|
131
|
+
}
|
|
132
|
+
export interface IGraphAsTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends TaskConfig = TaskConfig> extends ITask<Input, Output, Config> {
|
|
133
|
+
get compoundMerge(): CompoundMergeStrategy;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Type for task constructor
|
|
137
|
+
*/
|
|
138
|
+
type ITaskConstructorType<Input extends TaskInput, Output extends TaskOutput, Config extends TaskConfig> = new (input: Input, config: Config) => ITask<Input, Output, Config>;
|
|
139
|
+
/**
|
|
140
|
+
* Interface for task constructor with static properties
|
|
141
|
+
*/
|
|
142
|
+
export type ITaskConstructor<Input extends TaskInput, Output extends TaskOutput, Config extends TaskConfig> = ITaskConstructorType<Input, Output, Config> & ITaskStaticProperties;
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=ITask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITask.d.ts","sourceRoot":"","sources":["../../src/task/ITask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,iBAA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CAAC,KAAK,EAAE,MAAM,CAAC,EAC7B,kBAAkB,EAClB,kBAAkB;CAAG;AAEzB,MAAM,WAAW,YAAY,CAC3B,KAAK,SAAS,SAAS,GAAG,SAAS,EACnC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,MAAM,SAAS,UAAU,GAAG,UAAU,CACtC,SAAQ,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IACpC,IAAI,aAAa,IAAI,qBAAqB,CAAC;CAC5C;AAED;;GAEG;AACH,KAAK,oBAAoB,CACvB,KAAK,SAAS,SAAS,EACvB,MAAM,SAAS,UAAU,EACzB,MAAM,SAAS,UAAU,IACvB,KAAK,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAC1B,KAAK,SAAS,SAAS,EACvB,MAAM,SAAS,UAAU,EACzB,MAAM,SAAS,UAAU,IACvB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { ITask } from "./ITask";
|
|
7
|
+
import type { TaskConfig, TaskInput, TaskOutput } from "./TaskTypes";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for TaskRunner
|
|
10
|
+
* Responsible for running tasks and managing their execution lifecycle
|
|
11
|
+
*/
|
|
12
|
+
export interface ITaskRunner<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends TaskConfig = TaskConfig> {
|
|
13
|
+
/**
|
|
14
|
+
* The task being run
|
|
15
|
+
*/
|
|
16
|
+
readonly task: ITask<Input, Output, Config>;
|
|
17
|
+
/**
|
|
18
|
+
* Runs the task with the provided input overrides
|
|
19
|
+
* @param overrides Optional input overrides
|
|
20
|
+
*/
|
|
21
|
+
run(overrides?: Partial<Input>): Promise<Output>;
|
|
22
|
+
/**
|
|
23
|
+
* Runs the task in reactive mode
|
|
24
|
+
* @param overrides Optional input overrides
|
|
25
|
+
*/
|
|
26
|
+
runReactive(overrides?: Partial<Input>): Promise<Output>;
|
|
27
|
+
/**
|
|
28
|
+
* Aborts the task execution
|
|
29
|
+
*/
|
|
30
|
+
abort(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Disables the task execution
|
|
33
|
+
*/
|
|
34
|
+
disable(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=ITaskRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITaskRunner.d.ts","sourceRoot":"","sources":["../../src/task/ITaskRunner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErE;;;GAGG;AAEH,MAAM,WAAW,WAAW,CAC1B,KAAK,SAAS,SAAS,GAAG,SAAS,EACnC,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,MAAM,SAAS,UAAU,GAAG,UAAU;IAEtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAE5C;;;OAGG;IACH,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD;;;OAGG;IACH,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzD;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Job, JobConstructorParam, JobQueue, JobQueueOptions } from "@workglow/job-queue";
|
|
7
|
+
import type { JobQueueTask, JobQueueTaskConfig } from "./JobQueueTask";
|
|
8
|
+
import type { TaskInput, TaskOutput } from "./TaskTypes";
|
|
9
|
+
export type JobClassConstructor<Input extends TaskInput, Output extends TaskOutput> = new (params: JobConstructorParam<Input, Output>) => Job<Input, Output>;
|
|
10
|
+
export interface JobQueueFactoryParams<Input extends TaskInput, Output extends TaskOutput> {
|
|
11
|
+
queueName: string;
|
|
12
|
+
jobClass: JobClassConstructor<Input, Output>;
|
|
13
|
+
input?: Input;
|
|
14
|
+
config?: JobQueueTaskConfig;
|
|
15
|
+
task?: JobQueueTask<Input, Output>;
|
|
16
|
+
options?: JobQueueOptions<Input, Output>;
|
|
17
|
+
}
|
|
18
|
+
export type JobQueueFactory = <Input extends TaskInput, Output extends TaskOutput>(params: JobQueueFactoryParams<Input, Output>) => Promise<JobQueue<Input, Output>> | JobQueue<Input, Output>;
|
|
19
|
+
export declare const JOB_QUEUE_FACTORY: import("@workglow/util").ServiceToken<JobQueueFactory>;
|
|
20
|
+
export declare function registerJobQueueFactory(factory: JobQueueFactory): void;
|
|
21
|
+
export declare function createJobQueueFactoryFromClass(QueueCtor: new (queueName: string, jobCls: JobClassConstructor<any, any>, options: JobQueueOptions<any, any>) => JobQueue<any, any>, defaultOptions?: Partial<JobQueueOptions<any, any>>): JobQueueFactory;
|
|
22
|
+
export declare function getJobQueueFactory(): JobQueueFactory;
|
|
23
|
+
//# sourceMappingURL=JobQueueFactory.d.ts.map
|
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