Untitled
unknown
plain_text
a year ago
1.2 kB
15
Indexable
class Graph {
constructor() {
this.graph = new Map();
}
addNode(functionName, params = null, returnData = null, status = 'success') {
if (!this.graph.has(functionName)) {
this.graph.set(functionName, []);
}
this.graph.get(functionName).push({
params,
returnData,
status,
});
}
addEdge(fromFunction, toFunction) {
if (!this.graph.has(fromFunction)) {
this.addNode(fromFunction);
}
if (!this.graph.has(toFunction)) {
this.addNode(toFunction);
}
}
printGraph() {
this.graph.forEach((calls, functionName) => {
console.log(`${functionName} calls:`);
calls.forEach((call) => {
const { params, returnData, status } = call;
console.log(` |_ Params: ${JSON.stringify(params)}`);
console.log(` Return Data: ${JSON.stringify(returnData)}`);
console.log(` Status: ${status}`);
});
});
}
}
const g = new Graph();
g.addNode('login', { email: "a@gmail.com" });
g.addEdge('login', 'getOrgDB');
g.addNode('getOrgDB', { orgCode: 444 }, null, 'failure');
g.addEdge('login', 'getUser');
console.log(g.printGraph())
Editor is loading...
Leave a Comment