Skip to content

Commit 4425f7a

Browse files
authored
Merge pull request #54 from tabkram/feature/trace
feat: introduce standalone `execute()` and `executionTrace()` functions and `@trace()` decorator
2 parents e8a22c0 + 2e4d89d commit 4425f7a

44 files changed

Lines changed: 2512 additions & 1688 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/ExecutionEngine.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ExecutionEngine
22

3-
The `ExecutionEngine` class extends the [`TraceableExecution`](./TraceableExecution.md) class, inheriting traceability
3+
The `ExecutionEngine` class extends the [`TraceableEngine`](./TraceableEngine.md) class, inheriting traceability
44
features and adding contextual execution capabilities.
55

66
## Usage
@@ -99,9 +99,9 @@ Returns the updated instance of `ExecutionEngine`.
9999

100100
## Additional Information
101101

102-
### [TraceableExecution](./TraceableExecution.md) Integration
102+
### [TraceableEngine](./TraceableEngine.md) Integration
103103

104-
The `ExecutionEngine` class extends the [`TraceableExecution`](./TraceableExecution.md) class, inheriting methods for
104+
The `ExecutionEngine` class extends the [`TraceableEngine`](./TraceableEngine.md) class, inheriting methods for
105105
managing the execution trace.
106106
This integration provides a complete picture of the execution flow, including contextual information.
107107

