@cratis/chronicle 6.57.0 → 6.59.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 +2 -2
- package/README.md +1 -1
- package/connection/ChronicleConnection.ts +2 -2
- package/connection/ChronicleConnectionString.spec.ts +21 -0
- package/connection/ChronicleConnectionString.ts +16 -6
- package/connection/LeastConnectionsLoadBalancerStrategy.ts +1 -1
- package/connection/LoadBalancerStrategyFactory.ts +2 -2
- package/connection/TokenProvider.ts +2 -1
- package/connection/fetchOAuthAccessToken.ts +3 -3
- package/connection/for_ChronicleConnection/when_warning_about_tls_validation/tls_validation_warning.spec.ts +6 -1
- package/dist/EventStore.js +2 -2
- package/dist/EventStore.js.map +1 -1
- package/dist/connection/ChronicleConnection.js +2 -2
- package/dist/connection/ChronicleConnection.js.map +1 -1
- package/dist/connection/ChronicleConnectionString.d.ts +7 -2
- package/dist/connection/ChronicleConnectionString.d.ts.map +1 -1
- package/dist/connection/ChronicleConnectionString.js +14 -6
- package/dist/connection/ChronicleConnectionString.js.map +1 -1
- package/dist/connection/LeastConnectionsLoadBalancerStrategy.d.ts +1 -1
- package/dist/connection/LeastConnectionsLoadBalancerStrategy.js +1 -1
- package/dist/connection/LoadBalancerStrategyFactory.d.ts +2 -2
- package/dist/connection/LoadBalancerStrategyFactory.js +2 -2
- package/dist/connection/TokenProvider.d.ts +2 -1
- package/dist/connection/TokenProvider.d.ts.map +1 -1
- package/dist/connection/TokenProvider.js +2 -1
- package/dist/connection/TokenProvider.js.map +1 -1
- package/dist/connection/fetchOAuthAccessToken.d.ts +1 -1
- package/dist/connection/fetchOAuthAccessToken.js +3 -3
- package/dist/connection/fetchOAuthAccessToken.js.map +1 -1
- package/dist/observation/batches/BatchContext.d.ts +43 -0
- package/dist/observation/batches/BatchContext.d.ts.map +1 -0
- package/dist/observation/batches/BatchContext.js +60 -0
- package/dist/observation/batches/BatchContext.js.map +1 -0
- package/dist/observation/batches/BatchContextObserver.d.ts +14 -0
- package/dist/observation/batches/BatchContextObserver.d.ts.map +1 -0
- package/dist/observation/batches/BatchContextObserver.js +4 -0
- package/dist/observation/batches/BatchContextObserver.js.map +1 -0
- package/dist/observation/batches/BatchContextValues.d.ts +13 -0
- package/dist/observation/batches/BatchContextValues.d.ts.map +1 -0
- package/dist/observation/batches/BatchContextValues.js +4 -0
- package/dist/observation/batches/BatchContextValues.js.map +1 -0
- package/dist/observation/batches/BatchMethod.d.ts +9 -0
- package/dist/observation/batches/BatchMethod.d.ts.map +1 -0
- package/dist/observation/batches/BatchMethod.js +4 -0
- package/dist/observation/batches/BatchMethod.js.map +1 -0
- package/dist/observation/batches/BatchMethodReturnedAValue.d.ts +12 -0
- package/dist/observation/batches/BatchMethodReturnedAValue.d.ts.map +1 -0
- package/dist/observation/batches/BatchMethodReturnedAValue.js +20 -0
- package/dist/observation/batches/BatchMethodReturnedAValue.js.map +1 -0
- package/dist/observation/batches/BatchMethods.d.ts +31 -0
- package/dist/observation/batches/BatchMethods.d.ts.map +1 -0
- package/dist/observation/batches/BatchMethods.js +81 -0
- package/dist/observation/batches/BatchMethods.js.map +1 -0
- package/dist/observation/batches/BatchOutcome.d.ts +15 -0
- package/dist/observation/batches/BatchOutcome.d.ts.map +1 -0
- package/dist/observation/batches/BatchOutcome.js +4 -0
- package/dist/observation/batches/BatchOutcome.js.map +1 -0
- package/dist/observation/batches/BatchOutcomeKind.d.ts +8 -0
- package/dist/observation/batches/BatchOutcomeKind.d.ts.map +1 -0
- package/dist/observation/batches/BatchOutcomeKind.js +11 -0
- package/dist/observation/batches/BatchOutcomeKind.js.map +1 -0
- package/dist/observation/batches/DeferralNotSupportedByKernel.d.ts +13 -0
- package/dist/observation/batches/DeferralNotSupportedByKernel.d.ts.map +1 -0
- package/dist/observation/batches/DeferralNotSupportedByKernel.js +19 -0
- package/dist/observation/batches/DeferralNotSupportedByKernel.js.map +1 -0
- package/dist/observation/batches/DeliveredPartition.d.ts +11 -0
- package/dist/observation/batches/DeliveredPartition.d.ts.map +1 -0
- package/dist/observation/batches/DeliveredPartition.js +4 -0
- package/dist/observation/batches/DeliveredPartition.js.map +1 -0
- package/dist/observation/batches/EventAndContext.d.ts +28 -0
- package/dist/observation/batches/EventAndContext.d.ts.map +1 -0
- package/dist/observation/batches/EventAndContext.js +35 -0
- package/dist/observation/batches/EventAndContext.js.map +1 -0
- package/dist/observation/batches/EventBatch.d.ts +52 -0
- package/dist/observation/batches/EventBatch.d.ts.map +1 -0
- package/dist/observation/batches/EventBatch.js +92 -0
- package/dist/observation/batches/EventBatch.js.map +1 -0
- package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.d.ts +14 -0
- package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.d.ts.map +1 -0
- package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.js +23 -0
- package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.js.map +1 -0
- package/dist/observation/batches/InvalidBatchMethod.d.ts +13 -0
- package/dist/observation/batches/InvalidBatchMethod.d.ts.map +1 -0
- package/dist/observation/batches/InvalidBatchMethod.js +20 -0
- package/dist/observation/batches/InvalidBatchMethod.js.map +1 -0
- package/dist/observation/batches/ObservationOrigin.d.ts +21 -0
- package/dist/observation/batches/ObservationOrigin.d.ts.map +1 -0
- package/dist/observation/batches/ObservationOrigin.js +32 -0
- package/dist/observation/batches/ObservationOrigin.js.map +1 -0
- package/dist/observation/batches/ObservedEventType.d.ts +11 -0
- package/dist/observation/batches/ObservedEventType.d.ts.map +1 -0
- package/dist/observation/batches/ObservedEventType.js +4 -0
- package/dist/observation/batches/ObservedEventType.js.map +1 -0
- package/dist/observation/batches/PageMessages.d.ts +22 -0
- package/dist/observation/batches/PageMessages.d.ts.map +1 -0
- package/dist/observation/batches/PageMessages.js +32 -0
- package/dist/observation/batches/PageMessages.js.map +1 -0
- package/dist/observation/batches/PartitionFailedInBatch.d.ts +10 -0
- package/dist/observation/batches/PartitionFailedInBatch.d.ts.map +1 -0
- package/dist/observation/batches/PartitionFailedInBatch.js +16 -0
- package/dist/observation/batches/PartitionFailedInBatch.js.map +1 -0
- package/dist/observation/batches/PartitionNotInBatch.d.ts +10 -0
- package/dist/observation/batches/PartitionNotInBatch.d.ts.map +1 -0
- package/dist/observation/batches/PartitionNotInBatch.js +16 -0
- package/dist/observation/batches/PartitionNotInBatch.js.map +1 -0
- package/dist/observation/batches/PartitionOutcome.d.ts +19 -0
- package/dist/observation/batches/PartitionOutcome.d.ts.map +1 -0
- package/dist/observation/batches/PartitionOutcome.js +4 -0
- package/dist/observation/batches/PartitionOutcome.js.map +1 -0
- package/dist/observation/batches/PartitionProblem.d.ts +17 -0
- package/dist/observation/batches/PartitionProblem.d.ts.map +1 -0
- package/dist/observation/batches/PartitionProblem.js +4 -0
- package/dist/observation/batches/PartitionProblem.js.map +1 -0
- package/dist/observation/batches/PartitionSettlement.d.ts +29 -0
- package/dist/observation/batches/PartitionSettlement.d.ts.map +1 -0
- package/dist/observation/batches/PartitionSettlement.js +64 -0
- package/dist/observation/batches/PartitionSettlement.js.map +1 -0
- package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.d.ts +12 -0
- package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.d.ts.map +1 -0
- package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.js +20 -0
- package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.js.map +1 -0
- package/dist/observation/batches/batchSize.d.ts +42 -0
- package/dist/observation/batches/batchSize.d.ts.map +1 -0
- package/dist/observation/batches/batchSize.js +55 -0
- package/dist/observation/batches/batchSize.js.map +1 -0
- package/dist/observation/batches/createBatchContext.d.ts +13 -0
- package/dist/observation/batches/createBatchContext.d.ts.map +1 -0
- package/dist/observation/batches/createBatchContext.js +27 -0
- package/dist/observation/batches/createBatchContext.js.map +1 -0
- package/dist/observation/batches/observes.d.ts +39 -0
- package/dist/observation/batches/observes.d.ts.map +1 -0
- package/dist/observation/batches/observes.js +63 -0
- package/dist/observation/batches/observes.js.map +1 -0
- package/dist/observation/batches/runConcurrently.d.ts +9 -0
- package/dist/observation/batches/runConcurrently.d.ts.map +1 -0
- package/dist/observation/batches/runConcurrently.js +22 -0
- package/dist/observation/batches/runConcurrently.js.map +1 -0
- package/dist/observation/createHandlerInstanceValidator.d.ts +1 -1
- package/dist/observation/createHandlerInstanceValidator.d.ts.map +1 -1
- package/dist/observation/createHandlerInstanceValidator.js +5 -7
- package/dist/observation/createHandlerInstanceValidator.js.map +1 -1
- package/dist/observation/getInstanceMethods.d.ts +3 -1
- package/dist/observation/getInstanceMethods.d.ts.map +1 -1
- package/dist/observation/getInstanceMethods.js +13 -4
- package/dist/observation/getInstanceMethods.js.map +1 -1
- package/dist/observation/index.d.ts +14 -0
- package/dist/observation/index.d.ts.map +1 -1
- package/dist/observation/index.js +13 -0
- package/dist/observation/index.js.map +1 -1
- package/dist/reactors/ReactorDispatcher.d.ts +15 -0
- package/dist/reactors/ReactorDispatcher.d.ts.map +1 -1
- package/dist/reactors/ReactorDispatcher.js +25 -2
- package/dist/reactors/ReactorDispatcher.js.map +1 -1
- package/dist/reactors/ReactorObservationTarget.d.ts +45 -0
- package/dist/reactors/ReactorObservationTarget.d.ts.map +1 -0
- package/dist/reactors/ReactorObservationTarget.js +4 -0
- package/dist/reactors/ReactorObservationTarget.js.map +1 -0
- package/dist/reactors/ReactorPageDispatcher.d.ts +33 -0
- package/dist/reactors/ReactorPageDispatcher.d.ts.map +1 -0
- package/dist/reactors/ReactorPageDispatcher.js +293 -0
- package/dist/reactors/ReactorPageDispatcher.js.map +1 -0
- package/dist/reactors/Reactors.d.ts.map +1 -1
- package/dist/reactors/Reactors.js +21 -149
- package/dist/reactors/Reactors.js.map +1 -1
- package/dist/reactors/for_Reactors/given/observe_reactor_messages.d.ts +14 -0
- package/dist/reactors/for_Reactors/given/observe_reactor_messages.d.ts.map +1 -0
- package/dist/reactors/for_Reactors/given/observe_reactor_messages.js +61 -0
- package/dist/reactors/for_Reactors/given/observe_reactor_messages.js.map +1 -0
- package/dist/reactors/index.d.ts +2 -0
- package/dist/reactors/index.d.ts.map +1 -1
- package/dist/reactors/index.js +1 -0
- package/dist/reactors/index.js.map +1 -1
- package/dist/reducers/ReducerEventDispatcher.d.ts +26 -1
- package/dist/reducers/ReducerEventDispatcher.d.ts.map +1 -1
- package/dist/reducers/ReducerEventDispatcher.js +35 -3
- package/dist/reducers/ReducerEventDispatcher.js.map +1 -1
- package/dist/reducers/Reducers.d.ts +2 -0
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +94 -22
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/reducers/ReductionOutcome.d.ts +27 -3
- package/dist/reducers/ReductionOutcome.d.ts.map +1 -1
- package/dist/reducers/ReductionOutcome.js +51 -7
- package/dist/reducers/ReductionOutcome.js.map +1 -1
- package/dist/reducers/for_Reducers/given/observe_reducer_messages.d.ts +19 -0
- package/dist/reducers/for_Reducers/given/observe_reducer_messages.d.ts.map +1 -0
- package/dist/reducers/for_Reducers/given/observe_reducer_messages.js +61 -0
- package/dist/reducers/for_Reducers/given/observe_reducer_messages.js.map +1 -0
- package/dist/reducers/index.d.ts +2 -0
- package/dist/reducers/index.d.ts.map +1 -1
- package/dist/reducers/index.js +1 -0
- package/dist/reducers/index.js.map +1 -1
- package/dist/testing/ReactorScenario.d.ts.map +1 -1
- package/dist/testing/ReactorScenario.js +4 -1
- package/dist/testing/ReactorScenario.js.map +1 -1
- package/dist/testing/ReducerReadModelProcessor.d.ts +1 -0
- package/dist/testing/ReducerReadModelProcessor.d.ts.map +1 -1
- package/dist/testing/ReducerReadModelProcessor.js +45 -0
- package/dist/testing/ReducerReadModelProcessor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/observation/batches/BatchContext.ts +75 -0
- package/observation/batches/BatchContextObserver.ts +16 -0
- package/observation/batches/BatchContextValues.ts +16 -0
- package/observation/batches/BatchMethod.ts +13 -0
- package/observation/batches/BatchMethodReturnedAValue.ts +16 -0
- package/observation/batches/BatchMethods.ts +90 -0
- package/observation/batches/BatchOutcome.ts +22 -0
- package/observation/batches/BatchOutcomeKind.ts +11 -0
- package/observation/batches/DeferralNotSupportedByKernel.ts +17 -0
- package/observation/batches/DeliveredPartition.ts +16 -0
- package/observation/batches/EventAndContext.ts +37 -0
- package/observation/batches/EventBatch.ts +105 -0
- package/observation/batches/EventTypeObservedByMoreThanOneMethod.ts +17 -0
- package/observation/batches/InvalidBatchMethod.ts +16 -0
- package/observation/batches/ObservationOrigin.ts +37 -0
- package/observation/batches/ObservedEventType.ts +16 -0
- package/observation/batches/PageMessages.ts +37 -0
- package/observation/batches/PartitionFailedInBatch.ts +14 -0
- package/observation/batches/PartitionNotInBatch.ts +14 -0
- package/observation/batches/PartitionOutcome.ts +22 -0
- package/observation/batches/PartitionProblem.ts +25 -0
- package/observation/batches/PartitionSettlement.ts +70 -0
- package/observation/batches/ReducerMixesBatchAndPerEventMethods.ts +16 -0
- package/observation/batches/batchSize.ts +79 -0
- package/observation/batches/createBatchContext.ts +32 -0
- package/observation/batches/for_BatchMethods/when_discovering_batch_methods.spec.ts +155 -0
- package/observation/batches/for_EventBatch/when_reporting_outcomes.spec.ts +66 -0
- package/observation/batches/for_PartitionSettlement/when_settling_a_partition.spec.ts +31 -0
- package/observation/batches/for_batchSize/when_declaring_bounds.spec.ts +23 -0
- package/observation/batches/for_observes/when_decorating_methods.legacy.spec.ts +28 -0
- package/observation/batches/for_observes/when_decorating_methods.spec.ts +33 -0
- package/observation/batches/for_runConcurrently/when_running_items.spec.ts +22 -0
- package/observation/batches/observes.ts +68 -0
- package/observation/batches/runConcurrently.ts +23 -0
- package/observation/createHandlerInstanceValidator.ts +5 -7
- package/observation/getInstanceMethods.ts +13 -4
- package/observation/index.ts +14 -0
- package/package.json +1 -1
- package/reactors/ReactorDispatcher.ts +27 -2
- package/reactors/ReactorObservationTarget.ts +48 -0
- package/reactors/ReactorPageDispatcher.ts +321 -0
- package/reactors/Reactors.ts +22 -164
- package/reactors/for_Reactors/given/observe_reactor_messages.ts +72 -0
- package/reactors/for_Reactors/when_delivering_pages/as_a_legacy_single_partition.spec.ts +51 -0
- package/reactors/for_Reactors/when_delivering_pages/returning_a_value_from_a_batch_method.spec.ts +34 -0
- package/reactors/for_Reactors/when_delivering_pages/with_batch_and_per_event_methods.spec.ts +81 -0
- package/reactors/for_Reactors/when_delivering_pages/with_batch_outcomes.spec.ts +86 -0
- package/reactors/for_Reactors/when_delivering_pages/with_per_event_handlers.spec.ts +52 -0
- package/reactors/index.ts +2 -0
- package/reducers/ReducerEventDispatcher.ts +44 -3
- package/reducers/Reducers.ts +109 -25
- package/reducers/ReductionOutcome.ts +55 -8
- package/reducers/for_Reducers/given/observe_reducer_messages.ts +77 -0
- package/reducers/for_Reducers/when_delivering_pages/to_a_batch_reducer.spec.ts +111 -0
- package/reducers/for_Reducers/when_delivering_pages/to_a_per_event_reducer.spec.ts +53 -0
- package/reducers/index.ts +2 -0
- package/testing/ReactorScenario.ts +5 -1
- package/testing/ReducerReadModelProcessor.ts +44 -0
- package/testing/for_ReactorScenario/when_the_reactor_has_a_batch_method.spec.ts +26 -0
- package/testing/for_ReadModelScenario/when_reducing_with_a_batch_method/with_events_for_two_event_sources.spec.ts +43 -0
|
@@ -24,7 +24,7 @@ import { EventStoreName } from '../EventStoreName.js';
|
|
|
24
24
|
import { EventStoreNamespaceName } from '../EventStoreNamespaceName.js';
|
|
25
25
|
import type { IEventStore } from '../IEventStore.js';
|
|
26
26
|
import type { IReadModels } from '../readModels/IReadModels.js';
|
|
27
|
-
import { getReactorEventTypes, invokeReactorHandler, selectReactorHandler } from '../reactors/ReactorDispatcher.js';
|
|
27
|
+
import { getReactorBatchMethods, getReactorEventTypes, invokeReactorHandler, selectReactorHandler } from '../reactors/ReactorDispatcher.js';
|
|
28
28
|
import { createHandlerInstanceValidator } from '../observation/createHandlerInstanceValidator.js';
|
|
29
29
|
import { getReactorMetadata } from '../reactors/reactor.js';
|
|
30
30
|
import { normalizeReactorSideEffects } from '../reactors/ReactorSideEffects.js';
|
|
@@ -89,6 +89,10 @@ export class ReactorScenario {
|
|
|
89
89
|
eventTypeMigrations: eventTypeMigrations === undefined ? undefined : [...eventTypeMigrations]
|
|
90
90
|
} });
|
|
91
91
|
this._entries = getReactorEventTypes(_reactor, this._eventTypes);
|
|
92
|
+
if (getReactorBatchMethods(_reactor, this._eventTypes).length > 0) {
|
|
93
|
+
throw new UnsupportedReactorOperation('reactor.batchMethod', _reactor.name,
|
|
94
|
+
'Batch methods (@observes) are not fixture-backed yet.');
|
|
95
|
+
}
|
|
92
96
|
this._validateInstance = createHandlerInstanceValidator(_reactor,
|
|
93
97
|
this._entries.flatMap(entry => [entry.methodName, entry.replayMethodName].filter((name): name is string => !!name)));
|
|
94
98
|
// Every unsupported event-sequence operation is latched at its source, whichever result or stream carries it.
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import type { Constructor } from '@cratis/fundamentals';
|
|
5
5
|
import { ReducerEventDispatcher } from '../reducers/ReducerEventDispatcher.js';
|
|
6
|
+
import { BatchContext } from '../observation/batches/BatchContext.js';
|
|
7
|
+
import { EventAndContext } from '../observation/batches/EventAndContext.js';
|
|
8
|
+
import { EventBatch } from '../observation/batches/EventBatch.js';
|
|
9
|
+
import { ObservationOrigin } from '../observation/batches/ObservationOrigin.js';
|
|
10
|
+
import { PartitionFailedInBatch } from '../observation/batches/PartitionFailedInBatch.js';
|
|
6
11
|
import { getEventSourceTypeFor } from '../events/eventSourceTypeDecorator.js';
|
|
7
12
|
import { getEventStreamTypeFor } from '../events/eventStreamTypeDecorator.js';
|
|
8
13
|
import { getFilterTagsFor } from '../events/filterEventsByTagDecorator.js';
|
|
@@ -32,6 +37,10 @@ export class ReducerReadModelProcessor<TReadModel extends object> implements IRe
|
|
|
32
37
|
const results = new Map<string, ReadModelState<TReadModel>>();
|
|
33
38
|
const reducer = new (this._reducerType as new () => Record<string, Function>)();
|
|
34
39
|
this._dispatcher.validateInstance(reducer);
|
|
40
|
+
if (this._dispatcher.batchMethod) {
|
|
41
|
+
await this.processBatches(reducer, events, results);
|
|
42
|
+
return results;
|
|
43
|
+
}
|
|
35
44
|
for (const event of events) {
|
|
36
45
|
const handler = this._dispatcher.handlerFor(event.context.eventType.id.value);
|
|
37
46
|
if (!handler) continue;
|
|
@@ -50,4 +59,39 @@ export class ReducerReadModelProcessor<TReadModel extends object> implements IRe
|
|
|
50
59
|
}
|
|
51
60
|
return results;
|
|
52
61
|
}
|
|
62
|
+
|
|
63
|
+
private async processBatches(reducer: Record<string, Function>, events: readonly ScenarioEvent[],
|
|
64
|
+
results: Map<string, ReadModelState<TReadModel>>): Promise<void> {
|
|
65
|
+
const method = this._dispatcher.batchMethod!;
|
|
66
|
+
const bySource = new Map<string, EventAndContext[]>();
|
|
67
|
+
for (const event of events) {
|
|
68
|
+
const observed = method.eventTypes.get(event.context.eventType.id.value);
|
|
69
|
+
if (!observed) continue;
|
|
70
|
+
const sourceEvents = bySource.get(event.sourceId) ?? [];
|
|
71
|
+
sourceEvents.push(new EventAndContext(event.content, event.context, observed.type));
|
|
72
|
+
bySource.set(event.sourceId, sourceEvents);
|
|
73
|
+
}
|
|
74
|
+
const signal = new AbortController().signal;
|
|
75
|
+
for (const [sourceId, sourceEvents] of bySource) {
|
|
76
|
+
const batch = new EventBatch(sourceEvents, false);
|
|
77
|
+
const sequenceNumbers = sourceEvents.map(event => event.context.sequenceNumber);
|
|
78
|
+
const context = new BatchContext({
|
|
79
|
+
observerId: this._reducerType.name, eventStore: sourceEvents[0].context.eventStore ?? '', namespace: sourceEvents[0].context.namespace ?? '',
|
|
80
|
+
eventSequenceId: 'event-log', origin: ObservationOrigin.Unknown, partitions: [sourceId], eventCount: sourceEvents.length,
|
|
81
|
+
firstSequenceNumber: sequenceNumbers[0], lastSequenceNumber: sequenceNumbers.at(-1), deadline: undefined, signal, canDefer: false
|
|
82
|
+
});
|
|
83
|
+
let next: unknown;
|
|
84
|
+
try {
|
|
85
|
+
next = await this._dispatcher.invokeBatch(reducer, batch, undefined, context);
|
|
86
|
+
const [reported] = batch.outcomes;
|
|
87
|
+
if (reported) throw reported.error ?? new PartitionFailedInBatch(sourceId);
|
|
88
|
+
} catch (cause) {
|
|
89
|
+
throw new Error(`Reducer '${this._reducerType.name}' for read model '${this._readModelType.name}' failed`, { cause });
|
|
90
|
+
}
|
|
91
|
+
results.set(sourceId, {
|
|
92
|
+
instance: next === undefined ? null : next as TReadModel | null,
|
|
93
|
+
deleted: next === undefined
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
53
97
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { field } from '@cratis/fundamentals';
|
|
5
|
+
import { chai, describe, it } from 'vitest';
|
|
6
|
+
import { eventType, observes, reactor } from '../../index.js';
|
|
7
|
+
import { ReactorScenario, UnsupportedReactorOperation } from '../index.js';
|
|
8
|
+
|
|
9
|
+
chai.should();
|
|
10
|
+
|
|
11
|
+
@eventType('scenario-batch-shipment-sent')
|
|
12
|
+
class ShipmentSent {
|
|
13
|
+
@field(String) trackingNumber = '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@reactor('scenario-batch-shipments')
|
|
17
|
+
class Shipments {
|
|
18
|
+
@observes(ShipmentSent)
|
|
19
|
+
track() {}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('when creating a reactor scenario for a reactor with a batch method', () => {
|
|
23
|
+
it('should refuse it instead of skipping its events', () =>
|
|
24
|
+
(() => new ReactorScenario(Shipments, { artifacts: { eventTypes: [ShipmentSent] }, constraints: 'disabled' }))
|
|
25
|
+
.should.throw(UnsupportedReactorOperation, 'reactor.batchMethod'));
|
|
26
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { chai, describe, it } from 'vitest';
|
|
5
|
+
import { field } from '@cratis/fundamentals';
|
|
6
|
+
import { eventType } from '../../../events/eventTypeDecorator.js';
|
|
7
|
+
import { EventBatch, observes } from '../../../observation/index.js';
|
|
8
|
+
import { reducer } from '../../../reducers/reducer.js';
|
|
9
|
+
import { ReadModelScenario } from '../../index.js';
|
|
10
|
+
|
|
11
|
+
chai.should();
|
|
12
|
+
|
|
13
|
+
@eventType('scenario-batch-points-earned')
|
|
14
|
+
class PointsEarned {
|
|
15
|
+
constructor(readonly points: number = 0) {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class Score {
|
|
19
|
+
@field(Number) points = 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let calls = 0;
|
|
23
|
+
|
|
24
|
+
@reducer('scenario-batch-scores', undefined, Score)
|
|
25
|
+
class Scores {
|
|
26
|
+
@observes(PointsEarned)
|
|
27
|
+
reduce(events: EventBatch, current: Score | undefined): Score {
|
|
28
|
+
calls++;
|
|
29
|
+
return { points: events.ofType(PointsEarned).reduce((total, entry) => total + entry.event.points, current?.points ?? 0) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('when reducing with a batch method in a read model scenario', () => {
|
|
34
|
+
it('should call the batch method once per event source and keep each state', async () => {
|
|
35
|
+
calls = 0;
|
|
36
|
+
const scenario = new ReadModelScenario(Score, { eventTypes: [PointsEarned], reducers: [Scores] });
|
|
37
|
+
scenario.given.forEventSource('player-1').events(new PointsEarned(3), new PointsEarned(4));
|
|
38
|
+
scenario.given.forEventSource('player-2').events(new PointsEarned(10));
|
|
39
|
+
(await scenario.instanceForEventSourceId('player-1'))!.should.deep.equal({ points: 7 });
|
|
40
|
+
(await scenario.instanceForEventSourceId('player-2'))!.should.deep.equal({ points: 10 });
|
|
41
|
+
calls.should.be.greaterThan(0);
|
|
42
|
+
});
|
|
43
|
+
});
|