@dbml/core 5.1.0 → 5.2.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 (53) hide show
  1. package/lib/export/DbmlExporter.js +3 -2
  2. package/lib/export/MysqlExporter.js +2 -2
  3. package/lib/export/OracleExporter.js +2 -2
  4. package/lib/export/PostgresExporter.js +2 -2
  5. package/lib/export/SqlServerExporter.js +2 -2
  6. package/lib/model_structure/element.js +1 -3
  7. package/lib/parse/ANTLR/ASTGeneration/AST.js +0 -2
  8. package/lib/parse/ANTLR/ASTGeneration/constants.js +1 -0
  9. package/lib/parse/ANTLR/ASTGeneration/index.js +16 -3
  10. package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +1 -1
  11. package/lib/parse/ANTLR/ASTGeneration/mssql/README.md +157 -0
  12. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +1 -1
  13. package/lib/parse/ANTLR/ASTGeneration/mysql/README.md +157 -0
  14. package/lib/parse/ANTLR/ASTGeneration/oraclesql/OracleSQLASTGen.js +1154 -0
  15. package/lib/parse/ANTLR/ASTGeneration/oraclesql/README.md +157 -0
  16. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +2 -3
  17. package/lib/parse/ANTLR/ASTGeneration/postgres/README.md +157 -0
  18. package/lib/parse/ANTLR/ASTGeneration/snowflake/README.md +157 -0
  19. package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +1 -1
  20. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +60 -2
  21. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +25 -4
  22. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +1235 -1171
  23. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +2306 -2300
  24. package/lib/parse/ANTLR/parsers/mysql/MySqlLexerBase.js +52 -0
  25. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +6 -4
  26. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +15 -3
  27. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +2 -2
  28. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +2306 -2300
  29. package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +1 -1
  30. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.g4 +2623 -0
  31. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.interp +7475 -0
  32. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.js +3 -0
  33. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexer.tokens +4934 -0
  34. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlLexerBase.js +35 -0
  35. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.g4 +9988 -0
  36. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.interp +6174 -0
  37. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.js +3 -0
  38. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParser.tokens +4934 -0
  39. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserBase.js +64 -0
  40. package/lib/parse/ANTLR/parsers/oraclesql/OracleSqlParserVisitor.js +8466 -0
  41. package/lib/parse/Parser.js +8 -0
  42. package/lib/parse/buildParser.js +1 -1
  43. package/lib/parse/databaseGenerator.js +2 -2
  44. package/lib/parse/error.js +0 -1
  45. package/lib/parse/mssql/fk_definition/actions.js +1 -1
  46. package/lib/parse/mssql/index.js +0 -1
  47. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -1
  48. package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -2
  49. package/lib/parse/mssql/statements/statement_types/comments/index.js +2 -2
  50. package/lib/parse/mssql/utils.js +0 -1
  51. package/package.json +16 -5
  52. package/types/import/index.d.ts +1 -1
  53. package/types/parse/Parser.d.ts +3 -1
