@magek/core 0.0.5 → 0.0.7

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 (100) hide show
  1. package/dist/authorizer.js +1 -1
  2. package/dist/command-dispatcher.js +47 -41
  3. package/dist/core-concepts/data-migration/entities/data-migration-entity.js +5 -2
  4. package/dist/core-concepts/data-migration/events/data-migration-finished.js +3 -1
  5. package/dist/core-concepts/data-migration/events/data-migration-started.js +3 -1
  6. package/dist/core-concepts/data-migration/events/entity-migrated.js +4 -0
  7. package/dist/core-concepts/touch-entity/events/entity-touched.js +2 -0
  8. package/dist/data-migrations.js +59 -54
  9. package/dist/decorators/command.d.ts +4 -11
  10. package/dist/decorators/command.js +10 -18
  11. package/dist/decorators/data-migration.d.ts +4 -1
  12. package/dist/decorators/data-migration.js +3 -1
  13. package/dist/decorators/decorator-types.d.ts +50 -0
  14. package/dist/decorators/decorator-types.js +11 -0
  15. package/dist/decorators/decorator-utils.d.ts +1 -0
  16. package/dist/decorators/decorator-utils.js +2 -0
  17. package/dist/decorators/entity.d.ts +7 -15
  18. package/dist/decorators/entity.js +27 -37
  19. package/dist/decorators/event-handler.d.ts +11 -1
  20. package/dist/decorators/event-handler.js +13 -1
  21. package/dist/decorators/event.d.ts +4 -1
  22. package/dist/decorators/event.js +3 -2
  23. package/dist/decorators/field-metadata-reader.d.ts +8 -3
  24. package/dist/decorators/field-metadata-reader.js +50 -62
  25. package/dist/decorators/field.d.ts +23 -0
  26. package/dist/decorators/field.js +41 -0
  27. package/dist/decorators/global-error-handler.d.ts +10 -1
  28. package/dist/decorators/global-error-handler.js +9 -1
  29. package/dist/decorators/global-event-handler.d.ts +10 -1
  30. package/dist/decorators/global-event-handler.js +9 -1
  31. package/dist/decorators/health-sensor.d.ts +4 -1
  32. package/dist/decorators/health-sensor.js +3 -2
  33. package/dist/decorators/index.d.ts +3 -0
  34. package/dist/decorators/index.js +2 -0
  35. package/dist/decorators/metadata.d.ts +17 -1
  36. package/dist/decorators/metadata.js +22 -22
  37. package/dist/decorators/non-exposed.d.ts +13 -2
  38. package/dist/decorators/non-exposed.js +22 -20
  39. package/dist/decorators/notification.d.ts +6 -18
  40. package/dist/decorators/notification.js +10 -50
  41. package/dist/decorators/projects.d.ts +5 -18
  42. package/dist/decorators/projects.js +23 -54
  43. package/dist/decorators/query.d.ts +11 -1
  44. package/dist/decorators/query.js +18 -4
  45. package/dist/decorators/read-model.d.ts +13 -27
  46. package/dist/decorators/read-model.js +45 -77
  47. package/dist/decorators/role.d.ts +9 -3
  48. package/dist/decorators/role.js +8 -3
  49. package/dist/decorators/scheduled-command.d.ts +4 -1
  50. package/dist/decorators/scheduled-command.js +3 -1
  51. package/dist/decorators/schema-migration.d.ts +11 -27
  52. package/dist/decorators/schema-migration.js +32 -77
  53. package/dist/decorators/sequenced-by.d.ts +7 -25
  54. package/dist/decorators/sequenced-by.js +11 -71
  55. package/dist/event-dispatcher.js +29 -24
  56. package/dist/event-processor.js +106 -103
  57. package/dist/event-stream-consumer.js +25 -20
  58. package/dist/event-stream-producer.js +22 -17
  59. package/dist/events-reader.js +1 -0
  60. package/dist/global-error-dispatcher.js +3 -2
  61. package/dist/graphql-dispatcher.js +161 -156
  62. package/dist/index.js +4 -0
  63. package/dist/instrumentation/decorator/trace.d.ts +11 -3
  64. package/dist/instrumentation/decorator/trace.js +17 -71
  65. package/dist/magek.js +2 -2
  66. package/dist/query-dispatcher.js +2 -0
  67. package/dist/read-model-schema-migrator.js +71 -68
  68. package/dist/read-models-reader.js +178 -180
  69. package/dist/register-handler.js +3 -3
  70. package/dist/scheduled-command-dispatcher.js +48 -42
  71. package/dist/schema-migrator.js +63 -59
  72. package/dist/sensor/health/health-service.js +2 -1
  73. package/dist/services/event-store.js +221 -224
  74. package/dist/services/graphql/graphql-generator.js +11 -8
  75. package/dist/services/graphql/graphql-mutation-generator.js +4 -0
  76. package/dist/services/graphql/graphql-query-generator.js +14 -0
  77. package/dist/services/graphql/graphql-subcriptions-generator.js +7 -0
  78. package/dist/services/graphql/graphql-type-informer.js +4 -3
  79. package/dist/services/graphql/query-generators/graphql-query-by-keys-generator.js +4 -0
  80. package/dist/services/graphql/query-generators/graphql-query-events-generator.js +3 -0
  81. package/dist/services/graphql/query-generators/graphql-query-filters-generator.js +6 -0
  82. package/dist/services/graphql/query-generators/graphql-query-generator.js +4 -0
  83. package/dist/services/graphql/query-generators/graphql-query-listed-generator.js +7 -0
  84. package/dist/services/graphql/query-helpers/graphql-handled-fields-generator.js +5 -2
  85. package/dist/services/graphql/query-helpers/graphql-query-filter-arguments-builder.js +3 -0
  86. package/dist/services/graphql/query-helpers/graphql-query-filter-fields-builder.js +4 -0
  87. package/dist/services/graphql/query-helpers/graphql-query-sort-builder.js +4 -2
  88. package/dist/services/graphql/websocket-protocol/graphql-websocket-protocol.js +5 -3
  89. package/dist/services/pub-sub/read-model-pub-sub.js +1 -0
  90. package/dist/services/raw-events-parser.js +1 -1
  91. package/dist/services/read-model-store.js +16 -17
  92. package/dist/services/token-verifiers/jwks-uri-token-verifier.js +8 -4
  93. package/dist/services/token-verifiers/public-key-token-verifier.js +4 -2
  94. package/dist/services/token-verifiers/role-based-token-verifier.js +2 -1
  95. package/dist/services/token-verifiers/utilities.js +1 -1
  96. package/dist/subscribers-notifier.js +98 -92
  97. package/dist/token-verifier.js +2 -1
  98. package/package.json +4 -4
  99. package/dist/decorators/stage3-utils.d.ts +0 -6
  100. package/dist/decorators/stage3-utils.js +0 -25
