@dbml/core 3.6.2 → 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.
Files changed (157) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +0 -0
  3. package/lib/{connector/index.js → connectors/connector.js} +23 -23
  4. package/lib/connectors/mssqlConnector.js +391 -0
  5. package/lib/connectors/mysqlConnector.js +490 -0
  6. package/lib/{parse/connection/postgres/utils.js → connectors/postgresConnector.js} +106 -168
  7. package/lib/export/DbmlExporter.js +5 -2
  8. package/lib/export/JsonExporter.js +0 -0
  9. package/lib/export/ModelExporter.js +0 -0
  10. package/lib/export/MysqlExporter.js +0 -0
  11. package/lib/export/OracleExporter.js +0 -0
  12. package/lib/export/PostgresExporter.js +0 -0
  13. package/lib/export/README.md +0 -0
  14. package/lib/export/SqlServerExporter.js +0 -0
  15. package/lib/export/index.js +0 -0
  16. package/lib/export/utils.js +0 -0
  17. package/lib/import/index.js +32 -1
  18. package/lib/index.js +0 -0
  19. package/lib/model_structure/config.js +0 -0
  20. package/lib/model_structure/database.js +0 -0
  21. package/lib/model_structure/dbState.js +0 -0
  22. package/lib/model_structure/element.js +0 -0
  23. package/lib/model_structure/endpoint.js +0 -0
  24. package/lib/model_structure/enum.js +0 -0
  25. package/lib/model_structure/enumValue.js +0 -0
  26. package/lib/model_structure/field.js +0 -0
  27. package/lib/model_structure/indexColumn.js +0 -0
  28. package/lib/model_structure/indexes.js +0 -0
  29. package/lib/model_structure/ref.js +0 -0
  30. package/lib/model_structure/schema.js +0 -0
  31. package/lib/model_structure/stickyNote.js +0 -0
  32. package/lib/model_structure/table.js +0 -0
  33. package/lib/model_structure/tableGroup.js +0 -0
  34. package/lib/model_structure/utils.js +0 -0
  35. package/lib/parse/ANTLR/ASTGeneration/AST.js +1 -0
  36. package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +0 -0
  37. package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +0 -0
  38. package/lib/parse/ANTLR/ASTGeneration/constants.js +0 -0
  39. package/lib/parse/ANTLR/ASTGeneration/helpers.js +0 -0
  40. package/lib/parse/ANTLR/ASTGeneration/index.js +0 -0
  41. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +0 -0
  42. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +0 -0
  43. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +0 -0
  44. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +0 -0
  45. package/lib/parse/ANTLR/ASTGeneration/snowflake/SnowflakeASTGen.js +1 -1
  46. package/lib/parse/ANTLR/README.md +0 -0
  47. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.g4 +0 -0
  48. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.interp +0 -0
  49. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.js +0 -0
  50. package/lib/parse/ANTLR/parsers/mysql/MySqlLexer.tokens +0 -0
  51. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.g4 +0 -0
  52. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.interp +0 -0
  53. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.js +0 -0
  54. package/lib/parse/ANTLR/parsers/mysql/MySqlParser.tokens +0 -0
  55. package/lib/parse/ANTLR/parsers/mysql/MySqlParserVisitor.js +0 -0
  56. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +0 -0
  57. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +0 -0
  58. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +0 -0
  59. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +0 -0
  60. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +0 -0
  61. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +0 -0
  62. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +0 -0
  63. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +0 -0
  64. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +0 -0
  65. package/lib/parse/ANTLR/parsers/postgresql/README.md +0 -0
  66. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.g4 +0 -0
  67. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.interp +0 -0
  68. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.js +0 -0
  69. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeLexer.tokens +0 -0
  70. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.g4 +0 -0
  71. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.interp +0 -0
  72. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.js +0 -0
  73. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParser.tokens +0 -0
  74. package/lib/parse/ANTLR/parsers/snowflake/SnowflakeParserVisitor.js +0 -0
  75. package/lib/parse/Parser.js +0 -0
  76. package/lib/parse/buildParser.js +0 -0
  77. package/lib/parse/databaseGenerator.js +118 -0
  78. package/lib/parse/dbml/parser.pegjs +0 -0
  79. package/lib/parse/dbmlParser.js +0 -0
  80. package/lib/parse/error.js +0 -0
  81. package/lib/parse/mssql/base_parsers.js +0 -0
  82. package/lib/parse/mssql/column_definition/actions.js +0 -0
  83. package/lib/parse/mssql/column_definition/index.js +0 -0
  84. package/lib/parse/mssql/constraint_definition/actions.js +0 -0
  85. package/lib/parse/mssql/constraint_definition/index.js +0 -0
  86. package/lib/parse/mssql/expression.js +0 -0
  87. package/lib/parse/mssql/fk_definition/actions.js +0 -0
  88. package/lib/parse/mssql/fk_definition/index.js +0 -0
  89. package/lib/parse/mssql/index.js +0 -0
  90. package/lib/parse/mssql/index_definition/actions.js +0 -0
  91. package/lib/parse/mssql/index_definition/index.js +0 -0
  92. package/lib/parse/mssql/keyword_parsers.js +0 -0
  93. package/lib/parse/mssql/keyword_utils.js +0 -0
  94. package/lib/parse/mssql/statements/actions.js +0 -0
  95. package/lib/parse/mssql/statements/index.js +0 -0
  96. package/lib/parse/mssql/statements/statement_types/alter_table/actions.js +0 -0
  97. package/lib/parse/mssql/statements/statement_types/alter_table/add/actions.js +0 -0
  98. package/lib/parse/mssql/statements/statement_types/alter_table/add/index.js +0 -0
  99. package/lib/parse/mssql/statements/statement_types/alter_table/index.js +0 -0
  100. package/lib/parse/mssql/statements/statement_types/comments/actions.js +0 -0
  101. package/lib/parse/mssql/statements/statement_types/comments/index.js +0 -0
  102. package/lib/parse/mssql/statements/statement_types/create_index/actions.js +0 -0
  103. package/lib/parse/mssql/statements/statement_types/create_index/index.js +0 -0
  104. package/lib/parse/mssql/statements/statement_types/create_table/actions.js +0 -0
  105. package/lib/parse/mssql/statements/statement_types/create_table/index.js +0 -0
  106. package/lib/parse/mssql/statements/statement_types/index.js +0 -0
  107. package/lib/parse/mssql/utils.js +0 -0
  108. package/lib/parse/mssql/whitespaces.js +0 -0
  109. package/lib/parse/mssqlParser.js +0 -0
  110. package/lib/parse/mysql/parser.pegjs +0 -0
  111. package/lib/parse/mysqlParser.js +0 -0
  112. package/lib/parse/postgresParser.js +0 -0
  113. package/lib/parse/postgresql/Base_rules.pegjs +0 -0
  114. package/lib/parse/postgresql/Commands/Alter_table/Alter_table.pegjs +0 -0
  115. package/lib/parse/postgresql/Commands/Commands.pegjs +0 -0
  116. package/lib/parse/postgresql/Commands/Comment.pegjs +0 -0
  117. package/lib/parse/postgresql/Commands/Create_index.pegjs +0 -0
  118. package/lib/parse/postgresql/Commands/Create_table/Create_table.pegjs +0 -0
  119. package/lib/parse/postgresql/Commands/Create_table/Create_table_normal.pegjs +0 -0
  120. package/lib/parse/postgresql/Commands/Create_table/Create_table_of.pegjs +0 -0
  121. package/lib/parse/postgresql/Commands/Create_table/Create_table_partition_of.pegjs +0 -0
  122. package/lib/parse/postgresql/Commands/Create_type/Create_type.pegjs +0 -0
  123. package/lib/parse/postgresql/Commands/Create_type/Create_type_enum.pegjs +0 -0
  124. package/lib/parse/postgresql/Commands/Create_type/Create_type_range.pegjs +0 -0
  125. package/lib/parse/postgresql/Commands/Ignore_syntax.pegjs +0 -0
  126. package/lib/parse/postgresql/Expression.pegjs +0 -0
  127. package/lib/parse/postgresql/InitializerUtils.pegjs +0 -0
  128. package/lib/parse/postgresql/Keywords.pegjs +0 -0
  129. package/lib/parse/postgresql/get_parser.js +0 -0
  130. package/lib/parse/postgresql/parser.pegjs +0 -0
  131. package/lib/parse/schemarb/parser.pegjs +0 -0
  132. package/lib/parse/schemarbParser.js +0 -0
  133. package/lib/utils/version.js +0 -0
  134. package/package.json +10 -3
  135. package/types/export/ModelExporter.d.ts +0 -0
  136. package/types/export/index.d.ts +0 -0
  137. package/types/import/index.d.ts +2 -0
  138. package/types/index.d.ts +0 -0
  139. package/types/model_structure/database.d.ts +0 -0
  140. package/types/model_structure/dbState.d.ts +0 -0
  141. package/types/model_structure/element.d.ts +0 -0
  142. package/types/model_structure/endpoint.d.ts +0 -0
  143. package/types/model_structure/enum.d.ts +0 -0
  144. package/types/model_structure/enumValue.d.ts +0 -0
  145. package/types/model_structure/field.d.ts +0 -0
  146. package/types/model_structure/indexColumn.d.ts +0 -0
  147. package/types/model_structure/indexes.d.ts +0 -0
  148. package/types/model_structure/ref.d.ts +0 -0
  149. package/types/model_structure/schema.d.ts +0 -0
  150. package/types/model_structure/stickyNote.d.ts +0 -0
  151. package/types/model_structure/table.d.ts +0 -0
  152. package/types/model_structure/tableGroup.d.ts +0 -0
  153. package/types/parse/Parser.d.ts +0 -0
  154. package/types/parse/error.d.ts +0 -0
  155. package/lib/parse/DatabaseConnector.js +0 -87
  156. package/lib/parse/connection/ConnectionASTGeneration.js +0 -21
  157. package/lib/parse/connection/postgres/PostgresConnectionASTGen.js +0 -63
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -10,6 +10,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
10
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
11
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
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 camelcase */
13
14
  /* eslint-disable max-classes-per-file */
