@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
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { PropertyAccessor } from '@cratis/fundamentals';
5
5
  import { ICompositeKeyBuilder } from './ICompositeKeyBuilder.js';
6
+ import type { DictionaryKeySource } from './DictionaryKey.js';
6
7
  import { IAddBuilder } from './IAddBuilder.js';
7
8
  import { IAddChildBuilder } from './IAddChildBuilder.js';
8
9
  import { ISetBuilder } from './ISetBuilder.js';
@@ -74,37 +75,47 @@ export interface IReadModelPropertiesBuilder<TReadModel, TEvent, TBuilder> {
74
75
  /**
75
76
  * Increments the specified read model property by one when this event occurs.
76
77
  * @param readModelPropertyAccessor - Accessor for the read model property to increment.
78
+ * @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
79
+ * an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
77
80
  * @returns This builder for fluent chaining.
78
81
  */
79
- increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>): TBuilder;
82
+ increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): TBuilder;
80
83
 
81
84
  /**
82
85
  * Decrements the specified read model property by one when this event occurs.
83
86
  * @param readModelPropertyAccessor - Accessor for the read model property to decrement.
87
+ * @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
88
+ * an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
84
89
  * @returns This builder for fluent chaining.
85
90
  */
86
- decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>): TBuilder;
91
+ decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): TBuilder;
87
92
 
88
93
  /**
89
94
  * Begins an add operation on the specified read model property.
90
95
  * @param readModelPropertyAccessor - Accessor for the read model property to add to.
96
+ * @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
97
+ * an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
91
98
  * @returns An add builder for specifying the event property value.
92
99
  */
93
- add(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAddBuilder<TEvent, TBuilder>;
100
+ add(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): IAddBuilder<TEvent, TBuilder>;
94
101
 
95
102
  /**
96
103
  * Begins a subtract operation on the specified read model property.
97
104
  * @param readModelPropertyAccessor - Accessor for the read model property to subtract from.
105
+ * @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
106
+ * an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
98
107
  * @returns A subtract builder for specifying the event property value.
99
108
  */
100
- subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISubtractBuilder<TEvent, TBuilder>;
109
+ subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISubtractBuilder<TEvent, TBuilder>;
101
110
 
102
111
  /**
103
112
  * Counts the number of matching events into the specified read model property.
104
113
  * @param readModelPropertyAccessor - Accessor for the read model property to store the count in.
114
+ * @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
115
+ * an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
105
116
  * @returns This builder for fluent chaining.
106
117
  */
107
- count(readModelPropertyAccessor: PropertyAccessor<TReadModel>): TBuilder;
118
+ count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): TBuilder;
108
119
 
109
120
  /**
110
121
  * Adds a child model configured through a child builder to a collection on the read model.
@@ -137,9 +148,31 @@ export interface IReadModelPropertiesBuilder<TReadModel, TEvent, TBuilder> {
137
148
  /**
138
149
  * Begins a set operation to map an event property to the specified read model property.
139
150
  * @param readModelPropertyAccessor - Accessor for the read model property to set.
151
+ * @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
152
+ * an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
140
153
  * @returns A set builder for specifying the event property value.
141
154
  */
