Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts2uml

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts2uml - npm Package Compare versions

Comparing version 0.0.51 to 0.0.52

3

flow-diagram.js

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports._getFlowDiagram = void 0;
exports._getFlowDiagram = _getFlowDiagram;
const model_1 = require("./model");

@@ -24,3 +24,2 @@ const fs_1 = __importDefault(require("fs"));

}
exports._getFlowDiagram = _getFlowDiagram;
/** generate

@@ -27,0 +26,0 @@ * flowchart TD

@@ -8,2 +8,8 @@ export declare enum NodeType {

}
export declare class StackInfo {
className: string;
method: string;
filePath: string;
modifier?: Modifier;
}
export declare enum Modifier {

@@ -23,3 +29,3 @@ Public = "public",

readonly srcMethod: string;
constructor(source: string, srcMethod: string, reciever: string, method: string, args: string, timestamp: number, type: NodeType, modifier: Modifier);
constructor(source: string, srcMethod: string, reciever: string, method: string, args: string, timestamp: number, type: NodeType, modifier?: Modifier);
}

@@ -26,0 +32,0 @@ export declare function fntoReadable(params: string): string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.umlConfig = exports._graphs = exports.expand = exports.fntoReadable = exports.GraphNode = exports.Modifier = exports.NodeType = void 0;
exports.umlConfig = exports._graphs = exports.GraphNode = exports.Modifier = exports.StackInfo = exports.NodeType = void 0;
exports.fntoReadable = fntoReadable;
exports.expand = expand;
var NodeType;

@@ -12,2 +14,8 @@ (function (NodeType) {

})(NodeType || (exports.NodeType = NodeType = {}));
class StackInfo {
constructor() {
this.className = "Root";
}
}
exports.StackInfo = StackInfo;
var Modifier;

@@ -20,3 +28,3 @@ (function (Modifier) {

class GraphNode {
constructor(source, srcMethod, reciever, method, args, timestamp, type, modifier) {
constructor(source, srcMethod, reciever, method, args, timestamp, type, modifier = Modifier.Public) {
this.args = args;

@@ -51,7 +59,5 @@ this.timestamp = timestamp;

}
exports.fntoReadable = fntoReadable;
function expand(short) {
return exports._graphs.dedups[short] || short;
}
exports.expand = expand;
class UmlConfig {

@@ -58,0 +64,0 @@ constructor() {

{
"name": "ts2uml",
"version": "0.0.51",
"version": "0.0.52",
"description": "typescript workflow to uml sequence",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -26,3 +26,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.handleNewParticipant = exports._getSequence = void 0;
exports._getSequence = _getSequence;
exports.handleNewParticipant = handleNewParticipant;
const fs_1 = __importStar(require("fs"));

@@ -64,3 +65,2 @@ const model_1 = require("./model");

}
exports._getSequence = _getSequence;
function getSequenceFromNode(nodes, dedups, participants) {

@@ -91,3 +91,2 @@ let sequence = "";

}
exports.handleNewParticipant = handleNewParticipant;
function getTimeStamp(node, isTimeSet) {

@@ -94,0 +93,0 @@ let result = undefined;

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports._getSequenceTemplate = void 0;
exports._getSequenceTemplate = _getSequenceTemplate;
const fs_1 = __importStar(require("fs"));

@@ -61,3 +61,2 @@ const model_1 = require("./model");

}
exports._getSequenceTemplate = _getSequenceTemplate;
// getSequenceFromNode with no duplicate sequence

@@ -64,0 +63,0 @@ function getSequenceTemplateFromNode(nodes, sequenceArray, participants) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseSequence = exports.getSequenceDirection = exports.chunk = void 0;
exports.chunk = chunk;
exports.getSequenceDirection = getSequenceDirection;
exports.parseSequence = parseSequence;
const model_1 = require("./model");

@@ -9,3 +11,2 @@ // write chunk implementation

}
exports.chunk = chunk;
function getSequenceDirection(node) {

@@ -23,6 +24,4 @@ switch (node.type) {

}
exports.getSequenceDirection = getSequenceDirection;
function parseSequence(node) {
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))}`;
}
exports.parseSequence = parseSequence;

@@ -0,6 +1,8 @@

import { Modifier, StackInfo } from './model';
export declare class StackHandler {
readonly excludeList: string[];
findClassAndMethodName(filePath: string, targetLineNumber: number): {
className: string | null;
method: string | null;
findClassAndMethodName(fileName: string, lineNumber: number): {
className?: string;
methodName?: string;
modifier?: Modifier;
};

@@ -10,8 +12,5 @@ findPromiseStartMethod(filePath: string, targetLineNumber: number): {

className: string;
modifier?: Modifier;
};
getStackMethod(error: Error): {
className: string;
method: string;
filePath: string;
}[];
getStackMethod(error: Error): StackInfo[];
parseRemoteUrl(remote: string, local: string): string;

@@ -23,3 +22,9 @@ findOverlap(remote: string, local: string): string;

filePath: string;
modifier?: undefined;
} | {
className: string;
method: string;
filePath: string;
modifier: Modifier;
};
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StackHandler = void 0;
const fs_1 = __importDefault(require("fs"));
const model_1 = require("./model");
const ts = __importStar(require("typescript"));
const fs = __importStar(require("fs"));
class StackHandler {

@@ -13,49 +34,48 @@ constructor() {

}
findClassAndMethodName(filePath, targetLineNumber) {
const content = fs_1.default.readFileSync(filePath, 'utf8');
const lines = content.split(/\r?\n/);
// Example usage
findClassAndMethodName(fileName, lineNumber) {
let currentClassName = "Root";
let currentMethodName = null;
let blockDepth = 0; // Track the depth of nested blocks
let gothrough = true;
// Ensure targetLineNumber is within bounds
if (targetLineNumber < 0 || targetLineNumber > lines.length) {
throw new Error("targetLineNumber is out of bounds");
}
for (let i = targetLineNumber - 1; i >= 0; i--) {
const line = lines[i];
// Increase or decrease block depth based on opening and closing braces
blockDepth += (line.match(/{/g) || []).length;
blockDepth -= (line.match(/}/g) || []).length;
// Match class declaration, considering possible keywords like 'export'
const classMatch = line.match(/(?<=(?:export\s+)?(?:abstract\s+)?class\s+)(\w+)/);
if (currentMethodName && classMatch) {
currentClassName = classMatch[1];
break; // Stop searching once a class is found
let currentMethodName;
let modifier = model_1.Modifier.Public;
const fileContent = fs.readFileSync(fileName, 'utf-8');
const sourceFile = ts.createSourceFile(fileName, fileContent, ts.ScriptTarget.Latest, true);
function find(node) {
var _a;
const { line: startLine } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
const { line: endLine } = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
if (startLine <= lineNumber && lineNumber <= endLine) {
if (ts.isMethodDeclaration(node) || ts.isFunctionDeclaration(node)) {
// For methods and named functions, update the current method name
if (node.name) {
currentMethodName = node.name.getText(sourceFile);
if (ts.isMethodDeclaration(node)) {
modifier = ((_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.some((mod) => mod.kind === ts.SyntaxKind.PrivateKeyword)) ? model_1.Modifier.Private : model_1.Modifier.Public;
}
}
}
else if (ts.isClassDeclaration(node)) {
// For class declarations, update the current class name and reset method name
if (node.name) {
currentClassName = node.name.getText(sourceFile) || "Root";
}
}
else if (ts.isVariableDeclaration(node) && node.initializer && ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node)) {
// For arrow functions or function expressions, check if it's assigned to a variable
if (node.name) {
currentMethodName = node.name.getText(sourceFile);
}
}
// Continue traversing to find nested functions or classes
ts.forEachChild(node, find);
}
// Skip processing if we're inside a nested block
if (blockDepth !== 1) {
gothrough = false;
continue;
}
;
// Match method or function declaration
const regex = /(\w+(?=\((?:[^()]*|\([^()]*\))*\)\s*{)|(?<=(let|const)\s+)\w+)/g;
const methodOrFunctionMatch = line.match(regex);
if (!currentMethodName && methodOrFunctionMatch && methodOrFunctionMatch[0] && !["if", "for"].includes(methodOrFunctionMatch[0])) {
currentMethodName = methodOrFunctionMatch[0];
}
}
// Adjust for cases where blockDepth might not return to 0 due to unbalanced braces
if (blockDepth < 0) {
console.warn("Warning: Unbalanced braces detected. The results might not be accurate.");
}
console.log(currentClassName, " --> ", currentMethodName);
return { className: currentClassName, method: currentMethodName };
ts.forEachChild(sourceFile, find);
return { className: currentClassName, methodName: currentMethodName, modifier };
}
findPromiseStartMethod(filePath, targetLineNumber) {
const content = fs_1.default.readFileSync(filePath, 'utf8');
const content = fs.readFileSync(filePath, 'utf8');
const lines = content.split(/\r?\n/);
let method = undefined;
let className = "Root";
let modifier = model_1.Modifier.Public;
let thenFound = false;

@@ -77,10 +97,11 @@ for (let i = targetLineNumber - 1; i >= 0; i--) {

className = CM.className || 'Root';
method = CM.method;
method = CM.methodName;
modifier = CM.modifier || model_1.Modifier.Public;
break;
}
}
return { method, className };
return { method, className, modifier };
}
getStackMethod(error) {
let stack = [{ className: "Root", method: "", filePath: "" }, { className: "Root", method: "", filePath: "" }];
let stack = [{ className: "Root", method: "", filePath: "", modifier: model_1.Modifier.Public }, { className: "Root", method: "", filePath: "" }];
let i = 0;

@@ -150,5 +171,5 @@ error.stack.split("\n").slice(1, 5).forEach((line) => {

let lineNumber = parts[0].replace(/.*?:([0-9]+):.*/, "$1");
let { method, className } = this.findPromiseStartMethod(filePath, parseInt(lineNumber));
let { method, className, modifier } = this.findPromiseStartMethod(filePath, parseInt(lineNumber));
filePath = this.parseRemoteUrl(model_1.umlConfig.remoteBaseUrl, filePath);
return { className, method, filePath };
return { className, method, filePath, modifier };
}

