@cratis/chronicle 6.56.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 (299) hide show
  1. package/EventStore.ts +2 -2
  2. package/WellKnownTelemetryNames.ts +2 -0
  3. package/auditing/CausationType.ts +5 -0
  4. package/dist/EventStore.js +2 -2
  5. package/dist/EventStore.js.map +1 -1
  6. package/dist/WellKnownTelemetryNames.d.ts +2 -0
  7. package/dist/WellKnownTelemetryNames.d.ts.map +1 -1
  8. package/dist/WellKnownTelemetryNames.js +2 -0
  9. package/dist/WellKnownTelemetryNames.js.map +1 -1
  10. package/dist/auditing/CausationType.d.ts +4 -0
  11. package/dist/auditing/CausationType.d.ts.map +1 -1
  12. package/dist/auditing/CausationType.js +4 -0
  13. package/dist/auditing/CausationType.js.map +1 -1
  14. package/dist/eventSequences/CompensateOptions.d.ts +7 -0
  15. package/dist/eventSequences/CompensateOptions.d.ts.map +1 -0
  16. package/dist/eventSequences/CompensateOptions.js +4 -0
  17. package/dist/eventSequences/CompensateOptions.js.map +1 -0
  18. package/dist/eventSequences/EventSequence.d.ts +3 -0
  19. package/dist/eventSequences/EventSequence.d.ts.map +1 -1
  20. package/dist/eventSequences/EventSequence.js +45 -0
  21. package/dist/eventSequences/EventSequence.js.map +1 -1
  22. package/dist/eventSequences/IEventSequence.d.ts +13 -0
  23. package/dist/eventSequences/IEventSequence.d.ts.map +1 -1
  24. package/dist/eventSequences/index.d.ts +1 -0
  25. package/dist/eventSequences/index.d.ts.map +1 -1
  26. package/dist/eventSequences/index.js.map +1 -1
  27. package/dist/events/EventContext.d.ts +5 -0
  28. package/dist/events/EventContext.d.ts.map +1 -1
  29. package/dist/events/compensationForDecorator.d.ts +32 -0
  30. package/dist/events/compensationForDecorator.d.ts.map +1 -0
  31. package/dist/events/compensationForDecorator.js +44 -0
  32. package/dist/events/compensationForDecorator.js.map +1 -0
  33. package/dist/events/eventTypeDecorator.d.ts +7 -0
  34. package/dist/events/eventTypeDecorator.d.ts.map +1 -1
  35. package/dist/events/eventTypeDecorator.js +13 -4
  36. package/dist/events/eventTypeDecorator.js.map +1 -1
  37. package/dist/events/index.d.ts +2 -1
  38. package/dist/events/index.d.ts.map +1 -1
  39. package/dist/events/index.js +2 -1
  40. package/dist/events/index.js.map +1 -1
  41. package/dist/events/toClientEventContext.d.ts.map +1 -1
  42. package/dist/events/toClientEventContext.js +20 -0
  43. package/dist/events/toClientEventContext.js.map +1 -1
  44. package/dist/observation/batches/BatchContext.d.ts +43 -0
  45. package/dist/observation/batches/BatchContext.d.ts.map +1 -0
  46. package/dist/observation/batches/BatchContext.js +60 -0
  47. package/dist/observation/batches/BatchContext.js.map +1 -0
  48. package/dist/observation/batches/BatchContextObserver.d.ts +14 -0
  49. package/dist/observation/batches/BatchContextObserver.d.ts.map +1 -0
  50. package/dist/observation/batches/BatchContextObserver.js +4 -0
  51. package/dist/observation/batches/BatchContextObserver.js.map +1 -0
  52. package/dist/observation/batches/BatchContextValues.d.ts +13 -0
  53. package/dist/observation/batches/BatchContextValues.d.ts.map +1 -0
  54. package/dist/observation/batches/BatchContextValues.js +4 -0
  55. package/dist/observation/batches/BatchContextValues.js.map +1 -0
  56. package/dist/observation/batches/BatchMethod.d.ts +9 -0
  57. package/dist/observation/batches/BatchMethod.d.ts.map +1 -0
  58. package/dist/observation/batches/BatchMethod.js +4 -0
  59. package/dist/observation/batches/BatchMethod.js.map +1 -0
  60. package/dist/observation/batches/BatchMethodReturnedAValue.d.ts +12 -0
  61. package/dist/observation/batches/BatchMethodReturnedAValue.d.ts.map +1 -0
  62. package/dist/observation/batches/BatchMethodReturnedAValue.js +20 -0
  63. package/dist/observation/batches/BatchMethodReturnedAValue.js.map +1 -0
  64. package/dist/observation/batches/BatchMethods.d.ts +31 -0
  65. package/dist/observation/batches/BatchMethods.d.ts.map +1 -0
  66. package/dist/observation/batches/BatchMethods.js +81 -0
  67. package/dist/observation/batches/BatchMethods.js.map +1 -0
  68. package/dist/observation/batches/BatchOutcome.d.ts +15 -0
  69. package/dist/observation/batches/BatchOutcome.d.ts.map +1 -0
  70. package/dist/observation/batches/BatchOutcome.js +4 -0
  71. package/dist/observation/batches/BatchOutcome.js.map +1 -0
  72. package/dist/observation/batches/BatchOutcomeKind.d.ts +8 -0
  73. package/dist/observation/batches/BatchOutcomeKind.d.ts.map +1 -0
  74. package/dist/observation/batches/BatchOutcomeKind.js +11 -0
  75. package/dist/observation/batches/BatchOutcomeKind.js.map +1 -0
  76. package/dist/observation/batches/DeferralNotSupportedByKernel.d.ts +13 -0
  77. package/dist/observation/batches/DeferralNotSupportedByKernel.d.ts.map +1 -0
  78. package/dist/observation/batches/DeferralNotSupportedByKernel.js +19 -0
  79. package/dist/observation/batches/DeferralNotSupportedByKernel.js.map +1 -0
  80. package/dist/observation/batches/DeliveredPartition.d.ts +11 -0
  81. package/dist/observation/batches/DeliveredPartition.d.ts.map +1 -0
  82. package/dist/observation/batches/DeliveredPartition.js +4 -0
  83. package/dist/observation/batches/DeliveredPartition.js.map +1 -0
  84. package/dist/observation/batches/EventAndContext.d.ts +28 -0
  85. package/dist/observation/batches/EventAndContext.d.ts.map +1 -0
  86. package/dist/observation/batches/EventAndContext.js +35 -0
  87. package/dist/observation/batches/EventAndContext.js.map +1 -0
  88. package/dist/observation/batches/EventBatch.d.ts +52 -0
  89. package/dist/observation/batches/EventBatch.d.ts.map +1 -0
  90. package/dist/observation/batches/EventBatch.js +92 -0
  91. package/dist/observation/batches/EventBatch.js.map +1 -0
  92. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.d.ts +14 -0
  93. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.d.ts.map +1 -0
  94. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.js +23 -0
  95. package/dist/observation/batches/EventTypeObservedByMoreThanOneMethod.js.map +1 -0
  96. package/dist/observation/batches/InvalidBatchMethod.d.ts +13 -0
  97. package/dist/observation/batches/InvalidBatchMethod.d.ts.map +1 -0
  98. package/dist/observation/batches/InvalidBatchMethod.js +20 -0
  99. package/dist/observation/batches/InvalidBatchMethod.js.map +1 -0
  100. package/dist/observation/batches/ObservationOrigin.d.ts +21 -0
  101. package/dist/observation/batches/ObservationOrigin.d.ts.map +1 -0
  102. package/dist/observation/batches/ObservationOrigin.js +32 -0
  103. package/dist/observation/batches/ObservationOrigin.js.map +1 -0
  104. package/dist/observation/batches/ObservedEventType.d.ts +11 -0
  105. package/dist/observation/batches/ObservedEventType.d.ts.map +1 -0
  106. package/dist/observation/batches/ObservedEventType.js +4 -0
  107. package/dist/observation/batches/ObservedEventType.js.map +1 -0
  108. package/dist/observation/batches/PageMessages.d.ts +22 -0
  109. package/dist/observation/batches/PageMessages.d.ts.map +1 -0
  110. package/dist/observation/batches/PageMessages.js +32 -0
  111. package/dist/observation/batches/PageMessages.js.map +1 -0
  112. package/dist/observation/batches/PartitionFailedInBatch.d.ts +10 -0
  113. package/dist/observation/batches/PartitionFailedInBatch.d.ts.map +1 -0
  114. package/dist/observation/batches/PartitionFailedInBatch.js +16 -0
  115. package/dist/observation/batches/PartitionFailedInBatch.js.map +1 -0
  116. package/dist/observation/batches/PartitionNotInBatch.d.ts +10 -0
  117. package/dist/observation/batches/PartitionNotInBatch.d.ts.map +1 -0
  118. package/dist/observation/batches/PartitionNotInBatch.js +16 -0
  119. package/dist/observation/batches/PartitionNotInBatch.js.map +1 -0
  120. package/dist/observation/batches/PartitionOutcome.d.ts +19 -0
  121. package/dist/observation/batches/PartitionOutcome.d.ts.map +1 -0
  122. package/dist/observation/batches/PartitionOutcome.js +4 -0
  123. package/dist/observation/batches/PartitionOutcome.js.map +1 -0
  124. package/dist/observation/batches/PartitionProblem.d.ts +17 -0
  125. package/dist/observation/batches/PartitionProblem.d.ts.map +1 -0
  126. package/dist/observation/batches/PartitionProblem.js +4 -0
  127. package/dist/observation/batches/PartitionProblem.js.map +1 -0
  128. package/dist/observation/batches/PartitionSettlement.d.ts +29 -0
  129. package/dist/observation/batches/PartitionSettlement.d.ts.map +1 -0
  130. package/dist/observation/batches/PartitionSettlement.js +64 -0
  131. package/dist/observation/batches/PartitionSettlement.js.map +1 -0
  132. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.d.ts +12 -0
  133. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.d.ts.map +1 -0
  134. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.js +20 -0
  135. package/dist/observation/batches/ReducerMixesBatchAndPerEventMethods.js.map +1 -0
  136. package/dist/observation/batches/batchSize.d.ts +42 -0
  137. package/dist/observation/batches/batchSize.d.ts.map +1 -0
  138. package/dist/observation/batches/batchSize.js +55 -0
  139. package/dist/observation/batches/batchSize.js.map +1 -0
  140. package/dist/observation/batches/createBatchContext.d.ts +13 -0
  141. package/dist/observation/batches/createBatchContext.d.ts.map +1 -0
  142. package/dist/observation/batches/createBatchContext.js +27 -0
  143. package/dist/observation/batches/createBatchContext.js.map +1 -0
  144. package/dist/observation/batches/observes.d.ts +39 -0
  145. package/dist/observation/batches/observes.d.ts.map +1 -0
  146. package/dist/observation/batches/observes.js +63 -0
  147. package/dist/observation/batches/observes.js.map +1 -0
  148. package/dist/observation/batches/runConcurrently.d.ts +9 -0
  149. package/dist/observation/batches/runConcurrently.d.ts.map +1 -0
  150. package/dist/observation/batches/runConcurrently.js +22 -0
  151. package/dist/observation/batches/runConcurrently.js.map +1 -0
  152. package/dist/observation/createHandlerInstanceValidator.d.ts +1 -1
  153. package/dist/observation/createHandlerInstanceValidator.d.ts.map +1 -1
  154. package/dist/observation/createHandlerInstanceValidator.js +5 -7
  155. package/dist/observation/createHandlerInstanceValidator.js.map +1 -1
  156. package/dist/observation/getInstanceMethods.d.ts +3 -1
  157. package/dist/observation/getInstanceMethods.d.ts.map +1 -1
  158. package/dist/observation/getInstanceMethods.js +13 -4
  159. package/dist/observation/getInstanceMethods.js.map +1 -1
  160. package/dist/observation/index.d.ts +14 -0
  161. package/dist/observation/index.d.ts.map +1 -1
  162. package/dist/observation/index.js +13 -0
  163. package/dist/observation/index.js.map +1 -1
  164. package/dist/projections/eventContextPropertyExpression.js +1 -1
  165. package/dist/projections/eventContextPropertyExpression.js.map +1 -1
  166. package/dist/reactors/ReactorDispatcher.d.ts +15 -0
  167. package/dist/reactors/ReactorDispatcher.d.ts.map +1 -1
  168. package/dist/reactors/ReactorDispatcher.js +25 -2
  169. package/dist/reactors/ReactorDispatcher.js.map +1 -1
  170. package/dist/reactors/ReactorObservationTarget.d.ts +45 -0
  171. package/dist/reactors/ReactorObservationTarget.d.ts.map +1 -0
  172. package/dist/reactors/ReactorObservationTarget.js +4 -0
  173. package/dist/reactors/ReactorObservationTarget.js.map +1 -0
  174. package/dist/reactors/ReactorPageDispatcher.d.ts +33 -0
  175. package/dist/reactors/ReactorPageDispatcher.d.ts.map +1 -0
  176. package/dist/reactors/ReactorPageDispatcher.js +293 -0
  177. package/dist/reactors/ReactorPageDispatcher.js.map +1 -0
  178. package/dist/reactors/Reactors.d.ts.map +1 -1
  179. package/dist/reactors/Reactors.js +21 -149
  180. package/dist/reactors/Reactors.js.map +1 -1
  181. package/dist/reactors/for_Reactors/given/observe_reactor_messages.d.ts +14 -0
  182. package/dist/reactors/for_Reactors/given/observe_reactor_messages.d.ts.map +1 -0
  183. package/dist/reactors/for_Reactors/given/observe_reactor_messages.js +61 -0
  184. package/dist/reactors/for_Reactors/given/observe_reactor_messages.js.map +1 -0
  185. package/dist/reactors/index.d.ts +2 -0
  186. package/dist/reactors/index.d.ts.map +1 -1
  187. package/dist/reactors/index.js +1 -0
  188. package/dist/reactors/index.js.map +1 -1
  189. package/dist/reducers/ReducerEventDispatcher.d.ts +26 -1
  190. package/dist/reducers/ReducerEventDispatcher.d.ts.map +1 -1
  191. package/dist/reducers/ReducerEventDispatcher.js +35 -3
  192. package/dist/reducers/ReducerEventDispatcher.js.map +1 -1
  193. package/dist/reducers/Reducers.d.ts +2 -0
  194. package/dist/reducers/Reducers.d.ts.map +1 -1
  195. package/dist/reducers/Reducers.js +94 -22
  196. package/dist/reducers/Reducers.js.map +1 -1
  197. package/dist/reducers/ReductionOutcome.d.ts +27 -3
  198. package/dist/reducers/ReductionOutcome.d.ts.map +1 -1
  199. package/dist/reducers/ReductionOutcome.js +51 -7
  200. package/dist/reducers/ReductionOutcome.js.map +1 -1
  201. package/dist/reducers/for_Reducers/given/observe_reducer_messages.d.ts +19 -0
  202. package/dist/reducers/for_Reducers/given/observe_reducer_messages.d.ts.map +1 -0
  203. package/dist/reducers/for_Reducers/given/observe_reducer_messages.js +61 -0
  204. package/dist/reducers/for_Reducers/given/observe_reducer_messages.js.map +1 -0
  205. package/dist/reducers/index.d.ts +2 -0
  206. package/dist/reducers/index.d.ts.map +1 -1
  207. package/dist/reducers/index.js +1 -0
  208. package/dist/reducers/index.js.map +1 -1
  209. package/dist/schemas/JsonSchema.d.ts +2 -0
  210. package/dist/schemas/JsonSchema.d.ts.map +1 -1
  211. package/dist/testing/InProcessEventSequence.d.ts +1 -0
  212. package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
  213. package/dist/testing/InProcessEventSequence.js +1 -0
  214. package/dist/testing/InProcessEventSequence.js.map +1 -1
  215. package/dist/testing/ReactorScenario.d.ts.map +1 -1
  216. package/dist/testing/ReactorScenario.js +4 -1
  217. package/dist/testing/ReactorScenario.js.map +1 -1
  218. package/dist/testing/ReducerReadModelProcessor.d.ts +1 -0
  219. package/dist/testing/ReducerReadModelProcessor.d.ts.map +1 -1
  220. package/dist/testing/ReducerReadModelProcessor.js +45 -0
  221. package/dist/testing/ReducerReadModelProcessor.js.map +1 -1
  222. package/dist/tsconfig.tsbuildinfo +1 -1
  223. package/eventSequences/CompensateOptions.ts +10 -0
  224. package/eventSequences/EventSequence.compensate.spec.ts +72 -0
  225. package/eventSequences/EventSequence.ts +51 -0
  226. package/eventSequences/IEventSequence.ts +14 -0
  227. package/eventSequences/index.ts +1 -0
  228. package/events/EventContext.ts +6 -0
  229. package/events/compensationFor.spec.ts +73 -0
  230. package/events/compensationForDecorator.ts +48 -0
  231. package/events/eventTypeDecorator.ts +13 -4
  232. package/events/index.ts +2 -1
  233. package/events/toClientEventContext.ts +21 -0
  234. package/observation/batches/BatchContext.ts +75 -0
  235. package/observation/batches/BatchContextObserver.ts +16 -0
  236. package/observation/batches/BatchContextValues.ts +16 -0
  237. package/observation/batches/BatchMethod.ts +13 -0
  238. package/observation/batches/BatchMethodReturnedAValue.ts +16 -0
  239. package/observation/batches/BatchMethods.ts +90 -0
  240. package/observation/batches/BatchOutcome.ts +22 -0
  241. package/observation/batches/BatchOutcomeKind.ts +11 -0
  242. package/observation/batches/DeferralNotSupportedByKernel.ts +17 -0
  243. package/observation/batches/DeliveredPartition.ts +16 -0
  244. package/observation/batches/EventAndContext.ts +37 -0
  245. package/observation/batches/EventBatch.ts +105 -0
  246. package/observation/batches/EventTypeObservedByMoreThanOneMethod.ts +17 -0
  247. package/observation/batches/InvalidBatchMethod.ts +16 -0
  248. package/observation/batches/ObservationOrigin.ts +37 -0
  249. package/observation/batches/ObservedEventType.ts +16 -0
  250. package/observation/batches/PageMessages.ts +37 -0
  251. package/observation/batches/PartitionFailedInBatch.ts +14 -0
  252. package/observation/batches/PartitionNotInBatch.ts +14 -0
  253. package/observation/batches/PartitionOutcome.ts +22 -0
  254. package/observation/batches/PartitionProblem.ts +25 -0
  255. package/observation/batches/PartitionSettlement.ts +70 -0
  256. package/observation/batches/ReducerMixesBatchAndPerEventMethods.ts +16 -0
  257. package/observation/batches/batchSize.ts +79 -0
  258. package/observation/batches/createBatchContext.ts +32 -0
  259. package/observation/batches/for_BatchMethods/when_discovering_batch_methods.spec.ts +155 -0
  260. package/observation/batches/for_EventBatch/when_reporting_outcomes.spec.ts +66 -0
  261. package/observation/batches/for_PartitionSettlement/when_settling_a_partition.spec.ts +31 -0
  262. package/observation/batches/for_batchSize/when_declaring_bounds.spec.ts +23 -0
  263. package/observation/batches/for_observes/when_decorating_methods.legacy.spec.ts +28 -0
  264. package/observation/batches/for_observes/when_decorating_methods.spec.ts +33 -0
  265. package/observation/batches/for_runConcurrently/when_running_items.spec.ts +22 -0
  266. package/observation/batches/observes.ts +68 -0
  267. package/observation/batches/runConcurrently.ts +23 -0
  268. package/observation/createHandlerInstanceValidator.ts +5 -7
  269. package/observation/getInstanceMethods.ts +13 -4
  270. package/observation/index.ts +14 -0
  271. package/package.json +2 -2
  272. package/projections/eventContextPropertyExpression.ts +2 -2
  273. package/reactors/ReactorDispatcher.ts +27 -2
  274. package/reactors/ReactorObservationTarget.ts +48 -0
  275. package/reactors/ReactorPageDispatcher.ts +321 -0
  276. package/reactors/Reactors.ts +22 -164
  277. package/reactors/for_Reactors/given/observe_reactor_messages.ts +72 -0
  278. package/reactors/for_Reactors/when_delivering_pages/as_a_legacy_single_partition.spec.ts +51 -0
  279. package/reactors/for_Reactors/when_delivering_pages/returning_a_value_from_a_batch_method.spec.ts +34 -0
  280. package/reactors/for_Reactors/when_delivering_pages/with_batch_and_per_event_methods.spec.ts +81 -0
  281. package/reactors/for_Reactors/when_delivering_pages/with_batch_outcomes.spec.ts +86 -0
  282. package/reactors/for_Reactors/when_delivering_pages/with_per_event_handlers.spec.ts +52 -0
  283. package/reactors/index.ts +2 -0
  284. package/reducers/ReducerEventDispatcher.ts +44 -3
  285. package/reducers/Reducers.ts +109 -25
  286. package/reducers/ReductionOutcome.ts +55 -8
  287. package/reducers/for_Reducers/given/observe_reducer_messages.ts +77 -0
  288. package/reducers/for_Reducers/when_delivering_pages/to_a_batch_reducer.spec.ts +111 -0
  289. package/reducers/for_Reducers/when_delivering_pages/to_a_per_event_reducer.spec.ts +53 -0
  290. package/reducers/index.ts +2 -0
  291. package/schemas/JsonSchema.ts +2 -0
  292. package/telemetry/for_ChronicleTelemetry/given/a_client.fixture.ts +1 -0
  293. package/telemetry/for_ChronicleTelemetry/given/a_span_name_registry.fixture.ts +2 -0
  294. package/telemetry/for_ChronicleTelemetry/when_naming_spans/with_convention_names.spec.ts +2 -1
  295. package/testing/InProcessEventSequence.ts +1 -0
  296. package/testing/ReactorScenario.ts +5 -1
  297. package/testing/ReducerReadModelProcessor.ts +44 -0
  298. package/testing/for_ReactorScenario/when_the_reactor_has_a_batch_method.spec.ts +26 -0
  299. package/testing/for_ReadModelScenario/when_reducing_with_a_batch_method/with_events_for_two_event_sources.spec.ts +43 -0
