@dbml/core 3.4.1 → 3.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -192,9 +192,9 @@ var DbmlExporter = /*#__PURE__*/function () {
192
192
  var tableSettingStr = _this.getTableSettings(table);
193
193
  var indexStr = '';
194
194
  if (!_lodash["default"].isEmpty(tableContent.indexContents)) {
195
- indexStr = "\nIndexes {\n".concat(tableContent.indexContents.map(function (indexLine) {
196
- return " ".concat(indexLine);
197
- }).join('\n'), "\n}");
195
+ indexStr = "\n Indexes {\n".concat(tableContent.indexContents.map(function (indexLine) {
196
+ return " ".concat(indexLine);
197
+ }).join('\n'), "\n }");
198
198
  }
199
199
  var tableNote = table.note ? " Note: ".concat(DbmlExporter.escapeNote(table.note), "\n") : '';
200
200
  var tableStr = "Table ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(table.name, "\"").concat(tableSettingStr, " {\n").concat(tableContent.fieldContents.map(function (line) {
@@ -29,12 +29,14 @@ var IndexColumn = /*#__PURE__*/function (_Element) {
29
29
  var _this;
30
30
  var type = _ref.type,
31
31
  value = _ref.value,
32
- index = _ref.index;
32
+ index = _ref.index,
33
+ token = _ref.token;
33
34
  _classCallCheck(this, IndexColumn);
34
35
  _this = _super.call(this);
35
36
  _this.type = type;
36
37
  _this.value = value;
37
38
  _this.index = index;
39
+ _this.token = token;
38
40
  _this.dbState = _this.index.dbState;
39
41
  _this.generateId();
40
42
  return _this;
@@ -920,7 +920,7 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
920
920
  var schemaName = names.length > 1 ? names[names.length - 2] : undefined;
921
921
  var cmds = ctx.alter_table_cmds().accept(this);
922
922
  return cmds.map(function (cmd) {
923
- if (!cmd) return;
923
+ if (!cmd) return null;
924
924
  var kind = null;
925
925
  switch (cmd.kind) {
926
926
  case _constants.TABLE_CONSTRAINT_KIND.FK:
@@ -929,6 +929,39 @@ var PostgresASTGen = /*#__PURE__*/function (_PostgreSQLParserVisi) {
929
929
  cmd.value.endpoints[0].schemaName = schemaName;
930
930
  _this8.data.refs.push(cmd.value);
931
931
  break;
932
+ case _constants.TABLE_CONSTRAINT_KIND.UNIQUE:
933
+ case _constants.TABLE_CONSTRAINT_KIND.PK:
934
+ case _constants.TABLE_CONSTRAINT_KIND.INDEX:
935
+ {
936
+ if (cmd.value.columns.length === 0) break;
937
+ if (!(cmd.value.pk || cmd.value.unique)) break;
938
+ // eslint-disable-next-line prefer-destructuring
939
+ kind = cmd.kind;
940
+ var table = findTable(_this8.data.tables, schemaName, tableName);
941
+ if (!table) break;
942
+ if (cmd.value.columns.length === 1 && (cmd.value.unique || cmd.value.pk)) {
943
+ var key = cmd.value.columns[0].value;
944
+ var fieldToUpdate = table.fields.find(function (f) {
945
+ return f.name === key;
946
+ });
947
+ if (fieldToUpdate) {
948
+ // If we have an exact match, this is a column, if not, might be an expression
949
+ fieldToUpdate[cmd.value.unique ? 'unique' : 'pk'] = true;
950
+ break;
951
+ }
952
+ }
953
+ // multi column constraint -> need to create new index
954
+ var index = new _AST.Index({
955
+ name: cmd.value.name,
956
+ columns: cmd.value.columns,
957
+ note: cmd.value.note,
958
+ pk: cmd.value.pk,
959
+ type: cmd.value.type,
960
+ unique: cmd.value.unique
961
+ });
962
+ table.indexes.push(index);
963
+ break;
964
+ }
932
965
  default:
933
966
  break;
934
967
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/core",
3
- "version": "3.4.1",
3
+ "version": "3.4.3",
4
4
  "description": "> TODO: description",
5
5
  "author": "Holistics <dev@holistics.io>",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  "prepublish": "npm run build"
33
33
  },
34
34
  "dependencies": {
35
- "@dbml/parse": "^3.4.1",
35
+ "@dbml/parse": "^3.4.3",
36
36
  "antlr4": "^4.13.1",
37
37
  "lodash": "^4.17.15",
38
38
  "parsimmon": "^1.13.0",
@@ -59,5 +59,5 @@
59
59
  "\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
60
60
  }
61
61
  },
62
- "gitHead": "cbec59d485564023f5d2d95e10ad6379cc8d00fb"
62
+ "gitHead": "57885a9d08f8b5bc33aa629432a6ecf8e839d71a"
63
63
  }
@@ -1,72 +0,0 @@
1
- "use strict";
2
-
3
- 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); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _element = _interopRequireDefault(require("./element"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
15
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
19
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
20
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
21
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
22
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
23
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
24
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
25
- var Note = /*#__PURE__*/function (_Element) {
26
- _inherits(Note, _Element);
27
- var _super = _createSuper(Note);
28
- function Note() {
29
- var _this;
30
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
31
- name = _ref.name,
32
- content = _ref.content,
33
- headerColor = _ref.headerColor,
34
- token = _ref.token,
35
- _ref$database = _ref.database,
36
- database = _ref$database === void 0 ? {} : _ref$database;
37
- _classCallCheck(this, Note);
38
- _this = _super.call(this, token);
39
- _this.name = name;
40
- _this.content = content;
41
- _this.headerColor = headerColor;
42
- _this.database = database;
43
- _this.dbState = _this.database.dbState;
44
- _this.generateId();
45
- return _this;
46
- }
47
- _createClass(Note, [{
48
- key: "generateId",
49
- value: function generateId() {
50
- this.id = this.dbState.generateId('noteId');
51
- }
52
- }, {
53
- key: "export",
54
- value: function _export() {
55
- return {
56
- name: this.name,
57
- content: this.content,
58
- headerColor: this.headerColor
59
- };
60
- }
61
- }, {
62
- key: "normalize",
63
- value: function normalize(model) {
64
- model.notes = _objectSpread(_objectSpread({}, model.notes), {}, _defineProperty({}, this.id, _objectSpread({
65
- id: this.id
66
- }, this["export"]())));
67
- }
68
- }]);
69
- return Note;
70
- }(_element["default"]);
71
- var _default = Note;
72
- exports["default"] = _default;