Comparing version 0.0.28 to 0.0.29
15
model.js
@@ -24,13 +24,14 @@ "use strict"; | ||
function abbreviate(name) { | ||
if (!name || exports._graphs.dedups[name]) | ||
return exports._graphs.dedups[name]; | ||
const newName = name.replace(/[_$]/g, ""); | ||
if (!newName || exports._graphs.dedups[newName]) | ||
return exports._graphs.dedups[newName]; | ||
let i = 1; | ||
let a = name.replace(/([A-Z])[a-z]*/g, "$1"); | ||
let a = newName.replace(/.*?([A-Z])[a-z_]*/g, "$1"); | ||
while (exports._graphs.dedups.includes(a)) { | ||
a = name.replace(/([A-Z])[a-z]*/g, "$1") + i++; | ||
a = newName.replace(/.*?([A-Z])[a-z_]*/g, "$1") + i++; | ||
} | ||
exports._graphs.dedups.push(a); | ||
exports._graphs.dedups[name] = a; | ||
exports._graphs.dedups[a] = name; | ||
exports._graphs.dedups.push(name); | ||
exports._graphs.dedups[newName] = a; | ||
exports._graphs.dedups[a] = newName; | ||
exports._graphs.dedups.push(newName); | ||
return a; | ||
@@ -37,0 +38,0 @@ } |
{ | ||
"name": "ts2uml", | ||
"version": "0.0.28", | ||
"version": "0.0.29", | ||
"description": "typescript workflow to uml sequence", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -36,3 +36,4 @@ "use strict"; | ||
function handleClass(d, _class) { | ||
return class _sequenceTempImpl extends _class { | ||
let classes = {}; | ||
return class extends _class { | ||
constructor(...args) { | ||
@@ -42,3 +43,4 @@ super(...args); | ||
const orgImpl = this; | ||
getAllMethodNames(this).forEach((key) => { | ||
const methods = getAllMethodNames(this); | ||
methods.forEach((key) => { | ||
orgImpl[key.toString()] = handleFn(undefined, orgImpl[key.toString()]); | ||
@@ -51,7 +53,9 @@ }); | ||
const originalMethod = (d && d.value) || method; | ||
const overidden = function (...args) { | ||
const result = _applyGraph.call(this, originalMethod, args); | ||
d = d || { value: method }; | ||
return d.value = function (...args) { | ||
this.name = method.name; | ||
let error = new Error(); | ||
const result = _applyGraph.call(this, originalMethod, args, error); | ||
return result; | ||
}; | ||
return d && (d.value = overidden) || overidden; | ||
} | ||
@@ -62,18 +66,11 @@ function setTraceId(requestId) { | ||
exports.setTraceId = setTraceId; | ||
function _applyGraph(originalMethod, args) { | ||
// get the original method's class name | ||
let className = this.constructor.name; | ||
if (className === "_sequenceTempImpl") { | ||
className = Object.getPrototypeOf(this.constructor).name; | ||
} | ||
function _applyGraph(originalMethod, args, error) { | ||
let stack = getStackMethod(error); | ||
const current = stack[0]; | ||
const previous = stack[1]; | ||
const requestId = model_1._graphs._getRequestId(); | ||
const pop = model_1._graphs.classStack.pop() || { className: "Root", method: undefined }; | ||
const startTime = new Date(); | ||
if (requestId) { | ||
const nodesById = model_1._graphs.graphs[requestId] || []; | ||
model_1._graphs.classStack.push(pop); | ||
if (pop || pop.className !== className) { | ||
model_1._graphs.classStack.push({ className, method: originalMethod.name }); | ||
} | ||
const newNode = new model_1.GraphNode(pop.className, pop.method, className, originalMethod.name, args && Object.keys(args).length ? JSON.stringify(args) : "", startTime.getTime(), model_1.NodeType.Request); | ||
const newNode = new model_1.GraphNode(previous.className, previous.method, current.className, current.method, args && Object.keys(args).length ? JSON.stringify(args) : "", startTime.getTime(), model_1.NodeType.Request); | ||
nodesById.push(newNode); | ||
@@ -85,3 +82,3 @@ model_1._graphs.graphs[requestId] = nodesById; | ||
if (requestId) { | ||
handleResponse(result, pop, className, originalMethod.name, startTime); | ||
handleResponse(result, previous.className, previous.method, current.className, current.method, startTime); | ||
} | ||
@@ -92,5 +89,4 @@ return result; | ||
if (requestId) { | ||
handleResponse(e, pop, className, originalMethod.name, startTime); | ||
handleResponse(e, previous.className, previous.method, current.className, current.method, startTime); | ||
(0, sequence_diagram_1._getSequence)(); | ||
setTraceId(requestId); | ||
} | ||
@@ -100,8 +96,7 @@ throw e; | ||
} | ||
function handleResponse(result, pop, className, method, startTime) { | ||
function handleResponse(result, prevClassName, prevMethod, className, method, startTime) { | ||
const nodes = model_1._graphs.graphs[model_1._graphs._getRequestId()] || []; | ||
model_1._graphs.classStack.pop(); | ||
if (result instanceof Promise) { | ||
result.then((res) => { | ||
const newNode = new model_1.GraphNode(className, pop.method, pop.className, method, res && Object.keys(res).length ? JSON.stringify(res) : "", new Date().getTime() - startTime.getTime(), model_1.NodeType.ResponseAsync); | ||
const newNode = new model_1.GraphNode(className, prevMethod, prevClassName, method, res && Object.keys(res).length ? JSON.stringify(res) : "", new Date().getTime() - startTime.getTime(), model_1.NodeType.ResponseAsync); | ||
nodes.push(newNode); | ||
@@ -111,3 +106,3 @@ return res; | ||
} | ||
const newNode = new model_1.GraphNode(className, pop.method, pop.className, method, result && Object.keys(result).length ? JSON.stringify(result) : "", new Date().getTime() - startTime.getTime(), result instanceof Promise ? model_1.NodeType.AsyncReturn : model_1.NodeType.Response); | ||
const newNode = new model_1.GraphNode(className, prevMethod, prevClassName, method, result && Object.keys(result).length ? JSON.stringify(result) : "", new Date().getTime() - startTime.getTime(), result instanceof Promise ? model_1.NodeType.AsyncReturn : model_1.NodeType.Response); | ||
nodes.push(newNode); | ||
@@ -123,1 +118,25 @@ model_1._graphs.graphs[model_1._graphs._getRequestId()] = nodes; | ||
exports.clear = _clear; | ||
function getStackMethod(error) { | ||
let stack = [{ className: "Root", method: "" }, { className: "Root", method: "" }]; | ||
let i = 0; | ||
error.stack.split("\n").slice(1, 3).forEach((line) => { | ||
stack[i++] = processStackLine(line); | ||
}); | ||
return stack; | ||
} | ||
function processStackLine(line) { | ||
if (line.includes("at ")) { | ||
if (line.includes("Object.<anonymous>")) { | ||
return { className: "Root", method: "" }; | ||
} | ||
const parts = line.split("at ")[1].split(" "); | ||
if (parts.length > 1) { | ||
const classMethod = parts[0].split("."); | ||
let method = classMethod[1]; | ||
if (line.includes("as ")) { | ||
method = line.replace(/.*\[as (.*?)\].*/, "$1"); | ||
} | ||
return { className: classMethod[0], method: method }; | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29358
622