@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.
@@ -1,6 +1,4 @@
1
1
  import 'dotenv/config';
2
- import isEmpty from 'lodash-es/isEmpty';
3
- import isObject from 'lodash-es/isObject';
4
2
  import { decodeJwt } from 'jose';
5
3
  import { Pool } from 'pg';
6
4
 
@@ -617,6 +615,8 @@ var logProtector = function logProtector(logger) {
617
615
  return process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ? logger : null;
618
616
  };
619
617
 
618
+ var _excluded$1 = ["host", "port"],
619
+ _excluded2 = ["host", "port"];
620
620
  var ApiConfig = /*#__PURE__*/function () {
621
621
  function ApiConfig(_ref) {
622
622
  var basePath = _ref.basePath,
@@ -642,6 +642,7 @@ var ApiConfig = /*#__PURE__*/function () {
642
642
  var Config = /*#__PURE__*/function () {
643
643
  function Config(_config) {
644
644
  var _this = this,
645
+ _config$db2,
645
646
  _config$api$cookieKey2,
646
647
  _config$api2;
647
648
  this.user = void 0;
@@ -655,25 +656,26 @@ var Config = /*#__PURE__*/function () {
655
656
  this._userId = void 0;
656
657
  this.configure = /*#__PURE__*/function () {
657
658
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
658
- var _config$api$cookieKey, _config$api;
659
- var envVarConfig, host, _Logger, info, error, basePath, port, databaseName, url, res, database, possibleError, json, message, _database, apiHost, dbHost, name, id, dburl, apiurl;
659
+ var _config$db, _config$api$cookieKey, _config$api;
660
+ 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;
660
661
  return _regeneratorRuntime().wrap(function _callee$(_context) {
661
662
  while (1) switch (_context.prev = _context.next) {
662
663
  case 0:
664
+ _Logger = Logger(config, '[init]'), info = _Logger.info, error = _Logger.error;
663
665
  envVarConfig = {
664
666
  config: config
665
667
  };
666
- host = getDbHost(envVarConfig);
667
- _Logger = Logger(config, '[init]'), info = _Logger.info, error = _Logger.error;
668
- if (!(host && _this.databaseName && _this.databaseId)) {
669
- _context.next = 6;
668
+ _ref3 = (_config$db = config.db) != null ? _config$db : {}, host = _ref3.host, port = _ref3.port, dbConfig = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
669
+ configuredHost = host != null ? host : getDbHost(envVarConfig);
670
+ configuredPort = port != null ? port : getDbPort(envVarConfig);
671
+ if (!(configuredHost && _this.databaseName && _this.databaseId)) {
672
+ _context.next = 8;
670
673
  break;
671
674
  }
672
675
  info('Alreaady configured, aborting fetch');
673
676
  return _context.abrupt("return", _this);
674
- case 6:
677
+ case 8:
675
678
  basePath = getBasePath(envVarConfig);
676
- port = getDbPort(envVarConfig);
677
679
  databaseName = getDatabaseName({
678
680
  config: config,
679
681
  logger: 'getInfo'
@@ -683,7 +685,7 @@ var Config = /*#__PURE__*/function () {
683
685
  url.searchParams.set('databaseName', databaseName);
684
686
  }
685
687
  info(url.href);
686
- _context.next = 14;
688
+ _context.next = 15;
687
689
  return fetch(url, {
688
690
  headers: {
689
691
  Authorization: "Bearer " + getInfoBearer({
@@ -691,13 +693,13 @@ var Config = /*#__PURE__*/function () {
691
693
  })
692
694
  }
693
695
  });
694
- case 14:
696
+ case 15:
695
697
  res = _context.sent;
696
698
  possibleError = res.clone();
697
- _context.prev = 16;
698
- _context.next = 19;
699
+ _context.prev = 17;
700
+ _context.next = 20;
699
701
  return res.json();
700
- case 19:
702
+ case 20:
701
703
  json = _context.sent;
702
704
  if (res.status === 404) {
703
705
  info('is the configured databaseName correct?');
@@ -709,48 +711,48 @@ var Config = /*#__PURE__*/function () {
709
711
  } else {
710
712
  database = json;
711
713
  }
712
- _context.next = 31;
714
+ _context.next = 32;
713
715
  break;
714
- case 24:
715
- _context.prev = 24;
716
- _context.t0 = _context["catch"](16);
717
- _context.next = 28;
716
+ case 25:
717
+ _context.prev = 25;
718
+ _context.t0 = _context["catch"](17);
719
+ _context.next = 29;
718
720
  return possibleError.text();
719
- case 28:
721
+ case 29:
720
722
  message = _context.sent;
721
723
  error(message);
722
724
  database = {
723
725
  message: message
724
726
  };
725
- case 31:
727
+ case 32:
726
728
  info('[fetched database]', database);
727
729
  if (!(process.env.NODE_ENV !== 'TEST')) {
728
- _context.next = 41;
730
+ _context.next = 42;
729
731
  break;
730
732
  }
731
733
  if (!('message' in database)) {
732
- _context.next = 40;
734
+ _context.next = 41;
733
735
  break;
734
736
  }
735
737
  if (!('statusCode' in database)) {
736
- _context.next = 39;
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
- host = dburl.host;
752
+ configuredHost = dburl.host;
751
753
  basePath = apiurl.origin;
752
754
  }
753
- case 41:
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: host,
765
- port: port,
766
+ host: configuredHost,
767
+ port: configuredPort,
766
768
  database: _this.databaseName
767
- }, typeof (config == null ? void 0 : config.db) === 'object' ? config.db : {});
769
+ }, dbConfig);
768
770
  info('[config set]', _this);
769
771
  return _context.abrupt("return", _this);
770
- case 45:
772
+ case 46:
771
773
  case "end":
772
774
  return _context.stop();
773
775
  }
774
- }, _callee, null, [[16, 24]]);
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 _host = getDbHost(_envVarConfig);
792
- var _port = getDbPort(_envVarConfig);
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: _host,
804
- port: _port
805
- }, typeof (_config == null ? void 0 : _config.db) === 'object' ? _config.db : {});
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 || isEmpty(req) || isObject(req) && Object.values(req).length === 0) {
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,7 +2176,5 @@ function _create() {
2170
2176
  return _create.apply(this, arguments);
2171
2177
  }
2172
2178
 
2173
- module.exports = create;
2174
-
2175
2179
  export { Server, create as default };
2176
2180
  //# sourceMappingURL=server.esm.js.map