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.34 to 0.0.35

sequence-template-diagram.d.ts

12

flow-diagram.js

@@ -44,7 +44,7 @@ "use strict";

participants[node.reciever][node.recMethod] = undefined;
const path = `\n${node.srcMethod ? node.srcMethod : node.source}-->${node.recMethod ? node.recMethod : node.reciever}`;
const path = `\n${node.srcMethod ? node.srcMethod : node.source}---->${node.recMethod ? node.recMethod : node.reciever}`;
if (participants[path])
return;
flow += path;
participants[path] = true;
flow += path.replace(/---->/g, `--${Object.keys(participants).filter(p => p.includes("--")).length}-->`);
});

@@ -55,4 +55,8 @@ Object.keys(participants).filter(p => !p.includes("-")).forEach((p) => {

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]}"`;
if (methods && methods.length > 1 && model_1.umlConfig.remoteBaseUrl) {
const links = Object.keys(participants[p]).filter(m => m && m != 'undefined' && m != 'null').join(",");
if (links && links.length) {
flow += `\nclick ${links} href "${model_1._graphs.remoteUrl[p]}" "${model_1._graphs.remoteUrl[p]}"`;
}
}
flow += `\nend`;

@@ -59,0 +63,0 @@ });

{
"name": "ts2uml",
"version": "0.0.34",
"version": "0.0.35",
"description": "typescript workflow to uml sequence",

@@ -14,6 +14,3 @@ "main": "index.js",

"author": "tin2tin",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.12.12"
}
"license": "ISC"
}

