@dbml/core 3.7.0 → 3.7.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.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.7.
|
|
35
|
+
"@dbml/parse": "^3.7.1",
|
|
36
36
|
"@tediousjs/connection-string": "^0.5.0",
|
|
37
37
|
"antlr4": "^4.13.1",
|
|
38
38
|
"lodash": "^4.17.15",
|
|
@@ -63,5 +63,8 @@
|
|
|
63
63
|
"\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "71d7e2cd00ba5d60d2e36c465d43ce1d91189274",
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=18"
|
|
69
|
+
}
|
|
67
70
|
}
|
package/lib/connectors/ utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseConnStr = void 0;
|
|
7
|
-
var _connectionString = require("@tediousjs/connection-string");
|
|
8
|
-
var parseConnStr = function parseConnStr(connectionString) {
|
|
9
|
-
return (0, _connectionString.parseSqlConnectionString)(connectionString, true);
|
|
10
|
-
};
|
|
11
|
-
exports.parseConnStr = parseConnStr;
|
package/lib/connectors/dbml.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createEnums = createEnums;
|
|
7
|
-
exports.createRefs = createRefs;
|
|
8
|
-
exports.createTables = createTables;
|
|
9
|
-
var _AST = require("../../../ANTLR/ASTGeneration/AST");
|
|
10
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
-
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."); }
|
|
12
|
-
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); }
|
|
13
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
14
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
-
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; } /* eslint-disable no-use-before-define */
|
|
16
|
-
function createEnums(enumList) {
|
|
17
|
-
return enumList.map(function (item) {
|
|
18
|
-
var name = item.name,
|
|
19
|
-
values = item.values;
|
|
20
|
-
return new _AST.Enum({
|
|
21
|
-
name: name,
|
|
22
|
-
values: values
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
function createRefs(tableForeignKeyMap) {
|
|
27
|
-
var result = [];
|
|
28
|
-
Object.values(tableForeignKeyMap).forEach(function (tableForeignKey) {
|
|
29
|
-
var refList = Object.values(tableForeignKey).map(function (key) {
|
|
30
|
-
var onDelete = key.onDelete,
|
|
31
|
-
onUpdate = key.onUpdate,
|
|
32
|
-
foreignColumns = key.foreignColumns,
|
|
33
|
-
foreignTableName = key.foreignTableName,
|
|
34
|
-
refTableName = key.refTableName,
|
|
35
|
-
refColumns = key.refColumns,
|
|
36
|
-
name = key.name;
|
|
37
|
-
var endpoint1 = new _AST.Endpoint({
|
|
38
|
-
tableName: refTableName,
|
|
39
|
-
fieldNames: refColumns,
|
|
40
|
-
relation: '1'
|
|
41
|
-
});
|
|
42
|
-
var endpoint2 = new _AST.Endpoint({
|
|
43
|
-
tableName: foreignTableName,
|
|
44
|
-
fieldNames: foreignColumns,
|
|
45
|
-
relation: '*'
|
|
46
|
-
});
|
|
47
|
-
var ref = new _AST.Ref({
|
|
48
|
-
name: name,
|
|
49
|
-
endpoints: [endpoint1, endpoint2]
|
|
50
|
-
});
|
|
51
|
-
if (onDelete !== 'NO ACTION') {
|
|
52
|
-
ref.onDelete = onDelete;
|
|
53
|
-
}
|
|
54
|
-
if (onUpdate !== 'NO ACTION') {
|
|
55
|
-
ref.onUpdate = onUpdate;
|
|
56
|
-
}
|
|
57
|
-
return ref;
|
|
58
|
-
});
|
|
59
|
-
result.push.apply(result, _toConsumableArray(refList));
|
|
60
|
-
});
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
function createTables(tableList, fieldMap, primaryKeyMap, uniqueConstraintMap, indexMap) {
|
|
64
|
-
return tableList.map(function (table) {
|
|
65
|
-
var name = table.name,
|
|
66
|
-
schemaName = table.schemaName,
|
|
67
|
-
note = table.note;
|
|
68
|
-
var fieldList = fieldMap[name] || [];
|
|
69
|
-
var indexList = indexMap[name] || [];
|
|
70
|
-
var tablePrimayKey = primaryKeyMap[name] || {};
|
|
71
|
-
var tableUniqueConstraintList = uniqueConstraintMap[name] || {};
|
|
72
|
-
var inlineUniqueConstraintList = getInlineUniqueConstraints(tableUniqueConstraintList);
|
|
73
|
-
var fieldEntityList = createFields(fieldList, tablePrimayKey, inlineUniqueConstraintList);
|
|
74
|
-
var compositeUniqueConstraintList = getCompositeUniqueConstraints(tableUniqueConstraintList);
|
|
75
|
-
var indexEntityList = createIndexes(Object.values(indexList), tablePrimayKey, compositeUniqueConstraintList);
|
|
76
|
-
return new _AST.Table({
|
|
77
|
-
name: name,
|
|
78
|
-
schemaName: schemaName,
|
|
79
|
-
note: note,
|
|
80
|
-
fields: fieldEntityList,
|
|
81
|
-
indexes: indexEntityList
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// TODO: check unique
|
|
87
|
-
function createFields(fieldList, primaryKey, inlineUniqueConstraintList) {
|
|
88
|
-
return fieldList.map(function (field) {
|
|
89
|
-
var name = field.name,
|
|
90
|
-
type = field.type,
|
|
91
|
-
notNull = field.notNull,
|
|
92
|
-
increment = field.increment,
|
|
93
|
-
note = field.note,
|
|
94
|
-
dbdefault = field.dbdefault;
|
|
95
|
-
var fieldEntity = new _AST.Field({
|
|
96
|
-
name: name,
|
|
97
|
-
type: type,
|
|
98
|
-
not_null: notNull,
|
|
99
|
-
increment: increment,
|
|
100
|
-
dbdefault: dbdefault,
|
|
101
|
-
note: note,
|
|
102
|
-
pk: false,
|
|
103
|
-
unique: false
|
|
104
|
-
});
|
|
105
|
-
if (Array.isArray(primaryKey.columns) && primaryKey.columns.length === 1 && primaryKey.columns[0] === name) {
|
|
106
|
-
fieldEntity.pk = true;
|
|
107
|
-
}
|
|
108
|
-
var uniqueConstraint = inlineUniqueConstraintList.find(function (constraint) {
|
|
109
|
-
return constraint.columns[0] === name;
|
|
110
|
-
});
|
|
111
|
-
if (uniqueConstraint) {
|
|
112
|
-
fieldEntity.unique = true;
|
|
113
|
-
}
|
|
114
|
-
return fieldEntity;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function createIndexes(indexList, primaryKey, compositeUniqueConstraintList) {
|
|
118
|
-
var indexEntityList = [];
|
|
119
|
-
indexList.forEach(function (index) {
|
|
120
|
-
var indexEntity = new _AST.Index({
|
|
121
|
-
name: index.name,
|
|
122
|
-
unique: index.unique,
|
|
123
|
-
type: index.type,
|
|
124
|
-
columns: index.columns,
|
|
125
|
-
pk: false
|
|
126
|
-
});
|
|
127
|
-
indexEntityList.push(indexEntity);
|
|
128
|
-
});
|
|
129
|
-
if (Array.isArray(primaryKey.columns) && primaryKey.columns.length > 1) {
|
|
130
|
-
var indexColumnList = primaryKey.columns.map(function (col) {
|
|
131
|
-
return {
|
|
132
|
-
value: col,
|
|
133
|
-
type: 'column'
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
var indexEntity = new _AST.Index({
|
|
137
|
-
name: primaryKey.name,
|
|
138
|
-
unique: false,
|
|
139
|
-
columns: indexColumnList,
|
|
140
|
-
pk: true
|
|
141
|
-
});
|
|
142
|
-
indexEntityList.push(indexEntity);
|
|
143
|
-
}
|
|
144
|
-
compositeUniqueConstraintList.forEach(function (key) {
|
|
145
|
-
var indexColumnList = key.columns.map(function (col) {
|
|
146
|
-
return {
|
|
147
|
-
value: col,
|
|
148
|
-
type: 'column'
|
|
149
|
-
};
|
|
150
|
-
});
|
|
151
|
-
var indexEntity = new _AST.Index({
|
|
152
|
-
name: key.name,
|
|
153
|
-
unique: true,
|
|
154
|
-
pk: false,
|
|
155
|
-
columns: indexColumnList
|
|
156
|
-
});
|
|
157
|
-
indexEntityList.push(indexEntity);
|
|
158
|
-
});
|
|
159
|
-
return indexEntityList;
|
|
160
|
-
}
|
|
161
|
-
function getInlineUniqueConstraints(constraintMap) {
|
|
162
|
-
return Object.values(constraintMap).filter(function (constraint) {
|
|
163
|
-
return Array.isArray(constraint.columns) && constraint.columns.length === 1;
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
function getCompositeUniqueConstraints(constraintMap) {
|
|
167
|
-
return Object.values(constraintMap).filter(function (constraint) {
|
|
168
|
-
return Array.isArray(constraint.columns) && constraint.columns.length > 1;
|
|
169
|
-
});
|
|
170
|
-
}
|
|
File without changes
|