@cratis/chronicle 6.57.0 → 6.58.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.
Files changed (234) hide show
  1. package/EventStore.ts +2 -2
  2. package/dist/EventStore.js +2 -2
  3. package/dist/EventStore.js.map +1 -1
  4. package/dist/observation/batches/BatchContext.d.ts +43 -0
  5. package/dist/observation/batches/BatchContext.d.ts.map +1 -0
  6. package/dist/observation/batches/BatchContext.js +60 -0
  7. package/dist/observation/batches/BatchContext.js.map +1 -0
  8. package/dist/observation/batches/BatchContextObserver.d.ts +14 -0
  9. package/dist/observation/batches/BatchContextObserver.d.ts.map +1 -0
  10. package/dist/observation/batches/BatchContextObserver.js +4 -0
  11. package/dist/observation/batches/BatchContextObserver.js.map +1 -0
  12. package/dist/observation/batches/BatchContextValues.d.ts +13 -0
  13. package/dist/observation/batches/BatchContextValues.d.ts.map +1 -0
  14. package/dist/observation/batches/BatchContextValues.js +4 -0
  15. package/dist/observation/batches/BatchContextValues.js.map +1 -0
  16. package/dist/observation/batches/BatchMethod.d.ts +9 -0
  17. package/dist/observation/batches/BatchMethod.d.ts.map +1 -0
  18. package/dist/observation/batches/BatchMethod.js +4 -0
  19. package/dist/observation/batches/BatchMethod.js.map +1 -0
  20. package/dist/observation/batches/BatchMethodReturnedAValue.d.ts +12 -0
  21. package/dist/observation/batches/BatchMethodReturnedAValue.d.ts.map +1 -0
  22. package/dist/observation/batches/BatchMethodReturnedAValue.js +20 -0
  23. package/dist/observation/batches/BatchMethodReturnedAValue.js.map +1 -0
  24. package/dist/observation/batches/BatchMethods.d.ts +31 -0
  25. package/dist/observation/batches/BatchMethods.d.ts.map +1 -0
  26. package/dist/observation/batches/BatchMethods.js +81 -0
  27. package/dist/observation/batches/BatchMethods.js.map +1 -0
  28. package/dist/observation/batches/BatchOutcome.d.ts +15 -0
  29. package/dist/observation/batches/BatchOutcome.d.ts.map +1 -0
  30. package/dist/observation/batches/BatchOutcome.js +4 -0
  31. package/dist/observation/batches/BatchOutcome.js.map +1 -0
  32. package/dist/observation/batches/BatchOutcomeKind.d.ts +8 -0
  33. package/dist/observation/batches/BatchOutcomeKind.d.ts.map +1 -0
  34. package/dist/observation/batches/BatchOutcomeKind.js +11 -0
  35. package/dist/observation/batches/BatchOutcomeKind.js.map +1 -0
  36. package/dist/observation/batches/DeferralNotSupportedByKernel.d.ts +13 -0
  37. package/dist/observation/batches/DeferralNotSupportedByKernel.d.ts.map +1 -0
  38. package/dist/observation/batches/DeferralNotSupportedByKernel.js +19 -0
  39. package/dist/observation/batches/DeferralNotSupportedByKernel.js.map +1 -0
  40. package/dist/observation/batches/DeliveredPartition.d.ts +11 -0
  41. package/dist/observation/batches/DeliveredPartition.d.ts.map +1 -0
  42. package/dist/observation/batches/DeliveredPartition.js +4 -0
  43. package/dist/observation/batches/DeliveredPartition.js.map +1 -0
  44. package/dist/observation/batches/EventAndContext.d.ts +28 -0
  45. package/dist/observation/batches/EventAndContext.d.ts.map +1 -0
  46. package/dist/observation/batches/EventAndContext.js +35 -0
  47. package/dist/observation/batches/EventAndContext.js.map +1 -0
  48. package/dist/observation/batches/EventBatch.d.ts +52 -0
  49. package/dist/observation/batches/EventBatch.d.ts.map +1 -0
  50. package/dist/observation/batches/EventBatch.js +92 -0
  51. package/dist/observation/batches/EventBatch.js.map +1 -0
  52. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.d.ts +14 -0
  53. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.d.ts.map +1 -0
  54. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.js +23 -0
  55. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.js.map +1 -0
  56. package/dist/observation/batches/InvalidBatchMethod.d.ts +13 -0
  57. package/dist/observation/batches/InvalidBatchMethod.d.ts.map +1 -0
  58. package/dist/observation/batches/InvalidBatchMethod.js +20 -0
  59. package/dist/observation/batches/InvalidBatchMethod.js.map +1 -0
  60. package/dist/observation/batches/ObservationOrigin.d.ts +21 -0
  61. package/dist/observation/batches/ObservationOrigin.d.ts.map +1 -0
  62. package/dist/observation/batches/ObservationOrigin.js +32 -0
  63. package/dist/observation/batches/ObservationOrigin.js.map +1 -0
  64. package/dist/observation/batches/ObservedEventType.d.ts +11 -0
  65. package/dist/observation/batches/ObservedEventType.d.ts.map +1 -0
  66. package/dist/observation/batches/ObservedEventType.js +4 -0
  67. package/dist/observation/batches/ObservedEventType.js.map +1 -0
  68. package/dist/observation/batches/PageMessages.d.ts +22 -0
  69. package/dist/observation/batches/PageMessages.d.ts.map +1 -0
  70. package/dist/observation/batches/PageMessages.js +32 -0
  71. package/dist/observation/batches/PageMessages.js.map +1 -0
  72. package/dist/observation/batches/PartitionFailedInBatch.d.ts +10 -0
  73. package/dist/observation/batches/PartitionFailedInBatch.d.ts.map +1 -0
  74. package/dist/observation/batches/PartitionFailedInBatch.js +16 -0
  75. package/dist/observation/batches/PartitionFailedInBatch.js.map +1 -0
  76. package/dist/observation/batches/PartitionNotInBatch.d.ts +10 -0
  77. package/dist/observation/batches/PartitionNotInBatch.d.ts.map +1 -0
  78. package/dist/observation/batches/PartitionNotInBatch.js +16 -0
  79. package/dist/observation/batches/PartitionNotInBatch.js.map +1 -0
  80. package/dist/observation/batches/PartitionOutcome.d.ts +19 -0
  81. package/dist/observation/batches/PartitionOutcome.d.ts.map +1 -0
  82. package/dist/observation/batches/PartitionOutcome.js +4 -0
  83. package/dist/observation/batches/PartitionOutcome.js.map +1 -0
  84. package/dist/observation/batches/PartitionProblem.d.ts +17 -0
  85. package/dist/observation/batches/PartitionProblem.d.ts.map +1 -0
  86. package/dist/observation/batches/PartitionProblem.js +4 -0
  87. package/dist/observation/batches/PartitionProblem.js.map +1 -0
  88. package/dist/observation/batches/PartitionSettlement.d.ts +29 -0
  89. package/dist/observation/batches/PartitionSettlement.d.ts.map +1 -0
  90. package/dist/observation/batches/PartitionSettlement.js +64 -0
  91. package/dist/observation/batches/PartitionSettlement.js.map +1 -0
  92. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.d.ts +12 -0
  93. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.d.ts.map +1 -0
  94. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.js +20 -0
  95. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.js.map +1 -0
  96. package/dist/observation/batches/batchSize.d.ts +42 -0
  97. package/dist/observation/batches/batchSize.d.ts.map +1 -0
  98. package/dist/observation/batches/batchSize.js +55 -0
  99. package/dist/observation/batches/batchSize.js.map +1 -0
  100. package/dist/observation/batches/createBatchContext.d.ts +13 -0
  101. package/dist/observation/batches/createBatchContext.d.ts.map +1 -0
  102. package/dist/observation/batches/createBatchContext.js +27 -0
  103. package/dist/observation/batches/createBatchContext.js.map +1 -0
  104. package/dist/observation/batches/observes.d.ts +39 -0
  105. package/dist/observation/batches/observes.d.ts.map +1 -0
  106. package/dist/observation/batches/observes.js +63 -0
  107. package/dist/observation/batches/observes.js.map +1 -0
  108. package/dist/observation/batches/runConcurrently.d.ts +9 -0
  109. package/dist/observation/batches/runConcurrently.d.ts.map +1 -0
  110. package/dist/observation/batches/runConcurrently.js +22 -0
  111. package/dist/observation/batches/runConcurrently.js.map +1 -0
  112. package/dist/observation/createHandlerInstanceValidator.d.ts +1 -1
  113. package/dist/observation/createHandlerInstanceValidator.d.ts.map +1 -1
  114. package/dist/observation/createHandlerInstanceValidator.js +5 -7
  115. package/dist/observation/createHandlerInstanceValidator.js.map +1 -1
  116. package/dist/observation/getInstanceMethods.d.ts +3 -1
  117. package/dist/observation/getInstanceMethods.d.ts.map +1 -1
  118. package/dist/observation/getInstanceMethods.js +13 -4
  119. package/dist/observation/getInstanceMethods.js.map +1 -1
  120. package/dist/observation/index.d.ts +14 -0
  121. package/dist/observation/index.d.ts.map +1 -1
  122. package/dist/observation/index.js +13 -0
  123. package/dist/observation/index.js.map +1 -1
  124. package/dist/reactors/ReactorDispatcher.d.ts +15 -0
  125. package/dist/reactors/ReactorDispatcher.d.ts.map +1 -1
  126. package/dist/reactors/ReactorDispatcher.js +25 -2
  127. package/dist/reactors/ReactorDispatcher.js.map +1 -1
  128. package/dist/reactors/ReactorObservationTarget.d.ts +45 -0
  129. package/dist/reactors/ReactorObservationTarget.d.ts.map +1 -0
  130. package/dist/reactors/ReactorObservationTarget.js +4 -0
  131. package/dist/reactors/ReactorObservationTarget.js.map +1 -0
  132. package/dist/reactors/ReactorPageDispatcher.d.ts +33 -0
  133. package/dist/reactors/ReactorPageDispatcher.d.ts.map +1 -0
  134. package/dist/reactors/ReactorPageDispatcher.js +293 -0
  135. package/dist/reactors/ReactorPageDispatcher.js.map +1 -0
  136. package/dist/reactors/Reactors.d.ts.map +1 -1
  137. package/dist/reactors/Reactors.js +21 -149
  138. package/dist/reactors/Reactors.js.map +1 -1
  139. package/dist/reactors/for_Reactors/given/observe_reactor_messages.d.ts +14 -0
  140. package/dist/reactors/for_Reactors/given/observe_reactor_messages.d.ts.map +1 -0
  141. package/dist/reactors/for_Reactors/given/observe_reactor_messages.js +61 -0
  142. package/dist/reactors/for_Reactors/given/observe_reactor_messages.js.map +1 -0
  143. package/dist/reactors/index.d.ts +2 -0
  144. package/dist/reactors/index.d.ts.map +1 -1
  145. package/dist/reactors/index.js +1 -0
  146. package/dist/reactors/index.js.map +1 -1
  147. package/dist/reducers/ReducerEventDispatcher.d.ts +26 -1
  148. package/dist/reducers/ReducerEventDispatcher.d.ts.map +1 -1
  149. package/dist/reducers/ReducerEventDispatcher.js +35 -3
  150. package/dist/reducers/ReducerEventDispatcher.js.map +1 -1
  151. package/dist/reducers/Reducers.d.ts +2 -0
  152. package/dist/reducers/Reducers.d.ts.map +1 -1
  153. package/dist/reducers/Reducers.js +94 -22
  154. package/dist/reducers/Reducers.js.map +1 -1
  155. package/dist/reducers/ReductionOutcome.d.ts +27 -3
  156. package/dist/reducers/ReductionOutcome.d.ts.map +1 -1
  157. package/dist/reducers/ReductionOutcome.js +51 -7
  158. package/dist/reducers/ReductionOutcome.js.map +1 -1
  159. package/dist/reducers/for_Reducers/given/observe_reducer_messages.d.ts +19 -0
  160. package/dist/reducers/for_Reducers/given/observe_reducer_messages.d.ts.map +1 -0
  161. package/dist/reducers/for_Reducers/given/observe_reducer_messages.js +61 -0
  162. package/dist/reducers/for_Reducers/given/observe_reducer_messages.js.map +1 -0
  163. package/dist/reducers/index.d.ts +2 -0
  164. package/dist/reducers/index.d.ts.map +1 -1
  165. package/dist/reducers/index.js +1 -0
  166. package/dist/reducers/index.js.map +1 -1
  167. package/dist/testing/ReactorScenario.d.ts.map +1 -1
  168. package/dist/testing/ReactorScenario.js +4 -1
  169. package/dist/testing/ReactorScenario.js.map +1 -1
  170. package/dist/testing/ReducerReadModelProcessor.d.ts +1 -0
  171. package/dist/testing/ReducerReadModelProcessor.d.ts.map +1 -1
  172. package/dist/testing/ReducerReadModelProcessor.js +45 -0
  173. package/dist/testing/ReducerReadModelProcessor.js.map +1 -1
  174. package/dist/tsconfig.tsbuildinfo +1 -1
  175. package/observation/batches/BatchContext.ts +75 -0
  176. package/observation/batches/BatchContextObserver.ts +16 -0
  177. package/observation/batches/BatchContextValues.ts +16 -0
  178. package/observation/batches/BatchMethod.ts +13 -0
  179. package/observation/batches/BatchMethodReturnedAValue.ts +16 -0
  180. package/observation/batches/BatchMethods.ts +90 -0
  181. package/observation/batches/BatchOutcome.ts +22 -0
  182. package/observation/batches/BatchOutcomeKind.ts +11 -0
  183. package/observation/batches/DeferralNotSupportedByKernel.ts +17 -0
  184. package/observation/batches/DeliveredPartition.ts +16 -0
  185. package/observation/batches/EventAndContext.ts +37 -0
  186. package/observation/batches/EventBatch.ts +105 -0
  187. package/observation/batches/EventTypeObservedByMoreThanOneMethod.ts +17 -0
  188. package/observation/batches/InvalidBatchMethod.ts +16 -0
  189. package/observation/batches/ObservationOrigin.ts +37 -0
  190. package/observation/batches/ObservedEventType.ts +16 -0
  191. package/observation/batches/PageMessages.ts +37 -0
  192. package/observation/batches/PartitionFailedInBatch.ts +14 -0
  193. package/observation/batches/PartitionNotInBatch.ts +14 -0
  194. package/observation/batches/PartitionOutcome.ts +22 -0
  195. package/observation/batches/PartitionProblem.ts +25 -0
  196. package/observation/batches/PartitionSettlement.ts +70 -0
  197. package/observation/batches/ReducerMixesBatchAndPerEventMethods.ts +16 -0
  198. package/observation/batches/batchSize.ts +79 -0
  199. package/observation/batches/createBatchContext.ts +32 -0
  200. package/observation/batches/for_BatchMethods/when_discovering_batch_methods.spec.ts +155 -0
  201. package/observation/batches/for_EventBatch/when_reporting_outcomes.spec.ts +66 -0
  202. package/observation/batches/for_PartitionSettlement/when_settling_a_partition.spec.ts +31 -0
  203. package/observation/batches/for_batchSize/when_declaring_bounds.spec.ts +23 -0
  204. package/observation/batches/for_observes/when_decorating_methods.legacy.spec.ts +28 -0
  205. package/observation/batches/for_observes/when_decorating_methods.spec.ts +33 -0
  206. package/observation/batches/for_runConcurrently/when_running_items.spec.ts +22 -0
  207. package/observation/batches/observes.ts +68 -0
  208. package/observation/batches/runConcurrently.ts +23 -0
  209. package/observation/createHandlerInstanceValidator.ts +5 -7
  210. package/observation/getInstanceMethods.ts +13 -4
  211. package/observation/index.ts +14 -0
  212. package/package.json +1 -1
  213. package/reactors/ReactorDispatcher.ts +27 -2
  214. package/reactors/ReactorObservationTarget.ts +48 -0
  215. package/reactors/ReactorPageDispatcher.ts +321 -0
  216. package/reactors/Reactors.ts +22 -164
  217. package/reactors/for_Reactors/given/observe_reactor_messages.ts +72 -0
  218. package/reactors/for_Reactors/when_delivering_pages/as_a_legacy_single_partition.spec.ts +51 -0
  219. package/reactors/for_Reactors/when_delivering_pages/returning_a_value_from_a_batch_method.spec.ts +34 -0
  220. package/reactors/for_Reactors/when_delivering_pages/with_batch_and_per_event_methods.spec.ts +81 -0
  221. package/reactors/for_Reactors/when_delivering_pages/with_batch_outcomes.spec.ts +86 -0
  222. package/reactors/for_Reactors/when_delivering_pages/with_per_event_handlers.spec.ts +52 -0
  223. package/reactors/index.ts +2 -0
  224. package/reducers/ReducerEventDispatcher.ts +44 -3
  225. package/reducers/Reducers.ts +109 -25
  226. package/reducers/ReductionOutcome.ts +55 -8
  227. package/reducers/for_Reducers/given/observe_reducer_messages.ts +77 -0
  228. package/reducers/for_Reducers/when_delivering_pages/to_a_batch_reducer.spec.ts +111 -0
  229. package/reducers/for_Reducers/when_delivering_pages/to_a_per_event_reducer.spec.ts +53 -0
  230. package/reducers/index.ts +2 -0
  231. package/testing/ReactorScenario.ts +5 -1
  232. package/testing/ReducerReadModelProcessor.ts +44 -0
  233. package/testing/for_ReactorScenario/when_the_reactor_has_a_batch_method.spec.ts +26 -0
  234. package/testing/for_ReadModelScenario/when_reducing_with_a_batch_method/with_events_for_two_event_sources.spec.ts +43 -0
