@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,212 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.ManagedModule = void 0;
|
|
55
|
+
var __1 = require("..");
|
|
56
|
+
var ConduitServiceModule_1 = require("./ConduitServiceModule");
|
|
57
|
+
var ConfigController_1 = require("./ConfigController");
|
|
58
|
+
var lodash_1 = require("lodash");
|
|
59
|
+
var grpc_js_1 = require("@grpc/grpc-js");
|
|
60
|
+
var ManagedModule = /** @class */ (function (_super) {
|
|
61
|
+
__extends(ManagedModule, _super);
|
|
62
|
+
function ManagedModule(moduleName) {
|
|
63
|
+
return _super.call(this, moduleName) || this;
|
|
64
|
+
}
|
|
65
|
+
Object.defineProperty(ManagedModule.prototype, "name", {
|
|
66
|
+
get: function () {
|
|
67
|
+
return this._moduleName;
|
|
68
|
+
},
|
|
69
|
+
enumerable: false,
|
|
70
|
+
configurable: true
|
|
71
|
+
});
|
|
72
|
+
ManagedModule.prototype.initialize = function (grpcSdk) {
|
|
73
|
+
this.grpcSdk = grpcSdk;
|
|
74
|
+
};
|
|
75
|
+
ManagedModule.prototype.preServerStart = function () {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}); });
|
|
79
|
+
};
|
|
80
|
+
ManagedModule.prototype.onServerStart = function () {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
82
|
+
return [2 /*return*/];
|
|
83
|
+
}); });
|
|
84
|
+
};
|
|
85
|
+
ManagedModule.prototype.preRegister = function () {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
87
|
+
return [2 /*return*/];
|
|
88
|
+
}); });
|
|
89
|
+
};
|
|
90
|
+
ManagedModule.prototype.onRegister = function () {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}); });
|
|
94
|
+
};
|
|
95
|
+
ManagedModule.prototype.preConfig = function (config) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
return [2 /*return*/, config];
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
ManagedModule.prototype.onConfig = function () {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
104
|
+
return [2 /*return*/];
|
|
105
|
+
}); });
|
|
106
|
+
};
|
|
107
|
+
ManagedModule.prototype.createGrpcServer = function (servicePort) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var _a;
|
|
110
|
+
return __generator(this, function (_b) {
|
|
111
|
+
switch (_b.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
this.grpcServer = new __1.GrpcServer(servicePort);
|
|
114
|
+
_a = this;
|
|
115
|
+
return [4 /*yield*/, this.grpcServer.createNewServer()];
|
|
116
|
+
case 1:
|
|
117
|
+
_a._port = (_b.sent()).toString();
|
|
118
|
+
return [2 /*return*/];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
ManagedModule.prototype.startGrpcServer = function () {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
return __generator(this, function (_a) {
|
|
126
|
+
switch (_a.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
if (!this.service) return [3 /*break*/, 4];
|
|
129
|
+
this._serviceName = this.service.protoDescription.substring(this.service.protoDescription.indexOf('.') + 1);
|
|
130
|
+
return [4 /*yield*/, this.grpcServer.addService(this.service.protoPath, this.service.protoDescription, this.service.functions)];
|
|
131
|
+
case 1:
|
|
132
|
+
_a.sent();
|
|
133
|
+
return [4 /*yield*/, this.addHealthCheckService()];
|
|
134
|
+
case 2:
|
|
135
|
+
_a.sent();
|
|
136
|
+
return [4 /*yield*/, this.grpcServer.start()];
|
|
137
|
+
case 3:
|
|
138
|
+
_a.sent();
|
|
139
|
+
console.log('gRPC server is online');
|
|
140
|
+
_a.label = 4;
|
|
141
|
+
case 4: return [2 /*return*/];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
ManagedModule.prototype.setConfig = function (call, callback) {
|
|
147
|
+
var _a;
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var config, moduleConfig, e_1;
|
|
150
|
+
return __generator(this, function (_b) {
|
|
151
|
+
switch (_b.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
_b.trys.push([0, 4, , 5]);
|
|
154
|
+
if (!this.config) {
|
|
155
|
+
return [2 /*return*/, callback({
|
|
156
|
+
code: grpc_js_1.status.INVALID_ARGUMENT,
|
|
157
|
+
message: 'Module is not configurable',
|
|
158
|
+
})];
|
|
159
|
+
}
|
|
160
|
+
config = JSON.parse(call.request.newConfig);
|
|
161
|
+
return [4 /*yield*/, this.preConfig(config)];
|
|
162
|
+
case 1:
|
|
163
|
+
config = _b.sent();
|
|
164
|
+
try {
|
|
165
|
+
this.config.load(config).validate();
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
return [2 /*return*/, callback({
|
|
169
|
+
code: grpc_js_1.status.INVALID_ARGUMENT,
|
|
170
|
+
message: 'Invalid configuration values',
|
|
171
|
+
})];
|
|
172
|
+
}
|
|
173
|
+
return [4 /*yield*/, this.grpcSdk.config.updateConfig(config, this.name)];
|
|
174
|
+
case 2:
|
|
175
|
+
moduleConfig = _b.sent();
|
|
176
|
+
ConfigController_1.ConfigController.getInstance().config = moduleConfig;
|
|
177
|
+
return [4 /*yield*/, this.onConfig()];
|
|
178
|
+
case 3:
|
|
179
|
+
_b.sent();
|
|
180
|
+
(_a = this.grpcSdk.bus) === null || _a === void 0 ? void 0 : _a.publish(lodash_1.kebabCase(this.name) + ':config:update', JSON.stringify(moduleConfig));
|
|
181
|
+
return [2 /*return*/, callback(null, { updatedConfig: JSON.stringify(moduleConfig) })];
|
|
182
|
+
case 4:
|
|
183
|
+
e_1 = _b.sent();
|
|
184
|
+
return [2 /*return*/, callback({ code: grpc_js_1.status.INTERNAL, message: e_1.message })];
|
|
185
|
+
case 5: return [2 /*return*/];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
ManagedModule.prototype.updateConfig = function (config) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
192
|
+
return __generator(this, function (_a) {
|
|
193
|
+
if (!this.config) {
|
|
194
|
+
throw new Error('Module is not configurable');
|
|
195
|
+
}
|
|
196
|
+
if (config) {
|
|
197
|
+
ConfigController_1.ConfigController.getInstance().config = config;
|
|
198
|
+
return [2 /*return*/, Promise.resolve()];
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return [2 /*return*/, this.grpcSdk.config.get(this.name).then(function (config) {
|
|
202
|
+
ConfigController_1.ConfigController.getInstance().config = config;
|
|
203
|
+
})];
|
|
204
|
+
}
|
|
205
|
+
return [2 /*return*/];
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
return ManagedModule;
|
|
210
|
+
}(ConduitServiceModule_1.ConduitServiceModule));
|
|
211
|
+
exports.ManagedModule = ManagedModule;
|
|
212
|
+
//# sourceMappingURL=ManagedModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManagedModule.js","sourceRoot":"","sources":["../../src/classes/ManagedModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wBAKY;AACZ,+DAA8D;AAC9D,uDAAsD;AACtD,iCAAmC;AACnC,yCAAuC;AAGvC;IAA+C,iCAAoB;IAIjE,uBAAsB,UAAkB;eACtC,kBAAM,UAAU,CAAC;IACnB,CAAC;IAED,sBAAI,+BAAI;aAAR;YACE,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;;;OAAA;IAED,kCAAU,GAAV,UAAW,OAAuB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEK,sCAAc,GAApB;;;;KAAyB;IAEnB,qCAAa,GAAnB;;;;KAAwB;IAElB,mCAAW,GAAjB;;;;KAAsB;IAEhB,kCAAU,GAAhB;;;;KAAqB;IAEf,iCAAS,GAAf,UAAgB,MAAS;;;gBACvB,sBAAO,MAAM,EAA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AAE,CAAC,MAAM,GAAG,MAAM,CAAC;oBAC/C,sBAAO,OAAO,CAAC,OAAO,EAAE,EAAC;iBAC1B;qBAAM;oBACL,sBAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAC,MAAS;4BACvD,mCAAgB,CAAC,WAAW,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;wBACjD,CAAC,CAAC,EAAC;iBACJ;;;;KACF;IACH,oBAAC;AAAD,CAAC,AA/FD,CAA+C,2CAAoB,GA+FlE;AA/FqB,sCAAa"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ManagedModule } from '..';
|
|
2
|
+
export declare class ModuleManager<T> {
|
|
3
|
+
private readonly module;
|
|
4
|
+
private readonly serviceAddress;
|
|
5
|
+
private readonly servicePort;
|
|
6
|
+
private readonly grpcSdk;
|
|
7
|
+
constructor(module: ManagedModule<T>);
|
|
8
|
+
start(): Promise<void>;
|
|
9
|
+
private preRegisterLifecycle;
|
|
10
|
+
private postRegisterLifecycle;
|
|
11
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (_) try {
|
|
37
|
+
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;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
exports.ModuleManager = void 0;
|
|
59
|
+
var __1 = __importStar(require(".."));
|
|
60
|
+
var ModuleManager = /** @class */ (function () {
|
|
61
|
+
function ModuleManager(module) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
this.module = module;
|
|
64
|
+
if (!process.env.CONDUIT_SERVER) {
|
|
65
|
+
throw new Error('CONDUIT_SERVER is undefined, specify Conduit server URL');
|
|
66
|
+
}
|
|
67
|
+
this.serviceAddress = process.env.SERVICE_IP
|
|
68
|
+
? process.env.SERVICE_IP.split(':')[0]
|
|
69
|
+
: '0.0.0.0';
|
|
70
|
+
this.servicePort = process.env.SERVICE_IP
|
|
71
|
+
? process.env.SERVICE_IP.split(':')[1]
|
|
72
|
+
: undefined;
|
|
73
|
+
try {
|
|
74
|
+
this.grpcSdk = new __1.default(process.env.CONDUIT_SERVER, function () {
|
|
75
|
+
return _this.module.healthState;
|
|
76
|
+
}, module.name);
|
|
77
|
+
}
|
|
78
|
+
catch (_a) {
|
|
79
|
+
throw new Error('Failed to initialize grpcSdk');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
ModuleManager.prototype.start = function () {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var self, url, err_1;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
|
+
case 0: return [4 /*yield*/, this.grpcSdk.initialize()];
|
|
88
|
+
case 1:
|
|
89
|
+
_a.sent();
|
|
90
|
+
this.module.initialize(this.grpcSdk);
|
|
91
|
+
self = this;
|
|
92
|
+
_a.label = 2;
|
|
93
|
+
case 2:
|
|
94
|
+
_a.trys.push([2, 5, , 6]);
|
|
95
|
+
return [4 /*yield*/, this.preRegisterLifecycle()];
|
|
96
|
+
case 3:
|
|
97
|
+
_a.sent();
|
|
98
|
+
url = (process.env.REGISTER_NAME === 'true'
|
|
99
|
+
? self.module.name + ":"
|
|
100
|
+
: self.serviceAddress + ":") + self.module.port;
|
|
101
|
+
return [4 /*yield*/, self.grpcSdk.config.registerModule(self.module.name, url, this.module.healthState)];
|
|
102
|
+
case 4:
|
|
103
|
+
_a.sent();
|
|
104
|
+
return [3 /*break*/, 6];
|
|
105
|
+
case 5:
|
|
106
|
+
err_1 = _a.sent();
|
|
107
|
+
console.log('Failed to initialize server');
|
|
108
|
+
console.error(err_1);
|
|
109
|
+
process.exit(-1);
|
|
110
|
+
return [3 /*break*/, 6];
|
|
111
|
+
case 6: return [4 /*yield*/, this.postRegisterLifecycle().catch(function (err) {
|
|
112
|
+
console.log('Failed to activate module');
|
|
113
|
+
console.error(err);
|
|
114
|
+
})];
|
|
115
|
+
case 7:
|
|
116
|
+
_a.sent();
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
ModuleManager.prototype.preRegisterLifecycle = function () {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
switch (_a.label) {
|
|
126
|
+
case 0: return [4 /*yield*/, this.module.createGrpcServer(this.servicePort)];
|
|
127
|
+
case 1:
|
|
128
|
+
_a.sent();
|
|
129
|
+
return [4 /*yield*/, this.module.preServerStart()];
|
|
130
|
+
case 2:
|
|
131
|
+
_a.sent();
|
|
132
|
+
return [4 /*yield*/, this.grpcSdk.initializeEventBus()];
|
|
133
|
+
case 3:
|
|
134
|
+
_a.sent();
|
|
135
|
+
return [4 /*yield*/, this.module.startGrpcServer()];
|
|
136
|
+
case 4:
|
|
137
|
+
_a.sent();
|
|
138
|
+
return [4 /*yield*/, this.module.onServerStart()];
|
|
139
|
+
case 5:
|
|
140
|
+
_a.sent();
|
|
141
|
+
return [4 /*yield*/, this.module.preRegister()];
|
|
142
|
+
case 6:
|
|
143
|
+
_a.sent();
|
|
144
|
+
return [2 /*return*/];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
ModuleManager.prototype.postRegisterLifecycle = function () {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
+
var config, e_1;
|
|
152
|
+
return __generator(this, function (_a) {
|
|
153
|
+
switch (_a.label) {
|
|
154
|
+
case 0: return [4 /*yield*/, this.module.onRegister()];
|
|
155
|
+
case 1:
|
|
156
|
+
_a.sent();
|
|
157
|
+
if (!this.module.config) return [3 /*break*/, 9];
|
|
158
|
+
config = void 0;
|
|
159
|
+
_a.label = 2;
|
|
160
|
+
case 2:
|
|
161
|
+
_a.trys.push([2, 4, , 6]);
|
|
162
|
+
return [4 /*yield*/, this.grpcSdk.config.get(this.module.name)];
|
|
163
|
+
case 3:
|
|
164
|
+
_a.sent();
|
|
165
|
+
return [3 /*break*/, 6];
|
|
166
|
+
case 4:
|
|
167
|
+
e_1 = _a.sent();
|
|
168
|
+
return [4 /*yield*/, this.grpcSdk.config.updateConfig(this.module.config.getProperties(), this.module.name)];
|
|
169
|
+
case 5:
|
|
170
|
+
_a.sent();
|
|
171
|
+
return [3 /*break*/, 6];
|
|
172
|
+
case 6: return [4 /*yield*/, this.grpcSdk.config.addFieldsToConfig(this.module.config.getProperties(), this.module.name)];
|
|
173
|
+
case 7:
|
|
174
|
+
config = _a.sent();
|
|
175
|
+
__1.ConfigController.getInstance();
|
|
176
|
+
if (config)
|
|
177
|
+
__1.ConfigController.getInstance().config = config;
|
|
178
|
+
if (!(!config || config.active)) return [3 /*break*/, 9];
|
|
179
|
+
return [4 /*yield*/, this.module.onConfig()];
|
|
180
|
+
case 8:
|
|
181
|
+
_a.sent();
|
|
182
|
+
_a.label = 9;
|
|
183
|
+
case 9: return [2 /*return*/];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
return ModuleManager;
|
|
189
|
+
}());
|
|
190
|
+
exports.ModuleManager = ModuleManager;
|
|
191
|
+
//# sourceMappingURL=ModuleManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModuleManager.js","sourceRoot":"","sources":["../../src/classes/ModuleManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAqE;AAErE;IAKE,uBAA6B,MAAwB;QAArD,iBAqBC;QArB4B,WAAM,GAAN,MAAM,CAAkB;QACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;SAC5E;QACD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU;YAC1C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACtC,CAAC,CAAC,SAAS,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU;YACvC,CAAC,C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;;wBAHD,SAGC,CAAC;;4BAEK,qBAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAClD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,EAClC,IAAI,CAAC,MAAM,CAAC,IAAI,CACjB,EAAA;;wBAHD,MAAM,GAAG,SAGR,CAAC;wBACF,oBAAgB,CAAC,WAAW,EAAE,CAAC;wBAC/B,IAAI,MAAM;4BAAE,oBAAgB,CAAC,WAAW,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC;6BACvD,CAAA,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAA,EAAxB,wBAAwB;wBAAE,qBAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAA;;wBAA5B,SAA4B,CAAC;;;;;;KAE9D;IACH,oBAAC;AAAD,CAAC,AApFD,IAoFC;AApFY,sCAAa"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ConduitModel, ConduitRouteActions, ConduitRouteOption, ConduitRouteOptions } from '../../interfaces';
|
|
2
|
+
import { ConduitRouteReturnDefinition } from '../ConduitRouteReturn';
|
|
3
|
+
import { RequestHandlers } from '../../helpers';
|
|
4
|
+
import { RoutingManager } from './RoutingManager';
|
|
5
|
+
export declare class RouteBuilder {
|
|
6
|
+
private readonly manager?;
|
|
7
|
+
private readonly _options;
|
|
8
|
+
private _returns;
|
|
9
|
+
private _handler;
|
|
10
|
+
constructor(manager?: RoutingManager | undefined);
|
|
11
|
+
method(action: ConduitRouteActions): RouteBuilder;
|
|
12
|
+
name(name: string): RouteBuilder;
|
|
13
|
+
description(description: string): RouteBuilder;
|
|
14
|
+
cacheControl(cache: string): RouteBuilder;
|
|
15
|
+
middleware(middleware: string | string[], allowDuplicates?: boolean): RouteBuilder;
|
|
16
|
+
path(path: string): RouteBuilder;
|
|
17
|
+
queryParams(params: ConduitRouteOption | ConduitModel): RouteBuilder;
|
|
18
|
+
urlParams(params: ConduitRouteOption | ConduitModel): RouteBuilder;
|
|
19
|
+
bodyParams(params: ConduitRouteOption | ConduitModel): RouteBuilder;
|
|
20
|
+
return(name: string, fields: ConduitModel | string): RouteBuilder;
|
|
21
|
+
handler(fn: RequestHandlers): RouteBuilder;
|
|
22
|
+
add(): void;
|
|
23
|
+
build(): {
|
|
24
|
+
input: ConduitRouteOptions;
|
|
25
|
+
returnType: ConduitRouteReturnDefinition;
|
|
26
|
+
handler: RequestHandlers;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteBuilder = void 0;
|
|
4
|
+
var ConduitRouteReturn_1 = require("../ConduitRouteReturn");
|
|
5
|
+
var RouteBuilder = /** @class */ (function () {
|
|
6
|
+
function RouteBuilder(manager) {
|
|
7
|
+
this.manager = manager;
|
|
8
|
+
this._options = {};
|
|
9
|
+
}
|
|
10
|
+
RouteBuilder.prototype.method = function (action) {
|
|
11
|
+
this._options.action = action;
|
|
12
|
+
return this;
|
|
13
|
+
};
|
|
14
|
+
RouteBuilder.prototype.name = function (name) {
|
|
15
|
+
this._options.name = name;
|
|
16
|
+
return this;
|
|
17
|
+
};
|
|
18
|
+
RouteBuilder.prototype.description = function (description) {
|
|
19
|
+
this._options.description = description;
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
RouteBuilder.prototype.cacheControl = function (cache) {
|
|
23
|
+
this._options.cacheControl = cache;
|
|
24
|
+
return this;
|
|
25
|
+
};
|
|
26
|
+
RouteBuilder.prototype.middleware = function (middleware, allowDuplicates) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
if (allowDuplicates === void 0) { allowDuplicates = false; }
|
|
30
|
+
if (!Array.isArray(middleware)) {
|
|
31
|
+
middleware = [middleware];
|
|
32
|
+
}
|
|
33
|
+
if (this._options.middlewares !== undefined &&
|
|
34
|
+
((_a = this._options.middlewares) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
|
|
35
|
+
if (allowDuplicates) {
|
|
36
|
+
(_b = this._options.middlewares) === null || _b === void 0 ? void 0 : _b.concat(middleware);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// add to existing middlewares and filter out potential duplicates
|
|
40
|
+
(_c = this._options.middlewares) === null || _c === void 0 ? void 0 : _c.concat(middleware.filter(function (mid) { var _a; return ((_a = _this._options.middlewares) === null || _a === void 0 ? void 0 : _a.indexOf(mid)) === -1; }));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this._options.middlewares = middleware;
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
47
|
+
};
|
|
48
|
+
RouteBuilder.prototype.path = function (path) {
|
|
49
|
+
this._options.path = path;
|
|
50
|
+
return this;
|
|
51
|
+
};
|
|
52
|
+
RouteBuilder.prototype.queryParams = function (params) {
|
|
53
|
+
this._options.queryParams = params;
|
|
54
|
+
return this;
|
|
55
|
+
};
|
|
56
|
+
RouteBuilder.prototype.urlParams = function (params) {
|
|
57
|
+
this._options.urlParams = params;
|
|
58
|
+
return this;
|
|
59
|
+
};
|
|
60
|
+
RouteBuilder.prototype.bodyParams = function (params) {
|
|
61
|
+
this._options.bodyParams = params;
|
|
62
|
+
return this;
|
|
63
|
+
};
|
|
64
|
+
RouteBuilder.prototype.return = function (name, fields) {
|
|
65
|
+
this._returns = new ConduitRouteReturn_1.ConduitRouteReturnDefinition(name, fields);
|
|
66
|
+
return this;
|
|
67
|
+
};
|
|
68
|
+
RouteBuilder.prototype.handler = function (fn) {
|
|
69
|
+
this._handler = fn;
|
|
70
|
+
return this;
|
|
71
|
+
};
|
|
72
|
+
RouteBuilder.prototype.add = function () {
|
|
73
|
+
if (!this.manager)
|
|
74
|
+
throw new Error('Builder not setup with manager');
|
|
75
|
+
if (!this._options)
|
|
76
|
+
throw new Error('Cannot build route without options');
|
|
77
|
+
if (!this._options.action)
|
|
78
|
+
throw new Error('Cannot build route without action');
|
|
79
|
+
if (!this._options.path)
|
|
80
|
+
throw new Error('Cannot build route without action');
|
|
81
|
+
if (!this._returns)
|
|
82
|
+
throw new Error('Cannot build route without return');
|
|
83
|
+
if (!this._handler)
|
|
84
|
+
throw new Error('Cannot build route without handler');
|
|
85
|
+
this.manager.route(this._options, this._returns, this._handler);
|
|
86
|
+
};
|
|
87
|
+
RouteBuilder.prototype.build = function () {
|
|
88
|
+
if (!this._options)
|
|
89
|
+
throw new Error('Cannot build route without options');
|
|
90
|
+
if (!this._options.action)
|
|
91
|
+
throw new Error('Cannot build route without action');
|
|
92
|
+
if (!this._options.path)
|
|
93
|
+
throw new Error('Cannot build route without action');
|
|
94
|
+
if (!this._returns)
|
|
95
|
+
throw new Error('Cannot build route without return');
|
|
96
|
+
if (!this._handler)
|
|
97
|
+
throw new Error('Cannot build route without handler');
|
|
98
|
+
return {
|
|
99
|
+
input: this._options,
|
|
100
|
+
returnType: this._returns,
|
|
101
|
+
handler: this._handler,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
return RouteBuilder;
|
|
105
|
+
}());
|
|
106
|
+
exports.RouteBuilder = RouteBuilder;
|
|
107
|
+
//# sourceMappingURL=RouteBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteBuilder.js","sourceRoot":"","sources":["../../../src/classes/Routing/RouteBuilder.ts"],"names":[],"mappings":";;;AAMA,4DAAqE;AAIrE;IAKE,sBAA6B,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QACnD,IAAI,CAAC,QAAQ,GAAG,EAAS,CAAC;IAC5B,CAAC;IAED,6BAAM,GAAN,UAAO,MAA2B;QAChC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,2BAAI,GAAJ,UAAK,IAAY;QACf,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG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,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClE,CAAC;IAED,4BAAK,GAAL;QAKE,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC1E,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAChF,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACzE,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC1E,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,QAAQ;YACpB,UAAU,EAAE,IAAI,CAAC,QAAQ;YACzB,OAAO,EAAE,IAAI,CAAC,QAAQ;SACvB,CAAC;IACJ,CAAC;IACH,mBAAC;AAAD,CAAC,AA3GD,IA2GC;AA3GY,oCAAY"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ConduitMiddlewareOptions, ConduitRouteOptions, ConduitSocketEventHandler, ConduitSocketOptions } from '../../interfaces';
|
|
2
|
+
import { ParsedRouterRequest, UnparsedRouterResponse } from '../../types';
|
|
3
|
+
import { ConduitRouteReturnDefinition, GrpcServer } from '../index';
|
|
4
|
+
import { Router } from '../../modules';
|
|
5
|
+
import { RequestHandlers } from '../../helpers';
|
|
6
|
+
import { RouteBuilder } from './RouteBuilder';
|
|
7
|
+
export declare class RoutingManager {
|
|
8
|
+
private readonly _router;
|
|
9
|
+
private readonly _server;
|
|
10
|
+
private _moduleRoutes;
|
|
11
|
+
private _routeHandlers;
|
|
12
|
+
constructor(_router: Router, _server: GrpcServer);
|
|
13
|
+
get(path: string): RouteBuilder;
|
|
14
|
+
post(path: string): RouteBuilder;
|
|
15
|
+
delete(path: string): RouteBuilder;
|
|
16
|
+
update(path: string): RouteBuilder;
|
|
17
|
+
patch(path: string): RouteBuilder;
|
|
18
|
+
clear(): void;
|
|
19
|
+
middleware(input: ConduitMiddlewareOptions, handler: (request: ParsedRouterRequest) => Promise<UnparsedRouterResponse>): void;
|
|
20
|
+
route(input: ConduitRouteOptions, type: ConduitRouteReturnDefinition, handler: RequestHandlers): void;
|
|
21
|
+
socket(input: ConduitSocketOptions, events: Record<string, ConduitSocketEventHandler>): void;
|
|
22
|
+
registerRoutes(): Promise<any>;
|
|
23
|
+
private generateGrpcName;
|
|
24
|
+
private extractNameFromPath;
|
|
25
|
+
}
|