@niledatabase/server 2.3.0 → 2.3.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.cjs.development.js +45 -41
- package/dist/server.cjs.development.js.map +1 -1
- package/dist/server.cjs.production.min.js +1 -1
- package/dist/server.cjs.production.min.js.map +1 -1
- package/dist/server.esm.js +46 -42
- package/dist/server.esm.js.map +1 -1
- package/dist/utils/Config/index.d.ts +1 -1
- package/package.json +3 -3
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('dotenv/config');
|
|
6
|
-
var isEmpty = require('lodash/isEmpty');
|
|
7
|
-
var isObject = require('lodash/isObject');
|
|
8
6
|
var jose = require('jose');
|
|
9
7
|
var pg = require('pg');
|
|
10
8
|
|
|
@@ -621,6 +619,8 @@ var logProtector = function logProtector(logger) {
|
|
|
621
619
|
return logger ;
|
|
622
620
|
};
|
|
623
621
|
|
|
622
|
+
var _excluded$1 = ["host", "port"],
|
|
623
|
+
_excluded2 = ["host", "port"];
|
|
624
624
|
var ApiConfig = /*#__PURE__*/function () {
|
|
625
625
|
function ApiConfig(_ref) {
|
|
626
626
|
var basePath = _ref.basePath,
|
|
@@ -646,6 +646,7 @@ var ApiConfig = /*#__PURE__*/function () {
|
|
|
646
646
|
var Config = /*#__PURE__*/function () {
|
|
647
647
|
function Config(_config) {
|
|
648
648
|
var _this = this,
|
|
649
|
+
_config$db2,
|
|
649
650
|
_config$api$cookieKey2,
|
|
650
651
|
_config$api2;
|
|
651
652
|
this.user = void 0;
|
|
@@ -659,25 +660,26 @@ var Config = /*#__PURE__*/function () {
|
|
|
659
660
|
this._userId = void 0;
|
|
660
661
|
this.configure = /*#__PURE__*/function () {
|
|
661
662
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
|
|
662
|
-
var _config$api$cookieKey, _config$api;
|
|
663
|
-
var envVarConfig, host,
|
|
663
|
+
var _config$db, _config$api$cookieKey, _config$api;
|
|
664
|
+
var _Logger, info, error, envVarConfig, _ref3, host, port, dbConfig, configuredHost, configuredPort, basePath, databaseName, url, res, database, possibleError, json, message, _database, apiHost, dbHost, name, id, dburl, apiurl;
|
|
664
665
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
665
666
|
while (1) switch (_context.prev = _context.next) {
|
|
666
667
|
case 0:
|
|
668
|
+
_Logger = Logger(config, '[init]'), info = _Logger.info, error = _Logger.error;
|
|
667
669
|
envVarConfig = {
|
|
668
670
|
config: config
|
|
669
671
|
};
|
|
670
|
-
host =
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
672
|
+
_ref3 = (_config$db = config.db) != null ? _config$db : {}, host = _ref3.host, port = _ref3.port, dbConfig = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
|
|
673
|
+
configuredHost = host != null ? host : getDbHost(envVarConfig);
|
|
674
|
+
configuredPort = port != null ? port : getDbPort(envVarConfig);
|
|
675
|
+
if (!(configuredHost && _this.databaseName && _this.databaseId)) {
|
|
676
|
+
_context.next = 8;
|
|
674
677
|
break;
|
|
675
678
|
}
|
|
676
679
|
info('Alreaady configured, aborting fetch');
|
|
677
680
|
return _context.abrupt("return", _this);
|
|
678
|
-
case
|
|
681
|
+
case 8:
|
|
679
682
|
basePath = getBasePath(envVarConfig);
|
|
680
|
-
port = getDbPort(envVarConfig);
|
|
681
683
|
databaseName = getDatabaseName({
|
|
682
684
|
config: config,
|
|
683
685
|
logger: 'getInfo'
|
|
@@ -687,7 +689,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
687
689
|
url.searchParams.set('databaseName', databaseName);
|
|
688
690
|
}
|
|
689
691
|
info(url.href);
|
|
690
|
-
_context.next =
|
|
692
|
+
_context.next = 15;
|
|
691
693
|
return fetch(url, {
|
|
692
694
|
headers: {
|
|
693
695
|
Authorization: "Bearer " + getInfoBearer({
|
|
@@ -695,13 +697,13 @@ var Config = /*#__PURE__*/function () {
|
|
|
695
697
|
})
|
|
696
698
|
}
|
|
697
699
|
});
|
|
698
|
-
case
|
|
700
|
+
case 15:
|
|
699
701
|
res = _context.sent;
|
|
700
702
|
possibleError = res.clone();
|
|
701
|
-
_context.prev =
|
|
702
|
-
_context.next =
|
|
703
|
+
_context.prev = 17;
|
|
704
|
+
_context.next = 20;
|
|
703
705
|
return res.json();
|
|
704
|
-
case
|
|
706
|
+
case 20:
|
|
705
707
|
json = _context.sent;
|
|
706
708
|
if (res.status === 404) {
|
|
707
709
|
info('is the configured databaseName correct?');
|
|
@@ -713,44 +715,44 @@ var Config = /*#__PURE__*/function () {
|
|
|
713
715
|
} else {
|
|
714
716
|
database = json;
|
|
715
717
|
}
|
|
716
|
-
_context.next =
|
|
718
|
+
_context.next = 32;
|
|
717
719
|
break;
|
|
718
|
-
case
|
|
719
|
-
_context.prev =
|
|
720
|
-
_context.t0 = _context["catch"](
|
|
721
|
-
_context.next =
|
|
720
|
+
case 25:
|
|
721
|
+
_context.prev = 25;
|
|
722
|
+
_context.t0 = _context["catch"](17);
|
|
723
|
+
_context.next = 29;
|
|
722
724
|
return possibleError.text();
|
|
723
|
-
case
|
|
725
|
+
case 29:
|
|
724
726
|
message = _context.sent;
|
|
725
727
|
error(message);
|
|
726
728
|
database = {
|
|
727
729
|
message: message
|
|
728
730
|
};
|
|
729
|
-
case
|
|
731
|
+
case 32:
|
|
730
732
|
info('[fetched database]', database);
|
|
731
733
|
if (!('message' in database)) {
|
|
732
|
-
_context.next =
|
|
734
|
+
_context.next = 41;
|
|
733
735
|
break;
|
|
734
736
|
}
|
|
735
737
|
if (!('statusCode' in database)) {
|
|
736
|
-
_context.next =
|
|
738
|
+
_context.next = 40;
|
|
737
739
|
break;
|
|
738
740
|
}
|
|
739
741
|
error(database);
|
|
740
742
|
throw new Error('HTTP error has occured');
|
|
741
|
-
case 39:
|
|
742
|
-
throw new Error('Unable to auto-configure. Please set or remove NILEDB_API, NILEDB_NAME, and NILEDB_HOST in your .env file.');
|
|
743
743
|
case 40:
|
|
744
|
+
throw new Error('Unable to auto-configure. Please set or remove NILEDB_API, NILEDB_NAME, and NILEDB_HOST in your .env file.');
|
|
745
|
+
case 41:
|
|
744
746
|
if (typeof database === 'object') {
|
|
745
747
|
_database = database, apiHost = _database.apiHost, dbHost = _database.dbHost, name = _database.name, id = _database.id;
|
|
746
748
|
_this.databaseId = id;
|
|
747
749
|
_this.databaseName = name;
|
|
748
750
|
dburl = new URL(dbHost);
|
|
749
751
|
apiurl = new URL(apiHost);
|
|
750
|
-
|
|
752
|
+
configuredHost = dburl.host;
|
|
751
753
|
basePath = apiurl.origin;
|
|
752
754
|
}
|
|
753
|
-
case
|
|
755
|
+
case 42:
|
|
754
756
|
_this.api = new ApiConfig({
|
|
755
757
|
basePath: basePath,
|
|
756
758
|
cookieKey: (_config$api$cookieKey = config == null || (_config$api = config.api) == null ? void 0 : _config$api.cookieKey) != null ? _config$api$cookieKey : 'token',
|
|
@@ -761,17 +763,17 @@ var Config = /*#__PURE__*/function () {
|
|
|
761
763
|
_this.db = _extends({
|
|
762
764
|
user: _this.user,
|
|
763
765
|
password: _this.password,
|
|
764
|
-
host:
|
|
765
|
-
port:
|
|
766
|
+
host: configuredHost,
|
|
767
|
+
port: configuredPort,
|
|
766
768
|
database: _this.databaseName
|
|
767
|
-
},
|
|
769
|
+
}, dbConfig);
|
|
768
770
|
info('[config set]', _this);
|
|
769
771
|
return _context.abrupt("return", _this);
|
|
770
|
-
case
|
|
772
|
+
case 46:
|
|
771
773
|
case "end":
|
|
772
774
|
return _context.stop();
|
|
773
775
|
}
|
|
774
|
-
}, _callee, null, [[
|
|
776
|
+
}, _callee, null, [[17, 25]]);
|
|
775
777
|
}));
|
|
776
778
|
return function (_x) {
|
|
777
779
|
return _ref2.apply(this, arguments);
|
|
@@ -788,8 +790,12 @@ var Config = /*#__PURE__*/function () {
|
|
|
788
790
|
this.debug = Boolean(_config == null ? void 0 : _config.debug);
|
|
789
791
|
this._userId = _config == null ? void 0 : _config.userId;
|
|
790
792
|
var _basePath = getBasePath(_envVarConfig);
|
|
791
|
-
var
|
|
792
|
-
|
|
793
|
+
var _ref4 = (_config$db2 = _config == null ? void 0 : _config.db) != null ? _config$db2 : {},
|
|
794
|
+
_host = _ref4.host,
|
|
795
|
+
_port = _ref4.port,
|
|
796
|
+
_dbConfig = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
797
|
+
var _configuredHost = _host != null ? _host : getDbHost(_envVarConfig);
|
|
798
|
+
var _configuredPort = _port != null ? _port : getDbPort(_envVarConfig);
|
|
793
799
|
this.api = new ApiConfig({
|
|
794
800
|
basePath: _basePath,
|
|
795
801
|
cookieKey: (_config$api$cookieKey2 = _config == null || (_config$api2 = _config.api) == null ? void 0 : _config$api2.cookieKey) != null ? _config$api$cookieKey2 : 'token',
|
|
@@ -800,9 +806,9 @@ var Config = /*#__PURE__*/function () {
|
|
|
800
806
|
this.db = _extends({
|
|
801
807
|
user: this.user,
|
|
802
808
|
password: this.password,
|
|
803
|
-
host:
|
|
804
|
-
port:
|
|
805
|
-
},
|
|
809
|
+
host: _configuredHost,
|
|
810
|
+
port: _configuredPort
|
|
811
|
+
}, _dbConfig);
|
|
806
812
|
if (this.databaseName) {
|
|
807
813
|
this.db.database = this.databaseName;
|
|
808
814
|
}
|
|
@@ -1236,7 +1242,7 @@ var Requester = /*#__PURE__*/function (_Config) {
|
|
|
1236
1242
|
case 13:
|
|
1237
1243
|
if (
|
|
1238
1244
|
// is just headers for a GET request
|
|
1239
|
-
req instanceof Headers ||
|
|
1245
|
+
req instanceof Headers || JSON.stringify(req) === '{}' || req && typeof req === 'object' && Object.values(req).length === 0) {
|
|
1240
1246
|
body = undefined;
|
|
1241
1247
|
}
|
|
1242
1248
|
case 14:
|
|
@@ -2170,8 +2176,6 @@ function _create() {
|
|
|
2170
2176
|
return _create.apply(this, arguments);
|
|
2171
2177
|
}
|
|
2172
2178
|
|
|
2173
|
-
module.exports = create;
|
|
2174
|
-
|
|
2175
2179
|
exports.Server = Server;
|
|
2176
2180
|
exports.default = create;
|
|
2177
2181
|
//# sourceMappingURL=server.cjs.development.js.map
|