New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

prisma-uml

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-uml - npm Package Compare versions

Comparing version

to
1.1.16

#!/usr/bin/env node
!function(e,t){for(var r in t)e[r]=t[r]}(exports,function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=8)}([function(e,t){e.exports=require("chalk")},function(e,t){e.exports=require("typescript-generic-datastructures")},function(e,t){e.exports=require("yargs")},function(e,t){e.exports=require("uuid")},function(e,t){e.exports=require("axios")},function(e,t){e.exports=require("@prisma/sdk")},function(e,t){e.exports=require("zlib")},function(e,t){e.exports=require("fs")},function(e,t,r){"use strict";r.r(t);var n=r(2),a=r.n(n);let i,s;function o(e,t){return[e,i.WhiteSpace,t,i.WhiteSpace,i.OpenBrace].join("")}function u(e){return e.padStart(e.length+2,i.WhiteSpace)}function c(e,t=1){const r=[e];for(let e=0;e<t;e++)r.push(i.Breakline);return r.join("")}function l(e){const t=[];return t.push(o(s.Entity,e.name)),t.push(i.Breakline,...e.fields.map(e=>(e=>{const t=[];return t.push(e.isRequired?""+(i.Asterisk+i.WhiteSpace):null,e.name,i.Colons,i.WhiteSpace,e.type,e.isList?""+(i.OpenBracket+i.closeBracket):null,e.isRequired?null:i.QuestionMark),t.join("")})(e)).map(u).map(e=>c(e)),i.CloseBrace),t.join("")}!function(e){e.WhiteSpace=" ",e.OpenBrace="{",e.CloseBrace="}",e.OpenBracket="[",e.closeBracket="]",e.Tab="\t",e.Breakline="\n",e.Colons=":",e.QuestionMark="?",e.Asterisk="*",e.DoubleDots=".."}(i||(i={})),function(e){e.Entity="entity",e.Enum="enum"}(s||(s={}));var p=r(5),d=r(1),f=r(3);const h=e=>e.name,m=e=>e.value.id;function g(e){return Array.isArray(e.values)}function y(e){return Array.isArray(e.fields)}function v(e){const t=function(e){const t=Object(f.v1)(),r=new d.Graph(!1),n=e.models.map(e=>new d.GraphVertex(e,h)),a=e.enums.map(e=>new d.GraphVertex(e,h));return n.forEach(e=>{r.addVertex(e)}),a.forEach(e=>{r.addVertex(e)}),e.models.filter(e=>e.fields.some(e=>"scalar"!==e.kind)).reduce((e,n)=>{const a=r.getVertexByKey(n.name),i=n.fields.filter(e=>"scalar"!==e.kind).map(e=>{const t=[];e.isList?t.push("{"):t.push("|"),e.isRequired?t.push("|"):t.push("o");const a=r.getVertexByKey(e.type);if(g(a.value))t.push("|","|");else if(y(a.value)){const e=a.value.fields.find(e=>e.type===n.name);(null==e?void 0:e.isRequired)?t.push("|"):t.push("o"),(null==e?void 0:e.isList)?t.push("}"):t.push("|")}const i={start:"",end:""};for(;t.length>0;)t.length>2?i.start+=t.pop():i.end+=t.pop();return{field:e,cardinality:i}}).map(({field:e,cardinality:n})=>{let i=`${a.value.name}.${e.name}.${e.relationName}`;const s=Object(f.v5)(i,t),o=r.getVertexByKey(e.type);return new d.GraphEdge(a,o,{id:s,cardinality:n},m)});return e.push(...i),e},[]).forEach(e=>{r.addEdge(e)}),r}(e.datamodel),r=t.getAllVertices().filter(e=>g(e.value)).map(e=>g(e.value)?function(e){const t=[];return t.push(o(s.Enum,e.name)),t.push(i.Breakline,...e.values.map(({name:e})=>`${u(e)}${i.Breakline}`),i.CloseBrace),t.join("")}(e.value):void 0),n=t.getAllVertices().filter(e=>y(e.value)).map(e=>y(e.value)?l(e.value):void 0),a=t.getAllVertices().reduce((e,t)=>(t.getEdges().forEach(t=>{e.push({start:t.startVertex.value,cardinality:t.value.cardinality,end:t.endVertex.value})}),e),[]),p=[];return p.push(c("@startuml",2)),p.push(c("skinparam linetype ortho",2)),p.push(r.concat(n).join(`${i.Breakline}${i.Breakline}`)),p.push(c("",2)),p.push(a.map(w).join(i.Breakline)),p.push(c("",2),c("@enduml",1)),p.join("")}function w(e){const t=[];return t.push(e.start.name,i.WhiteSpace,e.cardinality.start,i.DoubleDots,e.cardinality.end,i.WhiteSpace,e.end.name),t.join("")}var x=r(0),b=r.n(x),S=r(6);function G(e){return function(e){let t="";for(let r=0;r<e.length;r+=3)r+2==e.length?t+=O(e.charCodeAt(r),e.charCodeAt(r+1),0):r+1==e.length?t+=O(e.charCodeAt(r),0,0):t+=O(e.charCodeAt(r),e.charCodeAt(r+1),e.charCodeAt(r+2));return t}(Object(S.deflateRawSync)(e,{level:9}).toString("binary"))}function O(e,t,r){const n=(3&e)<<4|t>>4,a=(15&t)<<2|r>>6,i=63&r;let s="";return s+=P(63&e>>2),s+=P(63&n),s+=P(63&a),s+=P(63&i),s}function P(e){return e<10?String.fromCharCode(48+e):(e-=10)<26?String.fromCharCode(65+e):(e-=26)<26?String.fromCharCode(97+e):0==(e-=26)?"-":1==e?"_":"?"}var k,j,$,B,E=r(4),A=r.n(E),C=r(7);function V(e,...t){const r=F(e,t);return b.a.hex(k.Red).bold(r)}function q(e,...t){const r=F(e,t);return b.a.hex(k.Green).bold(r)}function F(e,...t){return e.reduce((e,r,n)=>(e+=r,e+=void 0!==t[n]?t[n]:""),"")}!function(e){e.Blue="#4285f4",e.Green="#34a853",e.Yellow="#fbbc05",e.Red="#ea4335"}(k||(k={}));Error;Error;class M extends Error{constructor(...e){super(V`${`\nOne argument below is required: ${e.reduce((e,t)=>e+="\n - "+t,"")}\n`}`),this.name="RequiredArgsError"}}Error;Error;!function(e){e.Text="text",e.SVG="svg",e.PNG="png",e.JPG="jpg"}(j||(j={})),function(e){e.Path="path"}($||($={})),function(e){e.Output="output",e.Server="server",e.File="file"}(B||(B={}));const R={command:["$0 <path>"],describe:"Generate a plantUML from a Prisma schema",builder:e=>e.positional($.Path,{describe:"Path to Prisma schema",type:"string"}).usage(`\nUsage\n ${b.a.green("$0")} <path> [options]`).example(b.a.green("$0")+" ./schema.prisma","Output a plantUML Entity Relation Diagram as text in the stdout").example(b.a.green("$0")+" ./schema.prisma > my-erd.plantuml","Save the diagram into a .plantuml file").example(b.a.green("$0")+" ./schema.prisma --output svg --file my-erd.svg","Output a diagram as SVG").example(b.a.green("$0")+" ./schema.prisma -o png -f my-erd.png","Output a diagram as PNG").example(b.a.green("$0")+" ./schema.prisma --server http://localhost:8080","Use a plantUML custom server to render the image").options({[B.Output]:{alias:"o",describe:"Output of the diagram",type:"string",default:j.Text,choices:[j.Text,j.SVG,j.PNG,j.JPG]},[B.Server]:{alias:"s",describe:"PlantUML Server URL",type:"string",default:"https://www.plantuml.com/plantuml"},[B.File]:{alias:"f",describe:"Filename or File full path to output",type:"string"}}).check(N).version(!1),handler:async e=>{const t=e[$.Path],r=e[B.Output],n=e[B.Server],a=e[B.File];var i;const s=v(await(i=t,Object(p.getDMMF)({datamodelPath:i})));switch(r){case j.Text:process.stdout.write(s);break;case j.SVG:try{const e=await L(s,n,T.SVG);await W(e.data,a),process.stdout.write(`✅ File ${a} successfully created!`)}catch(e){if(!U(e))throw process.stderr.write("❌ An error has occurred while creating the file"),e;process.stderr.write(e.message)}break;case j.PNG:try{const e=await L(s,n,T.PNG);await W(e.data,a),process.stdout.write(q`✅ File ${a} successfully created!`)}catch(e){if(!U(e))throw process.stderr.write(V`❌ An error has occurred while creating the file`),e;process.stderr.write(e.message)}break;case j.JPG:try{const e=await L(s,n,T.PNG);await W(e.data,a),process.stdout.write(q`✅ File ${a} successfully created!`)}catch(e){if(!U(e))throw process.stderr.write(V`❌ An error has occurred while creating the file`),e;process.stderr.write(e.message)}}}};var T;function L(e,t,r){const n=G(e);return r===T.JPG?A.a.request({baseURL:t,url:"/img/"+n,method:"GET",responseType:"stream"}):A.a.request({baseURL:t,url:`/${r}/${n}`,method:"GET",responseType:"stream"})}function W(e,t){return new Promise((r,n)=>{const a=Object(C.createWriteStream)(t,{encoding:"utf8"});a.on("finish",r),a.on("error",e=>n(e)),e.pipe(a)})}function U(e){return!!e.isAxiosError}function N(e){const t=e[B.Output],r=e[B.File];if(t!==j.Text&&!r)throw new M(B.File);return!0}!function(e){e.SVG="svg",e.PNG="png",e.JPG="jpg"}(T||(T={})),a.a.help().wrap(a.a.terminalWidth()).showHelpOnFail(!0).command(R).demandCommand().recommendCommands().strict().version(!0).argv}]));
!function(e,t){for(var r in t)e[r]=t[r]}(exports,function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=8)}([function(e,t){e.exports=require("chalk")},function(e,t){e.exports=require("typescript-generic-datastructures")},function(e,t){e.exports=require("yargs")},function(e,t){e.exports=require("uuid")},function(e,t){e.exports=require("axios")},function(e,t){e.exports=require("@prisma/sdk")},function(e,t){e.exports=require("zlib")},function(e,t){e.exports=require("fs")},function(e,t,r){"use strict";r.r(t);var n=r(2),a=r.n(n);let i,s;function o(e,t){return[e,i.WhiteSpace,t,i.WhiteSpace,i.OpenBrace].join("")}function u(e){return e.padStart(e.length+2,i.WhiteSpace)}function c(e,t=1){const r=[e];for(let e=0;e<t;e++)r.push(i.Breakline);return r.join("")}function l(e){const t=[];return t.push(o(s.Entity,e.name)),t.push(i.Breakline,...e.fields.map(e=>(e=>{const t=[];return t.push(e.isRequired?""+(i.Asterisk+i.WhiteSpace):null,e.name,i.Colons,i.WhiteSpace,e.type,e.isList?""+(i.OpenBracket+i.closeBracket):null,e.isRequired?null:i.QuestionMark),t.join("")})(e)).map(u).map(e=>c(e)),i.CloseBrace),t.join("")}!function(e){e.WhiteSpace=" ",e.OpenBrace="{",e.CloseBrace="}",e.OpenBracket="[",e.closeBracket="]",e.Tab="\t",e.Breakline="\n",e.Colons=":",e.QuestionMark="?",e.Asterisk="*",e.DoubleDots=".."}(i||(i={})),function(e){e.Entity="entity",e.Enum="enum"}(s||(s={}));var p=r(5),d=r(1),f=r(3);const h=e=>e.name,m=e=>e.value.id;function g(e){return Array.isArray(e.values)}function y(e){return Array.isArray(e.fields)}function v(e){const t=function(e){const t=Object(f.v1)(),r=new d.Graph(!1),n=e.models.map(e=>new d.GraphVertex(e,h)),a=e.enums.map(e=>new d.GraphVertex(e,h));return n.forEach(e=>{r.addVertex(e)}),a.forEach(e=>{r.addVertex(e)}),e.models.filter(e=>e.fields.some(e=>"scalar"!==e.kind)).reduce((e,n)=>{const a=r.getVertexByKey(n.name),i=n.fields.filter(e=>"scalar"!==e.kind).map(e=>{const t=[];e.isList?t.push("{"):t.push("|"),e.isRequired?t.push("|"):t.push("o");const a=r.getVertexByKey(e.type);if(g(a.value))t.push("|","|");else if(y(a.value)){const e=a.value.fields.find(e=>e.type===n.name);null!=e&&e.isRequired?t.push("|"):t.push("o"),null!=e&&e.isList?t.push("}"):t.push("|")}const i={start:"",end:""};for(;t.length>0;)t.length>2?i.start+=t.pop():i.end+=t.pop();return{field:e,cardinality:i}}).map(({field:e,cardinality:n})=>{let i=`${a.value.name}.${e.name}.${e.relationName}`;const s=Object(f.v5)(i,t),o=r.getVertexByKey(e.type);return new d.GraphEdge(a,o,{id:s,cardinality:n},m)});return e.push(...i),e},[]).forEach(e=>{r.addEdge(e)}),r}(e.datamodel),r=t.getAllVertices().filter(e=>g(e.value)).map(e=>g(e.value)?function(e){const t=[];return t.push(o(s.Enum,e.name)),t.push(i.Breakline,...e.values.map(({name:e})=>`${u(e)}${i.Breakline}`),i.CloseBrace),t.join("")}(e.value):void 0),n=t.getAllVertices().filter(e=>y(e.value)).map(e=>y(e.value)?l(e.value):void 0),a=t.getAllVertices().reduce((e,t)=>(t.getEdges().forEach(t=>{e.push({start:t.startVertex.value,cardinality:t.value.cardinality,end:t.endVertex.value})}),e),[]),p=[];return p.push(c("@startuml",2)),p.push(c("skinparam linetype ortho",2)),p.push(r.concat(n).join(`${i.Breakline}${i.Breakline}`)),p.push(c("",2)),p.push(a.map(w).join(i.Breakline)),p.push(c("",2),c("@enduml",1)),p.join("")}function w(e){const t=[];return t.push(e.start.name,i.WhiteSpace,e.cardinality.start,i.DoubleDots,e.cardinality.end,i.WhiteSpace,e.end.name),t.join("")}var x=r(0),b=r.n(x),S=r(6);function G(e){return function(e){let t="";for(let r=0;r<e.length;r+=3)r+2==e.length?t+=O(e.charCodeAt(r),e.charCodeAt(r+1),0):r+1==e.length?t+=O(e.charCodeAt(r),0,0):t+=O(e.charCodeAt(r),e.charCodeAt(r+1),e.charCodeAt(r+2));return t}(Object(S.deflateRawSync)(e,{level:9}).toString("binary"))}function O(e,t,r){const n=(3&e)<<4|t>>4,a=(15&t)<<2|r>>6,i=63&r;let s="";return s+=P(63&e>>2),s+=P(63&n),s+=P(63&a),s+=P(63&i),s}function P(e){return e<10?String.fromCharCode(48+e):(e-=10)<26?String.fromCharCode(65+e):(e-=26)<26?String.fromCharCode(97+e):0==(e-=26)?"-":1==e?"_":"?"}var k,j,$,B,E=r(4),A=r.n(E),C=r(7);function V(e,...t){const r=F(e,t);return b.a.hex(k.Red).bold(r)}function q(e,...t){const r=F(e,t);return b.a.hex(k.Green).bold(r)}function F(e,...t){return e.reduce((e,r,n)=>(e+=r,e+=void 0!==t[n]?t[n]:""),"")}!function(e){e.Blue="#4285f4",e.Green="#34a853",e.Yellow="#fbbc05",e.Red="#ea4335"}(k||(k={}));Error;Error;class M extends Error{constructor(...e){super(V`${`\nOne argument below is required: ${e.reduce((e,t)=>e+="\n - "+t,"")}\n`}`),this.name="RequiredArgsError"}}Error;Error;!function(e){e.Text="text",e.SVG="svg",e.PNG="png",e.JPG="jpg"}(j||(j={})),function(e){e.Path="path"}($||($={})),function(e){e.Output="output",e.Server="server",e.File="file"}(B||(B={}));const R={command:["$0 <path>"],describe:"Generate a plantUML from a Prisma schema",builder:e=>e.positional($.Path,{describe:"Path to Prisma schema",type:"string"}).usage(`\nUsage\n ${b.a.green("$0")} <path> [options]`).example(b.a.green("$0")+" ./schema.prisma","Output a plantUML Entity Relation Diagram as text in the stdout").example(b.a.green("$0")+" ./schema.prisma > my-erd.plantuml","Save the diagram into a .plantuml file").example(b.a.green("$0")+" ./schema.prisma --output svg --file my-erd.svg","Output a diagram as SVG").example(b.a.green("$0")+" ./schema.prisma -o png -f my-erd.png","Output a diagram as PNG").example(b.a.green("$0")+" ./schema.prisma --server http://localhost:8080","Use a plantUML custom server to render the image").options({[B.Output]:{alias:"o",describe:"Output of the diagram",type:"string",default:j.Text,choices:[j.Text,j.SVG,j.PNG,j.JPG]},[B.Server]:{alias:"s",describe:"PlantUML Server URL",type:"string",default:"https://www.plantuml.com/plantuml"},[B.File]:{alias:"f",describe:"Filename or File full path to output",type:"string"}}).check(N).version(!1),handler:async e=>{const t=e[$.Path],r=e[B.Output],n=e[B.Server],a=e[B.File];var i;const s=v(await(i=t,Object(p.getDMMF)({datamodelPath:i})));switch(r){case j.Text:process.stdout.write(s);break;case j.SVG:try{const e=await L(s,n,T.SVG);await W(e.data,a),process.stdout.write(`✅ File ${a} successfully created!`)}catch(e){if(!U(e))throw process.stderr.write("❌ An error has occurred while creating the file"),e;process.stderr.write(e.message)}break;case j.PNG:try{const e=await L(s,n,T.PNG);await W(e.data,a),process.stdout.write(q`✅ File ${a} successfully created!`)}catch(e){if(!U(e))throw process.stderr.write(V`❌ An error has occurred while creating the file`),e;process.stderr.write(e.message)}break;case j.JPG:try{const e=await L(s,n,T.PNG);await W(e.data,a),process.stdout.write(q`✅ File ${a} successfully created!`)}catch(e){if(!U(e))throw process.stderr.write(V`❌ An error has occurred while creating the file`),e;process.stderr.write(e.message)}}}};var T;function L(e,t,r){const n=G(e);return r===T.JPG?A.a.request({baseURL:t,url:"/img/"+n,method:"GET",responseType:"stream"}):A.a.request({baseURL:t,url:`/${r}/${n}`,method:"GET",responseType:"stream"})}function W(e,t){return new Promise((r,n)=>{const a=Object(C.createWriteStream)(t,{encoding:"utf8"});a.on("finish",r),a.on("error",e=>n(e)),e.pipe(a)})}function U(e){return!!e.isAxiosError}function N(e){const t=e[B.Output],r=e[B.File];if(t!==j.Text&&!r)throw new M(B.File);return!0}!function(e){e.SVG="svg",e.PNG="png",e.JPG="jpg"}(T||(T={})),a.a.help().wrap(a.a.terminalWidth()).showHelpOnFail(!0).command(R).demandCommand().recommendCommands().strict().version(!0).argv}]));
{
"name": "prisma-uml",
"version": "1.1.15",
"version": "1.1.16",
"description": "A CLI to transform a Prisma schema to a PlantUML Entity RelationShip Diagram",

@@ -21,3 +21,3 @@ "main": "./dist/prisma-uml.js",

"snyk-protect": "snyk protect",
"prepare": "yarn run snyk-protect"
"prepare": "yarn run snyk-protect && husky install"
},

@@ -46,2 +46,11 @@ "release": {

"license": "MIT",
"dependencies": {
"@prisma/sdk": "^2.21.2",
"axios": "^0.21.1",
"chalk": "^4.1.0",
"snyk": "^1.667.0",
"typescript-generic-datastructures": "^1.3.0",
"uuid": "^8.3.2",
"yargs": "^16.2.0"
},
"devDependencies": {

@@ -57,4 +66,7 @@ "@babel/core": "^7.9.0",

"babel-loader": "^8.1.0",
"husky": ">=6",
"jest": "^25.3.0",
"lint-staged": ">=10",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"semantic-release": "^17.0.7",

@@ -71,12 +83,12 @@ "source-map-loader": "^0.2.4",

},
"dependencies": {
"@prisma/sdk": "^2.3.0",
"axios": "^0.21.1",
"chalk": "^4.1.0",
"typescript-generic-datastructures": "^1.3.0",
"uuid": "^8.3.2",
"yargs": "^16.2.0",
"snyk": "^1.465.0"
"snyk": true,
"lint-staged": {
"*.{ts,js,css,md}": "prettier --write"
},
"snyk": true
"prettier": {
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
}