@magek/core 0.0.1

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 (195) hide show
  1. package/dist/authorizer.d.ts +7 -0
  2. package/dist/authorizer.js +35 -0
  3. package/dist/command-dispatcher.d.ts +8 -0
  4. package/dist/command-dispatcher.js +55 -0
  5. package/dist/core-concepts/data-migration/entities/data-migration-entity.d.ts +12 -0
  6. package/dist/core-concepts/data-migration/entities/data-migration-entity.js +37 -0
  7. package/dist/core-concepts/data-migration/events/data-migration-finished.d.ts +7 -0
  8. package/dist/core-concepts/data-migration/events/data-migration-finished.js +13 -0
  9. package/dist/core-concepts/data-migration/events/data-migration-started.d.ts +7 -0
  10. package/dist/core-concepts/data-migration/events/data-migration-started.js +13 -0
  11. package/dist/core-concepts/data-migration/events/entity-migrated.d.ts +9 -0
  12. package/dist/core-concepts/data-migration/events/entity-migrated.js +15 -0
  13. package/dist/core-concepts/touch-entity/events/entity-touched.d.ts +7 -0
  14. package/dist/core-concepts/touch-entity/events/entity-touched.js +13 -0
  15. package/dist/data-migrations.d.ts +8 -0
  16. package/dist/data-migrations.js +73 -0
  17. package/dist/decorators/command.d.ts +19 -0
  18. package/dist/decorators/command.js +47 -0
  19. package/dist/decorators/data-migration.d.ts +9 -0
  20. package/dist/decorators/data-migration.js +25 -0
  21. package/dist/decorators/entity.d.ts +32 -0
  22. package/dist/decorators/entity.js +100 -0
  23. package/dist/decorators/event-handler.d.ts +3 -0
  24. package/dist/decorators/event-handler.js +18 -0
  25. package/dist/decorators/event.d.ts +8 -0
  26. package/dist/decorators/event.js +22 -0
  27. package/dist/decorators/field-metadata-reader.d.ts +6 -0
  28. package/dist/decorators/field-metadata-reader.js +221 -0
  29. package/dist/decorators/global-error-handler.d.ts +2 -0
  30. package/dist/decorators/global-error-handler.js +15 -0
  31. package/dist/decorators/global-event-handler.d.ts +3 -0
  32. package/dist/decorators/global-event-handler.js +9 -0
  33. package/dist/decorators/health-sensor.d.ts +14 -0
  34. package/dist/decorators/health-sensor.js +38 -0
  35. package/dist/decorators/index.d.ts +16 -0
  36. package/dist/decorators/index.js +19 -0
  37. package/dist/decorators/metadata.d.ts +13 -0
  38. package/dist/decorators/metadata.js +55 -0
  39. package/dist/decorators/non-exposed.d.ts +2 -0
  40. package/dist/decorators/non-exposed.js +24 -0
  41. package/dist/decorators/notification.d.ts +35 -0
  42. package/dist/decorators/notification.js +94 -0
  43. package/dist/decorators/projects.d.ts +32 -0
  44. package/dist/decorators/projects.js +87 -0
  45. package/dist/decorators/query.d.ts +2 -0
  46. package/dist/decorators/query.js +25 -0
  47. package/dist/decorators/read-model.d.ts +39 -0
  48. package/dist/decorators/read-model.js +129 -0
  49. package/dist/decorators/role.d.ts +6 -0
  50. package/dist/decorators/role.js +15 -0
  51. package/dist/decorators/scheduled-command.d.ts +9 -0
  52. package/dist/decorators/scheduled-command.js +25 -0
  53. package/dist/decorators/schema-migration.d.ts +36 -0
  54. package/dist/decorators/schema-migration.js +146 -0
  55. package/dist/decorators/sequenced-by.d.ts +28 -0
  56. package/dist/decorators/sequenced-by.js +79 -0
  57. package/dist/decorators/stage3-utils.d.ts +6 -0
  58. package/dist/decorators/stage3-utils.js +25 -0
  59. package/dist/delete-event-dispatcher.d.ts +4 -0
  60. package/dist/delete-event-dispatcher.js +23 -0
  61. package/dist/event-dispatcher.d.ts +9 -0
  62. package/dist/event-dispatcher.js +37 -0
  63. package/dist/event-processor.d.ts +15 -0
  64. package/dist/event-processor.js +125 -0
  65. package/dist/event-search.d.ts +2 -0
  66. package/dist/event-search.js +26 -0
  67. package/dist/event-stream-consumer.d.ts +7 -0
  68. package/dist/event-stream-consumer.js +36 -0
  69. package/dist/event-stream-producer.d.ts +7 -0
  70. package/dist/event-stream-producer.js +30 -0
  71. package/dist/events-reader.d.ts +11 -0
  72. package/dist/events-reader.js +63 -0
  73. package/dist/global-error-dispatcher.d.ts +16 -0
  74. package/dist/global-error-dispatcher.js +109 -0
  75. package/dist/graphql-dispatcher.d.ts +16 -0
  76. package/dist/graphql-dispatcher.js +195 -0
  77. package/dist/importer.d.ts +14 -0
  78. package/dist/importer.js +49 -0
  79. package/dist/index.d.ts +60 -0
  80. package/dist/index.js +100 -0
  81. package/dist/injectable/index.d.ts +21 -0
  82. package/dist/injectable/index.js +2 -0
  83. package/dist/instrumentation/decorator/trace.d.ts +13 -0
  84. package/dist/instrumentation/decorator/trace.js +116 -0
  85. package/dist/instrumentation/index.d.ts +2 -0
  86. package/dist/instrumentation/index.js +5 -0
  87. package/dist/instrumentation/trace-notifier.d.ts +3 -0
  88. package/dist/instrumentation/trace-notifier.js +26 -0
  89. package/dist/magek.d.ts +42 -0
  90. package/dist/magek.js +158 -0
  91. package/dist/query-dispatcher.d.ts +8 -0
  92. package/dist/query-dispatcher.js +47 -0
  93. package/dist/read-model-schema-migrator.d.ts +14 -0
  94. package/dist/read-model-schema-migrator.js +80 -0
  95. package/dist/read-models-reader.d.ts +31 -0
  96. package/dist/read-models-reader.js +196 -0
  97. package/dist/register-handler.d.ts +11 -0
  98. package/dist/register-handler.js +95 -0
  99. package/dist/rocket-dispatcher.d.ts +6 -0
  100. package/dist/rocket-dispatcher.js +21 -0
  101. package/dist/scheduled-command-dispatcher.d.ts +12 -0
  102. package/dist/scheduled-command-dispatcher.js +54 -0
  103. package/dist/schema-migrator.d.ts +12 -0
  104. package/dist/schema-migrator.js +71 -0
  105. package/dist/sensor/health/health-indicators/database-events-health-indicator.d.ts +5 -0
  106. package/dist/sensor/health/health-indicators/database-events-health-indicator.js +26 -0
  107. package/dist/sensor/health/health-indicators/database-health-indicator.d.ts +5 -0
  108. package/dist/sensor/health/health-indicators/database-health-indicator.js +29 -0
  109. package/dist/sensor/health/health-indicators/database-read-models-health-indicator.d.ts +5 -0
  110. package/dist/sensor/health/health-indicators/database-read-models-health-indicator.js +26 -0
  111. package/dist/sensor/health/health-indicators/default-health-indicators.d.ts +5 -0
  112. package/dist/sensor/health/health-indicators/default-health-indicators.js +39 -0
  113. package/dist/sensor/health/health-indicators/function-health-indicator.d.ts +5 -0
  114. package/dist/sensor/health/health-indicators/function-health-indicator.js +30 -0
  115. package/dist/sensor/health/health-indicators/health-indicator.d.ts +5 -0
  116. package/dist/sensor/health/health-indicators/health-indicator.js +30 -0
  117. package/dist/sensor/health/health-indicators/index.d.ts +3 -0
  118. package/dist/sensor/health/health-indicators/index.js +6 -0
  119. package/dist/sensor/health/health-indicators/os-info.d.ts +14 -0
  120. package/dist/sensor/health/health-indicators/os-info.js +38 -0
  121. package/dist/sensor/health/health-indicators/rockets-health-indicator.d.ts +5 -0
  122. package/dist/sensor/health/health-indicators/rockets-health-indicator.js +57 -0
  123. package/dist/sensor/health/health-indicators/version.d.ts +2 -0
  124. package/dist/sensor/health/health-indicators/version.js +24 -0
  125. package/dist/sensor/health/health-service.d.ts +22 -0
  126. package/dist/sensor/health/health-service.js +117 -0
  127. package/dist/sensor/health/health-utils.d.ts +7 -0
  128. package/dist/sensor/health/health-utils.js +53 -0
  129. package/dist/sensor/health/index.d.ts +3 -0
  130. package/dist/sensor/health/index.js +6 -0
  131. package/dist/sensor/index.d.ts +1 -0
  132. package/dist/sensor/index.js +4 -0
  133. package/dist/services/event-store.d.ts +27 -0
  134. package/dist/services/event-store.js +260 -0
  135. package/dist/services/filter-helpers.d.ts +3 -0
  136. package/dist/services/filter-helpers.js +19 -0
  137. package/dist/services/graphql/common.d.ts +26 -0
  138. package/dist/services/graphql/common.js +53 -0
  139. package/dist/services/graphql/graphql-generator.d.ts +46 -0
  140. package/dist/services/graphql/graphql-generator.js +269 -0
  141. package/dist/services/graphql/graphql-mutation-generator.d.ts +12 -0
  142. package/dist/services/graphql/graphql-mutation-generator.js +25 -0
  143. package/dist/services/graphql/graphql-query-generator.d.ts +22 -0
  144. package/dist/services/graphql/graphql-query-generator.js +39 -0
  145. package/dist/services/graphql/graphql-subcriptions-generator.d.ts +17 -0
  146. package/dist/services/graphql/graphql-subcriptions-generator.js +60 -0
  147. package/dist/services/graphql/graphql-type-informer.d.ts +23 -0
  148. package/dist/services/graphql/graphql-type-informer.js +160 -0
  149. package/dist/services/graphql/query-generators/graphql-query-by-keys-generator.d.ts +14 -0
  150. package/dist/services/graphql/query-generators/graphql-query-by-keys-generator.js +48 -0
  151. package/dist/services/graphql/query-generators/graphql-query-events-generator.d.ts +11 -0
  152. package/dist/services/graphql/query-generators/graphql-query-events-generator.js +68 -0
  153. package/dist/services/graphql/query-generators/graphql-query-filters-generator.d.ts +14 -0
  154. package/dist/services/graphql/query-generators/graphql-query-filters-generator.js +31 -0
  155. package/dist/services/graphql/query-generators/graphql-query-generator.d.ts +12 -0
  156. package/dist/services/graphql/query-generators/graphql-query-generator.js +17 -0
  157. package/dist/services/graphql/query-generators/graphql-query-listed-generator.d.ts +16 -0
  158. package/dist/services/graphql/query-generators/graphql-query-listed-generator.js +65 -0
  159. package/dist/services/graphql/query-helpers/graphql-handled-fields-generator.d.ts +15 -0
  160. package/dist/services/graphql/query-helpers/graphql-handled-fields-generator.js +65 -0
  161. package/dist/services/graphql/query-helpers/graphql-query-filter-arguments-builder.d.ts +13 -0
  162. package/dist/services/graphql/query-helpers/graphql-query-filter-arguments-builder.js +169 -0
  163. package/dist/services/graphql/query-helpers/graphql-query-filter-fields-builder.d.ts +11 -0
  164. package/dist/services/graphql/query-helpers/graphql-query-filter-fields-builder.js +28 -0
  165. package/dist/services/graphql/query-helpers/graphql-query-sort-builder.d.ts +12 -0
  166. package/dist/services/graphql/query-helpers/graphql-query-sort-builder.js +61 -0
  167. package/dist/services/graphql/websocket-protocol/graphql-websocket-protocol.d.ts +20 -0
  168. package/dist/services/graphql/websocket-protocol/graphql-websocket-protocol.js +127 -0
  169. package/dist/services/pub-sub/noop-read-model-pub-sub.d.ts +5 -0
  170. package/dist/services/pub-sub/noop-read-model-pub-sub.js +10 -0
  171. package/dist/services/pub-sub/read-model-pub-sub.d.ts +9 -0
  172. package/dist/services/pub-sub/read-model-pub-sub.js +112 -0
  173. package/dist/services/raw-events-parser.d.ts +5 -0
  174. package/dist/services/raw-events-parser.js +44 -0
  175. package/dist/services/read-model-searcher.d.ts +2 -0
  176. package/dist/services/read-model-searcher.js +11 -0
  177. package/dist/services/read-model-store.d.ts +41 -0
  178. package/dist/services/read-model-store.js +295 -0
  179. package/dist/services/token-verifiers/index.d.ts +4 -0
  180. package/dist/services/token-verifiers/index.js +7 -0
  181. package/dist/services/token-verifiers/jwks-uri-token-verifier.d.ts +21 -0
  182. package/dist/services/token-verifiers/jwks-uri-token-verifier.js +23 -0
  183. package/dist/services/token-verifiers/public-key-token-verifier.d.ts +13 -0
  184. package/dist/services/token-verifiers/public-key-token-verifier.js +19 -0
  185. package/dist/services/token-verifiers/role-based-token-verifier.d.ts +8 -0
  186. package/dist/services/token-verifiers/role-based-token-verifier.js +35 -0
  187. package/dist/services/token-verifiers/utilities.d.ts +31 -0
  188. package/dist/services/token-verifiers/utilities.js +70 -0
  189. package/dist/subscribers-notifier.d.ts +14 -0
  190. package/dist/subscribers-notifier.js +109 -0
  191. package/dist/token-verifier.d.ts +11 -0
  192. package/dist/token-verifier.js +46 -0
  193. package/dist/touch-entity-handler.d.ts +4 -0
  194. package/dist/touch-entity-handler.js +16 -0
  195. package/package.json +71 -0
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekRocketDispatcher = void 0;
4
+ class MagekRocketDispatcher {
5
+ constructor(config) {
6
+ this.config = config;
7
+ }
8
+ dispatch(request) {
9
+ const rawToEnvelopes = this.config.provider.rockets.rawToEnvelopes(this.config, request);
10
+ const rocketId = rawToEnvelopes.rocketId;
11
+ if (!rocketId) {
12
+ throw new Error('Attempt to execute a rocket function but the ID is missing.');
13
+ }
14
+ const rocketFunction = this.config.getRegisteredRocketFunction(rocketId);
15
+ if (!rocketFunction) {
16
+ throw new Error(`Rocket function with ID "${rocketId}" not found. Did you forget registering the function with "config.registerRocketFunction()"?`);
17
+ }
18
+ return rocketFunction(this.config, request);
19
+ }
20
+ }
21
+ exports.MagekRocketDispatcher = MagekRocketDispatcher;
@@ -0,0 +1,12 @@
1
+ import { MagekConfig, ScheduledCommandEnvelope } from '@magek/common';
2
+ export declare class MagekScheduledCommandDispatcher {
3
+ readonly config: MagekConfig;
4
+ private readonly globalErrorDispatcher;
5
+ constructor(config: MagekConfig);
6
+ dispatchCommand(commandEnvelope: ScheduledCommandEnvelope): Promise<void>;
7
+ /**
8
+ * Entry point to dispatch scheduled commands.
9
+ * @param request The incoming request
10
+ */
11
+ dispatch(request: unknown): Promise<void>;
12
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekScheduledCommandDispatcher = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@magek/common");
6
+ const register_handler_1 = require("./register-handler");
7
+ const global_error_dispatcher_1 = require("./global-error-dispatcher");
8
+ const instrumentation_1 = require("./instrumentation");
9
+ class MagekScheduledCommandDispatcher {
10
+ constructor(config) {
11
+ this.config = config;
12
+ this.globalErrorDispatcher = new global_error_dispatcher_1.MagekGlobalErrorDispatcher(config);
13
+ }
14
+ async dispatchCommand(commandEnvelope) {
15
+ const logger = (0, common_1.getLogger)(this.config, 'MagekScheduledCommandDispatcher#dispatchCommand');
16
+ logger.debug('Dispatching the following scheduled command envelope: ', commandEnvelope);
17
+ const commandMetadata = this.config.scheduledCommandHandlers[commandEnvelope.typeName];
18
+ if (!commandMetadata) {
19
+ throw new common_1.NotFoundError(`Could not find a proper handler for ${commandEnvelope.typeName}`);
20
+ }
21
+ const commandClass = commandMetadata.class;
22
+ logger.debug('Found the following command:', commandClass.name);
23
+ const command = commandClass;
24
+ const register = new common_1.Register(commandEnvelope.requestID, {}, register_handler_1.RegisterHandler.flush, undefined, commandEnvelope.context);
25
+ try {
26
+ logger.debug('Calling "handle" method on command: ', command);
27
+ await command.handle(register);
28
+ }
29
+ catch (e) {
30
+ const error = await this.globalErrorDispatcher.dispatch(new common_1.ScheduleCommandGlobalError(commandEnvelope, commandMetadata, e));
31
+ if (error)
32
+ throw error;
33
+ }
34
+ logger.debug('Command dispatched with register: ', register);
35
+ await register_handler_1.RegisterHandler.handle(this.config, register);
36
+ }
37
+ /**
38
+ * Entry point to dispatch scheduled commands.
39
+ * @param request The incoming request
40
+ */
41
+ async dispatch(request) {
42
+ const logger = (0, common_1.getLogger)(this.config, 'MagekScheduledCommandDispatcher#dispatch');
43
+ const envelopeOrError = await this.config.provider.scheduled.rawToEnvelope(this.config, request);
44
+ logger.debug('Received ScheduledCommand envelope...', envelopeOrError);
45
+ await this.dispatchCommand(envelopeOrError);
46
+ }
47
+ }
48
+ exports.MagekScheduledCommandDispatcher = MagekScheduledCommandDispatcher;
49
+ tslib_1.__decorate([
50
+ (0, instrumentation_1.Trace)(common_1.TraceActionTypes.SCHEDULED_COMMAND_HANDLER),
51
+ tslib_1.__metadata("design:type", Function),
52
+ tslib_1.__metadata("design:paramtypes", [Object]),
53
+ tslib_1.__metadata("design:returntype", Promise)
54
+ ], MagekScheduledCommandDispatcher.prototype, "dispatchCommand", null);
@@ -0,0 +1,12 @@
1
+ import { MagekConfig, CommandEnvelope, EventEnvelope, EntitySnapshotEnvelope } from '@magek/common';
2
+ type SchemaMigrableEnvelope = CommandEnvelope | EventEnvelope | EntitySnapshotEnvelope;
3
+ export declare class SchemaMigrator {
4
+ private config;
5
+ constructor(config: MagekConfig);
6
+ migrate<TMigrableEnvelope extends SchemaMigrableEnvelope>(conceptEnvelope: TMigrableEnvelope): Promise<TMigrableEnvelope>;
7
+ private checkVersionRange;
8
+ private needsMigration;
9
+ private applyAllMigrations;
10
+ private applyMigration;
11
+ }
12
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SchemaMigrator = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@magek/common");
7
+ const instrumentation_1 = require("./instrumentation");
8
+ class SchemaMigrator {
9
+ constructor(config) {
10
+ this.config = config;
11
+ }
12
+ async migrate(conceptEnvelope) {
13
+ this.checkVersionRange(conceptEnvelope);
14
+ if (this.needsMigration(conceptEnvelope)) {
15
+ return await this.applyAllMigrations(conceptEnvelope);
16
+ }
17
+ return conceptEnvelope; // The current version is exactly the same as the version of the concept
18
+ }
19
+ checkVersionRange(conceptEnvelope) {
20
+ if (conceptEnvelope.version < 1) {
21
+ throw new common_1.InvalidVersionError(`Received an invalid schema version value, ${conceptEnvelope.version}, for ${conceptEnvelope.typeName}. ` +
22
+ 'Versions must be greater than 0');
23
+ }
24
+ const currentVersion = this.config.currentVersionFor(conceptEnvelope.typeName);
25
+ if (currentVersion < conceptEnvelope.version) {
26
+ throw new common_1.InvalidVersionError(`Can not migrate schema an unknown version: The current schema version of ${conceptEnvelope.typeName} is ${currentVersion}, which is ` +
27
+ `lower than the received version ${conceptEnvelope.version}`);
28
+ }
29
+ }
30
+ needsMigration(conceptEnvelope) {
31
+ const currentVersion = this.config.currentVersionFor(conceptEnvelope.typeName);
32
+ return currentVersion > conceptEnvelope.version;
33
+ }
34
+ async applyAllMigrations(oldConceptEnvelope) {
35
+ const logger = (0, common_1.getLogger)(this.config, 'SchemaMigrator#applyAllMigrations');
36
+ const currentVersion = this.config.currentVersionFor(oldConceptEnvelope.typeName);
37
+ const oldVersion = oldConceptEnvelope.version;
38
+ logger.info(`Migrating schema ${oldConceptEnvelope.typeName} from version ${oldVersion} to version ${currentVersion}`);
39
+ logger.debug('Envelope before schema migration:\n', oldConceptEnvelope);
40
+ const migrations = this.config.schemaMigrations[oldConceptEnvelope.typeName];
41
+ let migratedConceptValue = oldConceptEnvelope.value;
42
+ for (let toVersion = oldVersion + 1; toVersion <= currentVersion; toVersion++) {
43
+ migratedConceptValue = await this.applyMigration(migratedConceptValue, migrations.get(toVersion));
44
+ }
45
+ const newConceptEnvelope = {
46
+ ...oldConceptEnvelope,
47
+ value: migratedConceptValue,
48
+ version: currentVersion,
49
+ };
50
+ logger.debug('Envelope after migration:\n', newConceptEnvelope);
51
+ return newConceptEnvelope;
52
+ }
53
+ async applyMigration(oldValue, migration) {
54
+ const logger = (0, common_1.getLogger)(this.config, 'SchemaMigrator#applyMigration');
55
+ if (!migration) {
56
+ throw new common_1.InvalidVersionError('Received an undefined schema migration value. Are there "gaps" between the versions of the schema migrations?');
57
+ }
58
+ const oldConcept = Object.assign(new migration.fromSchema(), oldValue);
59
+ const migrationMethod = new migration.migrationClass()[migration.methodName];
60
+ const newConcept = await migrationMethod(oldConcept);
61
+ logger.debug(`Partial migration finished. Migrated from oldValue=${oldConcept} to newValue=${newConcept}`);
62
+ return newConcept;
63
+ }
64
+ }
65
+ exports.SchemaMigrator = SchemaMigrator;
66
+ tslib_1.__decorate([
67
+ (0, instrumentation_1.Trace)(common_1.TraceActionTypes.SCHEMA_MIGRATOR_MIGRATE),
68
+ tslib_1.__metadata("design:type", Function),
69
+ tslib_1.__metadata("design:paramtypes", [typeof (_a = typeof TMigrableEnvelope !== "undefined" && TMigrableEnvelope) === "function" ? _a : Object]),
70
+ tslib_1.__metadata("design:returntype", Promise)
71
+ ], SchemaMigrator.prototype, "migrate", null);
@@ -0,0 +1,5 @@
1
+ import { MagekConfig, HealthIndicatorResult, HealthIndicatorMetadata } from '@magek/common';
2
+ export declare class MagekDatabaseEventsHealthIndicator {
3
+ health(config: MagekConfig, healthIndicatorMetadata: HealthIndicatorMetadata): Promise<HealthIndicatorResult>;
4
+ private isUp;
5
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekDatabaseEventsHealthIndicator = void 0;
4
+ const common_1 = require("@magek/common");
5
+ class MagekDatabaseEventsHealthIndicator {
6
+ async health(config, healthIndicatorMetadata) {
7
+ try {
8
+ const result = {
9
+ status: await this.isUp(config),
10
+ };
11
+ if (healthIndicatorMetadata.healthIndicatorConfiguration.details) {
12
+ const details = await config.provider.sensor.databaseEventsHealthDetails(config);
13
+ result.details = details;
14
+ }
15
+ return result;
16
+ }
17
+ catch (e) {
18
+ return { status: common_1.HealthStatus.DOWN, details: e };
19
+ }
20
+ }
21
+ async isUp(config) {
22
+ const databaseEvents = await config.provider.sensor.isDatabaseEventUp(config);
23
+ return databaseEvents ? common_1.HealthStatus.UP : common_1.HealthStatus.DOWN;
24
+ }
25
+ }
26
+ exports.MagekDatabaseEventsHealthIndicator = MagekDatabaseEventsHealthIndicator;
@@ -0,0 +1,5 @@
1
+ import { MagekConfig, HealthIndicatorResult, HealthIndicatorMetadata } from '@magek/common';
2
+ export declare class MagekDatabaseHealthIndicator {
3
+ health(config: MagekConfig, healthIndicatorMetadata: HealthIndicatorMetadata): Promise<HealthIndicatorResult>;
4
+ private isUp;
5
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekDatabaseHealthIndicator = void 0;
4
+ const common_1 = require("@magek/common");
5
+ class MagekDatabaseHealthIndicator {
6
+ async health(config, healthIndicatorMetadata) {
7
+ try {
8
+ const result = {
9
+ status: await this.isUp(config),
10
+ };
11
+ if (healthIndicatorMetadata.healthIndicatorConfiguration.details) {
12
+ const details = {
13
+ urls: await config.provider.sensor.databaseUrls(config),
14
+ };
15
+ result.details = details;
16
+ }
17
+ return result;
18
+ }
19
+ catch (e) {
20
+ return { status: common_1.HealthStatus.DOWN, details: e };
21
+ }
22
+ }
23
+ async isUp(config) {
24
+ const databaseEvents = await config.provider.sensor.isDatabaseEventUp(config);
25
+ const databaseReadModels = await config.provider.sensor.areDatabaseReadModelsUp(config);
26
+ return databaseEvents && databaseReadModels ? common_1.HealthStatus.UP : common_1.HealthStatus.DOWN;
27
+ }
28
+ }
29
+ exports.MagekDatabaseHealthIndicator = MagekDatabaseHealthIndicator;
@@ -0,0 +1,5 @@
1
+ import { MagekConfig, HealthIndicatorResult, HealthIndicatorMetadata } from '@magek/common';
2
+ export declare class MagekDatabaseReadModelsHealthIndicator {
3
+ health(config: MagekConfig, healthIndicatorMetadata: HealthIndicatorMetadata): Promise<HealthIndicatorResult>;
4
+ private isUp;
5
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekDatabaseReadModelsHealthIndicator = void 0;
4
+ const common_1 = require("@magek/common");
5
+ class MagekDatabaseReadModelsHealthIndicator {
6
+ async health(config, healthIndicatorMetadata) {
7
+ try {
8
+ const result = {
9
+ status: await this.isUp(config),
10
+ };
11
+ if (healthIndicatorMetadata.healthIndicatorConfiguration.details) {
12
+ const details = await config.provider.sensor.databaseReadModelsHealthDetails(config);
13
+ result.details = details;
14
+ }
15
+ return result;
16
+ }
17
+ catch (e) {
18
+ return { status: common_1.HealthStatus.DOWN, details: e };
19
+ }
20
+ }
21
+ async isUp(config) {
22
+ const databaseReadModels = await config.provider.sensor.areDatabaseReadModelsUp(config);
23
+ return databaseReadModels ? common_1.HealthStatus.UP : common_1.HealthStatus.DOWN;
24
+ }
25
+ }
26
+ exports.MagekDatabaseReadModelsHealthIndicator = MagekDatabaseReadModelsHealthIndicator;
@@ -0,0 +1,5 @@
1
+ import { MagekConfig, HealthIndicatorMetadata } from '@magek/common';
2
+ /**
3
+ * Magek configured HealthIndicators
4
+ */
5
+ export declare function defaultMagekHealthIndicators(config: MagekConfig): Record<string, HealthIndicatorMetadata>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultMagekHealthIndicators = defaultMagekHealthIndicators;
4
+ const common_1 = require("@magek/common");
5
+ const health_indicator_1 = require("./health-indicator");
6
+ const database_health_indicator_1 = require("./database-health-indicator");
7
+ const database_events_health_indicator_1 = require("./database-events-health-indicator");
8
+ const function_health_indicator_1 = require("./function-health-indicator");
9
+ const database_read_models_health_indicator_1 = require("./database-read-models-health-indicator");
10
+ function buildMetadata(config, id, name, healthIndicator) {
11
+ const health = config.sensorConfiguration.health;
12
+ return {
13
+ class: healthIndicator,
14
+ healthIndicatorConfiguration: {
15
+ id: id,
16
+ name: name,
17
+ enabled: health.magek[id].enabled,
18
+ details: health.magek[id].details,
19
+ showChildren: health.magek[id].showChildren,
20
+ },
21
+ };
22
+ }
23
+ /**
24
+ * Magek configured HealthIndicators
25
+ */
26
+ function defaultMagekHealthIndicators(config) {
27
+ const root = buildMetadata(config, common_1.HEALTH_INDICATORS_IDS.ROOT, 'Magek', health_indicator_1.MagekHealthIndicator);
28
+ const magekFunction = buildMetadata(config, common_1.HEALTH_INDICATORS_IDS.FUNCTION, 'Magek Function', function_health_indicator_1.MagekFunctionHealthIndicator);
29
+ const magekDatabase = buildMetadata(config, common_1.HEALTH_INDICATORS_IDS.DATABASE, 'Magek Database', database_health_indicator_1.MagekDatabaseHealthIndicator);
30
+ const databaseEvents = buildMetadata(config, common_1.HEALTH_INDICATORS_IDS.DATABASE_EVENTS, 'Magek Database Events', database_events_health_indicator_1.MagekDatabaseEventsHealthIndicator);
31
+ const databaseReadModels = buildMetadata(config, common_1.HEALTH_INDICATORS_IDS.DATABASE_READ_MODELS, 'Magek Database ReadModels', database_read_models_health_indicator_1.MagekDatabaseReadModelsHealthIndicator);
32
+ return {
33
+ [root.healthIndicatorConfiguration.id]: root,
34
+ [magekFunction.healthIndicatorConfiguration.id]: magekFunction,
35
+ [magekDatabase.healthIndicatorConfiguration.id]: magekDatabase,
36
+ [databaseEvents.healthIndicatorConfiguration.id]: databaseEvents,
37
+ [databaseReadModels.healthIndicatorConfiguration.id]: databaseReadModels,
38
+ };
39
+ }
@@ -0,0 +1,5 @@
1
+ import { MagekConfig, HealthIndicatorMetadata, HealthIndicatorResult } from '@magek/common';
2
+ export declare class MagekFunctionHealthIndicator {
3
+ health(config: MagekConfig, healthIndicatorMetadata: HealthIndicatorMetadata): Promise<HealthIndicatorResult>;
4
+ private isUp;
5
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekFunctionHealthIndicator = void 0;
4
+ const common_1 = require("@magek/common");
5
+ const os_info_1 = require("./os-info");
6
+ class MagekFunctionHealthIndicator {
7
+ async health(config, healthIndicatorMetadata) {
8
+ try {
9
+ const result = {
10
+ status: await this.isUp(config),
11
+ };
12
+ if (healthIndicatorMetadata.healthIndicatorConfiguration.details) {
13
+ const graphQLUrl = await config.provider.sensor.graphQLFunctionUrl(config);
14
+ const osInfoResult = await (0, os_info_1.osInfo)();
15
+ result.details = {
16
+ ...osInfoResult,
17
+ graphQL_url: graphQLUrl,
18
+ };
19
+ }
20
+ return result;
21
+ }
22
+ catch (e) {
23
+ return { status: common_1.HealthStatus.DOWN, details: e };
24
+ }
25
+ }
26
+ async isUp(config) {
27
+ return (await config.provider.sensor.isGraphQLFunctionUp(config)) ? common_1.HealthStatus.UP : common_1.HealthStatus.DOWN;
28
+ }
29
+ }
30
+ exports.MagekFunctionHealthIndicator = MagekFunctionHealthIndicator;
@@ -0,0 +1,5 @@
1
+ import { MagekConfig, HealthIndicatorResult, HealthIndicatorMetadata } from '@magek/common';
2
+ export declare class MagekHealthIndicator {
3
+ health(config: MagekConfig, healthIndicatorMetadata: HealthIndicatorMetadata): Promise<HealthIndicatorResult>;
4
+ private isUp;
5
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagekHealthIndicator = void 0;
4
+ const common_1 = require("@magek/common");
5
+ const version_1 = require("./version");
6
+ class MagekHealthIndicator {
7
+ async health(config, healthIndicatorMetadata) {
8
+ try {
9
+ const result = {
10
+ status: await this.isUp(config),
11
+ };
12
+ if (healthIndicatorMetadata.healthIndicatorConfiguration.details) {
13
+ result.details = {
14
+ magekVersion: (0, version_1.magekVersion)(config),
15
+ };
16
+ }
17
+ return result;
18
+ }
19
+ catch (e) {
20
+ return { status: common_1.HealthStatus.DOWN, details: e };
21
+ }
22
+ }
23
+ async isUp(config) {
24
+ const graphqlUp = await config.provider.sensor.isGraphQLFunctionUp(config);
25
+ const databaseEvents = await config.provider.sensor.isDatabaseEventUp(config);
26
+ const databaseReadModels = await config.provider.sensor.areDatabaseReadModelsUp(config);
27
+ return graphqlUp && databaseEvents && databaseReadModels ? common_1.HealthStatus.UP : common_1.HealthStatus.DOWN;
28
+ }
29
+ }
30
+ exports.MagekHealthIndicator = MagekHealthIndicator;
@@ -0,0 +1,3 @@
1
+ export * from './health-indicator';
2
+ export * from './default-health-indicators';
3
+ export * from './function-health-indicator';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./health-indicator"), exports);
5
+ tslib_1.__exportStar(require("./default-health-indicators"), exports);
6
+ tslib_1.__exportStar(require("./function-health-indicator"), exports);
@@ -0,0 +1,14 @@
1
+ import * as os from 'os';
2
+ export interface OsInfoCpuResult {
3
+ cpu: os.CpuInfo;
4
+ timesPercentages: Array<number>;
5
+ }
6
+ export interface OsInfoMemoryResult {
7
+ totalBytes: number;
8
+ freeBytes: number;
9
+ }
10
+ export interface OsInfoResult {
11
+ cpus: Array<OsInfoCpuResult>;
12
+ memory: OsInfoMemoryResult;
13
+ }
14
+ export declare function osInfo(): Promise<OsInfoResult>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.osInfo = osInfo;
4
+ const os = require("os");
5
+ async function osInfo() {
6
+ const rawCpus = os.cpus();
7
+ const cpus = rawCpus.length > 0 ? rawCpus : [fallbackCpuInfo()];
8
+ const cpuResult = cpus.map((cpu) => {
9
+ // times is an object containing the number of CPU ticks spent in: user, nice, sys, idle, and irq
10
+ const totalTimes = Object.values(cpu.times).reduce((accumulator, value) => accumulator + value, 0);
11
+ const safeTotalTimes = totalTimes === 0 ? 1 : totalTimes;
12
+ const timesPercentages = Object.values(cpu.times).map((time) => Math.round((100 * time) / safeTotalTimes));
13
+ return {
14
+ cpu,
15
+ timesPercentages,
16
+ };
17
+ });
18
+ return {
19
+ cpus: cpuResult,
20
+ memory: {
21
+ totalBytes: os.totalmem(),
22
+ freeBytes: os.freemem(),
23
+ },
24
+ };
25
+ }
26
+ function fallbackCpuInfo() {
27
+ return {
28
+ model: 'unknown',
29
+ speed: 0,
30
+ times: {
31
+ user: 0,
32
+ nice: 0,
33
+ sys: 0,
34
+ idle: 0,
35
+ irq: 0,
36
+ },
37
+ };
38
+ }
@@ -0,0 +1,5 @@
1
+ import { MagekConfig, HealthIndicatorMetadata, HealthIndicatorsResult } from '@magek/common';
2
+ export declare class RocketsHealthIndicator {
3
+ health(config: MagekConfig, healthIndicatorMetadata: HealthIndicatorMetadata): Promise<HealthIndicatorsResult>;
4
+ private getOverAllHealthStatus;
5
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RocketsHealthIndicator = void 0;
4
+ const common_1 = require("@magek/common");
5
+ class RocketsHealthIndicator {
6
+ async health(config, healthIndicatorMetadata) {
7
+ const results = await config.provider.sensor.areRocketFunctionsUp(config);
8
+ if (Object.keys(results).length === 0) {
9
+ return {
10
+ name: 'Rockets',
11
+ id: common_1.HEALTH_INDICATORS_IDS.ROCKETS,
12
+ status: common_1.HealthStatus.UNKNOWN,
13
+ details: {
14
+ reason: 'No Rockets found',
15
+ },
16
+ };
17
+ }
18
+ // Check if we're looking for a specific rocket
19
+ const componentPath = healthIndicatorMetadata.healthIndicatorConfiguration.id;
20
+ const rocketName = componentPath.split('/')[1]; // rockets/<rocket-name>
21
+ if (rocketName) {
22
+ const rocketStatus = results[rocketName];
23
+ if (rocketStatus === undefined) {
24
+ throw new Error(`Rocket "${rocketName}" not found`);
25
+ }
26
+ return {
27
+ name: rocketName,
28
+ id: `${common_1.HEALTH_INDICATORS_IDS.ROCKETS}/${rocketName}`,
29
+ status: rocketStatus ? common_1.HealthStatus.UP : common_1.HealthStatus.DOWN,
30
+ };
31
+ }
32
+ // return all rockets status
33
+ return {
34
+ name: 'Rockets',
35
+ id: common_1.HEALTH_INDICATORS_IDS.ROCKETS,
36
+ status: this.getOverAllHealthStatus(results),
37
+ components: Object.entries(results).map(([rocketName, status]) => {
38
+ return {
39
+ name: rocketName,
40
+ id: `${common_1.HEALTH_INDICATORS_IDS.ROCKETS}/${rocketName}`,
41
+ status: status ? common_1.HealthStatus.UP : common_1.HealthStatus.DOWN,
42
+ };
43
+ }),
44
+ };
45
+ }
46
+ getOverAllHealthStatus(results) {
47
+ const statusValues = Object.values(results);
48
+ if (statusValues.every((status) => status)) {
49
+ return common_1.HealthStatus.UP;
50
+ }
51
+ if (statusValues.every((status) => !status)) {
52
+ return common_1.HealthStatus.DOWN;
53
+ }
54
+ return common_1.HealthStatus.PARTIALLY_UP;
55
+ }
56
+ }
57
+ exports.RocketsHealthIndicator = RocketsHealthIndicator;
@@ -0,0 +1,2 @@
1
+ import { MagekConfig } from '@magek/common';
2
+ export declare function magekVersion(config: MagekConfig): any;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.magekVersion = magekVersion;
4
+ const path = require("path");
5
+ const process = require("process");
6
+ const common_1 = require("@magek/common");
7
+ function magekVersion(config) {
8
+ const projectAbsolutePath = path.resolve(process.cwd());
9
+ const logger = (0, common_1.getLogger)(config, 'magekVersion');
10
+ try {
11
+ const packageJsonContents = require(path.join(projectAbsolutePath, 'package.json'));
12
+ const version = packageJsonContents.dependencies['@magek/core'];
13
+ if (!version) {
14
+ logger.warn('Could not get Magek Version');
15
+ return '';
16
+ }
17
+ const versionParts = version.replace('workspace:', '').replace('^', '').replace('.tgz', '').split('-');
18
+ return versionParts[versionParts.length - 1];
19
+ }
20
+ catch (e) {
21
+ logger.warn('There was an error when calculating the magek version the application', e);
22
+ return '';
23
+ }
24
+ }
@@ -0,0 +1,22 @@
1
+ import { MagekConfig } from '@magek/common';
2
+ /**
3
+ * This class is in charge of handling the health check requests
4
+ * and dispatching the health checks to the corresponding health indicators
5
+ */
6
+ export declare class MagekHealthService {
7
+ readonly config: MagekConfig;
8
+ constructor(config: MagekConfig);
9
+ health(request: unknown): Promise<unknown>;
10
+ private validate;
11
+ private healthProviderResolver;
12
+ private enabledIndicatorHealth;
13
+ private indicatorHealth;
14
+ /**
15
+ * If there is not any indicator configured, then we will use only the Magek indicators.
16
+ * @private
17
+ */
18
+ private getHealthProviders;
19
+ private parentsHealthProviders;
20
+ private verify;
21
+ private isOverallHealthy;
22
+ }