@dbml/core 3.13.0-alpha.1 → 3.13.0-alpha.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.
@@ -75,21 +75,26 @@ var Database = /*#__PURE__*/function (_Element) {
75
75
  _this.records = [];
76
76
  _this.tablePartials = [];
77
77
  _this.injectedRawRefs = [];
78
+
79
+ // The process order is important. Do not change !
78
80
  _this.processNotes(notes);
79
81
  _this.processRecords(records);
80
82
  _this.processTablePartials(tablePartials);
81
- // The process order is important. Do not change !
82
83
  _this.processSchemas(schemas);
83
84
  _this.processSchemaElements(enums, _config.ENUM);
84
85
  _this.processSchemaElements(tables, _config.TABLE);
85
86
  _this.processSchemaElements(notes, _config.NOTE);
86
87
  _this.processSchemaElements(refs, _config.REF);
87
88
  _this.processSchemaElements(tableGroups, _config.TABLE_GROUP);
88
- _this.injectedRawRefs.forEach(function (ref) {
89
+ _this.injectedRawRefs.forEach(function (rawRef) {
89
90
  var schema = _this.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
90
- schema.pushRef(new _ref3["default"](_objectSpread(_objectSpread({}, ref), {}, {
91
+ var ref = new _ref3["default"](_objectSpread(_objectSpread({}, rawRef), {}, {
91
92
  schema: schema
92
- })));
93
+ }));
94
+ if (schema.refs.some(function (r) {
95
+ return r.equals(ref);
96
+ })) return;
97
+ schema.pushRef(ref);
93
98
  });
94
99
  return _this;
95
100
  }
@@ -346,7 +351,8 @@ var Database = /*#__PURE__*/function (_Element) {
346
351
  indexes: {},
347
352
  indexColumns: {},
348
353
  fields: {},
349
- records: {}
354
+ records: {},
355
+ tablePartials: {}
350
356
  };
351
357
  this.schemas.forEach(function (schema) {
352
358
  return schema.normalize(normalizedModel);
@@ -355,7 +361,10 @@ var Database = /*#__PURE__*/function (_Element) {
355
361
  return note.normalize(normalizedModel);
356
362
  });
357
363
  this.records.forEach(function (record) {
358
- return normalizedModel.records[record.id] = _objectSpread({}, record);
364
+ normalizedModel.records[record.id] = _objectSpread({}, record);
365
+ });
366
+ this.tablePartials.forEach(function (tablePartial) {
367
+ return tablePartial.normalize(normalizedModel);
359
368
  });
360
369
  return normalizedModel;
361
370
  }
@@ -26,6 +26,7 @@ var DbState = /*#__PURE__*/function () {
26
26
  this.fieldId = 1;
27
27
  this.indexColumnId = 1;
28
28
  this.recordId = 1;
29
+ this.tablePartialId = 1;
29
30
  }
30
31
  _createClass(DbState, [{
31
32
  key: "generateId",
@@ -104,11 +104,13 @@ var Endpoint = /*#__PURE__*/function (_Element) {
104
104
  }, {
105
105
  key: "shallowExport",
106
106
  value: function shallowExport() {
107
+ var _this$injectedPartial;
107
108
  return {
108
109
  schemaName: this.schemaName,
109
110
  tableName: this.tableName,
110
111
  fieldNames: this.fieldNames,
111
- relation: this.relation
112
+ relation: this.relation,
113
+ injectedPartialId: (_this$injectedPartial = this.injectedPartial) === null || _this$injectedPartial === void 0 ? void 0 : _this$injectedPartial.id
112
114
  };
113
115
  }
114
116
  }, {
@@ -44,7 +44,9 @@ var Field = /*#__PURE__*/function (_Element) {
44
44
  _ref$noteToken = _ref.noteToken,
45
45
  noteToken = _ref$noteToken === void 0 ? null : _ref$noteToken,
46
46
  _ref$injectedPartial = _ref.injectedPartial,
47
- injectedPartial = _ref$injectedPartial === void 0 ? null : _ref$injectedPartial;
47
+ injectedPartial = _ref$injectedPartial === void 0 ? null : _ref$injectedPartial,
48
+ _ref$injectedToken = _ref.injectedToken,
49
+ injectedToken = _ref$injectedToken === void 0 ? null : _ref$injectedToken;
48
50
  _classCallCheck(this, Field);
49
51
  _this = _super.call(this, token);
50
52
  if (!name) {
@@ -65,7 +67,9 @@ var Field = /*#__PURE__*/function (_Element) {
65
67
  _this.increment = increment;
66
68
  _this.endpoints = [];
67
69
  _this.table = table;
68
- _this.injectedPartial = injectedPartial, _this.dbState = _this.table.dbState;
70
+ _this.injectedPartial = injectedPartial;
71
+ _this.injectedToken = injectedToken;
72
+ _this.dbState = _this.table.dbState;
69
73
  _this.generateId();
70
74
  _this.bindType();
71
75
  return _this;
@@ -127,6 +131,7 @@ var Field = /*#__PURE__*/function (_Element) {
127
131
  }, {
128
132
  key: "shallowExport",
129
133
  value: function shallowExport() {
134
+ var _this$injectedPartial;
130
135
  return {
131
136
  name: this.name,
132
137
  type: this.type,
@@ -135,7 +140,8 @@ var Field = /*#__PURE__*/function (_Element) {
135
140
  not_null: this.not_null,
136
141
  note: this.note,
137
142
  dbdefault: this.dbdefault,
138
- increment: this.increment
143
+ increment: this.increment,
144
+ injectedPartialId: (_this$injectedPartial = this.injectedPartial) === null || _this$injectedPartial === void 0 ? void 0 : _this$injectedPartial.id
139
145
  };
140
146
  }
141
147
  }, {
@@ -101,11 +101,13 @@ var Ref = /*#__PURE__*/function (_Element) {
101
101
  }, {
102
102
  key: "shallowExport",
103
103
  value: function shallowExport() {
104
+ var _this$injectedPartial;
104
105
  return {
105
106
  name: this.name,
106
107
  color: this.color,
107
108
  onDelete: this.onDelete,
108
- onUpdate: this.onUpdate
109
+ onUpdate: this.onUpdate,
110
+ injectedPartialId: (_this$injectedPartial = this.injectedPartial) === null || _this$injectedPartial === void 0 ? void 0 : _this$injectedPartial.id
109
111
  };
110
112
  }
111
113
  }, {
@@ -68,8 +68,10 @@ var Table = /*#__PURE__*/function (_Element) {
68
68
  _this.dbState = _this.schema.dbState;
69
69
  _this.generateId();
70
70
  _this.processFields(fields);
71
- _this.processIndexes(indexes);
71
+ // Process partials after fields to get injected fields' orders
72
+ // Process partials before indexes for indexes to properly check all owned and injected columns
72
73
  _this.processPartials();
74
+ _this.processIndexes(indexes);
73
75
  return _this;
74
76
  }
75
77
  _createClass(Table, [{
@@ -149,16 +151,19 @@ var Table = /*#__PURE__*/function (_Element) {
149
151
  var _this$partials,
150
152
  _this5 = this;
151
153
  if (!((_this$partials = this.partials) !== null && _this$partials !== void 0 && _this$partials.length)) return;
152
-
153
154
  /**
154
155
  * When encountering conflicting columns or settings with identical names, the following resolution order is applied:
155
156
  * 1. Local Table Definition: If a definition exists within the local table, it takes precedence.
156
157
  * 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
+ * the definition from the last partial (in dbml source) containing the conflicting name is used.
158
159
  *
159
- * Indexes with identical column tuples and attributes will be merged into a single index.
160
+ * each partial has the following structure:
161
+ * {
162
+ * name: string,
163
+ * order: number, // determine where the partials fields will be injected in comparison with the table fields and other partials
164
+ * token, // token of the partial definition
165
+ * }
160
166
  */
161
-
162
167
  var existingFieldNames = new Set(this.fields.map(function (f) {
163
168
  return f.name;
164
169
  }));
@@ -178,6 +183,7 @@ var Table = /*#__PURE__*/function (_Element) {
178
183
  sortedPartials.forEach(function (partial) {
179
184
  var tablePartial = _this5.schema.database.findTablePartial(partial.name);
180
185
  if (!tablePartial) _this5.error("Table partial ".concat(partial.name, " not found"), partial.token);
186
+ partial.id = tablePartial.id;
181
187
  if (tablePartial.fields) {
182
188
  var _this5$fields;
183
189
  // ignore fields that already exist in the table, or have been added by a later partial
@@ -190,17 +196,21 @@ var Table = /*#__PURE__*/function (_Element) {
190
196
  // convert inline_refs from injected fields to refs
191
197
  if (rawField.inline_refs) {
192
198
  rawField.inline_refs.forEach(function (iref) {
199
+ var _this5$schema;
193
200
  var ref = {
201
+ token: rawField.token,
194
202
  endpoints: [{
195
203
  tableName: _this5.name,
196
- schemaName: _this5.schema.name,
204
+ schemaName: (_this5$schema = _this5.schema) === null || _this5$schema === void 0 ? void 0 : _this5$schema.name,
197
205
  fieldNames: [rawField.name],
198
- relation: ['-', '<'].includes(iref.relation) ? '1' : '*'
206
+ relation: ['-', '<'].includes(iref.relation) ? '1' : '*',
207
+ token: rawField.token
199
208
  }, {
200
209
  tableName: iref.tableName,
201
210
  schemaName: iref.schemaName,
202
211
  fieldNames: iref.fieldNames,
203
- relation: ['-', '>'].includes(iref.relation) ? '1' : '*'
212
+ relation: ['-', '>'].includes(iref.relation) ? '1' : '*',
213
+ token: iref.token
204
214
  }],
205
215
  injectedPartial: tablePartial
206
216
  };
@@ -208,8 +218,10 @@ var Table = /*#__PURE__*/function (_Element) {
208
218
  });
209
219
  }
210
220
  return new _field["default"](_objectSpread(_objectSpread({}, rawField), {}, {
221
+ noteToken: null,
211
222
  table: _this5,
212
- injectedPartial: tablePartial
223
+ injectedPartial: tablePartial,
224
+ injectedToken: partial.token
213
225
  }));
214
226
  });
215
227
  (_this5$fields = _this5.fields).splice.apply(_this5$fields, [partial.order, 1].concat(_toConsumableArray(fields)));
@@ -235,14 +247,6 @@ var Table = /*#__PURE__*/function (_Element) {
235
247
  injectedPartial: tablePartial
236
248
  })));
237
249
  });
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
250
  });
247
251
  }
248
252
  }, {
@@ -289,7 +293,8 @@ var Table = /*#__PURE__*/function (_Element) {
289
293
  name: this.name,
290
294
  alias: this.alias,
291
295
  note: this.note,
292
- headerColor: this.headerColor
296
+ headerColor: this.headerColor,
297
+ partials: this.partials
293
298
  };
294
299
  }
295
300
  }, {
@@ -7,10 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _lodash = require("lodash");
9
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
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
11
  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
12
  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; }
@@ -54,9 +50,6 @@ var TablePartial = /*#__PURE__*/function (_Element) {
54
50
  _this.indexes = indexes;
55
51
  _this.dbState = dbState;
56
52
  _this.generateId();
57
-
58
- // this.processFields(fields);
59
- // this.processIndexes(indexes);
60
53
  return _this;
61
54
  }
62
55
  _createClass(TablePartial, [{
@@ -64,74 +57,10 @@ var TablePartial = /*#__PURE__*/function (_Element) {
64
57
  value: function generateId() {
65
58
  this.id = this.dbState.generateId('tablePartialId');
66
59
  }
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
60
  }, {
108
61
  key: "export",
109
62
  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
- };
63
+ return _objectSpread({}, this.shallowExport());
135
64
  }
136
65
  }, {
137
66
  key: "shallowExport",
@@ -139,21 +68,17 @@ var TablePartial = /*#__PURE__*/function (_Element) {
139
68
  return {
140
69
  name: this.name,
141
70
  note: this.note,
142
- headerColor: this.headerColor
71
+ headerColor: this.headerColor,
72
+ fields: this.fields,
73
+ indexes: this.indexes
143
74
  };
144
75
  }
145
76
  }, {
146
77
  key: "normalize",
147
78
  value: function normalize(model) {
148
- model.tables[this.id] = _objectSpread(_objectSpread({
79
+ model.tablePartials[this.id] = _objectSpread({
149
80
  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
- });
81
+ }, this.shallowExport());
157
82
  }
158
83
  }]);
159
84
  return TablePartial;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/core",
3
- "version": "3.13.0-alpha.1",
3
+ "version": "3.13.0-alpha.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.13.0-alpha.1",
35
+ "@dbml/parse": "^3.13.0-alpha.3",
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": "f695a53584ead08c4349f5824744d868bd350313",
62
+ "gitHead": "65d1cf56fcad06c42f625c9214c17c1b4c54b249",
63
63
  "engines": {
64
64
  "node": ">=16"
65
65
  }
@@ -11,6 +11,7 @@ import { NormalizedEnumValue } from './enumValue';
11
11
  import { NormalizedField } from './field';
12
12
  import { NormalizedIndexColumn } from './indexColumn';
13
13
  import { NormalizedIndex } from './indexes';
14
+ import TablePartial, { NormalizedTablePartial } from './tablePartial';
14
15
  export interface Project {
15
16
  note: RawNote;
16
17
  database_type: string;
@@ -44,6 +45,7 @@ export interface RawDatabase {
44
45
  tableGroups: TableGroup[];
45
46
  project: Project;
46
47
  records: RawTableRecord[];
48
+ tablePartials: TablePartial[];
47
49
  }
48
50
  declare class Database extends Element {
49
51
  dbState: DbState;
@@ -65,6 +67,8 @@ declare class Database extends Element {
65
67
  processSchemaElements(elements: Schema[] | Table[] | Enum[] | TableGroup[] | Ref[], elementType: any): void;
66
68
  findOrCreateSchema(schemaName: string): Schema;
67
69
  findTable(rawTable: any): Table;
70
+ processTablePartials(rawTablePartials: any[]): TablePartial[];
71
+ findTablePartial(partialName: string): TablePartial;
68
72
  export(): {
69
73
  schemas: {
70
74
  tables: {
@@ -140,6 +144,33 @@ declare class Database extends Element {
140
144
  type: string;
141
145
  }[][];
142
146
  }[];
147
+ tablePartials: {
148
+ name: string;
149
+ note: string;
150
+ headerColor: string;
151
+ fields: {
152
+ name: string;
153
+ type: any;
154
+ unique: boolean;
155
+ pk: boolean;
156
+ not_null: boolean;
157
+ note: string;
158
+ dbdefault: any;
159
+ increment: boolean;
160
+ injectedPartialId: number | undefined,
161
+ }[];
162
+ indexes: {
163
+ columns: {
164
+ type: any;
165
+ value: any;
166
+ }[];
167
+ name: string;
168
+ type: any;
169
+ unique: boolean;
170
+ pk: string;
171
+ note: string;
172
+ }[];
173
+ }[];
143
174
  };
144
175
  shallowExport(): {
145
176
  hasDefaultSchema: boolean;
@@ -212,6 +243,33 @@ declare class Database extends Element {
212
243
  content: string;
213
244
  headerColor: string;
214
245
  }[];
246
+ tablePartials: {
247
+ name: string;
248
+ note: string;
249
+ headerColor: string;
250
+ fields: {
251
+ name: string;
252
+ type: any;
253
+ unique: boolean;
254
+ pk: boolean;
255
+ not_null: boolean;
256
+ note: string;
257
+ dbdefault: any;
258
+ increment: boolean;
259
+ injectedPartialId: number | undefined,
260
+ }[];
261
+ indexes: {
262
+ columns: {
263
+ type: any;
264
+ value: any;
265
+ }[];
266
+ name: string;
267
+ type: any;
268
+ unique: boolean;
269
+ pk: string;
270
+ note: string;
271
+ }[];
272
+ }[];
215
273
  };
216
274
  exportChildIds(): {
217
275
  schemaIds: number[];
@@ -243,5 +301,6 @@ export interface NormalizedDatabase {
243
301
  indexColumns: NormalizedIndexColumn;
244
302
  fields: NormalizedField;
245
303
  records: NormalizedRecords;
304
+ tablePartials: NormalizedTablePartial;
246
305
  }
247
306
  export default Database;
@@ -11,5 +11,6 @@ export default class DbState {
11
11
  indexId: number;
12
12
  fieldId: number;
13
13
  indexColumnId: number;
14
+ tablePartialId: number;
14
15
  generateId(el: string): any;
15
16
  }
@@ -4,6 +4,7 @@ import Element, { Token, RawNote } from './element';
4
4
  import Endpoint from './endpoint';
5
5
  import Enum from './enum';
6
6
  import Table from './table';
7
+ import TablePartial from './tablePartial';
7
8
  interface RawField {
8
9
  name: string;
9
10
  type: any;
@@ -30,6 +31,8 @@ declare class Field extends Element {
30
31
  table: Table;
31
32
  endpoints: Endpoint[];
32
33
  _enum: Enum;
34
+ injectedPartial?: TablePartial;
35
+ injectedToken: Token;
33
36
  constructor({ name, type, unique, pk, token, not_null, note, dbdefault, increment, table }: RawField);
34
37
  generateId(): void;
35
38
  pushEndpoint(endpoint: any): void;
@@ -42,6 +45,7 @@ declare class Field extends Element {
42
45
  note: string;
43
46
  dbdefault: any;
44
47
  increment: boolean;
48
+ injectedPartialId?: number;
45
49
  };
46
50
  exportParentIds(): {
47
51
  tableId: number;
@@ -59,6 +63,7 @@ declare class Field extends Element {
59
63
  note: string;
60
64
  dbdefault: any;
61
65
  increment: boolean;
66
+ injectedPartialId?: number;
62
67
  };
63
68
  normalize(model: NormalizedDatabase): void;
64
69
  }
@@ -76,6 +81,7 @@ export interface NormalizedField {
76
81
  tableId: number;
77
82
  endpointIds: number[];
78
83
  enumId: number;
84
+ injectedPartialId?: number;
79
85
  };
80
86
  }
81
87
  export default Field;
@@ -3,6 +3,7 @@ import Endpoint from './endpoint';
3
3
  import Schema from './schema';
4
4
  import DbState from './dbState';
5
5
  import Database, { NormalizedDatabase } from './database';
6
+ import TablePartial from './tablePartial';
6
7
  interface RawRef {
7
8
  name: string;
8
9
  color?: string;
@@ -22,6 +23,7 @@ declare class Ref extends Element {
22
23
  dbState: DbState;
23
24
  id: number;
24
25
  database: Database;
26
+ injectedPartial?: TablePartial;
25
27
  constructor({ name, endpoints, onDelete, onUpdate, token, schema }: RawRef);
26
28
  generateId(): void;
27
29
  processEndpoints(rawEndpoints: any): void;
@@ -36,11 +38,13 @@ declare class Ref extends Element {
36
38
  name: string;
37
39
  onDelete: any;
38
40
  onUpdate: any;
41
+ injectedPartialId?: number;
39
42
  };
40
43
  shallowExport(): {
41
44
  name: string;
42
45
  onDelete: any;
43
46
  onUpdate: any;
47
+ injectedPartialId?: number;
44
48
  };
45
49
  exportChild(): {
46
50
  endpoints: {
@@ -67,6 +71,7 @@ export interface NormalizedRef {
67
71
  onDelete?: string;
68
72
  endpointIds: number[];
69
73
  schemaId: number;
74
+ injectedPartialId?: number;
70
75
  };
71
76
  }
72
77
  export default Ref;
@@ -4,7 +4,9 @@ import Index from './indexes';
4
4
  import Schema from './schema';
5
5
  import DbState from './dbState';
6
6
  import TableGroup from './tableGroup';
7
+ import TablePartial from './tablePartial';
7
8
  import { NormalizedDatabase } from './database';
9
+
8
10
  interface RawTable {
9
11
  name: string;
10
12
  alias: string;
@@ -14,7 +16,9 @@ interface RawTable {
14
16
  schema: Schema;
15
17
  token: Token;
16
18
  headerColor: string;
19
+ partials: TablePartial[];
17
20
  }
21
+
18
22
  declare class Table extends Element {
19
23
  name: string;
20
24
  alias: string;
@@ -27,6 +31,8 @@ declare class Table extends Element {
27
31
  dbState: DbState;
28
32
  id: number;
29
33
  group: TableGroup;
34
+ partials: TablePartial[];
35
+
30
36
  constructor({ name, alias, note, fields, indexes, schema, token, headerColor }: RawTable);
31
37
  generateId(): void;
32
38
  processFields(rawFields: any): void;
@@ -37,6 +43,7 @@ declare class Table extends Element {
37
43
  checkIndex(index: any): void;
38
44
  findField(fieldName: any): Field;
39
45
  checkSameId(table: any): boolean;
46
+ processPartials(): void;
40
47
  export(): {
41
48
  fields: {
42
49
  name: string;
@@ -63,6 +70,7 @@ declare class Table extends Element {
63
70
  alias: string;
64
71
  note: string;
65
72
  headerColor: string;
73
+ partials: TablePartial[];
66
74
  };
67
75
  exportChild(): {
68
76
  fields: {
@@ -100,9 +108,11 @@ declare class Table extends Element {
100
108
  alias: string;
101
109
  note: string;
102
110
  headerColor: string;
111
+ partials: TablePartial[];
103
112
  };
104
113
  normalize(model: NormalizedDatabase): void;
105
114
  }
115
+
106
116
  export interface NormalizedTable {
107
117
  [id: number]: {
108
118
  id: number;
@@ -114,6 +124,8 @@ export interface NormalizedTable {
114
124
  indexIds: number[];
115
125
  schemaId: number;
116
126
  groupId: number;
127
+ partials: TablePartial[];
117
128
  };
118
129
  }
130
+
119
131
  export default Table;
@@ -0,0 +1,97 @@
1
+ import Element, { RawNote, Token } from './element';
2
+ import Field from './field';
3
+ import Index from './indexes';
4
+ import DbState from './dbState';
5
+ import { NormalizedDatabase } from './database';
6
+
7
+ interface RawTablePartial {
8
+ name: string;
9
+ note: RawNote;
10
+ fields: Field[];
11
+ indexes: Index[];
12
+ token: Token;
13
+ headerColor: string;
14
+ dbState: DbState;
15
+ }
16
+
17
+ declare class TablePartial extends Element {
18
+ name: string;
19
+ note: string;
20
+ noteToken: Token;
21
+ fields: Field[];
22
+ indexes: Index[];
23
+ headerColor: string;
24
+ dbState: DbState;
25
+ id: number;
26
+
27
+ constructor({ name, note, fields, indexes, token, headerColor, dbState }: RawTablePartial);
28
+ generateId(): void;
29
+ export(): {
30
+ name: string;
31
+ note: string;
32
+ headerColor: string;
33
+ fields: {
34
+ name: string;
35
+ type: any;
36
+ unique: boolean;
37
+ pk: boolean;
38
+ not_null: boolean;
39
+ note: string;
40
+ dbdefault: any;
41
+ increment: boolean;
42
+ injectedPartialId: number | undefined,
43
+ }[];
44
+ indexes: {
45
+ columns: {
46
+ type: any;
47
+ value: any;
48
+ }[];
49
+ name: string;
50
+ type: any;
51
+ unique: boolean;
52
+ pk: string;
53
+ note: string;
54
+ }[];
55
+ };
56
+ shallowExport(): {
57
+ name: string;
58
+ note: string;
59
+ headerColor: string;
60
+ fields: {
61
+ name: string;
62
+ type: any;
63
+ unique: boolean;
64
+ pk: boolean;
65
+ not_null: boolean;
66
+ note: string;
67
+ dbdefault: any;
68
+ increment: boolean;
69
+ injectedPartialId: number | undefined,
70
+ }[];
71
+ indexes: {
72
+ columns: {
73
+ type: any;
74
+ value: any;
75
+ }[];
76
+ name: string;
77
+ type: any;
78
+ unique: boolean;
79
+ pk: string;
80
+ note: string;
81
+ }[];
82
+ };
83
+ normalize(model: NormalizedDatabase): void;
84
+ }
85
+
86
+ export interface NormalizedTablePartial {
87
+ [id: number]: {
88
+ id: number;
89
+ name: string;
90
+ note: string;
91
+ headerColor: string;
92
+ fieldIds: number[];
93
+ indexIds: number[];
94
+ };
95
+ }
96
+
97
+ export default TablePartial;
@@ -0,0 +1,38 @@
1
+ export default TablePartial;
2
+ declare class TablePartial extends Element {
3
+ constructor({ name, note, fields, indexes, token, headerColor, noteToken, dbState, }?: {
4
+ name: any;
5
+ note: any;
6
+ fields?: any[];
7
+ indexes?: any[];
8
+ token: any;
9
+ headerColor: any;
10
+ noteToken?: any;
11
+ dbState: any;
12
+ });
13
+ name: any;
14
+ note: any;
15
+ noteToken: any;
16
+ headerColor: any;
17
+ fields: any[];
18
+ indexes: any[];
19
+ dbState: any;
20
+ generateId(): void;
21
+ id: any;
22
+ export(): {
23
+ name: any;
24
+ note: any;
25
+ headerColor: any;
26
+ fields: any[];
27
+ indexes: any[];
28
+ };
29
+ shallowExport(): {
30
+ name: any;
31
+ note: any;
32
+ headerColor: any;
33
+ fields: any[];
34
+ indexes: any[];
35
+ };
36
+ normalize(model: any): void;
37
+ }
38
+ import Element from './element';