@cratis/chronicle 6.63.0 → 6.64.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 (366) hide show
  1. package/artifacts/DefaultClientArtifactsProvider.ts +5 -0
  2. package/artifacts/IClientArtifactsProvider.ts +3 -0
  3. package/dist/artifacts/DefaultClientArtifactsProvider.d.ts +2 -0
  4. package/dist/artifacts/DefaultClientArtifactsProvider.d.ts.map +1 -1
  5. package/dist/artifacts/DefaultClientArtifactsProvider.js +4 -0
  6. package/dist/artifacts/DefaultClientArtifactsProvider.js.map +1 -1
  7. package/dist/artifacts/IClientArtifactsProvider.d.ts +2 -0
  8. package/dist/artifacts/IClientArtifactsProvider.d.ts.map +1 -1
  9. package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts +2 -1
  10. package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts.map +1 -1
  11. package/dist/projections/for_Graphs/given/a_discovered_graph.js +3 -2
  12. package/dist/projections/for_Graphs/given/a_discovered_graph.js.map +1 -1
  13. package/dist/projections/for_Graphs/given/a_graph_with_views.d.ts +40 -0
  14. package/dist/projections/for_Graphs/given/a_graph_with_views.d.ts.map +1 -0
  15. package/dist/projections/for_Graphs/given/a_graph_with_views.js +80 -0
  16. package/dist/projections/for_Graphs/given/a_graph_with_views.js.map +1 -0
  17. package/dist/projections/for_Graphs/given/organization.d.ts +2 -1
  18. package/dist/projections/for_Graphs/given/organization.d.ts.map +1 -1
  19. package/dist/projections/for_Graphs/given/organization.js +3 -2
  20. package/dist/projections/for_Graphs/given/organization.js.map +1 -1
  21. package/dist/projections/graphs/Graphs.d.ts +5 -0
  22. package/dist/projections/graphs/Graphs.d.ts.map +1 -1
  23. package/dist/projections/graphs/Graphs.js +43 -0
  24. package/dist/projections/graphs/Graphs.js.map +1 -1
  25. package/dist/projections/graphs/IGraphs.d.ts +9 -2
  26. package/dist/projections/graphs/IGraphs.d.ts.map +1 -1
  27. package/dist/projections/graphs/index.d.ts +1 -0
  28. package/dist/projections/graphs/index.d.ts.map +1 -1
  29. package/dist/projections/graphs/index.js +1 -0
  30. package/dist/projections/graphs/index.js.map +1 -1
  31. package/dist/projections/graphs/views/AmbiguousDirection.d.ts +16 -0
  32. package/dist/projections/graphs/views/AmbiguousDirection.d.ts.map +1 -0
  33. package/dist/projections/graphs/views/AmbiguousDirection.js +21 -0
  34. package/dist/projections/graphs/views/AmbiguousDirection.js.map +1 -0
  35. package/dist/projections/graphs/views/DuplicateViewName.d.ts +16 -0
  36. package/dist/projections/graphs/views/DuplicateViewName.d.ts.map +1 -0
  37. package/dist/projections/graphs/views/DuplicateViewName.js +21 -0
  38. package/dist/projections/graphs/views/DuplicateViewName.js.map +1 -0
  39. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.d.ts +17 -0
  40. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.d.ts.map +1 -0
  41. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.js +22 -0
  42. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.js.map +1 -0
  43. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.d.ts +14 -0
  44. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.d.ts.map +1 -0
  45. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.js +19 -0
  46. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.js.map +1 -0
  47. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.d.ts +15 -0
  48. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.d.ts.map +1 -0
  49. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.js +20 -0
  50. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.js.map +1 -0
  51. package/dist/projections/graphs/views/FollowsOptions.d.ts +16 -0
  52. package/dist/projections/graphs/views/FollowsOptions.d.ts.map +1 -0
  53. package/dist/projections/graphs/views/FollowsOptions.js +4 -0
  54. package/dist/projections/graphs/views/FollowsOptions.js.map +1 -0
  55. package/dist/projections/graphs/views/GraphEdgeDirection.d.ts +10 -0
  56. package/dist/projections/graphs/views/GraphEdgeDirection.d.ts.map +1 -0
  57. package/dist/projections/graphs/views/GraphEdgeDirection.js +13 -0
  58. package/dist/projections/graphs/views/GraphEdgeDirection.js.map +1 -0
  59. package/dist/projections/graphs/views/GraphView.d.ts +13 -0
  60. package/dist/projections/graphs/views/GraphView.d.ts.map +1 -0
  61. package/dist/projections/graphs/views/GraphView.js +4 -0
  62. package/dist/projections/graphs/views/GraphView.js.map +1 -0
  63. package/dist/projections/graphs/views/GraphViewBuildResult.d.ts +15 -0
  64. package/dist/projections/graphs/views/GraphViewBuildResult.d.ts.map +1 -0
  65. package/dist/projections/graphs/views/GraphViewBuildResult.js +4 -0
  66. package/dist/projections/graphs/views/GraphViewBuildResult.js.map +1 -0
  67. package/dist/projections/graphs/views/GraphViewCardinality.d.ts +10 -0
  68. package/dist/projections/graphs/views/GraphViewCardinality.d.ts.map +1 -0
  69. package/dist/projections/graphs/views/GraphViewCardinality.js +13 -0
  70. package/dist/projections/graphs/views/GraphViewCardinality.js.map +1 -0
  71. package/dist/projections/graphs/views/GraphViewDefinition.d.ts +15 -0
  72. package/dist/projections/graphs/views/GraphViewDefinition.d.ts.map +1 -0
  73. package/dist/projections/graphs/views/GraphViewDefinition.js +4 -0
  74. package/dist/projections/graphs/views/GraphViewDefinition.js.map +1 -0
  75. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.d.ts +30 -0
  76. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.d.ts.map +1 -0
  77. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.js +259 -0
  78. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.js.map +1 -0
  79. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.d.ts +21 -0
  80. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.d.ts.map +1 -0
  81. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.js +77 -0
  82. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.js.map +1 -0
  83. package/dist/projections/graphs/views/GraphViewEdgeReference.d.ts +6 -0
  84. package/dist/projections/graphs/views/GraphViewEdgeReference.d.ts.map +1 -0
  85. package/dist/projections/graphs/views/GraphViewEdgeReference.js +4 -0
  86. package/dist/projections/graphs/views/GraphViewEdgeReference.js.map +1 -0
  87. package/dist/projections/graphs/views/GraphViewMember.d.ts +8 -0
  88. package/dist/projections/graphs/views/GraphViewMember.d.ts.map +1 -0
  89. package/dist/projections/graphs/views/GraphViewMember.js +4 -0
  90. package/dist/projections/graphs/views/GraphViewMember.js.map +1 -0
  91. package/dist/projections/graphs/views/GraphViewMemberKind.d.ts +12 -0
  92. package/dist/projections/graphs/views/GraphViewMemberKind.d.ts.map +1 -0
  93. package/dist/projections/graphs/views/GraphViewMemberKind.js +15 -0
  94. package/dist/projections/graphs/views/GraphViewMemberKind.js.map +1 -0
  95. package/dist/projections/graphs/views/GraphViewMemberMetadata.d.ts +22 -0
  96. package/dist/projections/graphs/views/GraphViewMemberMetadata.d.ts.map +1 -0
  97. package/dist/projections/graphs/views/GraphViewMemberMetadata.js +4 -0
  98. package/dist/projections/graphs/views/GraphViewMemberMetadata.js.map +1 -0
  99. package/dist/projections/graphs/views/GraphViewPropertyMember.d.ts +13 -0
  100. package/dist/projections/graphs/views/GraphViewPropertyMember.d.ts.map +1 -0
  101. package/dist/projections/graphs/views/GraphViewPropertyMember.js +4 -0
  102. package/dist/projections/graphs/views/GraphViewPropertyMember.js.map +1 -0
  103. package/dist/projections/graphs/views/GraphViewReason.d.ts +33 -0
  104. package/dist/projections/graphs/views/GraphViewReason.d.ts.map +1 -0
  105. package/dist/projections/graphs/views/GraphViewReason.js +36 -0
  106. package/dist/projections/graphs/views/GraphViewReason.js.map +1 -0
  107. package/dist/projections/graphs/views/GraphViewRelationMember.d.ts +21 -0
  108. package/dist/projections/graphs/views/GraphViewRelationMember.d.ts.map +1 -0
  109. package/dist/projections/graphs/views/GraphViewRelationMember.js +4 -0
  110. package/dist/projections/graphs/views/GraphViewRelationMember.js.map +1 -0
  111. package/dist/projections/graphs/views/GraphViewSchema.d.ts +10 -0
  112. package/dist/projections/graphs/views/GraphViewSchema.d.ts.map +1 -0
  113. package/dist/projections/graphs/views/GraphViewSchema.js +4 -0
  114. package/dist/projections/graphs/views/GraphViewSchema.js.map +1 -0
  115. package/dist/projections/graphs/views/GraphViewSchemaEdge.d.ts +14 -0
  116. package/dist/projections/graphs/views/GraphViewSchemaEdge.d.ts.map +1 -0
  117. package/dist/projections/graphs/views/GraphViewSchemaEdge.js +4 -0
  118. package/dist/projections/graphs/views/GraphViewSchemaEdge.js.map +1 -0
  119. package/dist/projections/graphs/views/GraphViewSchemaNode.d.ts +10 -0
  120. package/dist/projections/graphs/views/GraphViewSchemaNode.d.ts.map +1 -0
  121. package/dist/projections/graphs/views/GraphViewSchemaNode.js +4 -0
  122. package/dist/projections/graphs/views/GraphViewSchemaNode.js.map +1 -0
  123. package/dist/projections/graphs/views/GraphViewSerializerOptions.d.ts +9 -0
  124. package/dist/projections/graphs/views/GraphViewSerializerOptions.d.ts.map +1 -0
  125. package/dist/projections/graphs/views/GraphViewSerializerOptions.js +4 -0
  126. package/dist/projections/graphs/views/GraphViewSerializerOptions.js.map +1 -0
  127. package/dist/projections/graphs/views/RecursiveView.d.ts +15 -0
  128. package/dist/projections/graphs/views/RecursiveView.d.ts.map +1 -0
  129. package/dist/projections/graphs/views/RecursiveView.js +20 -0
  130. package/dist/projections/graphs/views/RecursiveView.js.map +1 -0
  131. package/dist/projections/graphs/views/RelationTargetNotAView.d.ts +16 -0
  132. package/dist/projections/graphs/views/RelationTargetNotAView.d.ts.map +1 -0
  133. package/dist/projections/graphs/views/RelationTargetNotAView.js +21 -0
  134. package/dist/projections/graphs/views/RelationTargetNotAView.js.map +1 -0
  135. package/dist/projections/graphs/views/TargetLabelMismatch.d.ts +18 -0
  136. package/dist/projections/graphs/views/TargetLabelMismatch.d.ts.map +1 -0
  137. package/dist/projections/graphs/views/TargetLabelMismatch.js +23 -0
  138. package/dist/projections/graphs/views/TargetLabelMismatch.js.map +1 -0
  139. package/dist/projections/graphs/views/UnknownEdge.d.ts +16 -0
  140. package/dist/projections/graphs/views/UnknownEdge.d.ts.map +1 -0
  141. package/dist/projections/graphs/views/UnknownEdge.js +21 -0
  142. package/dist/projections/graphs/views/UnknownEdge.js.map +1 -0
  143. package/dist/projections/graphs/views/UnknownEdgeProperty.d.ts +17 -0
  144. package/dist/projections/graphs/views/UnknownEdgeProperty.d.ts.map +1 -0
  145. package/dist/projections/graphs/views/UnknownEdgeProperty.js +22 -0
  146. package/dist/projections/graphs/views/UnknownEdgeProperty.js.map +1 -0
  147. package/dist/projections/graphs/views/UnknownNodeProperty.d.ts +17 -0
  148. package/dist/projections/graphs/views/UnknownNodeProperty.d.ts.map +1 -0
  149. package/dist/projections/graphs/views/UnknownNodeProperty.js +22 -0
  150. package/dist/projections/graphs/views/UnknownNodeProperty.js.map +1 -0
  151. package/dist/projections/graphs/views/ViewIsAlsoSchema.d.ts +14 -0
  152. package/dist/projections/graphs/views/ViewIsAlsoSchema.d.ts.map +1 -0
  153. package/dist/projections/graphs/views/ViewIsAlsoSchema.js +19 -0
  154. package/dist/projections/graphs/views/ViewIsAlsoSchema.js.map +1 -0
  155. package/dist/projections/graphs/views/ViewOfMetadata.d.ts +8 -0
  156. package/dist/projections/graphs/views/ViewOfMetadata.d.ts.map +1 -0
  157. package/dist/projections/graphs/views/ViewOfMetadata.js +4 -0
  158. package/dist/projections/graphs/views/ViewOfMetadata.js.map +1 -0
  159. package/dist/projections/graphs/views/ViewOfOptions.d.ts +6 -0
  160. package/dist/projections/graphs/views/ViewOfOptions.d.ts.map +1 -0
  161. package/dist/projections/graphs/views/ViewOfOptions.js +4 -0
  162. package/dist/projections/graphs/views/ViewOfOptions.js.map +1 -0
  163. package/dist/projections/graphs/views/ViewRootNotANode.d.ts +16 -0
  164. package/dist/projections/graphs/views/ViewRootNotANode.d.ts.map +1 -0
  165. package/dist/projections/graphs/views/ViewRootNotANode.js +21 -0
  166. package/dist/projections/graphs/views/ViewRootNotANode.js.map +1 -0
  167. package/dist/projections/graphs/views/declareGraphViewMember.d.ts +17 -0
  168. package/dist/projections/graphs/views/declareGraphViewMember.d.ts.map +1 -0
  169. package/dist/projections/graphs/views/declareGraphViewMember.js +31 -0
  170. package/dist/projections/graphs/views/declareGraphViewMember.js.map +1 -0
  171. package/dist/projections/graphs/views/follows.d.ts +13 -0
  172. package/dist/projections/graphs/views/follows.d.ts.map +1 -0
  173. package/dist/projections/graphs/views/follows.js +24 -0
  174. package/dist/projections/graphs/views/follows.js.map +1 -0
  175. package/dist/projections/graphs/views/fromEdge.d.ts +10 -0
  176. package/dist/projections/graphs/views/fromEdge.d.ts.map +1 -0
  177. package/dist/projections/graphs/views/fromEdge.js +15 -0
  178. package/dist/projections/graphs/views/fromEdge.js.map +1 -0
  179. package/dist/projections/graphs/views/index.d.ts +41 -0
  180. package/dist/projections/graphs/views/index.d.ts.map +1 -0
  181. package/dist/projections/graphs/views/index.js +28 -0
  182. package/dist/projections/graphs/views/index.js.map +1 -0
  183. package/dist/projections/graphs/views/viewKey.d.ts +8 -0
  184. package/dist/projections/graphs/views/viewKey.d.ts.map +1 -0
  185. package/dist/projections/graphs/views/viewKey.js +13 -0
  186. package/dist/projections/graphs/views/viewKey.js.map +1 -0
  187. package/dist/projections/graphs/views/viewOf.d.ts +22 -0
  188. package/dist/projections/graphs/views/viewOf.d.ts.map +1 -0
  189. package/dist/projections/graphs/views/viewOf.js +41 -0
  190. package/dist/projections/graphs/views/viewOf.js.map +1 -0
  191. package/dist/projections/graphs/views/viewProperty.d.ts +9 -0
  192. package/dist/projections/graphs/views/viewProperty.d.ts.map +1 -0
  193. package/dist/projections/graphs/views/viewProperty.js +14 -0
  194. package/dist/projections/graphs/views/viewProperty.js.map +1 -0
  195. package/dist/testing/InProcessAppendMetadata.d.ts +30 -0
  196. package/dist/testing/InProcessAppendMetadata.d.ts.map +1 -0
  197. package/dist/testing/InProcessAppendMetadata.js +107 -0
  198. package/dist/testing/InProcessAppendMetadata.js.map +1 -0
  199. package/dist/testing/InProcessBatchAppend.d.ts +62 -0
  200. package/dist/testing/InProcessBatchAppend.d.ts.map +1 -0
  201. package/dist/testing/InProcessBatchAppend.js +131 -0
  202. package/dist/testing/InProcessBatchAppend.js.map +1 -0
  203. package/dist/testing/InProcessEventPayload.d.ts +23 -0
  204. package/dist/testing/InProcessEventPayload.d.ts.map +1 -0
  205. package/dist/testing/InProcessEventPayload.js +94 -0
  206. package/dist/testing/InProcessEventPayload.js.map +1 -0
  207. package/dist/testing/InProcessEventReadCriteria.d.ts +9 -0
  208. package/dist/testing/InProcessEventReadCriteria.d.ts.map +1 -0
  209. package/dist/testing/InProcessEventReadCriteria.js +4 -0
  210. package/dist/testing/InProcessEventReadCriteria.js.map +1 -0
  211. package/dist/testing/InProcessEventReadFilter.d.ts +14 -0
  212. package/dist/testing/InProcessEventReadFilter.d.ts.map +1 -0
  213. package/dist/testing/InProcessEventReadFilter.js +31 -0
  214. package/dist/testing/InProcessEventReadFilter.js.map +1 -0
  215. package/dist/testing/InProcessEventSequence.d.ts +8 -5
  216. package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
  217. package/dist/testing/InProcessEventSequence.js +59 -275
  218. package/dist/testing/InProcessEventSequence.js.map +1 -1
  219. package/dist/testing/InProcessEventSequenceEnvironment.d.ts +13 -0
  220. package/dist/testing/InProcessEventSequenceEnvironment.d.ts.map +1 -0
  221. package/dist/testing/InProcessEventSequenceEnvironment.js +4 -0
  222. package/dist/testing/InProcessEventSequenceEnvironment.js.map +1 -0
  223. package/dist/testing/InProcessSingleAppend.d.ts +34 -0
  224. package/dist/testing/InProcessSingleAppend.d.ts.map +1 -0
  225. package/dist/testing/InProcessSingleAppend.js +95 -0
  226. package/dist/testing/InProcessSingleAppend.js.map +1 -0
  227. package/dist/testing/projections/ProjectionCapabilities.d.ts +0 -8
  228. package/dist/testing/projections/ProjectionCapabilities.d.ts.map +1 -1
  229. package/dist/testing/projections/ProjectionCapabilities.js +21 -312
  230. package/dist/testing/projections/ProjectionCapabilities.js.map +1 -1
  231. package/dist/testing/projections/ProjectionCapabilityReject.d.ts +3 -0
  232. package/dist/testing/projections/ProjectionCapabilityReject.d.ts.map +1 -0
  233. package/dist/testing/projections/ProjectionCapabilityReject.js +4 -0
  234. package/dist/testing/projections/ProjectionCapabilityReject.js.map +1 -0
  235. package/dist/testing/projections/ProjectionCapabilityReporter.d.ts +12 -0
  236. package/dist/testing/projections/ProjectionCapabilityReporter.d.ts.map +1 -0
  237. package/dist/testing/projections/ProjectionCapabilityReporter.js +33 -0
  238. package/dist/testing/projections/ProjectionCapabilityReporter.js.map +1 -0
  239. package/dist/testing/projections/ProjectionDefinitionCapabilities.d.ts +11 -0
  240. package/dist/testing/projections/ProjectionDefinitionCapabilities.d.ts.map +1 -0
  241. package/dist/testing/projections/ProjectionDefinitionCapabilities.js +45 -0
  242. package/dist/testing/projections/ProjectionDefinitionCapabilities.js.map +1 -0
  243. package/dist/testing/projections/ProjectionEventSchemaResolver.d.ts +13 -0
  244. package/dist/testing/projections/ProjectionEventSchemaResolver.d.ts.map +1 -0
  245. package/dist/testing/projections/ProjectionEventSchemaResolver.js +22 -0
  246. package/dist/testing/projections/ProjectionEventSchemaResolver.js.map +1 -0
  247. package/dist/testing/projections/ProjectionExpressionCapabilities.d.ts +19 -0
  248. package/dist/testing/projections/ProjectionExpressionCapabilities.d.ts.map +1 -0
  249. package/dist/testing/projections/ProjectionExpressionCapabilities.js +103 -0
  250. package/dist/testing/projections/ProjectionExpressionCapabilities.js.map +1 -0
  251. package/dist/testing/projections/ProjectionInitialValueCapabilities.d.ts +16 -0
  252. package/dist/testing/projections/ProjectionInitialValueCapabilities.d.ts.map +1 -0
  253. package/dist/testing/projections/ProjectionInitialValueCapabilities.js +72 -0
  254. package/dist/testing/projections/ProjectionInitialValueCapabilities.js.map +1 -0
  255. package/dist/testing/projections/ProjectionMappingCapabilities.d.ts +21 -0
  256. package/dist/testing/projections/ProjectionMappingCapabilities.d.ts.map +1 -0
  257. package/dist/testing/projections/ProjectionMappingCapabilities.js +86 -0
  258. package/dist/testing/projections/ProjectionMappingCapabilities.js.map +1 -0
  259. package/dist/testing/projections/ProjectionMappingValidation.d.ts +9 -0
  260. package/dist/testing/projections/ProjectionMappingValidation.d.ts.map +1 -0
  261. package/dist/testing/projections/ProjectionMappingValidation.js +4 -0
  262. package/dist/testing/projections/ProjectionMappingValidation.js.map +1 -0
  263. package/dist/testing/projections/ProjectionReadModelCapabilities.d.ts +11 -0
  264. package/dist/testing/projections/ProjectionReadModelCapabilities.d.ts.map +1 -0
  265. package/dist/testing/projections/ProjectionReadModelCapabilities.js +40 -0
  266. package/dist/testing/projections/ProjectionReadModelCapabilities.js.map +1 -0
  267. package/dist/testing/projections/ProjectionRootCapabilities.d.ts +20 -0
  268. package/dist/testing/projections/ProjectionRootCapabilities.d.ts.map +1 -0
  269. package/dist/testing/projections/ProjectionRootCapabilities.js +73 -0
  270. package/dist/testing/projections/ProjectionRootCapabilities.js.map +1 -0
  271. package/dist/testing/projections/ProjectionScalarConverter.d.ts +21 -0
  272. package/dist/testing/projections/ProjectionScalarConverter.d.ts.map +1 -0
  273. package/dist/testing/projections/ProjectionScalarConverter.js +105 -0
  274. package/dist/testing/projections/ProjectionScalarConverter.js.map +1 -0
  275. package/dist/testing/projections/ProjectionSchemaCapabilities.d.ts +26 -0
  276. package/dist/testing/projections/ProjectionSchemaCapabilities.d.ts.map +1 -0
  277. package/dist/testing/projections/ProjectionSchemaCapabilities.js +109 -0
  278. package/dist/testing/projections/ProjectionSchemaCapabilities.js.map +1 -0
  279. package/dist/testing/projections/ProjectionValueConverter.d.ts +5 -0
  280. package/dist/testing/projections/ProjectionValueConverter.d.ts.map +1 -1
  281. package/dist/testing/projections/ProjectionValueConverter.js +36 -84
  282. package/dist/testing/projections/ProjectionValueConverter.js.map +1 -1
  283. package/dist/tsconfig.tsbuildinfo +1 -1
  284. package/dist/types/DecoratorType.d.ts +3 -1
  285. package/dist/types/DecoratorType.d.ts.map +1 -1
  286. package/dist/types/DecoratorType.js +2 -0
  287. package/dist/types/DecoratorType.js.map +1 -1
  288. package/package.json +2 -2
  289. package/projections/for_Graphs/given/a_discovered_graph.ts +3 -2
  290. package/projections/for_Graphs/given/a_graph_with_views.ts +91 -0
  291. package/projections/for_Graphs/given/organization.ts +3 -2
  292. package/projections/for_Graphs/given/organization_with_views.fixture.ts +129 -0
  293. package/projections/for_Graphs/when_building_graph_views.spec.ts +218 -0
  294. package/projections/for_Graphs/when_declaring_an_invalid_graph_view.spec.ts +229 -0
  295. package/projections/for_Graphs/when_declaring_graph_views.standard.spec.ts +49 -0
  296. package/projections/for_Graphs/when_discovering_graph_views.spec.ts +58 -0
  297. package/projections/graphs/Graphs.ts +44 -0
  298. package/projections/graphs/IGraphs.ts +10 -2
  299. package/projections/graphs/index.ts +1 -0
  300. package/projections/graphs/views/AmbiguousDirection.ts +23 -0
  301. package/projections/graphs/views/DuplicateViewName.ts +23 -0
  302. package/projections/graphs/views/EdgeNotIncidentOnRoot.ts +24 -0
  303. package/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.ts +21 -0
  304. package/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.ts +22 -0
  305. package/projections/graphs/views/FollowsOptions.ts +20 -0
  306. package/projections/graphs/views/GraphEdgeDirection.ts +13 -0
  307. package/projections/graphs/views/GraphView.ts +18 -0
  308. package/projections/graphs/views/GraphViewBuildResult.ts +19 -0
  309. package/projections/graphs/views/GraphViewCardinality.ts +13 -0
  310. package/projections/graphs/views/GraphViewDefinition.ts +20 -0
  311. package/projections/graphs/views/GraphViewDefinitionBuilder.ts +322 -0
  312. package/projections/graphs/views/GraphViewDefinitionSerializer.ts +90 -0
  313. package/projections/graphs/views/GraphViewEdgeReference.ts +8 -0
  314. package/projections/graphs/views/GraphViewMember.ts +11 -0
  315. package/projections/graphs/views/GraphViewMemberKind.ts +16 -0
  316. package/projections/graphs/views/GraphViewMemberMetadata.ts +31 -0
  317. package/projections/graphs/views/GraphViewPropertyMember.ts +18 -0
  318. package/projections/graphs/views/GraphViewReason.ts +47 -0
  319. package/projections/graphs/views/GraphViewRelationMember.ts +29 -0
  320. package/projections/graphs/views/GraphViewSchema.ts +14 -0
  321. package/projections/graphs/views/GraphViewSchemaEdge.ts +20 -0
  322. package/projections/graphs/views/GraphViewSchemaNode.ts +14 -0
  323. package/projections/graphs/views/GraphViewSerializerOptions.ts +11 -0
  324. package/projections/graphs/views/RecursiveView.ts +22 -0
  325. package/projections/graphs/views/RelationTargetNotAView.ts +23 -0
  326. package/projections/graphs/views/TargetLabelMismatch.ts +25 -0
  327. package/projections/graphs/views/UnknownEdge.ts +23 -0
  328. package/projections/graphs/views/UnknownEdgeProperty.ts +24 -0
  329. package/projections/graphs/views/UnknownNodeProperty.ts +24 -0
  330. package/projections/graphs/views/ViewIsAlsoSchema.ts +21 -0
  331. package/projections/graphs/views/ViewOfMetadata.ts +11 -0
  332. package/projections/graphs/views/ViewOfOptions.ts +8 -0
  333. package/projections/graphs/views/ViewRootNotANode.ts +23 -0
  334. package/projections/graphs/views/declareGraphViewMember.ts +36 -0
  335. package/projections/graphs/views/follows.ts +28 -0
  336. package/projections/graphs/views/fromEdge.ts +17 -0
  337. package/projections/graphs/views/index.ts +43 -0
  338. package/projections/graphs/views/viewKey.ts +15 -0
  339. package/projections/graphs/views/viewOf.ts +50 -0
  340. package/projections/graphs/views/viewProperty.ts +16 -0
  341. package/testing/InProcessAppendMetadata.ts +119 -0
  342. package/testing/InProcessBatchAppend.ts +142 -0
  343. package/testing/InProcessEventPayload.ts +100 -0
  344. package/testing/InProcessEventReadCriteria.ts +11 -0
  345. package/testing/InProcessEventReadFilter.ts +37 -0
  346. package/testing/InProcessEventSequence.ts +63 -257
  347. package/testing/InProcessEventSequenceEnvironment.ts +16 -0
  348. package/testing/InProcessSingleAppend.ts +99 -0
  349. package/testing/for_InProcessEventSequence/when_preserving_validation_and_commit_order.spec.ts +95 -0
  350. package/testing/projections/ProjectionCapabilities.ts +23 -279
  351. package/testing/projections/ProjectionCapabilityReject.ts +5 -0
  352. package/testing/projections/ProjectionCapabilityReporter.ts +31 -0
  353. package/testing/projections/ProjectionDefinitionCapabilities.ts +45 -0
  354. package/testing/projections/ProjectionEventSchemaResolver.ts +23 -0
  355. package/testing/projections/ProjectionExpressionCapabilities.ts +101 -0
  356. package/testing/projections/ProjectionInitialValueCapabilities.ts +73 -0
  357. package/testing/projections/ProjectionMappingCapabilities.ts +85 -0
  358. package/testing/projections/ProjectionMappingValidation.ts +12 -0
  359. package/testing/projections/ProjectionReadModelCapabilities.ts +42 -0
  360. package/testing/projections/ProjectionRootCapabilities.ts +75 -0
  361. package/testing/projections/ProjectionScalarConverter.ts +106 -0
  362. package/testing/projections/ProjectionSchemaCapabilities.ts +112 -0
  363. package/testing/projections/ProjectionValueConverter.ts +37 -76
  364. package/testing/projections/for_ProjectionCapabilities/when_reporting_the_first_unsupported_operation.spec.ts +74 -0
  365. package/testing/projections/for_ProjectionValueConverter/when_converting_structured_and_scalar_values.spec.ts +64 -0
  366. package/types/DecoratorType.ts +4 -1
