@cratis/chronicle 6.3.2 → 6.4.0
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/EventStore.ts +3 -0
- package/README.md +13 -2
- package/artifacts/validateArtifactSchemas.spec.ts +61 -0
- package/artifacts/validateArtifactSchemas.ts +39 -0
- package/compliance/pii.ts +7 -6
- package/compliance/subject.ts +6 -5
- package/confidentiality/encrypted.ts +7 -6
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +2 -0
- package/dist/EventStore.js.map +1 -1
- package/dist/artifacts/validateArtifactSchemas.d.ts +4 -0
- package/dist/artifacts/validateArtifactSchemas.d.ts.map +1 -0
- package/dist/artifacts/validateArtifactSchemas.js +38 -0
- package/dist/artifacts/validateArtifactSchemas.js.map +1 -0
- package/dist/compliance/pii.d.ts +2 -1
- package/dist/compliance/pii.d.ts.map +1 -1
- package/dist/compliance/pii.js +6 -5
- package/dist/compliance/pii.js.map +1 -1
- package/dist/compliance/subject.d.ts +2 -1
- package/dist/compliance/subject.d.ts.map +1 -1
- package/dist/compliance/subject.js +5 -4
- package/dist/compliance/subject.js.map +1 -1
- package/dist/confidentiality/encrypted.d.ts +2 -1
- package/dist/confidentiality/encrypted.d.ts.map +1 -1
- package/dist/confidentiality/encrypted.js +6 -5
- package/dist/confidentiality/encrypted.js.map +1 -1
- package/dist/events/eventTypeDecorator.d.ts +8 -7
- package/dist/events/eventTypeDecorator.d.ts.map +1 -1
- package/dist/events/eventTypeDecorator.js +22 -5
- package/dist/events/eventTypeDecorator.js.map +1 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -0
- package/dist/events/index.js.map +1 -1
- package/dist/projections/modelBound/addFrom.d.ts +2 -1
- package/dist/projections/modelBound/addFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/addFrom.js +4 -3
- package/dist/projections/modelBound/addFrom.js.map +1 -1
- package/dist/projections/modelBound/childrenFrom.d.ts +2 -1
- package/dist/projections/modelBound/childrenFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/childrenFrom.js +4 -3
- package/dist/projections/modelBound/childrenFrom.js.map +1 -1
- package/dist/projections/modelBound/clearWith.d.ts +2 -1
- package/dist/projections/modelBound/clearWith.d.ts.map +1 -1
- package/dist/projections/modelBound/clearWith.js +4 -3
- package/dist/projections/modelBound/clearWith.js.map +1 -1
- package/dist/projections/modelBound/count.d.ts +2 -1
- package/dist/projections/modelBound/count.d.ts.map +1 -1
- package/dist/projections/modelBound/count.js +4 -3
- package/dist/projections/modelBound/count.js.map +1 -1
- package/dist/projections/modelBound/decrement.d.ts +2 -1
- package/dist/projections/modelBound/decrement.d.ts.map +1 -1
- package/dist/projections/modelBound/decrement.js +4 -3
- package/dist/projections/modelBound/decrement.js.map +1 -1
- package/dist/projections/modelBound/fromAll.d.ts +2 -1
- package/dist/projections/modelBound/fromAll.d.ts.map +1 -1
- package/dist/projections/modelBound/fromAll.js +4 -3
- package/dist/projections/modelBound/fromAll.js.map +1 -1
- package/dist/projections/modelBound/fromEvery.d.ts +2 -1
- package/dist/projections/modelBound/fromEvery.d.ts.map +1 -1
- package/dist/projections/modelBound/fromEvery.js +4 -3
- package/dist/projections/modelBound/fromEvery.js.map +1 -1
- package/dist/projections/modelBound/increment.d.ts +2 -1
- package/dist/projections/modelBound/increment.d.ts.map +1 -1
- package/dist/projections/modelBound/increment.js +4 -3
- package/dist/projections/modelBound/increment.js.map +1 -1
- package/dist/projections/modelBound/join.d.ts +2 -1
- package/dist/projections/modelBound/join.d.ts.map +1 -1
- package/dist/projections/modelBound/join.js +4 -3
- package/dist/projections/modelBound/join.js.map +1 -1
- package/dist/projections/modelBound/nested.d.ts +1 -6
- package/dist/projections/modelBound/nested.d.ts.map +1 -1
- package/dist/projections/modelBound/nested.js +6 -2
- package/dist/projections/modelBound/nested.js.map +1 -1
- package/dist/projections/modelBound/noAutoMap.d.ts +4 -11
- package/dist/projections/modelBound/noAutoMap.d.ts.map +1 -1
- package/dist/projections/modelBound/noAutoMap.js +6 -2
- package/dist/projections/modelBound/noAutoMap.js.map +1 -1
- package/dist/projections/modelBound/removedWith.d.ts +2 -1
- package/dist/projections/modelBound/removedWith.d.ts.map +1 -1
- package/dist/projections/modelBound/removedWith.js +4 -3
- package/dist/projections/modelBound/removedWith.js.map +1 -1
- package/dist/projections/modelBound/removedWithJoin.d.ts +2 -1
- package/dist/projections/modelBound/removedWithJoin.d.ts.map +1 -1
- package/dist/projections/modelBound/removedWithJoin.js +4 -3
- package/dist/projections/modelBound/removedWithJoin.js.map +1 -1
- package/dist/projections/modelBound/setFrom.d.ts +2 -1
- package/dist/projections/modelBound/setFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/setFrom.js +4 -3
- package/dist/projections/modelBound/setFrom.js.map +1 -1
- package/dist/projections/modelBound/setFromContext.d.ts +3 -2
- package/dist/projections/modelBound/setFromContext.d.ts.map +1 -1
- package/dist/projections/modelBound/setFromContext.js +4 -3
- package/dist/projections/modelBound/setFromContext.js.map +1 -1
- package/dist/projections/modelBound/setValue.d.ts +2 -1
- package/dist/projections/modelBound/setValue.d.ts.map +1 -1
- package/dist/projections/modelBound/setValue.js +4 -3
- package/dist/projections/modelBound/setValue.js.map +1 -1
- package/dist/projections/modelBound/subtractFrom.d.ts +2 -1
- package/dist/projections/modelBound/subtractFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/subtractFrom.js +4 -3
- package/dist/projections/modelBound/subtractFrom.js.map +1 -1
- package/dist/readModels/readModel.d.ts +2 -1
- package/dist/readModels/readModel.d.ts.map +1 -1
- package/dist/readModels/readModel.js +22 -5
- package/dist/readModels/readModel.js.map +1 -1
- package/dist/schemas/JsonSchemaGenerator.d.ts +6 -1
- package/dist/schemas/JsonSchemaGenerator.d.ts.map +1 -1
- package/dist/schemas/JsonSchemaGenerator.js +41 -31
- package/dist/schemas/JsonSchemaGenerator.js.map +1 -1
- package/dist/schemas/createDeferredSchema.d.ts +7 -0
- package/dist/schemas/createDeferredSchema.d.ts.map +1 -0
- package/dist/schemas/createDeferredSchema.js +19 -0
- package/dist/schemas/createDeferredSchema.js.map +1 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/jsonSchemaProperty.d.ts +2 -1
- package/dist/schemas/jsonSchemaProperty.d.ts.map +1 -1
- package/dist/schemas/jsonSchemaProperty.js +3 -2
- package/dist/schemas/jsonSchemaProperty.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/TypeIntrospector.d.ts.map +1 -1
- package/dist/types/TypeIntrospector.js +9 -3
- package/dist/types/TypeIntrospector.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/propertyDecoratorMetadata.d.ts +17 -0
- package/dist/types/propertyDecoratorMetadata.d.ts.map +1 -0
- package/dist/types/propertyDecoratorMetadata.js +76 -0
- package/dist/types/propertyDecoratorMetadata.js.map +1 -0
- package/dist/types/standardDecoratorMetadata.d.ts +9 -0
- package/dist/types/standardDecoratorMetadata.d.ts.map +1 -0
- package/dist/types/standardDecoratorMetadata.js +20 -0
- package/dist/types/standardDecoratorMetadata.js.map +1 -0
- package/events/classDecorators.standard.spec.ts +77 -0
- package/events/eventTypeDecorator.ts +31 -13
- package/events/index.ts +2 -0
- package/package.json +3 -1
- package/projections/modelBound/addFrom.ts +5 -4
- package/projections/modelBound/childrenFrom.ts +5 -4
- package/projections/modelBound/clearWith.ts +5 -4
- package/projections/modelBound/count.ts +5 -4
- package/projections/modelBound/decorators.standard.spec.ts +71 -0
- package/projections/modelBound/decrement.ts +5 -4
- package/projections/modelBound/fromAll.ts +5 -4
- package/projections/modelBound/fromEvery.ts +5 -4
- package/projections/modelBound/increment.ts +5 -4
- package/projections/modelBound/join.ts +5 -4
- package/projections/modelBound/nested.ts +9 -2
- package/projections/modelBound/noAutoMap.ts +11 -2
- package/projections/modelBound/removedWith.ts +5 -4
- package/projections/modelBound/removedWithJoin.ts +5 -4
- package/projections/modelBound/setFrom.ts +5 -4
- package/projections/modelBound/setFromContext.ts +7 -6
- package/projections/modelBound/setValue.ts +5 -4
- package/projections/modelBound/subtractFrom.ts +5 -4
- package/readModels/readModel.ts +24 -6
- package/readModels/standardFallbacks.standard.spec.ts +39 -0
- package/schemas/JsonSchemaGenerator.confidentiality.spec.ts +2 -0
- package/schemas/JsonSchemaGenerator.spec.ts +28 -1
- package/schemas/JsonSchemaGenerator.ts +45 -30
- package/schemas/createDeferredSchema.ts +21 -0
- package/schemas/decorators.expected.fixture.ts +24 -0
- package/schemas/decorators.legacy.spec.ts +62 -0
- package/schemas/decorators.standard.spec.ts +235 -0
- package/schemas/index.ts +1 -0
- package/schemas/jsonSchemaProperty.ts +4 -3
- package/schemas/legacyDesignMetadata.spec.ts +39 -0
- package/types/TypeIntrospector.ts +8 -3
- package/types/index.ts +2 -0
- package/types/propertyDecoratorMetadata.ts +80 -0
- package/types/standardDecoratorMetadata.spec.ts +31 -0
- package/types/standardDecoratorMetadata.ts +26 -0
- package/vitest.config.ts +17 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the addFrom property decorator. */
|
|
8
9
|
export interface AddFromMetadata {
|
|
@@ -20,14 +21,14 @@ const METADATA_KEY = 'chronicle:projection:addFrom';
|
|
|
20
21
|
* @param eventPropertyName - Optional event property name. Defaults to the property name.
|
|
21
22
|
* @returns A property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function addFrom(eventType: Function, eventPropertyName?: string):
|
|
24
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
24
|
+
export function addFrom(eventType: Function, eventPropertyName?: string): ChroniclePropertyDecorator {
|
|
25
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
25
26
|
const key = propertyKey.toString();
|
|
26
27
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
27
28
|
const existing: AddFromMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
28
29
|
const metadata: AddFromMetadata = { eventType, eventPropertyName };
|
|
29
30
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -37,5 +38,5 @@ export function addFrom(eventType: Function, eventPropertyName?: string): Proper
|
|
|
37
38
|
* @returns An array of addFrom metadata entries.
|
|
38
39
|
*/
|
|
39
40
|
export function getAddFromMetadata(target: object, propertyKey: string): AddFromMetadata[] {
|
|
40
|
-
return
|
|
41
|
+
return getPropertyMetadata<AddFromMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
41
42
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the childrenFrom property decorator. */
|
|
8
9
|
export interface ChildrenFromMetadata {
|
|
@@ -31,14 +32,14 @@ export function childrenFrom(
|
|
|
31
32
|
key?: string,
|
|
32
33
|
identifiedBy?: string,
|
|
33
34
|
parentKey?: string
|
|
34
|
-
):
|
|
35
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
35
|
+
): ChroniclePropertyDecorator {
|
|
36
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
36
37
|
const propKey = propertyKey.toString();
|
|
37
38
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, propKey);
|
|
38
39
|
const existing: ChildrenFromMetadata[] = Reflect.getMetadata(METADATA_KEY, target, propKey) ?? [];
|
|
39
40
|
const metadata: ChildrenFromMetadata = { eventType, key, identifiedBy, parentKey };
|
|
40
41
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, propKey);
|
|
41
|
-
};
|
|
42
|
+
});
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -48,5 +49,5 @@ export function childrenFrom(
|
|
|
48
49
|
* @returns An array of childrenFrom metadata entries.
|
|
49
50
|
*/
|
|
50
51
|
export function getChildrenFromMetadata(target: object, propertyKey: string): ChildrenFromMetadata[] {
|
|
51
|
-
return
|
|
52
|
+
return getPropertyMetadata<ChildrenFromMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
52
53
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChronicleClassOrPropertyDecorator, decorateClassOrProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the clearWith class or property decorator. */
|
|
8
9
|
export interface ClearWithMetadata {
|
|
@@ -20,8 +21,8 @@ const PROPERTY_METADATA_KEY = 'chronicle:projection:clearWith:property';
|
|
|
20
21
|
* @param eventType - The event constructor.
|
|
21
22
|
* @returns A class and property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function clearWith(eventType: Function):
|
|
24
|
-
return (target: object, propertyKey?: string | symbol) => {
|
|
24
|
+
export function clearWith(eventType: Function): ChronicleClassOrPropertyDecorator {
|
|
25
|
+
return decorateClassOrProperty((target: object, propertyKey?: string | symbol) => {
|
|
25
26
|
if (propertyKey !== undefined) {
|
|
26
27
|
const key = propertyKey.toString();
|
|
27
28
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
@@ -31,7 +32,7 @@ export function clearWith(eventType: Function): ClassDecorator & PropertyDecorat
|
|
|
31
32
|
const existing: ClearWithMetadata[] = Reflect.getMetadata(CLASS_METADATA_KEY, target) ?? [];
|
|
32
33
|
Reflect.defineMetadata(CLASS_METADATA_KEY, [...existing, { eventType }], target);
|
|
33
34
|
}
|
|
34
|
-
};
|
|
35
|
+
});
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/**
|
|
@@ -50,5 +51,5 @@ export function getClearWithClassMetadata(target: Function): ClearWithMetadata[]
|
|
|
50
51
|
* @returns An array of clearWith metadata entries.
|
|
51
52
|
*/
|
|
52
53
|
export function getClearWithPropertyMetadata(target: object, propertyKey: string): ClearWithMetadata[] {
|
|
53
|
-
return
|
|
54
|
+
return getPropertyMetadata<ClearWithMetadata[]>(PROPERTY_METADATA_KEY, target, propertyKey) ?? [];
|
|
54
55
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the count property decorator. */
|
|
8
9
|
export interface CountMetadata {
|
|
@@ -20,14 +21,14 @@ const METADATA_KEY = 'chronicle:projection:count';
|
|
|
20
21
|
* @param constantKey - Optional constant key value.
|
|
21
22
|
* @returns A property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function count(eventType: Function, constantKey?: string):
|
|
24
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
24
|
+
export function count(eventType: Function, constantKey?: string): ChroniclePropertyDecorator {
|
|
25
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
25
26
|
const key = propertyKey.toString();
|
|
26
27
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
27
28
|
const existing: CountMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
28
29
|
const metadata: CountMetadata = { eventType, constantKey };
|
|
29
30
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -37,5 +38,5 @@ export function count(eventType: Function, constantKey?: string): PropertyDecora
|
|
|
37
38
|
* @returns An array of count metadata entries.
|
|
38
39
|
*/
|
|
39
40
|
export function getCountMetadata(target: object, propertyKey: string): CountMetadata[] {
|
|
40
|
-
return
|
|
41
|
+
return getPropertyMetadata<CountMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
41
42
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { addFrom, getAddFromMetadata } from './addFrom.js';
|
|
6
|
+
import { childrenFrom, getChildrenFromMetadata } from './childrenFrom.js';
|
|
7
|
+
import { clearWith, getClearWithPropertyMetadata } from './clearWith.js';
|
|
8
|
+
import { count, getCountMetadata } from './count.js';
|
|
9
|
+
import { decrement, getDecrementMetadata } from './decrement.js';
|
|
10
|
+
import { fromAll, getFromAllMetadata } from './fromAll.js';
|
|
11
|
+
import { fromEvery, getFromEveryMetadata } from './fromEvery.js';
|
|
12
|
+
import { increment, getIncrementMetadata } from './increment.js';
|
|
13
|
+
import { join, getJoinMetadata } from './join.js';
|
|
14
|
+
import { isNested, nested } from './nested.js';
|
|
15
|
+
import { isNoAutoMap, isPropertyNoAutoMap, noAutoMap } from './noAutoMap.js';
|
|
16
|
+
import { getRemovedWithPropertyMetadata, removedWith } from './removedWith.js';
|
|
17
|
+
import { getRemovedWithJoinPropertyMetadata, removedWithJoin } from './removedWithJoin.js';
|
|
18
|
+
import { getSetFromContextMetadata, setFromContext } from './setFromContext.js';
|
|
19
|
+
import { getSetFromMetadata, setFrom } from './setFrom.js';
|
|
20
|
+
import { getSetValueMetadata, setValue } from './setValue.js';
|
|
21
|
+
import { getSubtractFromMetadata, subtractFrom } from './subtractFrom.js';
|
|
22
|
+
import { getTrackedJsonSchemaProperties, jsonSchemaProperty } from '../../schemas/jsonSchemaProperty.js';
|
|
23
|
+
|
|
24
|
+
class Changed {}
|
|
25
|
+
|
|
26
|
+
@noAutoMap
|
|
27
|
+
class Mappings {
|
|
28
|
+
@addFrom(Changed) added!: number;
|
|
29
|
+
@childrenFrom(Changed) children!: object[];
|
|
30
|
+
@clearWith(Changed) cleared!: string;
|
|
31
|
+
@count(Changed) counted!: number;
|
|
32
|
+
@decrement(Changed) decremented!: number;
|
|
33
|
+
@fromAll() all!: string;
|
|
34
|
+
@fromEvery() every!: string;
|
|
35
|
+
@increment(Changed) incremented!: number;
|
|
36
|
+
@join(Changed) joined!: string;
|
|
37
|
+
@nested nestedValue!: object;
|
|
38
|
+
@noAutoMap excluded!: string;
|
|
39
|
+
@removedWith(Changed) removed!: string;
|
|
40
|
+
@removedWithJoin(Changed) removedJoin!: string;
|
|
41
|
+
@setFromContext(Changed) contextValue!: string;
|
|
42
|
+
@setFrom(Changed) set!: string;
|
|
43
|
+
@setValue(Changed, 'fixed') constant!: string;
|
|
44
|
+
@subtractFrom(Changed) subtracted!: number;
|
|
45
|
+
@jsonSchemaProperty() tracked!: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('standard model-bound decorators', () => {
|
|
49
|
+
it('stores class and property annotations without constructing an instance', () => {
|
|
50
|
+
const target = Mappings.prototype;
|
|
51
|
+
expect(isNoAutoMap(Mappings)).toBe(true);
|
|
52
|
+
expect(isPropertyNoAutoMap(target, 'excluded')).toBe(true);
|
|
53
|
+
expect(isNested(target, 'nestedValue')).toBe(true);
|
|
54
|
+
expect(getAddFromMetadata(target, 'added')).toHaveLength(1);
|
|
55
|
+
expect(getChildrenFromMetadata(target, 'children')).toHaveLength(1);
|
|
56
|
+
expect(getClearWithPropertyMetadata(target, 'cleared')).toHaveLength(1);
|
|
57
|
+
expect(getCountMetadata(target, 'counted')).toHaveLength(1);
|
|
58
|
+
expect(getDecrementMetadata(target, 'decremented')).toHaveLength(1);
|
|
59
|
+
expect(getFromAllMetadata(target, 'all')).toEqual({ property: undefined, contextProperty: undefined });
|
|
60
|
+
expect(getFromEveryMetadata(target, 'every')).toEqual({ property: undefined, contextProperty: undefined });
|
|
61
|
+
expect(getIncrementMetadata(target, 'incremented')).toHaveLength(1);
|
|
62
|
+
expect(getJoinMetadata(target, 'joined')).toHaveLength(1);
|
|
63
|
+
expect(getRemovedWithPropertyMetadata(target, 'removed')).toHaveLength(1);
|
|
64
|
+
expect(getRemovedWithJoinPropertyMetadata(target, 'removedJoin')).toHaveLength(1);
|
|
65
|
+
expect(getSetFromContextMetadata(target, 'contextValue')).toHaveLength(1);
|
|
66
|
+
expect(getSetFromMetadata(target, 'set')).toHaveLength(1);
|
|
67
|
+
expect(getSetValueMetadata(target, 'constant')).toEqual([{ eventType: Changed, value: 'fixed' }]);
|
|
68
|
+
expect(getSubtractFromMetadata(target, 'subtracted')).toHaveLength(1);
|
|
69
|
+
expect(getTrackedJsonSchemaProperties(Mappings)).toContain('tracked');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the decrement property decorator. */
|
|
8
9
|
export interface DecrementMetadata {
|
|
@@ -20,14 +21,14 @@ const METADATA_KEY = 'chronicle:projection:decrement';
|
|
|
20
21
|
* @param constantKey - Optional constant key value.
|
|
21
22
|
* @returns A property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function decrement(eventType: Function, constantKey?: string):
|
|
24
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
24
|
+
export function decrement(eventType: Function, constantKey?: string): ChroniclePropertyDecorator {
|
|
25
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
25
26
|
const key = propertyKey.toString();
|
|
26
27
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
27
28
|
const existing: DecrementMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
28
29
|
const metadata: DecrementMetadata = { eventType, constantKey };
|
|
29
30
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -37,5 +38,5 @@ export function decrement(eventType: Function, constantKey?: string): PropertyDe
|
|
|
37
38
|
* @returns An array of decrement metadata entries.
|
|
38
39
|
*/
|
|
39
40
|
export function getDecrementMetadata(target: object, propertyKey: string): DecrementMetadata[] {
|
|
40
|
-
return
|
|
41
|
+
return getPropertyMetadata<DecrementMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
41
42
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the fromAll property decorator. */
|
|
8
9
|
export interface FromAllMetadata {
|
|
@@ -23,12 +24,12 @@ const METADATA_KEY = 'chronicle:projection:fromAll';
|
|
|
23
24
|
* @param contextProperty - Optional event context property name.
|
|
24
25
|
* @returns A property decorator.
|
|
25
26
|
*/
|
|
26
|
-
export function fromAll(property?: string, contextProperty?: string):
|
|
27
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
27
|
+
export function fromAll(property?: string, contextProperty?: string): ChroniclePropertyDecorator {
|
|
28
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
28
29
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, propertyKey.toString());
|
|
29
30
|
const metadata: FromAllMetadata = { property, contextProperty };
|
|
30
31
|
Reflect.defineMetadata(METADATA_KEY, metadata, target, propertyKey.toString());
|
|
31
|
-
};
|
|
32
|
+
});
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -38,5 +39,5 @@ export function fromAll(property?: string, contextProperty?: string): PropertyDe
|
|
|
38
39
|
* @returns The fromAll metadata, or undefined if not decorated.
|
|
39
40
|
*/
|
|
40
41
|
export function getFromAllMetadata(target: object, propertyKey: string): FromAllMetadata | undefined {
|
|
41
|
-
return
|
|
42
|
+
return getPropertyMetadata<FromAllMetadata>(METADATA_KEY, target, propertyKey);
|
|
42
43
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the fromEvery property decorator. */
|
|
8
9
|
export interface FromEveryMetadata {
|
|
@@ -20,12 +21,12 @@ const METADATA_KEY = 'chronicle:projection:fromEvery';
|
|
|
20
21
|
* @param contextProperty - Optional event context property name.
|
|
21
22
|
* @returns A property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function fromEvery(property?: string, contextProperty?: string):
|
|
24
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
24
|
+
export function fromEvery(property?: string, contextProperty?: string): ChroniclePropertyDecorator {
|
|
25
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
25
26
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, propertyKey.toString());
|
|
26
27
|
const metadata: FromEveryMetadata = { property, contextProperty };
|
|
27
28
|
Reflect.defineMetadata(METADATA_KEY, metadata, target, propertyKey.toString());
|
|
28
|
-
};
|
|
29
|
+
});
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -35,5 +36,5 @@ export function fromEvery(property?: string, contextProperty?: string): Property
|
|
|
35
36
|
* @returns The fromEvery metadata, or undefined if not decorated.
|
|
36
37
|
*/
|
|
37
38
|
export function getFromEveryMetadata(target: object, propertyKey: string): FromEveryMetadata | undefined {
|
|
38
|
-
return
|
|
39
|
+
return getPropertyMetadata<FromEveryMetadata>(METADATA_KEY, target, propertyKey);
|
|
39
40
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the increment property decorator. */
|
|
8
9
|
export interface IncrementMetadata {
|
|
@@ -20,14 +21,14 @@ const METADATA_KEY = 'chronicle:projection:increment';
|
|
|
20
21
|
* @param constantKey - Optional constant key value.
|
|
21
22
|
* @returns A property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function increment(eventType: Function, constantKey?: string):
|
|
24
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
24
|
+
export function increment(eventType: Function, constantKey?: string): ChroniclePropertyDecorator {
|
|
25
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
25
26
|
const key = propertyKey.toString();
|
|
26
27
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
27
28
|
const existing: IncrementMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
28
29
|
const metadata: IncrementMetadata = { eventType, constantKey };
|
|
29
30
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -37,5 +38,5 @@ export function increment(eventType: Function, constantKey?: string): PropertyDe
|
|
|
37
38
|
* @returns An array of increment metadata entries.
|
|
38
39
|
*/
|
|
39
40
|
export function getIncrementMetadata(target: object, propertyKey: string): IncrementMetadata[] {
|
|
40
|
-
return
|
|
41
|
+
return getPropertyMetadata<IncrementMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
41
42
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the join property decorator. */
|
|
8
9
|
export interface JoinMetadata {
|
|
@@ -23,14 +24,14 @@ const METADATA_KEY = 'chronicle:projection:join';
|
|
|
23
24
|
* @param eventPropertyName - Optional event property name. Defaults to the property name.
|
|
24
25
|
* @returns A property decorator.
|
|
25
26
|
*/
|
|
26
|
-
export function join(eventType: Function, on?: string, eventPropertyName?: string):
|
|
27
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
27
|
+
export function join(eventType: Function, on?: string, eventPropertyName?: string): ChroniclePropertyDecorator {
|
|
28
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
28
29
|
const key = propertyKey.toString();
|
|
29
30
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
30
31
|
const existing: JoinMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
31
32
|
const metadata: JoinMetadata = { eventType, on, eventPropertyName };
|
|
32
33
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
33
|
-
};
|
|
34
|
+
});
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
@@ -40,5 +41,5 @@ export function join(eventType: Function, on?: string, eventPropertyName?: strin
|
|
|
40
41
|
* @returns An array of join metadata entries.
|
|
41
42
|
*/
|
|
42
43
|
export function getJoinMetadata(target: object, propertyKey: string): JoinMetadata[] {
|
|
43
|
-
return
|
|
44
|
+
return getPropertyMetadata<JoinMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
44
45
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { decorateProperty, hasPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
const METADATA_KEY = 'chronicle:projection:nested';
|
|
8
9
|
|
|
@@ -12,10 +13,16 @@ const METADATA_KEY = 'chronicle:projection:nested';
|
|
|
12
13
|
* @param target - The class prototype.
|
|
13
14
|
* @param propertyKey - The property name.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
const decorateNested = decorateProperty((target: object, propertyKey: string | symbol): void => {
|
|
16
17
|
const key = propertyKey.toString();
|
|
17
18
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
18
19
|
Reflect.defineMetadata(METADATA_KEY, true, target, key);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export function nested(target: object, propertyKey: string | symbol): void;
|
|
23
|
+
export function nested(value: undefined, context: ClassFieldDecoratorContext): void;
|
|
24
|
+
export function nested(target: object | undefined, propertyKeyOrContext: string | symbol | ClassFieldDecoratorContext): void {
|
|
25
|
+
decorateNested(target as undefined, propertyKeyOrContext as ClassFieldDecoratorContext);
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
/**
|
|
@@ -25,5 +32,5 @@ export function nested(target: object, propertyKey: string | symbol): void {
|
|
|
25
32
|
* @returns True if the property is marked as nested; false otherwise.
|
|
26
33
|
*/
|
|
27
34
|
export function isNested(target: object, propertyKey: string): boolean {
|
|
28
|
-
return
|
|
35
|
+
return hasPropertyMetadata(METADATA_KEY, target, propertyKey);
|
|
29
36
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { decorateClassOrProperty, hasPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
const CLASS_METADATA_KEY = 'chronicle:projection:noAutoMap:class';
|
|
8
9
|
const PROPERTY_METADATA_KEY = 'chronicle:projection:noAutoMap:property';
|
|
@@ -17,7 +18,7 @@ const PROPERTY_METADATA_KEY = 'chronicle:projection:noAutoMap:property';
|
|
|
17
18
|
* @param target - The class constructor, or the class prototype when used on a property.
|
|
18
19
|
* @param propertyKey - The property name, when used as a property decorator.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
const decorateNoAutoMap = decorateClassOrProperty((target: object, propertyKey?: string | symbol): void => {
|
|
21
22
|
if (propertyKey !== undefined) {
|
|
22
23
|
const key = propertyKey.toString();
|
|
23
24
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
@@ -25,6 +26,14 @@ export function noAutoMap(target: object, propertyKey?: string | symbol): void {
|
|
|
25
26
|
} else {
|
|
26
27
|
Reflect.defineMetadata(CLASS_METADATA_KEY, true, target as Function);
|
|
27
28
|
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export function noAutoMap(target: Function): void;
|
|
32
|
+
export function noAutoMap(target: object, propertyKey: string | symbol): void;
|
|
33
|
+
export function noAutoMap(value: Function, context: ClassDecoratorContext): void;
|
|
34
|
+
export function noAutoMap(value: undefined, context: ClassFieldDecoratorContext): void;
|
|
35
|
+
export function noAutoMap(target: object | undefined, propertyKeyOrContext?: string | symbol | ClassDecoratorContext | ClassFieldDecoratorContext): void {
|
|
36
|
+
decorateNoAutoMap(target as Function, propertyKeyOrContext as ClassDecoratorContext);
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
/**
|
|
@@ -43,5 +52,5 @@ export function isNoAutoMap(target: Function): boolean {
|
|
|
43
52
|
* @returns True if the property is marked with {@link noAutoMap}; false otherwise.
|
|
44
53
|
*/
|
|
45
54
|
export function isPropertyNoAutoMap(target: object, propertyKey: string): boolean {
|
|
46
|
-
return
|
|
55
|
+
return hasPropertyMetadata(PROPERTY_METADATA_KEY, target, propertyKey);
|
|
47
56
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChronicleClassOrPropertyDecorator, decorateClassOrProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the removedWith class or property decorator. */
|
|
8
9
|
export interface RemovedWithMetadata {
|
|
@@ -26,8 +27,8 @@ const PROPERTY_METADATA_KEY = 'chronicle:projection:removedWith:property';
|
|
|
26
27
|
* @param parentKey - Optional event property name used as the parent key (for children only).
|
|
27
28
|
* @returns A class and property decorator.
|
|
28
29
|
*/
|
|
29
|
-
export function removedWith(eventType: Function, key?: string, parentKey?: string):
|
|
30
|
-
return (target: object, propertyKey?: string | symbol) => {
|
|
30
|
+
export function removedWith(eventType: Function, key?: string, parentKey?: string): ChronicleClassOrPropertyDecorator {
|
|
31
|
+
return decorateClassOrProperty((target: object, propertyKey?: string | symbol) => {
|
|
31
32
|
if (propertyKey !== undefined) {
|
|
32
33
|
const propKey = propertyKey.toString();
|
|
33
34
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, propKey);
|
|
@@ -37,7 +38,7 @@ export function removedWith(eventType: Function, key?: string, parentKey?: strin
|
|
|
37
38
|
const existing: RemovedWithMetadata[] = Reflect.getMetadata(CLASS_METADATA_KEY, target) ?? [];
|
|
38
39
|
Reflect.defineMetadata(CLASS_METADATA_KEY, [...existing, { eventType, key, parentKey }], target);
|
|
39
40
|
}
|
|
40
|
-
};
|
|
41
|
+
});
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
/**
|
|
@@ -56,5 +57,5 @@ export function getRemovedWithClassMetadata(target: Function): RemovedWithMetada
|
|
|
56
57
|
* @returns An array of removedWith metadata entries.
|
|
57
58
|
*/
|
|
58
59
|
export function getRemovedWithPropertyMetadata(target: object, propertyKey: string): RemovedWithMetadata[] {
|
|
59
|
-
return
|
|
60
|
+
return getPropertyMetadata<RemovedWithMetadata[]>(PROPERTY_METADATA_KEY, target, propertyKey) ?? [];
|
|
60
61
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChronicleClassOrPropertyDecorator, decorateClassOrProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the removedWithJoin class or property decorator. */
|
|
8
9
|
export interface RemovedWithJoinMetadata {
|
|
@@ -21,8 +22,8 @@ const PROPERTY_METADATA_KEY = 'chronicle:projection:removedWithJoin:property';
|
|
|
21
22
|
* @param key - Optional event property name used as the key to identify the instance to remove.
|
|
22
23
|
* @returns A class and property decorator.
|
|
23
24
|
*/
|
|
24
|
-
export function removedWithJoin(eventType: Function, key?: string):
|
|
25
|
-
return (target: object, propertyKey?: string | symbol) => {
|
|
25
|
+
export function removedWithJoin(eventType: Function, key?: string): ChronicleClassOrPropertyDecorator {
|
|
26
|
+
return decorateClassOrProperty((target: object, propertyKey?: string | symbol) => {
|
|
26
27
|
if (propertyKey !== undefined) {
|
|
27
28
|
const propKey = propertyKey.toString();
|
|
28
29
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, propKey);
|
|
@@ -32,7 +33,7 @@ export function removedWithJoin(eventType: Function, key?: string): ClassDecorat
|
|
|
32
33
|
const existing: RemovedWithJoinMetadata[] = Reflect.getMetadata(CLASS_METADATA_KEY, target) ?? [];
|
|
33
34
|
Reflect.defineMetadata(CLASS_METADATA_KEY, [...existing, { eventType, key }], target);
|
|
34
35
|
}
|
|
35
|
-
};
|
|
36
|
+
});
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
/**
|
|
@@ -51,5 +52,5 @@ export function getRemovedWithJoinClassMetadata(target: Function): RemovedWithJo
|
|
|
51
52
|
* @returns An array of removedWithJoin metadata entries.
|
|
52
53
|
*/
|
|
53
54
|
export function getRemovedWithJoinPropertyMetadata(target: object, propertyKey: string): RemovedWithJoinMetadata[] {
|
|
54
|
-
return
|
|
55
|
+
return getPropertyMetadata<RemovedWithJoinMetadata[]>(PROPERTY_METADATA_KEY, target, propertyKey) ?? [];
|
|
55
56
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the setFrom property decorator. */
|
|
8
9
|
export interface SetFromMetadata {
|
|
@@ -20,14 +21,14 @@ const METADATA_KEY = 'chronicle:projection:setFrom';
|
|
|
20
21
|
* @param eventPropertyName - Optional event property name. Defaults to the property name.
|
|
21
22
|
* @returns A property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function setFrom(eventType: Function, eventPropertyName?: string):
|
|
24
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
24
|
+
export function setFrom(eventType: Function, eventPropertyName?: string): ChroniclePropertyDecorator {
|
|
25
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
25
26
|
const key = propertyKey.toString();
|
|
26
27
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
27
28
|
const existing: SetFromMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
28
29
|
const metadata: SetFromMetadata = { eventType, eventPropertyName };
|
|
29
30
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -37,5 +38,5 @@ export function setFrom(eventType: Function, eventPropertyName?: string): Proper
|
|
|
37
38
|
* @returns An array of setFrom metadata entries.
|
|
38
39
|
*/
|
|
39
40
|
export function getSetFromMetadata(target: object, propertyKey: string): SetFromMetadata[] {
|
|
40
|
-
return
|
|
41
|
+
return getPropertyMetadata<SetFromMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
41
42
|
}
|
|
@@ -5,6 +5,7 @@ import 'reflect-metadata';
|
|
|
5
5
|
import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
6
6
|
import type { EventContext } from '../../events/index.js';
|
|
7
7
|
import { TypeIntrospector } from '../../types/index.js';
|
|
8
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
8
9
|
|
|
9
10
|
/** Metadata stored by the setFromContext property decorator. */
|
|
10
11
|
export interface SetFromContextMetadata {
|
|
@@ -22,13 +23,13 @@ const METADATA_KEY = 'chronicle:projection:setFromContext';
|
|
|
22
23
|
* @param contextPropertyOrAccessor - Optional event context property name or property accessor. Defaults to the property name.
|
|
23
24
|
* @returns A property decorator.
|
|
24
25
|
*/
|
|
25
|
-
export function setFromContext(eventType: Function, contextPropertyName?: string):
|
|
26
|
-
export function setFromContext(eventType: Function, contextPropertyAccessor?: PropertyAccessor<EventContext>):
|
|
26
|
+
export function setFromContext(eventType: Function, contextPropertyName?: string): ChroniclePropertyDecorator;
|
|
27
|
+
export function setFromContext(eventType: Function, contextPropertyAccessor?: PropertyAccessor<EventContext>): ChroniclePropertyDecorator;
|
|
27
28
|
export function setFromContext(
|
|
28
29
|
eventType: Function,
|
|
29
30
|
contextPropertyOrAccessor?: string | PropertyAccessor<EventContext>
|
|
30
|
-
):
|
|
31
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
31
|
+
): ChroniclePropertyDecorator {
|
|
32
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
32
33
|
const key = propertyKey.toString();
|
|
33
34
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
34
35
|
const existing: SetFromContextMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
@@ -45,7 +46,7 @@ export function setFromContext(
|
|
|
45
46
|
|
|
46
47
|
const metadata: SetFromContextMetadata = { eventType, contextPropertyName };
|
|
47
48
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
48
|
-
};
|
|
49
|
+
});
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
@@ -55,5 +56,5 @@ export function setFromContext(
|
|
|
55
56
|
* @returns An array of setFromContext metadata entries.
|
|
56
57
|
*/
|
|
57
58
|
export function getSetFromContextMetadata(target: object, propertyKey: string): SetFromContextMetadata[] {
|
|
58
|
-
return
|
|
59
|
+
return getPropertyMetadata<SetFromContextMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
59
60
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
6
7
|
|
|
7
8
|
/** Metadata stored by the setValue property decorator. */
|
|
8
9
|
export interface SetValueMetadata {
|
|
@@ -20,14 +21,14 @@ const METADATA_KEY = 'chronicle:projection:setValue';
|
|
|
20
21
|
* @param value - The constant value to assign.
|
|
21
22
|
* @returns A property decorator.
|
|
22
23
|
*/
|
|
23
|
-
export function setValue(eventType: Function, value: unknown):
|
|
24
|
-
return (target: object, propertyKey: string | symbol) => {
|
|
24
|
+
export function setValue(eventType: Function, value: unknown): ChroniclePropertyDecorator {
|
|
25
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
25
26
|
const key = propertyKey.toString();
|
|
26
27
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
27
28
|
const existing: SetValueMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
28
29
|
const metadata: SetValueMetadata = { eventType, value };
|
|
29
30
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -37,5 +38,5 @@ export function setValue(eventType: Function, value: unknown): PropertyDecorator
|
|
|
37
38
|
* @returns An array of setValue metadata entries.
|
|
38
39
|
*/
|
|
39
40
|
export function getSetValueMetadata(target: object, propertyKey: string): SetValueMetadata[] {
|
|
40
|
-
return
|
|
41
|
+
return getPropertyMetadata<SetValueMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
41
42
|
}
|