@cratis/chronicle 6.60.0 → 6.62.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 (379) hide show
  1. package/connection/ChronicleConnection.ts +7 -1
  2. package/connection/ChronicleServices.ts +2 -0
  3. package/dist/connection/ChronicleConnection.d.ts +1 -0
  4. package/dist/connection/ChronicleConnection.d.ts.map +1 -1
  5. package/dist/connection/ChronicleConnection.js +6 -2
  6. package/dist/connection/ChronicleConnection.js.map +1 -1
  7. package/dist/connection/ChronicleServices.d.ts +2 -1
  8. package/dist/connection/ChronicleServices.d.ts.map +1 -1
  9. package/dist/eventSequences/EventForEventSourceId.d.ts +21 -1
  10. package/dist/eventSequences/EventForEventSourceId.d.ts.map +1 -1
  11. package/dist/eventSequences/EventSequence.d.ts +9 -0
  12. package/dist/eventSequences/EventSequence.d.ts.map +1 -1
  13. package/dist/eventSequences/EventSequence.js +18 -0
  14. package/dist/eventSequences/EventSequence.js.map +1 -1
  15. package/dist/eventSequences/IEventSequence.d.ts +30 -0
  16. package/dist/eventSequences/IEventSequence.d.ts.map +1 -1
  17. package/dist/imports/EventImport.d.ts +29 -0
  18. package/dist/imports/EventImport.d.ts.map +1 -0
  19. package/dist/imports/EventImport.js +248 -0
  20. package/dist/imports/EventImport.js.map +1 -0
  21. package/dist/imports/EventImportSettings.d.ts +32 -0
  22. package/dist/imports/EventImportSettings.d.ts.map +1 -0
  23. package/dist/imports/EventImportSettings.js +4 -0
  24. package/dist/imports/EventImportSettings.js.map +1 -0
  25. package/dist/imports/IEventImport.d.ts +50 -0
  26. package/dist/imports/IEventImport.d.ts.map +1 -0
  27. package/dist/imports/IEventImport.js +4 -0
  28. package/dist/imports/IEventImport.js.map +1 -0
  29. package/dist/imports/ImportChunkRefused.d.ts +12 -0
  30. package/dist/imports/ImportChunkRefused.d.ts.map +1 -0
  31. package/dist/imports/ImportChunkRefused.js +19 -0
  32. package/dist/imports/ImportChunkRefused.js.map +1 -0
  33. package/dist/imports/ImportCouldNotBegin.d.ts +10 -0
  34. package/dist/imports/ImportCouldNotBegin.d.ts.map +1 -0
  35. package/dist/imports/ImportCouldNotBegin.js +16 -0
  36. package/dist/imports/ImportCouldNotBegin.js.map +1 -0
  37. package/dist/imports/ImportOptions.d.ts +26 -0
  38. package/dist/imports/ImportOptions.d.ts.map +1 -0
  39. package/dist/imports/ImportOptions.js +4 -0
  40. package/dist/imports/ImportOptions.js.map +1 -0
  41. package/dist/imports/ImportProgress.d.ts +20 -0
  42. package/dist/imports/ImportProgress.d.ts.map +1 -0
  43. package/dist/imports/ImportProgress.js +4 -0
  44. package/dist/imports/ImportProgress.js.map +1 -0
  45. package/dist/imports/ImportRejection.d.ts +10 -0
  46. package/dist/imports/ImportRejection.d.ts.map +1 -0
  47. package/dist/imports/ImportRejection.js +4 -0
  48. package/dist/imports/ImportRejection.js.map +1 -0
  49. package/dist/imports/ImportResult.d.ts +30 -0
  50. package/dist/imports/ImportResult.d.ts.map +1 -0
  51. package/dist/imports/ImportResult.js +4 -0
  52. package/dist/imports/ImportResult.js.map +1 -0
  53. package/dist/imports/ImportState.d.ts +18 -0
  54. package/dist/imports/ImportState.d.ts.map +1 -0
  55. package/dist/imports/ImportState.js +21 -0
  56. package/dist/imports/ImportState.js.map +1 -0
  57. package/dist/imports/ImportTarget.d.ts +16 -0
  58. package/dist/imports/ImportTarget.d.ts.map +1 -0
  59. package/dist/imports/ImportTarget.js +4 -0
  60. package/dist/imports/ImportTarget.js.map +1 -0
  61. package/dist/imports/ImportWasAbandoned.d.ts +11 -0
  62. package/dist/imports/ImportWasAbandoned.d.ts.map +1 -0
  63. package/dist/imports/ImportWasAbandoned.js +16 -0
  64. package/dist/imports/ImportWasAbandoned.js.map +1 -0
  65. package/dist/imports/ImportsNotSupported.d.ts +5 -0
  66. package/dist/imports/ImportsNotSupported.d.ts.map +1 -0
  67. package/dist/imports/ImportsNotSupported.js +10 -0
  68. package/dist/imports/ImportsNotSupported.js.map +1 -0
  69. package/dist/imports/OnInvalidEvent.d.ts +8 -0
  70. package/dist/imports/OnInvalidEvent.d.ts.map +1 -0
  71. package/dist/imports/OnInvalidEvent.js +11 -0
  72. package/dist/imports/OnInvalidEvent.js.map +1 -0
  73. package/dist/imports/abortable.d.ts +23 -0
  74. package/dist/imports/abortable.d.ts.map +1 -0
  75. package/dist/imports/abortable.js +60 -0
  76. package/dist/imports/abortable.js.map +1 -0
  77. package/dist/imports/beginEventImport.d.ts +16 -0
  78. package/dist/imports/beginEventImport.d.ts.map +1 -0
  79. package/dist/imports/beginEventImport.js +74 -0
  80. package/dist/imports/beginEventImport.js.map +1 -0
  81. package/dist/imports/for_EventImport/given/a_kernel_import_session.d.ts +144 -0
  82. package/dist/imports/for_EventImport/given/a_kernel_import_session.d.ts.map +1 -0
  83. package/dist/imports/for_EventImport/given/a_kernel_import_session.js +132 -0
  84. package/dist/imports/for_EventImport/given/a_kernel_import_session.js.map +1 -0
  85. package/dist/imports/importEvents.d.ts +13 -0
  86. package/dist/imports/importEvents.d.ts.map +1 -0
  87. package/dist/imports/importEvents.js +35 -0
  88. package/dist/imports/importEvents.js.map +1 -0
  89. package/dist/imports/index.d.ts +12 -0
  90. package/dist/imports/index.d.ts.map +1 -0
  91. package/dist/imports/index.js +9 -0
  92. package/dist/imports/index.js.map +1 -0
  93. package/dist/imports/isTransientImportFailure.d.ts +7 -0
  94. package/dist/imports/isTransientImportFailure.d.ts.map +1 -0
  95. package/dist/imports/isTransientImportFailure.js +13 -0
  96. package/dist/imports/isTransientImportFailure.js.map +1 -0
  97. package/dist/imports/sizeOfImportEvent.d.ts +9 -0
  98. package/dist/imports/sizeOfImportEvent.d.ts.map +1 -0
  99. package/dist/imports/sizeOfImportEvent.js +25 -0
  100. package/dist/imports/sizeOfImportEvent.js.map +1 -0
  101. package/dist/imports/toImportEvent.d.ts +14 -0
  102. package/dist/imports/toImportEvent.d.ts.map +1 -0
  103. package/dist/imports/toImportEvent.js +54 -0
  104. package/dist/imports/toImportEvent.js.map +1 -0
  105. package/dist/imports/toImportProgress.d.ts +9 -0
  106. package/dist/imports/toImportProgress.d.ts.map +1 -0
  107. package/dist/imports/toImportProgress.js +20 -0
  108. package/dist/imports/toImportProgress.js.map +1 -0
  109. package/dist/imports/toImportResult.d.ts +9 -0
  110. package/dist/imports/toImportResult.d.ts.map +1 -0
  111. package/dist/imports/toImportResult.js +33 -0
  112. package/dist/imports/toImportResult.js.map +1 -0
  113. package/dist/index.d.ts +3 -1
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +3 -1
  116. package/dist/index.js.map +1 -1
  117. package/dist/observation/index.d.ts +2 -0
  118. package/dist/observation/index.d.ts.map +1 -1
  119. package/dist/observation/index.js +1 -0
  120. package/dist/observation/index.js.map +1 -1
  121. package/dist/projections/ChildrenOrderingNotSupportedByContracts.d.ts +15 -0
  122. package/dist/projections/ChildrenOrderingNotSupportedByContracts.d.ts.map +1 -0
  123. package/dist/projections/ChildrenOrderingNotSupportedByContracts.js +22 -0
  124. package/dist/projections/ChildrenOrderingNotSupportedByContracts.js.map +1 -0
  125. package/dist/projections/InvalidCausedByProperty.d.ts +10 -0
  126. package/dist/projections/InvalidCausedByProperty.d.ts.map +1 -0
  127. package/dist/projections/InvalidCausedByProperty.js +16 -0
  128. package/dist/projections/InvalidCausedByProperty.js.map +1 -0
  129. package/dist/projections/Projections.d.ts.map +1 -1
  130. package/dist/projections/Projections.js +4 -0
  131. package/dist/projections/Projections.js.map +1 -1
  132. package/dist/projections/causedBy.d.ts +15 -0
  133. package/dist/projections/causedBy.d.ts.map +1 -0
  134. package/dist/projections/causedBy.js +24 -0
  135. package/dist/projections/causedBy.js.map +1 -0
  136. package/dist/projections/childrenOrdering.d.ts +38 -0
  137. package/dist/projections/childrenOrdering.d.ts.map +1 -0
  138. package/dist/projections/childrenOrdering.js +37 -0
  139. package/dist/projections/childrenOrdering.js.map +1 -0
  140. package/dist/projections/childrenOrderingSupport.d.ts +14 -0
  141. package/dist/projections/childrenOrderingSupport.d.ts.map +1 -0
  142. package/dist/projections/childrenOrderingSupport.js +37 -0
  143. package/dist/projections/childrenOrderingSupport.js.map +1 -0
  144. package/dist/projections/declarative/AllSetBuilder.d.ts +3 -0
  145. package/dist/projections/declarative/AllSetBuilder.d.ts.map +1 -1
  146. package/dist/projections/declarative/AllSetBuilder.js +6 -0
  147. package/dist/projections/declarative/AllSetBuilder.js.map +1 -1
  148. package/dist/projections/declarative/ChildrenBuilder.d.ts +9 -0
  149. package/dist/projections/declarative/ChildrenBuilder.d.ts.map +1 -1
  150. package/dist/projections/declarative/ChildrenBuilder.js +29 -1
  151. package/dist/projections/declarative/ChildrenBuilder.js.map +1 -1
  152. package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.d.ts +6 -0
  153. package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.d.ts.map +1 -0
  154. package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.js +11 -0
  155. package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.js.map +1 -0
  156. package/dist/projections/declarative/DictionaryKey.d.ts +48 -0
  157. package/dist/projections/declarative/DictionaryKey.d.ts.map +1 -0
  158. package/dist/projections/declarative/DictionaryKey.js +82 -0
  159. package/dist/projections/declarative/DictionaryKey.js.map +1 -0
  160. package/dist/projections/declarative/FromAllBuilder.d.ts +2 -0
  161. package/dist/projections/declarative/FromAllBuilder.d.ts.map +1 -1
  162. package/dist/projections/declarative/FromAllBuilder.js +5 -0
  163. package/dist/projections/declarative/FromAllBuilder.js.map +1 -1
  164. package/dist/projections/declarative/FromBuilder.d.ts +18 -6
  165. package/dist/projections/declarative/FromBuilder.d.ts.map +1 -1
  166. package/dist/projections/declarative/FromBuilder.js +34 -31
  167. package/dist/projections/declarative/FromBuilder.js.map +1 -1
  168. package/dist/projections/declarative/FromEveryBuilder.d.ts +2 -0
  169. package/dist/projections/declarative/FromEveryBuilder.d.ts.map +1 -1
  170. package/dist/projections/declarative/FromEveryBuilder.js +7 -0
  171. package/dist/projections/declarative/FromEveryBuilder.js.map +1 -1
  172. package/dist/projections/declarative/IAllSetBuilder.d.ts +7 -0
  173. package/dist/projections/declarative/IAllSetBuilder.d.ts.map +1 -1
  174. package/dist/projections/declarative/IChildrenBuilder.d.ts +19 -0
  175. package/dist/projections/declarative/IChildrenBuilder.d.ts.map +1 -1
  176. package/dist/projections/declarative/IFromAllBuilder.d.ts +6 -0
  177. package/dist/projections/declarative/IFromAllBuilder.d.ts.map +1 -1
  178. package/dist/projections/declarative/IFromEveryBuilder.d.ts +6 -0
  179. package/dist/projections/declarative/IFromEveryBuilder.d.ts.map +1 -1
  180. package/dist/projections/declarative/IReadModelPropertiesBuilder.d.ts +37 -6
  181. package/dist/projections/declarative/IReadModelPropertiesBuilder.d.ts.map +1 -1
  182. package/dist/projections/declarative/ISetBuilder.d.ts +7 -0
  183. package/dist/projections/declarative/ISetBuilder.d.ts.map +1 -1
  184. package/dist/projections/declarative/InvalidDictionaryKey.d.ts +10 -0
  185. package/dist/projections/declarative/InvalidDictionaryKey.d.ts.map +1 -0
  186. package/dist/projections/declarative/InvalidDictionaryKey.js +16 -0
  187. package/dist/projections/declarative/InvalidDictionaryKey.js.map +1 -0
  188. package/dist/projections/declarative/JoinBuilder.d.ts +18 -6
  189. package/dist/projections/declarative/JoinBuilder.d.ts.map +1 -1
  190. package/dist/projections/declarative/JoinBuilder.js +34 -31
  191. package/dist/projections/declarative/JoinBuilder.js.map +1 -1
  192. package/dist/projections/declarative/ProjectionBuilderCore.d.ts +2 -0
  193. package/dist/projections/declarative/ProjectionBuilderCore.d.ts.map +1 -1
  194. package/dist/projections/declarative/ProjectionBuilderCore.js.map +1 -1
  195. package/dist/projections/declarative/SetBuilder.d.ts +3 -0
  196. package/dist/projections/declarative/SetBuilder.d.ts.map +1 -1
  197. package/dist/projections/declarative/SetBuilder.js +6 -0
  198. package/dist/projections/declarative/SetBuilder.js.map +1 -1
  199. package/dist/projections/declarative/index.d.ts +4 -0
  200. package/dist/projections/declarative/index.d.ts.map +1 -1
  201. package/dist/projections/declarative/index.js +3 -0
  202. package/dist/projections/declarative/index.js.map +1 -1
  203. package/dist/projections/graphs/GraphDefinitionBuilder.d.ts.map +1 -1
  204. package/dist/projections/graphs/GraphDefinitionBuilder.js +7 -4
  205. package/dist/projections/graphs/GraphDefinitionBuilder.js.map +1 -1
  206. package/dist/projections/graphs/GraphMemberMappings.d.ts +1 -0
  207. package/dist/projections/graphs/GraphMemberMappings.d.ts.map +1 -1
  208. package/dist/projections/graphs/GraphMemberMappings.js +10 -5
  209. package/dist/projections/graphs/GraphMemberMappings.js.map +1 -1
  210. package/dist/projections/graphs/SetOnceNotSupportedInGraph.d.ts +13 -0
  211. package/dist/projections/graphs/SetOnceNotSupportedInGraph.d.ts.map +1 -0
  212. package/dist/projections/graphs/SetOnceNotSupportedInGraph.js +18 -0
  213. package/dist/projections/graphs/SetOnceNotSupportedInGraph.js.map +1 -0
  214. package/dist/projections/graphs/index.d.ts +1 -0
  215. package/dist/projections/graphs/index.d.ts.map +1 -1
  216. package/dist/projections/graphs/index.js +1 -0
  217. package/dist/projections/graphs/index.js.map +1 -1
  218. package/dist/projections/index.d.ts +5 -0
  219. package/dist/projections/index.d.ts.map +1 -1
  220. package/dist/projections/index.js +3 -0
  221. package/dist/projections/index.js.map +1 -1
  222. package/dist/projections/modelBound/ConflictingChildrenOrdering.d.ts +10 -0
  223. package/dist/projections/modelBound/ConflictingChildrenOrdering.d.ts.map +1 -0
  224. package/dist/projections/modelBound/ConflictingChildrenOrdering.js +16 -0
  225. package/dist/projections/modelBound/ConflictingChildrenOrdering.js.map +1 -0
  226. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts +2 -0
  227. package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts.map +1 -1
  228. package/dist/projections/modelBound/childrenAndNestedBuilder.js +9 -5
  229. package/dist/projections/modelBound/childrenAndNestedBuilder.js.map +1 -1
  230. package/dist/projections/modelBound/childrenFrom.d.ts +39 -1
  231. package/dist/projections/modelBound/childrenFrom.d.ts.map +1 -1
  232. package/dist/projections/modelBound/childrenFrom.js +30 -1
  233. package/dist/projections/modelBound/childrenFrom.js.map +1 -1
  234. package/dist/projections/modelBound/index.d.ts +3 -2
  235. package/dist/projections/modelBound/index.d.ts.map +1 -1
  236. package/dist/projections/modelBound/index.js +1 -0
  237. package/dist/projections/modelBound/index.js.map +1 -1
  238. package/dist/projections/modelBound/setFrom.d.ts +26 -0
  239. package/dist/projections/modelBound/setFrom.d.ts.map +1 -1
  240. package/dist/projections/modelBound/setFrom.js +15 -8
  241. package/dist/projections/modelBound/setFrom.js.map +1 -1
  242. package/dist/projections/modelBound/setFromContext.d.ts +23 -1
  243. package/dist/projections/modelBound/setFromContext.d.ts.map +1 -1
  244. package/dist/projections/modelBound/setFromContext.js +20 -2
  245. package/dist/projections/modelBound/setFromContext.js.map +1 -1
  246. package/dist/projections/propertyExpressions.d.ts +9 -0
  247. package/dist/projections/propertyExpressions.d.ts.map +1 -0
  248. package/dist/projections/propertyExpressions.js +13 -0
  249. package/dist/projections/propertyExpressions.js.map +1 -0
  250. package/dist/reducers/Reducers.d.ts.map +1 -1
  251. package/dist/reducers/Reducers.js +2 -1
  252. package/dist/reducers/Reducers.js.map +1 -1
  253. package/dist/testing/BatchPartitionOutcome.d.ts +7 -0
  254. package/dist/testing/BatchPartitionOutcome.d.ts.map +1 -0
  255. package/dist/testing/BatchPartitionOutcome.js +4 -0
  256. package/dist/testing/BatchPartitionOutcome.js.map +1 -0
  257. package/dist/testing/InProcessEventSequence.d.ts +4 -0
  258. package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
  259. package/dist/testing/InProcessEventSequence.js +2 -0
  260. package/dist/testing/InProcessEventSequence.js.map +1 -1
  261. package/dist/testing/ReactorDeliveryResult.d.ts +2 -0
  262. package/dist/testing/ReactorDeliveryResult.d.ts.map +1 -1
  263. package/dist/testing/ReactorScenario.d.ts +46 -10
  264. package/dist/testing/ReactorScenario.d.ts.map +1 -1
  265. package/dist/testing/ReactorScenario.js +120 -29
  266. package/dist/testing/ReactorScenario.js.map +1 -1
  267. package/dist/testing/deliverToBatchMethods.d.ts +35 -0
  268. package/dist/testing/deliverToBatchMethods.d.ts.map +1 -0
  269. package/dist/testing/deliverToBatchMethods.js +55 -0
  270. package/dist/testing/deliverToBatchMethods.js.map +1 -0
  271. package/dist/testing/projections/ProjectionCapabilities.d.ts.map +1 -1
  272. package/dist/testing/projections/ProjectionCapabilities.js +2 -0
  273. package/dist/testing/projections/ProjectionCapabilities.js.map +1 -1
  274. package/dist/testing/projections/ProjectionChildrenCapabilities.d.ts.map +1 -1
  275. package/dist/testing/projections/ProjectionChildrenCapabilities.js +2 -0
  276. package/dist/testing/projections/ProjectionChildrenCapabilities.js.map +1 -1
  277. package/dist/tsconfig.tsbuildinfo +1 -1
  278. package/eventSequences/EventForEventSourceId.ts +25 -1
  279. package/eventSequences/EventSequence.ts +28 -0
  280. package/eventSequences/IEventSequence.ts +33 -0
  281. package/imports/EventImport.ts +263 -0
  282. package/imports/EventImportSettings.ts +46 -0
  283. package/imports/IEventImport.ts +58 -0
  284. package/imports/ImportChunkRefused.ts +15 -0
  285. package/imports/ImportCouldNotBegin.ts +14 -0
  286. package/imports/ImportOptions.ts +36 -0
  287. package/imports/ImportProgress.ts +29 -0
  288. package/imports/ImportRejection.ts +14 -0
  289. package/imports/ImportResult.ts +43 -0
  290. package/imports/ImportState.ts +26 -0
  291. package/imports/ImportTarget.ts +23 -0
  292. package/imports/ImportWasAbandoned.ts +16 -0
  293. package/imports/ImportsNotSupported.ts +10 -0
  294. package/imports/OnInvalidEvent.ts +11 -0
  295. package/imports/abortable.ts +57 -0
  296. package/imports/beginEventImport.ts +85 -0
  297. package/imports/for_EventImport/given/a_kernel_import_session.ts +160 -0
  298. package/imports/for_EventImport/when_a_chunk_fails.spec.ts +65 -0
  299. package/imports/for_EventImport/when_abandoning.spec.ts +52 -0
  300. package/imports/for_EventImport/when_cancelling_with_an_abort_signal.spec.ts +59 -0
  301. package/imports/for_EventImport/when_completing.spec.ts +71 -0
  302. package/imports/for_EventImport/when_cutting_events_into_chunks.spec.ts +70 -0
  303. package/imports/for_EventImport/when_keeping_chunks_in_flight.spec.ts +49 -0
  304. package/imports/for_beginEventImport/when_reattaching.spec.ts +82 -0
  305. package/imports/for_beginEventImport/when_the_kernel_does_not_serve_imports.spec.ts +55 -0
  306. package/imports/for_importEvents/when_importing_in_one_call.spec.ts +99 -0
  307. package/imports/for_toImportEvent/when_converting_an_event.spec.ts +74 -0
  308. package/imports/importEvents.ts +44 -0
  309. package/imports/index.ts +14 -0
  310. package/imports/isTransientImportFailure.ts +15 -0
  311. package/imports/sizeOfImportEvent.ts +25 -0
  312. package/imports/toImportEvent.ts +60 -0
  313. package/imports/toImportProgress.ts +24 -0
  314. package/imports/toImportResult.ts +36 -0
  315. package/index.ts +3 -0
  316. package/observation/index.ts +2 -0
  317. package/package.json +7 -2
  318. package/projections/ChildrenOrderingNotSupportedByContracts.ts +18 -0
  319. package/projections/InvalidCausedByProperty.ts +14 -0
  320. package/projections/Projections.ts +4 -0
  321. package/projections/causedBy.ts +30 -0
  322. package/projections/childrenOrdering.ts +53 -0
  323. package/projections/childrenOrderingSupport.ts +40 -0
  324. package/projections/declarative/AllSetBuilder.ts +7 -0
  325. package/projections/declarative/ChildrenBuilder.ts +34 -1
  326. package/projections/declarative/ChildrenOrderingAlreadyDefined.ts +11 -0
  327. package/projections/declarative/DictionaryKey.ts +88 -0
  328. package/projections/declarative/FromAllBuilder.ts +10 -0
  329. package/projections/declarative/FromBuilder.ts +42 -32
  330. package/projections/declarative/FromEveryBuilder.ts +12 -0
  331. package/projections/declarative/IAllSetBuilder.ts +8 -0
  332. package/projections/declarative/IChildrenBuilder.ts +22 -0
  333. package/projections/declarative/IFromAllBuilder.ts +7 -0
  334. package/projections/declarative/IFromEveryBuilder.ts +7 -0
  335. package/projections/declarative/IReadModelPropertiesBuilder.ts +39 -6
  336. package/projections/declarative/ISetBuilder.ts +8 -0
  337. package/projections/declarative/InvalidDictionaryKey.ts +14 -0
  338. package/projections/declarative/JoinBuilder.ts +41 -32
  339. package/projections/declarative/ProjectionBuilderCore.ts +2 -0
  340. package/projections/declarative/SetBuilder.ts +7 -0
  341. package/projections/declarative/for_ChildrenBuilder/when_ordering_children.spec.ts +52 -0
  342. package/projections/declarative/for_FromAllBuilder/when_setting_once.spec.ts +29 -0
  343. package/projections/declarative/for_FromBuilder/when_setting_once.spec.ts +39 -0
  344. package/projections/declarative/for_FromBuilder/when_targeting_dictionary_entries.spec.ts +99 -0
  345. package/projections/declarative/for_JoinBuilder/when_setting_once_and_targeting_dictionary_entries.spec.ts +36 -0
  346. package/projections/declarative/for_SetBuilder/when_setting_to_the_causing_identity.spec.ts +37 -0
  347. package/projections/declarative/index.ts +4 -0
  348. package/projections/for_Graphs/when_building_a_fluent_graph.spec.ts +1 -1
  349. package/projections/for_Graphs/when_building_a_model_bound_graph.spec.ts +5 -4
  350. package/projections/for_Graphs/when_declaring_an_invalid_graph.spec.ts +28 -0
  351. package/projections/for_Graphs/when_declaring_with_standard_decorators.standard.spec.ts +4 -4
  352. package/projections/for_Graphs/when_mapping_properties.spec.ts +1 -1
  353. package/projections/for_Projections/when_registering_ordered_children.spec.ts +66 -0
  354. package/projections/for_childrenOrderingSupport/when_detecting_support_in_the_pinned_contracts.spec.ts +22 -0
  355. package/projections/for_childrenOrderingSupport/when_ensuring_children_ordering_is_supported.spec.ts +35 -0
  356. package/projections/graphs/GraphDefinitionBuilder.ts +7 -4
  357. package/projections/graphs/GraphMemberMappings.ts +8 -5
  358. package/projections/graphs/SetOnceNotSupportedInGraph.ts +18 -0
  359. package/projections/graphs/index.ts +1 -0
  360. package/projections/index.ts +5 -0
  361. package/projections/modelBound/ConflictingChildrenOrdering.ts +14 -0
  362. package/projections/modelBound/childrenAndNestedBuilder.ts +11 -5
  363. package/projections/modelBound/childrenFrom.ts +62 -2
  364. package/projections/modelBound/for_childrenFrom/when_ordering_children.spec.ts +91 -0
  365. package/projections/modelBound/for_setFrom/when_setting_once.spec.ts +52 -0
  366. package/projections/modelBound/index.ts +3 -2
  367. package/projections/modelBound/setFrom.ts +37 -2
  368. package/projections/modelBound/setFromContext.ts +38 -3
  369. package/projections/propertyExpressions.ts +14 -0
  370. package/reducers/Reducers.ts +2 -1
  371. package/testing/BatchPartitionOutcome.ts +10 -0
  372. package/testing/InProcessEventSequence.ts +4 -0
  373. package/testing/ReactorDeliveryResult.ts +2 -0
  374. package/testing/ReactorScenario.ts +147 -39
  375. package/testing/deliverToBatchMethods.ts +90 -0
  376. package/testing/for_ReactorScenario/when_the_reactor_has_a_batch_method.spec.ts +143 -9
  377. package/testing/projections/ProjectionCapabilities.ts +1 -0
  378. package/testing/projections/ProjectionChildrenCapabilities.ts +1 -0
  379. package/testing/projections/for_ProjectionCapabilities/when_rejecting_set_once_dictionary_entries_and_ordered_children.spec.ts +52 -0