@@ -1,23 +1,15 @@
1
1
  // Copyright (c) Cratis. All rights reserved.
2
2
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
 
4
- import { createHash } from 'node:crypto';
5
- import { EventObservationState } from '@cratis/chronicle.contracts';
6
4
  import { AppendOperationsBroadcaster } from '../eventSequences/AppendOperationsBroadcaster.js';
7
- import { prepareBatchAppend } from '../eventSequences/prepareBatchAppend.js';
8
5
  import { createAppendNotification, mapAppendNotificationCausation } from '../eventSequences/createAppendNotification.js';
9
6
  import { createAppendResult } from '../eventSequences/createAppendResult.js';
10
- import { conceptAsTypeKey, Guid, JsonSerializer, typeKeyOf, type Constructor } from '@cratis/fundamentals';
11
- import { getEventTypeMetadata, getEventTypeFor } from '../events/eventTypeDecorator.js';
7
+ import { Guid, type Constructor } from '@cratis/fundamentals';
8
+ import { getEventTypeMetadata } from '../events/eventTypeDecorator.js';
12
9
  import { getTagsFor } from '../events/tagDecorator.js';
13
10
  import type { AppendedEvent } from '../events/AppendedEvent.js';
14
- import { Tag } from '../events/Tag.js';
15
- import { EventType } from '../events/EventType.js';
16
- import { EventTypeId } from '../events/EventTypeId.js';
17
- import { EventTypeGeneration } from '../events/EventTypeGeneration.js';
18
- import { Identity } from '../identity/Identity.js';
11
+
19
12
  import type { AppendOptions } from '../eventSequences/AppendOptions.js';
