prisma-uml
Advanced tools
Comparing version 1.1.1 to 1.1.2
#!/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 v(e){return Array.isArray(e.fields)}function y(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(v(a.value)){const e=a.value.fields.find(e=>e.type===n.name);(null==e?void 0:e.isList)?t.push("}"):t.push("|"),(null==e?void 0:e.isRequired)?t.push("|"):t.push("o")}const i={start:"",end:""};for(;t.length>0;)t.length>2?i.start+=t.pop():i.end+=t.pop();return{targetVertex:a,cardinality:i}}).map(({targetVertex:e,cardinality:r})=>{const n=`${a.value.name}.${e.value.name}`,i=Object(f.v5)(n,t);return new d.GraphEdge(a,e,{id:i,cardinality:r},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=>v(e.value)).map(e=>v(e.value)?l(e.value):void 0),a={},p=t.getAllVertices().reduce((e,t)=>(t.getEdges().forEach(t=>{t.value.id in a||(e.push({start:t.startVertex.value,cardinality:t.value.cardinality,end:t.endVertex.value}),a[t.value.id]=t.value.id)}),e),[]),y=[];return y.push(c("@startuml",2)),y.push(r.concat(n).join(`${i.Breakline}${i.Breakline}`)),y.push(c("",2)),y.push(p.map(x).join(i.Breakline)),y.push(c("",2),c("@enduml",1)),y.join("")}function x(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 w=r(0),b=r.n(w),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,E,$,A=r(4),B=r.n(A),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"}(E||(E={})),function(e){e.Output="output",e.Server="server",e.File="file"}($||($={}));const R={command:["$0 <path>"],describe:"Generate a plantUML from a Prisma schema",builder:e=>e.positional(E.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({[$.Output]:{alias:"o",describe:"Output of the diagram",type:"string",default:j.Text,choices:[j.Text,j.SVG,j.PNG,j.JPG]},[$.Server]:{alias:"s",describe:"PlantUML Server URL",type:"string",default:"https://www.plantuml.com/plantuml"},[$.File]:{alias:"f",describe:"Filename or File full path to output",type:"string"}}).check(N).version(!1),handler:async e=>{const t=e[E.Path],r=e[$.Output],n=e[$.Server],a=e[$.File];var i;const s=y(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?B.a.request({baseURL:t,url:"/img/"+n,method:"GET",responseType:"stream"}):B.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[$.Output],r=e[$.File];if(t!==j.Text&&!r)throw new M($.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?void 0:e.isList)?t.push("}"):t.push("|"),(null==e?void 0:e.isRequired)?t.push("|"):t.push("o")}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(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.1", | ||
"version": "1.1.2", | ||
"description": "A CLI to transform a Prisma schema to a PlantUML Entity RelationShip Diagram", | ||
@@ -5,0 +5,0 @@ "main": "./dist/prisma-uml.js", |
@@ -92,3 +92,3 @@ <h1 align="center">Welcome to prisma-uml 👋</h1> | ||
You might prefer to not send you diagram over the wire for some reason, `prisma-uml` allows you to specify a custom/local server. You could easily run your own local server using Docker: | ||
You might want to avoid sending your diagram over the wire for some reason, `prisma-uml` allows you to specify a custom/local server. You could easily run your own local server using Docker: | ||
@@ -111,6 +111,9 @@ ```sh | ||
- [ ] Split attributes by entity (scalar, enum, navigation fields / external type). | ||
- [ ] Group relations by entities. | ||
- [ ] NextJs Preview that run the CLI on server to render a prisma schema to a plantUML ERD ? | ||
- [ ] Put `@prisma/sdk` as PeerDependencies (support starts a beta-2) | ||
- [ ] Feat: Split attributes by entity (scalar, enum, navigation fields / external type). | ||
- [ ] Feat: Group relations by entities. | ||
- [ ] Feat: NextJs Preview that run the CLI on server to render a prisma schema to a plantUML ERD ? | ||
- [ ] Feat: Display Version Number | ||
- [ ] Feat: Handle `-o text -f my-erd.puml|.wsd|.plantuml...` | ||
- [ ] Fix: Left side / Start leaf have wrong order on `o|` | ||
- [ ] Remove `--output` in favor of extension handling (.svg, .png, .jpg, .puml...) (?) | ||
@@ -117,0 +120,0 @@ ## Authors |
14904
131