Comparing version 0.0.32 to 0.0.33
@@ -26,3 +26,3 @@ export declare enum NodeType { | ||
requestId: string; | ||
staticMethods: {}; | ||
methods: {}; | ||
remoteUrl: {}; | ||
@@ -29,0 +29,0 @@ _getRequestId(): string; |
10
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 = abbreviate(source + ""); | ||
this.method = abbreviate(method + ""); | ||
this.srcMethod = abbreviate(srcMethod + ""); | ||
this.reciever = abbreviate(reciever + ""); | ||
} | ||
@@ -57,3 +57,3 @@ } | ||
this.requestId = ""; | ||
this.staticMethods = {}; | ||
this.methods = {}; | ||
this.remoteUrl = {}; | ||
@@ -60,0 +60,0 @@ this.graphs = {}; |
{ | ||
"name": "ts2uml", | ||
"version": "0.0.32", | ||
"version": "0.0.33", | ||
"description": "typescript workflow to uml sequence", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,4 +13,7 @@ # ts2uml | ||
Executing uml-sprinkler is optional if you choose to do manually. | ||
Executing uml-sprinkler is optional if you choose to do manually annotate the methods and classes. | ||
![Sequence Image](https://raw.githubusercontent.com/senthurai/ts2uml/master/sprnklr.png) | ||
### Use the sequence decorator in your TypeScript classes, follow these steps: | ||
@@ -17,0 +20,0 @@ |
@@ -11,2 +11,3 @@ export declare class StackHandler { | ||
}; | ||
private handleImport; | ||
findPromiseStartMethod(filePath: string, targetLineNumber: number): { | ||
@@ -13,0 +14,0 @@ method: string; |
@@ -11,3 +11,3 @@ "use strict"; | ||
constructor() { | ||
this.excludeList = ["Module", "_compile"]; | ||
this.excludeList = ["Module", "_compile", 'processTicksAndRejections', "Object.<anonymous>", "Function.Module._load", "Function.Module.runMain", "Function.Module._resolveFilename", "Function.Module._load", "Module.require", "Module.load", "Module._compile", "Object.Module"]; | ||
} | ||
@@ -53,11 +53,32 @@ findClassAndMethodName(filePath, targetLineNumber) { | ||
declaredMethod = varMatch[5]; | ||
if (declaredType === "this") { | ||
declaredType = this.findClassAndMethodName(filePath, lineNumber).className; | ||
} | ||
return { declaredType, declaredMethod }; | ||
} | ||
if (declaredType === "this") { | ||
declaredType = this.findClassAndMethodName(filePath, lineNumber).className; | ||
} | ||
else { | ||
const stack = this.findDeclaredType(filePath, declaredType, lineNumber); | ||
declaredType = stack.declaredType; | ||
declaredMethod = stack.declaredMethod; | ||
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; | ||
} | ||
@@ -67,2 +88,14 @@ // Add more patterns as needed, such as for interfaces, type aliases, etc. | ||
} | ||
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) { | ||
@@ -78,11 +111,11 @@ const content = fs_1.default.readFileSync(filePath, 'utf8'); | ||
// This regex needs to be adjusted based on the actual coding patterns | ||
const methodCallMatch = line.match(/\s*(\w+)\.(\w+)\(/); | ||
const thenMatch = line.match(/(\w+)(\(.*\))?\.then\(/); | ||
const methodCallMatch = line.match(/\s*(\w+|(\w+)\.(\w+))\(/); | ||
const thenMatch = line.match(/(\w+)?(\(.*\))?\.then\(/); | ||
if (thenMatch) { | ||
thenFound = true; | ||
} | ||
if (methodCallMatch && thenFound) { | ||
if (methodCallMatch && methodCallMatch[1] !== 'then' && thenFound) { | ||
// Found a potential promise starting method call | ||
className = methodCallMatch[1]; | ||
method = methodCallMatch[2]; | ||
className = methodCallMatch[2] || methodCallMatch[1]; | ||
method = methodCallMatch[3]; | ||
if (className === "this") { | ||
@@ -94,2 +127,5 @@ className = this.findClassAndMethodName(filePath, i).className; | ||
className = stack.declaredType; | ||
if (stack.declaredMethod) { | ||
method = stack.declaredMethod; | ||
} | ||
method = method === 'then' ? stack.declaredMethod : method; | ||
@@ -108,3 +144,3 @@ } | ||
}); | ||
return stack.filter((s) => s !== null && (!this.excludeList.includes(s.className) && !this.excludeList.includes(s.method))).slice(0, 2); | ||
return stack.slice(0, 2); | ||
} | ||
@@ -143,4 +179,6 @@ parseRemoteUrl(remote, local) { | ||
if (line.includes("at ")) { | ||
if (line.includes("Object.<anonymous>")) { | ||
return null; | ||
for (const exclude of this.excludeList) { | ||
if (line.includes(exclude)) { | ||
return null; | ||
} | ||
} | ||
@@ -157,3 +195,3 @@ const parts = line.split("at ")[1].split(" "); | ||
if (className === null || className === void 0 ? void 0 : className.includes("Function")) { | ||
className = model_1._graphs.staticMethods[method]; | ||
className = model_1._graphs.methods[method]; | ||
} | ||
@@ -160,0 +198,0 @@ let filePath = localFilePath; |
@@ -0,3 +1,3 @@ | ||
import { _getFlowDiagram } from "./flow-diagram"; | ||
import { _getSequence, _getSequenceTemplate } from './sequence-diagram'; | ||
import { _getFlowDiagram } from "./flow-diagram"; | ||
export declare function uml(): Function; | ||
@@ -4,0 +4,0 @@ export declare function setTraceId(requestId: string): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.clear = exports.getSequenceTemplate = exports.getFlowDiagram = exports.getSequence = exports.setTraceId = exports.uml = void 0; | ||
const flow_diagram_1 = require("./flow-diagram"); | ||
const model_1 = require("./model"); | ||
const sequence_diagram_1 = require("./sequence-diagram"); | ||
const model_1 = require("./model"); | ||
const flow_diagram_1 = require("./flow-diagram"); | ||
const StackHandler_1 = require("./StackHandler"); | ||
@@ -47,3 +47,3 @@ const defaultFn = ["constructor", "length", "name", "prototype", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "__proto__", "toLocaleString"]; | ||
simpeTest[key.toString()] = handleFn(undefined, simpeTest[key.toString()]); | ||
model_1._graphs.staticMethods[key.toString()] = _class.name; | ||
model_1._graphs.methods[key.toString()] = _class.name; | ||
}); | ||
@@ -54,2 +54,3 @@ return simpeTest; | ||
const umlAlias = {}; | ||
model_1._graphs.requestId; | ||
eval(` umlAlias.${_class.name} = class extends _class { | ||
@@ -56,0 +57,0 @@ constructor(...args) { |
@@ -29,9 +29,10 @@ "use strict"; | ||
fileContent = (modified = true) && fileContent.replace(classMatch[0], `\n@uml()\n${classMatch[0]}`); | ||
// Add import statement if not already present | ||
const import_stmt = "import { uml } from 'ts2uml';"; | ||
if (!fileContent.includes(import_stmt)) { | ||
console.log(`Adding uml import statement to file ${filePath}`); | ||
fileContent = (modified = true) && `\n${import_stmt}\n${fileContent}`; | ||
} | ||
} | ||
} | ||
// Add import statement if not already present | ||
const import_stmt = "import { uml } from 'ts2uml';"; | ||
if (!fileContent.includes(import_stmt)) { | ||
fileContent = (modified = true) && `\n${import_stmt}\n${fileContent}`; | ||
} | ||
// Write modified content back to file if any modifications were made | ||
@@ -38,0 +39,0 @@ if (modified) { |
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
41698
876
76