14
15
  var Index = /*#__PURE__*/function () {
15
16
  /**
File without changes
File without changes
File without changes
File without changes
@@ -711,7 +711,7 @@ var SnowflakeASTGen = /*#__PURE__*/function (_SnowflakeParserVisit) {
711
711
  key: "visitLiteral",
712
712
  value: function visitLiteral(ctx) {
713
713
  if (ctx.STRING()) return {
714
- value: (0, _helpers.getOriginalText)(ctx),
714
+ value: sanitizeComment(ctx),
715
715
  type: 'string'
716
716
  };
717
717
  if (ctx.DECIMAL() || ctx.REAL || ctx.FLOAT) return {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateDatabase = void 0;
7
+ var _database = _interopRequireDefault(require("../model_structure/database"));
8
+ var _AST = require("./ANTLR/ASTGeneration/AST");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ var parseJSONToDatabase = function parseJSONToDatabase(rawDatabase) {
11
+ return new _database["default"](rawDatabase);
12
+ };
13
+ var createRefs = function createRefs(rawRefs) {
14
+ return rawRefs.map(function (rawRef) {
15
+ var name = rawRef.name,
16
+ endpoints = rawRef.endpoints,
17
+ onDelete = rawRef.onDelete,
18
+ onUpdate = rawRef.onUpdate;
19
+ var eps = endpoints.map(function (ep) {
20
+ return new _AST.Endpoint(ep);
21
+ });
22
+ return new _AST.Ref({
23
+ name: name,
24
+ endpoints: eps,
25
+ onDelete: onDelete,
26
+ onUpdate: onUpdate
27
+ }).toJSON();
28
+ });
29
+ };
30
+ var createEnums = function createEnums(rawEnums) {
31
+ return rawEnums.map(function (rawEnum) {
32
+ var name = rawEnum.name,
33
+ schemaName = rawEnum.schemaName,
34
+ values = rawEnum.values;
35
+ return new _AST.Enum({
36
+ name: name,
37
+ schemaName: schemaName,
38
+ values: values
39
+ });
40
+ });
41
+ };
42
+ var createFields = function createFields(rawFields, fieldsConstraints) {
43
+ return rawFields.map(function (field) {
44
+ var constraints = fieldsConstraints[field.name] || {};
45
+ var f = new _AST.Field({
46
+ name: field.name,
47
+ type: field.type,
48
+ dbdefault: field.dbdefault,
49
+ not_null: field.not_null,
50
+ increment: field.increment,
51
+ pk: constraints.pk,
52
+ unique: constraints.unique,
53
+ note: field.note
54
+ });
55
+ return f;
56
+ });
57
+ };
58
+ var createIndexes = function createIndexes(rawIndexes) {
59
+ return rawIndexes.map(function (rawIndex) {
60
+ var name = rawIndex.name,
61
+ unique = rawIndex.unique,
62
+ primary = rawIndex.primary,
63
+ type = rawIndex.type,
64
+ columns = rawIndex.columns;
65
+ var index = new _AST.Index({
66
+ name: name,
67
+ unique: unique,
68
+ pk: primary,
69
+ type: type,
70
+ columns: columns
71
+ });
72
+ return index;
73
+ });
74
+ };
75
+ var createTables = function createTables(rawTables, rawFields, rawIndexes, tableConstraints) {
76
+ return rawTables.map(function (rawTable) {
77
+ var name = rawTable.name,
78
+ schemaName = rawTable.schemaName,
79
+ note = rawTable.note;
80
+ var key = schemaName ? "".concat(schemaName, ".").concat(name) : "".concat(name);
81
+ var constraints = tableConstraints[key] || {};
82
+ var fields = createFields(rawFields[key], constraints);
83
+ var indexes = createIndexes(rawIndexes[key] || []);
84
+ return new _AST.Table({
85
+ name: name,
86
+ schemaName: schemaName,
87
+ fields: fields,
88
+ indexes: indexes,
89
+ note: note
90
+ });
91
+ });
92
+ };
93
+ var generateDatabase = function generateDatabase(schemaJson) {
94
+ var rawTables = schemaJson.tables,
95
+ rawFields = schemaJson.fields,
96
+ rawIndexes = schemaJson.indexes,
97
+ rawRefs = schemaJson.refs,
98
+ rawEnums = schemaJson.enums,
99
+ tableConstraints = schemaJson.tableConstraints;
100
+ try {
101
+ var tables = createTables(rawTables, rawFields, rawIndexes, tableConstraints);
102
+ var enums = createEnums(rawEnums);
103
+ var refs = createRefs(rawRefs);
104
+ var rawDatabase = {
105
+ schemas: [],
106
+ tables: tables,
107
+ refs: refs,
108
+ enums: enums,
109
+ tableGroups: [],
110
+ aliases: [],
111
+ project: {}
112
+ };
113
+ return parseJSONToDatabase(rawDatabase);
114
+ } catch (err) {
115
+ throw new Error(err);
116
+ }
117
+ };
118
+ exports.generateDatabase = generateDatabase;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/core",
3
- "version": "3.6.2",
3
+ "version": "3.7.1",
4
4
  "description": "> TODO: description",
5
5
  "author": "Holistics <dev@holistics.io>",
6
6
  "license": "Apache-2.0",
@@ -32,10 +32,14 @@
32
32
  "prepublish": "npm run build"
33
33
  },
34
34
  "dependencies": {
35
- "@dbml/parse": "^3.6.2",
35
+ "@dbml/parse": "^3.7.1",
36
+ "@tediousjs/connection-string": "^0.5.0",
36
37
  "antlr4": "^4.13.1",
37
38
  "lodash": "^4.17.15",
39
+ "mssql": "^11.0.1",
40
+ "mysql2": "^3.11.0",
38
41
  "parsimmon": "^1.13.0",
42
+ "pg": "^8.12.0",
39
43
  "pluralize": "^8.0.0"
40
44
  },
41
45
  "devDependencies": {
@@ -59,5 +63,8 @@
59
63
  "\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
60
64
  }
61
65
  },
62
- "gitHead": "d3d82a3e8260f733098edc5fbfdbd3f8a381c6e3"
66
+ "gitHead": "71d7e2cd00ba5d60d2e36c465d43ce1d91189274",
67
+ "engines": {
68
+ "node": ">=18"
69
+ }
63
70
  }
File without changes
File without changes
@@ -1,5 +1,7 @@
1
1
  declare function _import(str: string, format: 'dbml' | 'mysql' | 'postgres' | 'json' | 'mssql' | 'postgresLegacy'): string;
2
+ declare async function generateDbml(connection: any, format: 'mysql' | 'postgres' | 'mssql'): string;
2
3
  declare const _default: {
3
4
  import: typeof _import;
5
+ generateDbml: typeof generateDbml;
4
6
  };
5
7
  export default _default;
package/types/index.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,87 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _database = _interopRequireDefault(require("../model_structure/database"));
8
- var _ConnectionASTGeneration = require("./connection/ConnectionASTGeneration");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- 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); }
11
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
14
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
- 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); } }
16
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
- 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); }
19
- var DatabaseConnector = /*#__PURE__*/function () {
20
- function DatabaseConnector(connection) {
21
- _classCallCheck(this, DatabaseConnector);
22
- this.connection = connection;
23
- }
24
- _createClass(DatabaseConnector, [{
25
- key: "fetch",
26
- value: function () {
27
- var _fetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(format) {
28
- var rawDatabase, schema;
29
- return _regeneratorRuntime().wrap(function _callee$(_context) {
30
- while (1) switch (_context.prev = _context.next) {
31
- case 0:
32
- rawDatabase = {};
33
- _context.t0 = format;
34
- _context.next = _context.t0 === 'postgres' ? 4 : 8;
35
- break;
36
- case 4:
37
- _context.next = 6;
38
- return DatabaseConnector.fetchPostgresToJSON(this.connection);
39
- case 6:
40
- rawDatabase = _context.sent;
41
- return _context.abrupt("break", 9);
42
- case 8:
43
- return _context.abrupt("break", 9);
44
- case 9:
45
- schema = DatabaseConnector.parseJSONToDatabase(rawDatabase);
46
- return _context.abrupt("return", schema);
47
- case 11:
48
- case "end":
49
- return _context.stop();
50
- }
51
- }, _callee, this);
52
- }));
53
- function fetch(_x) {
54
- return _fetch.apply(this, arguments);
55
- }
56
- return fetch;
57
- }()
58
- }], [{
59
- key: "parseJSONToDatabase",
60
- value: function parseJSONToDatabase(rawDatabase) {
61
- var database = new _database["default"](rawDatabase);
62
- return database;
63
- }
64
- }, {
65
- key: "fetchPostgresToJSON",
66
- value: function () {
67
- var _fetchPostgresToJSON = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(connection) {
68
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
69
- while (1) switch (_context2.prev = _context2.next) {
70
- case 0:
71
- return _context2.abrupt("return", (0, _ConnectionASTGeneration.fetch)(connection, 'postgres'));
72
- case 1:
73
- case "end":
74
- return _context2.stop();
75
- }
76
- }, _callee2);
77
- }));
78
- function fetchPostgresToJSON(_x2) {
79
- return _fetchPostgresToJSON.apply(this, arguments);
80
- }
81
- return fetchPostgresToJSON;
82
- }()
83
- }]);
84
- return DatabaseConnector;
85
- }();
86
- var _default = DatabaseConnector;
87
- exports["default"] = _default;