@dbml/core 2.5.4 → 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.
Files changed (28) 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/PostgresASTGen.js +1126 -0
  5. package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +47 -0
  6. package/lib/parse/ANTLR/ASTGeneration/index.js +32 -0
  7. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +43 -0
  8. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +37 -0
  9. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +1126 -0
  10. package/lib/parse/ANTLR/README.md +32 -0
  11. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +3044 -0
  12. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +2074 -0
  13. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +882 -0
  14. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +1314 -0
  15. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexerBase.js +42 -0
  16. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +5506 -0
  17. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +2182 -0
  18. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +3 -0
  19. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -0
  20. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserBase.js +36 -0
  21. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +5767 -0
  22. package/lib/parse/ANTLR/parsers/postgresql/README.md +10 -0
  23. package/lib/parse/Parser.js +9 -0
  24. package/lib/parse/dbml/parser.pegjs +2 -2
  25. package/lib/parse/dbmlParser.js +66 -103
  26. package/package.json +5 -2
  27. package/types/import/index.d.ts +1 -1
  28. package/types/parse/Parser.d.ts +1 -0
@@ -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() {}