@conduitplatform/grpc-sdk 0.16.0-alpha.2 → 0.16.0-alpha.21

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.
Files changed (249) hide show
  1. package/README.mdx +1 -7
  2. package/dist/classes/ConduitAuthorizedResource.js +5 -6
  3. package/dist/classes/ConduitAuthorizedResource.js.map +1 -1
  4. package/dist/classes/ConduitModule.d.ts +9 -6
  5. package/dist/classes/ConduitModule.js +68 -141
  6. package/dist/classes/ConduitModule.js.map +1 -1
  7. package/dist/classes/ConduitSchema.js +3 -4
  8. package/dist/classes/ConduitSchema.js.map +1 -1
  9. package/dist/classes/Error.js +17 -40
  10. package/dist/classes/Error.js.map +1 -1
  11. package/dist/classes/HealthCheck.js +30 -71
  12. package/dist/classes/HealthCheck.js.map +1 -1
  13. package/dist/classes/index.d.ts +2 -6
  14. package/dist/classes/index.js +2 -6
  15. package/dist/classes/index.js.map +1 -1
  16. package/dist/index.d.ts +34 -31
  17. package/dist/index.js +331 -499
  18. package/dist/index.js.map +1 -1
  19. package/dist/interceptors/grpcSignedToken.d.ts +1 -1
  20. package/dist/interceptors/grpcSignedToken.js +7 -79
  21. package/dist/interceptors/grpcSignedToken.js.map +1 -1
  22. package/dist/interceptors/moduleName.d.ts +1 -1
  23. package/dist/interceptors/moduleName.js +7 -79
  24. package/dist/interceptors/moduleName.js.map +1 -1
  25. package/dist/interfaces/ConduitMiddleware.js.map +1 -0
  26. package/dist/{routing/interfaces → interfaces}/ConduitRoute.d.ts +2 -3
  27. package/dist/interfaces/ConduitRoute.js.map +1 -0
  28. package/dist/{routing → interfaces}/ConduitRouteReturn.d.ts +3 -3
  29. package/dist/{routing → interfaces}/ConduitRouteReturn.js +9 -18
  30. package/dist/interfaces/ConduitRouteReturn.js.map +1 -0
  31. package/dist/interfaces/ConduitSchemaExtension.d.ts +1 -1
  32. package/dist/interfaces/GrpcCallback.d.ts +1 -1
  33. package/dist/{utilities/Logger.d.ts → interfaces/IConduitLogger.d.ts} +4 -7
  34. package/dist/interfaces/{ConduitService.js → IConduitLogger.js} +1 -1
  35. package/dist/interfaces/IConduitLogger.js.map +1 -0
  36. package/dist/{metrics/index.d.ts → interfaces/IConduitMetrics.d.ts} +5 -11
  37. package/dist/interfaces/IConduitMetrics.js +3 -0
  38. package/dist/interfaces/IConduitMetrics.js.map +1 -0
  39. package/dist/interfaces/Indexable.d.ts +7 -8
  40. package/dist/interfaces/Model.d.ts +66 -13
  41. package/dist/interfaces/Model.js.map +1 -1
  42. package/dist/interfaces/Params.d.ts +3 -3
  43. package/dist/interfaces/ProxyRoute.js.map +1 -0
  44. package/dist/interfaces/RawQuery.d.ts +2 -2
  45. package/dist/interfaces/Route.d.ts +64 -0
  46. package/dist/interfaces/Route.js +12 -0
  47. package/dist/interfaces/Route.js.map +1 -0
  48. package/dist/{routing/interfaces → interfaces}/Socket.d.ts +4 -5
  49. package/dist/interfaces/Socket.js.map +1 -0
  50. package/dist/interfaces/UntypedArray.d.ts +1 -1
  51. package/dist/interfaces/index.d.ts +9 -2
  52. package/dist/interfaces/index.js +9 -2
  53. package/dist/interfaces/index.js.map +1 -1
  54. package/dist/{routing/interfaces → interfaces}/types.d.ts +11 -9
  55. package/dist/{routing/interfaces → interfaces}/types.js.map +1 -1
  56. package/dist/module.proto +72 -0
  57. package/dist/modules/admin/index.d.ts +5 -5
  58. package/dist/modules/admin/index.js +18 -37
  59. package/dist/modules/admin/index.js.map +1 -1
  60. package/dist/modules/authentication/index.d.ts +5 -2
  61. package/dist/modules/authentication/index.js +30 -40
  62. package/dist/modules/authentication/index.js.map +1 -1
  63. package/dist/modules/authorization/index.d.ts +6 -2
  64. package/dist/modules/authorization/index.js +38 -47
  65. package/dist/modules/authorization/index.js.map +1 -1
  66. package/dist/modules/chat/index.js +16 -34
  67. package/dist/modules/chat/index.js.map +1 -1
  68. package/dist/modules/config/index.d.ts +14 -5
  69. package/dist/modules/config/index.js +85 -177
  70. package/dist/modules/config/index.js.map +1 -1
  71. package/dist/modules/core/index.js +8 -26
  72. package/dist/modules/core/index.js.map +1 -1
  73. package/dist/modules/database/index.d.ts +24 -14
  74. package/dist/modules/database/index.js +193 -134
  75. package/dist/modules/database/index.js.map +1 -1
  76. package/dist/modules/email/index.js +15 -33
  77. package/dist/modules/email/index.js.map +1 -1
  78. package/dist/modules/index.d.ts +0 -2
  79. package/dist/modules/index.js +0 -2
  80. package/dist/modules/index.js.map +1 -1
  81. package/dist/modules/pushNotifications/index.js +38 -56
  82. package/dist/modules/pushNotifications/index.js.map +1 -1
  83. package/dist/modules/router/index.d.ts +5 -5
  84. package/dist/modules/router/index.js +20 -39
  85. package/dist/modules/router/index.js.map +1 -1
  86. package/dist/modules/sms/index.js +17 -35
  87. package/dist/modules/sms/index.js.map +1 -1
  88. package/dist/modules/storage/index.d.ts +8 -4
  89. package/dist/modules/storage/index.js +66 -37
  90. package/dist/modules/storage/index.js.map +1 -1
  91. package/dist/protoUtils/authentication.d.ts +127 -46
  92. package/dist/protoUtils/authentication.js +481 -220
  93. package/dist/protoUtils/authentication.js.map +1 -1
  94. package/dist/protoUtils/authorization.d.ts +147 -82
  95. package/dist/protoUtils/authorization.js +684 -512
  96. package/dist/protoUtils/authorization.js.map +1 -1
  97. package/dist/protoUtils/chat.d.ts +7 -61
  98. package/dist/protoUtils/chat.js +130 -313
  99. package/dist/protoUtils/chat.js.map +1 -1
  100. package/dist/protoUtils/core.d.ts +88 -107
  101. package/dist/protoUtils/core.js +699 -733
  102. package/dist/protoUtils/core.js.map +1 -1
  103. package/dist/protoUtils/database.d.ts +195 -15
  104. package/dist/protoUtils/database.js +1077 -666
  105. package/dist/protoUtils/database.js.map +1 -1
  106. package/dist/protoUtils/email.d.ts +3 -48
  107. package/dist/protoUtils/email.js +145 -284
  108. package/dist/protoUtils/email.js.map +1 -1
  109. package/dist/protoUtils/google/protobuf/empty.d.ts +27 -0
  110. package/dist/protoUtils/google/protobuf/empty.js +46 -0
  111. package/dist/protoUtils/google/protobuf/empty.js.map +1 -0
  112. package/dist/protoUtils/grpc_health_check.d.ts +3 -4
  113. package/dist/protoUtils/grpc_health_check.js +37 -36
  114. package/dist/protoUtils/grpc_health_check.js.map +1 -1
  115. package/dist/protoUtils/index.d.ts +12 -0
  116. package/dist/{routing/interfaces → protoUtils}/index.js +12 -6
  117. package/dist/protoUtils/index.js.map +1 -0
  118. package/dist/protoUtils/module.d.ts +251 -0
  119. package/dist/protoUtils/module.js +874 -0
  120. package/dist/protoUtils/module.js.map +1 -0
  121. package/dist/protoUtils/push-notifications.d.ts +7 -50
  122. package/dist/protoUtils/push-notifications.js +269 -356
  123. package/dist/protoUtils/push-notifications.js.map +1 -1
  124. package/dist/protoUtils/router.d.ts +45 -111
  125. package/dist/protoUtils/router.js +357 -575
  126. package/dist/protoUtils/router.js.map +1 -1
  127. package/dist/protoUtils/sms.d.ts +3 -48
  128. package/dist/protoUtils/sms.js +120 -219
  129. package/dist/protoUtils/sms.js.map +1 -1
  130. package/dist/protoUtils/storage.d.ts +144 -62
  131. package/dist/protoUtils/storage.js +782 -282
  132. package/dist/protoUtils/storage.js.map +1 -1
  133. package/dist/types/db.d.ts +11 -11
  134. package/dist/types/index.d.ts +3 -10
  135. package/dist/types/index.js +21 -24
  136. package/dist/types/index.js.map +1 -1
  137. package/dist/utilities/EventBus.d.ts +3 -1
  138. package/dist/utilities/EventBus.js +38 -17
  139. package/dist/utilities/EventBus.js.map +1 -1
  140. package/dist/utilities/RedisManager.js +11 -21
  141. package/dist/utilities/RedisManager.js.map +1 -1
  142. package/dist/utilities/StateManager.js +13 -14
  143. package/dist/utilities/StateManager.js.map +1 -1
  144. package/dist/utilities/env.js +4 -4
  145. package/dist/utilities/env.js.map +1 -1
  146. package/dist/utilities/index.d.ts +3 -2
  147. package/dist/utilities/index.js +3 -2
  148. package/dist/utilities/index.js.map +1 -1
  149. package/dist/utilities/sleep.js +1 -1
  150. package/dist/utilities/sleep.js.map +1 -1
  151. package/package.json +24 -25
  152. package/dist/classes/ConduitActiveSchema.d.ts +0 -19
  153. package/dist/classes/ConduitActiveSchema.js +0 -57
  154. package/dist/classes/ConduitActiveSchema.js.map +0 -1
  155. package/dist/classes/ConduitServiceModule.d.ts +0 -26
  156. package/dist/classes/ConduitServiceModule.js +0 -166
  157. package/dist/classes/ConduitServiceModule.js.map +0 -1
  158. package/dist/classes/ConfigController.d.ts +0 -7
  159. package/dist/classes/ConfigController.js +0 -27
  160. package/dist/classes/ConfigController.js.map +0 -1
  161. package/dist/classes/GrpcServer.d.ts +0 -22
  162. package/dist/classes/GrpcServer.js +0 -207
  163. package/dist/classes/GrpcServer.js.map +0 -1
  164. package/dist/classes/ManagedModule.d.ts +0 -74
  165. package/dist/classes/ManagedModule.js +0 -333
  166. package/dist/classes/ManagedModule.js.map +0 -1
  167. package/dist/classes/ModuleManager.d.ts +0 -11
  168. package/dist/classes/ModuleManager.js +0 -204
  169. package/dist/classes/ModuleManager.js.map +0 -1
  170. package/dist/helpers/GrpcHelper.d.ts +0 -8
  171. package/dist/helpers/GrpcHelper.js +0 -43
  172. package/dist/helpers/GrpcHelper.js.map +0 -1
  173. package/dist/helpers/TypeHelpers.d.ts +0 -44
  174. package/dist/helpers/TypeHelpers.js +0 -144
  175. package/dist/helpers/TypeHelpers.js.map +0 -1
  176. package/dist/helpers/index.d.ts +0 -3
  177. package/dist/helpers/index.js +0 -20
  178. package/dist/helpers/index.js.map +0 -1
  179. package/dist/helpers/wrapGrpcFunctions.d.ts +0 -5
  180. package/dist/helpers/wrapGrpcFunctions.js +0 -56
  181. package/dist/helpers/wrapGrpcFunctions.js.map +0 -1
  182. package/dist/interfaces/ConduitService.d.ts +0 -8
  183. package/dist/interfaces/ConduitService.js.map +0 -1
  184. package/dist/metrics/MetricsServer.d.ts +0 -9
  185. package/dist/metrics/MetricsServer.js +0 -94
  186. package/dist/metrics/MetricsServer.js.map +0 -1
  187. package/dist/metrics/clientMiddleware.d.ts +0 -2
  188. package/dist/metrics/clientMiddleware.js +0 -265
  189. package/dist/metrics/clientMiddleware.js.map +0 -1
  190. package/dist/metrics/config/defaults.d.ts +0 -91
  191. package/dist/metrics/config/defaults.js +0 -93
  192. package/dist/metrics/config/defaults.js.map +0 -1
  193. package/dist/metrics/index.js +0 -152
  194. package/dist/metrics/index.js.map +0 -1
  195. package/dist/modules/forms/index.d.ts +0 -6
  196. package/dist/modules/forms/index.js +0 -32
  197. package/dist/modules/forms/index.js.map +0 -1
  198. package/dist/modules/functions/index.d.ts +0 -6
  199. package/dist/modules/functions/index.js +0 -32
  200. package/dist/modules/functions/index.js.map +0 -1
  201. package/dist/protoUtils/forms.d.ts +0 -58
  202. package/dist/protoUtils/forms.js +0 -127
  203. package/dist/protoUtils/forms.js.map +0 -1
  204. package/dist/protoUtils/functions.d.ts +0 -58
  205. package/dist/protoUtils/functions.js +0 -127
  206. package/dist/protoUtils/functions.js.map +0 -1
  207. package/dist/routing/ConduitRouteReturn.js.map +0 -1
  208. package/dist/routing/ProxyRouteBuilder.d.ts +0 -21
  209. package/dist/routing/ProxyRouteBuilder.js +0 -81
  210. package/dist/routing/ProxyRouteBuilder.js.map +0 -1
  211. package/dist/routing/RouteBuilder.d.ts +0 -24
  212. package/dist/routing/RouteBuilder.js +0 -107
  213. package/dist/routing/RouteBuilder.js.map +0 -1
  214. package/dist/routing/RoutingManager.d.ts +0 -33
  215. package/dist/routing/RoutingManager.js +0 -201
  216. package/dist/routing/RoutingManager.js.map +0 -1
  217. package/dist/routing/RoutingUtilities.d.ts +0 -7
  218. package/dist/routing/RoutingUtilities.js +0 -13
  219. package/dist/routing/RoutingUtilities.js.map +0 -1
  220. package/dist/routing/index.d.ts +0 -7
  221. package/dist/routing/index.js +0 -24
  222. package/dist/routing/index.js.map +0 -1
  223. package/dist/routing/interfaces/ConduitMiddleware.js.map +0 -1
  224. package/dist/routing/interfaces/ConduitRoute.js.map +0 -1
  225. package/dist/routing/interfaces/ProxyRoute.js.map +0 -1
  226. package/dist/routing/interfaces/Route.d.ts +0 -52
  227. package/dist/routing/interfaces/Route.js +0 -21
  228. package/dist/routing/interfaces/Route.js.map +0 -1
  229. package/dist/routing/interfaces/Socket.js.map +0 -1
  230. package/dist/routing/interfaces/index.d.ts +0 -6
  231. package/dist/routing/interfaces/index.js.map +0 -1
  232. package/dist/routing/wrapRouterFunctions.d.ts +0 -8
  233. package/dist/routing/wrapRouterFunctions.js +0 -132
  234. package/dist/routing/wrapRouterFunctions.js.map +0 -1
  235. package/dist/utilities/Logger.js +0 -255
  236. package/dist/utilities/Logger.js.map +0 -1
  237. package/dist/utilities/linearBackoffTimeout.d.ts +0 -10
  238. package/dist/utilities/linearBackoffTimeout.js +0 -119
  239. package/dist/utilities/linearBackoffTimeout.js.map +0 -1
  240. package/dist/utilities/merge.d.ts +0 -1
  241. package/dist/utilities/merge.js +0 -15
  242. package/dist/utilities/merge.js.map +0 -1
  243. /package/dist/{routing/interfaces → interfaces}/ConduitMiddleware.d.ts +0 -0
  244. /package/dist/{routing/interfaces → interfaces}/ConduitMiddleware.js +0 -0
  245. /package/dist/{routing/interfaces → interfaces}/ConduitRoute.js +0 -0
  246. /package/dist/{routing/interfaces → interfaces}/ProxyRoute.d.ts +0 -0
  247. /package/dist/{routing/interfaces → interfaces}/ProxyRoute.js +0 -0
  248. /package/dist/{routing/interfaces → interfaces}/Socket.js +0 -0
  249. /package/dist/{routing/interfaces → interfaces}/types.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conduitplatform/grpc-sdk",