@@ -0,0 +1,18 @@
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
+ * Error thrown when a projection orders its children but the installed `@cratis/chronicle.contracts` package cannot carry
6
+ * the ordering to the kernel. Registering anyway would silently append every child.
7
+ */
8
+ export class ChildrenOrderingNotSupportedByContracts extends Error {
9
+ /**
10
+ * Creates the error.
11
+ * @param projection - The projection identifier.
12
+ * @param path - The contract path of the ordered children collection.
13
+ */
14
+ constructor(readonly projection: string, readonly path: string) {
15
+ super(`Projection '${projection}' orders the children at '${path}', but the installed @cratis/chronicle.contracts package does not support children ordering. Upgrade @cratis/chronicle.contracts to a version that includes ChildrenOrderingDefinition, or remove the ordering.`);
16
+ this.name = 'ChildrenOrderingNotSupportedByContracts';
17
+ }
18
+ }
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /** Error thrown when a projection refers to a member of the causing identity that the kernel does not resolve. */
5
+ export class InvalidCausedByProperty extends Error {
6
+ /**
7
+ * Creates an error for an unsupported causing-identity member.
8
+ * @param property - The member supplied by the projection.
9
+ */
10
+ constructor(readonly property: string) {
11
+ super(`Invalid caused by property '${property}'. Use 'subject', 'name' or 'userName'.`);
12
+ this.name = 'InvalidCausedByProperty';
13
+ }
14
+ }
@@ -24,6 +24,7 @@ import { ProjectionId } from './ProjectionId.js';
24
24
  import { ProjectionQueryResult } from './ProjectionQueryResult.js';
