@niledatabase/server 2.3.0-alpha.2 → 2.3.0-alpha.4
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 +44 -36
- 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 +45 -37
- package/dist/server.esm.js.map +1 -1
- package/dist/utils/Config/index.d.ts +1 -1
- package/package.json +2 -2
|
@@ -619,6 +619,8 @@ var logProtector = function logProtector(logger) {
|
|
|
619
619
|
return logger ;
|
|
620
620
|
};
|
|
621
621
|
|
|
622
|
+
var _excluded$1 = ["host", "port"],
|
|
623
|
+
_excluded2 = ["host", "port"];
|
|
622
624
|
var ApiConfig = /*#__PURE__*/function () {
|
|
623
625
|
function ApiConfig(_ref) {
|
|
624
626
|
var basePath = _ref.basePath,
|
|
@@ -644,6 +646,7 @@ var ApiConfig = /*#__PURE__*/function () {
|
|
|
644
646
|
var Config = /*#__PURE__*/function () {
|
|
645
647
|
function Config(_config) {
|
|
646
648
|
var _this = this,
|
|
649
|
+
_config$db2,
|
|
647
650
|
_config$api$cookieKey2,
|
|
648
651
|
_config$api2;
|
|
649
652
|
this.user = void 0;
|
|
@@ -657,25 +660,26 @@ var Config = /*#__PURE__*/function () {
|
|
|
657
660
|
this._userId = void 0;
|
|
658
661
|
this.configure = /*#__PURE__*/function () {
|
|
659
662
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
|
|
660
|
-
var _config$api$cookieKey, _config$api;
|
|
661
|
-
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;
|
|
662
665
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
663
666
|
while (1) switch (_context.prev = _context.next) {
|
|
664
667
|
case 0:
|
|
668
|
+
_Logger = Logger(config, '[init]'), info = _Logger.info, error = _Logger.error;
|
|
665
669
|
envVarConfig = {
|
|
666
670
|
config: config
|
|
667
671
|
};
|
|
668
|
-
host =
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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;
|
|
672
677
|
break;
|
|
673
678
|
}
|
|
674
679
|
info('Alreaady configured, aborting fetch');
|
|
675
680
|
return _context.abrupt("return", _this);
|
|
676
|
-
case
|
|
681
|
+
case 8:
|
|
677
682
|
basePath = getBasePath(envVarConfig);
|
|
678
|
-
port = getDbPort(envVarConfig);
|
|
679
683
|
databaseName = getDatabaseName({
|
|
680
684
|
config: config,
|
|
681
685
|
logger: 'getInfo'
|
|
@@ -685,7 +689,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
685
689
|
url.searchParams.set('databaseName', databaseName);
|
|
686
690
|
}
|
|
687
691
|
info(url.href);
|
|
688
|
-
_context.next =
|
|
692
|
+
_context.next = 15;
|
|
689
693
|
return fetch(url, {
|
|
690
694
|
headers: {
|
|
691
695
|
Authorization: "Bearer " + getInfoBearer({
|
|
@@ -693,13 +697,13 @@ var Config = /*#__PURE__*/function () {
|
|
|
693
697
|
})
|
|
694
698
|
}
|
|
695
699
|
});
|
|
696
|
-
case
|
|
700
|
+
case 15:
|
|
697
701
|
res = _context.sent;
|
|
698
702
|
possibleError = res.clone();
|
|
699
|
-
_context.prev =
|
|
700
|
-
_context.next =
|
|
703
|
+
_context.prev = 17;
|
|
704
|
+
_context.next = 20;
|
|
701
705
|
return res.json();
|
|
702
|
-
case
|
|
706
|
+
case 20:
|
|
703
707
|
json = _context.sent;
|
|
704
708
|
if (res.status === 404) {
|
|
705
709
|
info('is the configured databaseName correct?');
|
|
@@ -711,44 +715,44 @@ var Config = /*#__PURE__*/function () {
|
|
|
711
715
|
} else {
|
|
712
716
|
database = json;
|
|
713
717
|
}
|
|
714
|
-
_context.next =
|
|
718
|
+
_context.next = 32;
|
|
715
719
|
break;
|
|
716
|
-
case
|
|
717
|
-
_context.prev =
|
|
718
|
-
_context.t0 = _context["catch"](
|
|
719
|
-
_context.next =
|
|
720
|
+
case 25:
|
|
721
|
+
_context.prev = 25;
|
|
722
|
+
_context.t0 = _context["catch"](17);
|
|
723
|
+
_context.next = 29;
|
|
720
724
|
return possibleError.text();
|
|
721
|
-
case
|
|
725
|
+
case 29:
|
|
722
726
|
message = _context.sent;
|
|
723
727
|
error(message);
|
|
724
728
|
database = {
|
|
725
729
|
message: message
|
|
726
730
|
};
|
|
727
|
-
case
|
|
731
|
+
case 32:
|
|
728
732
|
info('[fetched database]', database);
|
|
729
733
|
if (!('message' in database)) {
|
|
730
|
-
_context.next =
|
|
734
|
+
_context.next = 41;
|
|
731
735
|
break;
|
|
732
736
|
}
|
|
733
737
|
if (!('statusCode' in database)) {
|
|
734
|
-
_context.next =
|
|
738
|
+
_context.next = 40;
|
|
735
739
|
break;
|
|
736
740
|
}
|
|
737
741
|
error(database);
|
|
738
742
|
throw new Error('HTTP error has occured');
|
|
739
|
-
case 39:
|
|
740
|
-
throw new Error('Unable to auto-configure. Please set or remove NILEDB_API, NILEDB_NAME, and NILEDB_HOST in your .env file.');
|
|
741
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:
|
|
742
746
|
if (typeof database === 'object') {
|
|
743
747
|
_database = database, apiHost = _database.apiHost, dbHost = _database.dbHost, name = _database.name, id = _database.id;
|
|
744
748
|
_this.databaseId = id;
|
|
745
749
|
_this.databaseName = name;
|
|
746
750
|
dburl = new URL(dbHost);
|
|
747
751
|
apiurl = new URL(apiHost);
|
|
748
|
-
|
|
752
|
+
configuredHost = dburl.host;
|
|
749
753
|
basePath = apiurl.origin;
|
|
750
754
|
}
|
|
751
|
-
case
|
|
755
|
+
case 42:
|
|
752
756
|
_this.api = new ApiConfig({
|
|
753
757
|
basePath: basePath,
|
|
754
758
|
cookieKey: (_config$api$cookieKey = config == null || (_config$api = config.api) == null ? void 0 : _config$api.cookieKey) != null ? _config$api$cookieKey : 'token',
|
|
@@ -759,17 +763,17 @@ var Config = /*#__PURE__*/function () {
|
|
|
759
763
|
_this.db = _extends({
|
|
760
764
|
user: _this.user,
|
|
761
765
|
password: _this.password,
|
|
762
|
-
host:
|
|
763
|
-
port:
|
|
766
|
+
host: configuredHost,
|
|
767
|
+
port: configuredPort,
|
|
764
768
|
database: _this.databaseName
|
|
765
|
-
},
|
|
769
|
+
}, dbConfig);
|
|
766
770
|
info('[config set]', _this);
|
|
767
771
|
return _context.abrupt("return", _this);
|
|
768
|
-
case
|
|
772
|
+
case 46:
|
|
769
773
|
case "end":
|
|
770
774
|
return _context.stop();
|
|
771
775
|
}
|
|
772
|
-
}, _callee, null, [[
|
|
776
|
+
}, _callee, null, [[17, 25]]);
|
|
773
777
|
}));
|
|
774
778
|
return function (_x) {
|
|
775
779
|
return _ref2.apply(this, arguments);
|
|
@@ -786,8 +790,12 @@ var Config = /*#__PURE__*/function () {
|
|
|
786
790
|
this.debug = Boolean(_config == null ? void 0 : _config.debug);
|
|
787
791
|
this._userId = _config == null ? void 0 : _config.userId;
|
|
788
792
|
var _basePath = getBasePath(_envVarConfig);
|
|
789
|
-
var
|
|
790
|
-
|
|
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);
|
|
791
799
|
this.api = new ApiConfig({
|
|
792
800
|
basePath: _basePath,
|
|
793
801
|
cookieKey: (_config$api$cookieKey2 = _config == null || (_config$api2 = _config.api) == null ? void 0 : _config$api2.cookieKey) != null ? _config$api$cookieKey2 : 'token',
|
|
@@ -798,9 +806,9 @@ var Config = /*#__PURE__*/function () {
|
|
|
798
806
|
this.db = _extends({
|
|
799
807
|
user: this.user,
|
|
800
808
|
password: this.password,
|
|
801
|
-
host:
|
|
802
|
-
port:
|
|
803
|
-
},
|
|
809
|
+
host: _configuredHost,
|
|
810
|
+
port: _configuredPort
|
|
811
|
+
}, _dbConfig);
|
|
804
812
|
if (this.databaseName) {
|
|
805
813
|
this.db.database = this.databaseName;
|
|
806
814
|
}
|