@conduitplatform/grpc-sdk 0.13.0-rc0
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/README.md +20 -0
- package/dist/classes/ConduitActiveSchema.d.ts +19 -0
- package/dist/classes/ConduitActiveSchema.js +57 -0
- package/dist/classes/ConduitActiveSchema.js.map +1 -0
- package/dist/classes/ConduitMiddleware.d.ts +8 -0
- package/dist/classes/ConduitMiddleware.js +26 -0
- package/dist/classes/ConduitMiddleware.js.map +1 -0
- package/dist/classes/ConduitModule.d.ts +26 -0
- package/dist/classes/ConduitModule.js +170 -0
- package/dist/classes/ConduitModule.js.map +1 -0
- package/dist/classes/ConduitParser.d.ts +20 -0
- package/dist/classes/ConduitParser.js +84 -0
- package/dist/classes/ConduitParser.js.map +1 -0
- package/dist/classes/ConduitRoute.d.ts +12 -0
- package/dist/classes/ConduitRoute.js +44 -0
- package/dist/classes/ConduitRoute.js.map +1 -0
- package/dist/classes/ConduitRouteReturn.d.ts +48 -0
- package/dist/classes/ConduitRouteReturn.js +66 -0
- package/dist/classes/ConduitRouteReturn.js.map +1 -0
- package/dist/classes/ConduitSchema.d.ts +10 -0
- package/dist/classes/ConduitSchema.js +22 -0
- package/dist/classes/ConduitSchema.js.map +1 -0
- package/dist/classes/ConduitSchemaExtension.d.ts +7 -0
- package/dist/classes/ConduitSchemaExtension.js +19 -0
- package/dist/classes/ConduitSchemaExtension.js.map +1 -0
- package/dist/classes/ConduitServiceModule.d.ts +25 -0
- package/dist/classes/ConduitServiceModule.js +139 -0
- package/dist/classes/ConduitServiceModule.js.map +1 -0
- package/dist/classes/ConduitSocket.d.ts +9 -0
- package/dist/classes/ConduitSocket.js +27 -0
- package/dist/classes/ConduitSocket.js.map +1 -0
- package/dist/classes/ConfigController.d.ts +7 -0
- package/dist/classes/ConfigController.js +27 -0
- package/dist/classes/ConfigController.js.map +1 -0
- package/dist/classes/Error.d.ts +11 -0
- package/dist/classes/Error.js +51 -0
- package/dist/classes/Error.js.map +1 -0
- package/dist/classes/GrpcServer.d.ts +19 -0
- package/dist/classes/GrpcServer.js +185 -0
- package/dist/classes/GrpcServer.js.map +1 -0
- package/dist/classes/ManagedModule.d.ts +20 -0
- package/dist/classes/ManagedModule.js +212 -0
- package/dist/classes/ManagedModule.js.map +1 -0
- package/dist/classes/ModuleManager.d.ts +11 -0
- package/dist/classes/ModuleManager.js +191 -0
- package/dist/classes/ModuleManager.js.map +1 -0
- package/dist/classes/Routing/RouteBuilder.d.ts +28 -0
- package/dist/classes/Routing/RouteBuilder.js +107 -0
- package/dist/classes/Routing/RouteBuilder.js.map +1 -0
- package/dist/classes/Routing/RoutingManager.d.ts +25 -0
- package/dist/classes/Routing/RoutingManager.js +193 -0
- package/dist/classes/Routing/RoutingManager.js.map +1 -0
- package/dist/classes/index.d.ts +16 -0
- package/dist/classes/index.js +29 -0
- package/dist/classes/index.js.map +1 -0
- package/dist/constants/enums/PlatformTypesEnum.d.ts +9 -0
- package/dist/constants/enums/PlatformTypesEnum.js +14 -0
- package/dist/constants/enums/PlatformTypesEnum.js.map +1 -0
- package/dist/constants/enums/index.d.ts +1 -0
- package/dist/constants/enums/index.js +14 -0
- package/dist/constants/enums/index.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +14 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/helpers/GrpcHelper.d.ts +8 -0
- package/dist/helpers/GrpcHelper.js +44 -0
- package/dist/helpers/GrpcHelper.js.map +1 -0
- package/dist/helpers/RoutingJsonConstructor.d.ts +9 -0
- package/dist/helpers/RoutingJsonConstructor.js +89 -0
- package/dist/helpers/RoutingJsonConstructor.js.map +1 -0
- package/dist/helpers/RoutingUtilities.d.ts +13 -0
- package/dist/helpers/RoutingUtilities.js +69 -0
- package/dist/helpers/RoutingUtilities.js.map +1 -0
- package/dist/helpers/TypeHelpers.d.ts +44 -0
- package/dist/helpers/TypeHelpers.js +144 -0
- package/dist/helpers/TypeHelpers.js.map +1 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +18 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/wrapGrpcFunctions.d.ts +5 -0
- package/dist/helpers/wrapGrpcFunctions.js +37 -0
- package/dist/helpers/wrapGrpcFunctions.js.map +1 -0
- package/dist/helpers/wrapRouterFunctions.d.ts +7 -0
- package/dist/helpers/wrapRouterFunctions.js +111 -0
- package/dist/helpers/wrapRouterFunctions.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +481 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/grpcSignedToken.d.ts +2 -0
- package/dist/interceptors/grpcSignedToken.js +88 -0
- package/dist/interceptors/grpcSignedToken.js.map +1 -0
- package/dist/interceptors/index.d.ts +2 -0
- package/dist/interceptors/index.js +15 -0
- package/dist/interceptors/index.js.map +1 -0
- package/dist/interceptors/moduleName.d.ts +2 -0
- package/dist/interceptors/moduleName.js +88 -0
- package/dist/interceptors/moduleName.js.map +1 -0
- package/dist/interfaces/ConduitService.d.ts +8 -0
- package/dist/interfaces/ConduitService.js +3 -0
- package/dist/interfaces/ConduitService.js.map +1 -0
- package/dist/interfaces/GrpcCallback.d.ts +4 -0
- package/dist/interfaces/GrpcCallback.js +3 -0
- package/dist/interfaces/GrpcCallback.js.map +1 -0
- package/dist/interfaces/Indexable.d.ts +9 -0
- package/dist/interfaces/Indexable.js +3 -0
- package/dist/interfaces/Indexable.js.map +1 -0
- package/dist/interfaces/Middleware.d.ts +7 -0
- package/dist/interfaces/Middleware.js +3 -0
- package/dist/interfaces/Middleware.js.map +1 -0
- package/dist/interfaces/Model.d.ts +37 -0
- package/dist/interfaces/Model.js +19 -0
- package/dist/interfaces/Model.js.map +1 -0
- package/dist/interfaces/Route.d.ts +54 -0
- package/dist/interfaces/Route.js +21 -0
- package/dist/interfaces/Route.js.map +1 -0
- package/dist/interfaces/Socket.d.ts +34 -0
- package/dist/interfaces/Socket.js +9 -0
- package/dist/interfaces/Socket.js.map +1 -0
- package/dist/interfaces/index.d.ts +7 -0
- package/dist/interfaces/index.js +20 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/admin/index.d.ts +13 -0
- package/dist/modules/admin/index.js +131 -0
- package/dist/modules/admin/index.js.map +1 -0
- package/dist/modules/authentication/index.d.ts +11 -0
- package/dist/modules/authentication/index.js +50 -0
- package/dist/modules/authentication/index.js.map +1 -0
- package/dist/modules/chat/index.d.ts +10 -0
- package/dist/modules/chat/index.js +46 -0
- package/dist/modules/chat/index.js.map +1 -0
- package/dist/modules/config/index.d.ts +25 -0
- package/dist/modules/config/index.js +234 -0
- package/dist/modules/config/index.js.map +1 -0
- package/dist/modules/core/index.d.ts +6 -0
- package/dist/modules/core/index.js +32 -0
- package/dist/modules/core/index.js.map +1 -0
- package/dist/modules/database/index.d.ts +30 -0
- package/dist/modules/database/index.js +201 -0
- package/dist/modules/database/index.js.map +1 -0
- package/dist/modules/email/index.d.ts +21 -0
- package/dist/modules/email/index.js +63 -0
- package/dist/modules/email/index.js.map +1 -0
- package/dist/modules/forms/index.d.ts +7 -0
- package/dist/modules/forms/index.js +37 -0
- package/dist/modules/forms/index.js.map +1 -0
- package/dist/modules/index.d.ts +11 -0
- package/dist/modules/index.js +24 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/pushNotifications/index.d.ts +10 -0
- package/dist/modules/pushNotifications/index.js +63 -0
- package/dist/modules/pushNotifications/index.js.map +1 -0
- package/dist/modules/router/index.d.ts +8 -0
- package/dist/modules/router/index.js +43 -0
- package/dist/modules/router/index.js.map +1 -0
- package/dist/modules/sms/index.d.ts +10 -0
- package/dist/modules/sms/index.js +46 -0
- package/dist/modules/sms/index.js.map +1 -0
- package/dist/modules/storage/index.d.ts +10 -0
- package/dist/modules/storage/index.js +47 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/protoUtils/authentication.d.ts +209 -0
- package/dist/protoUtils/authentication.js +533 -0
- package/dist/protoUtils/authentication.js.map +1 -0
- package/dist/protoUtils/chat.d.ts +178 -0
- package/dist/protoUtils/chat.js +534 -0
- package/dist/protoUtils/chat.js.map +1 -0
- package/dist/protoUtils/core.d.ts +607 -0
- package/dist/protoUtils/core.js +1883 -0
- package/dist/protoUtils/core.js.map +1 -0
- package/dist/protoUtils/database.d.ts +496 -0
- package/dist/protoUtils/database.js +1275 -0
- package/dist/protoUtils/database.js.map +1 -0
- package/dist/protoUtils/email.d.ts +153 -0
- package/dist/protoUtils/email.js +543 -0
- package/dist/protoUtils/email.js.map +1 -0
- package/dist/protoUtils/forms.d.ts +54 -0
- package/dist/protoUtils/forms.js +141 -0
- package/dist/protoUtils/forms.js.map +1 -0
- package/dist/protoUtils/grpc_health_check.d.ts +83 -0
- package/dist/protoUtils/grpc_health_check.js +197 -0
- package/dist/protoUtils/grpc_health_check.js.map +1 -0
- package/dist/protoUtils/push-notifications.d.ts +179 -0
- package/dist/protoUtils/push-notifications.js +512 -0
- package/dist/protoUtils/push-notifications.js.map +1 -0
- package/dist/protoUtils/sms.d.ts +176 -0
- package/dist/protoUtils/sms.js +459 -0
- package/dist/protoUtils/sms.js.map +1 -0
- package/dist/protoUtils/storage.d.ts +203 -0
- package/dist/protoUtils/storage.js +522 -0
- package/dist/protoUtils/storage.js.map +1 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/index.js +37 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utilities/EventBus.d.ts +10 -0
- package/dist/utilities/EventBus.js +52 -0
- package/dist/utilities/EventBus.js.map +1 -0
- package/dist/utilities/RedisManager.d.ts +6 -0
- package/dist/utilities/RedisManager.js +32 -0
- package/dist/utilities/RedisManager.js.map +1 -0
- package/dist/utilities/StateManager.d.ts +10 -0
- package/dist/utilities/StateManager.js +31 -0
- package/dist/utilities/StateManager.js.map +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.js +10 -0
- package/dist/utilities/index.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConduitSchema = void 0;
|
|
4
|
+
var ConduitSchema = /** @class */ (function () {
|
|
5
|
+
function ConduitSchema(name, fields, schemaOptions, collectionName) {
|
|
6
|
+
this.ownerModule = 'unknown';
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.fields = fields;
|
|
9
|
+
this.schemaOptions = schemaOptions !== null && schemaOptions !== void 0 ? schemaOptions : {};
|
|
10
|
+
this.collectionName = collectionName && collectionName !== '' ? collectionName : '';
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(ConduitSchema.prototype, "modelSchema", {
|
|
13
|
+
get: function () {
|
|
14
|
+
return this.fields;
|
|
15
|
+
},
|
|
16
|
+
enumerable: false,
|
|
17
|
+
configurable: true
|
|
18
|
+
});
|
|
19
|
+
return ConduitSchema;
|
|
20
|
+
}());
|
|
21
|
+
exports.ConduitSchema = ConduitSchema;
|
|
22
|
+
//# sourceMappingURL=ConduitSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConduitSchema.js","sourceRoot":"","sources":["../../src/classes/ConduitSchema.ts"],"names":[],"mappings":";;;AAEA;IAOE,uBACE,IAAY,EACZ,MAAoB,EACpB,aAAmC,EACnC,cAAuB;QANzB,gBAAW,GAAW,SAAS,CAAC;QAQ9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,EAAE,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,cAAc,KAAK,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACtF,CAAC;IAED,sBAAI,sCAAW;aAAf;YACE,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;;;OAAA;IACH,oBAAC;AAAD,CAAC,AAtBD,IAsBC;AAtBY,sCAAa"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConduitSchemaExtension = void 0;
|
|
4
|
+
var ConduitSchemaExtension = /** @class */ (function () {
|
|
5
|
+
function ConduitSchemaExtension(name, fields) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.fields = fields;
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(ConduitSchemaExtension.prototype, "modelSchema", {
|
|
10
|
+
get: function () {
|
|
11
|
+
return this.fields;
|
|
12
|
+
},
|
|
13
|
+
enumerable: false,
|
|
14
|
+
configurable: true
|
|
15
|
+
});
|
|
16
|
+
return ConduitSchemaExtension;
|
|
17
|
+
}());
|
|
18
|
+
exports.ConduitSchemaExtension = ConduitSchemaExtension;
|
|
19
|
+
//# sourceMappingURL=ConduitSchemaExtension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConduitSchemaExtension.js","sourceRoot":"","sources":["../../src/classes/ConduitSchemaExtension.ts"],"names":[],"mappings":";;;AAEA;IAIE,gCAAY,IAAY,EAAE,MAAoB;QAC5C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,sBAAI,+CAAW;aAAf;YACE,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;;;OAAA;IACH,6BAAC;AAAD,CAAC,AAZD,IAYC;AAZY,wDAAsB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import ConduitGrpcSdk, { GrpcServer, HealthCheckStatus } from '..';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import { GrpcRequest } from '../types';
|
|
5
|
+
import { HealthCheckRequest, HealthCheckResponse } from '../protoUtils/grpc_health_check';
|
|
6
|
+
import { GrpcCallback } from '../interfaces';
|
|
7
|
+
import { ServerWritableStream } from '@grpc/grpc-js';
|
|
8
|
+
export declare abstract class ConduitServiceModule {
|
|
9
|
+
protected readonly _moduleName: string;
|
|
10
|
+
protected _serviceName?: string;
|
|
11
|
+
protected _port: string;
|
|
12
|
+
protected grpcServer: GrpcServer;
|
|
13
|
+
private _grpcSdk;
|
|
14
|
+
private _serviceHealthState;
|
|
15
|
+
protected readonly events: EventEmitter;
|
|
16
|
+
protected constructor(moduleName: string);
|
|
17
|
+
get healthState(): HealthCheckStatus;
|
|
18
|
+
set grpcSdk(grpcSdk: ConduitGrpcSdk);
|
|
19
|
+
get grpcSdk(): ConduitGrpcSdk;
|
|
20
|
+
get port(): string;
|
|
21
|
+
protected addHealthCheckService(): Promise<void>;
|
|
22
|
+
updateHealth(state: HealthCheckStatus, init?: boolean): void;
|
|
23
|
+
healthCheck(call: GrpcRequest<HealthCheckRequest>, callback: GrpcCallback<HealthCheckResponse>): void;
|
|
24
|
+
healthWatch(call: ServerWritableStream<HealthCheckRequest, HealthCheckResponse>): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.ConduitServiceModule = void 0;
|
|
43
|
+
var __1 = require("..");
|
|
44
|
+
var path_1 = __importDefault(require("path"));
|
|
45
|
+
var events_1 = require("events");
|
|
46
|
+
var lodash_1 = require("lodash");
|
|
47
|
+
var ConduitServiceModule = /** @class */ (function () {
|
|
48
|
+
function ConduitServiceModule(moduleName) {
|
|
49
|
+
this._serviceHealthState = __1.HealthCheckStatus.SERVING; // default for health-agnostic modules
|
|
50
|
+
this.events = new events_1.EventEmitter();
|
|
51
|
+
this._moduleName = lodash_1.camelCase(moduleName);
|
|
52
|
+
}
|
|
53
|
+
Object.defineProperty(ConduitServiceModule.prototype, "healthState", {
|
|
54
|
+
get: function () {
|
|
55
|
+
return this._serviceHealthState;
|
|
56
|
+
},
|
|
57
|
+
enumerable: false,
|
|
58
|
+
configurable: true
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(ConduitServiceModule.prototype, "grpcSdk", {
|
|
61
|
+
get: function () {
|
|
62
|
+
if (!this._grpcSdk)
|
|
63
|
+
throw new Error('grpcSdk not defined yet');
|
|
64
|
+
return this._grpcSdk;
|
|
65
|
+
},
|
|
66
|
+
set: function (grpcSdk) {
|
|
67
|
+
if (this._grpcSdk)
|
|
68
|
+
throw new Error('grpcSdk already defined');
|
|
69
|
+
this._grpcSdk = grpcSdk;
|
|
70
|
+
},
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(ConduitServiceModule.prototype, "port", {
|
|
75
|
+
get: function () {
|
|
76
|
+
return this._port;
|
|
77
|
+
},
|
|
78
|
+
enumerable: false,
|
|
79
|
+
configurable: true
|
|
80
|
+
});
|
|
81
|
+
ConduitServiceModule.prototype.addHealthCheckService = function () {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0: return [4 /*yield*/, this.grpcServer.addService(path_1.default.resolve(__dirname, '../../src/grpc_health_check.proto'), 'grpc.health.v1.Health', {
|
|
86
|
+
Check: this.healthCheck.bind(this),
|
|
87
|
+
Watch: this.healthWatch.bind(this),
|
|
88
|
+
})];
|
|
89
|
+
case 1:
|
|
90
|
+
_a.sent();
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
ConduitServiceModule.prototype.updateHealth = function (state, init) {
|
|
97
|
+
if (init === void 0) { init = false; }
|
|
98
|
+
if ((state === __1.HealthCheckStatus.UNKNOWN && !init) ||
|
|
99
|
+
state === __1.HealthCheckStatus.SERVICE_UNKNOWN) {
|
|
100
|
+
throw new Error("Cannot explicitly set gRPC health state to " + __1.HealthCheckStatus[state]);
|
|
101
|
+
}
|
|
102
|
+
if (this._serviceHealthState !== state) {
|
|
103
|
+
this._serviceHealthState = state;
|
|
104
|
+
this.events.emit("grpc-health-change:" + this._serviceName, state);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
ConduitServiceModule.prototype.healthCheck = function (call, callback) {
|
|
108
|
+
var service = call.request.service.substring(call.request.service.indexOf('.') + 1);
|
|
109
|
+
if (service && service !== this._serviceName) {
|
|
110
|
+
callback(null, {
|
|
111
|
+
status: __1.HealthCheckStatus.SERVICE_UNKNOWN,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
callback(null, {
|
|
116
|
+
status: this
|
|
117
|
+
._serviceHealthState,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
ConduitServiceModule.prototype.healthWatch = function (call) {
|
|
122
|
+
var service = call.request.service.substring(call.request.service.indexOf('.') + 1);
|
|
123
|
+
if (service && service !== this._serviceName) {
|
|
124
|
+
call.write({
|
|
125
|
+
status: __1.HealthCheckStatus.SERVICE_UNKNOWN,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.events.on("grpc-health-change:" + this._serviceName, function (status) {
|
|
130
|
+
call.write({
|
|
131
|
+
status: status,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return ConduitServiceModule;
|
|
137
|
+
}());
|
|
138
|
+
exports.ConduitServiceModule = ConduitServiceModule;
|
|
139
|
+
//# sourceMappingURL=ConduitServiceModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConduitServiceModule.js","sourceRoot":"","sources":["../../src/classes/ConduitServiceModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wBAAmE;AACnE,8CAAwB;AACxB,iCAAsC;AACtC,iCAAmC;AAUnC;IASE,8BAAsB,UAAkB;QAHhC,wBAAmB,GAAsB,qBAAiB,CAAC,OAAO,CAAC,CAAC,sCAAsC;QAC/F,WAAM,GAAiB,IAAI,qBAAY,EAAE,CAAC;QAG3D,IAAI,CAAC,WAAW,GAAG,kBAAS,CAAC,UAAU,CAAC,CAAC;IAC3C,CAAC;IAED,sBAAI,6CAAW;aAAf;YACE,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;;;OAAA;IAED,sBAAW,yCAAO;aAKlB;YACE,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC/D,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;aARD,UAAmB,OAAuB;YACxC,IAAI,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC9D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAC1B,CAAC;;;OAAA;IAOD,sBAAI,sCAAI;aAAR;YACE,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;;;OA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BAAoE;aACxE,CAAC,CAAC;SACJ;IACH,CAAC;IAED,0CAAW,GAAX,UAAY,IAAmE;QAC7E,IAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACtF,IAAI,OAAO,IAAI,OAAO,KAAK,IAAI,CAAC,YAAY,EAAE;YAC5C,IAAI,CAAC,KAAK,CAAC;gBACT,MAAM,EAAG,qBAAiB,CAAC,eAAgE;aAC5F,CAAC,CAAC;SACJ;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,EAAE,CACZ,wBAAsB,IAAI,CAAC,YAAc,EACzC,UAAC,MAAyB;gBACxB,IAAI,CAAC,KAAK,CAAC;oBACT,MAAM,EAAG,MAAuD;iBACjE,CAAC,CAAC;YACL,CAAC,CACF,CAAC;SACH;IACH,CAAC;IACH,2BAAC;AAAD,CAAC,AA3FD,IA2FC;AA3FqB,oDAAoB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConduitModel, ConduitSocketEvent, ConduitSocketOptions } from '../interfaces';
|
|
2
|
+
export declare class ConduitSocket {
|
|
3
|
+
private readonly _input;
|
|
4
|
+
readonly events: Record<string, ConduitSocketEvent>;
|
|
5
|
+
constructor(input: ConduitSocketOptions, events: Record<string, ConduitSocketEvent>);
|
|
6
|
+
get input(): ConduitSocketOptions;
|
|
7
|
+
returnTypeName(event: string): string;
|
|
8
|
+
returnTypeFields(event: string): ConduitModel | string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConduitSocket = void 0;
|
|
4
|
+
var ConduitSocket = /** @class */ (function () {
|
|
5
|
+
function ConduitSocket(input, events) {
|
|
6
|
+
this._input = input;
|
|
7
|
+
this.events = events;
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(ConduitSocket.prototype, "input", {
|
|
10
|
+
get: function () {
|
|
11
|
+
return this._input;
|
|
12
|
+
},
|
|
13
|
+
enumerable: false,
|
|
14
|
+
configurable: true
|
|
15
|
+
});
|
|
16
|
+
ConduitSocket.prototype.returnTypeName = function (event) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
return ((_b = (_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.returnType) === null || _b === void 0 ? void 0 : _b.name) || '';
|
|
19
|
+
};
|
|
20
|
+
ConduitSocket.prototype.returnTypeFields = function (event) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
return ((_b = (_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.returnType) === null || _b === void 0 ? void 0 : _b.fields) || '';
|
|
23
|
+
};
|
|
24
|
+
return ConduitSocket;
|
|
25
|
+
}());
|
|
26
|
+
exports.ConduitSocket = ConduitSocket;
|
|
27
|
+
//# sourceMappingURL=ConduitSocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConduitSocket.js","sourceRoot":"","sources":["../../src/classes/ConduitSocket.ts"],"names":[],"mappings":";;;AAEA;IAIE,uBAAY,KAA2B,EAAE,MAA0C;QACjF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,sBAAI,gCAAK;aAAT;YACE,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;;;OAAA;IAED,sCAAc,GAAd,UAAe,KAAa;;QAC1B,OAAO,CAAA,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0CAAE,UAAU,0CAAE,IAAI,KAAI,EAAE,CAAC;IACpD,CAAC;IAED,wCAAgB,GAAhB,UAAiB,KAAa;;QAC5B,OAAO,CAAA,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0CAAE,UAAU,0CAAE,MAAM,KAAI,EAAE,CAAC;IACtD,CAAC;IACH,oBAAC;AAAD,CAAC,AApBD,IAoBC;AApBY,sCAAa"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigController = void 0;
|
|
4
|
+
var ConfigController = /** @class */ (function () {
|
|
5
|
+
function ConfigController() {
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(ConfigController.prototype, "config", {
|
|
8
|
+
get: function () {
|
|
9
|
+
// return copy of config and not the original object;
|
|
10
|
+
return Object.assign({}, this._config);
|
|
11
|
+
},
|
|
12
|
+
set: function (config) {
|
|
13
|
+
this._config = config;
|
|
14
|
+
},
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: true
|
|
17
|
+
});
|
|
18
|
+
ConfigController.getInstance = function () {
|
|
19
|
+
if (!ConfigController.instance) {
|
|
20
|
+
ConfigController.instance = new ConfigController();
|
|
21
|
+
}
|
|
22
|
+
return ConfigController.instance;
|
|
23
|
+
};
|
|
24
|
+
return ConfigController;
|
|
25
|
+
}());
|
|
26
|
+
exports.ConfigController = ConfigController;
|
|
27
|
+
//# sourceMappingURL=ConfigController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigController.js","sourceRoot":"","sources":["../../src/classes/ConfigController.ts"],"names":[],"mappings":";;;AAAA;IAAA;IAoBA,CAAC;IAfC,sBAAI,oCAAM;aAAV;YACE,qDAAqD;YACrD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC;aAED,UAAW,MAAW;YACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACxB,CAAC;;;OAJA;IAMM,4BAAW,GAAlB;QACE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE;YAC9B,gBAAgB,CAAC,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;SACpD;QACD,OAAO,gBAAgB,CAAC,QAAQ,CAAC;IACnC,CAAC;IACH,uBAAC;AAAD,CAAC,AApBD,IAoBC;AApBY,4CAAgB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class ConduitError extends Error {
|
|
2
|
+
message: string;
|
|
3
|
+
name: string;
|
|
4
|
+
status: number;
|
|
5
|
+
constructor(name: string, status: number, message: string);
|
|
6
|
+
static unauthorized(message?: string): ConduitError;
|
|
7
|
+
static notFound(message?: string): ConduitError;
|
|
8
|
+
static forbidden(message?: string): ConduitError;
|
|
9
|
+
static userInput(message?: string): ConduitError;
|
|
10
|
+
static internalServerError(message?: string): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ConduitError = void 0;
|
|
19
|
+
var ConduitError = /** @class */ (function (_super) {
|
|
20
|
+
__extends(ConduitError, _super);
|
|
21
|
+
function ConduitError(name, status, message) {
|
|
22
|
+
var _this = _super.call(this, message) || this;
|
|
23
|
+
_this.name = name;
|
|
24
|
+
_this.message = message;
|
|
25
|
+
_this.status = status;
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
ConduitError.unauthorized = function (message) {
|
|
29
|
+
if (message === void 0) { message = 'Unauthorized'; }
|
|
30
|
+
return new ConduitError('UNAUTHORIZED', 401, message);
|
|
31
|
+
};
|
|
32
|
+
ConduitError.notFound = function (message) {
|
|
33
|
+
if (message === void 0) { message = 'Resource not found'; }
|
|
34
|
+
return new ConduitError('NOT_FOUND', 404, message);
|
|
35
|
+
};
|
|
36
|
+
ConduitError.forbidden = function (message) {
|
|
37
|
+
if (message === void 0) { message = 'Forbidden'; }
|
|
38
|
+
return new ConduitError('FORBIDDEN', 403, message);
|
|
39
|
+
};
|
|
40
|
+
ConduitError.userInput = function (message) {
|
|
41
|
+
if (message === void 0) { message = 'Request data are invalid'; }
|
|
42
|
+
return new ConduitError('USER_INPUT_ERROR', 400, message);
|
|
43
|
+
};
|
|
44
|
+
ConduitError.internalServerError = function (message) {
|
|
45
|
+
if (message === void 0) { message = 'Something went wrong'; }
|
|
46
|
+
throw new ConduitError('INTERNAL_SERVER_ERROR', 500, message);
|
|
47
|
+
};
|
|
48
|
+
return ConduitError;
|
|
49
|
+
}(Error));
|
|
50
|
+
exports.ConduitError = ConduitError;
|
|
51
|
+
//# sourceMappingURL=Error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Error.js","sourceRoot":"","sources":["../../src/classes/Error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;IAAkC,gCAAK;IAKrC,sBAAY,IAAY,EAAE,MAAc,EAAE,OAAe;QAAzD,YACE,kBAAM,OAAO,CAAC,SAIf;QAHC,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;;IACvB,CAAC;IAEM,yBAAY,GAAnB,UAAoB,OAAgC;QAAhC,wBAAA,EAAA,wBAAgC;QAClD,OAAO,IAAI,YAAY,CAAC,cAAc,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAEM,qBAAQ,GAAf,UAAgB,OAAsC;QAAtC,wBAAA,EAAA,8BAAsC;QACpD,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAEM,sBAAS,GAAhB,UAAiB,OAA6B;QAA7B,wBAAA,EAAA,qBAA6B;QAC5C,OAAO,IAAI,YAAY,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAEM,sBAAS,GAAhB,UAAiB,OAA4C;QAA5C,wBAAA,EAAA,oCAA4C;QAC3D,OAAO,IAAI,YAAY,CAAC,kBAAkB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAEM,gCAAmB,GAA1B,UAA2B,OAAgC;QAAhC,wBAAA,EAAA,gCAAgC;QACzD,MAAM,IAAI,YAAY,CAAC,uBAAuB,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IACH,mBAAC;AAAD,CAAC,AA/BD,CAAkC,KAAK,GA+BtC;AA/BY,oCAAY"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class GrpcServer {
|
|
2
|
+
private grpcServer?;
|
|
3
|
+
private started;
|
|
4
|
+
private startedOnce;
|
|
5
|
+
private _serviceNames;
|
|
6
|
+
private scheduledRestart;
|
|
7
|
+
private _services;
|
|
8
|
+
constructor(port?: string);
|
|
9
|
+
private _url;
|
|
10
|
+
get url(): string;
|
|
11
|
+
createNewServer(): Promise<number>;
|
|
12
|
+
addService(protoFilePath: string, protoDescription: string, functions: {
|
|
13
|
+
[name: string]: Function;
|
|
14
|
+
}): Promise<GrpcServer>;
|
|
15
|
+
wait(time: number): Promise<void>;
|
|
16
|
+
refresh(): Promise<void>;
|
|
17
|
+
scheduleRefresh(): void;
|
|
18
|
+
start(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.GrpcServer = void 0;
|
|
40
|
+
var helpers_1 = require("../helpers");
|
|
41
|
+
var GrpcServer = /** @class */ (function () {
|
|
42
|
+
function GrpcServer(port) {
|
|
43
|
+
this.started = false;
|
|
44
|
+
this.startedOnce = false;
|
|
45
|
+
this._serviceNames = [];
|
|
46
|
+
this._services = [];
|
|
47
|
+
this._url = "0.0.0.0:" + (port !== null && port !== void 0 ? port : '5000');
|
|
48
|
+
}
|
|
49
|
+
Object.defineProperty(GrpcServer.prototype, "url", {
|
|
50
|
+
get: function () {
|
|
51
|
+
return this._url;
|
|
52
|
+
},
|
|
53
|
+
enumerable: false,
|
|
54
|
+
configurable: true
|
|
55
|
+
});
|
|
56
|
+
GrpcServer.prototype.createNewServer = function () {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var serverResult;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0: return [4 /*yield*/, helpers_1.createServer(this._url)];
|
|
62
|
+
case 1:
|
|
63
|
+
serverResult = _a.sent();
|
|
64
|
+
this.grpcServer = serverResult.server;
|
|
65
|
+
this._url = this._url.split(':')[0] + ':' + serverResult.port.toString();
|
|
66
|
+
return [2 /*return*/, serverResult.port];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
GrpcServer.prototype.addService = function (protoFilePath, protoDescription, functions) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
if (process.env.GRPC_KEY) {
|
|
77
|
+
functions = helpers_1.wrapGrpcFunctions(functions);
|
|
78
|
+
}
|
|
79
|
+
if (!(this._serviceNames.indexOf(protoDescription) !== -1)) return [3 /*break*/, 1];
|
|
80
|
+
console.log('Service already exists, performing replace');
|
|
81
|
+
this._services[this._serviceNames.indexOf(protoDescription)] = {
|
|
82
|
+
protoFilePath: protoFilePath,
|
|
83
|
+
protoDescription: protoDescription,
|
|
84
|
+
functions: functions,
|
|
85
|
+
};
|
|
86
|
+
this.scheduleRefresh();
|
|
87
|
+
return [2 /*return*/, this];
|
|
88
|
+
case 1:
|
|
89
|
+
this._services.push({ protoFilePath: protoFilePath, protoDescription: protoDescription, functions: functions });
|
|
90
|
+
this._serviceNames.push(protoDescription);
|
|
91
|
+
if (!this.started) return [3 /*break*/, 2];
|
|
92
|
+
console.log('Server already started, scheduling refresh..');
|
|
93
|
+
this.scheduleRefresh();
|
|
94
|
+
return [2 /*return*/, this];
|
|
95
|
+
case 2:
|
|
96
|
+
if (!!this.grpcServer) return [3 /*break*/, 4];
|
|
97
|
+
return [4 /*yield*/, this.wait(1000)];
|
|
98
|
+
case 3:
|
|
99
|
+
_a.sent();
|
|
100
|
+
_a.label = 4;
|
|
101
|
+
case 4:
|
|
102
|
+
helpers_1.addServiceToServer(this.grpcServer, protoFilePath, protoDescription, functions);
|
|
103
|
+
return [2 /*return*/, this];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
GrpcServer.prototype.wait = function (time) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
112
|
+
var timeout = setTimeout(function () {
|
|
113
|
+
clearTimeout(timeout);
|
|
114
|
+
resolve();
|
|
115
|
+
}, time);
|
|
116
|
+
})];
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
GrpcServer.prototype.refresh = function () {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
+
var _this = this;
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
switch (_a.label) {
|
|
125
|
+
case 0:
|
|
126
|
+
if (!this.started) return [3 /*break*/, 2];
|
|
127
|
+
this.started = false;
|
|
128
|
+
//gracefully shutdown so that there are no service disruption
|
|
129
|
+
return [4 /*yield*/, new Promise(function (resolve) { return _this.grpcServer.tryShutdown(function () { return resolve(); }); })];
|
|
130
|
+
case 1:
|
|
131
|
+
//gracefully shutdown so that there are no service disruption
|
|
132
|
+
_a.sent();
|
|
133
|
+
_a.label = 2;
|
|
134
|
+
case 2: return [4 /*yield*/, this.createNewServer()];
|
|
135
|
+
case 3:
|
|
136
|
+
_a.sent();
|
|
137
|
+
this._services.forEach(function (service) {
|
|
138
|
+
helpers_1.addServiceToServer(_this.grpcServer, service.protoFilePath, service.protoDescription, service.functions);
|
|
139
|
+
});
|
|
140
|
+
if (!this.started && this.startedOnce) {
|
|
141
|
+
this.grpcServer.start();
|
|
142
|
+
this.started = true;
|
|
143
|
+
}
|
|
144
|
+
return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
GrpcServer.prototype.scheduleRefresh = function () {
|
|
150
|
+
var _this = this;
|
|
151
|
+
if (this.scheduledRestart) {
|
|
152
|
+
clearTimeout(this.scheduledRestart);
|
|
153
|
+
}
|
|
154
|
+
var self = this;
|
|
155
|
+
this.scheduledRestart = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
console.log('Begin refresh');
|
|
160
|
+
return [4 /*yield*/, self.refresh()];
|
|
161
|
+
case 1:
|
|
162
|
+
_a.sent();
|
|
163
|
+
console.log('Refresh complete');
|
|
164
|
+
return [2 /*return*/];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}); }, 2000);
|
|
168
|
+
};
|
|
169
|
+
GrpcServer.prototype.start = function () {
|
|
170
|
+
var _a;
|
|
171
|
+
if (this.started) {
|
|
172
|
+
console.error('gRPC server is already running!');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
else if (!this.started && this.startedOnce) {
|
|
176
|
+
console.error('gRPC server is down for refresh!');
|
|
177
|
+
}
|
|
178
|
+
this.started = true;
|
|
179
|
+
this.startedOnce = true;
|
|
180
|
+
(_a = this.grpcServer) === null || _a === void 0 ? void 0 : _a.start();
|
|
181
|
+
};
|
|
182
|
+
return GrpcServer;
|
|
183
|
+
}());
|
|
184
|
+
exports.GrpcServer = GrpcServer;
|
|
185
|
+
//# sourceMappingURL=GrpcServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GrpcServer.js","sourceRoot":"","sources":["../../src/classes/GrpcServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAiF;AAGjF;IAYE,oBAAY,IAAa;QAVjB,YAAO,GAAY,KAAK,CAAC;QACzB,gBAAW,GAAY,KAAK,CAAC;QAC7B,kBAAa,GAAa,EAAE,CAAC;QAE7B,cAAS,GAIX,EAAE,CAAC;QAGP,IAAI,CAAC,IAAI,GAAG,cAAW,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,MAAM,CAAE,CAAC;IAC1C,CAAC;IAID,sBAAI,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ACH,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE;4BACrC,IAAI,CAAC,UAAW,CAAC,KAAK,EAAE,CAAC;4BACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;yBACrB;;;;;KACF;IAED,oCAAe,GAAf;QAAA,iBAUC;QATC,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;SACrC;QACD,IAAM,IAAI,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC;;;;wBACjC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;wBAC7B,qBAAM,IAAI,CAAC,OAAO,EAAE,EAAA;;wBAApB,SAAoB,CAAC;wBACrB,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;;;;aACjC,EAAE,IAAI,CAAC,CAAC;IACX,CAAC;IAED,0BAAK,GAAL;;QACE,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACjD,OAAO;SACR;aAAM,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE;YAC5C,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACnD;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;IACH,iBAAC;AAAD,CAAC,AApHD,IAoHC;AApHY,gCAAU"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ConduitGrpcSdk, { ConduitService, SetConfigRequest, SetConfigResponse } from '..';
|
|
2
|
+
import { ConduitServiceModule } from './ConduitServiceModule';
|
|
3
|
+
import convict from 'convict';
|
|
4
|
+
export declare abstract class ManagedModule<T> extends ConduitServiceModule {
|
|
5
|
+
abstract readonly config?: convict.Config<T>;
|
|
6
|
+
service?: ConduitService;
|
|
7
|
+
protected constructor(moduleName: string);
|
|
8
|
+
get name(): string;
|
|
9
|
+
initialize(grpcSdk: ConduitGrpcSdk): void;
|
|
10
|
+
preServerStart(): Promise<void>;
|
|
11
|
+
onServerStart(): Promise<void>;
|
|
12
|
+
preRegister(): Promise<void>;
|
|
13
|
+
onRegister(): Promise<void>;
|
|
14
|
+
preConfig(config: T): Promise<T>;
|
|
15
|
+
onConfig(): Promise<void>;
|
|
16
|
+
createGrpcServer(servicePort?: string): Promise<void>;
|
|
17
|
+
startGrpcServer(): Promise<void>;
|
|
18
|
+
setConfig(call: SetConfigRequest, callback: SetConfigResponse): Promise<void>;
|
|
19
|
+
protected updateConfig(config?: T): Promise<void>;
|
|
20
|
+
}
|