@cratis/chronicle 6.59.0 → 6.60.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 (359) hide show
  1. package/ChronicleClient.ts +1 -1
  2. package/ChronicleOptions.ts +11 -0
  3. package/EventStore.ts +9 -1
  4. package/IEventStore.ts +7 -0
  5. package/README.md +1 -1
  6. package/artifacts/DefaultClientArtifactsProvider.ts +13 -1
  7. package/artifacts/IClientArtifactsProvider.ts +6 -0
  8. package/dist/ChronicleClient.js +1 -1
  9. package/dist/ChronicleClient.js.map +1 -1
  10. package/dist/ChronicleOptions.d.ts +7 -0
  11. package/dist/ChronicleOptions.d.ts.map +1 -1
  12. package/dist/ChronicleOptions.js +8 -0
  13. package/dist/ChronicleOptions.js.map +1 -1
  14. package/dist/EventStore.d.ts +3 -1
  15. package/dist/EventStore.d.ts.map +1 -1
  16. package/dist/EventStore.js +7 -1
  17. package/dist/EventStore.js.map +1 -1
  18. package/dist/IEventStore.d.ts +6 -0
  19. package/dist/IEventStore.d.ts.map +1 -1
  20. package/dist/artifacts/DefaultClientArtifactsProvider.d.ts +4 -0
  21. package/dist/artifacts/DefaultClientArtifactsProvider.d.ts.map +1 -1
  22. package/dist/artifacts/DefaultClientArtifactsProvider.js +11 -1
  23. package/dist/artifacts/DefaultClientArtifactsProvider.js.map +1 -1
  24. package/dist/artifacts/IClientArtifactsProvider.d.ts +4 -0
  25. package/dist/artifacts/IClientArtifactsProvider.d.ts.map +1 -1
  26. package/dist/projections/Projections.d.ts.map +1 -1
  27. package/dist/projections/Projections.js +3 -30
  28. package/dist/projections/Projections.js.map +1 -1
  29. package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts +29 -0
  30. package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts.map +1 -0
  31. package/dist/projections/for_Graphs/given/a_discovered_graph.js +19 -0
  32. package/dist/projections/for_Graphs/given/a_discovered_graph.js.map +1 -0
  33. package/dist/projections/for_Graphs/given/a_fake_connection.d.ts +24 -0
  34. package/dist/projections/for_Graphs/given/a_fake_connection.d.ts.map +1 -0
  35. package/dist/projections/for_Graphs/given/a_fake_connection.js +17 -0
  36. package/dist/projections/for_Graphs/given/a_fake_connection.js.map +1 -0
  37. package/dist/projections/for_Graphs/given/organization.d.ts +43 -0
  38. package/dist/projections/for_Graphs/given/organization.d.ts.map +1 -0
  39. package/dist/projections/for_Graphs/given/organization.js +84 -0
  40. package/dist/projections/for_Graphs/given/organization.js.map +1 -0
  41. package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.d.ts +11 -0
  42. package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.d.ts.map +1 -0
  43. package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.js +16 -0
  44. package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.js.map +1 -0
  45. package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.d.ts +11 -0
  46. package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.d.ts.map +1 -0
  47. package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.js +16 -0
  48. package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.js.map +1 -0
  49. package/dist/projections/graphs/GraphDeclaredMoreThanOnce.d.ts +11 -0
  50. package/dist/projections/graphs/GraphDeclaredMoreThanOnce.d.ts.map +1 -0
  51. package/dist/projections/graphs/GraphDeclaredMoreThanOnce.js +16 -0
  52. package/dist/projections/graphs/GraphDeclaredMoreThanOnce.js.map +1 -0
  53. package/dist/projections/graphs/GraphDefinitionBuilder.d.ts +24 -0
  54. package/dist/projections/graphs/GraphDefinitionBuilder.d.ts.map +1 -0
  55. package/dist/projections/graphs/GraphDefinitionBuilder.js +145 -0
  56. package/dist/projections/graphs/GraphDefinitionBuilder.js.map +1 -0
  57. package/dist/projections/graphs/GraphEdgeBuilder.d.ts +41 -0
  58. package/dist/projections/graphs/GraphEdgeBuilder.d.ts.map +1 -0
  59. package/dist/projections/graphs/GraphEdgeBuilder.js +94 -0
  60. package/dist/projections/graphs/GraphEdgeBuilder.js.map +1 -0
  61. package/dist/projections/graphs/GraphEdgeFromBuilder.d.ts +25 -0
  62. package/dist/projections/graphs/GraphEdgeFromBuilder.d.ts.map +1 -0
  63. package/dist/projections/graphs/GraphEdgeFromBuilder.js +37 -0
  64. package/dist/projections/graphs/GraphEdgeFromBuilder.js.map +1 -0
  65. package/dist/projections/graphs/GraphEdgeFromModel.d.ts +16 -0
  66. package/dist/projections/graphs/GraphEdgeFromModel.d.ts.map +1 -0
  67. package/dist/projections/graphs/GraphEdgeFromModel.js +4 -0
  68. package/dist/projections/graphs/GraphEdgeFromModel.js.map +1 -0
  69. package/dist/projections/graphs/GraphEdgeModel.d.ts +24 -0
  70. package/dist/projections/graphs/GraphEdgeModel.d.ts.map +1 -0
  71. package/dist/projections/graphs/GraphEdgeModel.js +4 -0
  72. package/dist/projections/graphs/GraphEdgeModel.js.map +1 -0
  73. package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.d.ts +21 -0
  74. package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.d.ts.map +1 -0
  75. package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.js +31 -0
  76. package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.js.map +1 -0
  77. package/dist/projections/graphs/GraphEdgeRemovedWithModel.d.ts +14 -0
  78. package/dist/projections/graphs/GraphEdgeRemovedWithModel.d.ts.map +1 -0
  79. package/dist/projections/graphs/GraphEdgeRemovedWithModel.js +4 -0
  80. package/dist/projections/graphs/GraphEdgeRemovedWithModel.js.map +1 -0
  81. package/dist/projections/graphs/GraphElementCannotBeReadModel.d.ts +11 -0
  82. package/dist/projections/graphs/GraphElementCannotBeReadModel.d.ts.map +1 -0
  83. package/dist/projections/graphs/GraphElementCannotBeReadModel.js +16 -0
  84. package/dist/projections/graphs/GraphElementCannotBeReadModel.js.map +1 -0
  85. package/dist/projections/graphs/GraphHasDuplicateElement.d.ts +13 -0
  86. package/dist/projections/graphs/GraphHasDuplicateElement.d.ts.map +1 -0
  87. package/dist/projections/graphs/GraphHasDuplicateElement.js +18 -0
  88. package/dist/projections/graphs/GraphHasDuplicateElement.js.map +1 -0
  89. package/dist/projections/graphs/GraphKeyPropertyNotFound.d.ts +12 -0
  90. package/dist/projections/graphs/GraphKeyPropertyNotFound.d.ts.map +1 -0
  91. package/dist/projections/graphs/GraphKeyPropertyNotFound.js +17 -0
  92. package/dist/projections/graphs/GraphKeyPropertyNotFound.js.map +1 -0
  93. package/dist/projections/graphs/GraphMappingBuilder.d.ts +32 -0
  94. package/dist/projections/graphs/GraphMappingBuilder.d.ts.map +1 -0
  95. package/dist/projections/graphs/GraphMappingBuilder.js +48 -0
  96. package/dist/projections/graphs/GraphMappingBuilder.js.map +1 -0
  97. package/dist/projections/graphs/GraphMemberMappings.d.ts +8 -0
  98. package/dist/projections/graphs/GraphMemberMappings.d.ts.map +1 -0
  99. package/dist/projections/graphs/GraphMemberMappings.js +54 -0
  100. package/dist/projections/graphs/GraphMemberMappings.js.map +1 -0
  101. package/dist/projections/graphs/GraphModel.d.ts +15 -0
  102. package/dist/projections/graphs/GraphModel.d.ts.map +1 -0
  103. package/dist/projections/graphs/GraphModel.js +4 -0
  104. package/dist/projections/graphs/GraphModel.js.map +1 -0
  105. package/dist/projections/graphs/GraphNameRequired.d.ts +11 -0
  106. package/dist/projections/graphs/GraphNameRequired.d.ts.map +1 -0
  107. package/dist/projections/graphs/GraphNameRequired.js +16 -0
  108. package/dist/projections/graphs/GraphNameRequired.js.map +1 -0
  109. package/dist/projections/graphs/GraphNodeBuilder.d.ts +34 -0
  110. package/dist/projections/graphs/GraphNodeBuilder.d.ts.map +1 -0
  111. package/dist/projections/graphs/GraphNodeBuilder.js +66 -0
  112. package/dist/projections/graphs/GraphNodeBuilder.js.map +1 -0
  113. package/dist/projections/graphs/GraphNodeFromBuilder.d.ts +21 -0
  114. package/dist/projections/graphs/GraphNodeFromBuilder.d.ts.map +1 -0
  115. package/dist/projections/graphs/GraphNodeFromBuilder.js +30 -0
  116. package/dist/projections/graphs/GraphNodeFromBuilder.js.map +1 -0
  117. package/dist/projections/graphs/GraphNodeFromModel.d.ts +14 -0
  118. package/dist/projections/graphs/GraphNodeFromModel.d.ts.map +1 -0
  119. package/dist/projections/graphs/GraphNodeFromModel.js +4 -0
  120. package/dist/projections/graphs/GraphNodeFromModel.js.map +1 -0
  121. package/dist/projections/graphs/GraphNodeModel.d.ts +18 -0
  122. package/dist/projections/graphs/GraphNodeModel.d.ts.map +1 -0
  123. package/dist/projections/graphs/GraphNodeModel.js +4 -0
  124. package/dist/projections/graphs/GraphNodeModel.js.map +1 -0
  125. package/dist/projections/graphs/GraphNodeRemovedWithBuilder.d.ts +17 -0
  126. package/dist/projections/graphs/GraphNodeRemovedWithBuilder.d.ts.map +1 -0
  127. package/dist/projections/graphs/GraphNodeRemovedWithBuilder.js +24 -0
  128. package/dist/projections/graphs/GraphNodeRemovedWithBuilder.js.map +1 -0
  129. package/dist/projections/graphs/GraphNodeRemovedWithModel.d.ts +12 -0
  130. package/dist/projections/graphs/GraphNodeRemovedWithModel.d.ts.map +1 -0
  131. package/dist/projections/graphs/GraphNodeRemovedWithModel.js +4 -0
  132. package/dist/projections/graphs/GraphNodeRemovedWithModel.js.map +1 -0
  133. package/dist/projections/graphs/GraphProjectionBuilder.d.ts +25 -0
  134. package/dist/projections/graphs/GraphProjectionBuilder.d.ts.map +1 -0
  135. package/dist/projections/graphs/GraphProjectionBuilder.js +36 -0
  136. package/dist/projections/graphs/GraphProjectionBuilder.js.map +1 -0
  137. package/dist/projections/graphs/GraphRegistration.d.ts +14 -0
  138. package/dist/projections/graphs/GraphRegistration.d.ts.map +1 -0
  139. package/dist/projections/graphs/GraphRegistration.js +4 -0
  140. package/dist/projections/graphs/GraphRegistration.js.map +1 -0
  141. package/dist/projections/graphs/GraphSchemaWriter.d.ts +28 -0
  142. package/dist/projections/graphs/GraphSchemaWriter.d.ts.map +1 -0
  143. package/dist/projections/graphs/GraphSchemaWriter.js +76 -0
  144. package/dist/projections/graphs/GraphSchemaWriter.js.map +1 -0
  145. package/dist/projections/graphs/Graphs.d.ts +39 -0
  146. package/dist/projections/graphs/Graphs.d.ts.map +1 -0
  147. package/dist/projections/graphs/Graphs.js +144 -0
  148. package/dist/projections/graphs/Graphs.js.map +1 -0
  149. package/dist/projections/graphs/IGraphEdgeBuilder.d.ts +37 -0
  150. package/dist/projections/graphs/IGraphEdgeBuilder.d.ts.map +1 -0
  151. package/dist/projections/graphs/IGraphEdgeBuilder.js +4 -0
  152. package/dist/projections/graphs/IGraphEdgeBuilder.js.map +1 -0
  153. package/dist/projections/graphs/IGraphEdgeFromBuilder.d.ts +29 -0
  154. package/dist/projections/graphs/IGraphEdgeFromBuilder.d.ts.map +1 -0
  155. package/dist/projections/graphs/IGraphEdgeFromBuilder.js +4 -0
  156. package/dist/projections/graphs/IGraphEdgeFromBuilder.js.map +1 -0
  157. package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.d.ts +27 -0
  158. package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.d.ts.map +1 -0
  159. package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.js +4 -0
  160. package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.js.map +1 -0
  161. package/dist/projections/graphs/IGraphMappingBuilder.d.ts +49 -0
  162. package/dist/projections/graphs/IGraphMappingBuilder.d.ts.map +1 -0
  163. package/dist/projections/graphs/IGraphMappingBuilder.js +4 -0
  164. package/dist/projections/graphs/IGraphMappingBuilder.js.map +1 -0
  165. package/dist/projections/graphs/IGraphNodeBuilder.d.ts +32 -0
  166. package/dist/projections/graphs/IGraphNodeBuilder.d.ts.map +1 -0
  167. package/dist/projections/graphs/IGraphNodeBuilder.js +4 -0
  168. package/dist/projections/graphs/IGraphNodeBuilder.js.map +1 -0
  169. package/dist/projections/graphs/IGraphNodeFromBuilder.d.ts +21 -0
  170. package/dist/projections/graphs/IGraphNodeFromBuilder.d.ts.map +1 -0
  171. package/dist/projections/graphs/IGraphNodeFromBuilder.js +4 -0
  172. package/dist/projections/graphs/IGraphNodeFromBuilder.js.map +1 -0
  173. package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.d.ts +19 -0
  174. package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.d.ts.map +1 -0
  175. package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.js +4 -0
  176. package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.js.map +1 -0
  177. package/dist/projections/graphs/IGraphProjection.d.ts +13 -0
  178. package/dist/projections/graphs/IGraphProjection.d.ts.map +1 -0
  179. package/dist/projections/graphs/IGraphProjection.js +4 -0
  180. package/dist/projections/graphs/IGraphProjection.js.map +1 -0
  181. package/dist/projections/graphs/IGraphProjectionBuilder.d.ts +26 -0
  182. package/dist/projections/graphs/IGraphProjectionBuilder.d.ts.map +1 -0
  183. package/dist/projections/graphs/IGraphProjectionBuilder.js +4 -0
  184. package/dist/projections/graphs/IGraphProjectionBuilder.js.map +1 -0
  185. package/dist/projections/graphs/IGraphs.d.ts +27 -0
  186. package/dist/projections/graphs/IGraphs.d.ts.map +1 -0
  187. package/dist/projections/graphs/IGraphs.js +4 -0
  188. package/dist/projections/graphs/IGraphs.js.map +1 -0
  189. package/dist/projections/graphs/ModelBoundGraphReader.d.ts +30 -0
  190. package/dist/projections/graphs/ModelBoundGraphReader.d.ts.map +1 -0
  191. package/dist/projections/graphs/ModelBoundGraphReader.js +112 -0
  192. package/dist/projections/graphs/ModelBoundGraphReader.js.map +1 -0
  193. package/dist/projections/graphs/NestedObjectInGraph.d.ts +12 -0
  194. package/dist/projections/graphs/NestedObjectInGraph.d.ts.map +1 -0
  195. package/dist/projections/graphs/NestedObjectInGraph.js +17 -0
  196. package/dist/projections/graphs/NestedObjectInGraph.js.map +1 -0
  197. package/dist/projections/graphs/NodeMustHaveExactlyOneKey.d.ts +12 -0
  198. package/dist/projections/graphs/NodeMustHaveExactlyOneKey.d.ts.map +1 -0
  199. package/dist/projections/graphs/NodeMustHaveExactlyOneKey.js +17 -0
  200. package/dist/projections/graphs/NodeMustHaveExactlyOneKey.js.map +1 -0
  201. package/dist/projections/graphs/UnknownGraphEventProperty.d.ts +13 -0
  202. package/dist/projections/graphs/UnknownGraphEventProperty.d.ts.map +1 -0
  203. package/dist/projections/graphs/UnknownGraphEventProperty.js +18 -0
  204. package/dist/projections/graphs/UnknownGraphEventProperty.js.map +1 -0
  205. package/dist/projections/graphs/UnknownGraphNode.d.ts +12 -0
  206. package/dist/projections/graphs/UnknownGraphNode.d.ts.map +1 -0
  207. package/dist/projections/graphs/UnknownGraphNode.js +17 -0
  208. package/dist/projections/graphs/UnknownGraphNode.js.map +1 -0
  209. package/dist/projections/graphs/edge.d.ts +23 -0
  210. package/dist/projections/graphs/edge.d.ts.map +1 -0
  211. package/dist/projections/graphs/edge.js +29 -0
  212. package/dist/projections/graphs/edge.js.map +1 -0
  213. package/dist/projections/graphs/edgeFrom.d.ts +31 -0
  214. package/dist/projections/graphs/edgeFrom.d.ts.map +1 -0
  215. package/dist/projections/graphs/edgeFrom.js +26 -0
  216. package/dist/projections/graphs/edgeFrom.js.map +1 -0
  217. package/dist/projections/graphs/edgeRemovedWith.d.ts +22 -0
  218. package/dist/projections/graphs/edgeRemovedWith.d.ts.map +1 -0
  219. package/dist/projections/graphs/edgeRemovedWith.js +25 -0
  220. package/dist/projections/graphs/edgeRemovedWith.js.map +1 -0
  221. package/dist/projections/graphs/edgeSource.d.ts +22 -0
  222. package/dist/projections/graphs/edgeSource.d.ts.map +1 -0
  223. package/dist/projections/graphs/edgeSource.js +30 -0
  224. package/dist/projections/graphs/edgeSource.js.map +1 -0
  225. package/dist/projections/graphs/edgeTarget.d.ts +22 -0
  226. package/dist/projections/graphs/edgeTarget.d.ts.map +1 -0
  227. package/dist/projections/graphs/edgeTarget.js +30 -0
  228. package/dist/projections/graphs/edgeTarget.js.map +1 -0
  229. package/dist/projections/graphs/graph.d.ts +16 -0
  230. package/dist/projections/graphs/graph.d.ts.map +1 -0
  231. package/dist/projections/graphs/graph.js +24 -0
  232. package/dist/projections/graphs/graph.js.map +1 -0
  233. package/dist/projections/graphs/graphKey.d.ts +16 -0
  234. package/dist/projections/graphs/graphKey.d.ts.map +1 -0
  235. package/dist/projections/graphs/graphKey.js +28 -0
  236. package/dist/projections/graphs/graphKey.js.map +1 -0
  237. package/dist/projections/graphs/graphProjection.d.ts +21 -0
  238. package/dist/projections/graphs/graphProjection.d.ts.map +1 -0
  239. package/dist/projections/graphs/graphProjection.js +28 -0
  240. package/dist/projections/graphs/graphProjection.js.map +1 -0
  241. package/dist/projections/graphs/index.d.ts +48 -0
  242. package/dist/projections/graphs/index.d.ts.map +1 -0
  243. package/dist/projections/graphs/index.js +27 -0
  244. package/dist/projections/graphs/index.js.map +1 -0
  245. package/dist/projections/graphs/isGraphElement.d.ts +7 -0
  246. package/dist/projections/graphs/isGraphElement.d.ts.map +1 -0
  247. package/dist/projections/graphs/isGraphElement.js +13 -0
  248. package/dist/projections/graphs/isGraphElement.js.map +1 -0
  249. package/dist/projections/graphs/node.d.ts +22 -0
  250. package/dist/projections/graphs/node.d.ts.map +1 -0
  251. package/dist/projections/graphs/node.js +29 -0
  252. package/dist/projections/graphs/node.js.map +1 -0
  253. package/dist/projections/graphs/nodeFrom.d.ts +31 -0
  254. package/dist/projections/graphs/nodeFrom.d.ts.map +1 -0
  255. package/dist/projections/graphs/nodeFrom.js +26 -0
  256. package/dist/projections/graphs/nodeFrom.js.map +1 -0
  257. package/dist/projections/graphs/nodeRemovedWith.d.ts +28 -0
  258. package/dist/projections/graphs/nodeRemovedWith.d.ts.map +1 -0
  259. package/dist/projections/graphs/nodeRemovedWith.js +25 -0
  260. package/dist/projections/graphs/nodeRemovedWith.js.map +1 -0
  261. package/dist/projections/graphs/propertyPathOf.d.ts +8 -0
  262. package/dist/projections/graphs/propertyPathOf.d.ts.map +1 -0
  263. package/dist/projections/graphs/propertyPathOf.js +14 -0
  264. package/dist/projections/graphs/propertyPathOf.js.map +1 -0
  265. package/dist/projections/index.d.ts +1 -0
  266. package/dist/projections/index.d.ts.map +1 -1
  267. package/dist/projections/index.js +1 -0
  268. package/dist/projections/index.js.map +1 -1
  269. package/dist/projections/registerProjectionWithRetry.d.ts +15 -0
  270. package/dist/projections/registerProjectionWithRetry.d.ts.map +1 -0
  271. package/dist/projections/registerProjectionWithRetry.js +44 -0
  272. package/dist/projections/registerProjectionWithRetry.js.map +1 -0
  273. package/dist/readModels/rootReadModelTypes.d.ts.map +1 -1
  274. package/dist/readModels/rootReadModelTypes.js +3 -1
  275. package/dist/readModels/rootReadModelTypes.js.map +1 -1
  276. package/dist/sinks/WellKnownSinks.d.ts +4 -0
  277. package/dist/sinks/WellKnownSinks.d.ts.map +1 -1
  278. package/dist/sinks/WellKnownSinks.js +5 -1
  279. package/dist/sinks/WellKnownSinks.js.map +1 -1
  280. package/dist/tsconfig.tsbuildinfo +1 -1
  281. package/dist/types/DecoratorType.d.ts +5 -1
  282. package/dist/types/DecoratorType.d.ts.map +1 -1
  283. package/dist/types/DecoratorType.js +4 -0
  284. package/dist/types/DecoratorType.js.map +1 -1
  285. package/for_ChronicleOptions/when_configuring_the_graph_sink/with_graph_sink_type.spec.ts +22 -0
  286. package/package.json +3 -3
  287. package/projections/Projections.ts +4 -29
  288. package/projections/for_Graphs/given/a_discovered_graph.ts +21 -0
  289. package/projections/for_Graphs/given/a_fake_connection.ts +19 -0
  290. package/projections/for_Graphs/given/organization.ts +96 -0
  291. package/projections/for_Graphs/when_building_a_fluent_graph.spec.ts +112 -0
  292. package/projections/for_Graphs/when_building_a_model_bound_graph.spec.ts +91 -0
  293. package/projections/for_Graphs/when_declaring_an_edge_with_an_identity.spec.ts +137 -0
  294. package/projections/for_Graphs/when_declaring_an_invalid_graph.spec.ts +199 -0
  295. package/projections/for_Graphs/when_declaring_with_standard_decorators.standard.spec.ts +92 -0
  296. package/projections/for_Graphs/when_discovering_graph_elements.spec.ts +32 -0
  297. package/projections/for_Graphs/when_mapping_properties.spec.ts +159 -0
  298. package/projections/for_Graphs/when_registering_graphs.spec.ts +56 -0
  299. package/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.ts +16 -0
  300. package/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.ts +16 -0
  301. package/projections/graphs/GraphDeclaredMoreThanOnce.ts +16 -0
  302. package/projections/graphs/GraphDefinitionBuilder.ts +166 -0
  303. package/projections/graphs/GraphEdgeBuilder.ts +107 -0
  304. package/projections/graphs/GraphEdgeFromBuilder.ts +47 -0
  305. package/projections/graphs/GraphEdgeFromModel.ts +22 -0
  306. package/projections/graphs/GraphEdgeModel.ts +34 -0
  307. package/projections/graphs/GraphEdgeRemovedWithBuilder.ts +39 -0
  308. package/projections/graphs/GraphEdgeRemovedWithModel.ts +19 -0
  309. package/projections/graphs/GraphElementCannotBeReadModel.ts +16 -0
  310. package/projections/graphs/GraphHasDuplicateElement.ts +18 -0
  311. package/projections/graphs/GraphKeyPropertyNotFound.ts +17 -0
  312. package/projections/graphs/GraphMappingBuilder.ts +65 -0
  313. package/projections/graphs/GraphMemberMappings.ts +57 -0
  314. package/projections/graphs/GraphModel.ts +20 -0
  315. package/projections/graphs/GraphNameRequired.ts +16 -0
  316. package/projections/graphs/GraphNodeBuilder.ts +76 -0
  317. package/projections/graphs/GraphNodeFromBuilder.ts +38 -0
  318. package/projections/graphs/GraphNodeFromModel.ts +19 -0
  319. package/projections/graphs/GraphNodeModel.ts +25 -0
  320. package/projections/graphs/GraphNodeRemovedWithBuilder.ts +30 -0
  321. package/projections/graphs/GraphNodeRemovedWithModel.ts +16 -0
  322. package/projections/graphs/GraphProjectionBuilder.ts +52 -0
  323. package/projections/graphs/GraphRegistration.ts +19 -0
  324. package/projections/graphs/GraphSchemaWriter.ts +80 -0
  325. package/projections/graphs/Graphs.ts +165 -0
  326. package/projections/graphs/IGraphEdgeBuilder.ts +43 -0
  327. package/projections/graphs/IGraphEdgeFromBuilder.ts +34 -0
  328. package/projections/graphs/IGraphEdgeRemovedWithBuilder.ts +32 -0
  329. package/projections/graphs/IGraphMappingBuilder.ts +57 -0
  330. package/projections/graphs/IGraphNodeBuilder.ts +37 -0
  331. package/projections/graphs/IGraphNodeFromBuilder.ts +25 -0
  332. package/projections/graphs/IGraphNodeRemovedWithBuilder.ts +23 -0
  333. package/projections/graphs/IGraphProjection.ts +16 -0
  334. package/projections/graphs/IGraphProjectionBuilder.ts +34 -0
  335. package/projections/graphs/IGraphs.ts +33 -0
  336. package/projections/graphs/ModelBoundGraphReader.ts +119 -0
  337. package/projections/graphs/NestedObjectInGraph.ts +17 -0
  338. package/projections/graphs/NodeMustHaveExactlyOneKey.ts +17 -0
  339. package/projections/graphs/UnknownGraphEventProperty.ts +18 -0
  340. package/projections/graphs/UnknownGraphNode.ts +17 -0
  341. package/projections/graphs/edge.ts +40 -0
  342. package/projections/graphs/edgeFrom.ts +48 -0
  343. package/projections/graphs/edgeRemovedWith.ts +36 -0
  344. package/projections/graphs/edgeSource.ts +39 -0
  345. package/projections/graphs/edgeTarget.ts +39 -0
  346. package/projections/graphs/graph.ts +28 -0
  347. package/projections/graphs/graphKey.ts +31 -0
  348. package/projections/graphs/graphProjection.ts +39 -0
  349. package/projections/graphs/index.ts +50 -0
  350. package/projections/graphs/isGraphElement.ts +14 -0
  351. package/projections/graphs/node.ts +40 -0
  352. package/projections/graphs/nodeFrom.ts +48 -0
  353. package/projections/graphs/nodeRemovedWith.ts +44 -0
  354. package/projections/graphs/propertyPathOf.ts +15 -0
  355. package/projections/index.ts +1 -0
  356. package/projections/registerProjectionWithRetry.ts +53 -0
  357. package/readModels/rootReadModelTypes.ts +3 -1
  358. package/sinks/WellKnownSinks.ts +7 -1
  359. package/types/DecoratorType.ts +7 -1