25
25
  import { ProjectionState } from './ProjectionState.js';
26
26
  import { ProjectionDefinitionCompiler } from './ProjectionDefinitionCompiler.js';
27
+ import { ensureChildrenOrderingIsSupported } from './childrenOrderingSupport.js';
27
28
  import { registerProjectionWithRetry } from './registerProjectionWithRetry.js';
28
29
  import type { ResolvedModelBoundMetadata } from './ResolvedModelBoundMetadata.js';
29
30
  import { UnableToQueryProjection } from './UnableToQueryProjection.js';
@@ -112,6 +113,9 @@ export class Projections implements IProjections {
112
113
  const compiled = new ProjectionDefinitionCompiler(this._clientArtifacts, this._defaultSinkTypeId, this._readModelNamingPolicy)
113
114
  .compile(this._declarative.values(), this._modelBound.values());
114
115
  const projections = compiled.definitions;
116
+ for (const projection of projections) {
117
+ ensureChildrenOrderingIsSupported(projection);
118
+ }
115
119
 
116
120
  if (projections.length === 0) {
117
121
  this._logger.info('No projections to register');
@@ -0,0 +1,30 @@
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 { InvalidCausedByProperty } from './InvalidCausedByProperty.js';
5
+
6
+ /** The identity members of the identity that caused an event, as the kernel's `$causedBy` expression accepts them. */
7
+ export type CausedByProperty = 'subject' | 'name' | 'userName';
8
+
9
+ const causedByProperties: readonly string[] = ['subject', 'name', 'userName'];
10
+
11
+ /**
12
+ * Validates a member of the identity that caused an event. The kernel matches the member case-sensitively.
13
+ * @param property - The identity member.
14
+ * @returns The validated member.
15
+ */
16
+ export function causedByProperty(property: string): CausedByProperty {
17
+ if (!causedByProperties.includes(property)) {
18
+ throw new InvalidCausedByProperty(property);
19
+ }
20
+ return property as CausedByProperty;
21
+ }
22
+
23
+ /**
24
+ * Builds the `$causedBy` event value expression - the whole identity that caused the event, or one of its members.
25
+ * @param property - Optional identity member; omit it for the whole identity.
26
+ * @returns The `$causedBy` or `$causedBy(<member>)` expression.
27
+ */
28
+ export function causedByExpression(property?: CausedByProperty): string {
29
+ return property === undefined ? '$causedBy' : `$causedBy(${causedByProperty(property)})`;
30
+ }
@@ -0,0 +1,53 @@
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
+ /** Where a new child goes in its collection. Mirrors the `ChildrenPlacement` contract enum. */
5
+ export enum ChildrenPlacement {
6
+ /** New children are added at the end of the collection (the default). */
7
+ Append = 0,
8
+
9
+ /** New children are added at the start of the collection. */
10
+ Prepend = 1,
11
+
12
+ /** New children are inserted at their sorted position. */
13
+ Sorted = 2
14
+ }
15
+
16
+ /** The direction children are sorted in. Mirrors the `SortDirection` contract enum. */
17
+ export enum SortDirection {
18
+ /** Smallest first; children without a value sort first. */
19
+ Ascending = 0,
20
+
21
+ /** Largest first; children without a value sort last. */
22
+ Descending = 1
23
+ }
24
+
25
+ /** Plain object shape matching the wire-level `ChildrenOrderingDefinition`. */
26
+ export interface ChildrenOrderingDefinitionLike {
27
+ /** Where new children go. */
28
+ Placement: ChildrenPlacement;
29
+
30
+ /** The property path on the child to sort by; empty unless {@link ChildrenPlacement.Sorted}. */
31
+ SortBy: string;
32
+
33
+ /** The sort direction; only meaningful for {@link ChildrenPlacement.Sorted}. */
34
+ Direction: SortDirection;
35
+ }
36
+
37
+ /**
38
+ * Creates the ordering that adds new children at the start of the collection.
39
+ * @returns The ordering definition.
40
+ */
41
+ export function prependOrdering(): ChildrenOrderingDefinitionLike {
42
+ return { Placement: ChildrenPlacement.Prepend, SortBy: '', Direction: SortDirection.Ascending };
43
+ }
44
+
45
+ /**
46
+ * Creates the ordering that inserts new children at their sorted position.
47
+ * @param sortBy - The property path on the child to sort by.
48
+ * @param direction - The sort direction.
49
+ * @returns The ordering definition.
50
+ */
51
+ export function sortedOrdering(sortBy: string, direction: SortDirection): ChildrenOrderingDefinitionLike {
52
+ return { Placement: ChildrenPlacement.Sorted, SortBy: sortBy, Direction: direction };
53
+ }
@@ -0,0 +1,40 @@
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 { ChildrenDefinition, type ProjectionDefinition } from '@cratis/chronicle.contracts';
5
+ import { ChildrenOrderingNotSupportedByContracts } from './ChildrenOrderingNotSupportedByContracts.js';
6
+
7
+ type ChildrenLike = { Children?: Record<string, ChildrenLike>; Nested?: Record<string, ChildrenLike>; Ordering?: unknown };
8
+
9
+ /**
10
+ * Detects whether the installed contracts carry `ChildrenDefinition.Ordering` to the kernel. The generated codec drops
11
+ * fields it does not know, so an ordering the contracts cannot encode would be lost on the wire.
12
+ * @returns True when the contracts encode children ordering.
13
+ */
14
+ export function contractsSupportChildrenOrdering(): boolean {
15
+ const probe = ChildrenDefinition.fromPartial({ Ordering: { Placement: 1, SortBy: '', Direction: 0 } } as Parameters<typeof ChildrenDefinition.fromPartial>[0]);
16
+ return (probe as { Ordering?: unknown }).Ordering !== undefined;
17
+ }
18
+
19
+ /**
20
+ * Throws when a projection orders any of its children collections, at any depth, and the contracts cannot carry it.
21
+ * @param definition - The compiled projection definition.
22
+ * @param supported - Whether the contracts support children ordering. Defaults to detecting it.
23
+ */
24
+ export function ensureChildrenOrderingIsSupported(definition: ProjectionDefinition, supported: boolean = contractsSupportChildrenOrdering()): void {
25
+ if (supported) return;
26
+ const projection = String(definition.Identifier ?? '<unknown>');
27
+ const visit = (owner: ChildrenLike, path: string): void => {
28
+ for (const [property, child] of Object.entries(owner.Children ?? {})) {
29
+ const childPath = `${path}Children.${property}`;
30
+ if (child.Ordering !== undefined) {
31
+ throw new ChildrenOrderingNotSupportedByContracts(projection, childPath);
32
+ }
33
+ visit(child, `${childPath}.`);
34
+ }
35
+ for (const [property, nested] of Object.entries(owner.Nested ?? {})) {
36
+ visit(nested, `${path}Nested.${property}.`);
37
+ }
38
+ };
39
+ visit(definition as unknown as ChildrenLike, '');
40
+ }
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
5
  import { IAllSetBuilder } from './IAllSetBuilder.js';
6
+ import { CausedByProperty, causedByExpression } from '../causedBy.js';
6
7
  import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
7
8
 
8
9
  /**
@@ -37,4 +38,10 @@ export class AllSetBuilder<TReadModel, TParentBuilder> implements IAllSetBuilder
37
38
  this._setProperty(this._targetProperty, '$eventSourceId');
38
39
  return this._parent;
39
40
  }
41
+
42
+ /** @inheritdoc */
43
+ toCausedBy(property?: CausedByProperty): TParentBuilder {
44
+ this._setProperty(this._targetProperty, causedByExpression(property));
45
+ return this._parent;
46
+ }
40
47
  }
@@ -2,6 +2,8 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
+ import { ChildrenOrderingDefinitionLike, prependOrdering, SortDirection, sortedOrdering } from '../childrenOrdering.js';
6
+ import { ChildrenOrderingAlreadyDefined } from './ChildrenOrderingAlreadyDefined.js';
5
7
  import { ChildrenDefinitionLike, ProjectionBuilderCore } from './ProjectionBuilderCore.js';
6
8
  import { IChildrenBuilder } from './IChildrenBuilder.js';
7
9
  import { INestedBuilder } from './INestedBuilder.js';
@@ -18,6 +20,7 @@ export class ChildrenBuilder<TParentReadModel, TChildReadModel>
18
20
  implements IChildrenBuilder<TParentReadModel, TChildReadModel> {
19
21
  private _identifiedBy: string | undefined;
20
22
  private _fromEventPropertyPath: string | undefined;
23
+ private _ordering: ChildrenOrderingDefinitionLike | undefined;
21
24
 
22
25
  /** @inheritdoc */
23
26
  identifiedBy(propertyAccessor: PropertyAccessor<TChildReadModel>): IChildrenBuilder<TParentReadModel, TChildReadModel> {
@@ -67,6 +70,21 @@ export class ChildrenBuilder<TParentReadModel, TChildReadModel>
67
70
  return this;
68
71
  }
69
72
 
73
+ /** @inheritdoc */
74
+ prepend(): IChildrenBuilder<TParentReadModel, TChildReadModel> {
75
+ return this.withOrdering(prependOrdering());
76
+ }
77
+
78
+ /** @inheritdoc */
79
+ orderBy(propertyAccessor: PropertyAccessor<TChildReadModel>): IChildrenBuilder<TParentReadModel, TChildReadModel> {
80
+ return this.withOrdering(sortedOrdering(this.childPropertyPath(propertyAccessor), SortDirection.Ascending));
81
+ }
82
+
83
+ /** @inheritdoc */
84
+ orderByDescending(propertyAccessor: PropertyAccessor<TChildReadModel>): IChildrenBuilder<TParentReadModel, TChildReadModel> {
85
+ return this.withOrdering(sortedOrdering(this.childPropertyPath(propertyAccessor), SortDirection.Descending));
86
+ }
87
+
70
88
  /** @inheritdoc */
71
89
  protected defaultJoinOn(): string | undefined {
72
90
  return this._identifiedBy;
@@ -90,7 +108,22 @@ export class ChildrenBuilder<TParentReadModel, TChildReadModel>
90
108
  RemovedWith: this._removedWith,
91
109
  RemovedWithJoin: this._removedWithJoin,
92
110
  AutoMap: this._autoMap,
93
- Nested: this._nested
111
+ Nested: this._nested,
112
+ ...(this._ordering === undefined ? {} : { Ordering: this._ordering })
94
113
  };
95
114
  }
115
+
116
+ private withOrdering(ordering: ChildrenOrderingDefinitionLike): this {
117
+ if (this._ordering !== undefined) {
118
+ throw new ChildrenOrderingAlreadyDefined();
119
+ }
120
+ this._ordering = ordering;
121
+ return this;
122
+ }
123
+
124
+ private childPropertyPath(propertyAccessor: PropertyAccessor<TChildReadModel>): string {
125
+ const handler = new PropertyPathResolverProxyHandler();
126
+ propertyAccessor(new Proxy({}, handler) as TChildReadModel);
127
+ return handler.path;
128
+ }
96
129
  }
