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

sol2uml

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sol2uml - npm Package Compare versions

Comparing version 1.1.20 to 1.1.21

37

lib/converter.js

@@ -56,8 +56,9 @@ "use strict";

// Sort UML Classes by folder of source file
const umlClassesSortedBySourceFiles = sortUmlClassesBySourceFolder(umlClasses);
let sourceFolder = '';
for (const umlClass of umlClassesSortedBySourceFiles) {
if (sourceFolder !== umlClass.codeSource) {
const umlClassesSortedByCodePath = sortUmlClassesByCodePath(umlClasses);
let currentCodeFolder = '';
for (const umlClass of umlClassesSortedByCodePath) {
const codeFolder = path.dirname(umlClass.codePath);
if (currentCodeFolder !== codeFolder) {
// Need to close off the last subgraph if not the first
if (sourceFolder != '') {
if (currentCodeFolder != '') {
dotString += '\n}';

@@ -67,4 +68,4 @@ }

subgraph ${getSubGraphName(clusterFolders)} {
label="${umlClass.codeSource}"`;
sourceFolder = umlClass.codeSource;
label="${codeFolder}"`;
currentCodeFolder = codeFolder;
}

@@ -74,3 +75,3 @@ dotString += dotGenerator_1.dotUmlClass(umlClass, classOptions);

// Need to close off the last subgraph if not the first
if (sourceFolder != '') {
if (currentCodeFolder != '') {
dotString += '\n}';

@@ -92,8 +93,8 @@ }

}
function sortUmlClassesBySourceFolder(umlClasses) {
function sortUmlClassesByCodePath(umlClasses) {
return umlClasses.sort((a, b) => {
if (a.codeSource < b.codeSource) {
if (a.codePath < b.codePath) {
return -1;
}
if (a.codeSource > b.codeSource) {
if (a.codePath > b.codePath) {
return 1;

@@ -106,6 +107,2 @@ }

let dotString = '';
let nameToIdMap = {};
for (const umlClass of umlClasses) {
nameToIdMap[umlClass.name] = umlClass;
}
// for each class

@@ -115,4 +112,10 @@ for (const sourceUmlClass of umlClasses) {

for (const association of Object.values(sourceUmlClass.associations)) {
// find the target class
const targetUmlClass = nameToIdMap[association.targetUmlClassName];
// find the target class with the same class name and
// codePath of the target in the importedPaths of the source class OR
// the codePath of the target is the same as the codePath pf the source class
const targetUmlClass = umlClasses.find((targetUmlClass) => {
return (targetUmlClass.name === association.targetUmlClassName &&
(sourceUmlClass.importedPaths.includes(targetUmlClass.codePath) ||
sourceUmlClass.codePath === targetUmlClass.codePath));
});
if (targetUmlClass) {

@@ -119,0 +122,0 @@ dotString += addAssociationToDot(sourceUmlClass, targetUmlClass, association);

@@ -19,5 +19,4 @@ "use strict";

const node = await parseSolidityFile(file);
const sourceFolder = path_1.dirname(file);
const relativeSourceFolder = path_1.relative(process.cwd(), sourceFolder);
const umlClass = parser_2.convertNodeToUmlClass(node, relativeSourceFolder);
const relativePath = path_1.relative(process.cwd(), file);
const umlClass = parser_2.convertNodeToUmlClass(node, relativePath);
umlClasses = umlClasses.concat(umlClass);

@@ -24,0 +23,0 @@ }

import { ASTNode } from '@solidity-parser/parser';
import { UmlClass } from './umlClass';
export declare function convertNodeToUmlClass(node: ASTNode, codeSource: string): UmlClass[];
export declare function convertNodeToUmlClass(node: ASTNode, codePath: string): UmlClass[];

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

const umlClass_1 = require("./umlClass");
const path_1 = require("path");
const debug = require('debug')('sol2uml');
function convertNodeToUmlClass(node, codeSource) {
function convertNodeToUmlClass(node, codePath) {
let umlClasses = [];
const importedPaths = [];
if (node.type === 'SourceUnit') {

@@ -15,3 +17,3 @@ node.children.forEach((childNode) => {

name: childNode.name,
codeSource: codeSource,
codePath,
});

@@ -22,4 +24,5 @@ umlClass = parseContractDefinition(umlClass, childNode);

else if (childNode.type === 'ImportDirective') {
// TODO travers to parse imports
// importedContracts.push(contract)
const codeFolder = path_1.dirname(codePath);
const importPath = path_1.join(codeFolder, childNode.path);
importedPaths.push(importPath);
}

@@ -31,2 +34,5 @@ });

}
umlClasses.forEach((umlClass) => {
umlClass.importedPaths = importedPaths;
});
return umlClasses;

@@ -33,0 +39,0 @@ }

@@ -50,3 +50,4 @@ export declare enum Visibility {

name: string;
codeSource: string;
codePath: string;
importedFileNames?: string[];
stereotype?: ClassStereotype;

@@ -66,3 +67,4 @@ enums?: {

name: string;
codeSource: string;
codePath: string;
importedPaths?: string[];
stereotype?: ClassStereotype;

@@ -69,0 +71,0 @@ attributes: Attribute[];

{
"name": "sol2uml",
"version": "1.1.20",
"version": "1.1.21",
"description": "Unified Modeling Language (UML) class diagram generator for Solidity contracts",

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

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