@dbml/core 3.12.0 → 3.13.0-alpha.1

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.
Files changed (161) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +0 -0
  3. package/lib/export/DbmlExporter.js +0 -0
  4. package/lib/export/JsonExporter.js +0 -0
  5. package/lib/export/ModelExporter.js +0 -0
  6. package/lib/export/MysqlExporter.js +0 -0
  7. package/lib/export/OracleExporter.js +0 -0
  8. package/lib/export/PostgresExporter.js +0 -0
  9. package/lib/export/README.md +0 -0
  10. package/lib/export/SqlServerExporter.js +0 -0
  11. package/lib/export/index.js +0 -0
  12. package/lib/export/utils.js +0 -0
  13. package/lib/import/index.js +0 -0
  14. package/lib/index.js +0 -0
  15. package/lib/model_structure/config.js +0 -0
  16. package/lib/model_structure/database.js +36 -7
  17. package/lib/model_structure/dbState.js +0 -0
  18. package/lib/model_structure/element.js +0 -0
  19. package/lib/model_structure/endpoint.js +0 -0
  20. package/lib/model_structure/enum.js +0 -0
  21. package/lib/model_structure/enumValue.js +0 -0
  22. package/lib/model_structure/field.js +4 -2
  23. package/lib/model_structure/indexColumn.js +0 -0
  24. package/lib/model_structure/indexes.js +4 -1
  25. package/lib/model_structure/ref.js +4 -1
  26. package/lib/model_structure/schema.js +0 -0
  27. package/lib/model_structure/stickyNote.js +0 -0
  28. package/lib/model_structure/table.js +113 -1
  29. package/lib/model_structure/tableGroup.js +0 -0
  30. package/lib/model_structure/tablePartial.js +162 -0
  31. package/lib/model_structure/utils.js +0 -0
  32. package/lib/parse/ANTLR/ASTGeneration/AST.js +0 -0
  33. package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +0 -0
  34. package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +0 -0
  35. package/lib/parse/ANTLR/ASTGeneration/constants.js +0 -0
  36. package/lib/parse/ANTLR/ASTGeneration/helpers.js +0 -0
  37. package/lib/parse/ANTLR/ASTGeneration/index.js +0 -0
  38. package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +0 -0
  39. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +0 -0
  40. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +0 -0
  41. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +0 -0
  42. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +0 -0
  43. package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +0 -0
  44. package/lib/parse/ANTLR/README.md +0 -0
  45. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.g4 +0 -0
  46. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.interp +0 -0
  47. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.js +0 -0
  48. package/lib/parse/ANTLR/parsers/mssql/TSqlLexer.tokens +0 -0
  49. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.g4 +0 -0
  50. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.interp +0 -0
  51. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.js +0 -0
  52. package/lib/parse/ANTLR/parsers/mssql/TSqlParser.tokens +0 -0
  53. package/lib/parse/ANTLR/parsers/mssql/TSqlParserVisitor.js +0 -0
  54. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +0 -0
  55. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +0 -0
  56. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +0 -0
  57. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +0 -0
  58. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +0 -0
  59. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +0 -0
  60. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +0 -0
  61. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +0 -0
  62. package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +0 -0
  63. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +0 -0
  64. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +0 -0
  65. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +0 -0
  66. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +0 -0
  67. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +0 -0
  68. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +0 -0
  69. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +0 -0
  70. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +0 -0
  71. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +0 -0
  72. package/lib/parse/ANTLR/parsers/postgresql/README.md +0 -0
  73. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.g4 +0 -0
  74. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.interp +0 -0
  75. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.js +0 -0
  76. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.tokens +0 -0
  77. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.g4 +0 -0
  78. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.interp +0 -0
  79. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.js +0 -0
  80. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.tokens +0 -0
  81. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParserVisitor.js +0 -0
  82. package/lib/parse/Parser.js +0 -0
  83. package/lib/parse/buildParser.js +0 -0
  84. package/lib/parse/databaseGenerator.js +0 -0
  85. package/lib/parse/dbml/parser.pegjs +0 -0
  86. package/lib/parse/dbmlParser.js +0 -0
  87. package/lib/parse/error.js +0 -0
  88. package/lib/parse/mssql/base_parsers.js +0 -0
  89. package/lib/parse/mssql/column_definition/actions.js +0 -0
  90. package/lib/parse/mssql/column_definition/index.js +0 -0
  91. package/lib/parse/mssql/constraint_definition/actions.js +0 -0
  92. package/lib/parse/mssql/constraint_definition/index.js +0 -0
  93. package/lib/parse/mssql/expression.js +0 -0
  94. package/lib/parse/mssql/fk_definition/actions.js +0 -0
  95. package/lib/parse/mssql/fk_definition/index.js +0 -0
  96. package/lib/parse/mssql/index.js +0 -0
  97. package/lib/parse/mssql/index_definition/actions.js +0 -0
  98. package/lib/parse/mssql/index_definition/index.js +0 -0
  99. package/lib/parse/mssql/keyword_parsers.js +0 -0
  100. package/lib/parse/mssql/keyword_utils.js +0 -0
  101. package/lib/parse/mssql/statements/actions.js +0 -0
  102. package/lib/parse/mssql/statements/index.js +0 -0
  103. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -0
  104. package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -0
  105. package/lib/parse/mssql/statements/statement_types/alter_table/add/index.js +0 -0
  106. package/lib/parse/mssql/statements/statement_types/alter_table/index.js +0 -0
  107. package/lib/parse/mssql/statements/statement_types/comments/actions.js +0 -0
  108. package/lib/parse/mssql/statements/statement_types/comments/index.js +0 -0
  109. package/lib/parse/mssql/statements/statement_types/create_index/actions.js +0 -0
  110. package/lib/parse/mssql/statements/statement_types/create_index/index.js +0 -0
  111. package/lib/parse/mssql/statements/statement_types/create_table/actions.js +0 -0
  112. package/lib/parse/mssql/statements/statement_types/create_table/index.js +0 -0
  113. package/lib/parse/mssql/statements/statement_types/index.js +0 -0
  114. package/lib/parse/mssql/utils.js +0 -0
  115. package/lib/parse/mssql/whitespaces.js +0 -0
  116. package/lib/parse/mssqlParser.js +0 -0
  117. package/lib/parse/mysql/parser.pegjs +0 -0
  118. package/lib/parse/mysqlParser.js +0 -0
  119. package/lib/parse/postgresParser.js +0 -0
  120. package/lib/parse/postgresql/Base_rules.pegjs +0 -0
  121. package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +0 -0
  122. package/lib/parse/postgresql/Commands/Commands.pegjs +0 -0
  123. package/lib/parse/postgresql/Commands/Comment.pegjs +0 -0
  124. package/lib/parse/postgresql/Commands/Create_index.pegjs +0 -0
  125. package/lib/parse/postgresql/Commands/Create_table/Create_table.pegjs +0 -0
  126. package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +0 -0
  127. package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +0 -0
  128. package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +0 -0
  129. package/lib/parse/postgresql/Commands/Create_type/Create_type.pegjs +0 -0
  130. package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +0 -0
  131. package/lib/parse/postgresql/Commands/Create_type/Create_type_range.pegjs +0 -0
  132. package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +0 -0
  133. package/lib/parse/postgresql/Expression.pegjs +0 -0
  134. package/lib/parse/postgresql/InitializerUtils.pegjs +0 -0
  135. package/lib/parse/postgresql/Keywords.pegjs +0 -0
  136. package/lib/parse/postgresql/get_parser.js +0 -0
  137. package/lib/parse/postgresql/parser.pegjs +0 -0
  138. package/lib/parse/schemarb/parser.pegjs +0 -0
  139. package/lib/parse/schemarbParser.js +0 -0
  140. package/lib/utils/version.js +0 -0
  141. package/package.json +3 -3
  142. package/types/export/ModelExporter.d.ts +0 -0
  143. package/types/export/index.d.ts +0 -0
  144. package/types/import/index.d.ts +0 -0
  145. package/types/index.d.ts +0 -0
  146. package/types/model_structure/database.d.ts +0 -0
  147. package/types/model_structure/dbState.d.ts +0 -0
  148. package/types/model_structure/element.d.ts +0 -0
  149. package/types/model_structure/endpoint.d.ts +0 -0
  150. package/types/model_structure/enum.d.ts +0 -0
  151. package/types/model_structure/enumValue.d.ts +0 -0
  152. package/types/model_structure/field.d.ts +0 -0
  153. package/types/model_structure/indexColumn.d.ts +0 -0
  154. package/types/model_structure/indexes.d.ts +0 -0
  155. package/types/model_structure/ref.d.ts +0 -0
  156. package/types/model_structure/schema.d.ts +0 -0
  157. package/types/model_structure/stickyNote.d.ts +0 -0
  158. package/types/model_structure/table.d.ts +0 -0
  159. package/types/model_structure/tableGroup.d.ts +0 -0
  160. package/types/parse/Parser.d.ts +0 -0
  161. package/types/parse/error.d.ts +0 -0
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/lib/index.js CHANGED
File without changes
File without changes
@@ -15,6 +15,7 @@ var _stickyNote = _interopRequireDefault(require("./stickyNote"));
15
15
  var _element = _interopRequireDefault(require("./element"));