20
- import { hasNamedTags, singleAppendRoute } from './singleAppendRoute.js';
21
13
  import type { AppendResult } from '../eventSequences/AppendResult.js';
22
14
  import type { AppendedEventWithResult } from '../eventSequences/AppendedEventWithResult.js';
23
15
  import type { EventForEventSourceId } from '../eventSequences/EventForEventSourceId.js';
@@ -28,31 +20,20 @@ import type { ITransactionalEventSequence } from '../eventSequences/ITransaction
28
20
  import type { CompleteStreamResult } from '../eventSequences/CompleteStreamResult.js';
29
21
  import type { IEventImport } from '../imports/IEventImport.js';
30
22
  import type { ImportResult } from '../imports/ImportResult.js';
31
- import { prepareSingleAppend } from '../eventSequences/prepareSingleAppend.js';
32
- import { toContractsGuid } from '../connection/Guid.js';
33
23
  import { getRemovedConstraintNames } from '../events/constraints/removeConstraint.js';
34
24
  import { InProcessConstraints, type WireConstraintViolation } from './InProcessConstraints.js';
35
- import { matchesEventField, supportsEventField } from './EventFieldSchema.js';
25
+ import { supportsEventField } from './EventFieldSchema.js';
26
+ import { InProcessBatchAppend } from './InProcessBatchAppend.js';
27
+ import { InProcessEventPayload } from './InProcessEventPayload.js';
28
+ import { InProcessEventReadFilter } from './InProcessEventReadFilter.js';
29
+ import { InProcessSingleAppend } from './InProcessSingleAppend.js';
30
+ import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
36
31
  import type { EventScenarioOptions } from './EventScenarioOptions.js';
