Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/EntityDb.Abstractions/Commands/ICommand.cs

This file was deleted.

15 changes: 15 additions & 0 deletions src/EntityDb.Abstractions/Reducers/IReducer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace EntityDb.Abstractions.Reducers;

/// <summary>
/// Represents a type that can reduce one state into another state.
/// </summary>
/// <typeparam name="TState">The state to be reduced.</typeparam>
public interface IReducer<TState>
{
/// <summary>
/// Returns a new <see cref="TState"/> that incorporates this object into input <see cref="TState"/>.
/// </summary>
/// <param name="state">The state to be reduced.</param>
/// <returns></returns>
TState Reduce(TState state);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Annotations;
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Disposables;
using EntityDb.Abstractions.Leases;
using EntityDb.Abstractions.Queries;
Expand Down Expand Up @@ -86,7 +85,7 @@ public interface ITransactionRepository<TEntity> : IDisposableResource
/// </summary>
/// <param name="commandQuery">The command query.</param>
/// <returns>The commands which are found by <paramref name="commandQuery" />.</returns>
Task<ICommand<TEntity>[]> GetCommands(ICommandQuery commandQuery);
Task<object[]> GetCommands(ICommandQuery commandQuery);

/// <summary>
/// Returns the leases which are found by a lease query.
Expand All @@ -107,7 +106,7 @@ public interface ITransactionRepository<TEntity> : IDisposableResource
/// </summary>
/// <param name="commandQuery">The command query.</param>
/// <returns>The annotated commands which are found by <paramref name="commandQuery" />.</returns>
Task<IEntityAnnotation<ICommand<TEntity>>[]> GetAnnotatedCommands(ICommandQuery commandQuery);
Task<IEntityAnnotation<object>[]> GetAnnotatedCommands(ICommandQuery commandQuery);

/// <summary>
/// Inserts a single transaction with an atomic commit.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using EntityDb.Abstractions.Commands;

namespace EntityDb.Abstractions.Transactions.Steps;
namespace EntityDb.Abstractions.Transactions.Steps;

/// <summary>
/// Represents a modification to an entity's state.
Expand All @@ -11,7 +9,7 @@ public interface ICommandTransactionStep<TEntity> : ITransactionStep<TEntity>
/// <summary>
/// The modifier.
/// </summary>
ICommand<TEntity> Command { get; }
object Command { get; }

/// <summary>
/// A snapshot of the entity before the command.
Expand Down
7 changes: 7 additions & 0 deletions src/EntityDb.Common/Entities/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public interface IEntity<out TEntity>
/// </summary>
/// <returns></returns>
ulong GetVersionNumber();

/// <summary>
/// Returns a new <typeparamref name="TEntity" /> that incorporates the commands.
/// </summary>
/// <param name="commands">The commands</param>
/// <returns>A new <typeparamref name="TEntity" /> that incorporates <paramref name="commands"/>.</returns>
TEntity Reduce(params object[] commands);
}
49 changes: 0 additions & 49 deletions src/EntityDb.Common/Extensions/EntityExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Leases;
using EntityDb.Abstractions.Leases;
using EntityDb.Abstractions.Tags;
using EntityDb.Abstractions.Transactions;
using EntityDb.Common.Entities;
Expand Down Expand Up @@ -52,7 +51,7 @@ public bool IsEntityKnown()
/// <returns>The transaction builder.</returns>
/// <remarks>
/// Call this method to load an entity that already exists before calling
/// <see cref="Append(ICommand{TEntity})"/>.
/// <see cref="Append(object)"/>.
/// </remarks>
public SingleEntityTransactionBuilder<TEntity> Load(TEntity entity)
{
Expand All @@ -62,11 +61,11 @@ public SingleEntityTransactionBuilder<TEntity> Load(TEntity entity)
}

/// <summary>
/// Adds a transaction step that appends a single <see cref="ICommand{TEntity}"/>.
/// Adds a transaction step that appends a single command.
/// </summary>
/// <param name="command">The new command that modifies the <typeparamref name="TEntity"/>.</param>
/// <returns>The transaction builder.</returns>
public SingleEntityTransactionBuilder<TEntity> Append(ICommand<TEntity> command)
public SingleEntityTransactionBuilder<TEntity> Append(object command)
{
_transactionBuilder.Append(EntityId, command);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Agents;
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Leases;
using EntityDb.Abstractions.Tags;
using EntityDb.Abstractions.Transactions;
Expand Down Expand Up @@ -50,7 +49,7 @@ private void ConstructIfNotKnown(Guid entityId)
_knownEntities.Add(entityId, entity);
}

