@dbml/core 3.1.8-alpha.0 → 3.1.8

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.
@@ -3,13 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TABLE_GROUP = exports.TABLE = exports.REF = exports.NOTE = exports.ENUM = exports.DEFAULT_SCHEMA_NAME = void 0;
6
+ exports.TABLE_GROUP = exports.TABLE = exports.REF = exports.ENUM = exports.DEFAULT_SCHEMA_NAME = void 0;
7
7
  var DEFAULT_SCHEMA_NAME = 'public';
8
8
  exports.DEFAULT_SCHEMA_NAME = DEFAULT_SCHEMA_NAME;
9
9
  var TABLE = 'table';
10
10
  exports.TABLE = TABLE;
11
- var NOTE = 'note';
12
- exports.NOTE = NOTE;
13
11
  var ENUM = 'enum';
14
12
  exports.ENUM = ENUM;
15
13
  var REF = 'ref';
@@ -11,7 +11,6 @@ var _ref2 = _interopRequireDefault(require("./ref"));
11
11
  var _enum2 = _interopRequireDefault(require("./enum"));
12
12
  var _tableGroup = _interopRequireDefault(require("./tableGroup"));
13
13
  var _table = _interopRequireDefault(require("./table"));
14
- var _stickyNote = _interopRequireDefault(require("./stickyNote"));
15
14
  var _element = _interopRequireDefault(require("./element"));
16
15
  var _config = require("./config");
17
16
  var _dbState = _interopRequireDefault(require("./dbState"));
@@ -42,8 +41,6 @@ var Database = /*#__PURE__*/function (_Element) {
42
41
  schemas = _ref$schemas === void 0 ? [] : _ref$schemas,
43
42
  _ref$tables = _ref.tables,
44
43
  tables = _ref$tables === void 0 ? [] : _ref$tables,
45
- _ref$notes = _ref.notes,
46
- notes = _ref$notes === void 0 ? [] : _ref$notes,
47
44
  _ref$enums = _ref.enums,
48
45
  enums = _ref$enums === void 0 ? [] : _ref$enums,
49
46
  _ref$refs = _ref.refs,
@@ -60,18 +57,16 @@ var Database = /*#__PURE__*/function (_Element) {
60
57
  _this.generateId();
61
58
  _this.hasDefaultSchema = false;
62
59
  _this.schemas = [];
63
- _this.notes = [];
64
60
  _this.note = project.note ? (0, _lodash.get)(project, 'note.value', project.note) : null;
65
61
  _this.noteToken = project.note ? (0, _lodash.get)(project, 'note.token', project.noteToken) : null;
66
62
  _this.databaseType = project.database_type;
67
63
  _this.name = project.name;
68
64
  _this.aliases = aliases;
69
- _this.processNotes(notes);
65
+
70
66
  // The process order is important. Do not change !
71
67
  _this.processSchemas(schemas);
72
68
  _this.processSchemaElements(enums, _config.ENUM);
73
69
  _this.processSchemaElements(tables, _config.TABLE);
74
- _this.processSchemaElements(notes, _config.NOTE);
75
70
  _this.processSchemaElements(refs, _config.REF);
76
71
  _this.processSchemaElements(tableGroups, _config.TABLE_GROUP);
77
72
  return _this;
@@ -81,38 +76,13 @@ var Database = /*#__PURE__*/function (_Element) {
81
76
  value: function generateId() {
82
77
  this.id = this.dbState.generateId('dbId');
83
78
  }
84
- }, {
85
- key: "processNotes",
86
- value: function processNotes(rawNotes) {
87
- var _this2 = this;
88
- rawNotes.forEach(function (note) {
89
- _this2.pushNote(new _stickyNote["default"](_objectSpread(_objectSpread({}, note), {}, {
90
- database: _this2
91
- })));
92
- });
93
- }
94
- }, {
95
- key: "pushNote",
96
- value: function pushNote(note) {
97
- this.checkNote(note);
98
- this.notes.push(note);
99
- }
100
- }, {
101
- key: "checkNote",
102
- value: function checkNote(note) {
103
- if (this.notes.some(function (n) {
104
- return n.name === note.name;
105
- })) {
106
- note.error("Notes ".concat(note.name, " existed"));
107
- }
108
- }
109
79
  }, {
110
80
  key: "processSchemas",
111
81
  value: function processSchemas(rawSchemas) {
112
- var _this3 = this;
82
+ var _this2 = this;
113
83
  rawSchemas.forEach(function (schema) {
114
- _this3.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, {
115
- database: _this3
84
+ _this2.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, {
85
+ database: _this2
116
86
  })));
117
87
  });
118
88
  }
@@ -134,16 +104,16 @@ var Database = /*#__PURE__*/function (_Element) {
134
104
  }, {
135
105
  key: "processSchemaElements",
136
106
  value: function processSchemaElements(elements, elementType) {
137
- var _this4 = this;
107
+ var _this3 = this;
138
108
  var schema;
139
109
  elements.forEach(function (element) {
140
110
  if (element.schemaName) {
141
- schema = _this4.findOrCreateSchema(element.schemaName);
111
+ schema = _this3.findOrCreateSchema(element.schemaName);
142
112
  if (element.schemaName === _config.DEFAULT_SCHEMA_NAME) {
143
113
  // this.hasDefaultSchema = true;
144
114
  }
145
115
  } else {
146
- schema = _this4.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
116
+ schema = _this3.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
147
117
  }
148
118
  switch (elementType) {
149
119
  case _config.TABLE:
@@ -255,9 +225,6 @@ var Database = /*#__PURE__*/function (_Element) {
255
225
  return {
256
226
  schemas: this.schemas.map(function (s) {
257
227
  return s["export"]();
258
- }),
259
- notes: this.notes.map(function (n) {
260
- return n["export"]();
261
228
  })
262
229
  };
263
230
  }
@@ -267,9 +234,6 @@ var Database = /*#__PURE__*/function (_Element) {
267
234
  return {
268
235
  schemaIds: this.schemas.map(function (s) {
269
236
  return s.id;
270
- }),
271
- noteIds: this.notes.map(function (n) {
272
- return n.id;
273
237
  })
274
238
  };
275
239
  }
@@ -281,7 +245,6 @@ var Database = /*#__PURE__*/function (_Element) {
281
245
  id: this.id
282
246
  }, this.shallowExport()), this.exportChildIds())),
283
247
  schemas: {},
284
- notes: {},
285
248
  refs: {},
286
249
  enums: {},
287
250
  tableGroups: {},
@@ -295,9 +258,6 @@ var Database = /*#__PURE__*/function (_Element) {
295
258
  this.schemas.forEach(function (schema) {
296
259
  return schema.normalize(normalizedModel);
297
260
  });
298
- this.notes.forEach(function (note) {
299
- return note.normalize(normalizedModel);
300
- });
301
261
  return normalizedModel;
302
262
  }
303
263
  }]);