37
32
  import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
38
33
 
39
34
  // JS trim() omits U+0085, which the kernel trims. Reject unproven non-ASCII whitespace and controls.
40
35
  const unprovenFilterCharacters = /[\u007f-\u009f]|(?=[^\x00-\x7f])\p{White_Space}/u;
41
36
 
42
- function resolveStoredSubject(subject: string | undefined, eventSourceId: string): string {
43
- // Match the kernel's string.IsNullOrWhiteSpace, including U+0085 but not U+FEFF.
44
- return subject && !/^\p{White_Space}*$/u.test(subject) ? subject : eventSourceId;
45
- }
46
-
47
- function matchesConstrainedValue(value: unknown, content: unknown): boolean {
48
- // Use production serialization for concepts, not their wrapper object's runtime type.
49
- // Keep rejecting other unproven conversions, such as a Date assigned to a string field.
50
- if (value && typeof value === 'object' && [conceptAsTypeKey, 'Guid'].includes(typeKeyOf(value.constructor as Constructor) ?? '')) {
51
- return JsonSerializer.serialize(value) === JSON.stringify(content);
52
- }
53
- return value === content;
54
- }
55
-
56
37
  // Observers ReactorScenario registers to latch unsupported operations, keyed by sequence.
57
38
  const unsupportedObservers = new WeakMap<object, (error: UnsupportedEventSequenceOperation) => void>();
