@magek/core 0.0.6 → 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.
- package/dist/authorizer.js +1 -1
- package/dist/command-dispatcher.js +47 -41
- package/dist/core-concepts/data-migration/entities/data-migration-entity.js +5 -2
- package/dist/core-concepts/data-migration/events/data-migration-finished.js +3 -1
- package/dist/core-concepts/data-migration/events/data-migration-started.js +3 -1
- package/dist/core-concepts/data-migration/events/entity-migrated.js +4 -0
- package/dist/core-concepts/touch-entity/events/entity-touched.js +2 -0
- package/dist/data-migrations.js +59 -54
- package/dist/decorators/command.d.ts +4 -11
- package/dist/decorators/command.js +10 -18
- package/dist/decorators/data-migration.d.ts +4 -1
- package/dist/decorators/data-migration.js +3 -1
- package/dist/decorators/decorator-types.d.ts +50 -0
- package/dist/decorators/decorator-types.js +11 -0
- package/dist/decorators/decorator-utils.d.ts +1 -0
- package/dist/decorators/decorator-utils.js +2 -0
- package/dist/decorators/entity.d.ts +7 -15
- package/dist/decorators/entity.js +27 -37
- package/dist/decorators/event-handler.d.ts +11 -1
- package/dist/decorators/event-handler.js +13 -1
- package/dist/decorators/event.d.ts +4 -1
- package/dist/decorators/event.js +3 -2
- package/dist/decorators/field-metadata-reader.d.ts +8 -3
- package/dist/decorators/field-metadata-reader.js +50 -62
- package/dist/decorators/field.d.ts +23 -0
- package/dist/decorators/field.js +41 -0
- package/dist/decorators/global-error-handler.d.ts +10 -1
- package/dist/decorators/global-error-handler.js +9 -1
- package/dist/decorators/global-event-handler.d.ts +10 -1
- package/dist/decorators/global-event-handler.js +9 -1
- package/dist/decorators/health-sensor.d.ts +4 -1
- package/dist/decorators/health-sensor.js +3 -2
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/metadata.d.ts +17 -1
- package/dist/decorators/metadata.js +22 -22
- package/dist/decorators/non-exposed.d.ts +13 -2
- package/dist/decorators/non-exposed.js +22 -20
- package/dist/decorators/notification.d.ts +6 -18
- package/dist/decorators/notification.js +10 -50
- package/dist/decorators/projects.d.ts +5 -18
- package/dist/decorators/projects.js +23 -54
- package/dist/decorators/query.d.ts +11 -1
- package/dist/decorators/query.js +18 -4
- package/dist/decorators/read-model.d.ts +13 -27
- package/dist/decorators/read-model.js +45 -77
- package/dist/decorators/role.d.ts +9 -3
- package/dist/decorators/role.js +8 -3
- package/dist/decorators/scheduled-command.d.ts +4 -1
- package/dist/decorators/scheduled-command.js +3 -1
- package/dist/decorators/schema-migration.d.ts +11 -27
- package/dist/decorators/schema-migration.js +32 -77
- package/dist/decorators/sequenced-by.d.ts +7 -25
- package/dist/decorators/sequenced-by.js +11 -71
- package/dist/event-dispatcher.js +29 -24
- package/dist/event-processor.js +106 -103
- package/dist/event-stream-consumer.js +25 -20
- package/dist/event-stream-producer.js +22 -17
- package/dist/events-reader.js +1 -0
- package/dist/global-error-dispatcher.js +3 -2
- package/dist/graphql-dispatcher.js +161 -156
- package/dist/index.js +4 -0
- package/dist/instrumentation/decorator/trace.d.ts +11 -3
- package/dist/instrumentation/decorator/trace.js +17 -71
- package/dist/magek.js +2 -2
- package/dist/query-dispatcher.js +2 -0
- package/dist/read-model-schema-migrator.js +71 -68
- package/dist/read-models-reader.js +178 -180
- package/dist/register-handler.js +3 -3
- package/dist/scheduled-command-dispatcher.js +48 -42
- package/dist/schema-migrator.js +63 -59
- package/dist/sensor/health/health-service.js +2 -1
- package/dist/services/event-store.js +221 -224
- package/dist/services/graphql/graphql-generator.js +11 -8
- package/dist/services/graphql/graphql-mutation-generator.js +4 -0
- package/dist/services/graphql/graphql-query-generator.js +14 -0
- package/dist/services/graphql/graphql-subcriptions-generator.js +7 -0
- package/dist/services/graphql/graphql-type-informer.js +4 -3
- package/dist/services/graphql/query-generators/graphql-query-by-keys-generator.js +4 -0
- package/dist/services/graphql/query-generators/graphql-query-events-generator.js +3 -0
- package/dist/services/graphql/query-generators/graphql-query-filters-generator.js +6 -0
- package/dist/services/graphql/query-generators/graphql-query-generator.js +4 -0
- package/dist/services/graphql/query-generators/graphql-query-listed-generator.js +7 -0
- package/dist/services/graphql/query-helpers/graphql-handled-fields-generator.js +5 -2
- package/dist/services/graphql/query-helpers/graphql-query-filter-arguments-builder.js +3 -0
- package/dist/services/graphql/query-helpers/graphql-query-filter-fields-builder.js +4 -0
- package/dist/services/graphql/query-helpers/graphql-query-sort-builder.js +4 -2
- package/dist/services/graphql/websocket-protocol/graphql-websocket-protocol.js +5 -3
- package/dist/services/pub-sub/read-model-pub-sub.js +1 -0
- package/dist/services/raw-events-parser.js +1 -1
- package/dist/services/read-model-store.js +16 -17
- package/dist/services/token-verifiers/jwks-uri-token-verifier.js +8 -4
- package/dist/services/token-verifiers/public-key-token-verifier.js +4 -2
- package/dist/services/token-verifiers/role-based-token-verifier.js +2 -1
- package/dist/services/token-verifiers/utilities.js +1 -1
- package/dist/subscribers-notifier.js +98 -92
- package/dist/token-verifier.js +2 -1
- package/package.json +4 -4
- package/dist/decorators/stage3-utils.d.ts +0 -6
- package/dist/decorators/stage3-utils.js +0 -25
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { EventInterface, EventHandlerInterface, Class, NotificationInterface } from '@magek/common';
|
|
2
|
-
|
|
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
|
-
|
|
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
|
|
11
|
+
export declare function Event<TEvent extends EventInterface>(eventClass: Class<TEvent>, _context: ClassDecoratorContext): void;
|
package/dist/decorators/event.js
CHANGED
|
@@ -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
|
-
|
|
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 @
|
|
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("
|
|
6
|
-
|
|
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 @
|
|
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: @
|
|
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
|
-
|
|
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
|
|
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
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
|
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 @
|
|
183
|
-
const dependencies =
|
|
184
|
-
|
|
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 @
|
|
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 @
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
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';
|
package/dist/decorators/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 =
|
|
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 {
|
|
2
|
-
|
|
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.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
}
|