@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,221 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.buildClassMetadataFromFields = buildClassMetadataFromFields;
5
+ require("reflect-metadata");
6
+ // Symbol used by Stage 3 decorators to store field metadata
7
+ const FIELDS_KEY = Symbol.for('magek:fields');
8
+ // Symbol.metadata may not be defined in all TypeScript lib versions
9
+ // Use a well-known symbol that Stage 3 decorators use
10
+ const METADATA_KEY = (_a = Symbol.metadata) !== null && _a !== void 0 ? _a : Symbol.for('Symbol.metadata');
11
+ /**
12
+ * Extract TypeMetadata from a @Field() decorator's metadata
13
+ */
14
+ function extractTypeMetadata(fieldMeta, isGetter = false) {
15
+ let targetType;
16
+ let isArray = false;
17
+ let isReadonlyArray = false;
18
+ // If typeFunction is provided, use it
19
+ if (fieldMeta.typeFunction) {
20
+ const result = fieldMeta.typeFunction();
21
+ // Handle array syntax: @Field(type => [String])
22
+ if (Array.isArray(result)) {
23
+ isArray = true;
24
+ targetType = result[0];
25
+ }
26
+ else {
27
+ targetType = result;
28
+ }
29
+ }
30
+ else {
31
+ // Fall back to design:type from emitDecoratorMetadata
32
+ targetType = fieldMeta.designType;
33
+ }
34
+ // Determine type group and construct TypeMetadata
35
+ return analyzeType(targetType, {
36
+ isNullable: fieldMeta.options.nullable || false,
37
+ isGetAccessor: isGetter,
38
+ isArray,
39
+ isReadonlyArray,
40
+ });
41
+ }
42
+ /**
43
+ * Analyze a type and convert it to TypeMetadata
44
+ */
45
+ function analyzeType(targetType, options) {
46
+ const { isNullable, isGetAccessor, isArray, isReadonlyArray } = options;
47
+ // Handle Array first (before primitive checks, since element type may be a primitive)
48
+ if (isArray || isReadonlyArray) {
49
+ const elementType = analyzeType(targetType, {
50
+ isNullable: false,
51
+ isGetAccessor: false,
52
+ isArray: false,
53
+ isReadonlyArray: false,
54
+ });
55
+ return {
56
+ name: isReadonlyArray ? `readonly ${elementType.name}[]` : `${elementType.name}[]`,
57
+ typeGroup: isReadonlyArray ? 'ReadonlyArray' : 'Array',
58
+ typeName: isReadonlyArray ? 'ReadonlyArray' : 'Array',
59
+ parameters: [elementType],
60
+ isNullable,
61
+ isGetAccessor,
62
+ };
63
+ }
64
+ // Handle primitives
65
+ if (targetType === String) {
66
+ return {
67
+ name: 'string',
68
+ typeGroup: 'String',
69
+ typeName: 'String',
70
+ parameters: [],
71
+ isNullable,
72
+ isGetAccessor,
73
+ type: String,
74
+ };
75
+ }
76
+ if (targetType === Number) {
77
+ return {
78
+ name: 'number',
79
+ typeGroup: 'Number',
80
+ typeName: 'Number',
81
+ parameters: [],
82
+ isNullable,
83
+ isGetAccessor,
84
+ type: Number,
85
+ };
86
+ }
87
+ if (targetType === Boolean) {
88
+ return {
89
+ name: 'boolean',
90
+ typeGroup: 'Boolean',
91
+ typeName: 'Boolean',
92
+ parameters: [],
93
+ isNullable,
94
+ isGetAccessor,
95
+ type: Boolean,
96
+ };
97
+ }
98
+ // Handle Object (fallback for unknown types)
99
+ if (targetType === Object || !targetType) {
100
+ return {
101
+ name: 'any',
102
+ typeGroup: 'Other',
103
+ typeName: 'any',
104
+ parameters: [],
105
+ isNullable,
106
+ isGetAccessor,
107
+ };
108
+ }
109
+ // Handle Class types
110
+ if (typeof targetType === 'function') {
111
+ return {
112
+ name: targetType.name || 'Unknown',
113
+ typeGroup: 'Class',
114
+ typeName: targetType.name,
115
+ parameters: [],
116
+ isNullable,
117
+ isGetAccessor,
118
+ type: targetType,
119
+ };
120
+ }
121
+ // Default fallback
122
+ return {
123
+ name: 'unknown',
124
+ typeGroup: 'Other',
125
+ typeName: 'unknown',
126
+ parameters: [],
127
+ isNullable,
128
+ isGetAccessor,
129
+ };
130
+ }
131
+ /**
132
+ * Get all fields from a class, including inherited fields
133
+ */
134
+ function getAllFields(classType) {
135
+ const fields = [];
136
+ // First, check for Stage 3 decorator metadata (Symbol.metadata on the class)
137
+ // Stage 3 decorators store metadata in classType[Symbol.metadata]
138
+ const classAsRecord = classType;
139
+ const metadata = classAsRecord[METADATA_KEY];
140
+ if (metadata && metadata[FIELDS_KEY]) {
141
+ const stage3Fields = metadata[FIELDS_KEY];
142
+ for (const field of stage3Fields) {
143
+ if (!fields.some((f) => f.name === field.name)) {
144
+ fields.push(field);
145
+ }
146
+ }
147
+ }
148
+ // Then walk up the prototype chain for legacy decorator metadata
149
+ let currentPrototype = classType.prototype;
150
+ while (currentPrototype && currentPrototype !== Object.prototype) {
151
+ const constructor = currentPrototype.constructor;
152
+ // Try Reflect.getMetadata first, then fallback to __magek_fields__
153
+ let prototypeFields = [];
154
+ if (typeof Reflect.getMetadata === 'function') {
155
+ prototypeFields = Reflect.getMetadata('magek:fields', constructor) || [];
156
+ }
157
+ // Also check fallback property
158
+ if (prototypeFields.length === 0 && constructor.__magek_fields__) {
159
+ prototypeFields = constructor.__magek_fields__;
160
+ }
161
+ // Add fields that aren't already in the list (child overrides parent)
162
+ for (const field of prototypeFields) {
163
+ if (!fields.some((f) => f.name === field.name)) {
164
+ fields.push(field);
165
+ }
166
+ }
167
+ currentPrototype = Object.getPrototypeOf(currentPrototype);
168
+ }
169
+ return fields;
170
+ }
171
+ /**
172
+ * Get all getters (calculated fields) from a class
173
+ */
174
+ function getAllGetters(classType) {
175
+ var _a;
176
+ const getters = [];
177
+ const prototype = classType.prototype;
178
+ // Get property descriptors
179
+ const descriptors = Object.getOwnPropertyDescriptors(prototype);
180
+ for (const [propertyKey, descriptor] of Object.entries(descriptors)) {
181
+ if (descriptor.get) {
182
+ // This is a getter, check if it has @CalculatedField metadata
183
+ const dependencies = ((_a = Reflect.getMetadata('dynamic:dependencies', classType)) === null || _a === void 0 ? void 0 : _a[propertyKey]) || [];
184
+ // Get return type from design:returntype if available
185
+ const returnType = Reflect.getMetadata('design:returntype', prototype, propertyKey);
186
+ const typeMetadata = analyzeType(returnType || Object, {
187
+ isNullable: false,
188
+ isGetAccessor: true,
189
+ isArray: false,
190
+ isReadonlyArray: false,
191
+ });
192
+ getters.push({
193
+ name: propertyKey,
194
+ typeInfo: typeMetadata,
195
+ dependencies,
196
+ });
197
+ }
198
+ }
199
+ return getters;
200
+ }
201
+ /**
202
+ * Build ClassMetadata from @Field() decorators
203
+ */
204
+ function buildClassMetadataFromFields(classType) {
205
+ // Get all fields (including inherited)
206
+ const fieldMetadatas = getAllFields(classType);
207
+ // Convert to PropertyMetadata
208
+ const fields = fieldMetadatas.map((fieldMeta) => ({
209
+ name: fieldMeta.name,
210
+ typeInfo: extractTypeMetadata(fieldMeta, false),
211
+ dependencies: [],
212
+ }));
213
+ // Get getter methods (for @CalculatedField)
214
+ const methods = getAllGetters(classType);
215
+ return {
216
+ name: classType.name,
217
+ type: classType,
218
+ fields,
219
+ methods,
220
+ };
221
+ }
@@ -0,0 +1,2 @@
1
+ import { GlobalErrorHandlerInterface } from '@magek/common';
2
+ export declare function GlobalErrorHandler(): (errorHandlerClass: GlobalErrorHandlerInterface) => void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlobalErrorHandler = GlobalErrorHandler;
4
+ const magek_1 = require("../magek");
5
+ function GlobalErrorHandler() {
6
+ return (errorHandlerClass) => {
7
+ magek_1.Magek.configureCurrentEnv((config) => {
8
+ if (config.globalErrorsHandler) {
9
+ throw new Error(`An error handler called ${errorHandlerClass.name} is already registered.
10
+ If you think that this is an error, try performing a clean build.`);
11
+ }
12
+ config.globalErrorsHandler = { class: errorHandlerClass };
13
+ });
14
+ };
15
+ }
@@ -0,0 +1,3 @@
1
+ import { EventHandlerInterface } from '@magek/common';
2
+ export declare const GLOBAL_EVENT_HANDLERS = "GLOBAL_EVENT_HANDLERS";
3
+ export declare function GlobalEventHandler<TEventHandler extends EventHandlerInterface>(eventHandlerClass: TEventHandler): void;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GLOBAL_EVENT_HANDLERS = void 0;
4
+ exports.GlobalEventHandler = GlobalEventHandler;
5
+ const event_handler_1 = require("./event-handler");
6
+ exports.GLOBAL_EVENT_HANDLERS = 'GLOBAL_EVENT_HANDLERS';
7
+ function GlobalEventHandler(eventHandlerClass) {
8
+ (0, event_handler_1.registerEventHandler)(exports.GLOBAL_EVENT_HANDLERS, eventHandlerClass);
9
+ }
@@ -0,0 +1,14 @@
1
+ import { Class, HealthIndicatorConfiguration, HealthIndicatorInterface } from '@magek/common';
2
+ /**
3
+ * Decorator to mark a class as a Magek Health Sensor.
4
+ * Health sensors provide health status information for monitoring endpoints.
5
+ *
6
+ * @param attributes - Health indicator configuration
7
+ * @param attributes.id - Unique indicator identifier
8
+ * @param attributes.name - Indicator description
9
+ * @param attributes.enabled - If false, this indicator and its children will be skipped
10
+ * @param attributes.details - If false, the indicator will not include details
11
+ * @param attributes.showChildren - If false, children components won't be included in the tree
12
+ * @returns A class decorator function
13
+ */
14
+ export declare function HealthSensor(attributes: HealthIndicatorConfiguration): <TIndicator extends HealthIndicatorInterface>(healthIndicator: Class<TIndicator>) => void;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HealthSensor = HealthSensor;
4
+ const magek_1 = require("../magek");
5
+ const health_indicators_1 = require("../sensor/health/health-indicators");
6
+ /**
7
+ * Decorator to mark a class as a Magek Health Sensor.
8
+ * Health sensors provide health status information for monitoring endpoints.
9
+ *
10
+ * @param attributes - Health indicator configuration
11
+ * @param attributes.id - Unique indicator identifier
12
+ * @param attributes.name - Indicator description
13
+ * @param attributes.enabled - If false, this indicator and its children will be skipped
14
+ * @param attributes.details - If false, the indicator will not include details
15
+ * @param attributes.showChildren - If false, children components won't be included in the tree
16
+ * @returns A class decorator function
17
+ */
18
+ function HealthSensor(attributes) {
19
+ return (healthIndicator) => {
20
+ magek_1.Magek.configureCurrentEnv((config) => {
21
+ var _a;
22
+ if (Object.keys(config.userHealthIndicators).length === 0) {
23
+ config.userHealthIndicators = (0, health_indicators_1.defaultMagekHealthIndicators)(config);
24
+ }
25
+ const path = attributes.id;
26
+ config.userHealthIndicators[path] = {
27
+ class: healthIndicator,
28
+ healthIndicatorConfiguration: {
29
+ id: attributes.id,
30
+ name: attributes.name,
31
+ enabled: attributes.enabled,
32
+ details: attributes.details,
33
+ showChildren: (_a = attributes.showChildren) !== null && _a !== void 0 ? _a : true,
34
+ },
35
+ };
36
+ });
37
+ };
38
+ }
@@ -0,0 +1,16 @@
1
+ export * from './command';
2
+ export * from './query';
3
+ export * from './data-migration';
4
+ export * from './entity';
5
+ export * from './event';
6
+ export * from './event-handler';
7
+ export * from './global-error-handler';
8
+ export * from './notification';
9
+ export * from './projects';
10
+ export * from './read-model';
11
+ export * from './role';
12
+ export * from './scheduled-command';
13
+ export * from './schema-migration';
14
+ export * from './sequenced-by';
15
+ export * from './global-event-handler';
16
+ export * from './non-exposed';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./command"), exports);
5
+ tslib_1.__exportStar(require("./query"), exports);
6
+ tslib_1.__exportStar(require("./data-migration"), exports);
7
+ tslib_1.__exportStar(require("./entity"), exports);
8
+ tslib_1.__exportStar(require("./event"), exports);
9
+ tslib_1.__exportStar(require("./event-handler"), exports);
10
+ tslib_1.__exportStar(require("./global-error-handler"), exports);
11
+ tslib_1.__exportStar(require("./notification"), exports);
12
+ tslib_1.__exportStar(require("./projects"), exports);
13
+ tslib_1.__exportStar(require("./read-model"), exports);
14
+ tslib_1.__exportStar(require("./role"), exports);
15
+ tslib_1.__exportStar(require("./scheduled-command"), exports);
16
+ tslib_1.__exportStar(require("./schema-migration"), exports);
17
+ tslib_1.__exportStar(require("./sequenced-by"), exports);
18
+ tslib_1.__exportStar(require("./global-event-handler"), exports);
19
+ tslib_1.__exportStar(require("./non-exposed"), exports);
@@ -0,0 +1,13 @@
1
+ import { AnyClass, ClassMetadata } from '@magek/common';
2
+ export declare function getClassMetadata(classType: AnyClass): ClassMetadata;
3
+ /**
4
+ * Get the argument names from a given function.
5
+ *
6
+ * This implementation is a TypeScript adaptation of a JavaScript implementation
7
+ * borrowed from the promisify-node code and can be found in the following link:
8
+ * https://github.com/nodegit/promisify-node/blob/02fc47cfc00146a533193bc4740e2e3e3be81c6f/utils/args.js
9
+ *
10
+ * @param {Function} func - The function to parse.
11
+ * @returns {Array} arg - List of arguments in the function.
12
+ */
13
+ export declare function getFunctionArguments(func: Function): Array<string>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getClassMetadata = getClassMetadata;
4
+ exports.getFunctionArguments = getFunctionArguments;
5
+ const common_1 = require("@magek/common");
6
+ const field_metadata_reader_1 = require("./field-metadata-reader");
7
+ function getClassMetadata(classType) {
8
+ // Try new @Field() decorator system first
9
+ try {
10
+ const fieldMetadata = (0, field_metadata_reader_1.buildClassMetadataFromFields)(classType);
11
+ // Check if any fields were actually found
12
+ if (fieldMetadata.fields.length > 0 || fieldMetadata.methods.length > 0) {
13
+ return fieldMetadata;
14
+ }
15
+ }
16
+ catch (error) {
17
+ // If field metadata reading fails, try old system
18
+ }
19
+ // Fall back to old transformer-based system
20
+ const meta = (0, common_1.getMetadata)('magek:typeinfo', classType);
21
+ if (!meta) {
22
+ throw Error(`Couldn't get proper metadata information of ${classType.name}. ` +
23
+ 'Make sure to decorate all properties with @Field() or enable the TypeScript transformer.');
24
+ }
25
+ return meta;
26
+ }
27
+ /**
28
+ * Get the argument names from a given function.
29
+ *
30
+ * This implementation is a TypeScript adaptation of a JavaScript implementation
31
+ * borrowed from the promisify-node code and can be found in the following link:
32
+ * https://github.com/nodegit/promisify-node/blob/02fc47cfc00146a533193bc4740e2e3e3be81c6f/utils/args.js
33
+ *
34
+ * @param {Function} func - The function to parse.
35
+ * @returns {Array} arg - List of arguments in the function.
36
+ */
37
+ // TODO: Consider extending `@magek/metadata` to yield constructor argument types
38
+ function getFunctionArguments(func) {
39
+ var _a;
40
+ // First match everything inside the function argument parens.
41
+ const args = (_a = func.toString().match(/([^(])*\(([^)]*)\)/)) === null || _a === void 0 ? void 0 : _a[2];
42
+ if (!args)
43
+ return [];
44
+ // Split the arguments string into an array comma delimited.
45
+ return args
46
+ .split(', ')
47
+ .map(function (arg) {
48
+ // Ensure no inline comments are parsed and trim the whitespace.
49
+ return arg.replace(/\/\*.*\*\//, '').trim();
50
+ })
51
+ .filter(function (arg) {
52
+ // Ensure no undefineds are added.
53
+ return arg;
54
+ });
55
+ }
@@ -0,0 +1,2 @@
1
+ import { AnyClass } from '@magek/common';
2
+ export declare function NonExposed(target: AnyClass | InstanceType<AnyClass>, methodName: string | undefined, parameterIndex?: number): void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NonExposed = NonExposed;
4
+ const magek_1 = require("../magek");
5
+ const metadata_1 = require("./metadata");
6
+ function NonExposed(target, methodName, parameterIndex) {
7
+ magek_1.Magek.configureCurrentEnv((config) => {
8
+ var _a;
9
+ const className = (_a = target.name) !== null && _a !== void 0 ? _a : target.constructor.name;
10
+ const value = config.nonExposedGraphQLMetadataKey[className] || [];
11
+ const fieldName = getFieldName(methodName, target, parameterIndex);
12
+ config.nonExposedGraphQLMetadataKey[className] = [...value, fieldName];
13
+ });
14
+ }
15
+ function getFieldName(methodName, target, parameterIndex) {
16
+ if (methodName) {
17
+ return methodName;
18
+ }
19
+ if (!parameterIndex) {
20
+ throw new Error(`We could not get field name information in ${target} for method ${methodName}`);
21
+ }
22
+ const argumentNames = (0, metadata_1.getFunctionArguments)(target);
23
+ return argumentNames[parameterIndex];
24
+ }
@@ -0,0 +1,35 @@
1
+ import { Class, NotificationInterface } from '@magek/common';
2
+ export type NotificationOptions = {
3
+ topic?: string;
4
+ };
5
+ /**
6
+ * Stage 3 field decorator context
7
+ */
8
+ interface Stage3FieldContext {
9
+ kind: 'field';
10
+ name: string | symbol;
11
+ static: boolean;
12
+ private: boolean;
13
+ metadata: Record<string | symbol, unknown>;
14
+ addInitializer?: (initializer: () => void) => void;
15
+ }
16
+ /**
17
+ * Decorator to mark a class as a Magek Notification.
18
+ * Notifications are events that can be published to external systems.
19
+ *
20
+ * @param options - Optional configuration for the notification (e.g., topic name)
21
+ * @returns A class decorator function
22
+ */
23
+ export declare const Notification: <TEvent extends NotificationInterface>(options?: NotificationOptions) => (eventClass: Class<TEvent>, context?: {
24
+ kind: "class";
25
+ metadata: Record<string | symbol, unknown>;
26
+ }) => void;
27
+ /**
28
+ * Optional decorator that marks a field in a notification class as the partition key.
29
+ * This is useful if you want to guarantee that all the event handlers for notifications
30
+ * of the same type will be executed in the same order.
31
+ *
32
+ * Can be used as both a parameter decorator and property decorator.
33
+ */
34
+ export declare function partitionKey(target: Class<NotificationInterface> | Object | undefined, propertyKeyOrContext?: string | symbol | Stage3FieldContext, parameterIndex?: number): void;
35
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Notification = void 0;
4
+ exports.partitionKey = partitionKey;
5
+ const magek_1 = require("../magek");
6
+ const metadata_1 = require("./metadata");
7
+ /**
8
+ * Type guard to detect Stage 3 field decorator context
9
+ */
10
+ function isStage3FieldContext(arg) {
11
+ return (arg !== null &&
12
+ typeof arg === 'object' &&
13
+ 'kind' in arg &&
14
+ arg.kind === 'field' &&
15
+ 'name' in arg);
16
+ }
17
+ // Symbol for storing partition key in Stage 3 metadata
18
+ const PARTITION_KEY_SYMBOL = Symbol.for('magek:partitionKey');
19
+ /**
20
+ * Decorator to mark a class as a Magek Notification.
21
+ * Notifications are events that can be published to external systems.
22
+ *
23
+ * @param options - Optional configuration for the notification (e.g., topic name)
24
+ * @returns A class decorator function
25
+ */
26
+ const Notification = (options) => (eventClass, context) => {
27
+ // Handle Stage 3: transfer partition key from context.metadata to config
28
+ if (context && context.kind === 'class' && context.metadata[PARTITION_KEY_SYMBOL]) {
29
+ const propertyName = context.metadata[PARTITION_KEY_SYMBOL];
30
+ magek_1.Magek.configureCurrentEnv((config) => {
31
+ config.partitionKeys[eventClass.name] = propertyName;
32
+ });
33
+ }
34
+ magek_1.Magek.configureCurrentEnv((config) => {
35
+ var _a;
36
+ if (config.notifications[eventClass.name] || config.events[eventClass.name]) {
37
+ throw new Error(`A notification called ${eventClass.name} is already registered.
38
+ If you think that this is an error, try performing a clean build.`);
39
+ }
40
+ const topic = (_a = options === null || options === void 0 ? void 0 : options.topic) !== null && _a !== void 0 ? _a : 'defaultTopic';
41
+ if (topic) {
42
+ config.eventToTopic[eventClass.name] = topic;
43
+ config.topicToEvent[topic] = eventClass.name;
44
+ }
45
+ config.notifications[eventClass.name] = {
46
+ class: eventClass,
47
+ };
48
+ });
49
+ };
50
+ exports.Notification = Notification;
51
+ /**
52
+ * Optional decorator that marks a field in a notification class as the partition key.
53
+ * This is useful if you want to guarantee that all the event handlers for notifications
54
+ * of the same type will be executed in the same order.
55
+ *
56
+ * Can be used as both a parameter decorator and property decorator.
57
+ */
58
+ function partitionKey(target, propertyKeyOrContext, parameterIndex) {
59
+ // Stage 3 field decorator usage
60
+ if (isStage3FieldContext(propertyKeyOrContext)) {
61
+ const context = propertyKeyOrContext;
62
+ const propertyName = String(context.name);
63
+ // Store in context.metadata so @Notification can read it
64
+ context.metadata[PARTITION_KEY_SYMBOL] = propertyName;
65
+ return;
66
+ }
67
+ // Property decorator usage: @partitionKey on a class property (legacy)
68
+ if (propertyKeyOrContext !== undefined && parameterIndex === undefined && target) {
69
+ const notificationClass = target.constructor;
70
+ const propertyName = String(propertyKeyOrContext);
71
+ magek_1.Magek.configureCurrentEnv((config) => {
72
+ if (config.partitionKeys[notificationClass.name] && config.partitionKeys[notificationClass.name] !== propertyName) {
73
+ throw new Error(`Error trying to register a partition key named \`${propertyName}\` for class \`${notificationClass.name}\`. It already had the partition key \`${config.partitionKeys[notificationClass.name]}\` defined and only one partition key is allowed for each notification event.`);
74
+ }
75
+ else {
76
+ config.partitionKeys[notificationClass.name] = propertyName;
77
+ }
78
+ });
79
+ }
80
+ // Parameter decorator usage: @partitionKey on constructor parameter
81
+ else if (parameterIndex !== undefined && target) {
82
+ const notificationClass = target;
83
+ const args = (0, metadata_1.getFunctionArguments)(notificationClass);
84
+ const propertyName = args[parameterIndex];
85
+ magek_1.Magek.configureCurrentEnv((config) => {
86
+ if (config.partitionKeys[notificationClass.name] && config.partitionKeys[notificationClass.name] !== propertyName) {
87
+ throw new Error(`Error trying to register a partition key named \`${propertyName}\` for class \`${notificationClass.name}\`. It already had the partition key \`${config.partitionKeys[notificationClass.name]}\` defined and only one partition key is allowed for each notification event.`);
88
+ }
89
+ else {
90
+ config.partitionKeys[notificationClass.name] = propertyName;
91
+ }
92
+ });
93
+ }
94
+ }
@@ -0,0 +1,32 @@
1
+ import { Class, EntityInterface, ProjectionInfo, ProjectionResult, ReadModelInterface, ReadModelJoinKeyFunction, UUID } from '@magek/common';
2
+ type PropertyType<TObj, TProp extends keyof TObj> = TObj[TProp];
3
+ type JoinKeyType<TEntity extends EntityInterface, TReadModel extends ReadModelInterface> = keyof TEntity | ReadModelJoinKeyFunction<TEntity, TReadModel>;
4
+ type UUIDLike = string | UUID;
5
+ /**
6
+ * Stage 3 method decorator context
7
+ */
8
+ interface Stage3MethodContext {
9
+ kind: 'method';
10
+ name: string | symbol;
11
+ static: boolean;
12
+ private: boolean;
13
+ metadata: Record<string | symbol, unknown>;
14
+ addInitializer?: (initializer: () => void) => void;
15
+ }
16
+ /**
17
+ * Decorator to register a read model method as a projection
18
+ * for a specific entity
19
+ *
20
+ * @param originEntity The entity that this method will react to
21
+ * @param joinKey
22
+ * @param unProject
23
+ */
24
+ export declare function Projects<TEntity extends EntityInterface, TJoinKey extends keyof TEntity, TReadModel extends ReadModelInterface>(originEntity: Class<TEntity>, joinKey: JoinKeyType<TEntity, TReadModel>, unProject?: UnprojectionMethod<TEntity, TReadModel, PropertyType<TEntity, TJoinKey>>): <TReceivedReadModel extends ReadModelInterface>(readModelClassOrMethod: Class<TReceivedReadModel> | Function, methodNameOrContext: string | Stage3MethodContext, methodDescriptor?: ProjectionMethod<TEntity, TReceivedReadModel, JoinKeyType<TEntity, TReceivedReadModel>>) => void;
25
+ type ProjectionMethodDefinitionForArray<TEntity, TReadModel> = (_: TEntity, readModelID: UUID, readModel?: TReadModel, projectionInfo?: ProjectionInfo) => ProjectionResult<TReadModel>;
26
+ type ProjectionMethodDefinition<TEntity, TReadModel> = (_: TEntity, readModel?: TReadModel, projectionInfo?: ProjectionInfo) => ProjectionResult<TReadModel>;
27
+ type ProjectionMethod<TEntity extends EntityInterface, TReadModel extends ReadModelInterface, TJoinKeyType extends JoinKeyType<TEntity, TReadModel>> = TJoinKeyType extends ReadModelJoinKeyFunction<TEntity, TReadModel> ? ProjectionMethodWithEntityConditionalReadModelIdAndReadModel<TEntity, TReadModel> : TJoinKeyType extends keyof TEntity ? NonNullable<PropertyType<TEntity, TJoinKeyType>> extends Array<UUIDLike> ? ProjectionMethodWithEntityReadModelIdAndReadModel<TEntity, TReadModel> : ProjectionMethodWithEntityAndReadModel<TEntity, TReadModel> : never;
28
+ type ProjectionMethodWithEntityAndReadModel<TEntity extends EntityInterface, TReadModel extends ReadModelInterface> = TypedPropertyDescriptor<(_: TEntity, readModel?: TReadModel) => ProjectionResult<TReadModel>>;
29
+ type ProjectionMethodWithEntityConditionalReadModelIdAndReadModel<TEntity extends EntityInterface, TReadModel extends ReadModelInterface> = TypedPropertyDescriptor<(_: TEntity, readModelID: UUID | undefined, readModel?: TReadModel) => ProjectionResult<TReadModel>>;
30
+ type ProjectionMethodWithEntityReadModelIdAndReadModel<TEntity extends EntityInterface, TReadModel extends ReadModelInterface> = TypedPropertyDescriptor<(_: TEntity, readModelID: UUID, readModel?: TReadModel) => ProjectionResult<TReadModel>>;
31
+ type UnprojectionMethod<TEntity, TReadModel, TPropType> = TPropType extends Array<UUID> ? ProjectionMethodDefinitionForArray<TEntity, TReadModel> : ProjectionMethodDefinition<TEntity, TReadModel>;
32
+ export {};