58
39
 
@@ -75,6 +56,9 @@ export class InProcessEventSequence implements IEventSequence {
75
56
  private readonly _namespace: string;
76
57
  private readonly _clock: () => Date;
77
58
  private readonly _correlationId?: () => string;
59
+ private readonly _payload: InProcessEventPayload;
60
+ private readonly _singleAppend: InProcessSingleAppend;
61
+ private readonly _batchAppend: InProcessBatchAppend;
78
62
  private _setup = false;
79
63
  private _allowSeedAppend = false;
80
64
  private _stagedSeeds?: AppendedEvent[];
@@ -132,6 +116,14 @@ export class InProcessEventSequence implements IEventSequence {
132
116
  }
133
117
  this._catalog.set(type, metadata);
134
118
  }
119
+ const environment: InProcessEventSequenceEnvironment = {
120
+ catalog: this._catalog, store: this._store, namespace: this._namespace, sequenceId: this.id.value,
121
+ clock: () => this._clock(), correlationId: this._correlationId ? () => this._correlationId!() : undefined,
122
+ unsupported: (operation, artifact, reason) => this.unsupported(operation, artifact, reason)
123
+ };
124
+ this._payload = new InProcessEventPayload(environment, this._constraints);
125
+ this._singleAppend = new InProcessSingleAppend(environment, this._payload);
126
+ this._batchAppend = new InProcessBatchAppend(environment, this._payload, (sequence, artifact) => this.success(sequence, artifact));
135
127
  }
136
128
 
137
129
  get results(): readonly AppendResult[] { return Object.freeze([...this._results]); }
