@@ -898,7 +898,7 @@ const sharedUtils_1 = require("./utils/sharedUtils");
898898const constants_1 = require ( "./utils/constants" ) ;
899899/**
900900 * SQL Tools Plugin for importing diagrams from SQL DDL and exporting to SQL.
901- * Version: 0.0.4
901+ * Version: 0.0.5
902902 */
903903Draw . loadPlugin ( function ( ui ) {
904904 // export sql methods
@@ -1035,7 +1035,6 @@ Draw.loadPlugin(function (ui) {
10351035 tableCell . insert ( rowCell ) ;
10361036 tableCell . geometry . height += 26 ;
10371037 }
1038- rowCell = rowCell ;
10391038 }
10401039 ;
10411040 function parseSql ( text , type ) {
@@ -1229,9 +1228,16 @@ Draw.loadPlugin(function (ui) {
12291228} , { "./utils/constants" :5 , "./utils/sharedUtils" :6 , "@funktechno/little-mermaid-2-the-sql/lib/src/generate-sql-ddl" :1 , "@funktechno/sqlsimpleparser" :3 } ] , 5 :[ function ( require , module , exports ) {
12301229"use strict" ;
12311230Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
1232- exports . pluginVersion = void 0 ;
1231+ exports . validEnumTypes = exports . enumKeyword = exports . formatKeyword = exports . commentColumnQuantifiers = exports . pluginVersion = void 0 ;
12331232// export sql methods
1234- exports . pluginVersion = "0.0.4" ;
1233+ exports . pluginVersion = "0.0.5" ;
1234+ exports . commentColumnQuantifiers = {
1235+ Start : "/**" ,
1236+ End : "*/" ,
1237+ } ;
1238+ exports . formatKeyword = "@format" ;
1239+ exports . enumKeyword = "enum" ;
1240+ exports . validEnumTypes = [ "string" , "number" , "integer" , "boolean" ] ;
12351241
12361242} , { } ] , 6 :[ function ( require , module , exports ) {
12371243"use strict" ;
@@ -1241,7 +1247,12 @@ exports.removeHtml = removeHtml;
12411247exports . dbTypeEnds = dbTypeEnds ;
12421248exports . RemoveNameQuantifiers = RemoveNameQuantifiers ;
12431249exports . getDbLabel = getDbLabel ;
1250+ exports . entityName = entityName ;
1251+ exports . getCommentIndexes = getCommentIndexes ;
12441252exports . getMermaidDiagramDb = getMermaidDiagramDb ;
1253+ exports . GenerateDatabaseModel = GenerateDatabaseModel ;
1254+ exports . generateComment = generateComment ;
1255+ const constants_1 = require ( "./constants" ) ;
12451256/**
12461257 * return text quantifiers for dialect
12471258 * @returns json
@@ -1307,6 +1318,34 @@ function getDbLabel(label, columnQuantifiers) {
13071318 } ;
13081319 return attribute ;
13091320}
1321+ function entityName ( description , format ) {
1322+ let result = "" ;
1323+ if ( description ) {
1324+ result += `${ description } ` ;
1325+ }
1326+ if ( format ) {
1327+ result += ` @format ${ format } ` ;
1328+ }
1329+ if ( result ) {
1330+ result = result . trim ( ) ;
1331+ result = `/** ${ result } */` ;
1332+ }
1333+ return result ;
1334+ }
1335+ function getCommentIndexes ( result ) {
1336+ let hasComment = false ;
1337+ if ( result . indexOf ( constants_1 . commentColumnQuantifiers . Start ) !== - 1 && result . indexOf ( constants_1 . commentColumnQuantifiers . End ) !== - 1 ) {
1338+ hasComment = true ;
1339+ }
1340+ const beforeIndex = hasComment ? result . indexOf ( constants_1 . commentColumnQuantifiers . Start ) : - 1 ;
1341+ const firstSpaceIndex = hasComment ? result . indexOf ( constants_1 . commentColumnQuantifiers . Start ) + constants_1 . commentColumnQuantifiers . Start . length : - 1 ;
1342+ const lastSpaceIndex = hasComment ? result . indexOf ( constants_1 . commentColumnQuantifiers . End ) - 1 : - 1 ;
1343+ return {
1344+ beforeStart : beforeIndex ,
1345+ start : firstSpaceIndex ,
1346+ end : lastSpaceIndex
1347+ } ;
1348+ }
13101349/**
13111350 * generate db from drawio graph models
13121351 * @param ui
@@ -1319,16 +1358,43 @@ function getMermaidDiagramDb(ui, type) {
13191358 // only difference is entities is an array rather than object to allow duplicate tables
13201359 const entities = { } ;
13211360 const relationships = [ ] ;
1361+ // TODO: support for ts and openapi enum
13221362 // build models
13231363 for ( const key in model . cells ) {
13241364 if ( Object . hasOwnProperty . call ( model . cells , key ) ) {
13251365 const mxcell = model . cells [ key ] ;
13261366 if ( mxcell . mxObjectId . indexOf ( "mxCell" ) !== - 1 ) {
13271367 if ( mxcell . style && mxcell . style . trim ( ) . startsWith ( "swimlane;" ) ) {
1368+ let entityName = mxcell . value . toString ( ) ;
1369+ let description = "" ;
1370+ let formatValue = "" ;
1371+ if ( ( entityName === null || entityName === void 0 ? void 0 : entityName . includes ( constants_1 . commentColumnQuantifiers . Start ) ) &&
1372+ ( entityName === null || entityName === void 0 ? void 0 : entityName . includes ( constants_1 . commentColumnQuantifiers . End ) ) ) {
1373+ let result = entityName . toString ( ) ;
1374+ const commentIndexes = getCommentIndexes ( result ) ;
1375+ const firstSpaceIndex = commentIndexes . start ;
1376+ const lastSpaceIndex = commentIndexes . end ;
1377+ entityName = result . substring ( 0 , commentIndexes . beforeStart ) ;
1378+ result = result . substring ( firstSpaceIndex , lastSpaceIndex ) ;
1379+ if ( result . indexOf ( constants_1 . formatKeyword ) !== - 1 ) {
1380+ const formatIndex = result . indexOf ( constants_1 . formatKeyword ) ;
1381+ formatValue = result . substring ( formatIndex + constants_1 . formatKeyword . length ) . trim ( ) ;
1382+ result = result . substring ( 0 , formatIndex ) ;
1383+ }
1384+ if ( result ) {
1385+ description = result ;
1386+ }
1387+ // decription = attribute.attributeType?.replace("/**", "").replace("*/", "");
1388+ }
13281389 const entity = {
1329- name : RemoveNameQuantifiers ( mxcell . value ) ,
1390+ name : RemoveNameQuantifiers ( entityName ) ,
13301391 attributes : [ ] ,
13311392 } ;
1393+ const comment = generateComment ( description , formatValue ) ;
1394+ if ( comment ) {
1395+ entity . name += comment ;
1396+ }
1397+ // const comment =
13321398 for ( let c = 0 ; c < mxcell . children . length ; c ++ ) {
13331399 const col = mxcell . children [ c ] ;
13341400 if ( col . mxObjectId . indexOf ( "mxCell" ) !== - 1 ) {
@@ -1482,6 +1548,10 @@ function getMermaidDiagramDb(ui, type) {
14821548 }
14831549 }
14841550 }
1551+ const db = GenerateDatabaseModel ( entities , relationships ) ;
1552+ return db ;
1553+ }
1554+ function GenerateDatabaseModel ( entities , relationships ) {
14851555 class DatabaseModel {
14861556 constructor ( entities , relationships ) {
14871557 this . entities = entities ;
@@ -1497,5 +1567,19 @@ function getMermaidDiagramDb(ui, type) {
14971567 const db = new DatabaseModel ( entities , relationships ) ;
14981568 return db ;
14991569}
1570+ function generateComment ( description , formatValue ) {
1571+ let result = "" ;
1572+ if ( description ) {
1573+ result += `${ description } ` ;
1574+ }
1575+ if ( formatValue ) {
1576+ result += ` @format ${ formatValue } ` ;
1577+ }
1578+ if ( result ) {
1579+ result = result . trim ( ) ;
1580+ result = `${ constants_1 . commentColumnQuantifiers . Start } ${ result } ${ constants_1 . commentColumnQuantifiers . End } ` ;
1581+ }
1582+ return result ;
1583+ }
15001584
1501- } , { } ] } , { } , [ 4 ] ) ;
1585+ } , { "./constants" : 5 } ] } , { } , [ 4 ] ) ;
0 commit comments