Skip to content

Commit

Permalink
Merge pull request #44 from funktechno/f/updates
Browse files Browse the repository at this point in the history
F/updates code format
  • Loading branch information
lastlink authored Jul 6, 2024
2 parents 8505b2d + 201aae1 commit 161645d
Show file tree
Hide file tree
Showing 9 changed files with 887 additions and 760 deletions.
32 changes: 14 additions & 18 deletions dist/nosql-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -200894,15 +200894,16 @@ Draw.loadPlugin(function (ui) {
if (type == "ts") {
const { data: doc } = (0, core_types_json_schema_1.convertOpenApiToCoreTypes)(openapi);
const { data: sourceCode } = (0, core_types_ts_1.convertCoreTypesToTypeScript)(doc);
result = `/*\n\tGenerated in drawio\n\tDatabase: ${type}\n\tPlugin: nosql\n\tVersion: ${constants_1.pluginVersion}\n*/\n\n` + result;
result =
`/*\n\tGenerated in drawio\n\tDatabase: ${type}\n\tPlugin: nosql\n\tVersion: ${constants_1.pluginVersion}\n*/\n\n` +
result;
result += sourceCode;
}
else if (type == "openapi") {
result = JSON.stringify(openapi, null, 2);
}
sqlInputGenSQL.value = result;
}
;
mxUtils.br(divGenSQL);
const resetBtnGenSQL = mxUtils.button(mxResources.get("reset"), function () {
sqlInputGenSQL.value = sqlExportDefault;
Expand Down Expand Up @@ -200971,7 +200972,7 @@ Draw.loadPlugin(function (ui) {
let openApi = null;
const openApiOptions = {
title: "nosql default options",
version: constants_1.pluginVersion
version: constants_1.pluginVersion,
};
if (type == "openapi") {
// should already be a json, but going to serialize to openapi for validation
Expand Down Expand Up @@ -201009,7 +201010,6 @@ Draw.loadPlugin(function (ui) {
console.log(error);
}
}
;
mxUtils.br(divFromNOSQL);
const resetBtnFromNOSQL = mxUtils.button(mxResources.get("Reset TS"), function () {
sqlInputFromNOSQL.value = constants_nosql_1.defaultReset;
Expand Down Expand Up @@ -201178,7 +201178,7 @@ const JSONSchemaTypes = [
"object",
"array",
"null",
"any"
"any",
];
exports.validJSONSchemaTypes = JSONSchemaTypes;

Expand Down Expand Up @@ -201357,32 +201357,35 @@ function dbToOpenApi(db) {
//
}
else {
// else {
removeType = true;
$ref = `#/components/schemas/${(0, sharedUtils_1.RemoveNameQuantifiers)(type)}`;
}
}
if (["array", "object"].indexOf(type) !== -1) {
const relationships = db.getRelationships().filter(x => x.entityA == key);
const relationships = db
.getRelationships()
.filter((x) => x.entityA == key);
const roleLookup = `[${key}.${propName}]`;
// FIND MATCH
const rel = relationships.find(x => x.roleA.indexOf(roleLookup) != -1);
const rel = relationships.find((x) => x.roleA.indexOf(roleLookup) != -1);
if (rel) {
const commentFKIndexes = (0, sharedUtils_1.getCommentIndexes)(rel.entityB);
const entityBName = rel.entityB.substring(0, commentFKIndexes.beforeStart).trim();
const entityBName = rel.entityB
.substring(0, commentFKIndexes.beforeStart)
.trim();
$ref = `#/components/schemas/${entityBName}`;
}
if ($ref) {
// if array additionalProperties.$ref
if (type == "array") {
items = {
$ref: $ref
$ref: $ref,
};
}
// if object items.$ref
if (type == "object") {
additionalProperties = {
$ref: $ref
$ref: $ref,
};
}
}
Expand Down Expand Up @@ -201443,9 +201446,7 @@ function GeneratePropertyModel(tableName, propertyName, property) {
if (property.items && typeof property.items === constants_1.objectKeyword) {
if (property.items.format && !property.format) {
property.format = property.items.format;
// columnProperties = `${(property.items as JSONSchema4).format}[]`;
}
// else
if (property.items.type)
columnProperties = `${property.items.type}[]`;
}
Expand Down Expand Up @@ -201549,10 +201550,6 @@ function ConvertOpenApiToDatabaseModel(schemas) {
property.type = refName;
}
const propertyModel = GeneratePropertyModel(tableModel.Name, propertyKey, property);
// if (
// propertyModel.ColumnProperties.includes(objectKeyword) ||
// propertyModel.ColumnProperties.includes(arrayKeyword)
// ) {
if (refName) {
const primaryKeyModel = {
PrimaryKeyTableName: tableModel.Name,
Expand All @@ -201574,7 +201571,6 @@ function ConvertOpenApiToDatabaseModel(schemas) {
models.ForeignKeyList.push(primaryKeyModel);
propertyModel.IsForeignKey = true;
}
// }
tableModel.Properties.push(propertyModel);
}
}
Expand Down
28 changes: 11 additions & 17 deletions dist/nosql.js
Original file line number Diff line number Diff line change
Expand Up @@ -4650,7 +4650,6 @@ Draw.loadPlugin(function (ui) {
}
sqlInputGenSQL.value = result;
}
;
mxUtils.br(divGenSQL);
const resetBtnGenSQL = mxUtils.button(mxResources.get("reset"), function () {
sqlInputGenSQL.value = sqlExportDefault;
Expand Down Expand Up @@ -4713,7 +4712,7 @@ Draw.loadPlugin(function (ui) {
let openApi = null;
const openApiOptions = {
title: "nosql default options",
version: constants_1.pluginVersion
version: constants_1.pluginVersion,
};
if (type == "openapi") {
// should already be a json, but going to serialize to openapi for validation
Expand Down Expand Up @@ -4748,7 +4747,6 @@ Draw.loadPlugin(function (ui) {
console.log(error);
}
}
;
mxUtils.br(divFromNOSQL);
const resetOpenAPIBtnFromNOSQL = mxUtils.button("Reset OpenAPI", function () {
sqlInputFromNOSQL.value = constants_nosql_1.defaultResetOpenApi;
Expand Down Expand Up @@ -4904,7 +4902,7 @@ const JSONSchemaTypes = [
"object",
"array",
"null",
"any"
"any",
];
exports.validJSONSchemaTypes = JSONSchemaTypes;

Expand Down Expand Up @@ -5083,32 +5081,35 @@ function dbToOpenApi(db) {
//
}
else {
// else {
removeType = true;
$ref = `#/components/schemas/${(0, sharedUtils_1.RemoveNameQuantifiers)(type)}`;
}
}
if (["array", "object"].indexOf(type) !== -1) {
const relationships = db.getRelationships().filter(x => x.entityA == key);
const relationships = db
.getRelationships()
.filter((x) => x.entityA == key);
const roleLookup = `[${key}.${propName}]`;
// FIND MATCH
const rel = relationships.find(x => x.roleA.indexOf(roleLookup) != -1);
const rel = relationships.find((x) => x.roleA.indexOf(roleLookup) != -1);
if (rel) {
const commentFKIndexes = (0, sharedUtils_1.getCommentIndexes)(rel.entityB);
const entityBName = rel.entityB.substring(0, commentFKIndexes.beforeStart).trim();
const entityBName = rel.entityB
.substring(0, commentFKIndexes.beforeStart)
.trim();
$ref = `#/components/schemas/${entityBName}`;
}
if ($ref) {
// if array additionalProperties.$ref
if (type == "array") {
items = {
$ref: $ref
$ref: $ref,
};
}
// if object items.$ref
if (type == "object") {
additionalProperties = {
$ref: $ref
$ref: $ref,
};
}
}
Expand Down Expand Up @@ -5169,9 +5170,7 @@ function GeneratePropertyModel(tableName, propertyName, property) {
if (property.items && typeof property.items === constants_1.objectKeyword) {
if (property.items.format && !property.format) {
property.format = property.items.format;
// columnProperties = `${(property.items as JSONSchema4).format}[]`;
}
// else
if (property.items.type)
columnProperties = `${property.items.type}[]`;
}
Expand Down Expand Up @@ -5275,10 +5274,6 @@ function ConvertOpenApiToDatabaseModel(schemas) {
property.type = refName;
}
const propertyModel = GeneratePropertyModel(tableModel.Name, propertyKey, property);
// if (
// propertyModel.ColumnProperties.includes(objectKeyword) ||
// propertyModel.ColumnProperties.includes(arrayKeyword)
// ) {
if (refName) {
const primaryKeyModel = {
PrimaryKeyTableName: tableModel.Name,
Expand All @@ -5300,7 +5295,6 @@ function ConvertOpenApiToDatabaseModel(schemas) {
models.ForeignKeyList.push(primaryKeyModel);
propertyModel.IsForeignKey = true;
}
// }
tableModel.Properties.push(propertyModel);
}
}
Expand Down
12 changes: 4 additions & 8 deletions dist/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,14 +935,15 @@ Draw.loadPlugin(function (ui) {
const parser = new generate_sql_ddl_1.DbParser(type, db);
// generate sql
let sql = parser.getSQLDataDefinition();
sql = `/*\n\tGenerated in drawio\n\tDatabase: ${type}\n\tPlugin: sql\n\tVersion: ${constants_1.pluginVersion}\n*/\n\n` + sql;
sql =
`/*\n\tGenerated in drawio\n\tDatabase: ${type}\n\tPlugin: sql\n\tVersion: ${constants_1.pluginVersion}\n*/\n\n` +
sql;
sql = sql.trim();
// update sql value in text area
sqlInputGenSQL.value = sql;
// TODO: use selection as well?
// const modelSelected = ui.editor.graph.getSelectionModel();
}
;
mxUtils.br(divGenSQL);
const resetBtnGenSQL = mxUtils.button(mxResources.get("reset"), function () {
sqlInputGenSQL.value = sqlExportDefault;
Expand Down Expand Up @@ -1023,11 +1024,7 @@ Draw.loadPlugin(function (ui) {
rowCell = null;
// load parser
const parser = new sqlsimpleparser_1.SqlSimpleParser(type);
const models = parser
.feed(text)
.WithoutEnds()
.WithEnds()
.ToModel();
const models = parser.feed(text).WithoutEnds().WithEnds().ToModel();
foreignKeyList = models.ForeignKeyList;
primaryKeyList = models.PrimaryKeyList;
tableList = models.TableList;
Expand All @@ -1041,7 +1038,6 @@ Draw.loadPlugin(function (ui) {
rowCell = createTableResult.rowCell;
}
}
;
mxUtils.br(divFromSQL);
const resetBtnFromSQL = mxUtils.button(mxResources.get("reset"), function () {
sqlInputFromSQL.value = defaultReset;
Expand Down
Loading

0 comments on commit 161645d

Please sign in to comment.