Comparing version 0.0.33 to 0.0.34
@@ -17,3 +17,3 @@ "use strict"; | ||
fs_1.default.existsSync(root) || fs_1.default.mkdirSync("./.ts2uml/", { recursive: true }); | ||
const flow = "```mermaid\nflowchart\n" + seq + "\n```"; | ||
const flow = "```mermaid\nflowchart LR\n" + seq + "\n```"; | ||
fs_1.default.writeFileSync(root + "flowchart_" + key + ".md", flow); | ||
@@ -36,3 +36,3 @@ return flow; | ||
const participants = {}; | ||
nodes.filter(n => n.type == model_1.NodeType.Request).forEach((node) => { | ||
nodes.filter(n => n.type == model_1.NodeType.Request).forEach((node, i) => { | ||
if (!participants[node.source]) { | ||
@@ -45,7 +45,8 @@ participants[node.source] = {}; | ||
participants[node.source][node.srcMethod] = undefined; | ||
participants[node.reciever][node.method] = undefined; | ||
if (participants[node.srcMethod + "-" + node.method]) | ||
participants[node.reciever][node.recMethod] = undefined; | ||
const path = `\n${node.srcMethod ? node.srcMethod : node.source}-->${node.recMethod ? node.recMethod : node.reciever}`; | ||
if (participants[path]) | ||
return; | ||
flow += `\n${node.srcMethod ? node.srcMethod : node.source}-->${node.method ? node.method : node.reciever}`; | ||
participants[node.srcMethod + "-" + node.method] = true; | ||
flow += path; | ||
participants[path] = true; | ||
}); | ||
@@ -55,8 +56,4 @@ Object.keys(participants).filter(p => !p.includes("-")).forEach((p) => { | ||
const methods = Object.keys(participants[p]); | ||
methods.forEach((m) => { | ||
if (m == 'undefined') | ||
return; | ||
flow += `\n${m}` + (m && `[${(0, model_1.fntoReadable)((0, model_1.expand)(m))}]`); | ||
}); | ||
if (methods && methods.length > 1) | ||
methods.filter(m => m && m != 'undefined' && m != 'null').forEach((m) => flow += `\n${m}` + (m && `[${(0, model_1.fntoReadable)((0, model_1.expand)(m))}]`)); | ||
if (methods && methods.length > 1 && model_1.umlConfig.remoteBaseUrl) | ||
flow += `\nclick ${Object.keys(participants[p]).join(",")} href "${model_1._graphs.remoteUrl[p]}" "${model_1._graphs.remoteUrl[p]}"`; | ||
@@ -63,0 +60,0 @@ flow += `\nend`; |
@@ -12,3 +12,3 @@ export declare enum NodeType { | ||
readonly source: string; | ||
readonly method: string; | ||
readonly recMethod: string; | ||
readonly reciever: string; | ||
@@ -15,0 +15,0 @@ readonly srcMethod: string; |
12
model.js
@@ -16,6 +16,6 @@ "use strict"; | ||
this.type = type; | ||
this.source = abbreviate(source + ""); | ||
this.method = abbreviate(method + ""); | ||
this.srcMethod = abbreviate(srcMethod + ""); | ||
this.reciever = abbreviate(reciever + ""); | ||
this.source = source && abbreviate(source); | ||
this.recMethod = method && abbreviate(method); | ||
this.srcMethod = srcMethod && abbreviate(srcMethod); | ||
this.reciever = reciever && abbreviate(reciever); | ||
} | ||
@@ -49,4 +49,4 @@ } | ||
constructor() { | ||
this.remoteBaseUrl = ""; | ||
this.enableLink = true; | ||
this.remoteBaseUrl = null; | ||
this.enableLink = false; | ||
} | ||
@@ -53,0 +53,0 @@ } |
{ | ||
"name": "ts2uml", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"description": "typescript workflow to uml sequence", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -78,3 +78,3 @@ "use strict"; | ||
} | ||
sequence += `\n${node.source} ${getSequenceDirection(node)} ${node.reciever}: ${(0, model_1.fntoReadable)((0, model_1.expand)(node.method))}`; | ||
sequence += `\n${node.type == model_1.NodeType.Request ? node.source : node.reciever} ${getSequenceDirection(node)} ${node.type == model_1.NodeType.Request ? node.reciever : node.source}: ${(0, model_1.fntoReadable)((0, model_1.expand)(node.type == model_1.NodeType.Request ? node.recMethod : node.srcMethod || node.recMethod))}`; | ||
if (!dedups.includes(node.timestamp + "")) { | ||
@@ -199,3 +199,3 @@ let result = getTimeStamp(node, isDtimeSet); | ||
function parseSequence(node) { | ||
return `\n${node.source} ${getSequenceDirection(node)} ${node.reciever}: ${(0, model_1.fntoReadable)((0, model_1.expand)(node.method))}`; | ||
return `\n${node.type === model_1.NodeType.Request ? node.source : node.reciever} ${getSequenceDirection(node)} ${node.type === model_1.NodeType.Request ? node.reciever : node.source}: ${(0, model_1.fntoReadable)((0, model_1.expand)(node.recMethod))}`; | ||
} | ||
@@ -202,0 +202,0 @@ function getSequenceDirection(node) { |
@@ -7,7 +7,2 @@ export declare class StackHandler { | ||
}; | ||
findDeclaredType(filePath: string, objectName: string, lineNumber: number): { | ||
declaredType: string; | ||
declaredMethod: string; | ||
}; | ||
private handleImport; | ||
findPromiseStartMethod(filePath: string, targetLineNumber: number): { | ||
@@ -14,0 +9,0 @@ method: string; |
@@ -16,5 +16,5 @@ "use strict"; | ||
const lines = content.split(/\r?\n/); | ||
let currentClassName = null; | ||
let currentClassName = "Root"; | ||
let currentMethodName = null; | ||
for (let i = 0; i < lines.length; i++) { | ||
for (let i = targetLineNumber; i > lines.length; i--) { | ||
const line = lines[i]; | ||
@@ -33,3 +33,3 @@ const lineNumber = i + 1; | ||
// Check if the target line number is reached | ||
if (lineNumber === targetLineNumber) { | ||
if (currentClassName) { | ||
return { className: currentClassName, method: currentMethodName }; | ||
@@ -39,68 +39,9 @@ } | ||
// Return null if no class or method is found at the given line number | ||
return { className: null, method: null }; | ||
return { className: currentClassName, method: currentMethodName }; | ||
} | ||
findDeclaredType(filePath, objectName, lineNumber) { | ||
const content = fs_1.default.readFileSync(filePath, 'utf8'); | ||
let declaredType = objectName; | ||
let declaredMethod = ""; | ||
const varMatch = content.match(new RegExp(`(let|const|var)\\s+${objectName}\\s*(:\\s*(\\w+))?\\s*=\\s*new\\s+(\\w+)\\(`)); | ||
if (varMatch && (varMatch[4])) { | ||
declaredType = varMatch[4]; | ||
} | ||
else { | ||
const varMatch = content.match(new RegExp(`(let|const|var)\\s+${objectName}\\s*(:\\s*(\\w+))?\\s*=\\s*(\\w+)\\.(\\w+)`)); | ||
if (varMatch && varMatch[4]) { | ||
declaredType = varMatch[4]; | ||
declaredMethod = varMatch[5]; | ||
if (declaredType === "this") { | ||
declaredType = this.findClassAndMethodName(filePath, lineNumber).className; | ||
} | ||
return { declaredType, declaredMethod }; | ||
} | ||
else { | ||
const varMatch = content.match(new RegExp(`(function)\\s+${objectName}`)); | ||
if (varMatch) { | ||
declaredMethod = objectName; | ||
declaredType = "Function"; | ||
return { declaredType, declaredMethod }; | ||
} | ||
else { | ||
const varMatch = content.match(new RegExp(`import\\s+\\*\\s+as\\s+${objectName}\\s+from\\s+['"](.*)['"]`)); | ||
if (varMatch) { | ||
({ declaredType, declaredMethod } = this.handleImport(varMatch, declaredType, declaredMethod, objectName, filePath, lineNumber)); | ||
return { declaredType, declaredMethod }; | ||
} | ||
else { | ||
const varMatch = content.match(new RegExp(`import\\s+{.*${objectName}.*}\\s+from\\s+['"](.*)['"]`)); | ||
if (varMatch) { | ||
({ declaredType, declaredMethod } = this.handleImport(varMatch, declaredType, declaredMethod, objectName, filePath, lineNumber)); | ||
return { declaredType, declaredMethod }; | ||
} | ||
} | ||
} | ||
} | ||
const stack = this.findDeclaredType(filePath, declaredType, lineNumber); | ||
declaredType = stack.declaredType; | ||
declaredMethod = stack.declaredMethod; | ||
} | ||
// Add more patterns as needed, such as for interfaces, type aliases, etc. | ||
return { declaredType, declaredMethod }; | ||
} | ||
handleImport(varMatch, declaredType, declaredMethod, objectName, filePath, lineNumber) { | ||
if (varMatch[1].includes("/")) { | ||
declaredType = varMatch[1]; | ||
declaredMethod = objectName; | ||
} | ||
else { | ||
const CM = this.findClassAndMethodName(filePath, lineNumber); | ||
declaredType = CM.className + ""; | ||
declaredMethod = CM.method + ""; | ||
} | ||
return { declaredType, declaredMethod }; | ||
} | ||
findPromiseStartMethod(filePath, targetLineNumber) { | ||
const content = fs_1.default.readFileSync(filePath, 'utf8'); | ||
const lines = content.split(/\r?\n/); | ||
let method = null; | ||
let className = ""; | ||
let method = undefined; | ||
let className = "Root"; | ||
let thenFound = false; | ||
@@ -120,13 +61,5 @@ for (let i = targetLineNumber - 1; i >= 0; i--) { | ||
method = methodCallMatch[3]; | ||
if (className === "this") { | ||
className = this.findClassAndMethodName(filePath, i).className; | ||
} | ||
else { | ||
const stack = this.findDeclaredType(filePath, className, i); | ||
className = stack.declaredType; | ||
if (stack.declaredMethod) { | ||
method = stack.declaredMethod; | ||
} | ||
method = method === 'then' ? stack.declaredMethod : method; | ||
} | ||
const CM = this.findClassAndMethodName(filePath, i); | ||
className = CM.className || 'Root'; | ||
method = CM.method; | ||
break; | ||
@@ -159,3 +92,3 @@ } | ||
// e.g., https://github.com/user/repo/path/to/file or https://bitbucket.org/user/repo/path/to/file | ||
const pathMatch = remote.match(/^[^:]+:\/\/[^\/]+\/[^\/]+\/[^\/]+\/(.*)/); | ||
const pathMatch = (remote + "").match(/^[^:]+:\/\/[^\/]+\/[^\/]+\/[^\/]+\/(.*)/); | ||
if (!pathMatch) | ||
@@ -162,0 +95,0 @@ return ""; // No valid path found in the URL |
@@ -86,7 +86,7 @@ "use strict"; | ||
const requestId = model_1._graphs._getRequestId(); | ||
let startTime, previous = { className: "Root", method: "" }, current = { className: "Root", method: "" }; | ||
let startTime, previous = { className: "Root", method: "", filePath: "" }, current = { className: "Root", method: "", filePath: "" }; | ||
if (requestId) { | ||
let stack = stackHandler.getStackMethod(error); | ||
const current = stack[0]; | ||
const previous = stack[1] || { className: "Root", method: "", filePath: "" }; | ||
current = stack[0]; | ||
previous = stack[1] || { className: "Root", method: "", filePath: "" }; | ||
startTime = new Date(); | ||
@@ -118,3 +118,3 @@ const nodesById = model_1._graphs.graphs[requestId] || []; | ||
result.then((res) => { | ||
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); | ||
const newNode = new model_1.GraphNode(prevClassName, prevMethod, className, method, res && Object.keys(res).length ? JSON.stringify(res) : "", new Date().getTime() - startTime.getTime(), model_1.NodeType.ResponseAsync); | ||
nodes.push(newNode); | ||
@@ -124,3 +124,3 @@ return res; | ||
} | ||
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); | ||
const newNode = new model_1.GraphNode(prevClassName, prevMethod, 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); | ||
nodes.push(newNode); | ||
@@ -127,0 +127,0 @@ model_1._graphs.graphs[model_1._graphs._getRequestId()] = nodes; |
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
38554
802