@@ -19,7 +19,6 @@ var DbState = /*#__PURE__*/function () {
19
19
  this.tableGroupId = 1;
20
20
  this.refId = 1;
21
21
  this.tableId = 1;
22
- this.noteId = 1;
23
22
  this.enumValueId = 1;
24
23
  this.endpointId = 1;
25
24
  this.indexId = 1;
@@ -129,11 +129,6 @@ var Parser = /*#__PURE__*/function () {
129
129
  value: function parseMSSQLToJSON(str) {
130
130
  return _mssqlParser["default"].parseWithPegError(str);
131
131
  }
132
- }, {
133
- key: "parse",
134
- value: function parse(str, format) {
135
- return new Parser().parse(str, format);
136
- }
137
132
  }]);
138
133
  return Parser;
139
134
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/core",
3
- "version": "3.1.8-alpha.0",
3
+ "version": "3.1.8",
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.1.8-alpha.0",
35
+ "@dbml/parse": "^3.1.8",
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": "6e0430bbe735bad5c9619fe13eb4baf161163503"
62
+ "gitHead": "865bf404680f008d9282e8859412c702d5fc6e2b"
63
63
  }
@@ -3,7 +3,6 @@ import Ref, { NormalizedRef } from './ref';
3
3
  import Enum, { NormalizedEnum } from './enum';
4
4
  import TableGroup, { NormalizedTableGroup } from './tableGroup';
5
5
  import Table, { NormalizedTable } from './table';
6
- import StickyNote, { NormalizedStickyNote } from './stickyNote';
7
6
  import Element, { RawNote, Token } from './element';
8
7
  import DbState from './dbState';
9
8
  import { NormalizedEndpoint } from './endpoint';