@@ -155,0 +176,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clear = exports.getSequenceTemplate = exports.getFlowDiagram = exports.getSequence = exports.setTraceId = exports.uml = void 0;
exports.clear = exports.getSequenceTemplate = exports.getFlowDiagram = exports.getSequence = void 0;
exports.uml = uml;
exports.setTraceId = setTraceId;
const flow_diagram_1 = require("./flow-diagram");

@@ -29,3 +31,2 @@ const model_1 = require("./model");

}
exports.uml = uml;
function getAllMethodNames(obj) {

@@ -85,23 +86,10 @@ let methods = new Set();

}
exports.setTraceId = setTraceId;
function findModifier(originalMethod) {
const impl = originalMethod.toString();
if (impl.indexOf("private") > -1) {
return model_1.Modifier.Private;
}
else if (impl.indexOf("protected") > -1) {
return model_1.Modifier.Protected;
}
else {
return model_1.Modifier.Public;
}
}
function _applyGraph(originalMethod, args, error) {
const requestId = model_1._graphs._getRequestId();
let startTime, modifier, previous = { className: "Root", method: "", filePath: "" }, current = { className: "Root", method: "", filePath: "" };
let startTime, modifier, previous = new model_1.StackInfo(), current = new model_1.StackInfo();
if (requestId) {
modifier = findModifier(originalMethod);
let stack = stackHandler.getStackMethod(error);
current = stack[0];
previous = stack[1] || { className: "Root", method: "", filePath: "" };
previous = stack[1] || new model_1.StackInfo();
modifier = previous.modifier;
startTime = new Date();

@@ -108,0 +96,0 @@ const nodesById = model_1._graphs.graphs[requestId] || [];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc