62 lines
2.7 KiB
C#
62 lines
2.7 KiB
C#
using System;
|
|
using Svrnty.CQRS.Events.Abstractions.EventStore;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Svrnty.CQRS.Events.Abstractions.Models;
|
|
|
|
namespace Svrnty.CQRS.Events.Abstractions.EventStore;
|
|
|
|
/// <summary>
|
|
/// Storage abstraction for persisting and retrieving events.
|
|
/// Implementations can use any storage mechanism (SQL, NoSQL, in-memory, etc.).
|
|
/// </summary>
|
|
public interface IEventStore
|
|
{
|
|
/// <summary>
|
|
/// Append an event to the store and assign it a sequence number.
|
|
/// </summary>
|
|
/// <param name="event">The event to store.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>The sequence number assigned to this event.</returns>
|
|
Task<long> AppendAsync(ICorrelatedEvent @event, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Append multiple events in a batch.
|
|
/// </summary>
|
|
/// <param name="events">The events to store.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Dictionary mapping event IDs to their sequence numbers.</returns>
|
|
Task<Dictionary<string, long>> AppendBatchAsync(IEnumerable<ICorrelatedEvent> events, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Get events for a specific correlation ID.
|
|
/// </summary>
|
|
/// <param name="correlationId">The correlation ID to query.</param>
|
|
/// <param name="afterSequence">Only return events after this sequence number (for catch-up).</param>
|
|
/// <param name="eventTypes">Optional filter for specific event types.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>List of stored events ordered by sequence.</returns>
|
|
Task<List<StoredEvent>> GetEventsAsync(
|
|
string correlationId,
|
|
long afterSequence = 0,
|
|
HashSet<string>? eventTypes = null,
|
|
CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Get a specific event by its ID.
|
|
/// </summary>
|
|
/// <param name="eventId">The event ID.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>The stored event, or null if not found.</returns>
|
|
Task<StoredEvent?> GetEventByIdAsync(string eventId, CancellationToken cancellationToken = default);
|
|
|
|
/// <summary>
|
|
/// Delete events older than the specified date (for cleanup/retention policies).
|
|
/// </summary>
|
|
/// <param name="olderThan">Delete events older than this date.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Number of events deleted.</returns>
|
|
Task<int> DeleteOldEventsAsync(DateTimeOffset olderThan, CancellationToken cancellationToken = default);
|
|
}
|