@@ -0,0 +1,79 @@
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 'reflect-metadata';
5
+ import type { PageDelivery } from '@cratis/chronicle.contracts';
6
+ import { availableParallelism } from 'node:os';
7
+
8
+ const METADATA_KEY = 'chronicle:observation:batchSize';
9
+
10
+ /** The bounds an observer declares for the pages the kernel delivers to it. */
11
+ export interface BatchSizeOptions {
12
+ /** The most events in one page. The kernel's own maximum caps it. Defaults to the kernel's default. */
13
+ readonly maxEvents?: number;
14
+
15
+ /** The most bytes in one page. The kernel's own maximum caps it. Defaults to the kernel's default. */
16
+ readonly maxBytes?: number;
17
+
18
+ /** How long, in milliseconds, the kernel may wait to fill a live page. Defaults to no delay. */
19
+ readonly maxDelayMilliseconds?: number;
20
+
21
+ /**
22
+ * How many event sources of one page a reducer reduces at the same time. Defaults to the number of processors;
23
+ * `1` reduces them one after another. Reactors call their methods for a page in order and ignore it.
24
+ */
25
+ readonly maxConcurrency?: number;
26
+ }
27
+
28
+ /**
29
+ * Declares the bounds of the pages a reactor or reducer receives, the TypeScript equivalent of the C# `[BatchSize]` attribute.
30
+ * @param options - The {@link BatchSizeOptions}.
31
+ * @returns A class decorator for legacy and standard TypeScript decorators.
32
+ */
33
+ export function batchSize(options: BatchSizeOptions): ClassDecorator & ((value: Function, context: ClassDecoratorContext) => void) {
34
+ for (const [name, value] of Object.entries(options)) {
35
+ if (value !== undefined && (!Number.isInteger(value) || (value as number) < (name === 'maxDelayMilliseconds' ? 0 : 1))) {
36
+ throw new RangeError(`Batch size '${name}' must be a ${name === 'maxDelayMilliseconds' ? 'non-negative' : 'positive'} integer.`);
37
+ }
38
+ }
39
+ return (target: object, context?: ClassDecoratorContext) => {
40
+ if (context !== undefined && context.kind !== 'class') {
41
+ throw new TypeError('Batch size can only decorate a reactor or reducer class.');
42
+ }
43
+ Reflect.defineMetadata(METADATA_KEY, Object.freeze({ ...options }), target);
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Gets the {@link BatchSizeOptions} declared on an observer class.
49
+ * @param target - The observer class.
50
+ * @returns The declared options, or an empty object when none are declared.
51
+ */
52
+ export function getBatchSize(target: Function): BatchSizeOptions {
53
+ return (Reflect.getOwnMetadata(METADATA_KEY, target) as BatchSizeOptions | undefined) ?? {};
54
+ }
55
+
56
+ /**
57
+ * Gets how many event sources of one page a reducer reduces at the same time.
58
+ * @param target - The reducer class.
59
+ * @returns The declared concurrency, or the number of processors.
60
+ */
61
+ export function getMaxConcurrency(target: Function): number {
62
+ return getBatchSize(target).maxConcurrency ?? availableParallelism();
63
+ }
64
+
65
+ /**
66
+ * Creates the page delivery the client opts in to at registration. A kernel that does not know page delivery ignores it
67
+ * and keeps delivering one partition at a time.
68
+ * @param target - The observer class.
69
+ * @returns The {@link PageDelivery} for the registration.
70
+ */
71
+ export function toPageDelivery(target: Function): PageDelivery {
72
+ const options = getBatchSize(target);
73
+ return {
74
+ Enabled: true,
75
+ MaxEventsPerPage: options.maxEvents ?? 0,
76
+ MaxBytesPerPage: options.maxBytes ?? 0,
77
+ MaxDelayMilliseconds: options.maxDelayMilliseconds ?? 0
78
+ };
79
+ }
@@ -0,0 +1,32 @@
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 type { EventsToObserve, ReduceOperationMessage } from '@cratis/chronicle.contracts';
5
+ import { BatchContext } from './BatchContext.js';
6
+ import type { BatchContextObserver } from './BatchContextObserver.js';
7
+ import type { DeliveredPartition } from './DeliveredPartition.js';
8
+ import { toObservationOrigin } from './ObservationOrigin.js';
9
+ import { isPage } from './PageMessages.js';
10
+
11
+ /**
12
+ * Creates the {@link BatchContext} describing a delivered page.
13
+ * @param observer - The observer the page is delivered to.
14
+ * @param message - The delivered message.
15
+ * @param partitions - The partitions of the delivery.
16
+ * @returns The {@link BatchContext}.
17
+ */
18
+ export function createBatchContext(observer: BatchContextObserver, message: EventsToObserve | ReduceOperationMessage,
19
+ partitions: readonly DeliveredPartition[]): BatchContext {
20
+ const sequenceNumbers = partitions.flatMap(partition => partition.events.map(event => event.Context!.SequenceNumber));
21
+ const deliverWithin = Number(message.DeliverWithinMilliseconds ?? 0n);
22
+ return new BatchContext({
23
+ ...observer,
24
+ origin: toObservationOrigin(message.Origin),
25
+ partitions: partitions.map(partition => partition.partition),
26
+ eventCount: sequenceNumbers.length,
27
+ firstSequenceNumber: sequenceNumbers.length > 0 ? sequenceNumbers.reduce((min, value) => value < min ? value : min) : undefined,
28
+ lastSequenceNumber: sequenceNumbers.length > 0 ? sequenceNumbers.reduce((max, value) => value > max ? value : max) : undefined,
29
+ deadline: deliverWithin > 0 ? new Date(Date.now() + deliverWithin) : undefined,
30
+ canDefer: isPage(message)
31
+ });
32
+ }
@@ -0,0 +1,155 @@
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 { eventType } from '../../../events/eventTypeDecorator.js';
6
+ import { handles } from '../../../events/handles.js';
7
+ import { onceOnly } from '../../../reactors/onceOnly.js';
8
+ import { replay } from '../../../reactors/replay.js';
9
+ import { getReactorEventTypes } from '../../../reactors/ReactorDispatcher.js';
10
+ import { ReducerEventDispatcher } from '../../../reducers/ReducerEventDispatcher.js';
11
+ import { getBatchMethods } from '../BatchMethods.js';
12
+ import { EventTypeObservedByMoreThanOneMethod } from '../EventTypeObservedByMoreThanOneMethod.js';
13
+ import { InvalidBatchMethod } from '../InvalidBatchMethod.js';
14
+ import { observes } from '../observes.js';
15
+ import { ReducerMixesBatchAndPerEventMethods } from '../ReducerMixesBatchAndPerEventMethods.js';
16
+
17
+ chai.should();
18
+
19
+ @eventType('discovery-account-opened')
20
+ class AccountOpened {}
21
+
22
+ @eventType('discovery-money-deposited')
23
+ class MoneyDeposited {}
24
+
25
+ class Unregistered {}
26
+
27
+ const registered = [AccountOpened, MoneyDeposited];
28
+
29
+ describe('when discovering batch methods', () => {
30
+ it('should find each batch method with the event types it observes', () => {
31
+ class Accounts {
32
+ @observes(AccountOpened)
33
+ @observes(MoneyDeposited)
34
+ all() {}
35
+ }
36
+ const [method] = getBatchMethods(Accounts, registered);
37
+ method.methodName.should.equal('all');
38
+ [...method.eventTypes.keys()].sort().should.deep.equal(['discovery-account-opened', 'discovery-money-deposited']);
39
+ });
40
+
41
+ it('should refuse an event type observed by two batch methods', () => {
42
+ class Accounts {
43
+ @observes(AccountOpened)
44
+ first() {}
45
+
46
+ @observes(AccountOpened)
47
+ second() {}
48
+ }
49
+ (() => getBatchMethods(Accounts, registered)).should.throw(EventTypeObservedByMoreThanOneMethod);
50
+ });
51
+
52
+ it('should refuse an event type that is not registered', () => {
53
+ class Accounts {
54
+ @observes(Unregistered)
55
+ all() {}
56
+ }
57
+ (() => getBatchMethods(Accounts, registered)).should.throw(InvalidBatchMethod, 'no registered event type');
58
+ });
59
+
60
+ it('should refuse a batch method that also declares per-event decorators', () => {
61
+ class WithHandles {
62
+ @observes(AccountOpened)
63
+ @handles(MoneyDeposited)
64
+ all() {}
65
+ }
66
+ class WithReplay {
67
+ @observes(AccountOpened)
68
+ @replay(AccountOpened)
69
+ all() {}
70
+ }
71
+ class WithOnceOnly {
72
+ @observes(AccountOpened)
73
+ @onceOnly()
74
+ all() {}
75
+ }
76
+ (() => getBatchMethods(WithHandles, registered)).should.throw(InvalidBatchMethod, '@handles');
77
+ (() => getBatchMethods(WithReplay, registered)).should.throw(InvalidBatchMethod, '@replay');
78
+ (() => getBatchMethods(WithOnceOnly, registered)).should.throw(InvalidBatchMethod, '@onceOnly');
79
+ });
80
+ });
81
+
82
+ describe('when registering a reactor with batch methods', () => {
83
+ it('should accept batch and per-event methods for different event types', () => {
84
+ class Accounts {
85
+ @observes(AccountOpened)
86
+ opened() {}
87
+
88
+ moneyDeposited() {}
89
+ }
90
+ getReactorEventTypes(Accounts, registered).map(entry => entry.methodName).should.deep.equal(['moneyDeposited']);
91
+ });
92
+
93
+ it('should refuse an event type reaching a batch method and a conventionally named per-event method', () => {
94
+ class Accounts {
95
+ @observes(AccountOpened)
96
+ opened() {}
97
+
98
+ accountOpened() {}
99
+ }
100
+ (() => getReactorEventTypes(Accounts, registered)).should.throw(EventTypeObservedByMoreThanOneMethod, "'opened', 'accountOpened'");
101
+ });
102
+
103
+ it('should refuse an event type reaching a batch method and an explicit per-event method', () => {
104
+ class Accounts {
105
+ @observes(AccountOpened)
106
+ opened() {}
107
+
108
+ @handles(AccountOpened)
109
+ alsoOpened() {}
110
+ }
111
+ (() => getReactorEventTypes(Accounts, registered)).should.throw(EventTypeObservedByMoreThanOneMethod);
112
+ });
113
+
114
+ it('should not treat a batch method named after an event type as a per-event method', () => {
115
+ class Accounts {
116
+ @observes(AccountOpened)
117
+ accountOpened() {}
118
+ }
119
+ getReactorEventTypes(Accounts, registered).should.be.empty;
120
+ });
121
+ });
122
+
123
+ describe('when registering a reducer with a batch method', () => {
124
+ it('should register the observed event types of its batch method', () => {
125
+ class Balance {
126
+ @observes(AccountOpened)
127
+ @observes(MoneyDeposited)
128
+ reduce() {}
129
+ }
130
+ const dispatcher = new ReducerEventDispatcher(Balance, registered);
131
+ dispatcher.batchMethod!.methodName.should.equal('reduce');
132
+ dispatcher.eventTypes.map(eventType => eventType.id).sort().should.deep.equal(['discovery-account-opened', 'discovery-money-deposited']);
133
+ });
134
+
135
+ it('should refuse a reducer mixing a batch method and per-event methods', () => {
136
+ class Balance {
137
+ @observes(AccountOpened)
138
+ reduce() {}
139
+
140
+ moneyDeposited() {}
141
+ }
142
+ (() => new ReducerEventDispatcher(Balance, registered)).should.throw(ReducerMixesBatchAndPerEventMethods);
143
+ });
144
+
145
+ it('should refuse a reducer with two batch methods', () => {
146
+ class Balance {
147
+ @observes(AccountOpened)
148
+ opened() {}
149
+
150
+ @observes(MoneyDeposited)
151
+ deposited() {}
152
+ }
153
+ (() => new ReducerEventDispatcher(Balance, registered)).should.throw(ReducerMixesBatchAndPerEventMethods);
154
+ });
155
+ });
@@ -0,0 +1,66 @@
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 type { EventContext } from '../../../events/EventContext.js';
6
+ import { BatchOutcomeKind } from '../BatchOutcomeKind.js';
7
+ import { DeferralNotSupportedByKernel } from '../DeferralNotSupportedByKernel.js';
8
+ import { EventAndContext } from '../EventAndContext.js';
9
+ import { EventBatch } from '../EventBatch.js';
10
+ import { PartitionNotInBatch } from '../PartitionNotInBatch.js';
11
+
12
+ chai.should();
13
+
14
+ class Opened { constructor(readonly owner: string = '') {} }
15
+ class Closed {}
16
+
17
+ const contextFor = (eventSourceId: string, sequenceNumber: bigint) => ({ eventSourceId, sequenceNumber } as EventContext);
18
+ const events = [
19
+ new EventAndContext({ owner: 'Jane' }, contextFor('a', 1n), Opened),
20
+ new EventAndContext({}, contextFor('b', 2n), Opened),
21
+ new EventAndContext({}, contextFor('a', 3n), Closed)
22
+ ];
23
+
24
+ describe('when reporting outcomes from an event batch', () => {
25
+ it('should list its partitions in the order their first event appears', () => new EventBatch(events).partitions.should.deep.equal(['a', 'b']));
26
+
27
+ it('should narrow events by type', () => {
28
+ const opened = new EventBatch(events).ofType(Opened);
29
+ opened.length.should.equal(2);
30
+ opened[0].event.owner.should.equal('Jane');
31
+ events[2].is(Opened).should.be.false;
32
+ });
33
+
34
+ it('should fail a partition from its first event in the batch', () => {
35
+ const batch = new EventBatch(events);
36
+ const error = new Error('down');
37
+ batch.fail('a', error);
38
+ batch.outcomes.should.deep.equal([{ partition: 'a', at: 1n, kind: BatchOutcomeKind.Failed, error, retryAfterMilliseconds: 0 }]);
39
+ });
40
+
41
+ it('should fail the partition of an event from that event', () => {
42
+ const batch = new EventBatch(events);
43
+ batch.fail(contextFor('a', 3n));
44
+ batch.outcomes[0].at.should.equal(3n);
45
+ batch.outcomes[0].partition.should.equal('a');
46
+ });
47
+
48
+ it('should defer a partition with its delay', () => {
49
+ const batch = new EventBatch(events);
50
+ batch.defer(contextFor('b', 2n), 250);
51
+ batch.outcomes.should.deep.equal([{ partition: 'b', at: 2n, kind: BatchOutcomeKind.Deferred, retryAfterMilliseconds: 250 }]);
52
+ });
53
+
54
+ it('should fail instead of deferring when the kernel cannot take deferrals', () => {
55
+ const batch = new EventBatch(events, false);
56
+ batch.defer('b', 250);
57
+ batch.outcomes[0].kind.should.equal(BatchOutcomeKind.Failed);
58
+ batch.outcomes[0].error!.should.be.instanceOf(DeferralNotSupportedByKernel);
59
+ });
60
+
61
+ it('should refuse a partition it holds no events for', () => {
62
+ const batch = new EventBatch(events);
63
+ (() => batch.fail('c')).should.throw(PartitionNotInBatch);
64
+ (() => batch.defer(contextFor('c', 9n), 10)).should.throw(PartitionNotInBatch);
65
+ });
66
+ });
@@ -0,0 +1,31 @@
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 { ObservationState } from '@cratis/chronicle.contracts';
6
+ import { failedAt, settlePartition, SEQUENCE_NUMBER_UNAVAILABLE } from '../PartitionSettlement.js';
7
+
8
+ chai.should();
9
+
10
+ describe('when settling a partition', () => {
11
+ const sequenceNumbers = [3n, 5n, 8n];
12
+
13
+ it('should succeed at its last event when nothing was reported for it', () => {
14
+ const outcome = settlePartition('a', sequenceNumbers, [failedAt('b', 1n, new Error('other'))]);
15
+ outcome.state.should.equal(ObservationState.Success);
16
+ outcome.lastSuccessfulObservation.should.equal(8n);
17
+ });
18
+
19
+ it('should settle at the earliest problem, counting the events before it as observed', () => {
20
+ const outcome = settlePartition('a', sequenceNumbers, [
21
+ failedAt('a', 8n, new Error('late')),
22
+ { ...failedAt('a', 5n, new Error('early')), state: ObservationState.Deferred, retryAfterMilliseconds: 20 }
23
+ ]);
24
+ outcome.state.should.equal(ObservationState.Deferred);
25
+ outcome.lastSuccessfulObservation.should.equal(3n);
26
+ outcome.retryAfterMilliseconds.should.equal(20);
27
+ });
28
+
29
+ it('should report no observed event when it fails at its first event', () =>
30
+ settlePartition('a', sequenceNumbers, [failedAt('a', 3n, new Error('first'))]).lastSuccessfulObservation.should.equal(SEQUENCE_NUMBER_UNAVAILABLE));
31
+ });
@@ -0,0 +1,23 @@
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 { availableParallelism } from 'node:os';
5
+ import { chai, describe, it } from 'vitest';
6
+ import { batchSize, getMaxConcurrency, toPageDelivery } from '../batchSize.js';
7
+
8
+ chai.should();
9
+
10
+ @batchSize({ maxEvents: 1000, maxBytes: 4096, maxDelayMilliseconds: 50, maxConcurrency: 2 })
11
+ class Bounded {}
12
+
13
+ class Unbounded {}
14
+
15
+ describe('when declaring the bounds of pages', () => {
16
+ it('should opt in to pages with the declared bounds', () =>
17
+ toPageDelivery(Bounded).should.deep.equal({ Enabled: true, MaxEventsPerPage: 1000, MaxBytesPerPage: 4096, MaxDelayMilliseconds: 50 }));
18
+ it('should opt in to pages with the kernel defaults when nothing is declared', () =>
19
+ toPageDelivery(Unbounded).should.deep.equal({ Enabled: true, MaxEventsPerPage: 0, MaxBytesPerPage: 0, MaxDelayMilliseconds: 0 }));
20
+ it('should use the declared concurrency', () => getMaxConcurrency(Bounded).should.equal(2));
21
+ it('should default the concurrency to the number of processors', () => getMaxConcurrency(Unbounded).should.equal(availableParallelism()));
22
+ it('should refuse a concurrency below one', () => (() => batchSize({ maxConcurrency: 0 })).should.throw(RangeError));
23
+ });
@@ -0,0 +1,28 @@
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 { getObservedEventTypes, observes } from '../observes.js';
6
+
7
+ chai.should();
8
+
9
+ class First {}
10
+ class Second {}
11
+
12
+ class Observer {
13
+ @observes(First)
14
+ @observes(Second)
15
+ both() {}
16
+ }
17
+
18
+ describe('when decorating methods with observes using legacy decorators', () => {
19
+ it('should collect every observed event type of a method', () =>
20
+ getObservedEventTypes(Observer.prototype.both).length.should.equal(2));
21
+ it('should refuse a static method', () => (() => {
22
+ class Static {
23
+ @observes(First)
24
+ static batch() {}
25
+ }
26
+ return Static;
27
+ }).should.throw(TypeError, 'public, string-named instance method'));
28
+ });
@@ -0,0 +1,33 @@
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 { getObservedEventTypes, isBatchMethod, observes } from '../observes.js';
6
+
7
+ chai.should();
8
+
9
+ class First {}
10
+ class Second {}
11
+
12
+ class Observer {
13
+ @observes(First)
14
+ @observes(Second)
15
+ both() {}
16
+
17
+ single() {}
18
+ }
19
+
20
+ describe('when decorating methods with observes', () => {
21
+ it('should collect every observed event type of a method', () =>
22
+ [...getObservedEventTypes(Observer.prototype.both)].sort((left, right) => left.name.localeCompare(right.name)).should.deep.equal([First, Second]));
23
+ it('should make the method a batch method', () => isBatchMethod(Observer.prototype.both).should.be.true);
24
+ it('should leave other methods alone', () => isBatchMethod(Observer.prototype.single).should.be.false);
25
+ it('should refuse the same event type twice', () => (() => {
26
+ class Duplicate {
27
+ @observes(First)
28
+ @observes(First)
29
+ twice() {}
30
+ }
31
+ return Duplicate;
32
+ }).should.throw(TypeError, "observes 'First' more than once"));
33
+ });
@@ -0,0 +1,22 @@
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 { runConcurrently } from '../runConcurrently.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when running items concurrently', () => {
10
+ it('should keep the results in item order and never exceed the limit', async () => {
11
+ let running = 0;
12
+ let highest = 0;
13
+ const results = await runConcurrently([30, 10, 20, 5], 2, async delay => {
14
+ highest = Math.max(highest, ++running);
15
+ await new Promise(resolve => setTimeout(resolve, delay));
16
+ running--;
17
+ return delay * 2;
18
+ });
19
+ results.should.deep.equal([60, 20, 40, 10]);
20
+ highest.should.equal(2);
21
+ });
22
+ });
@@ -0,0 +1,68 @@
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 'reflect-metadata';
5
+ import type { Constructor } from '@cratis/fundamentals';
6
+
7
+ const METADATA_KEY = 'chronicle:observation:observes';
8
+
9
+ /**
10
+ * Makes a reactor or reducer method a batch method and declares one event type it observes. Apply it once per event
11
+ * type; it is the TypeScript equivalent of the C# `[Observes<TEvent>]` attribute.
12
+ *
13
+ * A batch method receives an {@link EventBatch} of every event of the types it observes, in sequence order, and a
14
+ * {@link BatchContext} describing the page. Each event type reaches exactly one method of an observer: a batch method
15
+ * or a per-event method, never both.
16
+ *
17
+ * @param eventType - The event constructor observed by this method. The event type must be registered with the owning event store.
18
+ * @returns A method decorator for legacy and standard TypeScript decorators.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * @reactor()
23
+ * class Users {
24
+ * @observes(UserRegistered)
25
+ * @observes(UserRenamed)
26
+ * async index(batch: EventBatch, context: BatchContext): Promise<void> {
27
+ * // ...
28
+ * }
29
+ * }
30
+ * ```
31
+ */
32
+ export function observes(eventType: Constructor): MethodDecorator & ((value: Function, context: ClassMethodDecoratorContext) => void) {
33
+ return (target: object, propertyOrContext: string | symbol | ClassMethodDecoratorContext, descriptor?: PropertyDescriptor) => {
34
+ const isStandard = typeof propertyOrContext === 'object';
35
+ const method = isStandard ? target : descriptor?.value;
36
+ const name = isStandard ? propertyOrContext.name : propertyOrContext;
37
+ if ((isStandard && (propertyOrContext.kind !== 'method' || propertyOrContext.static || propertyOrContext.private)) ||
38
+ (!isStandard && typeof target === 'function') || typeof name !== 'string' || typeof method !== 'function') {
39
+ throw new TypeError('Observes requires a public, string-named instance method.');
40
+ }
41
+ if (typeof eventType !== 'function') {
42
+ throw new TypeError('Observes requires an event constructor.');
43
+ }
44
+ const observed = (Reflect.getOwnMetadata(METADATA_KEY, method) as Constructor[] | undefined) ?? [];
45
+ if (observed.includes(eventType)) {
46
+ throw new TypeError(`Batch method '${name}' observes '${(eventType as Function).name}' more than once.`);
47
+ }
48
+ Reflect.defineMetadata(METADATA_KEY, [...observed, eventType], method);
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Gets the event constructors a batch method observes, without inheriting metadata.
54
+ * @param method - The method.
55
+ * @returns The observed event constructors, or an empty array when the method is not a batch method.
56
+ */
57
+ export function getObservedEventTypes(method: Function): readonly Constructor[] {
58
+ return (Reflect.getOwnMetadata(METADATA_KEY, method) as Constructor[] | undefined) ?? [];
59
+ }
60
+
61
+ /**
62
+ * Checks whether a method is a batch method, that is decorated with {@link observes}.
63
+ * @param method - The method.
64
+ * @returns True when it is a batch method.
65
+ */
66
+ export function isBatchMethod(method: Function): boolean {
67
+ return getObservedEventTypes(method).length > 0;
68
+ }
@@ -0,0 +1,23 @@
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
+ /**
5
+ * Runs a callback for every item, with at most a given number running at the same time, and keeps the results in item order.
6
+ * @param items - The items.
7
+ * @param maxConcurrency - The most callbacks running at the same time; `1` runs them one after another.
8
+ * @param callback - The callback for one item.
9
+ * @returns The results, in the order of the items.
10
+ */
11
+ export async function runConcurrently<TItem, TResult>(items: readonly TItem[], maxConcurrency: number,
12
+ callback: (item: TItem, index: number) => Promise<TResult>): Promise<TResult[]> {
13
+ const results = new Array<TResult>(items.length);
14
+ let next = 0;
15
+ const worker = async () => {
16
+ while (next < items.length) {
17
+ const index = next++;
18
+ results[index] = await callback(items[index], index);
19
+ }
20
+ };
21
+ await Promise.all(Array.from({ length: Math.max(1, Math.min(maxConcurrency, items.length)) }, worker));
22
+ return results;
23
+ }
@@ -2,20 +2,18 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import type { Constructor } from '@cratis/fundamentals';
5
- import { getHandledEventType } from '../events/handles.js';
6
- import { getInstanceMethods } from './getInstanceMethods.js';
5
+ import { describeExplicitHandler, getInstanceMethods } from './getInstanceMethods.js';
7
6
 
8
- /** Captures @handles prototype methods during preflight and rejects instance properties hiding them, except bound methods. */
7
+ /** Captures @handles and @observes prototype methods during preflight and rejects instance properties hiding them, except bound methods. */
9
8
  export function createHandlerInstanceValidator(type: Constructor, names: Iterable<string>, methods = getInstanceMethods(type)):
10
9
  (instance: object) => void {
11
- const handlers = [...new Set(names)].filter(name => getHandledEventType(methods.get(name)!) !== undefined).map(name => {
10
+ const handlers = [...new Set(names)].filter(name => describeExplicitHandler(methods.get(name)!) !== undefined).map(name => {
12
11
  const method = methods.get(name)!;
13
12
  let declaring = type.prototype;
14
13
  while (declaring && Object.getOwnPropertyDescriptor(declaring, name)?.value !== method) {
15
14
  declaring = Object.getPrototypeOf(declaring);
16
15
  }
17
- const eventType = getHandledEventType(method)!;
18
- const declaration = `@handles(${(eventType as Function).name})`;
16
+ const declaration = describeExplicitHandler(method)!;
19
17
  return { name, method, declaration, declaringType: declaring?.constructor.name ?? type.name };
20
18
  });
21
19
  return instance => {
@@ -25,7 +23,7 @@ export function createHandlerInstanceValidator(type: Constructor, names: Iterabl
25
23
  const value: unknown = current ? Object.getOwnPropertyDescriptor(current, name)?.value : undefined;
26
24
  if (current === instance && typeof value === 'function' && isBoundCopyOf(value, method)) continue;
27
25
  if (current === instance || !current || value !== method) {
28
- throw new Error(`Override '${name}' on '${type.name}' hides ${declaration} declared on '${declaringType}'; use a method with @handles instead of an instance field.`);
26
+ throw new Error(`Override '${name}' on '${type.name}' hides ${declaration} declared on '${declaringType}'; use a method with ${declaration.startsWith('@observes') ? '@observes' : '@handles'} instead of an instance field.`);
29
27
  }
30
28
  }
31
29
  };
@@ -3,8 +3,9 @@
3
3
 
4
4
  import type { Constructor } from '@cratis/fundamentals';
5
5
  import { getHandledEventType } from '../events/handles.js';
6
+ import { getObservedEventTypes } from './batches/observes.js';
6
7
 
7
- /** Finds prototype methods without invoking getters; explicit handlers require explicitly decorated overrides. */
8
+ /** Finds prototype methods without invoking getters; explicit handlers and batch methods require explicitly decorated overrides. */
8
9
  export function getInstanceMethods(type: Constructor): Map<string, Function> {
9
10
  const methods = new Map<string, Function>();
10
11
  const declaringTypes = new Map<string, string>();
@@ -14,10 +15,10 @@ export function getInstanceMethods(type: Constructor): Map<string, Function> {
14
15
  const method = Object.getOwnPropertyDescriptor(current, name)?.value;
15
16
  const declaringType = declaringTypes.get(name);
16
17
  if (declaringType !== undefined) {
17
- const eventType = typeof method === 'function' ? getHandledEventType(method) : undefined;
18
+ const declaration = typeof method === 'function' ? describeExplicitHandler(method) : undefined;
18
19
  const override = methods.get(name);
19
- if (eventType && (!override || getHandledEventType(override) === undefined)) {
20
- throw new Error(`Override '${name}' on '${declaringType}' hides @handles(${(eventType as Function).name}) declared on '${current.constructor.name}'; redecorate the override.`);
20
+ if (declaration && (!override || describeExplicitHandler(override) === undefined)) {
21
+ throw new Error(`Override '${name}' on '${declaringType}' hides ${declaration} declared on '${current.constructor.name}'; redecorate the override.`);
21
22
  }
22
23
  continue;
23
24
  }
@@ -27,3 +28,11 @@ export function getInstanceMethods(type: Constructor): Map<string, Function> {
27
28
  }
28
29
  return methods;
29
30
  }
31
+
32
+ /** Describes the explicit handler decorator of a method, or undefined when it has none. */
33
+ export function describeExplicitHandler(method: Function): string | undefined {
34
+ const eventType = getHandledEventType(method);
35
+ if (eventType) return `@handles(${(eventType as Function).name})`;
36
+ const observed = getObservedEventTypes(method);
37
+ return observed.length > 0 ? observed.map(type => `@observes(${(type as Function).name})`).join(' ') : undefined;
38
+ }
@@ -21,3 +21,17 @@ export type { IObservers } from './IObservers.js';
21
21
  export { Observers } from './Observers.js';
22
22
  export type { ICanBeNotifiedWhenReplay } from './ICanBeNotifiedWhenReplay.js';
23
23
  export type { ICanBeNotifiedWhenPartitionReplayed } from './ICanBeNotifiedWhenPartitionReplayed.js';
24
+ export { observes } from './batches/observes.js';
25
+ export { batchSize } from './batches/batchSize.js';
26
+ export type { BatchSizeOptions } from './batches/batchSize.js';
27
+ export { EventBatch } from './batches/EventBatch.js';
28
+ export { EventAndContext } from './batches/EventAndContext.js';
29
+ export { BatchContext } from './batches/BatchContext.js';
30
+ export { ObservationOrigin } from './batches/ObservationOrigin.js';
31
+ export { PartitionNotInBatch } from './batches/PartitionNotInBatch.js';
32
+ export { PartitionFailedInBatch } from './batches/PartitionFailedInBatch.js';
33
+ export { DeferralNotSupportedByKernel } from './batches/DeferralNotSupportedByKernel.js';
34
+ export { EventTypeObservedByMoreThanOneMethod } from './batches/EventTypeObservedByMoreThanOneMethod.js';
35
+ export { InvalidBatchMethod } from './batches/InvalidBatchMethod.js';
36
+ export { ReducerMixesBatchAndPerEventMethods } from './batches/ReducerMixesBatchAndPerEventMethods.js';
37
+ export { BatchMethodReturnedAValue } from './batches/BatchMethodReturnedAValue.js';