@@ -0,0 +1,199 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import 'reflect-metadata';
5
+ import { field } from '@cratis/fundamentals';
6
+ import { chai, describe, it } from 'vitest';
7
+ import { eventType } from '../../events/eventTypeDecorator.js';
8
+ import { fromEvent } from '../modelBound/fromEvent.js';
9
+ import { edge } from '../graphs/edge.js';
10
+ import { edgeFrom } from '../graphs/edgeFrom.js';
11
+ import { edgeSource } from '../graphs/edgeSource.js';
12
+ import { edgeTarget } from '../graphs/edgeTarget.js';
13
+ import { EdgeCanHaveOnlyOneIdentifyingKey } from '../graphs/EdgeCanHaveOnlyOneIdentifyingKey.js';
14
+ import { EdgeMustHaveOneSourceAndOneTarget } from '../graphs/EdgeMustHaveOneSourceAndOneTarget.js';
15
+ import { graph } from '../graphs/graph.js';
16
+ import { GraphDeclaredMoreThanOnce } from '../graphs/GraphDeclaredMoreThanOnce.js';
17
+ import { GraphElementCannotBeReadModel } from '../graphs/GraphElementCannotBeReadModel.js';
18
+ import { GraphHasDuplicateElement } from '../graphs/GraphHasDuplicateElement.js';
19
+ import { graphKey } from '../graphs/graphKey.js';
20
+ import { GraphKeyPropertyNotFound } from '../graphs/GraphKeyPropertyNotFound.js';
21
+ import { GraphNameRequired } from '../graphs/GraphNameRequired.js';
22
+ import { graphProjection } from '../graphs/graphProjection.js';
23
+ import type { IGraphProjection } from '../graphs/IGraphProjection.js';
24
+ import type { IGraphProjectionBuilder } from '../graphs/IGraphProjectionBuilder.js';
25
+ import { NestedObjectInGraph } from '../graphs/NestedObjectInGraph.js';
26
+ import { node } from '../graphs/node.js';
27
+ import { nodeFrom } from '../graphs/nodeFrom.js';
28
+ import { NodeMustHaveExactlyOneKey } from '../graphs/NodeMustHaveExactlyOneKey.js';
29
+ import { UnknownGraphNode } from '../graphs/UnknownGraphNode.js';
30
+ import { discoverGraphs } from './given/a_discovered_graph.js';
31
+
32
+ chai.should();
33
+
34
+ class ThingHappened { thingId = ''; }
35
+ eventType()(ThingHappened);
36
+
37
+ function aNode(graphName: string, ...keys: string[]) {
38
+ class Thing {
39
+ thingId = '';
40
+ otherId = '';
41
+ }
42
+ graph(graphName)(Thing);
43
+ node()(Thing);
44
+ for (const key of keys) graphKey()(Thing.prototype, key);
45
+ nodeFrom(ThingHappened, { key: 'thingId' })(Thing);
46
+ return Thing;
47
+ }
48
+
49
+ async function failureOf(...elements: Function[]) {
50
+ const result = await discoverGraphs(elements as never[]);
51
+ const failures = [...result.graphs.failures.values()];
52
+ return { failures, registered: result.graphs.registrations.length };
53
+ }
54
+
55
+ describe('when a node has no key', () => {
56
+ it('should fail with NodeMustHaveExactlyOneKey', async () => {
57
+ const { failures, registered } = await failureOf(aNode('NoKey'));
58
+ failures[0].should.be.instanceOf(NodeMustHaveExactlyOneKey);
59
+ registered.should.equal(0);
60
+ });
61
+ });
62
+
63
+ describe('when a node has two keys', () => {
64
+ it('should fail with NodeMustHaveExactlyOneKey', async () => {
65
+ const { failures } = await failureOf(aNode('TwoKeys', 'thingId', 'otherId'));
66
+ failures[0].should.be.instanceOf(NodeMustHaveExactlyOneKey).and.have.property('message').that.includes('but it has 2');
67
+ });
68
+ });
69
+
70
+ describe('when the key of a node is not a property', () => {
71
+ it('should fail with GraphKeyPropertyNotFound', async () => {
72
+ class Keyless { present = ''; }
73
+ graph('Keyless')(Keyless);
74
+ node()(Keyless);
75
+ graphKey()(Keyless.prototype, 'absent');
76
+ const { failures } = await failureOf(Keyless);
77
+ failures[0].should.be.instanceOf(GraphKeyPropertyNotFound);
78
+ });
79
+ });
80
+
81
+ describe('when an edge does not name its end nodes', () => {
82
+ it('should fail with EdgeMustHaveOneSourceAndOneTarget', async () => {
83
+ class Dangling { weight = 0; }
84
+ graph('Dangling')(Dangling);
85
+ edge('DANGLES')(Dangling);
86
+ const { failures } = await failureOf(Dangling);
87
+ failures[0].should.be.instanceOf(EdgeMustHaveOneSourceAndOneTarget);
88
+ });
89
+ });
90
+
91
+ describe('when an edge has two identifying keys', () => {
92
+ it('should fail with EdgeCanHaveOnlyOneIdentifyingKey', async () => {
93
+ const Thing = aNode('TwoIdentities', 'thingId');
94
+ class Twice { fromId = ''; toId = ''; a = ''; b = ''; }
95
+ graph('TwoIdentities')(Twice);
96
+ edge('TWICE')(Twice);
97
+ edgeSource(Thing)(Twice.prototype, 'fromId');
98
+ edgeTarget(Thing)(Twice.prototype, 'toId');
99
+ graphKey()(Twice.prototype, 'a');
100
+ graphKey()(Twice.prototype, 'b');
101
+ edgeFrom(ThingHappened, { sourceKey: 'thingId', targetKey: 'thingId' })(Twice);
102
+ const { failures } = await failureOf(Thing, Twice);
103
+ failures[0].should.be.instanceOf(EdgeCanHaveOnlyOneIdentifyingKey);
104
+ });
105
+ });
106
+
107
+ describe('when an edge connects a type that is not a node of its graph', () => {
108
+ it('should fail with UnknownGraphNode', async () => {
109
+ const Thing = aNode('Unconnected', 'thingId');
110
+ class Stranger { strangerId = ''; }
111
+ class Lonely { fromId = ''; toId = ''; }
112
+ graph('Unconnected')(Lonely);
113
+ edge('LONELY')(Lonely);
114
+ edgeSource(Thing)(Lonely.prototype, 'fromId');
115
+ edgeTarget(Stranger)(Lonely.prototype, 'toId');
116
+ const { failures, registered } = await failureOf(Thing, Lonely);
117
+ failures[0].should.be.instanceOf(UnknownGraphNode);
118
+ registered.should.equal(0);
119
+ });
120
+ });
121
+
122
+ describe('when a node has an object property', () => {
123
+ it('should fail with NestedObjectInGraph', async () => {
124
+ class Address { street = ''; }
125
+ class Resident { residentId = ''; address = new Address(); }
126
+ field(String)(Resident.prototype, 'residentId');
127
+ field(Address)(Resident.prototype, 'address');
128
+ graph('Residents')(Resident);
129
+ node()(Resident);
130
+ graphKey()(Resident.prototype, 'residentId');
131
+ const { failures } = await failureOf(Resident);
132
+ failures[0].should.be.instanceOf(NestedObjectInGraph).and.have.property('message').that.includes("'address'");
133
+ });
134
+ });
135
+
136
+ describe('when a node does not say which graph it belongs to', () => {
137
+ it('should fail with GraphNameRequired', async () => {
138
+ class Homeless { homelessId = ''; }
139
+ node()(Homeless);
140
+ graphKey()(Homeless.prototype, 'homelessId');
141
+ const { failures } = await failureOf(Homeless);
142
+ failures[0].should.be.instanceOf(GraphNameRequired);
143
+ });
144
+ });
145
+
146
+ describe('when a node is also a read model', () => {
147
+ it('should fail with GraphElementCannotBeReadModel', async () => {
148
+ const Thing = aNode('Both', 'thingId');
149
+ fromEvent(ThingHappened)(Thing);
150
+ const { failures } = await failureOf(Thing);
151
+ failures[0].should.be.instanceOf(GraphElementCannotBeReadModel);
152
+ });
153
+ });
154
+
155
+ describe('when two nodes of a graph have the same label', () => {
156
+ it('should fail with GraphHasDuplicateElement', async () => {
157
+ const first = aNode('Duplicates', 'thingId');
158
+ const second = aNode('Duplicates', 'thingId');
159
+ const { failures } = await failureOf(first, second);
160
+ failures[0].should.be.instanceOf(GraphHasDuplicateElement);
161
+ });
162
+ });
163
+
164
+ describe('when one graph is invalid', () => {
165
+ it('should still register the valid graphs', async () => {
166
+ const valid = aNode('Valid', 'thingId');
167
+ const invalid = aNode('Invalid');
168
+ const result = await discoverGraphs([valid, invalid]);
169
+ result.graphs.registrations.map(_ => _.graphName).should.deep.equal(['Valid']);
170
+ result.graphs.failures.has(invalid).should.be.true;
171
+ });
172
+
173
+ it('should leave a graph unregistered when one of its elements is invalid', async () => {
174
+ const valid = aNode('Partial', 'thingId');
175
+ class Unfinished { unfinishedId = ''; }
176
+ graph('Partial')(Unfinished);
177
+ node()(Unfinished);
178
+ const result = await discoverGraphs([valid, Unfinished]);
179
+ result.graphs.registrations.length.should.equal(0);
180
+ result.graphs.failures.has(Unfinished).should.be.true;
181
+ });
182
+ });
183
+
184
+ describe('when two graph projections declare the same graph', () => {
185
+ it('should register the first and fail the second with GraphDeclaredMoreThanOnce', async () => {
186
+ const Thing = aNode('Twice', 'thingId');
187
+ class First implements IGraphProjection {
188
+ define(builder: IGraphProjectionBuilder): void {
189
+ builder.node(Thing, node => node.from(ThingHappened));
190
+ }
191
+ }
192
+ class Second extends First {}
193
+ graphProjection('Twice')(First);
194
+ graphProjection('Twice')(Second);
195
+ const result = await discoverGraphs([], [First, Second]);
196
+ result.graphs.registrations.length.should.equal(1);
197
+ result.graphs.failures.get(Second)!.should.be.instanceOf(GraphDeclaredMoreThanOnce);
198
+ });
199
+ });
@@ -0,0 +1,92 @@
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 { field } from '@cratis/fundamentals';
5
+ import { chai, describe, it, type Assertion } from 'vitest';
6
+ import { eventType } from '../../events/eventTypeDecorator.js';
7
+ import { edge } from '../graphs/edge.js';
8
+ import { edgeFrom } from '../graphs/edgeFrom.js';
9
+ import { edgeRemovedWith } from '../graphs/edgeRemovedWith.js';
10
+ import { edgeSource } from '../graphs/edgeSource.js';
11
+ import { edgeTarget } from '../graphs/edgeTarget.js';
12
+ import { graph } from '../graphs/graph.js';
13
+ import { graphKey } from '../graphs/graphKey.js';
14
+ import { node } from '../graphs/node.js';
15
+ import { nodeFrom } from '../graphs/nodeFrom.js';
16
+ import { nodeRemovedWith } from '../graphs/nodeRemovedWith.js';
17
+ import { count } from '../modelBound/count.js';
18
+ import { setFromContext } from '../modelBound/setFromContext.js';
19
+ import { discoverGraphs } from './given/a_discovered_graph.js';
20
+
21
+ chai.should();
22
+ function should(value: unknown): Assertion { return (value as { should: Assertion }).should; }
23
+
24
+ @eventType()
25
+ class AuthorJoined {
26
+ @field(String) authorId = '';
27
+ @field(String) name = '';
28
+ }
29
+
30
+ @eventType()
31
+ class AuthorLeft {
32
+ @field(String) authorId = '';
33
+ }
34
+
35
+ @eventType()
36
+ class BookWritten {
37
+ @field(String) authorId = '';
38
+ @field(String) bookId = '';
39
+ }
40
+
41
+ @graph('Library')
42
+ @node()
43
+ @nodeFrom(AuthorJoined, { key: 'authorId' })
44
+ @nodeRemovedWith(AuthorLeft, { key: 'authorId', detach: true })
45
+ class Author {
46
+ @graphKey() @field(String) authorId = '';
47
+ @field(String) name = '';
48
+ }
49
+
50
+ @graph('Library')
51
+ @node()
52
+ @nodeFrom(BookWritten, { key: 'bookId' })
53
+ class Book {
54
+ @graphKey() @field(String) bookId = '';
55
+ @count(BookWritten) @field(Number) editions = 0;
56
+ }
57
+
58
+ @graph('Library')
59
+ @edge('WROTE')
60
+ @edgeFrom(BookWritten, { sourceKey: 'authorId', targetKey: 'bookId' })
61
+ @edgeRemovedWith(AuthorLeft, { sourceKey: 'authorId', targetKey: 'authorId' })
62
+ class Wrote {
63
+ @edgeSource(Author) @field(String) authorId = '';
64
+ @edgeTarget(Book) @field(String) bookId = '';
65
+ @setFromContext(BookWritten, 'occurred') @field(Date) writtenAt = new Date();
66
+ }
67
+
68
+ describe('when declaring a graph with standard decorators', () => {
69
+ it('should build the same graph as with legacy decorators', async () => {
70
+ const result = await discoverGraphs([Author, Book, Wrote]);
71
+ should(result.graphs.failures.size).equal(0);
72
+ const registration = result.graphs.registrations[0];
73
+ should(registration.graphName).equal('Library');
74
+ should(JSON.parse(registration.readModel.Schema).properties.WROTE).deep.equal({
75
+ type: 'object',
76
+ properties: { writtenAt: { type: 'string', format: 'date-time' } },
77
+ 'x-graph-kind': 'Edge',
78
+ 'x-graph-source': 'Author',
79
+ 'x-graph-target': 'Book'
80
+ });
81
+ should(registration.projection.Graph!.Nodes.Author).deep.equal({
82
+ From: { 'AuthorJoined+1': { Key: 'authorId', Properties: { name: 'name' }, UpdateOnly: false } },
83
+ RemovedWith: { 'AuthorLeft+1': { Key: 'authorId', Detach: true } }
84
+ });
85
+ should(registration.projection.Graph!.Nodes.Book.From['BookWritten+1']).deep.equal({
86
+ Key: 'bookId', Properties: { editions: '$count' }, UpdateOnly: false
87
+ });
88
+ should(registration.projection.Graph!.Edges.WROTE.From['BookWritten+1']).deep.equal({
89
+ SourceKey: 'authorId', TargetKey: 'bookId', Identity: '', Properties: { writtenAt: '$eventContext(Occurred)' }
90
+ });
91
+ });
92
+ });
@@ -0,0 +1,32 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import 'reflect-metadata';
5
+ import { chai, describe, it } from 'vitest';
6
+ import { DefaultClientArtifactsProvider } from '../../artifacts/DefaultClientArtifactsProvider.js';
7
+ import { rootReadModelTypes } from '../../readModels/rootReadModelTypes.js';
8
+ import { TypeDiscoverer } from '../../types/index.js';
9
+ import { isGraphElement } from '../graphs/isGraphElement.js';
10
+ import { discoverGraphs } from './given/a_discovered_graph.js';
11
+ import { Group, MemberOf, Person } from './given/organization.js';
12
+
13
+ chai.should();
14
+
15
+ describe('when discovering the artifacts of an application with a graph', () => {
16
+ const provider = new DefaultClientArtifactsProvider(TypeDiscoverer.default);
17
+
18
+ it('should find the nodes and edges', () => {
19
+ provider.graphElements.should.include.members([Person, Group, MemberOf]);
20
+ });
21
+ it('should recognize them as graph elements', () => {
22
+ [Person, Group, MemberOf].every(isGraphElement).should.be.true;
23
+ });
24
+ it('should not treat them as read models, even though they map properties like read models do', () => {
25
+ provider.readModels.should.not.include.members([MemberOf]);
26
+ rootReadModelTypes(provider).should.not.include.members([Person, Group, MemberOf]);
27
+ });
28
+ it('should build the graph from what it finds', async () => {
29
+ const result = await discoverGraphs(provider.graphElements);
30
+ result.graphs.registrations.map(_ => _.graphName).should.include('Organization');
31
+ });
32
+ });
@@ -0,0 +1,159 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import 'reflect-metadata';
5
+ import { beforeAll, chai, describe, it } from 'vitest';
6
+ import type { GraphNodeProjectionDefinition } from '@cratis/chronicle.contracts';
7
+ import { eventType } from '../../events/eventTypeDecorator.js';
8
+ import { addFrom } from '../modelBound/addFrom.js';
9
+ import { count } from '../modelBound/count.js';
10
+ import { decrement } from '../modelBound/decrement.js';
11
+ import { increment } from '../modelBound/increment.js';
12
+ import { setFrom } from '../modelBound/setFrom.js';
13
+ import { setFromContext } from '../modelBound/setFromContext.js';
14
+ import { setValue } from '../modelBound/setValue.js';
15
+ import { subtractFrom } from '../modelBound/subtractFrom.js';
16
+ import { graph } from '../graphs/graph.js';
17
+ import { graphKey } from '../graphs/graphKey.js';
18
+ import { graphProjection } from '../graphs/graphProjection.js';
19
+ import type { IGraphProjection } from '../graphs/IGraphProjection.js';
20
+ import type { IGraphProjectionBuilder } from '../graphs/IGraphProjectionBuilder.js';
21
+ import { node } from '../graphs/node.js';
22
+ import { nodeFrom } from '../graphs/nodeFrom.js';
23
+ import { discoverGraphs } from './given/a_discovered_graph.js';
24
+
25
+ chai.should();
26
+
27
+ class TeamFormed { teamId = ''; title = ''; }
28
+ eventType()(TeamFormed);
29
+ class MemberJoined { teamId = ''; points = 0; }
30
+ eventType()(MemberJoined);
31
+ class MemberLeft { teamId = ''; points = 0; }
32
+ eventType()(MemberLeft);
33
+ class TeamRenamed { teamId = ''; newTitle = ''; }
34
+ eventType()(TeamRenamed);
35
+ class TeamArchived { teamId = ''; }
36
+ eventType()(TeamArchived);
37
+
38
+ class Team {
39
+ teamId = '';
40
+ title = '';
41
+ memberCount = 0;
42
+ totalPoints = 0;
43
+ archived = false;
44
+ renamedAt = '';
45
+ visits = 0;
46
+ status = '';
47
+ }
48
+ graph('Teams')(Team);
49
+ node()(Team);
50
+ graphKey()(Team.prototype, 'teamId');
51
+ nodeFrom(TeamFormed, { key: 'teamId' })(Team);
52
+ nodeFrom(MemberJoined, { key: 'teamId' })(Team);
53
+ nodeFrom(MemberLeft, { key: 'teamId' })(Team);
54
+ increment(MemberJoined)(Team.prototype, 'memberCount');
55
+ decrement(MemberLeft)(Team.prototype, 'memberCount');
56
+ addFrom(MemberJoined, 'points')(Team.prototype, 'totalPoints');
57
+ subtractFrom(MemberLeft, 'points')(Team.prototype, 'totalPoints');
58
+ count(MemberJoined)(Team.prototype, 'visits');
59
+ setFromContext(TeamRenamed, 'occurred')(Team.prototype, 'renamedAt');
60
+ setFrom(TeamRenamed, 'newTitle')(Team.prototype, 'title');
61
+ setValue(TeamArchived, true)(Team.prototype, 'archived');
62
+ setValue(TeamArchived, 'archived')(Team.prototype, 'status');
63
+
64
+ describe('when mapping the properties of a node with decorators', () => {
65
+ let nodeDefinition: GraphNodeProjectionDefinition;
66
+
67
+ beforeAll(async () => {
68
+ const result = await discoverGraphs([Team]);
69
+ result.graphs.failures.size.should.equal(0);
70
+ nodeDefinition = result.graphs.registrations[0].projection.Graph!.Nodes.Team;
71
+ });
72
+
73
+ it('should map a property by name from the event that has a property of that name', () => {
74
+ nodeDefinition.From['TeamFormed+1'].Properties.should.deep.equal({ title: 'title' });
75
+ });
76
+ it('should add, increment and count', () => {
77
+ nodeDefinition.From['MemberJoined+1'].Properties.should.deep.equal({
78
+ memberCount: '$increment', totalPoints: '$add(points)', visits: '$count'
79
+ });
80
+ });
81
+ it('should subtract and decrement', () => {
82
+ nodeDefinition.From['MemberLeft+1'].Properties.should.deep.equal({ memberCount: '$decrement', totalPoints: '$subtract(points)' });
83
+ });
84
+ it('should map an event property of another name and the event context', () => {
85
+ nodeDefinition.From['TeamRenamed+1'].Properties.should.deep.equal({ title: 'newTitle', renamedAt: '$eventContext(Occurred)' });
86
+ });
87
+ it('should project the node from an event only a property refers to, keyed by the event source id', () => {
88
+ nodeDefinition.From['TeamRenamed+1'].Key.should.equal('$eventSourceId');
89
+ nodeDefinition.From['TeamRenamed+1'].UpdateOnly.should.be.false;
90
+ });
91
+ it('should set constant values', () => {
92
+ nodeDefinition.From['TeamArchived+1'].Properties.should.deep.equal({ archived: '$value(true)', status: '$value(archived)' });
93
+ });
94
+ });
95
+
96
+ describe('when declaring how an event projects a node', () => {
97
+ class Counter { counterId = ''; total = 0; }
98
+ graph('Counters')(Counter);
99
+ node()(Counter);
100
+ graphKey()(Counter.prototype, 'counterId');
101
+ nodeFrom(MemberJoined, { constantKey: 'all', updateOnly: true })(Counter);
102
+ count(MemberJoined)(Counter.prototype, 'total');
103
+
104
+ it('should key the node with the constant and only change a node that exists', async () => {
105
+ const result = await discoverGraphs([Counter]);
106
+ result.graphs.registrations[0].projection.Graph!.Nodes.Counter.From['MemberJoined+1'].should.deep.equal({
107
+ Key: '$value(all)', Properties: { total: '$count' }, UpdateOnly: true
108
+ });
109
+ });
110
+ });
111
+
112
+ describe('when mapping the properties of a node with the fluent builder', () => {
113
+ let nodeDefinition: GraphNodeProjectionDefinition;
114
+
115
+ beforeAll(async () => {
116
+ class TeamsGraph implements IGraphProjection {
117
+ define(builder: IGraphProjectionBuilder): void {
118
+ builder.node(Team, node => node
119
+ .from(TeamFormed, from => from.usingKey(event => event.teamId))
120
+ .from(MemberJoined, from => from
121
+ .usingKey(event => event.teamId)
122
+ .increment(team => team.memberCount)
123
+ .add(team => team.totalPoints).with(event => event.points)
124
+ .count(team => team.visits))
125
+ .from(MemberLeft, from => from
126
+ .decrement(team => team.memberCount)
127
+ .subtract(team => team.totalPoints).with(event => event.points))
128
+ .from(TeamRenamed, from => from
129
+ .set(team => team.title).to(event => event.newTitle)
130
+ .set(team => team.renamedAt).toEventContextProperty('occurred')
131
+ .set(team => team.status).toValue('renamed')
132
+ .set(team => team.archived).toValue(false)
133
+ .set(team => team.teamId).toEventSourceId()
134
+ .onlyWhenExisting()));
135
+ }
136
+ }
137
+ graphProjection('FluentTeams')(TeamsGraph);
138
+ const result = await discoverGraphs([], [TeamsGraph]);
139
+ result.graphs.failures.size.should.equal(0);
140
+ nodeDefinition = result.graphs.registrations[0].projection.Graph!.Nodes.Team;
141
+ });
142
+
143
+ it('should map by name, add, increment and count', () => {
144
+ nodeDefinition.From['MemberJoined+1'].Properties.should.deep.equal({
145
+ memberCount: '$increment', totalPoints: '$add(points)', visits: '$count'
146
+ });
147
+ });
148
+ it('should subtract and decrement', () => {
149
+ nodeDefinition.From['MemberLeft+1'].Properties.should.deep.equal({ memberCount: '$decrement', totalPoints: '$subtract(points)' });
150
+ });
151
+ it('should set from the event, the event context, a constant and the event source id', () => {
152
+ nodeDefinition.From['TeamRenamed+1'].Properties.should.deep.include({
153
+ title: 'newTitle', renamedAt: '$eventContext(Occurred)', status: '$value(renamed)', archived: '$value(false)', teamId: '$eventSourceId'
154
+ });
155
+ });
156
+ it('should only change a node that exists', () => {
157
+ nodeDefinition.From['TeamRenamed+1'].UpdateOnly.should.be.true;
158
+ });
159
+ });
@@ -0,0 +1,56 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import 'reflect-metadata';
5
+ import { ProjectionOwner } from '@cratis/chronicle.contracts';
6
+ import { beforeAll, chai, describe, it } from 'vitest';
7
+ import { discoverGraphs } from './given/a_discovered_graph.js';
8
+ import { Group, MemberOf, Person } from './given/organization.js';
9
+
10
+ chai.should();
11
+
12
+ describe('when registering a graph', () => {
13
+ let result: Awaited<ReturnType<typeof discoverGraphs>>;
14
+
15
+ beforeAll(async () => {
16
+ result = await discoverGraphs([Person, Group, MemberOf]);
17
+ await result.graphs.register();
18
+ });
19
+
20
+ it('should register the graph as a read model of the event store', () => {
21
+ result.readModelRequests.length.should.equal(1);
22
+ const request = result.readModelRequests[0];
23
+ request.EventStore.should.equal('the-store');
24
+ request.ReadModels.map(readModel => readModel.Type.Identifier).should.deep.equal(['Organization']);
25
+ });
26
+ it('should register the projection that fills the graph, with the graph definition on the wire', () => {
27
+ result.projectionRequests.length.should.equal(1);
28
+ const request = result.projectionRequests[0];
29
+ request.EventStore.should.equal('the-store');
30
+ request.Owner.should.equal(ProjectionOwner.PROJECTION_OWNER_Client);
31
+ request.Projections[0].Identifier.should.equal('Organization');
32
+ Object.keys(request.Projections[0].Graph.Nodes).should.deep.equal(['Person', 'Group']);
33
+ Object.keys(request.Projections[0].Graph.Edges).should.deep.equal(['MEMBER_OF']);
34
+ });
35
+ });
36
+
37
+ describe('when registering without graphs', () => {
38
+ it('should not call the kernel', async () => {
39
+ const result = await discoverGraphs([]);
40
+ await result.graphs.register();
41
+ result.readModelRequests.length.should.equal(0);
42
+ result.projectionRequests.length.should.equal(0);
43
+ });
44
+ });
45
+
46
+ describe('when the graph definition has to be encoded for the wire', () => {
47
+ it('should encode as a projection definition', async () => {
48
+ const { ProjectionDefinition } = await import('@cratis/chronicle.contracts');
49
+ const result = await discoverGraphs([Person, Group, MemberOf]);
50
+ const bytes = ProjectionDefinition.encode(result.graphs.registrations[0].projection).finish();
51
+ const decoded = ProjectionDefinition.decode(bytes);
52
+ decoded.Graph!.Nodes.Person.From['PersonRegistered+1'].Key.should.equal('personId');
53
+ decoded.Graph!.Edges.MEMBER_OF.From['MemberAdded+1'].Properties.since.should.equal('$eventContext(Occurred)');
54
+ decoded.Graph!.Nodes.Person.RemovedWith['PersonRemoved+1'].Detach.should.be.true;
55
+ });
56
+ });
@@ -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
+ /**
5
+ * Error thrown when an edge type has more than one identifying key.
6
+ */
7
+ export class EdgeCanHaveOnlyOneIdentifyingKey extends Error {
8
+ /**
9
+ * Creates a new {@link EdgeCanHaveOnlyOneIdentifyingKey}.
10
+ * @param type - The edge type.
11
+ */
12
+ constructor(type: Function) {
13
+ super(`The edge type '${type.name}' can have at most one member with the graphKey decorator, the one that identifies the edge.`);
14
+ this.name = 'EdgeCanHaveOnlyOneIdentifyingKey';
15
+ }
16
+ }
@@ -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
+ /**
5
+ * Error thrown when an edge type does not name its end nodes.
6
+ */
7
+ export class EdgeMustHaveOneSourceAndOneTarget extends Error {
8
+ /**
9
+ * Creates a new {@link EdgeMustHaveOneSourceAndOneTarget}.
10
+ * @param type - The edge type.
11
+ */
12
+ constructor(type: Function) {
13
+ super(`The edge type '${type.name}' must have exactly one member with the edgeSource decorator and exactly one with the edgeTarget decorator.`);
14
+ this.name = 'EdgeMustHaveOneSourceAndOneTarget';
15
+ }
16
+ }
@@ -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
+ /**
5
+ * Error thrown when two declarations produce a graph with the same name.
6
+ */
7
+ export class GraphDeclaredMoreThanOnce extends Error {
8
+ /**
9
+ * Creates a new {@link GraphDeclaredMoreThanOnce}.
10
+ * @param graph - The name of the graph.
11
+ */
12
+ constructor(graph: string) {
13
+ super(`The graph '${graph}' is declared by more than one graph projection. A graph is the read model of exactly one projection.`);
14
+ this.name = 'GraphDeclaredMoreThanOnce';
15
+ }
16
+ }