@@ -61,6 +61,9 @@ var Parser = /*#__PURE__*/function () {
61
61
  case 'mssql':
62
62
  rawDatabase = Parser.parseMSSQLToJSONv2(str);
63
63
  break;
64
+ case 'oracle':
65
+ rawDatabase = Parser.parseOracleToJSON(str);
66
+ break;
64
67
  case 'json':
65
68
  if (_typeof(str) === 'object') {
66
69
  rawDatabase = str;
@@ -152,6 +155,11 @@ var Parser = /*#__PURE__*/function () {
152
155
  value: function parseSnowflakeToJSON(str) {
153
156
  return (0, _ASTGeneration.parse)(str, 'snowflake');
154
157
  }
158
+ }, {
159
+ key: "parseOracleToJSON",
160
+ value: function parseOracleToJSON(str) {
161
+ return (0, _ASTGeneration.parse)(str, 'oracle');
162
+ }
155
163
  }, {
156
164
  key: "parse",
157
165
  value: function parse(str, format) {
@@ -8,7 +8,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
8
8
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
9
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof Symbol ? Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return Object.defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = Object.getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l); function g(t) { ["next", "throw", "return"].forEach(function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
10
10
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
11
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /* eslint-disable */ /* eslint-enable */
11
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
12
12
  _bluebird["default"].promisifyAll(_fs["default"]);
13
13
  function buildParserFile(_x, _x2) {
14
14
  return _buildParserFile.apply(this, arguments);
@@ -60,13 +60,13 @@ var createIndexes = function createIndexes(rawIndexes) {
60
60
  return rawIndexes.map(function (rawIndex) {
61
61
  var name = rawIndex.name,
62
62
  unique = rawIndex.unique,
63
- primary = rawIndex.primary,
63
+ pk = rawIndex.pk,
64
64
  type = rawIndex.type,
65
65
  columns = rawIndex.columns;
66
66
  var index = new _AST.Index({
67
67
  name: name,
68
68
  unique: unique,
69
- pk: primary,
69
+ pk: pk,
70
70
  type: type,
71
71
  columns: columns
72
72
  });
@@ -26,7 +26,6 @@ var CompilerError = exports.CompilerError = /*#__PURE__*/function () {
26
26
  }], [{
27
27
  key: "create",
28
28
  value: function create(nestedDiags) {
29
- // eslint-disable-next-line no-use-before-define
30
29
  return new CompilerError(flattenDiag(nestedDiags));
31
30
  }
32
31
  }]);
@@ -44,7 +44,7 @@ function makeTableConstraintFK(_keyword1, endpoint1, _keyword2, tableName, endpo
44
44
  var fullTableName = getFullTableName(tableName);
45
45
  if (!endpoint2) {
46
46
  // Omits columns list, see: https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-ver16#foreign-key-constraints
47
- // eslint-disable-next-line no-param-reassign
47
+
48
48
  endpoint2 = {
49
49
  type: 'endpoint',
50
50
  value: {
@@ -15,7 +15,6 @@ mssqlParser.parseWithPegError = function (input) {
15
15
  var lastExpected = err.result.expected.pop();
16
16
  var expectedString = "".concat(err.result.expected.join(', '), ", or ").concat(lastExpected);
17
17
  pegJSError.message = "Expected ".concat(expectedString, " but \"").concat(pegJSError.found, "\" found.");
18
- // eslint-disable-next-line no-console
19
18
  throw pegJSError;
20
19
  }
21
20
  };
@@ -17,7 +17,6 @@ function addTableName(tableName, result) {
17
17
  function handleAlterTableResult(_keyword, tableName, results) {
18
18
  if (!results) return null;
19
19
  var fullName = getFullTableName(tableName);
20
- // eslint-disable-next-line consistent-return
21
20
  results.forEach(function (result) {
22
21
  if (result) {
23
22
  switch (result.type) {
@@ -2,8 +2,6 @@
2
2
 
3
3
  var _require = require('../../../../constraint_definition'),
4
4
  makeTableConstraint = _require.makeTableConstraint;
5
-
6
- // eslint-disable-next-line no-unused-vars
7
5
  function makeDefault(_keyword, constExpression, _for, fieldName, _withValues) {
8
6
  var value = {};
9
7
  if (constExpression.type) {
@@ -19,10 +19,10 @@ var Lang = P.createLanguage({
19
19
  return P.seq(KP.Semicolon.atMost(1), KP.KeywordGo);
20
20
  },
21
21
  StartString: function StartString() {
22
- return P.alt(KP.SingleQuote, P.string("N'"));
22
+ return P.alt(KP.SingleQuote, P.string('N\''));
23
23
  },
24
24
  ManyDoubleSingleQuote: function ManyDoubleSingleQuote() {
25
- return P.string("''");
25
+ return P.string('\'\'');
26
26
  },
27
27
  NoSingleQuote: function NoSingleQuote() {
28
28
  return P.regex(/[^']/);
@@ -34,7 +34,6 @@ exports.makeList = function (parser) {
34
34
  exports.streamline = function (type) {
35
35
  return function (parser) {
36
36
  return parser.skip(wss).map(function (value) {
37
- // eslint-disable-next-line no-param-reassign
38
37
  if (value !== 0 && !value) value = '';
39
38
  return {
40
39
  type: type,
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/package",
2
3
  "name": "@dbml/core",
3
- "version": "5.1.0",
4
+ "version": "5.2.0",
4
5
  "description": "> TODO: description",
5
6
  "author": "Holistics <dev@holistics.io>",
6
7
  "license": "Apache-2.0",
@@ -29,10 +30,12 @@
29
30
  "build:lib": "babel src --out-dir lib --copy-files",
30
31
  "build:parser": "npx babel-node src/parse/buildParser.js",
31
32
  "build": "npm run build:parser && npm run build:lib",
32
- "prepublish": "npm run build"
33
+ "prepublish": "npm run build",
34
+ "lint": "eslint .",
35
+ "lint:fix": "eslint --fix ."
33
36
  },
34
37
  "dependencies": {
35
- "@dbml/parse": "^5.1.0",
38
+ "@dbml/parse": "^5.2.0",
36
39
  "antlr4": "^4.13.1",
37
40
  "lodash": "^4.17.15",
38
41
  "parsimmon": "^1.13.0",
@@ -44,11 +47,19 @@
44
47
  "@babel/node": "^7.20.7",
45
48
  "@babel/preset-env": "^7.21.4",
46
49
  "@glen/jest-raw-loader": "^2.0.0",
50
+ "@stylistic/eslint-plugin": "^5.5.0",
51
+ "@typescript-eslint/eslint-plugin": "^8.46.3",
52
+ "@typescript-eslint/parser": "^8.46.3",
47
53
  "babel-jest": "^29.5.0",
48
54
  "bluebird": "^3.5.5",
55
+ "eslint": "^9.39.1",
56
+ "eslint-plugin-jest": "^29.0.1",
57
+ "globals": "^16.5.0",
49
58
  "jest": "^29.5.0",
50
59
  "jest-bench": "^29.4.1",
51
- "pegjs-require-import": "0.0.6"
60
+ "pegjs-require-import": "0.0.6",
61
+ "typescript": "^5.9.3",
62
+ "typescript-eslint": "^8.46.3"
52
63
  },
53
64
  "jest": {
54
65
  "setupFiles": [
@@ -62,7 +73,7 @@
62
73
  "^lodash-es$": "lodash"
63
74
  }
64
75
  },
65
- "gitHead": "376dca507512a3fe549f630e6f22d7d339939183",
76
+ "gitHead": "20d556a6e6baad8a989c730e2afd3b65dedcea89",
66
77
  "engines": {
67
78
  "node": ">=16"
68
79
  }
@@ -1,4 +1,4 @@
1
- declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy' | 'mssqlLegacy'): string;
1
+ declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy' | 'mssqlLegacy' | 'oracle'): string;
2
2
 
3
3
  /**
4
4
  * @param {any} schemaJson
@@ -7,7 +7,8 @@ declare type ParseFormat = 'json'
7
7
  | 'dbml' | 'dbmlv2'
8
8
  | 'mssql' | 'mssqlLegacy'
9
9
  | 'schemarb'
10
- | 'snowflake';
10
+ | 'snowflake'
11
+ | 'oracle';
11
12
 
12
13
  declare class Parser {
13
14
  public DBMLCompiler: Compiler;
@@ -23,6 +24,7 @@ declare class Parser {
23
24
  static parseMSSQLToJSON(str: string): RawDatabase;
24
25
  static parseMSSQLToJSONv2(str: string): RawDatabase;
25
26
  static parseSnowflakeToJSON(str: string): RawDatabase;
27
+ static parseOracleToJSON(str: string): RawDatabase;
26
28
  /**
27
29
  * Should use parse() instance method instead of this static method whenever possible
28
30
  */