142
- set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISetBuilder<TEvent, TBuilder>;
155
+ set(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, TBuilder>;
156
+
157
+ /**
158
+ * Begins a set operation that only assigns the read model property while it has no value yet. The first event that
159
+ * carries a value wins; later events leave the property as it is. Use it to capture a first occurrence - for instance
160
+ * `setOnce(m => m.firstSeen).toEventContextProperty('occurred')` - without a dedicated creation event.
161
+ * @param readModelPropertyAccessor - Accessor for the read model property to set once.
162
+ * @param key - Optional dictionary key. When given, the property is a dictionary and the operation targets the entry with this key:
163
+ * an accessor on the event, or a {@link DictionaryKey} for keys from the event context or the identity that caused the event.
164
+ * @returns A set builder for specifying the value.
165
+ */
166
+ setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, TBuilder>;
167
+
168
+ /**
169
+ * Removes an entry from a dictionary-typed read model property when this event occurs. Removing a key that is not
170
+ * present leaves the dictionary as it is.
171
+ * @param readModelPropertyAccessor - Accessor for the dictionary-typed read model property.
172
+ * @param key - The key of the entry to remove: an accessor on the event, or a {@link DictionaryKey}.
173
+ * @returns This builder for fluent chaining.
174
+ */
175
+ removeKey(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key: DictionaryKeySource<TEvent>): TBuilder;
143
176
 
144
177
  /**
145
178
  * Begins a set operation that maps the entire event value to a read model property.
@@ -2,6 +2,7 @@
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
4
  import { PropertyAccessor } from '@cratis/fundamentals';
5
+ import type { CausedByProperty } from '../causedBy.js';
5
6
 
6
7
  /**
7
8
  * Defines a builder for configuring a set operation on a read model property.
@@ -35,4 +36,11 @@ export interface ISetBuilder<TEvent, TParentBuilder> {
35
36
  * @returns The parent builder for fluent chaining.
36
37
  */
37
38
  toEventSourceId(): TParentBuilder;
39
+
40
+ /**
41
+ * Maps the read model property from the identity that caused the event, or one of its members.
42
+ * @param property - Optional identity member: `subject`, `name` or `userName`. Omit it for the whole identity.
43
+ * @returns The parent builder for fluent chaining.
44
+ */
45
+ toCausedBy(property?: CausedByProperty): TParentBuilder;
38
46
  }
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /** Error thrown when a dictionary key does not resolve to a property path on the event. */
5
+ export class InvalidDictionaryKey extends Error {
6
+ /**
7
+ * Creates an error for an unusable dictionary key path.
8
+ * @param path - The path the key accessor resolved to.
9
+ */
10
+ constructor(readonly path: string) {
11
+ super(`Invalid dictionary key '${path}'. The key accessor has to select a property on the event, for example 'e => e.category'.`);
12
+ this.name = 'InvalidDictionaryKey';
13
+ }
14
+ }
@@ -4,9 +4,11 @@
4
4
  import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
5
  import { constantValueExpression } from '../constantValueExpression.js';
6
6
  import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
7
+ import { removeExpression, setOnceExpression } from '../propertyExpressions.js';
7
8
  import { AddBuilder } from './AddBuilder.js';
8
9
  import { AddChildBuilder, ChildAdditionEntry } from './AddChildBuilder.js';
9
10
  import { CompositeKeyBuilder } from './CompositeKeyBuilder.js';
11
+ import { DictionaryKeySource, dictionaryEntryPath } from './DictionaryKey.js';
10
12
  import { IAddBuilder } from './IAddBuilder.js';
11
13
  import { IAddChildBuilder } from './IAddChildBuilder.js';
12
14
  import { ICompositeKeyBuilder } from './ICompositeKeyBuilder.js';
@@ -49,19 +51,29 @@ export class JoinBuilder<TReadModel, TEvent> implements IJoinBuilder<TReadModel,
49
51
  }
50
52
 
51
53
  /** @inheritdoc */
