@cratis/chronicle 6.59.0 → 6.61.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.
- package/ChronicleClient.ts +1 -1
- package/ChronicleOptions.ts +11 -0
- package/EventStore.ts +9 -1
- package/IEventStore.ts +7 -0
- package/README.md +1 -1
- package/artifacts/DefaultClientArtifactsProvider.ts +13 -1
- package/artifacts/IClientArtifactsProvider.ts +6 -0
- package/dist/ChronicleClient.js +1 -1
- package/dist/ChronicleClient.js.map +1 -1
- package/dist/ChronicleOptions.d.ts +7 -0
- package/dist/ChronicleOptions.d.ts.map +1 -1
- package/dist/ChronicleOptions.js +8 -0
- package/dist/ChronicleOptions.js.map +1 -1
- package/dist/EventStore.d.ts +3 -1
- package/dist/EventStore.d.ts.map +1 -1
- package/dist/EventStore.js +7 -1
- package/dist/EventStore.js.map +1 -1
- package/dist/IEventStore.d.ts +6 -0
- package/dist/IEventStore.d.ts.map +1 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.d.ts +4 -0
- package/dist/artifacts/DefaultClientArtifactsProvider.d.ts.map +1 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.js +11 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.js.map +1 -1
- package/dist/artifacts/IClientArtifactsProvider.d.ts +4 -0
- package/dist/artifacts/IClientArtifactsProvider.d.ts.map +1 -1
- package/dist/projections/ChildrenOrderingNotSupportedByContracts.d.ts +15 -0
- package/dist/projections/ChildrenOrderingNotSupportedByContracts.d.ts.map +1 -0
- package/dist/projections/ChildrenOrderingNotSupportedByContracts.js +22 -0
- package/dist/projections/ChildrenOrderingNotSupportedByContracts.js.map +1 -0
- package/dist/projections/InvalidCausedByProperty.d.ts +10 -0
- package/dist/projections/InvalidCausedByProperty.d.ts.map +1 -0
- package/dist/projections/InvalidCausedByProperty.js +16 -0
- package/dist/projections/InvalidCausedByProperty.js.map +1 -0
- package/dist/projections/Projections.d.ts.map +1 -1
- package/dist/projections/Projections.js +7 -30
- package/dist/projections/Projections.js.map +1 -1
- package/dist/projections/causedBy.d.ts +15 -0
- package/dist/projections/causedBy.d.ts.map +1 -0
- package/dist/projections/causedBy.js +24 -0
- package/dist/projections/causedBy.js.map +1 -0
- package/dist/projections/childrenOrdering.d.ts +38 -0
- package/dist/projections/childrenOrdering.d.ts.map +1 -0
- package/dist/projections/childrenOrdering.js +37 -0
- package/dist/projections/childrenOrdering.js.map +1 -0
- package/dist/projections/childrenOrderingSupport.d.ts +14 -0
- package/dist/projections/childrenOrderingSupport.d.ts.map +1 -0
- package/dist/projections/childrenOrderingSupport.js +37 -0
- package/dist/projections/childrenOrderingSupport.js.map +1 -0
- package/dist/projections/declarative/AllSetBuilder.d.ts +3 -0
- package/dist/projections/declarative/AllSetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/AllSetBuilder.js +6 -0
- package/dist/projections/declarative/AllSetBuilder.js.map +1 -1
- package/dist/projections/declarative/ChildrenBuilder.d.ts +9 -0
- package/dist/projections/declarative/ChildrenBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/ChildrenBuilder.js +29 -1
- package/dist/projections/declarative/ChildrenBuilder.js.map +1 -1
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.d.ts +6 -0
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.d.ts.map +1 -0
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.js +11 -0
- package/dist/projections/declarative/ChildrenOrderingAlreadyDefined.js.map +1 -0
- package/dist/projections/declarative/DictionaryKey.d.ts +48 -0
- package/dist/projections/declarative/DictionaryKey.d.ts.map +1 -0
- package/dist/projections/declarative/DictionaryKey.js +82 -0
- package/dist/projections/declarative/DictionaryKey.js.map +1 -0
- package/dist/projections/declarative/FromAllBuilder.d.ts +2 -0
- package/dist/projections/declarative/FromAllBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/FromAllBuilder.js +5 -0
- package/dist/projections/declarative/FromAllBuilder.js.map +1 -1
- package/dist/projections/declarative/FromBuilder.d.ts +18 -6
- package/dist/projections/declarative/FromBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/FromBuilder.js +34 -31
- package/dist/projections/declarative/FromBuilder.js.map +1 -1
- package/dist/projections/declarative/FromEveryBuilder.d.ts +2 -0
- package/dist/projections/declarative/FromEveryBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/FromEveryBuilder.js +7 -0
- package/dist/projections/declarative/FromEveryBuilder.js.map +1 -1
- package/dist/projections/declarative/IAllSetBuilder.d.ts +7 -0
- package/dist/projections/declarative/IAllSetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IChildrenBuilder.d.ts +19 -0
- package/dist/projections/declarative/IChildrenBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IFromAllBuilder.d.ts +6 -0
- package/dist/projections/declarative/IFromAllBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IFromEveryBuilder.d.ts +6 -0
- package/dist/projections/declarative/IFromEveryBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/IReadModelPropertiesBuilder.d.ts +37 -6
- package/dist/projections/declarative/IReadModelPropertiesBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/ISetBuilder.d.ts +7 -0
- package/dist/projections/declarative/ISetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/InvalidDictionaryKey.d.ts +10 -0
- package/dist/projections/declarative/InvalidDictionaryKey.d.ts.map +1 -0
- package/dist/projections/declarative/InvalidDictionaryKey.js +16 -0
- package/dist/projections/declarative/InvalidDictionaryKey.js.map +1 -0
- package/dist/projections/declarative/JoinBuilder.d.ts +18 -6
- package/dist/projections/declarative/JoinBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/JoinBuilder.js +34 -31
- package/dist/projections/declarative/JoinBuilder.js.map +1 -1
- package/dist/projections/declarative/ProjectionBuilderCore.d.ts +2 -0
- package/dist/projections/declarative/ProjectionBuilderCore.d.ts.map +1 -1
- package/dist/projections/declarative/ProjectionBuilderCore.js.map +1 -1
- package/dist/projections/declarative/SetBuilder.d.ts +3 -0
- package/dist/projections/declarative/SetBuilder.d.ts.map +1 -1
- package/dist/projections/declarative/SetBuilder.js +6 -0
- package/dist/projections/declarative/SetBuilder.js.map +1 -1
- package/dist/projections/declarative/index.d.ts +4 -0
- package/dist/projections/declarative/index.d.ts.map +1 -1
- package/dist/projections/declarative/index.js +3 -0
- package/dist/projections/declarative/index.js.map +1 -1
- package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts +29 -0
- package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts.map +1 -0
- package/dist/projections/for_Graphs/given/a_discovered_graph.js +19 -0
- package/dist/projections/for_Graphs/given/a_discovered_graph.js.map +1 -0
- package/dist/projections/for_Graphs/given/a_fake_connection.d.ts +24 -0
- package/dist/projections/for_Graphs/given/a_fake_connection.d.ts.map +1 -0
- package/dist/projections/for_Graphs/given/a_fake_connection.js +17 -0
- package/dist/projections/for_Graphs/given/a_fake_connection.js.map +1 -0
- package/dist/projections/for_Graphs/given/organization.d.ts +43 -0
- package/dist/projections/for_Graphs/given/organization.d.ts.map +1 -0
- package/dist/projections/for_Graphs/given/organization.js +84 -0
- package/dist/projections/for_Graphs/given/organization.js.map +1 -0
- package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.d.ts +11 -0
- package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.d.ts.map +1 -0
- package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.js +16 -0
- package/dist/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.js.map +1 -0
- package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.d.ts +11 -0
- package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.d.ts.map +1 -0
- package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.js +16 -0
- package/dist/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.js.map +1 -0
- package/dist/projections/graphs/GraphDeclaredMoreThanOnce.d.ts +11 -0
- package/dist/projections/graphs/GraphDeclaredMoreThanOnce.d.ts.map +1 -0
- package/dist/projections/graphs/GraphDeclaredMoreThanOnce.js +16 -0
- package/dist/projections/graphs/GraphDeclaredMoreThanOnce.js.map +1 -0
- package/dist/projections/graphs/GraphDefinitionBuilder.d.ts +24 -0
- package/dist/projections/graphs/GraphDefinitionBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphDefinitionBuilder.js +148 -0
- package/dist/projections/graphs/GraphDefinitionBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphEdgeBuilder.d.ts +41 -0
- package/dist/projections/graphs/GraphEdgeBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphEdgeBuilder.js +94 -0
- package/dist/projections/graphs/GraphEdgeBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphEdgeFromBuilder.d.ts +25 -0
- package/dist/projections/graphs/GraphEdgeFromBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphEdgeFromBuilder.js +37 -0
- package/dist/projections/graphs/GraphEdgeFromBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphEdgeFromModel.d.ts +16 -0
- package/dist/projections/graphs/GraphEdgeFromModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphEdgeFromModel.js +4 -0
- package/dist/projections/graphs/GraphEdgeFromModel.js.map +1 -0
- package/dist/projections/graphs/GraphEdgeModel.d.ts +24 -0
- package/dist/projections/graphs/GraphEdgeModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphEdgeModel.js +4 -0
- package/dist/projections/graphs/GraphEdgeModel.js.map +1 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.d.ts +21 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.js +31 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithModel.d.ts +14 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithModel.js +4 -0
- package/dist/projections/graphs/GraphEdgeRemovedWithModel.js.map +1 -0
- package/dist/projections/graphs/GraphElementCannotBeReadModel.d.ts +11 -0
- package/dist/projections/graphs/GraphElementCannotBeReadModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphElementCannotBeReadModel.js +16 -0
- package/dist/projections/graphs/GraphElementCannotBeReadModel.js.map +1 -0
- package/dist/projections/graphs/GraphHasDuplicateElement.d.ts +13 -0
- package/dist/projections/graphs/GraphHasDuplicateElement.d.ts.map +1 -0
- package/dist/projections/graphs/GraphHasDuplicateElement.js +18 -0
- package/dist/projections/graphs/GraphHasDuplicateElement.js.map +1 -0
- package/dist/projections/graphs/GraphKeyPropertyNotFound.d.ts +12 -0
- package/dist/projections/graphs/GraphKeyPropertyNotFound.d.ts.map +1 -0
- package/dist/projections/graphs/GraphKeyPropertyNotFound.js +17 -0
- package/dist/projections/graphs/GraphKeyPropertyNotFound.js.map +1 -0
- package/dist/projections/graphs/GraphMappingBuilder.d.ts +32 -0
- package/dist/projections/graphs/GraphMappingBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphMappingBuilder.js +48 -0
- package/dist/projections/graphs/GraphMappingBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphMemberMappings.d.ts +9 -0
- package/dist/projections/graphs/GraphMemberMappings.d.ts.map +1 -0
- package/dist/projections/graphs/GraphMemberMappings.js +59 -0
- package/dist/projections/graphs/GraphMemberMappings.js.map +1 -0
- package/dist/projections/graphs/GraphModel.d.ts +15 -0
- package/dist/projections/graphs/GraphModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphModel.js +4 -0
- package/dist/projections/graphs/GraphModel.js.map +1 -0
- package/dist/projections/graphs/GraphNameRequired.d.ts +11 -0
- package/dist/projections/graphs/GraphNameRequired.d.ts.map +1 -0
- package/dist/projections/graphs/GraphNameRequired.js +16 -0
- package/dist/projections/graphs/GraphNameRequired.js.map +1 -0
- package/dist/projections/graphs/GraphNodeBuilder.d.ts +34 -0
- package/dist/projections/graphs/GraphNodeBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphNodeBuilder.js +66 -0
- package/dist/projections/graphs/GraphNodeBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphNodeFromBuilder.d.ts +21 -0
- package/dist/projections/graphs/GraphNodeFromBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphNodeFromBuilder.js +30 -0
- package/dist/projections/graphs/GraphNodeFromBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphNodeFromModel.d.ts +14 -0
- package/dist/projections/graphs/GraphNodeFromModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphNodeFromModel.js +4 -0
- package/dist/projections/graphs/GraphNodeFromModel.js.map +1 -0
- package/dist/projections/graphs/GraphNodeModel.d.ts +18 -0
- package/dist/projections/graphs/GraphNodeModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphNodeModel.js +4 -0
- package/dist/projections/graphs/GraphNodeModel.js.map +1 -0
- package/dist/projections/graphs/GraphNodeRemovedWithBuilder.d.ts +17 -0
- package/dist/projections/graphs/GraphNodeRemovedWithBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphNodeRemovedWithBuilder.js +24 -0
- package/dist/projections/graphs/GraphNodeRemovedWithBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphNodeRemovedWithModel.d.ts +12 -0
- package/dist/projections/graphs/GraphNodeRemovedWithModel.d.ts.map +1 -0
- package/dist/projections/graphs/GraphNodeRemovedWithModel.js +4 -0
- package/dist/projections/graphs/GraphNodeRemovedWithModel.js.map +1 -0
- package/dist/projections/graphs/GraphProjectionBuilder.d.ts +25 -0
- package/dist/projections/graphs/GraphProjectionBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/GraphProjectionBuilder.js +36 -0
- package/dist/projections/graphs/GraphProjectionBuilder.js.map +1 -0
- package/dist/projections/graphs/GraphRegistration.d.ts +14 -0
- package/dist/projections/graphs/GraphRegistration.d.ts.map +1 -0
- package/dist/projections/graphs/GraphRegistration.js +4 -0
- package/dist/projections/graphs/GraphRegistration.js.map +1 -0
- package/dist/projections/graphs/GraphSchemaWriter.d.ts +28 -0
- package/dist/projections/graphs/GraphSchemaWriter.d.ts.map +1 -0
- package/dist/projections/graphs/GraphSchemaWriter.js +76 -0
- package/dist/projections/graphs/GraphSchemaWriter.js.map +1 -0
- package/dist/projections/graphs/Graphs.d.ts +39 -0
- package/dist/projections/graphs/Graphs.d.ts.map +1 -0
- package/dist/projections/graphs/Graphs.js +144 -0
- package/dist/projections/graphs/Graphs.js.map +1 -0
- package/dist/projections/graphs/IGraphEdgeBuilder.d.ts +37 -0
- package/dist/projections/graphs/IGraphEdgeBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphEdgeBuilder.js +4 -0
- package/dist/projections/graphs/IGraphEdgeBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphEdgeFromBuilder.d.ts +29 -0
- package/dist/projections/graphs/IGraphEdgeFromBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphEdgeFromBuilder.js +4 -0
- package/dist/projections/graphs/IGraphEdgeFromBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.d.ts +27 -0
- package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.js +4 -0
- package/dist/projections/graphs/IGraphEdgeRemovedWithBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphMappingBuilder.d.ts +49 -0
- package/dist/projections/graphs/IGraphMappingBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphMappingBuilder.js +4 -0
- package/dist/projections/graphs/IGraphMappingBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphNodeBuilder.d.ts +32 -0
- package/dist/projections/graphs/IGraphNodeBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphNodeBuilder.js +4 -0
- package/dist/projections/graphs/IGraphNodeBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphNodeFromBuilder.d.ts +21 -0
- package/dist/projections/graphs/IGraphNodeFromBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphNodeFromBuilder.js +4 -0
- package/dist/projections/graphs/IGraphNodeFromBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.d.ts +19 -0
- package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.js +4 -0
- package/dist/projections/graphs/IGraphNodeRemovedWithBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphProjection.d.ts +13 -0
- package/dist/projections/graphs/IGraphProjection.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphProjection.js +4 -0
- package/dist/projections/graphs/IGraphProjection.js.map +1 -0
- package/dist/projections/graphs/IGraphProjectionBuilder.d.ts +26 -0
- package/dist/projections/graphs/IGraphProjectionBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphProjectionBuilder.js +4 -0
- package/dist/projections/graphs/IGraphProjectionBuilder.js.map +1 -0
- package/dist/projections/graphs/IGraphs.d.ts +27 -0
- package/dist/projections/graphs/IGraphs.d.ts.map +1 -0
- package/dist/projections/graphs/IGraphs.js +4 -0
- package/dist/projections/graphs/IGraphs.js.map +1 -0
- package/dist/projections/graphs/ModelBoundGraphReader.d.ts +30 -0
- package/dist/projections/graphs/ModelBoundGraphReader.d.ts.map +1 -0
- package/dist/projections/graphs/ModelBoundGraphReader.js +112 -0
- package/dist/projections/graphs/ModelBoundGraphReader.js.map +1 -0
- package/dist/projections/graphs/NestedObjectInGraph.d.ts +12 -0
- package/dist/projections/graphs/NestedObjectInGraph.d.ts.map +1 -0
- package/dist/projections/graphs/NestedObjectInGraph.js +17 -0
- package/dist/projections/graphs/NestedObjectInGraph.js.map +1 -0
- package/dist/projections/graphs/NodeMustHaveExactlyOneKey.d.ts +12 -0
- package/dist/projections/graphs/NodeMustHaveExactlyOneKey.d.ts.map +1 -0
- package/dist/projections/graphs/NodeMustHaveExactlyOneKey.js +17 -0
- package/dist/projections/graphs/NodeMustHaveExactlyOneKey.js.map +1 -0
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.d.ts +13 -0
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.d.ts.map +1 -0
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.js +18 -0
- package/dist/projections/graphs/SetOnceNotSupportedInGraph.js.map +1 -0
- package/dist/projections/graphs/UnknownGraphEventProperty.d.ts +13 -0
- package/dist/projections/graphs/UnknownGraphEventProperty.d.ts.map +1 -0
- package/dist/projections/graphs/UnknownGraphEventProperty.js +18 -0
- package/dist/projections/graphs/UnknownGraphEventProperty.js.map +1 -0
- package/dist/projections/graphs/UnknownGraphNode.d.ts +12 -0
- package/dist/projections/graphs/UnknownGraphNode.d.ts.map +1 -0
- package/dist/projections/graphs/UnknownGraphNode.js +17 -0
- package/dist/projections/graphs/UnknownGraphNode.js.map +1 -0
- package/dist/projections/graphs/edge.d.ts +23 -0
- package/dist/projections/graphs/edge.d.ts.map +1 -0
- package/dist/projections/graphs/edge.js +29 -0
- package/dist/projections/graphs/edge.js.map +1 -0
- package/dist/projections/graphs/edgeFrom.d.ts +31 -0
- package/dist/projections/graphs/edgeFrom.d.ts.map +1 -0
- package/dist/projections/graphs/edgeFrom.js +26 -0
- package/dist/projections/graphs/edgeFrom.js.map +1 -0
- package/dist/projections/graphs/edgeRemovedWith.d.ts +22 -0
- package/dist/projections/graphs/edgeRemovedWith.d.ts.map +1 -0
- package/dist/projections/graphs/edgeRemovedWith.js +25 -0
- package/dist/projections/graphs/edgeRemovedWith.js.map +1 -0
- package/dist/projections/graphs/edgeSource.d.ts +22 -0
- package/dist/projections/graphs/edgeSource.d.ts.map +1 -0
- package/dist/projections/graphs/edgeSource.js +30 -0
- package/dist/projections/graphs/edgeSource.js.map +1 -0
- package/dist/projections/graphs/edgeTarget.d.ts +22 -0
- package/dist/projections/graphs/edgeTarget.d.ts.map +1 -0
- package/dist/projections/graphs/edgeTarget.js +30 -0
- package/dist/projections/graphs/edgeTarget.js.map +1 -0
- package/dist/projections/graphs/graph.d.ts +16 -0
- package/dist/projections/graphs/graph.d.ts.map +1 -0
- package/dist/projections/graphs/graph.js +24 -0
- package/dist/projections/graphs/graph.js.map +1 -0
- package/dist/projections/graphs/graphKey.d.ts +16 -0
- package/dist/projections/graphs/graphKey.d.ts.map +1 -0
- package/dist/projections/graphs/graphKey.js +28 -0
- package/dist/projections/graphs/graphKey.js.map +1 -0
- package/dist/projections/graphs/graphProjection.d.ts +21 -0
- package/dist/projections/graphs/graphProjection.d.ts.map +1 -0
- package/dist/projections/graphs/graphProjection.js +28 -0
- package/dist/projections/graphs/graphProjection.js.map +1 -0
- package/dist/projections/graphs/index.d.ts +49 -0
- package/dist/projections/graphs/index.d.ts.map +1 -0
- package/dist/projections/graphs/index.js +28 -0
- package/dist/projections/graphs/index.js.map +1 -0
- package/dist/projections/graphs/isGraphElement.d.ts +7 -0
- package/dist/projections/graphs/isGraphElement.d.ts.map +1 -0
- package/dist/projections/graphs/isGraphElement.js +13 -0
- package/dist/projections/graphs/isGraphElement.js.map +1 -0
- package/dist/projections/graphs/node.d.ts +22 -0
- package/dist/projections/graphs/node.d.ts.map +1 -0
- package/dist/projections/graphs/node.js +29 -0
- package/dist/projections/graphs/node.js.map +1 -0
- package/dist/projections/graphs/nodeFrom.d.ts +31 -0
- package/dist/projections/graphs/nodeFrom.d.ts.map +1 -0
- package/dist/projections/graphs/nodeFrom.js +26 -0
- package/dist/projections/graphs/nodeFrom.js.map +1 -0
- package/dist/projections/graphs/nodeRemovedWith.d.ts +28 -0
- package/dist/projections/graphs/nodeRemovedWith.d.ts.map +1 -0
- package/dist/projections/graphs/nodeRemovedWith.js +25 -0
- package/dist/projections/graphs/nodeRemovedWith.js.map +1 -0
- package/dist/projections/graphs/propertyPathOf.d.ts +8 -0
- package/dist/projections/graphs/propertyPathOf.d.ts.map +1 -0
- package/dist/projections/graphs/propertyPathOf.js +14 -0
- package/dist/projections/graphs/propertyPathOf.js.map +1 -0
- package/dist/projections/index.d.ts +6 -0
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/index.js +4 -0
- package/dist/projections/index.js.map +1 -1
- package/dist/projections/modelBound/ConflictingChildrenOrdering.d.ts +10 -0
- package/dist/projections/modelBound/ConflictingChildrenOrdering.d.ts.map +1 -0
- package/dist/projections/modelBound/ConflictingChildrenOrdering.js +16 -0
- package/dist/projections/modelBound/ConflictingChildrenOrdering.js.map +1 -0
- package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts +2 -0
- package/dist/projections/modelBound/childrenAndNestedBuilder.d.ts.map +1 -1
- package/dist/projections/modelBound/childrenAndNestedBuilder.js +9 -5
- package/dist/projections/modelBound/childrenAndNestedBuilder.js.map +1 -1
- package/dist/projections/modelBound/childrenFrom.d.ts +39 -1
- package/dist/projections/modelBound/childrenFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/childrenFrom.js +30 -1
- package/dist/projections/modelBound/childrenFrom.js.map +1 -1
- package/dist/projections/modelBound/index.d.ts +3 -2
- package/dist/projections/modelBound/index.d.ts.map +1 -1
- package/dist/projections/modelBound/index.js +1 -0
- package/dist/projections/modelBound/index.js.map +1 -1
- package/dist/projections/modelBound/setFrom.d.ts +26 -0
- package/dist/projections/modelBound/setFrom.d.ts.map +1 -1
- package/dist/projections/modelBound/setFrom.js +15 -8
- package/dist/projections/modelBound/setFrom.js.map +1 -1
- package/dist/projections/modelBound/setFromContext.d.ts +23 -1
- package/dist/projections/modelBound/setFromContext.d.ts.map +1 -1
- package/dist/projections/modelBound/setFromContext.js +20 -2
- package/dist/projections/modelBound/setFromContext.js.map +1 -1
- package/dist/projections/propertyExpressions.d.ts +9 -0
- package/dist/projections/propertyExpressions.d.ts.map +1 -0
- package/dist/projections/propertyExpressions.js +13 -0
- package/dist/projections/propertyExpressions.js.map +1 -0
- package/dist/projections/registerProjectionWithRetry.d.ts +15 -0
- package/dist/projections/registerProjectionWithRetry.d.ts.map +1 -0
- package/dist/projections/registerProjectionWithRetry.js +44 -0
- package/dist/projections/registerProjectionWithRetry.js.map +1 -0
- package/dist/readModels/rootReadModelTypes.d.ts.map +1 -1
- package/dist/readModels/rootReadModelTypes.js +3 -1
- package/dist/readModels/rootReadModelTypes.js.map +1 -1
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +2 -1
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/sinks/WellKnownSinks.d.ts +4 -0
- package/dist/sinks/WellKnownSinks.d.ts.map +1 -1
- package/dist/sinks/WellKnownSinks.js +5 -1
- package/dist/sinks/WellKnownSinks.js.map +1 -1
- package/dist/testing/projections/ProjectionCapabilities.d.ts.map +1 -1
- package/dist/testing/projections/ProjectionCapabilities.js +2 -0
- package/dist/testing/projections/ProjectionCapabilities.js.map +1 -1
- package/dist/testing/projections/ProjectionChildrenCapabilities.d.ts.map +1 -1
- package/dist/testing/projections/ProjectionChildrenCapabilities.js +2 -0
- package/dist/testing/projections/ProjectionChildrenCapabilities.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/DecoratorType.d.ts +5 -1
- package/dist/types/DecoratorType.d.ts.map +1 -1
- package/dist/types/DecoratorType.js +4 -0
- package/dist/types/DecoratorType.js.map +1 -1
- package/for_ChronicleOptions/when_configuring_the_graph_sink/with_graph_sink_type.spec.ts +22 -0
- package/package.json +3 -3
- package/projections/ChildrenOrderingNotSupportedByContracts.ts +18 -0
- package/projections/InvalidCausedByProperty.ts +14 -0
- package/projections/Projections.ts +8 -29
- package/projections/causedBy.ts +30 -0
- package/projections/childrenOrdering.ts +53 -0
- package/projections/childrenOrderingSupport.ts +40 -0
- package/projections/declarative/AllSetBuilder.ts +7 -0
- package/projections/declarative/ChildrenBuilder.ts +34 -1
- package/projections/declarative/ChildrenOrderingAlreadyDefined.ts +11 -0
- package/projections/declarative/DictionaryKey.ts +88 -0
- package/projections/declarative/FromAllBuilder.ts +10 -0
- package/projections/declarative/FromBuilder.ts +42 -32
- package/projections/declarative/FromEveryBuilder.ts +12 -0
- package/projections/declarative/IAllSetBuilder.ts +8 -0
- package/projections/declarative/IChildrenBuilder.ts +22 -0
- package/projections/declarative/IFromAllBuilder.ts +7 -0
- package/projections/declarative/IFromEveryBuilder.ts +7 -0
- package/projections/declarative/IReadModelPropertiesBuilder.ts +39 -6
- package/projections/declarative/ISetBuilder.ts +8 -0
- package/projections/declarative/InvalidDictionaryKey.ts +14 -0
- package/projections/declarative/JoinBuilder.ts +41 -32
- package/projections/declarative/ProjectionBuilderCore.ts +2 -0
- package/projections/declarative/SetBuilder.ts +7 -0
- package/projections/declarative/for_ChildrenBuilder/when_ordering_children.spec.ts +52 -0
- package/projections/declarative/for_FromAllBuilder/when_setting_once.spec.ts +29 -0
- package/projections/declarative/for_FromBuilder/when_setting_once.spec.ts +39 -0
- package/projections/declarative/for_FromBuilder/when_targeting_dictionary_entries.spec.ts +99 -0
- package/projections/declarative/for_JoinBuilder/when_setting_once_and_targeting_dictionary_entries.spec.ts +36 -0
- package/projections/declarative/for_SetBuilder/when_setting_to_the_causing_identity.spec.ts +37 -0
- package/projections/declarative/index.ts +4 -0
- package/projections/for_Graphs/given/a_discovered_graph.ts +21 -0
- package/projections/for_Graphs/given/a_fake_connection.ts +19 -0
- package/projections/for_Graphs/given/organization.ts +96 -0
- package/projections/for_Graphs/when_building_a_fluent_graph.spec.ts +112 -0
- package/projections/for_Graphs/when_building_a_model_bound_graph.spec.ts +92 -0
- package/projections/for_Graphs/when_declaring_an_edge_with_an_identity.spec.ts +137 -0
- package/projections/for_Graphs/when_declaring_an_invalid_graph.spec.ts +227 -0
- package/projections/for_Graphs/when_declaring_with_standard_decorators.standard.spec.ts +92 -0
- package/projections/for_Graphs/when_discovering_graph_elements.spec.ts +32 -0
- package/projections/for_Graphs/when_mapping_properties.spec.ts +159 -0
- package/projections/for_Graphs/when_registering_graphs.spec.ts +56 -0
- package/projections/for_Projections/when_registering_ordered_children.spec.ts +66 -0
- package/projections/for_childrenOrderingSupport/when_detecting_support_in_the_pinned_contracts.spec.ts +22 -0
- package/projections/for_childrenOrderingSupport/when_ensuring_children_ordering_is_supported.spec.ts +35 -0
- package/projections/graphs/EdgeCanHaveOnlyOneIdentifyingKey.ts +16 -0
- package/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.ts +16 -0
- package/projections/graphs/GraphDeclaredMoreThanOnce.ts +16 -0
- package/projections/graphs/GraphDefinitionBuilder.ts +169 -0
- package/projections/graphs/GraphEdgeBuilder.ts +107 -0
- package/projections/graphs/GraphEdgeFromBuilder.ts +47 -0
- package/projections/graphs/GraphEdgeFromModel.ts +22 -0
- package/projections/graphs/GraphEdgeModel.ts +34 -0
- package/projections/graphs/GraphEdgeRemovedWithBuilder.ts +39 -0
- package/projections/graphs/GraphEdgeRemovedWithModel.ts +19 -0
- package/projections/graphs/GraphElementCannotBeReadModel.ts +16 -0
- package/projections/graphs/GraphHasDuplicateElement.ts +18 -0
- package/projections/graphs/GraphKeyPropertyNotFound.ts +17 -0
- package/projections/graphs/GraphMappingBuilder.ts +65 -0
- package/projections/graphs/GraphMemberMappings.ts +60 -0
- package/projections/graphs/GraphModel.ts +20 -0
- package/projections/graphs/GraphNameRequired.ts +16 -0
- package/projections/graphs/GraphNodeBuilder.ts +76 -0
- package/projections/graphs/GraphNodeFromBuilder.ts +38 -0
- package/projections/graphs/GraphNodeFromModel.ts +19 -0
- package/projections/graphs/GraphNodeModel.ts +25 -0
- package/projections/graphs/GraphNodeRemovedWithBuilder.ts +30 -0
- package/projections/graphs/GraphNodeRemovedWithModel.ts +16 -0
- package/projections/graphs/GraphProjectionBuilder.ts +52 -0
- package/projections/graphs/GraphRegistration.ts +19 -0
- package/projections/graphs/GraphSchemaWriter.ts +80 -0
- package/projections/graphs/Graphs.ts +165 -0
- package/projections/graphs/IGraphEdgeBuilder.ts +43 -0
- package/projections/graphs/IGraphEdgeFromBuilder.ts +34 -0
- package/projections/graphs/IGraphEdgeRemovedWithBuilder.ts +32 -0
- package/projections/graphs/IGraphMappingBuilder.ts +57 -0
- package/projections/graphs/IGraphNodeBuilder.ts +37 -0
- package/projections/graphs/IGraphNodeFromBuilder.ts +25 -0
- package/projections/graphs/IGraphNodeRemovedWithBuilder.ts +23 -0
- package/projections/graphs/IGraphProjection.ts +16 -0
- package/projections/graphs/IGraphProjectionBuilder.ts +34 -0
- package/projections/graphs/IGraphs.ts +33 -0
- package/projections/graphs/ModelBoundGraphReader.ts +119 -0
- package/projections/graphs/NestedObjectInGraph.ts +17 -0
- package/projections/graphs/NodeMustHaveExactlyOneKey.ts +17 -0
- package/projections/graphs/SetOnceNotSupportedInGraph.ts +18 -0
- package/projections/graphs/UnknownGraphEventProperty.ts +18 -0
- package/projections/graphs/UnknownGraphNode.ts +17 -0
- package/projections/graphs/edge.ts +40 -0
- package/projections/graphs/edgeFrom.ts +48 -0
- package/projections/graphs/edgeRemovedWith.ts +36 -0
- package/projections/graphs/edgeSource.ts +39 -0
- package/projections/graphs/edgeTarget.ts +39 -0
- package/projections/graphs/graph.ts +28 -0
- package/projections/graphs/graphKey.ts +31 -0
- package/projections/graphs/graphProjection.ts +39 -0
- package/projections/graphs/index.ts +51 -0
- package/projections/graphs/isGraphElement.ts +14 -0
- package/projections/graphs/node.ts +40 -0
- package/projections/graphs/nodeFrom.ts +48 -0
- package/projections/graphs/nodeRemovedWith.ts +44 -0
- package/projections/graphs/propertyPathOf.ts +15 -0
- package/projections/index.ts +6 -0
- package/projections/modelBound/ConflictingChildrenOrdering.ts +14 -0
- package/projections/modelBound/childrenAndNestedBuilder.ts +11 -5
- package/projections/modelBound/childrenFrom.ts +62 -2
- package/projections/modelBound/for_childrenFrom/when_ordering_children.spec.ts +91 -0
- package/projections/modelBound/for_setFrom/when_setting_once.spec.ts +52 -0
- package/projections/modelBound/index.ts +3 -2
- package/projections/modelBound/setFrom.ts +37 -2
- package/projections/modelBound/setFromContext.ts +38 -3
- package/projections/propertyExpressions.ts +14 -0
- package/projections/registerProjectionWithRetry.ts +53 -0
- package/readModels/rootReadModelTypes.ts +3 -1
- package/reducers/Reducers.ts +2 -1
- package/sinks/WellKnownSinks.ts +7 -1
- package/testing/projections/ProjectionCapabilities.ts +1 -0
- package/testing/projections/ProjectionChildrenCapabilities.ts +1 -0
- package/testing/projections/for_ProjectionCapabilities/when_rejecting_set_once_dictionary_entries_and_ordered_children.spec.ts +52 -0
- package/types/DecoratorType.ts +7 -1
|
@@ -0,0 +1,112 @@
|
|
|
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 { graph } from '../graphs/graph.js';
|
|
7
|
+
import { graphProjection } from '../graphs/graphProjection.js';
|
|
8
|
+
import type { IGraphProjection } from '../graphs/IGraphProjection.js';
|
|
9
|
+
import type { IGraphProjectionBuilder } from '../graphs/IGraphProjectionBuilder.js';
|
|
10
|
+
import { discoverGraphs } from './given/a_discovered_graph.js';
|
|
11
|
+
import {
|
|
12
|
+
Group, GroupCreated, MemberAdded, MemberOf, MemberRemoved, Person, PersonRegistered, PersonRemoved
|
|
13
|
+
} from './given/organization.js';
|
|
14
|
+
|
|
15
|
+
chai.should();
|
|
16
|
+
|
|
17
|
+
// The nodes and edges of the fluent graph are the plain types; the fluent builder says what the decorators say elsewhere.
|
|
18
|
+
class PlainPerson { personId = ''; name = ''; }
|
|
19
|
+
class PlainGroup { groupId = ''; name = ''; }
|
|
20
|
+
class PlainMemberOf { times = 0; }
|
|
21
|
+
|
|
22
|
+
class OrganizationGraph implements IGraphProjection {
|
|
23
|
+
define(builder: IGraphProjectionBuilder): void {
|
|
24
|
+
builder
|
|
25
|
+
.node(Person, node => node
|
|
26
|
+
.from(PersonRegistered, from => from.usingKey(event => event.personId))
|
|
27
|
+
.removedWith(PersonRemoved, removed => removed.usingKey(event => event.personId).detach()))
|
|
28
|
+
.node(Group, node => node
|
|
29
|
+
.from(GroupCreated, from => from.usingKey(event => event.groupId)))
|
|
30
|
+
.edge(MemberOf, Person, Group, edge => edge
|
|
31
|
+
.from(MemberAdded, from => from
|
|
32
|
+
.usingSourceKey(event => event.personId)
|
|
33
|
+
.usingTargetKey(event => event.groupId)
|
|
34
|
+
.set(member => member.since).toEventContextProperty('occurred'))
|
|
35
|
+
.removedWith(MemberRemoved, removed => removed
|
|
36
|
+
.usingSourceKey(event => event.personId)
|
|
37
|
+
.usingTargetKey(event => event.groupId)));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
graphProjection('Organization')(OrganizationGraph);
|
|
41
|
+
|
|
42
|
+
describe('when building the same graph with the fluent builder as with the decorators', () => {
|
|
43
|
+
let fluent: Awaited<ReturnType<typeof discoverGraphs>>;
|
|
44
|
+
let decorated: Awaited<ReturnType<typeof discoverGraphs>>;
|
|
45
|
+
|
|
46
|
+
beforeAll(async () => {
|
|
47
|
+
fluent = await discoverGraphs([], [OrganizationGraph]);
|
|
48
|
+
decorated = await discoverGraphs([Person, Group, MemberOf]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should not fail', () => fluent.graphs.failures.size.should.equal(0));
|
|
52
|
+
it('should describe the graph with the same schema', () => {
|
|
53
|
+
fluent.graphs.registrations[0].readModel.Schema.should.equal(decorated.graphs.registrations[0].readModel.Schema);
|
|
54
|
+
});
|
|
55
|
+
it('should map the graph from the same events', () => {
|
|
56
|
+
fluent.graphs.registrations[0].projection.Graph!.should.deep.equal(decorated.graphs.registrations[0].projection.Graph!);
|
|
57
|
+
});
|
|
58
|
+
it('should be the projection that fills the read model of the graph', () => {
|
|
59
|
+
fluent.graphs.registrations[0].projection.ReadModel.should.equal('Organization');
|
|
60
|
+
fluent.graphs.registrations[0].projection.Identifier.should.equal('OrganizationGraph');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('when declaring a fluent graph without a name', () => {
|
|
65
|
+
it('should name the graph after the class', async () => {
|
|
66
|
+
class Anonymous implements IGraphProjection {
|
|
67
|
+
define(builder: IGraphProjectionBuilder): void {
|
|
68
|
+
builder.node(PlainPerson, node => node.identifiedBy(person => person.personId).from(PersonRegistered));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
graphProjection()(Anonymous);
|
|
72
|
+
const result = await discoverGraphs([], [Anonymous]);
|
|
73
|
+
result.graphs.registrations[0].graphName.should.equal('Anonymous');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('when declaring a fluent graph without decorators on its nodes and edges', () => {
|
|
78
|
+
let projection: Awaited<ReturnType<typeof discoverGraphs>>['graphs']['registrations'][0]['projection'];
|
|
79
|
+
|
|
80
|
+
beforeAll(async () => {
|
|
81
|
+
class PlainGraph implements IGraphProjection {
|
|
82
|
+
define(builder: IGraphProjectionBuilder): void {
|
|
83
|
+
builder
|
|
84
|
+
.node(PlainPerson, node => node.identifiedBy(person => person.personId).from(PersonRegistered))
|
|
85
|
+
.node(PlainGroup, node => node.identifiedBy(group => group.groupId).from(GroupCreated))
|
|
86
|
+
.edge(PlainMemberOf, PlainPerson, PlainGroup, edge => edge
|
|
87
|
+
.named('MEMBER_OF')
|
|
88
|
+
.from(MemberAdded, from => from
|
|
89
|
+
.usingSourceKey(event => event.personId)
|
|
90
|
+
.usingTargetKey(event => event.groupId)
|
|
91
|
+
.increment(member => member.times)));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
graph('Plain')(PlainGraph);
|
|
95
|
+
graphProjection('Plain')(PlainGraph);
|
|
96
|
+
const result = await discoverGraphs([], [PlainGraph]);
|
|
97
|
+
projection = result.graphs.registrations[0].projection;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should label the nodes with the name of the class and take the key from identifiedBy', () => {
|
|
101
|
+
Object.keys(projection.Graph!.Nodes).should.deep.equal(['PlainPerson', 'PlainGroup']);
|
|
102
|
+
projection.Graph!.Nodes.PlainPerson.From['PersonRegistered+1'].Key.should.equal('$eventSourceId');
|
|
103
|
+
});
|
|
104
|
+
it('should name the edge', () => {
|
|
105
|
+
Object.keys(projection.Graph!.Edges).should.deep.equal(['MEMBER_OF']);
|
|
106
|
+
});
|
|
107
|
+
it('should take the end node keys from the event and map the properties of the edge', () => {
|
|
108
|
+
projection.Graph!.Edges.MEMBER_OF.From['MemberAdded+1'].should.deep.equal({
|
|
109
|
+
SourceKey: 'personId', TargetKey: 'groupId', Identity: '', Properties: { times: '$increment' }, ForEach: ''
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -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 'reflect-metadata';
|
|
5
|
+
import { beforeAll, chai, describe, it } from 'vitest';
|
|
6
|
+
import { ReadModelObserverType } from '@cratis/chronicle.contracts';
|
|
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 building a graph from decorated nodes and edges', () => {
|
|
13
|
+
let result: Awaited<ReturnType<typeof discoverGraphs>>;
|
|
14
|
+
let schema: Record<string, any>;
|
|
15
|
+
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
result = await discoverGraphs([Person, Group, MemberOf]);
|
|
18
|
+
schema = JSON.parse(result.graphs.registrations[0].readModel.Schema);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should not fail', () => result.graphs.failures.size.should.equal(0));
|
|
22
|
+
it('should register one graph named by the decorators', () => {
|
|
23
|
+
result.graphs.registrations.map(_ => _.graphName).should.deep.equal(['Organization']);
|
|
24
|
+
});
|
|
25
|
+
it('should store the graph in the graph sink as a read model of the projection', () => {
|
|
26
|
+
const readModel = result.graphs.registrations[0].readModel;
|
|
27
|
+
readModel.Type.Identifier.should.equal('Organization');
|
|
28
|
+
readModel.Sink.TypeId.should.equal('Neo4j');
|
|
29
|
+
readModel.ObserverType.should.equal(ReadModelObserverType.Projection);
|
|
30
|
+
readModel.ObserverIdentifier.should.equal('Organization');
|
|
31
|
+
});
|
|
32
|
+
it('should mark the schema root as a graph', () => {
|
|
33
|
+
schema['x-graph'].should.be.true;
|
|
34
|
+
schema.title.should.equal('Organization');
|
|
35
|
+
});
|
|
36
|
+
it('should annotate a node with its kind and key and describe its properties', () => {
|
|
37
|
+
schema.properties.Person.should.deep.equal({
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: { personId: { type: 'string' }, name: { type: 'string' } },
|
|
40
|
+
'x-graph-kind': 'Node',
|
|
41
|
+
'x-graph-key': 'personId'
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('should annotate an edge with its kind, end nodes and leave the keys of the end nodes out of its properties', () => {
|
|
45
|
+
schema.properties.MEMBER_OF.should.deep.equal({
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: { since: { type: 'string', format: 'date-time' } },
|
|
48
|
+
'x-graph-kind': 'Edge',
|
|
49
|
+
'x-graph-source': 'Person',
|
|
50
|
+
'x-graph-target': 'Group'
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('should project the graph from the event log, rewindable, with an empty read model state', () => {
|
|
54
|
+
const projection = result.graphs.registrations[0].projection;
|
|
55
|
+
projection.EventSequenceId.should.equal('event-log');
|
|
56
|
+
projection.Identifier.should.equal('Organization');
|
|
57
|
+
projection.ReadModel.should.equal('Organization');
|
|
58
|
+
projection.IsActive.should.be.true;
|
|
59
|
+
projection.IsRewindable.should.be.true;
|
|
60
|
+
projection.InitialModelState.should.equal('{}');
|
|
61
|
+
});
|
|
62
|
+
it('should map a node from an event keyed by the event type id and generation', () => {
|
|
63
|
+
result.graphs.registrations[0].projection.Graph!.Nodes.Person.should.deep.equal({
|
|
64
|
+
From: { 'PersonRegistered+1': { Key: 'personId', Properties: { name: 'name' }, UpdateOnly: false, ForEach: '' } },
|
|
65
|
+
RemovedWith: { 'PersonRemoved+1': { Key: 'personId', Detach: true, ForEach: '' } }
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it('should map the properties of a node by name and leave out the key', () => {
|
|
69
|
+
result.graphs.registrations[0].projection.Graph!.Nodes.Group.From['GroupCreated+1'].Properties.should.deep.equal({ name: 'name' });
|
|
70
|
+
});
|
|
71
|
+
it('should map an edge from the events that create and remove it', () => {
|
|
72
|
+
result.graphs.registrations[0].projection.Graph!.Edges.MEMBER_OF.should.deep.equal({
|
|
73
|
+
From: {
|
|
74
|
+
'MemberAdded+1': {
|
|
75
|
+
SourceKey: 'personId',
|
|
76
|
+
TargetKey: 'groupId',
|
|
77
|
+
Identity: '',
|
|
78
|
+
Properties: { since: '$eventContext(Occurred)' },
|
|
79
|
+
ForEach: ''
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
RemovedWith: { 'MemberRemoved+1': { SourceKey: 'personId', TargetKey: 'groupId', Identity: '', ForEach: '' } }
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('when building a graph for a sink type', () => {
|
|
88
|
+
it('should use the sink type', async () => {
|
|
89
|
+
const result = await discoverGraphs([Person, Group, MemberOf], [], 'InMemoryGraph');
|
|
90
|
+
result.graphs.registrations[0].readModel.Sink.TypeId.should.equal('InMemoryGraph');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { eventType } from '../../events/eventTypeDecorator.js';
|
|
7
|
+
import { count } from '../modelBound/count.js';
|
|
8
|
+
import { edge } from '../graphs/edge.js';
|
|
9
|
+
import { edgeFrom } from '../graphs/edgeFrom.js';
|
|
10
|
+
import { edgeRemovedWith } from '../graphs/edgeRemovedWith.js';
|
|
11
|
+
import { edgeSource } from '../graphs/edgeSource.js';
|
|
12
|
+
import { edgeTarget } from '../graphs/edgeTarget.js';
|
|
13
|
+
import { graph } from '../graphs/graph.js';
|
|
14
|
+
import { graphKey } from '../graphs/graphKey.js';
|
|
15
|
+
import { graphProjection } from '../graphs/graphProjection.js';
|
|
16
|
+
import type { IGraphProjection } from '../graphs/IGraphProjection.js';
|
|
17
|
+
import type { IGraphProjectionBuilder } from '../graphs/IGraphProjectionBuilder.js';
|
|
18
|
+
import { node } from '../graphs/node.js';
|
|
19
|
+
import { nodeFrom } from '../graphs/nodeFrom.js';
|
|
20
|
+
import { UnknownGraphEventProperty } from '../graphs/UnknownGraphEventProperty.js';
|
|
21
|
+
import { discoverGraphs } from './given/a_discovered_graph.js';
|
|
22
|
+
|
|
23
|
+
chai.should();
|
|
24
|
+
|
|
25
|
+
class PlaceVisited { personId = ''; placeId = ''; visitId = ''; }
|
|
26
|
+
eventType()(PlaceVisited);
|
|
27
|
+
class VisitCancelled { personId = ''; placeId = ''; visitId = ''; }
|
|
28
|
+
eventType()(VisitCancelled);
|
|
29
|
+
class NoteWritten { personId = ''; placeId = ''; }
|
|
30
|
+
eventType()(NoteWritten);
|
|
31
|
+
|
|
32
|
+
class Visitor { personId = ''; }
|
|
33
|
+
graph('Places')(Visitor);
|
|
34
|
+
node()(Visitor);
|
|
35
|
+
graphKey()(Visitor.prototype, 'personId');
|
|
36
|
+
nodeFrom(PlaceVisited, { key: 'personId' })(Visitor);
|
|
37
|
+
|
|
38
|
+
class Place { placeId = ''; }
|
|
39
|
+
graph('Places')(Place);
|
|
40
|
+
node()(Place);
|
|
41
|
+
graphKey()(Place.prototype, 'placeId');
|
|
42
|
+
nodeFrom(PlaceVisited, { key: 'placeId' })(Place);
|
|
43
|
+
|
|
44
|
+
class Visited {
|
|
45
|
+
personId = '';
|
|
46
|
+
placeId = '';
|
|
47
|
+
visitId = '';
|
|
48
|
+
times = 0;
|
|
49
|
+
}
|
|
50
|
+
graph('Places')(Visited);
|
|
51
|
+
edge('VISITED')(Visited);
|
|
52
|
+
edgeSource(Visitor)(Visited.prototype, 'personId');
|
|
53
|
+
edgeTarget(Place)(Visited.prototype, 'placeId');
|
|
54
|
+
graphKey()(Visited.prototype, 'visitId');
|
|
55
|
+
count(PlaceVisited)(Visited.prototype, 'times');
|
|
56
|
+
edgeFrom(PlaceVisited, { sourceKey: 'personId', targetKey: 'placeId', identity: 'visitId' })(Visited);
|
|
57
|
+
edgeRemovedWith(VisitCancelled, { sourceKey: 'personId', targetKey: 'placeId' })(Visited);
|
|
58
|
+
|
|
59
|
+
describe('when declaring an edge with an identifying key', () => {
|
|
60
|
+
let result: Awaited<ReturnType<typeof discoverGraphs>>;
|
|
61
|
+
|
|
62
|
+
beforeAll(async () => {
|
|
63
|
+
result = await discoverGraphs([Visitor, Place, Visited]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should annotate the edge with the identifying property', () => {
|
|
67
|
+
JSON.parse(result.graphs.registrations[0].readModel.Schema).properties.VISITED['x-graph-identity'].should.equal('visitId');
|
|
68
|
+
});
|
|
69
|
+
it('should keep the identifying property out of the properties the events map', () => {
|
|
70
|
+
result.graphs.registrations[0].projection.Graph!.Edges.VISITED.From['PlaceVisited+1'].Properties.should.deep.equal({ times: '$count' });
|
|
71
|
+
});
|
|
72
|
+
it('should take the identity from the event property it names', () => {
|
|
73
|
+
result.graphs.registrations[0].projection.Graph!.Edges.VISITED.From['PlaceVisited+1'].Identity.should.equal('visitId');
|
|
74
|
+
});
|
|
75
|
+
it('should take the identity of a removal from the event property of the same name when none is named', () => {
|
|
76
|
+
result.graphs.registrations[0].projection.Graph!.Edges.VISITED.RemovedWith['VisitCancelled+1'].Identity.should.equal('visitId');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('when an event of an identified edge has no property for the identity', () => {
|
|
81
|
+
it('should fail the graph and name the property', async () => {
|
|
82
|
+
class NoteAuthor { personId = ''; }
|
|
83
|
+
graph('Notes')(NoteAuthor);
|
|
84
|
+
node()(NoteAuthor);
|
|
85
|
+
graphKey()(NoteAuthor.prototype, 'personId');
|
|
86
|
+
class NotePlace { placeId = ''; }
|
|
87
|
+
graph('Notes')(NotePlace);
|
|
88
|
+
node()(NotePlace);
|
|
89
|
+
graphKey()(NotePlace.prototype, 'placeId');
|
|
90
|
+
class Noted { personId = ''; placeId = ''; noteId = ''; }
|
|
91
|
+
graph('Notes')(Noted);
|
|
92
|
+
edge('NOTED')(Noted);
|
|
93
|
+
edgeSource(NoteAuthor)(Noted.prototype, 'personId');
|
|
94
|
+
edgeTarget(NotePlace)(Noted.prototype, 'placeId');
|
|
95
|
+
graphKey()(Noted.prototype, 'noteId');
|
|
96
|
+
edgeFrom(NoteWritten, { sourceKey: 'personId', targetKey: 'placeId' })(Noted);
|
|
97
|
+
|
|
98
|
+
const result = await discoverGraphs([NoteAuthor, NotePlace, Noted]);
|
|
99
|
+
|
|
100
|
+
result.graphs.registrations.length.should.equal(0);
|
|
101
|
+
[...result.graphs.failures.values()][0].should.be.instanceOf(UnknownGraphEventProperty).and.have.property('message').that.includes('noteId');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('when identifying an edge with the fluent builder', () => {
|
|
106
|
+
it('should identify it by the property and read the identity from the event property of the same name', async () => {
|
|
107
|
+
class VisitsGraph implements IGraphProjection {
|
|
108
|
+
define(builder: IGraphProjectionBuilder): void {
|
|
109
|
+
builder
|
|
110
|
+
.node(Visitor, node => node.from(PlaceVisited, from => from.usingKey(event => event.personId)))
|
|
111
|
+
.node(Place, node => node.from(PlaceVisited, from => from.usingKey(event => event.placeId)))
|
|
112
|
+
.edge(Visited, Visitor, Place, edge => edge
|
|
113
|
+
.identifiedBy(visited => visited.visitId)
|
|
114
|
+
.from(PlaceVisited, from => from.usingSourceKey(event => event.personId).usingTargetKey(event => event.placeId)));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
graphProjection('Visits')(VisitsGraph);
|
|
118
|
+
const result = await discoverGraphs([], [VisitsGraph]);
|
|
119
|
+
result.graphs.failures.size.should.equal(0);
|
|
120
|
+
result.graphs.registrations[0].projection.Graph!.Edges.VISITED.From['PlaceVisited+1'].Identity.should.equal('visitId');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should fail when the event has no property to identify the edge with', async () => {
|
|
124
|
+
class NotesGraph implements IGraphProjection {
|
|
125
|
+
define(builder: IGraphProjectionBuilder): void {
|
|
126
|
+
builder
|
|
127
|
+
.node(Visitor, node => node.from(NoteWritten, from => from.usingKey(event => event.personId)))
|
|
128
|
+
.node(Place, node => node.from(NoteWritten, from => from.usingKey(event => event.placeId)))
|
|
129
|
+
.edge(Visited, Visitor, Place, edge => edge
|
|
130
|
+
.from(NoteWritten, from => from.usingSourceKey(event => event.personId).usingTargetKey(event => event.placeId)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
graphProjection('Notes')(NotesGraph);
|
|
134
|
+
const result = await discoverGraphs([], [NotesGraph]);
|
|
135
|
+
result.graphs.failures.get(NotesGraph)!.should.be.instanceOf(UnknownGraphEventProperty);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
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 { SetOnceNotSupportedInGraph } from '../graphs/SetOnceNotSupportedInGraph.js';
|
|
27
|
+
import { setFrom } from '../modelBound/setFrom.js';
|
|
28
|
+
import { setFromContext } from '../modelBound/setFromContext.js';
|
|
29
|
+
import { node } from '../graphs/node.js';
|
|
30
|
+
import { nodeFrom } from '../graphs/nodeFrom.js';
|
|
31
|
+
import { NodeMustHaveExactlyOneKey } from '../graphs/NodeMustHaveExactlyOneKey.js';
|
|
32
|
+
import { UnknownGraphNode } from '../graphs/UnknownGraphNode.js';
|
|
33
|
+
import { discoverGraphs } from './given/a_discovered_graph.js';
|
|
34
|
+
|
|
35
|
+
chai.should();
|
|
36
|
+
|
|
37
|
+
class ThingHappened { thingId = ''; }
|
|
38
|
+
eventType()(ThingHappened);
|
|
39
|
+
|
|
40
|
+
function aNode(graphName: string, ...keys: string[]) {
|
|
41
|
+
class Thing {
|
|
42
|
+
thingId = '';
|
|
43
|
+
otherId = '';
|
|
44
|
+
}
|
|
45
|
+
graph(graphName)(Thing);
|
|
46
|
+
node()(Thing);
|
|
47
|
+
for (const key of keys) graphKey()(Thing.prototype, key);
|
|
48
|
+
nodeFrom(ThingHappened, { key: 'thingId' })(Thing);
|
|
49
|
+
return Thing;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function failureOf(...elements: Function[]) {
|
|
53
|
+
const result = await discoverGraphs(elements as never[]);
|
|
54
|
+
const failures = [...result.graphs.failures.values()];
|
|
55
|
+
return { failures, registered: result.graphs.registrations.length };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
describe('when a node has no key', () => {
|
|
59
|
+
it('should fail with NodeMustHaveExactlyOneKey', async () => {
|
|
60
|
+
const { failures, registered } = await failureOf(aNode('NoKey'));
|
|
61
|
+
failures[0].should.be.instanceOf(NodeMustHaveExactlyOneKey);
|
|
62
|
+
registered.should.equal(0);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('when a node has two keys', () => {
|
|
67
|
+
it('should fail with NodeMustHaveExactlyOneKey', async () => {
|
|
68
|
+
const { failures } = await failureOf(aNode('TwoKeys', 'thingId', 'otherId'));
|
|
69
|
+
failures[0].should.be.instanceOf(NodeMustHaveExactlyOneKey).and.have.property('message').that.includes('but it has 2');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('when the key of a node is not a property', () => {
|
|
74
|
+
it('should fail with GraphKeyPropertyNotFound', async () => {
|
|
75
|
+
class Keyless { present = ''; }
|
|
76
|
+
graph('Keyless')(Keyless);
|
|
77
|
+
node()(Keyless);
|
|
78
|
+
graphKey()(Keyless.prototype, 'absent');
|
|
79
|
+
const { failures } = await failureOf(Keyless);
|
|
80
|
+
failures[0].should.be.instanceOf(GraphKeyPropertyNotFound);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('when an edge does not name its end nodes', () => {
|
|
85
|
+
it('should fail with EdgeMustHaveOneSourceAndOneTarget', async () => {
|
|
86
|
+
class Dangling { weight = 0; }
|
|
87
|
+
graph('Dangling')(Dangling);
|
|
88
|
+
edge('DANGLES')(Dangling);
|
|
89
|
+
const { failures } = await failureOf(Dangling);
|
|
90
|
+
failures[0].should.be.instanceOf(EdgeMustHaveOneSourceAndOneTarget);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('when an edge has two identifying keys', () => {
|
|
95
|
+
it('should fail with EdgeCanHaveOnlyOneIdentifyingKey', async () => {
|
|
96
|
+
const Thing = aNode('TwoIdentities', 'thingId');
|
|
97
|
+
class Twice { fromId = ''; toId = ''; a = ''; b = ''; }
|
|
98
|
+
graph('TwoIdentities')(Twice);
|
|
99
|
+
edge('TWICE')(Twice);
|
|
100
|
+
edgeSource(Thing)(Twice.prototype, 'fromId');
|
|
101
|
+
edgeTarget(Thing)(Twice.prototype, 'toId');
|
|
102
|
+
graphKey()(Twice.prototype, 'a');
|
|
103
|
+
graphKey()(Twice.prototype, 'b');
|
|
104
|
+
edgeFrom(ThingHappened, { sourceKey: 'thingId', targetKey: 'thingId' })(Twice);
|
|
105
|
+
const { failures } = await failureOf(Thing, Twice);
|
|
106
|
+
failures[0].should.be.instanceOf(EdgeCanHaveOnlyOneIdentifyingKey);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('when an edge connects a type that is not a node of its graph', () => {
|
|
111
|
+
it('should fail with UnknownGraphNode', async () => {
|
|
112
|
+
const Thing = aNode('Unconnected', 'thingId');
|
|
113
|
+
class Stranger { strangerId = ''; }
|
|
114
|
+
class Lonely { fromId = ''; toId = ''; }
|
|
115
|
+
graph('Unconnected')(Lonely);
|
|
116
|
+
edge('LONELY')(Lonely);
|
|
117
|
+
edgeSource(Thing)(Lonely.prototype, 'fromId');
|
|
118
|
+
edgeTarget(Stranger)(Lonely.prototype, 'toId');
|
|
119
|
+
const { failures, registered } = await failureOf(Thing, Lonely);
|
|
120
|
+
failures[0].should.be.instanceOf(UnknownGraphNode);
|
|
121
|
+
registered.should.equal(0);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('when a node has an object property', () => {
|
|
126
|
+
it('should fail with NestedObjectInGraph', async () => {
|
|
127
|
+
class Address { street = ''; }
|
|
128
|
+
class Resident { residentId = ''; address = new Address(); }
|
|
129
|
+
field(String)(Resident.prototype, 'residentId');
|
|
130
|
+
field(Address)(Resident.prototype, 'address');
|
|
131
|
+
graph('Residents')(Resident);
|
|
132
|
+
node()(Resident);
|
|
133
|
+
graphKey()(Resident.prototype, 'residentId');
|
|
134
|
+
const { failures } = await failureOf(Resident);
|
|
135
|
+
failures[0].should.be.instanceOf(NestedObjectInGraph).and.have.property('message').that.includes("'address'");
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('when a node property is set from an event only once', () => {
|
|
140
|
+
it('should fail with SetOnceNotSupportedInGraph', async () => {
|
|
141
|
+
const Thing = aNode('SetOnceNode', 'thingId');
|
|
142
|
+
setFrom(ThingHappened, { eventPropertyName: 'thingId', setOnce: true })(Thing.prototype, 'otherId');
|
|
143
|
+
const { failures, registered } = await failureOf(Thing);
|
|
144
|
+
failures[0].should.be.instanceOf(SetOnceNotSupportedInGraph).and.have.property('message').that.includes("'otherId'");
|
|
145
|
+
registered.should.equal(0);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('when an edge property is set from the event context only once', () => {
|
|
150
|
+
it('should fail with SetOnceNotSupportedInGraph', async () => {
|
|
151
|
+
const Thing = aNode('SetOnceEdge', 'thingId');
|
|
152
|
+
class Linked { fromId = ''; toId = ''; since = new Date(); }
|
|
153
|
+
graph('SetOnceEdge')(Linked);
|
|
154
|
+
edge('LINKED')(Linked);
|
|
155
|
+
edgeSource(Thing)(Linked.prototype, 'fromId');
|
|
156
|
+
edgeTarget(Thing)(Linked.prototype, 'toId');
|
|
157
|
+
setFromContext(ThingHappened, { contextProperty: 'occurred', setOnce: true })(Linked.prototype, 'since');
|
|
158
|
+
edgeFrom(ThingHappened, { sourceKey: 'thingId', targetKey: 'thingId' })(Linked);
|
|
159
|
+
const { failures } = await failureOf(Thing, Linked);
|
|
160
|
+
failures[0].should.be.instanceOf(SetOnceNotSupportedInGraph).and.have.property('message').that.includes("'since'");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('when a node does not say which graph it belongs to', () => {
|
|
165
|
+
it('should fail with GraphNameRequired', async () => {
|
|
166
|
+
class Homeless { homelessId = ''; }
|
|
167
|
+
node()(Homeless);
|
|
168
|
+
graphKey()(Homeless.prototype, 'homelessId');
|
|
169
|
+
const { failures } = await failureOf(Homeless);
|
|
170
|
+
failures[0].should.be.instanceOf(GraphNameRequired);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('when a node is also a read model', () => {
|
|
175
|
+
it('should fail with GraphElementCannotBeReadModel', async () => {
|
|
176
|
+
const Thing = aNode('Both', 'thingId');
|
|
177
|
+
fromEvent(ThingHappened)(Thing);
|
|
178
|
+
const { failures } = await failureOf(Thing);
|
|
179
|
+
failures[0].should.be.instanceOf(GraphElementCannotBeReadModel);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('when two nodes of a graph have the same label', () => {
|
|
184
|
+
it('should fail with GraphHasDuplicateElement', async () => {
|
|
185
|
+
const first = aNode('Duplicates', 'thingId');
|
|
186
|
+
const second = aNode('Duplicates', 'thingId');
|
|
187
|
+
const { failures } = await failureOf(first, second);
|
|
188
|
+
failures[0].should.be.instanceOf(GraphHasDuplicateElement);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('when one graph is invalid', () => {
|
|
193
|
+
it('should still register the valid graphs', async () => {
|
|
194
|
+
const valid = aNode('Valid', 'thingId');
|
|
195
|
+
const invalid = aNode('Invalid');
|
|
196
|
+
const result = await discoverGraphs([valid, invalid]);
|
|
197
|
+
result.graphs.registrations.map(_ => _.graphName).should.deep.equal(['Valid']);
|
|
198
|
+
result.graphs.failures.has(invalid).should.be.true;
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('should leave a graph unregistered when one of its elements is invalid', async () => {
|
|
202
|
+
const valid = aNode('Partial', 'thingId');
|
|
203
|
+
class Unfinished { unfinishedId = ''; }
|
|
204
|
+
graph('Partial')(Unfinished);
|
|
205
|
+
node()(Unfinished);
|
|
206
|
+
const result = await discoverGraphs([valid, Unfinished]);
|
|
207
|
+
result.graphs.registrations.length.should.equal(0);
|
|
208
|
+
result.graphs.failures.has(Unfinished).should.be.true;
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe('when two graph projections declare the same graph', () => {
|
|
213
|
+
it('should register the first and fail the second with GraphDeclaredMoreThanOnce', async () => {
|
|
214
|
+
const Thing = aNode('Twice', 'thingId');
|
|
215
|
+
class First implements IGraphProjection {
|
|
216
|
+
define(builder: IGraphProjectionBuilder): void {
|
|
217
|
+
builder.node(Thing, node => node.from(ThingHappened));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
class Second extends First {}
|
|
221
|
+
graphProjection('Twice')(First);
|
|
222
|
+
graphProjection('Twice')(Second);
|
|
223
|
+
const result = await discoverGraphs([], [First, Second]);
|
|
224
|
+
result.graphs.registrations.length.should.equal(1);
|
|
225
|
+
result.graphs.failures.get(Second)!.should.be.instanceOf(GraphDeclaredMoreThanOnce);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
@@ -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, ForEach: '' } },
|
|
83
|
+
RemovedWith: { 'AuthorLeft+1': { Key: 'authorId', Detach: true, ForEach: '' } }
|
|
84
|
+
});
|
|
85
|
+
should(registration.projection.Graph!.Nodes.Book.From['BookWritten+1']).deep.equal({
|
|
86
|
+
Key: 'bookId', Properties: { editions: '$count' }, UpdateOnly: false, ForEach: ''
|
|
87
|
+
});
|
|
88
|
+
should(registration.projection.Graph!.Edges.WROTE.From['BookWritten+1']).deep.equal({
|
|
89
|
+
SourceKey: 'authorId', TargetKey: 'bookId', Identity: '', Properties: { writtenAt: '$eventContext(Occurred)' }, ForEach: ''
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|