@cratis/chronicle 6.62.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 (448) hide show
  1. package/ChronicleClient.ts +86 -3
  2. package/artifacts/DefaultClientArtifactsProvider.ts +5 -0
  3. package/artifacts/IClientArtifactsProvider.ts +3 -0
  4. package/connection/ConnectionLifecycle.ts +42 -1
  5. package/dist/ChronicleClient.d.ts +28 -1
  6. package/dist/ChronicleClient.d.ts.map +1 -1
  7. package/dist/ChronicleClient.js +71 -3
  8. package/dist/ChronicleClient.js.map +1 -1
  9. package/dist/artifacts/DefaultClientArtifactsProvider.d.ts +2 -0
  10. package/dist/artifacts/DefaultClientArtifactsProvider.d.ts.map +1 -1
  11. package/dist/artifacts/DefaultClientArtifactsProvider.js +4 -0
  12. package/dist/artifacts/DefaultClientArtifactsProvider.js.map +1 -1
  13. package/dist/artifacts/IClientArtifactsProvider.d.ts +2 -0
  14. package/dist/artifacts/IClientArtifactsProvider.d.ts.map +1 -1
  15. package/dist/connection/ConnectionLifecycle.d.ts +24 -0
  16. package/dist/connection/ConnectionLifecycle.d.ts.map +1 -1
  17. package/dist/connection/ConnectionLifecycle.js +40 -1
  18. package/dist/connection/ConnectionLifecycle.js.map +1 -1
  19. package/dist/observation/ObservationReconnectBackoff.d.ts +64 -0
  20. package/dist/observation/ObservationReconnectBackoff.d.ts.map +1 -0
  21. package/dist/observation/ObservationReconnectBackoff.js +75 -0
  22. package/dist/observation/ObservationReconnectBackoff.js.map +1 -0
  23. package/dist/observation/ObservationStreamOutcome.d.ts +10 -0
  24. package/dist/observation/ObservationStreamOutcome.d.ts.map +1 -0
  25. package/dist/observation/ObservationStreamOutcome.js +4 -0
  26. package/dist/observation/ObservationStreamOutcome.js.map +1 -0
  27. package/dist/observation/classifyStreamError.d.ts +25 -0
  28. package/dist/observation/classifyStreamError.d.ts.map +1 -0
  29. package/dist/observation/classifyStreamError.js +55 -0
  30. package/dist/observation/classifyStreamError.js.map +1 -0
  31. package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.d.ts +13 -0
  32. package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.d.ts.map +1 -0
  33. package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.js +25 -0
  34. package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.js.map +1 -0
  35. package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.d.ts +27 -0
  36. package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.d.ts.map +1 -0
  37. package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.js +36 -0
  38. package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.js.map +1 -0
  39. package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts +2 -1
  40. package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts.map +1 -1
  41. package/dist/projections/for_Graphs/given/a_discovered_graph.js +3 -2
  42. package/dist/projections/for_Graphs/given/a_discovered_graph.js.map +1 -1
  43. package/dist/projections/for_Graphs/given/a_graph_with_views.d.ts +40 -0
  44. package/dist/projections/for_Graphs/given/a_graph_with_views.d.ts.map +1 -0
  45. package/dist/projections/for_Graphs/given/a_graph_with_views.js +80 -0
  46. package/dist/projections/for_Graphs/given/a_graph_with_views.js.map +1 -0
  47. package/dist/projections/for_Graphs/given/organization.d.ts +2 -1
  48. package/dist/projections/for_Graphs/given/organization.d.ts.map +1 -1
  49. package/dist/projections/for_Graphs/given/organization.js +3 -2
  50. package/dist/projections/for_Graphs/given/organization.js.map +1 -1
  51. package/dist/projections/graphs/Graphs.d.ts +5 -0
  52. package/dist/projections/graphs/Graphs.d.ts.map +1 -1
  53. package/dist/projections/graphs/Graphs.js +43 -0
  54. package/dist/projections/graphs/Graphs.js.map +1 -1
  55. package/dist/projections/graphs/IGraphs.d.ts +9 -2
  56. package/dist/projections/graphs/IGraphs.d.ts.map +1 -1
  57. package/dist/projections/graphs/index.d.ts +1 -0
  58. package/dist/projections/graphs/index.d.ts.map +1 -1
  59. package/dist/projections/graphs/index.js +1 -0
  60. package/dist/projections/graphs/index.js.map +1 -1
  61. package/dist/projections/graphs/views/AmbiguousDirection.d.ts +16 -0
  62. package/dist/projections/graphs/views/AmbiguousDirection.d.ts.map +1 -0
  63. package/dist/projections/graphs/views/AmbiguousDirection.js +21 -0
  64. package/dist/projections/graphs/views/AmbiguousDirection.js.map +1 -0
  65. package/dist/projections/graphs/views/DuplicateViewName.d.ts +16 -0
  66. package/dist/projections/graphs/views/DuplicateViewName.d.ts.map +1 -0
  67. package/dist/projections/graphs/views/DuplicateViewName.js +21 -0
  68. package/dist/projections/graphs/views/DuplicateViewName.js.map +1 -0
  69. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.d.ts +17 -0
  70. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.d.ts.map +1 -0
  71. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.js +22 -0
  72. package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.js.map +1 -0
  73. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.d.ts +14 -0
  74. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.d.ts.map +1 -0
  75. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.js +19 -0
  76. package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.js.map +1 -0
  77. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.d.ts +15 -0
  78. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.d.ts.map +1 -0
  79. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.js +20 -0
  80. package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.js.map +1 -0
  81. package/dist/projections/graphs/views/FollowsOptions.d.ts +16 -0
  82. package/dist/projections/graphs/views/FollowsOptions.d.ts.map +1 -0
  83. package/dist/projections/graphs/views/FollowsOptions.js +4 -0
  84. package/dist/projections/graphs/views/FollowsOptions.js.map +1 -0
  85. package/dist/projections/graphs/views/GraphEdgeDirection.d.ts +10 -0
  86. package/dist/projections/graphs/views/GraphEdgeDirection.d.ts.map +1 -0
  87. package/dist/projections/graphs/views/GraphEdgeDirection.js +13 -0
  88. package/dist/projections/graphs/views/GraphEdgeDirection.js.map +1 -0
  89. package/dist/projections/graphs/views/GraphView.d.ts +13 -0
  90. package/dist/projections/graphs/views/GraphView.d.ts.map +1 -0
  91. package/dist/projections/graphs/views/GraphView.js +4 -0
  92. package/dist/projections/graphs/views/GraphView.js.map +1 -0
  93. package/dist/projections/graphs/views/GraphViewBuildResult.d.ts +15 -0
  94. package/dist/projections/graphs/views/GraphViewBuildResult.d.ts.map +1 -0
  95. package/dist/projections/graphs/views/GraphViewBuildResult.js +4 -0
  96. package/dist/projections/graphs/views/GraphViewBuildResult.js.map +1 -0
  97. package/dist/projections/graphs/views/GraphViewCardinality.d.ts +10 -0
  98. package/dist/projections/graphs/views/GraphViewCardinality.d.ts.map +1 -0
  99. package/dist/projections/graphs/views/GraphViewCardinality.js +13 -0
  100. package/dist/projections/graphs/views/GraphViewCardinality.js.map +1 -0
  101. package/dist/projections/graphs/views/GraphViewDefinition.d.ts +15 -0
  102. package/dist/projections/graphs/views/GraphViewDefinition.d.ts.map +1 -0
  103. package/dist/projections/graphs/views/GraphViewDefinition.js +4 -0
  104. package/dist/projections/graphs/views/GraphViewDefinition.js.map +1 -0
  105. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.d.ts +30 -0
  106. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.d.ts.map +1 -0
  107. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.js +259 -0
  108. package/dist/projections/graphs/views/GraphViewDefinitionBuilder.js.map +1 -0
  109. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.d.ts +21 -0
  110. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.d.ts.map +1 -0
  111. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.js +77 -0
  112. package/dist/projections/graphs/views/GraphViewDefinitionSerializer.js.map +1 -0
  113. package/dist/projections/graphs/views/GraphViewEdgeReference.d.ts +6 -0
  114. package/dist/projections/graphs/views/GraphViewEdgeReference.d.ts.map +1 -0
  115. package/dist/projections/graphs/views/GraphViewEdgeReference.js +4 -0
  116. package/dist/projections/graphs/views/GraphViewEdgeReference.js.map +1 -0
  117. package/dist/projections/graphs/views/GraphViewMember.d.ts +8 -0
  118. package/dist/projections/graphs/views/GraphViewMember.d.ts.map +1 -0
  119. package/dist/projections/graphs/views/GraphViewMember.js +4 -0
  120. package/dist/projections/graphs/views/GraphViewMember.js.map +1 -0
  121. package/dist/projections/graphs/views/GraphViewMemberKind.d.ts +12 -0
  122. package/dist/projections/graphs/views/GraphViewMemberKind.d.ts.map +1 -0
  123. package/dist/projections/graphs/views/GraphViewMemberKind.js +15 -0
  124. package/dist/projections/graphs/views/GraphViewMemberKind.js.map +1 -0
  125. package/dist/projections/graphs/views/GraphViewMemberMetadata.d.ts +22 -0
  126. package/dist/projections/graphs/views/GraphViewMemberMetadata.d.ts.map +1 -0
  127. package/dist/projections/graphs/views/GraphViewMemberMetadata.js +4 -0
  128. package/dist/projections/graphs/views/GraphViewMemberMetadata.js.map +1 -0
  129. package/dist/projections/graphs/views/GraphViewPropertyMember.d.ts +13 -0
  130. package/dist/projections/graphs/views/GraphViewPropertyMember.d.ts.map +1 -0
  131. package/dist/projections/graphs/views/GraphViewPropertyMember.js +4 -0
  132. package/dist/projections/graphs/views/GraphViewPropertyMember.js.map +1 -0
  133. package/dist/projections/graphs/views/GraphViewReason.d.ts +33 -0
  134. package/dist/projections/graphs/views/GraphViewReason.d.ts.map +1 -0
  135. package/dist/projections/graphs/views/GraphViewReason.js +36 -0
  136. package/dist/projections/graphs/views/GraphViewReason.js.map +1 -0
  137. package/dist/projections/graphs/views/GraphViewRelationMember.d.ts +21 -0
  138. package/dist/projections/graphs/views/GraphViewRelationMember.d.ts.map +1 -0
  139. package/dist/projections/graphs/views/GraphViewRelationMember.js +4 -0
  140. package/dist/projections/graphs/views/GraphViewRelationMember.js.map +1 -0
  141. package/dist/projections/graphs/views/GraphViewSchema.d.ts +10 -0
  142. package/dist/projections/graphs/views/GraphViewSchema.d.ts.map +1 -0
  143. package/dist/projections/graphs/views/GraphViewSchema.js +4 -0
  144. package/dist/projections/graphs/views/GraphViewSchema.js.map +1 -0
  145. package/dist/projections/graphs/views/GraphViewSchemaEdge.d.ts +14 -0
  146. package/dist/projections/graphs/views/GraphViewSchemaEdge.d.ts.map +1 -0
  147. package/dist/projections/graphs/views/GraphViewSchemaEdge.js +4 -0
  148. package/dist/projections/graphs/views/GraphViewSchemaEdge.js.map +1 -0
  149. package/dist/projections/graphs/views/GraphViewSchemaNode.d.ts +10 -0
  150. package/dist/projections/graphs/views/GraphViewSchemaNode.d.ts.map +1 -0
  151. package/dist/projections/graphs/views/GraphViewSchemaNode.js +4 -0
  152. package/dist/projections/graphs/views/GraphViewSchemaNode.js.map +1 -0
  153. package/dist/projections/graphs/views/GraphViewSerializerOptions.d.ts +9 -0
  154. package/dist/projections/graphs/views/GraphViewSerializerOptions.d.ts.map +1 -0
  155. package/dist/projections/graphs/views/GraphViewSerializerOptions.js +4 -0
  156. package/dist/projections/graphs/views/GraphViewSerializerOptions.js.map +1 -0
  157. package/dist/projections/graphs/views/RecursiveView.d.ts +15 -0
  158. package/dist/projections/graphs/views/RecursiveView.d.ts.map +1 -0
  159. package/dist/projections/graphs/views/RecursiveView.js +20 -0
  160. package/dist/projections/graphs/views/RecursiveView.js.map +1 -0
  161. package/dist/projections/graphs/views/RelationTargetNotAView.d.ts +16 -0
  162. package/dist/projections/graphs/views/RelationTargetNotAView.d.ts.map +1 -0
  163. package/dist/projections/graphs/views/RelationTargetNotAView.js +21 -0
  164. package/dist/projections/graphs/views/RelationTargetNotAView.js.map +1 -0
  165. package/dist/projections/graphs/views/TargetLabelMismatch.d.ts +18 -0
  166. package/dist/projections/graphs/views/TargetLabelMismatch.d.ts.map +1 -0
  167. package/dist/projections/graphs/views/TargetLabelMismatch.js +23 -0
  168. package/dist/projections/graphs/views/TargetLabelMismatch.js.map +1 -0
  169. package/dist/projections/graphs/views/UnknownEdge.d.ts +16 -0
  170. package/dist/projections/graphs/views/UnknownEdge.d.ts.map +1 -0
  171. package/dist/projections/graphs/views/UnknownEdge.js +21 -0
  172. package/dist/projections/graphs/views/UnknownEdge.js.map +1 -0
  173. package/dist/projections/graphs/views/UnknownEdgeProperty.d.ts +17 -0
  174. package/dist/projections/graphs/views/UnknownEdgeProperty.d.ts.map +1 -0
  175. package/dist/projections/graphs/views/UnknownEdgeProperty.js +22 -0
  176. package/dist/projections/graphs/views/UnknownEdgeProperty.js.map +1 -0
  177. package/dist/projections/graphs/views/UnknownNodeProperty.d.ts +17 -0
  178. package/dist/projections/graphs/views/UnknownNodeProperty.d.ts.map +1 -0
  179. package/dist/projections/graphs/views/UnknownNodeProperty.js +22 -0
  180. package/dist/projections/graphs/views/UnknownNodeProperty.js.map +1 -0
  181. package/dist/projections/graphs/views/ViewIsAlsoSchema.d.ts +14 -0
  182. package/dist/projections/graphs/views/ViewIsAlsoSchema.d.ts.map +1 -0
  183. package/dist/projections/graphs/views/ViewIsAlsoSchema.js +19 -0
  184. package/dist/projections/graphs/views/ViewIsAlsoSchema.js.map +1 -0
  185. package/dist/projections/graphs/views/ViewOfMetadata.d.ts +8 -0
  186. package/dist/projections/graphs/views/ViewOfMetadata.d.ts.map +1 -0
  187. package/dist/projections/graphs/views/ViewOfMetadata.js +4 -0
  188. package/dist/projections/graphs/views/ViewOfMetadata.js.map +1 -0
  189. package/dist/projections/graphs/views/ViewOfOptions.d.ts +6 -0
  190. package/dist/projections/graphs/views/ViewOfOptions.d.ts.map +1 -0
  191. package/dist/projections/graphs/views/ViewOfOptions.js +4 -0
  192. package/dist/projections/graphs/views/ViewOfOptions.js.map +1 -0
  193. package/dist/projections/graphs/views/ViewRootNotANode.d.ts +16 -0
  194. package/dist/projections/graphs/views/ViewRootNotANode.d.ts.map +1 -0
  195. package/dist/projections/graphs/views/ViewRootNotANode.js +21 -0
  196. package/dist/projections/graphs/views/ViewRootNotANode.js.map +1 -0
  197. package/dist/projections/graphs/views/declareGraphViewMember.d.ts +17 -0
  198. package/dist/projections/graphs/views/declareGraphViewMember.d.ts.map +1 -0
  199. package/dist/projections/graphs/views/declareGraphViewMember.js +31 -0
  200. package/dist/projections/graphs/views/declareGraphViewMember.js.map +1 -0
  201. package/dist/projections/graphs/views/follows.d.ts +13 -0
  202. package/dist/projections/graphs/views/follows.d.ts.map +1 -0
  203. package/dist/projections/graphs/views/follows.js +24 -0
  204. package/dist/projections/graphs/views/follows.js.map +1 -0
  205. package/dist/projections/graphs/views/fromEdge.d.ts +10 -0
  206. package/dist/projections/graphs/views/fromEdge.d.ts.map +1 -0
  207. package/dist/projections/graphs/views/fromEdge.js +15 -0
  208. package/dist/projections/graphs/views/fromEdge.js.map +1 -0
  209. package/dist/projections/graphs/views/index.d.ts +41 -0
  210. package/dist/projections/graphs/views/index.d.ts.map +1 -0
  211. package/dist/projections/graphs/views/index.js +28 -0
  212. package/dist/projections/graphs/views/index.js.map +1 -0
  213. package/dist/projections/graphs/views/viewKey.d.ts +8 -0
  214. package/dist/projections/graphs/views/viewKey.d.ts.map +1 -0
  215. package/dist/projections/graphs/views/viewKey.js +13 -0
  216. package/dist/projections/graphs/views/viewKey.js.map +1 -0
  217. package/dist/projections/graphs/views/viewOf.d.ts +22 -0
  218. package/dist/projections/graphs/views/viewOf.d.ts.map +1 -0
  219. package/dist/projections/graphs/views/viewOf.js +41 -0
  220. package/dist/projections/graphs/views/viewOf.js.map +1 -0
  221. package/dist/projections/graphs/views/viewProperty.d.ts +9 -0
  222. package/dist/projections/graphs/views/viewProperty.d.ts.map +1 -0
  223. package/dist/projections/graphs/views/viewProperty.js +14 -0
  224. package/dist/projections/graphs/views/viewProperty.js.map +1 -0
  225. package/dist/reactors/Reactors.d.ts +15 -5
  226. package/dist/reactors/Reactors.d.ts.map +1 -1
  227. package/dist/reactors/Reactors.js +95 -18
  228. package/dist/reactors/Reactors.js.map +1 -1
  229. package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.d.ts +26 -0
  230. package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.d.ts.map +1 -0
  231. package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.js +64 -0
  232. package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.js.map +1 -0
  233. package/dist/reducers/Reducers.d.ts +11 -5
  234. package/dist/reducers/Reducers.d.ts.map +1 -1
  235. package/dist/reducers/Reducers.js +93 -19
  236. package/dist/reducers/Reducers.js.map +1 -1
  237. package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.d.ts +25 -0
  238. package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.d.ts.map +1 -0
  239. package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.js +70 -0
  240. package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.js.map +1 -0
  241. package/dist/testing/InProcessAppendMetadata.d.ts +30 -0
  242. package/dist/testing/InProcessAppendMetadata.d.ts.map +1 -0
  243. package/dist/testing/InProcessAppendMetadata.js +107 -0
  244. package/dist/testing/InProcessAppendMetadata.js.map +1 -0
  245. package/dist/testing/InProcessBatchAppend.d.ts +62 -0
  246. package/dist/testing/InProcessBatchAppend.d.ts.map +1 -0
  247. package/dist/testing/InProcessBatchAppend.js +131 -0
  248. package/dist/testing/InProcessBatchAppend.js.map +1 -0
  249. package/dist/testing/InProcessEventPayload.d.ts +23 -0
  250. package/dist/testing/InProcessEventPayload.d.ts.map +1 -0
  251. package/dist/testing/InProcessEventPayload.js +94 -0
  252. package/dist/testing/InProcessEventPayload.js.map +1 -0
  253. package/dist/testing/InProcessEventReadCriteria.d.ts +9 -0
  254. package/dist/testing/InProcessEventReadCriteria.d.ts.map +1 -0
  255. package/dist/testing/InProcessEventReadCriteria.js +4 -0
  256. package/dist/testing/InProcessEventReadCriteria.js.map +1 -0
  257. package/dist/testing/InProcessEventReadFilter.d.ts +14 -0
  258. package/dist/testing/InProcessEventReadFilter.d.ts.map +1 -0
  259. package/dist/testing/InProcessEventReadFilter.js +31 -0
  260. package/dist/testing/InProcessEventReadFilter.js.map +1 -0
  261. package/dist/testing/InProcessEventSequence.d.ts +8 -5
  262. package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
  263. package/dist/testing/InProcessEventSequence.js +59 -275
  264. package/dist/testing/InProcessEventSequence.js.map +1 -1
  265. package/dist/testing/InProcessEventSequenceEnvironment.d.ts +13 -0
  266. package/dist/testing/InProcessEventSequenceEnvironment.d.ts.map +1 -0
  267. package/dist/testing/InProcessEventSequenceEnvironment.js +4 -0
  268. package/dist/testing/InProcessEventSequenceEnvironment.js.map +1 -0
  269. package/dist/testing/InProcessSingleAppend.d.ts +34 -0
  270. package/dist/testing/InProcessSingleAppend.d.ts.map +1 -0
  271. package/dist/testing/InProcessSingleAppend.js +95 -0
  272. package/dist/testing/InProcessSingleAppend.js.map +1 -0
  273. package/dist/testing/projections/ProjectionCapabilities.d.ts +0 -8
  274. package/dist/testing/projections/ProjectionCapabilities.d.ts.map +1 -1
  275. package/dist/testing/projections/ProjectionCapabilities.js +21 -312
  276. package/dist/testing/projections/ProjectionCapabilities.js.map +1 -1
  277. package/dist/testing/projections/ProjectionCapabilityReject.d.ts +3 -0
  278. package/dist/testing/projections/ProjectionCapabilityReject.d.ts.map +1 -0
  279. package/dist/testing/projections/ProjectionCapabilityReject.js +4 -0
  280. package/dist/testing/projections/ProjectionCapabilityReject.js.map +1 -0
  281. package/dist/testing/projections/ProjectionCapabilityReporter.d.ts +12 -0
  282. package/dist/testing/projections/ProjectionCapabilityReporter.d.ts.map +1 -0
  283. package/dist/testing/projections/ProjectionCapabilityReporter.js +33 -0
  284. package/dist/testing/projections/ProjectionCapabilityReporter.js.map +1 -0
  285. package/dist/testing/projections/ProjectionDefinitionCapabilities.d.ts +11 -0
  286. package/dist/testing/projections/ProjectionDefinitionCapabilities.d.ts.map +1 -0
  287. package/dist/testing/projections/ProjectionDefinitionCapabilities.js +45 -0
  288. package/dist/testing/projections/ProjectionDefinitionCapabilities.js.map +1 -0
  289. package/dist/testing/projections/ProjectionEventSchemaResolver.d.ts +13 -0
  290. package/dist/testing/projections/ProjectionEventSchemaResolver.d.ts.map +1 -0
  291. package/dist/testing/projections/ProjectionEventSchemaResolver.js +22 -0
  292. package/dist/testing/projections/ProjectionEventSchemaResolver.js.map +1 -0
  293. package/dist/testing/projections/ProjectionExpressionCapabilities.d.ts +19 -0
  294. package/dist/testing/projections/ProjectionExpressionCapabilities.d.ts.map +1 -0
  295. package/dist/testing/projections/ProjectionExpressionCapabilities.js +103 -0
  296. package/dist/testing/projections/ProjectionExpressionCapabilities.js.map +1 -0
  297. package/dist/testing/projections/ProjectionInitialValueCapabilities.d.ts +16 -0
  298. package/dist/testing/projections/ProjectionInitialValueCapabilities.d.ts.map +1 -0
  299. package/dist/testing/projections/ProjectionInitialValueCapabilities.js +72 -0
  300. package/dist/testing/projections/ProjectionInitialValueCapabilities.js.map +1 -0
  301. package/dist/testing/projections/ProjectionMappingCapabilities.d.ts +21 -0
  302. package/dist/testing/projections/ProjectionMappingCapabilities.d.ts.map +1 -0
  303. package/dist/testing/projections/ProjectionMappingCapabilities.js +86 -0
  304. package/dist/testing/projections/ProjectionMappingCapabilities.js.map +1 -0
  305. package/dist/testing/projections/ProjectionMappingValidation.d.ts +9 -0
  306. package/dist/testing/projections/ProjectionMappingValidation.d.ts.map +1 -0
  307. package/dist/testing/projections/ProjectionMappingValidation.js +4 -0
  308. package/dist/testing/projections/ProjectionMappingValidation.js.map +1 -0
  309. package/dist/testing/projections/ProjectionReadModelCapabilities.d.ts +11 -0
  310. package/dist/testing/projections/ProjectionReadModelCapabilities.d.ts.map +1 -0
  311. package/dist/testing/projections/ProjectionReadModelCapabilities.js +40 -0
  312. package/dist/testing/projections/ProjectionReadModelCapabilities.js.map +1 -0
  313. package/dist/testing/projections/ProjectionRootCapabilities.d.ts +20 -0
  314. package/dist/testing/projections/ProjectionRootCapabilities.d.ts.map +1 -0
  315. package/dist/testing/projections/ProjectionRootCapabilities.js +73 -0
  316. package/dist/testing/projections/ProjectionRootCapabilities.js.map +1 -0
  317. package/dist/testing/projections/ProjectionScalarConverter.d.ts +21 -0
  318. package/dist/testing/projections/ProjectionScalarConverter.d.ts.map +1 -0
  319. package/dist/testing/projections/ProjectionScalarConverter.js +105 -0
  320. package/dist/testing/projections/ProjectionScalarConverter.js.map +1 -0
  321. package/dist/testing/projections/ProjectionSchemaCapabilities.d.ts +26 -0
  322. package/dist/testing/projections/ProjectionSchemaCapabilities.d.ts.map +1 -0
  323. package/dist/testing/projections/ProjectionSchemaCapabilities.js +109 -0
  324. package/dist/testing/projections/ProjectionSchemaCapabilities.js.map +1 -0
  325. package/dist/testing/projections/ProjectionValueConverter.d.ts +5 -0
  326. package/dist/testing/projections/ProjectionValueConverter.d.ts.map +1 -1
  327. package/dist/testing/projections/ProjectionValueConverter.js +36 -84
  328. package/dist/testing/projections/ProjectionValueConverter.js.map +1 -1
  329. package/dist/tsconfig.tsbuildinfo +1 -1
  330. package/dist/types/DecoratorType.d.ts +3 -1
  331. package/dist/types/DecoratorType.d.ts.map +1 -1
  332. package/dist/types/DecoratorType.js +2 -0
  333. package/dist/types/DecoratorType.js.map +1 -1
  334. package/for_ChronicleClient/when_reconnecting/and_an_observation_stream_lost_its_session.spec.ts +212 -0
  335. package/observation/ObservationReconnectBackoff.ts +109 -0
  336. package/observation/ObservationStreamOutcome.ts +12 -0
  337. package/observation/classifyStreamError.ts +67 -0
  338. package/observation/for_ObservationReconnectBackoff/given/a_backoff.ts +29 -0
  339. package/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.ts +52 -0
  340. package/observation/for_ObservationReconnectBackoff/when_a_stream_delivered_before_it_ended.spec.ts +23 -0
  341. package/observation/for_ObservationReconnectBackoff/when_a_stream_stayed_open_before_it_ended.spec.ts +25 -0
  342. package/observation/for_ObservationReconnectBackoff/when_jittering_the_delay.spec.ts +24 -0
  343. package/observation/for_ObservationReconnectBackoff/when_streams_keep_ending_without_working.spec.ts +24 -0
  344. package/observation/for_ObservationReconnectBackoff/when_the_base_delay_is_not_positive.spec.ts +18 -0
  345. package/observation/for_ObservationReconnectBackoff/when_the_settings_are_not_finite.spec.ts +32 -0
  346. package/observation/for_ObservationReconnectBackoff/when_using_the_defaults.spec.ts +29 -0
  347. package/observation/for_classifyStreamError/when_classifying_a_stream_error.spec.ts +36 -0
  348. package/package.json +2 -2
  349. package/projections/for_Graphs/given/a_discovered_graph.ts +3 -2
  350. package/projections/for_Graphs/given/a_graph_with_views.ts +91 -0
  351. package/projections/for_Graphs/given/organization.ts +3 -2
  352. package/projections/for_Graphs/given/organization_with_views.fixture.ts +129 -0
  353. package/projections/for_Graphs/when_building_graph_views.spec.ts +218 -0
  354. package/projections/for_Graphs/when_declaring_an_invalid_graph_view.spec.ts +229 -0
  355. package/projections/for_Graphs/when_declaring_graph_views.standard.spec.ts +49 -0
  356. package/projections/for_Graphs/when_discovering_graph_views.spec.ts +58 -0
  357. package/projections/graphs/Graphs.ts +44 -0
  358. package/projections/graphs/IGraphs.ts +10 -2
  359. package/projections/graphs/index.ts +1 -0
  360. package/projections/graphs/views/AmbiguousDirection.ts +23 -0
  361. package/projections/graphs/views/DuplicateViewName.ts +23 -0
  362. package/projections/graphs/views/EdgeNotIncidentOnRoot.ts +24 -0
  363. package/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.ts +21 -0
  364. package/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.ts +22 -0
  365. package/projections/graphs/views/FollowsOptions.ts +20 -0
  366. package/projections/graphs/views/GraphEdgeDirection.ts +13 -0
  367. package/projections/graphs/views/GraphView.ts +18 -0
  368. package/projections/graphs/views/GraphViewBuildResult.ts +19 -0
  369. package/projections/graphs/views/GraphViewCardinality.ts +13 -0
  370. package/projections/graphs/views/GraphViewDefinition.ts +20 -0
  371. package/projections/graphs/views/GraphViewDefinitionBuilder.ts +322 -0
  372. package/projections/graphs/views/GraphViewDefinitionSerializer.ts +90 -0
  373. package/projections/graphs/views/GraphViewEdgeReference.ts +8 -0
  374. package/projections/graphs/views/GraphViewMember.ts +11 -0
  375. package/projections/graphs/views/GraphViewMemberKind.ts +16 -0
  376. package/projections/graphs/views/GraphViewMemberMetadata.ts +31 -0
  377. package/projections/graphs/views/GraphViewPropertyMember.ts +18 -0
  378. package/projections/graphs/views/GraphViewReason.ts +47 -0
  379. package/projections/graphs/views/GraphViewRelationMember.ts +29 -0
  380. package/projections/graphs/views/GraphViewSchema.ts +14 -0
  381. package/projections/graphs/views/GraphViewSchemaEdge.ts +20 -0
  382. package/projections/graphs/views/GraphViewSchemaNode.ts +14 -0
  383. package/projections/graphs/views/GraphViewSerializerOptions.ts +11 -0
  384. package/projections/graphs/views/RecursiveView.ts +22 -0
  385. package/projections/graphs/views/RelationTargetNotAView.ts +23 -0
  386. package/projections/graphs/views/TargetLabelMismatch.ts +25 -0
  387. package/projections/graphs/views/UnknownEdge.ts +23 -0
  388. package/projections/graphs/views/UnknownEdgeProperty.ts +24 -0
  389. package/projections/graphs/views/UnknownNodeProperty.ts +24 -0
  390. package/projections/graphs/views/ViewIsAlsoSchema.ts +21 -0
  391. package/projections/graphs/views/ViewOfMetadata.ts +11 -0
  392. package/projections/graphs/views/ViewOfOptions.ts +8 -0
  393. package/projections/graphs/views/ViewRootNotANode.ts +23 -0
  394. package/projections/graphs/views/declareGraphViewMember.ts +36 -0
  395. package/projections/graphs/views/follows.ts +28 -0
  396. package/projections/graphs/views/fromEdge.ts +17 -0
  397. package/projections/graphs/views/index.ts +43 -0
  398. package/projections/graphs/views/viewKey.ts +15 -0
  399. package/projections/graphs/views/viewOf.ts +50 -0
  400. package/projections/graphs/views/viewProperty.ts +16 -0
  401. package/reactors/Reactors.ts +101 -18
  402. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_handler_failed_with_a_lost_session.spec.ts +32 -0
  403. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_replaced_stream_fails_late.spec.ts +28 -0
  404. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_stream_delivered_before_it_ended.spec.ts +24 -0
  405. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_stream_stayed_open_before_it_ended.spec.ts +23 -0
  406. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_it_is_disposed_while_waiting_to_reopen.spec.ts +27 -0
  407. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_streams_keep_ending_without_working.spec.ts +24 -0
  408. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_client_reconnected_after_streams_kept_ending.spec.ts +24 -0
  409. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_client_reconnected_while_waiting_to_reopen.spec.ts +25 -0
  410. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_kernel_lost_the_session.spec.ts +24 -0
  411. package/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.ts +69 -0
  412. package/reducers/Reducers.ts +99 -19
  413. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_reducer_failed_with_a_lost_session.spec.ts +33 -0
  414. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_replaced_stream_fails_late.spec.ts +28 -0
  415. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_stream_delivered_before_it_ended.spec.ts +24 -0
  416. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_stream_stayed_open_before_it_ended.spec.ts +23 -0
  417. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_it_is_disposed_while_waiting_to_reopen.spec.ts +27 -0
  418. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_streams_keep_ending_without_working.spec.ts +24 -0
  419. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_client_reconnected_after_streams_kept_ending.spec.ts +24 -0
  420. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_client_reconnected_while_waiting_to_reopen.spec.ts +25 -0
  421. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_kernel_lost_the_session.spec.ts +24 -0
  422. package/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.ts +69 -0
  423. package/testing/InProcessAppendMetadata.ts +119 -0
  424. package/testing/InProcessBatchAppend.ts +142 -0
  425. package/testing/InProcessEventPayload.ts +100 -0
  426. package/testing/InProcessEventReadCriteria.ts +11 -0
  427. package/testing/InProcessEventReadFilter.ts +37 -0
  428. package/testing/InProcessEventSequence.ts +63 -257
  429. package/testing/InProcessEventSequenceEnvironment.ts +16 -0
  430. package/testing/InProcessSingleAppend.ts +99 -0
  431. package/testing/for_InProcessEventSequence/when_preserving_validation_and_commit_order.spec.ts +95 -0
  432. package/testing/projections/ProjectionCapabilities.ts +23 -279
  433. package/testing/projections/ProjectionCapabilityReject.ts +5 -0
  434. package/testing/projections/ProjectionCapabilityReporter.ts +31 -0
  435. package/testing/projections/ProjectionDefinitionCapabilities.ts +45 -0
  436. package/testing/projections/ProjectionEventSchemaResolver.ts +23 -0
  437. package/testing/projections/ProjectionExpressionCapabilities.ts +101 -0
  438. package/testing/projections/ProjectionInitialValueCapabilities.ts +73 -0
  439. package/testing/projections/ProjectionMappingCapabilities.ts +85 -0
  440. package/testing/projections/ProjectionMappingValidation.ts +12 -0
  441. package/testing/projections/ProjectionReadModelCapabilities.ts +42 -0
  442. package/testing/projections/ProjectionRootCapabilities.ts +75 -0
  443. package/testing/projections/ProjectionScalarConverter.ts +106 -0
  444. package/testing/projections/ProjectionSchemaCapabilities.ts +112 -0
  445. package/testing/projections/ProjectionValueConverter.ts +37 -76
  446. package/testing/projections/for_ProjectionCapabilities/when_reporting_the_first_unsupported_operation.spec.ts +74 -0
  447. package/testing/projections/for_ProjectionValueConverter/when_converting_structured_and_scalar_values.spec.ts +64 -0
  448. package/types/DecoratorType.ts +4 -1
