diff --git a/CHANGELOG.md b/CHANGELOG.md index a61e9da..5abd119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Remove `IEventStoreManagementClient` and move `DeleteStreamAsync` method to `IEventStoreClient`. + ## [1.14.11] - 2024-12-09 ### Added diff --git a/src/Atc.Cosmos.EventStore/DependencyInjection/ServiceCollectionExtensions.cs b/src/Atc.Cosmos.EventStore/DependencyInjection/ServiceCollectionExtensions.cs index 03f6b4a..e81e1a8 100644 --- a/src/Atc.Cosmos.EventStore/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Atc.Cosmos.EventStore/DependencyInjection/ServiceCollectionExtensions.cs @@ -16,7 +16,6 @@ public static IServiceCollection AddEventStore( { services.TryAddSingleton(); services.TryAddSingleton(); - services.TryAddSingleton(); var configureOptions = new EventStoreOptionsBuilder(services); configure?.Invoke(configureOptions); diff --git a/src/Atc.Cosmos.EventStore/EventStoreClient.cs b/src/Atc.Cosmos.EventStore/EventStoreClient.cs index de9a4ef..953a101 100644 --- a/src/Atc.Cosmos.EventStore/EventStoreClient.cs +++ b/src/Atc.Cosmos.EventStore/EventStoreClient.cs @@ -13,6 +13,7 @@ internal class EventStoreClient : IEventStoreClient private readonly IStreamCheckpointReader checkpointReader; private readonly IStreamSubscriptionFactory subscriptionFactory; private readonly IStreamSubscriptionRemover subscriptionRemover; + private readonly IStreamDeleter streamDeleter; public EventStoreClient( IStreamWriter streamWriter, @@ -22,7 +23,8 @@ public EventStoreClient( IStreamCheckpointWriter checkpointWriter, IStreamCheckpointReader checkpointReader, IStreamSubscriptionFactory subscriptionFactory, - IStreamSubscriptionRemover subscriptionRemover) + IStreamSubscriptionRemover subscriptionRemover, + IStreamDeleter streamDeleter) { this.streamWriter = streamWriter; this.streamReader = streamReader; @@ -32,6 +34,7 @@ public EventStoreClient( this.checkpointReader = checkpointReader; this.subscriptionFactory = subscriptionFactory; this.subscriptionRemover = subscriptionRemover; + this.streamDeleter = streamDeleter; } public Task DeleteSubscriptionAsync( @@ -130,4 +133,9 @@ public Task SetStreamCheckpointAsync( streamId, cancellationToken) .ConfigureAwait(false); + + public Task DeleteStreamAsync( + StreamId streamId, + CancellationToken cancellationToken = default) + => streamDeleter.DeleteAsync(streamId, cancellationToken); } \ No newline at end of file diff --git a/src/Atc.Cosmos.EventStore/EventStoreManagementClient.cs b/src/Atc.Cosmos.EventStore/EventStoreManagementClient.cs deleted file mode 100644 index f6dcc8a..0000000 --- a/src/Atc.Cosmos.EventStore/EventStoreManagementClient.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Atc.Cosmos.EventStore.Streams; - -namespace Atc.Cosmos.EventStore; - -internal class EventStoreManagementClient : IEventStoreManagementClient -{ - private readonly IStreamDeleter streamDeleter; - - public EventStoreManagementClient(IStreamDeleter streamDeleter) - { - this.streamDeleter = streamDeleter; - } - - public Task DeleteStreamAsync( - StreamId streamId, - CancellationToken cancellationToken = default) - => streamDeleter.DeleteAsync(streamId, cancellationToken); - - public Task PurgeStreamAsync( - StreamId streamId, - StreamVersion version, - long count, - CancellationToken cancellationToken = default) - => throw new NotImplementedException(); - - public Task RetireStreamAsync( - StreamId streamId, - StreamVersion? expectedVersion = default, - CancellationToken cancellationToken = default) - => throw new System.NotImplementedException(); -} \ No newline at end of file diff --git a/src/Atc.Cosmos.EventStore/IEventStoreClient.cs b/src/Atc.Cosmos.EventStore/IEventStoreClient.cs index 8aecf05..c5449fc 100644 --- a/src/Atc.Cosmos.EventStore/IEventStoreClient.cs +++ b/src/Atc.Cosmos.EventStore/IEventStoreClient.cs @@ -129,4 +129,15 @@ Task SetStreamCheckpointAsync( string name, StreamId streamId, CancellationToken cancellationToken = default); + + /// + /// Deletes an entire stream. + /// + /// Attempting to write to a deleted stream will create a new empty stream. + /// Id of the event stream to delete. + /// (Optional) representing request cancellation. + /// A representing the asynchronous operation. + Task DeleteStreamAsync( + StreamId streamId, + CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Atc.Cosmos.EventStore/IEventStoreManagementClient.cs b/src/Atc.Cosmos.EventStore/IEventStoreManagementClient.cs deleted file mode 100644 index 8b4d022..0000000 --- a/src/Atc.Cosmos.EventStore/IEventStoreManagementClient.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace Atc.Cosmos.EventStore; - -internal interface IEventStoreManagementClient -{ - /// - /// Mark stream as closed, preventing any further writes. - /// - /// - /// Set to the current stream version to ensure no new events has been written to the - /// stream prior to executing the delete operation. - /// - /// Id of the event stream to delete. - /// (Optional) Specify the expected version the stream to be at to allow deletion. - /// (Optional) representing request cancellation. - /// Response of the end operation. - Task RetireStreamAsync( - StreamId streamId, - StreamVersion? expectedVersion = default, - CancellationToken cancellationToken = default); - - /// - /// Purge events from a stream. - /// - /// - /// Using a negative value for will purge backwards from .
- /// To purge the entire stream set to and to 0.
- /// - /// This operation can not be revoked as purged events within the stream will be deleted. - ///
- /// Id of the event stream to purge. - /// Specifies the version of the first event to purge from stream. - /// Number of events to purge. - /// (Optional) representing request cancellation. - /// A representing the asynchronous operation. - Task PurgeStreamAsync( - StreamId streamId, - StreamVersion version, - long count, - CancellationToken cancellationToken = default); - - /// - /// Deletes an entire stream. - /// - /// Attempting to write to a deleted stream will create a new empty stream. - /// Id of the event stream to delete. - /// (Optional) representing request cancellation. - /// A representing the asynchronous operation. - Task DeleteStreamAsync( - StreamId streamId, - CancellationToken cancellationToken = default); -} \ No newline at end of file diff --git a/test/Atc.Cosmos.EventStore.Tests/EventStoreClientTests.cs b/test/Atc.Cosmos.EventStore.Tests/EventStoreClientTests.cs index 87df0e0..4da9fe8 100644 --- a/test/Atc.Cosmos.EventStore.Tests/EventStoreClientTests.cs +++ b/test/Atc.Cosmos.EventStore.Tests/EventStoreClientTests.cs @@ -231,4 +231,22 @@ internal Task Should_Throw_On_GetStreamCheckpoint_Without_State_When_Name_IsNull .Awaiting(() => sut.GetStreamCheckpointAsync(null, streamId, cancellationToken)) .Should() .ThrowAsync(); + + [Theory, AutoNSubstituteData] + internal async Task Should_DeleteStream( + [Frozen] IStreamDeleter deleter, + EventStoreClient sut, + StreamId streamId, + CancellationToken cancellationToken) + { + await sut.DeleteStreamAsync( + streamId, + cancellationToken: cancellationToken); + + _ = deleter + .Received(1) + .DeleteAsync( + streamId, + cancellationToken); + } } \ No newline at end of file diff --git a/test/Atc.Cosmos.EventStore.Tests/EventStoreManagementClientTests.cs b/test/Atc.Cosmos.EventStore.Tests/EventStoreManagementClientTests.cs deleted file mode 100644 index 6c1c670..0000000 --- a/test/Atc.Cosmos.EventStore.Tests/EventStoreManagementClientTests.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Atc.Cosmos.EventStore.Streams; -using Atc.Test; -using AutoFixture.Xunit2; -using FluentAssertions; -using NSubstitute; -using Xunit; - -namespace Atc.Cosmos.EventStore.Tests; - -public class EventStoreManagementClientTests -{ - [Theory, AutoNSubstituteData] - internal async Task Should_DeleteStream( - [Frozen] IStreamDeleter deleter, - EventStoreManagementClient sut, - StreamId streamId, - CancellationToken cancellationToken) - { - await sut.DeleteStreamAsync( - streamId, - cancellationToken: cancellationToken); - - _ = deleter - .Received(1) - .DeleteAsync( - streamId, - cancellationToken); - } -} \ No newline at end of file