@@ -0,0 +1,11 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /** Error thrown when a children collection is given more than one ordering. */
5
+ export class ChildrenOrderingAlreadyDefined extends Error {
6
+ /** Creates the error. */
7
+ constructor() {
8
+ super('The children collection already has an ordering. Use only one of prepend(), orderBy() or orderByDescending().');
9
+ this.name = 'ChildrenOrderingAlreadyDefined';
10
+ }
11
+ }
@@ -0,0 +1,88 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
+ import type { EventContext } from '../../events/EventContext.js';
6
+ import { CausedByProperty, causedByProperty } from '../causedBy.js';
7
+ import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
8
+ import { InvalidEventContextPropertyError } from '../InvalidEventContextPropertyError.js';
9
+ import { InvalidDictionaryKey } from './InvalidDictionaryKey.js';
10
+
11
+ /**
12
+ * Where the key of a dictionary entry comes from when a projection maps into a dictionary-typed read model property.
13
+ * Pass a plain accessor on the event for the common case; use the factory methods for keys from the event content,
14
+ * the event context or the identity that caused the event.
15
+ */
16
+ export class DictionaryKey {
17
+ private constructor(readonly expression: string) {}
18
+
19
+ /**
20
+ * The key is read from a property of the event content. Nested paths are supported; the kernel requires the
21
+ * property to exist on the event (case-sensitively) and an event without a value for it leaves the dictionary as it is.
22
+ * @param eventPropertyAccessor - Accessor for the event property holding the key.
23
+ * @returns The dictionary key.
24
+ */
25
+ static fromEventContent<TEvent>(eventPropertyAccessor: PropertyAccessor<TEvent>): DictionaryKey {
26
+ const handler = new PropertyPathResolverProxyHandler();
27
+ eventPropertyAccessor(new Proxy({}, handler) as TEvent);
28
+ const path = handler.path;
29
+ if (!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(path) || path.split('.').some(segment => segment.startsWith('$'))) {
30
+ throw new InvalidDictionaryKey(path);
31
+ }
32
+ return new DictionaryKey(`$eventContent.${path}`);
33
+ }
34
+
35
+ /**
36
+ * The key is read from the event context, for instance `eventSourceId` or `causedBy.subject`.
37
+ * @param contextProperty - The event context property name, or an accessor on the {@link EventContext}.
38
+ * @returns The dictionary key.
39
+ */
40
+ static fromEventContext(contextProperty: string | PropertyAccessor<EventContext>): DictionaryKey {
41
+ let path: string;
42
+ if (typeof contextProperty === 'function') {
43
+ const handler = new PropertyPathResolverProxyHandler();
44
+ contextProperty(new Proxy({}, handler) as EventContext);
45
+ path = handler.path;
46
+ } else {
47
+ path = contextProperty;
48
+ }
49
+ if (path.endsWith('()')) {
50
+ throw new InvalidEventContextPropertyError(path);
51
+ }
52
+ eventContextPropertyExpression(path);
53
+ const camelCased = path.split('.').map(segment => segment.charAt(0).toLowerCase() + segment.slice(1)).join('.');
54
+ return new DictionaryKey(`$eventContext.${camelCased}`);
55
+ }
56
+
57
+ /**
58
+ * The key is a member of the identity that caused the event.
59
+ * @param property - The identity member: `subject`, `name` or `userName`.
60
+ * @returns The dictionary key.
61
+ */
62
+ static causedBy(property: CausedByProperty): DictionaryKey {
63
+ return new DictionaryKey(`$causedBy.${causedByProperty(property)}`);
64
+ }
65
+ }
66
+
67
+ /** A dictionary key: an accessor on the event (the key is read from the event content) or a {@link DictionaryKey}. */
68
+ export type DictionaryKeySource<TEvent> = PropertyAccessor<TEvent> | DictionaryKey;
69
+
70
+ /**
71
+ * Resolves a dictionary key source to its {@link DictionaryKey}.
72
+ * @param key - The key source.
73
+ * @returns The dictionary key.
74
+ */
75
+ export function toDictionaryKey<TEvent>(key: DictionaryKeySource<TEvent>): DictionaryKey {
76
+ return key instanceof DictionaryKey ? key : DictionaryKey.fromEventContent(key);
77
+ }
78
+
79
+ /**
80
+ * Builds the target property path of a dictionary entry: `<dictionary>.<key expression>`, for example
81
+ * `slots.$eventContent.category`.
82
+ * @param dictionaryProperty - The dictionary-typed read model property.
83
+ * @param key - Where the key of the entry comes from.
84
+ * @returns The dynamic property path the kernel resolves per event.
85
+ */
86
+ export function dictionaryEntryPath<TEvent>(dictionaryProperty: string, key: DictionaryKeySource<TEvent>): string {
87
+ return `${dictionaryProperty}.${toDictionaryKey(key).expression}`;
88
+ }
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
+ import { setOnceExpression } from '../propertyExpressions.js';
5
6
  import { AllSetBuilder } from './AllSetBuilder.js';
