@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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import type { EventForEventSourceId } from '../../eventSequences/EventForEventSourceId.js';
|
|
6
|
+
import { a_kernel_import_session, contentsOf, gate, numbered } from './given/a_kernel_import_session.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
|
|
10
|
+
describe('when keeping chunks in flight', () => {
|
|
11
|
+
let kernel: a_kernel_import_session;
|
|
12
|
+
let readWhileHeld: number;
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
kernel = new a_kernel_import_session();
|
|
15
|
+
const held = gate();
|
|
16
|
+
kernel.answerChunk = async () => { await held.promise; return { Error: '' }; };
|
|
17
|
+
let read = 0;
|
|
18
|
+
async function* source(): AsyncGenerator<EventForEventSourceId> {
|
|
19
|
+
for (let index = 0; index < 40; index++) {
|
|
20
|
+
read++;
|
|
21
|
+
yield numbered(index);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const session = kernel.session({ maxChunkEvents: 2 });
|
|
25
|
+
const adding = session.add(source());
|
|
26
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
27
|
+
readWhileHeld = read;
|
|
28
|
+
held.open();
|
|
29
|
+
await adding;
|
|
30
|
+
await session.complete();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should have at most four chunks in flight', () => kernel.maxInFlight.should.equal(4));
|
|
34
|
+
it('should stop reading the source while the kernel holds the chunks', () => readWhileHeld.should.be.at.most(4 * 2 + 3));
|
|
35
|
+
it('should send every event once, in order', () => kernel.receivedContents.should.deep.equal(contentsOf(40)));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('when keeping chunks in flight with a configured bound', () => {
|
|
39
|
+
let kernel: a_kernel_import_session;
|
|
40
|
+
beforeEach(async () => {
|
|
41
|
+
kernel = new a_kernel_import_session();
|
|
42
|
+
kernel.answerChunk = async () => { await new Promise(resolve => setTimeout(resolve, 1)); return { Error: '' }; };
|
|
43
|
+
const session = kernel.session({ maxChunkEvents: 1, options: { maxChunksInFlight: 2 } });
|
|
44
|
+
await session.add(Array.from({ length: 12 }, (_, index) => numbered(index)));
|
|
45
|
+
await session.complete();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should have at most the configured number in flight', () => kernel.maxInFlight.should.equal(2));
|
|
49
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
5
|
+
import { beginEventImport } from '../beginEventImport.js';
|
|
6
|
+
import type { IEventImport } from '../IEventImport.js';
|
|
7
|
+
import { ImportCouldNotBegin } from '../ImportCouldNotBegin.js';
|
|
8
|
+
import { OnInvalidEvent } from '../OnInvalidEvent.js';
|
|
9
|
+
import { a_kernel_import_session, numberedEvents } from '../for_EventImport/given/a_kernel_import_session.js';
|
|
10
|
+
|
|
11
|
+
chai.should();
|
|
12
|
+
|
|
13
|
+
describe('when reattaching to an import the kernel holds chunks for', () => {
|
|
14
|
+
let kernel: a_kernel_import_session;
|
|
15
|
+
let session: IEventImport;
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
kernel = new a_kernel_import_session();
|
|
18
|
+
kernel.reads = [
|
|
19
|
+
{ EventSequenceId: 'event-log', OnInvalid: 1, MaxChunkEvents: 3, AcknowledgedChunks: 2, AcknowledgedEvents: 6n },
|
|
20
|
+
{ State: 4 }
|
|
21
|
+
];
|
|
22
|
+
session = await beginEventImport({ imports: kernel.client, eventStore: 'store', namespace: 'default', eventSequenceId: 'event-log' },
|
|
23
|
+
kernel.importId.toString());
|
|
24
|
+
await session.add(numberedEvents(10).slice(session.eventsAcknowledged));
|
|
25
|
+
await session.complete();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should keep the identifier of the import', () => session.importId.toString().should.equal(kernel.importId.toString()));
|
|
29
|
+
it('should say how many events the kernel already holds', () => session.eventsAcknowledged.should.equal(6));
|
|
30
|
+
it('should continue numbering chunks after the acknowledged ones', () =>
|
|
31
|
+
kernel.chunks.map(chunk => chunk.chunkIndex).sort().should.deep.equal([2, 3]));
|
|
32
|
+
it('should continue numbering events after the acknowledged ones', () =>
|
|
33
|
+
[...kernel.chunks].sort((left, right) => left.chunkIndex - right.chunkIndex).map(chunk => chunk.firstEventIndex)
|
|
34
|
+
.should.deep.equal([6n, 9n]));
|
|
35
|
+
it('should complete with every chunk and event of the import', () =>
|
|
36
|
+
kernel.completions.should.deep.equal([{ ExpectedChunks: 4, ExpectedEvents: 10n }]));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('when reattaching to an import into another event sequence', () => {
|
|
40
|
+
let error: unknown;
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
const kernel = new a_kernel_import_session();
|
|
43
|
+
kernel.reads = [{ EventSequenceId: 'outbox' }];
|
|
44
|
+
error = await beginEventImport({ imports: kernel.client, eventStore: 'store', namespace: 'default', eventSequenceId: 'event-log' },
|
|
45
|
+
kernel.importId).catch(caught => caught);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should refuse to reattach', () => error.should.be.instanceOf(ImportCouldNotBegin));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('when reattaching to an import that does not exist', () => {
|
|
52
|
+
let error: unknown;
|
|
53
|
+
beforeEach(async () => {
|
|
54
|
+
const kernel = new a_kernel_import_session();
|
|
55
|
+
kernel.imports.getImport = async () => ({ IsAuthorized: true, ValidationResults: [], ExceptionMessages: [], ExceptionStackTrace: '',
|
|
56
|
+
CorrelationId: undefined, Data: undefined as never });
|
|
57
|
+
error = await beginEventImport({ imports: kernel.client, eventStore: 'store', namespace: 'default', eventSequenceId: 'event-log' },
|
|
58
|
+
kernel.importId).catch(caught => caught);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should refuse to reattach', () => error.should.be.instanceOf(ImportCouldNotBegin));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('when beginning a new import', () => {
|
|
65
|
+
let request: Record<string, unknown>;
|
|
66
|
+
let session: IEventImport;
|
|
67
|
+
beforeEach(async () => {
|
|
68
|
+
const kernel = new a_kernel_import_session();
|
|
69
|
+
const imports = { ...kernel.imports, beginImport: async (given: Record<string, unknown>) => {
|
|
70
|
+
request = given;
|
|
71
|
+
return { IsAuthorized: true, ValidationResults: [], ExceptionMessages: [], ExceptionStackTrace: '', AuthorizationFailureReason: '',
|
|
72
|
+
CorrelationId: undefined, Response: { ImportId: given.ImportId, State: 0, MaxChunkEvents: 2, MaxChunkBytes: 0, Error: '' } };
|
|
73
|
+
} };
|
|
74
|
+
session = await beginEventImport({ imports: imports as never, eventStore: 'store', namespace: 'default', eventSequenceId: 'event-log' },
|
|
75
|
+
{ onInvalid: OnInvalidEvent.Skip, importId: kernel.importId });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should begin it for the event sequence', () => request.EventSequenceId!.should.equal('event-log'));
|
|
79
|
+
it('should pass what to do with invalid events', () => request.OnInvalid!.should.equal(1));
|
|
80
|
+
it('should use the identifier the kernel gives back', () => session.importId.toString().length.should.equal(36));
|
|
81
|
+
it('should start from the beginning', () => session.eventsAcknowledged.should.equal(0));
|
|
82
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { ClientError, Status } from 'nice-grpc-common';
|
|
5
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
6
|
+
import { beginEventImport } from '../beginEventImport.js';
|
|
7
|
+
import { ImportCouldNotBegin } from '../ImportCouldNotBegin.js';
|
|
8
|
+
import { ImportsNotSupported } from '../ImportsNotSupported.js';
|
|
9
|
+
import { a_kernel_import_session } from '../for_EventImport/given/a_kernel_import_session.js';
|
|
10
|
+
|
|
11
|
+
chai.should();
|
|
12
|
+
|
|
13
|
+
describe('when beginning an import on a kernel that does not serve imports', () => {
|
|
14
|
+
let error: unknown;
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
const kernel = new a_kernel_import_session();
|
|
17
|
+
const imports = { ...kernel.imports, beginImport: async () => { throw new ClientError('/Imports/BeginImport', Status.UNIMPLEMENTED, ''); } };
|
|
18
|
+
error = await beginEventImport({ imports: imports as never, eventStore: 'store', namespace: 'default', eventSequenceId: 'event-log' })
|
|
19
|
+
.catch(caught => caught);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should say imports are not supported', () => error.should.be.instanceOf(ImportsNotSupported));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('when the kernel refuses to begin an import', () => {
|
|
26
|
+
let error: unknown;
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
const kernel = new a_kernel_import_session();
|
|
29
|
+
const imports = { ...kernel.imports, beginImport: async () => ({ IsAuthorized: true, ValidationResults: [], ExceptionMessages: [],
|
|
30
|
+
ExceptionStackTrace: '', AuthorizationFailureReason: '', CorrelationId: undefined,
|
|
31
|
+
Response: { ImportId: undefined, State: 0, MaxChunkEvents: 0, MaxChunkBytes: 0, Error: 'Imports into the outbox are not supported' } }) };
|
|
32
|
+
error = await beginEventImport({ imports: imports as never, eventStore: 'store', namespace: 'default', eventSequenceId: 'outbox' })
|
|
33
|
+
.catch(caught => caught);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should say it could not begin', () => error.should.be.instanceOf(ImportCouldNotBegin));
|
|
37
|
+
it('should carry the reason', () => (error as ImportCouldNotBegin).reason.should.equal('Imports into the outbox are not supported'));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('when beginning an import with a signal that already aborted', () => {
|
|
41
|
+
let error: unknown;
|
|
42
|
+
let called: boolean;
|
|
43
|
+
beforeEach(async () => {
|
|
44
|
+
const kernel = new a_kernel_import_session();
|
|
45
|
+
called = false;
|
|
46
|
+
const imports = { ...kernel.imports, beginImport: async () => { called = true; throw new Error('should not be called'); } };
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
controller.abort(new Error('cancelled before it began'));
|
|
49
|
+
error = await beginEventImport({ imports: imports as never, eventStore: 'store', namespace: 'default', eventSequenceId: 'event-log' },
|
|
50
|
+
{ signal: controller.signal }).catch(caught => caught);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should not call the kernel', () => called.should.be.false);
|
|
54
|
+
it('should stop with the reason', () => (error as Error).message.should.equal('cancelled before it began'));
|
|
55
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
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 { ImportState as ContractsImportState } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { field } from '@cratis/fundamentals';
|
|
6
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
7
|
+
import { eventType } from '../../events/eventTypeDecorator.js';
|
|
8
|
+
import type { EventForEventSourceId } from '../../eventSequences/EventForEventSourceId.js';
|
|
9
|
+
import { importEvents } from '../importEvents.js';
|
|
10
|
+
import type { ImportProgress } from '../ImportProgress.js';
|
|
11
|
+
import type { ImportResult } from '../ImportResult.js';
|
|
12
|
+
import { ImportState } from '../ImportState.js';
|
|
13
|
+
import type { ImportTarget } from '../ImportTarget.js';
|
|
14
|
+
import { a_kernel_import_session } from '../for_EventImport/given/a_kernel_import_session.js';
|
|
15
|
+
|
|
16
|
+
chai.should();
|
|
17
|
+
|
|
18
|
+
@eventType('import-spec-item-counted')
|
|
19
|
+
class ItemCounted {
|
|
20
|
+
@field(Number) number: number;
|
|
21
|
+
constructor(number = 0) { this.number = number; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const numbered = (number: number): EventForEventSourceId => ({ eventSourceId: 'source', event: new ItemCounted(number) });
|
|
25
|
+
const range = (count: number) => Array.from({ length: count }, (_, index) => index);
|
|
26
|
+
const numbersReceivedBy = (kernel: a_kernel_import_session) => kernel.receivedContents.map(content => (JSON.parse(content) as ItemCounted).number);
|
|
27
|
+
|
|
28
|
+
function targetFor(kernel: a_kernel_import_session): ImportTarget {
|
|
29
|
+
return { imports: kernel.client, eventStore: 'store', namespace: 'default', eventSequenceId: 'event-log' };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('when importing events from an async iterable in one call', () => {
|
|
33
|
+
let kernel: a_kernel_import_session;
|
|
34
|
+
let result: ImportResult;
|
|
35
|
+
let progress: ImportProgress[];
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
kernel = new a_kernel_import_session();
|
|
38
|
+
kernel.limits = { MaxChunkEvents: 5, MaxChunkBytes: 0 };
|
|
39
|
+
kernel.observed = [
|
|
40
|
+
{ State: ContractsImportState.Staging, EventsReceived: 5n, EventsStaged: 5n },
|
|
41
|
+
{ State: ContractsImportState.Committing, EventsReceived: 12n, EventsStaged: 12n, EventsCommitted: 4n, RejectedCount: 0n }
|
|
42
|
+
];
|
|
43
|
+
kernel.reads = [{ State: ContractsImportState.Completed, EventsStaged: 12n, EventsCommitted: 12n, FirstSequenceNumber: 0n, LastSequenceNumber: 11n }];
|
|
44
|
+
progress = [];
|
|
45
|
+
async function* source(): AsyncGenerator<EventForEventSourceId> {
|
|
46
|
+
for (let index = 0; index < 12; index++) yield numbered(index);
|
|
47
|
+
}
|
|
48
|
+
result = await importEvents(targetFor(kernel), source(), { onProgress: report => progress.push(report) });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should send every event once, in order', () => numbersReceivedBy(kernel).should.deep.equal(range(12)));
|
|
52
|
+
it('should cut chunks within the kernel limit', () => kernel.chunks.length.should.equal(3));
|
|
53
|
+
it('should complete the import', () => kernel.completions.should.deep.equal([{ ExpectedChunks: 3, ExpectedEvents: 12n }]));
|
|
54
|
+
it('should report the result', () => result.isSuccess.should.be.true);
|
|
55
|
+
it('should report the committed range', () => result.lastSequenceNumber!.value.should.equal(11n));
|
|
56
|
+
it('should report progress as the kernel reports it', () => progress.map(report => report.state)
|
|
57
|
+
.should.deep.equal([ImportState.Staging, ImportState.Committing]));
|
|
58
|
+
it('should report the counts of the progress', () => progress[1].eventsCommitted.should.equal(4));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('when importing events from an iterable in one call', () => {
|
|
62
|
+
let kernel: a_kernel_import_session;
|
|
63
|
+
let result: ImportResult;
|
|
64
|
+
beforeEach(async () => {
|
|
65
|
+
kernel = new a_kernel_import_session();
|
|
66
|
+
function* source(): Generator<EventForEventSourceId> {
|
|
67
|
+
for (let index = 0; index < 3; index++) yield numbered(index);
|
|
68
|
+
}
|
|
69
|
+
result = await importEvents(targetFor(kernel), source());
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should send every event', () => numbersReceivedBy(kernel).should.deep.equal(range(3)));
|
|
73
|
+
it('should report the result', () => result.isSuccess.should.be.true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('when cancelling an import in one call with an abort signal', () => {
|
|
77
|
+
let kernel: a_kernel_import_session;
|
|
78
|
+
let error: unknown;
|
|
79
|
+
let reason: Error;
|
|
80
|
+
beforeEach(async () => {
|
|
81
|
+
kernel = new a_kernel_import_session();
|
|
82
|
+
kernel.limits = { MaxChunkEvents: 1, MaxChunkBytes: 0 };
|
|
83
|
+
const controller = new AbortController();
|
|
84
|
+
reason = new Error('cancelled by the caller');
|
|
85
|
+
async function* source(): AsyncGenerator<EventForEventSourceId> {
|
|
86
|
+
yield numbered(0);
|
|
87
|
+
yield numbered(1);
|
|
88
|
+
controller.abort(reason);
|
|
89
|
+
yield numbered(2);
|
|
90
|
+
yield numbered(3);
|
|
91
|
+
}
|
|
92
|
+
error = await importEvents(targetFor(kernel), source(), { signal: controller.signal }).catch(caught => caught);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should stop with the reason it was cancelled for', () => error!.should.equal(reason));
|
|
96
|
+
it('should not complete the import', () => kernel.completions.should.be.empty);
|
|
97
|
+
it('should stop reading the source', () => kernel.receivedContents.length.should.be.at.most(2));
|
|
98
|
+
it('should leave the import open on the kernel to be reattached', () => kernel.abandons.should.be.empty);
|
|
99
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { field, Guid } from '@cratis/fundamentals';
|
|
5
|
+
import type { ImportEvent } from '@cratis/chronicle.contracts';
|
|
6
|
+
import { beforeEach, chai, describe, it } from 'vitest';
|
|
7
|
+
import { fromContractsGuid } from '../../connection/Guid.js';
|
|
8
|
+
import { eventType } from '../../events/eventTypeDecorator.js';
|
|
9
|
+
import { NamedTag } from '../../events/NamedTag.js';
|
|
10
|
+
import { tag } from '../../events/tagDecorator.js';
|
|
11
|
+
import { Identity } from '../../identity/Identity.js';
|
|
12
|
+
import { toImportEvent } from '../toImportEvent.js';
|
|
13
|
+
|
|
14
|
+
chai.should();
|
|
15
|
+
|
|
16
|
+
@eventType('import-spec-customer-registered', 2)
|
|
17
|
+
@tag('migrated')
|
|
18
|
+
class CustomerRegistered {
|
|
19
|
+
@field(String) name: string;
|
|
20
|
+
constructor(name = '') { this.name = name; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('when converting an event that carries what its source said', () => {
|
|
24
|
+
const correlationId = Guid.create();
|
|
25
|
+
const occurred = new Date('2019-05-06T07:08:09.000Z');
|
|
26
|
+
let converted: ImportEvent;
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
converted = toImportEvent({
|
|
29
|
+
eventSourceId: 'customer-1',
|
|
30
|
+
event: new CustomerRegistered('Jane'),
|
|
31
|
+
eventStreamType: 'Onboarding',
|
|
32
|
+
eventStreamId: 'web',
|
|
33
|
+
eventSourceType: 'Customer',
|
|
34
|
+
occurred,
|
|
35
|
+
subject: 'person-1',
|
|
36
|
+
tags: ['legacy'],
|
|
37
|
+
namedTags: [new NamedTag('region', 'north')],
|
|
38
|
+
correlationId,
|
|
39
|
+
causedBy: new Identity('user-1', 'Jane Doe', 'jane', new Identity('system', 'Migrator')),
|
|
40
|
+
generation: 1,
|
|
41
|
+
sourceSequenceNumber: 41
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should keep the event source', () => converted.EventSourceId.should.equal('customer-1'));
|
|
46
|
+
it('should keep the route', () => [converted.EventSourceType, converted.EventStreamType, converted.EventStreamId]
|
|
47
|
+
.should.deep.equal(['Customer', 'Onboarding', 'web']));
|
|
48
|
+
it('should keep the event type', () => converted.EventType!.Id.should.equal('import-spec-customer-registered'));
|
|
49
|
+
it('should keep the generation the event was written in', () => converted.EventType!.Generation.should.equal(1));
|
|
50
|
+
it('should carry the content', () => JSON.parse(converted.Content).name.should.equal('Jane'));
|
|
51
|
+
it('should keep when it occurred', () => converted.Occurred!.Value.should.equal(occurred.toISOString()));
|
|
52
|
+
it('should keep the subject', () => converted.Subject.should.equal('person-1'));
|
|
53
|
+
it('should combine its tags with the tags of its type', () => converted.Tags.should.have.members(['migrated', 'legacy']));
|
|
54
|
+
it('should keep the named tags', () => converted.NamedTags.should.deep.equal([{ Name: 'region', Value: 'north' }]));
|
|
55
|
+
it('should keep the correlation', () => fromContractsGuid(converted.CorrelationId).toString().should.equal(correlationId.toString()));
|
|
56
|
+
it('should keep who caused it', () => converted.CausedBy!.Subject.should.equal('user-1'));
|
|
57
|
+
it('should keep who it was caused on behalf of', () => converted.CausedBy!.OnBehalfOf!.Subject.should.equal('system'));
|
|
58
|
+
it('should keep the sequence number it had in its source', () => converted.SourceSequenceNumber.should.equal(41n));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('when converting an event that says nothing about its source', () => {
|
|
62
|
+
let converted: ImportEvent;
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
converted = toImportEvent({ eventSourceId: 'customer-2', event: new CustomerRegistered('John') });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should use the generation its type is registered with', () => converted.EventType!.Generation.should.equal(2));
|
|
68
|
+
it('should leave the occurrence time to the kernel', () => (converted.Occurred === undefined).should.be.true);
|
|
69
|
+
it('should leave the correlation to the kernel', () => (converted.CorrelationId === undefined).should.be.true);
|
|
70
|
+
it('should leave who caused it to the kernel', () => (converted.CausedBy === undefined).should.be.true);
|
|
71
|
+
it('should carry no source sequence number', () => converted.SourceSequenceNumber.should.equal(0n));
|
|
72
|
+
it('should leave the route to the kernel', () => [converted.EventSourceType, converted.EventStreamType, converted.EventStreamId]
|
|
73
|
+
.should.deep.equal(['', '', '']));
|
|
74
|
+
});
|
|
@@ -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 type { EventForEventSourceId } from '../eventSequences/EventForEventSourceId.js';
|
|
5
|
+
import { beginEventImport } from './beginEventImport.js';
|
|
6
|
+
import type { IEventImport } from './IEventImport.js';
|
|
7
|
+
import type { ImportOptions } from './ImportOptions.js';
|
|
8
|
+
import type { ImportProgress } from './ImportProgress.js';
|
|
9
|
+
import type { ImportResult } from './ImportResult.js';
|
|
10
|
+
import type { ImportTarget } from './ImportTarget.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Imports events in one call: begins an import, adds the events as they are read, and completes it.
|
|
14
|
+
* @param target - The {@link ImportTarget}.
|
|
15
|
+
* @param events - The events, in the order they are to be committed. They are read lazily, as they are uploaded.
|
|
16
|
+
* @param options - The {@link ImportOptions}.
|
|
17
|
+
* @returns The {@link ImportResult}.
|
|
18
|
+
*/
|
|
19
|
+
export async function importEvents(
|
|
20
|
+
target: ImportTarget,
|
|
21
|
+
events: AsyncIterable<EventForEventSourceId> | Iterable<EventForEventSourceId>,
|
|
22
|
+
options?: ImportOptions
|
|
23
|
+
): Promise<ImportResult> {
|
|
24
|
+
const session = await beginEventImport(target, options);
|
|
25
|
+
const reporting = options?.onProgress ? report(session, options.onProgress) : undefined;
|
|
26
|
+
try {
|
|
27
|
+
await session.add(events, options?.signal);
|
|
28
|
+
return await session.complete(options?.signal);
|
|
29
|
+
} finally {
|
|
30
|
+
reporting?.abort();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function report(session: IEventImport, onProgress: (progress: ImportProgress) => void): AbortController {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
void (async () => {
|
|
37
|
+
try {
|
|
38
|
+
for await (const progress of session.progress(controller.signal)) onProgress(progress);
|
|
39
|
+
} catch {
|
|
40
|
+
// Progress is informational: a failed observation never fails the import.
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
return controller;
|
|
44
|
+
}
|
package/imports/index.ts
ADDED
|
@@ -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
|
+
export type { IEventImport } from './IEventImport.js';
|
|
5
|
+
export { ImportChunkRefused } from './ImportChunkRefused.js';
|
|
6
|
+
export { ImportCouldNotBegin } from './ImportCouldNotBegin.js';
|
|
7
|
+
export type { ImportOptions } from './ImportOptions.js';
|
|
8
|
+
export type { ImportProgress } from './ImportProgress.js';
|
|
9
|
+
export type { ImportRejection } from './ImportRejection.js';
|
|
10
|
+
export type { ImportResult } from './ImportResult.js';
|
|
11
|
+
export { ImportState } from './ImportState.js';
|
|
12
|
+
export { ImportWasAbandoned } from './ImportWasAbandoned.js';
|
|
13
|
+
export { ImportsNotSupported } from './ImportsNotSupported.js';
|
|
14
|
+
export { OnInvalidEvent } from './OnInvalidEvent.js';
|
|
@@ -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 { ClientError, Status } from 'nice-grpc-common';
|
|
5
|
+
|
|
6
|
+
const transientStatuses = new Set<Status>([Status.UNAVAILABLE, Status.DEADLINE_EXCEEDED, Status.RESOURCE_EXHAUSTED, Status.ABORTED, Status.INTERNAL]);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Determines whether a failed call is worth sending again: the connection failed rather than the kernel refusing it.
|
|
10
|
+
* @param error - What the call failed with.
|
|
11
|
+
* @returns True when the call can be sent again.
|
|
12
|
+
*/
|
|
13
|
+
export function isTransientImportFailure(error: unknown): boolean {
|
|
14
|
+
return error instanceof ClientError && transientStatuses.has(error.code);
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { ImportEvent } from '@cratis/chronicle.contracts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Measures an event as the kernel counts it against its chunk byte limit: the content, tags, named tags, causation
|
|
8
|
+
* and idempotency key, as UTF-8.
|
|
9
|
+
* @param event - The {@link ImportEvent} in its wire form.
|
|
10
|
+
* @returns The bytes it carries.
|
|
11
|
+
*/
|
|
12
|
+
export function sizeOfImportEvent(event: ImportEvent): number {
|
|
13
|
+
let bytes = utf8(event.Content) + utf8(event.IdempotencyKey);
|
|
14
|
+
for (const tag of event.Tags) bytes += utf8(tag);
|
|
15
|
+
for (const tag of event.NamedTags) bytes += utf8(tag.Name) + utf8(tag.Value);
|
|
16
|
+
for (const causation of event.Causation) {
|
|
17
|
+
bytes += utf8(causation.Type);
|
|
18
|
+
for (const [name, value] of Object.entries(causation.Properties)) bytes += utf8(name) + utf8(value);
|
|
19
|
+
}
|
|
20
|
+
return bytes;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function utf8(value: string | undefined): number {
|
|
24
|
+
return value ? Buffer.byteLength(value, 'utf8') : 0;
|
|
25
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { Guid, JsonSerializer } from '@cratis/fundamentals';
|
|
5
|
+
import type { Identity as ContractsIdentity, ImportEvent } from '@cratis/chronicle.contracts';
|
|
6
|
+
import { resolveEventSubject } from '../compliance/resolveEventSubject.js';
|
|
7
|
+
import { toContractsGuid } from '../connection/Guid.js';
|
|
8
|
+
import { getEventTypeFor } from '../events/eventTypeDecorator.js';
|
|
9
|
+
import { mergeNamedTags } from '../events/mergeNamedTags.js';
|
|
10
|
+
import { mergeTags } from '../events/mergeTags.js';
|
|
11
|
+
import { getTagsFor } from '../events/tagDecorator.js';
|
|
12
|
+
import type { IEventSources } from '../eventSources/IEventSources.js';
|
|
13
|
+
import type { EventForEventSourceId } from '../eventSequences/EventForEventSourceId.js';
|
|
14
|
+
import { resolveBatchRouting } from '../eventSequences/resolveEventSourceRouting.js';
|
|
15
|
+
import type { Identity } from '../identity/Identity.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converts an event to the form an import sends it in, keeping everything the event says about its source.
|
|
19
|
+
* @param event - The {@link EventForEventSourceId}.
|
|
20
|
+
* @param eventSources - The registered event sources, for events routed through a definition.
|
|
21
|
+
* @returns The {@link ImportEvent}.
|
|
22
|
+
* @remarks
|
|
23
|
+
* What the event does not say is left for the kernel to resolve: an omitted occurrence time, subject, route or
|
|
24
|
+
* correlation is not filled in from the importing process.
|
|
25
|
+
*/
|
|
26
|
+
export function toImportEvent(event: EventForEventSourceId, eventSources?: IEventSources): ImportEvent {
|
|
27
|
+
const routing = resolveBatchRouting(eventSources, event);
|
|
28
|
+
const eventType = getEventTypeFor(event.event.constructor as Function);
|
|
29
|
+
return {
|
|
30
|
+
EventSourceId: event.eventSourceId,
|
|
31
|
+
EventSourceType: routing?.sourceType ?? event.eventSourceType ?? '',
|
|
32
|
+
EventStreamType: routing?.streamType ?? event.eventStreamType ?? '',
|
|
33
|
+
EventStreamId: event.eventStreamId ?? '',
|
|
34
|
+
EventType: {
|
|
35
|
+
Id: eventType.id.value,
|
|
36
|
+
Generation: event.generation ?? eventType.generation.value,
|
|
37
|
+
Tombstone: eventType.tombstone
|
|
38
|
+
},
|
|
39
|
+
Content: JsonSerializer.serialize(event.event),
|
|
40
|
+
Tags: mergeTags(getTagsFor(event.event.constructor as Function), event.tags),
|
|
41
|
+
NamedTags: mergeNamedTags(event.namedTags).map(tag => ({ Name: tag.name, Value: tag.value })),
|
|
42
|
+
Occurred: event.occurred === undefined ? undefined : { Value: event.occurred.toISOString() },
|
|
43
|
+
Subject: event.subject ?? resolveEventSubject(event.event) ?? '',
|
|
44
|
+
CorrelationId: event.correlationId === undefined ? undefined : toContractsGuid(Guid.as(event.correlationId)),
|
|
45
|
+
Causation: [],
|
|
46
|
+
CausedBy: event.causedBy === undefined ? undefined : toContractsIdentity(event.causedBy),
|
|
47
|
+
IdempotencyKey: '',
|
|
48
|
+
EventSource: routing?.eventSource ?? '',
|
|
49
|
+
SourceSequenceNumber: event.sourceSequenceNumber === undefined ? 0n : BigInt(event.sourceSequenceNumber)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function toContractsIdentity(identity: Identity): ContractsIdentity {
|
|
54
|
+
return {
|
|
55
|
+
Subject: identity.subject,
|
|
56
|
+
Name: identity.name,
|
|
57
|
+
UserName: identity.userName,
|
|
58
|
+
OnBehalfOf: identity.onBehalfOf === undefined ? undefined : toContractsIdentity(identity.onBehalfOf)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { ImportProgressResponse } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { fromContractsGuid } from '../connection/Guid.js';
|
|
6
|
+
import type { ImportProgress } from './ImportProgress.js';
|
|
7
|
+
import type { ImportState } from './ImportState.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Converts the progress the kernel reports to {@link ImportProgress}.
|
|
11
|
+
* @param progress - The {@link ImportProgressResponse}.
|
|
12
|
+
* @returns The {@link ImportProgress}.
|
|
13
|
+
*/
|
|
14
|
+
export function toImportProgress(progress: ImportProgressResponse): ImportProgress {
|
|
15
|
+
return {
|
|
16
|
+
importId: fromContractsGuid(progress.ImportId),
|
|
17
|
+
state: progress.State as number as ImportState,
|
|
18
|
+
eventsReceived: Number(progress.EventsReceived),
|
|
19
|
+
eventsStaged: Number(progress.EventsStaged),
|
|
20
|
+
eventsCommitted: Number(progress.EventsCommitted),
|
|
21
|
+
alreadyAppended: Number(progress.AlreadyAppended),
|
|
22
|
+
eventsRejected: Number(progress.RejectedCount)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { ImportProgressResponse } from '@cratis/chronicle.contracts';
|
|
5
|
+
import { fromContractsGuid } from '../connection/Guid.js';
|
|
6
|
+
import { EventSequenceNumber } from '../eventSequences/EventSequenceNumber.js';
|
|
7
|
+
import type { ImportResult } from './ImportResult.js';
|
|
8
|
+
import { ImportState } from './ImportState.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Converts the progress the kernel reports to the {@link ImportResult} it amounts to.
|
|
12
|
+
* @param progress - The {@link ImportProgressResponse}.
|
|
13
|
+
* @returns The {@link ImportResult}.
|
|
14
|
+
*/
|
|
15
|
+
export function toImportResult(progress: ImportProgressResponse): ImportResult {
|
|
16
|
+
const state = progress.State as number as ImportState;
|
|
17
|
+
// Sequence numbers are only meaningful once the import committed something.
|
|
18
|
+
const committed = progress.EventsCommitted > 0n;
|
|
19
|
+
return {
|
|
20
|
+
importId: fromContractsGuid(progress.ImportId),
|
|
21
|
+
state,
|
|
22
|
+
eventsStaged: Number(progress.EventsStaged),
|
|
23
|
+
eventsCommitted: Number(progress.EventsCommitted),
|
|
24
|
+
alreadyAppended: Number(progress.AlreadyAppended),
|
|
25
|
+
firstSequenceNumber: committed ? new EventSequenceNumber(progress.FirstSequenceNumber) : undefined,
|
|
26
|
+
lastSequenceNumber: committed ? new EventSequenceNumber(progress.LastSequenceNumber) : undefined,
|
|
27
|
+
rejectedCount: Number(progress.RejectedCount),
|
|
28
|
+
rejections: (progress.Rejections ?? []).map(rejection => ({
|
|
29
|
+
index: Number(rejection.Index),
|
|
30
|
+
eventType: rejection.EventType,
|
|
31
|
+
reasons: [...rejection.Reasons]
|
|
32
|
+
})),
|
|
33
|
+
failureReason: progress.FailureReason ? progress.FailureReason : undefined,
|
|
34
|
+
isSuccess: state === ImportState.Completed
|
|
35
|
+
};
|
|
36
|
+
}
|
package/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ import * as transactions from './transactions/index.js';
|
|
|
26
26
|
import * as eventStoreSubscriptions from './eventStoreSubscriptions/index.js';
|
|
27
27
|
import * as compliance from './compliance/index.js';
|
|
28
28
|
import * as confidentiality from './confidentiality/index.js';
|
|
29
|
+
import * as imports from './imports/index.js';
|
|
29
30
|
|
|
30
31
|
export { ChronicleClient } from './ChronicleClient.js';
|
|
31
32
|
export { IncompatibleChronicleServer } from './connection/IncompatibleChronicleServer.js';
|
|
@@ -73,6 +74,7 @@ export * from './transactions/index.js';
|
|
|
73
74
|
export * from './eventStoreSubscriptions/index.js';
|
|
74
75
|
export * from './compliance/index.js';
|
|
75
76
|
export * from './confidentiality/index.js';
|
|
77
|
+
export * from './imports/index.js';
|
|
76
78
|
|
|
77
79
|
export {
|
|
78
80
|
events,
|
|
@@ -100,4 +102,5 @@ export {
|
|
|
100
102
|
eventStoreSubscriptions,
|
|
101
103
|
compliance,
|
|
102
104
|
confidentiality,
|
|
105
|
+
imports,
|
|
103
106
|
};
|
package/observation/index.ts
CHANGED
|
@@ -25,6 +25,8 @@ export { observes } from './batches/observes.js';
|
|
|
25
25
|
export { batchSize } from './batches/batchSize.js';
|
|
26
26
|
export type { BatchSizeOptions } from './batches/batchSize.js';
|
|
27
27
|
export { EventBatch } from './batches/EventBatch.js';
|
|
28
|
+
export type { BatchOutcome } from './batches/BatchOutcome.js';
|
|
29
|
+
export { BatchOutcomeKind } from './batches/BatchOutcomeKind.js';
|
|
28
30
|
export { EventAndContext } from './batches/EventAndContext.js';
|
|
29
31
|
export { BatchContext } from './batches/BatchContext.js';
|
|
30
32
|
export { ObservationOrigin } from './batches/ObservationOrigin.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cratis/chronicle",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.62.0",
|
|
4
4
|
"description": "Event sourcing for TypeScript and Node.js — the idiomatic client for Cratis Chronicle, the open-source event-sourcing database",
|
|
5
5
|
"author": "Cratis",
|
|
6
6
|
"license": "MIT",
|
|
@@ -165,6 +165,11 @@
|
|
|
165
165
|
"types": "./dist/transactions/index.d.ts",
|
|
166
166
|
"import": "./dist/transactions/index.js",
|
|
167
167
|
"default": "./dist/transactions/index.js"
|
|
168
|
+
},
|
|
169
|
+
"./imports": {
|
|
170
|
+
"types": "./dist/imports/index.d.ts",
|
|
171
|
+
"import": "./dist/imports/index.js",
|
|
172
|
+
"default": "./dist/imports/index.js"
|
|
168
173
|
}
|
|
169
174
|
},
|
|
170
175
|
"scripts": {
|
|
@@ -178,7 +183,7 @@
|
|
|
178
183
|
},
|
|
179
184
|
"dependencies": {
|
|
180
185
|
"@bufbuild/protobuf": "^2.16.0",
|
|
181
|
-
"@cratis/chronicle.contracts": "19.
|
|
186
|
+
"@cratis/chronicle.contracts": "19.153.0",
|
|
182
187
|
"@grpc/grpc-js": "^1.14.5",
|
|
183
188
|
"@opentelemetry/api": "^1.9.1",
|
|
184
189
|
"glob": "^13.0.6",
|