@dbml/core 3.1.5-alpha.0 → 3.1.6

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.
@@ -36,7 +36,18 @@ var DbmlExporter = /*#__PURE__*/function () {
36
36
  }, {
37
37
  key: "escapeNote",
38
38
  value: function escapeNote(str) {
39
- return str.replaceAll("'", "\\'");
39
+ if (str === null) {
40
+ return '';
41
+ }
42
+ var newStr = str.replaceAll('\\', '\\\\');
43
+ if (!newStr.match(/[\n\r']/)) {
44
+ // Only safe chars, no simple quotes nor CR/LF
45
+ return "'".concat(newStr, "'");
46
+ }
47
+ // see https://dbml.dbdiagram.io/docs/#multi-line-string
48
+ newStr = newStr.replaceAll("'''", "\\'''");
49
+ newStr = newStr.replaceAll('\r\n', '\n'); // turn all CRLF to LF
50
+ return "'''".concat(newStr, "'''");
40
51
  }
41
52
  }, {
42
53
  key: "exportEnums",
@@ -45,7 +56,7 @@ var DbmlExporter = /*#__PURE__*/function () {
45
56
  var _enum = model.enums[enumId];
46
57
  var schema = model.schemas[_enum.schemaId];
47
58
  return "Enum ".concat((0, _utils.shouldPrintSchema)(schema, model) ? "\"".concat(schema.name, "\".") : '', "\"").concat(_enum.name, "\" {\n").concat(_enum.valueIds.map(function (valueId) {
48
- return " \"".concat(model.enumValues[valueId].name, "\"").concat(model.enumValues[valueId].note ? " [note: '".concat(DbmlExporter.escapeNote(model.enumValues[valueId].note), "']") : '');
59
+ return " \"".concat(model.enumValues[valueId].name, "\"").concat(model.enumValues[valueId].note ? " [note: ".concat(DbmlExporter.escapeNote(model.enumValues[valueId].note), "]") : '');
49
60
  }).join('\n'), "\n}\n");
50
61
  });
51
62
  return enumStrs.length ? enumStrs.join('\n') : '';
@@ -93,7 +104,7 @@ var DbmlExporter = /*#__PURE__*/function () {
93
104
  constraints.push(value);
94
105
  }
95
106
  if (field.note) {
96
- constraints.push("note: '".concat(DbmlExporter.escapeNote(field.note), "'"));
107
+ constraints.push("note: ".concat(DbmlExporter.escapeNote(field.note)));
97
108
  }
98
109
  if (constraints.length > 0) {
99
110
  line += " [".concat(constraints.join(', '), "]");
@@ -185,7 +196,7 @@ var DbmlExporter = /*#__PURE__*/function () {
185
196
  return " ".concat(indexLine);
186
197
  }).join('\n'), "\n}");
187
198
  }
188
- var tableNote = table.note ? " Note: '".concat(DbmlExporter.escapeNote(table.note), "'\n") : '';
199
+ var tableNote = table.note ? " Note: ".concat(DbmlExporter.escapeNote(table.note), "\n") : '';
189
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) {
190
201
  return " ".concat(line);
191
202
  }).join('\n'), "\n").concat(indexStr ? "".concat(indexStr, "\n") : '').concat(tableNote, "}\n");
@@ -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 _note = _interopRequireDefault(require("./note"));
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 _note["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.5-alpha.0",
3
+ "version": "3.1.6",
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.5-alpha.0",
35
+ "@dbml/parse": "^3.1.6",
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": "21f760b3d70c53ca78c40720f07f99933862349e"
62
+ "gitHead": "f82965d9636209e22f31794111f37e05c5da79ce"
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 Note, { NormalizedNote } from './note';
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: Note[];
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: Note[];
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: NormalizedNote;
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,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 Note 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 NormalizedNote {
30
- [id: number]: {
31
- id: number;
32
- name: string;
33
- content: string;
34
- headerColor: string;
35
- };
36
- }
37
- export default Note;