docs/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A TypeScript library for tracing and visualizing code execution workflows
1010
- [Installation](#installation-)
1111
- [Components](#components-)
1212
- [ExecutionTimer](#executiontimer)
13-
- [TraceableExecution](#traceableexecution)
13+
- [TraceableEngine](#traceableengine)
1414
- [ExecutionEngine](#executionengine)
1515
- [EngineTask with @engine and @run Decorators](#enginetask-with-engine-and-run-decorators)
1616

@@ -97,15 +97,20 @@ You can:
9797

9898
The __[ExecutionTimer](./ExecutionTimer.md)__ is a simple class for measuring the execution time of code blocks.
9999

100-
### TraceableExecution
100+
### TraceableEngine
101101

102-
The __[TraceableExecution](./TraceableExecution.md)__ class provides a framework for traceable execution of functions.
102+
> **⚠️ Deprecation Notice:**
103+
> - `TraceableEngine` is deprecated and will be removed in a future release. Use `TraceableEngine` instead.
104+
105+
### TraceableEngine
106+
107+
The __[TraceableEngine](./TraceableEngine.md)__ class provides a framework for providing traceable engine and trace the execution of functions.
103108

104109
### ExecutionEngine
105110

106111
The __[ExecutionEngine](./ExecutionEngine.md)__ enhances traceable execution by introducing a context object (`CXT`) for
107112
capturing additional relevant information.
108-
It builds upon the functionality of [TraceableExecution](./TraceableExecution.md).
113+
It builds upon the functionality of [TraceableEngine](./TraceableEngine.md).
109114

110115
### EngineTask with @engine and @run Decorators
111116

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# TraceableExecution
1+
# TraceableEngine
22

3-
The `TraceableExecution` class is a TypeScript utility that facilitates tracing and logging of function executions. It
3+
The `TraceableEngine` class is a TypeScript utility that facilitates tracing and logging of function executions. It
44
captures detailed information about the inputs, outputs, errors, and execution time for each function call, allowing for
55
the creation of a trace graph.
66

@@ -10,7 +10,7 @@ scenarios.
1010

1111
## Overview
1212

13-
The `TraceableExecution` class allows users to run functions in a traceable manner, capturing detailed information about
13+
The `TraceableEngine` class allows users to run functions in a traceable manner, capturing detailed information about
1414
each execution step. The key features include:
1515

1616
- **Execution Trace:**
@@ -26,16 +26,16 @@ each execution step. The key features include:
2626

2727
## Usage
2828

29-
1. Import the `TraceableExecution` class:
29+
1. Import the `TraceableEngine` class:
3030

3131
```typescript
32-
import { TraceableExecution } from "execution-engine";
32+
import { TraceableEngine } from "execution-engine";
3333
```
3434

35-
2. Create an instance of `TraceableExecution`:
35+
2. Create an instance of `TraceableEngine`:
3636

3737
```typescript
38-
const traceableExecution = new TraceableExecution();
38+
const traceableExecution = new TraceableEngine();
3939
```
4040

4141

@@ -101,15 +101,15 @@ each execution step. The key features include:
101101

102102
## Advanced Configuration
103103

104-
The `TraceableExecution` class provides flexibility for advanced configurations, including custom trace options and
104+
The `TraceableEngine` class provides flexibility for advanced configurations, including custom trace options and
105105
narratives. Explore the class methods and options for a more tailored usage.
106106

107107
## Examples
108108

109109
### 1. Here's a basic example:
110110

111111
```typescript
112-
const traceableExecution = new TraceableExecution();
112+
const traceableExecution = new TraceableEngine();
113113

114114
const result = await traceableExecution.run(
115115
async (param1, param2) => {
@@ -125,7 +125,7 @@ const trace = traceableExecution.getTrace();
125125
console.log('Trace:', trace);
126126
```
127127

128-
### 2. How to use `TraceableExecution` consecutive calls
128+
### 2. How to use `TraceableEngine` consecutive calls
129129

130130
In this example, we showcase the trace functionality by sequentially executing `registerUser`, `loginUser`,
131131
and `getUserInformation` functions within the context of `traceableExecution`.
@@ -170,16 +170,16 @@ const finalTrace = traceableExecution.getTrace();
170170
console.log(JSON.stringify(finalTrace, null, 2));
171171
```
172172

173-
### 3. How to use `TraceableExecution` with asynchronous functions and parallel execution
173+
### 3. How to use `TraceableEngine` with asynchronous functions and parallel execution
174174

175175
In this example, `fetchCurrentTemperature` and `fetchDailyForecast` simulate asynchronous operations,
176176
while `getWeatherInformation` showcases running them in parallel with `Promise.all`
177-
within the context of `TraceableExecution`. The resulting trace will capture the parallel execution relationships.
177+
within the context of `TraceableEngine`. The resulting trace will capture the parallel execution relationships.
178178

179179
```typescript
180-
import { NodeData, TraceableExecution } from "./TraceableExecution";
180+
import { NodeData, TraceableEngine } from "./TraceableEngine";
181181

182-
const traceableExecution = new TraceableExecution();
182+
const traceableExecution = new TraceableEngine();
183183

184184
async function fetchCurrentTemperature(city: string) {
185185
return Promise.resolve(`Current Temperature in ${city}: 25°C`);
@@ -223,7 +223,7 @@ console.log(JSON.stringify(finalTrace, null, 2));
223223

224224
### `constructor(initialTrace?: Trace)`
225225

226-
Initializes a new instance of the `TraceableExecution` class.
226+
Initializes a new instance of the `TraceableEngine` class.
227227

228228
- `initialTrace` (optional): The initial trace to be used.
229229

@@ -247,7 +247,7 @@ Gets the nodes of the execution trace.
247247

248248
Returns an array containing nodes of the execution trace.
249249

250-
### `run<O>(blockFunction: (...params) => O | Promise<O>, inputs?: Array<unknown>, options?: TraceOptions<Array<any>, O>): Promise<NodeExecutionTrace<Array<unknown>, Awaited<O>>> | NodeExecutionTrace<Array<unknown>, O>`
250+
### `run<O>(blockFunction: (...params) => O | Promise<O>, inputs?: Array<unknown>, options?: TraceOptions<Array<any>, O>): Promise<ExecutionTrace<Array<unknown>, Awaited<O>>> | ExecutionTrace<Array<unknown>, O>`
251251

252252
Executes a function and captures the trace.
253253

@@ -257,14 +257,14 @@ Executes a function and captures the trace.
257257

258258
Returns a promise that resolves to the execution trace.
259259

260-
### `pushNarratives(nodeId: NodeTrace['id'], narratives: string | string[]): TraceableExecution`
260+
### `pushNarratives(nodeId: NodeTrace['id'], narratives: string | string[]): TraceableEngine`
261261

262262
Pushes or appends narratives to a trace node.
263263

264264
- `nodeId`: The ID of the node.
265265
- `narratives`: The narrative or array of narratives to be processed.
266266

267-
Returns the updated instance of `TraceableExecution`.
267+
Returns the updated instance of `TraceableEngine`.
268268

269269
### `getNarratives(): Array<string>`
270270

docs/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ navbar-links:
99
Getting started: "README"
1010
Components:
1111
- Execution Timer: "ExecutionTimer"
12-
- Traceable Execution: "TraceableExecution"
12+
- Traceable Engine: "TraceableEngine"
1313
- Execution Engine: "ExecutionEngine"
1414

1515
version: 1.1.0

examples/authentication.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
11
[
22
{
33
"data": {
4-
"id": "registerUser_1740075283095_7d0ee34b-4996-41f8-b26f-ff1bc19b4625",
4+
"id": "registerUser_1740421994942_1bd57a7b-4df1-4db3-ba82-1fd62b33c9cc",
55
"label": "registerUser",
66
"inputs": [
77
"john_doe",
88
"secure_password"
99
],
1010
"outputs": "User john_doe successfully registered",
11-
"startTime": "2025-02-20T18:14:43.095Z",
12-
"endTime": "2025-02-20T18:14:48.097Z",
13-
"duration": 5002.056375026703,
14-
"elapsedTime": "5 seconds and 2.056 ms",
11+
"startTime": "2025-02-24T18:33:14.942Z",
12+
"endTime": "2025-02-24T18:33:19.945Z",
13+
"duration": 5003.037957906723,
14+
"elapsedTime": "5 seconds and 3.038 ms",
1515
"narratives": [],
1616
"parallel": false,
1717
"abstract": false,
18-
"createTime": "2025-02-20T18:14:48.098Z"
18+
"createTime": "2025-02-24T18:33:19.946Z"
1919
},
2020
"group": "nodes"
2121
},
2222
{
2323
"data": {
24-
"id": "loginUser_1740075288098_229fc951-9746-45c1-a05b-2dd96cd92b26",
24+
"id": "loginUser_1740421999946_54b24360-5a68-4477-a46d-f952b396a094",
2525
"label": "loginUser",
2626
"inputs": [
2727
"john_doe",
2828
"secure_password"
2929
],
3030
"outputs": "User john_doe successfully logged in",
31-
"startTime": "2025-02-20T18:14:48.098Z",
32-
"endTime": "2025-02-20T18:14:51.099Z",
33-
"duration": 3001.3917499780655,
34-
"elapsedTime": "3 seconds and 1.392 ms",
31+
"startTime": "2025-02-24T18:33:19.946Z",
32+
"endTime": "2025-02-24T18:33:22.949Z",
33+
"duration": 3002.5867080688477,
34+
"elapsedTime": "3 seconds and 2.587 ms",
3535
"narratives": [],
3636
"parallel": false,
3737
"abstract": false,
38-
"createTime": "2025-02-20T18:14:51.099Z"
38+
"createTime": "2025-02-24T18:33:22.949Z"
3939
},
4040
"group": "nodes"
4141
},
4242
{
4343
"data": {
44-
"id": "getUserInformation_1740075291100_535d2c3e-9c9f-4f2b-8b42-5a176dcafc63",
44+
"id": "getUserInformation_1740422002950_42293cc0-db92-4c94-acef-31691d3306d0",
4545
"label": "getUserInformation",
4646
"inputs": [
4747
"john_doe"
4848
],
4949
"outputs": "User Information for john_doe: Full Name - John Doe, Email - john.doe@example.com, Role - User",
50-
"startTime": "2025-02-20T18:14:51.100Z",
51-
"endTime": "2025-02-20T18:14:52.101Z",
52-
"duration": 1001.484708070755,
53-
"elapsedTime": "1 second and 1.485 ms",
50+
"startTime": "2025-02-24T18:33:22.950Z",
51+
"endTime": "2025-02-24T18:33:23.951Z",
52+
"duration": 1001.3778331279755,
53+
"elapsedTime": "1 second and 1.378 ms",
5454
"narratives": [],
5555
"parallel": false,
5656
"abstract": false,
57-
"createTime": "2025-02-20T18:14:52.101Z"
57+
"createTime": "2025-02-24T18:33:23.951Z"
5858
},
5959
"group": "nodes"
6060
},
6161
{
6262
"data": {
63-
"id": "registerUser_1740075283095_7d0ee34b-4996-41f8-b26f-ff1bc19b4625->loginUser_1740075288098_229fc951-9746-45c1-a05b-2dd96cd92b26",
64-
"source": "registerUser_1740075283095_7d0ee34b-4996-41f8-b26f-ff1bc19b4625",
65-
"target": "loginUser_1740075288098_229fc951-9746-45c1-a05b-2dd96cd92b26",
63+
"id": "registerUser_1740421994942_1bd57a7b-4df1-4db3-ba82-1fd62b33c9cc->loginUser_1740421999946_54b24360-5a68-4477-a46d-f952b396a094",
64+
"source": "registerUser_1740421994942_1bd57a7b-4df1-4db3-ba82-1fd62b33c9cc",
65+
"target": "loginUser_1740421999946_54b24360-5a68-4477-a46d-f952b396a094",
6666
"parallel": false
6767
},
6868
"group": "edges"
6969
},
7070
{
7171
"data": {
72-
"id": "loginUser_1740075288098_229fc951-9746-45c1-a05b-2dd96cd92b26->getUserInformation_1740075291100_535d2c3e-9c9f-4f2b-8b42-5a176dcafc63",
73-
"source": "loginUser_1740075288098_229fc951-9746-45c1-a05b-2dd96cd92b26",
74-
"target": "getUserInformation_1740075291100_535d2c3e-9c9f-4f2b-8b42-5a176dcafc63",
72+
"id": "loginUser_1740421999946_54b24360-5a68-4477-a46d-f952b396a094->getUserInformation_1740422002950_42293cc0-db92-4c94-acef-31691d3306d0",
73+
"source": "loginUser_1740421999946_54b24360-5a68-4477-a46d-f952b396a094",
74+
"target": "getUserInformation_1740422002950_42293cc0-db92-4c94-acef-31691d3306d0",
7575
"parallel": false
7676
},
7777
"group": "edges"

0 commit comments

Comments
 (0)