52
- set(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>> {
53
- const handler = new PropertyPathResolverProxyHandler();
54
- const proxy = new Proxy({}, handler);
55
- readModelPropertyAccessor(proxy as TReadModel);
56
- const readModelProperty = handler.property;
57
-
54
+ set(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>> {
58
55
  return new SetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>>(
59
- readModelProperty,
56
+ this.targetOf(readModelPropertyAccessor, key),
60
57
  (property, expression) => { this.entry.properties[property] = expression; },
61
58
  this
62
59
  );
63
60
  }
64
61
 
62
+ /** @inheritdoc */
63
+ setOnce(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>> {
64
+ return new SetBuilder<TEvent, IJoinBuilder<TReadModel, TEvent>>(
65
+ this.targetOf(readModelPropertyAccessor, key),
66
+ (property, expression) => { this.entry.properties[property] = setOnceExpression(expression); },
67
+ this
68
+ );
69
+ }
70
+
71
+ /** @inheritdoc */
72
+ removeKey(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key: DictionaryKeySource<TEvent>): this {
73
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = removeExpression;
74
+ return this;
75
+ }
76
+
65
77
  /** @inheritdoc */
66
78
  usingKey(keyAccessor: PropertyAccessor<TEvent>): this {
67
79
  const handler = new PropertyPathResolverProxyHandler();
@@ -119,53 +131,38 @@ export class JoinBuilder<TReadModel, TEvent> implements IJoinBuilder<TReadModel,
119
131
  }
120
132
 
121
133
  /** @inheritdoc */
122
- increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
123
- const handler = new PropertyPathResolverProxyHandler();
124
- const proxy = new Proxy({}, handler);
125
- readModelPropertyAccessor(proxy as TReadModel);
126
- this.entry.properties[handler.property] = '$increment';
134
+ increment(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
135
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$increment';
127
136
  return this;
128
137
  }
129
138
 
130
139
  /** @inheritdoc */
131
- decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
132
- const handler = new PropertyPathResolverProxyHandler();
133
- const proxy = new Proxy({}, handler);
134
- readModelPropertyAccessor(proxy as TReadModel);
135
- this.entry.properties[handler.property] = '$decrement';
140
+ decrement(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
141
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$decrement';
136
142
  return this;
137
143
  }
138
144
 
139
145
  /** @inheritdoc */
140
- add(readModelPropertyAccessor: PropertyAccessor<TReadModel>): IAddBuilder<TEvent, this> {
141
- const handler = new PropertyPathResolverProxyHandler();
142
- const proxy = new Proxy({}, handler);
143
- readModelPropertyAccessor(proxy as TReadModel);
146
+ add(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): IAddBuilder<TEvent, this> {
144
147
  return new AddBuilder<TEvent, this>(
145
- handler.property,
148
+ this.targetOf(readModelPropertyAccessor, key),
146
149
  (property, expression) => { this.entry.properties[property] = expression; },
147
150
  this
148
151
  );
149
152
  }
150
153
 
151
154
  /** @inheritdoc */
152
- subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>): ISubtractBuilder<TEvent, this> {
153
- const handler = new PropertyPathResolverProxyHandler();
154
- const proxy = new Proxy({}, handler);
155
- readModelPropertyAccessor(proxy as TReadModel);
155
+ subtract(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): ISubtractBuilder<TEvent, this> {
156
156
  return new SubtractBuilder<TEvent, this>(
157
- handler.property,
157
+ this.targetOf(readModelPropertyAccessor, key),
158
158
  (property, expression) => { this.entry.properties[property] = expression; },
159
159
  this
160
160
  );
161
161
  }
162
162
 
163
163
  /** @inheritdoc */
164
- count(readModelPropertyAccessor: PropertyAccessor<TReadModel>): this {
165
- const handler = new PropertyPathResolverProxyHandler();
166
- const proxy = new Proxy({}, handler);
167
- readModelPropertyAccessor(proxy as TReadModel);
168
- this.entry.properties[handler.property] = '$count';
164
+ count(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): this {
165
+ this.entry.properties[this.targetOf(readModelPropertyAccessor, key)] = '$count';
169
166
  return this;
170
167
  }
171
168
 
@@ -204,4 +201,16 @@ export class JoinBuilder<TReadModel, TEvent> implements IJoinBuilder<TReadModel,
204
201
  this
205
202
  );
206
203
  }
204
+
205
+ /**
206
+ * Resolves the target property path: the property itself, or the entry of a dictionary-typed property.
207
+ * @param readModelPropertyAccessor - Accessor for the read model property.
208
+ * @param key - Optional dictionary key.
209
+ * @returns The target property path.
210
+ */
211
+ private targetOf(readModelPropertyAccessor: PropertyAccessor<TReadModel>, key?: DictionaryKeySource<TEvent>): string {
212
+ const handler = new PropertyPathResolverProxyHandler();
213
+ readModelPropertyAccessor(new Proxy({}, handler) as TReadModel);
214
+ return key === undefined ? handler.property : dictionaryEntryPath(handler.property, key);
215
+ }
207
216
  }
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { AutoMap } from '@cratis/chronicle.contracts';
5
5
  import { getEventTypeFor } from '../../events/eventTypeDecorator.js';
6
+ import type { ChildrenOrderingDefinitionLike } from '../childrenOrdering.js';
6
7
  import { FromBuilder } from './FromBuilder.js';
7
8
  import { IFromBuilder } from './IFromBuilder.js';
8
9
  import { IFromEveryBuilder } from './IFromEveryBuilder.js';
@@ -59,6 +60,7 @@ export interface ChildrenDefinitionLike {
59
60
  RemovedWithJoin: RemovedWithJoinRecord[];
60
61
  AutoMap: AutoMap;
61
62
  Nested: Record<string, ChildrenDefinitionLike>;
63
+ Ordering?: ChildrenOrderingDefinitionLike;
62
64
  }
63
65
 
64
66
  /**
@@ -4,6 +4,7 @@
4
4
  import { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
5
5
  import { ISetBuilder } from './ISetBuilder.js';
6
6
  import { constantValueExpression } from '../constantValueExpression.js';
7
+ import { CausedByProperty, causedByExpression } from '../causedBy.js';
7
8
  import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
8
9
 
9
10
  /**
@@ -45,4 +46,10 @@ export class SetBuilder<TEvent, TParentBuilder> implements ISetBuilder<TEvent, T
45
46
  this._setProperty(this._readModelProperty, '$eventSourceId');
46
47
  return this._parent;
47
48
  }
49
+
50
+ /** @inheritdoc */
51
+ toCausedBy(property?: CausedByProperty): TParentBuilder {
52
+ this._setProperty(this._readModelProperty, causedByExpression(property));
53
+ return this._parent;
54
+ }
48
55
  }
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { chai, describe, it } from 'vitest';
5
+ import { ChildrenPlacement, SortDirection } from '../../childrenOrdering.js';
6
+ import { ChildrenBuilder } from '../ChildrenBuilder.js';
7
+ import { ChildrenOrderingAlreadyDefined } from '../ChildrenOrderingAlreadyDefined.js';
8
+
9
+ chai.should();
10
+
11
+ class Order {
12
+ lines!: Line[];
13
+ }
14
+
15
+ class Line {
16
+ lineId!: string;
17
+ position!: number;
18
+ product!: { name: string };
19
+ }
20
+
21
+ const build = (configure: (builder: ChildrenBuilder<Order, Line>) => void) => {
22
+ const builder = new ChildrenBuilder<Order, Line>();
23
+ configure(builder);
24
+ return builder.buildDefinition();
25
+ };
26
+
27
+ describe('when building children without an ordering', () => {
28
+ it('should leave the ordering out of the definition', () => build(_ => _.identifiedBy(m => m.lineId)).should.not.have.property('Ordering'));
29
+ });
30
+
31
+ describe('when prepending children', () => {
32
+ it('should place new children first', () => build(_ => _.prepend()).Ordering!.should.deep.equal({
33
+ Placement: ChildrenPlacement.Prepend, SortBy: '', Direction: SortDirection.Ascending
34
+ }));
35
+ });
36
+
37
+ describe('when ordering children by a property', () => {
38
+ it('should sort new children ascending by the property', () => build(_ => _.orderBy(m => m.position)).Ordering!.should.deep.equal({
39
+ Placement: ChildrenPlacement.Sorted, SortBy: 'position', Direction: SortDirection.Ascending
40
+ }));
41
+ });
42
+
43
+ describe('when ordering children descending by a nested property', () => {
44
+ it('should sort new children descending by the property path', () => build(_ => _.orderByDescending(m => m.product.name)).Ordering!.should.deep.equal({
45
+ Placement: ChildrenPlacement.Sorted, SortBy: 'product.name', Direction: SortDirection.Descending
46
+ }));
47
+ });
48
+
49
+ describe('when ordering children twice', () => {
50
+ it('should reject the second ordering', () =>
51
+ (() => build(_ => _.prepend().orderBy(m => m.position))).should.throw(ChildrenOrderingAlreadyDefined));
52
+ });
@@ -0,0 +1,29 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { chai, describe, it } from 'vitest';
5
+ import { FromAllBuilder } from '../FromAllBuilder.js';
6
+ import { FromEveryBuilder } from '../FromEveryBuilder.js';
7
+
8
+ chai.should();
9
+
10
+ class Document {
11
+ firstSeen!: Date;
12
+ createdBy!: string;
13
+ }
14
+
15
+ describe('when setting once from all events', () => {
16
+ it('should wrap the event context value in set once', () => {
17
+ const builder = new FromAllBuilder<Document>();
18
+ builder.setOnce(m => m.firstSeen).toEventContextProperty('occurred');
19
+ builder.properties.firstSeen.should.equal('$setOnce($eventContext(Occurred))');
20
+ });
21
+ });
22
+
23
+ describe('when setting once from every event', () => {
24
+ it('should wrap the causing identity in set once', () => {
25
+ const builder = new FromEveryBuilder<Document>();
26
+ builder.setOnce(m => m.createdBy).toCausedBy('subject');
27
+ builder.entry.properties.createdBy.should.equal('$setOnce($causedBy(subject))');
28
+ });
29
+ });
@@ -0,0 +1,39 @@
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 { beforeEach, chai, describe, it } from 'vitest';
5
+ import { FromBuilder } from '../FromBuilder.js';
6
+
7
+ chai.should();
8
+
9
+ class Account {
10
+ name!: string;
11
+ openedAt!: Date;
12
+ openedBy!: string;
13
+ accountId!: string;
14
+ tier!: string;
15
+ }
16
+
17
+ class AccountChanged {
18
+ name!: string;
19
+ }
20
+
21
+ describe('when setting read model properties once', () => {
22
+ let builder: FromBuilder<Account, AccountChanged>;
23
+
24
+ beforeEach(() => {
25
+ builder = new FromBuilder<Account, AccountChanged>();
26
+ builder
27
+ .setOnce(m => m.name).to(e => e.name)
28
+ .setOnce(m => m.openedAt).toEventContextProperty('occurred')
29
+ .setOnce(m => m.openedBy).toCausedBy('subject')
30
+ .setOnce(m => m.accountId).toEventSourceId()
31
+ .setOnce(m => m.tier).toValue('basic');
32
+ });
33
+
34
+ it('should wrap an event property in set once', () => builder.entry.properties.name.should.equal('$setOnce(name)'));
35
+ it('should wrap an event context property in set once', () => builder.entry.properties.openedAt.should.equal('$setOnce($eventContext(Occurred))'));
36
+ it('should wrap the causing identity in set once', () => builder.entry.properties.openedBy.should.equal('$setOnce($causedBy(subject))'));
37
+ it('should wrap the event source id in set once', () => builder.entry.properties.accountId.should.equal('$setOnce($eventSourceId)'));
38
+ it('should wrap a constant in set once', () => builder.entry.properties.tier.should.equal('$setOnce($value(basic))'));
39
+ });
@@ -0,0 +1,99 @@
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 { beforeEach, chai, describe, it } from 'vitest';
5
+ import type { EventContext } from '../../../events/EventContext.js';
6
+ import { DictionaryKey } from '../DictionaryKey.js';
7
+ import { FromBuilder } from '../FromBuilder.js';
8
+
9
+ chai.should();
10
+
11
+ class Sales {
12
+ unitsByCategory!: Record<string, number>;
13
+ salesByCategory!: Record<string, number>;
14
+ salesByUser!: Record<string, number>;
15
+ returnsByCategory!: Record<string, number>;
16
+ firstSaleByCategory!: Record<string, Date>;
17
+ seriesBySlot!: Record<string, string>;
18
+ lastSeller!: Record<string, string>;
19
+ }
20
+
21
+ class ItemSold {
22
+ category!: string;
23
+ quantity!: number;
24
+ seriesId!: string;
25
+ slot!: { name: string };
26
+ }
27
+
28
+ describe('when targeting dictionary entries with keys from the event content', () => {
29
+ let builder: FromBuilder<Sales, ItemSold>;
30
+
31
+ beforeEach(() => {
32
+ builder = new FromBuilder<Sales, ItemSold>();
33
+ builder
34
+ .set(m => m.seriesBySlot, e => e.slot.name).to(e => e.seriesId)
35
+ .add(m => m.unitsByCategory, e => e.category).with(e => e.quantity)
36
+ .subtract(m => m.returnsByCategory, e => e.category).with(e => e.quantity)
37
+ .increment(m => m.salesByCategory, e => e.category)
38
+ .count(m => m.salesByUser, e => e.category)
39
+ .decrement(m => m.lastSeller, DictionaryKey.fromEventContent<ItemSold>(e => e.category));
40
+ });
41
+
42
+ it('should key a set entry by the nested event property', () => builder.entry.properties['seriesBySlot.$eventContent.slot.name'].should.equal('seriesId'));
43
+ it('should key an add entry by the event property', () => builder.entry.properties['unitsByCategory.$eventContent.category'].should.equal('$add(quantity)'));
44
+ it('should key a subtract entry by the event property', () => builder.entry.properties['returnsByCategory.$eventContent.category'].should.equal('$subtract(quantity)'));
45
+ it('should key an increment entry by the event property', () => builder.entry.properties['salesByCategory.$eventContent.category'].should.equal('$increment'));
46
+ it('should key a count entry by the event property', () => builder.entry.properties['salesByUser.$eventContent.category'].should.equal('$count'));
47
+ it('should accept an explicit event content key', () => builder.entry.properties['lastSeller.$eventContent.category'].should.equal('$decrement'));
48
+ });
49
+
50
+ describe('when targeting dictionary entries with keys from the event context', () => {
51
+ let builder: FromBuilder<Sales, ItemSold>;
52
+
53
+ beforeEach(() => {
54
+ builder = new FromBuilder<Sales, ItemSold>();
55
+ builder
56
+ .count(m => m.salesByUser, DictionaryKey.fromEventContext((c: EventContext) => c.causedBy!.subject))
57
+ .increment(m => m.salesByCategory, DictionaryKey.fromEventContext('EventSourceId'));
58
+ });
59
+
60
+ it('should key the entry by the event context path from an accessor', () => builder.entry.properties['salesByUser.$eventContext.causedBy.subject'].should.equal('$count'));
61
+ it('should key the entry by a camel-cased event context property name', () => builder.entry.properties['salesByCategory.$eventContext.eventSourceId'].should.equal('$increment'));
62
+ });
63
+
64
+ describe('when targeting dictionary entries with keys from the identity that caused the event', () => {
65
+ let builder: FromBuilder<Sales, ItemSold>;
66
+
67
+ beforeEach(() => {
68
+ builder = new FromBuilder<Sales, ItemSold>();
69
+ builder
70
+ .count(m => m.salesByUser, DictionaryKey.causedBy('userName'))
71
+ .set(m => m.lastSeller, DictionaryKey.causedBy('subject')).toCausedBy('name');
72
+ });
73
+
74
+ it('should key the entry by the causing user name', () => builder.entry.properties['salesByUser.$causedBy.userName'].should.equal('$count'));
75
+ it('should key the entry by the causing subject', () => builder.entry.properties['lastSeller.$causedBy.subject'].should.equal('$causedBy(name)'));
76
+ });
77
+
78
+ describe('when removing and setting dictionary entries once', () => {
79
+ let builder: FromBuilder<Sales, ItemSold>;
80
+
81
+ beforeEach(() => {
82
+ builder = new FromBuilder<Sales, ItemSold>();
83
+ builder
84
+ .removeKey(m => m.seriesBySlot, e => e.slot.name)
85
+ .removeKey(m => m.salesByUser, DictionaryKey.causedBy('subject'))
86
+ .setOnce(m => m.firstSaleByCategory, e => e.category).toEventContextProperty('occurred');
87
+ });
88
+
89
+ it('should remove the entry keyed by the event property', () => builder.entry.properties['seriesBySlot.$eventContent.slot.name'].should.equal('$remove'));
90
+ it('should remove the entry keyed by the causing subject', () => builder.entry.properties['salesByUser.$causedBy.subject'].should.equal('$remove'));
91
+ it('should wrap the entry value in set once', () => builder.entry.properties['firstSaleByCategory.$eventContent.category'].should.equal('$setOnce($eventContext(Occurred))'));
92
+ });
93
+
94
+ describe('when using invalid dictionary keys', () => {
95
+ it('should reject a key that selects no event property', () => (() => DictionaryKey.fromEventContent(e => e)).should.throw('Invalid dictionary key'));
96
+ it('should reject an unknown event context property', () => (() => DictionaryKey.fromEventContext('notAProperty')).should.throw("Invalid event context property 'notAProperty'"));
97
+ it('should reject a derived event context function', () => (() => DictionaryKey.fromEventContext('occurred.week()')).should.throw("Invalid event context property 'occurred.week()'"));
98
+ it('should reject an unknown causing identity member', () => (() => DictionaryKey.causedBy('email' as 'subject')).should.throw("Invalid caused by property 'email'"));
99
+ });
@@ -0,0 +1,36 @@
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 { beforeEach, chai, describe, it } from 'vitest';
5
+ import { DictionaryKey } from '../DictionaryKey.js';
6
+ import { JoinBuilder } from '../JoinBuilder.js';
7
+
8
+ chai.should();
9
+
10
+ class Order {
11
+ customerName!: string;
12
+ ratingsByReviewer!: Record<string, number>;
13
+ reviewers!: Record<string, string>;
14
+ }
15
+
16
+ class CustomerRated {
17
+ name!: string;
18
+ reviewer!: string;
19
+ rating!: number;
20
+ }
21
+
22
+ describe('when a join sets once and targets dictionary entries', () => {
23
+ let builder: JoinBuilder<Order, CustomerRated>;
24
+
25
+ beforeEach(() => {
26
+ builder = new JoinBuilder<Order, CustomerRated>();
27
+ builder
28
+ .setOnce(m => m.customerName).to(e => e.name)
29
+ .set(m => m.ratingsByReviewer, e => e.reviewer).to(e => e.rating)
30
+ .removeKey(m => m.reviewers, DictionaryKey.causedBy('subject'));
31
+ });
32
+
33
+ it('should wrap the value in set once', () => builder.entry.properties.customerName.should.equal('$setOnce(name)'));
34
+ it('should key the entry by the event property', () => builder.entry.properties['ratingsByReviewer.$eventContent.reviewer'].should.equal('rating'));
35
+ it('should remove the entry keyed by the causing subject', () => builder.entry.properties['reviewers.$causedBy.subject'].should.equal('$remove'));
36
+ });
@@ -0,0 +1,37 @@
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 { beforeEach, chai, describe, it } from 'vitest';
5
+ import { AllSetBuilder } from '../AllSetBuilder.js';
6
+ import { SetBuilder } from '../SetBuilder.js';
7
+
8
+ chai.should();
9
+
10
+ describe('when setting a property to the identity that caused the event', () => {
11
+ let properties: Record<string, string>;
12
+ let builder: (property: string) => SetBuilder<object, object>;
13
+
14
+ beforeEach(() => {
15
+ properties = {};
16
+ builder = property => new SetBuilder<object, object>(property, (target, expression) => { properties[target] = expression; }, {});
17
+ builder('causedBy').toCausedBy();
18
+ builder('subject').toCausedBy('subject');
19
+ builder('name').toCausedBy('name');
20
+ builder('userName').toCausedBy('userName');
21
+ });
22
+
23
+ it('should map the whole identity', () => properties.causedBy.should.equal('$causedBy'));
24
+ it('should map the subject', () => properties.subject.should.equal('$causedBy(subject)'));
25
+ it('should map the name', () => properties.name.should.equal('$causedBy(name)'));
26
+ it('should map the user name', () => properties.userName.should.equal('$causedBy(userName)'));
27
+ it('should reject an unknown member', () =>
28
+ (() => builder('other').toCausedBy('Subject' as 'subject')).should.throw("Invalid caused by property 'Subject'"));
29
+ });
30
+
31
+ describe('when setting an all-events property to the identity that caused the event', () => {
32
+ it('should map the member', () => {
33
+ const properties: Record<string, string> = {};
34
+ new AllSetBuilder<object, object>('lastChangedBy', (target, expression) => { properties[target] = expression; }, {}).toCausedBy('userName');
35
+ properties.lastChangedBy.should.equal('$causedBy(userName)');
36
+ });
37
+ });
@@ -6,6 +6,10 @@ export type { ProjectionMetadata } from './projection.js';
6
6
  export { ProjectionBuilderFor } from './ProjectionBuilderFor.js';
7
7
  export { ProjectionBuilderCore } from './ProjectionBuilderCore.js';
8
8
  export { ChildrenBuilder } from './ChildrenBuilder.js';
9
+ export { ChildrenOrderingAlreadyDefined } from './ChildrenOrderingAlreadyDefined.js';
10
+ export { DictionaryKey } from './DictionaryKey.js';
11
+ export type { DictionaryKeySource } from './DictionaryKey.js';
12
+ export { InvalidDictionaryKey } from './InvalidDictionaryKey.js';
9
13
  export { NestedBuilder } from './NestedBuilder.js';
10
14
  export { AddChildBuilder } from './AddChildBuilder.js';
11
15
  export type { ChildAdditionEntry } from './AddChildBuilder.js';
@@ -106,7 +106,7 @@ describe('when declaring a fluent graph without decorators on its nodes and edge
106
106
  });
107
107
  it('should take the end node keys from the event and map the properties of the edge', () => {
108
108
  projection.Graph!.Edges.MEMBER_OF.From['MemberAdded+1'].should.deep.equal({
109
- SourceKey: 'personId', TargetKey: 'groupId', Identity: '', Properties: { times: '$increment' }
109
+ SourceKey: 'personId', TargetKey: 'groupId', Identity: '', Properties: { times: '$increment' }, ForEach: ''
110
110
  });
111
111
  });
112
112
  });
