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

ts2uml

Package Overview
Dependencies
Maintainers
1
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.3 to 0.0.5

dist/index.min.js

80

dist/sequence.js

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

const model_1 = require("./model");
const defaultFn = ["constructor", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "__proto__", "toLocaleString"];
/**

@@ -14,18 +15,52 @@ * This decorator function modifies the original method to apply a graph sequence.

function sequence() {
return function (originalMethod, _context) {
console.log("sequence");
function replacementMethod(...args) {
try {
const result = _applyGraph.call(this, originalMethod, args);
return result;
}
catch (e) {
console.log("Error in method " + originalMethod.name);
throw e;
}
return function (method, caller, d) {
var _a, _b;
if ((caller && (caller === null || caller === void 0 ? void 0 : caller.kind) === "class") || ((method === null || method === void 0 ? void 0 : method.prototype) && ((_b = (_a = method === null || method === void 0 ? void 0 : method.prototype) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) === (method === null || method === void 0 ? void 0 : method.name))) {
return handleClass(d, method);
}
return replacementMethod;
else {
return handleFn(d, method);
}
};
}
exports.sequence = sequence;
function getAllMethodNames(obj) {
let methods = new Set();
while (obj = Reflect.getPrototypeOf(obj)) {
let keys = Reflect.ownKeys(obj);
keys.filter(f => !defaultFn.includes(f.toString() + "")).forEach((k) => methods.add(k));
}
return methods;
}
function handleClass(d, _class) {
return class _sequenceTempImpl extends _class {
constructor(...args) {
super(...args);
this.name = _class.name;
const orgImpl = this;
getAllMethodNames(this).forEach((key) => {
orgImpl[key.toString()] = handleFn(undefined, orgImpl[key.toString()]);
});
}
};
}
function handleFn(d, method) {
const originalMethod = (d && d.value) || method;
const overidden = function (...args) {
try {
const result = _applyGraph.call(this, originalMethod, args);
return result;
}
catch (e) {
console.log("Error in method " + originalMethod.name);
throw e;
}
};
if (d) {
d.value = overidden;
}
else {
return overidden;
}
}
function setSequenceId(requestId) {

@@ -37,14 +72,19 @@ model_1._graphs._setRequestId(requestId);

// get the original method's class name
const className = this.constructor.name;
let className = this.constructor.name;
if (className === "_sequenceTempImpl") {
className = Object.getPrototypeOf(this.constructor).name;
}
const requestId = model_1._graphs._getRequestId();
let oldNode = model_1._graphs.graphs[requestId];
if (!oldNode) {
oldNode = new model_1.GraphNode(requestId, "", args.length ? JSON.stringify(args) : "", undefined, []);
model_1._graphs.graphs[requestId] = oldNode;
if (requestId) {
if (!oldNode) {
oldNode = new model_1.GraphNode(requestId, "", args.length ? JSON.stringify(args) : "", undefined, []);
model_1._graphs.graphs[requestId] = oldNode;
}
const newNode = new model_1.GraphNode(className, originalMethod.name, args.length ? JSON.stringify(args) : "", oldNode);
oldNode.children.push(newNode);
model_1._graphs.graphs[requestId] = newNode;
}
const newNode = new model_1.GraphNode(className, originalMethod.name, args.length ? JSON.stringify(args) : "", oldNode);
oldNode.children.push(newNode);
model_1._graphs.graphs[requestId] = newNode;
const result = originalMethod.call(this, ...args);
model_1._graphs.graphs[requestId] = oldNode;
requestId && (model_1._graphs.graphs[requestId] = oldNode);
return result;

@@ -51,0 +91,0 @@ }

{
"name": "ts2uml",
"version": "0.0.3",
"version": "0.0.5",
"description": "typescript workflow to uml sequence",

@@ -8,3 +8,3 @@ "main": "dist/index.js",

"scripts": {
"build": "tsc",
"build": "tsc && terser -c -m -o ./dist/index.min.js -- ./dist/index.js",
"test": "jest"

@@ -17,4 +17,6 @@ },

"author": "tin2tin",
"license": "ISC"
"license": "ISC",
"devDependencies": {
"terser": "^5.31.0"
}
}

@@ -12,6 +12,9 @@ // Create a decorator function to apply annotations

@sequence()
public myMethod() {
public async myMethod() {
console.log(" Hello " + this.i++);
this.myMethod2();
}
constructor() {
}
@sequence()

@@ -18,0 +21,0 @@ public myMethod2() {

@@ -1,6 +0,3 @@

import { GraphNode, _graphs } from "./model";
import { GraphNode, _graphs } from "./model";
const defaultFn = ["constructor", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "__proto__", "toLocaleString"]
/**

@@ -13,18 +10,57 @@ * This decorator function modifies the original method to apply a graph sequence.

*/
export function sequence(): Function {
return function (originalMethod: any, _context: any) {
console.log("sequence");
function replacementMethod(this: any, ...args: any[]) {
try {
const result = _applyGraph.call(this, originalMethod, args);
return result;
} catch (e) {
console.log("Error in method " + originalMethod.name);
throw e;
}
return function (method: any, caller: any, d: PropertyDescriptor) {
if ((caller && caller?.kind === "class") || (method?.prototype && method?.prototype?.constructor?.name === method?.name)) {
return handleClass(d, method);
} else {
return handleFn(d, method);
}
return replacementMethod;
};
}
function getAllMethodNames(obj: any) {
let methods = new Set();
while (obj = Reflect.getPrototypeOf(obj)) {
let keys = Reflect.ownKeys(obj)
keys.filter(f => !defaultFn.includes(f.toString() + "")).forEach((k) => methods.add(k));
}
return methods;
}
function handleClass(d: PropertyDescriptor, _class: any) {
return class _sequenceTempImpl extends _class {
constructor(...args: any[]) {
super(...args);
this.name = _class.name;
const orgImpl = this;
getAllMethodNames(this).forEach((key: PropertyKey) => {
orgImpl[key.toString()] = handleFn(undefined, orgImpl[key.toString()]);
});
}
};
}
function handleFn(d: PropertyDescriptor, method: any) {
const originalMethod: any = (d && d.value) || method;
const overidden = function (this: any, ...args: any[]) {
try {
const result = _applyGraph.call(this, originalMethod, args);
return result;
} catch (e) {
console.log("Error in method " + originalMethod.name);
throw e;
}
};
if (d) {
d.value = overidden;
} else {
return overidden;
}
}
export function setSequenceId(requestId: string) {

@@ -36,16 +72,20 @@ _graphs._setRequestId(requestId);

// get the original method's class name
const className = this.constructor.name;
let className = this.constructor.name;
if(className === "_sequenceTempImpl"){
className = Object.getPrototypeOf(this.constructor).name;
}
const requestId = _graphs._getRequestId();
let oldNode = _graphs.graphs[requestId];
if (!oldNode) {
oldNode = new GraphNode(requestId, "", args.length ? JSON.stringify(args) : "", undefined, []);
_graphs.graphs[requestId] = oldNode;
if (requestId) {
if (!oldNode) {
oldNode = new GraphNode(requestId, "", args.length ? JSON.stringify(args) : "", undefined, []);
_graphs.graphs[requestId] = oldNode;
}
const newNode = new GraphNode(className, originalMethod.name, args.length ? JSON.stringify(args) : "", oldNode);
oldNode!.children.push(newNode);
_graphs.graphs[requestId] = newNode;
}
const newNode = new GraphNode(className, originalMethod.name, args.length ? JSON.stringify(args) : "", oldNode);
oldNode!.children.push(newNode);
_graphs.graphs[requestId] = newNode;
const result = originalMethod.call(this, ...args);
_graphs.graphs[requestId] = oldNode;
requestId && (_graphs.graphs[requestId] = oldNode);
return result;

@@ -59,3 +99,3 @@ }

* It then traverse and generates the sequence diagram .
*
*
* @returns {string} - A string representing the sequence diagram.

@@ -62,0 +102,0 @@ */

{
"compilerOptions": {
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "NodeNext", /* Specify what module code is generated. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */

@@ -10,6 +10,8 @@ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */

"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
"strict": false, /* Enable all strict type-checking options. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"declaration": true,
"moduleResolution": "node"
"moduleResolution": "NodeNext",
"emitDeclarationOnly": false,
"experimentalDecorators": true
},

@@ -16,0 +18,0 @@ "include": ["src/**/*"],

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