6
7
  import type { IAllSetBuilder } from './IAllSetBuilder.js';
7
8
  import type { IFromAllBuilder } from './IFromAllBuilder.js';
@@ -19,6 +20,15 @@ export class FromAllBuilder<TReadModel> implements IFromAllBuilder<TReadModel> {
19
20
  );
20
21
  }
21
22
 
23
+ /** @inheritdoc */
24
+ setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>> {
25
+ return new AllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>>(
26
+ this.targetProperty(readModelPropertyAccessor),
27
+ (property, expression) => { this.properties[property] = setOnceExpression(expression); },
28
+ this
29
+ );
30
+ }
31
+
22
32
  /** @inheritdoc */
23
33
  count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, contextPropertyName?: string): IFromAllBuilder<TReadModel> {
24
34
  return this.operation(readModelPropertyAccessor, '$count', contextPropertyName);
@@ -4,9 +4,11 @@
4
4
  import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
5
  import { constantValueExpression } from '../constantValueExpression.js';
6
6
  import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
7
+ import { removeExpression, setOnceExpression } from '../propertyExpressions.js';
7
8
  import { AddBuilder } from './AddBuilder.js';
8
9
  import { AddChildBuilder, ChildAdditionEntry } from './AddChildBuilder.js';
9
10
  import { CompositeKeyBuilder } from './CompositeKeyBuilder.js';
11
+ import { DictionaryKeySource, dictionaryEntryPath } from './DictionaryKey.js';
10
12
  import { IAddBuilder } from './IAddBuilder.js';
11
13
  import { IAddChildBuilder } from './IAddChildBuilder.js';
12
14
  import { ICompositeKeyBuilder } from './ICompositeKeyBuilder.js';
@@ -41,18 +43,29 @@ export class FromBuilder<TReadModel, TEvent> implements IFromBuilder<TReadModel,
41
43
  };
