Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dbml/core

Package Overview
Dependencies
Maintainers
7
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dbml/core - npm Package Compare versions

Comparing version 3.9.1 to 3.9.2-alpha.0

96

lib/export/DbmlExporter.js

@@ -7,6 +7,5 @@ "use strict";

exports["default"] = void 0;
var _lodash = _interopRequireDefault(require("lodash"));
var _lodash = require("lodash");
var _utils = require("./utils");
var _config = require("../model_structure/config");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

@@ -190,3 +189,2 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

value: function exportTables(tableIds, model) {
var _this = this;
var tableContentArr = DbmlExporter.getTableContentArr(tableIds, model);

@@ -196,14 +194,18 @@ var tableStrs = tableContentArr.map(function (tableContent) {

var schema = model.schemas[table.schemaId];
var tableSettingStr = _this.getTableSettings(table);
var tableSettingStr = DbmlExporter.getTableSettings(table);
// Include schema name if needed
var tableName = "\"".concat(table.name, "\"");
if ((0, _utils.shouldPrintSchema)(schema, model)) tableName = "\"".concat(schema.name, "\".\"").concat(table.name, "\"");
var fieldStr = tableContent.fieldContents.map(function (field) {
return " ".concat(field, "\n");
}).join('');
var indexStr = '';
if (!_lodash["default"].isEmpty(tableContent.indexContents)) {
indexStr = "\n Indexes {\n".concat(tableContent.indexContents.map(function (indexLine) {
return " ".concat(indexLine);
}).join('\n'), "\n }");
if (!(0, _lodash.isEmpty)(tableContent.indexContents)) {
var indexBody = tableContent.indexContents.map(function (indexLine) {
return " ".concat(indexLine, "\n");
}).join('');
indexStr = "\n Indexes {\n".concat(indexBody, " }\n");
}
var tableNote = table.note ? " Note: ".concat(DbmlExporter.escapeNote(table.note), "\n") : '';
var tableStr = "Table ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\"").concat(tableSettingStr, " {\n").concat(tableContent.fieldContents.map(function (line) {
return " ".concat(line);
}).join('\n'), "\n").concat(indexStr ? "".concat(indexStr, "\n") : '').concat(tableNote, "}\n");
return tableStr;
var noteStr = table.note ? " Note: ".concat(DbmlExporter.escapeNote(table.note), "\n") : '';
return "Table ".concat(tableName).concat(tableSettingStr, " {\n").concat(fieldStr).concat(indexStr).concat(noteStr, "}\n");
});

@@ -223,3 +225,3 @@ return tableStrs.length ? tableStrs.join('\n') : '';

value: function exportRefs(refIds, model) {
var _this2 = this;
var _this = this;
var strArr = refIds.map(function (refId) {

@@ -240,3 +242,3 @@ var ref = model.refs[refId];

var refEndpointSchema = model.schemas[refEndpointTable.schemaId];
var refEndpointFieldName = _this2.buildFieldName(refEndpoint.fieldIds, model, 'dbml');
var refEndpointFieldName = _this.buildFieldName(refEndpoint.fieldIds, model, 'dbml');
if (ref.name) {

@@ -250,3 +252,3 @@ line += " ".concat((0, _utils.shouldPrintSchema)(model.schemas[ref.schemaId], model) ? "\"".concat(model.schemas[ref.schemaId].name, "\".") : '', "\"").concat(ref.name, "\"");

var foreignEndpointSchema = model.schemas[foreignEndpointTable.schemaId];
var foreignEndpointFieldName = _this2.buildFieldName(foreignEndpoint.fieldIds, model, 'dbml');
var foreignEndpointFieldName = _this.buildFieldName(foreignEndpoint.fieldIds, model, 'dbml');
if (isManyToMany) line += '<> ';else if (foreignEndpoint.relation === '1') line += '- ';else line += '< ';

@@ -270,2 +272,9 @@ line += "".concat((0, _utils.shouldPrintSchema)(foreignEndpointSchema, model) ? "\"".concat(foreignEndpointSchema.name, "\".") : '', "\"").concat(foreignEndpointTable.name, "\".").concat(foreignEndpointFieldName);

}, {
key: "getTableGroupSettings",
value: function getTableGroupSettings(tableGroup) {
var settings = [];
if (tableGroup.color) settings.push("color: ".concat(tableGroup.color));
return settings.length ? " [".concat(settings.join(', '), "]") : '';
}
}, {
key: "exportTableGroups",

@@ -276,7 +285,13 @@ value: function exportTableGroups(tableGroupIds, model) {

var groupSchema = model.schemas[group.schemaId];
return "TableGroup ".concat((0, _utils.shouldPrintSchema)(groupSchema, model) ? "\"".concat(groupSchema.name, "\".") : '', "\"").concat(group.name, "\" {\n").concat(group.tableIds.map(function (tableId) {
var groupSettingStr = DbmlExporter.getTableGroupSettings(group);
var groupNote = group.note ? " Note: ".concat(DbmlExporter.escapeNote(group.note), "\n") : '';
var groupSchemaName = (0, _utils.shouldPrintSchema)(groupSchema, model) ? "\"".concat(groupSchema.name, "\".") : '';
var groupName = "".concat(groupSchemaName, "\"").concat(group.name, "\"");
var tableNames = group.tableIds.reduce(function (result, tableId) {
var table = model.tables[tableId];
var tableSchema = model.schemas[table.schemaId];
return " ".concat((0, _utils.shouldPrintSchema)(tableSchema, model) ? "\"".concat(tableSchema.name, "\".") : '', "\"").concat(table.name, "\"");
}).join('\n'), "\n}\n");
var tableName = " ".concat((0, _utils.shouldPrintSchema)(tableSchema, model) ? "\"".concat(tableSchema.name, "\".") : '', "\"").concat(table.name, "\"");
return result + "".concat(tableName, "\n");
}, '');
return "TableGroup ".concat(groupName).concat(groupSettingStr, " {\n").concat(tableNames).concat(groupNote, "}\n");
});

@@ -286,6 +301,16 @@ return tableGroupStrs.length ? tableGroupStrs.join('\n') : '';

}, {
key: "exportStickyNotes",
value: function exportStickyNotes(model) {
return (0, _lodash.reduce)(model.notes, function (result, note) {
var escapedContent = " ".concat(DbmlExporter.escapeNote(note.content));
var stickyNote = "Note ".concat(note.name, " {\n").concat(escapedContent, "\n}\n");
// Add a blank line between note elements
return result ? result + '\n' + stickyNote : stickyNote;
}, '');
}
}, {
key: "export",
value: function _export(model) {
var res = '';
var hasBlockAbove = false;
var elementStrs = [];
var database = model.database['1'];

@@ -298,24 +323,11 @@ database.schemaIds.forEach(function (schemaId) {

refIds = _model$schemas$schema.refIds;
if (!_lodash["default"].isEmpty(enumIds)) {
if (hasBlockAbove) res += '\n';
res += DbmlExporter.exportEnums(enumIds, model);
hasBlockAbove = true;
}
if (!_lodash["default"].isEmpty(tableIds)) {
if (hasBlockAbove) res += '\n';
res += DbmlExporter.exportTables(tableIds, model);
hasBlockAbove = true;
}
if (!_lodash["default"].isEmpty(tableGroupIds)) {
if (hasBlockAbove) res += '\n';
res += DbmlExporter.exportTableGroups(tableGroupIds, model);
hasBlockAbove = true;
}
if (!_lodash["default"].isEmpty(refIds)) {
if (hasBlockAbove) res += '\n';
res += DbmlExporter.exportRefs(refIds, model);
hasBlockAbove = true;
}
if (!(0, _lodash.isEmpty)(enumIds)) elementStrs.push(DbmlExporter.exportEnums(enumIds, model));
if (!(0, _lodash.isEmpty)(tableIds)) elementStrs.push(DbmlExporter.exportTables(tableIds, model));
if (!(0, _lodash.isEmpty)(tableGroupIds)) elementStrs.push(DbmlExporter.exportTableGroups(tableGroupIds, model));
if (!(0, _lodash.isEmpty)(refIds)) elementStrs.push(DbmlExporter.exportRefs(refIds, model));
});
return res;
if (!(0, _lodash.isEmpty)(model.notes)) elementStrs.push(DbmlExporter.exportStickyNotes(model));
// all elements already end with 1 '\n', so join('\n') to separate them with 1 blank line
return elementStrs.join('\n');
}

@@ -322,0 +334,0 @@ }]);

{
"name": "@dbml/core",
"version": "3.9.1",
"version": "3.9.2-alpha.0",
"description": "> TODO: description",

@@ -35,3 +35,3 @@ "author": "Holistics <dev@holistics.io>",

"dependencies": {
"@dbml/parse": "^3.9.1",
"@dbml/parse": "^3.9.2-alpha.0",
"antlr4": "^4.13.1",

@@ -63,3 +63,3 @@ "lodash": "^4.17.15",

},
"gitHead": "8494c278b97347945cf3b71d6f75cd658dbae85d",
"gitHead": "269532f01f0475328ef08c72ec2ca901a91b0846",
"engines": {

@@ -66,0 +66,0 @@ "node": ">=16"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc