@cratis/chronicle 6.59.0 → 6.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/Projections.d.ts.map +1 -1
- package/dist/projections/Projections.js +3 -30
- package/dist/projections/Projections.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 +145 -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 +8 -0
- package/dist/projections/graphs/GraphMemberMappings.d.ts.map +1 -0
- package/dist/projections/graphs/GraphMemberMappings.js +54 -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/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 +48 -0
- package/dist/projections/graphs/index.d.ts.map +1 -0
- package/dist/projections/graphs/index.js +27 -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 +1 -0
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/index.js +1 -0
- package/dist/projections/index.js.map +1 -1
- 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/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/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/Projections.ts +4 -29
- 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 +91 -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 +199 -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/graphs/EdgeCanHaveOnlyOneIdentifyingKey.ts +16 -0
- package/projections/graphs/EdgeMustHaveOneSourceAndOneTarget.ts +16 -0
- package/projections/graphs/GraphDeclaredMoreThanOnce.ts +16 -0
- package/projections/graphs/GraphDefinitionBuilder.ts +166 -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 +57 -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/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 +50 -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 +1 -0
- package/projections/registerProjectionWithRetry.ts +53 -0
- package/readModels/rootReadModelTypes.ts +3 -1
- package/sinks/WellKnownSinks.ts +7 -1
- package/types/DecoratorType.ts +7 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
+
import type { IAddBuilder } from '../declarative/IAddBuilder.js';
|
|
6
|
+
import type { ISetBuilder } from '../declarative/ISetBuilder.js';
|
|
7
|
+
import type { ISubtractBuilder } from '../declarative/ISubtractBuilder.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Defines the property mappings shared by nodes and edges.
|
|
11
|
+
* @template TElement - The type of the node or edge.
|
|
12
|
+
* @template TEvent - The type of event.
|
|
13
|
+
* @template TSelf - The type of the builder, for continuation.
|
|
14
|
+
*/
|
|
15
|
+
export interface IGraphMappingBuilder<TElement, TEvent, TSelf> {
|
|
16
|
+
/**
|
|
17
|
+
* Sets a property.
|
|
18
|
+
* @param propertyAccessor - Accessor for the property on the node or edge.
|
|
19
|
+
* @returns The builder for what to set it to.
|
|
20
|
+
*/
|
|
21
|
+
set(propertyAccessor: PropertyAccessor<TElement>): ISetBuilder<TEvent, TSelf>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adds the value of an event property to a counter property.
|
|
25
|
+
* @param propertyAccessor - Accessor for the counter property.
|
|
26
|
+
* @returns The builder for which event property to add.
|
|
27
|
+
*/
|
|
28
|
+
add(propertyAccessor: PropertyAccessor<TElement>): IAddBuilder<TEvent, TSelf>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Subtracts the value of an event property from a counter property.
|
|
32
|
+
* @param propertyAccessor - Accessor for the counter property.
|
|
33
|
+
* @returns The builder for which event property to subtract.
|
|
34
|
+
*/
|
|
35
|
+
subtract(propertyAccessor: PropertyAccessor<TElement>): ISubtractBuilder<TEvent, TSelf>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Increments a counter property by one.
|
|
39
|
+
* @param propertyAccessor - Accessor for the counter property.
|
|
40
|
+
* @returns The builder for continuation.
|
|
41
|
+
*/
|
|
42
|
+
increment(propertyAccessor: PropertyAccessor<TElement>): TSelf;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Decrements a counter property by one.
|
|
46
|
+
* @param propertyAccessor - Accessor for the counter property.
|
|
47
|
+
* @returns The builder for continuation.
|
|
48
|
+
*/
|
|
49
|
+
decrement(propertyAccessor: PropertyAccessor<TElement>): TSelf;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Counts the events on a counter property.
|
|
53
|
+
* @param propertyAccessor - Accessor for the counter property.
|
|
54
|
+
* @returns The builder for continuation.
|
|
55
|
+
*/
|
|
56
|
+
count(propertyAccessor: PropertyAccessor<TElement>): TSelf;
|
|
57
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { Constructor } from '@cratis/fundamentals';
|
|
5
|
+
import type { PropertyAccessor } from '@cratis/fundamentals';
|
|
6
|
+
import type { IGraphNodeFromBuilder } from './IGraphNodeFromBuilder.js';
|
|
7
|
+
import type { IGraphNodeRemovedWithBuilder } from './IGraphNodeRemovedWithBuilder.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Defines a builder for a node.
|
|
11
|
+
* @template TNode - The type of node.
|
|
12
|
+
*/
|
|
13
|
+
export interface IGraphNodeBuilder<TNode> {
|
|
14
|
+
/**
|
|
15
|
+
* Declares the property that holds the unique key of the node. Not needed when the property has the graphKey decorator.
|
|
16
|
+
* @param keyAccessor - Accessor for the key property.
|
|
17
|
+
* @returns The builder for continuation.
|
|
18
|
+
*/
|
|
19
|
+
identifiedBy(keyAccessor: PropertyAccessor<TNode>): IGraphNodeBuilder<TNode>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates or updates the node when an event is observed.
|
|
23
|
+
* @param eventType - The event constructor.
|
|
24
|
+
* @param configure - Optional callback for the key and the properties. By default the key is the event source id
|
|
25
|
+
* and properties are mapped by name.
|
|
26
|
+
* @returns The builder for continuation.
|
|
27
|
+
*/
|
|
28
|
+
from<TEvent>(eventType: Constructor<TEvent>, configure?: (builder: IGraphNodeFromBuilder<TNode, TEvent>) => void): IGraphNodeBuilder<TNode>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Deletes the node when an event is observed.
|
|
32
|
+
* @param eventType - The event constructor.
|
|
33
|
+
* @param configure - Optional callback for the key and for detaching. By default the key is the event source id.
|
|
34
|
+
* @returns The builder for continuation.
|
|
35
|
+
*/
|
|
36
|
+
removedWith<TEvent>(eventType: Constructor<TEvent>, configure?: (builder: IGraphNodeRemovedWithBuilder<TEvent>) => void): IGraphNodeBuilder<TNode>;
|
|
37
|
+
}
|
|
@@ -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 type { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
+
import type { IGraphMappingBuilder } from './IGraphMappingBuilder.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Defines the builder for how an event creates or updates a node.
|
|
9
|
+
* @template TNode - The type of node.
|
|
10
|
+
* @template TEvent - The type of event.
|
|
11
|
+
*/
|
|
12
|
+
export interface IGraphNodeFromBuilder<TNode, TEvent> extends IGraphMappingBuilder<TNode, TEvent, IGraphNodeFromBuilder<TNode, TEvent>> {
|
|
13
|
+
/**
|
|
14
|
+
* Takes the key of the node from a property on the event. By default it is the event source id.
|
|
15
|
+
* @param keyAccessor - Accessor for the event property.
|
|
16
|
+
* @returns The builder for continuation.
|
|
17
|
+
*/
|
|
18
|
+
usingKey(keyAccessor: PropertyAccessor<TEvent>): IGraphNodeFromBuilder<TNode, TEvent>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Only sets properties on a node that already exists, instead of creating it.
|
|
22
|
+
* @returns The builder for continuation.
|
|
23
|
+
*/
|
|
24
|
+
onlyWhenExisting(): IGraphNodeFromBuilder<TNode, TEvent>;
|
|
25
|
+
}
|
|
@@ -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 type { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines the builder for how an event deletes a node.
|
|
8
|
+
* @template TEvent - The type of event.
|
|
9
|
+
*/
|
|
10
|
+
export interface IGraphNodeRemovedWithBuilder<TEvent> {
|
|
11
|
+
/**
|
|
12
|
+
* Takes the key of the node from a property on the event. By default it is the event source id.
|
|
13
|
+
* @param keyAccessor - Accessor for the event property.
|
|
14
|
+
* @returns The builder for continuation.
|
|
15
|
+
*/
|
|
16
|
+
usingKey(keyAccessor: PropertyAccessor<TEvent>): IGraphNodeRemovedWithBuilder<TEvent>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Deletes the edges attached to the node with it. Without it a node that still has edges cannot be deleted.
|
|
20
|
+
* @returns The builder for continuation.
|
|
21
|
+
*/
|
|
22
|
+
detach(): IGraphNodeRemovedWithBuilder<TEvent>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { IGraphProjectionBuilder } from './IGraphProjectionBuilder.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Defines a projection of events onto a property graph, declared with a fluent builder.
|
|
8
|
+
* Implement it on a class decorated with graphProjection.
|
|
9
|
+
*/
|
|
10
|
+
export interface IGraphProjection {
|
|
11
|
+
/**
|
|
12
|
+
* Defines the nodes and edges of the graph and the events they are projected from.
|
|
13
|
+
* @param builder - The builder to define with.
|
|
14
|
+
*/
|
|
15
|
+
define(builder: IGraphProjectionBuilder): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { Constructor } from '@cratis/fundamentals';
|
|
5
|
+
import type { IGraphEdgeBuilder } from './IGraphEdgeBuilder.js';
|
|
6
|
+
import type { IGraphNodeBuilder } from './IGraphNodeBuilder.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Defines a builder for the nodes and edges of a graph projection.
|
|
10
|
+
*/
|
|
11
|
+
export interface IGraphProjectionBuilder {
|
|
12
|
+
/**
|
|
13
|
+
* Defines a node.
|
|
14
|
+
* @param nodeType - The class of the node. Its name is the label of the node, unless the class has the node decorator.
|
|
15
|
+
* @param configure - Callback that configures the node.
|
|
16
|
+
* @returns The builder for continuation.
|
|
17
|
+
*/
|
|
18
|
+
node<TNode>(nodeType: Constructor<TNode>, configure: (builder: IGraphNodeBuilder<TNode>) => void): IGraphProjectionBuilder;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Defines an edge.
|
|
22
|
+
* @param edgeType - The class of the edge. Its properties, apart from the ones holding the keys of the end nodes, are
|
|
23
|
+
* the properties of the edge.
|
|
24
|
+
* @param sourceType - The class of the node the edge starts at.
|
|
25
|
+
* @param targetType - The class of the node the edge ends at.
|
|
26
|
+
* @param configure - Callback that configures the edge.
|
|
27
|
+
* @returns The builder for continuation.
|
|
28
|
+
*/
|
|
29
|
+
edge<TEdge>(
|
|
30
|
+
edgeType: Constructor<TEdge>,
|
|
31
|
+
sourceType: Function,
|
|
32
|
+
targetType: Function,
|
|
33
|
+
configure: (builder: IGraphEdgeBuilder<TEdge>) => void): IGraphProjectionBuilder;
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { Constructor } from '@cratis/fundamentals';
|
|
5
|
+
import type { GraphRegistration } from './GraphRegistration.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Defines a system for the property graphs an application declares, with the decorators and with the fluent builder,
|
|
9
|
+
* including discovery and registration with the Chronicle Kernel.
|
|
10
|
+
*/
|
|
11
|
+
export interface IGraphs {
|
|
12
|
+
/** Gets the registrations found by the last call to {@link IGraphs.discover}. */
|
|
13
|
+
readonly registrations: readonly GraphRegistration[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Gets the declarations that could not be turned into a registration, and why. One invalid graph does not
|
|
17
|
+
* take the rest of the graphs down with it.
|
|
18
|
+
*/
|
|
19
|
+
readonly failures: ReadonlyMap<Constructor, Error>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Discovers the graphs from the registered client artifacts.
|
|
23
|
+
* @returns A promise that resolves when discovery is complete.
|
|
24
|
+
*/
|
|
25
|
+
discover(): Promise<void>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Registers all discovered graphs with the Chronicle Kernel: the read model that describes each graph and the
|
|
29
|
+
* projection that fills it.
|
|
30
|
+
* @returns A promise that resolves when registration is complete.
|
|
31
|
+
*/
|
|
32
|
+
register(): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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 { TypeIntrospector } from '../../types/index.js';
|
|
5
|
+
import { constantValueExpression } from '../constantValueExpression.js';
|
|
6
|
+
import { EdgeCanHaveOnlyOneIdentifyingKey } from './EdgeCanHaveOnlyOneIdentifyingKey.js';
|
|
7
|
+
import { EdgeMustHaveOneSourceAndOneTarget } from './EdgeMustHaveOneSourceAndOneTarget.js';
|
|
8
|
+
import { getEdgeMetadata } from './edge.js';
|
|
9
|
+
import { getEdgeFromMetadata } from './edgeFrom.js';
|
|
10
|
+
import { getEdgeRemovedWithMetadata } from './edgeRemovedWith.js';
|
|
11
|
+
import { getEdgeSourceMetadata } from './edgeSource.js';
|
|
12
|
+
import { getEdgeTargetMetadata } from './edgeTarget.js';
|
|
13
|
+
import { getGraphName } from './graph.js';
|
|
14
|
+
import { isGraphKey } from './graphKey.js';
|
|
15
|
+
import { GraphNameRequired } from './GraphNameRequired.js';
|
|
16
|
+
import type { GraphEdgeModel } from './GraphEdgeModel.js';
|
|
17
|
+
import type { GraphNodeFromModel } from './GraphNodeFromModel.js';
|
|
18
|
+
import type { GraphNodeModel } from './GraphNodeModel.js';
|
|
19
|
+
import { readGraphMemberMappings } from './GraphMemberMappings.js';
|
|
20
|
+
import { getNodeMetadata } from './node.js';
|
|
21
|
+
import { getNodeFromMetadata } from './nodeFrom.js';
|
|
22
|
+
import { getNodeRemovedWithMetadata } from './nodeRemovedWith.js';
|
|
23
|
+
import { NodeMustHaveExactlyOneKey } from './NodeMustHaveExactlyOneKey.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Reads nodes and edges from the decorators on their types.
|
|
27
|
+
*/
|
|
28
|
+
export class ModelBoundGraphReader {
|
|
29
|
+
/**
|
|
30
|
+
* Gets the name of the graph a node or an edge belongs to.
|
|
31
|
+
* @param type - The node or edge type.
|
|
32
|
+
* @returns The name of the graph.
|
|
33
|
+
* @throws {GraphNameRequired} When the type does not name its graph.
|
|
34
|
+
*/
|
|
35
|
+
static graphNameOf(type: Function): string {
|
|
36
|
+
const name = getGraphName(type);
|
|
37
|
+
if (name === undefined || name === '') throw new GraphNameRequired(type);
|
|
38
|
+
return name;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Read a node.
|
|
43
|
+
* @param type - The node type.
|
|
44
|
+
* @returns The {@link GraphNodeModel}.
|
|
45
|
+
* @throws {NodeMustHaveExactlyOneKey} When the type does not have exactly one member with the graphKey decorator.
|
|
46
|
+
*/
|
|
47
|
+
readNode(type: Function): GraphNodeModel {
|
|
48
|
+
const members = TypeIntrospector.getTrackedProperties(type);
|
|
49
|
+
const keys = members.filter(member => isGraphKey(type.prototype, member));
|
|
50
|
+
if (keys.length !== 1) throw new NodeMustHaveExactlyOneKey(type, keys.length);
|
|
51
|
+
|
|
52
|
+
const byEvent = readGraphMemberMappings(type.prototype, members);
|
|
53
|
+
const from: GraphNodeFromModel[] = getNodeFromMetadata(type).map(attribute => ({
|
|
54
|
+
eventType: attribute.eventType,
|
|
55
|
+
key: attribute.constantKey !== undefined ? constantValueExpression(attribute.constantKey) : attribute.key,
|
|
56
|
+
properties: byEvent.get(attribute.eventType) ?? {},
|
|
57
|
+
updateOnly: attribute.updateOnly === true
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
// An event that only a property refers to still projects the node, keyed by the event source id.
|
|
61
|
+
for (const [eventType, properties] of byEvent) {
|
|
62
|
+
if (from.every(declared => declared.eventType !== eventType)) {
|
|
63
|
+
from.push({ eventType, properties, updateOnly: false });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
type,
|
|
69
|
+
label: getNodeMetadata(type)?.label ?? type.name,
|
|
70
|
+
keyProperty: keys[0],
|
|
71
|
+
from,
|
|
72
|
+
removedWith: getNodeRemovedWithMetadata(type).map(attribute => ({
|
|
73
|
+
eventType: attribute.eventType,
|
|
74
|
+
key: attribute.key,
|
|
75
|
+
detach: attribute.detach === true
|
|
76
|
+
}))
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Read an edge.
|
|
82
|
+
* @param type - The edge type.
|
|
83
|
+
* @returns The {@link GraphEdgeModel}.
|
|
84
|
+
* @throws {EdgeMustHaveOneSourceAndOneTarget} When the type does not name exactly one source and one target.
|
|
85
|
+
* @throws {EdgeCanHaveOnlyOneIdentifyingKey} When the type has more than one member with the graphKey decorator.
|
|
86
|
+
*/
|
|
87
|
+
readEdge(type: Function): GraphEdgeModel {
|
|
88
|
+
const members = TypeIntrospector.getTrackedProperties(type);
|
|
89
|
+
const sources = members.filter(member => getEdgeSourceMetadata(type.prototype, member) !== undefined);
|
|
90
|
+
const targets = members.filter(member => getEdgeTargetMetadata(type.prototype, member) !== undefined);
|
|
91
|
+
if (sources.length !== 1 || targets.length !== 1) throw new EdgeMustHaveOneSourceAndOneTarget(type);
|
|
92
|
+
|
|
93
|
+
const keys = members.filter(member => isGraphKey(type.prototype, member));
|
|
94
|
+
if (keys.length > 1) throw new EdgeCanHaveOnlyOneIdentifyingKey(type);
|
|
95
|
+
|
|
96
|
+
const byEvent = readGraphMemberMappings(type.prototype, members.filter(member => member !== sources[0] && member !== targets[0]));
|
|
97
|
+
return {
|
|
98
|
+
type,
|
|
99
|
+
edgeType: getEdgeMetadata(type)?.type ?? type.name,
|
|
100
|
+
sourceNode: getEdgeSourceMetadata(type.prototype, sources[0])!.nodeType,
|
|
101
|
+
targetNode: getEdgeTargetMetadata(type.prototype, targets[0])!.nodeType,
|
|
102
|
+
identifyingProperty: keys.length === 1 ? keys[0] : undefined,
|
|
103
|
+
excludedProperties: [sources[0], targets[0]],
|
|
104
|
+
from: getEdgeFromMetadata(type).map(attribute => ({
|
|
105
|
+
eventType: attribute.eventType,
|
|
106
|
+
sourceKey: attribute.sourceKey,
|
|
107
|
+
targetKey: attribute.targetKey,
|
|
108
|
+
identity: attribute.identity,
|
|
109
|
+
properties: byEvent.get(attribute.eventType) ?? {}
|
|
110
|
+
})),
|
|
111
|
+
removedWith: getEdgeRemovedWithMetadata(type).map(attribute => ({
|
|
112
|
+
eventType: attribute.eventType,
|
|
113
|
+
sourceKey: attribute.sourceKey,
|
|
114
|
+
targetKey: attribute.targetKey,
|
|
115
|
+
identity: attribute.identity
|
|
116
|
+
}))
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a node or an edge has an object property.
|
|
6
|
+
*/
|
|
7
|
+
export class NestedObjectInGraph extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new {@link NestedObjectInGraph}.
|
|
10
|
+
* @param type - The node or edge type.
|
|
11
|
+
* @param property - The name of the property.
|
|
12
|
+
*/
|
|
13
|
+
constructor(type: Function, property: string) {
|
|
14
|
+
super(`The property '${property}' of '${type.name}' is an object. Nodes and edges can only have primitive properties and arrays of primitives.`);
|
|
15
|
+
this.name = 'NestedObjectInGraph';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a node type does not have exactly one member marked with the graphKey decorator.
|
|
6
|
+
*/
|
|
7
|
+
export class NodeMustHaveExactlyOneKey extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new {@link NodeMustHaveExactlyOneKey}.
|
|
10
|
+
* @param type - The node type.
|
|
11
|
+
* @param keys - The number of members with the graphKey decorator.
|
|
12
|
+
*/
|
|
13
|
+
constructor(type: Function, keys: number) {
|
|
14
|
+
super(`The node type '${type.name}' must have exactly one member with the graphKey decorator, but it has ${keys}.`);
|
|
15
|
+
this.name = 'NodeMustHaveExactlyOneKey';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -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
|
+
/**
|
|
5
|
+
* Error thrown when a graph mapping needs an event property that the event type does not have.
|
|
6
|
+
*/
|
|
7
|
+
export class UnknownGraphEventProperty extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new {@link UnknownGraphEventProperty}.
|
|
10
|
+
* @param type - The node or edge type.
|
|
11
|
+
* @param eventType - The event type.
|
|
12
|
+
* @param property - The name of the property.
|
|
13
|
+
*/
|
|
14
|
+
constructor(type: Function, eventType: Function, property: string) {
|
|
15
|
+
super(`The mapping of '${type.name}' refers to the property '${property}', which '${eventType.name}' does not have.`);
|
|
16
|
+
this.name = 'UnknownGraphEventProperty';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when an edge connects a type that is not a node of its graph.
|
|
6
|
+
*/
|
|
7
|
+
export class UnknownGraphNode extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new {@link UnknownGraphNode}.
|
|
10
|
+
* @param edgeType - The edge type.
|
|
11
|
+
* @param node - The type that is not a node of the graph.
|
|
12
|
+
*/
|
|
13
|
+
constructor(edgeType: string, node: Function) {
|
|
14
|
+
super(`The edge '${edgeType}' connects '${node.name}', which is not a node of the graph.`);
|
|
15
|
+
this.name = 'UnknownGraphNode';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { DecoratorType, TypeDiscoverer } from '../../types/index.js';
|
|
7
|
+
import type { ChronicleClassDecorator } from '../../types/standardDecoratorMetadata.js';
|
|
8
|
+
|
|
9
|
+
/** Metadata stored by the edge class decorator. */
|
|
10
|
+
export interface EdgeMetadata {
|
|
11
|
+
/** The edge type, for example MEMBER_OF. */
|
|
12
|
+
readonly type: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const METADATA_KEY = 'chronicle:graph:edge';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Class decorator that marks a class as an edge in a property graph. The members marked with edgeSource and
|
|
19
|
+
* edgeTarget hold the keys of the nodes at both ends and are not properties of the edge. An edge is identified by its
|
|
20
|
+
* type, source and target. Give a member the graphKey decorator to identify it by that property as well, which allows
|
|
21
|
+
* more than one edge of the type between the same two nodes.
|
|
22
|
+
* @param type - The edge type, for example MEMBER_OF.
|
|
23
|
+
* @returns A class decorator.
|
|
24
|
+
*/
|
|
25
|
+
export function edge(type: string): ChronicleClassDecorator {
|
|
26
|
+
return (target: object) => {
|
|
27
|
+
const metadata: EdgeMetadata = { type };
|
|
28
|
+
Reflect.defineMetadata(METADATA_KEY, metadata, target);
|
|
29
|
+
TypeDiscoverer.default.register(DecoratorType.GraphElement, target as Constructor);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves the metadata stored by the edge decorator.
|
|
35
|
+
* @param target - The class constructor.
|
|
36
|
+
* @returns The metadata, or undefined when the class is not an edge.
|
|
37
|
+
*/
|
|
38
|
+
export function getEdgeMetadata(target: Function): EdgeMetadata | undefined {
|
|
39
|
+
return Reflect.getMetadata(METADATA_KEY, target) as EdgeMetadata | undefined;
|
|
40
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { ChronicleClassDecorator } from '../../types/standardDecoratorMetadata.js';
|
|
6
|
+
|
|
7
|
+
/** Options for the edgeFrom class decorator. */
|
|
8
|
+
export interface EdgeFromOptions {
|
|
9
|
+
/** The name of the event property that holds the key of the source node. */
|
|
10
|
+
readonly sourceKey: string;
|
|
11
|
+
|
|
12
|
+
/** The name of the event property that holds the key of the target node. */
|
|
13
|
+
readonly targetKey: string;
|
|
14
|
+
|
|
15
|
+
/** The name of the event property that holds the identity of the edge, for an edge type with an identifying property. */
|
|
16
|
+
readonly identity?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Metadata stored by the edgeFrom class decorator. */
|
|
20
|
+
export interface EdgeFromMetadata extends EdgeFromOptions {
|
|
21
|
+
/** The event constructor. */
|
|
22
|
+
readonly eventType: Function;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const METADATA_KEY = 'chronicle:graph:edgeFrom';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Class decorator that creates or updates an edge when an event is observed. Both end nodes are created without
|
|
29
|
+
* properties when they do not exist.
|
|
30
|
+
* @param eventType - The event constructor.
|
|
31
|
+
* @param options - The event properties that hold the keys of the end nodes and, optionally, the identity of the edge.
|
|
32
|
+
* @returns A class decorator.
|
|
33
|
+
*/
|
|
34
|
+
export function edgeFrom(eventType: Function, options: EdgeFromOptions): ChronicleClassDecorator {
|
|
35
|
+
return (target: object) => {
|
|
36
|
+
const existing: EdgeFromMetadata[] = Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
37
|
+
Reflect.defineMetadata(METADATA_KEY, [...existing, { eventType, ...options }], target);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves all edgeFrom metadata stored on the given class constructor.
|
|
43
|
+
* @param target - The class constructor.
|
|
44
|
+
* @returns An array of edgeFrom metadata entries.
|
|
45
|
+
*/
|
|
46
|
+
export function getEdgeFromMetadata(target: Function): EdgeFromMetadata[] {
|
|
47
|
+
return Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
48
|
+
}
|
|
@@ -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 'reflect-metadata';
|
|
5
|
+
import type { ChronicleClassDecorator } from '../../types/standardDecoratorMetadata.js';
|
|
6
|
+
import type { EdgeFromOptions } from './edgeFrom.js';
|
|
7
|
+
|
|
8
|
+
/** Metadata stored by the edgeRemovedWith class decorator. */
|
|
9
|
+
export interface EdgeRemovedWithMetadata extends EdgeFromOptions {
|
|
10
|
+
/** The event constructor. */
|
|
11
|
+
readonly eventType: Function;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const METADATA_KEY = 'chronicle:graph:edgeRemovedWith';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Class decorator that deletes an edge when an event is observed. The nodes at both ends stay.
|
|
18
|
+
* @param eventType - The event constructor.
|
|
19
|
+
* @param options - The event properties that hold the keys of the end nodes and, optionally, the identity of the edge.
|
|
20
|
+
* @returns A class decorator.
|
|
21
|
+
*/
|
|
22
|
+
export function edgeRemovedWith(eventType: Function, options: EdgeFromOptions): ChronicleClassDecorator {
|
|
23
|
+
return (target: object) => {
|
|
24
|
+
const existing: EdgeRemovedWithMetadata[] = Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
25
|
+
Reflect.defineMetadata(METADATA_KEY, [...existing, { eventType, ...options }], target);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves all edgeRemovedWith metadata stored on the given class constructor.
|
|
31
|
+
* @param target - The class constructor.
|
|
32
|
+
* @returns An array of edgeRemovedWith metadata entries.
|
|
33
|
+
*/
|
|
34
|
+
export function getEdgeRemovedWithMetadata(target: Function): EdgeRemovedWithMetadata[] {
|
|
35
|
+
return Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
36
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import 'reflect-metadata';
|
|
5
|
+
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
7
|
+
|
|
8
|
+
/** Metadata stored by the edgeSource property decorator. */
|
|
9
|
+
export interface EdgeSourceMetadata {
|
|
10
|
+
/** The type of the node. */
|
|
11
|
+
readonly nodeType: Function;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const METADATA_KEY = 'chronicle:graph:edgeSource';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Property decorator that marks the member of an edge that holds the key of the node the edge starts at.
|
|
18
|
+
* The member is not a property of the edge.
|
|
19
|
+
* @param nodeType - The type of the node.
|
|
20
|
+
* @returns A property decorator.
|
|
21
|
+
*/
|
|
22
|
+
export function edgeSource(nodeType: Function): ChroniclePropertyDecorator {
|
|
23
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
24
|
+
const key = propertyKey.toString();
|
|
25
|
+
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
26
|
+
const metadata: EdgeSourceMetadata = { nodeType };
|
|
27
|
+
Reflect.defineMetadata(METADATA_KEY, metadata, target, key);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the metadata stored by the edgeSource decorator on a property.
|
|
33
|
+
* @param target - The class prototype.
|
|
34
|
+
* @param propertyKey - The property name.
|
|
35
|
+
* @returns The metadata, or undefined when the property is not marked.
|
|
36
|
+
*/
|
|
37
|
+
export function getEdgeSourceMetadata(target: object, propertyKey: string): EdgeSourceMetadata | undefined {
|
|
38
|
+
return getPropertyMetadata<EdgeSourceMetadata>(METADATA_KEY, target, propertyKey);
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import 'reflect-metadata';
|
|
5
|
+
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChroniclePropertyDecorator, decorateProperty, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
7
|
+
|
|
8
|
+
/** Metadata stored by the edgeTarget property decorator. */
|
|
9
|
+
export interface EdgeTargetMetadata {
|
|
10
|
+
/** The type of the node. */
|
|
11
|
+
readonly nodeType: Function;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const METADATA_KEY = 'chronicle:graph:edgeTarget';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Property decorator that marks the member of an edge that holds the key of the node the edge ends at.
|
|
18
|
+
* The member is not a property of the edge.
|
|
19
|
+
* @param nodeType - The type of the node.
|
|
20
|
+
* @returns A property decorator.
|
|
21
|
+
*/
|
|
22
|
+
export function edgeTarget(nodeType: Function): ChroniclePropertyDecorator {
|
|
23
|
+
return decorateProperty((target: object, propertyKey: string | symbol) => {
|
|
24
|
+
const key = propertyKey.toString();
|
|
25
|
+
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
26
|
+
const metadata: EdgeTargetMetadata = { nodeType };
|
|
27
|
+
Reflect.defineMetadata(METADATA_KEY, metadata, target, key);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the metadata stored by the edgeTarget decorator on a property.
|
|
33
|
+
* @param target - The class prototype.
|
|
34
|
+
* @param propertyKey - The property name.
|
|
35
|
+
* @returns The metadata, or undefined when the property is not marked.
|
|
36
|
+
*/
|
|
37
|
+
export function getEdgeTargetMetadata(target: object, propertyKey: string): EdgeTargetMetadata | undefined {
|
|
38
|
+
return getPropertyMetadata<EdgeTargetMetadata>(METADATA_KEY, target, propertyKey);
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { ChronicleClassDecorator } from '../../types/standardDecoratorMetadata.js';
|
|
6
|
+
|
|
7
|
+
const METADATA_KEY = 'chronicle:graph';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Class decorator that names the graph a node, an edge or a graph projection belongs to.
|
|
11
|
+
* All the nodes and edges that name the same graph are registered as one graph.
|
|
12
|
+
* @param name - The name of the graph. It is also the name of the read model the graph is registered as.
|
|
13
|
+
* @returns A class decorator.
|
|
14
|
+
*/
|
|
15
|
+
export function graph(name: string): ChronicleClassDecorator {
|
|
16
|
+
return (target: object) => {
|
|
17
|
+
Reflect.defineMetadata(METADATA_KEY, name, target);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the graph name stored by the graph decorator.
|
|
23
|
+
* @param target - The class constructor.
|
|
24
|
+
* @returns The name of the graph, or undefined when the type does not name one.
|
|
25
|
+
*/
|
|
26
|
+
export function getGraphName(target: Function): string | undefined {
|
|
27
|
+
return Reflect.getMetadata(METADATA_KEY, target) as string | undefined;
|
|
28
|
+
}
|