@@ -0,0 +1,109 @@
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
+ * Settings for how a reactor or reducer waits before opening its observation stream again.
6
+ * Every setting is optional; the defaults match the .NET client.
7
+ */
8
+ export interface ObservationReconnectBackoffOptions {
9
+ /** The wait in milliseconds after a stream that had worked. Defaults to 2 seconds. */
10
+ baseDelayMs?: number;
11
+
12
+ /** The longest wait in milliseconds, however often streams end. Defaults to 60 seconds. */
13
+ maxDelayMs?: number;
14
+
15
+ /** How long in milliseconds a stream must stay open to count as having worked. Defaults to 3 minutes. */
16
+ healthyStreamDurationMs?: number;
17
+
18
+ /** Returns the current time in milliseconds, measuring how long a stream stayed open. Defaults to `performance.now`. */
19
+ now?: () => number;
20
+
21
+ /** Returns a value in [0, 1) choosing where in the upper half of the wait this one lands. Defaults to `Math.random`. */
22
+ nextJitter?: () => number;
23
+ }
24
+
25
+ const finiteOr = (value: number | undefined, fallback: number, isAllowed: (value: number) => boolean): number =>
26
+ value !== undefined && Number.isFinite(value) && isAllowed(value) ? value : fallback;
27
+
28
+ /**
29
+ * Decides how long one reactor or reducer waits before opening its observation stream again after it ended.
30
+ *
31
+ * A fixed delay is right for one observer and wrong for many: seventy reactors whose streams fail together
32
+ * come back together, every two seconds, against a kernel that is still busy. So each stream that ends without
33
+ * having worked doubles the wait, up to a ceiling, and every wait lands at random in its upper half so a herd
34
+ * spreads out.
35
+ *
36
+ * The wait starts over once a stream has worked: it delivered something, or it stayed open long enough to have
37
+ * been established. A base delay of zero or less is used as it is.
38
+ */
39
+ export class ObservationReconnectBackoff {
40
+ /** The default wait after a stream that had worked. */
41
+ static readonly defaultBaseDelayMs = 2_000;
42
+
43
+ /** The default longest wait between attempts. */
44
+ static readonly defaultMaxDelayMs = 60_000;
45
+
46
+ /**
47
+ * The default time a stream must stay open to count as having worked.
48
+ *
49
+ * It is longer than the kernel takes to give up establishing a stream: the kernel asks a busy observer again
50
+ * on the same stream, up to four attempts of a thirty-second grain call each, before it fails the stream. A
51
+ * shorter threshold would count every such stream as having worked and start the wait over at the base delay.
52
+ */
53
+ static readonly defaultHealthyStreamDurationMs = 180_000;
54
+
55
+ private static readonly _maxExponent = 30;
56
+
57
+ private readonly _baseDelayMs: number;
58
+ private readonly _maxDelayMs: number;
59
+ private readonly _healthyStreamDurationMs: number;
60
+ private readonly _now: () => number;
61
+ private readonly _nextJitter: () => number;
62
+ private _streamsEndedWithoutWorking = 0;
63
+ private _streamOpenedAt: number;
64
+
65
+ /**
66
+ * Creates a new {@link ObservationReconnectBackoff}.
67
+ * @param options - The settings; anything left out uses its default.
68
+ */
69
+ constructor(options: ObservationReconnectBackoffOptions = {}) {
70
+ // A wait that is not a finite number would reach setTimeout as about one millisecond: a hot loop.
71
+ this._baseDelayMs = finiteOr(options.baseDelayMs, ObservationReconnectBackoff.defaultBaseDelayMs, () => true);
72
+ this._maxDelayMs = finiteOr(options.maxDelayMs, ObservationReconnectBackoff.defaultMaxDelayMs, value => value > 0);
73
+ this._healthyStreamDurationMs = finiteOr(options.healthyStreamDurationMs,
74
+ ObservationReconnectBackoff.defaultHealthyStreamDurationMs, value => value >= 0);
75
+ this._now = options.now ?? (() => performance.now());
76
+ this._nextJitter = options.nextJitter ?? Math.random;
77
+ this._streamOpenedAt = this._now();
78
+ }
79
+
80
+ /** Records that a new observation stream was opened. */
81
+ streamOpened(): void {
82
+ this._streamOpenedAt = this._now();
83
+ }
84
+
85
+ /** Records that the open stream delivered something, which proves it was established. */
86
+ streamDelivered(): void {
87
+ this._streamsEndedWithoutWorking = 0;
88
+ }
89
+
90
+ /**
91
+ * Gets how long to wait before opening the stream again, now that the open one has ended.
92
+ * @returns The wait in milliseconds.
93
+ */
94
+ nextDelayMs(): number {
95
+ if (this._baseDelayMs <= 0) {
96
+ return this._baseDelayMs;
97
+ }
98
+
99
+ if (this._now() - this._streamOpenedAt >= this._healthyStreamDurationMs) {
100
+ this._streamsEndedWithoutWorking = 0;
101
+ }
102
+
103
+ const exponent = Math.min(this._streamsEndedWithoutWorking, ObservationReconnectBackoff._maxExponent);
104
+ this._streamsEndedWithoutWorking++;
105
+ const ceiling = Math.min(this._maxDelayMs, this._baseDelayMs * Math.pow(2, exponent));
106
+ const jitter = 0.5 + 0.5 * Math.min(Math.max(this._nextJitter(), 0), 1);
107
+ return Math.floor(ceiling * jitter);
108
+ }
109
+ }
@@ -0,0 +1,12 @@
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
+ * How one reactor or reducer observation stream ended, which decides what happens next.
6
+ *
7
+ * - `ended`: the stream ended or failed while it was still the current one; open it again after a backoff.
8
+ * - `sessionLost`: the kernel no longer knows the connection; the whole client reconnects and re-registers it.
9
+ * - `superseded`: a disconnect, a dispose or a newer stream replaced it; nothing to do.
10
+ * - `stopped`: the client cancelled it on purpose; nothing to do.
11
+ */
12
+ export type ObservationStreamOutcome = 'ended' | 'sessionLost' | 'superseded' | 'stopped';
@@ -0,0 +1,67 @@
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
+ /** What ended a kernel observation stream, deciding how the client recovers. */
5
+ export enum StreamErrorKind {
6
+ /** The stream failed for a reason of its own; it is opened again after a backoff. */
7
+ Failure = 'Failure',
8
+
9
+ /** The client cancelled the stream itself; it is not opened again. */
10
+ Cancelled = 'Cancelled',
11
+
12
+ /** The kernel is stopping or unreachable; the stream is opened again after a backoff. */
13
+ ConnectionLost = 'ConnectionLost',
14
+
15
+ /**
16
+ * The kernel no longer knows this client's connection, for instance after it restarted. Opening the stream again
17
+ * with the same connection id can never work, so the whole client reconnects with a new one.
18
+ */
19
+ SessionLost = 'SessionLost'
20
+ }
21
+
22
+ const CANCELLED = 1;
23
+ const UNAVAILABLE = 14;
24
+ const CLIENT_IS_NOT_CONNECTED = 'ClientIsNotConnected';
25
+
26
+ interface GrpcLikeError {
27
+ code?: unknown;
28
+ details?: unknown;
29
+ message?: unknown;
30
+ name?: unknown;
31
+ cause?: unknown;
32
+ }
33
+
34
+ const mentionsClientIsNotConnected = (error: GrpcLikeError): boolean =>
35
+ [error.details, error.message].some(text => typeof text === 'string' && text.includes(CLIENT_IS_NOT_CONNECTED));
36
+
37
+ /**
38
+ * Classifies an error that ended a kernel observation stream, looking through wrapping errors.
39
+ *
40
+ * An {@link AggregateError} takes the most serious kind among the errors it wraps, in this order:
41
+ * {@link StreamErrorKind.Failure}, then {@link StreamErrorKind.SessionLost}, then {@link StreamErrorKind.ConnectionLost},
42
+ * then {@link StreamErrorKind.Cancelled}. This matches the .NET client.
43
+ * @param error - The error the stream ended with.
44
+ * @returns The {@link StreamErrorKind} for the error.
45
+ */
46
+ export function classifyStreamError(error: unknown): StreamErrorKind {
47
+ if (error === null || typeof error !== 'object') {
48
+ return StreamErrorKind.Failure;
49
+ }
50
+
51
+ if (error instanceof AggregateError && error.errors.length > 0) {
52
+ const kinds = error.errors.map(classifyStreamError);
53
+ if (kinds.includes(StreamErrorKind.Failure)) return StreamErrorKind.Failure;
54
+ if (kinds.includes(StreamErrorKind.SessionLost)) return StreamErrorKind.SessionLost;
55
+ return kinds.includes(StreamErrorKind.ConnectionLost) ? StreamErrorKind.ConnectionLost : StreamErrorKind.Cancelled;
56
+ }
57
+
58
+ const grpcError = error as GrpcLikeError;
59
+ if (grpcError.name === 'AbortError') return StreamErrorKind.Cancelled;
60
+ if (typeof grpcError.code === 'number') {
61
+ if (grpcError.code === CANCELLED) return StreamErrorKind.Cancelled;
62
+ if (grpcError.code === UNAVAILABLE) return StreamErrorKind.ConnectionLost;
63
+ return mentionsClientIsNotConnected(grpcError) ? StreamErrorKind.SessionLost : StreamErrorKind.Failure;
64
+ }
65
+
66
+ return grpcError.cause !== undefined ? classifyStreamError(grpcError.cause) : StreamErrorKind.Failure;
67
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ObservationReconnectBackoff } from '../../ObservationReconnectBackoff.js';
5
+
6
+ /** A backoff with a 2 second base, a 60 second ceiling and a 3 minute healthy threshold, on a clock and jitter the spec controls. */
7
+ export class a_backoff {
8
+ static readonly baseDelayMs = 2_000;
9
+ static readonly maxDelayMs = 60_000;
10
+ static readonly healthyStreamDurationMs = 180_000;
11
+
12
+ now = 0;
13
+ jitter = 0;
14
+
15
+ readonly backoff = new ObservationReconnectBackoff({
16
+ baseDelayMs: a_backoff.baseDelayMs,
17
+ maxDelayMs: a_backoff.maxDelayMs,
18
+ healthyStreamDurationMs: a_backoff.healthyStreamDurationMs,
19
+ now: () => this.now,
20
+ nextJitter: () => this.jitter
21
+ });
22
+
23
+ /** Opens a stream, lets it stay open for a while and ends it, returning the wait before the next one. */
24
+ streamEndsAfter(openForMs: number): number {
25
+ this.backoff.streamOpened();
26
+ this.now += openForMs;
27
+ return this.backoff.nextDelayMs();
28
+ }
29
+ }
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ /** How one observation stream behaves: what it delivers, how long it stays open and the error it ends with, if any. */
5
+ export interface StreamScript<T> {
6
+ /** What the stream delivers before it ends. */
7
+ deliver?: T[];
8
+
9
+ /** How long, in milliseconds, the stream stays open after delivering before it ends. */
10
+ openForMs?: number;
11
+
12
+ /** Whether the stream stays open until the client aborts it. */
13
+ untilAborted?: boolean;
14
+
15
+ /** How long, in milliseconds, an aborted stream takes to end, as a slow transport would. */
16
+ endsLateByMs?: number;
17
+
18
+ /** The error the stream ends with. */
19
+ error?: unknown;
20
+ }
21
+
22
+ /** Records the observation streams a reactor or reducer opens and plays them by their scripts. */
23
+ export class a_scripted_stream<T> {
24
+ readonly openedAt: number[] = [];
25
+ readonly scripts: StreamScript<T>[] = [];
26
+ open = 0;
27
+
28
+ /** The observe method of the fake kernel connection. */
29
+ readonly observe = (_messages: unknown, options: { signal: AbortSignal }): AsyncGenerator<T> => this.play(options.signal);
30
+
31
+ /** Gets the wait before each stream after the first was opened. */
32
+ get waits(): number[] {
33
+ return this.openedAt.slice(1).map((at, index) => at - this.openedAt[index]);
34
+ }
35
+
36
+ private async *play(signal: AbortSignal): AsyncGenerator<T> {
37
+ this.openedAt.push(Date.now());
38
+ this.open++;
39
+ try {
40
+ const script = this.scripts.shift() ?? {};
41
+ for (const delivery of script.deliver ?? []) yield delivery;
42
+ if (script.openForMs) await new Promise(resolve => setTimeout(resolve, script.openForMs));
43
+ if (script.untilAborted) {
44
+ await new Promise<void>(resolve => signal.aborted ? resolve() : signal.addEventListener('abort', () => resolve(), { once: true }));
45
+ if (script.endsLateByMs) await new Promise(resolve => setTimeout(resolve, script.endsLateByMs));
46
+ }
47
+ if (script.error) throw script.error;
48
+ } finally {
49
+ this.open--;
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,23 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { beforeEach, chai, describe, it } from 'vitest';
5
+ import { a_backoff } from './given/a_backoff.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when a stream delivered before it ended', () => {
10
+ let context: a_backoff;
11
+ let delay: number;
12
+
13
+ beforeEach(() => {
14
+ context = new a_backoff();
15
+ for (let attempt = 0; attempt < 4; attempt++) context.streamEndsAfter(1_000);
16
+ context.backoff.streamOpened();
17
+ context.backoff.streamDelivered();
18
+ context.now += 1_000;
19
+ delay = context.backoff.nextDelayMs();
20
+ });
21
+
22
+ it('should start the wait over at the base delay', () => delay.should.equal(a_backoff.baseDelayMs / 2));
23
+ });
@@ -0,0 +1,25 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { beforeEach, chai, describe, it } from 'vitest';
5
+ import { a_backoff } from './given/a_backoff.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when a stream stayed open before it ended', () => {
10
+ let longEnough: number;
11
+ let tooShort: number;
12
+
13
+ beforeEach(() => {
14
+ const healthy = new a_backoff();
15
+ for (let attempt = 0; attempt < 3; attempt++) healthy.streamEndsAfter(1_000);
16
+ longEnough = healthy.streamEndsAfter(a_backoff.healthyStreamDurationMs);
17
+
18
+ const unhealthy = new a_backoff();
19
+ for (let attempt = 0; attempt < 3; attempt++) unhealthy.streamEndsAfter(1_000);
20
+ tooShort = unhealthy.streamEndsAfter(a_backoff.healthyStreamDurationMs - 1);
21
+ });
22
+
23
+ it('should start the wait over at the base delay once it stayed open long enough', () => longEnough.should.equal(a_backoff.baseDelayMs / 2));
24
+ it('should keep backing off when it closed just before counting as having worked', () => tooShort.should.equal(8_000));
25
+ });
@@ -0,0 +1,24 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { beforeEach, chai, describe, it } from 'vitest';
5
+ import { a_backoff } from './given/a_backoff.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when jittering the delay', () => {
10
+ let delays: number[];
11
+
12
+ beforeEach(() => {
13
+ delays = [0, 0.5, -1, 2].map(jitter => {
14
+ const context = new a_backoff();
15
+ context.jitter = jitter;
16
+ return context.streamEndsAfter(0);
17
+ });
18
+ });
19
+
20
+ it('should land at half the wait for the lowest jitter', () => delays[0].should.equal(1_000));
21
+ it('should land in the upper half of the wait', () => delays[1].should.equal(1_500));
22
+ it('should clamp a jitter below zero to the lower bound', () => delays[2].should.equal(1_000));
23
+ it('should clamp a jitter above one to the full wait', () => delays[3].should.equal(2_000));
24
+ });
@@ -0,0 +1,24 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { beforeEach, chai, describe, it } from 'vitest';
5
+ import { a_backoff } from './given/a_backoff.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when streams keep ending without working', () => {
10
+ let context: a_backoff;
11
+ let delays: number[];
12
+
13
+ beforeEach(() => {
14
+ context = new a_backoff();
15
+ context.jitter = 0.999999;
16
+ delays = Array.from({ length: 8 }, () => context.streamEndsAfter(1_000));
17
+ });
18
+
19
+ it('should double the wait each time, starting from the base delay', () =>
20
+ delays.slice(0, 5).map(delay => Math.round(delay / 1_000)).should.deep.equal([2, 4, 8, 16, 32]));
21
+
22
+ it('should never wait longer than the ceiling', () => delays.forEach(delay => delay.should.be.at.most(a_backoff.maxDelayMs)));
23
+ it('should keep waiting close to the ceiling once it is reached', () => delays.slice(5).forEach(delay => delay.should.be.at.least(59_999)));
24
+ });
@@ -0,0 +1,18 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { beforeEach, chai, describe, it } from 'vitest';
5
+ import { ObservationReconnectBackoff } from '../ObservationReconnectBackoff.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when the base delay is not positive', () => {
10
+ let delays: number[];
11
+
12
+ beforeEach(() => {
13
+ const backoff = new ObservationReconnectBackoff({ baseDelayMs: 0, nextJitter: () => 0.5 });
14
+ delays = [backoff.nextDelayMs(), backoff.nextDelayMs(), backoff.nextDelayMs()];
15
+ });
16
+
17
+ it('should use the base delay as it is, without backing off', () => delays.should.deep.equal([0, 0, 0]));
18
+ });
@@ -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 { beforeEach, chai, describe, it } from 'vitest';
5
+ import { ObservationReconnectBackoff } from '../ObservationReconnectBackoff.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when the settings are not finite', () => {
10
+ let delays: number[];
11
+
12
+ beforeEach(() => {
13
+ let now = 0;
14
+ const backoff = new ObservationReconnectBackoff({
15
+ baseDelayMs: Number.NaN,
16
+ maxDelayMs: -1,
17
+ healthyStreamDurationMs: Number.POSITIVE_INFINITY,
18
+ now: () => now,
19
+ nextJitter: () => 1
20
+ });
21
+ delays = [];
22
+ for (let attempt = 0; attempt < 7; attempt++) {
23
+ backoff.streamOpened();
24
+ delays.push(backoff.nextDelayMs());
25
+ }
26
+ now = ObservationReconnectBackoff.defaultHealthyStreamDurationMs;
27
+ delays.push(backoff.nextDelayMs());
28
+ });
29
+
30
+ it('should fall back to the default delays', () =>
31
+ delays.should.deep.equal([2_000, 4_000, 8_000, 16_000, 32_000, 60_000, 60_000, 2_000]));
32
+ });
@@ -0,0 +1,29 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { beforeEach, chai, describe, it } from 'vitest';
5
+ import { ObservationReconnectBackoff } from '../ObservationReconnectBackoff.js';
6
+
7
+ chai.should();
8
+
9
+ describe('when using the defaults', () => {
10
+ let delays: number[];
11
+
12
+ beforeEach(() => {
13
+ let now = 0;
14
+ const backoff = new ObservationReconnectBackoff({ now: () => now, nextJitter: () => 0.999999 });
15
+ delays = Array.from({ length: 7 }, () => {
16
+ backoff.streamOpened();
17
+ now += 1_000;
18
+ return backoff.nextDelayMs();
19
+ });
20
+ backoff.streamOpened();
21
+ now += ObservationReconnectBackoff.defaultHealthyStreamDurationMs;
22
+ delays.push(backoff.nextDelayMs());
23
+ });
24
+
25
+ it('should start at two seconds', () => Math.round(delays[0] / 1_000).should.equal(2));
26
+ it('should never wait longer than a minute', () => delays.forEach(delay => delay.should.be.at.most(60_000)));
27
+ it('should reach a minute while streams keep ending', () => Math.round(delays[6] / 1_000).should.equal(60));
28
+ it('should start over after a stream stayed open for three minutes', () => Math.round(delays[7] / 1_000).should.equal(2));
29
+ });
@@ -0,0 +1,36 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { ClientError, Status } from 'nice-grpc';
5
+ import { chai, describe, it } from 'vitest';
6
+ import { classifyStreamError, StreamErrorKind } from '../classifyStreamError.js';
7
+
8
+ chai.should();
9
+
10
+ const sessionLost = () => new ClientError('/Reactors/Observe', Status.UNKNOWN, 'ClientIsNotConnected: connection 42 is not connected');
11
+ const abort = () => Object.assign(new Error('The operation has been aborted'), { name: 'AbortError' });
12
+
13
+ describe('when classifying a stream error', () => {
14
+ const cases: [string, unknown, StreamErrorKind][] = [
15
+ ['the kernel no longer knows the connection', sessionLost(), StreamErrorKind.SessionLost],
16
+ ['the message names the lost connection', Object.assign(new Error('ClientIsNotConnected'), { code: Status.INTERNAL }), StreamErrorKind.SessionLost],
17
+ ['the lost connection is wrapped', new Error('stream failed', { cause: sessionLost() }), StreamErrorKind.SessionLost],
18
+ ['every wrapped error lost the session or connection',
19
+ new AggregateError([sessionLost(), new ClientError('/x', Status.UNAVAILABLE, '')]), StreamErrorKind.SessionLost],
20
+ ['a wrapped error is a failure of its own',
21
+ new AggregateError([sessionLost(), new ClientError('/x', Status.INTERNAL, 'boom')]), StreamErrorKind.Failure],
22
+ ['a wrapped error lost the connection and another was cancelled',
23
+ new AggregateError([new ClientError('/x', Status.CANCELLED, ''), new ClientError('/x', Status.UNAVAILABLE, '')]),
24
+ StreamErrorKind.ConnectionLost],
25
+ ['every wrapped error was cancelled', new AggregateError([abort(), new ClientError('/x', Status.CANCELLED, '')]), StreamErrorKind.Cancelled],
26
+ ['the kernel is unreachable', new ClientError('/x', Status.UNAVAILABLE, 'ClientIsNotConnected'), StreamErrorKind.ConnectionLost],
27
+ ['the call was cancelled', new ClientError('/x', Status.CANCELLED, ''), StreamErrorKind.Cancelled],
28
+ ['the client aborted the stream', abort(), StreamErrorKind.Cancelled],
29
+ ['the stream failed for another reason', new ClientError('/x', Status.INTERNAL, 'boom'), StreamErrorKind.Failure],
30
+ ['the error is not an object', 'boom', StreamErrorKind.Failure]
31
+ ];
32
+
33
+ for (const [scenario, error, kind] of cases) {
34
+ it(`should classify as ${kind} when ${scenario}`, () => classifyStreamError(error).should.equal(kind));
35
+ }
36
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/chronicle",
3
- "version": "6.62.0",
3
+ "version": "6.64.0",
4
4
  "description": "Event sourcing for TypeScript and Node.js — the idiomatic client for Cratis Chronicle, the open-source event-sourcing database",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",
@@ -178,7 +178,7 @@
178
178
  "clean": "rm -rf dist",
179
179
  "test": "vitest run",
180
180
  "test:integration": "vitest run --config vitest.integration.config.ts",
181
- "test:standard-types": "tsc --ignoreConfig --noEmit --target es2022 --module es2022 --moduleResolution bundler --lib es2022,esnext.decorators --types node --skipLibCheck --strict schemas/decorators.standard.spec.ts projections/declarative/addChildCompatibility.standard.spec.ts projections/declarative/for_CompositeKeyBuilder/when_typing_constant_parts.standard.spec.ts projections/modelBound/decorators.standard.spec.ts projections/for_Graphs/when_declaring_with_standard_decorators.standard.spec.ts events/classDecorators.standard.spec.ts reactors/decorators.standard.spec.ts readModels/standardFallbacks.standard.spec.ts readModels/registration.standard.spec.ts for_ChronicleClient/when_registering_artifacts/with_standard_property_mappings.standard.spec.ts artifacts/validateArtifactSchemas.spec.ts testing/for_EventScenario/when_appending_concept_fields/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_scoped_constraints/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_event_sequence_constraints/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_event_sequence_constraints/other_sequence_extended_key.standard.spec.ts events/constraints/for_Constraints/when_scoping_to_event_sequences/with_standard_decorators.standard.spec.ts schemas/for_JsonSchemaGenerator/when_generating_children/with_standard_decorators.standard.spec.ts events/for_handles/when_decorating_a_method.standard.spec.ts testing/for_ReadModelScenario/when_evaluating_arithmetic/with_standard_decorators.standard.spec.ts testing/for_ReadModelScenario/when_evaluating_joins/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_field_types/with_standard_decorators.standard.spec.ts eventSequences/for_EventSequence/when_appending/with_subject_annotations.standard.spec.ts projections/for_ProjectionDefinitionCompiler/when_compiling_from_all.standard.spec.ts projections/for_ProjectionDefinitionCompiler/when_compiling_tags/with_standard_decorators.standard.spec.ts telemetry/for_ChronicleTelemetry/when_exposing_names/with_convention_names.spec.ts projections/for_ProjectionDefinitionCompiler/when_compiling_from_all_events.standard.spec.ts events/for_observerFilters/when_registering/with_standard_decorators.standard.spec.ts reactors/for_Reactors/against_a_kernel/when_filtering_source_and_stream_types.integration.spec.ts testing/for_observerScenarios/when_selecting_filters/with_source_and_stream_types.spec.ts readModels/for_ReadModelWatcher/watchCompatibility.standard.spec.ts for_EventStore/when_implementing_a_legacy_event_store.spec.ts",
181
+ "test:standard-types": "tsc --ignoreConfig --noEmit --target es2022 --module es2022 --moduleResolution bundler --lib es2022,esnext.decorators --types node --skipLibCheck --strict schemas/decorators.standard.spec.ts projections/declarative/addChildCompatibility.standard.spec.ts projections/declarative/for_CompositeKeyBuilder/when_typing_constant_parts.standard.spec.ts projections/modelBound/decorators.standard.spec.ts projections/for_Graphs/when_declaring_with_standard_decorators.standard.spec.ts projections/for_Graphs/when_declaring_graph_views.standard.spec.ts events/classDecorators.standard.spec.ts reactors/decorators.standard.spec.ts readModels/standardFallbacks.standard.spec.ts readModels/registration.standard.spec.ts for_ChronicleClient/when_registering_artifacts/with_standard_property_mappings.standard.spec.ts artifacts/validateArtifactSchemas.spec.ts testing/for_EventScenario/when_appending_concept_fields/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_scoped_constraints/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_event_sequence_constraints/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_event_sequence_constraints/other_sequence_extended_key.standard.spec.ts events/constraints/for_Constraints/when_scoping_to_event_sequences/with_standard_decorators.standard.spec.ts schemas/for_JsonSchemaGenerator/when_generating_children/with_standard_decorators.standard.spec.ts events/for_handles/when_decorating_a_method.standard.spec.ts testing/for_ReadModelScenario/when_evaluating_arithmetic/with_standard_decorators.standard.spec.ts testing/for_ReadModelScenario/when_evaluating_joins/with_standard_decorators.standard.spec.ts testing/for_EventScenario/when_appending_field_types/with_standard_decorators.standard.spec.ts eventSequences/for_EventSequence/when_appending/with_subject_annotations.standard.spec.ts projections/for_ProjectionDefinitionCompiler/when_compiling_from_all.standard.spec.ts projections/for_ProjectionDefinitionCompiler/when_compiling_tags/with_standard_decorators.standard.spec.ts telemetry/for_ChronicleTelemetry/when_exposing_names/with_convention_names.spec.ts projections/for_ProjectionDefinitionCompiler/when_compiling_from_all_events.standard.spec.ts events/for_observerFilters/when_registering/with_standard_decorators.standard.spec.ts reactors/for_Reactors/against_a_kernel/when_filtering_source_and_stream_types.integration.spec.ts testing/for_observerScenarios/when_selecting_filters/with_source_and_stream_types.spec.ts readModels/for_ReadModelWatcher/watchCompatibility.standard.spec.ts for_EventStore/when_implementing_a_legacy_event_store.spec.ts",
182
182
  "test:native": "node ./scripts/check-native-esm.mjs"
183
183
  },
184
184
  "dependencies": {
@@ -11,11 +11,12 @@ import { artifactsWith } from './organization.js';
11
11
  * @param graphElements - The nodes and edges.
12
12
  * @param graphProjections - The fluent graph projections.
13
13
  * @param sinkTypeId - The sink type of the graphs.
14
+ * @param graphViews - The views over graphs.
14
15
  * @returns The graphs, once discovered, and what is needed to look at what they registered.
15
16
  */
16
- export async function discoverGraphs(graphElements: Constructor[], graphProjections: Constructor[] = [], sinkTypeId = 'Neo4j') {
17
+ export async function discoverGraphs(graphElements: Constructor[], graphProjections: Constructor[] = [], sinkTypeId = 'Neo4j', graphViews: Constructor[] = []) {
17
18
  const fake = aFakeConnection();
18
- const graphs = new Graphs('the-store', fake.connection, artifactsWith(graphElements, graphProjections), sinkTypeId);
19
+ const graphs = new Graphs('the-store', fake.connection, artifactsWith(graphElements, graphProjections, graphViews), sinkTypeId);
19
20
  await graphs.discover();
20
21
  return { graphs, ...fake };
21
22
  }
@@ -0,0 +1,91 @@
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 type { Constructor } from '@cratis/fundamentals';
6
+ import type { ChroniclePropertyDecorator } from '../../../types/propertyDecoratorMetadata.js';
7
+ import { edge } from '../../graphs/edge.js';
8
+ import { edgeSource } from '../../graphs/edgeSource.js';
9
+ import { edgeTarget } from '../../graphs/edgeTarget.js';
10
+ import { graph } from '../../graphs/graph.js';
11
+ import { graphKey } from '../../graphs/graphKey.js';
12
+ import { node } from '../../graphs/node.js';
13
+ import { viewOf } from '../../graphs/views/viewOf.js';
14
+ import { discoverGraphs } from './a_discovered_graph.js';
15
+
16
+ // Decorators are applied as plain function calls so the fixtures do not depend on decorator-syntax support.
17
+
18
+ /** A graph of people and groups, declared fresh so each specification owns its classes. */
19
+ export interface Organization {
20
+ readonly graphName: string;
21
+ readonly Person: Constructor;
22
+ readonly Group: Constructor;
23
+ /** Person to Group, with the property since. */
24
+ readonly MemberOf: Constructor;
25
+ /** Person to Person, a self edge, with the property since. */
26
+ readonly Knows: Constructor;
27
+ /** The nodes and edges, to hand to discovery. */
28
+ readonly elements: Constructor[];
29
+ }
30
+
31
+ /**
32
+ * Declares a graph of people and groups.
33
+ * @param graphName - The name of the graph.
34
+ * @returns The classes of the graph.
35
+ */
36
+ export function anOrganization(graphName: string): Organization {
37
+ class Person { personId = ''; name = ''; }
38
+ graph(graphName)(Person);
39
+ node()(Person);
40
+ graphKey()(Person.prototype, 'personId');
41
+
42
+ class Group { groupId = ''; name = ''; }
43
+ graph(graphName)(Group);
44
+ node()(Group);
45
+ graphKey()(Group.prototype, 'groupId');
46
+
47
+ class MemberOf { personId = ''; groupId = ''; since = ''; }
48
+ graph(graphName)(MemberOf);
49
+ edge('MEMBER_OF')(MemberOf);
50
+ edgeSource(Person)(MemberOf.prototype, 'personId');
51
+ edgeTarget(Group)(MemberOf.prototype, 'groupId');
52
+
53
+ class Knows { fromId = ''; toId = ''; since = ''; }
54
+ graph(graphName)(Knows);
55
+ edge('KNOWS')(Knows);
56
+ edgeSource(Person)(Knows.prototype, 'fromId');
57
+ edgeTarget(Person)(Knows.prototype, 'toId');
58
+
59
+ return { graphName, Person, Group, MemberOf, Knows, elements: [Person, Group, MemberOf, Knows] };
60
+ }
61
+
62
+ /** A member of a view: the name of the property and the decorator that declares it. */
63
+ export type ViewMember = readonly [property: string, decorator: ChroniclePropertyDecorator];
64
+
65
+ /**
66
+ * Declares a view over a graph.
67
+ * @param graphName - The name of the graph.
68
+ * @param name - The name of the view, which is also the name of the class.
69
+ * @param root - A function returning the class of the node the view is anchored at.
70
+ * @param members - The members of the view, in declaration order.
71
+ * @returns The class of the view.
72
+ */
73
+ export function aView(graphName: string, name: string, root: () => Function, ...members: ViewMember[]): Constructor {
74
+ class View {}
75
+ Object.defineProperty(View, 'name', { value: name });
76
+ graph(graphName)(View);
77
+ viewOf(root)(View);
78
+ for (const [property, decorator] of members) decorator(View.prototype, property);
79
+ return View;
80
+ }
81
+
82
+ /**
83
+ * Discovers a graph with views, once.
84
+ * @param organization - The graph.
85
+ * @param views - The views.
86
+ * @returns The discovered graphs.
87
+ */
88
+ export async function discoverViews(organization: Organization, ...views: Constructor[]) {
89
+ const result = await discoverGraphs(organization.elements, [], 'Neo4j', views);
90
+ return result.graphs;
91
+ }
@@ -86,11 +86,12 @@ edgeRemovedWith(MemberRemoved, { sourceKey: 'personId', targetKey: 'groupId' })(
86
86
  * Creates a provider that finds only the given graph artifacts.
87
87
  * @param graphElements - The nodes and edges.
88
88
  * @param graphProjections - The fluent graph projections.
89
+ * @param graphViews - The views over graphs.
89
90
  * @returns The provider.
90
91
  */
91
- export function artifactsWith(graphElements: Constructor[], graphProjections: Constructor[] = []): IClientArtifactsProvider {
92
+ export function artifactsWith(graphElements: Constructor[], graphProjections: Constructor[] = [], graphViews: Constructor[] = []): IClientArtifactsProvider {
92
93
  return {
93
94
  eventTypes: [], readModels: [], reactors: [], reducers: [], seeders: [], constraints: [], projections: [],
94
- webhooks: [], eventTypeMigrations: [], globalForHandlers: [], graphElements, graphProjections
95
+ webhooks: [], eventTypeMigrations: [], globalForHandlers: [], graphElements, graphProjections, graphViews
95
96
  };
96
97
  }