3
- "version": "0.16.0-alpha.2",
3
+ "version": "0.16.0-alpha.21",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "engines": {
@@ -15,24 +15,24 @@
15
15
  },
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "@grpc/grpc-js": "^1.6.7",
19
- "@grpc/proto-loader": "^0.6.13",
18
+ "@grpc/grpc-js": "^1.8.13",
19
+ "@grpc/proto-loader": "^0.7.6",
20
20
  "@types/google-protobuf": "^3.15.6",
21
21
  "@types/ioredis": "^4.28.10",
22
- "@types/lodash": "^4.14.182",
23
- "abort-controller-x": "^0.4.0",
24
- "convict": "^6.2.3",
25
- "express": "^4.18.1",
26
- "fast-jwt": "^1.6.0",
27
- "fs-extra": "^10.1.0",
28
- "ioredis": "^5.1.0",
22
+ "@types/lodash": "^4.14.192",
23
+ "abort-controller-x": "^0.4.1",
24
+ "convict": "^6.2.4",
25
+ "express": "^4.18.2",
26
+ "fast-jwt": "^2.2.1",
27
+ "fs-extra": "^11.1.1",
28
+ "ioredis": "^5.3.1",
29
29
  "lodash": "^4.17.21",
30
- "nice-grpc": "^1.2.0",
31
- "nice-grpc-client-middleware-retry": "^1",
32
- "prom-client": "^14.0.1",
33
- "protobufjs": "^6.11.3",
34
- "winston": "^3.8.1",
35
- "winston-loki": "^6.0.5"
30
+ "nice-grpc": "^2.1.4",
31
+ "nice-grpc-client-middleware-retry": "^3",
32
+ "prom-client": "^14.2.0",
33
+ "protobufjs": "^7.2.4",
34
+ "winston": "^3.8.2",
35
+ "winston-loki": "^6.0.7"
36
36
  },
