@dbml/core 2.5.4 → 2.6.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 (27) hide show
  1. package/lib/model_structure/field.js +3 -1
  2. package/lib/parse/ANTLR/ASTGeneration/AST.js +246 -0
  3. package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +40 -0
  4. package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +47 -0
  5. package/lib/parse/ANTLR/ASTGeneration/index.js +32 -0
  6. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +43 -0
  7. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +37 -0
  8. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +1126 -0
  9. package/lib/parse/ANTLR/README.md +32 -0
  10. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +3044 -0
  11. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +2074 -0
  12. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +882 -0
  13. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +1314 -0
  14. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +5506 -0
  15. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +2182 -0
  16. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +3 -0
  17. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -0
  18. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +5767 -0
  19. package/lib/parse/ANTLR/parsers/postgresql/README.md +10 -0
  20. package/lib/parse/Parser.js +9 -0
  21. package/lib/parse/dbml/parser.pegjs +2 -2
  22. package/lib/parse/dbmlParser.js +66 -103
  23. package/lib/parse/mysql/parser.pegjs +2 -2
  24. package/lib/parse/mysqlParser.js +281 -283
  25. package/package.json +5 -2
  26. package/types/import/index.d.ts +1 -1
  27. package/types/parse/Parser.d.ts +1 -0
@@ -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
- this.error("Cannot find type ".concat(typeSchemaName, " in schema ").concat(typeSchemaName));
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;
@@ -0,0 +1,47 @@
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
+ 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); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
+ 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); }
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+ 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); }
14
+ 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); }; }
15
+ 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); }
16
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
18
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
19
+ 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; } }
20
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
21
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
23
+ var SyntaxError = /*#__PURE__*/function (_Error) {
24
+ _inherits(SyntaxError, _Error);
25
+ var _super = _createSuper(SyntaxError);
26
+ function SyntaxError(line, column, msg) {
27
+ var _this;
28
+ _classCallCheck(this, SyntaxError);
29
+ _this = _super.call(this, msg);
30
+ // maintain proper stack trace
31
+ if (Error.captureStackTrace) {
32
+ Error.captureStackTrace(_assertThisInitialized(_this), SyntaxError);
33
+ }
34
+
35
+ // These properies names and structures are needed by other app (for example dbdiagram) to display error.
36
+ _this.text = msg;
37
+ _this.location = {
38
+ start: {
39
+ line: line,
40
+ column: column
41
+ }
42
+ };
43
+ return _this;
44
+ }
45
+ return _createClass(SyntaxError);
46
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
47
+ exports["default"] = SyntaxError;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parse = parse;
7
+ var _antlr = _interopRequireDefault(require("antlr4"));
8
+ var _PostgreSQLLexer = _interopRequireDefault(require("../parsers/postgresql/PostgreSQLLexer"));
9
+ var _PostgreSQLParser = _interopRequireDefault(require("../parsers/postgresql/PostgreSQLParser"));
10
+ var _PostgresASTGen = _interopRequireDefault(require("./postgres/PostgresASTGen"));
11
+ var _ParserErrorListener = _interopRequireDefault(require("./ParserErrorListener"));
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+ /* eslint-disable import/no-named-as-default-member */
14
+ /* eslint-disable import/no-named-as-default */
15
+
16
+ function parse(input, format) {
17
+ var chars = new _antlr["default"].InputStream(input);
18
+ var database = null;
19
+ if (format === 'postgres') {
20
+ var lexer = new _PostgreSQLLexer["default"](chars);
21
+ var tokens = new _antlr["default"].CommonTokenStream(lexer);
22
+ var parser = new _PostgreSQLParser["default"](tokens);
23
+ parser.buildParseTrees = true;
24
+ parser.removeErrorListeners();
25
+ parser.addErrorListener(new _ParserErrorListener["default"]());
26
+ var parseTree = parser.root();
27
+ database = parseTree.accept(new _PostgresASTGen["default"]());
28
+ } else {
29
+ throw new Error("Format not supported: ".concat(format));
30
+ }
31
+ return database;
32
+ }
@@ -0,0 +1,43 @@
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.HandleLessLessGreaterGreater = HandleLessLessGreaterGreater;
8
+ exports.checkLA = checkLA;
9
+ exports["default"] = void 0;
10
+ exports.isTag = isTag;
11
+ exports.pushTag = pushTag;
12
+ var _antlr = _interopRequireDefault(require("antlr4"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ 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); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
17
+ 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); }
18
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ 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); }
20
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
+ 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); }; }
22
+ 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); }
23
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
+ 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; } }
25
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
26
+ // original (C#): https://github.com/antlr/grammars-v4/blob/master/sql/postgresql/CSharp/PostgreSQLLexerBase.cs
27
+ // Base class required by the generated lexer
28
+ var PostgreSQLLexerBase = /*#__PURE__*/function (_antlr4$Lexer) {
29
+ _inherits(PostgreSQLLexerBase, _antlr4$Lexer);
30
+ var _super = _createSuper(PostgreSQLLexerBase);
31
+ function PostgreSQLLexerBase() {
32
+ _classCallCheck(this, PostgreSQLLexerBase);
33
+ return _super.apply(this, arguments);
34
+ }
35
+ return _createClass(PostgreSQLLexerBase);
36
+ }(_antlr["default"].Lexer); // helper functions required by the generated grammar, these were called implicitly without the 'this.' keyword
37
+ // In C#, these can be decleare as base classes's methods, this won't work in JS.
38
+ // To avoid error, we declare their signature and import them in the generated PostgreSQLLexer.js
39
+ exports["default"] = PostgreSQLLexerBase;
40
+ function checkLA() {}
41
+ function HandleLessLessGreaterGreater() {}
42
+ function pushTag() {}
43
+ function isTag() {}
@@ -0,0 +1,37 @@
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.ParseRoutineBody = ParseRoutineBody;
8
+ exports["default"] = void 0;
9
+ var _antlr = _interopRequireDefault(require("antlr4"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+ 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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ 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); }
15
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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
+ // Original (C#): https://github.com/antlr/grammars-v4/blob/master/sql/postgresql/CSharp/PostgreSQLLexerBase.cs
24
+ // Base class required by the generated parser
25
+ var PostgreSQLParserBase = /*#__PURE__*/function (_antlr4$Parser) {
26
+ _inherits(PostgreSQLParserBase, _antlr4$Parser);
27
+ var _super = _createSuper(PostgreSQLParserBase);
28
+ function PostgreSQLParserBase() {
29
+ _classCallCheck(this, PostgreSQLParserBase);
30
+ return _super.apply(this, arguments);
31
+ }
32
+ return _createClass(PostgreSQLParserBase);
33
+ }(_antlr["default"].Parser); // helper function required by the generated grammar, these were called implicitly without the 'this.' keyword
34
+ // In C#, these can be decleare as base classes's methods, this won't work in JS.
35
+ // To avoid error, we declare their signature and import them in the generated PostgreSQLParser.js
36
+ exports["default"] = PostgreSQLParserBase;
37
+ function ParseRoutineBody() {}