execution-engine
Version:
A TypeScript library for tracing and visualizing code execution workflows.
80 lines • 4.05 kB
TypeScript
import { EngineNodeTrace } from '../common/models/engineNodeData.model';
import { EngineNode, EngineTrace } from '../common/models/engineTrace.model';
import { TraceOptions } from '../common/models/engineTraceOptions.model';
import { ExecutionTrace } from '../common/models/executionTrace.model';
import { Awaited } from '../common/utils/awaited';
/**
* Represents a class for traceable execution of functions.
*/
export declare class TraceableEngine {
private nodes;
private edges;
private asyncLocalStorage;
/**
* A temporary storage for narratives associated with non-found nodes.
* Narratives are stored in memory until the corresponding node is created.
* @private
*/
private narrativesForNonFoundNodes;
/**
* Initializes a new instance of the TraceableExecution class.
* @param initialTrace - The initial trace to be used.
*/
constructor(initialTrace?: EngineTrace);
private static extractIOExecutionTraceWithConfig;
private extractNarrativeWithConfig;
/**
* Initializes the trace with given initialTrace.
*
* @param {EngineTrace} initialTrace - The initial trace to initialize: the nodes and edges.
* @return {TraceableExecution} - The traceable execution object after initialization.
*/
initTrace(initialTrace: EngineTrace): TraceableEngine;
/**
* Gets the execution trace.
* @returns An array containing nodes and edges of the execution trace.
*/
getTrace(): EngineTrace;
/**
* Gets the nodes of the execution trace.
* @returns An array containing nodes of the execution trace.
*/
getTraceNodes(): EngineNode[];
/**
* ATTENTION: TS chooses the first fitting overload in top-down order, so overloads are sorted from most specific to most broad.
* ATTENTION: arrow function as blockFunction could be caught by this one, even if it doesn't return a promise
* prefer using real functions with function keyword!!
* ATTENTION: functions that return a promise will fit here BUT should be mentioned with ASYNC keyword to work correctly!
* prefer to use functions with the ASYNC keyword even if rechecking is available so that functions with returned promises are executed safely
*/
run<O>(blockFunction: (...params: any[]) => Promise<O>, inputs: Array<unknown>, options?: TraceOptions<Array<any>, O>): Promise<ExecutionTrace<Array<unknown>, Awaited<O>>>;
run<O>(blockFunction: (...params: any[]) => Promise<O>, inputs: Array<unknown>, options?: TraceOptions<Array<any>, O>['trace']): Promise<ExecutionTrace<Array<unknown>, Awaited<O>>>;
/**
* ATTENTION: arrow function as blockFunction ARE NOT RECOMMENDED it will work correctly at the overload inferring level to get this signature.
* It will be caught as a Promise in the signature before!!
* Especially if you do:
* ```
* () => { throw new Error("error example");}
* ```
* prefer using real functions with function keyword!!
*/
run<O>(blockFunction: (...params: any[]) => O, inputs: Array<unknown>, options?: TraceOptions<Array<any>, O>): ExecutionTrace<Array<unknown>, O>;
run<O>(blockFunction: (...params: any[]) => O, inputs: Array<unknown>, options?: TraceOptions<Array<any>, O>['trace']): ExecutionTrace<Array<unknown>, O>;
/**
* Pushes or appends narratives to a trace node.
* @param nodeId - The ID of the node.
* @param narratives - The narrative or array of narratives to be processed.
* @returns The updated instance of TraceableExecution.
*/
pushNarratives(nodeId: EngineNodeTrace['id'], narratives: string | string[]): this;
/**
* Retrieves an ordered array of narratives.
*
* @returns {Array<string>} An array that contains the ordered narratives. If no narratives are found, an empty array is returned.
*/
getNarratives(): Array<string>;
private buildTrace;
private filterNodeTrace;
private filterNodeExecutionTrace;
}
//# sourceMappingURL=traceableEngine.d.ts.map