37
37
  "directories": {
38
38
  "lib": "dist",
@@ -48,19 +48,18 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@types/convict": "^6.1.1",
51
- "@types/express": "^4.17.13",
52
- "@types/fs-extra": "^9.0.13",
51
+ "@types/express": "^4.17.17",
52
+ "@types/fs-extra": "^11.0.1",
53
53
  "@types/google-protobuf": "^3.15.6",
54
54
  "@types/ioredis": "^4.28.10",
55
- "@types/lodash": "^4.14.182",
56
- "@types/node": "14.14.31",
55
+ "@types/lodash": "^4.14.192",
56
+ "@types/node": "18.15.11",
57
57
  "copyfiles": "^2.4.1",
58
- "rimraf": "^3.0.2",
59
- "ts-proto": "^1.117.0",
60
- "typescript": "~4.7.4"
58
+ "rimraf": "^5.0.0",
59
+ "ts-proto": "^1.159.2",
60
+ "typescript": "~5.0.4"
61
61
  },
62
62
  "peerDependencies": {
63
- "@grpc/grpc-js": "^1.5.2",
64
- "@grpc/proto-loader": "^0.6.13"
63
+ "@grpc/grpc-js": "^1.5.2"
65
64
  }
66
65
  }
@@ -1,19 +0,0 @@
1
- import { ConduitModel, ConduitSchemaOptions } from '../interfaces';
2
- import { ConduitSchema } from './ConduitSchema';
3
- import { DatabaseProvider } from '../modules';
4
- import { Query } from '../types/db';
5
- export declare class ConduitActiveSchema<T> extends ConduitSchema {
6
- private readonly dbInstance;
7
- constructor(dbInstance: DatabaseProvider, name: string, fields?: ConduitModel, modelOptions?: ConduitSchemaOptions, collectionName?: string);
8
- findOne(query: Query<T>, select?: string, populate?: string | string[]): Promise<T | null>;
9
- findMany(query: Query<T>, select?: string, skip?: number, limit?: number, sort?: {
10
- [field: string]: -1 | 1;
11
- } | string[] | string, populate?: string | string[]): Promise<T[]>;
12
- create(query: Query<T>): Promise<T>;
13
- createMany(query: Query<T>[]): Promise<T[]>;
14
- findByIdAndUpdate(id: string, document: Query<T>, populate?: string | string[]): Promise<T | null>;
15
- updateMany(filterQuery: Query<T>, query: Query<T>, populate?: string | string[]): Promise<any>;
16
- deleteOne(query: Query<T>): Promise<any>;
17
- deleteMany(query: Query<T>): Promise<any>;
18
- countDocuments(query: Query<T>): Promise<number>;
19
- }
@@ -1,57 +0,0 @@
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.ConduitActiveSchema = void 0;
19
- var ConduitSchema_1 = require("./ConduitSchema");
20
- var ConduitActiveSchema = /** @class */ (function (_super) {
21
- __extends(ConduitActiveSchema, _super);
22
- function ConduitActiveSchema(dbInstance, name, fields, modelOptions, collectionName) {
23
- var _this = _super.call(this, name, fields !== null && fields !== void 0 ? fields : {}, modelOptions, collectionName) || this;
24
- _this.dbInstance = dbInstance;
25
- return _this;
26
- }
27
- ConduitActiveSchema.prototype.findOne = function (query, select, populate) {
28
- return this.dbInstance.findOne(this.name, query, select, populate);
29
- };
30
- ConduitActiveSchema.prototype.findMany = function (query, select, skip, limit, sort, populate) {
31
- return this.dbInstance.findMany(this.name, query, select, skip, limit, sort, populate);
32
- };
33
- ConduitActiveSchema.prototype.create = function (query) {
34
- return this.dbInstance.create(this.name, query);
35
- };
36
- ConduitActiveSchema.prototype.createMany = function (query) {
37
- return this.dbInstance.createMany(this.name, query);
38
- };
39
- ConduitActiveSchema.prototype.findByIdAndUpdate = function (id, document, populate) {
40
- return this.dbInstance.findByIdAndUpdate(this.name, id, document, populate);
41
- };
42
- ConduitActiveSchema.prototype.updateMany = function (filterQuery, query, populate) {
43
- return this.dbInstance.updateMany(this.name, filterQuery, query, populate);
44
- };
45
- ConduitActiveSchema.prototype.deleteOne = function (query) {
46
- return this.dbInstance.deleteOne(this.name, query);
47
- };
48
- ConduitActiveSchema.prototype.deleteMany = function (query) {
49
- return this.dbInstance.deleteMany(this.name, query);
50
- };
51
- ConduitActiveSchema.prototype.countDocuments = function (query) {
52
- return this.dbInstance.countDocuments(this.name, query);
53
- };
54
- return ConduitActiveSchema;
55
- }(ConduitSchema_1.ConduitSchema));
56
- exports.ConduitActiveSchema = ConduitActiveSchema;
57
- //# sourceMappingURL=ConduitActiveSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConduitActiveSchema.js","sourceRoot":"","sources":["../../src/classes/ConduitActiveSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;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I,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7E,CAAC;IAED,uCAAS,GAAT,UAAU,KAAe;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,wCAAU,GAAV,UAAW,KAAe;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,4CAAc,GAAd,UAAe,KAAe;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC;IACH,0BAAC;AAAD,CAAC,AAxED,CAA4C,6BAAa,GAwExD;AAxEY,kDAAmB"}
@@ -1,26 +0,0 @@
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 _address: string;
12
- protected _port: string;
13
- protected grpcServer: GrpcServer;
14
- private _grpcSdk;
15
- private _serviceHealthState;
16
- protected readonly events: EventEmitter;
17
- protected constructor(moduleName: string);
18
- get healthState(): HealthCheckStatus;
19
- set grpcSdk(grpcSdk: ConduitGrpcSdk);
20
- get grpcSdk(): ConduitGrpcSdk;
21
- get port(): string;
22
- protected addHealthCheckService(): Promise<void>;
23
- updateHealth(state: HealthCheckStatus, init?: boolean): void;
24
- healthCheck(call: GrpcRequest<HealthCheckRequest>, callback: GrpcCallback<HealthCheckResponse>): void;
25
- healthWatch(call: ServerWritableStream<HealthCheckRequest, HealthCheckResponse>): void;
26
- }
@@ -1,166 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var __importDefault = (this && this.__importDefault) || function (mod) {
62
- return (mod && mod.__esModule) ? mod : { "default": mod };
63
- };
64
- Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.ConduitServiceModule = void 0;
66
- var __1 = __importStar(require(".."));
67
- var path_1 = __importDefault(require("path"));
68
- var events_1 = require("events");
69
- var lodash_1 = require("lodash");
70
- var ConduitServiceModule = /** @class */ (function () {
71
- function ConduitServiceModule(moduleName) {
72
- this._serviceHealthState = __1.HealthCheckStatus.SERVING; // default for health-agnostic modules
73
- this.events = new events_1.EventEmitter();
74
- this._moduleName = (0, lodash_1.camelCase)(moduleName);
75
- }
76
- Object.defineProperty(ConduitServiceModule.prototype, "healthState", {
77
- get: function () {
78
- return this._serviceHealthState;
79
- },
80
- enumerable: false,
81
- configurable: true
82
- });
83
- Object.defineProperty(ConduitServiceModule.prototype, "grpcSdk", {
84
- get: function () {
85
- if (!this._grpcSdk)
86
- throw new Error('grpcSdk not defined yet');
87
- return this._grpcSdk;
88
- },
89
- set: function (grpcSdk) {
90
- if (this._grpcSdk)
91
- throw new Error('grpcSdk already defined');
92
- this._grpcSdk = grpcSdk;
93
- },
94
- enumerable: false,
95
- configurable: true
96
- });
97
- Object.defineProperty(ConduitServiceModule.prototype, "port", {
98
- get: function () {
99
- return this._port;
100
- },
101
- enumerable: false,
102
- configurable: true
103
- });
104
- ConduitServiceModule.prototype.addHealthCheckService = function () {
105
- return __awaiter(this, void 0, void 0, function () {
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0: return [4 /*yield*/, this.grpcServer.addService(path_1.default.resolve(__dirname, '../grpc_health_check.proto'), 'grpc.health.v1.Health', {
109
- Check: this.healthCheck.bind(this),
110
- Watch: this.healthWatch.bind(this),
111
- })];
112
- case 1:
113
- _a.sent();
114
- return [2 /*return*/];
115
- }
116
- });
117
- });
118
- };
119
- ConduitServiceModule.prototype.updateHealth = function (state, init) {
120
- var _a, _b;
121
- if (init === void 0) { init = false; }
122
- if ((state === __1.HealthCheckStatus.UNKNOWN && !init) ||
123
- state === __1.HealthCheckStatus.SERVICE_UNKNOWN) {
124
- throw new Error("Cannot explicitly set gRPC health state to ".concat(__1.HealthCheckStatus[state]));
125
- }
126
- if (!init) {
127
- (_a = __1.default.Metrics) === null || _a === void 0 ? void 0 : _a.set('module_health_state', state === __1.HealthCheckStatus.SERVING ? 1 : 0);
128
- }
129
- if (this._serviceHealthState !== state) {
130
- this._serviceHealthState = state;
131
- this.events.emit("grpc-health-change:".concat(this._serviceName), state);
132
- (_b = this._grpcSdk) === null || _b === void 0 ? void 0 : _b.config.moduleHealthProbe(this._moduleName, this._address);
133
- }
134
- };
135
- ConduitServiceModule.prototype.healthCheck = function (call, callback) {
136
- var service = call.request.service.substring(call.request.service.indexOf('.') + 1);
137
- if (service && service !== this._serviceName) {
138
- callback(null, {
139
- status: __1.HealthCheckStatus.SERVICE_UNKNOWN,
140
- });
141
- }
142
- else {
143
- callback(null, {
144
- status: this._serviceHealthState,
145
- });
146
- }
147
- };
148
- ConduitServiceModule.prototype.healthWatch = function (call) {
149
- var service = call.request.service.substring(call.request.service.indexOf('.') + 1);
150
- if (service && service !== this._serviceName) {
151
- call.write({
152
- status: __1.HealthCheckStatus.SERVICE_UNKNOWN,
153
- });
154
- }
155
- else {
156
- this.events.on("grpc-health-change:".concat(this._serviceName), function (status) {
157
- call.write({
158
- status: status,
159
- });
160
- });
161
- }
162
- };
163
- return ConduitServiceModule;
164
- }());
165
- exports.ConduitServiceModule = ConduitServiceModule;
166
- //# sourceMappingURL=ConduitServiceModule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConduitServiceModule.js","sourceRoot":"","sources":["../../src/classes/ConduitServiceModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAmE;AACnE,8CAAwB;AACxB,iCAAsC;AACtC,iCAAmC;AAUnC;IAUE,8BAAsB,UAAkB;QAHhC,wBAAmB,GAAsB,qBAAiB,CAAC,OAAO,CAAC,CAAC,sCAAsC;QAC/F,WAAM,GAAiB,IAAI,qBAAY,EAAE,CAAC;QAG3D,IAAI,CAAC,WAAW,GAAG,IAAA,kBAAS,EAAC,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;QACv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@@ -1,7 +0,0 @@
1
- export declare class ConfigController {
2
- private static instance;
3
- private _config;
4
- get config(): any;
5
- set config(config: any);
6
- static getInstance(): ConfigController;
7
- }
@@ -1,27 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,22 +0,0 @@
1
- export declare class GrpcServer {
2
- private grpcServer?;
3
- private started;
4
- private startedOnce;
5
- private _serviceNames;
6
- private scheduledRestart;
7
- private _postponeRequests;
8
- private _useForce?;
9
- private _services;
10
- constructor(port?: string);
11
- private postponeRestart;
12
- private _url;
13
- get url(): string;
14
- createNewServer(useForce?: boolean): Promise<number>;
15
- addService(protoPath: string, protoDescription: string, functions: {
16
- [name: string]: Function;
17
- }): Promise<GrpcServer>;
18
- wait(time: number): Promise<void>;
19
- refresh(): Promise<void>;
20
- scheduleRefresh(): void;
21
- start(): void;
22
- }
@@ -1,207 +0,0 @@
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.GrpcServer = void 0;
43
- var helpers_1 = require("../helpers");
44
- var lodash_1 = require("lodash");
45
- var index_1 = __importDefault(require("../index"));
46
- var GrpcServer = /** @class */ (function () {
47
- function GrpcServer(port) {
48
- this.started = false;
49
- this.startedOnce = false;
50
- this._serviceNames = [];
51
- this._postponeRequests = 0;
52
- this._services = [];
53
- this._url = "0.0.0.0:".concat(port !== null && port !== void 0 ? port : '5000');
54
- }
55
- GrpcServer.prototype.postponeRestart = function () {
56
- if (!this.scheduledRestart || this._postponeRequests > 5)
57
- return;
58
- this._postponeRequests++;
59
- this.scheduleRefresh();
60
- };
61
- Object.defineProperty(GrpcServer.prototype, "url", {
62
- get: function () {
63
- return this._url;
64
- },
65
- enumerable: false,
66
- configurable: true
67
- });
68
- GrpcServer.prototype.createNewServer = function (useForce) {
69
- if (useForce === void 0) { useForce = false; }
70
- return __awaiter(this, void 0, void 0, function () {
71
- var serverResult;
72
- return __generator(this, function (_a) {
73
- switch (_a.label) {
74
- case 0:
75
- if ((0, lodash_1.isNil)(this._useForce)) {
76
- this._useForce = useForce;
77
- }
78
- return [4 /*yield*/, (0, helpers_1.createServer)(this._url)];
79
- case 1:
80
- serverResult = _a.sent();
81
- this.grpcServer = serverResult.server;
82
- this._url = this._url.split(':')[0] + ':' + serverResult.port.toString();
83
- return [2 /*return*/, serverResult.port];
84
- }
85
- });
86
- });
87
- };
88
- GrpcServer.prototype.addService = function (protoPath, protoDescription, functions) {
89
- return __awaiter(this, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0:
93
- functions = (0, helpers_1.wrapGrpcFunctions)(functions, this.postponeRestart.bind(this));
94
- if (!(this._serviceNames.indexOf(protoDescription) !== -1)) return [3 /*break*/, 1];
95
- index_1.default.Logger.log('Service already exists, performing replace');
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];
119
- }
120
- });
121
- });
122
- };
123
- GrpcServer.prototype.wait = function (time) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- return __generator(this, function (_a) {
126
- return [2 /*return*/, new Promise(function (resolve, reject) {
127
- var timeout = setTimeout(function () {
128
- clearTimeout(timeout);
129
- resolve();
130
- }, time);
131
- })];
132
- });
133
- });
134
- };
135
- GrpcServer.prototype.refresh = function () {
136
- return __awaiter(this, void 0, void 0, function () {
137
- var _this = this;
138
- return __generator(this, function (_a) {
139
- switch (_a.label) {
140
- case 0:
141
- if (!this.started) return [3 /*break*/, 3];
142
- this.started = false;
143
- if (!this._useForce) return [3 /*break*/, 1];
144
- this.grpcServer.forceShutdown();
145
- return [3 /*break*/, 3];
146
- case 1:
147
- //gracefully shutdown so that there are no service disruption
148
- return [4 /*yield*/, new Promise(function (resolve) { return _this.grpcServer.tryShutdown(function () { return resolve(); }); })];
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
- });
166
- });
167
- };
168
- GrpcServer.prototype.scheduleRefresh = function () {
169
- var _this = this;
170
- if (this.scheduledRestart) {
171
- clearTimeout(this.scheduledRestart);
172
- }
173
- var self = this;
174
- this.scheduledRestart = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
175
- return __generator(this, function (_a) {
176
- switch (_a.label) {
177
- case 0:
178
- index_1.default.Logger.log('Begin refresh');
179
- return [4 /*yield*/, self.refresh()];
180
- case 1:
181
- _a.sent();
182
- index_1.default.Logger.log('Refresh complete');
183
- clearTimeout(self.scheduledRestart);
184
- self.scheduledRestart = undefined;
185
- self._postponeRequests = 0;
186
- return [2 /*return*/];
187
- }
188
- });
189
- }); }, 2000);
190
- };
191
- GrpcServer.prototype.start = function () {
192
- var _a;
193
- if (this.started) {
194
- index_1.default.Logger.error('gRPC server is already running!');
195
- return;
196
- }
197
- else if (!this.started && this.startedOnce) {
198
- index_1.default.Logger.error('gRPC server is down for refresh!');
199
- }
200
- this.started = true;
201
- this.startedOnce = true;
202
- (_a = this.grpcServer) === null || _a === void 0 ? void 0 : _a.start();
203
- };
204
- return GrpcServer;
205
- }());
206
- exports.GrpcServer = GrpcServer;
207
- //# sourceMappingURL=Gr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