@cadenza.io/core 3.9.2 → 3.11.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 +1370 -184
- package/dist/index.d.ts +1370 -184
- package/dist/index.js +1408 -206
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1408 -206
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
type AnyObject = {
|
|
2
2
|
[key: string | number]: any;
|
|
3
3
|
};
|
|
4
|
+
interface ThrottleHandle {
|
|
5
|
+
/** Stop the repeating emission */
|
|
6
|
+
clear(): void;
|
|
7
|
+
}
|
|
4
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
|
+
*/
|
|
5
16
|
declare class GraphContext {
|
|
6
17
|
readonly id: string;
|
|
7
18
|
readonly fullContext: AnyObject;
|
|
@@ -13,12 +24,22 @@ declare class GraphContext {
|
|
|
13
24
|
* @returns Frozen user context.
|
|
14
25
|
*/
|
|
15
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
|
+
*/
|
|
16
32
|
getClonedContext(): AnyObject;
|
|
17
33
|
/**
|
|
18
34
|
* Gets full raw context (cloned for safety).
|
|
19
35
|
* @returns Cloned full context.
|
|
20
36
|
*/
|
|
21
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
|
+
*/
|
|
22
43
|
getClonedFullContext(): AnyObject;
|
|
23
44
|
/**
|
|
24
45
|
* Gets frozen metadata (read-only).
|
|
@@ -37,10 +58,11 @@ declare class GraphContext {
|
|
|
37
58
|
*/
|
|
38
59
|
mutate(context: AnyObject): GraphContext;
|
|
39
60
|
/**
|
|
40
|
-
* Combines with another
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
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.
|
|
44
66
|
*/
|
|
45
67
|
combine(otherContext: GraphContext): GraphContext;
|
|
46
68
|
/**
|
|
@@ -53,6 +75,10 @@ declare class GraphContext {
|
|
|
53
75
|
};
|
|
54
76
|
}
|
|
55
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
|
+
*/
|
|
56
82
|
declare abstract class Iterator {
|
|
57
83
|
abstract hasNext(): boolean;
|
|
58
84
|
abstract hasPrevious?(): boolean;
|
|
@@ -62,6 +88,11 @@ declare abstract class Iterator {
|
|
|
62
88
|
abstract getLast?(): any;
|
|
63
89
|
}
|
|
64
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
|
+
*/
|
|
65
96
|
declare abstract class Graph {
|
|
66
97
|
/**
|
|
67
98
|
* Executes this graph node/task.
|
|
@@ -96,6 +127,10 @@ declare abstract class Graph {
|
|
|
96
127
|
abstract getIterator(): Iterator;
|
|
97
128
|
}
|
|
98
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
|
+
*/
|
|
99
134
|
declare class GraphNodeIterator implements Iterator {
|
|
100
135
|
currentNode: GraphNode | undefined;
|
|
101
136
|
currentLayer: GraphNode[];
|
|
@@ -106,6 +141,10 @@ declare class GraphNodeIterator implements Iterator {
|
|
|
106
141
|
next(): any;
|
|
107
142
|
}
|
|
108
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Abstract class representing a signal emitter.
|
|
146
|
+
* Allows emitting events or signals, with the option to suppress emissions if desired.
|
|
147
|
+
*/
|
|
109
148
|
declare abstract class SignalEmitter {
|
|
110
149
|
silent: boolean;
|
|
111
150
|
/**
|
|
@@ -127,6 +166,11 @@ declare abstract class SignalEmitter {
|
|
|
127
166
|
emitMetrics(signal: string, data?: AnyObject): void;
|
|
128
167
|
}
|
|
129
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
|
+
*/
|
|
130
174
|
declare abstract class ExecutionChain {
|
|
131
175
|
next: ExecutionChain | undefined;
|
|
132
176
|
previous: ExecutionChain | undefined;
|
|
@@ -138,6 +182,13 @@ declare abstract class ExecutionChain {
|
|
|
138
182
|
decouple(): void;
|
|
139
183
|
}
|
|
140
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
|
+
*/
|
|
141
192
|
declare class GraphLayerIterator implements Iterator {
|
|
142
193
|
graph: GraphLayer;
|
|
143
194
|
currentLayer: GraphLayer | undefined;
|
|
@@ -150,6 +201,16 @@ declare class GraphLayerIterator implements Iterator {
|
|
|
150
201
|
getLast(): GraphLayer;
|
|
151
202
|
}
|
|
152
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
|
+
*/
|
|
153
214
|
declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
154
215
|
readonly index: number;
|
|
155
216
|
nodes: GraphNode[];
|
|
@@ -157,20 +218,104 @@ declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
|
157
218
|
executionStart: number;
|
|
158
219
|
debug: boolean;
|
|
159
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
|
+
*/
|
|
160
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
|
+
*/
|
|
161
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
|
+
*/
|
|
162
240
|
get hasPreceding(): boolean;
|
|
163
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
|
+
*/
|
|
164
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
|
+
*/
|
|
165
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
|
+
*/
|
|
166
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
|
+
*/
|
|
167
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
|
+
*/
|
|
168
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
|
+
*/
|
|
169
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
|
+
*/
|
|
170
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
|
+
*/
|
|
171
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
|
+
*/
|
|
172
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
|
+
*/
|
|
173
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
|
+
*/
|
|
174
319
|
accept(visitor: GraphVisitor): void;
|
|
175
320
|
export(): {
|
|
176
321
|
__index: number;
|
|
@@ -183,9 +328,24 @@ declare abstract class GraphLayer extends ExecutionChain implements Graph {
|
|
|
183
328
|
log(): void;
|
|
184
329
|
}
|
|
185
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
|
+
*/
|
|
186
345
|
declare class GraphNode extends SignalEmitter implements Graph {
|
|
187
346
|
id: string;
|
|
188
347
|
routineExecId: string;
|
|
348
|
+
executionTraceId: string;
|
|
189
349
|
task: Task;
|
|
190
350
|
context: GraphContext;
|
|
191
351
|
layer: GraphLayer | undefined;
|
|
@@ -215,45 +375,311 @@ declare class GraphNode extends SignalEmitter implements Graph {
|
|
|
215
375
|
isProcessing(): boolean;
|
|
216
376
|
subgraphDone(): boolean;
|
|
217
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
|
+
*/
|
|
218
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
|
+
*/
|
|
219
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
|
+
*/
|
|
220
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
|
+
*/
|
|
221
406
|
sharesContextWith(node: GraphNode): boolean;
|
|
222
407
|
getLayerIndex(): number;
|
|
223
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
|
+
*/
|
|
224
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
|
+
*/
|
|
225
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
|
+
*/
|
|
226
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
|
+
*/
|
|
227
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
|
+
*/
|
|
228
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
|
+
*/
|
|
229
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
|
+
*/
|
|
230
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
|
+
*/
|
|
231
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
|
+
*/
|
|
232
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
|
+
*/
|
|
233
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
|
+
*/
|
|
234
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
|
+
*/
|
|
235
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
|
+
*/
|
|
236
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
|
+
*/
|
|
237
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
|
+
*/
|
|
238
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
|
+
*/
|
|
239
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
|
+
*/
|
|
240
563
|
retryAsync(prevResult?: any): Promise<TaskResult>;
|
|
241
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
|
+
*/
|
|
242
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
|
+
*/
|
|
243
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
|
+
*/
|
|
244
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
|
+
*/
|
|
245
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
|
+
*/
|
|
246
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
|
+
*/
|
|
247
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
|
+
*/
|
|
248
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
|
+
*/
|
|
249
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
|
+
*/
|
|
250
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
|
+
*/
|
|
251
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
|
+
*/
|
|
252
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
|
+
*/
|
|
253
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
|
+
*/
|
|
254
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
|
+
*/
|
|
255
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
|
+
*/
|
|
256
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
|
+
*/
|
|
257
683
|
export(): {
|
|
258
684
|
__id: string;
|
|
259
685
|
__task: AnyObject;
|
|
@@ -310,6 +736,11 @@ declare abstract class GraphVisitor {
|
|
|
310
736
|
abstract visitTask(task: Task): any;
|
|
311
737
|
}
|
|
312
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
|
+
*/
|
|
313
744
|
declare class TaskIterator implements Iterator {
|
|
314
745
|
currentTask: Task | undefined;
|
|
315
746
|
currentLayer: Set<Task>;
|
|
@@ -351,6 +782,12 @@ type SchemaDefinition = {
|
|
|
351
782
|
type TaskFunction = (context: AnyObject, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void) => TaskResult;
|
|
352
783
|
type TaskResult = boolean | AnyObject | Generator | Promise<any> | void;
|
|
353
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
|
+
*/
|
|
354
791
|
declare class Task extends SignalEmitter implements Graph {
|
|
355
792
|
readonly name: string;
|
|
356
793
|
readonly description: string;
|
|
@@ -388,29 +825,36 @@ declare class Task extends SignalEmitter implements Graph {
|
|
|
388
825
|
observedSignals: Set<string>;
|
|
389
826
|
readonly taskFunction: TaskFunction;
|
|
390
827
|
/**
|
|
391
|
-
* Constructs
|
|
392
|
-
*
|
|
393
|
-
* @param task
|
|
394
|
-
* @param
|
|
395
|
-
* @param
|
|
396
|
-
* @param
|
|
397
|
-
* @param
|
|
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
|
-
* @
|
|
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.
|
|
412
849
|
*/
|
|
413
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
|
+
*/
|
|
414
858
|
getTag(context?: AnyObject): string;
|
|
415
859
|
setVersion(version: number): void;
|
|
416
860
|
setTimeout(timeout: number): void;
|
|
@@ -420,114 +864,316 @@ declare class Task extends SignalEmitter implements Graph {
|
|
|
420
864
|
setOutputContextSchema(schema: SchemaDefinition): void;
|
|
421
865
|
setValidateInputContext(value: boolean): void;
|
|
422
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
|
+
*/
|
|
423
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
|
+
*/
|
|
424
886
|
emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
|
|
425
887
|
/**
|
|
426
|
-
* Validates a
|
|
427
|
-
*
|
|
428
|
-
* @param
|
|
429
|
-
* @param
|
|
430
|
-
* @
|
|
431
|
-
* @
|
|
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.
|
|
432
895
|
*/
|
|
433
896
|
validateSchema(data: any, schema: SchemaDefinition | undefined, path?: string): {
|
|
434
897
|
valid: boolean;
|
|
435
898
|
errors: Record<string, string>;
|
|
436
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
|
+
*/
|
|
437
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
|
+
*/
|
|
438
914
|
validateOutput(context: AnyObject): true | AnyObject;
|
|
439
915
|
/**
|
|
440
|
-
* Executes
|
|
441
|
-
*
|
|
442
|
-
* @param
|
|
443
|
-
* @param
|
|
444
|
-
* @param
|
|
445
|
-
* @
|
|
446
|
-
* @
|
|
447
|
-
* @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.
|
|
448
923
|
*/
|
|
449
924
|
execute(context: GraphContext, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void, nodeData: {
|
|
450
925
|
nodeId: string;
|
|
451
926
|
routineExecId: string;
|
|
452
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
|
+
*/
|
|
453
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
|
+
*/
|
|
454
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
|
+
*/
|
|
455
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
|
+
*/
|
|
456
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
|
+
*/
|
|
457
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
|
+
*/
|
|
458
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
|
+
*/
|
|
459
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
|
+
*/
|
|
460
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
|
+
*/
|
|
461
999
|
mapPrevious(callback: (task: Task) => any): any[];
|
|
462
1000
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
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.
|
|
467
1007
|
*/
|
|
468
1008
|
doOn(...signals: string[]): this;
|
|
469
1009
|
/**
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
* @
|
|
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.
|
|
473
1014
|
*/
|
|
474
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
|
+
*/
|
|
475
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
|
+
*/
|
|
476
1031
|
attachSignal(signal: string, isOnFail?: boolean): void;
|
|
477
1032
|
/**
|
|
478
|
-
* Unsubscribes from
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
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.
|
|
482
1039
|
*/
|
|
483
1040
|
unsubscribe(...signals: string[]): this;
|
|
484
1041
|
/**
|
|
485
|
-
* Unsubscribes from all observed signals.
|
|
486
|
-
*
|
|
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.
|
|
487
1045
|
*/
|
|
488
1046
|
unsubscribeAll(): this;
|
|
489
1047
|
/**
|
|
490
|
-
* Detaches
|
|
491
|
-
*
|
|
492
|
-
* @
|
|
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.
|
|
493
1052
|
*/
|
|
494
1053
|
detachSignals(...signals: string[]): this;
|
|
495
1054
|
/**
|
|
496
|
-
* Detaches all
|
|
497
|
-
*
|
|
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.
|
|
498
1059
|
*/
|
|
499
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
|
+
*/
|
|
500
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
|
+
*/
|
|
501
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
|
+
*/
|
|
502
1083
|
mapObservedSignals(callback: (signal: string) => void): void[];
|
|
503
1084
|
/**
|
|
504
|
-
* Emits
|
|
505
|
-
*
|
|
506
|
-
* @
|
|
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.
|
|
507
1089
|
*/
|
|
508
1090
|
emitSignals(context: GraphContext): void;
|
|
509
1091
|
/**
|
|
510
|
-
* Emits
|
|
511
|
-
*
|
|
512
|
-
* @
|
|
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.
|
|
513
1096
|
*/
|
|
514
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
|
+
*/
|
|
515
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
|
+
*/
|
|
516
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
|
+
*/
|
|
517
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
|
+
*/
|
|
518
1137
|
accept(visitor: GraphVisitor): void;
|
|
519
1138
|
log(): void;
|
|
520
1139
|
}
|
|
521
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
|
+
*/
|
|
522
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
|
+
*/
|
|
523
1155
|
execute(): GraphNode[];
|
|
524
1156
|
}
|
|
525
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
|
+
*/
|
|
526
1163
|
declare abstract class GraphExporter {
|
|
527
1164
|
abstract exportGraph(graph: SyncGraphLayer): any;
|
|
528
1165
|
abstract exportStaticGraph(graph: Task[]): any;
|
|
529
1166
|
}
|
|
530
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
|
+
*/
|
|
531
1177
|
declare abstract class GraphBuilder {
|
|
532
1178
|
graph: GraphLayer | undefined;
|
|
533
1179
|
topLayerIndex: number;
|
|
@@ -535,15 +1181,62 @@ declare abstract class GraphBuilder {
|
|
|
535
1181
|
debug: boolean;
|
|
536
1182
|
setDebug(value: boolean): void;
|
|
537
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
|
+
*/
|
|
538
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
|
+
*/
|
|
539
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
|
+
*/
|
|
540
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
|
+
*/
|
|
541
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
|
+
*/
|
|
542
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
|
+
*/
|
|
543
1230
|
getLayer(layerIndex: number): GraphLayer;
|
|
544
1231
|
reset(): void;
|
|
545
1232
|
}
|
|
546
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
|
+
*/
|
|
547
1240
|
declare abstract class GraphRunStrategy {
|
|
548
1241
|
graphBuilder: GraphBuilder;
|
|
549
1242
|
runInstance?: GraphRun;
|
|
@@ -563,6 +1256,10 @@ interface RunJson {
|
|
|
563
1256
|
__graph: any;
|
|
564
1257
|
__data: any;
|
|
565
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
|
+
*/
|
|
566
1263
|
declare class GraphRun {
|
|
567
1264
|
readonly id: string;
|
|
568
1265
|
graph: GraphLayer | undefined;
|
|
@@ -578,6 +1275,13 @@ declare class GraphRun {
|
|
|
578
1275
|
setExporter(exporter: GraphExporter): void;
|
|
579
1276
|
}
|
|
580
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
|
+
*/
|
|
581
1285
|
declare class GraphRoutine extends SignalEmitter {
|
|
582
1286
|
readonly name: string;
|
|
583
1287
|
version: number;
|
|
@@ -588,9 +1292,12 @@ declare class GraphRoutine extends SignalEmitter {
|
|
|
588
1292
|
observedSignals: Set<string>;
|
|
589
1293
|
constructor(name: string, tasks: Task[], description: string, isMeta?: boolean);
|
|
590
1294
|
/**
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
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.
|
|
594
1301
|
*/
|
|
595
1302
|
forEachTask(callBack: (task: Task) => any): Promise<void>;
|
|
596
1303
|
/**
|
|
@@ -599,30 +1306,42 @@ declare class GraphRoutine extends SignalEmitter {
|
|
|
599
1306
|
*/
|
|
600
1307
|
setVersion(version: number): void;
|
|
601
1308
|
/**
|
|
602
|
-
* Subscribes to signals
|
|
603
|
-
*
|
|
604
|
-
* @
|
|
605
|
-
* @
|
|
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.
|
|
606
1313
|
*/
|
|
607
1314
|
doOn(...signals: string[]): this;
|
|
608
1315
|
/**
|
|
609
|
-
* Unsubscribes from all observed signals
|
|
610
|
-
*
|
|
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.
|
|
611
1321
|
*/
|
|
612
1322
|
unsubscribeAll(): this;
|
|
613
1323
|
/**
|
|
614
|
-
* Unsubscribes from
|
|
615
|
-
*
|
|
616
|
-
* @
|
|
617
|
-
* @
|
|
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.
|
|
618
1328
|
*/
|
|
619
1329
|
unsubscribe(...signals: string[]): this;
|
|
620
1330
|
/**
|
|
621
|
-
*
|
|
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}
|
|
622
1337
|
*/
|
|
623
1338
|
destroy(): void;
|
|
624
1339
|
}
|
|
625
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
|
+
*/
|
|
626
1345
|
declare class GraphRunner extends SignalEmitter {
|
|
627
1346
|
currentRun: GraphRun;
|
|
628
1347
|
debug: boolean;
|
|
@@ -638,42 +1357,74 @@ declare class GraphRunner extends SignalEmitter {
|
|
|
638
1357
|
constructor(isMeta?: boolean);
|
|
639
1358
|
init(): void;
|
|
640
1359
|
/**
|
|
641
|
-
* Adds tasks
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* @
|
|
645
|
-
*
|
|
646
|
-
* @
|
|
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.
|
|
647
1368
|
*/
|
|
648
1369
|
addTasks(tasks: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): void;
|
|
649
1370
|
/**
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
* @
|
|
654
|
-
* @
|
|
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.
|
|
655
1377
|
*/
|
|
656
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
|
+
*/
|
|
657
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
|
+
*/
|
|
658
1393
|
reset(): GraphRun;
|
|
659
1394
|
setDebug(value: boolean): void;
|
|
660
1395
|
setVerbose(value: boolean): void;
|
|
661
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
|
+
*/
|
|
662
1404
|
setStrategy(strategy: GraphRunStrategy): void;
|
|
663
1405
|
startRun(context: AnyObject, emit: (signal: string, ctx: AnyObject) => void): boolean;
|
|
664
1406
|
}
|
|
665
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
|
+
*/
|
|
666
1412
|
declare class SignalBroker {
|
|
667
1413
|
static instance_: SignalBroker;
|
|
668
|
-
/**
|
|
669
|
-
* Singleton instance for signal management.
|
|
670
|
-
* @returns The broker instance.
|
|
671
|
-
*/
|
|
672
1414
|
static get instance(): SignalBroker;
|
|
673
1415
|
debug: boolean;
|
|
674
1416
|
verbose: boolean;
|
|
675
1417
|
setDebug(value: boolean): void;
|
|
676
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
|
+
*/
|
|
677
1428
|
validateSignalName(signalName: string): void;
|
|
678
1429
|
runner: GraphRunner | undefined;
|
|
679
1430
|
metaRunner: GraphRunner | undefined;
|
|
@@ -693,6 +1444,11 @@ declare class SignalBroker {
|
|
|
693
1444
|
* @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
|
|
694
1445
|
*/
|
|
695
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
|
+
*/
|
|
696
1452
|
init(): void;
|
|
697
1453
|
/**
|
|
698
1454
|
* Observes a signal with a routine/task.
|
|
@@ -709,15 +1465,64 @@ declare class SignalBroker {
|
|
|
709
1465
|
*/
|
|
710
1466
|
unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
|
|
711
1467
|
/**
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
* @param
|
|
715
|
-
* @
|
|
716
|
-
* @
|
|
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
|
+
*/
|
|
1476
|
+
schedule(signal: string, context: AnyObject, timeoutMs?: number, exactDateTime?: Date): AbortController;
|
|
1477
|
+
/**
|
|
1478
|
+
* Emits `signal` repeatedly with a fixed interval.
|
|
1479
|
+
*
|
|
1480
|
+
* @param signal
|
|
1481
|
+
* @param context
|
|
1482
|
+
* @param intervalMs
|
|
1483
|
+
* @param leading If true, emits immediately (unless a startDateTime is given and we are before it).
|
|
1484
|
+
* @param startDateTime Optional absolute Date when the *first* emission after `leading` should occur.
|
|
1485
|
+
* @returns a handle with `clear()` to stop the loop.
|
|
1486
|
+
*/
|
|
1487
|
+
throttle(signal: string, context: AnyObject, intervalMs?: number, leading?: boolean, startDateTime?: Date): ThrottleHandle;
|
|
1488
|
+
/**
|
|
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.
|
|
717
1495
|
*/
|
|
718
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
|
+
*/
|
|
719
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
|
+
*/
|
|
720
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
|
+
*/
|
|
721
1526
|
addSignal(signal: string): void;
|
|
722
1527
|
/**
|
|
723
1528
|
* Lists all observed signals.
|
|
@@ -727,6 +1532,10 @@ declare class SignalBroker {
|
|
|
727
1532
|
reset(): void;
|
|
728
1533
|
}
|
|
729
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
|
+
*/
|
|
730
1539
|
declare class GraphRegistry {
|
|
731
1540
|
static _instance: GraphRegistry;
|
|
732
1541
|
static get instance(): GraphRegistry;
|
|
@@ -745,6 +1554,16 @@ declare class GraphRegistry {
|
|
|
745
1554
|
getAllRoutines: Task;
|
|
746
1555
|
doForEachRoutine: Task;
|
|
747
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
|
+
*/
|
|
748
1567
|
constructor();
|
|
749
1568
|
reset(): void;
|
|
750
1569
|
}
|
|
@@ -754,6 +1573,11 @@ interface DebounceOptions {
|
|
|
754
1573
|
trailing?: boolean;
|
|
755
1574
|
maxWait?: number;
|
|
756
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
|
+
*/
|
|
757
1581
|
declare class DebounceTask extends Task {
|
|
758
1582
|
readonly debounceTime: number;
|
|
759
1583
|
leading: boolean;
|
|
@@ -769,8 +1593,37 @@ declare class DebounceTask extends Task {
|
|
|
769
1593
|
lastProgressCallback: ((progress: number) => void) | null;
|
|
770
1594
|
lastEmitFunction: ((signal: string, context: any) => void) | null;
|
|
771
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
|
+
*/
|
|
772
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
|
+
*/
|
|
773
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
|
+
*/
|
|
774
1627
|
execute(context: GraphContext, emit: (signal: string, context: any) => void, progressCallback: (progress: number) => void): TaskResult;
|
|
775
1628
|
}
|
|
776
1629
|
|
|
@@ -778,25 +1631,66 @@ type EphemeralTaskOptions = {
|
|
|
778
1631
|
once?: boolean;
|
|
779
1632
|
destroyCondition?: (context: any) => boolean;
|
|
780
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
|
+
*/
|
|
781
1643
|
declare class EphemeralTask extends Task {
|
|
782
1644
|
readonly once: boolean;
|
|
783
1645
|
readonly condition: (context: any) => boolean;
|
|
784
1646
|
readonly isEphemeral: boolean;
|
|
785
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
|
+
*/
|
|
786
1657
|
execute(context: any, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void, nodeData: {
|
|
787
1658
|
nodeId: string;
|
|
788
1659
|
routineExecId: string;
|
|
789
1660
|
}): TaskResult;
|
|
790
1661
|
}
|
|
791
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
|
+
*/
|
|
792
1668
|
declare class GraphAsyncRun extends GraphRunStrategy {
|
|
793
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
|
+
*/
|
|
794
1676
|
run(): Promise<void>;
|
|
795
1677
|
reset(): void;
|
|
796
1678
|
export(): any;
|
|
797
1679
|
}
|
|
798
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
|
+
*/
|
|
799
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
|
+
*/
|
|
800
1694
|
run(): void;
|
|
801
1695
|
export(): any;
|
|
802
1696
|
}
|
|
@@ -820,6 +1714,11 @@ interface TaskOptions {
|
|
|
820
1714
|
retryDelayFactor?: number;
|
|
821
1715
|
}
|
|
822
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
|
+
*/
|
|
823
1722
|
declare class Cadenza {
|
|
824
1723
|
static broker: SignalBroker;
|
|
825
1724
|
static runner: GraphRunner;
|
|
@@ -827,138 +1726,425 @@ declare class Cadenza {
|
|
|
827
1726
|
static registry: GraphRegistry;
|
|
828
1727
|
static isBootstrapped: boolean;
|
|
829
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
|
+
*/
|
|
830
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
|
+
*/
|
|
831
1744
|
static get runStrategy(): {
|
|
832
1745
|
PARALLEL: GraphAsyncRun;
|
|
833
1746
|
SEQUENTIAL: GraphStandardRun;
|
|
834
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
|
+
*/
|
|
835
1756
|
static setMode(mode: CadenzaMode): void;
|
|
836
1757
|
/**
|
|
837
|
-
* Validates
|
|
838
|
-
*
|
|
839
|
-
*
|
|
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.
|
|
840
1764
|
*/
|
|
841
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
|
+
*/
|
|
842
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
|
+
*/
|
|
843
1801
|
static emit(event: string, data?: AnyObject): void;
|
|
844
1802
|
/**
|
|
845
|
-
* Creates a
|
|
846
|
-
*
|
|
847
|
-
* @
|
|
848
|
-
*
|
|
849
|
-
* @param
|
|
850
|
-
* @
|
|
851
|
-
* @
|
|
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
|
+
* ```
|
|
852
1873
|
*/
|
|
853
1874
|
static createTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
854
1875
|
/**
|
|
855
|
-
* Creates a
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
* @
|
|
859
|
-
*
|
|
860
|
-
* @param
|
|
861
|
-
* @
|
|
862
|
-
* @
|
|
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.
|
|
863
1886
|
*/
|
|
864
1887
|
static createMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
865
1888
|
/**
|
|
866
|
-
* Creates a
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
* @
|
|
870
|
-
*
|
|
871
|
-
* @param
|
|
872
|
-
* @
|
|
873
|
-
* @
|
|
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
|
+
*
|
|
874
1935
|
*/
|
|
875
1936
|
static createUniqueTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
876
1937
|
/**
|
|
877
|
-
* Creates a
|
|
878
|
-
* @
|
|
879
|
-
*
|
|
880
|
-
* @param
|
|
881
|
-
* @param
|
|
882
|
-
* @
|
|
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.
|
|
883
1946
|
*/
|
|
884
1947
|
static createUniqueMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
|
|
885
1948
|
/**
|
|
886
|
-
* Creates a
|
|
887
|
-
*
|
|
888
|
-
* @
|
|
889
|
-
*
|
|
890
|
-
* @param
|
|
891
|
-
* @param
|
|
892
|
-
* @
|
|
893
|
-
* @
|
|
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
|
+
* ```
|
|
894
1976
|
*/
|
|
895
1977
|
static createThrottledTask(name: string, func: TaskFunction, throttledIdGetter?: ThrottleTagGetter, description?: string, options?: TaskOptions): Task;
|
|
896
1978
|
/**
|
|
897
|
-
* Creates a
|
|
898
|
-
* @
|
|
899
|
-
*
|
|
900
|
-
* @param
|
|
901
|
-
* @param
|
|
902
|
-
* @param
|
|
903
|
-
* @
|
|
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.
|
|
904
1988
|
*/
|
|
905
1989
|
static createThrottledMetaTask(name: string, func: TaskFunction, throttledIdGetter: ThrottleTagGetter, description?: string, options?: TaskOptions): Task;
|
|
906
1990
|
/**
|
|
907
|
-
* Creates
|
|
908
|
-
*
|
|
909
|
-
* @
|
|
910
|
-
*
|
|
911
|
-
* @param
|
|
912
|
-
* @param
|
|
913
|
-
* @
|
|
914
|
-
* @
|
|
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
|
+
* ```
|
|
915
2022
|
*/
|
|
916
2023
|
static createDebounceTask(name: string, func: TaskFunction, description?: string, debounceTime?: number, options?: TaskOptions & DebounceOptions): DebounceTask;
|
|
917
2024
|
/**
|
|
918
|
-
* Creates a
|
|
919
|
-
* @
|
|
920
|
-
*
|
|
921
|
-
* @param
|
|
922
|
-
* @param
|
|
923
|
-
* @param
|
|
924
|
-
* @
|
|
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.
|
|
925
2034
|
*/
|
|
926
2035
|
static createDebounceMetaTask(name: string, func: TaskFunction, description?: string, debounceTime?: number, options?: TaskOptions & DebounceOptions): DebounceTask;
|
|
927
2036
|
/**
|
|
928
|
-
* Creates an
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
* @
|
|
933
|
-
*
|
|
934
|
-
* @
|
|
935
|
-
* @
|
|
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
|
+
* ```
|
|
936
2095
|
*/
|
|
937
2096
|
static createEphemeralTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions & EphemeralTaskOptions): EphemeralTask;
|
|
938
2097
|
/**
|
|
939
|
-
* Creates an
|
|
940
|
-
* @
|
|
941
|
-
*
|
|
942
|
-
* @param
|
|
943
|
-
* @param
|
|
944
|
-
* @
|
|
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.
|
|
945
2106
|
*/
|
|
946
2107
|
static createEphemeralMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions & EphemeralTaskOptions): EphemeralTask;
|
|
947
2108
|
/**
|
|
948
|
-
* Creates a
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
* @
|
|
952
|
-
*
|
|
953
|
-
* @
|
|
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
|
+
* ```
|
|
954
2135
|
*/
|
|
955
2136
|
static createRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
|
|
956
2137
|
/**
|
|
957
|
-
* Creates a
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
* @
|
|
961
|
-
*
|
|
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.
|
|
962
2148
|
*/
|
|
963
2149
|
static createMetaRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
|
|
964
2150
|
static reset(): void;
|