@niledatabase/server 3.0.0-alpha.24 → 3.0.0-alpha.26
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/Api.d.ts +1 -0
- package/dist/server.cjs.development.js +36 -14
- 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 +36 -14
- package/dist/server.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/Api.d.ts
CHANGED
|
@@ -605,8 +605,8 @@ function getDbHost(cfg) {
|
|
|
605
605
|
}
|
|
606
606
|
if (process.env.NILEDB_POSTGRES_URL) {
|
|
607
607
|
var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
|
|
608
|
-
logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.
|
|
609
|
-
return pgUrl.
|
|
608
|
+
logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.hostname);
|
|
609
|
+
return pgUrl.hostname;
|
|
610
610
|
}
|
|
611
611
|
if (process.env.NILEDB_HOST) {
|
|
612
612
|
logger && info(logger + "[NILEDB_HOST] " + process.env.NILEDB_HOST);
|
|
@@ -799,7 +799,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
799
799
|
_this.databaseId = id;
|
|
800
800
|
_this.databaseName = name;
|
|
801
801
|
dburl = new URL(dbHost);
|
|
802
|
-
configuredHost = dburl.
|
|
802
|
+
configuredHost = dburl.hostname;
|
|
803
803
|
}
|
|
804
804
|
case 49:
|
|
805
805
|
_this.api = new ApiConfig({
|
|
@@ -1020,7 +1020,7 @@ var NileDatabase = /*#__PURE__*/function () {
|
|
|
1020
1020
|
remaining = _objectWithoutPropertiesLoose(poolConfig, _excluded$1);
|
|
1021
1021
|
config.db = poolConfig;
|
|
1022
1022
|
this.config = config;
|
|
1023
|
-
debug(JSON.stringify(this.config.db));
|
|
1023
|
+
debug("Connection pool config " + JSON.stringify(this.config.db));
|
|
1024
1024
|
this.pool = createProxyForPool(new pg.Pool(remaining), this.config);
|
|
1025
1025
|
if (typeof afterCreate === 'function') {
|
|
1026
1026
|
warn('Providing an pool configuration will stop automatic tenant context setting.');
|
|
@@ -1033,7 +1033,7 @@ var NileDatabase = /*#__PURE__*/function () {
|
|
|
1033
1033
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1034
1034
|
while (1) switch (_context.prev = _context.next) {
|
|
1035
1035
|
case 0:
|
|
1036
|
-
debug(
|
|
1036
|
+
debug("pool connected " + _this.id);
|
|
1037
1037
|
_this.startTimeout();
|
|
1038
1038
|
afterCreate = makeAfterCreate(config, _this.id + "-" + _this.timer);
|
|
1039
1039
|
afterCreate(client, function (err) {
|
|
@@ -1066,6 +1066,13 @@ var NileDatabase = /*#__PURE__*/function () {
|
|
|
1066
1066
|
});
|
|
1067
1067
|
evictPool(_this.id);
|
|
1068
1068
|
});
|
|
1069
|
+
this.pool.on('release', function (destroy) {
|
|
1070
|
+
if (destroy) {
|
|
1071
|
+
clearTimeout(_this.timer);
|
|
1072
|
+
evictPool(_this.id);
|
|
1073
|
+
debug("destroying pool " + _this.id);
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1069
1076
|
}
|
|
1070
1077
|
var _proto = NileDatabase.prototype;
|
|
1071
1078
|
_proto.startTimeout = function startTimeout() {
|
|
@@ -1120,12 +1127,6 @@ function makeAfterCreate(config, id) {
|
|
|
1120
1127
|
}
|
|
1121
1128
|
// in this example we use pg driver's connection API
|
|
1122
1129
|
conn.query(query.join(';'), function (err) {
|
|
1123
|
-
if (query.length === 1) {
|
|
1124
|
-
debug("connection context set: tenantId=" + config.tenantId);
|
|
1125
|
-
}
|
|
1126
|
-
if (query.length === 2) {
|
|
1127
|
-
debug("connection context set: tenantId=" + config.tenantId + " userId=" + config.userId);
|
|
1128
|
-
}
|
|
1129
1130
|
if (err) {
|
|
1130
1131
|
error('query connection failed', {
|
|
1131
1132
|
cause: err.cause,
|
|
@@ -1134,6 +1135,13 @@ function makeAfterCreate(config, id) {
|
|
|
1134
1135
|
name: err.name,
|
|
1135
1136
|
id: id
|
|
1136
1137
|
});
|
|
1138
|
+
} else {
|
|
1139
|
+
if (query.length === 1) {
|
|
1140
|
+
debug("connection context set: tenantId=" + config.tenantId);
|
|
1141
|
+
}
|
|
1142
|
+
if (query.length === 2) {
|
|
1143
|
+
debug("connection context set: tenantId=" + config.tenantId + " userId=" + config.userId);
|
|
1144
|
+
}
|
|
1137
1145
|
}
|
|
1138
1146
|
done(err, conn);
|
|
1139
1147
|
});
|
|
@@ -4051,6 +4059,10 @@ var Api = /*#__PURE__*/function () {
|
|
|
4051
4059
|
this.handlers = Handlers(this.routes, config);
|
|
4052
4060
|
}
|
|
4053
4061
|
var _proto = Api.prototype;
|
|
4062
|
+
_proto.updateConfig = function updateConfig(config) {
|
|
4063
|
+
this.config = config;
|
|
4064
|
+
this.handlers = Handlers(this.routes, config);
|
|
4065
|
+
};
|
|
4054
4066
|
_proto.login = /*#__PURE__*/function () {
|
|
4055
4067
|
var _login = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload) {
|
|
4056
4068
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -4102,6 +4114,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
4102
4114
|
var _proto = Server.prototype;
|
|
4103
4115
|
_proto.setConfig = function setConfig(cfg) {
|
|
4104
4116
|
this.config = new Config(cfg);
|
|
4117
|
+
this.api.updateConfig(this.config);
|
|
4105
4118
|
};
|
|
4106
4119
|
_proto.init = /*#__PURE__*/function () {
|
|
4107
4120
|
var _init = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(cfg) {
|
|
@@ -4210,11 +4223,20 @@ function _create() {
|
|
|
4210
4223
|
if (!server) {
|
|
4211
4224
|
server = new Server(config);
|
|
4212
4225
|
}
|
|
4213
|
-
|
|
4226
|
+
if (!config) {
|
|
4227
|
+
_context2.next = 5;
|
|
4228
|
+
break;
|
|
4229
|
+
}
|
|
4230
|
+
_context2.next = 4;
|
|
4231
|
+
return server.init(new Config(config));
|
|
4232
|
+
case 4:
|
|
4233
|
+
return _context2.abrupt("return", _context2.sent);
|
|
4234
|
+
case 5:
|
|
4235
|
+
_context2.next = 7;
|
|
4214
4236
|
return server.init();
|
|
4215
|
-
case
|
|
4237
|
+
case 7:
|
|
4216
4238
|
return _context2.abrupt("return", _context2.sent);
|
|
4217
|
-
case
|
|
4239
|
+
case 8:
|
|
4218
4240
|
case "end":
|
|
4219
4241
|
return _context2.stop();
|
|
4220
4242
|
}
|