@cratis/chronicle 6.62.0 → 6.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChronicleClient.ts +86 -3
- package/artifacts/DefaultClientArtifactsProvider.ts +5 -0
- package/artifacts/IClientArtifactsProvider.ts +3 -0
- package/connection/ConnectionLifecycle.ts +42 -1
- package/dist/ChronicleClient.d.ts +28 -1
- package/dist/ChronicleClient.d.ts.map +1 -1
- package/dist/ChronicleClient.js +71 -3
- package/dist/ChronicleClient.js.map +1 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.d.ts +2 -0
- package/dist/artifacts/DefaultClientArtifactsProvider.d.ts.map +1 -1
- package/dist/artifacts/DefaultClientArtifactsProvider.js +4 -0
- package/dist/artifacts/DefaultClientArtifactsProvider.js.map +1 -1
- package/dist/artifacts/IClientArtifactsProvider.d.ts +2 -0
- package/dist/artifacts/IClientArtifactsProvider.d.ts.map +1 -1
- package/dist/connection/ConnectionLifecycle.d.ts +24 -0
- package/dist/connection/ConnectionLifecycle.d.ts.map +1 -1
- package/dist/connection/ConnectionLifecycle.js +40 -1
- package/dist/connection/ConnectionLifecycle.js.map +1 -1
- package/dist/observation/ObservationReconnectBackoff.d.ts +64 -0
- package/dist/observation/ObservationReconnectBackoff.d.ts.map +1 -0
- package/dist/observation/ObservationReconnectBackoff.js +75 -0
- package/dist/observation/ObservationReconnectBackoff.js.map +1 -0
- package/dist/observation/ObservationStreamOutcome.d.ts +10 -0
- package/dist/observation/ObservationStreamOutcome.d.ts.map +1 -0
- package/dist/observation/ObservationStreamOutcome.js +4 -0
- package/dist/observation/ObservationStreamOutcome.js.map +1 -0
- package/dist/observation/classifyStreamError.d.ts +25 -0
- package/dist/observation/classifyStreamError.d.ts.map +1 -0
- package/dist/observation/classifyStreamError.js +55 -0
- package/dist/observation/classifyStreamError.js.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.d.ts +13 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.d.ts.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.js +25 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_backoff.js.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.d.ts +27 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.d.ts.map +1 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.js +36 -0
- package/dist/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.js.map +1 -0
- package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts +2 -1
- package/dist/projections/for_Graphs/given/a_discovered_graph.d.ts.map +1 -1
- package/dist/projections/for_Graphs/given/a_discovered_graph.js +3 -2
- package/dist/projections/for_Graphs/given/a_discovered_graph.js.map +1 -1
- package/dist/projections/for_Graphs/given/a_graph_with_views.d.ts +40 -0
- package/dist/projections/for_Graphs/given/a_graph_with_views.d.ts.map +1 -0
- package/dist/projections/for_Graphs/given/a_graph_with_views.js +80 -0
- package/dist/projections/for_Graphs/given/a_graph_with_views.js.map +1 -0
- package/dist/projections/for_Graphs/given/organization.d.ts +2 -1
- package/dist/projections/for_Graphs/given/organization.d.ts.map +1 -1
- package/dist/projections/for_Graphs/given/organization.js +3 -2
- package/dist/projections/for_Graphs/given/organization.js.map +1 -1
- package/dist/projections/graphs/Graphs.d.ts +5 -0
- package/dist/projections/graphs/Graphs.d.ts.map +1 -1
- package/dist/projections/graphs/Graphs.js +43 -0
- package/dist/projections/graphs/Graphs.js.map +1 -1
- package/dist/projections/graphs/IGraphs.d.ts +9 -2
- package/dist/projections/graphs/IGraphs.d.ts.map +1 -1
- 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/graphs/views/AmbiguousDirection.d.ts +16 -0
- package/dist/projections/graphs/views/AmbiguousDirection.d.ts.map +1 -0
- package/dist/projections/graphs/views/AmbiguousDirection.js +21 -0
- package/dist/projections/graphs/views/AmbiguousDirection.js.map +1 -0
- package/dist/projections/graphs/views/DuplicateViewName.d.ts +16 -0
- package/dist/projections/graphs/views/DuplicateViewName.d.ts.map +1 -0
- package/dist/projections/graphs/views/DuplicateViewName.js +21 -0
- package/dist/projections/graphs/views/DuplicateViewName.js.map +1 -0
- package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.d.ts +17 -0
- package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.d.ts.map +1 -0
- package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.js +22 -0
- package/dist/projections/graphs/views/EdgeNotIncidentOnRoot.js.map +1 -0
- package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.d.ts +14 -0
- package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.d.ts.map +1 -0
- package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.js +19 -0
- package/dist/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.js.map +1 -0
- package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.d.ts +15 -0
- package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.d.ts.map +1 -0
- package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.js +20 -0
- package/dist/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.js.map +1 -0
- package/dist/projections/graphs/views/FollowsOptions.d.ts +16 -0
- package/dist/projections/graphs/views/FollowsOptions.d.ts.map +1 -0
- package/dist/projections/graphs/views/FollowsOptions.js +4 -0
- package/dist/projections/graphs/views/FollowsOptions.js.map +1 -0
- package/dist/projections/graphs/views/GraphEdgeDirection.d.ts +10 -0
- package/dist/projections/graphs/views/GraphEdgeDirection.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphEdgeDirection.js +13 -0
- package/dist/projections/graphs/views/GraphEdgeDirection.js.map +1 -0
- package/dist/projections/graphs/views/GraphView.d.ts +13 -0
- package/dist/projections/graphs/views/GraphView.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphView.js +4 -0
- package/dist/projections/graphs/views/GraphView.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewBuildResult.d.ts +15 -0
- package/dist/projections/graphs/views/GraphViewBuildResult.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewBuildResult.js +4 -0
- package/dist/projections/graphs/views/GraphViewBuildResult.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewCardinality.d.ts +10 -0
- package/dist/projections/graphs/views/GraphViewCardinality.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewCardinality.js +13 -0
- package/dist/projections/graphs/views/GraphViewCardinality.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewDefinition.d.ts +15 -0
- package/dist/projections/graphs/views/GraphViewDefinition.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewDefinition.js +4 -0
- package/dist/projections/graphs/views/GraphViewDefinition.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewDefinitionBuilder.d.ts +30 -0
- package/dist/projections/graphs/views/GraphViewDefinitionBuilder.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewDefinitionBuilder.js +259 -0
- package/dist/projections/graphs/views/GraphViewDefinitionBuilder.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewDefinitionSerializer.d.ts +21 -0
- package/dist/projections/graphs/views/GraphViewDefinitionSerializer.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewDefinitionSerializer.js +77 -0
- package/dist/projections/graphs/views/GraphViewDefinitionSerializer.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewEdgeReference.d.ts +6 -0
- package/dist/projections/graphs/views/GraphViewEdgeReference.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewEdgeReference.js +4 -0
- package/dist/projections/graphs/views/GraphViewEdgeReference.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewMember.d.ts +8 -0
- package/dist/projections/graphs/views/GraphViewMember.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewMember.js +4 -0
- package/dist/projections/graphs/views/GraphViewMember.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewMemberKind.d.ts +12 -0
- package/dist/projections/graphs/views/GraphViewMemberKind.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewMemberKind.js +15 -0
- package/dist/projections/graphs/views/GraphViewMemberKind.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewMemberMetadata.d.ts +22 -0
- package/dist/projections/graphs/views/GraphViewMemberMetadata.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewMemberMetadata.js +4 -0
- package/dist/projections/graphs/views/GraphViewMemberMetadata.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewPropertyMember.d.ts +13 -0
- package/dist/projections/graphs/views/GraphViewPropertyMember.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewPropertyMember.js +4 -0
- package/dist/projections/graphs/views/GraphViewPropertyMember.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewReason.d.ts +33 -0
- package/dist/projections/graphs/views/GraphViewReason.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewReason.js +36 -0
- package/dist/projections/graphs/views/GraphViewReason.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewRelationMember.d.ts +21 -0
- package/dist/projections/graphs/views/GraphViewRelationMember.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewRelationMember.js +4 -0
- package/dist/projections/graphs/views/GraphViewRelationMember.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewSchema.d.ts +10 -0
- package/dist/projections/graphs/views/GraphViewSchema.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewSchema.js +4 -0
- package/dist/projections/graphs/views/GraphViewSchema.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewSchemaEdge.d.ts +14 -0
- package/dist/projections/graphs/views/GraphViewSchemaEdge.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewSchemaEdge.js +4 -0
- package/dist/projections/graphs/views/GraphViewSchemaEdge.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewSchemaNode.d.ts +10 -0
- package/dist/projections/graphs/views/GraphViewSchemaNode.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewSchemaNode.js +4 -0
- package/dist/projections/graphs/views/GraphViewSchemaNode.js.map +1 -0
- package/dist/projections/graphs/views/GraphViewSerializerOptions.d.ts +9 -0
- package/dist/projections/graphs/views/GraphViewSerializerOptions.d.ts.map +1 -0
- package/dist/projections/graphs/views/GraphViewSerializerOptions.js +4 -0
- package/dist/projections/graphs/views/GraphViewSerializerOptions.js.map +1 -0
- package/dist/projections/graphs/views/RecursiveView.d.ts +15 -0
- package/dist/projections/graphs/views/RecursiveView.d.ts.map +1 -0
- package/dist/projections/graphs/views/RecursiveView.js +20 -0
- package/dist/projections/graphs/views/RecursiveView.js.map +1 -0
- package/dist/projections/graphs/views/RelationTargetNotAView.d.ts +16 -0
- package/dist/projections/graphs/views/RelationTargetNotAView.d.ts.map +1 -0
- package/dist/projections/graphs/views/RelationTargetNotAView.js +21 -0
- package/dist/projections/graphs/views/RelationTargetNotAView.js.map +1 -0
- package/dist/projections/graphs/views/TargetLabelMismatch.d.ts +18 -0
- package/dist/projections/graphs/views/TargetLabelMismatch.d.ts.map +1 -0
- package/dist/projections/graphs/views/TargetLabelMismatch.js +23 -0
- package/dist/projections/graphs/views/TargetLabelMismatch.js.map +1 -0
- package/dist/projections/graphs/views/UnknownEdge.d.ts +16 -0
- package/dist/projections/graphs/views/UnknownEdge.d.ts.map +1 -0
- package/dist/projections/graphs/views/UnknownEdge.js +21 -0
- package/dist/projections/graphs/views/UnknownEdge.js.map +1 -0
- package/dist/projections/graphs/views/UnknownEdgeProperty.d.ts +17 -0
- package/dist/projections/graphs/views/UnknownEdgeProperty.d.ts.map +1 -0
- package/dist/projections/graphs/views/UnknownEdgeProperty.js +22 -0
- package/dist/projections/graphs/views/UnknownEdgeProperty.js.map +1 -0
- package/dist/projections/graphs/views/UnknownNodeProperty.d.ts +17 -0
- package/dist/projections/graphs/views/UnknownNodeProperty.d.ts.map +1 -0
- package/dist/projections/graphs/views/UnknownNodeProperty.js +22 -0
- package/dist/projections/graphs/views/UnknownNodeProperty.js.map +1 -0
- package/dist/projections/graphs/views/ViewIsAlsoSchema.d.ts +14 -0
- package/dist/projections/graphs/views/ViewIsAlsoSchema.d.ts.map +1 -0
- package/dist/projections/graphs/views/ViewIsAlsoSchema.js +19 -0
- package/dist/projections/graphs/views/ViewIsAlsoSchema.js.map +1 -0
- package/dist/projections/graphs/views/ViewOfMetadata.d.ts +8 -0
- package/dist/projections/graphs/views/ViewOfMetadata.d.ts.map +1 -0
- package/dist/projections/graphs/views/ViewOfMetadata.js +4 -0
- package/dist/projections/graphs/views/ViewOfMetadata.js.map +1 -0
- package/dist/projections/graphs/views/ViewOfOptions.d.ts +6 -0
- package/dist/projections/graphs/views/ViewOfOptions.d.ts.map +1 -0
- package/dist/projections/graphs/views/ViewOfOptions.js +4 -0
- package/dist/projections/graphs/views/ViewOfOptions.js.map +1 -0
- package/dist/projections/graphs/views/ViewRootNotANode.d.ts +16 -0
- package/dist/projections/graphs/views/ViewRootNotANode.d.ts.map +1 -0
- package/dist/projections/graphs/views/ViewRootNotANode.js +21 -0
- package/dist/projections/graphs/views/ViewRootNotANode.js.map +1 -0
- package/dist/projections/graphs/views/declareGraphViewMember.d.ts +17 -0
- package/dist/projections/graphs/views/declareGraphViewMember.d.ts.map +1 -0
- package/dist/projections/graphs/views/declareGraphViewMember.js +31 -0
- package/dist/projections/graphs/views/declareGraphViewMember.js.map +1 -0
- package/dist/projections/graphs/views/follows.d.ts +13 -0
- package/dist/projections/graphs/views/follows.d.ts.map +1 -0
- package/dist/projections/graphs/views/follows.js +24 -0
- package/dist/projections/graphs/views/follows.js.map +1 -0
- package/dist/projections/graphs/views/fromEdge.d.ts +10 -0
- package/dist/projections/graphs/views/fromEdge.d.ts.map +1 -0
- package/dist/projections/graphs/views/fromEdge.js +15 -0
- package/dist/projections/graphs/views/fromEdge.js.map +1 -0
- package/dist/projections/graphs/views/index.d.ts +41 -0
- package/dist/projections/graphs/views/index.d.ts.map +1 -0
- package/dist/projections/graphs/views/index.js +28 -0
- package/dist/projections/graphs/views/index.js.map +1 -0
- package/dist/projections/graphs/views/viewKey.d.ts +8 -0
- package/dist/projections/graphs/views/viewKey.d.ts.map +1 -0
- package/dist/projections/graphs/views/viewKey.js +13 -0
- package/dist/projections/graphs/views/viewKey.js.map +1 -0
- package/dist/projections/graphs/views/viewOf.d.ts +22 -0
- package/dist/projections/graphs/views/viewOf.d.ts.map +1 -0
- package/dist/projections/graphs/views/viewOf.js +41 -0
- package/dist/projections/graphs/views/viewOf.js.map +1 -0
- package/dist/projections/graphs/views/viewProperty.d.ts +9 -0
- package/dist/projections/graphs/views/viewProperty.d.ts.map +1 -0
- package/dist/projections/graphs/views/viewProperty.js +14 -0
- package/dist/projections/graphs/views/viewProperty.js.map +1 -0
- package/dist/reactors/Reactors.d.ts +15 -5
- package/dist/reactors/Reactors.d.ts.map +1 -1
- package/dist/reactors/Reactors.js +95 -18
- package/dist/reactors/Reactors.js.map +1 -1
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.d.ts +26 -0
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.d.ts.map +1 -0
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.js +64 -0
- package/dist/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.js.map +1 -0
- package/dist/reducers/Reducers.d.ts +11 -5
- package/dist/reducers/Reducers.d.ts.map +1 -1
- package/dist/reducers/Reducers.js +93 -19
- package/dist/reducers/Reducers.js.map +1 -1
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.d.ts +25 -0
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.d.ts.map +1 -0
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.js +70 -0
- package/dist/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.js.map +1 -0
- package/dist/testing/InProcessAppendMetadata.d.ts +30 -0
- package/dist/testing/InProcessAppendMetadata.d.ts.map +1 -0
- package/dist/testing/InProcessAppendMetadata.js +107 -0
- package/dist/testing/InProcessAppendMetadata.js.map +1 -0
- package/dist/testing/InProcessBatchAppend.d.ts +62 -0
- package/dist/testing/InProcessBatchAppend.d.ts.map +1 -0
- package/dist/testing/InProcessBatchAppend.js +131 -0
- package/dist/testing/InProcessBatchAppend.js.map +1 -0
- package/dist/testing/InProcessEventPayload.d.ts +23 -0
- package/dist/testing/InProcessEventPayload.d.ts.map +1 -0
- package/dist/testing/InProcessEventPayload.js +94 -0
- package/dist/testing/InProcessEventPayload.js.map +1 -0
- package/dist/testing/InProcessEventReadCriteria.d.ts +9 -0
- package/dist/testing/InProcessEventReadCriteria.d.ts.map +1 -0
- package/dist/testing/InProcessEventReadCriteria.js +4 -0
- package/dist/testing/InProcessEventReadCriteria.js.map +1 -0
- package/dist/testing/InProcessEventReadFilter.d.ts +14 -0
- package/dist/testing/InProcessEventReadFilter.d.ts.map +1 -0
- package/dist/testing/InProcessEventReadFilter.js +31 -0
- package/dist/testing/InProcessEventReadFilter.js.map +1 -0
- package/dist/testing/InProcessEventSequence.d.ts +8 -5
- package/dist/testing/InProcessEventSequence.d.ts.map +1 -1
- package/dist/testing/InProcessEventSequence.js +59 -275
- package/dist/testing/InProcessEventSequence.js.map +1 -1
- package/dist/testing/InProcessEventSequenceEnvironment.d.ts +13 -0
- package/dist/testing/InProcessEventSequenceEnvironment.d.ts.map +1 -0
- package/dist/testing/InProcessEventSequenceEnvironment.js +4 -0
- package/dist/testing/InProcessEventSequenceEnvironment.js.map +1 -0
- package/dist/testing/InProcessSingleAppend.d.ts +34 -0
- package/dist/testing/InProcessSingleAppend.d.ts.map +1 -0
- package/dist/testing/InProcessSingleAppend.js +95 -0
- package/dist/testing/InProcessSingleAppend.js.map +1 -0
- package/dist/testing/projections/ProjectionCapabilities.d.ts +0 -8
- package/dist/testing/projections/ProjectionCapabilities.d.ts.map +1 -1
- package/dist/testing/projections/ProjectionCapabilities.js +21 -312
- package/dist/testing/projections/ProjectionCapabilities.js.map +1 -1
- package/dist/testing/projections/ProjectionCapabilityReject.d.ts +3 -0
- package/dist/testing/projections/ProjectionCapabilityReject.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionCapabilityReject.js +4 -0
- package/dist/testing/projections/ProjectionCapabilityReject.js.map +1 -0
- package/dist/testing/projections/ProjectionCapabilityReporter.d.ts +12 -0
- package/dist/testing/projections/ProjectionCapabilityReporter.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionCapabilityReporter.js +33 -0
- package/dist/testing/projections/ProjectionCapabilityReporter.js.map +1 -0
- package/dist/testing/projections/ProjectionDefinitionCapabilities.d.ts +11 -0
- package/dist/testing/projections/ProjectionDefinitionCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionDefinitionCapabilities.js +45 -0
- package/dist/testing/projections/ProjectionDefinitionCapabilities.js.map +1 -0
- package/dist/testing/projections/ProjectionEventSchemaResolver.d.ts +13 -0
- package/dist/testing/projections/ProjectionEventSchemaResolver.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionEventSchemaResolver.js +22 -0
- package/dist/testing/projections/ProjectionEventSchemaResolver.js.map +1 -0
- package/dist/testing/projections/ProjectionExpressionCapabilities.d.ts +19 -0
- package/dist/testing/projections/ProjectionExpressionCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionExpressionCapabilities.js +103 -0
- package/dist/testing/projections/ProjectionExpressionCapabilities.js.map +1 -0
- package/dist/testing/projections/ProjectionInitialValueCapabilities.d.ts +16 -0
- package/dist/testing/projections/ProjectionInitialValueCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionInitialValueCapabilities.js +72 -0
- package/dist/testing/projections/ProjectionInitialValueCapabilities.js.map +1 -0
- package/dist/testing/projections/ProjectionMappingCapabilities.d.ts +21 -0
- package/dist/testing/projections/ProjectionMappingCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionMappingCapabilities.js +86 -0
- package/dist/testing/projections/ProjectionMappingCapabilities.js.map +1 -0
- package/dist/testing/projections/ProjectionMappingValidation.d.ts +9 -0
- package/dist/testing/projections/ProjectionMappingValidation.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionMappingValidation.js +4 -0
- package/dist/testing/projections/ProjectionMappingValidation.js.map +1 -0
- package/dist/testing/projections/ProjectionReadModelCapabilities.d.ts +11 -0
- package/dist/testing/projections/ProjectionReadModelCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionReadModelCapabilities.js +40 -0
- package/dist/testing/projections/ProjectionReadModelCapabilities.js.map +1 -0
- package/dist/testing/projections/ProjectionRootCapabilities.d.ts +20 -0
- package/dist/testing/projections/ProjectionRootCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionRootCapabilities.js +73 -0
- package/dist/testing/projections/ProjectionRootCapabilities.js.map +1 -0
- package/dist/testing/projections/ProjectionScalarConverter.d.ts +21 -0
- package/dist/testing/projections/ProjectionScalarConverter.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionScalarConverter.js +105 -0
- package/dist/testing/projections/ProjectionScalarConverter.js.map +1 -0
- package/dist/testing/projections/ProjectionSchemaCapabilities.d.ts +26 -0
- package/dist/testing/projections/ProjectionSchemaCapabilities.d.ts.map +1 -0
- package/dist/testing/projections/ProjectionSchemaCapabilities.js +109 -0
- package/dist/testing/projections/ProjectionSchemaCapabilities.js.map +1 -0
- package/dist/testing/projections/ProjectionValueConverter.d.ts +5 -0
- package/dist/testing/projections/ProjectionValueConverter.d.ts.map +1 -1
- package/dist/testing/projections/ProjectionValueConverter.js +36 -84
- package/dist/testing/projections/ProjectionValueConverter.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/DecoratorType.d.ts +3 -1
- package/dist/types/DecoratorType.d.ts.map +1 -1
- package/dist/types/DecoratorType.js +2 -0
- package/dist/types/DecoratorType.js.map +1 -1
- package/for_ChronicleClient/when_reconnecting/and_an_observation_stream_lost_its_session.spec.ts +212 -0
- package/observation/ObservationReconnectBackoff.ts +109 -0
- package/observation/ObservationStreamOutcome.ts +12 -0
- package/observation/classifyStreamError.ts +67 -0
- package/observation/for_ObservationReconnectBackoff/given/a_backoff.ts +29 -0
- package/observation/for_ObservationReconnectBackoff/given/a_scripted_stream.ts +52 -0
- package/observation/for_ObservationReconnectBackoff/when_a_stream_delivered_before_it_ended.spec.ts +23 -0
- package/observation/for_ObservationReconnectBackoff/when_a_stream_stayed_open_before_it_ended.spec.ts +25 -0
- package/observation/for_ObservationReconnectBackoff/when_jittering_the_delay.spec.ts +24 -0
- package/observation/for_ObservationReconnectBackoff/when_streams_keep_ending_without_working.spec.ts +24 -0
- package/observation/for_ObservationReconnectBackoff/when_the_base_delay_is_not_positive.spec.ts +18 -0
- package/observation/for_ObservationReconnectBackoff/when_the_settings_are_not_finite.spec.ts +32 -0
- package/observation/for_ObservationReconnectBackoff/when_using_the_defaults.spec.ts +29 -0
- package/observation/for_classifyStreamError/when_classifying_a_stream_error.spec.ts +36 -0
- package/package.json +2 -2
- package/projections/for_Graphs/given/a_discovered_graph.ts +3 -2
- package/projections/for_Graphs/given/a_graph_with_views.ts +91 -0
- package/projections/for_Graphs/given/organization.ts +3 -2
- package/projections/for_Graphs/given/organization_with_views.fixture.ts +129 -0
- package/projections/for_Graphs/when_building_graph_views.spec.ts +218 -0
- package/projections/for_Graphs/when_declaring_an_invalid_graph_view.spec.ts +229 -0
- package/projections/for_Graphs/when_declaring_graph_views.standard.spec.ts +49 -0
- package/projections/for_Graphs/when_discovering_graph_views.spec.ts +58 -0
- package/projections/graphs/Graphs.ts +44 -0
- package/projections/graphs/IGraphs.ts +10 -2
- package/projections/graphs/index.ts +1 -0
- package/projections/graphs/views/AmbiguousDirection.ts +23 -0
- package/projections/graphs/views/DuplicateViewName.ts +23 -0
- package/projections/graphs/views/EdgeNotIncidentOnRoot.ts +24 -0
- package/projections/graphs/views/EdgePropertyViewNotUsedAsTarget.ts +21 -0
- package/projections/graphs/views/EdgePropertyViewSharedAcrossEdges.ts +22 -0
- package/projections/graphs/views/FollowsOptions.ts +20 -0
- package/projections/graphs/views/GraphEdgeDirection.ts +13 -0
- package/projections/graphs/views/GraphView.ts +18 -0
- package/projections/graphs/views/GraphViewBuildResult.ts +19 -0
- package/projections/graphs/views/GraphViewCardinality.ts +13 -0
- package/projections/graphs/views/GraphViewDefinition.ts +20 -0
- package/projections/graphs/views/GraphViewDefinitionBuilder.ts +322 -0
- package/projections/graphs/views/GraphViewDefinitionSerializer.ts +90 -0
- package/projections/graphs/views/GraphViewEdgeReference.ts +8 -0
- package/projections/graphs/views/GraphViewMember.ts +11 -0
- package/projections/graphs/views/GraphViewMemberKind.ts +16 -0
- package/projections/graphs/views/GraphViewMemberMetadata.ts +31 -0
- package/projections/graphs/views/GraphViewPropertyMember.ts +18 -0
- package/projections/graphs/views/GraphViewReason.ts +47 -0
- package/projections/graphs/views/GraphViewRelationMember.ts +29 -0
- package/projections/graphs/views/GraphViewSchema.ts +14 -0
- package/projections/graphs/views/GraphViewSchemaEdge.ts +20 -0
- package/projections/graphs/views/GraphViewSchemaNode.ts +14 -0
- package/projections/graphs/views/GraphViewSerializerOptions.ts +11 -0
- package/projections/graphs/views/RecursiveView.ts +22 -0
- package/projections/graphs/views/RelationTargetNotAView.ts +23 -0
- package/projections/graphs/views/TargetLabelMismatch.ts +25 -0
- package/projections/graphs/views/UnknownEdge.ts +23 -0
- package/projections/graphs/views/UnknownEdgeProperty.ts +24 -0
- package/projections/graphs/views/UnknownNodeProperty.ts +24 -0
- package/projections/graphs/views/ViewIsAlsoSchema.ts +21 -0
- package/projections/graphs/views/ViewOfMetadata.ts +11 -0
- package/projections/graphs/views/ViewOfOptions.ts +8 -0
- package/projections/graphs/views/ViewRootNotANode.ts +23 -0
- package/projections/graphs/views/declareGraphViewMember.ts +36 -0
- package/projections/graphs/views/follows.ts +28 -0
- package/projections/graphs/views/fromEdge.ts +17 -0
- package/projections/graphs/views/index.ts +43 -0
- package/projections/graphs/views/viewKey.ts +15 -0
- package/projections/graphs/views/viewOf.ts +50 -0
- package/projections/graphs/views/viewProperty.ts +16 -0
- package/reactors/Reactors.ts +101 -18
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_handler_failed_with_a_lost_session.spec.ts +32 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_replaced_stream_fails_late.spec.ts +28 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_stream_delivered_before_it_ended.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_a_stream_stayed_open_before_it_ended.spec.ts +23 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_it_is_disposed_while_waiting_to_reopen.spec.ts +27 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_streams_keep_ending_without_working.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_client_reconnected_after_streams_kept_ending.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_client_reconnected_while_waiting_to_reopen.spec.ts +25 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/and_the_kernel_lost_the_session.spec.ts +24 -0
- package/reactors/for_Reactors/when_reconnecting_the_observation_stream/given/a_reactor_whose_stream_ends.ts +69 -0
- package/reducers/Reducers.ts +99 -19
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_reducer_failed_with_a_lost_session.spec.ts +33 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_replaced_stream_fails_late.spec.ts +28 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_stream_delivered_before_it_ended.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_a_stream_stayed_open_before_it_ended.spec.ts +23 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_it_is_disposed_while_waiting_to_reopen.spec.ts +27 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_streams_keep_ending_without_working.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_client_reconnected_after_streams_kept_ending.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_client_reconnected_while_waiting_to_reopen.spec.ts +25 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/and_the_kernel_lost_the_session.spec.ts +24 -0
- package/reducers/for_Reducers/when_reconnecting_the_observation_stream/given/a_reducer_whose_stream_ends.ts +69 -0
- package/testing/InProcessAppendMetadata.ts +119 -0
- package/testing/InProcessBatchAppend.ts +142 -0
- package/testing/InProcessEventPayload.ts +100 -0
- package/testing/InProcessEventReadCriteria.ts +11 -0
- package/testing/InProcessEventReadFilter.ts +37 -0
- package/testing/InProcessEventSequence.ts +63 -257
- package/testing/InProcessEventSequenceEnvironment.ts +16 -0
- package/testing/InProcessSingleAppend.ts +99 -0
- package/testing/for_InProcessEventSequence/when_preserving_validation_and_commit_order.spec.ts +95 -0
- package/testing/projections/ProjectionCapabilities.ts +23 -279
- package/testing/projections/ProjectionCapabilityReject.ts +5 -0
- package/testing/projections/ProjectionCapabilityReporter.ts +31 -0
- package/testing/projections/ProjectionDefinitionCapabilities.ts +45 -0
- package/testing/projections/ProjectionEventSchemaResolver.ts +23 -0
- package/testing/projections/ProjectionExpressionCapabilities.ts +101 -0
- package/testing/projections/ProjectionInitialValueCapabilities.ts +73 -0
- package/testing/projections/ProjectionMappingCapabilities.ts +85 -0
- package/testing/projections/ProjectionMappingValidation.ts +12 -0
- package/testing/projections/ProjectionReadModelCapabilities.ts +42 -0
- package/testing/projections/ProjectionRootCapabilities.ts +75 -0
- package/testing/projections/ProjectionScalarConverter.ts +106 -0
- package/testing/projections/ProjectionSchemaCapabilities.ts +112 -0
- package/testing/projections/ProjectionValueConverter.ts +37 -76
- package/testing/projections/for_ProjectionCapabilities/when_reporting_the_first_unsupported_operation.spec.ts +74 -0
- package/testing/projections/for_ProjectionValueConverter/when_converting_structured_and_scalar_values.spec.ts +64 -0
- package/types/DecoratorType.ts +4 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { a_reducer_whose_stream_ends } from './given/a_reducer_whose_stream_ends.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when reconnecting a reducer observation stream and a stream stayed open before it ended', () => {
|
|
10
|
+
let context: a_reducer_whose_stream_ends;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
context = new a_reducer_whose_stream_ends();
|
|
14
|
+
context.scripts.push({}, {}, { openForMs: 180_000 }, { untilAborted: true });
|
|
15
|
+
await context.reducers.register();
|
|
16
|
+
await vi.advanceTimersByTimeAsync(185_000);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => context.dispose());
|
|
20
|
+
|
|
21
|
+
it('should start the wait over at the base delay after the stream that stayed open', () =>
|
|
22
|
+
context.waits.should.deep.equal([1_000, 2_000, 181_000]));
|
|
23
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { a_reducer_whose_stream_ends } from './given/a_reducer_whose_stream_ends.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when reconnecting a reducer observation stream and it is disposed while it waits to reopen', () => {
|
|
10
|
+
let context: a_reducer_whose_stream_ends;
|
|
11
|
+
let timersAfterDispose: number;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
context = new a_reducer_whose_stream_ends();
|
|
15
|
+
context.scripts.push({});
|
|
16
|
+
await context.reducers.register();
|
|
17
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
18
|
+
context.reducers.dispose();
|
|
19
|
+
timersAfterDispose = vi.getTimerCount();
|
|
20
|
+
await vi.advanceTimersByTimeAsync(120_000);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(() => context.dispose());
|
|
24
|
+
|
|
25
|
+
it('should not open the stream again', () => context.openedAt.should.have.lengthOf(1));
|
|
26
|
+
it('should leave no timer behind', () => timersAfterDispose.should.equal(0));
|
|
27
|
+
});
|
|
@@ -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 { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { ClientError, Status } from 'nice-grpc';
|
|
6
|
+
import { a_reducer_whose_stream_ends } from './given/a_reducer_whose_stream_ends.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
|
|
10
|
+
describe('when reconnecting a reducer observation stream and streams keep ending without working', () => {
|
|
11
|
+
let context: a_reducer_whose_stream_ends;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
context = new a_reducer_whose_stream_ends();
|
|
15
|
+
context.scripts.push({}, { error: new ClientError('/Reducers/Observe', Status.UNAVAILABLE, 'kernel stopping') });
|
|
16
|
+
await context.reducers.register();
|
|
17
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => context.dispose());
|
|
21
|
+
|
|
22
|
+
it('should double the wait each time a stream ends', () => context.waits.slice(0, 5).should.deep.equal([1_000, 2_000, 4_000, 8_000, 16_000]));
|
|
23
|
+
it('should not reconnect the client', () => context.reconnectRequests.should.be.empty);
|
|
24
|
+
});
|
|
@@ -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 { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { a_reducer_whose_stream_ends } from './given/a_reducer_whose_stream_ends.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when reconnecting a reducer observation stream and the client reconnected after streams kept ending', () => {
|
|
10
|
+
let context: a_reducer_whose_stream_ends;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
context = new a_reducer_whose_stream_ends();
|
|
14
|
+
context.scripts.push({}, {}, {}, { untilAborted: true });
|
|
15
|
+
await context.reducers.register();
|
|
16
|
+
await vi.advanceTimersByTimeAsync(1_000);
|
|
17
|
+
await context.reconnect();
|
|
18
|
+
await vi.advanceTimersByTimeAsync(4_000);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => context.dispose());
|
|
22
|
+
|
|
23
|
+
it('should keep the wait it had grown to', () => context.waits.should.deep.equal([1_000, 0, 4_000]));
|
|
24
|
+
});
|
|
@@ -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 { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { a_reducer_whose_stream_ends } from './given/a_reducer_whose_stream_ends.js';
|
|
6
|
+
|
|
7
|
+
chai.should();
|
|
8
|
+
|
|
9
|
+
describe('when reconnecting a reducer observation stream and the client reconnected while it waited to reopen', () => {
|
|
10
|
+
let context: a_reducer_whose_stream_ends;
|
|
11
|
+
|
|
12
|
+
beforeEach(async () => {
|
|
13
|
+
context = new a_reducer_whose_stream_ends();
|
|
14
|
+
context.scripts.push({}, { untilAborted: true });
|
|
15
|
+
await context.reducers.register();
|
|
16
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
17
|
+
await context.reconnect();
|
|
18
|
+
await vi.advanceTimersByTimeAsync(120_000);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => context.dispose());
|
|
22
|
+
|
|
23
|
+
it('should only open the stream the reconnect registered', () => context.openedAt.should.have.lengthOf(2));
|
|
24
|
+
it('should leave exactly one stream open', () => context.stream.open.should.equal(1));
|
|
25
|
+
});
|
|
@@ -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 { afterEach, beforeEach, chai, describe, it, vi } from 'vitest';
|
|
5
|
+
import { ClientError, Status } from 'nice-grpc';
|
|
6
|
+
import { a_reducer_whose_stream_ends } from './given/a_reducer_whose_stream_ends.js';
|
|
7
|
+
|
|
8
|
+
chai.should();
|
|
9
|
+
|
|
10
|
+
describe('when reconnecting a reducer observation stream and the kernel lost the session', () => {
|
|
11
|
+
let context: a_reducer_whose_stream_ends;
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
context = new a_reducer_whose_stream_ends();
|
|
15
|
+
context.scripts.push({ error: new ClientError('/Reducers/Observe', Status.UNKNOWN, 'ClientIsNotConnected: connection is not connected') });
|
|
16
|
+
await context.reducers.register();
|
|
17
|
+
await vi.advanceTimersByTimeAsync(120_000);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => context.dispose());
|
|
21
|
+
|
|
22
|
+
it('should ask the whole client to reconnect', () => context.reconnectRequests.should.deep.equal(['reducer-session-lost']));
|
|
23
|
+
it('should not open the stream again with the same connection', () => context.openedAt.should.have.lengthOf(1));
|
|
24
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { vi } from 'vitest';
|
|
5
|
+
import type { ReduceOperationMessage } from '@cratis/chronicle.contracts';
|
|
6
|
+
import { Reducers } from '../../../Reducers.js';
|
|
7
|
+
import { reducer } from '../../../reducer.js';
|
|
8
|
+
import { eventType } from '../../../../events/eventTypeDecorator.js';
|
|
9
|
+
import { ConnectionLifecycle } from '../../../../connection/ConnectionLifecycle.js';
|
|
10
|
+
import type { ChronicleConnection } from '../../../../connection/ChronicleConnection.js';
|
|
11
|
+
import type { IClientArtifactsProvider } from '../../../../artifacts/IClientArtifactsProvider.js';
|
|
12
|
+
import { a_scripted_stream, type StreamScript } from '../../../../observation/for_ObservationReconnectBackoff/given/a_scripted_stream.js';
|
|
13
|
+
|
|
14
|
+
@eventType('reconnecting-reducer-item')
|
|
15
|
+
class Item {}
|
|
16
|
+
class Model {}
|
|
17
|
+
|
|
18
|
+
@reducer('reconnecting-reducer', undefined, Model)
|
|
19
|
+
class Observer { item() { return new Model(); } }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A reducer whose observation streams follow a script, on fake timers and a jitter of zero, so every wait is
|
|
23
|
+
* exactly half of its ceiling.
|
|
24
|
+
*/
|
|
25
|
+
export class a_reducer_whose_stream_ends {
|
|
26
|
+
readonly lifecycle = new ConnectionLifecycle();
|
|
27
|
+
readonly reconnectRequests: string[] = [];
|
|
28
|
+
readonly stream = new a_scripted_stream<ReduceOperationMessage>();
|
|
29
|
+
readonly reducers: Reducers;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
vi.useFakeTimers();
|
|
33
|
+
this.lifecycle.onReconnectRequested(reason => this.reconnectRequests.push(reason));
|
|
34
|
+
const artifacts = { eventTypes: [Item], reducers: [Observer], reactors: [], readModels: [Model], seeders: [], constraints: [],
|
|
35
|
+
projections: [], webhooks: [], eventTypeMigrations: [], globalForHandlers: [] } as IClientArtifactsProvider;
|
|
36
|
+
const connection = {
|
|
37
|
+
reducers: { observe: this.stream.observe },
|
|
38
|
+
readModels: { registerMany: vi.fn().mockResolvedValue({}) }
|
|
39
|
+
} as unknown as ChronicleConnection;
|
|
40
|
+
this.reducers = new Reducers(artifacts, connection, 'store', 'Default', this.lifecycle, 'sink',
|
|
41
|
+
undefined, undefined, undefined, false, { now: () => Date.now(), nextJitter: () => 0 });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Gets the scripts the next streams follow. */
|
|
45
|
+
get scripts(): StreamScript<ReduceOperationMessage>[] {
|
|
46
|
+
return this.stream.scripts;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Gets when each stream was opened. */
|
|
50
|
+
get openedAt(): number[] {
|
|
51
|
+
return this.stream.openedAt;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Gets the wait before each stream after the first was opened. */
|
|
55
|
+
get waits(): number[] {
|
|
56
|
+
return this.stream.waits;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Drops the session and registers again, as a client reconnect does. */
|
|
60
|
+
async reconnect(): Promise<void> {
|
|
61
|
+
await this.lifecycle.disconnected(() => undefined);
|
|
62
|
+
await this.reducers.register();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dispose(): void {
|
|
66
|
+
this.reducers.dispose();
|
|
67
|
+
vi.useRealTimers();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { Guid } from '@cratis/fundamentals';
|
|
5
|
+
import { toContractsGuid } from '../connection/Guid.js';
|
|
6
|
+
import { Identity } from '../identity/Identity.js';
|
|
7
|
+
import type { prepareSingleAppend } from '../eventSequences/prepareSingleAppend.js';
|
|
8
|
+
import type { AppendOptions } from '../eventSequences/AppendOptions.js';
|
|
9
|
+
import type { EventForEventSourceId } from '../eventSequences/EventForEventSourceId.js';
|
|
10
|
+
import { hasNamedTags } from './singleAppendRoute.js';
|
|
11
|
+
import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
|
|
12
|
+
|
|
13
|
+
/** Prepares only the metadata domain proven by the in-process append fixtures. */
|
|
14
|
+
export class InProcessAppendMetadata {
|
|
15
|
+
constructor(private readonly environment: InProcessEventSequenceEnvironment) {}
|
|
16
|
+
|
|
17
|
+
batch(options?: AppendOptions): void {
|
|
18
|
+
if (options === undefined) return;
|
|
19
|
+
if (!this.optionsObject(options)) {
|
|
20
|
+
throw this.environment.unsupported('appendMany.options', this.environment.sequenceId, 'Append options must be an object.');
|
|
21
|
+
}
|
|
22
|
+
if (hasNamedTags(options.namedTags)) throw this.environment.unsupported('appendMany.namedTags', this.environment.sequenceId, 'Named tags are not fixture-backed.');
|
|
23
|
+
this.batchKeys(options);
|
|
24
|
+
this.subject(options);
|
|
25
|
+
this.tags(options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
entry(entry: EventForEventSourceId): void {
|
|
29
|
+
if (!this.entryObject(entry) || this.unknown(entry,
|
|
30
|
+
['eventSourceId', 'event', 'eventSourceType', 'eventStreamType', 'eventStreamId', 'subject', 'occurred', 'tags', 'namedTags'])) {
|
|
31
|
+
throw this.environment.unsupported('appendMany.entry', this.environment.sequenceId, 'Unrecognized per-entry metadata.');
|
|
32
|
+
}
|
|
33
|
+
if (hasNamedTags(entry.namedTags)) throw this.environment.unsupported('appendMany.namedTags', this.environment.sequenceId, 'Named tags are not fixture-backed.');
|
|
34
|
+
if (entry.occurred !== undefined) this.checkedDate(entry.occurred, 'appendMany.occurred');
|
|
35
|
+
this.subject(entry);
|
|
36
|
+
this.tags(entry);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
guid(value: string | Guid, operation: string): void {
|
|
40
|
+
try {
|
|
41
|
+
toContractsGuid(Guid.as(value));
|
|
42
|
+
if (!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(value.toString())) throw new Error('Invalid GUID.');
|
|
43
|
+
} catch { throw this.environment.unsupported(operation, this.environment.sequenceId, 'Correlation ID must be a valid GUID.'); }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
checkedDate(value: Date, operation: string): Date {
|
|
47
|
+
if (!(value instanceof Date) || !this.validTime(value)) {
|
|
48
|
+
throw this.environment.unsupported(operation, this.environment.sequenceId, 'Occurrence must be within UTC years 1–9999 at millisecond precision.');
|
|
49
|
+
}
|
|
50
|
+
return new Date(value);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
source(source: string, operation: string): void {
|
|
54
|
+
if (typeof source !== 'string' || !/^[A-Za-z0-9_-]+$/.test(source)) {
|
|
55
|
+
throw this.environment.unsupported(operation, String(source), 'Only simple source identifiers are fixture-backed.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private subject(metadata: Pick<AppendOptions, 'subject'>): void {
|
|
60
|
+
if (!this.validSubject(metadata)) {
|
|
61
|
+
throw this.environment.unsupported('appendMany.subject', this.environment.sequenceId, 'Subject must be a string.');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private validSubject(metadata: Pick<AppendOptions, 'subject'>): boolean {
|
|
66
|
+
return metadata.subject === undefined || metadata.subject === null || typeof metadata.subject === 'string';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private tags(metadata: Pick<AppendOptions, 'tags'>): void {
|
|
70
|
+
if (metadata.tags && !this.stringTags(metadata)) {
|
|
71
|
+
throw this.environment.unsupported('appendMany.tags', this.environment.sequenceId, 'Only plain string tags are fixture-backed.');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
unsupportedOptions(options?: AppendOptions): boolean {
|
|
76
|
+
if (options?.concurrencyScope !== undefined || options?.concurrencyScopes !== undefined) return true;
|
|
77
|
+
return options?.eventSourceId !== undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
storedSubject(subject: string | undefined, eventSourceId: string): string {
|
|
81
|
+
// Match the kernel's string.IsNullOrWhiteSpace, including U+0085 but not U+FEFF.
|
|
82
|
+
return subject && !/^\p{White_Space}*$/u.test(subject) ? subject : eventSourceId;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private batchKeys(options: AppendOptions): void {
|
|
86
|
+
const allowed = ['correlationId', 'sourceType', 'streamType', 'streamId', 'subject', 'occurred', 'tags', 'namedTags'];
|
|
87
|
+
if (this.unknown(options, allowed) || this.unsupportedOptions(options)) {
|
|
88
|
+
throw this.environment.unsupported('appendMany.options', this.environment.sequenceId, 'Concurrency and unrecognized metadata are not fixture-backed.');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private unknown(value: object, allowed: string[]): boolean {
|
|
93
|
+
return Reflect.ownKeys(value).some(key => !allowed.includes(String(key)));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private validTime(value: Date): boolean {
|
|
97
|
+
return !Number.isNaN(value.getTime()) && value.getUTCFullYear() >= 1 && value.getUTCFullYear() <= 9999;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private stringTags(metadata: Pick<AppendOptions, 'tags'>): boolean {
|
|
101
|
+
return Array.isArray(metadata.tags) && !metadata.tags.some(tag => typeof tag !== 'string');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private entryObject(value: unknown): boolean {
|
|
105
|
+
return !!value && typeof value === 'object';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private optionsObject(value: unknown): boolean {
|
|
109
|
+
return this.entryObject(value) && !Array.isArray(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
ambientContext(identity: Identity, chain: ReturnType<typeof prepareSingleAppend>['causationChain']): boolean {
|
|
113
|
+
return identity === Identity.system && this.emptyRoot(chain);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private emptyRoot(chain: ReturnType<typeof prepareSingleAppend>['causationChain']): boolean {
|
|
117
|
+
return chain.length === 2 && Object.keys(chain[0].properties).length === 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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 { AppendedEvent } from '../events/AppendedEvent.js';
|
|
5
|
+
import { EventObservationState } from '@cratis/chronicle.contracts';
|
|
6
|
+
import { getEventTypeFor } from '../events/eventTypeDecorator.js';
|
|
7
|
+
import { Tag } from '../events/Tag.js';
|
|
8
|
+
import type { AppendOptions } from '../eventSequences/AppendOptions.js';
|
|
9
|
+
import type { AppendResult } from '../eventSequences/AppendResult.js';
|
|
10
|
+
import type { EventForEventSourceId } from '../eventSequences/EventForEventSourceId.js';
|
|
11
|
+
import { EventSequenceNumber } from '../eventSequences/EventSequenceNumber.js';
|
|
12
|
+
import { prepareBatchAppend } from '../eventSequences/prepareBatchAppend.js';
|
|
13
|
+
import { InProcessAppendMetadata } from './InProcessAppendMetadata.js';
|
|
14
|
+
import { InProcessEventPayload } from './InProcessEventPayload.js';
|
|
15
|
+
import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
|
|
16
|
+
import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
|
|
17
|
+
|
|
18
|
+
/** Stages a complete batch; the sequence alone decides whether to commit it. */
|
|
19
|
+
export class InProcessBatchAppend {
|
|
20
|
+
private readonly metadata: InProcessAppendMetadata;
|
|
21
|
+
|
|
22
|
+
constructor(private readonly environment: InProcessEventSequenceEnvironment, private readonly payload: InProcessEventPayload,
|
|
23
|
+
private readonly success: (sequence: EventSequenceNumber, artifact: string) => AppendResult) {
|
|
24
|
+
this.metadata = new InProcessAppendMetadata(environment);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
prepare(sourceOrEvents: string | EventForEventSourceId[], eventsOrOptions: object[] | AppendOptions | undefined, options: AppendOptions | undefined, position: number) {
|
|
28
|
+
const entries = typeof sourceOrEvents === 'string' ? eventsOrOptions as object[] : sourceOrEvents;
|
|
29
|
+
const shared = typeof sourceOrEvents === 'string' ? options : eventsOrOptions as AppendOptions | undefined;
|
|
30
|
+
this.validateEntries(entries, shared, typeof sourceOrEvents === 'string');
|
|
31
|
+
const prepared = this.serialize(sourceOrEvents, entries, shared);
|
|
32
|
+
this.metadata.guid(prepared.correlationId, 'appendMany.correlationId');
|
|
33
|
+
this.context(prepared, entries.length);
|
|
34
|
+
const staged = prepared.eventsForEventSourceIds.map((_, index) => this.stage(prepared, index, position));
|
|
35
|
+
return { prepared, staged };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private validateEntries(entries: object[], shared: AppendOptions | undefined, sameSource: boolean): void {
|
|
39
|
+
this.array(entries);
|
|
40
|
+
this.metadata.batch(shared);
|
|
41
|
+
this.sharedOccurrence(shared);
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
if (sameSource) break;
|
|
44
|
+
this.metadata.entry(entry as EventForEventSourceId);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private sharedOccurrence(shared?: AppendOptions): void {
|
|
49
|
+
if (shared?.occurred !== undefined) this.metadata.checkedDate(shared.occurred, 'appendMany.occurred');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private array(entries: object[]): void {
|
|
53
|
+
if (!Array.isArray(entries)) throw this.environment.unsupported('appendMany.arguments', this.environment.sequenceId, 'Events must be an array.');
|
|
54
|
+
if (!entries.length) throw this.environment.unsupported('appendMany.empty', this.environment.sequenceId, 'The kernel rejects an empty batch.');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private serialize(sourceOrEvents: string | EventForEventSourceId[], entries: object[], shared?: AppendOptions) {
|
|
58
|
+
try {
|
|
59
|
+
const batchOptions = this.options(shared);
|
|
60
|
+
if (batchOptions?.correlationId !== undefined) this.metadata.guid(batchOptions.correlationId, 'appendMany.correlationId');
|
|
61
|
+
return typeof sourceOrEvents === 'string'
|
|
62
|
+
? prepareBatchAppend(sourceOrEvents, entries, batchOptions)
|
|
63
|
+
: prepareBatchAppend(sourceOrEvents, batchOptions);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof UnsupportedEventSequenceOperation) throw error;
|
|
66
|
+
throw this.environment.unsupported('appendMany.serialization', this.environment.sequenceId, `Batch preparation failed: ${String(error)}.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private options(shared?: AppendOptions): AppendOptions | undefined {
|
|
71
|
+
return shared?.correlationId === undefined && this.environment.correlationId ? this.withCorrelation(shared) : shared;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private withCorrelation(shared?: AppendOptions): AppendOptions {
|
|
75
|
+
const metadata = shared ?? {};
|
|
76
|
+
return { correlationId: this.environment.correlationId!(), sourceType: metadata.sourceType, streamType: metadata.streamType,
|
|
77
|
+
streamId: metadata.streamId, subject: metadata.subject, occurred: metadata.occurred, tags: metadata.tags,
|
|
78
|
+
namedTags: metadata.namedTags };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private context({ identity, batchCausationChain }: ReturnType<typeof prepareBatchAppend>, count: number): void {
|
|
82
|
+
if (!this.metadata.ambientContext(identity, batchCausationChain) || !this.batchContext(batchCausationChain, count)) {
|
|
83
|
+
throw this.environment.unsupported('appendMany.context', this.environment.sequenceId, 'Ambient identity or causation metadata is not fixture-backed.');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private batchContext(chain: ReturnType<typeof prepareBatchAppend>['batchCausationChain'], count: number): boolean {
|
|
88
|
+
return chain[1].type.name === 'TypeScriptClient.AppendMany' && chain[1].properties.count === String(count);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private stage(prepared: ReturnType<typeof prepareBatchAppend>, index: number, position: number) {
|
|
92
|
+
const { eventSourceId, event } = prepared.eventsForEventSourceIds[index];
|
|
93
|
+
this.eventInstance(event);
|
|
94
|
+
this.metadata.source(eventSourceId, 'appendMany.source');
|
|
95
|
+
const wire = prepared.eventsToAppend[index];
|
|
96
|
+
this.route(wire);
|
|
97
|
+
this.tags(wire, event);
|
|
98
|
+
const occurred = wire.Occurred ? this.metadata.checkedDate(new Date(wire.Occurred.Value), 'appendMany.occurred')
|
|
99
|
+
: this.metadata.checkedDate(this.environment.clock(), 'appendMany.clock');
|
|
100
|
+
const content = this.payload.checkedContent(event, wire.Content, 'appendMany.content');
|
|
101
|
+
const hash = this.payload.hash(wire.EventType.Id, eventSourceId, content);
|
|
102
|
+
const sequenceNumber = new EventSequenceNumber(BigInt(position + index));
|
|
103
|
+
const eventType = getEventTypeFor(event.constructor);
|
|
104
|
+
const stored: AppendedEvent = { eventType, content, context: {
|
|
105
|
+
eventStore: this.environment.store, namespace: this.environment.namespace, sequenceNumber: sequenceNumber.value, eventSourceId,
|
|
106
|
+
eventSourceType: wire.EventSourceType || 'Default', eventStreamType: wire.EventStreamType || 'All',
|
|
107
|
+
eventStreamId: wire.EventStreamId || 'Default', subject: this.metadata.storedSubject(wire.Subject, eventSourceId), hash, causedBy: prepared.identity,
|
|
108
|
+
observationState: EventObservationState.Initial, eventType, occurred, correlationId: prepared.correlationId.toString(),
|
|
109
|
+
causation: prepared.batchCausationChain.map(item => ({ type: item.type.name, occurred: item.occurred, properties: { ...item.properties } })),
|
|
110
|
+
tags: wire.Tags.map(tag => new Tag(tag)), namedTags: []
|
|
111
|
+
} };
|
|
112
|
+
return { stored, result: this.success(sequenceNumber, event.constructor.name) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private eventInstance(event: object): void {
|
|
116
|
+
if (!this.registeredEvent(event)) {
|
|
117
|
+
throw this.environment.unsupported('appendMany.event', event?.constructor?.name ?? this.environment.sequenceId, 'Event is not in the selected catalog.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private registeredEvent(event: object): boolean {
|
|
122
|
+
return !!event && typeof event === 'object' && this.environment.catalog.has(event.constructor);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private route(wire: ReturnType<typeof prepareBatchAppend>['eventsToAppend'][number]): void {
|
|
126
|
+
for (const [name, value] of Object.entries({ sourceType: wire.EventSourceType, streamType: wire.EventStreamType, streamId: wire.EventStreamId })) {
|
|
127
|
+
if (value !== undefined && !this.routeIdentifier(value)) {
|
|
128
|
+
throw this.environment.unsupported(`appendMany.${name}`, String(value), 'Only simple metadata identifiers are fixture-backed.');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private routeIdentifier(value: unknown): boolean {
|
|
134
|
+
return typeof value === 'string' && /^[A-Za-z0-9_-]*$/.test(value);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private tags(wire: ReturnType<typeof prepareBatchAppend>['eventsToAppend'][number], event: object): void {
|
|
138
|
+
if (wire.Tags.some(tag => !/^[A-Za-z0-9_-]+$/.test(tag))) {
|
|
139
|
+
throw this.environment.unsupported('appendMany.tags', event.constructor.name, 'Only simple string tags are fixture-backed.');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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 { createHash } from 'node:crypto';
|
|
5
|
+
import { conceptAsTypeKey, JsonSerializer, typeKeyOf, type Constructor } from '@cratis/fundamentals';
|
|
6
|
+
import type { AppendedEvent } from '../events/AppendedEvent.js';
|
|
7
|
+
import { EventType } from '../events/EventType.js';
|
|
8
|
+
import { EventTypeId } from '../events/EventTypeId.js';
|
|
9
|
+
import { EventTypeGeneration } from '../events/EventTypeGeneration.js';
|
|
10
|
+
import { Tag } from '../events/Tag.js';
|
|
11
|
+
import { Identity } from '../identity/Identity.js';
|
|
12
|
+
import type { JsonSchema } from '../schemas/JsonSchema.js';
|
|
13
|
+
import { matchesEventField } from './EventFieldSchema.js';
|
|
14
|
+
import type { InProcessConstraints } from './InProcessConstraints.js';
|
|
15
|
+
import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
|
|
16
|
+
|
|
17
|
+
/** Schema-bound payload validation, canonical hashing, and isolated history snapshots. */
|
|
18
|
+
export class InProcessEventPayload {
|
|
19
|
+
constructor(private readonly environment: InProcessEventSequenceEnvironment, private readonly constraints?: InProcessConstraints) {}
|
|
20
|
+
|
|
21
|
+
checkedContent(event: object, serialized: string, operation: string,
|
|
22
|
+
mismatchReason = 'Content differs from the event schema.'): Record<string, unknown> {
|
|
23
|
+
const content = this.parse(serialized, event, operation);
|
|
24
|
+
const metadata = this.environment.catalog.get(event.constructor)!;
|
|
25
|
+
const properties = metadata.schema.properties!;
|
|
26
|
+
if (!this.objectWithProperties(content, properties) || !this.matchesProperties(event, content, properties)) {
|
|
27
|
+
throw this.environment.unsupported(operation, event.constructor.name, mismatchReason);
|
|
28
|
+
}
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
hash(typeId: string, source: string, content: Record<string, unknown>): string {
|
|
33
|
+
const canonical = Object.fromEntries(Object.entries(content).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
34
|
+
return createHash('sha256').update(`${typeId}|${source}|${JSON.stringify(canonical)}`).digest('base64');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
snapshot(event: AppendedEvent): AppendedEvent {
|
|
38
|
+
const eventType = new EventType(new EventTypeId(event.eventType.id.value),
|
|
39
|
+
new EventTypeGeneration(event.eventType.generation.value), event.eventType.tombstone);
|
|
40
|
+
const causedBy = event.context.causedBy;
|
|
41
|
+
return {
|
|
42
|
+
eventType,
|
|
43
|
+
content: JSON.parse(JSON.stringify(event.content)) as Record<string, unknown>,
|
|
44
|
+
context: { ...event.context, eventType, occurred: new Date(event.context.occurred),
|
|
45
|
+
causedBy: causedBy && new Identity(causedBy.subject, causedBy.name, causedBy.userName, causedBy.onBehalfOf),
|
|
46
|
+
causation: event.context.causation.map(item => ({ ...item, occurred: item.occurred && new Date(item.occurred), properties: { ...item.properties } })),
|
|
47
|
+
tags: event.context.tags.map(item => new Tag(item.value)),
|
|
48
|
+
namedTags: [...(event.context.namedTags ?? [])] }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private parse(serialized: string, event: object, operation: string): Record<string, unknown> {
|
|
53
|
+
try { return JSON.parse(serialized) as Record<string, unknown>; }
|
|
54
|
+
catch { throw this.environment.unsupported(operation, event.constructor.name, 'Content must be valid JSON.'); }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private objectWithProperties(content: Record<string, unknown>, properties: Record<string, JsonSchema>): boolean {
|
|
58
|
+
if (!this.isObject(content)) return false;
|
|
59
|
+
return Object.keys(content).length === Object.keys(properties).length;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private isObject(content: unknown): boolean {
|
|
63
|
+
return !!content && typeof content === 'object' && !Array.isArray(content);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private matchesProperties(event: object, content: Record<string, unknown>, properties: Record<string, JsonSchema>): boolean {
|
|
67
|
+
return Object.entries(properties).every(property => this.matchesSchema(event, content, property));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private matchesSchema(event: object, content: Record<string, unknown>, [key, property]: [string, JsonSchema]): boolean {
|
|
71
|
+
return this.matchesProperty(content, key, property) && this.matchesConstraint(event, content, key) && this.matchesText(content[key], property);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private matchesProperty(content: Record<string, unknown>, key: string, property: JsonSchema): boolean {
|
|
75
|
+
return Object.hasOwn(content, key) && matchesEventField(content[key], property);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private matchesText(value: unknown, property: JsonSchema): boolean {
|
|
79
|
+
if (property.type !== 'string' || property.format !== undefined) return true;
|
|
80
|
+
return /^[\x20-\x21\x23-\x5b\x5d-\x7e\u00e9]*$/.test(value as string);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private matchesConstraint(event: object, content: Record<string, unknown>, key: string): boolean {
|
|
84
|
+
const metadata = this.environment.catalog.get(event.constructor)!;
|
|
85
|
+
if (!this.constraints?.isConstrainedProperty(metadata.eventType.id.value, key)) return true;
|
|
86
|
+
return this.matchesConstrainedValue(Reflect.get(event, key), content[key]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private matchesConstrainedValue(value: unknown, content: unknown): boolean {
|
|
90
|
+
// Use production serialization for concepts, not their wrapper object's runtime type.
|
|
91
|
+
// Keep rejecting other unproven conversions, such as a Date assigned to a string field.
|
|
92
|
+
if (this.serializedConcept(value)) return JsonSerializer.serialize(value) === JSON.stringify(content);
|
|
93
|
+
return value === content;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private serializedConcept(value: unknown): boolean {
|
|
97
|
+
if (!value || typeof value !== 'object') return false;
|
|
98
|
+
return [conceptAsTypeKey, 'Guid'].includes(typeKeyOf(value.constructor as Constructor) ?? '');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
/** Validated read criteria; route sentinels deliberately do not narrow history. */
|
|
5
|
+
export interface InProcessEventReadCriteria {
|
|
6
|
+
readonly source?: string;
|
|
7
|
+
readonly sourceType?: string;
|
|
8
|
+
readonly streamType?: string;
|
|
9
|
+
readonly streamId?: string;
|
|
10
|
+
readonly ids: readonly string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { AppendedEvent } from '../events/AppendedEvent.js';
|
|
5
|
+
import type { InProcessEventReadCriteria } from './InProcessEventReadCriteria.js';
|
|
6
|
+
|
|
7
|
+
/** Applies the same source, route-sentinel, and event-type semantics to each read surface. */
|
|
8
|
+
export class InProcessEventReadFilter {
|
|
9
|
+
constructor(private readonly criteria: InProcessEventReadCriteria) {}
|
|
10
|
+
|
|
11
|
+
matches(event: AppendedEvent): boolean {
|
|
12
|
+
return this.source(event) && this.sourceType(event) && this.streamType(event) && this.streamId(event) && this.eventType(event);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private source(event: AppendedEvent): boolean {
|
|
16
|
+
return this.criteria.source === undefined || event.context.eventSourceId === this.criteria.source;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private sourceType(event: AppendedEvent): boolean {
|
|
20
|
+
const value = this.criteria.sourceType;
|
|
21
|
+
return value === undefined || value === 'Default' || event.context.eventSourceType === value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private streamType(event: AppendedEvent): boolean {
|
|
25
|
+
const value = this.criteria.streamType;
|
|
26
|
+
return value === undefined || value === 'All' || event.context.eventStreamType === value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private streamId(event: AppendedEvent): boolean {
|
|
30
|
+
const value = this.criteria.streamId;
|
|
31
|
+
return value === undefined || value === 'Default' || event.context.eventStreamId === value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private eventType(event: AppendedEvent): boolean {
|
|
35
|
+
return !this.criteria.ids.length || this.criteria.ids.includes(event.eventType.id.value);
|
|
36
|
+
}
|
|
37
|
+
}
|