@dbml/core 3.13.0-alpha.1 → 3.13.0-alpha.2
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.
- package/lib/model_structure/database.js +15 -6
- package/lib/model_structure/dbState.js +1 -0
- package/lib/model_structure/endpoint.js +3 -1
- package/lib/model_structure/field.js +9 -3
- package/lib/model_structure/ref.js +3 -1
- package/lib/model_structure/table.js +23 -18
- package/lib/model_structure/tablePartial.js +6 -81
- package/package.json +3 -3
|
@@ -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 (
|
|
89
|
+
_this.injectedRawRefs.forEach(function (rawRef) {
|
|
89
90
|
var schema = _this.findOrCreateSchema(_config.DEFAULT_SCHEMA_NAME);
|
|
90
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
158
|
+
* the definition from the last partial (in dbml source) containing the conflicting name is used.
|
|
158
159
|
*
|
|
159
|
-
*
|
|
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(
|
|
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.
|
|
79
|
+
model.tablePartials[this.id] = _objectSpread({
|
|
149
80
|
id: this.id
|
|
150
|
-
}, this.shallowExport())
|
|
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.
|
|
3
|
+
"version": "3.13.0-alpha.2",
|
|
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.
|
|
35
|
+
"@dbml/parse": "^3.13.0-alpha.2",
|
|
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": "
|
|
62
|
+
"gitHead": "2a00c9bde5b128f5463344b6567248c3a1d7f7a1",
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=16"
|
|
65
65
|
}
|