42
44
 
43
45
  /** @inheritdoc */
44
- set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>> {
45
- const handler = new PropertyPathResolverProxyHandler();
46
- const proxy = new Proxy({}, handler);
47
- readModelPropertyAccessor(proxy as TReadModel);
48
- const rmProp = handler.property;
46
+ set(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>> {
49
47
  return new SetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>>(
50
- rmProp,
51
- (rp, expr) => { this.entry.properties[rp] = expr; },
48
+ this.targetOf(readModelPropertyAccessor, key),
49
+ (property, expression) => { this.entry.properties[property] = expression; },
50
+ this
51
+ );
52
+ }
53
+
54
+ /** @inheritdoc */
55
+ setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>> {
56
+ return new SetBuilder<TEvent, IFromBuilder<TReadModel, TEvent>>(
57
+ this.targetOf(readModelPropertyAccessor, key),
58
+ (property, expression) => { this.entry.properties[property] = setOnceExpression(expression); },
52
59
  this
53
60
  );
54
61
  }
55
62
 
63
+ /** @inheritdoc */
64
+ removeKey(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key: DictionaryKeySource<TEvent>): this {
65
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = removeExpression;
66
+ return this;
67
+ }
68
+
56
69
  /** @inheritdoc */
57
70
  usingKey(keyAccessor: PropertyAccessor<TEvent>): this {
58
71
  const handler = new PropertyPathResolverProxyHandler();
@@ -120,53 +133,38 @@ export class FromBuilder<TReadModel, TEvent> implements IFromBuilder<TReadModel,
120
133
  }
121
134
 
122
135
  /** @inheritdoc */
123
- increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
124
- const handler = new PropertyPathResolverProxyHandler();
125
- const proxy = new Proxy({}, handler);
126
- readModelPropertyAccessor(proxy as TReadModel);
127
- this.entry.properties[handler.property] = '$increment';
136
+ increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
137
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$increment';
128
138
  return this;
129
139
  }
130
140
 
131
141
  /** @inheritdoc */
132
- decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
133
- const handler = new PropertyPathResolverProxyHandler();
134
- const proxy = new Proxy({}, handler);
135
- readModelPropertyAccessor(proxy as TReadModel);
136
- this.entry.properties[handler.property] = '$decrement';
142
+ decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
143
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$decrement';
137
144
  return this;
138
145
  }