@@ -0,0 +1,16 @@
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
+ /** Reported when a batch method fails a partition without giving a reason. */
4
+ export class PartitionFailedInBatch extends Error {
5
+ partition;
6
+ /**
7
+ * Creates a new {@link PartitionFailedInBatch}.
8
+ * @param partition - The partition that was failed.
9
+ */
10
+ constructor(partition) {
11
+ super(`Partition '${partition}' was failed by a batch method.`);
12
+ this.partition = partition;
13
+ this.name = 'PartitionFailedInBatch';
14
+ }
15
+ }
16
+ //# sourceMappingURL=PartitionFailedInBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionFailedInBatch.js","sourceRoot":"","sources":["../../../observation/batches/PartitionFailedInBatch.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,8EAA8E;AAC9E,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAKxB,SAAS;IAJ9B;;;OAGG;IACH,YAAqB,SAAiB;QAClC,KAAK,CAAC,cAAc,SAAS,iCAAiC,CAAC,CAAC;yBAD/C,SAAS;QAE1B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACzC,CAAC;CACJ"}
@@ -0,0 +1,10 @@
1
+ /** Thrown when a batch method reports an outcome for a partition the batch holds no events for. */
2
+ export declare class PartitionNotInBatch extends Error {
3
+ readonly partition: string;
4
+ /**
5
+ * Creates a new {@link PartitionNotInBatch}.
6
+ * @param partition - The partition the outcome was reported for.
7
+ */
8
+ constructor(partition: string);
9
+ }
10
+ //# sourceMappingURL=PartitionNotInBatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionNotInBatch.d.ts","sourceRoot":"","sources":["../../../observation/batches/PartitionNotInBatch.ts"],"names":[],"mappings":"AAGA,mGAAmG;AACnG,qBAAa,mBAAoB,SAAQ,KAAK;IAK9B,QAAQ,CAAC,SAAS,EAAE,MAAM;IAJtC;;;OAGG;IACH,YAAqB,SAAS,EAAE,MAAM,EAGrC;CACJ"}
@@ -0,0 +1,16 @@
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
+ /** Thrown when a batch method reports an outcome for a partition the batch holds no events for. */
4
+ export class PartitionNotInBatch extends Error {
5
+ partition;
6
+ /**
7
+ * Creates a new {@link PartitionNotInBatch}.
8
+ * @param partition - The partition the outcome was reported for.
9
+ */
10
+ constructor(partition) {
11
+ super(`The batch holds no events for partition '${partition}', so no outcome can be reported for it.`);
12
+ this.partition = partition;
13
+ this.name = 'PartitionNotInBatch';
14
+ }
15
+ }
16
+ //# sourceMappingURL=PartitionNotInBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionNotInBatch.js","sourceRoot":"","sources":["../../../observation/batches/PartitionNotInBatch.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,mGAAmG;AACnG,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAKrB,SAAS;IAJ9B;;;OAGG;IACH,YAAqB,SAAiB;QAClC,KAAK,CAAC,4CAA4C,SAAS,0CAA0C,CAAC,CAAC;yBADtF,SAAS;QAE1B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACtC,CAAC;CACJ"}
@@ -0,0 +1,19 @@
1
+ import type { ObservationState } from '@cratis/chronicle.contracts';
2
+ /** The outcome of observing the events of one partition of a delivery. */
3
+ export interface PartitionOutcome {
4
+ /** The partition. */
5
+ readonly partition: string;
6
+ /** The settled state of the partition. */
7
+ readonly state: ObservationState;
8
+ /** The last event of the partition that was observed successfully. */
9
+ readonly lastSuccessfulObservation: bigint;
10
+ /** The messages describing a failure. */
11
+ readonly exceptionMessages: readonly string[];
12
+ /** The stack trace of a failure. */
13
+ readonly exceptionStackTrace: string;
14
+ /** How long to wait before delivering again, for a deferral. */
15
+ readonly retryAfterMilliseconds: number;
16
+ /** The reduced read model state as JSON, for reducers. */
17
+ readonly readModelState?: string;
18
+ }
19
+ //# sourceMappingURL=PartitionOutcome.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionOutcome.d.ts","sourceRoot":"","sources":["../../../observation/batches/PartitionOutcome.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,0EAA0E;AAC1E,MAAM,WAAW,gBAAgB;IAC7B,qBAAqB;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,sEAAsE;IACtE,QAAQ,CAAC,yBAAyB,EAAE,MAAM,CAAC;IAC3C,yCAAyC;IACzC,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9C,oCAAoC;IACpC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,gEAAgE;IAChE,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,0DAA0D;IAC1D,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CACpC"}
@@ -0,0 +1,4 @@
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
+ export {};
4
+ //# sourceMappingURL=PartitionOutcome.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionOutcome.js","sourceRoot":"","sources":["../../../observation/batches/PartitionOutcome.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG"}
@@ -0,0 +1,17 @@
1
+ import type { ObservationState } from '@cratis/chronicle.contracts';
2
+ /** The first event of a partition that one method of an observer did not handle. */
3
+ export interface PartitionProblem {
4
+ /** The partition. */
5
+ readonly partition: string;
6
+ /** The sequence number of the event. */
7
+ readonly at: bigint;
8
+ /** Whether the partition failed or was deferred. */
9
+ readonly state: ObservationState.Failed | ObservationState.Deferred;
10
+ /** The messages describing a failure. */
11
+ readonly exceptionMessages: readonly string[];
12
+ /** The stack trace of a failure. */
13
+ readonly exceptionStackTrace: string;
14
+ /** How long to wait before delivering again, for a deferral. */
15
+ readonly retryAfterMilliseconds: number;
16
+ }
17
+ //# sourceMappingURL=PartitionProblem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionProblem.d.ts","sourceRoot":"","sources":["../../../observation/batches/PartitionProblem.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,oFAAoF;AACpF,MAAM,WAAW,gBAAgB;IAC7B,qBAAqB;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC;IAEpE,yCAAyC;IACzC,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;IAE9C,oCAAoC;IACpC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IAErC,gEAAgE;IAChE,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;CAC3C"}
@@ -0,0 +1,4 @@
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
+ export {};
4
+ //# sourceMappingURL=PartitionProblem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionProblem.js","sourceRoot":"","sources":["../../../observation/batches/PartitionProblem.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG"}
@@ -0,0 +1,29 @@
1
+ import { type PartitionResult } from '@cratis/chronicle.contracts';
2
+ import type { PartitionOutcome } from './PartitionOutcome.js';
3
+ import type { PartitionProblem } from './PartitionProblem.js';
4
+ /** Sequence number reported when no event of a partition was observed successfully. */
5
+ export declare const SEQUENCE_NUMBER_UNAVAILABLE = 4294967295n;
6
+ /**
7
+ * Creates a {@link PartitionProblem} for a failure.
8
+ * @param partition - The partition.
9
+ * @param at - The sequence number of the event it failed at.
10
+ * @param error - What went wrong.
11
+ * @returns The {@link PartitionProblem}.
12
+ */
13
+ export declare function failedAt(partition: string, at: bigint, error: unknown): PartitionProblem;
14
+ /**
15
+ * Settles a partition: it succeeds when no method reported a problem for it, and otherwise settles at its earliest problem.
16
+ * Events before that problem count as observed.
17
+ * @param partition - The partition.
18
+ * @param sequenceNumbers - The sequence numbers of the partition's events, in order.
19
+ * @param problems - The problems reported by any method, for any partition.
20
+ * @returns The {@link PartitionOutcome}.
21
+ */
22
+ export declare function settlePartition(partition: string, sequenceNumbers: readonly bigint[], problems: readonly PartitionProblem[]): PartitionOutcome;
23
+ /**
24
+ * Converts a {@link PartitionOutcome} to the {@link PartitionResult} sent to the kernel.
25
+ * @param outcome - The outcome.
26
+ * @returns The {@link PartitionResult}.
27
+ */
28
+ export declare function toPartitionResult(outcome: PartitionOutcome): PartitionResult;
29
+ //# sourceMappingURL=PartitionSettlement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionSettlement.d.ts","sourceRoot":"","sources":["../../../observation/batches/PartitionSettlement.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,uFAAuF;AACvF,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAOxF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,MAAM,EAAE,EAAE,QAAQ,EAAE,SAAS,gBAAgB,EAAE,GAAG,gBAAgB,CAkB9I;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAU5E"}
@@ -0,0 +1,64 @@
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
+ import { ObservationState } from '@cratis/chronicle.contracts';
4
+ /** Sequence number reported when no event of a partition was observed successfully. */
5
+ export const SEQUENCE_NUMBER_UNAVAILABLE = 4294967295n;
6
+ /**
7
+ * Creates a {@link PartitionProblem} for a failure.
8
+ * @param partition - The partition.
9
+ * @param at - The sequence number of the event it failed at.
10
+ * @param error - What went wrong.
11
+ * @returns The {@link PartitionProblem}.
12
+ */
13
+ export function failedAt(partition, at, error) {
14
+ return {
15
+ partition, at, state: ObservationState.Failed,
16
+ exceptionMessages: [String(error)],
17
+ exceptionStackTrace: error instanceof Error ? (error.stack ?? '') : '',
18
+ retryAfterMilliseconds: 0
19
+ };
20
+ }
21
+ /**
22
+ * Settles a partition: it succeeds when no method reported a problem for it, and otherwise settles at its earliest problem.
23
+ * Events before that problem count as observed.
24
+ * @param partition - The partition.
25
+ * @param sequenceNumbers - The sequence numbers of the partition's events, in order.
26
+ * @param problems - The problems reported by any method, for any partition.
27
+ * @returns The {@link PartitionOutcome}.
28
+ */
29
+ export function settlePartition(partition, sequenceNumbers, problems) {
30
+ const earliest = problems
31
+ .filter(problem => problem.partition === partition)
32
+ .reduce((first, problem) => !first || problem.at < first.at ? problem : first, undefined);
33
+ if (!earliest) {
34
+ return {
35
+ partition, state: ObservationState.Success,
36
+ lastSuccessfulObservation: sequenceNumbers.at(-1) ?? SEQUENCE_NUMBER_UNAVAILABLE,
37
+ exceptionMessages: [], exceptionStackTrace: '', retryAfterMilliseconds: 0
38
+ };
39
+ }
40
+ const handled = sequenceNumbers.filter(sequenceNumber => sequenceNumber < earliest.at);
41
+ return {
42
+ partition, state: earliest.state,
43
+ lastSuccessfulObservation: handled.at(-1) ?? SEQUENCE_NUMBER_UNAVAILABLE,
44
+ exceptionMessages: earliest.exceptionMessages, exceptionStackTrace: earliest.exceptionStackTrace,
45
+ retryAfterMilliseconds: earliest.retryAfterMilliseconds
46
+ };
47
+ }
48
+ /**
49
+ * Converts a {@link PartitionOutcome} to the {@link PartitionResult} sent to the kernel.
50
+ * @param outcome - The outcome.
51
+ * @returns The {@link PartitionResult}.
52
+ */
53
+ export function toPartitionResult(outcome) {
54
+ return {
55
+ Partition: outcome.partition,
56
+ State: outcome.state,
57
+ LastSuccessfulObservation: outcome.lastSuccessfulObservation,
58
+ ExceptionMessages: [...outcome.exceptionMessages],
59
+ ExceptionStackTrace: outcome.exceptionStackTrace,
60
+ RetryAfterMilliseconds: BigInt(Math.max(0, Math.round(outcome.retryAfterMilliseconds))),
61
+ ReadModelState: outcome.readModelState ?? ''
62
+ };
63
+ }
64
+ //# sourceMappingURL=PartitionSettlement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartitionSettlement.js","sourceRoot":"","sources":["../../../observation/batches/PartitionSettlement.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,OAAO,EAAE,gBAAgB,EAAwB,MAAM,6BAA6B,CAAC;AAIrF,uFAAuF;AACvF,MAAM,CAAC,MAAM,2BAA2B,GAAG,WAAW,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAiB,EAAE,EAAU,EAAE,KAAc;IAClE,OAAO;QACH,SAAS,EAAE,EAAE,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM;QAC7C,iBAAiB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClC,mBAAmB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;QACtE,sBAAsB,EAAE,CAAC;KAC5B,CAAC;AACN,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiB,EAAE,eAAkC,EAAE,QAAqC;IACxH,MAAM,QAAQ,GAAG,QAAQ;SACpB,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC;SAClD,MAAM,CAA+B,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC5H,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO;YACH,SAAS,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO;YAC1C,yBAAyB,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,2BAA2B;YAChF,iBAAiB,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAAE,EAAE,sBAAsB,EAAE,CAAC;SAC5E,CAAC;IACN,CAAC;IACD,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,cAAc,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvF,OAAO;QACH,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK;QAChC,yBAAyB,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,2BAA2B;QACxE,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB,EAAE,mBAAmB,EAAE,QAAQ,CAAC,mBAAmB;QAChG,sBAAsB,EAAE,QAAQ,CAAC,sBAAsB;KAC1D,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAyB;IACvD,OAAO;QACH,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,yBAAyB,EAAE,OAAO,CAAC,yBAAyB;QAC5D,iBAAiB,EAAE,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACjD,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;QAChD,sBAAsB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC;QACvF,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,EAAE;KAC/C,CAAC;AACN,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** Thrown at registration when a reducer declares a batch method and per-event methods, or more than one batch method. */
2
+ export declare class ReducerMixesBatchAndPerEventMethods extends Error {
3
+ readonly reducerType: string;
4
+ readonly methods: readonly string[];
5
+ /**
6
+ * Creates a new {@link ReducerMixesBatchAndPerEventMethods}.
7
+ * @param reducerType - The name of the reducer class.
8
+ * @param methods - The methods that conflict.
9
+ */
10
+ constructor(reducerType: string, methods: readonly string[]);
11
+ }
12
+ //# sourceMappingURL=ReducerMixesBatchAndPerEventMethods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReducerMixesBatchAndPerEventMethods.d.ts","sourceRoot":"","sources":["../../../observation/batches/ReducerMixesBatchAndPerEventMethods.ts"],"names":[],"mappings":"AAGA,0HAA0H;AAC1H,qBAAa,mCAAoC,SAAQ,KAAK;IAM9C,QAAQ,CAAC,WAAW,EAAE,MAAM;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE;IAL7E;;;;OAIG;IACH,YAAqB,WAAW,EAAE,MAAM,EAAW,OAAO,EAAE,SAAS,MAAM,EAAE,EAI5E;CACJ"}
@@ -0,0 +1,20 @@
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
+ /** Thrown at registration when a reducer declares a batch method and per-event methods, or more than one batch method. */
4
+ export class ReducerMixesBatchAndPerEventMethods extends Error {
5
+ reducerType;
6
+ methods;
7
+ /**
8
+ * Creates a new {@link ReducerMixesBatchAndPerEventMethods}.
9
+ * @param reducerType - The name of the reducer class.
10
+ * @param methods - The methods that conflict.
11
+ */
12
+ constructor(reducerType, methods) {
13
+ super(`Reducer '${reducerType}' declares ${methods.map(method => `'${method}'`).join(', ')}. ` +
14
+ 'A reducer has either per-event methods or exactly one batch method, never both, because it is a single fold over one event source.');
15
+ this.reducerType = reducerType;
16
+ this.methods = methods;
17
+ this.name = 'ReducerMixesBatchAndPerEventMethods';
18
+ }
19
+ }
20
+ //# sourceMappingURL=ReducerMixesBatchAndPerEventMethods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReducerMixesBatchAndPerEventMethods.js","sourceRoot":"","sources":["../../../observation/batches/ReducerMixesBatchAndPerEventMethods.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,0HAA0H;AAC1H,MAAM,OAAO,mCAAoC,SAAQ,KAAK;IAMrC,WAAW;IAAmB,OAAO;IAL1D;;;;OAIG;IACH,YAAqB,WAAmB,EAAW,OAA0B;QACzE,KAAK,CAAC,YAAY,WAAW,cAAc,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC1F,oIAAoI,CAAC,CAAC;2BAFzH,WAAW;uBAAmB,OAAO;QAGtD,IAAI,CAAC,IAAI,GAAG,qCAAqC,CAAC;IACtD,CAAC;CACJ"}
@@ -0,0 +1,42 @@
1
+ import 'reflect-metadata';
2
+ import type { PageDelivery } from '@cratis/chronicle.contracts';
3
+ /** The bounds an observer declares for the pages the kernel delivers to it. */
4
+ export interface BatchSizeOptions {
5
+ /** The most events in one page. The kernel's own maximum caps it. Defaults to the kernel's default. */
6
+ readonly maxEvents?: number;
7
+ /** The most bytes in one page. The kernel's own maximum caps it. Defaults to the kernel's default. */
8
+ readonly maxBytes?: number;
9
+ /** How long, in milliseconds, the kernel may wait to fill a live page. Defaults to no delay. */
10
+ readonly maxDelayMilliseconds?: number;
11
+ /**
12
+ * How many event sources of one page a reducer reduces at the same time. Defaults to the number of processors;
13
+ * `1` reduces them one after another. Reactors call their methods for a page in order and ignore it.
14
+ */
15
+ readonly maxConcurrency?: number;
16
+ }
17
+ /**
18
+ * Declares the bounds of the pages a reactor or reducer receives, the TypeScript equivalent of the C# `[BatchSize]` attribute.
19
+ * @param options - The {@link BatchSizeOptions}.
20
+ * @returns A class decorator for legacy and standard TypeScript decorators.
21
+ */
22
+ export declare function batchSize(options: BatchSizeOptions): ClassDecorator & ((value: Function, context: ClassDecoratorContext) => void);
23
+ /**
24
+ * Gets the {@link BatchSizeOptions} declared on an observer class.
25
+ * @param target - The observer class.
26
+ * @returns The declared options, or an empty object when none are declared.
27
+ */
28
+ export declare function getBatchSize(target: Function): BatchSizeOptions;
29
+ /**
30
+ * Gets how many event sources of one page a reducer reduces at the same time.
31
+ * @param target - The reducer class.
32
+ * @returns The declared concurrency, or the number of processors.
33
+ */
34
+ export declare function getMaxConcurrency(target: Function): number;
35
+ /**
36
+ * Creates the page delivery the client opts in to at registration. A kernel that does not know page delivery ignores it
37
+ * and keeps delivering one partition at a time.
38
+ * @param target - The observer class.
39
+ * @returns The {@link PageDelivery} for the registration.
40
+ */
41
+ export declare function toPageDelivery(target: Function): PageDelivery;
42
+ //# sourceMappingURL=batchSize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batchSize.d.ts","sourceRoot":"","sources":["../../../observation/batches/batchSize.ts"],"names":[],"mappings":"AAGA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAKhE,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC7B,uGAAuG;IACvG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B,gGAAgG;IAChG,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAEvC;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,cAAc,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC,CAYjI;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,gBAAgB,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,GAAG,YAAY,CAQ7D"}
@@ -0,0 +1,55 @@
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
+ import 'reflect-metadata';
4
+ import { availableParallelism } from 'node:os';
5
+ const METADATA_KEY = 'chronicle:observation:batchSize';
6
+ /**
7
+ * Declares the bounds of the pages a reactor or reducer receives, the TypeScript equivalent of the C# `[BatchSize]` attribute.
8
+ * @param options - The {@link BatchSizeOptions}.
9
+ * @returns A class decorator for legacy and standard TypeScript decorators.
10
+ */
11
+ export function batchSize(options) {
12
+ for (const [name, value] of Object.entries(options)) {
13
+ if (value !== undefined && (!Number.isInteger(value) || value < (name === 'maxDelayMilliseconds' ? 0 : 1))) {
14
+ throw new RangeError(`Batch size '${name}' must be a ${name === 'maxDelayMilliseconds' ? 'non-negative' : 'positive'} integer.`);
15
+ }
16
+ }
17
+ return (target, context) => {
18
+ if (context !== undefined && context.kind !== 'class') {
19
+ throw new TypeError('Batch size can only decorate a reactor or reducer class.');
20
+ }
21
+ Reflect.defineMetadata(METADATA_KEY, Object.freeze({ ...options }), target);
22
+ };
23
+ }
24
+ /**
25
+ * Gets the {@link BatchSizeOptions} declared on an observer class.
26
+ * @param target - The observer class.
27
+ * @returns The declared options, or an empty object when none are declared.
28
+ */
29
+ export function getBatchSize(target) {
30
+ return Reflect.getOwnMetadata(METADATA_KEY, target) ?? {};
31
+ }
32
+ /**
33
+ * Gets how many event sources of one page a reducer reduces at the same time.
34
+ * @param target - The reducer class.
35
+ * @returns The declared concurrency, or the number of processors.
36
+ */
37
+ export function getMaxConcurrency(target) {
38
+ return getBatchSize(target).maxConcurrency ?? availableParallelism();
39
+ }
40
+ /**
41
+ * Creates the page delivery the client opts in to at registration. A kernel that does not know page delivery ignores it
42
+ * and keeps delivering one partition at a time.
43
+ * @param target - The observer class.
44
+ * @returns The {@link PageDelivery} for the registration.
45
+ */
46
+ export function toPageDelivery(target) {
47
+ const options = getBatchSize(target);
48
+ return {
49
+ Enabled: true,
50
+ MaxEventsPerPage: options.maxEvents ?? 0,
51
+ MaxBytesPerPage: options.maxBytes ?? 0,
52
+ MaxDelayMilliseconds: options.maxDelayMilliseconds ?? 0
53
+ };
54
+ }
55
+ //# sourceMappingURL=batchSize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batchSize.js","sourceRoot":"","sources":["../../../observation/batches/batchSize.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,YAAY,GAAG,iCAAiC,CAAC;AAoBvD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,OAAyB;IAC/C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAK,KAAgB,GAAG,CAAC,IAAI,KAAK,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACrH,MAAM,IAAI,UAAU,CAAC,eAAe,IAAI,eAAe,IAAI,KAAK,sBAAsB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,WAAW,CAAC,CAAC;QACrI,CAAC;IACL,CAAC;IACD,OAAO,CAAC,MAAc,EAAE,OAA+B,EAAE,EAAE;QACvD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACpD,MAAM,IAAI,SAAS,CAAC,0DAA0D,CAAC,CAAC;QACpF,CAAC;QACD,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IAChF,CAAC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAgB;IACzC,OAAQ,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAAkC,IAAI,EAAE,CAAC;AAChG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAgB;IAC9C,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,cAAc,IAAI,oBAAoB,EAAE,CAAC;AACzE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAgB;IAC3C,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO;QACH,OAAO,EAAE,IAAI;QACb,gBAAgB,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC;QACxC,eAAe,EAAE,OAAO,CAAC,QAAQ,IAAI,CAAC;QACtC,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,IAAI,CAAC;KAC1D,CAAC;AACN,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { EventsToObserve, ReduceOperationMessage } from '@cratis/chronicle.contracts';
2
+ import { BatchContext } from './BatchContext.js';
3
+ import type { BatchContextObserver } from './BatchContextObserver.js';
4
+ import type { DeliveredPartition } from './DeliveredPartition.js';
5
+ /**
6
+ * Creates the {@link BatchContext} describing a delivered page.
7
+ * @param observer - The observer the page is delivered to.
8
+ * @param message - The delivered message.
9
+ * @param partitions - The partitions of the delivery.
10
+ * @returns The {@link BatchContext}.
11
+ */
12
+ export declare function createBatchContext(observer: BatchContextObserver, message: EventsToObserve | ReduceOperationMessage, partitions: readonly DeliveredPartition[]): BatchContext;
13
+ //# sourceMappingURL=createBatchContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBatchContext.d.ts","sourceRoot":"","sources":["../../../observation/batches/createBatchContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIlE;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,OAAO,EAAE,eAAe,GAAG,sBAAsB,EAChH,UAAU,EAAE,SAAS,kBAAkB,EAAE,GAAG,YAAY,CAa3D"}
@@ -0,0 +1,27 @@
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
+ import { BatchContext } from './BatchContext.js';
4
+ import { toObservationOrigin } from './ObservationOrigin.js';
5
+ import { isPage } from './PageMessages.js';
6
+ /**
7
+ * Creates the {@link BatchContext} describing a delivered page.
8
+ * @param observer - The observer the page is delivered to.
9
+ * @param message - The delivered message.
10
+ * @param partitions - The partitions of the delivery.
11
+ * @returns The {@link BatchContext}.
12
+ */
13
+ export function createBatchContext(observer, message, partitions) {
14
+ const sequenceNumbers = partitions.flatMap(partition => partition.events.map(event => event.Context.SequenceNumber));
15
+ const deliverWithin = Number(message.DeliverWithinMilliseconds ?? 0n);
16
+ return new BatchContext({
17
+ ...observer,
18
+ origin: toObservationOrigin(message.Origin),
19
+ partitions: partitions.map(partition => partition.partition),
20
+ eventCount: sequenceNumbers.length,
21
+ firstSequenceNumber: sequenceNumbers.length > 0 ? sequenceNumbers.reduce((min, value) => value < min ? value : min) : undefined,
22
+ lastSequenceNumber: sequenceNumbers.length > 0 ? sequenceNumbers.reduce((max, value) => value > max ? value : max) : undefined,
23
+ deadline: deliverWithin > 0 ? new Date(Date.now() + deliverWithin) : undefined,
24
+ canDefer: isPage(message)
25
+ });
26
+ }
27
+ //# sourceMappingURL=createBatchContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBatchContext.js","sourceRoot":"","sources":["../../../observation/batches/createBatchContext.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAGrG,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAA8B,EAAE,OAAiD,EAChH,UAAyC;IACzC,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;IACtH,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IACtE,OAAO,IAAI,YAAY,CAAC;QACpB,GAAG,QAAQ;QACX,MAAM,EAAE,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC;QAC3C,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC;QAC5D,UAAU,EAAE,eAAe,CAAC,MAAM;QAClC,mBAAmB,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;QAC/H,kBAAkB,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;QAC9H,QAAQ,EAAE,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS;QAC9E,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC;KAC5B,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,39 @@
1
+ import 'reflect-metadata';
2
+ import type { Constructor } from '@cratis/fundamentals';
3
+ /**
4
+ * Makes a reactor or reducer method a batch method and declares one event type it observes. Apply it once per event
5
+ * type; it is the TypeScript equivalent of the C# `[Observes<TEvent>]` attribute.
6
+ *
7
+ * A batch method receives an {@link EventBatch} of every event of the types it observes, in sequence order, and a
8
+ * {@link BatchContext} describing the page. Each event type reaches exactly one method of an observer: a batch method
9
+ * or a per-event method, never both.
10
+ *
11
+ * @param eventType - The event constructor observed by this method. The event type must be registered with the owning event store.
12
+ * @returns A method decorator for legacy and standard TypeScript decorators.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * @reactor()
17
+ * class Users {
18
+ * @observes(UserRegistered)
19
+ * @observes(UserRenamed)
20
+ * async index(batch: EventBatch, context: BatchContext): Promise<void> {
21
+ * // ...
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function observes(eventType: Constructor): MethodDecorator & ((value: Function, context: ClassMethodDecoratorContext) => void);
27
+ /**
28
+ * Gets the event constructors a batch method observes, without inheriting metadata.
29
+ * @param method - The method.
30
+ * @returns The observed event constructors, or an empty array when the method is not a batch method.
31
+ */
32
+ export declare function getObservedEventTypes(method: Function): readonly Constructor[];
33
+ /**
34
+ * Checks whether a method is a batch method, that is decorated with {@link observes}.
35
+ * @param method - The method.
36
+ * @returns True when it is a batch method.
37
+ */
38
+ export declare function isBatchMethod(method: Function): boolean;
39
+ //# sourceMappingURL=observes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observes.d.ts","sourceRoot":"","sources":["../../../observation/batches/observes.ts"],"names":[],"mappings":"AAGA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,WAAW,GAAG,eAAe,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,2BAA2B,KAAK,IAAI,CAAC,CAkBpI;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,WAAW,EAAE,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAEvD"}
@@ -0,0 +1,63 @@
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
+ import 'reflect-metadata';
4
+ const METADATA_KEY = 'chronicle:observation:observes';
5
+ /**
6
+ * Makes a reactor or reducer method a batch method and declares one event type it observes. Apply it once per event
7
+ * type; it is the TypeScript equivalent of the C# `[Observes<TEvent>]` attribute.
8
+ *
9
+ * A batch method receives an {@link EventBatch} of every event of the types it observes, in sequence order, and a
10
+ * {@link BatchContext} describing the page. Each event type reaches exactly one method of an observer: a batch method
11
+ * or a per-event method, never both.
12
+ *
13
+ * @param eventType - The event constructor observed by this method. The event type must be registered with the owning event store.
14
+ * @returns A method decorator for legacy and standard TypeScript decorators.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * @reactor()
19
+ * class Users {
20
+ * @observes(UserRegistered)
21
+ * @observes(UserRenamed)
22
+ * async index(batch: EventBatch, context: BatchContext): Promise<void> {
23
+ * // ...
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ export function observes(eventType) {
29
+ return (target, propertyOrContext, descriptor) => {
30
+ const isStandard = typeof propertyOrContext === 'object';
31
+ const method = isStandard ? target : descriptor?.value;
32
+ const name = isStandard ? propertyOrContext.name : propertyOrContext;
33
+ if ((isStandard && (propertyOrContext.kind !== 'method' || propertyOrContext.static || propertyOrContext.private)) ||
34
+ (!isStandard && typeof target === 'function') || typeof name !== 'string' || typeof method !== 'function') {
35
+ throw new TypeError('Observes requires a public, string-named instance method.');
36
+ }
37
+ if (typeof eventType !== 'function') {
38
+ throw new TypeError('Observes requires an event constructor.');
39
+ }
40
+ const observed = Reflect.getOwnMetadata(METADATA_KEY, method) ?? [];
41
+ if (observed.includes(eventType)) {
42
+ throw new TypeError(`Batch method '${name}' observes '${eventType.name}' more than once.`);
43
+ }
44
+ Reflect.defineMetadata(METADATA_KEY, [...observed, eventType], method);
45
+ };
46
+ }
47
+ /**
48
+ * Gets the event constructors a batch method observes, without inheriting metadata.
49
+ * @param method - The method.
50
+ * @returns The observed event constructors, or an empty array when the method is not a batch method.
51
+ */
52
+ export function getObservedEventTypes(method) {
53
+ return Reflect.getOwnMetadata(METADATA_KEY, method) ?? [];
54
+ }
55
+ /**
56
+ * Checks whether a method is a batch method, that is decorated with {@link observes}.
57
+ * @param method - The method.
58
+ * @returns True when it is a batch method.
59
+ */
60
+ export function isBatchMethod(method) {
61
+ return getObservedEventTypes(method).length > 0;
62
+ }
63
+ //# sourceMappingURL=observes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observes.js","sourceRoot":"","sources":["../../../observation/batches/observes.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG,OAAO,kBAAkB,CAAC;AAG1B,MAAM,YAAY,GAAG,gCAAgC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAsB;IAC3C,OAAO,CAAC,MAAc,EAAE,iBAAgE,EAAE,UAA+B,EAAE,EAAE;QACzH,MAAM,UAAU,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC;QACzD,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC;QACvD,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC;QACrE,IAAI,CAAC,UAAU,IAAI,CAAC,iBAAiB,CAAC,IAAI,KAAK,QAAQ,IAAI,iBAAiB,CAAC,MAAM,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;YAC9G,CAAC,CAAC,UAAU,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YAC5G,MAAM,IAAI,SAAS,CAAC,2DAA2D,CAAC,CAAC;QACrF,CAAC;QACD,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAC;QACnE,CAAC;QACD,MAAM,QAAQ,GAAI,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAA+B,IAAI,EAAE,CAAC;QACnG,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,SAAS,CAAC,iBAAiB,IAAI,eAAgB,SAAsB,CAAC,IAAI,mBAAmB,CAAC,CAAC;QAC7G,CAAC;QACD,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,GAAG,QAAQ,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAgB;IAClD,OAAQ,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,CAA+B,IAAI,EAAE,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAgB;IAC1C,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Runs a callback for every item, with at most a given number running at the same time, and keeps the results in item order.
3
+ * @param items - The items.
4
+ * @param maxConcurrency - The most callbacks running at the same time; `1` runs them one after another.
5
+ * @param callback - The callback for one item.
6
+ * @returns The results, in the order of the items.
7
+ */
8
+ export declare function runConcurrently<TItem, TResult>(items: readonly TItem[], maxConcurrency: number, callback: (item: TItem, index: number) => Promise<TResult>): Promise<TResult[]>;
9
+ //# sourceMappingURL=runConcurrently.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runConcurrently.d.ts","sourceRoot":"","sources":["../../../observation/batches/runConcurrently.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,EACjG,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAWlF"}
@@ -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
+ * Runs a callback for every item, with at most a given number running at the same time, and keeps the results in item order.
5
+ * @param items - The items.
6
+ * @param maxConcurrency - The most callbacks running at the same time; `1` runs them one after another.
7
+ * @param callback - The callback for one item.
8
+ * @returns The results, in the order of the items.
9
+ */
10
+ export async function runConcurrently(items, maxConcurrency, callback) {
11
+ const results = new Array(items.length);
12
+ let next = 0;
13
+ const worker = async () => {
14
+ while (next < items.length) {
15
+ const index = next++;
16
+ results[index] = await callback(items[index], index);
17
+ }
18
+ };
19
+ await Promise.all(Array.from({ length: Math.max(1, Math.min(maxConcurrency, items.length)) }, worker));
20
+ return results;
21
+ }
22
+ //# sourceMappingURL=runConcurrently.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runConcurrently.js","sourceRoot":"","sources":["../../../observation/batches/runConcurrently.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,qGAAqG;AAErG;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAiB,KAAuB,EAAE,cAAsB,EACjG,QAA0D;IAC1D,MAAM,OAAO,GAAG,IAAI,KAAK,CAAU,KAAK,CAAC,MAAM,CAAC,CAAC;IACjD,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,MAAM,MAAM,GAAG,KAAK,IAAI,EAAE;QACtB,OAAO,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QACzD,CAAC;IACL,CAAC,CAAC;IACF,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACvG,OAAO,OAAO,CAAC;AACnB,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import type { Constructor } from '@cratis/fundamentals';
2
- /** Captures @handles prototype methods during preflight and rejects instance properties hiding them, except bound methods. */
2
+ /** Captures @handles and @observes prototype methods during preflight and rejects instance properties hiding them, except bound methods. */
3
3
  export declare function createHandlerInstanceValidator(type: Constructor, names: Iterable<string>, methods?: Map<string, Function>): (instance: object) => void;
4
4
  //# sourceMappingURL=createHandlerInstanceValidator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createHandlerInstanceValidator.d.ts","sourceRoot":"","sources":["../../observation/createHandlerInstanceValidator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD,8HAA8H;AAC9H,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,wBAA2B,GACzH,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAsB7B"}
1
+ {"version":3,"file":"createHandlerInstanceValidator.d.ts","sourceRoot":"","sources":["../../observation/createHandlerInstanceValidator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,4IAA4I;AAC5I,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,wBAA2B,GACzH,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAqB7B"}