@@ -1,3 +1,13 @@
1
1
  import { EventInterface, EventHandlerInterface, Class, NotificationInterface } from '@magek/common';
2
- export declare function EventHandler<TEvent extends EventInterface | NotificationInterface>(event: Class<TEvent>): <TEventHandler extends EventHandlerInterface>(eventHandlerClass: TEventHandler) => void;
2
+ import { ClassDecoratorContext } from './decorator-types';
3
+ /**
4
+ * Decorator to mark a class as an Event Handler.
5
+ * Event handlers react to specific events and perform side effects.
6
+ *
7
+ * Uses TC39 Stage 3 decorators.
8
+ *
9
+ * @param event - The event class to handle
10
+ * @returns A class decorator function
11
+ */
12
+ export declare function EventHandler<TEvent extends EventInterface | NotificationInterface>(event: Class<TEvent>): <TEventHandler extends EventHandlerInterface>(eventHandlerClass: TEventHandler, context: ClassDecoratorContext) => void;
3
13
  export declare function registerEventHandler<TEventHandler extends EventHandlerInterface>(eventName: string, eventHandlerClass: TEventHandler): void;
@@ -3,8 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventHandler = EventHandler;
4
4
  exports.registerEventHandler = registerEventHandler;
5
5
  const magek_1 = require("../magek");
