@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,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 node class decorator. */
|
|
10
|
+
export interface NodeMetadata {
|
|
11
|
+
/** The node label. */
|
|
12
|
+
readonly label: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const METADATA_KEY = 'chronicle:graph:node';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Class decorator that marks a class as a node in a property graph. The properties of the class are the
|
|
19
|
+
* properties of the node, and the member with the graphKey decorator holds its unique key. Which events create,
|
|
20
|
+
* update and remove nodes is declared with nodeFrom, nodeRemovedWith and the property mapping decorators.
|
|
21
|
+
* @param label - The node label. Defaults to the name of the class.
|
|
22
|
+
* @returns A class decorator.
|
|
23
|
+
*/
|
|
24
|
+
export function node(label?: string): ChronicleClassDecorator {
|
|
25
|
+
return (target: object) => {
|
|
26
|
+
const type = target as Function;
|
|
27
|
+
const metadata: NodeMetadata = { label: label ?? type.name };
|
|
28
|
+
Reflect.defineMetadata(METADATA_KEY, metadata, target);
|
|
29
|
+
TypeDiscoverer.default.register(DecoratorType.GraphElement, type as Constructor);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves the metadata stored by the node decorator.
|
|
35
|
+
* @param target - The class constructor.
|
|
36
|
+
* @returns The metadata, or undefined when the class is not a node.
|
|
37
|
+
*/
|
|
38
|
+
export function getNodeMetadata(target: Function): NodeMetadata | undefined {
|
|
39
|
+
return Reflect.getMetadata(METADATA_KEY, target) as NodeMetadata | 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 nodeFrom class decorator. */
|
|
8
|
+
export interface NodeFromOptions {
|
|
9
|
+
/** The name of the event property that holds the key of the node. Defaults to the event source id. */
|
|
10
|
+
readonly key?: string;
|
|
11
|
+
|
|
12
|
+
/** A constant key. Every event then updates the same node. */
|
|
13
|
+
readonly constantKey?: string;
|
|
14
|
+
|
|
15
|
+
/** Only set properties on a node that already exists, instead of creating it. */
|
|
16
|
+
readonly updateOnly?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Metadata stored by the nodeFrom class decorator. */
|
|
20
|
+
export interface NodeFromMetadata extends NodeFromOptions {
|
|
21
|
+
/** The event constructor. */
|
|
22
|
+
readonly eventType: Function;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const METADATA_KEY = 'chronicle:graph:nodeFrom';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Class decorator that creates or updates a node when an event is observed. Properties of the node are mapped by
|
|
29
|
+
* name from an event property of the same name, or explicitly with the property mapping decorators.
|
|
30
|
+
* @param eventType - The event constructor.
|
|
31
|
+
* @param options - Optional key and update-only configuration.
|
|
32
|
+
* @returns A class decorator.
|
|
33
|
+
*/
|
|
34
|
+
export function nodeFrom(eventType: Function, options?: NodeFromOptions): ChronicleClassDecorator {
|
|
35
|
+
return (target: object) => {
|
|
36
|
+
const existing: NodeFromMetadata[] = Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
37
|
+
Reflect.defineMetadata(METADATA_KEY, [...existing, { eventType, ...options }], target);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves all nodeFrom metadata stored on the given class constructor.
|
|
43
|
+
* @param target - The class constructor.
|
|
44
|
+
* @returns An array of nodeFrom metadata entries.
|
|
45
|
+
*/
|
|
46
|
+
export function getNodeFromMetadata(target: Function): NodeFromMetadata[] {
|
|
47
|
+
return Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
48
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 nodeRemovedWith class decorator. */
|
|
8
|
+
export interface NodeRemovedWithOptions {
|
|
9
|
+
/** The name of the event property that holds the key of the node. Defaults to the event source id. */
|
|
10
|
+
readonly key?: string;
|
|
11
|
+
|
|
12
|
+
/** Delete the edges attached to the node with it. Without it a node that still has edges cannot be deleted. */
|
|
13
|
+
readonly detach?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Metadata stored by the nodeRemovedWith class decorator. */
|
|
17
|
+
export interface NodeRemovedWithMetadata extends NodeRemovedWithOptions {
|
|
18
|
+
/** The event constructor. */
|
|
19
|
+
readonly eventType: Function;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const METADATA_KEY = 'chronicle:graph:nodeRemovedWith';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Class decorator that deletes a node when an event is observed.
|
|
26
|
+
* @param eventType - The event constructor.
|
|
27
|
+
* @param options - Optional key and detach configuration.
|
|
28
|
+
* @returns A class decorator.
|
|
29
|
+
*/
|
|
30
|
+
export function nodeRemovedWith(eventType: Function, options?: NodeRemovedWithOptions): ChronicleClassDecorator {
|
|
31
|
+
return (target: object) => {
|
|
32
|
+
const existing: NodeRemovedWithMetadata[] = Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
33
|
+
Reflect.defineMetadata(METADATA_KEY, [...existing, { eventType, ...options }], target);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves all nodeRemovedWith metadata stored on the given class constructor.
|
|
39
|
+
* @param target - The class constructor.
|
|
40
|
+
* @returns An array of nodeRemovedWith metadata entries.
|
|
41
|
+
*/
|
|
42
|
+
export function getNodeRemovedWithMetadata(target: Function): NodeRemovedWithMetadata[] {
|
|
43
|
+
return Reflect.getMetadata(METADATA_KEY, target) ?? [];
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { PropertyAccessor, PropertyPathResolverProxyHandler } from '@cratis/fundamentals';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resolves the path of the property an accessor selects.
|
|
8
|
+
* @param accessor - The property accessor, for example `event => event.personId`.
|
|
9
|
+
* @returns The property path.
|
|
10
|
+
*/
|
|
11
|
+
export function propertyPathOf<T>(accessor: PropertyAccessor<T>): string {
|
|
12
|
+
const handler = new PropertyPathResolverProxyHandler();
|
|
13
|
+
accessor(new Proxy({}, handler) as T);
|
|
14
|
+
return handler.property;
|
|
15
|
+
}
|
package/projections/index.ts
CHANGED
|
@@ -8,7 +8,13 @@ export type { ProjectionState } from './ProjectionState.js';
|
|
|
8
8
|
export type { ProjectionQueryResult } from './ProjectionQueryResult.js';
|
|
9
9
|
export { UnableToQueryProjection } from './UnableToQueryProjection.js';
|
|
10
10
|
export { InvalidEventContextPropertyError } from './InvalidEventContextPropertyError.js';
|
|
11
|
+
export { InvalidCausedByProperty } from './InvalidCausedByProperty.js';
|
|
12
|
+
export type { CausedByProperty } from './causedBy.js';
|
|
13
|
+
export { ChildrenPlacement, SortDirection } from './childrenOrdering.js';
|
|
14
|
+
export type { ChildrenOrderingDefinitionLike } from './childrenOrdering.js';
|
|
15
|
+
export { ChildrenOrderingNotSupportedByContracts } from './ChildrenOrderingNotSupportedByContracts.js';
|
|
11
16
|
export { VariantMustDeclareEntersOnEvent } from './VariantMustDeclareEntersOnEvent.js';
|
|
12
17
|
export { GlobalHandlerPropertyNotOnVariant } from './GlobalHandlerPropertyNotOnVariant.js';
|
|
13
18
|
export * from './declarative/index.js';
|
|
14
19
|
export * from './modelBound/index.js';
|
|
20
|
+
export * from './graphs/index.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
/** Error thrown when the childrenFrom decorators on a property declare different orderings for the same children collection. */
|
|
5
|
+
export class ConflictingChildrenOrdering extends Error {
|
|
6
|
+
/**
|
|
7
|
+
* Creates the error.
|
|
8
|
+
* @param property - The children property.
|
|
9
|
+
*/
|
|
10
|
+
constructor(readonly property: string) {
|
|
11
|
+
super(`The children property '${property}' declares more than one ordering. Use only one of prepend, orderBy or orderByDescending, and declare the same ordering on every @childrenFrom for the property or leave it unset.`);
|
|
12
|
+
this.name = 'ConflictingChildrenOrdering';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -5,12 +5,13 @@ import 'reflect-metadata';
|
|
|
5
5
|
import { AutoMap } from '@cratis/chronicle.contracts';
|
|
6
6
|
import { Constructor, Fields } from '@cratis/fundamentals';
|
|
7
7
|
import { TypeIntrospector } from '../../types/index.js';
|
|
8
|
+
import type { ChildrenOrderingDefinitionLike } from '../childrenOrdering.js';
|
|
8
9
|
import { constantValueExpression } from '../constantValueExpression.js';
|
|
9
10
|
import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
|
|
10
11
|
import { notSetPropertyPath } from '../notSetPropertyPath.js';
|
|
11
12
|
import { getEventTypeFor } from '../../events/eventTypeDecorator.js';
|
|
12
13
|
import { getAddFromMetadata } from './addFrom.js';
|
|
13
|
-
import { ChildrenFromMetadata, getChildrenFromMetadata } from './childrenFrom.js';
|
|
14
|
+
import { ChildrenFromMetadata, getChildrenFromMetadata, getChildrenOrdering } from './childrenFrom.js';
|
|
14
15
|
import { getClearWithClassMetadata, getClearWithPropertyMetadata } from './clearWith.js';
|
|
15
16
|
import { getCountMetadata } from './count.js';
|
|
16
17
|
import { getDecrementMetadata } from './decrement.js';
|
|
@@ -20,8 +21,8 @@ import { isNested } from './nested.js';
|
|
|
20
21
|
import { isNoAutoMap, isPropertyNoAutoMap } from './noAutoMap.js';
|
|
21
22
|
import { getRemovedWithClassMetadata, getRemovedWithPropertyMetadata } from './removedWith.js';
|
|
22
23
|
import { getRemovedWithJoinClassMetadata, getRemovedWithJoinPropertyMetadata } from './removedWithJoin.js';
|
|
23
|
-
import { getSetFromMetadata } from './setFrom.js';
|
|
24
|
-
import { getSetFromContextMetadata } from './setFromContext.js';
|
|
24
|
+
import { getSetFromMetadata, setFromExpression } from './setFrom.js';
|
|
25
|
+
import { getSetFromContextMetadata, setFromContextExpression } from './setFromContext.js';
|
|
25
26
|
import { getSetValueMetadata } from './setValue.js';
|
|
26
27
|
import { getSubtractFromMetadata } from './subtractFrom.js';
|
|
27
28
|
|
|
@@ -46,6 +47,7 @@ export interface ChildrenDefinitionLike {
|
|
|
46
47
|
AutoMap: AutoMap;
|
|
47
48
|
Nested: Record<string, ChildrenDefinitionLike>;
|
|
48
49
|
NoAutoMapProperties: string[];
|
|
50
|
+
Ordering?: ChildrenOrderingDefinitionLike;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
const aggregateExpressions = ['$count', '$increment', '$decrement', '$add', '$subtract'];
|
|
@@ -107,12 +109,12 @@ export function ensureFromEntry(fromByEventType: Map<string, FromRecord>, eventT
|
|
|
107
109
|
export function applyPropertyMappings(prototype: object, property: string, fromByEventType: Map<string, FromRecord>): void {
|
|
108
110
|
for (const mapping of getSetFromMetadata(prototype, property)) {
|
|
109
111
|
const entry = ensureFromEntry(fromByEventType, mapping.eventType);
|
|
110
|
-
entry.Value.Properties[property] = mapping
|
|
112
|
+
entry.Value.Properties[property] = setFromExpression(mapping, property);
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
for (const mapping of getSetFromContextMetadata(prototype, property)) {
|
|
114
116
|
const entry = ensureFromEntry(fromByEventType, mapping.eventType);
|
|
115
|
-
entry.Value.Properties[property] =
|
|
117
|
+
entry.Value.Properties[property] = setFromContextExpression(mapping, property);
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
for (const mapping of getSetValueMetadata(prototype, property)) {
|
|
@@ -342,6 +344,10 @@ export function buildChildrenEntry(
|
|
|
342
344
|
|
|
343
345
|
const explicitIdentifiedBy = metadataList.find(metadata => metadata.identifiedBy)?.identifiedBy;
|
|
344
346
|
definition.IdentifiedBy = explicitIdentifiedBy ?? discoverIdentifiedBy(childType, metadataList[0]?.key) ?? '$eventSourceId';
|
|
347
|
+
const ordering = getChildrenOrdering(property, metadataList);
|
|
348
|
+
if (ordering !== undefined) {
|
|
349
|
+
definition.Ordering = ordering;
|
|
350
|
+
}
|
|
345
351
|
|
|
346
352
|
for (const metadata of metadataList) {
|
|
347
353
|
const eventType = toContractEventType(metadata.eventType);
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { ChildrenOrderingDefinitionLike, prependOrdering, SortDirection, sortedOrdering } from '../childrenOrdering.js';
|
|
7
|
+
import { ConflictingChildrenOrdering } from './ConflictingChildrenOrdering.js';
|
|
6
8
|
import { decorateModelBoundProperty } from '../../types/modelBoundProperty.js';
|
|
7
9
|
import { ChroniclePropertyDecorator, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
8
10
|
|
|
@@ -18,6 +20,21 @@ export interface ChildrenFromMetadata {
|
|
|
18
20
|
readonly identifiedBy?: string;
|
|
19
21
|
/** The event property name used as the parent key. Defaults to the event source identifier. */
|
|
20
22
|
readonly parentKey?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Add new children at the start of the collection instead of the end. Ordering belongs to the collection: every
|
|
25
|
+
* childrenFrom on the same property has to agree on it, or leave it unset. Updating an existing child never moves it.
|
|
26
|
+
*/
|
|
27
|
+
readonly prepend?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Insert new children at their position when sorted ascending by this child property; children without a value sort
|
|
30
|
+
* first. Every childrenFrom on the same property has to agree on the ordering, or leave it unset.
|
|
31
|
+
*/
|
|
32
|
+
readonly orderBy?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Insert new children at their position when sorted descending by this child property; children without a value sort
|
|
35
|
+
* last. Every childrenFrom on the same property has to agree on the ordering, or leave it unset.
|
|
36
|
+
*/
|
|
37
|
+
readonly orderByDescending?: string;
|
|
21
38
|
}
|
|
22
39
|
|
|
23
40
|
/** Options for the options form of the childrenFrom property decorator. */
|
|
@@ -30,6 +47,21 @@ export interface ChildrenFromOptions {
|
|
|
30
47
|
readonly identifiedBy?: string;
|
|
31
48
|
/** The event property name used as the parent key. Defaults to the event source identifier. */
|
|
32
49
|
readonly parentKey?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Add new children at the start of the collection instead of the end. Ordering belongs to the collection: every
|
|
52
|
+
* childrenFrom on the same property has to agree on it, or leave it unset. Updating an existing child never moves it.
|
|
53
|
+
*/
|
|
54
|
+
readonly prepend?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Insert new children at their position when sorted ascending by this child property; children without a value sort
|
|
57
|
+
* first. Every childrenFrom on the same property has to agree on the ordering, or leave it unset.
|
|
58
|
+
*/
|
|
59
|
+
readonly orderBy?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Insert new children at their position when sorted descending by this child property; children without a value sort
|
|
62
|
+
* last. Every childrenFrom on the same property has to agree on the ordering, or leave it unset.
|
|
63
|
+
*/
|
|
64
|
+
readonly orderByDescending?: string;
|
|
33
65
|
}
|
|
34
66
|
|
|
35
67
|
const METADATA_KEY = 'chronicle:projection:childrenFrom';
|
|
@@ -38,7 +70,7 @@ const METADATA_KEY = 'chronicle:projection:childrenFrom';
|
|
|
38
70
|
* Property decorator that configures a children collection sub-projection from an event type.
|
|
39
71
|
* Use this form to name the child type and an explicit child key together.
|
|
40
72
|
* @param eventType - The event constructor.
|
|
41
|
-
* @param options - The child type, key, identifiedBy and
|
|
73
|
+
* @param options - The child type, key, identifiedBy, parentKey and ordering of new children.
|
|
42
74
|
* @returns A property decorator.
|
|
43
75
|
*/
|
|
44
76
|
export function childrenFrom(eventType: Function, options: ChildrenFromOptions): ChroniclePropertyDecorator;
|
|
@@ -75,7 +107,10 @@ function toMetadata(
|
|
|
75
107
|
if (typeof keyOrOptions === 'object' && keyOrOptions !== null) {
|
|
76
108
|
return {
|
|
77
109
|
eventType, childType: keyOrOptions.childType, key: keyOrOptions.key,
|
|
78
|
-
identifiedBy: keyOrOptions.identifiedBy, parentKey: keyOrOptions.parentKey
|
|
110
|
+
identifiedBy: keyOrOptions.identifiedBy, parentKey: keyOrOptions.parentKey,
|
|
111
|
+
...(keyOrOptions.prepend === true ? { prepend: true } : {}),
|
|
112
|
+
...(keyOrOptions.orderBy === undefined ? {} : { orderBy: keyOrOptions.orderBy }),
|
|
113
|
+
...(keyOrOptions.orderByDescending === undefined ? {} : { orderByDescending: keyOrOptions.orderByDescending })
|
|
79
114
|
};
|
|
80
115
|
}
|
|
81
116
|
return {
|
|
@@ -93,3 +128,28 @@ function toMetadata(
|
|
|
93
128
|
export function getChildrenFromMetadata(target: object, propertyKey: string): ChildrenFromMetadata[] {
|
|
94
129
|
return getPropertyMetadata<ChildrenFromMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
95
130
|
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Resolves the ordering of new children declared by the childrenFrom decorators on a property.
|
|
134
|
+
* @param property - The children property.
|
|
135
|
+
* @param metadataList - The childrenFrom metadata declared on the property.
|
|
136
|
+
* @returns The ordering, or undefined when new children are appended.
|
|
137
|
+
*/
|
|
138
|
+
export function getChildrenOrdering(property: string, metadataList: readonly ChildrenFromMetadata[]): ChildrenOrderingDefinitionLike | undefined {
|
|
139
|
+
const declared = metadataList.map(metadata => {
|
|
140
|
+
const orderings = [
|
|
141
|
+
metadata.prepend === true ? prependOrdering() : undefined,
|
|
142
|
+
metadata.orderBy === undefined ? undefined : sortedOrdering(metadata.orderBy, SortDirection.Ascending),
|
|
143
|
+
metadata.orderByDescending === undefined ? undefined : sortedOrdering(metadata.orderByDescending, SortDirection.Descending)
|
|
144
|
+
].filter(ordering => ordering !== undefined);
|
|
145
|
+
if (orderings.length > 1) {
|
|
146
|
+
throw new ConflictingChildrenOrdering(property);
|
|
147
|
+
}
|
|
148
|
+
return orderings[0];
|
|
149
|
+
}).filter(ordering => ordering !== undefined);
|
|
150
|
+
const [first] = declared;
|
|
151
|
+
if (declared.some(ordering => ordering.Placement !== first.Placement || ordering.SortBy !== first.SortBy || ordering.Direction !== first.Direction)) {
|
|
152
|
+
throw new ConflictingChildrenOrdering(property);
|
|
153
|
+
}
|
|
154
|
+
return first;
|
|
155
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import 'reflect-metadata';
|
|
5
|
+
import { field } from '@cratis/fundamentals';
|
|
6
|
+
import { chai, describe, it } from 'vitest';
|
|
7
|
+
import { eventType } from '../../../events/eventTypeDecorator.js';
|
|
8
|
+
import { ChildrenPlacement, SortDirection } from '../../childrenOrdering.js';
|
|
9
|
+
import { compileModelBound } from '../../for_ProjectionDefinitionCompiler/given/compile_model_bound.js';
|
|
10
|
+
import { childrenFrom } from '../childrenFrom.js';
|
|
11
|
+
import { ConflictingChildrenOrdering } from '../ConflictingChildrenOrdering.js';
|
|
12
|
+
|
|
13
|
+
chai.should();
|
|
14
|
+
|
|
15
|
+
class LineAdded {
|
|
16
|
+
lineId = '';
|
|
17
|
+
position = 0;
|
|
18
|
+
}
|
|
19
|
+
eventType()(LineAdded);
|
|
20
|
+
|
|
21
|
+
class LineImported {
|
|
22
|
+
lineId = '';
|
|
23
|
+
position = 0;
|
|
24
|
+
}
|
|
25
|
+
eventType()(LineImported);
|
|
26
|
+
|
|
27
|
+
class Line {
|
|
28
|
+
lineId = '';
|
|
29
|
+
position = 0;
|
|
30
|
+
}
|
|
31
|
+
field(String)(Line.prototype, 'lineId');
|
|
32
|
+
field(Number)(Line.prototype, 'position');
|
|
33
|
+
|
|
34
|
+
const orderingOf = (configure: (target: object) => void) => {
|
|
35
|
+
class Order {
|
|
36
|
+
id = '';
|
|
37
|
+
lines: Line[] = [];
|
|
38
|
+
}
|
|
39
|
+
field(String)(Order.prototype, 'id');
|
|
40
|
+
configure(Order.prototype);
|
|
41
|
+
const { definition } = compileModelBound(Order);
|
|
42
|
+
return (definition.Children.lines as unknown as { Ordering?: unknown }).Ordering;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
describe('when children declare no ordering', () => {
|
|
46
|
+
it('should leave the ordering out of the definition', () => {
|
|
47
|
+
const ordering = orderingOf(target => childrenFrom(LineAdded, { childType: Line, key: 'lineId' })(target, 'lines'));
|
|
48
|
+
(ordering === undefined).should.be.true;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('when children are prepended', () => {
|
|
53
|
+
it('should place new children first', () => orderingOf(target =>
|
|
54
|
+
childrenFrom(LineAdded, { childType: Line, key: 'lineId', prepend: true })(target, 'lines'))!.should.deep.equal({
|
|
55
|
+
Placement: ChildrenPlacement.Prepend, SortBy: '', Direction: SortDirection.Ascending
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('when children are ordered by a property', () => {
|
|
60
|
+
it('should sort new children ascending by it', () => orderingOf(target =>
|
|
61
|
+
childrenFrom(LineAdded, { childType: Line, key: 'lineId', orderBy: 'position' })(target, 'lines'))!.should.deep.equal({
|
|
62
|
+
Placement: ChildrenPlacement.Sorted, SortBy: 'position', Direction: SortDirection.Ascending
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('when children are ordered descending by a property on one of several creating events', () => {
|
|
67
|
+
it('should sort new children descending by it', () => orderingOf(target => {
|
|
68
|
+
childrenFrom(LineAdded, { childType: Line, key: 'lineId', orderByDescending: 'position' })(target, 'lines');
|
|
69
|
+
childrenFrom(LineImported, { childType: Line, key: 'lineId' })(target, 'lines');
|
|
70
|
+
})!.should.deep.equal({ Placement: ChildrenPlacement.Sorted, SortBy: 'position', Direction: SortDirection.Descending }));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('when every creating event declares the same ordering', () => {
|
|
74
|
+
it('should use it', () => orderingOf(target => {
|
|
75
|
+
childrenFrom(LineAdded, { childType: Line, key: 'lineId', orderBy: 'position' })(target, 'lines');
|
|
76
|
+
childrenFrom(LineImported, { childType: Line, key: 'lineId', orderBy: 'position' })(target, 'lines');
|
|
77
|
+
})!.should.deep.equal({ Placement: ChildrenPlacement.Sorted, SortBy: 'position', Direction: SortDirection.Ascending }));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('when creating events declare different orderings', () => {
|
|
81
|
+
it('should reject the conflict', () => (() => orderingOf(target => {
|
|
82
|
+
childrenFrom(LineAdded, { childType: Line, key: 'lineId', orderBy: 'position' })(target, 'lines');
|
|
83
|
+
childrenFrom(LineImported, { childType: Line, key: 'lineId', prepend: true })(target, 'lines');
|
|
84
|
+
})).should.throw(ConflictingChildrenOrdering, "'lines'"));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('when one creating event declares more than one ordering', () => {
|
|
88
|
+
it('should reject the conflict', () => (() => orderingOf(target =>
|
|
89
|
+
childrenFrom(LineAdded, { childType: Line, key: 'lineId', prepend: true, orderBy: 'position' })(target, 'lines')
|
|
90
|
+
)).should.throw(ConflictingChildrenOrdering));
|
|
91
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import 'reflect-metadata';
|
|
5
|
+
import { field } from '@cratis/fundamentals';
|
|
6
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
7
|
+
import type { EventContext } from '../../../events/EventContext.js';
|
|
8
|
+
import { eventType } from '../../../events/eventTypeDecorator.js';
|
|
9
|
+
import { compileModelBound } from '../../for_ProjectionDefinitionCompiler/given/compile_model_bound.js';
|
|
10
|
+
import { setFrom } from '../setFrom.js';
|
|
11
|
+
import { setFromContext } from '../setFromContext.js';
|
|
12
|
+
|
|
13
|
+
chai.should();
|
|
14
|
+
|
|
15
|
+
class AccountRenamed {
|
|
16
|
+
name = '';
|
|
17
|
+
displayName = '';
|
|
18
|
+
}
|
|
19
|
+
eventType()(AccountRenamed);
|
|
20
|
+
|
|
21
|
+
describe('when model-bound properties are set once', () => {
|
|
22
|
+
let properties: Record<string, string>;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
class Account {
|
|
26
|
+
id = '';
|
|
27
|
+
name = '';
|
|
28
|
+
firstName = '';
|
|
29
|
+
latestName = '';
|
|
30
|
+
createdAt = new Date(0);
|
|
31
|
+
createdBy = '';
|
|
32
|
+
renamedBy = '';
|
|
33
|
+
}
|
|
34
|
+
for (const property of ['id', 'name', 'firstName', 'latestName', 'createdBy', 'renamedBy']) field(String)(Account.prototype, property);
|
|
35
|
+
field(Date)(Account.prototype, 'createdAt');
|
|
36
|
+
setFrom(AccountRenamed, { setOnce: true })(Account.prototype, 'name');
|
|
37
|
+
setFrom(AccountRenamed, { eventPropertyName: 'displayName', setOnce: true })(Account.prototype, 'firstName');
|
|
38
|
+
setFrom(AccountRenamed, { eventPropertyName: 'displayName' })(Account.prototype, 'latestName');
|
|
39
|
+
setFromContext(AccountRenamed, { contextProperty: 'occurred', setOnce: true })(Account.prototype, 'createdAt');
|
|
40
|
+
setFromContext(AccountRenamed, { contextProperty: (c: EventContext) => c.causedBy, setOnce: true })(Account.prototype, 'createdBy');
|
|
41
|
+
setFromContext(AccountRenamed, 'causedBy')(Account.prototype, 'renamedBy');
|
|
42
|
+
const { definition } = compileModelBound(Account);
|
|
43
|
+
properties = definition.From.find(entry => entry.Key!.Id === 'AccountRenamed')!.Value!.Properties;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should wrap the same-named event property in set once', () => properties.name.should.equal('$setOnce(name)'));
|
|
47
|
+
it('should wrap the named event property in set once', () => properties.firstName.should.equal('$setOnce(displayName)'));
|
|
48
|
+
it('should keep a plain options mapping as a set', () => properties.latestName.should.equal('displayName'));
|
|
49
|
+
it('should wrap the event context property in set once', () => properties.createdAt.should.equal('$setOnce($eventContext(Occurred))'));
|
|
50
|
+
it('should wrap an event context accessor in set once', () => properties.createdBy.should.equal('$setOnce($eventContext(CausedBy))'));
|
|
51
|
+
it('should keep the positional event context form as a set', () => properties.renamedBy.should.equal('$eventContext(CausedBy)'));
|
|
52
|
+
});
|
|
@@ -5,9 +5,9 @@ export { fromEvent, getFromEventMetadata, hasFromEventMetadata } from './fromEve
|
|
|
5
5
|
export type { FromEventOptions } from './FromEventOptions.js';
|
|
6
6
|
export type { FromEventMetadata } from './FromEventMetadata.js';
|
|
7
7
|
export { setFrom, getSetFromMetadata } from './setFrom.js';
|
|
8
|
-
export type { SetFromMetadata } from './setFrom.js';
|
|
8
|
+
export type { SetFromMetadata, SetFromOptions } from './setFrom.js';
|
|
9
9
|
export { setFromContext, getSetFromContextMetadata } from './setFromContext.js';
|
|
10
|
-
export type { SetFromContextMetadata } from './setFromContext.js';
|
|
10
|
+
export type { SetFromContextMetadata, SetFromContextOptions } from './setFromContext.js';
|
|
11
11
|
export { join, getJoinMetadata } from './join.js';
|
|
12
12
|
export type { JoinMetadata } from './join.js';
|
|
13
13
|
export { addFrom, getAddFromMetadata } from './addFrom.js';
|
|
@@ -22,6 +22,7 @@ export { count, getCountMetadata } from './count.js';
|
|
|
22
22
|
export type { CountMetadata } from './count.js';
|
|
23
23
|
export { childrenFrom, getChildrenFromMetadata } from './childrenFrom.js';
|
|
24
24
|
export type { ChildrenFromMetadata, ChildrenFromOptions } from './childrenFrom.js';
|
|
25
|
+
export { ConflictingChildrenOrdering } from './ConflictingChildrenOrdering.js';
|
|
25
26
|
export { nested, isNested } from './nested.js';
|
|
26
27
|
export { clearWith, getClearWithClassMetadata, getClearWithPropertyMetadata } from './clearWith.js';
|
|
27
28
|
export type { ClearWithMetadata } from './clearWith.js';
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
import { TypeIntrospector } from '../../types/index.js';
|
|
6
|
+
import { setOnceExpression } from '../propertyExpressions.js';
|
|
6
7
|
import { decorateModelBoundProperty } from '../../types/modelBoundProperty.js';
|
|
7
8
|
import { ChroniclePropertyDecorator, getPropertyMetadata } from '../../types/propertyDecoratorMetadata.js';
|
|
8
9
|
|
|
@@ -12,22 +13,45 @@ export interface SetFromMetadata {
|
|
|
12
13
|
readonly eventType: Function;
|
|
13
14
|
/** The event property name to read the value from. Defaults to the decorated property name. */
|
|
14
15
|
readonly eventPropertyName?: string;
|
|
16
|
+
/** Whether the property is only assigned while it has no value yet. */
|
|
17
|
+
readonly setOnce?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Options for the setFrom property decorator. */
|
|
21
|
+
export interface SetFromOptions {
|
|
22
|
+
/** The event property name to read the value from. Defaults to the decorated property name. */
|
|
23
|
+
readonly eventPropertyName?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Only assign the property while it has no value yet: the first event that carries a value wins and later events
|
|
26
|
+
* leave the property as it is.
|
|
27
|
+
*/
|
|
28
|
+
readonly setOnce?: boolean;
|
|
15
29
|
}
|
|
16
30
|
|
|
17
31
|
const METADATA_KEY = 'chronicle:projection:setFrom';
|
|
18
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Property decorator that maps an event property value onto the decorated read model property.
|
|
35
|
+
* @param eventType - The event constructor.
|
|
36
|
+
* @param options - Options naming the event property and whether the property is only set once.
|
|
37
|
+
* @returns A property decorator.
|
|
38
|
+
*/
|
|
39
|
+
export function setFrom(eventType: Function, options: SetFromOptions): ChroniclePropertyDecorator;
|
|
19
40
|
/**
|
|
20
41
|
* Property decorator that maps an event property value onto the decorated read model property.
|
|
21
42
|
* @param eventType - The event constructor.
|
|
22
43
|
* @param eventPropertyName - Optional event property name. Defaults to the property name.
|
|
23
44
|
* @returns A property decorator.
|
|
24
45
|
*/
|
|
25
|
-
export function setFrom(eventType: Function, eventPropertyName?: string): ChroniclePropertyDecorator
|
|
46
|
+
export function setFrom(eventType: Function, eventPropertyName?: string): ChroniclePropertyDecorator;
|
|
47
|
+
export function setFrom(eventType: Function, eventPropertyNameOrOptions?: string | SetFromOptions): ChroniclePropertyDecorator {
|
|
48
|
+
const metadata: SetFromMetadata = typeof eventPropertyNameOrOptions === 'object' && eventPropertyNameOrOptions !== null
|
|
49
|
+
? { eventType, eventPropertyName: eventPropertyNameOrOptions.eventPropertyName, ...(eventPropertyNameOrOptions.setOnce === true ? { setOnce: true } : {}) }
|
|
50
|
+
: { eventType, eventPropertyName: eventPropertyNameOrOptions };
|
|
26
51
|
return decorateModelBoundProperty((target: object, propertyKey: string | symbol) => {
|
|
27
52
|
const key = propertyKey.toString();
|
|
28
53
|
TypeIntrospector.trackProperty((target as { constructor: Function }).constructor, key);
|
|
29
54
|
const existing: SetFromMetadata[] = Reflect.getMetadata(METADATA_KEY, target, key) ?? [];
|
|
30
|
-
const metadata: SetFromMetadata = { eventType, eventPropertyName };
|
|
31
55
|
Reflect.defineMetadata(METADATA_KEY, [...existing, metadata], target, key);
|
|
32
56
|
});
|
|
33
57
|
}
|
|
@@ -41,3 +65,14 @@ export function setFrom(eventType: Function, eventPropertyName?: string): Chroni
|
|
|
41
65
|
export function getSetFromMetadata(target: object, propertyKey: string): SetFromMetadata[] {
|
|
42
66
|
return getPropertyMetadata<SetFromMetadata[]>(METADATA_KEY, target, propertyKey) ?? [];
|
|
43
67
|
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Builds the property expression for a setFrom mapping.
|
|
71
|
+
* @param mapping - The setFrom metadata.
|
|
72
|
+
* @param property - The decorated read model property.
|
|
73
|
+
* @returns The event property, wrapped in `$setOnce(...)` when the mapping only sets once.
|
|
74
|
+
*/
|
|
75
|
+
export function setFromExpression(mapping: SetFromMetadata, property: string): string {
|
|
76
|
+
const expression = mapping.eventPropertyName ?? property;
|
|
77
|
+
return mapping.setOnce === true ? setOnceExpression(expression) : expression;
|
|
78
|
+
}
|