@cratis/chronicle 6.60.0 → 6.62.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/connection/ChronicleConnection.ts +7 -1
- package/connection/ChronicleServices.ts +2 -0
- package/dist/connection/ChronicleConnection.d.ts +1 -0
- package/dist/connection/ChronicleConnection.d.ts.map +1 -1
- package/dist/connection/ChronicleConnection.js +6 -2
- package/dist/connection/ChronicleConnection.js.map +1 -1
- package/dist/connection/ChronicleServices.d.ts +2 -1
- package/dist/connection/ChronicleServices.d.ts.map +1 -1
- package/dist/eventSequences/EventForEventSourceId.d.ts +21 -1
- package/dist/eventSequences/EventForEventSourceId.d.ts.map +1 -1
- package/dist/eventSequences/EventSequence.d.ts +9 -0
- package/dist/eventSequences/EventSequence.d.ts.map +1 -1
- package/dist/eventSequences/EventSequence.js +18 -0
- package/dist/eventSequences/EventSequence.js.map +1 -1
- package/dist/eventSequences/IEventSequence.d.ts +30 -0
- package/dist/eventSequences/IEventSequence.d.ts.map +1 -1
- package/dist/imports/EventImport.d.ts +29 -0
- package/dist/imports/EventImport.d.ts.map +1 -0
- package/dist/imports/EventImport.js +248 -0
- package/dist/imports/EventImport.js.map +1 -0
- package/dist/imports/EventImportSettings.d.ts +32 -0
- package/dist/imports/EventImportSettings.d.ts.map +1 -0
- package/dist/imports/EventImportSettings.js +4 -0
- package/dist/imports/EventImportSettings.js.map +1 -0
- package/dist/imports/IEventImport.d.ts +50 -0
- package/dist/imports/IEventImport.d.ts.map +1 -0
- package/dist/imports/IEventImport.js +4 -0
- package/dist/imports/IEventImport.js.map +1 -0
- package/dist/imports/ImportChunkRefused.d.ts +12 -0
- package/dist/imports/ImportChunkRefused.d.ts.map +1 -0
- package/dist/imports/ImportChunkRefused.js +19 -0
- package/dist/imports/ImportChunkRefused.js.map +1 -0
- package/dist/imports/ImportCouldNotBegin.d.ts +10 -0
- package/dist/imports/ImportCouldNotBegin.d.ts.map +1 -0
- package/dist/imports/ImportCouldNotBegin.js +16 -0
- package/dist/imports/ImportCouldNotBegin.js.map +1 -0
- package/dist/imports/ImportOptions.d.ts +26 -0
- package/dist/imports/ImportOptions.d.ts.map +1 -0
- package/dist/imports/ImportOptions.js +4 -0
- package/dist/imports/ImportOptions.js.map +1 -0
- package/dist/imports/ImportProgress.d.ts +20 -0
- package/dist/imports/ImportProgress.d.ts.map +1 -0
- package/dist/imports/ImportProgress.js +4 -0
- package/dist/imports/ImportProgress.js.map +1 -0
- package/dist/imports/ImportRejection.d.ts +10 -0
- package/dist/imports/ImportRejection.d.ts.map +1 -0
- package/dist/imports/ImportRejection.js +4 -0
- package/dist/imports/ImportRejection.js.map +1 -0
- package/dist/imports/ImportResult.d.ts +30 -0
- package/dist/imports/ImportResult.d.ts.map +1 -0
- package/dist/imports/ImportResult.js +4 -0
- package/dist/imports/ImportResult.js.map +1 -0
- package/dist/imports/ImportState.d.ts +18 -0
- package/dist/imports/ImportState.d.ts.map +1 -0
- package/dist/imports/ImportState.js +21 -0
- package/dist/imports/ImportState.js.map +1 -0
- package/dist/imports/ImportTarget.d.ts +16 -0
- package/dist/imports/ImportTarget.d.ts.map +1 -0
- package/dist/imports/ImportTarget.js +4 -0
- package/dist/imports/ImportTarget.js.map +1 -0
- package/dist/imports/ImportWasAbandoned.d.ts +11 -0
- package/dist/imports/ImportWasAbandoned.d.ts.map +1 -0
- package/dist/imports/ImportWasAbandoned.js +16 -0
- package/dist/imports/ImportWasAbandoned.js.map +1 -0
- package/dist/imports/ImportsNotSupported.d.ts +5 -0
- package/dist/imports/ImportsNotSupported.d.ts.map +1 -0
- package/dist/imports/ImportsNotSupported.js +10 -0
- package/dist/imports/ImportsNotSupported.js.map +1 -0
- package/dist/imports/OnInvalidEvent.d.ts +8 -0
- package/dist/imports/OnInvalidEvent.d.ts.map +1 -0
- package/dist/imports/OnInvalidEvent.js +11 -0
- package/dist/imports/OnInvalidEvent.js.map +1 -0
- package/dist/imports/abortable.d.ts +23 -0
- package/dist/imports/abortable.d.ts.map +1 -0
- package/dist/imports/abortable.js +60 -0
- package/dist/imports/abortable.js.map +1 -0
- package/dist/imports/beginEventImport.d.ts +16 -0
- package/dist/imports/beginEventImport.d.ts.map +1 -0
- package/dist/imports/beginEventImport.js +74 -0
- package/dist/imports/beginEventImport.js.map +1 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.d.ts +144 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.d.ts.map +1 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.js +132 -0
- package/dist/imports/for_EventImport/given/a_kernel_import_session.js.map +1 -0
- package/dist/imports/importEvents.d.ts +13 -0
- package/dist/imports/importEvents.d.ts.map +1 -0
- package/dist/imports/importEvents.js +35 -0
- package/dist/imports/importEvents.js.map +1 -0
- package/dist/imports/index.d.ts +12 -0
- package/dist/imports/index.d.ts.map +1 -0
- package/dist/imports/index.js +9 -0
- package/dist/imports/index.js.map +1 -0
- package/dist/imports/isTransientImportFailure.d.ts +7 -0
- package/dist/imports/isTransientImportFailure.d.ts.map +1 -0
- package/dist/imports/isTransientImportFailure.js +13 -0
- package/dist/imports/isTransientImportFailure.js.map +1 -0
- package/dist/imports/sizeOfImportEvent.d.ts +9 -0
- package/dist/imports/sizeOfImportEvent.d.ts.map +1 -0
- package/dist/imports/sizeOfImportEvent.js +25 -0
- package/dist/imports/sizeOfImportEvent.js.map +1 -0
- package/dist/imports/toImportEvent.d.ts +14 -0
- package/dist/imports/toImportEvent.d.ts.map +1 -0
- package/dist/imports/toImportEvent.js +54 -0
- package/dist/imports/toImportEvent.js.map +1 -0
- package/dist/imports/toImportProgress.d.ts +9 -0
- package/dist/imports/toImportProgress.d.ts.map +1 -0
- package/dist/imports/toImportProgress.js +20 -0
- package/dist/imports/toImportProgress.js.map +1 -0
- package/dist/imports/toImportResult.d.ts +9 -0
- package/dist/imports/toImportResult.d.ts.map +1 -0
- package/dist/imports/toImportResult.js +33 -0
- package/dist/imports/toImportResult.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/observation/index.d.ts +2 -0
- package/dist/observation/index.d.ts.map +1 -1
- package/dist/observation/index.js +1 -0
- package/dist/observation/index.js.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 +4 -0
- 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/graphs/GraphDefinitionBuilder.d.ts.map +1 -1
- package/dist/projections/graphs/GraphDefinitionBuilder.js +7 -4
- package/dist/projections/graphs/GraphDefinitionBuilder.js.map +1 -1
- package/dist/projections/graphs/GraphMemberMappings.d.ts +1 -0
- package/dist/projections/graphs/GraphMemberMappings.d.ts.map +1 -1
- package/dist/projections/graphs/GraphMemberMappings.js +10 -5
- package/dist/projections/graphs/GraphMemberMappings.js.map +1 -1
- 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/index.d.ts +1 -0
- package/dist/projections/graphs/index.d.ts.map +1 -1
- package/dist/projections/graphs/index.js +1 -0
- package/dist/projections/graphs/index.js.map +1 -1
- package/dist/projections/index.d.ts +5 -0
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/index.js +3 -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/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +2 -1
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/testing/BatchPartitionOutcome.d.ts +7 -0
- package/dist/testing/BatchPartitionOutcome.d.ts.map +1 -0
- package/dist/testing/BatchPartitionOutcome.js +4 -0
- package/dist/testing/BatchPartitionOutcome.js.map +1 -0
- package/dist/testing/InProcessEventSequence.d.ts +4 -0
- package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
- package/dist/testing/InProcessEventSequence.js +2 -0
- package/dist/testing/InProcessEventSequence.js.map +1 -1
- package/dist/testing/ReactorDeliveryResult.d.ts +2 -0
- package/dist/testing/ReactorDeliveryResult.d.ts.map +1 -1
- package/dist/testing/ReactorScenario.d.ts +46 -10
- package/dist/testing/ReactorScenario.d.ts.map +1 -1
- package/dist/testing/ReactorScenario.js +120 -29
- package/dist/testing/ReactorScenario.js.map +1 -1
- package/dist/testing/deliverToBatchMethods.d.ts +35 -0
- package/dist/testing/deliverToBatchMethods.d.ts.map +1 -0
- package/dist/testing/deliverToBatchMethods.js +55 -0
- package/dist/testing/deliverToBatchMethods.js.map +1 -0
- 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/eventSequences/EventForEventSourceId.ts +25 -1
- package/eventSequences/EventSequence.ts +28 -0
- package/eventSequences/IEventSequence.ts +33 -0
- package/imports/EventImport.ts +263 -0
- package/imports/EventImportSettings.ts +46 -0
- package/imports/IEventImport.ts +58 -0
- package/imports/ImportChunkRefused.ts +15 -0
- package/imports/ImportCouldNotBegin.ts +14 -0
- package/imports/ImportOptions.ts +36 -0
- package/imports/ImportProgress.ts +29 -0
- package/imports/ImportRejection.ts +14 -0
- package/imports/ImportResult.ts +43 -0
- package/imports/ImportState.ts +26 -0
- package/imports/ImportTarget.ts +23 -0
- package/imports/ImportWasAbandoned.ts +16 -0
- package/imports/ImportsNotSupported.ts +10 -0
- package/imports/OnInvalidEvent.ts +11 -0
- package/imports/abortable.ts +57 -0
- package/imports/beginEventImport.ts +85 -0
- package/imports/for_EventImport/given/a_kernel_import_session.ts +160 -0
- package/imports/for_EventImport/when_a_chunk_fails.spec.ts +65 -0
- package/imports/for_EventImport/when_abandoning.spec.ts +52 -0
- package/imports/for_EventImport/when_cancelling_with_an_abort_signal.spec.ts +59 -0
- package/imports/for_EventImport/when_completing.spec.ts +71 -0
- package/imports/for_EventImport/when_cutting_events_into_chunks.spec.ts +70 -0
- package/imports/for_EventImport/when_keeping_chunks_in_flight.spec.ts +49 -0
- package/imports/for_beginEventImport/when_reattaching.spec.ts +82 -0
- package/imports/for_beginEventImport/when_the_kernel_does_not_serve_imports.spec.ts +55 -0
- package/imports/for_importEvents/when_importing_in_one_call.spec.ts +99 -0
- package/imports/for_toImportEvent/when_converting_an_event.spec.ts +74 -0
- package/imports/importEvents.ts +44 -0
- package/imports/index.ts +14 -0
- package/imports/isTransientImportFailure.ts +15 -0
- package/imports/sizeOfImportEvent.ts +25 -0
- package/imports/toImportEvent.ts +60 -0
- package/imports/toImportProgress.ts +24 -0
- package/imports/toImportResult.ts +36 -0
- package/index.ts +3 -0
- package/observation/index.ts +2 -0
- package/package.json +7 -2
- package/projections/ChildrenOrderingNotSupportedByContracts.ts +18 -0
- package/projections/InvalidCausedByProperty.ts +14 -0
- package/projections/Projections.ts +4 -0
- 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/when_building_a_fluent_graph.spec.ts +1 -1
- package/projections/for_Graphs/when_building_a_model_bound_graph.spec.ts +5 -4
- package/projections/for_Graphs/when_declaring_an_invalid_graph.spec.ts +28 -0
- package/projections/for_Graphs/when_declaring_with_standard_decorators.standard.spec.ts +4 -4
- package/projections/for_Graphs/when_mapping_properties.spec.ts +1 -1
- 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/GraphDefinitionBuilder.ts +7 -4
- package/projections/graphs/GraphMemberMappings.ts +8 -5
- package/projections/graphs/SetOnceNotSupportedInGraph.ts +18 -0
- package/projections/graphs/index.ts +1 -0
- package/projections/index.ts +5 -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/reducers/Reducers.ts +2 -1
- package/testing/BatchPartitionOutcome.ts +10 -0
- package/testing/InProcessEventSequence.ts +4 -0
- package/testing/ReactorDeliveryResult.ts +2 -0
- package/testing/ReactorScenario.ts +147 -39
- package/testing/deliverToBatchMethods.ts +90 -0
- package/testing/for_ReactorScenario/when_the_reactor_has_a_batch_method.spec.ts +143 -9
- 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
|
@@ -23,6 +23,9 @@ import { graphProjection } from '../graphs/graphProjection.js';
|
|
|
23
23
|
import type { IGraphProjection } from '../graphs/IGraphProjection.js';
|
|
24
24
|
import type { IGraphProjectionBuilder } from '../graphs/IGraphProjectionBuilder.js';
|
|
25
25
|
import { NestedObjectInGraph } from '../graphs/NestedObjectInGraph.js';
|
|
26
|
+
import { SetOnceNotSupportedInGraph } from '../graphs/SetOnceNotSupportedInGraph.js';
|
|
27
|
+
import { setFrom } from '../modelBound/setFrom.js';
|
|
28
|
+
import { setFromContext } from '../modelBound/setFromContext.js';
|
|
26
29
|
import { node } from '../graphs/node.js';
|
|
27
30
|
import { nodeFrom } from '../graphs/nodeFrom.js';
|
|
28
31
|
import { NodeMustHaveExactlyOneKey } from '../graphs/NodeMustHaveExactlyOneKey.js';
|
|
@@ -133,6 +136,31 @@ describe('when a node has an object property', () => {
|
|
|
133
136
|
});
|
|
134
137
|
});
|
|
135
138
|
|
|
139
|
+
describe('when a node property is set from an event only once', () => {
|
|
140
|
+
it('should fail with SetOnceNotSupportedInGraph', async () => {
|
|
141
|
+
const Thing = aNode('SetOnceNode', 'thingId');
|
|
142
|
+
setFrom(ThingHappened, { eventPropertyName: 'thingId', setOnce: true })(Thing.prototype, 'otherId');
|
|
143
|
+
const { failures, registered } = await failureOf(Thing);
|
|
144
|
+
failures[0].should.be.instanceOf(SetOnceNotSupportedInGraph).and.have.property('message').that.includes("'otherId'");
|
|
145
|
+
registered.should.equal(0);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('when an edge property is set from the event context only once', () => {
|
|
150
|
+
it('should fail with SetOnceNotSupportedInGraph', async () => {
|
|
151
|
+
const Thing = aNode('SetOnceEdge', 'thingId');
|
|
152
|
+
class Linked { fromId = ''; toId = ''; since = new Date(); }
|
|
153
|
+
graph('SetOnceEdge')(Linked);
|
|
154
|
+
edge('LINKED')(Linked);
|
|
155
|
+
edgeSource(Thing)(Linked.prototype, 'fromId');
|
|
156
|
+
edgeTarget(Thing)(Linked.prototype, 'toId');
|
|
157
|
+
setFromContext(ThingHappened, { contextProperty: 'occurred', setOnce: true })(Linked.prototype, 'since');
|
|
158
|
+
edgeFrom(ThingHappened, { sourceKey: 'thingId', targetKey: 'thingId' })(Linked);
|
|
159
|
+
const { failures } = await failureOf(Thing, Linked);
|
|
160
|
+
failures[0].should.be.instanceOf(SetOnceNotSupportedInGraph).and.have.property('message').that.includes("'since'");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
136
164
|
describe('when a node does not say which graph it belongs to', () => {
|
|
137
165
|
it('should fail with GraphNameRequired', async () => {
|
|
138
166
|
class Homeless { homelessId = ''; }
|
|
@@ -79,14 +79,14 @@ describe('when declaring a graph with standard decorators', () => {
|
|
|
79
79
|
'x-graph-target': 'Book'
|
|
80
80
|
});
|
|
81
81
|
should(registration.projection.Graph!.Nodes.Author).deep.equal({
|
|
82
|
-
From: { 'AuthorJoined+1': { Key: 'authorId', Properties: { name: 'name' }, UpdateOnly: false } },
|
|
83
|
-
RemovedWith: { 'AuthorLeft+1': { Key: 'authorId', Detach: true } }
|
|
82
|
+
From: { 'AuthorJoined+1': { Key: 'authorId', Properties: { name: 'name' }, UpdateOnly: false, ForEach: '' } },
|
|
83
|
+
RemovedWith: { 'AuthorLeft+1': { Key: 'authorId', Detach: true, ForEach: '' } }
|
|
84
84
|
});
|
|
85
85
|
should(registration.projection.Graph!.Nodes.Book.From['BookWritten+1']).deep.equal({
|
|
86
|
-
Key: 'bookId', Properties: { editions: '$count' }, UpdateOnly: false
|
|
86
|
+
Key: 'bookId', Properties: { editions: '$count' }, UpdateOnly: false, ForEach: ''
|
|
87
87
|
});
|
|
88
88
|
should(registration.projection.Graph!.Edges.WROTE.From['BookWritten+1']).deep.equal({
|
|
89
|
-
SourceKey: 'authorId', TargetKey: 'bookId', Identity: '', Properties: { writtenAt: '$eventContext(Occurred)' }
|
|
89
|
+
SourceKey: 'authorId', TargetKey: 'bookId', Identity: '', Properties: { writtenAt: '$eventContext(Occurred)' }, ForEach: ''
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
});
|
|
@@ -104,7 +104,7 @@ describe('when declaring how an event projects a node', () => {
|
|
|
104
104
|
it('should key the node with the constant and only change a node that exists', async () => {
|
|
105
105
|
const result = await discoverGraphs([Counter]);
|
|
106
106
|
result.graphs.registrations[0].projection.Graph!.Nodes.Counter.From['MemberJoined+1'].should.deep.equal({
|
|
107
|
-
Key: '$value(all)', Properties: { total: '$count' }, UpdateOnly: true
|
|
107
|
+
Key: '$value(all)', Properties: { total: '$count' }, UpdateOnly: true, ForEach: ''
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
110
|
});
|
|
@@ -0,0 +1,66 @@
|
|
|
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, vi } from 'vitest';
|
|
7
|
+
import type { IClientArtifactsProvider } from '../../artifacts/index.js';
|
|
8
|
+
import type { ChronicleConnection } from '../../connection/index.js';
|
|
9
|
+
import { eventType } from '../../events/eventTypeDecorator.js';
|
|
10
|
+
import { ChildrenOrderingNotSupportedByContracts } from '../ChildrenOrderingNotSupportedByContracts.js';
|
|
11
|
+
import { contractsSupportChildrenOrdering } from '../childrenOrderingSupport.js';
|
|
12
|
+
import { childrenFrom } from '../modelBound/childrenFrom.js';
|
|
13
|
+
import { Projections } from '../Projections.js';
|
|
14
|
+
|
|
15
|
+
chai.should();
|
|
16
|
+
|
|
17
|
+
class OrderLineAdded {
|
|
18
|
+
lineId = '';
|
|
19
|
+
}
|
|
20
|
+
eventType()(OrderLineAdded);
|
|
21
|
+
|
|
22
|
+
class OrderLine {
|
|
23
|
+
lineId = '';
|
|
24
|
+
}
|
|
25
|
+
field(String)(OrderLine.prototype, 'lineId');
|
|
26
|
+
|
|
27
|
+
class OrderWithOrderedLines {
|
|
28
|
+
id = '';
|
|
29
|
+
lines: OrderLine[] = [];
|
|
30
|
+
}
|
|
31
|
+
field(String)(OrderWithOrderedLines.prototype, 'id');
|
|
32
|
+
childrenFrom(OrderLineAdded, { childType: OrderLine, key: 'lineId', prepend: true })(OrderWithOrderedLines.prototype, 'lines');
|
|
33
|
+
|
|
34
|
+
const supported = contractsSupportChildrenOrdering();
|
|
35
|
+
|
|
36
|
+
describe('when registering a projection with ordered children', () => {
|
|
37
|
+
let register: ReturnType<typeof vi.fn>;
|
|
38
|
+
let registration: Promise<void>;
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
register = vi.fn().mockResolvedValue(undefined);
|
|
42
|
+
const connection = {
|
|
43
|
+
readModels: { registerMany: vi.fn().mockResolvedValue(undefined) },
|
|
44
|
+
projections: { register }
|
|
45
|
+
} as unknown as ChronicleConnection;
|
|
46
|
+
const artifacts: IClientArtifactsProvider = {
|
|
47
|
+
readModels: [OrderWithOrderedLines] as unknown as IClientArtifactsProvider['readModels'],
|
|
48
|
+
projections: [], eventTypes: [], globalForHandlers: [], reducers: [], reactors: [],
|
|
49
|
+
seeders: [], constraints: [], webhooks: [], eventTypeMigrations: []
|
|
50
|
+
};
|
|
51
|
+
registration = new Projections('store', 'namespace', connection, artifacts, 'sink').register();
|
|
52
|
+
registration.catch(() => undefined);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it.runIf(!supported)('should fail registration until the contracts carry the ordering', async () => {
|
|
56
|
+
const error = await registration.then(() => undefined, (reason: unknown) => reason);
|
|
57
|
+
(error as Error).should.be.instanceOf(ChildrenOrderingNotSupportedByContracts);
|
|
58
|
+
register.mock.calls.length.should.equal(0);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it.runIf(supported)('should send the ordering to the kernel', async () => {
|
|
62
|
+
await registration;
|
|
63
|
+
const request = register.mock.calls[0][0] as { Projections: Array<{ Children: Record<string, { Ordering?: { Placement: number } }> }> };
|
|
64
|
+
request.Projections[0].Children.lines.Ordering!.Placement.should.equal(1);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { readFileSync } from 'node:fs';
|
|
5
|
+
import { chai, describe, it } from 'vitest';
|
|
6
|
+
import { contractsSupportChildrenOrdering } from '../childrenOrderingSupport.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
|
|
10
|
+
// The contracts version this expectation was verified against. Bumping the contracts fails the first spec on purpose:
|
|
11
|
+
// re-check children ordering support for the new version, then update both the version and the expectation together.
|
|
12
|
+
const verifiedContractsVersion = '19.153.0';
|
|
13
|
+
const supportedInVerifiedVersion = true;
|
|
14
|
+
|
|
15
|
+
const pinnedContractsVersion = (JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')) as {
|
|
16
|
+
dependencies: Record<string, string>;
|
|
17
|
+
}).dependencies['@cratis/chronicle.contracts'];
|
|
18
|
+
|
|
19
|
+
describe('when detecting children ordering support in the pinned contracts', () => {
|
|
20
|
+
it('should be verified against the pinned contracts version', () => pinnedContractsVersion.should.equal(verifiedContractsVersion));
|
|
21
|
+
it('should match the verified support', () => contractsSupportChildrenOrdering().should.equal(supportedInVerifiedVersion));
|
|
22
|
+
});
|
package/projections/for_childrenOrderingSupport/when_ensuring_children_ordering_is_supported.spec.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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 { ProjectionDefinition } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { chai, describe, it } from 'vitest';
|
|
6
|
+
import { ChildrenOrderingNotSupportedByContracts } from '../ChildrenOrderingNotSupportedByContracts.js';
|
|
7
|
+
import { prependOrdering } from '../childrenOrdering.js';
|
|
8
|
+
import { ensureChildrenOrderingIsSupported } from '../childrenOrderingSupport.js';
|
|
9
|
+
|
|
10
|
+
chai.should();
|
|
11
|
+
|
|
12
|
+
const definitionWith = (children: Record<string, unknown>, nested: Record<string, unknown> = {}) =>
|
|
13
|
+
({ Identifier: 'orders', Children: children, Nested: nested }) as unknown as ProjectionDefinition;
|
|
14
|
+
|
|
15
|
+
describe('when the contracts cannot carry children ordering', () => {
|
|
16
|
+
it('should accept a projection without ordered children', () =>
|
|
17
|
+
(() => ensureChildrenOrderingIsSupported(definitionWith({ lines: { Children: {}, Nested: {} } }), false)).should.not.throw());
|
|
18
|
+
|
|
19
|
+
it('should reject ordered children with the projection and path', () =>
|
|
20
|
+
(() => ensureChildrenOrderingIsSupported(definitionWith({ lines: { Ordering: prependOrdering() } }), false))
|
|
21
|
+
.should.throw(ChildrenOrderingNotSupportedByContracts, "Projection 'orders' orders the children at 'Children.lines'"));
|
|
22
|
+
|
|
23
|
+
it('should reject ordered children inside a nested object', () =>
|
|
24
|
+
(() => ensureChildrenOrderingIsSupported(definitionWith({}, { summary: { Children: { lines: { Ordering: prependOrdering() } } } }), false))
|
|
25
|
+
.should.throw(ChildrenOrderingNotSupportedByContracts, "'Nested.summary.Children.lines'"));
|
|
26
|
+
|
|
27
|
+
it('should reject ordered grandchildren', () =>
|
|
28
|
+
(() => ensureChildrenOrderingIsSupported(definitionWith({ lines: { Children: { notes: { Ordering: prependOrdering() } } } }), false))
|
|
29
|
+
.should.throw(ChildrenOrderingNotSupportedByContracts, "'Children.lines.Children.notes'"));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when the contracts carry children ordering', () => {
|
|
33
|
+
it('should accept ordered children', () =>
|
|
34
|
+
(() => ensureChildrenOrderingIsSupported(definitionWith({ lines: { Ordering: prependOrdering() } }), true)).should.not.throw());
|
|
35
|
+
});
|
|
@@ -95,12 +95,13 @@ export class GraphDefinitionBuilder {
|
|
|
95
95
|
result.From[this.eventTypeOf(from.eventType)] = {
|
|
96
96
|
Key: from.key ?? eventSourceId,
|
|
97
97
|
Properties: this.properties(from.eventType, properties.filter(name => name !== node.keyProperty), from.properties),
|
|
98
|
-
UpdateOnly: from.updateOnly
|
|
98
|
+
UpdateOnly: from.updateOnly,
|
|
99
|
+
ForEach: ''
|
|
99
100
|
};
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
for (const removal of node.removedWith) {
|
|
103
|
-
result.RemovedWith[this.eventTypeOf(removal.eventType)] = { Key: removal.key ?? eventSourceId, Detach: removal.detach };
|
|
104
|
+
result.RemovedWith[this.eventTypeOf(removal.eventType)] = { Key: removal.key ?? eventSourceId, Detach: removal.detach, ForEach: '' };
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
return result;
|
|
@@ -114,7 +115,8 @@ export class GraphDefinitionBuilder {
|
|
|
114
115
|
SourceKey: from.sourceKey ?? eventSourceId,
|
|
115
116
|
TargetKey: from.targetKey ?? eventSourceId,
|
|
116
117
|
Identity: this.identity(edge, from.eventType, from.identity),
|
|
117
|
-
Properties: this.properties(from.eventType, properties.filter(name => name !== edge.identifyingProperty), from.properties)
|
|
118
|
+
Properties: this.properties(from.eventType, properties.filter(name => name !== edge.identifyingProperty), from.properties),
|
|
119
|
+
ForEach: ''
|
|
118
120
|
};
|
|
119
121
|
}
|
|
120
122
|
|
|
@@ -122,7 +124,8 @@ export class GraphDefinitionBuilder {
|
|
|
122
124
|
result.RemovedWith[this.eventTypeOf(removal.eventType)] = {
|
|
123
125
|
SourceKey: removal.sourceKey ?? eventSourceId,
|
|
124
126
|
TargetKey: removal.targetKey ?? eventSourceId,
|
|
125
|
-
Identity: this.identity(edge, removal.eventType, removal.identity)
|
|
127
|
+
Identity: this.identity(edge, removal.eventType, removal.identity),
|
|
128
|
+
ForEach: ''
|
|
126
129
|
};
|
|
127
130
|
}
|
|
128
131
|
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
4
|
import { constantValueExpression } from '../constantValueExpression.js';
|
|
5
|
-
import { eventContextPropertyExpression } from '../eventContextPropertyExpression.js';
|
|
6
5
|
import { getAddFromMetadata } from '../modelBound/addFrom.js';
|
|
7
6
|
import { getCountMetadata } from '../modelBound/count.js';
|
|
8
7
|
import { getDecrementMetadata } from '../modelBound/decrement.js';
|
|
9
8
|
import { getIncrementMetadata } from '../modelBound/increment.js';
|
|
10
|
-
import { getSetFromMetadata } from '../modelBound/setFrom.js';
|
|
11
|
-
import { getSetFromContextMetadata } from '../modelBound/setFromContext.js';
|
|
9
|
+
import { getSetFromMetadata, setFromExpression } from '../modelBound/setFrom.js';
|
|
10
|
+
import { getSetFromContextMetadata, setFromContextExpression } from '../modelBound/setFromContext.js';
|
|
12
11
|
import { getSetValueMetadata } from '../modelBound/setValue.js';
|
|
13
12
|
import { getSubtractFromMetadata } from '../modelBound/subtractFrom.js';
|
|
13
|
+
import { SetOnceNotSupportedInGraph } from './SetOnceNotSupportedInGraph.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Reads the property mappings the model-bound decorators on the members of a node or an edge declare per event type.
|
|
17
17
|
* @param prototype - The class prototype of the node or edge.
|
|
18
18
|
* @param properties - The names of the members to read.
|
|
19
19
|
* @returns For each event type, the property name to expression.
|
|
20
|
+
* @throws {SetOnceNotSupportedInGraph} When a member is mapped with setOnce - graph projections cannot honor it.
|
|
20
21
|
*/
|
|
21
22
|
export function readGraphMemberMappings(prototype: object, properties: Iterable<string>): Map<Function, Record<string, string>> {
|
|
22
23
|
const result = new Map<Function, Record<string, string>>();
|
|
@@ -28,10 +29,12 @@ export function readGraphMemberMappings(prototype: object, properties: Iterable<
|
|
|
28
29
|
|
|
29
30
|
for (const property of properties) {
|
|
30
31
|
for (const mapping of getSetFromMetadata(prototype, property)) {
|
|
31
|
-
|
|
32
|
+
if (mapping.setOnce === true) throw new SetOnceNotSupportedInGraph(prototype.constructor, property);
|
|
33
|
+
record(mapping.eventType, property, setFromExpression(mapping, property));
|
|
32
34
|
}
|
|
33
35
|
for (const mapping of getSetFromContextMetadata(prototype, property)) {
|
|
34
|
-
|
|
36
|
+
if (mapping.setOnce === true) throw new SetOnceNotSupportedInGraph(prototype.constructor, property);
|
|
37
|
+
record(mapping.eventType, property, setFromContextExpression(mapping, property));
|
|
35
38
|
}
|
|
36
39
|
for (const mapping of getSetValueMetadata(prototype, property)) {
|
|
37
40
|
record(mapping.eventType, property, constantValueExpression(mapping.value));
|
|
@@ -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 member of a node or an edge asks to only be set once. Graph projections do not read the current
|
|
6
|
+
* state of a node or an edge, so a set once mapping would silently overwrite the value.
|
|
7
|
+
*/
|
|
8
|
+
export class SetOnceNotSupportedInGraph extends Error {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new {@link SetOnceNotSupportedInGraph}.
|
|
11
|
+
* @param type - The node or edge type.
|
|
12
|
+
* @param property - The name of the property.
|
|
13
|
+
*/
|
|
14
|
+
constructor(type: Function, property: string) {
|
|
15
|
+
super(`The property '${property}' of '${type.name}' is mapped with setOnce. Set once is not supported on graph nodes and edges.`);
|
|
16
|
+
this.name = 'SetOnceNotSupportedInGraph';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -41,6 +41,7 @@ export { NodeMustHaveExactlyOneKey } from './NodeMustHaveExactlyOneKey.js';
|
|
|
41
41
|
export { EdgeMustHaveOneSourceAndOneTarget } from './EdgeMustHaveOneSourceAndOneTarget.js';
|
|
42
42
|
export { EdgeCanHaveOnlyOneIdentifyingKey } from './EdgeCanHaveOnlyOneIdentifyingKey.js';
|
|
43
43
|
export { NestedObjectInGraph } from './NestedObjectInGraph.js';
|
|
44
|
+
export { SetOnceNotSupportedInGraph } from './SetOnceNotSupportedInGraph.js';
|
|
44
45
|
export { UnknownGraphEventProperty } from './UnknownGraphEventProperty.js';
|
|
45
46
|
export { UnknownGraphNode } from './UnknownGraphNode.js';
|
|
46
47
|
export { GraphNameRequired } from './GraphNameRequired.js';
|
package/projections/index.ts
CHANGED
|
@@ -8,6 +8,11 @@ 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';
|
|
@@ -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
|
+
});
|