Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add more examples to explain ExecutionEngine usage
- Loading branch information
Showing
5 changed files
with
638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[ | ||
{ | ||
"data": { | ||
"inputs": [ | ||
"john_doe", | ||
"secure_password" | ||
], | ||
"outputs": "User john_doe successfully logged in", | ||
"startTime": "2023-11-18T19:22:28.044Z", | ||
"endTime": "2023-11-18T19:22:28.044Z", | ||
"duration": 0, | ||
"id": "loginUser_1700335348044_cfccf8cb-5dc5-4857-8891-4afc79be398f", | ||
"label": "loginUser", | ||
"parallel": false, | ||
"abstract": false, | ||
"createTime": "2023-11-18T19:22:28.044Z" | ||
}, | ||
"group": "nodes" | ||
}, | ||
{ | ||
"data": { | ||
"inputs": [ | ||
"john_doe" | ||
], | ||
"outputs": "User Information for john_doe: Full Name - John Doe, Email - john.doe@example.com, Role - User", | ||
"startTime": "2023-11-18T19:22:28.044Z", | ||
"endTime": "2023-11-18T19:22:28.044Z", | ||
"duration": 0, | ||
"id": "getUserInformation_1700335348044_d92efa30-7bd2-4eea-910b-df040bc5fcf2", | ||
"label": "getUserInformation", | ||
"parallel": false, | ||
"abstract": false, | ||
"createTime": "2023-11-18T19:22:28.044Z" | ||
}, | ||
"group": "nodes" | ||
}, | ||
{ | ||
"data": { | ||
"id": "loginUser_1700335348044_cfccf8cb-5dc5-4857-8891-4afc79be398f->getUserInformation_1700335348044_d92efa30-7bd2-4eea-910b-df040bc5fcf2", | ||
"source": "loginUser_1700335348044_cfccf8cb-5dc5-4857-8891-4afc79be398f", | ||
"target": "getUserInformation_1700335348044_d92efa30-7bd2-4eea-910b-df040bc5fcf2", | ||
"parallel": false | ||
}, | ||
"group": "edges" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ExecutionEngine } from "../src"; | ||
import * as fs from "fs"; | ||
|
||
function registerUser(username: string, password: string) { | ||
if (username && password) { | ||
return Promise.resolve(`User ${username} successfully registered`); | ||
} else { | ||
Promise.reject("Invalid registration information"); | ||
} | ||
} | ||
|
||
function loginUser(username: string, password: string) { | ||
if (username && password) { | ||
return `User ${username} successfully logged in`; | ||
} else { | ||
throw new Error("Invalid login credentials"); | ||
} | ||
} | ||
|
||
function getUserInformation(username: string) { | ||
const userInfo = { | ||
fullName: "John Doe", | ||
email: "john.doe@example.com", | ||
role: "User", | ||
}; | ||
return `User Information for ${username}: Full Name - ${userInfo.fullName}, Email - ${userInfo.email}, Role - ${userInfo.role}`; | ||
} | ||
|
||
// Sequential consecutive calls for user registration, login, and retrieving user information | ||
const newUser = { | ||
username: "john_doe", | ||
password: "secure_password", | ||
}; | ||
const executionEngine = new ExecutionEngine(); | ||
executionEngine | ||
.run(registerUser, [newUser.username, newUser.password]) | ||
.then((result) => result); | ||
executionEngine.run(loginUser, [newUser.username, newUser.password]); | ||
executionEngine.run(getUserInformation, [newUser.username]); | ||
|
||
// Retrieve the trace | ||
const finalTrace = executionEngine.getTrace(); | ||
const jsonString = JSON.stringify(finalTrace, null, 2); | ||
|
||
// Write the JSON string to the file | ||
const filePath = process?.argv?.[1]?.replace(".ts", ".json"); | ||
fs.writeFile(filePath, jsonString, "utf-8", (err) => { | ||
if (err) { | ||
console.error("Error writing JSON to file:", err); | ||
} else { | ||
console.log(`JSON data written to ${filePath}`); | ||
} | ||
}); |
Oops, something went wrong.