@cadenza.io/core 3.10.0 → 3.12.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.
- package/dist/index.d.mts +1354 -184
- package/dist/index.d.ts +1354 -184
- package/dist/index.js +1348 -206
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1348 -206
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,13 @@ interface ThrottleHandle {
|
|
|
6
6
|
clear(): void;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Represents a context object used within a graph system.
|
|
11
|
+
* Contexts are essentially a container for data that is relevant to a specific task or routine.
|
|
12
|
+
* They are passed down the graph and can be used to store and manipulate data during the execution process.
|
|
13
|
+
* The context is divided into full context, user data, and metadata.
|
|
14
|
+
* Provides methods for accessing, cloning, mutating, combining, and exporting the context data.
|
|
15
|
+
*/
|
|
9
16
|
declare class GraphContext {
|
|
10
17
|
readonly id: string;
|
|
11
18
|
readonly fullContext: AnyObject;
|
|
@@ -17,12 +24,22 @@ declare class GraphContext {
|
|
|
17
24
|
* @returns Frozen user context.
|
|
18
25
|
*/
|
|
19
26
|
getContext(): AnyObject;
|
|
27
|
+
/**
|
|
28
|
+
* Clones the current user context data and returns a deep-cloned copy of it.
|
|
29
|
+
*
|
|
30
|
+
* @return {AnyObject} A deep-cloned copy of the user context data.
|
|
31
|
+
*/
|
|
20
32
|
getClonedContext(): AnyObject;
|
|
21
33
|
/**
|
|
22
34
|
* Gets full raw context (cloned for safety).
|
|
23
35
|
* @returns Cloned full context.
|
|
24
36
|
*/
|
|
25
37
|
getFullContext(): AnyObject;
|
|
38
|
+
/**
|
|
39
|
+
* Creates and returns a deep-cloned version of the fullContext object.
|
|
40
|
+
*
|
|
41
|
+
* @return {AnyObject} A deep copy of the fullContext instance, preserving all nested structures and data.
|
|
42
|
+
*/
|
|
26
43
|
getClonedFullContext(): AnyObject;
|
|
27
44
|
/**
|
|
28
45
|
* Gets frozen metadata (read-only).
|
|
@@ -41,10 +58,11 @@ declare class GraphContext {
|
|
|
41
58
|
*/
|
|
42
59
|
mutate(context: AnyObject): GraphContext;
|
|
43
60
|
/**
|
|
44
|
-
* Combines with another
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
61
|
+
* Combines the current GraphContext with another GraphContext, merging their user data
|
|
62
|
+
* and full context into a new GraphContext instance.
|
|
63
|
+
*
|
|
64
|
+
* @param {GraphContext} otherContext - The other GraphContext to combine with the current one.
|
|
65
|
+
* @return {GraphContext} A new GraphContext instance containing merged data from both contexts.
|
|
48
66
|
*/
|
|
49
67
|
combine(otherContext: GraphContext): GraphContext;
|
|
50
68
|
/**
|
|
@@ -57,6 +75,10 @@ declare class GraphContext {
|
|
|
57
75
|
};
|
|
58
76
|
}
|
|
59
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Abstract class representing an iterator for traversing a collection of elements.
|
|
80
|
+
* Subclasses must implement core methods to allow iteration and may optionally implement additional methods for extended functionality.
|
|
81
|
+
*/
|
|
60
82
|
declare abstract class Iterator {
|
|
61
83
|
abstract hasNext(): boolean;
|
|
62
84
|
abstract hasPrevious?(): boolean;
|
|
@@ -66,6 +88,11 @@ declare abstract class Iterator {
|
|
|
66
88
|
abstract getLast?(): any;
|
|
67
89
|
}
|
|
68
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Represents an abstract base class for a graph node or task.
|
|
93
|
+
* This class provides the foundation for graph-related operations such as traversal,
|
|
94
|
+
* exportation, logging, and execution. It must be extended by concrete implementations.
|
|
95
|
+
*/
|
|
69
96
|
declare abstract class Graph {
|
|
70
97
|
/**
|
|
71
98
|
* Executes this graph node/task.
|
|
@@ -100,6 +127,10 @@ declare abstract class Graph {
|
|
|
100
127
|
abstract getIterator(): Iterator;
|
|
101
128
|
}
|
|
102
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Represents an iterator for traversing nodes in a graph structure.
|
|
132
|
+
* Implements the Iterator interface and allows traversal of nodes layer by layer.
|
|
133
|
+
*/
|
|
103
134
|
declare class GraphNodeIterator implements Iterator {
|
|
104
135
|
currentNode: GraphNode | undefined;
|
|
105
136
|
currentLayer: GraphNode[];
|
|
@@ -110,6 +141,10 @@ declare class GraphNodeIterator implements Iterator {
|
|
|
110
141
|
next(): any;
|
|
111
142
|
}
|
|
112
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Abstract class representing a signal emitter.
|
|
146
|
+
* Allows emitting events or signals, with the option to suppress emissions if desired.
|
|
147
|
+
*/
|
|
113
148
|
declare abstract class SignalEmitter {
|
|
114
149
|
silent: boolean;
|
|
115
150
|
/**
|
|
@@ -131,6 +166,11 @@ declare abstract class SignalEmitter {
|
|
|
131
166
|
emitMetrics(signal: string, data?: AnyObject): void;
|
|
132
167
|
}
|
|
133
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Represents an abstract chain of execution, where each instance can be
|
|
171
|
+
* connected to a succeeding or preceding instance to form a chain of steps.
|
|
172
|
+
* Provides methods to manage the links between instances in the chain.
|
|
173
|
+
*/
|
|
134
174
|
declare abstract class ExecutionChain {
|
|
135
175
|
next: ExecutionChain | undefined;
|
|
136
176
|
previous: ExecutionChain | undefined;
|
|
@@ -142,6 +182,13 @@ declare abstract class ExecutionChain {
|
|
|
142
182
|
decouple(): void;
|
|
143
183
|
}
|
|
144
184
|
|
|
185
|
+
/**
|
|
186
|
+
* The `GraphLayerIterator` class provides an iterator for traversing through
|
|
187
|
+
* layers of a `GraphLayer` data structure. It allows sequential and bi-directional
|
|
188
|
+
* iteration, as well as access to the first and last layers in the graph.
|
|
189
|
+
*
|
|
190
|
+
* @implements {Iterator}
|
|
191
|
+
*/
|
|
145
192
|
declare class GraphLayerIterator implements Iterator {
|
|
146
193
|
graph: GraphLayer;
|
|
147
194
|
currentLayer: GraphLayer | undefined;
|
|
@@ -154,6 +201,16 @@ declare class GraphLayerIterator implements Iterator {
|
|
|
154
201
|
getLast(): GraphLayer;
|
|
155
202
|
}
|
|
156
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Represents an abstract layer in a graph, handling nodes and their execution.
|
|
206
|
+
* A `GraphLayer` can manage execution states, debug states, and relationships with other layers in the graph.
|
|
207
|
+
* This class is designed to be extended and requires the implementation of the `execute` method.
|
|
208
|
+
*
|
|
209
|
+
* @abstract
|
|
210
|
+
* @class GraphLayer
|
|
211
|
+
* @extends ExecutionChain
|
|
212
|
+
* @implements Graph
|
|
213
|
+
*/
|
|
157
214
|
declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
158
215
|
readonly index: number;
|
|
159
216
|
nodes: GraphNode[];
|
|
@@ -161,20 +218,104 @@ declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
|
161
218
|
executionStart: number;
|
|
162
219
|
debug: boolean;
|
|
163
220
|
constructor(index: number);
|
|
221
|
+
/**
|
|
222
|
+
* Sets the debug mode for the current instance and all associated nodes.
|
|
223
|
+
*
|
|
224
|
+
* @param {boolean} value - A boolean value to enable (true) or disable (false) debug mode.
|
|
225
|
+
* @return {void} No return value.
|
|
226
|
+
*/
|
|
164
227
|
setDebug(value: boolean): void;
|
|
228
|
+
/**
|
|
229
|
+
* Abstract method to execute a specific operation given a context.
|
|
230
|
+
*
|
|
231
|
+
* @param {GraphContext} [context] - Optional parameter representing the execution context, which contains relevant data for performing the operation.
|
|
232
|
+
* @return {unknown} - Returns the result of the operation, its type may vary depending on the implementation.
|
|
233
|
+
*/
|
|
165
234
|
abstract execute(context?: GraphContext): unknown;
|
|
235
|
+
/**
|
|
236
|
+
* Checks if the current layer has a preceding layer.
|
|
237
|
+
*
|
|
238
|
+
* @return {boolean} True if the current layer has a preceding layer that is an instance of GraphLayer; otherwise, false.
|
|
239
|
+
*/
|
|
166
240
|
get hasPreceding(): boolean;
|
|
167
241
|
getNumberOfNodes(): number;
|
|
242
|
+
/**
|
|
243
|
+
* Retrieves a list of nodes that match the given routine execution ID.
|
|
244
|
+
*
|
|
245
|
+
* @param {string} routineExecId - The ID of the routine execution to filter nodes by.
|
|
246
|
+
* @return {Array} An array of nodes that have the specified routine execution ID.
|
|
247
|
+
*/
|
|
168
248
|
getNodesByRoutineExecId(routineExecId: string): GraphNode[];
|
|
249
|
+
/**
|
|
250
|
+
* Finds and returns all nodes in the graph that are identical to the given node.
|
|
251
|
+
* Two nodes are considered identical if they share the same routine execution ID
|
|
252
|
+
* and share a task with each other.
|
|
253
|
+
*
|
|
254
|
+
* @param {GraphNode} node - The reference node to compare against other nodes in the graph.
|
|
255
|
+
* @return {GraphNode[]} An array of nodes that are identical to the given node.
|
|
256
|
+
*/
|
|
169
257
|
getIdenticalNodes(node: GraphNode): GraphNode[];
|
|
258
|
+
/**
|
|
259
|
+
* Checks whether all nodes in the collection have been processed.
|
|
260
|
+
*
|
|
261
|
+
* @return {boolean} Returns true if all nodes are processed, otherwise false.
|
|
262
|
+
*/
|
|
170
263
|
isProcessed(): boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Checks whether all layers in the graph have been processed.
|
|
266
|
+
*
|
|
267
|
+
* @return {boolean} Returns true if all graph layers are processed; otherwise, returns false.
|
|
268
|
+
*/
|
|
171
269
|
graphDone(): boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Sets the next GraphLayer in the sequence if it has a higher index than the current layer.
|
|
272
|
+
* Updates the previous property if the given next layer has an existing previous layer.
|
|
273
|
+
*
|
|
274
|
+
* @param {GraphLayer} next - The next GraphLayer to be linked in the sequence.
|
|
275
|
+
* @return {void} Does not return a value. Modifies the current layer's state.
|
|
276
|
+
*/
|
|
172
277
|
setNext(next: GraphLayer): void;
|
|
278
|
+
/**
|
|
279
|
+
* Adds a node to the graph.
|
|
280
|
+
*
|
|
281
|
+
* @param {GraphNode} node - The node to be added to the graph.
|
|
282
|
+
* @return {void}
|
|
283
|
+
*/
|
|
173
284
|
add(node: GraphNode): void;
|
|
285
|
+
/**
|
|
286
|
+
* Starts the execution timer if it has not been started already.
|
|
287
|
+
* Records the current timestamp as the start time.
|
|
288
|
+
*
|
|
289
|
+
* @return {number} The timestamp representing the start time in milliseconds.
|
|
290
|
+
*/
|
|
174
291
|
start(): number;
|
|
292
|
+
/**
|
|
293
|
+
* Marks the end of a process by capturing the current timestamp and calculating the execution time if a start time exists.
|
|
294
|
+
*
|
|
295
|
+
* @return {number} The timestamp at which the process ended, or 0 if the start time is not defined.
|
|
296
|
+
*/
|
|
175
297
|
end(): number;
|
|
298
|
+
/**
|
|
299
|
+
* Destroys the current graph layer and its associated resources.
|
|
300
|
+
* This method recursively destroys all nodes in the current layer, clears the node list,
|
|
301
|
+
* and ensures that any connected subsequent graph layers are also destroyed.
|
|
302
|
+
* Additionally, it calls the decoupling logic to disconnect the current layer from its dependencies.
|
|
303
|
+
*
|
|
304
|
+
* @return {void} Does not return any value.
|
|
305
|
+
*/
|
|
176
306
|
destroy(): void;
|
|
307
|
+
/**
|
|
308
|
+
* Returns an iterator for traversing through the graph layers.
|
|
309
|
+
*
|
|
310
|
+
* @return {GraphLayerIterator} An instance of GraphLayerIterator to traverse graph layers.
|
|
311
|
+
*/
|
|
177
312
|
getIterator(): GraphLayerIterator;
|
|
313
|
+
/**
|
|
314
|
+
* Accepts a visitor object to traverse or perform operations on the current graph layer and its nodes.
|
|
315
|
+
*
|
|
316
|
+
* @param {GraphVisitor} visitor - The visitor instance implementing the visitLayer and visitNode behavior.
|
|
317
|
+
* @return {void} Returns nothing.
|
|
318
|
+
*/
|
|
178
319
|
accept(visitor: GraphVisitor): void;
|
|
179
320
|
export(): {
|
|
180
321
|
__index: number;
|
|
@@ -187,9 +328,24 @@ declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
|
187
328
|
log(): void;
|
|
188
329
|
}
|
|
189
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Represents a node in a graph structure used for executing tasks.
|
|
333
|
+
* A Node is a container for a task and its associated context, providing
|
|
334
|
+
* methods for executing the task and managing its lifecycle.
|
|
335
|
+
*
|
|
336
|
+
* It extends the SignalEmitter class to emit and handle signals related to
|
|
337
|
+
* the node's lifecycle, such as "meta.node.started" and "meta.node.completed".
|
|
338
|
+
*
|
|
339
|
+
* It also implements the Graph interface, allowing it to be used as a part of
|
|
340
|
+
* a graph structure, such as a GraphLayer or GraphRoutine.
|
|
341
|
+
*
|
|
342
|
+
* @extends SignalEmitter
|
|
343
|
+
* @implements Graph
|
|
344
|
+
*/
|
|
190
345
|
declare class GraphNode extends SignalEmitter implements Graph {
|
|
191
346
|
id: string;
|
|
192
347
|
routineExecId: string;
|
|
348
|
+
executionTraceId: string;
|
|
193
349
|
task: Task;
|
|
194
350
|
context: GraphContext;
|
|
195
351
|
layer: GraphLayer | undefined;
|
|
@@ -219,45 +375,311 @@ declare class GraphNode extends SignalEmitter implements Graph {
|
|
|
219
375
|
isProcessing(): boolean;
|
|
220
376
|
subgraphDone(): boolean;
|
|
221
377
|
graphDone(): boolean;
|
|
378
|
+
/**
|
|
379
|
+
* Compares the current GraphNode instance with another GraphNode to determine if they are considered equal.
|
|
380
|
+
*
|
|
381
|
+
* @param {GraphNode} node - The GraphNode object to compare with the current instance.
|
|
382
|
+
* @return {boolean} Returns true if the nodes share the same task, context, and belong to the same graph; otherwise, false.
|
|
383
|
+
*/
|
|
222
384
|
isEqualTo(node: GraphNode): boolean;
|
|
385
|
+
/**
|
|
386
|
+
* Determines if the given node is part of the same graph as the current node.
|
|
387
|
+
*
|
|
388
|
+
* @param {GraphNode} node - The node to compare with the current node.
|
|
389
|
+
* @return {boolean} Returns true if the provided node is part of the same graph
|
|
390
|
+
* (i.e., has the same routineExecId), otherwise false.
|
|
391
|
+
*/
|
|
223
392
|
isPartOfSameGraph(node: GraphNode): boolean;
|
|
393
|
+
/**
|
|
394
|
+
* Determines whether the current instance shares a task with the provided node.
|
|
395
|
+
*
|
|
396
|
+
* @param {GraphNode} node - The graph node to compare with the current instance.
|
|
397
|
+
* @return {boolean} Returns true if the task names of both nodes match, otherwise false.
|
|
398
|
+
*/
|
|
224
399
|
sharesTaskWith(node: GraphNode): boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Determines whether the current node shares the same context as the specified node.
|
|
402
|
+
*
|
|
403
|
+
* @param {GraphNode} node - The graph node to compare with the current node's context.
|
|
404
|
+
* @return {boolean} True if both nodes share the same context; otherwise, false.
|
|
405
|
+
*/
|
|
225
406
|
sharesContextWith(node: GraphNode): boolean;
|
|
226
407
|
getLayerIndex(): number;
|
|
227
408
|
getConcurrency(): number;
|
|
409
|
+
/**
|
|
410
|
+
* Retrieves the tag associated with the current task and context.
|
|
411
|
+
*
|
|
412
|
+
* @return {string} The tag retrieved from the task within the given context.
|
|
413
|
+
*/
|
|
228
414
|
getTag(): string;
|
|
415
|
+
/**
|
|
416
|
+
* Schedules the current node/task on the specified graph layer if applicable.
|
|
417
|
+
*
|
|
418
|
+
* This method assesses whether the current node/task should be scheduled
|
|
419
|
+
* on the given graph layer. It ensures that tasks are only scheduled
|
|
420
|
+
* under certain conditions, such as checking if the task shares
|
|
421
|
+
* execution contexts or dependencies with other nodes, and handles
|
|
422
|
+
* various metadata emissions and context updates during the scheduling process.
|
|
423
|
+
*
|
|
424
|
+
* @param {GraphLayer} layer - The graph layer on which the current task should be scheduled.
|
|
425
|
+
* @returns {void} Does not return a value.
|
|
426
|
+
*/
|
|
229
427
|
scheduleOn(layer: GraphLayer): void;
|
|
428
|
+
/**
|
|
429
|
+
* Starts the execution process by initializing the execution start timestamp,
|
|
430
|
+
* emitting relevant metadata, and logging debug information if applicable.
|
|
431
|
+
*
|
|
432
|
+
* The method performs the following actions:
|
|
433
|
+
* 1. Sets the execution start timestamp if it's not already initialized.
|
|
434
|
+
* 2. Emits metrics with metadata about the routine execution starting, including additional data if there are no previous nodes.
|
|
435
|
+
* 3. Optionally logs debug or verbose information based on the current settings.
|
|
436
|
+
* 4. Emits additional metrics to indicate that the execution has started.
|
|
437
|
+
*
|
|
438
|
+
* @return {number} The timestamp indicating when the execution started.
|
|
439
|
+
*/
|
|
230
440
|
start(): number;
|
|
441
|
+
/**
|
|
442
|
+
* Marks the end of an execution process, performs necessary cleanup, emits
|
|
443
|
+
* metrics with associated metadata, and signals the completion of execution.
|
|
444
|
+
* Also handles specific cases when the graph completes.
|
|
445
|
+
*
|
|
446
|
+
* @return {number} The timestamp corresponding to the end of execution. If execution
|
|
447
|
+
* was not started, it returns 0.
|
|
448
|
+
*/
|
|
231
449
|
end(): number;
|
|
450
|
+
/**
|
|
451
|
+
* Executes the main logic of the task, including input validation, processing, and post-processing.
|
|
452
|
+
* Handles both synchronous and asynchronous workflows.
|
|
453
|
+
*
|
|
454
|
+
* @return {Array|Promise|undefined} Returns the next nodes to process if available.
|
|
455
|
+
* If asynchronous processing is required, it returns a Promise that resolves to the next nodes.
|
|
456
|
+
* Returns undefined in case of an error during input validation or preconditions that prevent processing.
|
|
457
|
+
*/
|
|
232
458
|
execute(): GraphNode[] | Promise<GraphNode[]>;
|
|
459
|
+
/**
|
|
460
|
+
* Executes an asynchronous workflow that processes a result and retries on errors.
|
|
461
|
+
* The method handles different result states, checks for error properties, and invokes
|
|
462
|
+
* error handling when necessary.
|
|
463
|
+
*
|
|
464
|
+
* @return {Promise<void>} A promise that resolves when the operation completes successfully,
|
|
465
|
+
* or rejects if an unhandled error occurs.
|
|
466
|
+
*/
|
|
233
467
|
workAsync(): Promise<void>;
|
|
468
|
+
/**
|
|
469
|
+
* Executes an asynchronous operation, processes the result, and determines the next nodes to execute.
|
|
470
|
+
* This method will manage asynchronous work, handle post-processing of results, and ensure proper handling of both synchronous and asynchronous next node configurations.
|
|
471
|
+
*
|
|
472
|
+
* @return {Promise<any>} A promise resolving to the next nodes to be executed. Can be the result of post-processing or a directly resolved next nodes object.
|
|
473
|
+
*/
|
|
234
474
|
executeAsync(): Promise<GraphNode[]>;
|
|
475
|
+
/**
|
|
476
|
+
* Executes the task associated with the current instance, using the given context,
|
|
477
|
+
* progress callback, and metadata. If the task fails or an error occurs, it attempts
|
|
478
|
+
* to retry the execution. If the retry is not successful, it propagates the error and
|
|
479
|
+
* returns the result.
|
|
480
|
+
*
|
|
481
|
+
* @return {TaskResult | Promise<TaskResult>} The result of the task execution, or a
|
|
482
|
+
* promise that resolves to the task result. This includes handling for retries on
|
|
483
|
+
* failure and error propagation.
|
|
484
|
+
*/
|
|
235
485
|
work(): TaskResult | Promise<TaskResult>;
|
|
486
|
+
/**
|
|
487
|
+
* Emits a signal along with its associated metadata. The metadata includes
|
|
488
|
+
* task-specific information such as task name, version, execution ID, and
|
|
489
|
+
* additional context metadata like routine execution ID and execution trace ID.
|
|
490
|
+
* This method is designed to enrich emitted signals with relevant details
|
|
491
|
+
* before broadcasting them.
|
|
492
|
+
*
|
|
493
|
+
* @param {string} signal - The name of the signal to be emitted.
|
|
494
|
+
* @param {AnyObject} data - The data object to be sent along with the signal. Metadata
|
|
495
|
+
* will be injected into this object before being emitted.
|
|
496
|
+
* @return {void} No return value.
|
|
497
|
+
*/
|
|
236
498
|
emitWithMetadata(signal: string, data: AnyObject): void;
|
|
499
|
+
/**
|
|
500
|
+
* Emits metrics with additional metadata describing the task execution and context.
|
|
501
|
+
*
|
|
502
|
+
* @param {string} signal - The signal name being emitted.
|
|
503
|
+
* @param {AnyObject} data - The data associated with the signal emission, enriched with metadata.
|
|
504
|
+
* @return {void} Emits the signal with enriched data and does not return a value.
|
|
505
|
+
*/
|
|
237
506
|
emitMetricsWithMetadata(signal: string, data: AnyObject): void;
|
|
507
|
+
/**
|
|
508
|
+
* Updates the progress of a task and emits metrics with associated metadata.
|
|
509
|
+
*
|
|
510
|
+
* @param {number} progress - A number representing the progress value, which will be clamped between 0 and 1.
|
|
511
|
+
* @return {void} This method does not return a value.
|
|
512
|
+
*/
|
|
238
513
|
onProgress(progress: number): void;
|
|
514
|
+
/**
|
|
515
|
+
* Processes the result of the current operation, validates it, and determines the next set of nodes.
|
|
516
|
+
*
|
|
517
|
+
* This method ensures that results of certain types such as strings or arrays
|
|
518
|
+
* are flagged as errors. It divides the current context into subsequent nodes
|
|
519
|
+
* for further processing. If the division returns a promise, it delegates the
|
|
520
|
+
* processing to `postProcessAsync`. For synchronous division, it sets the
|
|
521
|
+
* `nextNodes` and finalizes the operation.
|
|
522
|
+
*
|
|
523
|
+
* @return {(Array|undefined)} Returns an array of next nodes for further processing,
|
|
524
|
+
* or undefined if no further processing is required.
|
|
525
|
+
*/
|
|
239
526
|
postProcess(): GraphNode[] | Promise<GraphNode[]>;
|
|
527
|
+
/**
|
|
528
|
+
* Asynchronously processes and finalizes the provided graph nodes.
|
|
529
|
+
*
|
|
530
|
+
* @param {Promise<GraphNode[]>} nextNodes A promise that resolves to an array of graph nodes to be processed.
|
|
531
|
+
* @return {Promise<GraphNode[]>} A promise that resolves to the processed array of graph nodes.
|
|
532
|
+
*/
|
|
240
533
|
postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
|
|
534
|
+
/**
|
|
535
|
+
* Finalizes the current task execution by determining if the task is complete, handles any errors or failures,
|
|
536
|
+
* emits relevant signals based on the task outcomes, and ensures proper end of the task lifecycle.
|
|
537
|
+
*
|
|
538
|
+
* @return {void} Does not return a value.
|
|
539
|
+
*/
|
|
241
540
|
finalize(): void;
|
|
541
|
+
/**
|
|
542
|
+
* Handles an error event, processes the error, and updates the state accordingly.
|
|
543
|
+
*
|
|
544
|
+
* @param {unknown} error - The error object or message that occurred.
|
|
545
|
+
* @param {AnyObject} [errorData={}] - Additional error data to include in the result.
|
|
546
|
+
* @return {void} This method does not return any value.
|
|
547
|
+
*/
|
|
242
548
|
onError(error: unknown, errorData?: AnyObject): void;
|
|
549
|
+
/**
|
|
550
|
+
* Retries a task based on the defined retry count and delay time. If the retry count is 0, it immediately resolves with the provided previous result.
|
|
551
|
+
*
|
|
552
|
+
* @param {any} [prevResult] - The result from a previous attempt, if any, to return when no retries are performed.
|
|
553
|
+
* @return {Promise<TaskResult>} - A promise that resolves with the result of the retried task or the previous result if no retries occur.
|
|
554
|
+
*/
|
|
243
555
|
retry(prevResult?: any): Promise<TaskResult>;
|
|
556
|
+
/**
|
|
557
|
+
* Retries an asynchronous operation and returns its result.
|
|
558
|
+
* If the retry count is zero, the method immediately returns the provided previous result.
|
|
559
|
+
*
|
|
560
|
+
* @param {any} [prevResult] - The optional result from a previous operation attempt, if applicable.
|
|
561
|
+
* @return {Promise<TaskResult>} A promise that resolves to the result of the retried operation.
|
|
562
|
+
*/
|
|
244
563
|
retryAsync(prevResult?: any): Promise<TaskResult>;
|
|
245
564
|
delayRetry(): Promise<void>;
|
|
565
|
+
/**
|
|
566
|
+
* Processes the result of a task by generating new nodes based on the task output.
|
|
567
|
+
* The method handles synchronous and asynchronous generators, validates task output,
|
|
568
|
+
* and creates new nodes accordingly. If errors occur, the method attempts to handle them
|
|
569
|
+
* by generating alternative task nodes.
|
|
570
|
+
*
|
|
571
|
+
* @return {GraphNode[] | Promise<GraphNode[]>} Returns an array of generated GraphNode objects
|
|
572
|
+
* (synchronously or wrapped in a Promise) based on the task result, or propagates errors if validation fails.
|
|
573
|
+
*/
|
|
246
574
|
divide(): GraphNode[] | Promise<GraphNode[]>;
|
|
575
|
+
/**
|
|
576
|
+
* Processes an asynchronous iterator result, validates its output, and generates new graph nodes accordingly.
|
|
577
|
+
* Additionally, continues to process and validate results from an asynchronous generator.
|
|
578
|
+
*
|
|
579
|
+
* @param {Promise<IteratorResult<any>>} current - A promise resolving to the current step result from an asynchronous iterator.
|
|
580
|
+
* @return {Promise<GraphNode[]>} A promise resolving to an array of generated GraphNode objects based on validated outputs.
|
|
581
|
+
*/
|
|
247
582
|
divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
|
|
583
|
+
/**
|
|
584
|
+
* Generates new nodes based on the provided result and task configuration.
|
|
585
|
+
*
|
|
586
|
+
* @param {any} result - The result of the previous operation, which determines the configuration and context for new nodes. It can be a boolean or an object containing details like failure, errors, or metadata.
|
|
587
|
+
* @return {GraphNode[]} An array of newly generated graph nodes configured based on the task and context.
|
|
588
|
+
*/
|
|
248
589
|
generateNewNodes(result: any): GraphNode[];
|
|
590
|
+
/**
|
|
591
|
+
* Executes the differentiation process based on a given task and updates the instance properties accordingly.
|
|
592
|
+
*
|
|
593
|
+
* @param {Task} task - The task object containing information such as retry count, retry delay, and metadata status.
|
|
594
|
+
* @return {GraphNode} The updated instance after processing the task.
|
|
595
|
+
*/
|
|
249
596
|
differentiate(task: Task): GraphNode;
|
|
597
|
+
/**
|
|
598
|
+
* Migrates the current instance to a new context and returns the updated instance.
|
|
599
|
+
*
|
|
600
|
+
* @param {any} ctx - The context data to be used for migration.
|
|
601
|
+
* @return {GraphNode} The updated instance after migration.
|
|
602
|
+
*/
|
|
250
603
|
migrate(ctx: any): GraphNode;
|
|
604
|
+
/**
|
|
605
|
+
* Splits the current node into a new group identified by the provided ID.
|
|
606
|
+
*
|
|
607
|
+
* @param {string} id - The unique identifier for the new split group.
|
|
608
|
+
* @return {GraphNode} The current instance of the GraphNode with the updated split group ID.
|
|
609
|
+
*/
|
|
251
610
|
split(id: string): GraphNode;
|
|
611
|
+
/**
|
|
612
|
+
* Creates a new instance of the GraphNode with the current node's properties.
|
|
613
|
+
* This method allows for duplicating the existing graph node.
|
|
614
|
+
*
|
|
615
|
+
* @return {GraphNode} A new instance of GraphNode that is a copy of the current node.
|
|
616
|
+
*/
|
|
252
617
|
clone(): GraphNode;
|
|
618
|
+
/**
|
|
619
|
+
* Consumes the given graph node by combining contexts, merging previous nodes,
|
|
620
|
+
* and performing associated operations on the provided node.
|
|
621
|
+
*
|
|
622
|
+
* @param {GraphNode} node - The graph node to be consumed.
|
|
623
|
+
* @return {void} This method does not return a value.
|
|
624
|
+
*/
|
|
253
625
|
consume(node: GraphNode): void;
|
|
626
|
+
/**
|
|
627
|
+
* Changes the identity of the current instance by updating the `id` property.
|
|
628
|
+
*
|
|
629
|
+
* @param {string} id - The new identity value to be assigned.
|
|
630
|
+
* @return {void} Does not return a value.
|
|
631
|
+
*/
|
|
254
632
|
changeIdentity(id: string): void;
|
|
633
|
+
/**
|
|
634
|
+
* Completes the subgraph for the current node and recursively for its previous nodes
|
|
635
|
+
* once all next nodes have their subgraphs marked as done. If there are no previous nodes,
|
|
636
|
+
* it completes the entire graph.
|
|
637
|
+
*
|
|
638
|
+
* @return {void} Does not return a value.
|
|
639
|
+
*/
|
|
255
640
|
completeSubgraph(): void;
|
|
641
|
+
/**
|
|
642
|
+
* Completes the current graph by setting a flag indicating the graph has been completed
|
|
643
|
+
* and recursively completes all subsequent nodes in the graph.
|
|
644
|
+
*
|
|
645
|
+
* @return {void} Does not return a value.
|
|
646
|
+
*/
|
|
256
647
|
completeGraph(): void;
|
|
648
|
+
/**
|
|
649
|
+
* Destroys the current instance by releasing resources, breaking references,
|
|
650
|
+
* and resetting properties to ensure proper cleanup.
|
|
651
|
+
*
|
|
652
|
+
* @return {void} No return value.
|
|
653
|
+
*/
|
|
257
654
|
destroy(): void;
|
|
655
|
+
/**
|
|
656
|
+
* Retrieves an iterator for traversing through the graph nodes.
|
|
657
|
+
*
|
|
658
|
+
* @return {GraphNodeIterator} An iterator instance specific to this graph node.
|
|
659
|
+
*/
|
|
258
660
|
getIterator(): GraphNodeIterator;
|
|
661
|
+
/**
|
|
662
|
+
* Applies a callback function to each node in the `nextNodes` array and returns
|
|
663
|
+
* the resulting array from the map operation.
|
|
664
|
+
*
|
|
665
|
+
* @param {function} callback - A function to execute on each `GraphNode` in the `nextNodes` array.
|
|
666
|
+
* The function receives a `GraphNode` as its argument.
|
|
667
|
+
* @return {Array} The resulting array after applying the callback function to each node in `nextNodes`.
|
|
668
|
+
*/
|
|
259
669
|
mapNext(callback: (node: GraphNode) => any): any[];
|
|
670
|
+
/**
|
|
671
|
+
* Accepts a visitor object and calls its visitNode method with the current instance.
|
|
672
|
+
*
|
|
673
|
+
* @param {GraphVisitor} visitor - The visitor instance implementing the GraphVisitor interface.
|
|
674
|
+
* @return {void} This method does not return a value.
|
|
675
|
+
*/
|
|
260
676
|
accept(visitor: GraphVisitor): void;
|
|
677
|
+
/**
|
|
678
|
+
* Exports the current object's state and returns it in a serialized format.
|
|
679
|
+
* The exported object contains metadata, task details, context information, execution times, node relationships, routine execution status, and other state information.
|
|
680
|
+
*
|
|
681
|
+
* @return {Object} An object representing the current state.
|
|
682
|
+
*/
|
|
261
683
|
export(): {
|
|
262
684
|
__id: string;
|
|
263
685
|
__task: AnyObject;
|
|
@@ -314,6 +736,11 @@ declare abstract class GraphVisitor {
|
|
|
314
736
|
abstract visitTask(task: Task): any;
|
|
315
737
|
}
|
|
316
738
|
|
|
739
|
+
/**
|
|
740
|
+
* TaskIterator is a custom iterator for traversing over a set of tasks.
|
|
741
|
+
* It provides mechanisms to iterate through tasks in a layered manner,
|
|
742
|
+
* where each task can branch out to other tasks forming multiple layers.
|
|
743
|
+
*/
|
|
317
744
|
declare class TaskIterator implements Iterator {
|
|
318
745
|
currentTask: Task | undefined;
|
|
319
746
|
currentLayer: Set<Task>;
|
|
@@ -355,6 +782,12 @@ type SchemaDefinition = {
|
|
|
355
782
|
type TaskFunction = (context: AnyObject, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void) => TaskResult;
|
|
356
783
|
type TaskResult = boolean | AnyObject | Generator | Promise<any> | void;
|
|
357
784
|
type ThrottleTagGetter = (context?: AnyObject, task?: Task) => string;
|
|
785
|
+
/**
|
|
786
|
+
* Represents a task with a specific behavior, configuration, and lifecycle management.
|
|
787
|
+
* Tasks are used to define units of work that can be executed and orchestrated.
|
|
788
|
+
* Tasks can specify input/output validation, concurrency, retry policies, and more.
|
|
789
|
+
* This class extends SignalEmitter and implements Graph, allowing tasks to emit and observe signals.
|
|
790
|
+
*/
|
|
358
791
|
declare class Task extends SignalEmitter implements Graph {
|
|
359
792
|
readonly name: string;
|
|
360
793
|
readonly description: string;
|
|
@@ -392,29 +825,36 @@ declare class Task extends SignalEmitter implements Graph {
|
|
|
392
825
|
observedSignals: Set<string>;
|
|
393
826
|
readonly taskFunction: TaskFunction;
|
|
394
827
|
/**
|
|
395
|
-
* Constructs
|
|
396
|
-
*
|
|
397
|
-
* @param task
|
|
398
|
-
* @param
|
|
399
|
-
* @param
|
|
400
|
-
* @param
|
|
401
|
-
* @param
|
|
402
|
-
* @param
|
|
403
|
-
* @param
|
|
404
|
-
* @param
|
|
405
|
-
* @param
|
|
406
|
-
* @param
|
|
407
|
-
* @param
|
|
408
|
-
* @param
|
|
409
|
-
* @param
|
|
410
|
-
* @param
|
|
411
|
-
* @param
|
|
412
|
-
* @param
|
|
413
|
-
* @param
|
|
414
|
-
* @param
|
|
415
|
-
* @
|
|
828
|
+
* Constructs an instance of the task with the specified properties and configuration options.
|
|
829
|
+
*
|
|
830
|
+
* @param {string} name - The name of the task.
|
|
831
|
+
* @param {TaskFunction} task - The function that represents the task logic.
|
|
832
|
+
* @param {string} [description=""] - A description of the task.
|
|
833
|
+
* @param {number} [concurrency=0] - The number of concurrent executions allowed for the task.
|
|
834
|
+
* @param {number} [timeout=0] - The maximum execution time for the task in milliseconds.
|
|
835
|
+
* @param {boolean} [register=true] - Indicates if the task should be registered or not.
|
|
836
|
+
* @param {boolean} [isUnique=false] - Specifies if the task should only allow one instance to exist at any time.
|
|
837
|
+
* @param {boolean} [isMeta=false] - Indicates if the task is a meta-task.
|
|
838
|
+
* @param {boolean} [isSubMeta=false] - Indicates if the task is a sub-meta-task.
|
|
839
|
+
* @param {boolean} [isHidden=false] - Determines if the task is hidden and not exposed publicly.
|
|
840
|
+
* @param {ThrottleTagGetter} [getTagCallback=undefined] - A callback to generate a throttle tag for the task.
|
|
841
|
+
* @param {SchemaDefinition} [inputSchema=undefined] - The input schema for validating the task's input context.
|
|
842
|
+
* @param {boolean} [validateInputContext=false] - Specifies if the input context should be validated against the input schema.
|
|
843
|
+
* @param {SchemaDefinition} [outputSchema=undefined] - The output schema for validating the task's output context.
|
|
844
|
+
* @param {boolean} [validateOutputContext=false] - Specifies if the output context should be validated against the output schema.
|
|
845
|
+
* @param {number} [retryCount=0] - The number of retry attempts allowed for the task in case of failure.
|
|
846
|
+
* @param {number} [retryDelay=0] - The initial delay (in milliseconds) between retry attempts.
|
|
847
|
+
* @param {number} [retryDelayMax=0] - The maximum delay (in milliseconds) allowed between retries.
|
|
848
|
+
* @param {number} [retryDelayFactor=1] - The factor by which the retry delay increases after each attempt.
|
|
416
849
|
*/
|
|
417
850
|
constructor(name: string, task: TaskFunction, description?: string, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, isSubMeta?: boolean, isHidden?: boolean, getTagCallback?: ThrottleTagGetter | undefined, inputSchema?: SchemaDefinition | undefined, validateInputContext?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputContext?: boolean, retryCount?: number, retryDelay?: number, retryDelayMax?: number, retryDelayFactor?: number);
|
|
851
|
+
/**
|
|
852
|
+
* Retrieves the tag associated with the instance.
|
|
853
|
+
* Can be overridden by subclasses.
|
|
854
|
+
*
|
|
855
|
+
* @param {AnyObject} [context] - Optional context parameter that can be provided.
|
|
856
|
+
* @return {string} The tag value of the instance.
|
|
857
|
+
*/
|
|
418
858
|
getTag(context?: AnyObject): string;
|
|
419
859
|
setVersion(version: number): void;
|
|
420
860
|
setTimeout(timeout: number): void;
|
|
@@ -424,114 +864,316 @@ declare class Task extends SignalEmitter implements Graph {
|
|
|
424
864
|
setOutputContextSchema(schema: SchemaDefinition): void;
|
|
425
865
|
setValidateInputContext(value: boolean): void;
|
|
426
866
|
setValidateOutputContext(value: boolean): void;
|
|
867
|
+
/**
|
|
868
|
+
* Emits a signal along with metadata if certain conditions are met.
|
|
869
|
+
*
|
|
870
|
+
* This method sends a signal with optional context data and adds metadata
|
|
871
|
+
* to the emitted data if the instance is not hidden and not a subordinate metadata object.
|
|
872
|
+
*
|
|
873
|
+
* @param {string} signal - The name of the signal to emit.
|
|
874
|
+
* @param {AnyObject} [ctx={}] - Additional context data to include with the emitted signal.
|
|
875
|
+
* @return {void} Does not return a value.
|
|
876
|
+
*/
|
|
427
877
|
emitWithMetadata(signal: string, ctx?: AnyObject): void;
|
|
878
|
+
/**
|
|
879
|
+
* Emits metrics with additional metadata enhancement based on the context and the state of the instance.
|
|
880
|
+
* This is used to prevent loops on the meta layer in debug mode.
|
|
881
|
+
*
|
|
882
|
+
* @param {string} signal - The signal identifier for the metric being emitted.
|
|
883
|
+
* @param {AnyObject} [ctx={}] - Optional context object to provide additional information with the metric.
|
|
884
|
+
* @return {void} This method does not return any value.
|
|
885
|
+
*/
|
|
428
886
|
emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
|
|
429
887
|
/**
|
|
430
|
-
* Validates a
|
|
431
|
-
*
|
|
432
|
-
* @param
|
|
433
|
-
* @param
|
|
434
|
-
* @
|
|
435
|
-
* @
|
|
888
|
+
* Validates a data object against a specified schema definition and returns validation results.
|
|
889
|
+
*
|
|
890
|
+
* @param {any} data - The target object to validate against the schema.
|
|
891
|
+
* @param {SchemaDefinition | undefined} schema - The schema definition describing the expected structure and constraints of the data.
|
|
892
|
+
* @param {string} [path="context"] - The base path or context for traversing the data, used in generating error messages.
|
|
893
|
+
* @return {{ valid: boolean, errors: Record<string, string> }} - An object containing a validity flag (`valid`)
|
|
894
|
+
* and a map (`errors`) of validation error messages keyed by property paths.
|
|
436
895
|
*/
|
|
437
896
|
validateSchema(data: any, schema: SchemaDefinition | undefined, path?: string): {
|
|
438
897
|
valid: boolean;
|
|
439
898
|
errors: Record<string, string>;
|
|
440
899
|
};
|
|
900
|
+
/**
|
|
901
|
+
* Validates the input context against the predefined schema and emits metadata if validation fails.
|
|
902
|
+
*
|
|
903
|
+
* @param {AnyObject} context - The input context to validate.
|
|
904
|
+
* @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
|
|
905
|
+
*/
|
|
441
906
|
validateInput(context: AnyObject): true | AnyObject;
|
|
907
|
+
/**
|
|
908
|
+
* Validates the output context using the provided schema and emits metadata if validation fails.
|
|
909
|
+
*
|
|
910
|
+
* @param {AnyObject} context - The output context to validate.
|
|
911
|
+
* @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
|
|
912
|
+
* containing error information when validation fails.
|
|
913
|
+
*/
|
|
442
914
|
validateOutput(context: AnyObject): true | AnyObject;
|
|
443
915
|
/**
|
|
444
|
-
* Executes
|
|
445
|
-
*
|
|
446
|
-
* @param
|
|
447
|
-
* @param
|
|
448
|
-
* @param
|
|
449
|
-
* @
|
|
450
|
-
* @
|
|
451
|
-
* @edge If validateOutputContext is true, validates output; on failure, emits 'meta.task.outputValidationFailed' with detailed errors.
|
|
916
|
+
* Executes a task within a given context, optionally emitting signals and reporting progress.
|
|
917
|
+
*
|
|
918
|
+
* @param {GraphContext} context The execution context which provides data and functions necessary for the task.
|
|
919
|
+
* @param {function(string, AnyObject): void} emit A function to emit signals and communicate intermediate results or states.
|
|
920
|
+
* @param {function(number): void} progressCallback A callback function used to report task progress as a percentage (0 to 100).
|
|
921
|
+
* @param {{ nodeId: string; routineExecId: string }} nodeData An object containing identifiers related to the node and execution routine.
|
|
922
|
+
* @return {TaskResult} The result of the executed task.
|
|
452
923
|
*/
|
|
453
924
|
execute(context: GraphContext, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void, nodeData: {
|
|
454
925
|
nodeId: string;
|
|
455
926
|
routineExecId: string;
|
|
456
927
|
}): TaskResult;
|
|
928
|
+
/**
|
|
929
|
+
* Adds tasks as predecessors to the current task and establishes dependencies between them.
|
|
930
|
+
* Ensures that adding predecessors does not create cyclic dependencies.
|
|
931
|
+
* Updates task relationships, progress weights, and emits relevant metrics after operations.
|
|
932
|
+
*
|
|
933
|
+
* @param {Task[]} tasks - An array of tasks to be added as predecessors to the current task.
|
|
934
|
+
* @return {this} The current task instance for method chaining.
|
|
935
|
+
* @throws {Error} Throws an error if adding a predecessor creates a cycle in the task structure.
|
|
936
|
+
*/
|
|
457
937
|
doAfter(...tasks: Task[]): this;
|
|
938
|
+
/**
|
|
939
|
+
* Adds a sequence of tasks as successors to the current task, ensuring no cyclic dependencies are introduced.
|
|
940
|
+
* Metrics are emitted when a relationship is successfully added.
|
|
941
|
+
*
|
|
942
|
+
* @param {...Task} tasks - The tasks to be added as successors to the current task.
|
|
943
|
+
* @return {this} Returns the current task instance for method chaining.
|
|
944
|
+
* @throws {Error} Throws an error if adding a task causes a cyclic dependency.
|
|
945
|
+
*/
|
|
458
946
|
then(...tasks: Task[]): this;
|
|
947
|
+
/**
|
|
948
|
+
* Decouples the current task from the provided task by removing mutual references.
|
|
949
|
+
*
|
|
950
|
+
* @param {Task} task - The task to decouple from the current task.
|
|
951
|
+
* @return {void} This method does not return a value.
|
|
952
|
+
*/
|
|
459
953
|
decouple(task: Task): void;
|
|
954
|
+
/**
|
|
955
|
+
* Updates the progress weights for tasks within each layer of the subgraph.
|
|
956
|
+
* The progress weight for each task is calculated based on the inverse proportion
|
|
957
|
+
* of the number of layers and the number of tasks in each layer. This ensures an
|
|
958
|
+
* even distribution of progress weight across the tasks in the layers.
|
|
959
|
+
*
|
|
960
|
+
* @return {void} Does not return a value.
|
|
961
|
+
*/
|
|
460
962
|
updateProgressWeights(): void;
|
|
963
|
+
/**
|
|
964
|
+
* Retrieves a mapping of layer indices to sets of tasks within each layer of a subgraph.
|
|
965
|
+
* This method traverses the task dependencies and organizes tasks by their respective layer indices.
|
|
966
|
+
*
|
|
967
|
+
* @return {Map<number, Set<Task>>} A map where the key is the layer index (number) and the value is a set of tasks (Set<Task>) belonging to that layer.
|
|
968
|
+
*/
|
|
461
969
|
getSubgraphLayers(): Map<number, Set<Task>>;
|
|
970
|
+
/**
|
|
971
|
+
* Updates the `layerIndex` of the current task based on the maximum layer index of its predecessors
|
|
972
|
+
* and propagates the update recursively to all subsequent tasks. If the `layerIndex` changes,
|
|
973
|
+
* emits a metric event with metadata about the change.
|
|
974
|
+
*
|
|
975
|
+
* @return {void} This method does not return a value.
|
|
976
|
+
*/
|
|
462
977
|
updateLayerFromPredecessors(): void;
|
|
978
|
+
/**
|
|
979
|
+
* Determines whether there is a cycle in the tasks graph.
|
|
980
|
+
* This method performs a depth-first search (DFS) to detect cycles.
|
|
981
|
+
*
|
|
982
|
+
* @return {boolean} - Returns true if a cycle is found in the graph, otherwise false.
|
|
983
|
+
*/
|
|
463
984
|
hasCycle(): boolean;
|
|
985
|
+
/**
|
|
986
|
+
* Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
|
|
987
|
+
*
|
|
988
|
+
* @param {Function} callback A function that will be called with each task, transforming the task as needed. It receives a single parameter of type Task.
|
|
989
|
+
* @param {boolean} [failed=false] A boolean that determines whether to map over the failed tasks (true) or the next tasks (false).
|
|
990
|
+
* @return {any[]} An array of transformed tasks resulting from applying the callback function.
|
|
991
|
+
*/
|
|
464
992
|
mapNext(callback: (task: Task) => any, failed?: boolean): any[];
|
|
993
|
+
/**
|
|
994
|
+
* Maps through each task in the set of predecessor tasks and applies the provided callback function.
|
|
995
|
+
*
|
|
996
|
+
* @param {function} callback - A function to execute on each task in the predecessor tasks. The function receives a `Task` object as its argument and returns any value.
|
|
997
|
+
* @return {any[]} An array containing the results of applying the callback function to each predecessor task.
|
|
998
|
+
*/
|
|
465
999
|
mapPrevious(callback: (task: Task) => any): any[];
|
|
466
1000
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
1001
|
+
* Adds the specified signals to the current instance, making it observe them.
|
|
1002
|
+
* If the instance is already observing a signal, it will be skipped.
|
|
1003
|
+
* The method also emits metadata information if the `register` property is set.
|
|
1004
|
+
*
|
|
1005
|
+
* @param {...string[]} signals - The array of signal names to observe.
|
|
1006
|
+
* @return {this} The current instance after adding the specified signals.
|
|
471
1007
|
*/
|
|
472
1008
|
doOn(...signals: string[]): this;
|
|
473
1009
|
/**
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
* @
|
|
1010
|
+
* Registers the specified signals to be emitted after the Task executes successfully and attaches them for further processing.
|
|
1011
|
+
*
|
|
1012
|
+
* @param {...string} signals - The list of signals to be registered for emission.
|
|
1013
|
+
* @return {this} The current instance for method chaining.
|
|
477
1014
|
*/
|
|
478
1015
|
emits(...signals: string[]): this;
|
|
1016
|
+
/**
|
|
1017
|
+
* Configures the instance to emit specified signals when the task execution fails.
|
|
1018
|
+
* A failure is defined as anything that does not return a successful result.
|
|
1019
|
+
*
|
|
1020
|
+
* @param {...string} signals - The names of the signals to emit upon failure.
|
|
1021
|
+
* @return {this} Returns the current instance for chaining.
|
|
1022
|
+
*/
|
|
479
1023
|
emitsOnFail(...signals: string[]): this;
|
|
1024
|
+
/**
|
|
1025
|
+
* Attaches a signal to the current context and emits metadata if the register flag is set.
|
|
1026
|
+
*
|
|
1027
|
+
* @param {string} signal - The name of the signal to attach.
|
|
1028
|
+
* @param {boolean} [isOnFail=false] - Indicates if the signal should be marked as "on fail".
|
|
1029
|
+
* @return {void} This method does not return a value.
|
|
1030
|
+
*/
|
|
480
1031
|
attachSignal(signal: string, isOnFail?: boolean): void;
|
|
481
1032
|
/**
|
|
482
|
-
* Unsubscribes from
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
1033
|
+
* Unsubscribes the current instance from the specified signals.
|
|
1034
|
+
* This method removes the signals from the observedSignals set, unsubscribes
|
|
1035
|
+
* from the underlying broker, and emits metadata for the unsubscription if applicable.
|
|
1036
|
+
*
|
|
1037
|
+
* @param {string[]} signals - The list of signal names to unsubscribe from.
|
|
1038
|
+
* @return {this} Returns the current instance for method chaining.
|
|
486
1039
|
*/
|
|
487
1040
|
unsubscribe(...signals: string[]): this;
|
|
488
1041
|
/**
|
|
489
|
-
* Unsubscribes from all observed signals.
|
|
490
|
-
*
|
|
1042
|
+
* Unsubscribes from all currently observed signals and clears the list of observed signals.
|
|
1043
|
+
*
|
|
1044
|
+
* @return {this} The instance of the class to allow method chaining.
|
|
491
1045
|
*/
|
|
492
1046
|
unsubscribeAll(): this;
|
|
493
1047
|
/**
|
|
494
|
-
* Detaches
|
|
495
|
-
*
|
|
496
|
-
* @
|
|
1048
|
+
* Detaches the specified signals from being emitted after execution and optionally emits metadata for each detached signal.
|
|
1049
|
+
*
|
|
1050
|
+
* @param {...string} signals - The list of signal names to be detached. Signals can be in the format "namespace:signalName".
|
|
1051
|
+
* @return {this} Returns the current instance of the object for method chaining.
|
|
497
1052
|
*/
|
|
498
1053
|
detachSignals(...signals: string[]): this;
|
|
499
1054
|
/**
|
|
500
|
-
* Detaches all
|
|
501
|
-
*
|
|
1055
|
+
* Detaches all signals associated with the object by invoking the `detachSignals` method
|
|
1056
|
+
* and clearing the `signalsToEmitAfter` collection.
|
|
1057
|
+
*
|
|
1058
|
+
* @return {this} Returns the current instance to allow method chaining.
|
|
502
1059
|
*/
|
|
503
1060
|
detachAllSignals(): this;
|
|
1061
|
+
/**
|
|
1062
|
+
* Maps over the signals in the `signalsToEmitAfter` set and applies a callback function to each signal.
|
|
1063
|
+
*
|
|
1064
|
+
* @param {function(string): void} callback - A function that is called with each signal
|
|
1065
|
+
* in the `signalsToEmitAfter` set, providing the signal as an argument.
|
|
1066
|
+
* @return {Array<any>} An array containing the results of applying the callback
|
|
1067
|
+
* function to each signal.
|
|
1068
|
+
*/
|
|
504
1069
|
mapSignals(callback: (signal: string) => void): void[];
|
|
1070
|
+
/**
|
|
1071
|
+
* Maps over the signals in `signalsToEmitOnFail` and applies the provided callback to each signal.
|
|
1072
|
+
*
|
|
1073
|
+
* @param {function(string): void} callback - A function that receives each signal as a string and performs an operation or transformation on it.
|
|
1074
|
+
* @return {Array} The array resulting from applying the callback to each signal in `signalsToEmitOnFail`.
|
|
1075
|
+
*/
|
|
505
1076
|
mapOnFailSignals(callback: (signal: string) => void): void[];
|
|
1077
|
+
/**
|
|
1078
|
+
* Maps over the observed signals with the provided callback function.
|
|
1079
|
+
*
|
|
1080
|
+
* @param {function(string): void} callback - A function to execute on each signal in the observed signals array.
|
|
1081
|
+
* @return {Array} A new array containing the results of calling the callback function on each observed signal.
|
|
1082
|
+
*/
|
|
506
1083
|
mapObservedSignals(callback: (signal: string) => void): void[];
|
|
507
1084
|
/**
|
|
508
|
-
* Emits
|
|
509
|
-
*
|
|
510
|
-
* @
|
|
1085
|
+
* Emits a collection of signals stored in the `signalsToEmitAfter` array.
|
|
1086
|
+
*
|
|
1087
|
+
* @param {GraphContext} context - The context object containing data or state to be passed to the emitted signals.
|
|
1088
|
+
* @return {void} This method does not return a value.
|
|
511
1089
|
*/
|
|
512
1090
|
emitSignals(context: GraphContext): void;
|
|
513
1091
|
/**
|
|
514
|
-
* Emits
|
|
515
|
-
*
|
|
516
|
-
* @
|
|
1092
|
+
* Emits registered signals when an operation fails.
|
|
1093
|
+
*
|
|
1094
|
+
* @param {GraphContext} context - The context from which the full context is derived and passed to the signals being emitted.
|
|
1095
|
+
* @return {void} This method does not return any value.
|
|
517
1096
|
*/
|
|
518
1097
|
emitOnFailSignals(context: GraphContext): void;
|
|
1098
|
+
/**
|
|
1099
|
+
* Cleans up and destroys the task instance, detaching it from other tasks and
|
|
1100
|
+
* performing necessary cleanup operations.
|
|
1101
|
+
*
|
|
1102
|
+
* This method:
|
|
1103
|
+
* - Unsubscribes from all signals and events.
|
|
1104
|
+
* - Detaches all associated signal handlers.
|
|
1105
|
+
* - Removes the task from successor and predecessor task mappings.
|
|
1106
|
+
* - Clears all task relationships and marks the task as destroyed.
|
|
1107
|
+
* - Emits destruction metrics, if applicable.
|
|
1108
|
+
*
|
|
1109
|
+
* @return {void} No value is returned because the function performs clean-up operations.
|
|
1110
|
+
*/
|
|
519
1111
|
destroy(): void;
|
|
1112
|
+
/**
|
|
1113
|
+
* Exports the current state of the object as a structured plain object.
|
|
1114
|
+
*
|
|
1115
|
+
* @return {AnyObject} An object containing the serialized properties of the current instance. The exported object includes various metadata, schema information, task attributes, and related tasks, such as:
|
|
1116
|
+
* - Name and description of the task.
|
|
1117
|
+
* - Layer index, uniqueness, meta, and signal-related flags.
|
|
1118
|
+
* - Event triggers and attached signals.
|
|
1119
|
+
* - Throttling, concurrency, timeout settings, and ephemeral flag.
|
|
1120
|
+
* - Task function as a string.
|
|
1121
|
+
* - Serialization of getter callbacks and schemas for input/output validation.
|
|
1122
|
+
* - Relationships such as next tasks, failure tasks, and predecessor tasks.
|
|
1123
|
+
*/
|
|
520
1124
|
export(): AnyObject;
|
|
1125
|
+
/**
|
|
1126
|
+
* Returns an iterator for iterating over tasks associated with this instance.
|
|
1127
|
+
*
|
|
1128
|
+
* @return {TaskIterator} An iterator instance for tasks.
|
|
1129
|
+
*/
|
|
521
1130
|
getIterator(): TaskIterator;
|
|
1131
|
+
/**
|
|
1132
|
+
* Accepts a visitor object to perform operations on the current instance.
|
|
1133
|
+
*
|
|
1134
|
+
* @param {GraphVisitor} visitor - The visitor object implementing operations for this instance.
|
|
1135
|
+
* @return {void} This method does not return a value.
|
|
1136
|
+
*/
|
|
522
1137
|
accept(visitor: GraphVisitor): void;
|
|
523
1138
|
log(): void;
|
|
524
1139
|
}
|
|
525
1140
|
|
|
1141
|
+
/**
|
|
1142
|
+
* Represents a synchronous graph layer derived from the GraphLayer base class.
|
|
1143
|
+
* This class is designed to execute graph nodes in a strictly synchronous manner.
|
|
1144
|
+
* Asynchronous functions are explicitly disallowed, ensuring consistency and predictability.
|
|
1145
|
+
*/
|
|
526
1146
|
declare class SyncGraphLayer extends GraphLayer {
|
|
1147
|
+
/**
|
|
1148
|
+
* Executes the processing logic of the current set of graph nodes. Iterates through all
|
|
1149
|
+
* nodes, skipping any that have already been processed, and executes their respective
|
|
1150
|
+
* logic to generate new nodes. Asynchronous functions are not supported and will
|
|
1151
|
+
* trigger an error log.
|
|
1152
|
+
*
|
|
1153
|
+
* @return {GraphNode[]} An array of newly generated graph nodes after executing the logic of each unprocessed node.
|
|
1154
|
+
*/
|
|
527
1155
|
execute(): GraphNode[];
|
|
528
1156
|
}
|
|
529
1157
|
|
|
1158
|
+
/**
|
|
1159
|
+
* An abstract class representing a GraphExporter.
|
|
1160
|
+
* This class defines a structure for exporting graph data in different formats,
|
|
1161
|
+
* depending on the implementations provided by subclasses.
|
|
1162
|
+
*/
|
|
530
1163
|
declare abstract class GraphExporter {
|
|
531
1164
|
abstract exportGraph(graph: SyncGraphLayer): any;
|
|
532
1165
|
abstract exportStaticGraph(graph: Task[]): any;
|
|
533
1166
|
}
|
|
534
1167
|
|
|
1168
|
+
/**
|
|
1169
|
+
* GraphBuilder is an abstract base class designed to construct and manage a graph structure
|
|
1170
|
+
* composed of multiple layers. Subclasses are expected to implement the `compose` method
|
|
1171
|
+
* based on specific requirements. This class provides methods for adding nodes, managing
|
|
1172
|
+
* layers, and resetting the graph construction process.
|
|
1173
|
+
*
|
|
1174
|
+
* This class supports creating layered graph structures, dynamically adding layers and nodes,
|
|
1175
|
+
* and debugging graph-building operations.
|
|
1176
|
+
*/
|
|
535
1177
|
declare abstract class GraphBuilder {
|
|
536
1178
|
graph: GraphLayer | undefined;
|
|
537
1179
|
topLayerIndex: number;
|
|
@@ -539,15 +1181,62 @@ declare abstract class GraphBuilder {
|
|
|
539
1181
|
debug: boolean;
|
|
540
1182
|
setDebug(value: boolean): void;
|
|
541
1183
|
getResult(): GraphLayer;
|
|
1184
|
+
/**
|
|
1185
|
+
* Composes a series of functions or operations.
|
|
1186
|
+
* This method should be implemented in the child class
|
|
1187
|
+
* to define custom composition logic.
|
|
1188
|
+
*
|
|
1189
|
+
* @return {any} The result of the composed operations or functions
|
|
1190
|
+
* when implemented in the child class.
|
|
1191
|
+
*/
|
|
542
1192
|
compose(): void;
|
|
1193
|
+
/**
|
|
1194
|
+
* Adds a node to the appropriate layer of the graph.
|
|
1195
|
+
*
|
|
1196
|
+
* @param {GraphNode} node - The node to be added to the graph. The node contains
|
|
1197
|
+
* layer information that determines which layer it belongs to.
|
|
1198
|
+
* @return {void} Does not return a value.
|
|
1199
|
+
*/
|
|
543
1200
|
addNode(node: GraphNode): void;
|
|
1201
|
+
/**
|
|
1202
|
+
* Adds multiple nodes to the graph.
|
|
1203
|
+
*
|
|
1204
|
+
* @param {GraphNode[]} nodes - An array of nodes to be added to the graph.
|
|
1205
|
+
* @return {void} This method does not return a value.
|
|
1206
|
+
*/
|
|
544
1207
|
addNodes(nodes: GraphNode[]): void;
|
|
1208
|
+
/**
|
|
1209
|
+
* Adds a new layer to the graph at the specified index. If the graph does not exist,
|
|
1210
|
+
* it creates the graph using the specified index. Updates the graph's top layer index
|
|
1211
|
+
* and maintains the order of layers.
|
|
1212
|
+
*
|
|
1213
|
+
* @param {number} index - The index at which the new layer should be added to the graph.
|
|
1214
|
+
* @return {void} This method does not return a value.
|
|
1215
|
+
*/
|
|
545
1216
|
addLayer(index: number): void;
|
|
1217
|
+
/**
|
|
1218
|
+
* Creates a new layer for the graph at the specified index.
|
|
1219
|
+
*
|
|
1220
|
+
* @param {number} index - The index of the layer to be created.
|
|
1221
|
+
* @return {GraphLayer} A new instance of the graph layer corresponding to the provided index.
|
|
1222
|
+
*/
|
|
546
1223
|
createLayer(index: number): GraphLayer;
|
|
1224
|
+
/**
|
|
1225
|
+
* Retrieves a specific layer from the current set of layers.
|
|
1226
|
+
*
|
|
1227
|
+
* @param {number} layerIndex - The index of the layer to retrieve.
|
|
1228
|
+
* @return {*} The layer corresponding to the given index.
|
|
1229
|
+
*/
|
|
547
1230
|
getLayer(layerIndex: number): GraphLayer;
|
|
548
1231
|
reset(): void;
|
|
549
1232
|
}
|
|
550
1233
|
|
|
1234
|
+
/**
|
|
1235
|
+
* Abstract class representing a strategy for configuring and executing graph operations.
|
|
1236
|
+
* Provides a structure for managing graph builders, altering strategies, and updating the execution context.
|
|
1237
|
+
*
|
|
1238
|
+
* This class cannot be instantiated directly and must be extended by concrete implementations.
|
|
1239
|
+
*/
|
|
551
1240
|
declare abstract class GraphRunStrategy {
|
|
552
1241
|
graphBuilder: GraphBuilder;
|
|
553
1242
|
runInstance?: GraphRun;
|
|
@@ -567,6 +1256,10 @@ interface RunJson {
|
|
|
567
1256
|
__graph: any;
|
|
568
1257
|
__data: any;
|
|
569
1258
|
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Represents a GraphRun instance which manages the execution of a graph-based workflow.
|
|
1261
|
+
* It utilizes a specific strategy and export mechanism to manage, execute, and export the graph data.
|
|
1262
|
+
*/
|
|
570
1263
|
declare class GraphRun {
|
|
571
1264
|
readonly id: string;
|
|
572
1265
|
graph: GraphLayer | undefined;
|
|
@@ -582,6 +1275,13 @@ declare class GraphRun {
|
|
|
582
1275
|
setExporter(exporter: GraphExporter): void;
|
|
583
1276
|
}
|
|
584
1277
|
|
|
1278
|
+
/**
|
|
1279
|
+
* Represents a routine in a graph structure with tasks and signal observation capabilities.
|
|
1280
|
+
* Routines are named entrypoint for a sub-graph, describing the purpose for the subsequent flow.
|
|
1281
|
+
* Since Task names are specific to the task it performs, it doesn't describe the overall flow.
|
|
1282
|
+
* Routines, therefore are used to assign names to sub-flows that can be referenced using that name instead of the name of the task(s).
|
|
1283
|
+
* Extends SignalEmitter to emit and handle signals related to the routine's lifecycle and tasks.
|
|
1284
|
+
*/
|
|
585
1285
|
declare class GraphRoutine extends SignalEmitter {
|
|
586
1286
|
readonly name: string;
|
|
587
1287
|
version: number;
|
|
@@ -592,9 +1292,12 @@ declare class GraphRoutine extends SignalEmitter {
|
|
|
592
1292
|
observedSignals: Set<string>;
|
|
593
1293
|
constructor(name: string, tasks: Task[], description: string, isMeta?: boolean);
|
|
594
1294
|
/**
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
1295
|
+
* Iterates over each task in the `tasks` collection and applies the provided callback function.
|
|
1296
|
+
* If the callback returns a Promise, resolves all Promises concurrently.
|
|
1297
|
+
*
|
|
1298
|
+
* @param {function} callBack - A function to be executed on each task from the `tasks` collection.
|
|
1299
|
+
* The callback receives the current task as its argument.
|
|
1300
|
+
* @return {Promise<void>} A Promise that resolves once all callback executions, including asynchronous ones, are complete.
|
|
598
1301
|
*/
|
|
599
1302
|
forEachTask(callBack: (task: Task) => any): Promise<void>;
|
|
600
1303
|
/**
|
|
@@ -603,30 +1306,42 @@ declare class GraphRoutine extends SignalEmitter {
|
|
|
603
1306
|
*/
|
|
604
1307
|
setVersion(version: number): void;
|
|
605
1308
|
/**
|
|
606
|
-
* Subscribes to signals
|
|
607
|
-
*
|
|
608
|
-
* @
|
|
609
|
-
* @
|
|
1309
|
+
* Subscribes the current instance to the specified signals, enabling it to observe them.
|
|
1310
|
+
*
|
|
1311
|
+
* @param {...string} signals - The names of the signals to observe.
|
|
1312
|
+
* @return {this} Returns the instance to allow for method chaining.
|
|
610
1313
|
*/
|
|
611
1314
|
doOn(...signals: string[]): this;
|
|
612
1315
|
/**
|
|
613
|
-
* Unsubscribes from all observed signals
|
|
614
|
-
*
|
|
1316
|
+
* Unsubscribes from all observed signals and clears the internal collection
|
|
1317
|
+
* of observed signals. This ensures that the instance is no longer listening
|
|
1318
|
+
* or reacting to any previously subscribed signals.
|
|
1319
|
+
*
|
|
1320
|
+
* @return {this} Returns the current instance for chaining purposes.
|
|
615
1321
|
*/
|
|
616
1322
|
unsubscribeAll(): this;
|
|
617
1323
|
/**
|
|
618
|
-
* Unsubscribes from
|
|
619
|
-
*
|
|
620
|
-
* @
|
|
621
|
-
* @
|
|
1324
|
+
* Unsubscribes the current instance from the specified signals.
|
|
1325
|
+
*
|
|
1326
|
+
* @param {...string} signals - The signals to unsubscribe from.
|
|
1327
|
+
* @return {this} The current instance for method chaining.
|
|
622
1328
|
*/
|
|
623
1329
|
unsubscribe(...signals: string[]): this;
|
|
624
1330
|
/**
|
|
625
|
-
*
|
|
1331
|
+
* Cleans up resources and emits an event indicating the destruction of the routine.
|
|
1332
|
+
*
|
|
1333
|
+
* This method unsubscribes from all events, clears the tasks list,
|
|
1334
|
+
* and emits a "meta.routine.destroyed" event with details of the destruction.
|
|
1335
|
+
*
|
|
1336
|
+
* @return {void}
|
|
626
1337
|
*/
|
|
627
1338
|
destroy(): void;
|
|
628
1339
|
}
|
|
629
1340
|
|
|
1341
|
+
/**
|
|
1342
|
+
* Represents a runner for managing and executing tasks or routines within a graph.
|
|
1343
|
+
* The `GraphRunner` extends `SignalEmitter` to include signal-based event-driven mechanisms.
|
|
1344
|
+
*/
|
|
630
1345
|
declare class GraphRunner extends SignalEmitter {
|
|
631
1346
|
currentRun: GraphRun;
|
|
632
1347
|
debug: boolean;
|
|
@@ -642,42 +1357,74 @@ declare class GraphRunner extends SignalEmitter {
|
|
|
642
1357
|
constructor(isMeta?: boolean);
|
|
643
1358
|
init(): void;
|
|
644
1359
|
/**
|
|
645
|
-
* Adds tasks
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
* @
|
|
649
|
-
*
|
|
650
|
-
* @
|
|
1360
|
+
* Adds tasks or routines to the current execution pipeline. Supports both individual tasks,
|
|
1361
|
+
* routines, or arrays of tasks and routines. Handles metadata and execution context management.
|
|
1362
|
+
*
|
|
1363
|
+
* @param {Task|GraphRoutine|(Task|GraphRoutine)[]} tasks - The task(s) or routine(s) to be added.
|
|
1364
|
+
* It can be a single task, a single routine, or an array of tasks and routines.
|
|
1365
|
+
* @param {AnyObject} [context={}] - Optional context object to provide execution trace and metadata.
|
|
1366
|
+
* Used to propagate information across task or routine executions.
|
|
1367
|
+
* @return {void} - This method does not return a value.
|
|
651
1368
|
*/
|
|
652
1369
|
addTasks(tasks: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): void;
|
|
653
1370
|
/**
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* @
|
|
658
|
-
* @
|
|
1371
|
+
* Executes the provided tasks or routines. Maintains the execution state
|
|
1372
|
+
* and handles synchronous or asynchronous processing.
|
|
1373
|
+
*
|
|
1374
|
+
* @param {Task|GraphRoutine|(Task|GraphRoutine)[]} [tasks] - A single task, a single routine, or an array of tasks or routines to execute. Optional.
|
|
1375
|
+
* @param {AnyObject} [context] - An optional context object to be used during task execution.
|
|
1376
|
+
* @return {GraphRun|Promise<GraphRun>} - Returns a `GraphRun` instance if the execution is synchronous, or a `Promise` resolving to a `GraphRun` for asynchronous execution.
|
|
659
1377
|
*/
|
|
660
1378
|
run(tasks?: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): GraphRun | Promise<GraphRun>;
|
|
1379
|
+
/**
|
|
1380
|
+
* Executes the provided asynchronous operation and resets the state afterwards.
|
|
1381
|
+
*
|
|
1382
|
+
* @param {Promise<void>} run - A promise representing the asynchronous operation to execute.
|
|
1383
|
+
* @return {Promise<GraphRun>} A promise that resolves to the result of the reset operation after the asynchronous operation completes.
|
|
1384
|
+
*/
|
|
661
1385
|
runAsync(run: Promise<void>): Promise<GraphRun>;
|
|
1386
|
+
/**
|
|
1387
|
+
* Resets the current state of the graph, creating a new GraphRun instance
|
|
1388
|
+
* and returning the previous run instance.
|
|
1389
|
+
* If the debug mode is not enabled, it will destroy the existing resources.
|
|
1390
|
+
*
|
|
1391
|
+
* @return {GraphRun} The last GraphRun instance before the reset.
|
|
1392
|
+
*/
|
|
662
1393
|
reset(): GraphRun;
|
|
663
1394
|
setDebug(value: boolean): void;
|
|
664
1395
|
setVerbose(value: boolean): void;
|
|
665
1396
|
destroy(): void;
|
|
1397
|
+
/**
|
|
1398
|
+
* Sets the strategy to be used for running the graph and initializes
|
|
1399
|
+
* the current run with the provided strategy if no process is currently running.
|
|
1400
|
+
*
|
|
1401
|
+
* @param {GraphRunStrategy} strategy - The strategy to use for running the graph.
|
|
1402
|
+
* @return {void}
|
|
1403
|
+
*/
|
|
666
1404
|
setStrategy(strategy: GraphRunStrategy): void;
|
|
667
1405
|
startRun(context: AnyObject, emit: (signal: string, ctx: AnyObject) => void): boolean;
|
|
668
1406
|
}
|
|
669
1407
|
|
|
1408
|
+
/**
|
|
1409
|
+
* This class manages signals and observers, enabling communication across different parts of an application.
|
|
1410
|
+
* It follows a singleton design pattern, allowing for centralized signal management.
|
|
1411
|
+
*/
|
|
670
1412
|
declare class SignalBroker {
|
|
671
1413
|
static instance_: SignalBroker;
|
|
672
|
-
/**
|
|
673
|
-
* Singleton instance for signal management.
|
|
674
|
-
* @returns The broker instance.
|
|
675
|
-
*/
|
|
676
1414
|
static get instance(): SignalBroker;
|
|
677
1415
|
debug: boolean;
|
|
678
1416
|
verbose: boolean;
|
|
679
1417
|
setDebug(value: boolean): void;
|
|
680
1418
|
setVerbose(value: boolean): void;
|
|
1419
|
+
/**
|
|
1420
|
+
* Validates the provided signal name string to ensure it adheres to specific formatting rules.
|
|
1421
|
+
* Throws an error if any of the validation checks fail.
|
|
1422
|
+
*
|
|
1423
|
+
* @param {string} signalName - The signal name to be validated.
|
|
1424
|
+
* @return {void} - Returns nothing if the signal name is valid.
|
|
1425
|
+
* @throws {Error} - Throws an error if the signal name is longer than 100 characters, contains spaces,
|
|
1426
|
+
* contains backslashes, or contains uppercase letters in restricted parts of the name.
|
|
1427
|
+
*/
|
|
681
1428
|
validateSignalName(signalName: string): void;
|
|
682
1429
|
runner: GraphRunner | undefined;
|
|
683
1430
|
metaRunner: GraphRunner | undefined;
|
|
@@ -697,6 +1444,11 @@ declare class SignalBroker {
|
|
|
697
1444
|
* @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
|
|
698
1445
|
*/
|
|
699
1446
|
bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void;
|
|
1447
|
+
/**
|
|
1448
|
+
* Initializes and sets up the various tasks for managing and processing signals.
|
|
1449
|
+
*
|
|
1450
|
+
* @return {void} This method does not return a value.
|
|
1451
|
+
*/
|
|
700
1452
|
init(): void;
|
|
701
1453
|
/**
|
|
702
1454
|
* Observes a signal with a routine/task.
|
|
@@ -712,6 +1464,15 @@ declare class SignalBroker {
|
|
|
712
1464
|
* @edge Removes all instances if duplicate; deletes if empty.
|
|
713
1465
|
*/
|
|
714
1466
|
unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
|
|
1467
|
+
/**
|
|
1468
|
+
* Schedules a signal to be emitted after a specified delay or at an exact date and time.
|
|
1469
|
+
*
|
|
1470
|
+
* @param {string} signal - The name of the signal to be emitted.
|
|
1471
|
+
* @param {AnyObject} context - The context to be passed along with the signal.
|
|
1472
|
+
* @param {number} [timeoutMs=60000] - The delay in milliseconds before the signal is emitted. Defaults to 60,000 ms.
|
|
1473
|
+
* @param {Date} [exactDateTime] - An exact date and time at which to emit the signal. If provided, this overrides the `timeoutMs`.
|
|
1474
|
+
* @return {AbortController} An AbortController instance that can be used to cancel the scheduled signal emission.
|
|
1475
|
+
*/
|
|
715
1476
|
schedule(signal: string, context: AnyObject, timeoutMs?: number, exactDateTime?: Date): AbortController;
|
|
716
1477
|
/**
|
|
717
1478
|
* Emits `signal` repeatedly with a fixed interval.
|
|
@@ -725,15 +1486,43 @@ declare class SignalBroker {
|
|
|
725
1486
|
*/
|
|
726
1487
|
throttle(signal: string, context: AnyObject, intervalMs?: number, leading?: boolean, startDateTime?: Date): ThrottleHandle;
|
|
727
1488
|
/**
|
|
728
|
-
* Emits a signal
|
|
729
|
-
*
|
|
730
|
-
* @param
|
|
731
|
-
* @
|
|
732
|
-
*
|
|
1489
|
+
* Emits a signal with the specified context, triggering any associated handlers for that signal.
|
|
1490
|
+
*
|
|
1491
|
+
* @param {string} signal - The name of the signal to emit.
|
|
1492
|
+
* @param {AnyObject} [context={}] - An optional context object containing additional information or metadata
|
|
1493
|
+
* associated with the signal. If the context includes a `__routineExecId`, it will be handled accordingly.
|
|
1494
|
+
* @return {void} This method does not return a value.
|
|
733
1495
|
*/
|
|
734
1496
|
emit(signal: string, context?: AnyObject): void;
|
|
1497
|
+
/**
|
|
1498
|
+
* Executes a signal by emitting events, updating context, and invoking listeners.
|
|
1499
|
+
* Creates a new execution trace if necessary and updates the context with relevant metadata.
|
|
1500
|
+
* Handles specific, hierarchy-based, and wildcard signals.
|
|
1501
|
+
*
|
|
1502
|
+
* @param {string} signal - The signal name to be executed, potentially including namespaces or tags (e.g., "meta.*" or "signal:type").
|
|
1503
|
+
* @param {AnyObject} context - An object containing relevant metadata and execution details used for handling the signal.
|
|
1504
|
+
* @return {boolean} Returns true if any listeners were successfully executed, otherwise false.
|
|
1505
|
+
*/
|
|
735
1506
|
execute(signal: string, context: AnyObject): boolean;
|
|
1507
|
+
/**
|
|
1508
|
+
* Executes the tasks associated with a given signal and context.
|
|
1509
|
+
* It processes both normal and meta tasks depending on the signal type
|
|
1510
|
+
* and the availability of the appropriate runner.
|
|
1511
|
+
*
|
|
1512
|
+
* @param {string} signal - The signal identifier that determines which tasks to execute.
|
|
1513
|
+
* @param {AnyObject} context - The context object passed to the task execution function.
|
|
1514
|
+
* @return {boolean} - Returns true if tasks were executed; otherwise, false.
|
|
1515
|
+
*/
|
|
736
1516
|
executeListener(signal: string, context: AnyObject): boolean;
|
|
1517
|
+
/**
|
|
1518
|
+
* Adds a signal to the signalObservers for tracking and execution.
|
|
1519
|
+
* Performs validation on the signal name and emits a meta signal event when added.
|
|
1520
|
+
* If the signal contains a namespace (denoted by a colon ":"), its base signal is
|
|
1521
|
+
* also added if it doesn't already exist.
|
|
1522
|
+
*
|
|
1523
|
+
* @param {string} signal - The name of the signal to be added.
|
|
1524
|
+
* @return {void} This method does not return any value.
|
|
1525
|
+
*/
|
|
737
1526
|
addSignal(signal: string): void;
|
|
738
1527
|
/**
|
|
739
1528
|
* Lists all observed signals.
|
|
@@ -743,6 +1532,10 @@ declare class SignalBroker {
|
|
|
743
1532
|
reset(): void;
|
|
744
1533
|
}
|
|
745
1534
|
|
|
1535
|
+
/**
|
|
1536
|
+
* This class serves as a registry for managing tasks and routines within a graph-based execution model.
|
|
1537
|
+
* It provides functionalities to register, update, retrieve, delete, and iterate over tasks and routines.
|
|
1538
|
+
*/
|
|
746
1539
|
declare class GraphRegistry {
|
|
747
1540
|
static _instance: GraphRegistry;
|
|
748
1541
|
static get instance(): GraphRegistry;
|
|
@@ -761,6 +1554,16 @@ declare class GraphRegistry {
|
|
|
761
1554
|
getAllRoutines: Task;
|
|
762
1555
|
doForEachRoutine: Task;
|
|
763
1556
|
deleteRoutine: Task;
|
|
1557
|
+
/**
|
|
1558
|
+
* Constructs a new instance and sets up various meta tasks and routines.
|
|
1559
|
+
*
|
|
1560
|
+
* This constructor initializes several predefined tasks for managing operations
|
|
1561
|
+
* like registering tasks, updating schemas for tasks, fetching tasks or routines,
|
|
1562
|
+
* and performing actions on all tasks or routines. It also initializes routines
|
|
1563
|
+
* to handle similar operations and hardcodes the initial meta tasks and routines.
|
|
1564
|
+
*
|
|
1565
|
+
* It initializes the instance state by setting up tasks and routines.
|
|
1566
|
+
*/
|
|
764
1567
|
constructor();
|
|
765
1568
|
reset(): void;
|
|
766
1569
|
}
|
|
@@ -770,6 +1573,11 @@ interface DebounceOptions {
|
|
|
770
1573
|
trailing?: boolean;
|
|
771
1574
|
maxWait?: number;
|
|
772
1575
|
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Class representing a debounced task, inheriting from the `Task` class.
|
|
1578
|
+
* This class allows tasks to be executed with debounce behavior, controlling
|
|
1579
|
+
* the frequency at which the task function is triggered.
|
|
1580
|
+
*/
|
|
773
1581
|
declare class DebounceTask extends Task {
|
|
774
1582
|
readonly debounceTime: number;
|
|
775
1583
|
leading: boolean;
|
|
@@ -785,8 +1593,37 @@ declare class DebounceTask extends Task {
|
|
|
785
1593
|
lastProgressCallback: ((progress: number) => void) | null;
|
|
786
1594
|
lastEmitFunction: ((signal: string, context: any) => void) | null;
|
|
787
1595
|
constructor(name: string, task: TaskFunction, description?: string, debounceTime?: number, leading?: boolean, trailing?: boolean, maxWait?: number, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, isSubMeta?: boolean, isHidden?: boolean, inputSchema?: SchemaDefinition | undefined, validateInputSchema?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputSchema?: boolean);
|
|
1596
|
+
/**
|
|
1597
|
+
* Executes the taskFunction with the provided context, emit function, and progress callback.
|
|
1598
|
+
* It clears any existing timeout before execution.
|
|
1599
|
+
* Handles synchronous and asynchronous results from taskFunction.
|
|
1600
|
+
* If an error occurs during execution, it resolves with the error.
|
|
1601
|
+
*
|
|
1602
|
+
* @return {void} This method does not return any value.
|
|
1603
|
+
*/
|
|
788
1604
|
executeFunction(): void;
|
|
1605
|
+
/**
|
|
1606
|
+
* Executes a debounced operation, ensuring controlled execution of functions
|
|
1607
|
+
* over a specified debounce time and maximum wait time. This method handles
|
|
1608
|
+
* both leading and trailing edge executions and invokes callbacks accordingly.
|
|
1609
|
+
*
|
|
1610
|
+
* @param {Function} resolve - The function to call when the operation is successfully resolved.
|
|
1611
|
+
* @param {Function} reject - The function to call with an error or reason if the operation fails.
|
|
1612
|
+
* @param {GraphContext} context - The execution context for the operation.
|
|
1613
|
+
* @param {NodeJS.Timeout} timeout - A timeout object for managing execution delays.
|
|
1614
|
+
* @param {Function} emit - A callback function to emit signals with a specific context.
|
|
1615
|
+
* @param {Function} progressCallback - A callback function to report progress during operation execution.
|
|
1616
|
+
* @return {void} Does not return a value but sets internal timers and invokes provided callbacks.
|
|
1617
|
+
*/
|
|
789
1618
|
debouncedTrigger(resolve: (value: unknown) => void, reject: (reason?: any) => void, context: GraphContext, timeout: NodeJS.Timeout, emit: (signal: string, context: any) => void, progressCallback: (progress: number) => void): void;
|
|
1619
|
+
/**
|
|
1620
|
+
* Executes a task with a debounced trigger mechanism.
|
|
1621
|
+
*
|
|
1622
|
+
* @param {GraphContext} context - The context containing relevant graph data for the execution.
|
|
1623
|
+
* @param {function(string, any): void} emit - A function used to emit signals with associated context.
|
|
1624
|
+
* @param {function(number): void} progressCallback - A callback function to report the progress of the task as a number between 0 and 1.
|
|
1625
|
+
* @return {Promise<TaskResult>} A promise that resolves with the task result upon completion or rejects on failure.
|
|
1626
|
+
*/
|
|
790
1627
|
execute(context: GraphContext, emit: (signal: string, context: any) => void, progressCallback: (progress: number) => void): TaskResult;
|
|
791
1628
|
}
|
|
792
1629
|
|
|
@@ -794,25 +1631,66 @@ type EphemeralTaskOptions = {
|
|
|
794
1631
|
once?: boolean;
|
|
795
1632
|
destroyCondition?: (context: any) => boolean;
|
|
796
1633
|
};
|
|
1634
|
+
/**
|
|
1635
|
+
* Represents a transient task that executes and may optionally self-destruct
|
|
1636
|
+
* based on given conditions.
|
|
1637
|
+
*
|
|
1638
|
+
* EphemeralTask extends the standard Task class and introduces additional
|
|
1639
|
+
* features for managing tasks that are intended to run only once, or under
|
|
1640
|
+
* certain conditions. This class is particularly useful when you want a task
|
|
1641
|
+
* to clean up after itself and not persist within the system indefinitely.
|
|
1642
|
+
*/
|
|
797
1643
|
declare class EphemeralTask extends Task {
|
|
798
1644
|
readonly once: boolean;
|
|
799
1645
|
readonly condition: (context: any) => boolean;
|
|
800
1646
|
readonly isEphemeral: boolean;
|
|
801
1647
|
constructor(name: string, task: TaskFunction, description?: string, once?: boolean, condition?: (context: any) => boolean, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, isSubMeta?: boolean, isHidden?: boolean, getTagCallback?: ThrottleTagGetter | undefined, inputSchema?: SchemaDefinition | undefined, validateInputContext?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputContext?: boolean, retryCount?: number, retryDelay?: number, retryDelayMax?: number, retryDelayFactor?: number);
|
|
1648
|
+
/**
|
|
1649
|
+
* Executes the process logic with the provided context, emit function, progress callback, and node data.
|
|
1650
|
+
*
|
|
1651
|
+
* @param {any} context - The execution context, carrying necessary parameters or states for the operation.
|
|
1652
|
+
* @param {function(string, AnyObject): void} emit - A function to emit signals with a string identifier and associated context.
|
|
1653
|
+
* @param {function(number): void} progressCallback - A callback function to report the progress of the execution as a numerical value.
|
|
1654
|
+
* @param {{ nodeId: string, routineExecId: string }} nodeData - An object containing details about the node ID and routine execution ID.
|
|
1655
|
+
* @return {any} The result of the execution, returned from the base implementation or processed internally.
|
|
1656
|
+
*/
|
|
802
1657
|
execute(context: any, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void, nodeData: {
|
|
803
1658
|
nodeId: string;
|
|
804
1659
|
routineExecId: string;
|
|
805
1660
|
}): TaskResult;
|
|
806
1661
|
}
|
|
807
1662
|
|
|
1663
|
+
/**
|
|
1664
|
+
* The GraphAsyncRun class extends GraphRunStrategy to implement an asynchronous
|
|
1665
|
+
* graph execution strategy. It utilizes a GraphAsyncQueueBuilder for building
|
|
1666
|
+
* and composing the graph asynchronously before execution.
|
|
1667
|
+
*/
|
|
808
1668
|
declare class GraphAsyncRun extends GraphRunStrategy {
|
|
809
1669
|
constructor();
|
|
1670
|
+
/**
|
|
1671
|
+
* Executes the run operation, which involves composing the graph builder,
|
|
1672
|
+
* updating the run instance, and resetting the state.
|
|
1673
|
+
*
|
|
1674
|
+
* @return {Promise<void>} A promise that resolves when the operation completes.
|
|
1675
|
+
*/
|
|
810
1676
|
run(): Promise<void>;
|
|
811
1677
|
reset(): void;
|
|
812
1678
|
export(): any;
|
|
813
1679
|
}
|
|
814
1680
|
|
|
1681
|
+
/**
|
|
1682
|
+
* The GraphStandardRun class extends the GraphRunStrategy and provides
|
|
1683
|
+
* a concrete implementation of methods to manage and execute a graph run.
|
|
1684
|
+
* This class is responsible for orchestrating the graph composition,
|
|
1685
|
+
* updating the run instance, and resetting its state after execution.
|
|
1686
|
+
*/
|
|
815
1687
|
declare class GraphStandardRun extends GraphRunStrategy {
|
|
1688
|
+
/**
|
|
1689
|
+
* Executes the sequence of operations involving graph composition,
|
|
1690
|
+
* instance updating, and reset mechanisms.
|
|
1691
|
+
*
|
|
1692
|
+
* @return {void} Does not return a value.
|
|
1693
|
+
*/
|
|
816
1694
|
run(): void;
|
|
817
1695
|
export(): any;
|
|
818
1696
|
}
|
|
@@ -836,6 +1714,11 @@ interface TaskOptions {
|
|
|
836
1714
|
retryDelayFactor?: number;
|
|
837
1715
|
}
|
|
838
1716
|
type CadenzaMode = "dev" | "debug" | "verbose" | "production";
|
|
1717
|
+
/**
|
|
1718
|
+
* Represents the core class of the Cadenza framework managing tasks, meta-tasks, signal emissions, and execution strategies.
|
|
1719
|
+
* All core components such as SignalBroker, GraphRunner, and GraphRegistry are initialized through this class, and it provides
|
|
1720
|
+
* utility methods to create, register, and manage various task types.
|
|
1721
|
+
*/
|
|
839
1722
|
declare class Cadenza {
|
|
840
1723
|
static broker: SignalBroker;
|
|
841
1724
|
static runner: GraphRunner;
|
|
@@ -843,138 +1726,425 @@ declare class Cadenza {
|
|
|
843
1726
|
static registry: GraphRegistry;
|
|
844
1727
|
static isBootstrapped: boolean;
|
|
845
1728
|
static mode: CadenzaMode;
|
|
1729
|
+
/**
|
|
1730
|
+
* Initializes the system by setting up the required components such as the
|
|
1731
|
+
* signal broker, runners, and graph registry. Ensures the initialization
|
|
1732
|
+
* happens only once. Configures debug settings if applicable.
|
|
1733
|
+
*
|
|
1734
|
+
* @return {void} No value is returned.
|
|
1735
|
+
*/
|
|
846
1736
|
static bootstrap(): void;
|
|
1737
|
+
/**
|
|
1738
|
+
* Retrieves the available strategies for running graphs.
|
|
1739
|
+
*
|
|
1740
|
+
* @return {Object} An object containing the available run strategies, where:
|
|
1741
|
+
* - PARALLEL: Executes graph runs asynchronously.
|
|
1742
|
+
* - SEQUENTIAL: Executes graph runs in a sequential order.
|
|
1743
|
+
*/
|
|
847
1744
|
static get runStrategy(): {
|
|
848
1745
|
PARALLEL: GraphAsyncRun;
|
|
849
1746
|
SEQUENTIAL: GraphStandardRun;
|
|
850
1747
|
};
|
|
1748
|
+
/**
|
|
1749
|
+
* Sets the mode for the application and configures the broker and runner settings accordingly.
|
|
1750
|
+
*
|
|
1751
|
+
* @param {CadenzaMode} mode - The mode to set. It can be one of the following:
|
|
1752
|
+
* "debug", "dev", "verbose", or "production".
|
|
1753
|
+
* Each mode adjusts debug and verbosity settings.
|
|
1754
|
+
* @return {void} This method does not return a value.
|
|
1755
|
+
*/
|
|
851
1756
|
static setMode(mode: CadenzaMode): void;
|
|
852
1757
|
/**
|
|
853
|
-
* Validates
|
|
854
|
-
*
|
|
855
|
-
*
|
|
1758
|
+
* Validates the given name to ensure it is a non-empty string.
|
|
1759
|
+
* Throws an error if the validation fails.
|
|
1760
|
+
*
|
|
1761
|
+
* @param {string} name - The name to validate.
|
|
1762
|
+
* @return {void} This method does not return anything.
|
|
1763
|
+
* @throws {Error} If the name is not a non-empty string.
|
|
856
1764
|
*/
|
|
857
1765
|
static validateName(name: string): void;
|
|
1766
|
+
/**
|
|
1767
|
+
* Executes the specified task or GraphRoutine with the given context using an internal runner.
|
|
1768
|
+
*
|
|
1769
|
+
* @param {Task | GraphRoutine} task - The task or GraphRoutine to be executed.
|
|
1770
|
+
* @param {AnyObject} context - The context in which the task or GraphRoutine should be executed.
|
|
1771
|
+
* @return {void}
|
|
1772
|
+
*
|
|
1773
|
+
* @example
|
|
1774
|
+
* ```ts
|
|
1775
|
+
* const task = Cadenza.createTask('My task', (ctx) => {
|
|
1776
|
+
* console.log('My task executed with context:', ctx);
|
|
1777
|
+
* });
|
|
1778
|
+
*
|
|
1779
|
+
* Cadenza.run(task, { foo: 'bar' });
|
|
1780
|
+
*
|
|
1781
|
+
* const routine = Cadenza.createRoutine('My routine', [task], 'My routine description');
|
|
1782
|
+
*
|
|
1783
|
+
* Cadenza.run(routine, { foo: 'bar' });
|
|
1784
|
+
* ```
|
|
1785
|
+
*/
|
|
858
1786
|
static run(task: Task | GraphRoutine, context: AnyObject): void;
|
|
1787
|
+
/**
|
|
1788
|
+
* Emits an event with the specified name and data payload to the broker.
|
|
1789
|
+
*
|
|
1790
|
+
* @param {string} event - The name of the event to emit.
|
|
1791
|
+
* @param {AnyObject} [data={}] - The data payload associated with the event.
|
|
1792
|
+
* @return {void} - No return value.
|
|
1793
|
+
*
|
|
1794
|
+
* @example
|
|
1795
|
+
* This is meant to be used as a global event emitter.
|
|
1796
|
+
* If you want to emit an event from within a task, you can use the `emit` method provided to the task function. See {@link TaskFunction}.
|
|
1797
|
+
* ```ts
|
|
1798
|
+
* Cadenza.emit('main.my_event', { foo: 'bar' });
|
|
1799
|
+
* ```
|
|
1800
|
+
*/
|
|
859
1801
|
static emit(event: string, data?: AnyObject): void;
|
|
860
1802
|
/**
|
|
861
|
-
* Creates a
|
|
862
|
-
*
|
|
863
|
-
* @
|
|
864
|
-
*
|
|
865
|
-
* @param
|
|
866
|
-
* @
|
|
867
|
-
* @
|
|
1803
|
+
* Creates and registers a new task with the specified parameters and options.
|
|
1804
|
+
* Tasks are the basic building blocks of Cadenza graphs and are responsible for executing logic.
|
|
1805
|
+
* See {@link Task} for more information.
|
|
1806
|
+
*
|
|
1807
|
+
* @param {string} name - The unique name of the task.
|
|
1808
|
+
* @param {TaskFunction} func - The function to be executed by the task.
|
|
1809
|
+
* @param {string} [description] - An optional description for the task.
|
|
1810
|
+
* @param {TaskOptions} [options={}] - Configuration options for the task, such as concurrency, timeout, and retry settings.
|
|
1811
|
+
* @return {Task} The created task instance.
|
|
1812
|
+
*
|
|
1813
|
+
* @example
|
|
1814
|
+
* You can use arrow functions to create tasks.
|
|
1815
|
+
* ```ts
|
|
1816
|
+
* const task = Cadenza.createTask('My task', (ctx) => {
|
|
1817
|
+
* console.log('My task executed with context:', ctx);
|
|
1818
|
+
* }, 'My task description');
|
|
1819
|
+
* ```
|
|
1820
|
+
*
|
|
1821
|
+
* You can also use named functions to create tasks.
|
|
1822
|
+
* This is the preferred way to create tasks since it allows for code inspection in the CadenzaUI.
|
|
1823
|
+
* ```ts
|
|
1824
|
+
* function myTask(ctx) {
|
|
1825
|
+
* console.log('My task executed with context:', ctx);
|
|
1826
|
+
* }
|
|
1827
|
+
*
|
|
1828
|
+
* const task = Cadenza.createTask('My task', myTask);
|
|
1829
|
+
* ```
|
|
1830
|
+
*
|
|
1831
|
+
* ** Use the TaskOptions object to configure the task. **
|
|
1832
|
+
*
|
|
1833
|
+
* With concurrency limit, timeout limit and retry settings.
|
|
1834
|
+
* ```ts
|
|
1835
|
+
* Cadenza.createTask('My task', (ctx) => {
|
|
1836
|
+
* console.log('My task executed with context:', ctx);
|
|
1837
|
+
* }, 'My task description', {
|
|
1838
|
+
* concurrency: 10,
|
|
1839
|
+
* timeout: 10000,
|
|
1840
|
+
* retryCount: 3,
|
|
1841
|
+
* retryDelay: 1000,
|
|
1842
|
+
* retryDelayFactor: 1.5,
|
|
1843
|
+
* });
|
|
1844
|
+
* ```
|
|
1845
|
+
*
|
|
1846
|
+
* You can specify the input and output context schemas for the task.
|
|
1847
|
+
* ```ts
|
|
1848
|
+
* Cadenza.createTask('My task', (ctx) => {
|
|
1849
|
+
* return { bar: 'foo' + ctx.foo };
|
|
1850
|
+
* }, 'My task description', {
|
|
1851
|
+
* inputContextSchema: {
|
|
1852
|
+
* type: 'object',
|
|
1853
|
+
* properties: {
|
|
1854
|
+
* foo: {
|
|
1855
|
+
* type: 'string',
|
|
1856
|
+
* },
|
|
1857
|
+
* },
|
|
1858
|
+
* required: ['foo'],
|
|
1859
|
+
* },
|
|
1860
|
+
* validateInputContext: true, // default is false
|
|
1861
|
+
* outputContextSchema: {
|
|
1862
|
+
* type: 'object',
|
|
1863
|
+
* properties: {
|
|
1864
|
+
* bar: {
|
|
1865
|
+
* type: 'string',
|
|
1866
|
+
* },
|
|
1867
|
+
* },
|
|
1868
|
+
* required: ['bar'],
|
|
1869
|
+
* },
|
|
1870
|
+
* validateOutputContext: true, // default is false
|
|
1871
|
+
* });
|
|
1872
|
+
* ```
|
|
868
1873
|
*/
|
|
869
1874
|
static createTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
870
1875
|
/**
|
|
871
|
-
* Creates a
|
|
872
|
-
*
|
|
873
|
-
*
|
|
874
|
-
* @
|
|
875
|
-
*
|
|
876
|
-
* @param
|
|
877
|
-
* @
|
|
878
|
-
* @
|
|
1876
|
+
* Creates a meta task with the specified name, functionality, description, and options.
|
|
1877
|
+
* This is used for creating tasks that lives on the meta layer.
|
|
1878
|
+
* The meta layer is a special layer that is executed separately from the business logic layer and is used for extending Cadenzas core functionality.
|
|
1879
|
+
* See {@link Task} or {@link createTask} for more information.
|
|
1880
|
+
*
|
|
1881
|
+
* @param {string} name - The name of the meta task.
|
|
1882
|
+
* @param {TaskFunction} func - The function to be executed by the meta task.
|
|
1883
|
+
* @param {string} [description] - An optional description of the meta task.
|
|
1884
|
+
* @param {TaskOptions} [options={}] - Additional optional task configuration. Automatically sets `isMeta` to true.
|
|
1885
|
+
* @return {Task} A task instance configured as a meta task.
|
|
879
1886
|
*/
|
|
880
1887
|
static createMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
881
1888
|
/**
|
|
882
|
-
* Creates a
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
* @
|
|
886
|
-
*
|
|
887
|
-
* @param
|
|
888
|
-
* @
|
|
889
|
-
* @
|
|
1889
|
+
* Creates a unique task by wrapping the provided task function with a uniqueness constraint.
|
|
1890
|
+
* Unique tasks are designed to execute once per execution ID, merging parents. This is useful for
|
|
1891
|
+
* tasks that require fan-in/joins after parallel branches.
|
|
1892
|
+
* See {@link Task} for more information.
|
|
1893
|
+
*
|
|
1894
|
+
* @param {string} name - The name of the task to be created.
|
|
1895
|
+
* @param {TaskFunction} func - The function that contains the logic for the task. It receives joinedContexts as a list in the context (context.joinedContexts).
|
|
1896
|
+
* @param {string} [description] - An optional description of the task.
|
|
1897
|
+
* @param {TaskOptions} [options={}] - Optional configuration for the task, such as additional metadata or task options.
|
|
1898
|
+
* @return {Task} The task instance that was created with a uniqueness constraint.
|
|
1899
|
+
*
|
|
1900
|
+
* @example
|
|
1901
|
+
* ```ts
|
|
1902
|
+
* const splitTask = Cadenza.createTask('Split foos', function* (ctx) {
|
|
1903
|
+
* for (const foo of ctx.foos) {
|
|
1904
|
+
* yield { foo };
|
|
1905
|
+
* }
|
|
1906
|
+
* }, 'Splits a list of foos into multiple sub-branches');
|
|
1907
|
+
*
|
|
1908
|
+
* const processTask = Cadenza.createTask('Process foo', (ctx) => {
|
|
1909
|
+
* return { bar: 'foo' + ctx.foo };
|
|
1910
|
+
* }, 'Process a foo');
|
|
1911
|
+
*
|
|
1912
|
+
* const uniqueTask = Cadenza.createUniqueTask('Gather processed foos', (ctx) => {
|
|
1913
|
+
* // A unique task will always be provided with a list of contexts (ctx.joinedContexts) from its predecessors.
|
|
1914
|
+
* const processedFoos = ctx.joinedContexts.map((c) => c.bar);
|
|
1915
|
+
* return { foos: processedFoos };
|
|
1916
|
+
* }, 'Gathers together the processed foos.');
|
|
1917
|
+
*
|
|
1918
|
+
* splitTask.then(
|
|
1919
|
+
* processTask.then(
|
|
1920
|
+
* uniqueTask,
|
|
1921
|
+
* ),
|
|
1922
|
+
* );
|
|
1923
|
+
*
|
|
1924
|
+
* // Give the flow a name using a routine
|
|
1925
|
+
* Cadenza.createRoutine(
|
|
1926
|
+
* 'Process foos',
|
|
1927
|
+
* [splitTask],
|
|
1928
|
+
* 'Processes a list of foos'
|
|
1929
|
+
* ).doOn('main.received_foos'); // Subscribe to a signal
|
|
1930
|
+
*
|
|
1931
|
+
* // Trigger the flow from anywhere
|
|
1932
|
+
* Cadenza.emit('main.received_foos', { foos: ['foo1', 'foo2', 'foo3'] });
|
|
1933
|
+
* ```
|
|
1934
|
+
*
|
|
890
1935
|
*/
|
|
891
1936
|
static createUniqueTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
892
1937
|
/**
|
|
893
|
-
* Creates a
|
|
894
|
-
* @
|
|
895
|
-
*
|
|
896
|
-
* @param
|
|
897
|
-
* @param
|
|
898
|
-
* @
|
|
1938
|
+
* Creates a unique meta task with the specified name, function, description, and options.
|
|
1939
|
+
* See {@link createUniqueTask} and {@link createMetaTask} for more information.
|
|
1940
|
+
*
|
|
1941
|
+
* @param {string} name - The name of the task to create.
|
|
1942
|
+
* @param {TaskFunction} func - The function to execute when the task is run.
|
|
1943
|
+
* @param {string} [description] - An optional description of the task.
|
|
1944
|
+
* @param {TaskOptions} [options={}] - Optional settings for the task. Defaults to an empty object. Automatically sets `isMeta` and `isUnique` to true.
|
|
1945
|
+
* @return {Task} The created unique meta task.
|
|
899
1946
|
*/
|
|
900
1947
|
static createUniqueMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
901
1948
|
/**
|
|
902
|
-
* Creates a
|
|
903
|
-
*
|
|
904
|
-
* @
|
|
905
|
-
*
|
|
906
|
-
* @param
|
|
907
|
-
* @param
|
|
908
|
-
* @
|
|
909
|
-
* @
|
|
1949
|
+
* Creates a throttled task with a concurrency limit of 1, ensuring that only one instance of the task can run at a time for a specific throttle tag.
|
|
1950
|
+
* This is useful for ensuring execution order and preventing race conditions.
|
|
1951
|
+
* See {@link Task} for more information.
|
|
1952
|
+
*
|
|
1953
|
+
* @param {string} name - The name of the task.
|
|
1954
|
+
* @param {TaskFunction} func - The function to be executed when the task runs.
|
|
1955
|
+
* @param {ThrottleTagGetter} [throttledIdGetter=() => "default"] - A function that generates a throttle tag identifier to group tasks for throttling.
|
|
1956
|
+
* @param {string} [description] - An optional description of the task.
|
|
1957
|
+
* @param {TaskOptions} [options={}] - Additional options to customize the task behavior.
|
|
1958
|
+
* @return {Task} The created throttled task.
|
|
1959
|
+
*
|
|
1960
|
+
* @example
|
|
1961
|
+
* ```ts
|
|
1962
|
+
* const task = Cadenza.createThrottledTask(
|
|
1963
|
+
* 'My task',
|
|
1964
|
+
* async (ctx) => {
|
|
1965
|
+
* await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1966
|
+
* console.log('My task executed with context:', ctx);
|
|
1967
|
+
* },
|
|
1968
|
+
* // Will throttle by the value of ctx.foo to make sure tasks with the same value are executed sequentially
|
|
1969
|
+
* (ctx) => ctx.foo,
|
|
1970
|
+
* );
|
|
1971
|
+
*
|
|
1972
|
+
* Cadenza.run(task, { foo: 'bar' }); // (First execution)
|
|
1973
|
+
* Cadenza.run(task, { foo: 'bar' }); // This will be executed after the first execution is finished
|
|
1974
|
+
* Cadenza.run(task, { foo: 'baz' }); // This will be executed in parallel with the first execution
|
|
1975
|
+
* ```
|
|
910
1976
|
*/
|
|
911
1977
|
static createThrottledTask(name: string, func: TaskFunction, throttledIdGetter?: ThrottleTagGetter, description?: string, options?: TaskOptions): Task;
|
|
912
1978
|
/**
|
|
913
|
-
* Creates a
|
|
914
|
-
* @
|
|
915
|
-
*
|
|
916
|
-
* @param
|
|
917
|
-
* @param
|
|
918
|
-
* @param
|
|
919
|
-
* @
|
|
1979
|
+
* Creates a throttled meta task with the specified configuration.
|
|
1980
|
+
* See {@link createThrottledTask} and {@link createMetaTask} for more information.
|
|
1981
|
+
*
|
|
1982
|
+
* @param {string} name - The name of the throttled meta task.
|
|
1983
|
+
* @param {TaskFunction} func - The task function to be executed.
|
|
1984
|
+
* @param {ThrottleTagGetter} throttledIdGetter - A function to retrieve the throttling identifier.
|
|
1985
|
+
* @param {string} [description] - An optional description of the task.
|
|
1986
|
+
* @param {TaskOptions} [options={}] - Additional options for configuring the task.
|
|
1987
|
+
* @return {Task} The created throttled meta task.
|
|
920
1988
|
*/
|
|
921
1989
|
static createThrottledMetaTask(name: string, func: TaskFunction, throttledIdGetter: ThrottleTagGetter, description?: string, options?: TaskOptions): Task;
|
|
922
1990
|
/**
|
|
923
|
-
* Creates
|
|
924
|
-
*
|
|
925
|
-
* @
|
|
926
|
-
*
|
|
927
|
-
* @param
|
|
928
|
-
* @param
|
|
929
|
-
* @
|
|
930
|
-
* @
|
|
1991
|
+
* Creates and returns a new debounced task with the specified parameters.
|
|
1992
|
+
* This is useful to prevent rapid execution of tasks that may be triggered by multiple events within a certain time frame.
|
|
1993
|
+
* See {@link DebounceTask} for more information.
|
|
1994
|
+
*
|
|
1995
|
+
* @param {string} name - The unique name of the task to be created.
|
|
1996
|
+
* @param {TaskFunction} func - The function to be executed by the task.
|
|
1997
|
+
* @param {string} [description] - An optional description of the task.
|
|
1998
|
+
* @param {number} [debounceTime=1000] - The debounce time in milliseconds to delay the execution of the task.
|
|
1999
|
+
* @param {TaskOptions & DebounceOptions} [options={}] - Additional configuration options for the task, including debounce behavior and other task properties.
|
|
2000
|
+
* @return {DebounceTask} A new instance of the DebounceTask with the specified configuration.
|
|
2001
|
+
*
|
|
2002
|
+
* @example
|
|
2003
|
+
* ```ts
|
|
2004
|
+
* const task = Cadenza.createDebounceTask(
|
|
2005
|
+
* 'My debounced task',
|
|
2006
|
+
* (ctx) => {
|
|
2007
|
+
* console.log('My task executed with context:', ctx);
|
|
2008
|
+
* },
|
|
2009
|
+
* 'My debounced task description',
|
|
2010
|
+
* 100, // Debounce time in milliseconds. Default is 1000
|
|
2011
|
+
* {
|
|
2012
|
+
* leading: false, // Should the first execution of a burst be executed immediately? Default is false
|
|
2013
|
+
* trailing: true, // Should the last execution of a burst be executed? Default is true
|
|
2014
|
+
* maxWait: 1000, // Maximum time in milliseconds to wait for the next execution. Default is 0
|
|
2015
|
+
* },
|
|
2016
|
+
* );
|
|
2017
|
+
*
|
|
2018
|
+
* Cadenza.run(task, { foo: 'bar' }); // This will not be executed
|
|
2019
|
+
* Cadenza.run(task, { foo: 'bar' }); // This will not be executed
|
|
2020
|
+
* Cadenza.run(task, { foo: 'baz' }); // This execution will be delayed by 100ms
|
|
2021
|
+
* ```
|
|
931
2022
|
*/
|
|
932
2023
|
static createDebounceTask(name: string, func: TaskFunction, description?: string, debounceTime?: number, options?: TaskOptions & DebounceOptions): DebounceTask;
|
|
933
2024
|
/**
|
|
934
|
-
* Creates a
|
|
935
|
-
* @
|
|
936
|
-
*
|
|
937
|
-
* @param
|
|
938
|
-
* @param
|
|
939
|
-
* @param
|
|
940
|
-
* @
|
|
2025
|
+
* Creates a debounced meta task with the specified parameters.
|
|
2026
|
+
* See {@link createDebounceTask} and {@link createMetaTask} for more information.
|
|
2027
|
+
*
|
|
2028
|
+
* @param {string} name - The name of the task.
|
|
2029
|
+
* @param {TaskFunction} func - The function to be executed by the task.
|
|
2030
|
+
* @param {string} [description] - Optional description of the task.
|
|
2031
|
+
* @param {number} [debounceTime=1000] - The debounce delay in milliseconds.
|
|
2032
|
+
* @param {TaskOptions & DebounceOptions} [options={}] - Additional configuration options for the task.
|
|
2033
|
+
* @return {DebounceTask} Returns an instance of the debounced meta task.
|
|
941
2034
|
*/
|
|
942
2035
|
static createDebounceMetaTask(name: string, func: TaskFunction, description?: string, debounceTime?: number, options?: TaskOptions & DebounceOptions): DebounceTask;
|
|
943
2036
|
/**
|
|
944
|
-
* Creates an
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
* @
|
|
949
|
-
*
|
|
950
|
-
* @
|
|
951
|
-
* @
|
|
2037
|
+
* Creates an ephemeral task with the specified configuration.
|
|
2038
|
+
* Ephemeral tasks are designed to self-destruct after execution or a certain condition is met.
|
|
2039
|
+
* This is useful for transient tasks such as resolving promises or performing cleanup operations.
|
|
2040
|
+
* They are not registered by default.
|
|
2041
|
+
* See {@link EphemeralTask} for more information.
|
|
2042
|
+
*
|
|
2043
|
+
* @param {string} name - The name of the task to be created.
|
|
2044
|
+
* @param {TaskFunction} func - The function that defines the logic of the task.
|
|
2045
|
+
* @param {string} [description] - An optional description of the task.
|
|
2046
|
+
* @param {TaskOptions & EphemeralTaskOptions} [options={}] - The configuration options for the task, including concurrency, timeouts, and retry policies.
|
|
2047
|
+
* @return {EphemeralTask} The created ephemeral task instance.
|
|
2048
|
+
*
|
|
2049
|
+
* @example
|
|
2050
|
+
* By default, ephemeral tasks are executed once and destroyed after execution.
|
|
2051
|
+
* ```ts
|
|
2052
|
+
* const task = Cadenza.createEphemeralTask('My ephemeral task', (ctx) => {
|
|
2053
|
+
* console.log('My task executed with context:', ctx);
|
|
2054
|
+
* });
|
|
2055
|
+
*
|
|
2056
|
+
* Cadenza.run(task); // Executes the task once and destroys it after execution
|
|
2057
|
+
* Cadenza.run(task); // Does nothing, since the task is destroyed
|
|
2058
|
+
* ```
|
|
2059
|
+
*
|
|
2060
|
+
* Use destroy condition to conditionally destroy the task
|
|
2061
|
+
* ```ts
|
|
2062
|
+
* const task = Cadenza.createEphemeralTask(
|
|
2063
|
+
* 'My ephemeral task',
|
|
2064
|
+
* (ctx) => {
|
|
2065
|
+
* console.log('My task executed with context:', ctx);
|
|
2066
|
+
* },
|
|
2067
|
+
* 'My ephemeral task description',
|
|
2068
|
+
* {
|
|
2069
|
+
* once: false, // Should the task be executed only once? Default is true
|
|
2070
|
+
* destroyCondition: (ctx) => ctx.foo > 10, // Should the task be destroyed after execution? Default is undefined
|
|
2071
|
+
* },
|
|
2072
|
+
* );
|
|
2073
|
+
*
|
|
2074
|
+
* Cadenza.run(task, { foo: 5 }); // The task will not be destroyed and can still be executed
|
|
2075
|
+
* Cadenza.run(task, { foo: 10 }); // The task will not be destroyed and can still be executed
|
|
2076
|
+
* Cadenza.run(task, { foo: 20 }); // The task will be destroyed after execution and cannot be executed anymore
|
|
2077
|
+
* Cadenza.run(task, { foo: 30 }); // This will not be executed
|
|
2078
|
+
* ```
|
|
2079
|
+
*
|
|
2080
|
+
* A practical use case for ephemeral tasks is to resolve a promise upon some external event.
|
|
2081
|
+
* ```ts
|
|
2082
|
+
* const task = Cadenza.createTask('Confirm something', (ctx, emit) => {
|
|
2083
|
+
* return new Promise((resolve) => {
|
|
2084
|
+
* ctx.foo = uuid();
|
|
2085
|
+
*
|
|
2086
|
+
* Cadenza.createEphemeralTask(`Resolve promise of ${ctx.foo}`, (c) => {
|
|
2087
|
+
* console.log('My task executed with context:', ctx);
|
|
2088
|
+
* resolve(c);
|
|
2089
|
+
* }).doOn(`socket.confirmation_received:${ctx.foo}`);
|
|
2090
|
+
*
|
|
2091
|
+
* emit('this_domain.confirmation_requested', ctx);
|
|
2092
|
+
* });
|
|
2093
|
+
* });
|
|
2094
|
+
* ```
|
|
952
2095
|
*/
|
|
953
2096
|
static createEphemeralTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions & EphemeralTaskOptions): EphemeralTask;
|
|
954
2097
|
/**
|
|
955
|
-
* Creates an
|
|
956
|
-
* @
|
|
957
|
-
*
|
|
958
|
-
* @param
|
|
959
|
-
* @param
|
|
960
|
-
* @
|
|
2098
|
+
* Creates an ephemeral meta task with the specified name, function, description, and options.
|
|
2099
|
+
* See {@link createEphemeralTask} and {@link createMetaTask} for more details.
|
|
2100
|
+
*
|
|
2101
|
+
* @param {string} name - The name of the task to be created.
|
|
2102
|
+
* @param {TaskFunction} func - The function to be executed as part of the task.
|
|
2103
|
+
* @param {string} [description] - An optional description of the task.
|
|
2104
|
+
* @param {TaskOptions & EphemeralTaskOptions} [options={}] - Additional options for configuring the task.
|
|
2105
|
+
* @return {EphemeralTask} The created ephemeral meta task.
|
|
961
2106
|
*/
|
|
962
2107
|
static createEphemeralMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions & EphemeralTaskOptions): EphemeralTask;
|
|
963
2108
|
/**
|
|
964
|
-
* Creates a
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
* @
|
|
968
|
-
*
|
|
969
|
-
* @
|
|
2109
|
+
* Creates a new routine with the specified name, tasks, and an optional description.
|
|
2110
|
+
* Routines are named entry points to starting tasks and are registered in the GraphRegistry.
|
|
2111
|
+
* They are used to group tasks together and provide a high-level structure for organizing and managing the execution of a set of tasks.
|
|
2112
|
+
* See {@link GraphRoutine} for more information.
|
|
2113
|
+
*
|
|
2114
|
+
* @param {string} name - The name of the routine to create.
|
|
2115
|
+
* @param {Task[]} tasks - A list of tasks to include in the routine.
|
|
2116
|
+
* @param {string} [description=""] - An optional description for the routine.
|
|
2117
|
+
* @return {GraphRoutine} A new instance of the GraphRoutine containing the specified tasks and description.
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```ts
|
|
2121
|
+
* const task1 = Cadenza.createTask("Task 1", () => {});
|
|
2122
|
+
* const task2 = Cadenza.createTask("Task 2", () => {});
|
|
2123
|
+
*
|
|
2124
|
+
* task1.then(task2);
|
|
2125
|
+
*
|
|
2126
|
+
* const routine = Cadenza.createRoutine("Some routine", [task1]);
|
|
2127
|
+
*
|
|
2128
|
+
* Cadenza.run(routine);
|
|
2129
|
+
*
|
|
2130
|
+
* // Or, routines can be triggered by signals
|
|
2131
|
+
* routine.doOn("some.signal");
|
|
2132
|
+
*
|
|
2133
|
+
* Cadenza.emit("some.signal", {});
|
|
2134
|
+
* ```
|
|
970
2135
|
*/
|
|
971
2136
|
static createRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
|
|
972
2137
|
/**
|
|
973
|
-
* Creates a
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
* @
|
|
977
|
-
*
|
|
2138
|
+
* Creates a meta routine with a given name, tasks, and optional description.
|
|
2139
|
+
* Routines are named entry points to starting tasks and are registered in the GraphRegistry.
|
|
2140
|
+
* They are used to group tasks together and provide a high-level structure for organizing and managing the execution of a set of tasks.
|
|
2141
|
+
* See {@link GraphRoutine} and {@link createRoutine} for more information.
|
|
2142
|
+
*
|
|
2143
|
+
* @param {string} name - The name of the routine to be created.
|
|
2144
|
+
* @param {Task[]} tasks - An array of tasks that the routine will consist of.
|
|
2145
|
+
* @param {string} [description=""] - An optional description for the routine.
|
|
2146
|
+
* @return {GraphRoutine} A new instance of the `GraphRoutine` representing the created routine.
|
|
2147
|
+
* @throws {Error} If no starting tasks are provided.
|
|
978
2148
|
*/
|
|
979
2149
|
static createMetaRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
|
|
980
2150
|
static reset(): void;
|