@@ -169,72 +161,17 @@ export class InProcessEventSequence implements IEventSequence {
169
161
  get transactional(): ITransactionalEventSequence { throw this.unsupported('transactional', this.id.value, 'Transactions require a kernel.'); }
170
162
 
171
163
  async append(eventSourceId: string, event: object, options?: AppendOptions): Promise<AppendResult> {
172
- if (this._busy || (this._setup && !this._allowSeedAppend)) {
164
+ if (this.appendBusy()) {
173
165
  throw this.unsupported('append', this.id.value, 'Overlapping calls do not have proven ordering.');
174
166
  }
175
167
  this._busy = true;
176
168
  try {
177
- if (!event || typeof event !== 'object') throw this.unsupported('append.event', this.id.value, 'Only registered event instances are supported.');
178
- if (!/^[A-Za-z0-9_-]+$/.test(eventSourceId)) throw this.unsupported('append.source', eventSourceId, 'Only simple source identifiers are fixture-backed.');
179
- const route = singleAppendRoute(options, event.constructor.name, (operation, artifact, reason) => this.unsupported(operation, artifact, reason), true);
180
- const metadata = this._catalog.get(event.constructor);
181
- if (!metadata) throw this.unsupported('append.event', event.constructor.name, 'Event is not in the selected, validated catalog.');
182
- let prepared: ReturnType<typeof prepareSingleAppend>;
183
- let content: Record<string, unknown>;
184
- try {
185
- prepared = prepareSingleAppend(event, { subject: options?.subject, correlationId: this._correlationId?.() });
186
- content = this.checkedContent(event, prepared.content, 'append.content',
187
- 'Content differs from the event schema; null, missing and extra values are not proven.');
188
- } catch (error) {
189
- if (error instanceof UnsupportedEventSequenceOperation) throw error;
190
- throw this.unsupported('append.serialization', event.constructor.name, `Payload or metadata could not be serialized: ${String(error)}.`);
191
- }
192
- try {
193
- toContractsGuid(prepared.correlationId);
194
- if (!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(prepared.correlationId.toString())) throw new Error('Invalid correlation ID.');
195
- } catch {
196
- throw this.unsupported('append.correlationId', event.constructor.name, 'Correlation ID must be a valid GUID.');
197
- }
198
- if (prepared.identity !== Identity.system || prepared.causationChain.length !== 2 ||
199
- Object.keys(prepared.causationChain[0].properties).length !== 0) {
200
- throw this.unsupported('append.context', event.constructor.name, 'Ambient identity or causation metadata is not fixture-backed.');
201
- }
202
- const occurred = this._clock();
203
- // Date has millisecond precision; only the UTC year range representable by DateTimeOffset is supported.
204
- if (!(occurred instanceof Date) || Number.isNaN(occurred.getTime()) ||
205
- occurred.getUTCFullYear() < 1 || occurred.getUTCFullYear() > 9999) {
206
- throw this.unsupported('append.clock', event.constructor.name, 'Clock must return a valid Date within UTC years 1–9999 (millisecond precision).');
207
- }
208
- const canonical = Object.fromEntries(Object.entries(content).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
209
- const hash = createHash('sha256').update(`${prepared.eventType.id.value}|${eventSourceId}|${JSON.stringify(canonical)}`).digest('base64');
210
- const sequenceNumber = new EventSequenceNumber(BigInt(this._history.length + (this._stagedSeeds?.length ?? 0)));
211
- const stored: AppendedEvent = {
212
- eventType: prepared.eventType,
213
- content,
214
- context: {
215
- eventStore: this._store, namespace: this._namespace,
216
- sequenceNumber: sequenceNumber.value, eventSourceId,
217
- eventSourceType: route.sourceType, eventStreamType: route.streamType, eventStreamId: route.streamId,
218
- subject: resolveStoredSubject(prepared.subject, eventSourceId), hash, causedBy: prepared.identity, observationState: EventObservationState.Initial,
219
- eventType: prepared.eventType, occurred, correlationId: prepared.correlationId.toString(),
220
- causation: prepared.causationChain.map(item => ({ type: item.type.name, occurred: item.occurred, properties: { ...item.properties } })),
221
- tags: prepared.tags.map(tag => new Tag(tag)),
222
- namedTags: []
223
- }
224
- };
169
+ const { prepared, stored, sequenceNumber } = this._singleAppend.prepare(eventSourceId, event, options,
170
+ this._history.length + (this._stagedSeeds?.length ?? 0));
225
171
  const violations = this.validateConstraints([...this._history, ...(this._stagedSeeds ?? [])], [stored]);
226
172
  const result = violations.length ? this.rejected(violations) : this.success(sequenceNumber, event.constructor.name);
227
- if (result.isSuccess) {
228
- if (this._stagedSeeds) this._stagedSeeds.push(this.snapshot(stored));
229
- else this._history.push(this.snapshot(stored));
230
- }
231
- if (!this._setup) this._results.push(result);
232
- if (this._stagedNotifications || this.appendOperations.hasSubscribers) {
233
- const notification = [createAppendNotification(eventSourceId, event, result,
234
- prepared.correlationId.toString(), mapAppendNotificationCausation(prepared.causationChain), prepared.tags)];
235
- if (this._stagedNotifications) this._stagedNotifications.push(notification);
236
- else this.appendOperations.publish(notification);
237
- }
173
+ this.commitSingle(stored, result);
174
+ this.notifySingle(eventSourceId, event, result, prepared);
238
175
  return result;
239
176
  } finally {
240
177
  // Keep the append in flight until its promise crosses an async boundary.
@@ -243,94 +180,35 @@ export class InProcessEventSequence implements IEventSequence {
243
180
  }
244
181
  }
245
182
 
183
+ private appendBusy(): boolean {
184
+ return this._busy || (this._setup && !this._allowSeedAppend);
185
+ }
186
+
187
+ private commitSingle(stored: AppendedEvent, result: AppendResult): void {
188
+ if (result.isSuccess) {
189
+ if (this._stagedSeeds) this._stagedSeeds.push(this.snapshot(stored));
190
+ else this._history.push(this.snapshot(stored));
191
+ }
192
+ if (!this._setup) this._results.push(result);
193
+ }
194
+
195
+ private notifySingle(eventSourceId: string, event: object, result: AppendResult, prepared: ReturnType<InProcessSingleAppend['prepare']>['prepared']): void {
196
+ if (this._stagedNotifications || this.appendOperations.hasSubscribers) {
197
+ const notification = [createAppendNotification(eventSourceId, event, result,
198
+ prepared.correlationId.toString(), mapAppendNotificationCausation(prepared.causationChain), prepared.tags)];
199
+ if (this._stagedNotifications) this._stagedNotifications.push(notification);
200
+ else this.appendOperations.publish(notification);
201
+ }
202
+ }
203
+
246
204
  appendMany(eventSourceId: string, events: object[], options?: AppendOptions): Promise<AppendResult[]>;
247
205
  appendMany(events: EventForEventSourceId[], options?: AppendOptions): Promise<AppendResult[]>;
248
206
  async appendMany(sourceOrEvents: string | EventForEventSourceId[], eventsOrOptions?: object[] | AppendOptions, options?: AppendOptions): Promise<AppendResult[]> {
249
207
  if (this._busy || this._setup) throw this.unsupported('appendMany', this.id.value, 'Overlapping calls do not have proven ordering.');
250
208
  this._busy = true;
251
209
  try {
252
- const entries = typeof sourceOrEvents === 'string' ? eventsOrOptions as object[] : sourceOrEvents;
253
- const shared = typeof sourceOrEvents === 'string' ? options : eventsOrOptions as AppendOptions | undefined;
254
- if (!Array.isArray(entries)) throw this.unsupported('appendMany.arguments', this.id.value, 'Events must be an array.');
255
- if (!entries.length) throw this.unsupported('appendMany.empty', this.id.value, 'The kernel rejects an empty batch.');
256
- this.validateBatchOptions(shared);
257
- if (shared?.occurred !== undefined) this.checkedDate(shared.occurred, 'appendMany.occurred');
258
- for (const entry of entries) {
259
- if (typeof sourceOrEvents === 'string') break;
260
- if (!entry || typeof entry !== 'object' || Reflect.ownKeys(entry).some(key =>
261
- !['eventSourceId', 'event', 'eventSourceType', 'eventStreamType', 'eventStreamId', 'subject', 'occurred', 'tags', 'namedTags'].includes(String(key)))) {
262
- throw this.unsupported('appendMany.entry', this.id.value, 'Unrecognized per-entry metadata.');
263
- }
264
- const individual = entry as EventForEventSourceId;
265
- if (hasNamedTags(individual.namedTags)) {
266
- throw this.unsupported('appendMany.namedTags', this.id.value, 'Named tags are not fixture-backed.');
267
- }
268
- if (individual.occurred !== undefined) this.checkedDate(individual.occurred, 'appendMany.occurred');
269
- if (individual.subject !== undefined && individual.subject !== null && typeof individual.subject !== 'string') {
270
- throw this.unsupported('appendMany.subject', this.id.value, 'Subject must be a string.');
271
- }
272
- const tags = individual.tags;
273
- if (tags && (!Array.isArray(tags) || tags.some(tag => typeof tag !== 'string'))) {
274
- throw this.unsupported('appendMany.tags', this.id.value, 'Only plain string tags are fixture-backed.');
275
- }
276
- }
277
- let prepared: ReturnType<typeof prepareBatchAppend>;
278
- try {
279
- const batchOptions: AppendOptions | undefined = shared?.correlationId === undefined && this._correlationId
280
- ? { correlationId: this._correlationId(), sourceType: shared?.sourceType, streamType: shared?.streamType,
281
- streamId: shared?.streamId, subject: shared?.subject, occurred: shared?.occurred, tags: shared?.tags,
282
- namedTags: shared?.namedTags }
283
- : shared;
284
- if (batchOptions?.correlationId !== undefined) this.validateGuid(batchOptions.correlationId, 'appendMany.correlationId');
285
- prepared = typeof sourceOrEvents === 'string'
286
- ? prepareBatchAppend(sourceOrEvents, entries as object[], batchOptions)
287
- : prepareBatchAppend(sourceOrEvents, batchOptions);
288
- } catch (error) {
289
- if (error instanceof UnsupportedEventSequenceOperation) throw error;
290
- throw this.unsupported('appendMany.serialization', this.id.value, `Batch preparation failed: ${String(error)}.`);
291
- }
292
- const { eventsForEventSourceIds, eventsToAppend, correlationId, batchCausationChain, identity } = prepared;
293
- this.validateGuid(correlationId, 'appendMany.correlationId');
294
- if (identity !== Identity.system || batchCausationChain.length !== 2 ||
295
- Object.keys(batchCausationChain[0].properties).length !== 0 ||
296
- batchCausationChain[1].type.name !== 'TypeScriptClient.AppendMany' ||
297
- batchCausationChain[1].properties.count !== String(entries.length)) {
298
- throw this.unsupported('appendMany.context', this.id.value, 'Ambient identity or causation metadata is not fixture-backed.');
299
- }
300
- const staged = eventsForEventSourceIds.map(({ eventSourceId, event }, index) => {
301
- if (!event || typeof event !== 'object' || !this._catalog.has(event.constructor)) {
302
- throw this.unsupported('appendMany.event', event?.constructor?.name ?? this.id.value, 'Event is not in the selected catalog.');
303
- }
304
- this.validateSource(eventSourceId, 'appendMany.source');
305
- const wire = eventsToAppend[index];
306
- for (const [name, value] of Object.entries({ sourceType: wire.EventSourceType, streamType: wire.EventStreamType,
307
- streamId: wire.EventStreamId })) {
308
- const identifiers = /^[A-Za-z0-9_-]*$/;
309
- if (value !== undefined && (typeof value !== 'string' || !identifiers.test(value))) {
310
- throw this.unsupported(`appendMany.${name}`, String(value), 'Only simple metadata identifiers are fixture-backed.');
311
- }
312
- }
313
- if (wire.Tags.some(tag => !/^[A-Za-z0-9_-]+$/.test(tag))) {
314
- throw this.unsupported('appendMany.tags', event.constructor.name, 'Only simple string tags are fixture-backed.');
315
- }
316
- const occurred = wire.Occurred ? this.checkedDate(new Date(wire.Occurred.Value), 'appendMany.occurred')
317
- : this.checkedDate(this._clock(), 'appendMany.clock');
318
- const content = this.checkedContent(event, wire.Content, 'appendMany.content');
319
- const canonical = Object.fromEntries(Object.entries(content).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
320
- const hash = createHash('sha256').update(`${wire.EventType.Id}|${eventSourceId}|${JSON.stringify(canonical)}`).digest('base64');
321
- const sequenceNumber = new EventSequenceNumber(BigInt(this._history.length + index));
322
- const eventType = getEventTypeFor(event.constructor);
323
- const stored: AppendedEvent = { eventType, content, context: {
324
- eventStore: this._store, namespace: this._namespace, sequenceNumber: sequenceNumber.value, eventSourceId,
325
- eventSourceType: wire.EventSourceType || 'Default', eventStreamType: wire.EventStreamType || 'All',
326
- eventStreamId: wire.EventStreamId || 'Default', subject: resolveStoredSubject(wire.Subject, eventSourceId), hash, causedBy: identity,
327
- observationState: EventObservationState.Initial, eventType, occurred, correlationId: correlationId.toString(),
328
- causation: batchCausationChain.map(item => ({ type: item.type.name, occurred: item.occurred, properties: { ...item.properties } })),
329
- tags: wire.Tags.map(tag => new Tag(tag)),
330
- namedTags: []
331
- } };
332
- return { stored, result: this.success(sequenceNumber, event.constructor.name) };
333
- });
210
+ const { prepared, staged } = this._batchAppend.prepare(sourceOrEvents, eventsOrOptions, options, this._history.length);
211
+ const { eventsForEventSourceIds, eventsToAppend, correlationId, batchCausationChain } = prepared;
334
212
  // The kernel validates the entire batch before persisting any events or allocating sequences.
335
213
  const violations = this.validateConstraints(this._history, staged.map(item => item.stored));
336
214
  const results = violations.length ? staged.map(() => this.rejected(violations)) : staged.map(item => item.result);
@@ -355,12 +233,8 @@ export class InProcessEventSequence implements IEventSequence {
355
233
  async getTailSequenceNumber(source?: string, sourceType?: string, streamType?: string, streamId?: string, types?: Constructor[]): Promise<EventSequenceNumber> {
356
234
  if (source !== undefined) this.validateReadSource('getTailSequenceNumber.source', source);
357
235
  this.validateRouteFilters('getTailSequenceNumber.filters', sourceType, streamType, streamId);
358
- const ids = this.filterIds(types);
359
- const last = [...this._history].reverse().find(event => (source === undefined || event.context.eventSourceId === source) &&
360
- (sourceType === undefined || sourceType === 'Default' || event.context.eventSourceType === sourceType) &&
361
- (streamType === undefined || streamType === 'All' || event.context.eventStreamType === streamType) &&
362
- (streamId === undefined || streamId === 'Default' || event.context.eventStreamId === streamId) &&
363
- (!ids.length || ids.includes(event.eventType.id.value)));
236
+ const filter = new InProcessEventReadFilter({ source, sourceType, streamType, streamId, ids: this.filterIds(types) });
237
+ const last = [...this._history].reverse().find(event => filter.matches(event));
364
238
  return last ? new EventSequenceNumber(last.context.sequenceNumber) : EventSequenceNumber.unset;
365
239
  }
366
240
 
@@ -377,11 +251,8 @@ export class InProcessEventSequence implements IEventSequence {
377
251
  if (!types.length) throw this.unsupported('getForEventSourceIdAndEventTypes.filters', source, 'Explicit event types are required.');
378
252
  this.validateReadSource('getForEventSourceIdAndEventTypes.source', source);
379
253
  this.validateRouteFilters('getForEventSourceIdAndEventTypes.filters', sourceType, streamType, streamId);
380
- const ids = this.filterIds(types);
381
- return this._history.filter(event => event.context.eventSourceId === source && ids.includes(event.eventType.id.value) &&
382
- (sourceType === undefined || sourceType === 'Default' || event.context.eventSourceType === sourceType) &&
383
- (streamType === undefined || streamType === 'All' || event.context.eventStreamType === streamType) &&
384
- (streamId === undefined || streamId === 'Default' || event.context.eventStreamId === streamId)).map(event => this.snapshot(event));
254
+ const filter = new InProcessEventReadFilter({ source, sourceType, streamType, streamId, ids: this.filterIds(types) });
255
+ return this._history.filter(event => filter.matches(event)).map(event => this.snapshot(event));
385
256
  }
386
257
 
387
258
  async getFromSequenceNumber(sequence: EventSequenceNumber, source?: string, types?: Constructor[]): Promise<AppendedEvent[]> {
@@ -389,10 +260,8 @@ export class InProcessEventSequence implements IEventSequence {
389
260
  throw this.unsupported('getFromSequenceNumber.sequenceNumber', sequence.value.toString(), 'Sequence numbers must fit unsigned 64-bit wire values.');
390
261
  }
391
262
  if (source !== undefined) this.validateReadSource('getFromSequenceNumber.source', source);
392
- const ids = this.filterIds(types);
393
- return this._history.filter(event => event.context.sequenceNumber >= sequence.value &&
394
- (source === undefined || event.context.eventSourceId === source) &&
395
- (!ids.length || ids.includes(event.eventType.id.value))).map(event => this.snapshot(event));
263
+ const filter = new InProcessEventReadFilter({ source, ids: this.filterIds(types) });
264
+ return this._history.filter(event => event.context.sequenceNumber >= sequence.value && filter.matches(event)).map(event => this.snapshot(event));
396
265
  }
397
266
 
398
267
  async compensate(): Promise<AppendResult> { throw this.unsupported('compensate', this.id.value, 'Compensation requires kernel storage.'); }
@@ -413,70 +282,14 @@ export class InProcessEventSequence implements IEventSequence {
413
282
 
414
283
  private validateRouteFilters(operation: string, ...filters: (string | undefined)[]): void {
415
284
  for (const filter of filters) {
416
- if (filter !== undefined && (typeof filter !== 'string' || !/^[A-Za-z0-9_-]+$/.test(filter))) {
285
+ if (filter !== undefined && !this.simpleRouteFilter(filter)) {
417
286
  throw this.unsupported(operation, String(filter), 'Only simple, nonblank route filters are fixture-backed.');
418
287
  }
419
288
  }
420
289
  }
421
290
 
422
- private validateBatchOptions(options?: AppendOptions): void {
423
- if (options === undefined) return;
424
- if (!options || typeof options !== 'object' || Array.isArray(options)) {
425
- throw this.unsupported('appendMany.options', this.id.value, 'Append options must be an object.');
426
- }
427
- if (hasNamedTags(options.namedTags)) {
428
- throw this.unsupported('appendMany.namedTags', this.id.value, 'Named tags are not fixture-backed.');
429
- }
430
- const allowed = ['correlationId', 'sourceType', 'streamType', 'streamId', 'subject', 'occurred', 'tags', 'namedTags'];
431
- if (Reflect.ownKeys(options).some(key => !allowed.includes(String(key))) ||
432
- options.concurrencyScope !== undefined || options.concurrencyScopes !== undefined || options.eventSourceId !== undefined) {
433
- throw this.unsupported('appendMany.options', this.id.value, 'Concurrency and unrecognized metadata are not fixture-backed.');
434
- }
435
- if (options.subject !== undefined && options.subject !== null && typeof options.subject !== 'string') {
436
- throw this.unsupported('appendMany.subject', this.id.value, 'Subject must be a string.');
437
- }
438
- if (options.tags && (!Array.isArray(options.tags) || options.tags.some(tag => typeof tag !== 'string'))) {
439
- throw this.unsupported('appendMany.tags', this.id.value, 'Only plain string tags are fixture-backed.');
440
- }
441
- }
442
-
443
- private validateGuid(value: string | Guid, operation: string): void {
444
- try {
445
- toContractsGuid(Guid.as(value));
446
- if (!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(value.toString())) throw new Error('Invalid GUID.');
447
- } catch { throw this.unsupported(operation, this.id.value, 'Correlation ID must be a valid GUID.'); }
448
- }
449
-
450
- private checkedDate(value: Date, operation: string): Date {
451
- if (!(value instanceof Date) || Number.isNaN(value.getTime()) || value.getUTCFullYear() < 1 || value.getUTCFullYear() > 9999) {
452
- throw this.unsupported(operation, this.id.value, 'Occurrence must be within UTC years 1–9999 at millisecond precision.');
453
- }
454
- return new Date(value);
455
- }
456
-
457
- private validateSource(source: string, operation: string): void {
458
- if (typeof source !== 'string' || !/^[A-Za-z0-9_-]+$/.test(source)) {
459
- throw this.unsupported(operation, String(source), 'Only simple source identifiers are fixture-backed.');
460
- }
461
- }
462
-
463
- private checkedContent(event: object, serialized: string, operation: string,
464
- mismatchReason = 'Content differs from the event schema.'): Record<string, unknown> {
465
- let content: Record<string, unknown>;
466
- try { content = JSON.parse(serialized) as Record<string, unknown>; }
467
- catch { throw this.unsupported(operation, event.constructor.name, 'Content must be valid JSON.'); }
468
- const metadata = this._catalog.get(event.constructor)!;
469
- const properties = metadata.schema.properties!;
470
- if (!content || typeof content !== 'object' || Array.isArray(content) ||
471
- Object.keys(content).length !== Object.keys(properties).length ||
472
- Object.entries(properties).some(([key, property]) => !Object.hasOwn(content, key) || !matchesEventField(content[key], property) ||
473
- (this._constraints?.isConstrainedProperty(metadata.eventType.id.value, key) &&
474
- !matchesConstrainedValue(Reflect.get(event, key), content[key])) ||
475
- (property.type === 'string' && property.format === undefined &&
476
- !/^[\x20-\x21\x23-\x5b\x5d-\x7e\u00e9]*$/.test(content[key] as string)))) {
477
- throw this.unsupported(operation, event.constructor.name, mismatchReason);
478
- }
479
- return content;
291
+ private simpleRouteFilter(filter: string): boolean {
292
+ return typeof filter === 'string' && /^[A-Za-z0-9_-]+$/.test(filter);
480
293
  }
481
294
 
482
295
  private validateConstraints(history: readonly AppendedEvent[], incoming: readonly AppendedEvent[]): WireConstraintViolation[] {
@@ -499,26 +312,19 @@ export class InProcessEventSequence implements IEventSequence {
499
312
  }
500
313
 
501
314
  private snapshot(event: AppendedEvent): AppendedEvent {
502
- const eventType = new EventType(new EventTypeId(event.eventType.id.value),
503
- new EventTypeGeneration(event.eventType.generation.value), event.eventType.tombstone);
504
- const causedBy = event.context.causedBy;
505
- return {
506
- eventType,
507
- content: JSON.parse(JSON.stringify(event.content)) as Record<string, unknown>,
508
- context: { ...event.context, eventType, occurred: new Date(event.context.occurred),
509
- causedBy: causedBy && new Identity(causedBy.subject, causedBy.name, causedBy.userName, causedBy.onBehalfOf),
510
- causation: event.context.causation.map(item => ({ ...item, occurred: item.occurred && new Date(item.occurred), properties: { ...item.properties } })),
511
- tags: event.context.tags.map(item => new Tag(item.value)),
512
- namedTags: [...(event.context.namedTags ?? [])] }
513
- };
315
+ return this._payload.snapshot(event);
514
316
  }
515
317
 
516
318
  private validateReadSource(operation: string, source: string): void {
517
- if (!source.trim() || source !== source.trim() || unprovenFilterCharacters.test(source)) {
319
+ if (!this.simpleReadSource(source)) {
518
320
  throw this.unsupported(operation, source, 'Blank and padded source filters have unproven kernel normalization.');
519
321
  }
520
322
  }
521
323
 
324
+ private simpleReadSource(source: string): boolean {
325
+ return !!source.trim() && source === source.trim() && !unprovenFilterCharacters.test(source);
326
+ }
327
+
522
328
  private unsupported(operation: string, artifact: string, reason: string): UnsupportedEventSequenceOperation {
523
329
  const error = new UnsupportedEventSequenceOperation(operation, artifact, reason);
524
330
  unsupportedObservers.get(this)?.(error);
@@ -0,0 +1,16 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import type { getEventTypeMetadata } from '../events/eventTypeDecorator.js';
5
+ import type { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
6
+
7
+ /** Scenario-local dependencies used while preparing, but never committing, appends. */
8
+ export interface InProcessEventSequenceEnvironment {
9
+ readonly catalog: ReadonlyMap<Function, ReturnType<typeof getEventTypeMetadata>>;
10
+ readonly store: string;
11
+ readonly namespace: string;
12
+ readonly clock: () => Date;
13
+ readonly correlationId?: () => string;
14
+ readonly unsupported: (operation: string, artifact: string, reason: string) => UnsupportedEventSequenceOperation;
15
+ readonly sequenceId: string;
16
+ }
@@ -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 { toContractsGuid } from '../connection/Guid.js';
5
+ import type { AppendedEvent } from '../events/AppendedEvent.js';
6
+ import { EventObservationState } from '@cratis/chronicle.contracts';
7
+ import { Tag } from '../events/Tag.js';
8
+ import type { AppendOptions } from '../eventSequences/AppendOptions.js';
9
+ import { EventSequenceNumber } from '../eventSequences/EventSequenceNumber.js';
10
+ import { prepareSingleAppend } from '../eventSequences/prepareSingleAppend.js';
11
+ import { InProcessAppendMetadata } from './InProcessAppendMetadata.js';
12
+ import { InProcessEventPayload } from './InProcessEventPayload.js';
13
+ import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
14
+ import { singleAppendRoute } from './singleAppendRoute.js';
15
+ import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
16
+
17
+ /** Prepares one append without allocating history, results, or notifications. */
18
+ export class InProcessSingleAppend {
19
+ private readonly metadata: InProcessAppendMetadata;
20
+
21
+ constructor(private readonly environment: InProcessEventSequenceEnvironment, private readonly payload: InProcessEventPayload) {
22
+ this.metadata = new InProcessAppendMetadata(environment);
23
+ }
24
+
25
+ prepare(eventSourceId: string, event: object, options: AppendOptions | undefined, position: number) {
26
+ this.eventInstance(event);
27
+ if (!/^[A-Za-z0-9_-]+$/.test(eventSourceId)) throw this.environment.unsupported('append.source', eventSourceId, 'Only simple source identifiers are fixture-backed.');
28
+ const route = singleAppendRoute(options, event.constructor.name, this.environment.unsupported, true);
29
+ if (!this.environment.catalog.get(event.constructor)) throw this.environment.unsupported('append.event', event.constructor.name, 'Event is not in the selected, validated catalog.');
30
+ const { prepared, content } = this.serialize(event, options);
31
+ this.correlation(prepared, event);
32
+ this.context(prepared, event);
33
+ const occurred = this.occurred(event);
34
+ const hash = this.payload.hash(prepared.eventType.id.value, eventSourceId, content);
35
+ const sequenceNumber = new EventSequenceNumber(BigInt(position));
36
+ const stored: AppendedEvent = {
37
+ eventType: prepared.eventType,
38
+ content,
39
+ context: {
40
+ eventStore: this.environment.store, namespace: this.environment.namespace,
41
+ sequenceNumber: sequenceNumber.value, eventSourceId,
42
+ eventSourceType: route.sourceType, eventStreamType: route.streamType, eventStreamId: route.streamId,
43
+ subject: this.metadata.storedSubject(prepared.subject, eventSourceId), hash, causedBy: prepared.identity, observationState: EventObservationState.Initial,
44
+ eventType: prepared.eventType, occurred, correlationId: prepared.correlationId.toString(),
45
+ causation: prepared.causationChain.map(item => ({ type: item.type.name, occurred: item.occurred, properties: { ...item.properties } })),
46
+ tags: prepared.tags.map(tag => new Tag(tag)), namedTags: []
47
+ }
48
+ };
49
+ return { prepared, stored, sequenceNumber };
50
+ }
51
+
52
+ private eventInstance(event: object): void {
53
+ if (!event || typeof event !== 'object') throw this.environment.unsupported('append.event', this.environment.sequenceId, 'Only registered event instances are supported.');
54
+ }
55
+
56
+ private serialize(event: object, options?: AppendOptions) {
57
+ try {
58
+ const prepared = prepareSingleAppend(event, this.options(options));
59
+ const content = this.payload.checkedContent(event, prepared.content, 'append.content',
60
+ 'Content differs from the event schema; null, missing and extra values are not proven.');
61
+ return { prepared, content };
62
+ } catch (error) {
63
+ if (error instanceof UnsupportedEventSequenceOperation) throw error;
64
+ throw this.environment.unsupported('append.serialization', event.constructor.name, `Payload or metadata could not be serialized: ${String(error)}.`);
65
+ }
66
+ }
67
+
68
+ private options(options?: AppendOptions): AppendOptions {
69
+ return { subject: options?.subject, correlationId: this.environment.correlationId?.() };
70
+ }
71
+
72
+ private correlation(prepared: ReturnType<typeof prepareSingleAppend>, event: object): void {
73
+ try {
74
+ toContractsGuid(prepared.correlationId);
75
+ if (!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(prepared.correlationId.toString())) throw new Error('Invalid correlation ID.');
76
+ } catch {
77
+ throw this.environment.unsupported('append.correlationId', event.constructor.name, 'Correlation ID must be a valid GUID.');
78
+ }
79
+ }
80
+
81
+ private context(prepared: ReturnType<typeof prepareSingleAppend>, event: object): void {
82
+ if (!this.metadata.ambientContext(prepared.identity, prepared.causationChain)) {
83
+ throw this.environment.unsupported('append.context', event.constructor.name, 'Ambient identity or causation metadata is not fixture-backed.');
84
+ }
85
+ }
86
+
87
+ private occurred(event: object): Date {
88
+ const occurred = this.environment.clock();
89
+ // Date has millisecond precision; only the UTC year range representable by DateTimeOffset is supported.
90
+ if (!(occurred instanceof Date) || !this.validTime(occurred)) {
91
+ throw this.environment.unsupported('append.clock', event.constructor.name, 'Clock must return a valid Date within UTC years 1–9999 (millisecond precision).');
92
+ }
93
+ return occurred;
94
+ }
95
+
96
+ private validTime(value: Date): boolean {
97
+ return !Number.isNaN(value.getTime()) && value.getUTCFullYear() >= 1 && value.getUTCFullYear() <= 9999;
98
+ }
99
+ }