@@ -61,8 +61,8 @@ describe('when building a graph from decorated nodes and edges', () => {
61
61
  });
62
62
  it('should map a node from an event keyed by the event type id and generation', () => {
63
63
  result.graphs.registrations[0].projection.Graph!.Nodes.Person.should.deep.equal({
64
- From: { 'PersonRegistered+1': { Key: 'personId', Properties: { name: 'name' }, UpdateOnly: false } },
65
- RemovedWith: { 'PersonRemoved+1': { Key: 'personId', Detach: true } }
64
+ From: { 'PersonRegistered+1': { Key: 'personId', Properties: { name: 'name' }, UpdateOnly: false, ForEach: '' } },
65
+ RemovedWith: { 'PersonRemoved+1': { Key: 'personId', Detach: true, ForEach: '' } }
66
66
  });
67
67
  });
68
68
  it('should map the properties of a node by name and leave out the key', () => {
@@ -75,10 +75,11 @@ describe('when building a graph from decorated nodes and edges', () => {
75
75
  SourceKey: 'personId',
76
76
  TargetKey: 'groupId',
77
77
  Identity: '',
78
- Properties: { since: '$eventContext(Occurred)' }
78
+ Properties: { since: '$eventContext(Occurred)' },
79
+ ForEach: ''
79
80
  }
80
81
  },
81
- RemovedWith: { 'MemberRemoved+1': { SourceKey: 'personId', TargetKey: 'groupId', Identity: '' } }
82
+ RemovedWith: { 'MemberRemoved+1': { SourceKey: 'personId', TargetKey: 'groupId', Identity: '', ForEach: '' } }
82
83
  });
83
84
  });
84
85
  });