private void AddGeneralTransactionStep(Guid entityId, ICommand<TEntity> command)
private void AddGeneralTransactionStep(Guid entityId, object command)
{
ConstructIfNotKnown(entityId);

Expand Down Expand Up @@ -149,7 +148,7 @@ public bool IsEntityKnown(Guid entityId)
/// <returns>The transaction builder.</returns>
/// <remarks>
/// Call this method to load an entity that already exists before calling
/// <see cref="Append(Guid, ICommand{TEntity})" />.
/// <see cref="Append(Guid, object)" />.
/// </remarks>
public TransactionBuilder<TEntity> Load(Guid entityId, TEntity entity)
{
Expand All @@ -164,12 +163,12 @@ public TransactionBuilder<TEntity> Load(Guid entityId, TEntity entity)
}

/// <summary>
/// Adds a transaction step that appends a single <see cref="ICommand{TEntity}"/> associated with a given entity id.
/// Adds a transaction step that appends a single command associated with a given entity id.
/// </summary>
/// <param name="entityId">The id associated with the <typeparamref name="TEntity"/>.</param>
/// <param name="command">The new command that modifies the <typeparamref name="TEntity"/>.</param>
/// <returns>The transaction builder.</returns>
public TransactionBuilder<TEntity> Append(Guid entityId, ICommand<TEntity> command)
public TransactionBuilder<TEntity> Append(Guid entityId, object command)
{
AddGeneralTransactionStep(entityId, command);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Transactions.Steps;
using EntityDb.Abstractions.Transactions.Steps;
using System;

namespace EntityDb.Common.Transactions.Steps;

internal sealed record CommandTransactionStep<TEntity> : ICommandTransactionStep<TEntity>
{
public Guid EntityId { get; init; }
public ICommand<TEntity> Command { get; init; } = default!;
public object Command { get; init; } = default!;
public TEntity PreviousEntitySnapshot { get; init; } = default!;
public ulong PreviousEntityVersionNumber { get; init; }
public TEntity NextEntitySnapshot { get; init; } = default!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Annotations;
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Leases;
using EntityDb.Abstractions.Queries;
using EntityDb.Abstractions.Tags;
Expand Down Expand Up @@ -64,7 +63,7 @@ public Task<object[]> GetAgentSignatures(IAgentSignatureQuery agentSignatureQuer
return WrapQuery(_transactionRepository.GetAgentSignatures(agentSignatureQuery));
}

public Task<ICommand<TEntity>[]> GetCommands(ICommandQuery commandQuery)
public Task<object[]> GetCommands(ICommandQuery commandQuery)
{
return WrapQuery(_transactionRepository.GetCommands(commandQuery));
}
Expand All @@ -79,7 +78,7 @@ public Task<ITag[]> GetTags(ITagQuery tagQuery)
return WrapQuery(_transactionRepository.GetTags(tagQuery));
}

public Task<IEntityAnnotation<ICommand<TEntity>>[]> GetAnnotatedCommands(ICommandQuery commandQuery)
public Task<IEntityAnnotation<object>[]> GetAnnotatedCommands(ICommandQuery commandQuery)
{
return WrapQuery(_transactionRepository.GetAnnotatedCommands(commandQuery));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Annotations;
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Leases;
using EntityDb.Abstractions.Queries;
using EntityDb.Abstractions.Tags;
Expand Down Expand Up @@ -90,11 +89,11 @@ public Task<object[]> GetAgentSignatures(IAgentSignatureQuery agentSignatureQuer
.GetData<AgentSignatureDocument, object>();
}

public Task<ICommand<TEntity>[]> GetCommands(ICommandQuery commandQuery)
public Task<object[]> GetCommands(ICommandQuery commandQuery)
{
return CommandDocument
.GetQuery(_mongoSession, commandQuery)
.GetData<CommandDocument, ICommand<TEntity>>();
.GetData<CommandDocument, object>();
}

public Task<ILease[]> GetLeases(ILeaseQuery leaseQuery)
Expand All @@ -111,11 +110,11 @@ public Task<ITag[]> GetTags(ITagQuery tagQuery)
.GetData<TagDocument, ITag>();
}

public Task<IEntityAnnotation<ICommand<TEntity>>[]> GetAnnotatedCommands(ICommandQuery commandQuery)
public Task<IEntityAnnotation<object>[]> GetAnnotatedCommands(ICommandQuery commandQuery)
{
return CommandDocument
.GetQuery(_mongoSession, commandQuery)
.GetEntityAnnotation<CommandDocument, ICommand<TEntity>>();
.GetEntityAnnotation<CommandDocument, object>();
}

private async Task ExecuteCommandTransactionStep(ITransaction<TEntity> transaction, ICommandTransactionStep<TEntity> commandTransactionStep)
Expand Down
9 changes: 4 additions & 5 deletions src/EntityDb.Void/Transactions/VoidTransactionRepository.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Annotations;
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Leases;
using EntityDb.Abstractions.Queries;
using EntityDb.Abstractions.Tags;
Expand Down Expand Up @@ -57,9 +56,9 @@ public Task<object[]> GetAgentSignatures(IAgentSignatureQuery agentSignatureQuer
return Task.FromResult(Array.Empty<object>());
}

public Task<ICommand<TEntity>[]> GetCommands(ICommandQuery commandQuery)
public Task<object[]> GetCommands(ICommandQuery commandQuery)
{
return Task.FromResult(Array.Empty<ICommand<TEntity>>());
return Task.FromResult(Array.Empty<object>());
}

public Task<ILease[]> GetLeases(ILeaseQuery leaseQuery)
Expand All @@ -72,9 +71,9 @@ public Task<ITag[]> GetTags(ITagQuery tagQuery)
return Task.FromResult(Array.Empty<ITag>());
}

public Task<IEntityAnnotation<ICommand<TEntity>>[]> GetAnnotatedCommands(ICommandQuery commandQuery)
public Task<IEntityAnnotation<object>[]> GetAnnotatedCommands(ICommandQuery commandQuery)
{
return Task.FromResult(Array.Empty<IEntityAnnotation<ICommand<TEntity>>>());
return Task.FromResult(Array.Empty<IEntityAnnotation<object>>());
}

public Task<bool> PutTransaction(ITransaction<TEntity> transaction)
Expand Down
7 changes: 3 additions & 4 deletions test/EntityDb.Common.Tests/Entities/EntityTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Entities;
using EntityDb.Abstractions.Entities;
using EntityDb.Abstractions.Queries;
using EntityDb.Abstractions.Snapshots;
using EntityDb.Abstractions.Transactions;
Expand Down Expand Up @@ -53,7 +52,7 @@ public async Task GivenExistingEntityWithNoSnapshot_WhenGettingEntity_ThenGetCom

var entityId = Guid.NewGuid();

var commands = new List<ICommand<TransactionEntity>>();
var commands = new List<object>();

var transactionRepositoryMock = new Mock<ITransactionRepository<TransactionEntity>>(MockBehavior.Strict);

Expand Down Expand Up @@ -204,7 +203,7 @@ public async Task GivenSnapshotAndNewCommands_WhenGettingSnapshotOrDefault_ThenR

var snapshot = new TransactionEntity(1);

var newCommands = new ICommand<TransactionEntity>[]
var newCommands = new object[]
{
new DoNothing(),
new DoNothing()
Expand Down
35 changes: 0 additions & 35 deletions test/EntityDb.Common.Tests/Extensions/EntityExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Reducers;
using EntityDb.Common.Tests.Implementations.Entities;

namespace EntityDb.Common.Tests.Implementations.Commands;

public record Count(int Number) : ICommand<TransactionEntity>
public record Count(int Number) : IReducer<TransactionEntity>
{
public TransactionEntity Reduce(TransactionEntity entity)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using EntityDb.Abstractions.Commands;
using EntityDb.Abstractions.Reducers;
using EntityDb.Common.Tests.Implementations.Entities;

namespace EntityDb.Common.Tests.Implementations.Commands;

public record DoNothing : ICommand<TransactionEntity>
public record DoNothing : IReducer<TransactionEntity>
{
public TransactionEntity Reduce(TransactionEntity entity)
{
Expand Down
Loading