@cratis/chronicle 6.63.0 → 6.65.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/README.md +1 -1
- package/artifacts/DefaultClientArtifactsProvider.ts +5 -0
- package/artifacts/IClientArtifactsProvider.ts +3 -0
- package/connection/ChronicleConnection.ts +17 -7
- package/connection/ChronicleConnectionString.spec.ts +85 -0
- package/connection/ChronicleConnectionString.ts +186 -12
- package/connection/ChronicleTlsMaterial.spec.ts +160 -0
- package/connection/ChronicleTlsMaterial.ts +121 -0
- package/connection/CompatibilityPreflight.ts +9 -1
- package/connection/LeastConnectionsLoadBalancerStrategy.ts +4 -2
- package/connection/LoadBalancerStrategyFactory.ts +7 -2
- package/connection/TokenProvider.ts +4 -1
- package/connection/fetchOAuthAccessToken.ts +4 -2
- package/connection/for_CompatibilityPreflight/when_verifying/with_the_check_skipped.spec.ts +23 -0
- 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/ChronicleConnection.d.ts +1 -0
- package/dist/connection/ChronicleConnection.d.ts.map +1 -1
- package/dist/connection/ChronicleConnection.js +15 -7
- package/dist/connection/ChronicleConnection.js.map +1 -1
- package/dist/connection/ChronicleConnectionString.d.ts +50 -1
- package/dist/connection/ChronicleConnectionString.d.ts.map +1 -1
- package/dist/connection/ChronicleConnectionString.js +154 -12
- package/dist/connection/ChronicleConnectionString.js.map +1 -1
- package/dist/connection/ChronicleTlsMaterial.d.ts +54 -0
- package/dist/connection/ChronicleTlsMaterial.d.ts.map +1 -0
- package/dist/connection/ChronicleTlsMaterial.js +88 -0
- package/dist/connection/ChronicleTlsMaterial.js.map +1 -0
- package/dist/connection/CompatibilityPreflight.d.ts +2 -1
- package/dist/connection/CompatibilityPreflight.d.ts.map +1 -1
- package/dist/connection/CompatibilityPreflight.js +6 -1
- package/dist/connection/CompatibilityPreflight.js.map +1 -1
- package/dist/connection/LeastConnectionsLoadBalancerStrategy.d.ts +2 -1
- package/dist/connection/LeastConnectionsLoadBalancerStrategy.d.ts.map +1 -1
- package/dist/connection/LeastConnectionsLoadBalancerStrategy.js +3 -2
- package/dist/connection/LeastConnectionsLoadBalancerStrategy.js.map +1 -1
- package/dist/connection/LoadBalancerStrategyFactory.d.ts +2 -1
- package/dist/connection/LoadBalancerStrategyFactory.d.ts.map +1 -1
- package/dist/connection/LoadBalancerStrategyFactory.js +3 -2
- package/dist/connection/LoadBalancerStrategyFactory.js.map +1 -1
- package/dist/connection/TokenProvider.d.ts +4 -1
- package/dist/connection/TokenProvider.d.ts.map +1 -1
- package/dist/connection/TokenProvider.js +5 -1
- package/dist/connection/TokenProvider.js.map +1 -1
- package/dist/connection/fetchOAuthAccessToken.d.ts +2 -1
- package/dist/connection/fetchOAuthAccessToken.d.ts.map +1 -1
- package/dist/connection/fetchOAuthAccessToken.js +3 -2
- package/dist/connection/fetchOAuthAccessToken.js.map +1 -1
- 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/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_ChronicleOptions/when_configuring_keep_alive/with_skip_keep_alive.spec.ts +1 -1
- 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/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
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
// Copyright (c) Cratis. All rights reserved.
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
|
-
import { createHash } from 'node:crypto';
|
|
5
|
-
import { EventObservationState } from '@cratis/chronicle.contracts';
|
|
6
4
|
import { AppendOperationsBroadcaster } from '../eventSequences/AppendOperationsBroadcaster.js';
|
|
7
|
-
import { prepareBatchAppend } from '../eventSequences/prepareBatchAppend.js';
|
|
8
5
|
import { createAppendNotification, mapAppendNotificationCausation } from '../eventSequences/createAppendNotification.js';
|
|
9
6
|
import { createAppendResult } from '../eventSequences/createAppendResult.js';
|
|
10
|
-
import {
|
|
11
|
-
import { getEventTypeMetadata
|
|
7
|
+
import { Guid, type Constructor } from '@cratis/fundamentals';
|
|
8
|
+
import { getEventTypeMetadata } from '../events/eventTypeDecorator.js';
|
|
12
9
|
import { getTagsFor } from '../events/tagDecorator.js';
|
|
13
10
|
import type { AppendedEvent } from '../events/AppendedEvent.js';
|
|
14
|
-
|
|
15
|
-
import { EventType } from '../events/EventType.js';
|
|
16
|
-
import { EventTypeId } from '../events/EventTypeId.js';
|
|
17
|
-
import { EventTypeGeneration } from '../events/EventTypeGeneration.js';
|
|
18
|
-
import { Identity } from '../identity/Identity.js';
|
|
11
|
+
|
|
19
12
|
import type { AppendOptions } from '../eventSequences/AppendOptions.js';
|
|
20
|
-
import { hasNamedTags, singleAppendRoute } from './singleAppendRoute.js';
|
|
21
13
|
import type { AppendResult } from '../eventSequences/AppendResult.js';
|
|
22
14
|
import type { AppendedEventWithResult } from '../eventSequences/AppendedEventWithResult.js';
|
|
23
15
|
import type { EventForEventSourceId } from '../eventSequences/EventForEventSourceId.js';
|
|
@@ -28,31 +20,20 @@ import type { ITransactionalEventSequence } from '../eventSequences/ITransaction
|
|
|
28
20
|
import type { CompleteStreamResult } from '../eventSequences/CompleteStreamResult.js';
|
|
29
21
|
import type { IEventImport } from '../imports/IEventImport.js';
|
|
30
22
|
import type { ImportResult } from '../imports/ImportResult.js';
|
|
31
|
-
import { prepareSingleAppend } from '../eventSequences/prepareSingleAppend.js';
|
|
32
|
-
import { toContractsGuid } from '../connection/Guid.js';
|
|
33
23
|
import { getRemovedConstraintNames } from '../events/constraints/removeConstraint.js';
|
|
34
24
|
import { InProcessConstraints, type WireConstraintViolation } from './InProcessConstraints.js';
|
|
35
|
-
import {
|
|
25
|
+
import { supportsEventField } from './EventFieldSchema.js';
|
|
26
|
+
import { InProcessBatchAppend } from './InProcessBatchAppend.js';
|
|
27
|
+
import { InProcessEventPayload } from './InProcessEventPayload.js';
|
|
28
|
+
import { InProcessEventReadFilter } from './InProcessEventReadFilter.js';
|
|
29
|
+
import { InProcessSingleAppend } from './InProcessSingleAppend.js';
|
|
30
|
+
import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
|
|
36
31
|
import type { EventScenarioOptions } from './EventScenarioOptions.js';
|
|
37
32
|
import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
|
|
38
33
|
|
|
39
34
|
// JS trim() omits U+0085, which the kernel trims. Reject unproven non-ASCII whitespace and controls.
|
|
40
35
|
const unprovenFilterCharacters = /[\u007f-\u009f]|(?=[^\x00-\x7f])\p{White_Space}/u;
|
|
41
36
|
|
|
42
|
-
function resolveStoredSubject(subject: string | undefined, eventSourceId: string): string {
|
|
43
|
-
// Match the kernel's string.IsNullOrWhiteSpace, including U+0085 but not U+FEFF.
|
|
44
|
-
return subject && !/^\p{White_Space}*$/u.test(subject) ? subject : eventSourceId;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function matchesConstrainedValue(value: unknown, content: unknown): boolean {
|
|
48
|
-
// Use production serialization for concepts, not their wrapper object's runtime type.
|
|
49
|
-
// Keep rejecting other unproven conversions, such as a Date assigned to a string field.
|
|
50
|
-
if (value && typeof value === 'object' && [conceptAsTypeKey, 'Guid'].includes(typeKeyOf(value.constructor as Constructor) ?? '')) {
|
|
51
|
-
return JsonSerializer.serialize(value) === JSON.stringify(content);
|
|
52
|
-
}
|
|
53
|
-
return value === content;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
37
|
// Observers ReactorScenario registers to latch unsupported operations, keyed by sequence.
|
|
57
38
|
const unsupportedObservers = new WeakMap<object, (error: UnsupportedEventSequenceOperation) => void>();
|
|
58
39
|
|
|
@@ -75,6 +56,9 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
75
56
|
private readonly _namespace: string;
|
|
76
57
|
private readonly _clock: () => Date;
|
|
77
58
|
private readonly _correlationId?: () => string;
|
|
59
|
+
private readonly _payload: InProcessEventPayload;
|
|
60
|
+
private readonly _singleAppend: InProcessSingleAppend;
|
|
61
|
+
private readonly _batchAppend: InProcessBatchAppend;
|
|
78
62
|
private _setup = false;
|
|
79
63
|
private _allowSeedAppend = false;
|
|
80
64
|
private _stagedSeeds?: AppendedEvent[];
|
|
@@ -132,6 +116,14 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
132
116
|
}
|
|
133
117
|
this._catalog.set(type, metadata);
|
|
134
118
|
}
|
|
119
|
+
const environment: InProcessEventSequenceEnvironment = {
|
|
120
|
+
catalog: this._catalog, store: this._store, namespace: this._namespace, sequenceId: this.id.value,
|
|
121
|
+
clock: () => this._clock(), correlationId: this._correlationId ? () => this._correlationId!() : undefined,
|
|
122
|
+
unsupported: (operation, artifact, reason) => this.unsupported(operation, artifact, reason)
|
|
123
|
+
};
|
|
124
|
+
this._payload = new InProcessEventPayload(environment, this._constraints);
|
|
125
|
+
this._singleAppend = new InProcessSingleAppend(environment, this._payload);
|
|
126
|
+
this._batchAppend = new InProcessBatchAppend(environment, this._payload, (sequence, artifact) => this.success(sequence, artifact));
|
|
135
127
|
}
|
|
136
128
|
|
|
137
129
|
get results(): readonly AppendResult[] { return Object.freeze([...this._results]); }
|
|
@@ -169,72 +161,17 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
169
161
|
get transactional(): ITransactionalEventSequence { throw this.unsupported('transactional', this.id.value, 'Transactions require a kernel.'); }
|
|
170
162
|
|
|
171
163
|
async append(eventSourceId: string, event: object, options?: AppendOptions): Promise<AppendResult> {
|
|
172
|
-
if (this.
|
|
164
|
+
if (this.appendBusy()) {
|
|
173
165
|
throw this.unsupported('append', this.id.value, 'Overlapping calls do not have proven ordering.');
|
|
174
166
|
}
|
|
175
167
|
this._busy = true;
|
|
176
168
|
try {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const route = singleAppendRoute(options, event.constructor.name, (operation, artifact, reason) => this.unsupported(operation, artifact, reason), true);
|
|
180
|
-
const metadata = this._catalog.get(event.constructor);
|
|
181
|
-
if (!metadata) throw this.unsupported('append.event', event.constructor.name, 'Event is not in the selected, validated catalog.');
|
|
182
|
-
let prepared: ReturnType<typeof prepareSingleAppend>;
|
|
183
|
-
let content: Record<string, unknown>;
|
|
184
|
-
try {
|
|
185
|
-
prepared = prepareSingleAppend(event, { subject: options?.subject, correlationId: this._correlationId?.() });
|
|
186
|
-
content = this.checkedContent(event, prepared.content, 'append.content',
|
|
187
|
-
'Content differs from the event schema; null, missing and extra values are not proven.');
|
|
188
|
-
} catch (error) {
|
|
189
|
-
if (error instanceof UnsupportedEventSequenceOperation) throw error;
|
|
190
|
-
throw this.unsupported('append.serialization', event.constructor.name, `Payload or metadata could not be serialized: ${String(error)}.`);
|
|
191
|
-
}
|
|
192
|
-
try {
|
|
193
|
-
toContractsGuid(prepared.correlationId);
|
|
194
|
-
if (!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(prepared.correlationId.toString())) throw new Error('Invalid correlation ID.');
|
|
195
|
-
} catch {
|
|
196
|
-
throw this.unsupported('append.correlationId', event.constructor.name, 'Correlation ID must be a valid GUID.');
|
|
197
|
-
}
|
|
198
|
-
if (prepared.identity !== Identity.system || prepared.causationChain.length !== 2 ||
|
|
199
|
-
Object.keys(prepared.causationChain[0].properties).length !== 0) {
|
|
200
|
-
throw this.unsupported('append.context', event.constructor.name, 'Ambient identity or causation metadata is not fixture-backed.');
|
|
201
|
-
}
|
|
202
|
-
const occurred = this._clock();
|
|
203
|
-
// Date has millisecond precision; only the UTC year range representable by DateTimeOffset is supported.
|
|
204
|
-
if (!(occurred instanceof Date) || Number.isNaN(occurred.getTime()) ||
|
|
205
|
-
occurred.getUTCFullYear() < 1 || occurred.getUTCFullYear() > 9999) {
|
|
206
|
-
throw this.unsupported('append.clock', event.constructor.name, 'Clock must return a valid Date within UTC years 1–9999 (millisecond precision).');
|
|
207
|
-
}
|
|
208
|
-
const canonical = Object.fromEntries(Object.entries(content).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
209
|
-
const hash = createHash('sha256').update(`${prepared.eventType.id.value}|${eventSourceId}|${JSON.stringify(canonical)}`).digest('base64');
|
|
210
|
-
const sequenceNumber = new EventSequenceNumber(BigInt(this._history.length + (this._stagedSeeds?.length ?? 0)));
|
|
211
|
-
const stored: AppendedEvent = {
|
|
212
|
-
eventType: prepared.eventType,
|
|
213
|
-
content,
|
|
214
|
-
context: {
|
|
215
|
-
eventStore: this._store, namespace: this._namespace,
|
|
216
|
-
sequenceNumber: sequenceNumber.value, eventSourceId,
|
|
217
|
-
eventSourceType: route.sourceType, eventStreamType: route.streamType, eventStreamId: route.streamId,
|
|
218
|
-
subject: resolveStoredSubject(prepared.subject, eventSourceId), hash, causedBy: prepared.identity, observationState: EventObservationState.Initial,
|
|
219
|
-
eventType: prepared.eventType, occurred, correlationId: prepared.correlationId.toString(),
|
|
220
|
-
causation: prepared.causationChain.map(item => ({ type: item.type.name, occurred: item.occurred, properties: { ...item.properties } })),
|
|
221
|
-
tags: prepared.tags.map(tag => new Tag(tag)),
|
|
222
|
-
namedTags: []
|
|
223
|
-
}
|
|
224
|
-
};
|
|
169
|
+
const { prepared, stored, sequenceNumber } = this._singleAppend.prepare(eventSourceId, event, options,
|
|
170
|
+
this._history.length + (this._stagedSeeds?.length ?? 0));
|
|
225
171
|
const violations = this.validateConstraints([...this._history, ...(this._stagedSeeds ?? [])], [stored]);
|
|
226
172
|
const result = violations.length ? this.rejected(violations) : this.success(sequenceNumber, event.constructor.name);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
else this._history.push(this.snapshot(stored));
|
|
230
|
-
}
|
|
231
|
-
if (!this._setup) this._results.push(result);
|
|
232
|
-
if (this._stagedNotifications || this.appendOperations.hasSubscribers) {
|
|
233
|
-
const notification = [createAppendNotification(eventSourceId, event, result,
|
|
234
|
-
prepared.correlationId.toString(), mapAppendNotificationCausation(prepared.causationChain), prepared.tags)];
|
|
235
|
-
if (this._stagedNotifications) this._stagedNotifications.push(notification);
|
|
236
|
-
else this.appendOperations.publish(notification);
|
|
237
|
-
}
|
|
173
|
+
this.commitSingle(stored, result);
|
|
174
|
+
this.notifySingle(eventSourceId, event, result, prepared);
|
|
238
175
|
return result;
|
|
239
176
|
} finally {
|
|
240
177
|
// Keep the append in flight until its promise crosses an async boundary.
|
|
@@ -243,94 +180,35 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
243
180
|
}
|
|
244
181
|
}
|
|
245
182
|
|
|
183
|
+
private appendBusy(): boolean {
|
|
184
|
+
return this._busy || (this._setup && !this._allowSeedAppend);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private commitSingle(stored: AppendedEvent, result: AppendResult): void {
|
|
188
|
+
if (result.isSuccess) {
|
|
189
|
+
if (this._stagedSeeds) this._stagedSeeds.push(this.snapshot(stored));
|
|
190
|
+
else this._history.push(this.snapshot(stored));
|
|
191
|
+
}
|
|
192
|
+
if (!this._setup) this._results.push(result);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private notifySingle(eventSourceId: string, event: object, result: AppendResult, prepared: ReturnType<InProcessSingleAppend['prepare']>['prepared']): void {
|
|
196
|
+
if (this._stagedNotifications || this.appendOperations.hasSubscribers) {
|
|
197
|
+
const notification = [createAppendNotification(eventSourceId, event, result,
|
|
198
|
+
prepared.correlationId.toString(), mapAppendNotificationCausation(prepared.causationChain), prepared.tags)];
|
|
199
|
+
if (this._stagedNotifications) this._stagedNotifications.push(notification);
|
|
200
|
+
else this.appendOperations.publish(notification);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
246
204
|
appendMany(eventSourceId: string, events: object[], options?: AppendOptions): Promise<AppendResult[]>;
|
|
247
205
|
appendMany(events: EventForEventSourceId[], options?: AppendOptions): Promise<AppendResult[]>;
|
|
248
206
|
async appendMany(sourceOrEvents: string | EventForEventSourceId[], eventsOrOptions?: object[] | AppendOptions, options?: AppendOptions): Promise<AppendResult[]> {
|
|
249
207
|
if (this._busy || this._setup) throw this.unsupported('appendMany', this.id.value, 'Overlapping calls do not have proven ordering.');
|
|
250
208
|
this._busy = true;
|
|
251
209
|
try {
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
if (!Array.isArray(entries)) throw this.unsupported('appendMany.arguments', this.id.value, 'Events must be an array.');
|
|
255
|
-
if (!entries.length) throw this.unsupported('appendMany.empty', this.id.value, 'The kernel rejects an empty batch.');
|
|
256
|
-
this.validateBatchOptions(shared);
|
|
257
|
-
if (shared?.occurred !== undefined) this.checkedDate(shared.occurred, 'appendMany.occurred');
|
|
258
|
-
for (const entry of entries) {
|
|
259
|
-
if (typeof sourceOrEvents === 'string') break;
|
|
260
|
-
if (!entry || typeof entry !== 'object' || Reflect.ownKeys(entry).some(key =>
|
|
261
|
-
!['eventSourceId', 'event', 'eventSourceType', 'eventStreamType', 'eventStreamId', 'subject', 'occurred', 'tags', 'namedTags'].includes(String(key)))) {
|
|
262
|
-
throw this.unsupported('appendMany.entry', this.id.value, 'Unrecognized per-entry metadata.');
|
|
263
|
-
}
|
|
264
|
-
const individual = entry as EventForEventSourceId;
|
|
265
|
-
if (hasNamedTags(individual.namedTags)) {
|
|
266
|
-
throw this.unsupported('appendMany.namedTags', this.id.value, 'Named tags are not fixture-backed.');
|
|
267
|
-
}
|
|
268
|
-
if (individual.occurred !== undefined) this.checkedDate(individual.occurred, 'appendMany.occurred');
|
|
269
|
-
if (individual.subject !== undefined && individual.subject !== null && typeof individual.subject !== 'string') {
|
|
270
|
-
throw this.unsupported('appendMany.subject', this.id.value, 'Subject must be a string.');
|
|
271
|
-
}
|
|
272
|
-
const tags = individual.tags;
|
|
273
|
-
if (tags && (!Array.isArray(tags) || tags.some(tag => typeof tag !== 'string'))) {
|
|
274
|
-
throw this.unsupported('appendMany.tags', this.id.value, 'Only plain string tags are fixture-backed.');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
let prepared: ReturnType<typeof prepareBatchAppend>;
|
|
278
|
-
try {
|
|
279
|
-
const batchOptions: AppendOptions | undefined = shared?.correlationId === undefined && this._correlationId
|
|
280
|
-
? { correlationId: this._correlationId(), sourceType: shared?.sourceType, streamType: shared?.streamType,
|
|
281
|
-
streamId: shared?.streamId, subject: shared?.subject, occurred: shared?.occurred, tags: shared?.tags,
|
|
282
|
-
namedTags: shared?.namedTags }
|
|
283
|
-
: shared;
|
|
284
|
-
if (batchOptions?.correlationId !== undefined) this.validateGuid(batchOptions.correlationId, 'appendMany.correlationId');
|
|
285
|
-
prepared = typeof sourceOrEvents === 'string'
|
|
286
|
-
? prepareBatchAppend(sourceOrEvents, entries as object[], batchOptions)
|
|
287
|
-
: prepareBatchAppend(sourceOrEvents, batchOptions);
|
|
288
|
-
} catch (error) {
|
|
289
|
-
if (error instanceof UnsupportedEventSequenceOperation) throw error;
|
|
290
|
-
throw this.unsupported('appendMany.serialization', this.id.value, `Batch preparation failed: ${String(error)}.`);
|
|
291
|
-
}
|
|
292
|
-
const { eventsForEventSourceIds, eventsToAppend, correlationId, batchCausationChain, identity } = prepared;
|
|
293
|
-
this.validateGuid(correlationId, 'appendMany.correlationId');
|
|
294
|
-
if (identity !== Identity.system || batchCausationChain.length !== 2 ||
|
|
295
|
-
Object.keys(batchCausationChain[0].properties).length !== 0 ||
|
|
296
|
-
batchCausationChain[1].type.name !== 'TypeScriptClient.AppendMany' ||
|
|
297
|
-
batchCausationChain[1].properties.count !== String(entries.length)) {
|
|
298
|
-
throw this.unsupported('appendMany.context', this.id.value, 'Ambient identity or causation metadata is not fixture-backed.');
|
|
299
|
-
}
|
|
300
|
-
const staged = eventsForEventSourceIds.map(({ eventSourceId, event }, index) => {
|
|
301
|
-
if (!event || typeof event !== 'object' || !this._catalog.has(event.constructor)) {
|
|
302
|
-
throw this.unsupported('appendMany.event', event?.constructor?.name ?? this.id.value, 'Event is not in the selected catalog.');
|
|
303
|
-
}
|
|
304
|
-
this.validateSource(eventSourceId, 'appendMany.source');
|
|
305
|
-
const wire = eventsToAppend[index];
|
|
306
|
-
for (const [name, value] of Object.entries({ sourceType: wire.EventSourceType, streamType: wire.EventStreamType,
|
|
307
|
-
streamId: wire.EventStreamId })) {
|
|
308
|
-
const identifiers = /^[A-Za-z0-9_-]*$/;
|
|
309
|
-
if (value !== undefined && (typeof value !== 'string' || !identifiers.test(value))) {
|
|
310
|
-
throw this.unsupported(`appendMany.${name}`, String(value), 'Only simple metadata identifiers are fixture-backed.');
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
if (wire.Tags.some(tag => !/^[A-Za-z0-9_-]+$/.test(tag))) {
|
|
314
|
-
throw this.unsupported('appendMany.tags', event.constructor.name, 'Only simple string tags are fixture-backed.');
|
|
315
|
-
}
|
|
316
|
-
const occurred = wire.Occurred ? this.checkedDate(new Date(wire.Occurred.Value), 'appendMany.occurred')
|
|
317
|
-
: this.checkedDate(this._clock(), 'appendMany.clock');
|
|
318
|
-
const content = this.checkedContent(event, wire.Content, 'appendMany.content');
|
|
319
|
-
const canonical = Object.fromEntries(Object.entries(content).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
320
|
-
const hash = createHash('sha256').update(`${wire.EventType.Id}|${eventSourceId}|${JSON.stringify(canonical)}`).digest('base64');
|
|
321
|
-
const sequenceNumber = new EventSequenceNumber(BigInt(this._history.length + index));
|
|
322
|
-
const eventType = getEventTypeFor(event.constructor);
|
|
323
|
-
const stored: AppendedEvent = { eventType, content, context: {
|
|
324
|
-
eventStore: this._store, namespace: this._namespace, sequenceNumber: sequenceNumber.value, eventSourceId,
|
|
325
|
-
eventSourceType: wire.EventSourceType || 'Default', eventStreamType: wire.EventStreamType || 'All',
|
|
326
|
-
eventStreamId: wire.EventStreamId || 'Default', subject: resolveStoredSubject(wire.Subject, eventSourceId), hash, causedBy: identity,
|
|
327
|
-
observationState: EventObservationState.Initial, eventType, occurred, correlationId: correlationId.toString(),
|
|
328
|
-
causation: batchCausationChain.map(item => ({ type: item.type.name, occurred: item.occurred, properties: { ...item.properties } })),
|
|
329
|
-
tags: wire.Tags.map(tag => new Tag(tag)),
|
|
330
|
-
namedTags: []
|
|
331
|
-
} };
|
|
332
|
-
return { stored, result: this.success(sequenceNumber, event.constructor.name) };
|
|
333
|
-
});
|
|
210
|
+
const { prepared, staged } = this._batchAppend.prepare(sourceOrEvents, eventsOrOptions, options, this._history.length);
|
|
211
|
+
const { eventsForEventSourceIds, eventsToAppend, correlationId, batchCausationChain } = prepared;
|
|
334
212
|
// The kernel validates the entire batch before persisting any events or allocating sequences.
|
|
335
213
|
const violations = this.validateConstraints(this._history, staged.map(item => item.stored));
|
|
336
214
|
const results = violations.length ? staged.map(() => this.rejected(violations)) : staged.map(item => item.result);
|
|
@@ -355,12 +233,8 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
355
233
|
async getTailSequenceNumber(source?: string, sourceType?: string, streamType?: string, streamId?: string, types?: Constructor[]): Promise<EventSequenceNumber> {
|
|
356
234
|
if (source !== undefined) this.validateReadSource('getTailSequenceNumber.source', source);
|
|
357
235
|
this.validateRouteFilters('getTailSequenceNumber.filters', sourceType, streamType, streamId);
|
|
358
|
-
const
|
|
359
|
-
const last = [...this._history].reverse().find(event => (
|
|
360
|
-
(sourceType === undefined || sourceType === 'Default' || event.context.eventSourceType === sourceType) &&
|
|
361
|
-
(streamType === undefined || streamType === 'All' || event.context.eventStreamType === streamType) &&
|
|
362
|
-
(streamId === undefined || streamId === 'Default' || event.context.eventStreamId === streamId) &&
|
|
363
|
-
(!ids.length || ids.includes(event.eventType.id.value)));
|
|
236
|
+
const filter = new InProcessEventReadFilter({ source, sourceType, streamType, streamId, ids: this.filterIds(types) });
|
|
237
|
+
const last = [...this._history].reverse().find(event => filter.matches(event));
|
|
364
238
|
return last ? new EventSequenceNumber(last.context.sequenceNumber) : EventSequenceNumber.unset;
|
|
365
239
|
}
|
|
366
240
|
|
|
@@ -377,11 +251,8 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
377
251
|
if (!types.length) throw this.unsupported('getForEventSourceIdAndEventTypes.filters', source, 'Explicit event types are required.');
|
|
378
252
|
this.validateReadSource('getForEventSourceIdAndEventTypes.source', source);
|
|
379
253
|
this.validateRouteFilters('getForEventSourceIdAndEventTypes.filters', sourceType, streamType, streamId);
|
|
380
|
-
const
|
|
381
|
-
return this._history.filter(event => event.
|
|
382
|
-
(sourceType === undefined || sourceType === 'Default' || event.context.eventSourceType === sourceType) &&
|
|
383
|
-
(streamType === undefined || streamType === 'All' || event.context.eventStreamType === streamType) &&
|
|
384
|
-
(streamId === undefined || streamId === 'Default' || event.context.eventStreamId === streamId)).map(event => this.snapshot(event));
|
|
254
|
+
const filter = new InProcessEventReadFilter({ source, sourceType, streamType, streamId, ids: this.filterIds(types) });
|
|
255
|
+
return this._history.filter(event => filter.matches(event)).map(event => this.snapshot(event));
|
|
385
256
|
}
|
|
386
257
|
|
|
387
258
|
async getFromSequenceNumber(sequence: EventSequenceNumber, source?: string, types?: Constructor[]): Promise<AppendedEvent[]> {
|
|
@@ -389,10 +260,8 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
389
260
|
throw this.unsupported('getFromSequenceNumber.sequenceNumber', sequence.value.toString(), 'Sequence numbers must fit unsigned 64-bit wire values.');
|
|
390
261
|
}
|
|
391
262
|
if (source !== undefined) this.validateReadSource('getFromSequenceNumber.source', source);
|
|
392
|
-
const
|
|
393
|
-
return this._history.filter(event => event.context.sequenceNumber >= sequence.value &&
|
|
394
|
-
(source === undefined || event.context.eventSourceId === source) &&
|
|
395
|
-
(!ids.length || ids.includes(event.eventType.id.value))).map(event => this.snapshot(event));
|
|
263
|
+
const filter = new InProcessEventReadFilter({ source, ids: this.filterIds(types) });
|
|
264
|
+
return this._history.filter(event => event.context.sequenceNumber >= sequence.value && filter.matches(event)).map(event => this.snapshot(event));
|
|
396
265
|
}
|
|
397
266
|
|
|
398
267
|
async compensate(): Promise<AppendResult> { throw this.unsupported('compensate', this.id.value, 'Compensation requires kernel storage.'); }
|
|
@@ -413,70 +282,14 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
413
282
|
|
|
414
283
|
private validateRouteFilters(operation: string, ...filters: (string | undefined)[]): void {
|
|
415
284
|
for (const filter of filters) {
|
|
416
|
-
if (filter !== undefined && (
|
|
285
|
+
if (filter !== undefined && !this.simpleRouteFilter(filter)) {
|
|
417
286
|
throw this.unsupported(operation, String(filter), 'Only simple, nonblank route filters are fixture-backed.');
|
|
418
287
|
}
|
|
419
288
|
}
|
|
420
289
|
}
|
|
421
290
|
|
|
422
|
-
private
|
|
423
|
-
|
|
424
|
-
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
425
|
-
throw this.unsupported('appendMany.options', this.id.value, 'Append options must be an object.');
|
|
426
|
-
}
|
|
427
|
-
if (hasNamedTags(options.namedTags)) {
|
|
428
|
-
throw this.unsupported('appendMany.namedTags', this.id.value, 'Named tags are not fixture-backed.');
|
|
429
|
-
}
|
|
430
|
-
const allowed = ['correlationId', 'sourceType', 'streamType', 'streamId', 'subject', 'occurred', 'tags', 'namedTags'];
|
|
431
|
-
if (Reflect.ownKeys(options).some(key => !allowed.includes(String(key))) ||
|
|
432
|
-
options.concurrencyScope !== undefined || options.concurrencyScopes !== undefined || options.eventSourceId !== undefined) {
|
|
433
|
-
throw this.unsupported('appendMany.options', this.id.value, 'Concurrency and unrecognized metadata are not fixture-backed.');
|
|
434
|
-
}
|
|
435
|
-
if (options.subject !== undefined && options.subject !== null && typeof options.subject !== 'string') {
|
|
436
|
-
throw this.unsupported('appendMany.subject', this.id.value, 'Subject must be a string.');
|
|
437
|
-
}
|
|
438
|
-
if (options.tags && (!Array.isArray(options.tags) || options.tags.some(tag => typeof tag !== 'string'))) {
|
|
439
|
-
throw this.unsupported('appendMany.tags', this.id.value, 'Only plain string tags are fixture-backed.');
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
private validateGuid(value: string | Guid, operation: string): void {
|
|
444
|
-
try {
|
|
445
|
-
toContractsGuid(Guid.as(value));
|
|
446
|
-
if (!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(value.toString())) throw new Error('Invalid GUID.');
|
|
447
|
-
} catch { throw this.unsupported(operation, this.id.value, 'Correlation ID must be a valid GUID.'); }
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
private checkedDate(value: Date, operation: string): Date {
|
|
451
|
-
if (!(value instanceof Date) || Number.isNaN(value.getTime()) || value.getUTCFullYear() < 1 || value.getUTCFullYear() > 9999) {
|
|
452
|
-
throw this.unsupported(operation, this.id.value, 'Occurrence must be within UTC years 1–9999 at millisecond precision.');
|
|
453
|
-
}
|
|
454
|
-
return new Date(value);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
private validateSource(source: string, operation: string): void {
|
|
458
|
-
if (typeof source !== 'string' || !/^[A-Za-z0-9_-]+$/.test(source)) {
|
|
459
|
-
throw this.unsupported(operation, String(source), 'Only simple source identifiers are fixture-backed.');
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
private checkedContent(event: object, serialized: string, operation: string,
|
|
464
|
-
mismatchReason = 'Content differs from the event schema.'): Record<string, unknown> {
|
|
465
|
-
let content: Record<string, unknown>;
|
|
466
|
-
try { content = JSON.parse(serialized) as Record<string, unknown>; }
|
|
467
|
-
catch { throw this.unsupported(operation, event.constructor.name, 'Content must be valid JSON.'); }
|
|
468
|
-
const metadata = this._catalog.get(event.constructor)!;
|
|
469
|
-
const properties = metadata.schema.properties!;
|
|
470
|
-
if (!content || typeof content !== 'object' || Array.isArray(content) ||
|
|
471
|
-
Object.keys(content).length !== Object.keys(properties).length ||
|
|
472
|
-
Object.entries(properties).some(([key, property]) => !Object.hasOwn(content, key) || !matchesEventField(content[key], property) ||
|
|
473
|
-
(this._constraints?.isConstrainedProperty(metadata.eventType.id.value, key) &&
|
|
474
|
-
!matchesConstrainedValue(Reflect.get(event, key), content[key])) ||
|
|
475
|
-
(property.type === 'string' && property.format === undefined &&
|
|
476
|
-
!/^[\x20-\x21\x23-\x5b\x5d-\x7e\u00e9]*$/.test(content[key] as string)))) {
|
|
477
|
-
throw this.unsupported(operation, event.constructor.name, mismatchReason);
|
|
478
|
-
}
|
|
479
|
-
return content;
|
|
291
|
+
private simpleRouteFilter(filter: string): boolean {
|
|
292
|
+
return typeof filter === 'string' && /^[A-Za-z0-9_-]+$/.test(filter);
|
|
480
293
|
}
|
|
481
294
|
|
|
482
295
|
private validateConstraints(history: readonly AppendedEvent[], incoming: readonly AppendedEvent[]): WireConstraintViolation[] {
|
|
@@ -499,26 +312,19 @@ export class InProcessEventSequence implements IEventSequence {
|
|
|
499
312
|
}
|
|
500
313
|
|
|
501
314
|
private snapshot(event: AppendedEvent): AppendedEvent {
|
|
502
|
-
|
|
503
|
-
new EventTypeGeneration(event.eventType.generation.value), event.eventType.tombstone);
|
|
504
|
-
const causedBy = event.context.causedBy;
|
|
505
|
-
return {
|
|
506
|
-
eventType,
|
|
507
|
-
content: JSON.parse(JSON.stringify(event.content)) as Record<string, unknown>,
|
|
508
|
-
context: { ...event.context, eventType, occurred: new Date(event.context.occurred),
|
|
509
|
-
causedBy: causedBy && new Identity(causedBy.subject, causedBy.name, causedBy.userName, causedBy.onBehalfOf),
|
|
510
|
-
causation: event.context.causation.map(item => ({ ...item, occurred: item.occurred && new Date(item.occurred), properties: { ...item.properties } })),
|
|
511
|
-
tags: event.context.tags.map(item => new Tag(item.value)),
|
|
512
|
-
namedTags: [...(event.context.namedTags ?? [])] }
|
|
513
|
-
};
|
|
315
|
+
return this._payload.snapshot(event);
|
|
514
316
|
}
|
|
515
317
|
|
|
516
318
|
private validateReadSource(operation: string, source: string): void {
|
|
517
|
-
if (!
|
|
319
|
+
if (!this.simpleReadSource(source)) {
|
|
518
320
|
throw this.unsupported(operation, source, 'Blank and padded source filters have unproven kernel normalization.');
|
|
519
321
|
}
|
|
520
322
|
}
|
|
521
323
|
|
|
324
|
+
private simpleReadSource(source: string): boolean {
|
|
325
|
+
return !!source.trim() && source === source.trim() && !unprovenFilterCharacters.test(source);
|
|
326
|
+
}
|
|
327
|
+
|
|
522
328
|
private unsupported(operation: string, artifact: string, reason: string): UnsupportedEventSequenceOperation {
|
|
523
329
|
const error = new UnsupportedEventSequenceOperation(operation, artifact, reason);
|
|
524
330
|
unsupportedObservers.get(this)?.(error);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import type { getEventTypeMetadata } from '../events/eventTypeDecorator.js';
|
|
5
|
+
import type { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
|
|
6
|
+
|
|
7
|
+
/** Scenario-local dependencies used while preparing, but never committing, appends. */
|
|
8
|
+
export interface InProcessEventSequenceEnvironment {
|
|
9
|
+
readonly catalog: ReadonlyMap<Function, ReturnType<typeof getEventTypeMetadata>>;
|
|
10
|
+
readonly store: string;
|
|
11
|
+
readonly namespace: string;
|
|
12
|
+
readonly clock: () => Date;
|
|
13
|
+
readonly correlationId?: () => string;
|
|
14
|
+
readonly unsupported: (operation: string, artifact: string, reason: string) => UnsupportedEventSequenceOperation;
|
|
15
|
+
readonly sequenceId: string;
|
|
16
|
+
}
|
|
@@ -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 { toContractsGuid } from '../connection/Guid.js';
|
|
5
|
+
import type { AppendedEvent } from '../events/AppendedEvent.js';
|
|
6
|
+
import { EventObservationState } from '@cratis/chronicle.contracts';
|
|
7
|
+
import { Tag } from '../events/Tag.js';
|
|
8
|
+
import type { AppendOptions } from '../eventSequences/AppendOptions.js';
|
|
9
|
+
import { EventSequenceNumber } from '../eventSequences/EventSequenceNumber.js';
|
|
10
|
+
import { prepareSingleAppend } from '../eventSequences/prepareSingleAppend.js';
|
|
11
|
+
import { InProcessAppendMetadata } from './InProcessAppendMetadata.js';
|
|
12
|
+
import { InProcessEventPayload } from './InProcessEventPayload.js';
|
|
13
|
+
import type { InProcessEventSequenceEnvironment } from './InProcessEventSequenceEnvironment.js';
|
|
14
|
+
import { singleAppendRoute } from './singleAppendRoute.js';
|
|
15
|
+
import { UnsupportedEventSequenceOperation } from './UnsupportedEventSequenceOperation.js';
|
|
16
|
+
|
|
17
|
+
/** Prepares one append without allocating history, results, or notifications. */
|
|
18
|
+
export class InProcessSingleAppend {
|
|
19
|
+
private readonly metadata: InProcessAppendMetadata;
|
|
20
|
+
|
|
21
|
+
constructor(private readonly environment: InProcessEventSequenceEnvironment, private readonly payload: InProcessEventPayload) {
|
|
22
|
+
this.metadata = new InProcessAppendMetadata(environment);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
prepare(eventSourceId: string, event: object, options: AppendOptions | undefined, position: number) {
|
|
26
|
+
this.eventInstance(event);
|
|
27
|
+
if (!/^[A-Za-z0-9_-]+$/.test(eventSourceId)) throw this.environment.unsupported('append.source', eventSourceId, 'Only simple source identifiers are fixture-backed.');
|
|
28
|
+
const route = singleAppendRoute(options, event.constructor.name, this.environment.unsupported, true);
|
|
29
|
+
if (!this.environment.catalog.get(event.constructor)) throw this.environment.unsupported('append.event', event.constructor.name, 'Event is not in the selected, validated catalog.');
|
|
30
|
+
const { prepared, content } = this.serialize(event, options);
|
|
31
|
+
this.correlation(prepared, event);
|
|
32
|
+
this.context(prepared, event);
|
|
33
|
+
const occurred = this.occurred(event);
|
|
34
|
+
const hash = this.payload.hash(prepared.eventType.id.value, eventSourceId, content);
|
|
35
|
+
const sequenceNumber = new EventSequenceNumber(BigInt(position));
|
|
36
|
+
const stored: AppendedEvent = {
|
|
37
|
+
eventType: prepared.eventType,
|
|
38
|
+
content,
|
|
39
|
+
context: {
|
|
40
|
+
eventStore: this.environment.store, namespace: this.environment.namespace,
|
|
41
|
+
sequenceNumber: sequenceNumber.value, eventSourceId,
|
|
42
|
+
eventSourceType: route.sourceType, eventStreamType: route.streamType, eventStreamId: route.streamId,
|
|
43
|
+
subject: this.metadata.storedSubject(prepared.subject, eventSourceId), hash, causedBy: prepared.identity, observationState: EventObservationState.Initial,
|
|
44
|
+
eventType: prepared.eventType, occurred, correlationId: prepared.correlationId.toString(),
|
|
45
|
+
causation: prepared.causationChain.map(item => ({ type: item.type.name, occurred: item.occurred, properties: { ...item.properties } })),
|
|
46
|
+
tags: prepared.tags.map(tag => new Tag(tag)), namedTags: []
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return { prepared, stored, sequenceNumber };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private eventInstance(event: object): void {
|
|
53
|
+
if (!event || typeof event !== 'object') throw this.environment.unsupported('append.event', this.environment.sequenceId, 'Only registered event instances are supported.');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private serialize(event: object, options?: AppendOptions) {
|
|
57
|
+
try {
|
|
58
|
+
const prepared = prepareSingleAppend(event, this.options(options));
|
|
59
|
+
const content = this.payload.checkedContent(event, prepared.content, 'append.content',
|
|
60
|
+
'Content differs from the event schema; null, missing and extra values are not proven.');
|
|
61
|
+
return { prepared, content };
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (error instanceof UnsupportedEventSequenceOperation) throw error;
|
|
64
|
+
throw this.environment.unsupported('append.serialization', event.constructor.name, `Payload or metadata could not be serialized: ${String(error)}.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private options(options?: AppendOptions): AppendOptions {
|
|
69
|
+
return { subject: options?.subject, correlationId: this.environment.correlationId?.() };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private correlation(prepared: ReturnType<typeof prepareSingleAppend>, event: object): void {
|
|
73
|
+
try {
|
|
74
|
+
toContractsGuid(prepared.correlationId);
|
|
75
|
+
if (!/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(prepared.correlationId.toString())) throw new Error('Invalid correlation ID.');
|
|
76
|
+
} catch {
|
|
77
|
+
throw this.environment.unsupported('append.correlationId', event.constructor.name, 'Correlation ID must be a valid GUID.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private context(prepared: ReturnType<typeof prepareSingleAppend>, event: object): void {
|
|
82
|
+
if (!this.metadata.ambientContext(prepared.identity, prepared.causationChain)) {
|
|
83
|
+
throw this.environment.unsupported('append.context', event.constructor.name, 'Ambient identity or causation metadata is not fixture-backed.');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private occurred(event: object): Date {
|
|
88
|
+
const occurred = this.environment.clock();
|
|
89
|
+
// Date has millisecond precision; only the UTC year range representable by DateTimeOffset is supported.
|
|
90
|
+
if (!(occurred instanceof Date) || !this.validTime(occurred)) {
|
|
91
|
+
throw this.environment.unsupported('append.clock', event.constructor.name, 'Clock must return a valid Date within UTC years 1–9999 (millisecond precision).');
|
|
92
|
+
}
|
|
93
|
+
return occurred;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private validTime(value: Date): boolean {
|
|
97
|
+
return !Number.isNaN(value.getTime()) && value.getUTCFullYear() >= 1 && value.getUTCFullYear() <= 9999;
|
|
98
|
+
}
|
|
99
|
+
}
|