16
16
  var _config = require("./config");
17
17
  var _dbState = _interopRequireDefault(require("./dbState"));
18
+ var _tablePartial = _interopRequireDefault(require("./tablePartial"));
18
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
21
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -55,7 +56,9 @@ var Database = /*#__PURE__*/function (_Element) {
55
56
  _ref$aliases = _ref.aliases,
56
57
  aliases = _ref$aliases === void 0 ? [] : _ref$aliases,
57
58
  _ref$records = _ref.records,
58
- records = _ref$records === void 0 ? [] : _ref$records;
59
+ records = _ref$records === void 0 ? [] : _ref$records,
60
+ _ref$tablePartials = _ref.tablePartials,
61
+ tablePartials = _ref$tablePartials === void 0 ? [] : _ref$tablePartials;
59
62
  _classCallCheck(this, Database);
60
63
  _this = _super.call(this);
61
64
  _this.dbState = new _dbState["default"]();
@@ -70,8 +73,11 @@ var Database = /*#__PURE__*/function (_Element) {
70
73
  _this.token = project.token;
71
74
  _this.aliases = aliases;
72
75
  _this.records = [];
76
+ _this.tablePartials = [];
77
+ _this.injectedRawRefs = [];
73
78
  _this.processNotes(notes);
74
79
  _this.processRecords(records);
80
+ _this.processTablePartials(tablePartials);
75
81
  // The process order is important. Do not change !
76
82
  _this.processSchemas(schemas);
77
83
  _this.processSchemaElements(enums, _config.ENUM);
@@ -79,6 +85,12 @@ var Database = /*#__PURE__*/function (_Element) {
79
85
  _this.processSchemaElements(notes, _config.NOTE);
80
86
  _this.processSchemaElements(refs, _config.REF);
81
87
  _this.processSchemaElements(tableGroups, _config.TABLE_GROUP);
88
+ _this.injectedRawRefs.forEach(function (ref) {
89
+ var schema = _this.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
90
+ schema.pushRef(new _ref3["default"](_objectSpread(_objectSpread({}, ref), {}, {
91
+ schema: schema
92
+ })));
93
+ });
82
94
  return _this;
83
95
  }
84
96
  _createClass(Database, [{
@@ -114,6 +126,16 @@ var Database = /*#__PURE__*/function (_Element) {
114
126
  });
115
127
  });
116
128
  }
129
+ }, {
130
+ key: "processTablePartials",
131
+ value: function processTablePartials(rawTablePartials) {
132
+ var _this4 = this;
133
+ rawTablePartials.forEach(function (rawTablePartial) {
134
+ _this4.tablePartials.push(new _tablePartial["default"](_objectSpread(_objectSpread({}, rawTablePartial), {}, {
135
+ dbState: _this4.dbState
136
+ })));
137
+ });
138
+ }
117
139
  }, {
118
140
  key: "pushNote",
119
141
  value: function pushNote(note) {
@@ -132,10 +154,10 @@ var Database = /*#__PURE__*/function (_Element) {
132
154
  }, {
133
155
  key: "processSchemas",
134
156
  value: function processSchemas(rawSchemas) {
135
- var _this4 = this;
157
+ var _this5 = this;
136
158
  rawSchemas.forEach(function (schema) {
137
- _this4.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, {
138
- database: _this4
159
+ _this5.pushSchema(new _schema["default"](_objectSpread(_objectSpread({}, schema), {}, {
160
+ database: _this5
139
161
  })));
140
162
  });
141
163
  }
@@ -157,16 +179,16 @@ var Database = /*#__PURE__*/function (_Element) {
157
179
  }, {
158
180
  key: "processSchemaElements",
159
181
  value: function processSchemaElements(elements, elementType) {
160
- var _this5 = this;
182
+ var _this6 = this;
161
183
  var schema;
162
184
  elements.forEach(function (element) {
163
185
  if (element.schemaName) {
164
- schema = _this5.findOrCreateSchema(element.schemaName);
186
+ schema = _this6.findOrCreateSchema(element.schemaName);
165
187
  if (element.schemaName === _config.DEFAULT_SCHEMA_NAME) {
166
188
  // this.hasDefaultSchema = true;
167
189
  }
168
190
  } else {
169
- schema = _this5.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
191
+ schema = _this6.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
170
192
  }
171
193
  switch (elementType) {
172
194
  case _config.TABLE:
@@ -257,6 +279,13 @@ var Database = /*#__PURE__*/function (_Element) {
257
279
  });
258
280
  return _enum;
259
281
  }
282
+ }, {
283
+ key: "findTablePartial",
284
+ value: function findTablePartial(name) {
285
+ return this.tablePartials.find(function (tp) {
286
+ return tp.name === name;
287
+ });
288
+ }
260
289
  }, {
261
290
  key: "export",
262
291
  value: function _export() {
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -42,7 +42,9 @@ var Field = /*#__PURE__*/function (_Element) {
42
42
  _ref$table = _ref.table,
43
43
  table = _ref$table === void 0 ? {} : _ref$table,
44
44
  _ref$noteToken = _ref.noteToken,
45
- noteToken = _ref$noteToken === void 0 ? null : _ref$noteToken;
45
+ noteToken = _ref$noteToken === void 0 ? null : _ref$noteToken,
46
+ _ref$injectedPartial = _ref.injectedPartial,
47
+ injectedPartial = _ref$injectedPartial === void 0 ? null : _ref$injectedPartial;
46
48
  _classCallCheck(this, Field);
47
49
  _this = _super.call(this, token);
48
50
  if (!name) {
@@ -63,7 +65,7 @@ var Field = /*#__PURE__*/function (_Element) {
63
65
  _this.increment = increment;
64
66
  _this.endpoints = [];
65
67
  _this.table = table;
66
- _this.dbState = _this.table.dbState;
68
+ _this.injectedPartial = injectedPartial, _this.dbState = _this.table.dbState;
67
69
  _this.generateId();
68
70
  _this.bindType();
69
71
  return _this;
File without changes
@@ -37,7 +37,9 @@ var Index = /*#__PURE__*/function (_Element) {
37
37
  name = _ref.name,
38
38
  note = _ref.note,
39
39
  _ref$table = _ref.table,
40
- table = _ref$table === void 0 ? {} : _ref$table;
40
+ table = _ref$table === void 0 ? {} : _ref$table,
41
+ _ref$injectedPartial = _ref.injectedPartial,
42
+ injectedPartial = _ref$injectedPartial === void 0 ? null : _ref$injectedPartial;
41
43
  _classCallCheck(this, Index);
42
44
  _this = _super.call(this, token);
43
45
  _this.name = name;
@@ -48,6 +50,7 @@ var Index = /*#__PURE__*/function (_Element) {
48
50
  _this.pk = pk;
49
51
  _this.columns = [];
50
52
  _this.table = table;
53
+ _this.injectedPartial = injectedPartial;
51
54
  _this.dbState = _this.table.dbState;
52
55
  _this.generateId();
53
56
  _this.processIndexColumns(columns);
@@ -46,7 +46,9 @@ var Ref = /*#__PURE__*/function (_Element) {
46
46
  onUpdate = _ref.onUpdate,
47
47
  token = _ref.token,
48
48
  _ref$schema = _ref.schema,
49
- schema = _ref$schema === void 0 ? {} : _ref$schema;
49
+ schema = _ref$schema === void 0 ? {} : _ref$schema,
50
+ _ref$injectedPartial = _ref.injectedPartial,
51
+ injectedPartial = _ref$injectedPartial === void 0 ? null : _ref$injectedPartial;
50
52
  _classCallCheck(this, Ref);
51
53
  _this = _super.call(this, token);
52
54
  _this.name = name;
@@ -55,6 +57,7 @@ var Ref = /*#__PURE__*/function (_Element) {
55
57
  _this.onUpdate = onUpdate;
56
58
  _this.endpoints = [];
57
59
  _this.schema = schema;
60
+ _this.injectedPartial = injectedPartial;
58
61
  _this.dbState = _this.schema.dbState;
59
62
  _this.generateId();
60
63
  _this.processEndpoints(endpoints);
File without changes
File without changes
@@ -12,6 +12,12 @@ var _indexes = _interopRequireDefault(require("./indexes"));
12
12
  var _config = require("./config");
13
13
  var _utils = require("./utils");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
16
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
21
  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; }
16
22
  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; }
17
23
  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; }
@@ -45,7 +51,9 @@ var Table = /*#__PURE__*/function (_Element) {
45
51
  token = _ref.token,
46
52
  headerColor = _ref.headerColor,
47
53
  _ref$noteToken = _ref.noteToken,
48
- noteToken = _ref$noteToken === void 0 ? null : _ref$noteToken;
54
+ noteToken = _ref$noteToken === void 0 ? null : _ref$noteToken,
55
+ _ref$partials = _ref.partials,
56
+ partials = _ref$partials === void 0 ? [] : _ref$partials;
49
57
  _classCallCheck(this, Table);
50
58
  _this = _super.call(this, token);
51
59
  _this.name = name;
@@ -56,10 +64,12 @@ var Table = /*#__PURE__*/function (_Element) {
56
64
  _this.fields = [];
57
65
  _this.indexes = [];
58
66
  _this.schema = schema;
67
+ _this.partials = partials;
59
68
  _this.dbState = _this.schema.dbState;
60
69
  _this.generateId();
61
70
  _this.processFields(fields);
62
71
  _this.processIndexes(indexes);
72
+ _this.processPartials();
63
73
  return _this;
64
74
  }
65
75
  _createClass(Table, [{
@@ -133,6 +143,108 @@ var Table = /*#__PURE__*/function (_Element) {
133
143
  value: function checkSameId(table) {
134
144
  return this.schema.checkSameId(table.schemaName || _config.DEFAULT_SCHEMA_NAME) && (this.name === table.name || this.alias === table.name || this.name === table.alias || this.alias && this.alias === table.alias);
135
145
  }
146
+ }, {
147
+ key: "processPartials",
148
+ value: function processPartials() {
149
+ var _this$partials,
150
+ _this5 = this;
151
+ if (!((_this$partials = this.partials) !== null && _this$partials !== void 0 && _this$partials.length)) return;
152
+
153
+ /**
154
+ * When encountering conflicting columns or settings with identical names, the following resolution order is applied:
155
+ * 1. Local Table Definition: If a definition exists within the local table, it takes precedence.
156
+ * 2. Last Partial Definition: If no local definition is found,
157
+ * the definition from the most recently processed partial containing the conflicting name is used.
158
+ *
159
+ * Indexes with identical column tuples and attributes will be merged into a single index.
160
+ */
161
+
162
+ var existingFieldNames = new Set(this.fields.map(function (f) {
163
+ return f.name;
164
+ }));
165
+ var existingSettingNames = new Set();
166
+ if (!(0, _lodash.isNil)(this.note)) existingSettingNames.add('note');
167
+ if (!(0, _lodash.isNil)(this.headerColor)) existingSettingNames.add('headerColor');
168
+
169
+ // descending order, we'll inserted the partial fields from tail to head
170
+ var sortedPartials = this.partials.sort(function (a, b) {
171
+ return b.order - a.order;
172
+ });
173
+
174
+ // insert placeholder into table.fields
175
+ sortedPartials.toReversed().forEach(function (partial) {
176
+ _this5.fields.splice(partial.order, 0, 'dummy');
177
+ });
178
+ sortedPartials.forEach(function (partial) {
179
+ var tablePartial = _this5.schema.database.findTablePartial(partial.name);
180
+ if (!tablePartial) _this5.error("Table partial ".concat(partial.name, " not found"), partial.token);
181
+ if (tablePartial.fields) {
182
+ var _this5$fields;
183
+ // ignore fields that already exist in the table, or have been added by a later partial
184
+ var rawFields = tablePartial.fields.filter(function (f) {
185
+ return !existingFieldNames.has(f.name);
186
+ });
187
+ var fields = rawFields.map(function (rawField) {
188
+ existingFieldNames.add(rawField.name);
189
+
190
+ // convert inline_refs from injected fields to refs
191
+ if (rawField.inline_refs) {
192
+ rawField.inline_refs.forEach(function (iref) {
193
+ var ref = {
194
+ endpoints: [{
195
+ tableName: _this5.name,
196
+ schemaName: _this5.schema.name,
197
+ fieldNames: [rawField.name],
198
+ relation: ['-', '<'].includes(iref.relation) ? '1' : '*'
199
+ }, {
200
+ tableName: iref.tableName,
201
+ schemaName: iref.schemaName,
202
+ fieldNames: iref.fieldNames,
203
+ relation: ['-', '>'].includes(iref.relation) ? '1' : '*'
204
+ }],
205
+ injectedPartial: tablePartial
206
+ };
207
+ _this5.schema.database.injectedRawRefs.push(ref);
208
+ });
209
+ }
210
+ return new _field["default"](_objectSpread(_objectSpread({}, rawField), {}, {
211
+ table: _this5,
212
+ injectedPartial: tablePartial
213
+ }));
214
+ });
215
+ (_this5$fields = _this5.fields).splice.apply(_this5$fields, [partial.order, 1].concat(_toConsumableArray(fields)));
216
+ } else {
217
+ _this5.fields.splice(partial.order, 1); // still need to remove the dummy element, even when there's no field in the partial
218
+ }
219
+
220
+ // merge settings
221
+ if (!existingSettingNames.has('note') && !(0, _lodash.isNil)(tablePartial.note)) {
222
+ _this5.noteToken = null;
223
+ _this5.note = tablePartial.note;
224
+ existingSettingNames.add('note');
225
+ }
226
+ if (!existingSettingNames.has('headerColor') && !(0, _lodash.isNil)(tablePartial.headerColor)) {
227
+ _this5.headerColor = tablePartial.headerColor;
228
+ existingSettingNames.add('headerColor');
229
+ }
230
+
231
+ // merge indexes
232
+ tablePartial.indexes.forEach(function (index) {
233
+ _this5.indexes.push(new _indexes["default"](_objectSpread(_objectSpread({}, index), {}, {
234
+ table: _this5,
235
+ injectedPartial: tablePartial
236
+ })));
237
+ });
238
+
239
+ // uniqWith(this.indexes, (a, b) => {
240
+ // return
241
+ // isEqual(a.columns, b.columns) &&
242
+ // a.unique === b.unique &&
243
+ // a.pk === b.pk &&
244
+ // a.type === b.type
245
+ // });
246
+ });
247
+ }
136
248
  }, {
137
249
  key: "export",
138
250
  value: function _export() {
File without changes
@@ -0,0 +1,162 @@
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 _lodash = require("lodash");
9
+ var _element = _interopRequireDefault(require("./element"));
10
+ var _field = _interopRequireDefault(require("./field"));
11
+ var _indexes = _interopRequireDefault(require("./indexes"));
12
+ var _config = require("./config");
13
+ var _utils = require("./utils");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+ 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; }
16
+ 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; }
17
+ 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; }
18
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ 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); } }
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
22
+ 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); }
23
+ 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); }
24
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
+ 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); }; }
26
+ 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); }
27
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
+ 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; } }
29
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
30
+ var TablePartial = /*#__PURE__*/function (_Element) {
31
+ _inherits(TablePartial, _Element);
32
+ var _super = _createSuper(TablePartial);
33
+ function TablePartial() {
34
+ var _this;
35
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
36
+ name = _ref.name,
37
+ note = _ref.note,
38
+ _ref$fields = _ref.fields,
39
+ fields = _ref$fields === void 0 ? [] : _ref$fields,
40
+ _ref$indexes = _ref.indexes,
41
+ indexes = _ref$indexes === void 0 ? [] : _ref$indexes,
42
+ token = _ref.token,
43
+ headerColor = _ref.headerColor,
44
+ _ref$noteToken = _ref.noteToken,
45
+ noteToken = _ref$noteToken === void 0 ? null : _ref$noteToken,
46
+ dbState = _ref.dbState;
47
+ _classCallCheck(this, TablePartial);
48
+ _this = _super.call(this, token);
49
+ _this.name = name;
50
+ _this.note = note ? (0, _lodash.get)(note, 'value', note) : null;
51
+ _this.noteToken = note ? (0, _lodash.get)(note, 'token', noteToken) : null;
52
+ _this.headerColor = headerColor;
53
+ _this.fields = fields;
54
+ _this.indexes = indexes;
55
+ _this.dbState = dbState;
56
+ _this.generateId();
57
+
58
+ // this.processFields(fields);
59
+ // this.processIndexes(indexes);
60
+ return _this;
61
+ }
62
+ _createClass(TablePartial, [{
63
+ key: "generateId",
64
+ value: function generateId() {
65
+ this.id = this.dbState.generateId('tablePartialId');
66
+ }
67
+
68
+ // processFields (rawFields) {
69
+ // rawFields.forEach((field) => {
70
+ // this.pushField(new Field({ ...field, table: this }));
71
+ // });
72
+ // }
73
+
74
+ // pushField (field) {
75
+ // this.checkField(field);
76
+ // this.fields.push(field);
77
+ // }
78
+
79
+ // checkField (field) {
80
+ // if (this.fields.some(f => f.name === field.name)) {
81
+ // field.error(`Field "${field.name}" existed in table partial "${this.name}"`);
82
+ // }
83
+ // }
84
+
85
+ // processIndexes (rawIndexes) {
86
+ // rawIndexes.forEach((index) => {
87
+ // this.pushIndex(new Index({ ...index, table: this }));
88
+ // });
89
+ // }
90
+
91
+ // pushIndex (index) {
92
+ // this.checkIndex(index);
93
+ // this.indexes.push(index);
94
+ // }
95
+
96
+ // checkIndex (index) {
97
+ // index.columns.forEach((column) => {
98
+ // if (column.type === 'column' && !(this.findField(column.value))) {
99
+ // index.error(`Column "${column.value}" do not exist in table partial "${this.name}"`);
100
+ // }
101
+ // });
102
+ // }
103
+
104
+ // findField (fieldName) {
105
+ // return this.fields.find(f => f.name === fieldName);
106
+ // }
107
+ }, {
108
+ key: "export",
109
+ value: function _export() {
110
+ return _objectSpread(_objectSpread({}, this.shallowExport()), this.exportChild());
111
+ }
112
+ }, {
113
+ key: "exportChild",
114
+ value: function exportChild() {
115
+ return {
116
+ fields: this.fields.map(function (f) {
117
+ return f["export"]();
118
+ }),
119
+ indexes: this.indexes.map(function (i) {
120
+ return i["export"]();
121
+ })
122
+ };
123
+ }
124
+ }, {
125
+ key: "exportChildIds",
126
+ value: function exportChildIds() {
127
+ return {
128
+ fieldIds: this.fields.map(function (f) {
129
+ return f.id;
130
+ }),
131
+ indexIds: this.indexes.map(function (i) {
132
+ return i.id;
133
+ })
134
+ };
135
+ }
136
+ }, {
137
+ key: "shallowExport",
138
+ value: function shallowExport() {
139
+ return {
140
+ name: this.name,
141
+ note: this.note,
142
+ headerColor: this.headerColor
143
+ };
144
+ }
145
+ }, {
146
+ key: "normalize",
147
+ value: function normalize(model) {
148
+ model.tables[this.id] = _objectSpread(_objectSpread({
149
+ id: this.id
150
+ }, this.shallowExport()), this.exportChildIds());
151
+ this.fields.forEach(function (field) {
152
+ return field.normalize(model);
153
+ });
154
+ this.indexes.forEach(function (index) {
155
+ return index.normalize(model);
156
+ });
157
+ }
158
+ }]);
159
+ return TablePartial;
160
+ }(_element["default"]);
161
+ var _default = TablePartial;
162
+ exports["default"] = _default;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/core",
3
- "version": "3.12.0",
3
+ "version": "3.13.0-alpha.1",
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.12.0",
35
+ "@dbml/parse": "^3.13.0-alpha.1",
36
36
  "antlr4": "^4.13.1",
37
37
  "lodash": "^4.17.15",
38
38
  "parsimmon": "^1.13.0",
@@ -59,7 +59,7 @@
59
59
  "\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
60
60
  }
61
61
  },
62
- "gitHead": "e14cab048ba2c38acb622e780bea160a115a03d5",
62
+ "gitHead": "f695a53584ead08c4349f5824744d868bd350313",
63
63
  "engines": {
64
64
  "node": ">=16"
65
65
  }
File without changes
File without changes
File without changes
package/types/index.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes