@cratis/chronicle 6.60.0 → 6.61.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/dist/projections/ChildrenOrderingNotSupportedByContracts.d.ts +15 -0
- package/dist/projections/ChildrenOrderingNotSupportedByContracts.d.ts.map +1 -0
- package/dist/projections/ChildrenOrderingNotSupportedByContracts.js +22 -0
- package/dist/projections/ChildrenOrderingNotSupportedByContracts.js.map +1 -0
- package/dist/projections/InvalidCausedByProperty.d.ts +10 -0
- package/dist/projections/InvalidCausedByProperty.d.ts.map +1 -0
- package/dist/projections/InvalidCausedByProperty.js +16 -0
- package/dist/projections/InvalidCausedByProperty.js.map +1 -0
- package/dist/projections/Projections.d.ts.map +1 -1
- package/dist/projections/Projections.js +4 -0
- package/dist/projections/Projections.js.map +1 -1
- package/dist/projections/causedBy.d.ts +15 -0
- package/dist/projections/causedBy.d.ts.map +1 -0
- package/dist/projections/causedBy.js +24 -0
- package/dist/projections/causedBy.js.map +1 -0
- package/dist/projections/childrenOrdering.d.ts +38 -0
- package/dist/projections/childrenOrdering.d.ts.map +1 -0
- package/dist/projections/childrenOrdering.js +37 -0
- package/dist/projections/childrenOrdering.js.map +1 -0
- package/dist/projections/childrenOrderingSupport.d.ts +14 -0
- package/dist/projections/childrenOrderingSupport.d.ts.map +1 -0
- package/dist/projections/childrenOrderingSupport.js +37 -0
- package/dist/projections/childrenOrderingSupport.js.map +1 -0
- package/dist/projections/declarative/AllSetBuilder.d.ts +3 -0
- package/dist/projections/declarative/AllSetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/AllSetBuilder.js +6 -0
- package/dist/projections/declarative/AllSetBuilder.js.map +1 -1
- package/dist/projections/declarative/ChildrenBuilder.d.ts +9 -0
- package/dist/projections/declarative/ChildrenBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/ChildrenBuilder.js +29 -1
- package/dist/projections/declarative/ChildrenBuilder.js.map +1 -1
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.d.ts +6 -0
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.d.ts.map +1 -0
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.js +11 -0
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.js.map +1 -0
- package/dist/projections/declarative/DictionaryKey.d.ts +48 -0
- package/dist/projections/declarative/DictionaryKey.d.ts.map +1 -0
- package/dist/projections/declarative/DictionaryKey.js +82 -0
- package/dist/projections/declarative/DictionaryKey.js.map +1 -0
- package/dist/projections/declarative/FromAllBuilder.d.ts +2 -0
- package/dist/projections/declarative/FromAllBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/FromAllBuilder.js +5 -0
- package/dist/projections/declarative/FromAllBuilder.js.map +1 -1
- package/dist/projections/declarative/FromBuilder.d.ts +18 -6
- package/dist/projections/declarative/FromBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/FromBuilder.js +34 -31
- package/dist/projections/declarative/FromBuilder.js.map +1 -1
- package/dist/projections/declarative/FromEveryBuilder.d.ts +2 -0
- package/dist/projections/declarative/FromEveryBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/FromEveryBuilder.js +7 -0
- package/dist/projections/declarative/FromEveryBuilder.js.map +1 -1
- package/dist/projections/declarative/IAllSetBuilder.d.ts +7 -0
- package/dist/projections/declarative/IAllSetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IChildrenBuilder.d.ts +19 -0
- package/dist/projections/declarative/IChildrenBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IFromAllBuilder.d.ts +6 -0
- package/dist/projections/declarative/IFromAllBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IFromEveryBuilder.d.ts +6 -0
- package/dist/projections/declarative/IFromEveryBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IReadModelPropertiesBuilder.d.ts +37 -6
- package/dist/projections/declarative/IReadModelPropertiesBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/ISetBuilder.d.ts +7 -0
- package/dist/projections/declarative/ISetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/InvalidDictionaryKey.d.ts +10 -0
- package/dist/projections/declarative/InvalidDictionaryKey.d.ts.map +1 -0
- package/dist/projections/declarative/InvalidDictionaryKey.js +16 -0
- package/dist/projections/declarative/InvalidDictionaryKey.js.map +1 -0
- package/dist/projections/declarative/JoinBuilder.d.ts +18 -6
- package/dist/projections/declarative/JoinBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/JoinBuilder.js +34 -31
- package/dist/projections/declarative/JoinBuilder.js.map +1 -1
- package/dist/projections/declarative/ProjectionBuilderCore.d.ts +2 -0
- package/dist/projections/declarative/ProjectionBuilderCore.d.ts.map +1 -1
- package/dist/projections/declarative/ProjectionBuilderCore.js.map +1 -1
- package/dist/projections/declarative/SetBuilder.d.ts +3 -0
- package/dist/projections/declarative/SetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/SetBuilder.js +6 -0
- package/dist/projections/declarative/SetBuilder.js.map +1 -1
- package/dist/projections/declarative/index.d.ts +4 -0
- package/dist/projections/declarative/index.d.ts.map +1 -1
- package/dist/projections/declarative/index.js +3 -0
- package/dist/projections/declarative/index.js.map +1 -1
- package/dist/projections/graphs/GraphDefinitionBuilder.d.ts.map +1 -1
- package/dist/projections/graphs/GraphDefinitionBuilder.js +7 -4
- package/dist/projections/graphs/GraphDefinitionBuilder.js.map +1 -1
- package/dist/projections/graphs/GraphMemberMappings.d.ts +1 -0
- package/dist/projections/graphs/GraphMemberMappings.d.ts.map +1 -1
- package/dist/projections/graphs/GraphMemberMappings.js +10 -5
- package/dist/projections/graphs/GraphMemberMappings.js.map +1 -1
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.d.ts +13 -0
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.d.ts.map +1 -0
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.js +18 -0
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.js.map +1 -0
- package/dist/projections/graphs/index.d.ts +1 -0
- package/dist/projections/graphs/index.d.ts.map +1 -1
- package/dist/projections/graphs/index.js +1 -0
- package/dist/projections/graphs/index.js.map +1 -1
- package/dist/projections/index.d.ts +5 -0
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/index.js +3 -0
- package/dist/projections/index.js.map +1 -1
- package/dist/projections/modelBound/ConflictingChildrenOrdering.d.ts +10 -0
- package/dist/projections/modelBound/ConflictingChildrenOrdering.d.ts.map +1 -0
- package/dist/projections/modelBound/ConflictingChildrenOrdering.js +16 -0
- package/dist/projections/modelBound/ConflictingChildrenOrdering.js.map +1 -0
- package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts +2 -0
- package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts.map +1 -1
- package/dist/projections/modelBound/childrenAndNestedBuilder.js +9 -5
- package/dist/projections/modelBound/childrenAndNestedBuilder.js.map +1 -1
- package/dist/projections/modelBound/childrenFrom.d.ts +39 -1
- package/dist/projections/modelBound/childrenFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/childrenFrom.js +30 -1
- package/dist/projections/modelBound/childrenFrom.js.map +1 -1
- package/dist/projections/modelBound/index.d.ts +3 -2
- package/dist/projections/modelBound/index.d.ts.map +1 -1
- package/dist/projections/modelBound/index.js +1 -0
- package/dist/projections/modelBound/index.js.map +1 -1
- package/dist/projections/modelBound/setFrom.d.ts +26 -0
- package/dist/projections/modelBound/setFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/setFrom.js +15 -8
- package/dist/projections/modelBound/setFrom.js.map +1 -1
- package/dist/projections/modelBound/setFromContext.d.ts +23 -1
- package/dist/projections/modelBound/setFromContext.d.ts.map +1 -1
- package/dist/projections/modelBound/setFromContext.js +20 -2
- package/dist/projections/modelBound/setFromContext.js.map +1 -1
- package/dist/projections/propertyExpressions.d.ts +9 -0
- package/dist/projections/propertyExpressions.d.ts.map +1 -0
- package/dist/projections/propertyExpressions.js +13 -0
- package/dist/projections/propertyExpressions.js.map +1 -0
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +2 -1
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/testing/projections/ProjectionCapabilities.d.ts.map +1 -1
- package/dist/testing/projections/ProjectionCapabilities.js +2 -0
- package/dist/testing/projections/ProjectionCapabilities.js.map +1 -1
- package/dist/testing/projections/ProjectionChildrenCapabilities.d.ts.map +1 -1
- package/dist/testing/projections/ProjectionChildrenCapabilities.js +2 -0
- package/dist/testing/projections/ProjectionChildrenCapabilities.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/projections/ChildrenOrderingNotSupportedByContracts.ts +18 -0
- package/projections/InvalidCausedByProperty.ts +14 -0
- package/projections/Projections.ts +4 -0
- package/projections/causedBy.ts +30 -0
- package/projections/childrenOrdering.ts +53 -0
- package/projections/childrenOrderingSupport.ts +40 -0
- package/projections/declarative/AllSetBuilder.ts +7 -0
- package/projections/declarative/ChildrenBuilder.ts +34 -1
- package/projections/declarative/ChildrenOrderingAlreadyDefined.ts +11 -0
- package/projections/declarative/DictionaryKey.ts +88 -0
- package/projections/declarative/FromAllBuilder.ts +10 -0
- package/projections/declarative/FromBuilder.ts +42 -32
- package/projections/declarative/FromEveryBuilder.ts +12 -0
- package/projections/declarative/IAllSetBuilder.ts +8 -0
- package/projections/declarative/IChildrenBuilder.ts +22 -0
- package/projections/declarative/IFromAllBuilder.ts +7 -0
- package/projections/declarative/IFromEveryBuilder.ts +7 -0
- package/projections/declarative/IReadModelPropertiesBuilder.ts +39 -6
- package/projections/declarative/ISetBuilder.ts +8 -0
- package/projections/declarative/InvalidDictionaryKey.ts +14 -0
- package/projections/declarative/JoinBuilder.ts +41 -32
- package/projections/declarative/ProjectionBuilderCore.ts +2 -0
- package/projections/declarative/SetBuilder.ts +7 -0
- package/projections/declarative/for_ChildrenBuilder/when_ordering_children.spec.ts +52 -0
- package/projections/declarative/for_FromAllBuilder/when_setting_once.spec.ts +29 -0
- package/projections/declarative/for_FromBuilder/when_setting_once.spec.ts +39 -0
- package/projections/declarative/for_FromBuilder/when_targeting_dictionary_entries.spec.ts +99 -0
- package/projections/declarative/for_JoinBuilder/when_setting_once_and_targeting_dictionary_entries.spec.ts +36 -0
- package/projections/declarative/for_SetBuilder/when_setting_to_the_causing_identity.spec.ts +37 -0
- package/projections/declarative/index.ts +4 -0
- package/projections/for_Graphs/when_building_a_fluent_graph.spec.ts +1 -1
- package/projections/for_Graphs/when_building_a_model_bound_graph.spec.ts +5 -4
- package/projections/for_Graphs/when_declaring_an_invalid_graph.spec.ts +28 -0
- package/projections/for_Graphs/when_declaring_with_standard_decorators.standard.spec.ts +4 -4
- package/projections/for_Graphs/when_mapping_properties.spec.ts +1 -1
- package/projections/for_Projections/when_registering_ordered_children.spec.ts +66 -0
- package/projections/for_childrenOrderingSupport/when_detecting_support_in_the_pinned_contracts.spec.ts +22 -0
- package/projections/for_childrenOrderingSupport/when_ensuring_children_ordering_is_supported.spec.ts +35 -0
- package/projections/graphs/GraphDefinitionBuilder.ts +7 -4
- package/projections/graphs/GraphMemberMappings.ts +8 -5
- package/projections/graphs/SetOnceNotSupportedInGraph.ts +18 -0
- package/projections/graphs/index.ts +1 -0
- package/projections/index.ts +5 -0
- package/projections/modelBound/ConflictingChildrenOrdering.ts +14 -0
- package/projections/modelBound/childrenAndNestedBuilder.ts +11 -5
- package/projections/modelBound/childrenFrom.ts +62 -2
- package/projections/modelBound/for_childrenFrom/when_ordering_children.spec.ts +91 -0
- package/projections/modelBound/for_setFrom/when_setting_once.spec.ts +52 -0
- package/projections/modelBound/index.ts +3 -2
- package/projections/modelBound/setFrom.ts +37 -2
- package/projections/modelBound/setFromContext.ts +38 -3
- package/projections/propertyExpressions.ts +14 -0
- package/reducers/Reducers.ts +2 -1
- package/testing/projections/ProjectionCapabilities.ts +1 -0
- package/testing/projections/ProjectionChildrenCapabilities.ts +1 -0
- package/testing/projections/for_ProjectionCapabilities/when_rejecting_set_once_dictionary_entries_and_ordered_children.spec.ts +52 -0
|
@@ -0,0 +1,88 @@
|
|
|
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 { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
5
|
+
import type { EventContext } from '../../events/EventContext.js';
|
|
6
|
+
import { CausedByProperty, causedByProperty } from '../causedBy.js';
|
|
7
|
+
import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
|
|
8
|
+
import { InvalidEventContextPropertyError } from '../InvalidEventContextPropertyError.js';
|
|
9
|
+
import { InvalidDictionaryKey } from './InvalidDictionaryKey.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Where the key of a dictionary entry comes from when a projection maps into a dictionary-typed read model property.
|
|
13
|
+
* Pass a plain accessor on the event for the common case; use the factory methods for keys from the event content,
|
|
14
|
+
* the event context or the identity that caused the event.
|
|
15
|
+
*/
|
|
16
|
+
export class DictionaryKey {
|
|
17
|
+
private constructor(readonly expression: string) {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The key is read from a property of the event content. Nested paths are supported; the kernel requires the
|
|
21
|
+
* property to exist on the event (case-sensitively) and an event without a value for it leaves the dictionary as it is.
|
|
22
|
+
* @param eventPropertyAccessor - Accessor for the event property holding the key.
|
|
23
|
+
* @returns The dictionary key.
|
|
24
|
+
*/
|
|
25
|
+
static fromEventContent<TEvent>(eventPropertyAccessor: PropertyAccessor<TEvent>): DictionaryKey {
|
|
26
|
+
const handler = new PropertyPathResolverProxyHandler();
|
|
27
|
+
eventPropertyAccessor(new Proxy({}, handler) as TEvent);
|
|
28
|
+
const path = handler.path;
|
|
29
|
+
if (!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(path) || path.split('.').some(segment => segment.startsWith('$'))) {
|
|
30
|
+
throw new InvalidDictionaryKey(path);
|
|
31
|
+
}
|
|
32
|
+
return new DictionaryKey(`$eventContent.${path}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The key is read from the event context, for instance `eventSourceId` or `causedBy.subject`.
|
|
37
|
+
* @param contextProperty - The event context property name, or an accessor on the {@link EventContext}.
|
|
38
|
+
* @returns The dictionary key.
|
|
39
|
+
*/
|
|
40
|
+
static fromEventContext(contextProperty: string | PropertyAccessor<EventContext>): DictionaryKey {
|
|
41
|
+
let path: string;
|
|
42
|
+
if (typeof contextProperty === 'function') {
|
|
43
|
+
const handler = new PropertyPathResolverProxyHandler();
|
|
44
|
+
contextProperty(new Proxy({}, handler) as EventContext);
|
|
45
|
+
path = handler.path;
|
|
46
|
+
} else {
|
|
47
|
+
path = contextProperty;
|
|
48
|
+
}
|
|
49
|
+
if (path.endsWith('()')) {
|
|
50
|
+
throw new InvalidEventContextPropertyError(path);
|
|
51
|
+
}
|
|
52
|
+
eventContextPropertyExpression(path);
|
|
53
|
+
const camelCased = path.split('.').map(segment => segment.charAt(0).toLowerCase() + segment.slice(1)).join('.');
|
|
54
|
+
return new DictionaryKey(`$eventContext.${camelCased}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The key is a member of the identity that caused the event.
|
|
59
|
+
* @param property - The identity member: `subject`, `name` or `userName`.
|
|
60
|
+
* @returns The dictionary key.
|
|
61
|
+
*/
|
|
62
|
+
static causedBy(property: CausedByProperty): DictionaryKey {
|
|
63
|
+
return new DictionaryKey(`$causedBy.${causedByProperty(property)}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A dictionary key: an accessor on the event (the key is read from the event content) or a {@link DictionaryKey}. */
|
|
68
|
+
export type DictionaryKeySource<TEvent> = PropertyAccessor<TEvent> | DictionaryKey;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Resolves a dictionary key source to its {@link DictionaryKey}.
|
|
72
|
+
* @param key - The key source.
|
|
73
|
+
* @returns The dictionary key.
|
|
74
|
+
*/
|
|
75
|
+
export function toDictionaryKey<TEvent>(key: DictionaryKeySource<TEvent>): DictionaryKey {
|
|
76
|
+
return key instanceof DictionaryKey ? key : DictionaryKey.fromEventContent(key);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Builds the target property path of a dictionary entry: `<dictionary>.<key expression>`, for example
|
|
81
|
+
* `slots.$eventContent.category`.
|
|
82
|
+
* @param dictionaryProperty - The dictionary-typed read model property.
|
|
83
|
+
* @param key - Where the key of the entry comes from.
|
|
84
|
+
* @returns The dynamic property path the kernel resolves per event.
|
|
85
|
+
*/
|
|
86
|
+
export function dictionaryEntryPath<TEvent>(dictionaryProperty: string, key: DictionaryKeySource<TEvent>): string {
|
|
87
|
+
return `${dictionaryProperty}.${toDictionaryKey(key).expression}`;
|
|
88
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
4
|
import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
5
|
+
import { setOnceExpression } from '../propertyExpressions.js';
|
|
5
6
|
import { AllSetBuilder } from './AllSetBuilder.js';
|
|
6
7
|
import type { IAllSetBuilder } from './IAllSetBuilder.js';
|
|
7
8
|
import type { IFromAllBuilder } from './IFromAllBuilder.js';
|
|
@@ -19,6 +20,15 @@ export class FromAllBuilder<TReadModel> implements IFromAllBuilder<TReadModel> {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
/** @inheritdoc */
|
|
24
|
+
setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>> {
|
|
25
|
+
return new AllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>>(
|
|
26
|
+
this.targetProperty(readModelPropertyAccessor),
|
|
27
|
+
(property, expression) => { this.properties[property] = setOnceExpression(expression); },
|
|
28
|
+
this
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
/** @inheritdoc */
|
|
23
33
|
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, contextPropertyName?: string): IFromAllBuilder<TReadModel> {
|
|
24
34
|
return this.operation(readModelPropertyAccessor, '$count', contextPropertyName);
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
5
5
|
import { constantValueExpression } from '../constantValueExpression.js';
|
|
6
6
|
import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
|
|
7
|
+
import { removeExpression, setOnceExpression } from '../propertyExpressions.js';
|
|
7
8
|
import { AddBuilder } from './AddBuilder.js';
|
|
8
9
|
import { AddChildBuilder, ChildAdditionEntry } from './AddChildBuilder.js';
|
|
9
10
|
import { CompositeKeyBuilder } from './CompositeKeyBuilder.js';
|
|
11
|
+
import { DictionaryKeySource, dictionaryEntryPath } from './DictionaryKey.js';
|
|
10
12
|
import { IAddBuilder } from './IAddBuilder.js';
|
|
11
13
|
import { IAddChildBuilder } from './IAddChildBuilder.js';
|
|
12
14
|
import { ICompositeKeyBuilder } from './ICompositeKeyBuilder.js';
|
|
@@ -41,18 +43,29 @@ export class FromBuilder<TReadModel, TEvent> implements IFromBuilder<TReadModel,
|
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
/** @inheritdoc */
|
|
44
|
-
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>> {
|
|
45
|
-
const handler = new PropertyPathResolverProxyHandler();
|
|
46
|
-
const proxy = new Proxy({}, handler);
|
|
47
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
48
|
-
const rmProp = handler.property;
|
|
46
|
+
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>> {
|
|
49
47
|
return new SetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>>(
|
|
50
|
-
|
|
51
|
-
(
|
|
48
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
49
|
+
(property, expression) => { this.entry.properties[property] = expression; },
|
|
50
|
+
this
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @inheritdoc */
|
|
55
|
+
setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>> {
|
|
56
|
+
return new SetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>>(
|
|
57
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
58
|
+
(property, expression) => { this.entry.properties[property] = setOnceExpression(expression); },
|
|
52
59
|
this
|
|
53
60
|
);
|
|
54
61
|
}
|
|
55
62
|
|
|
63
|
+
/** @inheritdoc */
|
|
64
|
+
removeKey(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key: DictionaryKeySource<TEvent>): this {
|
|
65
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = removeExpression;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
/** @inheritdoc */
|
|
57
70
|
usingKey(keyAccessor: PropertyAccessor<TEvent>): this {
|
|
58
71
|
const handler = new PropertyPathResolverProxyHandler();
|
|
@@ -120,53 +133,38 @@ export class FromBuilder<TReadModel, TEvent> implements IFromBuilder<TReadModel,
|
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
/** @inheritdoc */
|
|
123
|
-
increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
|
|
124
|
-
|
|
125
|
-
const proxy = new Proxy({}, handler);
|
|
126
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
127
|
-
this.entry.properties[handler.property] = '$increment';
|
|
136
|
+
increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
|
|
137
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$increment';
|
|
128
138
|
return this;
|
|
129
139
|
}
|
|
130
140
|
|
|
131
141
|
/** @inheritdoc */
|
|
132
|
-
decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
|
|
133
|
-
|
|
134
|
-
const proxy = new Proxy({}, handler);
|
|
135
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
136
|
-
this.entry.properties[handler.property] = '$decrement';
|
|
142
|
+
decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
|
|
143
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$decrement';
|
|
137
144
|
return this;
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
/** @inheritdoc */
|
|
141
|
-
add(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAddBuilder<TEvent, this> {
|
|
142
|
-
const handler = new PropertyPathResolverProxyHandler();
|
|
143
|
-
const proxy = new Proxy({}, handler);
|
|
144
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
148
|
+
add(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): IAddBuilder<TEvent, this> {
|
|
145
149
|
return new AddBuilder<TEvent, this>(
|
|
146
|
-
|
|
150
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
147
151
|
(property, expression) => { this.entry.properties[property] = expression; },
|
|
148
152
|
this
|
|
149
153
|
);
|
|
150
154
|
}
|
|
151
155
|
|
|
152
156
|
/** @inheritdoc */
|
|
153
|
-
subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISubtractBuilder<TEvent, this> {
|
|
154
|
-
const handler = new PropertyPathResolverProxyHandler();
|
|
155
|
-
const proxy = new Proxy({}, handler);
|
|
156
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
157
|
+
subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISubtractBuilder<TEvent, this> {
|
|
157
158
|
return new SubtractBuilder<TEvent, this>(
|
|
158
|
-
|
|
159
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
159
160
|
(property, expression) => { this.entry.properties[property] = expression; },
|
|
160
161
|
this
|
|
161
162
|
);
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
/** @inheritdoc */
|
|
165
|
-
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
|
|
166
|
-
|
|
167
|
-
const proxy = new Proxy({}, handler);
|
|
168
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
169
|
-
this.entry.properties[handler.property] = '$count';
|
|
166
|
+
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
|
|
167
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$count';
|
|
170
168
|
return this;
|
|
171
169
|
}
|
|
172
170
|
|
|
@@ -205,4 +203,16 @@ export class FromBuilder<TReadModel, TEvent> implements IFromBuilder<TReadModel,
|
|
|
205
203
|
this
|
|
206
204
|
);
|
|
207
205
|
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Resolves the target property path: the property itself, or the entry of a dictionary-typed property.
|
|
209
|
+
* @param readModelPropertyAccessor - Accessor for the read model property.
|
|
210
|
+
* @param key - Optional dictionary key.
|
|
211
|
+
* @returns The target property path.
|
|
212
|
+
*/
|
|
213
|
+
private targetOf(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): string {
|
|
214
|
+
const handler = new PropertyPathResolverProxyHandler();
|
|
215
|
+
readModelPropertyAccessor(new Proxy({}, handler) as TReadModel);
|
|
216
|
+
return key === undefined ? handler.property : dictionaryEntryPath(handler.property, key);
|
|
217
|
+
}
|
|
208
218
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
5
5
|
import { IAllSetBuilder } from './IAllSetBuilder.js';
|
|
6
6
|
import { IFromEveryBuilder } from './IFromEveryBuilder.js';
|
|
7
|
+
import { setOnceExpression } from '../propertyExpressions.js';
|
|
7
8
|
import { AllSetBuilder } from './AllSetBuilder.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -38,6 +39,17 @@ export class FromEveryBuilder<TReadModel> implements IFromEveryBuilder<TReadMode
|
|
|
38
39
|
);
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
/** @inheritdoc */
|
|
43
|
+
setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>> {
|
|
44
|
+
const handler = new PropertyPathResolverProxyHandler();
|
|
45
|
+
readModelPropertyAccessor(new Proxy({}, handler) as TReadModel);
|
|
46
|
+
return new AllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>>(
|
|
47
|
+
handler.property,
|
|
48
|
+
(targetProperty, expression) => { this.entry.properties[targetProperty] = setOnceExpression(expression); },
|
|
49
|
+
this
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
/** @inheritdoc */
|
|
42
54
|
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, contextPropertyName: string): IFromEveryBuilder<TReadModel> {
|
|
43
55
|
const handler = new PropertyPathResolverProxyHandler();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
4
|
import { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
+
import type { CausedByProperty } from '../causedBy.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Defines a builder for set operations that apply to all events (fromEvery).
|
|
@@ -28,4 +29,11 @@ export interface IAllSetBuilder<TReadModel, TParentBuilder> {
|
|
|
28
29
|
* @returns The parent builder for fluent chaining.
|
|
29
30
|
*/
|
|
30
31
|
toEventSourceId(): TParentBuilder;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Maps the read model property from the identity that caused the event, or one of its members.
|
|
35
|
+
* @param property - Optional identity member: `subject`, `name` or `userName`. Omit it for the whole identity.
|
|
36
|
+
* @returns The parent builder for fluent chaining.
|
|
37
|
+
*/
|
|
38
|
+
toCausedBy(property?: CausedByProperty): TParentBuilder;
|
|
31
39
|
}
|
|
@@ -28,4 +28,26 @@ export interface IChildrenBuilder<TParentReadModel, TChildReadModel>
|
|
|
28
28
|
fromEventProperty<TEvent>(
|
|
29
29
|
propertyAccessor: PropertyAccessor<TEvent>
|
|
30
30
|
): IChildrenBuilder<TParentReadModel, TChildReadModel>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Adds new children at the start of the collection instead of the end. Updating an existing child never moves it.
|
|
34
|
+
* @returns This builder for fluent chaining.
|
|
35
|
+
*/
|
|
36
|
+
prepend(): IChildrenBuilder<TParentReadModel, TChildReadModel>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Inserts new children at their position when sorted ascending by a child property. Children without a value sort
|
|
40
|
+
* first and updating an existing child never moves it, even when the property changes.
|
|
41
|
+
* @param propertyAccessor - Accessor for the child property to sort by.
|
|
42
|
+
* @returns This builder for fluent chaining.
|
|
43
|
+
*/
|
|
44
|
+
orderBy(propertyAccessor: PropertyAccessor<TChildReadModel>): IChildrenBuilder<TParentReadModel, TChildReadModel>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Inserts new children at their position when sorted descending by a child property. Children without a value sort
|
|
48
|
+
* last and updating an existing child never moves it, even when the property changes.
|
|
49
|
+
* @param propertyAccessor - Accessor for the child property to sort by.
|
|
50
|
+
* @returns This builder for fluent chaining.
|
|
51
|
+
*/
|
|
52
|
+
orderByDescending(propertyAccessor: PropertyAccessor<TChildReadModel>): IChildrenBuilder<TParentReadModel, TChildReadModel>;
|
|
31
53
|
}
|
|
@@ -13,6 +13,13 @@ export interface IFromAllBuilder<TReadModel> {
|
|
|
13
13
|
*/
|
|
14
14
|
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>>;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Starts an assignment that only sets the read-model property while it has no value yet; later events leave it as it is.
|
|
18
|
+
* @param readModelPropertyAccessor - Target property accessor.
|
|
19
|
+
* @returns The assignment builder, continuing with this builder.
|
|
20
|
+
*/
|
|
21
|
+
setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>>;
|
|
22
|
+
|
|
16
23
|
/**
|
|
17
24
|
* Counts every event, optionally under a dynamic dictionary key.
|
|
18
25
|
* @param readModelPropertyAccessor - Scalar or dictionary target accessor.
|
|
@@ -16,6 +16,13 @@ export interface IFromEveryBuilder<TReadModel> {
|
|
|
16
16
|
*/
|
|
17
17
|
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>>;
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Starts an assignment that only sets the read-model property while it has no value yet; later events leave it as it is.
|
|
21
|
+
* @param readModelPropertyAccessor - Target property accessor.
|
|
22
|
+
* @returns The assignment builder, continuing with this builder.
|
|
23
|
+
*/
|
|
24
|
+
setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>>;
|
|
25
|
+
|
|
19
26
|
/**
|
|
20
27
|
* Counts every projected event into a dictionary property, using a dynamic key resolved from an event context property.
|
|
21
28
|
* The dictionary value at the resolved key is incremented by one for each matching event.
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
5
|
import { ICompositeKeyBuilder } from './ICompositeKeyBuilder.js';
|
|
6
|
+
import type { DictionaryKeySource } from './DictionaryKey.js';
|
|
6
7
|
import { IAddBuilder } from './IAddBuilder.js';
|
|
7
8
|
import { IAddChildBuilder } from './IAddChildBuilder.js';
|
|
8
9
|
import { ISetBuilder } from './ISetBuilder.js';
|
|
@@ -74,37 +75,47 @@ export interface IReadModelPropertiesBuilder<TReadModel, TEvent, TBuilder> {
|
|
|
74
75
|
/**
|
|
75
76
|
* Increments the specified read model property by one when this event occurs.
|
|
76
77
|
* @param readModelPropertyAccessor - Accessor for the read model property to increment.
|
|
78
|
+
* @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
|
|
79
|
+
* an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
|
|
77
80
|
* @returns This builder for fluent chaining.
|
|
78
81
|
*/
|
|
79
|
-
increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>): TBuilder;
|
|
82
|
+
increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): TBuilder;
|
|
80
83
|
|
|
81
84
|
/**
|
|
82
85
|
* Decrements the specified read model property by one when this event occurs.
|
|
83
86
|
* @param readModelPropertyAccessor - Accessor for the read model property to decrement.
|
|
87
|
+
* @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
|
|
88
|
+
* an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
|
|
84
89
|
* @returns This builder for fluent chaining.
|
|
85
90
|
*/
|
|
86
|
-
decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>): TBuilder;
|
|
91
|
+
decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): TBuilder;
|
|
87
92
|
|
|
88
93
|
/**
|
|
89
94
|
* Begins an add operation on the specified read model property.
|
|
90
95
|
* @param readModelPropertyAccessor - Accessor for the read model property to add to.
|
|
96
|
+
* @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
|
|
97
|
+
* an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
|
|
91
98
|
* @returns An add builder for specifying the event property value.
|
|
92
99
|
*/
|
|
93
|
-
add(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAddBuilder<TEvent, TBuilder>;
|
|
100
|
+
add(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): IAddBuilder<TEvent, TBuilder>;
|
|
94
101
|
|
|
95
102
|
/**
|
|
96
103
|
* Begins a subtract operation on the specified read model property.
|
|
97
104
|
* @param readModelPropertyAccessor - Accessor for the read model property to subtract from.
|
|
105
|
+
* @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
|
|
106
|
+
* an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
|
|
98
107
|
* @returns A subtract builder for specifying the event property value.
|
|
99
108
|
*/
|
|
100
|
-
subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISubtractBuilder<TEvent, TBuilder>;
|
|
109
|
+
subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISubtractBuilder<TEvent, TBuilder>;
|
|
101
110
|
|
|
102
111
|
/**
|
|
103
112
|
* Counts the number of matching events into the specified read model property.
|
|
104
113
|
* @param readModelPropertyAccessor - Accessor for the read model property to store the count in.
|
|
114
|
+
* @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
|
|
115
|
+
* an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
|
|
105
116
|
* @returns This builder for fluent chaining.
|
|
106
117
|
*/
|
|
107
|
-
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>): TBuilder;
|
|
118
|
+
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): TBuilder;
|
|
108
119
|
|
|
109
120
|
/**
|
|
110
121
|
* Adds a child model configured through a child builder to a collection on the read model.
|
|
@@ -137,9 +148,31 @@ export interface IReadModelPropertiesBuilder<TReadModel, TEvent, TBuilder> {
|
|
|
137
148
|
/**
|
|
138
149
|
* Begins a set operation to map an event property to the specified read model property.
|
|
139
150
|
* @param readModelPropertyAccessor - Accessor for the read model property to set.
|
|
151
|
+
* @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
|
|
152
|
+
* an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
|
|
140
153
|
* @returns A set builder for specifying the event property value.
|
|
141
154
|
*/
|
|
142
|
-
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISetBuilder<TEvent, TBuilder>;
|
|
155
|
+
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, TBuilder>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Begins a set operation that only assigns the read model property while it has no value yet. The first event that
|
|
159
|
+
* carries a value wins; later events leave the property as it is. Use it to capture a first occurrence - for instance
|
|
160
|
+
* `setOnce(m => m.firstSeen).toEventContextProperty('occurred')` - without a dedicated creation event.
|
|
161
|
+
* @param readModelPropertyAccessor - Accessor for the read model property to set once.
|
|
162
|
+
* @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
|
|
163
|
+
* an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
|
|
164
|
+
* @returns A set builder for specifying the value.
|
|
165
|
+
*/
|
|
166
|
+
setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, TBuilder>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Removes an entry from a dictionary-typed read model property when this event occurs. Removing a key that is not
|
|
170
|
+
* present leaves the dictionary as it is.
|
|
171
|
+
* @param readModelPropertyAccessor - Accessor for the dictionary-typed read model property.
|
|
172
|
+
* @param key - The key of the entry to remove: an accessor on the event, or a {@link DictionaryKey}.
|
|
173
|
+
* @returns This builder for fluent chaining.
|
|
174
|
+
*/
|
|
175
|
+
removeKey(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key: DictionaryKeySource<TEvent>): TBuilder;
|
|
143
176
|
|
|
144
177
|
/**
|
|
145
178
|
* Begins a set operation that maps the entire event value to a read model property.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
4
|
import { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
+
import type { CausedByProperty } from '../causedBy.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Defines a builder for configuring a set operation on a read model property.
|
|
@@ -35,4 +36,11 @@ export interface ISetBuilder<TEvent, TParentBuilder> {
|
|
|
35
36
|
* @returns The parent builder for fluent chaining.
|
|
36
37
|
*/
|
|
37
38
|
toEventSourceId(): TParentBuilder;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Maps the read model property from the identity that caused the event, or one of its members.
|
|
42
|
+
* @param property - Optional identity member: `subject`, `name` or `userName`. Omit it for the whole identity.
|
|
43
|
+
* @returns The parent builder for fluent chaining.
|
|
44
|
+
*/
|
|
45
|
+
toCausedBy(property?: CausedByProperty): TParentBuilder;
|
|
38
46
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
/** Error thrown when a dictionary key does not resolve to a property path on the event. */
|
|
5
|
+
export class InvalidDictionaryKey extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* Creates an error for an unusable dictionary key path.
|
|
8
|
+
* @param path - The path the key accessor resolved to.
|
|
9
|
+
*/
|
|
10
|
+
constructor(readonly path: string) {
|
|
11
|
+
super(`Invalid dictionary key '${path}'. The key accessor has to select a property on the event, for example 'e => e.category'.`);
|
|
12
|
+
this.name = 'InvalidDictionaryKey';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
5
5
|
import { constantValueExpression } from '../constantValueExpression.js';
|
|
6
6
|
import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
|
|
7
|
+
import { removeExpression, setOnceExpression } from '../propertyExpressions.js';
|
|
7
8
|
import { AddBuilder } from './AddBuilder.js';
|
|
8
9
|
import { AddChildBuilder, ChildAdditionEntry } from './AddChildBuilder.js';
|
|
9
10
|
import { CompositeKeyBuilder } from './CompositeKeyBuilder.js';
|
|
11
|
+
import { DictionaryKeySource, dictionaryEntryPath } from './DictionaryKey.js';
|
|
10
12
|
import { IAddBuilder } from './IAddBuilder.js';
|
|
11
13
|
import { IAddChildBuilder } from './IAddChildBuilder.js';
|
|
12
14
|
import { ICompositeKeyBuilder } from './ICompositeKeyBuilder.js';
|
|
@@ -49,19 +51,29 @@ export class JoinBuilder<TReadModel, TEvent> implements IJoinBuilder<TReadModel,
|
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
/** @inheritdoc */
|
|
52
|
-
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>> {
|
|
53
|
-
const handler = new PropertyPathResolverProxyHandler();
|
|
54
|
-
const proxy = new Proxy({}, handler);
|
|
55
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
56
|
-
const readModelProperty = handler.property;
|
|
57
|
-
|
|
54
|
+
set(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>> {
|
|
58
55
|
return new SetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>>(
|
|
59
|
-
|
|
56
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
60
57
|
(property, expression) => { this.entry.properties[property] = expression; },
|
|
61
58
|
this
|
|
62
59
|
);
|
|
63
60
|
}
|
|
64
61
|
|
|
62
|
+
/** @inheritdoc */
|
|
63
|
+
setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>> {
|
|
64
|
+
return new SetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>>(
|
|
65
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
66
|
+
(property, expression) => { this.entry.properties[property] = setOnceExpression(expression); },
|
|
67
|
+
this
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @inheritdoc */
|
|
72
|
+
removeKey(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key: DictionaryKeySource<TEvent>): this {
|
|
73
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = removeExpression;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
65
77
|
/** @inheritdoc */
|
|
66
78
|
usingKey(keyAccessor: PropertyAccessor<TEvent>): this {
|
|
67
79
|
const handler = new PropertyPathResolverProxyHandler();
|
|
@@ -119,53 +131,38 @@ export class JoinBuilder<TReadModel, TEvent> implements IJoinBuilder<TReadModel,
|
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
/** @inheritdoc */
|
|
122
|
-
increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
|
|
123
|
-
|
|
124
|
-
const proxy = new Proxy({}, handler);
|
|
125
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
126
|
-
this.entry.properties[handler.property] = '$increment';
|
|
134
|
+
increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
|
|
135
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$increment';
|
|
127
136
|
return this;
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
/** @inheritdoc */
|
|
131
|
-
decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
|
|
132
|
-
|
|
133
|
-
const proxy = new Proxy({}, handler);
|
|
134
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
135
|
-
this.entry.properties[handler.property] = '$decrement';
|
|
140
|
+
decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
|
|
141
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$decrement';
|
|
136
142
|
return this;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
/** @inheritdoc */
|
|
140
|
-
add(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAddBuilder<TEvent, this> {
|
|
141
|
-
const handler = new PropertyPathResolverProxyHandler();
|
|
142
|
-
const proxy = new Proxy({}, handler);
|
|
143
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
146
|
+
add(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): IAddBuilder<TEvent, this> {
|
|
144
147
|
return new AddBuilder<TEvent, this>(
|
|
145
|
-
|
|
148
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
146
149
|
(property, expression) => { this.entry.properties[property] = expression; },
|
|
147
150
|
this
|
|
148
151
|
);
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
/** @inheritdoc */
|
|
152
|
-
subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISubtractBuilder<TEvent, this> {
|
|
153
|
-
const handler = new PropertyPathResolverProxyHandler();
|
|
154
|
-
const proxy = new Proxy({}, handler);
|
|
155
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
155
|
+
subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISubtractBuilder<TEvent, this> {
|
|
156
156
|
return new SubtractBuilder<TEvent, this>(
|
|
157
|
-
|
|
157
|
+
this.targetOf(readModelPropertyAccessor, key),
|
|
158
158
|
(property, expression) => { this.entry.properties[property] = expression; },
|
|
159
159
|
this
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/** @inheritdoc */
|
|
164
|
-
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
|
|
165
|
-
|
|
166
|
-
const proxy = new Proxy({}, handler);
|
|
167
|
-
readModelPropertyAccessor(proxy as TReadModel);
|
|
168
|
-
this.entry.properties[handler.property] = '$count';
|
|
164
|
+
count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
|
|
165
|
+
this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$count';
|
|
169
166
|
return this;
|
|
170
167
|
}
|
|
171
168
|
|
|
@@ -204,4 +201,16 @@ export class JoinBuilder<TReadModel, TEvent> implements IJoinBuilder<TReadModel,
|
|
|
204
201
|
this
|
|
205
202
|
);
|
|
206
203
|
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Resolves the target property path: the property itself, or the entry of a dictionary-typed property.
|
|
207
|
+
* @param readModelPropertyAccessor - Accessor for the read model property.
|
|
208
|
+
* @param key - Optional dictionary key.
|
|
209
|
+
* @returns The target property path.
|
|
210
|
+
*/
|
|
211
|
+
private targetOf(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): string {
|
|
212
|
+
const handler = new PropertyPathResolverProxyHandler();
|
|
213
|
+
readModelPropertyAccessor(new Proxy({}, handler) as TReadModel);
|
|
214
|
+
return key === undefined ? handler.property : dictionaryEntryPath(handler.property, key);
|
|
215
|
+
}
|
|
207
216
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { AutoMap } from '@cratis/chronicle.contracts';
|
|
5
5
|
import { getEventTypeFor } from '../../events/eventTypeDecorator.js';
|
|
6
|
+
import type { ChildrenOrderingDefinitionLike } from '../childrenOrdering.js';
|
|
6
7
|
import { FromBuilder } from './FromBuilder.js';
|
|
7
8
|
import { IFromBuilder } from './IFromBuilder.js';
|
|
8
9
|
import { IFromEveryBuilder } from './IFromEveryBuilder.js';
|
|
@@ -59,6 +60,7 @@ export interface ChildrenDefinitionLike {
|
|
|
59
60
|
RemovedWithJoin: RemovedWithJoinRecord[];
|
|
60
61
|
AutoMap: AutoMap;
|
|
61
62
|
Nested: Record<string, ChildrenDefinitionLike>;
|
|
63
|
+
Ordering?: ChildrenOrderingDefinitionLike;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
5
5
|
import { ISetBuilder } from './ISetBuilder.js';
|
|
6
6
|
import { constantValueExpression } from '../constantValueExpression.js';
|
|
7
|
+
import { CausedByProperty, causedByExpression } from '../causedBy.js';
|
|
7
8
|
import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -45,4 +46,10 @@ export class SetBuilder<TEvent, TParentBuilder> implements ISetBuilder<TEvent, T
|
|
|
45
46
|
this._setProperty(this._readModelProperty, '$eventSourceId');
|
|
46
47
|
return this._parent;
|
|
47
48
|
}
|
|
49
|
+
|
|
50
|
+
/** @inheritdoc */
|
|
51
|
+
toCausedBy(property?: CausedByProperty): TParentBuilder {
|
|
52
|
+
this._setProperty(this._readModelProperty, causedByExpression(property));
|
|
53
|
+
return this._parent;
|
|
54
|
+
}
|
|
48
55
|
}
|