@@ -9,2 +9,2 @@ /**

export declare function _getSequence(): string;
export declare function _getSequenceTemplate(): string;
export declare function handleNewParticipant(source: string, participants: string[], sequence: string): string;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports._getSequenceTemplate = exports._getSequence = void 0;
exports.handleNewParticipant = exports._getSequence = void 0;
const fs_1 = __importStar(require("fs"));
const model_1 = require("./model");
const crypto_1 = require("crypto");
const sequence_util_1 = require("./sequence-util");
const rootTs2uml = "./.ts2uml/";

@@ -52,3 +52,3 @@ /**

writeStream.write(beginning);
chunk(nodeArray, chunkSize).forEach((nodes) => {
(0, sequence_util_1.chunk)(nodeArray, chunkSize).forEach((nodes) => {
let seq = getSequenceFromNode(nodes, dedups, participants) + "\n";

@@ -70,13 +70,5 @@ sequence += seq;

nodes.forEach((node) => {
const actorSrc = (0, model_1.fntoReadable)((0, model_1.expand)(node.source));
const actorDest = (0, model_1.fntoReadable)((0, model_1.expand)(node.reciever));
if (!participants.includes(node.source)) {
sequence += "\nParticipant " + node.source + " as " + actorSrc;
participants.push(node.source);
}
if (!participants.includes(node.reciever)) {
sequence += "\nParticipant " + node.reciever + " as " + actorDest;
participants.push(node.reciever);
}
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))}`;
sequence = handleNewParticipant(node.source, participants, sequence);
sequence = handleNewParticipant(node.reciever, participants, sequence);
sequence += (0, sequence_util_1.parseSequence)(node);
if (!dedups.includes(node.timestamp + "")) {

@@ -92,2 +84,11 @@ let result = getTimeStamp(node, isDtimeSet);

}
function handleNewParticipant(source, participants, sequence) {
const actorSrc = (0, model_1.fntoReadable)((0, model_1.expand)(source));
if (!participants.includes(source)) {
sequence += "\nParticipant " + source + " as " + actorSrc;
participants.push(source);
}
return sequence;
}
exports.handleNewParticipant = handleNewParticipant;
function getTimeStamp(node, isTimeSet) {

@@ -109,108 +110,1 @@ let result = undefined;

}
function _getSequenceTemplate() {
fs_1.default.existsSync(rootTs2uml) || fs_1.default.mkdirSync(rootTs2uml, { recursive: true });
const sequences = Object.keys(model_1._graphs.graphs).map((key) => {
let nodeArray = model_1._graphs.graphs[key];
const participants = [];
const sequenceArray = [];
const begining = "```mermaid\nsequenceDiagram\n";
let sequence = begining;
const fileToWrite = rootTs2uml + "sdt_" + key + ".md";
//delete the file if it exists
fs_1.default.existsSync(fileToWrite) && fs_1.default.unlinkSync(fileToWrite);
const writeStream = (0, fs_1.createWriteStream)(fileToWrite);
writeStream.write(begining);
chunk(nodeArray, 20).forEach((nodes) => {
let seq = getSequenceTemplateFromNode(nodes, sequenceArray, participants) + "\n";
sequence += seq;
});
chunk(sequenceArray, 20).forEach((seqArray) => {
const write = seqArray.join("");
writeStream.write(write);
sequence += write;
});
writeStream.write("\n```");
writeStream.end();
return sequence;
}).join("\n");
return sequences;
}
exports._getSequenceTemplate = _getSequenceTemplate;
// write chunk implementation
function chunk(array, size) {
return array.reduce((acc, _, i) => (i % size ? acc : [...acc, array.slice(i, i + size)]), []);
}
// getSequenceFromNode with no duplicate sequence
function getSequenceTemplateFromNode(nodes, sequenceArray, participants) {
let sequence = "";
nodes.forEach((node) => {
const actorSrc = (0, model_1.fntoReadable)((0, model_1.expand)(node.source));
const actorDest = (0, model_1.fntoReadable)((0, model_1.expand)(node.reciever));
if (!participants.includes(node.source)) {
sequence = handleParticipant(node.source, actorSrc, sequence, sequenceArray, participants);
}
if (!participants.includes(node.reciever)) {
sequence = handleParticipant(node.reciever, actorDest, sequence, sequenceArray, participants);
}
let seq = parseSequence(node);
calculateMean(participants, sequenceArray, seq, node);
});
return sequence;
}
function handleParticipant(actorAbbr, actor, sequence, sequenceArray, participants) {
const participant = addParticipant(actorAbbr, actor);
sequenceArray.push(participant);
participants.push(actorAbbr);
return sequence;
}
function addParticipant(actorAbbr, actor) {
return "\nParticipant " + actorAbbr + " as " + actor;
}
function calculateMean(participants, sequenceArray, seq, node) {
//get hash the of seq
let isOld = true;
if (!sequenceArray.includes(seq)) {
sequenceArray.push(seq);
isOld = false;
}
if (node.type !== model_1.NodeType.Request) {
let hash = (0, crypto_1.createHash)('sha256').update(seq).digest('hex');
const meanValue = participants[hash] || (participants[hash] = {});
const indexToDelete = sequenceArray.indexOf(seq) + 1;
let min = meanValue.min || 0;
let max = meanValue.max || 0;
let count = meanValue.count || 0;
let total = meanValue.total || 0;
if (min == 0 || node.timestamp < min) {
min = node.timestamp;
}
if (max == 0 || node.timestamp > max) {
max = node.timestamp;
}
total += node.timestamp;
count++;
meanValue.min = min;
meanValue.max = max;
meanValue.total = total;
meanValue.count = count;
meanValue.mean = total / count;
participants[hash] = meanValue;
const index = isOld && indexToDelete || sequenceArray.length;
sequenceArray[index] = (`\nNote left of ${node.source}:c:${count}|m:${min}/M:${max}/~${meanValue.mean.toPrecision(3)}/ms`);
}
}
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))}`;
}
function getSequenceDirection(node) {
switch (node.type) {
case model_1.NodeType.Request:
return "->>+";
case model_1.NodeType.Response:
return "-x-";
case model_1.NodeType.ResponseAsync:
return "-x-";
case model_1.NodeType.AsyncReturn:
return "--x";
}
}
import { _getFlowDiagram } from "./flow-diagram";
import { _getSequence, _getSequenceTemplate } from './sequence-diagram';
import { _getSequence } from './sequence-diagram';
import { _getSequenceTemplate } from "./sequence-template-diagram";
export declare function uml(): Function;

@@ -4,0 +5,0 @@ export declare function setTraceId(requestId: string): void;

@@ -7,2 +7,3 @@ "use strict";

const sequence_diagram_1 = require("./sequence-diagram");
const sequence_template_diagram_1 = require("./sequence-template-diagram");
const StackHandler_1 = require("./StackHandler");

@@ -132,3 +133,3 @@ const defaultFn = ["constructor", "length", "name", "prototype", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "__proto__", "toLocaleString"];

exports.getFlowDiagram = flow_diagram_1._getFlowDiagram;
exports.getSequenceTemplate = sequence_diagram_1._getSequenceTemplate;
exports.getSequenceTemplate = sequence_template_diagram_1._getSequenceTemplate;
exports.clear = _clear;
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