@dbml/core 3.6.0 → 3.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/connector/index.js +40 -0
- package/lib/model_structure/endpoint.js +2 -2
- package/lib/model_structure/enum.js +2 -2
- package/lib/model_structure/enumValue.js +2 -2
- package/lib/model_structure/field.js +2 -2
- package/lib/model_structure/indexColumn.js +2 -2
- package/lib/model_structure/indexes.js +2 -2
- package/lib/model_structure/ref.js +2 -2
- package/lib/model_structure/schema.js +2 -2
- package/lib/model_structure/stickyNote.js +2 -2
- package/lib/model_structure/table.js +2 -2
- package/lib/model_structure/tableGroup.js +2 -2
- package/lib/parse/DatabaseConnector.js +87 -0
- package/lib/parse/connection/ConnectionASTGeneration.js +21 -0
- package/lib/parse/connection/postgres/PostgresConnectionASTGen.js +63 -0
- package/lib/parse/connection/postgres/utils.js +462 -0
- package/package.json +3 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _DatabaseConnector = _interopRequireDefault(require("../parse/DatabaseConnector"));
|
|
8
|
+
var _ModelExporter = _interopRequireDefault(require("../export/ModelExporter"));
|
|
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 _fetch(_x, _x2) {
|
|
15
|
+
return _fetch2.apply(this, arguments);
|
|
16
|
+
}
|
|
17
|
+
function _fetch2() {
|
|
18
|
+
_fetch2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection, format) {
|
|
19
|
+
var database, dbml;
|
|
20
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
21
|
+
while (1) switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
_context.next = 2;
|
|
24
|
+
return new _DatabaseConnector["default"](connection).fetch(format);
|
|
25
|
+
case 2:
|
|
26
|
+
database = _context.sent;
|
|
27
|
+
dbml = _ModelExporter["default"]["export"](database.normalize(), 'dbml');
|
|
28
|
+
return _context.abrupt("return", dbml);
|
|
29
|
+
case 5:
|
|
30
|
+
case "end":
|
|
31
|
+
return _context.stop();
|
|
32
|
+
}
|
|
33
|
+
}, _callee);
|
|
34
|
+
}));
|
|
35
|
+
return _fetch2.apply(this, arguments);
|
|
36
|
+
}
|
|
37
|
+
var _default = {
|
|
38
|
+
fetch: _fetch
|
|
39
|
+
};
|
|
40
|
+
exports["default"] = _default;
|
|
@@ -147,9 +147,9 @@ var Endpoint = /*#__PURE__*/function (_Element) {
|
|
|
147
147
|
}, {
|
|
148
148
|
key: "normalize",
|
|
149
149
|
value: function normalize(model) {
|
|
150
|
-
model.endpoints
|
|
150
|
+
model.endpoints[this.id] = _objectSpread(_objectSpread({
|
|
151
151
|
id: this.id
|
|
152
|
-
}, this.shallowExport()), this.exportParentIds())
|
|
152
|
+
}, this.shallowExport()), this.exportParentIds());
|
|
153
153
|
}
|
|
154
154
|
}]);
|
|
155
155
|
return Endpoint;
|
|
@@ -143,9 +143,9 @@ var Enum = /*#__PURE__*/function (_Element) {
|
|
|
143
143
|
}, {
|
|
144
144
|
key: "normalize",
|
|
145
145
|
value: function normalize(model) {
|
|
146
|
-
model.enums
|
|
146
|
+
model.enums[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
147
147
|
id: this.id
|
|
148
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
148
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
149
149
|
this.values.forEach(function (v) {
|
|
150
150
|
return v.normalize(model);
|
|
151
151
|
});
|
|
@@ -76,9 +76,9 @@ var EnumValue = /*#__PURE__*/function (_Element) {
|
|
|
76
76
|
}, {
|
|
77
77
|
key: "normalize",
|
|
78
78
|
value: function normalize(model) {
|
|
79
|
-
model.enumValues
|
|
79
|
+
model.enumValues[this.id] = _objectSpread(_objectSpread({
|
|
80
80
|
id: this.id
|
|
81
|
-
}, this.shallowExport()), this.exportParentIds())
|
|
81
|
+
}, this.shallowExport()), this.exportParentIds());
|
|
82
82
|
}
|
|
83
83
|
}]);
|
|
84
84
|
return EnumValue;
|
|
@@ -139,9 +139,9 @@ var Field = /*#__PURE__*/function (_Element) {
|
|
|
139
139
|
}, {
|
|
140
140
|
key: "normalize",
|
|
141
141
|
value: function normalize(model) {
|
|
142
|
-
model.fields
|
|
142
|
+
model.fields[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
143
143
|
id: this.id
|
|
144
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
144
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
145
145
|
}
|
|
146
146
|
}]);
|
|
147
147
|
return Field;
|
|
@@ -69,9 +69,9 @@ var IndexColumn = /*#__PURE__*/function (_Element) {
|
|
|
69
69
|
}, {
|
|
70
70
|
key: "normalize",
|
|
71
71
|
value: function normalize(model) {
|
|
72
|
-
model.indexColumns
|
|
72
|
+
model.indexColumns[this.id] = _objectSpread(_objectSpread({
|
|
73
73
|
id: this.id
|
|
74
|
-
}, this.shallowExport()), this.exportParentIds())
|
|
74
|
+
}, this.shallowExport()), this.exportParentIds());
|
|
75
75
|
}
|
|
76
76
|
}]);
|
|
77
77
|
return IndexColumn;
|
|
@@ -127,9 +127,9 @@ var Index = /*#__PURE__*/function (_Element) {
|
|
|
127
127
|
}, {
|
|
128
128
|
key: "normalize",
|
|
129
129
|
value: function normalize(model) {
|
|
130
|
-
model.indexes
|
|
130
|
+
model.indexes[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
131
131
|
id: this.id
|
|
132
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
132
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
133
133
|
this.columns.forEach(function (c) {
|
|
134
134
|
return c.normalize(model);
|
|
135
135
|
});
|
|
@@ -130,9 +130,9 @@ var Ref = /*#__PURE__*/function (_Element) {
|
|
|
130
130
|
}, {
|
|
131
131
|
key: "normalize",
|
|
132
132
|
value: function normalize(model) {
|
|
133
|
-
model.refs
|
|
133
|
+
model.refs[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
134
134
|
id: this.id
|
|
135
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
135
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
136
136
|
this.endpoints.forEach(function (endpoint) {
|
|
137
137
|
return endpoint.normalize(model);
|
|
138
138
|
});
|
|
@@ -252,9 +252,9 @@ var Schema = /*#__PURE__*/function (_Element) {
|
|
|
252
252
|
}, {
|
|
253
253
|
key: "normalize",
|
|
254
254
|
value: function normalize(model) {
|
|
255
|
-
model.schemas
|
|
255
|
+
model.schemas[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
256
256
|
id: this.id
|
|
257
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
257
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
258
258
|
this.tables.forEach(function (table) {
|
|
259
259
|
return table.normalize(model);
|
|
260
260
|
});
|
|
@@ -61,9 +61,9 @@ var StickyNote = /*#__PURE__*/function (_Element) {
|
|
|
61
61
|
}, {
|
|
62
62
|
key: "normalize",
|
|
63
63
|
value: function normalize(model) {
|
|
64
|
-
model.notes
|
|
64
|
+
model.notes[this.id] = _objectSpread({
|
|
65
65
|
id: this.id
|
|
66
|
-
}, this["export"]())
|
|
66
|
+
}, this["export"]());
|
|
67
67
|
}
|
|
68
68
|
}]);
|
|
69
69
|
return StickyNote;
|
|
@@ -183,9 +183,9 @@ var Table = /*#__PURE__*/function (_Element) {
|
|
|
183
183
|
}, {
|
|
184
184
|
key: "normalize",
|
|
185
185
|
value: function normalize(model) {
|
|
186
|
-
model.tables
|
|
186
|
+
model.tables[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
187
187
|
id: this.id
|
|
188
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
188
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
189
189
|
this.fields.forEach(function (field) {
|
|
190
190
|
return field.normalize(model);
|
|
191
191
|
});
|
|
@@ -123,9 +123,9 @@ var TableGroup = /*#__PURE__*/function (_Element) {
|
|
|
123
123
|
}, {
|
|
124
124
|
key: "normalize",
|
|
125
125
|
value: function normalize(model) {
|
|
126
|
-
model.tableGroups
|
|
126
|
+
model.tableGroups[this.id] = _objectSpread(_objectSpread(_objectSpread({
|
|
127
127
|
id: this.id
|
|
128
|
-
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds())
|
|
128
|
+
}, this.shallowExport()), this.exportChildIds()), this.exportParentIds());
|
|
129
129
|
}
|
|
130
130
|
}]);
|
|
131
131
|
return TableGroup;
|
|
@@ -0,0 +1,87 @@
|
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fetch = fetch;
|
|
7
|
+
var _PostgresConnectionASTGen = _interopRequireDefault(require("./postgres/PostgresConnectionASTGen"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
|
+
function fetch(connection, format) {
|
|
10
|
+
var database = null;
|
|
11
|
+
switch (format) {
|
|
12
|
+
case 'postgres':
|
|
13
|
+
{
|
|
14
|
+
database = new _PostgresConnectionASTGen["default"]().fetch(connection);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
default:
|
|
18
|
+
throw new Error("Format not supported: ".concat(format));
|
|
19
|
+
}
|
|
20
|
+
return database;
|
|
21
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _utils = require("./utils");
|
|
8
|
+
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); }
|
|
9
|
+
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; }
|
|
10
|
+
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); } }
|
|
11
|
+
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); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
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); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
17
|
+
var PostgresConnectionASTGen = /*#__PURE__*/function () {
|
|
18
|
+
function PostgresConnectionASTGen() {
|
|
19
|
+
_classCallCheck(this, PostgresConnectionASTGen);
|
|
20
|
+
this.data = {
|
|
21
|
+
schemas: [],
|
|
22
|
+
tables: [],
|
|
23
|
+
refs: [],
|
|
24
|
+
enums: [],
|
|
25
|
+
tableGroups: [],
|
|
26
|
+
aliases: [],
|
|
27
|
+
project: {}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
_createClass(PostgresConnectionASTGen, [{
|
|
31
|
+
key: "fetch",
|
|
32
|
+
value: function () {
|
|
33
|
+
var _fetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection) {
|
|
34
|
+
var _yield$generateRawDb, tables, refs, enums;
|
|
35
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
36
|
+
while (1) switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
_context.next = 2;
|
|
39
|
+
return (0, _utils.generateRawDb)(connection);
|
|
40
|
+
case 2:
|
|
41
|
+
_yield$generateRawDb = _context.sent;
|
|
42
|
+
tables = _yield$generateRawDb.tables;
|
|
43
|
+
refs = _yield$generateRawDb.refs;
|
|
44
|
+
enums = _yield$generateRawDb.enums;
|
|
45
|
+
this.data.tables = tables;
|
|
46
|
+
this.data.refs = refs;
|
|
47
|
+
this.data.enums = enums;
|
|
48
|
+
return _context.abrupt("return", this.data);
|
|
49
|
+
case 10:
|
|
50
|
+
case "end":
|
|
51
|
+
return _context.stop();
|
|
52
|
+
}
|
|
53
|
+
}, _callee, this);
|
|
54
|
+
}));
|
|
55
|
+
function fetch(_x) {
|
|
56
|
+
return _fetch.apply(this, arguments);
|
|
57
|
+
}
|
|
58
|
+
return fetch;
|
|
59
|
+
}()
|
|
60
|
+
}]);
|
|
61
|
+
return PostgresConnectionASTGen;
|
|
62
|
+
}();
|
|
63
|
+
exports["default"] = PostgresConnectionASTGen;
|
|
@@ -0,0 +1,462 @@
|
|
|
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.generateRawDb = void 0;
|
|
8
|
+
var _pg = require("pg");
|
|
9
|
+
var _AST = require("../../ANTLR/ASTGeneration/AST");
|
|
10
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
14
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
+
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; }
|
|
17
|
+
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); } }
|
|
18
|
+
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); }); }; } /* eslint-disable camelcase */
|
|
19
|
+
var connectPg = /*#__PURE__*/function () {
|
|
20
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection) {
|
|
21
|
+
var client;
|
|
22
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
23
|
+
while (1) switch (_context.prev = _context.next) {
|
|
24
|
+
case 0:
|
|
25
|
+
client = new _pg.Client(connection); // bearer:disable javascript_lang_logger
|
|
26
|
+
client.on('error', function (err) {
|
|
27
|
+
return console.log('PG connection error:', err);
|
|
28
|
+
});
|
|
29
|
+
_context.next = 4;
|
|
30
|
+
return client.connect();
|
|
31
|
+
case 4:
|
|
32
|
+
return _context.abrupt("return", client);
|
|
33
|
+
case 5:
|
|
34
|
+
case "end":
|
|
35
|
+
return _context.stop();
|
|
36
|
+
}
|
|
37
|
+
}, _callee);
|
|
38
|
+
}));
|
|
39
|
+
return function connectPg(_x) {
|
|
40
|
+
return _ref.apply(this, arguments);
|
|
41
|
+
};
|
|
42
|
+
}();
|
|
43
|
+
var convertQueryBoolean = function convertQueryBoolean(val) {
|
|
44
|
+
return val === 'YES';
|
|
45
|
+
};
|
|
46
|
+
var getFieldType = function getFieldType(data_type, udt_name, character_maximum_length, numeric_precision, numeric_scale) {
|
|
47
|
+
if (data_type === 'ARRAY') {
|
|
48
|
+
return "".concat(udt_name.slice(1, udt_name.length), "[]");
|
|
49
|
+
}
|
|
50
|
+
if (character_maximum_length) {
|
|
51
|
+
return "".concat(udt_name, "(").concat(character_maximum_length, ")");
|
|
52
|
+
}
|
|
53
|
+
if (numeric_precision && numeric_scale) {
|
|
54
|
+
return "".concat(udt_name, "(").concat(numeric_precision, ",").concat(numeric_scale, ")");
|
|
55
|
+
}
|
|
56
|
+
return udt_name;
|
|
57
|
+
};
|
|
58
|
+
var getDbdefault = function getDbdefault(data_type, column_default, default_type) {
|
|
59
|
+
if (data_type === 'ARRAY') {
|
|
60
|
+
var values = column_default.slice(6, -1).split(',').map(function (value) {
|
|
61
|
+
return value.split('::')[0];
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
type: default_type,
|
|
65
|
+
value: "ARRAY[".concat(values.join(', '), "]")
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (default_type === 'string') {
|
|
69
|
+
var rawDefaultValues = column_default.split('::')[0];
|
|
70
|
+
var isJson = data_type === 'json' || data_type === 'jsonb';
|
|
71
|
+
var type = isJson ? 'expression' : 'string';
|
|
72
|
+
return {
|
|
73
|
+
type: type,
|
|
74
|
+
value: rawDefaultValues.slice(1, -1)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
type: default_type,
|
|
79
|
+
value: column_default
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var generateRawField = function generateRawField(row) {
|
|
83
|
+
var column_name = row.column_name,
|
|
84
|
+
data_type = row.data_type,
|
|
85
|
+
character_maximum_length = row.character_maximum_length,
|
|
86
|
+
numeric_precision = row.numeric_precision,
|
|
87
|
+
numeric_scale = row.numeric_scale,
|
|
88
|
+
udt_schema = row.udt_schema,
|
|
89
|
+
udt_name = row.udt_name,
|
|
90
|
+
identity_increment = row.identity_increment,
|
|
91
|
+
is_nullable = row.is_nullable,
|
|
92
|
+
column_default = row.column_default,
|
|
93
|
+
default_type = row.default_type,
|
|
94
|
+
column_comment = row.column_comment;
|
|
95
|
+
var dbdefault = column_default && default_type !== 'increment' ? getDbdefault(data_type, column_default, default_type) : null;
|
|
96
|
+
var fieldType = data_type === 'USER-DEFINED' ? {
|
|
97
|
+
type_name: udt_name,
|
|
98
|
+
schemaName: udt_schema
|
|
99
|
+
} : {
|
|
100
|
+
type_name: getFieldType(data_type, udt_name, character_maximum_length, numeric_precision, numeric_scale),
|
|
101
|
+
schemaname: null
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
name: column_name,
|
|
105
|
+
type: fieldType,
|
|
106
|
+
dbdefault: dbdefault,
|
|
107
|
+
not_null: !convertQueryBoolean(is_nullable),
|
|
108
|
+
increment: !!identity_increment || default_type === 'increment',
|
|
109
|
+
note: column_comment ? {
|
|
110
|
+
value: column_comment
|
|
111
|
+
} : {
|
|
112
|
+
value: ''
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
var generateRawTablesAndFields = /*#__PURE__*/function () {
|
|
117
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(client) {
|
|
118
|
+
var rawFields, tablesAndFieldsSql, tablesAndFieldsResult, rawTables;
|
|
119
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
120
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
121
|
+
case 0:
|
|
122
|
+
rawFields = {};
|
|
123
|
+
tablesAndFieldsSql = "\n SELECT\n t.table_schema,\n t.table_name,\n c.column_name,\n c.data_type,\n c.character_maximum_length,\n c.numeric_precision,\n c.numeric_scale,\n c.udt_schema,\n c.udt_name,\n c.identity_increment,\n c.is_nullable,\n c.column_default,\n CASE\n WHEN c.column_default IS NULL THEN NULL\n WHEN c.column_default LIKE 'nextval(%' THEN 'increment'\n WHEN c.column_default LIKE '''%' THEN 'string'\n WHEN c.column_default = 'true' OR c.column_default = 'false' THEN 'boolean'\n WHEN c.column_default ~ '^-?[0-9]+(.[0-9]+)?$' THEN 'number'\n ELSE 'expression'\n END AS default_type,\n -- Fetching table comments\n obj_description(t.table_name::regclass) AS table_comment,\n -- Fetching column comments\n col_description(c.table_name::regclass::oid, c.ordinal_position) AS column_comment\n FROM\n information_schema.columns c\n JOIN\n information_schema.tables t ON c.table_name = t.table_name AND c.table_schema = t.table_schema\n WHERE\n t.table_type = 'BASE TABLE'\n AND t.table_schema NOT IN ('pg_catalog', 'information_schema')\n ORDER BY\n t.table_schema,\n t.table_name,\n c.ordinal_position\n ;\n ";
|
|
124
|
+
_context2.next = 4;
|
|
125
|
+
return client.query(tablesAndFieldsSql);
|
|
126
|
+
case 4:
|
|
127
|
+
tablesAndFieldsResult = _context2.sent;
|
|
128
|
+
rawTables = tablesAndFieldsResult.rows.reduce(function (acc, row) {
|
|
129
|
+
var table_schema = row.table_schema,
|
|
130
|
+
table_name = row.table_name,
|
|
131
|
+
table_comment = row.table_comment;
|
|
132
|
+
if (!acc[table_name]) {
|
|
133
|
+
acc[table_name] = {
|
|
134
|
+
name: table_name,
|
|
135
|
+
schemaName: table_schema,
|
|
136
|
+
note: table_comment ? {
|
|
137
|
+
value: table_comment
|
|
138
|
+
} : {
|
|
139
|
+
value: ''
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (!rawFields[table_name]) rawFields[table_name] = [];
|
|
144
|
+
var field = generateRawField(row);
|
|
145
|
+
rawFields[table_name].push(field);
|
|
146
|
+
return acc;
|
|
147
|
+
}, {});
|
|
148
|
+
return _context2.abrupt("return", {
|
|
149
|
+
rawTables: Object.values(rawTables),
|
|
150
|
+
rawFields: rawFields
|
|
151
|
+
});
|
|
152
|
+
case 7:
|
|
153
|
+
case "end":
|
|
154
|
+
return _context2.stop();
|
|
155
|
+
}
|
|
156
|
+
}, _callee2);
|
|
157
|
+
}));
|
|
158
|
+
return function generateRawTablesAndFields(_x2) {
|
|
159
|
+
return _ref2.apply(this, arguments);
|
|
160
|
+
};
|
|
161
|
+
}();
|
|
162
|
+
var generateRefs = /*#__PURE__*/function () {
|
|
163
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(client) {
|
|
164
|
+
var registeredFK, refs, refsListSql, refsQueryResult;
|
|
165
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
166
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
167
|
+
case 0:
|
|
168
|
+
registeredFK = [];
|
|
169
|
+
refs = [];
|
|
170
|
+
refsListSql = "\n SELECT\n tc.table_schema,\n tc.constraint_name,\n tc.table_name,\n kcu.column_name,\n ccu.table_schema AS foreign_table_schema,\n ccu.table_name AS foreign_table_name,\n ccu.column_name AS foreign_column_name,\n tc.constraint_type,\n rc.delete_rule AS on_delete,\n rc.update_rule AS on_update\n FROM information_schema.table_constraints AS tc\n JOIN information_schema.key_column_usage AS kcu\n ON tc.constraint_name = kcu.constraint_name\n AND tc.table_schema = kcu.table_schema\n JOIN information_schema.constraint_column_usage AS ccu\n ON ccu.constraint_name = tc.constraint_name\n JOIN information_schema.referential_constraints AS rc\n ON tc.constraint_name = rc.constraint_name\n AND tc.table_schema = rc.constraint_schema\n WHERE tc.constraint_type = 'FOREIGN KEY'\n AND tc.table_schema NOT IN ('pg_catalog', 'information_schema');\n ";
|
|
171
|
+
_context3.next = 5;
|
|
172
|
+
return client.query(refsListSql);
|
|
173
|
+
case 5:
|
|
174
|
+
refsQueryResult = _context3.sent;
|
|
175
|
+
refsQueryResult.rows.forEach(function (refRow) {
|
|
176
|
+
var table_schema = refRow.table_schema,
|
|
177
|
+
constraint_name = refRow.constraint_name,
|
|
178
|
+
table_name = refRow.table_name,
|
|
179
|
+
column_name = refRow.column_name,
|
|
180
|
+
foreign_table_schema = refRow.foreign_table_schema,
|
|
181
|
+
foreign_table_name = refRow.foreign_table_name,
|
|
182
|
+
foreign_column_name = refRow.foreign_column_name,
|
|
183
|
+
on_delete = refRow.on_delete,
|
|
184
|
+
on_update = refRow.on_update;
|
|
185
|
+
var ep1 = new _AST.Endpoint({
|
|
186
|
+
tableName: table_name,
|
|
187
|
+
schemaName: table_schema,
|
|
188
|
+
fieldNames: [column_name],
|
|
189
|
+
relation: '*'
|
|
190
|
+
});
|
|
191
|
+
var ep2 = new _AST.Endpoint({
|
|
192
|
+
tableName: foreign_table_name,
|
|
193
|
+
schemaName: foreign_table_schema,
|
|
194
|
+
fieldNames: [foreign_column_name],
|
|
195
|
+
relation: '1'
|
|
196
|
+
});
|
|
197
|
+
var ref = new _AST.Ref({
|
|
198
|
+
name: constraint_name,
|
|
199
|
+
endpoints: [ep1, ep2],
|
|
200
|
+
onDelete: on_delete,
|
|
201
|
+
onUpdate: on_update
|
|
202
|
+
});
|
|
203
|
+
if (!registeredFK.some(function (fk) {
|
|
204
|
+
return fk.table_schema === table_schema && fk.table_name === table_name && fk.column_name === column_name && fk.foreign_table_schema === foreign_table_schema && fk.foreign_table_name === foreign_table_name && fk.foreign_column_name === foreign_column_name;
|
|
205
|
+
})) {
|
|
206
|
+
refs.push(ref.toJSON());
|
|
207
|
+
registeredFK.push({
|
|
208
|
+
table_schema: table_schema,
|
|
209
|
+
table_name: table_name,
|
|
210
|
+
column_name: column_name,
|
|
211
|
+
foreign_table_schema: foreign_table_schema,
|
|
212
|
+
foreign_table_name: foreign_table_name,
|
|
213
|
+
foreign_column_name: foreign_column_name
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
return _context3.abrupt("return", refs);
|
|
218
|
+
case 8:
|
|
219
|
+
case "end":
|
|
220
|
+
return _context3.stop();
|
|
221
|
+
}
|
|
222
|
+
}, _callee3);
|
|
223
|
+
}));
|
|
224
|
+
return function generateRefs(_x3) {
|
|
225
|
+
return _ref3.apply(this, arguments);
|
|
226
|
+
};
|
|
227
|
+
}();
|
|
228
|
+
var generateRawIndexes = /*#__PURE__*/function () {
|
|
229
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(client) {
|
|
230
|
+
var indexListSql, indexListResult, _indexListResult$rows, indexes, constraint, rawIndexes, tableConstraints;
|
|
231
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
232
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
233
|
+
case 0:
|
|
234
|
+
// const tableConstraints = {};
|
|
235
|
+
indexListSql = "\n WITH user_tables AS (\n SELECT tablename\n FROM pg_tables\n WHERE schemaname = 'public'\n AND tablename NOT LIKE 'pg_%'\n AND tablename NOT LIKE 'sql_%'\n ),\n index_info AS (\n SELECT\n t.relname AS table_name,\n i.relname AS index_name,\n ix.indisunique AS is_unique,\n ix.indisprimary AS is_primary,\n am.amname AS index_type,\n array_to_string(array_agg(a.attname ORDER BY x.n), ', ') AS columns,\n pg_get_expr(ix.indexprs, ix.indrelid) AS expressions,\n CASE\n WHEN ix.indisprimary THEN 'PRIMARY KEY'\n WHEN ix.indisunique THEN 'UNIQUE'\n ELSE NULL\n END AS constraint_type\n FROM\n pg_class t\n JOIN pg_index ix ON t.oid = ix.indrelid\n JOIN pg_class i ON i.oid = ix.indexrelid\n LEFT JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)\n JOIN pg_am am ON i.relam = am.oid\n LEFT JOIN generate_subscripts(ix.indkey, 1) AS x(n) ON a.attnum = ix.indkey[x.n]\n WHERE\n t.relkind = 'r'\n AND t.relname NOT LIKE 'pg_%'\n AND t.relname NOT LIKE 'sql_%'\n GROUP BY\n t.relname, i.relname, ix.indisunique, ix.indisprimary, am.amname, ix.indexprs, ix.indrelid\n )\n SELECT\n ut.tablename AS table_name,\n ii.index_name,\n ii.is_unique,\n ii.is_primary,\n ii.index_type,\n ii.columns,\n ii.expressions,\n ii.constraint_type -- Added constraint type\n FROM\n user_tables ut\n LEFT JOIN\n index_info ii ON ut.tablename = ii.table_name\n WHERE ii.columns IS NOT NULL\n ORDER BY\n ut.tablename,\n ii.constraint_type,\n ii.index_name\n ;\n ";
|
|
236
|
+
_context4.next = 3;
|
|
237
|
+
return client.query(indexListSql);
|
|
238
|
+
case 3:
|
|
239
|
+
indexListResult = _context4.sent;
|
|
240
|
+
_indexListResult$rows = indexListResult.rows.reduce(function (acc, row) {
|
|
241
|
+
var constraint_type = row.constraint_type,
|
|
242
|
+
columns = row.columns;
|
|
243
|
+
if (columns === 'null' || columns.trim() === '') return acc;
|
|
244
|
+
if (constraint_type === 'PRIMARY KEY' || constraint_type === 'UNIQUE') {
|
|
245
|
+
acc.constraint.push(row);
|
|
246
|
+
} else {
|
|
247
|
+
acc.indexes.push(row);
|
|
248
|
+
}
|
|
249
|
+
return acc;
|
|
250
|
+
}, {
|
|
251
|
+
indexes: [],
|
|
252
|
+
constraint: []
|
|
253
|
+
}), indexes = _indexListResult$rows.indexes, constraint = _indexListResult$rows.constraint;
|
|
254
|
+
rawIndexes = indexes.reduce(function (acc, indexRow) {
|
|
255
|
+
var table_name = indexRow.table_name,
|
|
256
|
+
index_name = indexRow.index_name,
|
|
257
|
+
index_type = indexRow.index_type,
|
|
258
|
+
columns = indexRow.columns,
|
|
259
|
+
expressions = indexRow.expressions;
|
|
260
|
+
var indexColumns = columns.split(',').map(function (column) {
|
|
261
|
+
return {
|
|
262
|
+
type: 'column',
|
|
263
|
+
value: column.trim()
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
var indexExpressions = expressions ? expressions.split(',').map(function (expression) {
|
|
267
|
+
return {
|
|
268
|
+
type: 'expression',
|
|
269
|
+
value: expression
|
|
270
|
+
};
|
|
271
|
+
}) : [];
|
|
272
|
+
var index = {
|
|
273
|
+
name: index_name,
|
|
274
|
+
type: index_type,
|
|
275
|
+
columns: [].concat(_toConsumableArray(indexColumns), _toConsumableArray(indexExpressions))
|
|
276
|
+
};
|
|
277
|
+
if (acc[table_name]) {
|
|
278
|
+
acc[table_name].push(index);
|
|
279
|
+
} else {
|
|
280
|
+
acc[table_name] = [index];
|
|
281
|
+
}
|
|
282
|
+
return acc;
|
|
283
|
+
}, {});
|
|
284
|
+
tableConstraints = constraint.reduce(function (acc, row) {
|
|
285
|
+
var table_name = row.table_name,
|
|
286
|
+
columns = row.columns,
|
|
287
|
+
constraint_type = row.constraint_type;
|
|
288
|
+
if (!acc[table_name]) acc[table_name] = {};
|
|
289
|
+
var columnNames = columns.split(',').map(function (column) {
|
|
290
|
+
return column.trim();
|
|
291
|
+
});
|
|
292
|
+
columnNames.forEach(function (columnName) {
|
|
293
|
+
if (!acc[table_name][columnName]) acc[table_name][columnName] = {};
|
|
294
|
+
if (constraint_type === 'PRIMARY KEY') {
|
|
295
|
+
acc[table_name][columnName].pk = true;
|
|
296
|
+
}
|
|
297
|
+
if (constraint_type === 'UNIQUE' && !acc[table_name][columnName].pk) {
|
|
298
|
+
acc[table_name][columnName].unique = true;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
return acc;
|
|
302
|
+
}, {});
|
|
303
|
+
return _context4.abrupt("return", {
|
|
304
|
+
rawIndexes: rawIndexes,
|
|
305
|
+
tableConstraints: tableConstraints
|
|
306
|
+
});
|
|
307
|
+
case 8:
|
|
308
|
+
case "end":
|
|
309
|
+
return _context4.stop();
|
|
310
|
+
}
|
|
311
|
+
}, _callee4);
|
|
312
|
+
}));
|
|
313
|
+
return function generateRawIndexes(_x4) {
|
|
314
|
+
return _ref4.apply(this, arguments);
|
|
315
|
+
};
|
|
316
|
+
}();
|
|
317
|
+
var generateRawEnums = /*#__PURE__*/function () {
|
|
318
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(client) {
|
|
319
|
+
var enumListSql, enumListResult, enums;
|
|
320
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
321
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
322
|
+
case 0:
|
|
323
|
+
enumListSql = "\n SELECT\n n.nspname AS schema_name,\n t.typname AS enum_type,\n e.enumlabel AS enum_value,\n e.enumsortorder AS sort_order\n FROM\n pg_enum e\n JOIN\n pg_type t ON e.enumtypid = t.oid\n JOIN\n pg_namespace n ON t.typnamespace = n.oid\n ORDER BY\n schema_name,\n enum_type,\n sort_order;\n ;\n ";
|
|
324
|
+
_context5.next = 3;
|
|
325
|
+
return client.query(enumListSql);
|
|
326
|
+
case 3:
|
|
327
|
+
enumListResult = _context5.sent;
|
|
328
|
+
enums = enumListResult.rows.reduce(function (acc, row) {
|
|
329
|
+
var schema_name = row.schema_name,
|
|
330
|
+
enum_type = row.enum_type,
|
|
331
|
+
enum_value = row.enum_value;
|
|
332
|
+
if (!acc[enum_type]) {
|
|
333
|
+
acc[enum_type] = {
|
|
334
|
+
name: enum_type,
|
|
335
|
+
schemaName: schema_name,
|
|
336
|
+
values: []
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
acc[enum_type].values.push({
|
|
340
|
+
name: enum_value
|
|
341
|
+
});
|
|
342
|
+
return acc;
|
|
343
|
+
}, {});
|
|
344
|
+
return _context5.abrupt("return", Object.values(enums));
|
|
345
|
+
case 6:
|
|
346
|
+
case "end":
|
|
347
|
+
return _context5.stop();
|
|
348
|
+
}
|
|
349
|
+
}, _callee5);
|
|
350
|
+
}));
|
|
351
|
+
return function generateRawEnums(_x5) {
|
|
352
|
+
return _ref5.apply(this, arguments);
|
|
353
|
+
};
|
|
354
|
+
}();
|
|
355
|
+
var createEnums = function createEnums(rawEnums) {
|
|
356
|
+
return rawEnums.map(function (rawEnum) {
|
|
357
|
+
var name = rawEnum.name,
|
|
358
|
+
schemaName = rawEnum.schemaName,
|
|
359
|
+
values = rawEnum.values;
|
|
360
|
+
return new _AST.Enum({
|
|
361
|
+
name: name,
|
|
362
|
+
schemaName: schemaName,
|
|
363
|
+
values: values
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
var createFields = function createFields(rawFields, fieldsConstraints) {
|
|
368
|
+
return rawFields.map(function (field) {
|
|
369
|
+
var constraints = fieldsConstraints[field.name] || {};
|
|
370
|
+
var f = new _AST.Field({
|
|
371
|
+
name: field.name,
|
|
372
|
+
type: field.type,
|
|
373
|
+
dbdefault: field.dbdefault,
|
|
374
|
+
not_null: field.not_null,
|
|
375
|
+
increment: field.increment,
|
|
376
|
+
pk: constraints.pk,
|
|
377
|
+
unique: constraints.unique,
|
|
378
|
+
note: field.note
|
|
379
|
+
});
|
|
380
|
+
return f;
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
var createIndexes = function createIndexes(rawIndexes) {
|
|
384
|
+
return rawIndexes.map(function (rawIndex) {
|
|
385
|
+
var name = rawIndex.name,
|
|
386
|
+
unique = rawIndex.unique,
|
|
387
|
+
primary = rawIndex.primary,
|
|
388
|
+
type = rawIndex.type,
|
|
389
|
+
columns = rawIndex.columns;
|
|
390
|
+
var index = new _AST.Index({
|
|
391
|
+
name: name,
|
|
392
|
+
unique: unique,
|
|
393
|
+
pk: primary,
|
|
394
|
+
type: type,
|
|
395
|
+
columns: columns
|
|
396
|
+
});
|
|
397
|
+
return index;
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
var createTables = function createTables(rawTables, rawFields, rawIndexes, tableConstraints) {
|
|
401
|
+
return rawTables.map(function (rawTable) {
|
|
402
|
+
var name = rawTable.name,
|
|
403
|
+
schemaName = rawTable.schemaName,
|
|
404
|
+
note = rawTable.note;
|
|
405
|
+
var constraints = tableConstraints[name] || {};
|
|
406
|
+
var fields = createFields(rawFields[name], constraints);
|
|
407
|
+
var indexes = createIndexes(rawIndexes[name] || []);
|
|
408
|
+
return new _AST.Table({
|
|
409
|
+
name: name,
|
|
410
|
+
schemaName: schemaName,
|
|
411
|
+
fields: fields,
|
|
412
|
+
indexes: indexes,
|
|
413
|
+
note: note
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
var generateRawDb = /*#__PURE__*/function () {
|
|
418
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(connection) {
|
|
419
|
+
var client, tablesAndFieldsRes, rawIndexesRes, refsRes, rawEnumsRes, res, _res$, rawTables, rawFields, _res$2, rawIndexes, tableConstraints, refs, rawEnums, tables, enums;
|
|
420
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
421
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
422
|
+
case 0:
|
|
423
|
+
_context6.next = 2;
|
|
424
|
+
return connectPg(connection);
|
|
425
|
+
case 2:
|
|
426
|
+
client = _context6.sent;
|
|
427
|
+
tablesAndFieldsRes = generateRawTablesAndFields(client);
|
|
428
|
+
rawIndexesRes = generateRawIndexes(client);
|
|
429
|
+
refsRes = generateRefs(client);
|
|
430
|
+
rawEnumsRes = generateRawEnums(client);
|
|
431
|
+
_context6.next = 9;
|
|
432
|
+
return Promise.all([tablesAndFieldsRes, rawIndexesRes, refsRes, rawEnumsRes]);
|
|
433
|
+
case 9:
|
|
434
|
+
res = _context6.sent;
|
|
435
|
+
client.end();
|
|
436
|
+
_res$ = res[0], rawTables = _res$.rawTables, rawFields = _res$.rawFields;
|
|
437
|
+
_res$2 = res[1], rawIndexes = _res$2.rawIndexes, tableConstraints = _res$2.tableConstraints;
|
|
438
|
+
refs = res[2];
|
|
439
|
+
rawEnums = res[3];
|
|
440
|
+
_context6.prev = 15;
|
|
441
|
+
tables = createTables(rawTables, rawFields, rawIndexes, tableConstraints);
|
|
442
|
+
enums = createEnums(rawEnums);
|
|
443
|
+
return _context6.abrupt("return", {
|
|
444
|
+
tables: tables,
|
|
445
|
+
refs: refs,
|
|
446
|
+
enums: enums
|
|
447
|
+
});
|
|
448
|
+
case 21:
|
|
449
|
+
_context6.prev = 21;
|
|
450
|
+
_context6.t0 = _context6["catch"](15);
|
|
451
|
+
throw new Error(_context6.t0);
|
|
452
|
+
case 24:
|
|
453
|
+
case "end":
|
|
454
|
+
return _context6.stop();
|
|
455
|
+
}
|
|
456
|
+
}, _callee6, null, [[15, 21]]);
|
|
457
|
+
}));
|
|
458
|
+
return function generateRawDb(_x6) {
|
|
459
|
+
return _ref6.apply(this, arguments);
|
|
460
|
+
};
|
|
461
|
+
}();
|
|
462
|
+
exports.generateRawDb = generateRawDb;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/core",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "Holistics <dev@holistics.io>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepublish": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@dbml/parse": "^3.6.
|
|
35
|
+
"@dbml/parse": "^3.6.2",
|
|
36
36
|
"antlr4": "^4.13.1",
|
|
37
37
|
"lodash": "^4.17.15",
|
|
38
38
|
"parsimmon": "^1.13.0",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"\\.(?!json$)[^.]*$": "@glen/jest-raw-loader"
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "d3d82a3e8260f733098edc5fbfdbd3f8a381c6e3"
|
|
63
63
|
}
|