139
146
 
140
147
  /** @inheritdoc */
141
- add(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAddBuilder<TEvent, this> {
142
- const handler = new PropertyPathResolverProxyHandler();
143
- const proxy = new Proxy({}, handler);
144
- readModelPropertyAccessor(proxy as TReadModel);
148
+ add(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): IAddBuilder<TEvent, this> {
145
149
  return new AddBuilder<TEvent, this>(
146
- handler.property,
150
+ this.targetOf(readModelPropertyAccessor, key),
147
151
  (property, expression) => { this.entry.properties[property] = expression; },
148
152
  this
149
153
  );
150
154
  }
151
155
 
152
156
  /** @inheritdoc */
153
- subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISubtractBuilder<TEvent, this> {
154
- const handler = new PropertyPathResolverProxyHandler();
155
- const proxy = new Proxy({}, handler);
156
- readModelPropertyAccessor(proxy as TReadModel);
157
+ subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISubtractBuilder<TEvent, this> {
157
158
  return new SubtractBuilder<TEvent, this>(
158
- handler.property,
159
+ this.targetOf(readModelPropertyAccessor, key),
159
160
  (property, expression) => { this.entry.properties[property] = expression; },
160
161
  this
161
162
  );
162
163
  }
163
164
 
164
165
  /** @inheritdoc */
165
- count(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
166
- const handler = new PropertyPathResolverProxyHandler();
167
- const proxy = new Proxy({}, handler);
168
- readModelPropertyAccessor(proxy as TReadModel);
169
- this.entry.properties[handler.property] = '$count';
166
+ count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
167
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$count';
170
168
  return this;
171
169
  }
172
170
 
@@ -205,4 +203,16 @@ export class FromBuilder<TReadModel, TEvent> implements IFromBuilder<TReadModel,
205
203
  this
206
204
  );
207
205
  }
206
+
207
+ /**
208
+ * Resolves the target property path: the property itself, or the entry of a dictionary-typed property.
209
+ * @param readModelPropertyAccessor - Accessor for the read model property.
210
+ * @param key - Optional dictionary key.
211
+ * @returns The target property path.
212
+ */
213
+ private targetOf(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): string {
214
+ const handler = new PropertyPathResolverProxyHandler();
215
+ readModelPropertyAccessor(new Proxy({}, handler) as TReadModel);
216
+ return key === undefined ? handler.property : dictionaryEntryPath(handler.property, key);
217
+ }
208
218
  }