@@ -19,7 +18,6 @@ export interface Project {
19
18
  export interface RawDatabase {
20
19
  schemas: Schema[];
21
20
  tables: Table[];
22
- notes: StickyNote[];
23
21
  enums: Enum[];
24
22
  refs: Ref[];
25
23
  tableGroups: TableGroup[];
@@ -29,7 +27,6 @@ declare class Database extends Element {
29
27
  dbState: DbState;
30
28
  hasDefaultSchema: boolean;
31
29
  schemas: Schema[];
32
- notes: StickyNote[];
33
30
  note: string;
34
31
  noteToken: Token;
35
32
  databaseType: string;
@@ -102,12 +99,6 @@ declare class Database extends Element {
102
99
  note: string;
103
100
  alias: string;
104
101
  }[];
105
- notes: {
106
- id: number;
107
- name: string;
108
- content: string;
109
- headerColor: string;
110
- }[];
111
102
  };
112
103
  shallowExport(): {
113
104
  hasDefaultSchema: boolean;
@@ -174,16 +165,9 @@ declare class Database extends Element {
174
165
  note: string;
175
166
  alias: string;
176
167
  }[];
177
- notes: {
178
- id: number;
179
- name: string;
180
- content: string;
181
- headerColor: string;
182
- }[];
183
168
  };
184
169
  exportChildIds(): {
185
170
  schemaIds: number[];
186
- noteIds: number[];
187
171
  };
188
172
  normalize(): NormalizedDatabase;
189
173
  }
@@ -196,11 +180,9 @@ export interface NormalizedDatabase {
196
180
  databaseType: string;
197
181
  name: string;
198
182
  schemaIds: number[];
199
- noteIds: number[];
200
183
  };
201
184
  };
202
185
  schemas: NormalizedSchema;
203
- notes: NormalizedStickyNote;
204
186
  refs: NormalizedRef;
205
187
  enums: NormalizedEnum;
206
188
  tableGroups: NormalizedTableGroup;
@@ -5,7 +5,6 @@ export default class DbState {
5
5
  tableGroupId: number;
6
6
  refId: number;
7
7
  tableId: number;
8
- noteId: number;
9
8
  enumValueId: number;
10
9
  endpointId: number;
11
10
  indexId: number;
@@ -159,7 +159,6 @@ declare class Schema extends Element {
159
159
  };
160
160
  exportChildIds(): {
161
161
  tableIds: number[];
162
- noteIds: number[];
163
162
  enumIds: number[];
164
163
  tableGroupIds: number[];
165
164
  refIds: number[];
@@ -181,7 +180,6 @@ export interface NormalizedSchema {
181
180
  note: string;
182
181
  alias: string;
183
182
  tableIds: number[];
184
- noteIds: number[];
185
183
  enumIds: number[];
186
184
  tableGroupIds: number[];
187
185
  refIds: number[];
@@ -1,7 +1,7 @@
1
1
  import { Compiler } from '@dbml/parse';
2
2
  import Database, { RawDatabase } from '../model_structure/database';
3
3
  declare class Parser {
4
- constructor(DBMLCompiler?: Compiler);
4
+ constructor(DBMLCompiler: Compiler?);
5
5
  static parseJSONToDatabase(rawDatabase: RawDatabase): Database;
6
6
  static parseMySQLToJSON(str: string): RawDatabase;
7
7
  static parsePostgresToJSON(str: string): RawDatabase;
@@ -9,10 +9,6 @@ declare class Parser {
9
9
  static parseDBMLToJSON(str: string): RawDatabase;
10
10
  static parseSchemaRbToJSON(str: string): RawDatabase;
11
11
  static parseMSSQLToJSON(str: string): RawDatabase;
12
- /**
13
- * Should use parse() instance method instead of this static method whenever possible
14
- */
15
- static parse(str: string, format: 'mysql' | 'postgres' | 'dbml' | 'dbmlv2' | 'schemarb' | 'mssql' | 'json'): Database;
16
12
  parse(str: string, format: 'mysql' | 'postgres' | 'dbml' | 'dbmlv2' | 'schemarb' | 'mssql' | 'json'): Database;
17
13
  }
18
14
  export default Parser;
@@ -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 StickyNote = /*#__PURE__*/function (_Element) {
26
- _inherits(StickyNote, _Element);
27
- var _super = _createSuper(StickyNote);
28
- function StickyNote() {
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, StickyNote);
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(StickyNote, [{
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 StickyNote;
70
- }(_element["default"]);
71
- var _default = StickyNote;
72
- exports["default"] = _default;
@@ -1,37 +0,0 @@
1
- import Element, { Token } from './element';
2
- import Database from './database';
3
- import DbState from './dbState';
4
- import { NormalizedDatabase } from './database';
5
- interface RawStickyNote {
6
- name: string;
7
- content: string;
8
- database: Database;
9
- token: Token;
10
- headerColor: string;
11
- }
12
- declare class StickyNote extends Element {
13
- name: string;
14
- content: string;
15
- noteToken: Token;
16
- headerColor: string;
17
- database: Database;
18
- dbState: DbState;
19
- id: number;
20
- constructor({ name, content, token, headerColor, database }: RawStickyNote);
21
- generateId(): void;
22
- export(): {
23
- name: string;
24
- content: string;
25
- headerColor: string;
26
- };
27
- normalize(model: NormalizedDatabase): void;
28
- }
29
- export interface NormalizedStickyNote {
30
- [id: number]: {
31
- id: number;
32
- name: string;
33
- content: string;
34
- headerColor: string;
35
- };
36
- }
37
- export default StickyNote;