@dbml/core 2.5.3 → 2.6.0
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/README.md +1 -1
- package/lib/model_structure/field.js +3 -1
- package/lib/parse/ANTLR/ASTGeneration/AST.js +246 -0
- package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +40 -0
- package/lib/parse/ANTLR/ASTGeneration/PostgresASTGen.js +1126 -0
- package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +47 -0
- package/lib/parse/ANTLR/ASTGeneration/index.js +32 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +43 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +37 -0
- package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +1126 -0
- package/lib/parse/ANTLR/README.md +32 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +3044 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +2074 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +882 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +1314 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexerBase.js +42 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +5506 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +2182 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +3 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserBase.js +36 -0
- package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +5767 -0
- package/lib/parse/ANTLR/parsers/postgresql/README.md +10 -0
- package/lib/parse/Parser.js +9 -0
- package/lib/parse/dbml/parser.pegjs +2 -2
- package/lib/parse/dbmlParser.js +66 -103
- package/lib/parse/mssql/constraint_definition/index.js +3 -3
- package/package.json +6 -3
- package/types/import/index.d.ts +1 -1
- package/types/parse/Parser.d.ts +1 -0
package/README.md
CHANGED
|
@@ -78,7 +78,9 @@ var Field = /*#__PURE__*/function (_Element) {
|
|
|
78
78
|
if (this.type.schemaName) {
|
|
79
79
|
var _enum = this.table.schema.database.findEnum(typeSchemaName, typeName);
|
|
80
80
|
if (!_enum) {
|
|
81
|
-
|
|
81
|
+
// SQL allow definition of non-enum type to be used as column type, which we don't have equivalent dbml counterpart.
|
|
82
|
+
// So instead of throwing errors on those type, we can view the type as plain text for the purpose of importing to dbml.
|
|
83
|
+
this.type.type_name = "".concat(typeSchemaName, ".").concat(typeName);
|
|
82
84
|
return;
|
|
83
85
|
}
|
|
84
86
|
this._enum = _enum;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Table = exports.Ref = exports.Index = exports.Field = exports.Enum = exports.Endpoint = void 0;
|
|
7
|
+
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); }
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
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); } }
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
13
|
+
/* eslint-disable max-classes-per-file */
|
|
14
|
+
var Index = /*#__PURE__*/function () {
|
|
15
|
+
function Index(_ref) {
|
|
16
|
+
var name = _ref.name,
|
|
17
|
+
unique = _ref.unique,
|
|
18
|
+
pk = _ref.pk,
|
|
19
|
+
type = _ref.type,
|
|
20
|
+
columns = _ref.columns;
|
|
21
|
+
_classCallCheck(this, Index);
|
|
22
|
+
/** @type {string} */
|
|
23
|
+
this.name = name;
|
|
24
|
+
|
|
25
|
+
/** @type {string} */
|
|
26
|
+
this.type = type;
|
|
27
|
+
|
|
28
|
+
/** @type {boolean} */
|
|
29
|
+
this.unique = unique;
|
|
30
|
+
|
|
31
|
+
/** @type {boolean} */
|
|
32
|
+
this.pk = pk;
|
|
33
|
+
|
|
34
|
+
/** @type {{value: string, type: string}[]} */
|
|
35
|
+
this.columns = columns;
|
|
36
|
+
}
|
|
37
|
+
_createClass(Index, [{
|
|
38
|
+
key: "toJSON",
|
|
39
|
+
value: function toJSON() {
|
|
40
|
+
return {
|
|
41
|
+
name: this.name,
|
|
42
|
+
type: this.type,
|
|
43
|
+
unique: this.unique,
|
|
44
|
+
pk: this.pk,
|
|
45
|
+
columns: this.columns
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
return Index;
|
|
50
|
+
}();
|
|
51
|
+
exports.Index = Index;
|
|
52
|
+
var Field = /*#__PURE__*/function () {
|
|
53
|
+
/** @type {boolean} */
|
|
54
|
+
// fk;
|
|
55
|
+
|
|
56
|
+
function Field(_ref2) {
|
|
57
|
+
var name = _ref2.name,
|
|
58
|
+
type = _ref2.type,
|
|
59
|
+
not_null = _ref2.not_null,
|
|
60
|
+
increment = _ref2.increment,
|
|
61
|
+
dbdefault = _ref2.dbdefault,
|
|
62
|
+
unique = _ref2.unique,
|
|
63
|
+
pk = _ref2.pk,
|
|
64
|
+
note = _ref2.note;
|
|
65
|
+
_classCallCheck(this, Field);
|
|
66
|
+
/** @type {string} */
|
|
67
|
+
this.name = name;
|
|
68
|
+
|
|
69
|
+
/** @type {{type_name: string, schemaName: string}} */
|
|
70
|
+
this.type = type;
|
|
71
|
+
|
|
72
|
+
/** @type {boolean} */
|
|
73
|
+
this.not_null = not_null;
|
|
74
|
+
|
|
75
|
+
/** @type {boolean} */
|
|
76
|
+
this.increment = increment;
|
|
77
|
+
|
|
78
|
+
/** @type {{value: string, type: 'string'}} */
|
|
79
|
+
this.dbdefault = dbdefault;
|
|
80
|
+
|
|
81
|
+
/** @type {boolean} */
|
|
82
|
+
this.unique = unique;
|
|
83
|
+
|
|
84
|
+
/** @type {boolean} */
|
|
85
|
+
this.pk = pk;
|
|
86
|
+
|
|
87
|
+
/** @type {string} */
|
|
88
|
+
this.note = note;
|
|
89
|
+
}
|
|
90
|
+
_createClass(Field, [{
|
|
91
|
+
key: "toJSON",
|
|
92
|
+
value: function toJSON() {
|
|
93
|
+
return {
|
|
94
|
+
name: this.name,
|
|
95
|
+
type: this.type,
|
|
96
|
+
not_null: this.not_null,
|
|
97
|
+
increment: this.increment,
|
|
98
|
+
dbdefault: this.dbdefault,
|
|
99
|
+
unique: this.unique,
|
|
100
|
+
pk: this.pk,
|
|
101
|
+
note: this.note
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}]);
|
|
105
|
+
return Field;
|
|
106
|
+
}();
|
|
107
|
+
exports.Field = Field;
|
|
108
|
+
var Table = /*#__PURE__*/function () {
|
|
109
|
+
function Table(_ref3) {
|
|
110
|
+
var name = _ref3.name,
|
|
111
|
+
schemaName = _ref3.schemaName,
|
|
112
|
+
fields = _ref3.fields,
|
|
113
|
+
indexes = _ref3.indexes,
|
|
114
|
+
note = _ref3.note;
|
|
115
|
+
_classCallCheck(this, Table);
|
|
116
|
+
/** @type {string} */
|
|
117
|
+
this.name = name;
|
|
118
|
+
|
|
119
|
+
/** @type {string} */
|
|
120
|
+
this.schemaName = schemaName;
|
|
121
|
+
|
|
122
|
+
/** @type {Array<Field>} */
|
|
123
|
+
this.fields = fields || [];
|
|
124
|
+
|
|
125
|
+
/** @type {Array<Index>} */
|
|
126
|
+
this.indexes = indexes || [];
|
|
127
|
+
|
|
128
|
+
/** @type {string} */
|
|
129
|
+
this.note = note;
|
|
130
|
+
}
|
|
131
|
+
_createClass(Table, [{
|
|
132
|
+
key: "toJSON",
|
|
133
|
+
value: function toJSON() {
|
|
134
|
+
var _this$fields, _this$indexes;
|
|
135
|
+
return {
|
|
136
|
+
name: this.name,
|
|
137
|
+
schemaName: this.schemaName,
|
|
138
|
+
fields: (_this$fields = this.fields) === null || _this$fields === void 0 ? void 0 : _this$fields.map(function (f) {
|
|
139
|
+
return f.toJSON();
|
|
140
|
+
}),
|
|
141
|
+
indexes: (_this$indexes = this.indexes) === null || _this$indexes === void 0 ? void 0 : _this$indexes.map(function (i) {
|
|
142
|
+
return i.toJSON();
|
|
143
|
+
}),
|
|
144
|
+
note: this.note
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}]);
|
|
148
|
+
return Table;
|
|
149
|
+
}();
|
|
150
|
+
exports.Table = Table;
|
|
151
|
+
var Endpoint = /*#__PURE__*/function () {
|
|
152
|
+
function Endpoint(_ref4) {
|
|
153
|
+
var tableName = _ref4.tableName,
|
|
154
|
+
schemaName = _ref4.schemaName,
|
|
155
|
+
fieldNames = _ref4.fieldNames,
|
|
156
|
+
relation = _ref4.relation;
|
|
157
|
+
_classCallCheck(this, Endpoint);
|
|
158
|
+
/** @type {string} */
|
|
159
|
+
this.tableName = tableName;
|
|
160
|
+
|
|
161
|
+
/** @type {string} */
|
|
162
|
+
this.schemaName = schemaName;
|
|
163
|
+
|
|
164
|
+
/** @type {string[]} */
|
|
165
|
+
this.fieldNames = fieldNames;
|
|
166
|
+
|
|
167
|
+
/** @type {string} */
|
|
168
|
+
this.relation = relation;
|
|
169
|
+
}
|
|
170
|
+
_createClass(Endpoint, [{
|
|
171
|
+
key: "toJSON",
|
|
172
|
+
value: function toJSON() {
|
|
173
|
+
return {
|
|
174
|
+
tableName: this.tableName,
|
|
175
|
+
schemaName: this.schemaName,
|
|
176
|
+
fieldNames: this.fieldNames,
|
|
177
|
+
relation: this.relation
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}]);
|
|
181
|
+
return Endpoint;
|
|
182
|
+
}();
|
|
183
|
+
exports.Endpoint = Endpoint;
|
|
184
|
+
var Ref = /*#__PURE__*/function () {
|
|
185
|
+
function Ref(_ref5) {
|
|
186
|
+
var name = _ref5.name,
|
|
187
|
+
endpoints = _ref5.endpoints,
|
|
188
|
+
onDelete = _ref5.onDelete,
|
|
189
|
+
onUpdate = _ref5.onUpdate;
|
|
190
|
+
_classCallCheck(this, Ref);
|
|
191
|
+
/** @type {string} */
|
|
192
|
+
this.name = name;
|
|
193
|
+
|
|
194
|
+
/** @type {Array<Endpoint>} */
|
|
195
|
+
this.endpoints = endpoints || [];
|
|
196
|
+
|
|
197
|
+
/** @type {string} */
|
|
198
|
+
this.onDelete = onDelete;
|
|
199
|
+
|
|
200
|
+
/** @type {string} */
|
|
201
|
+
this.onUpdate = onUpdate;
|
|
202
|
+
}
|
|
203
|
+
_createClass(Ref, [{
|
|
204
|
+
key: "toJSON",
|
|
205
|
+
value: function toJSON() {
|
|
206
|
+
return {
|
|
207
|
+
name: this.name,
|
|
208
|
+
onDelete: this.onDelete,
|
|
209
|
+
onUpdate: this.onUpdate,
|
|
210
|
+
endpoints: this.endpoints.map(function (e) {
|
|
211
|
+
return e.toJSON();
|
|
212
|
+
})
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}]);
|
|
216
|
+
return Ref;
|
|
217
|
+
}();
|
|
218
|
+
exports.Ref = Ref;
|
|
219
|
+
var Enum = /*#__PURE__*/function () {
|
|
220
|
+
function Enum(_ref6) {
|
|
221
|
+
var name = _ref6.name,
|
|
222
|
+
schemaName = _ref6.schemaName,
|
|
223
|
+
values = _ref6.values;
|
|
224
|
+
_classCallCheck(this, Enum);
|
|
225
|
+
/** @type {string} */
|
|
226
|
+
this.name = name;
|
|
227
|
+
|
|
228
|
+
/** @type {string} */
|
|
229
|
+
this.schemaName = schemaName;
|
|
230
|
+
|
|
231
|
+
/** @type {{name: string}[]} */
|
|
232
|
+
this.values = values;
|
|
233
|
+
}
|
|
234
|
+
_createClass(Enum, [{
|
|
235
|
+
key: "toJSON",
|
|
236
|
+
value: function toJSON() {
|
|
237
|
+
return {
|
|
238
|
+
name: this.name,
|
|
239
|
+
schemaName: this.schemaName,
|
|
240
|
+
values: this.values
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}]);
|
|
244
|
+
return Enum;
|
|
245
|
+
}();
|
|
246
|
+
exports.Enum = Enum;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 _antlr = _interopRequireDefault(require("antlr4"));
|
|
9
|
+
var _SyntaxError = _interopRequireDefault(require("./SyntaxError"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
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); } }
|
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
|
+
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); }
|
|
16
|
+
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); }
|
|
17
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
18
|
+
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); }; }
|
|
19
|
+
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); }
|
|
20
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
21
|
+
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; } }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
var ParserErrorListener = /*#__PURE__*/function (_antlr4$error$ErrorLi) {
|
|
24
|
+
_inherits(ParserErrorListener, _antlr4$error$ErrorLi);
|
|
25
|
+
var _super = _createSuper(ParserErrorListener);
|
|
26
|
+
function ParserErrorListener() {
|
|
27
|
+
_classCallCheck(this, ParserErrorListener);
|
|
28
|
+
return _super.apply(this, arguments);
|
|
29
|
+
}
|
|
30
|
+
_createClass(ParserErrorListener, [{
|
|
31
|
+
key: "syntaxError",
|
|
32
|
+
value:
|
|
33
|
+
// eslint-disable-next-line class-methods-use-this, no-unused-vars
|
|
34
|
+
function syntaxError(recognizer, offendingSymbol, line, column, msg, err) {
|
|
35
|
+
throw new _SyntaxError["default"](line, column, msg);
|
|
36
|
+
}
|
|
37
|
+
}]);
|
|
38
|
+
return ParserErrorListener;
|
|
39
|
+
}(_antlr["default"].error.ErrorListener);
|
|
40
|
+
exports["default"] = ParserErrorListener;
|