Skip to the content.

Execution Engine API Documentation

A TypeScript library for tracing and visualizing code execution workflows

Github repo GitHub license

Table of Contents

Installation 📦

Use npm package manager:

npm install execution-engine

Or use the yarn package manager:

yarn add execution-engine

Usage 📚

Example 1: Basic Usage

import { ExecutionEngine } from "execution-engine";

const engine = new ExecutionEngine();

// for sync functions:
const res1 = engine.run((param) => `result1 for ${param}`, ['param1']);

// for async functions:
const res2 = await engine.run(async (param) => `result2 for ${param}`, [res1.outputs]);

// Retrieve the trace
const trace = engine.getTrace();
console.log('Trace:', trace);

You can:

Example 2: Usage with Decorators

import { engine, run } from "execution-engine";

@engine({ id: "uniqueEngineId" })
class MyClass extends EngineTask {
  @run()
  myMethod1(param: string) {
    return `result1 for ${param}`;
  }

  @run()
  async myMethod2(param: string) {
    return `result2 for ${param}`;
  }
}

const myInstance = new MyClass();
myInstance.myMethod2("param1");
await myInstance.myMethod2("param2");

// Retrieve the trace
const trace = myInstance.engine.getTrace();
console.log("Trace:", trace);

You can:

Components 🧩

ExecutionTimer

The ExecutionTimer is a simple class for measuring the execution time of code blocks.

TraceableExecution

The TraceableExecution class provides a framework for traceable execution of functions.

ExecutionEngine

The ExecutionEngine enhances traceable execution by introducing a context object (CXT) for capturing additional relevant information. It builds upon the functionality of TraceableExecution.

EngineTask with @engine and @run Decorators

The EngineTask class works in conjunction with the @engine decorator and the @run decorator to integrate the ExecutionEngine into your classes, providing tracing capabilities for methods.

For more details and usage examples, refer to the source code in EngineTask.