Skip to content

Commit a6af1d1

Browse files
authored
Merge pull request #39 from funktechno/dev
v0.0.5
2 parents 8075d7f + edd3276 commit a6af1d1

21 files changed

+3756
-4731
lines changed

.eslintrc

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ jobs:
1818
with:
1919
node-version: current
2020
- run: npm ci
21+
- run: npm run lint
2122
- run: npm test
2223
- run: npm run build:client:all

dist/nosql-ts.js

Lines changed: 367 additions & 140 deletions
Large diffs are not rendered by default.

dist/nosql-ts.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/nosql.js

Lines changed: 367 additions & 140 deletions
Large diffs are not rendered by default.

dist/nosql.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sql.js

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ const sharedUtils_1 = require("./utils/sharedUtils");
898898
const 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
*/
903903
Draw.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";
12311230
Object.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;
12411247
exports.dbTypeEnds = dbTypeEnds;
12421248
exports.RemoveNameQuantifiers = RemoveNameQuantifiers;
12431249
exports.getDbLabel = getDbLabel;
1250+
exports.entityName = entityName;
1251+
exports.getCommentIndexes = getCommentIndexes;
12441252
exports.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]);

eslint.config.mjs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
5+
export default [
6+
pluginJs.configs.recommended,
7+
...tseslint.configs.recommended,
8+
{
9+
files: ["**/*.{js,mjs,cjs,ts}"],
10+
rules: {
11+
semi: ["error", "always"],
12+
quotes: ["error", "double"],
13+
"@typescript-eslint/explicit-function-return-type": "off",
14+
"@typescript-eslint/camelcase": "off",
15+
"@typescript-eslint/no-unsafe-function-type": "off",
16+
"@typescript-eslint/no-explicit-any": "off",
17+
"no-useless-escape": "off",
18+
"no-multiple-empty-lines": "error",
19+
"no-use-before-define": "off",
20+
"@typescript-eslint/no-non-null-assertion": "off",
21+
"@typescript-eslint/no-use-before-define": "off",
22+
"@typescript-eslint/no-inferrable-types": [
23+
"warn",
24+
{
25+
ignoreParameters: true,
26+
},
27+
],
28+
"@typescript-eslint/no-unused-vars": "warn",
29+
"@typescript-eslint/class-name-casing": "off",
30+
},
31+
ignores: ["lib/*", "deps/*", "dist/*", "archived"],
32+
},
33+
{
34+
files: ["**/__tests__/*.{j,t}s?(x)", "**/tests/**/*.spec.{j,t}s?(x)"],
35+
env: {
36+
jest: true,
37+
},
38+
},
39+
{ languageOptions: { globals: globals.browser } }
40+
];

jest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const config: Config = {
44
verbose: true,
55
globals: {
66
"ts-jest": {
7-
tsConfig: "tsconfig.json",
7+
tsconfig: "tsconfig.json",
88
},
99
},
1010
moduleFileExtensions: ["ts", "js"],
@@ -13,6 +13,7 @@ const config: Config = {
1313
},
1414
testMatch: ["**/tests/**/*.spec.(ts|js)"],
1515
// runner: "jest-serial-runner",
16+
testEnvironment: "jsdom",
1617
// testEnvironment: "node",
1718
reporters: ["default", "jest-junit"],
1819
collectCoverageFrom: ["src/**/*.{ts,js}", "!**/node_modules/**", "!**/lib/**"]

0 commit comments

Comments
 (0)