@@ -4,6 +4,7 @@
4
4
  import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
5
  import { IAllSetBuilder } from './IAllSetBuilder.js';
6
6
  import { IFromEveryBuilder } from './IFromEveryBuilder.js';
7
+ import { setOnceExpression } from '../propertyExpressions.js';
7
8
  import { AllSetBuilder } from './AllSetBuilder.js';
8
9
 
9
10
  /**
@@ -38,6 +39,17 @@ export class FromEveryBuilder<TReadModel> implements IFromEveryBuilder<TReadMode
38
39
  );
39
40
  }
40
41
 
42
+ /** @inheritdoc */
43
+ setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>> {
44
+ const handler = new PropertyPathResolverProxyHandler();
45
+ readModelPropertyAccessor(new Proxy({}, handler) as TReadModel);
46
+ return new AllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>>(
47
+ handler.property,
48
+ (targetProperty, expression) => { this.entry.properties[targetProperty] = setOnceExpression(expression); },
49
+ this
50
+ );
51
+ }
52
+
41
53
  /** @inheritdoc */
42
54
  count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, contextPropertyName: string): IFromEveryBuilder<TReadModel> {
43
55
  const handler = new PropertyPathResolverProxyHandler();
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import { PropertyAccessor } from '@cratis/fundamentals';
5
+ import type { CausedByProperty } from '../causedBy.js';
5
6
 
6
7
  /**
7
8
  * Defines a builder for set operations that apply to all events (fromEvery).
@@ -28,4 +29,11 @@ export interface IAllSetBuilder<TReadModel, TParentBuilder> {
28
29
  * @returns The parent builder for fluent chaining.
29
30
  */
30
31
  toEventSourceId(): TParentBuilder;
32
+
33
+ /**
34
+ * Maps the read model property from the identity that caused the event, or one of its members.
35
+ * @param property - Optional identity member: `subject`, `name` or `userName`. Omit it for the whole identity.
36
+ * @returns The parent builder for fluent chaining.
37
+ */
38
+ toCausedBy(property?: CausedByProperty): TParentBuilder;
31
39
  }
@@ -28,4 +28,26 @@ export interface IChildrenBuilder<TParentReadModel, TChildReadModel>
28
28
  fromEventProperty<TEvent>(
29
29
  propertyAccessor: PropertyAccessor<TEvent>
30
30
  ): IChildrenBuilder<TParentReadModel, TChildReadModel>;
31
+
32
+ /**
33
+ * Adds new children at the start of the collection instead of the end. Updating an existing child never moves it.
34
+ * @returns This builder for fluent chaining.
35
+ */
36
+ prepend(): IChildrenBuilder<TParentReadModel, TChildReadModel>;
37
+
38
+ /**
39
+ * Inserts new children at their position when sorted ascending by a child property. Children without a value sort
40
+ * first and updating an existing child never moves it, even when the property changes.
41
+ * @param propertyAccessor - Accessor for the child property to sort by.
42
+ * @returns This builder for fluent chaining.
43
+ */
44
+ orderBy(propertyAccessor: PropertyAccessor<TChildReadModel>): IChildrenBuilder<TParentReadModel, TChildReadModel>;
45
+
46
+ /**
47
+ * Inserts new children at their position when sorted descending by a child property. Children without a value sort
48
+ * last and updating an existing child never moves it, even when the property changes.
49
+ * @param propertyAccessor - Accessor for the child property to sort by.
50
+ * @returns This builder for fluent chaining.
51
+ */
52
+ orderByDescending(propertyAccessor: PropertyAccessor<TChildReadModel>): IChildrenBuilder<TParentReadModel, TChildReadModel>;
31
53
  }
@@ -13,6 +13,13 @@ export interface IFromAllBuilder<TReadModel> {
13
13
  */
14
14
  set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>>;
15
15
 
16
+ /**
17
+ * Starts an assignment that only sets the read-model property while it has no value yet; later events leave it as it is.
18
+ * @param readModelPropertyAccessor - Target property accessor.
19
+ * @returns The assignment builder, continuing with this builder.
20
+ */
21
+ setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromAllBuilder<TReadModel>>;
22
+
16
23
  /**
17
24
  * Counts every event, optionally under a dynamic dictionary key.
18
25
  * @param readModelPropertyAccessor - Scalar or dictionary target accessor.
@@ -16,6 +16,13 @@ export interface IFromEveryBuilder<TReadModel> {
16
16
  */
17
17
  set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>>;
18
18
 
19
+ /**
20
+ * Starts an assignment that only sets the read-model property while it has no value yet; later events leave it as it is.
21
+ * @param readModelPropertyAccessor - Target property accessor.
22
+ * @returns The assignment builder, continuing with this builder.
23
+ */
24
+ setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAllSetBuilder<TReadModel, IFromEveryBuilder<TReadModel>>;
25
+
19
26
  /**
20
27
  * Counts every projected event into a dictionary property, using a dynamic key resolved from an event context property.
21
28
  * The dictionary value at the resolved key is incremented by one for each matching event.