6
+ /**
7
+ * Decorator to mark a class as an Event Handler.
8
+ * Event handlers react to specific events and perform side effects.
9
+ *
10
+ * Uses TC39 Stage 3 decorators.
11
+ *
12
+ * @param event - The event class to handle
13
+ * @returns A class decorator function
14
+ */
6
15
  function EventHandler(event) {
7
- return (eventHandlerClass) => registerEventHandler(event.name, eventHandlerClass);
16
+ // Note: `_context` is required for the Stage 3 decorator signature but is not used here.
17
+ return (eventHandlerClass, _context) => {
18
+ registerEventHandler(event.name, eventHandlerClass);
19
+ };
8
20
  }
9
21
  function registerEventHandler(eventName, eventHandlerClass) {
10
22
  magek_1.Magek.configureCurrentEnv((config) => {
@@ -1,8 +1,11 @@
1
1
  import { Class, EventInterface } from '@magek/common';
2
+ import { ClassDecoratorContext } from './decorator-utils';
2
3
  /**
3
4
  * Decorator to mark a class as a Magek Event.
4
5
  * Events are immutable records of facts that occurred in your system.
5
6
  *
7
+ * Uses TC39 Stage 3 decorators.
8
+ *
6
9
  * @param eventClass - The event class to register
7
10
  */
8
- export declare function Event<TEvent extends EventInterface>(eventClass: Class<TEvent>): void;
11
+ export declare function Event<TEvent extends EventInterface>(eventClass: Class<TEvent>, _context: ClassDecoratorContext): void;
@@ -6,10 +6,11 @@ const magek_1 = require("../magek");
6
6
  * Decorator to mark a class as a Magek Event.
7
7
  * Events are immutable records of facts that occurred in your system.
8
8
  *
9
+ * Uses TC39 Stage 3 decorators.
10
+ *
9
11
  * @param eventClass - The event class to register
10
12
  */
11
- // Disabling unused vars here, because it won't allow us to call the decorator without parens
12
- function Event(eventClass) {
13
+ function Event(eventClass, _context) {
13
14
  magek_1.Magek.configureCurrentEnv((config) => {
14
15
  if (config.events[eventClass.name]) {
15
16
  throw new Error(`A event called ${eventClass.name} is already registered.
@@ -1,6 +1,11 @@
1
- import 'reflect-metadata';
2
1
  import { AnyClass, ClassMetadata } from '@magek/common';
2
+ import { DecoratorMetadataObject } from './decorator-types';
3
3
  /**
4
- * Build ClassMetadata from @Field() decorators
4
+ * Build ClassMetadata from @field() decorators.
5
+ *
6
+ * @param classType - The class to build metadata for
7
+ * @param contextMetadata - Optional context.metadata from class decorator.
8
+ * IMPORTANT: During class decorator execution, Symbol.metadata isn't yet attached to the class.
9
+ * Class decorators must pass context.metadata to read field metadata correctly.
5
10
  */
6
- export declare function buildClassMetadataFromFields(classType: AnyClass): ClassMetadata;
11
+ export declare function buildClassMetadataFromFields(classType: AnyClass, contextMetadata?: DecoratorMetadataObject): ClassMetadata;
@@ -1,24 +1,19 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  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');
4
+ const decorator_types_1 = require("./decorator-types");
5
+ const read_model_1 = require("./read-model");
11
6
  /**
12
- * Extract TypeMetadata from a @Field() decorator's metadata
7
+ * Extract TypeMetadata from a @field() decorator's metadata
13
8
  */
14
9
  function extractTypeMetadata(fieldMeta, isGetter = false) {
15
10
  let targetType;
16
11
  let isArray = false;
17
12
  let isReadonlyArray = false;
18
- // If typeFunction is provided, use it
13
+ // If typeFunction is provided, use it to determine the type
19
14
  if (fieldMeta.typeFunction) {
20
15
  const result = fieldMeta.typeFunction();
21
- // Handle array syntax: @Field(type => [String])
16
+ // Handle array syntax: @field(type => [String])
22
17
  if (Array.isArray(result)) {
23
18
  isArray = true;
24
19
  targetType = result[0];
@@ -27,10 +22,7 @@ function extractTypeMetadata(fieldMeta, isGetter = false) {
27
22
  targetType = result;
28
23
  }
29
24
  }
30
- else {
31
- // Fall back to design:type from emitDecoratorMetadata
32
- targetType = fieldMeta.designType;
33
- }
25
+ // If no typeFunction, targetType remains undefined and will be treated as 'any' type
34
26
  // Determine type group and construct TypeMetadata
35
27
  return analyzeType(targetType, {
36
28
  isNullable: fieldMeta.options.nullable || false,
@@ -129,61 +121,52 @@ function analyzeType(targetType, options) {
129
121
  };
130
122
  }
131
123
  /**
132
- * Get all fields from a class, including inherited fields
124
+ * Get metadata object, preferring contextMetadata (from class decorator) over Symbol.metadata.
125
+ * During class decorator execution, Symbol.metadata isn't yet attached to the class,
126
+ * so we need to use context.metadata directly.
133
127
  */
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
- }
128
+ function getMetadataObject(classType, contextMetadata) {
129
+ if (contextMetadata) {
130
+ return contextMetadata;
147
131
  }
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);
132
+ // Fall back to Symbol.metadata (for post-decorator access)
133
+ const classRecord = classType;
134
+ return classRecord[decorator_types_1.SYMBOL_METADATA];
135
+ }
136
+ /**
137
+ * Get all fields from a class, including inherited fields.
138
+ * Reads from Symbol.metadata (set by TC39 Stage 3 decorators).
139
+ *
140
+ * @param classType - The class to get fields from
141
+ * @param contextMetadata - Optional context.metadata from class decorator (used during decorator execution)
142
+ */
143
+ function getAllFields(classType, contextMetadata) {
144
+ const metadata = getMetadataObject(classType, contextMetadata);
145
+ if (metadata?.[decorator_types_1.FIELDS_METADATA_KEY]) {
146
+ return [...metadata[decorator_types_1.FIELDS_METADATA_KEY]];
168
147
  }
169
- return fields;
148
+ return [];
170
149
  }
171
150
  /**
172
- * Get all getters (calculated fields) from a class
151
+ * Get all getters (calculated fields) from a class.
152
+ * Reads dependencies from Symbol.metadata (set by @calculatedField decorator).
153
+ *
154
+ * @param classType - The class to get getters from
155
+ * @param contextMetadata - Optional context.metadata from class decorator (used during decorator execution)
173
156
  */
174
- function getAllGetters(classType) {
175
- var _a;
157
+ function getAllGetters(classType, contextMetadata) {
176
158
  const getters = [];
177
159
  const prototype = classType.prototype;
160
+ // Get calculated field dependencies from metadata
161
+ const metadata = getMetadataObject(classType, contextMetadata);
162
+ const calculatedFields = metadata?.[read_model_1.CALCULATED_FIELDS_SYMBOL];
178
163
  // Get property descriptors
179
164
  const descriptors = Object.getOwnPropertyDescriptors(prototype);
180
165
  for (const [propertyKey, descriptor] of Object.entries(descriptors)) {
181
166
  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, {
167
+ // This is a getter, check if it has @calculatedField metadata
168
+ const dependencies = calculatedFields?.[propertyKey] || [];
169
+ const typeMetadata = analyzeType(Object, {
187
170
  isNullable: false,
188
171
  isGetAccessor: true,
189
172
  isArray: false,
@@ -199,19 +182,24 @@ function getAllGetters(classType) {
199
182
  return getters;
200
183
  }
201
184
  /**
202
- * Build ClassMetadata from @Field() decorators
185
+ * Build ClassMetadata from @field() decorators.
186
+ *
187
+ * @param classType - The class to build metadata for
188
+ * @param contextMetadata - Optional context.metadata from class decorator.
189
+ * IMPORTANT: During class decorator execution, Symbol.metadata isn't yet attached to the class.
190
+ * Class decorators must pass context.metadata to read field metadata correctly.
203
191
  */
204
- function buildClassMetadataFromFields(classType) {
192
+ function buildClassMetadataFromFields(classType, contextMetadata) {
205
193
  // Get all fields (including inherited)
206
- const fieldMetadatas = getAllFields(classType);
194
+ const fieldMetadatas = getAllFields(classType, contextMetadata);
207
195
  // Convert to PropertyMetadata
208
196
  const fields = fieldMetadatas.map((fieldMeta) => ({
209
197
  name: fieldMeta.name,
210
198
  typeInfo: extractTypeMetadata(fieldMeta, false),
211
199
  dependencies: [],
212
200
  }));
213
- // Get getter methods (for @CalculatedField)
214
- const methods = getAllGetters(classType);
201
+ // Get getter methods (for @calculatedField)
202
+ const methods = getAllGetters(classType, contextMetadata);
215
203
  return {
216
204
  name: classType.name,
217
205
  type: classType,
@@ -0,0 +1,23 @@
1
+ import { FieldOptions, TypeFunction } from '@magek/common';
2
+ import { FieldDecoratorContext } from './decorator-types';
3
+ /**
4
+ * Stage 3 field decorator type
5
+ */
6
+ type Stage3FieldDecorator = (value: undefined, context: FieldDecoratorContext) => void;
7
+ /**
8
+ * @field() decorator for explicit type declaration
9
+ *
10
+ * Uses TC39 Stage 3 decorators.
11
+ *
12
+ * Usage:
13
+ * @field() - Simple type
14
+ * @field(type => String) - Explicit type
15
+ * @field(type => [String]) - Array type
16
+ * @field({ nullable: true }) - With options
17
+ * @field(type => String, { nullable: true }) - Type with options
18
+ */
19
+ export declare function field(): Stage3FieldDecorator;
20
+ export declare function field(options: FieldOptions): Stage3FieldDecorator;
21
+ export declare function field(typeFunction: TypeFunction): Stage3FieldDecorator;
22
+ export declare function field(typeFunction: TypeFunction, options: FieldOptions): Stage3FieldDecorator;
23
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.field = field;
4
+ const decorator_types_1 = require("./decorator-types");
5
+ /**
6
+ * Handle Stage 3 decorator format (TC39 decorators)
7
+ */
8
+ function handleStage3Decorator(context, typeFunction, fieldOptions) {
9
+ const fieldMetadata = {
10
+ name: context.name.toString(),
11
+ typeFunction,
12
+ options: fieldOptions,
13
+ };
14
+ // Store in context.metadata for later retrieval by class decorators
15
+ // Class decorators (like @Command, @Entity, etc.) will transfer this to the class constructor
16
+ if (context.metadata) {
17
+ if (!context.metadata[decorator_types_1.FIELDS_METADATA_KEY]) {
18
+ context.metadata[decorator_types_1.FIELDS_METADATA_KEY] = [];
19
+ }
20
+ const fields = context.metadata[decorator_types_1.FIELDS_METADATA_KEY];
21
+ const filteredFields = fields.filter((f) => f.name !== fieldMetadata.name);
22
+ filteredFields.push(fieldMetadata);
23
+ context.metadata[decorator_types_1.FIELDS_METADATA_KEY] = filteredFields;
24
+ }
25
+ }
26
+ function field(typeFunctionOrOptions, options) {
27
+ // Parse arguments
28
+ let typeFunction;
29
+ let fieldOptions = {};
30
+ if (typeof typeFunctionOrOptions === 'function') {
31
+ typeFunction = typeFunctionOrOptions;
32
+ fieldOptions = options || {};
33
+ }
34
+ else if (typeFunctionOrOptions) {
35
+ fieldOptions = typeFunctionOrOptions;
36
+ }
37
+ // Return Stage 3 decorator
38
+ return function fieldDecorator(_value, context) {
39
+ handleStage3Decorator(context, typeFunction, fieldOptions);
40
+ };
41
+ }
@@ -1,2 +1,11 @@
1
1
  import { GlobalErrorHandlerInterface } from '@magek/common';
2
- export declare function GlobalErrorHandler(): (errorHandlerClass: GlobalErrorHandlerInterface) => void;
2
+ import { ClassDecoratorContext } from './decorator-types';
3
+ /**
4
+ * Decorator to mark a class as a Global Error Handler.
5
+ * Global error handlers catch and handle errors from the entire system.
6
+ *
7
+ * Uses TC39 Stage 3 decorators.
8
+ *
9
+ * @returns A class decorator function
10
+ */
11
+ export declare function GlobalErrorHandler(): (errorHandlerClass: GlobalErrorHandlerInterface, context: ClassDecoratorContext) => void;
@@ -2,8 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GlobalErrorHandler = GlobalErrorHandler;
4
4
  const magek_1 = require("../magek");
5
+ /**
6
+ * Decorator to mark a class as a Global Error Handler.
7
+ * Global error handlers catch and handle errors from the entire system.
8
+ *
9
+ * Uses TC39 Stage 3 decorators.
10
+ *
11
+ * @returns A class decorator function
12
+ */
5
13
  function GlobalErrorHandler() {
6
- return (errorHandlerClass) => {
14
+ return (errorHandlerClass, _context) => {
7
15
  magek_1.Magek.configureCurrentEnv((config) => {
8
16
  if (config.globalErrorsHandler) {
9
17
  throw new Error(`An error handler called ${errorHandlerClass.name} is already registered.
@@ -1,3 +1,12 @@
1
1
  import { EventHandlerInterface } from '@magek/common';
2
+ import { ClassDecoratorContext } from './decorator-types';
2
3
  export declare const GLOBAL_EVENT_HANDLERS = "GLOBAL_EVENT_HANDLERS";
3
- export declare function GlobalEventHandler<TEventHandler extends EventHandlerInterface>(eventHandlerClass: TEventHandler): void;
4
+ /**
5
+ * Decorator to mark a class as a Global Event Handler.
6
+ * Global event handlers react to all events in the system.
7
+ *
8
+ * Uses TC39 Stage 3 decorators.
9
+ *
10
+ * @param eventHandlerClass - The event handler class
11
+ */
12
+ export declare function GlobalEventHandler<TEventHandler extends EventHandlerInterface>(eventHandlerClass: TEventHandler, context: ClassDecoratorContext): void;
@@ -4,6 +4,14 @@ exports.GLOBAL_EVENT_HANDLERS = void 0;
4
4
  exports.GlobalEventHandler = GlobalEventHandler;
5
5
  const event_handler_1 = require("./event-handler");
6
6
  exports.GLOBAL_EVENT_HANDLERS = 'GLOBAL_EVENT_HANDLERS';
7
- function GlobalEventHandler(eventHandlerClass) {
7
+ /**
8
+ * Decorator to mark a class as a Global Event Handler.
9
+ * Global event handlers react to all events in the system.
10
+ *
11
+ * Uses TC39 Stage 3 decorators.
12
+ *
13
+ * @param eventHandlerClass - The event handler class
14
+ */
15
+ function GlobalEventHandler(eventHandlerClass, context) {
8
16
  (0, event_handler_1.registerEventHandler)(exports.GLOBAL_EVENT_HANDLERS, eventHandlerClass);
9
17
  }
@@ -1,8 +1,11 @@
1
1
  import { Class, HealthIndicatorConfiguration, HealthIndicatorInterface } from '@magek/common';
2
+ import { ClassDecoratorContext } from './decorator-types';
2
3
  /**
3
4
  * Decorator to mark a class as a Magek Health Sensor.
4
5
  * Health sensors provide health status information for monitoring endpoints.
5
6
  *
7
+ * Uses TC39 Stage 3 decorators.
8
+ *
6
9
  * @param attributes - Health indicator configuration
7
10
  * @param attributes.id - Unique indicator identifier
8
11
  * @param attributes.name - Indicator description
@@ -11,4 +14,4 @@ import { Class, HealthIndicatorConfiguration, HealthIndicatorInterface } from '@
11
14
  * @param attributes.showChildren - If false, children components won't be included in the tree
12
15
  * @returns A class decorator function
13
16
  */
14
- export declare function HealthSensor(attributes: HealthIndicatorConfiguration): <TIndicator extends HealthIndicatorInterface>(healthIndicator: Class<TIndicator>) => void;
17
+ export declare function HealthSensor(attributes: HealthIndicatorConfiguration): <TIndicator extends HealthIndicatorInterface>(healthIndicator: Class<TIndicator>, context: ClassDecoratorContext) => void;
@@ -7,6 +7,8 @@ const health_indicators_1 = require("../sensor/health/health-indicators");
7
7
  * Decorator to mark a class as a Magek Health Sensor.
8
8
  * Health sensors provide health status information for monitoring endpoints.
9
9
  *
10
+ * Uses TC39 Stage 3 decorators.
11
+ *
10
12
  * @param attributes - Health indicator configuration
11
13
  * @param attributes.id - Unique indicator identifier
12
14
  * @param attributes.name - Indicator description
@@ -18,7 +20,6 @@ const health_indicators_1 = require("../sensor/health/health-indicators");
18
20
  function HealthSensor(attributes) {
19
21
  return (healthIndicator) => {
20
22
  magek_1.Magek.configureCurrentEnv((config) => {
21
- var _a;
22
23
  if (Object.keys(config.userHealthIndicators).length === 0) {
23
24
  config.userHealthIndicators = (0, health_indicators_1.defaultMagekHealthIndicators)(config);
24
25
  }
@@ -30,7 +31,7 @@ function HealthSensor(attributes) {
30
31
  name: attributes.name,
31
32
  enabled: attributes.enabled,
32
33
  details: attributes.details,
33
- showChildren: (_a = attributes.showChildren) !== null && _a !== void 0 ? _a : true,
34
+ showChildren: attributes.showChildren ?? true,
34
35
  },
35
36
  };
36
37
  });
@@ -1,4 +1,6 @@
1
+ export type { ClassDecoratorContext, FieldDecoratorContext, MethodDecoratorContext, GetterDecoratorContext, DecoratorMetadataObject, } from './decorator-types';
1
2
  export * from './command';
3
+ export * from './field';
2
4
  export * from './query';
3
5
  export * from './data-migration';
4
6
  export * from './entity';
@@ -14,3 +16,4 @@ export * from './schema-migration';
14
16
  export * from './sequenced-by';
15
17
  export * from './global-event-handler';
16
18
  export * from './non-exposed';
19
+ export * from './health-sensor';
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./command"), exports);
5
+ tslib_1.__exportStar(require("./field"), exports);
5
6
  tslib_1.__exportStar(require("./query"), exports);
6
7
  tslib_1.__exportStar(require("./data-migration"), exports);
7
8
  tslib_1.__exportStar(require("./entity"), exports);
@@ -17,3 +18,4 @@ tslib_1.__exportStar(require("./schema-migration"), exports);
17
18
  tslib_1.__exportStar(require("./sequenced-by"), exports);
18
19
  tslib_1.__exportStar(require("./global-event-handler"), exports);
19
20
  tslib_1.__exportStar(require("./non-exposed"), exports);
21
+ tslib_1.__exportStar(require("./health-sensor"), exports);
@@ -1,5 +1,21 @@
1
1
  import { AnyClass, ClassMetadata } from '@magek/common';
2
- export declare function getClassMetadata(classType: AnyClass): ClassMetadata;
2
+ import { DecoratorMetadataObject } from './decorator-types';
3
+ /**
4
+ * Get non-exposed fields from decorator metadata.
5
+ *
6
+ * @param metadata - The context.metadata object from a class decorator
7
+ * @returns Array of field names marked with @nonExposed
8
+ */
9
+ export declare function getNonExposedFields(metadata?: DecoratorMetadataObject): string[];
10
+ /**
11
+ * Get class metadata from @field() decorators.
12
+ *
13
+ * @param classType - The class to get metadata for
14
+ * @param contextMetadata - Optional context.metadata from class decorator.
15
+ * IMPORTANT: During class decorator execution, Symbol.metadata isn't yet attached to the class.
16
+ * Class decorators must pass context.metadata to read field metadata correctly.
17
+ */
18
+ export declare function getClassMetadata(classType: AnyClass, contextMetadata?: DecoratorMetadataObject): ClassMetadata;
3
19
  /**
4
20
  * Get the argument names from a given function.
5
21
  *
@@ -1,28 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNonExposedFields = getNonExposedFields;
3
4
  exports.getClassMetadata = getClassMetadata;
4
5
  exports.getFunctionArguments = getFunctionArguments;
5
- const common_1 = require("@magek/common");
6
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;
7
+ const non_exposed_1 = require("./non-exposed");
8
+ /**
9
+ * Get non-exposed fields from decorator metadata.
10
+ *
11
+ * @param metadata - The context.metadata object from a class decorator
12
+ * @returns Array of field names marked with @nonExposed
13
+ */
14
+ function getNonExposedFields(metadata) {
15
+ return metadata?.[non_exposed_1.NON_EXPOSED_SYMBOL] || [];
16
+ }
17
+ /**
18
+ * Get class metadata from @field() decorators.
19
+ *
20
+ * @param classType - The class to get metadata for
21
+ * @param contextMetadata - Optional context.metadata from class decorator.
22
+ * IMPORTANT: During class decorator execution, Symbol.metadata isn't yet attached to the class.
23
+ * Class decorators must pass context.metadata to read field metadata correctly.
24
+ */
25
+ function getClassMetadata(classType, contextMetadata) {
26
+ return (0, field_metadata_reader_1.buildClassMetadataFromFields)(classType, contextMetadata);
26
27
  }
27
28
  /**
28
29
  * Get the argument names from a given function.
@@ -36,9 +37,8 @@ function getClassMetadata(classType) {
36
37
  */
37
38
  // TODO: Consider extending `@magek/metadata` to yield constructor argument types
38
39
  function getFunctionArguments(func) {
39
- var _a;
40
40
  // First match everything inside the function argument parens.
41
- const args = (_a = func.toString().match(/([^(])*\(([^)]*)\)/)) === null || _a === void 0 ? void 0 : _a[2];
41
+ const args = func.toString().match(/([^(])*\(([^)]*)\)/)?.[2];
42
42
  if (!args)
43
43
  return [];
44
44
  // Split the arguments string into an array comma delimited.
@@ -1,2 +1,13 @@
1
- import { AnyClass } from '@magek/common';
2
- export declare function NonExposed(target: AnyClass | InstanceType<AnyClass>, methodName: string | undefined, parameterIndex?: number): void;
1
+ import { FieldDecoratorContext, MethodDecoratorContext } from './decorator-types';
2
+ type FieldOrMethodDecoratorContext = FieldDecoratorContext | MethodDecoratorContext;
3
+ /** Symbol for storing non-exposed fields in decorator context.metadata */
4
+ export declare const NON_EXPOSED_SYMBOL: unique symbol;
5
+ /**
6
+ * Decorator to mark a field or method as non-exposed in GraphQL.
7
+ *
8
+ * Uses TC39 Stage 3 decorators.
9
+ * Non-exposed fields are stored in context.metadata and read by class decorators
10
+ * (@Entity, @ReadModel, @Command, @Query) which register them to config.
11
+ */
12
+ export declare function nonExposed(_value: undefined | Function, context: FieldOrMethodDecoratorContext): void;
13
+ export {};
@@ -1,24 +1,26 @@
1
1
  "use strict";
2
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}`);
3
+ exports.NON_EXPOSED_SYMBOL = void 0;
4
+ exports.nonExposed = nonExposed;
5
+ /** Symbol for storing non-exposed fields in decorator context.metadata */
6
+ exports.NON_EXPOSED_SYMBOL = Symbol.for('magek:nonExposed');
7
+ /**
8
+ * Decorator to mark a field or method as non-exposed in GraphQL.
9
+ *
10
+ * Uses TC39 Stage 3 decorators.
11
+ * Non-exposed fields are stored in context.metadata and read by class decorators
12
+ * (@Entity, @ReadModel, @Command, @Query) which register them to config.
13
+ */
14
+ function nonExposed(_value, context) {
15
+ const fieldName = String(context.name);
16
+ // Store in context.metadata (becomes class[Symbol.metadata])
17
+ if (context.metadata) {
18
+ if (!context.metadata[exports.NON_EXPOSED_SYMBOL]) {
19
+ context.metadata[exports.NON_EXPOSED_SYMBOL] = [];
20
+ }
21
+ const nonExposedFields = context.metadata[exports.NON_EXPOSED_SYMBOL];
22
+ if (!nonExposedFields.includes(fieldName)) {
23
+ nonExposedFields.push(fieldName);
24
+ }
21
25
  }
22
- const argumentNames = (0, metadata_1.getFunctionArguments)(target);
23
- return argumentNames[parameterIndex];
24
26
  }