@conduitplatform/grpc-sdk 0.15.17 → 0.15.19
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/classes/ConduitActiveSchema.js +25 -43
- package/dist/classes/ConduitActiveSchema.js.map +1 -1
- package/dist/classes/ConduitAuthorizedResource.js +5 -6
- package/dist/classes/ConduitAuthorizedResource.js.map +1 -1
- package/dist/classes/ConduitModule.js +44 -138
- package/dist/classes/ConduitModule.js.map +1 -1
- package/dist/classes/ConduitSchema.js +3 -4
- package/dist/classes/ConduitSchema.js.map +1 -1
- package/dist/classes/ConduitServiceModule.js +39 -98
- package/dist/classes/ConduitServiceModule.js.map +1 -1
- package/dist/classes/ConfigController.js +10 -17
- package/dist/classes/ConfigController.js.map +1 -1
- package/dist/classes/Error.js +17 -40
- package/dist/classes/Error.js.map +1 -1
- package/dist/classes/GrpcServer.js +88 -172
- package/dist/classes/GrpcServer.js.map +1 -1
- package/dist/classes/HealthCheck.js +26 -72
- package/dist/classes/HealthCheck.js.map +1 -1
- package/dist/classes/ManagedModule.js +93 -245
- package/dist/classes/ManagedModule.js.map +1 -1
- package/dist/classes/ModuleManager.js +51 -149
- package/dist/classes/ModuleManager.js.map +1 -1
- package/dist/helpers/GrpcHelper.js +11 -11
- package/dist/helpers/GrpcHelper.js.map +1 -1
- package/dist/helpers/TypeHelpers.js +57 -119
- package/dist/helpers/TypeHelpers.js.map +1 -1
- package/dist/helpers/wrapGrpcFunctions.js +14 -15
- package/dist/helpers/wrapGrpcFunctions.js.map +1 -1
- package/dist/index.js +299 -467
- package/dist/index.js.map +1 -1
- package/dist/interceptors/grpcSignedToken.js +7 -79
- package/dist/interceptors/grpcSignedToken.js.map +1 -1
- package/dist/interceptors/moduleName.js +7 -79
- package/dist/interceptors/moduleName.js.map +1 -1
- package/dist/metrics/MetricsServer.js +25 -70
- package/dist/metrics/MetricsServer.js.map +1 -1
- package/dist/metrics/clientMiddleware.js +76 -217
- package/dist/metrics/clientMiddleware.js.map +1 -1
- package/dist/metrics/config/defaults.js +1 -1
- package/dist/metrics/config/defaults.js.map +1 -1
- package/dist/metrics/index.js +53 -89
- package/dist/metrics/index.js.map +1 -1
- package/dist/modules/admin/index.js +16 -34
- package/dist/modules/admin/index.js.map +1 -1
- package/dist/modules/authentication/index.js +20 -39
- package/dist/modules/authentication/index.js.map +1 -1
- package/dist/modules/authorization/index.js +29 -47
- package/dist/modules/authorization/index.js.map +1 -1
- package/dist/modules/chat/index.js +16 -34
- package/dist/modules/chat/index.js.map +1 -1
- package/dist/modules/config/index.js +70 -175
- package/dist/modules/config/index.js.map +1 -1
- package/dist/modules/core/index.js +8 -26
- package/dist/modules/core/index.js.map +1 -1
- package/dist/modules/database/index.js +80 -122
- package/dist/modules/database/index.js.map +1 -1
- package/dist/modules/email/index.js +15 -33
- package/dist/modules/email/index.js.map +1 -1
- package/dist/modules/forms/index.js +8 -26
- package/dist/modules/forms/index.js.map +1 -1
- package/dist/modules/functions/index.js +8 -26
- package/dist/modules/functions/index.js.map +1 -1
- package/dist/modules/pushNotifications/index.js +38 -56
- package/dist/modules/pushNotifications/index.js.map +1 -1
- package/dist/modules/router/index.js +18 -36
- package/dist/modules/router/index.js.map +1 -1
- package/dist/modules/sms/index.js +17 -35
- package/dist/modules/sms/index.js.map +1 -1
- package/dist/modules/storage/index.js +17 -36
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/protoUtils/authentication.d.ts +1 -1
- package/dist/protoUtils/authentication.js +188 -169
- package/dist/protoUtils/authentication.js.map +1 -1
- package/dist/protoUtils/authorization.d.ts +1 -1
- package/dist/protoUtils/authorization.js +332 -391
- package/dist/protoUtils/authorization.js.map +1 -1
- package/dist/protoUtils/chat.d.ts +1 -1
- package/dist/protoUtils/chat.js +176 -212
- package/dist/protoUtils/chat.js.map +1 -1
- package/dist/protoUtils/core.d.ts +1 -1
- package/dist/protoUtils/core.js +643 -605
- package/dist/protoUtils/core.js.map +1 -1
- package/dist/protoUtils/database.d.ts +1 -1
- package/dist/protoUtils/database.js +563 -554
- package/dist/protoUtils/database.js.map +1 -1
- package/dist/protoUtils/email.d.ts +1 -1
- package/dist/protoUtils/email.js +180 -208
- package/dist/protoUtils/email.js.map +1 -1
- package/dist/protoUtils/forms.d.ts +1 -1
- package/dist/protoUtils/forms.js +37 -35
- package/dist/protoUtils/forms.js.map +1 -1
- package/dist/protoUtils/functions.d.ts +1 -1
- package/dist/protoUtils/functions.js +37 -35
- package/dist/protoUtils/functions.js.map +1 -1
- package/dist/protoUtils/grpc_health_check.d.ts +1 -1
- package/dist/protoUtils/grpc_health_check.js +36 -34
- package/dist/protoUtils/grpc_health_check.js.map +1 -1
- package/dist/protoUtils/push-notifications.d.ts +1 -1
- package/dist/protoUtils/push-notifications.js +252 -272
- package/dist/protoUtils/push-notifications.js.map +1 -1
- package/dist/protoUtils/router.d.ts +1 -1
- package/dist/protoUtils/router.js +381 -387
- package/dist/protoUtils/router.js.map +1 -1
- package/dist/protoUtils/sms.d.ts +1 -1
- package/dist/protoUtils/sms.js +155 -143
- package/dist/protoUtils/sms.js.map +1 -1
- package/dist/protoUtils/storage.d.ts +1 -1
- package/dist/protoUtils/storage.js +190 -164
- package/dist/protoUtils/storage.js.map +1 -1
- package/dist/routing/ConduitRouteReturn.js +9 -18
- package/dist/routing/ConduitRouteReturn.js.map +1 -1
- package/dist/routing/ProxyRouteBuilder.js +21 -24
- package/dist/routing/ProxyRouteBuilder.js.map +1 -1
- package/dist/routing/RouteBuilder.js +31 -34
- package/dist/routing/RouteBuilder.js.map +1 -1
- package/dist/routing/RoutingManager.js +65 -115
- package/dist/routing/RoutingManager.js.map +1 -1
- package/dist/routing/RoutingUtilities.js +3 -3
- package/dist/routing/RoutingUtilities.js.map +1 -1
- package/dist/routing/wrapRouterFunctions.js +25 -34
- package/dist/routing/wrapRouterFunctions.js.map +1 -1
- package/dist/types/index.js +6 -24
- package/dist/types/index.js.map +1 -1
- package/dist/utilities/EventBus.js +16 -17
- package/dist/utilities/EventBus.js.map +1 -1
- package/dist/utilities/Logger.js +80 -180
- package/dist/utilities/Logger.js.map +1 -1
- package/dist/utilities/RedisManager.js +11 -21
- package/dist/utilities/RedisManager.js.map +1 -1
- package/dist/utilities/StateManager.js +13 -14
- package/dist/utilities/StateManager.js.map +1 -1
- package/dist/utilities/linearBackoffTimeout.js +28 -92
- package/dist/utilities/linearBackoffTimeout.js.map +1 -1
- package/dist/utilities/merge.js +2 -2
- package/dist/utilities/merge.js.map +1 -1
- package/dist/utilities/sleep.js +1 -1
- package/dist/utilities/sleep.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigController.js","sourceRoot":"","sources":["../../src/classes/ConfigController.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"ConfigController.js","sourceRoot":"","sources":["../../src/classes/ConfigController.ts"],"names":[],"mappings":";;;AAAA,MAAa,gBAAgB;IAK3B,IAAI,MAAM;QACR,qDAAqD;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,MAAM,CAAC,MAAW;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE;YAC9B,gBAAgB,CAAC,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;SACpD;QACD,OAAO,gBAAgB,CAAC,QAAQ,CAAC;IACnC,CAAC;CACF;AApBD,4CAoBC"}
|
package/dist/classes/Error.js
CHANGED
|
@@ -1,51 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.ConduitError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_this.status = status;
|
|
26
|
-
return _this;
|
|
4
|
+
class ConduitError extends Error {
|
|
5
|
+
constructor(name, status, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.status = status;
|
|
27
10
|
}
|
|
28
|
-
|
|
29
|
-
if (message === void 0) { message = 'Unauthorized'; }
|
|
11
|
+
static unauthorized(message = 'Unauthorized') {
|
|
30
12
|
return new ConduitError('UNAUTHORIZED', 401, message);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (message === void 0) { message = 'Resource not found'; }
|
|
13
|
+
}
|
|
14
|
+
static notFound(message = 'Resource not found') {
|
|
34
15
|
return new ConduitError('NOT_FOUND', 404, message);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (message === void 0) { message = 'Forbidden'; }
|
|
16
|
+
}
|
|
17
|
+
static forbidden(message = 'Forbidden') {
|
|
38
18
|
return new ConduitError('FORBIDDEN', 403, message);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (message === void 0) { message = 'Request data are invalid'; }
|
|
19
|
+
}
|
|
20
|
+
static userInput(message = 'Request data are invalid') {
|
|
42
21
|
return new ConduitError('USER_INPUT_ERROR', 400, message);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (message === void 0) { message = 'Something went wrong'; }
|
|
22
|
+
}
|
|
23
|
+
static internalServerError(message = 'Something went wrong') {
|
|
46
24
|
throw new ConduitError('INTERNAL_SERVER_ERROR', 500, message);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}(Error));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
50
27
|
exports.ConduitError = ConduitError;
|
|
51
28
|
//# sourceMappingURL=Error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.js","sourceRoot":"","sources":["../../src/classes/Error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Error.js","sourceRoot":"","sources":["../../src/classes/Error.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IAKrC,YAAY,IAAY,EAAE,MAAc,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,UAAkB,cAAc;QAClD,OAAO,IAAI,YAAY,CAAC,cAAc,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,UAAkB,oBAAoB;QACpD,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,UAAkB,WAAW;QAC5C,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,UAAkB,0BAA0B;QAC3D,OAAO,IAAI,YAAY,CAAC,kBAAkB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,CAAC,mBAAmB,CAAC,OAAO,GAAG,sBAAsB;QACzD,MAAM,IAAI,YAAY,CAAC,uBAAuB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;CACF;AA/BD,oCA+BC"}
|
|
@@ -1,194 +1,111 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.GrpcServer = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
7
|
+
const helpers_1 = require("../helpers");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const index_1 = __importDefault(require("../index"));
|
|
10
|
+
class GrpcServer {
|
|
11
|
+
constructor(port) {
|
|
48
12
|
this.started = false;
|
|
49
13
|
this.startedOnce = false;
|
|
50
14
|
this._serviceNames = [];
|
|
51
15
|
this._postponeRequests = 0;
|
|
52
16
|
this._services = [];
|
|
53
|
-
this._url =
|
|
17
|
+
this._url = `0.0.0.0:${port !== null && port !== void 0 ? port : '5000'}`;
|
|
54
18
|
}
|
|
55
|
-
|
|
19
|
+
postponeRestart() {
|
|
56
20
|
if (!this.scheduledRestart || this._postponeRequests > 5)
|
|
57
21
|
return;
|
|
58
22
|
this._postponeRequests++;
|
|
59
23
|
this.scheduleRefresh();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this._services[this._serviceNames.indexOf(protoDescription)] = {
|
|
97
|
-
protoPath: protoPath,
|
|
98
|
-
protoDescription: protoDescription,
|
|
99
|
-
functions: functions,
|
|
100
|
-
};
|
|
101
|
-
this.scheduleRefresh();
|
|
102
|
-
return [2 /*return*/, this];
|
|
103
|
-
case 1:
|
|
104
|
-
this._services.push({ protoPath: protoPath, protoDescription: protoDescription, functions: functions });
|
|
105
|
-
this._serviceNames.push(protoDescription);
|
|
106
|
-
if (!this.started) return [3 /*break*/, 2];
|
|
107
|
-
index_1.default.Logger.log('Server already started, scheduling refresh..');
|
|
108
|
-
this.scheduleRefresh();
|
|
109
|
-
return [2 /*return*/, this];
|
|
110
|
-
case 2:
|
|
111
|
-
if (!!this.grpcServer) return [3 /*break*/, 4];
|
|
112
|
-
return [4 /*yield*/, this.wait(1000)];
|
|
113
|
-
case 3:
|
|
114
|
-
_a.sent();
|
|
115
|
-
_a.label = 4;
|
|
116
|
-
case 4:
|
|
117
|
-
(0, helpers_1.addServiceToServer)(this.grpcServer, protoPath, protoDescription, functions);
|
|
118
|
-
return [2 /*return*/, this];
|
|
24
|
+
}
|
|
25
|
+
get url() {
|
|
26
|
+
return this._url;
|
|
27
|
+
}
|
|
28
|
+
async createNewServer(useForce = false) {
|
|
29
|
+
if ((0, lodash_1.isNil)(this._useForce)) {
|
|
30
|
+
this._useForce = useForce;
|
|
31
|
+
}
|
|
32
|
+
const serverResult = await (0, helpers_1.createServer)(this._url);
|
|
33
|
+
this.grpcServer = serverResult.server;
|
|
34
|
+
this._url = this._url.split(':')[0] + ':' + serverResult.port.toString();
|
|
35
|
+
return serverResult.port;
|
|
36
|
+
}
|
|
37
|
+
async addService(protoPath, protoDescription, functions) {
|
|
38
|
+
functions = (0, helpers_1.wrapGrpcFunctions)(functions, this.postponeRestart.bind(this));
|
|
39
|
+
if (this._serviceNames.indexOf(protoDescription) !== -1) {
|
|
40
|
+
index_1.default.Logger.log('Service already exists, performing replace');
|
|
41
|
+
this._services[this._serviceNames.indexOf(protoDescription)] = {
|
|
42
|
+
protoPath,
|
|
43
|
+
protoDescription,
|
|
44
|
+
functions,
|
|
45
|
+
};
|
|
46
|
+
this.scheduleRefresh();
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this._services.push({ protoPath, protoDescription, functions });
|
|
51
|
+
this._serviceNames.push(protoDescription);
|
|
52
|
+
if (this.started) {
|
|
53
|
+
index_1.default.Logger.log('Server already started, scheduling refresh..');
|
|
54
|
+
this.scheduleRefresh();
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (!this.grpcServer) {
|
|
59
|
+
await this.wait(1000);
|
|
119
60
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
})];
|
|
132
|
-
});
|
|
61
|
+
(0, helpers_1.addServiceToServer)(this.grpcServer, protoPath, protoDescription, functions);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async wait(time) {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const timeout = setTimeout(() => {
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
resolve();
|
|
71
|
+
}, time);
|
|
133
72
|
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
case 2:
|
|
150
|
-
//gracefully shutdown so that there are no service disruption
|
|
151
|
-
_a.sent();
|
|
152
|
-
_a.label = 3;
|
|
153
|
-
case 3: return [4 /*yield*/, this.createNewServer()];
|
|
154
|
-
case 4:
|
|
155
|
-
_a.sent();
|
|
156
|
-
this._services.forEach(function (service) {
|
|
157
|
-
(0, helpers_1.addServiceToServer)(_this.grpcServer, service.protoPath, service.protoDescription, service.functions);
|
|
158
|
-
});
|
|
159
|
-
if (!this.started && this.startedOnce) {
|
|
160
|
-
this.grpcServer.start();
|
|
161
|
-
this.started = true;
|
|
162
|
-
}
|
|
163
|
-
return [2 /*return*/];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
73
|
+
}
|
|
74
|
+
async refresh() {
|
|
75
|
+
if (this.started) {
|
|
76
|
+
this.started = false;
|
|
77
|
+
if (this._useForce) {
|
|
78
|
+
this.grpcServer.forceShutdown();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
//gracefully shutdown so that there are no service disruption
|
|
82
|
+
await new Promise(resolve => this.grpcServer.tryShutdown(() => resolve()));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
await this.createNewServer();
|
|
86
|
+
this._services.forEach(service => {
|
|
87
|
+
(0, helpers_1.addServiceToServer)(this.grpcServer, service.protoPath, service.protoDescription, service.functions);
|
|
166
88
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
89
|
+
if (!this.started && this.startedOnce) {
|
|
90
|
+
this.grpcServer.start();
|
|
91
|
+
this.started = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
scheduleRefresh() {
|
|
170
95
|
if (this.scheduledRestart) {
|
|
171
96
|
clearTimeout(this.scheduledRestart);
|
|
172
97
|
}
|
|
173
|
-
|
|
174
|
-
this.scheduledRestart = setTimeout(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
self.scheduledRestart = undefined;
|
|
185
|
-
self._postponeRequests = 0;
|
|
186
|
-
return [2 /*return*/];
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}); }, 2000);
|
|
190
|
-
};
|
|
191
|
-
GrpcServer.prototype.start = function () {
|
|
98
|
+
const self = this;
|
|
99
|
+
this.scheduledRestart = setTimeout(async () => {
|
|
100
|
+
index_1.default.Logger.log('Begin refresh');
|
|
101
|
+
await self.refresh();
|
|
102
|
+
index_1.default.Logger.log('Refresh complete');
|
|
103
|
+
clearTimeout(self.scheduledRestart);
|
|
104
|
+
self.scheduledRestart = undefined;
|
|
105
|
+
self._postponeRequests = 0;
|
|
106
|
+
}, 2000);
|
|
107
|
+
}
|
|
108
|
+
start() {
|
|
192
109
|
var _a;
|
|
193
110
|
if (this.started) {
|
|
194
111
|
index_1.default.Logger.error('gRPC server is already running!');
|
|
@@ -200,8 +117,7 @@ var GrpcServer = /** @class */ (function () {
|
|
|
200
117
|
this.started = true;
|
|
201
118
|
this.startedOnce = true;
|
|
202
119
|
(_a = this.grpcServer) === null || _a === void 0 ? void 0 : _a.start();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
}());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
206
122
|
exports.GrpcServer = GrpcServer;
|
|
207
123
|
//# sourceMappingURL=GrpcServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GrpcServer.js","sourceRoot":"","sources":["../../src/classes/GrpcServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GrpcServer.js","sourceRoot":"","sources":["../../src/classes/GrpcServer.ts"],"names":[],"mappings":";;;;;;AAAA,wCAAiF;AAEjF,mCAA+B;AAC/B,qDAAsC;AAEtC,MAAa,UAAU;IAcrB,YAAY,IAAa;QAZjB,YAAO,GAAY,KAAK,CAAC;QACzB,gBAAW,GAAY,KAAK,CAAC;QAC7B,kBAAa,GAAa,EAAE,CAAC;QAE7B,sBAAiB,GAAG,CAAC,CAAC;QAEtB,cAAS,GAIX,EAAE,CAAC;QAGP,IAAI,CAAC,IAAI,GAAG,WAAW,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,MAAM,EAAE,CAAC;IAC1C,CAAC;IAEO,eAAe;QACrB,IAAI,CAAC,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,iBAAiB,GAAG,CAAC;YAAE,OAAO;QACjE,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC;IAID,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,WAAoB,KAAK;QAC7C,IAAI,IAAA,cAAK,EAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACzB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;SAC3B;QACD,MAAM,YAAY,GAAG,MAAM,IAAA,sBAAY,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,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,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;YAC5C,eAAc,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YAC3C,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;YACrB,eAAc,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAC9C,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACpC,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;YAClC,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC;QAC7B,CAAC,EAAE,IAAI,CAAC,CAAC;IACX,CAAC;IAED,KAAK;;QACH,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,eAAc,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YAC/D,OAAO;SACR;aAAM,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE;YAC5C,eAAc,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACjE;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,MAAA,IAAI,CAAC,UAAU,0CAAE,KAAK,EAAE,CAAC;IAC3B,CAAC;CACF;AApID,gCAoIC"}
|
|
@@ -1,79 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.checkModuleHealth = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function checkModuleHealth(clientName, serviceUrl, service, grpcToken) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
channel = (0, nice_grpc_1.createChannel)(serviceUrl, undefined, {
|
|
52
|
-
'grpc.max_receive_message_length': 1024 * 1024 * 100,
|
|
53
|
-
'grpc.max_send_message_length': 1024 * 1024 * 100,
|
|
54
|
-
});
|
|
55
|
-
clientFactory = (0, nice_grpc_1.createClientFactory)()
|
|
56
|
-
.use((0, clientMiddleware_1.clientMiddleware)())
|
|
57
|
-
.use(grpcToken
|
|
58
|
-
? (0, interceptors_1.getGrpcSignedTokenInterceptor)(grpcToken)
|
|
59
|
-
: (0, interceptors_1.getModuleNameInterceptor)(clientName));
|
|
60
|
-
_healthClient = clientFactory.create(grpc_health_check_1.HealthDefinition, channel);
|
|
61
|
-
return [4 /*yield*/, _healthClient
|
|
62
|
-
.check({ service: service })
|
|
63
|
-
.then(function (res) {
|
|
64
|
-
return res.status;
|
|
65
|
-
})
|
|
66
|
-
.catch(function (err) { return (error = err); })];
|
|
67
|
-
case 1:
|
|
68
|
-
status = _a.sent();
|
|
69
|
-
channel.close();
|
|
70
|
-
if (!error) {
|
|
71
|
-
return [2 /*return*/, status];
|
|
72
|
-
}
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
4
|
+
const interceptors_1 = require("../interceptors");
|
|
5
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
6
|
+
const grpc_health_check_1 = require("../protoUtils/grpc_health_check");
|
|
7
|
+
const clientMiddleware_1 = require("../metrics/clientMiddleware");
|
|
8
|
+
async function checkModuleHealth(clientName, serviceUrl, service = '', grpcToken) {
|
|
9
|
+
const channel = (0, nice_grpc_1.createChannel)(serviceUrl, undefined, {
|
|
10
|
+
'grpc.max_receive_message_length': 1024 * 1024 * 100,
|
|
11
|
+
'grpc.max_send_message_length': 1024 * 1024 * 100,
|
|
76
12
|
});
|
|
13
|
+
const clientFactory = (0, nice_grpc_1.createClientFactory)()
|
|
14
|
+
.use((0, clientMiddleware_1.clientMiddleware)())
|
|
15
|
+
.use(grpcToken
|
|
16
|
+
? (0, interceptors_1.getGrpcSignedTokenInterceptor)(grpcToken)
|
|
17
|
+
: (0, interceptors_1.getModuleNameInterceptor)(clientName));
|
|
18
|
+
const _healthClient = clientFactory.create(grpc_health_check_1.HealthDefinition, channel);
|
|
19
|
+
let error;
|
|
20
|
+
let status = await _healthClient
|
|
21
|
+
.check({ service })
|
|
22
|
+
.then((res) => {
|
|
23
|
+
return res.status;
|
|
24
|
+
})
|
|
25
|
+
.catch(err => (error = err));
|
|
26
|
+
channel.close();
|
|
27
|
+
if (!error) {
|
|
28
|
+
return status;
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
77
31
|
}
|
|
78
32
|
exports.checkModuleHealth = checkModuleHealth;
|
|
79
33
|
//# sourceMappingURL=HealthCheck.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HealthCheck.js","sourceRoot":"","sources":["../../src/classes/HealthCheck.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HealthCheck.js","sourceRoot":"","sources":["../../src/classes/HealthCheck.ts"],"names":[],"mappings":";;;AAAA,kDAA0F;AAC1F,yCAA+D;AAC/D,uEAAwF;AACxF,kEAA+D;AAExD,KAAK,UAAU,iBAAiB,CACrC,UAAkB,EAClB,UAAkB,EAClB,UAAkB,EAAE,EACpB,SAAkB;IAElB,MAAM,OAAO,GAAG,IAAA,yBAAa,EAAC,UAAU,EAAE,SAAS,EAAE;QACnD,iCAAiC,EAAE,IAAI,GAAG,IAAI,GAAG,GAAG;QACpD,8BAA8B,EAAE,IAAI,GAAG,IAAI,GAAG,GAAG;KAClD,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,IAAA,+BAAmB,GAAE;SACxC,GAAG,CAAC,IAAA,mCAAgB,GAAE,CAAC;SACvB,GAAG,CACF,SAAS;QACP,CAAC,CAAC,IAAA,4CAA6B,EAAC,SAAS,CAAC;QAC1C,CAAC,CAAC,IAAA,uCAAwB,EAAC,UAAU,CAAC,CACzC,CAAC;IACJ,MAAM,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC,oCAAgB,EAAE,OAAO,CAAC,CAAC;IAEtE,IAAI,KAAK,CAAC;IACV,IAAI,MAAM,GAAG,MAAM,aAAa;SAC7B,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;SAClB,IAAI,CAAC,CAAC,GAAwB,EAAE,EAAE;QACjC,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC;IAC/B,OAAO,CAAC,KAAK,EAAE,CAAC;IAChB,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,MAAM,CAAC;KACf;IACD,MAAM,KAAK,CAAC;AACd,CAAC;AA/BD,8CA+BC"}
|