Skip to content

Commit

Permalink
chore: clean (#47)
Browse files Browse the repository at this point in the history
* chore: clean

run cleanup proceedures

* chore: more cleanup proceedure

* chore: clean up a few other things

* chore: last round of cleanup
  • Loading branch information
the-avid-engineer authored Jul 3, 2022
1 parent dfed490 commit cd1f698
Show file tree
Hide file tree
Showing 168 changed files with 2,268 additions and 2,051 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<EnablePreviewFeatures>True</EnablePreviewFeatures>
</PropertyGroup>
</PropertyGroup>
</Project>
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,41 @@ There are five core objects at the heart of this implementation

### Transactions

A transaction represents an atomic operation on multiple entities. A transaction is ideally* committed atomically or not at all.
If some step in the transaction fails, the entire transaction should fail.
A transaction represents an atomic operation on multiple entities. A transaction is ideally* committed atomically or not
at all. If some step in the transaction fails, the entire transaction should fail.

*In the MongoDb implementation, the transaction _is_ committed atomically. However, it is possible in the future that there
will be implementations that are not capable of doing this if you want to use tags and/or leases. An example would be EventStore,
which provides no ability to enforce uniqueness constraints in its transaction. Such implementations will need a complimentary
transaction in order to make use of tags and leases.
*In the MongoDb implementation, the transaction _is_ committed atomically. However, it is possible in the future that
there will be implementations that are not capable of doing this if you want to use tags and/or leases. An example would
be EventStore, which provides no ability to enforce uniqueness constraints in its transaction. Such implementations will
need a complimentary transaction in order to make use of tags and leases.

### Agent

An agent is an actor that can execute transactions. For example, if a transaction is initiated via an HTTP API, you might use
the `HttpContextAgent` - it's signature includes headers and connection information, and it uses the ClaimsPrincipal to decide
if an agent has a particular role required for authorized commands.
An agent is an actor that can execute transactions. For example, if a transaction is initiated via an HTTP API, you
might use the `HttpContextAgent` - it's signature includes headers and connection information, and it uses the
ClaimsPrincipal to decide if an agent has a particular role required for authorized commands.

### Commands

A command represents the intent to perform some operation on a single entity. Going back to the bank account example, one
command could be `PerformDeposit` while another could be `PerformWithdrawl`. The things that you can do are commands.
A command represents the intent to perform some operation on a single entity. Going back to the bank account example,
one command could be `PerformDeposit` while another could be `PerformWithdrawl`. The things that you can do are
commands.

### Tags

A tag is a way to index entities by some piece of information. A tag can have a label and a value, both of which are strings.
Many accounts are typed, and you could represent this with a tag where `Label` is `Type` and `Value` is `Savings` or `Checking`.
You could then run a query to get the account id of all accounts where `Label` is `Type` and `Value` is `Savings`. The number
of savings accounts in the system would be the number of entity ids.
A tag is a way to index entities by some piece of information. A tag can have a label and a value, both of which are
strings. Many accounts are typed, and you could represent this with a tag where `Label` is `Type` and `Value`
is `Savings` or `Checking`. You could then run a query to get the account id of all accounts where `Label` is `Type`
and `Value` is `Savings`. The number of savings accounts in the system would be the number of entity ids.

### Leases

A lease is like a tag, except that it has a uniqueness constraint. Many banks have online portals, allowing bank members
to see their accounts on the internet. From the bank's perspective, all of the accounts should be tied to a member id,
probably a guid. But the member will not want to remember nor lookup this guid - they will want to use a username.
What you can do in EntityDb is make a lease for member entities where the entity id is the member id, the `Label` is `Username`
and the `Value` is whatever username the member wants to use. If an attempt to commit a transaction is made that would violate the
uniqueness constraint, it will be rejected. (This is obnoxious behavior for the user, though, so the bank should check before attempting
to commit to see if the username is available and give immediate feedback to choose a different username).
probably a guid. But the member will not want to remember nor lookup this guid - they will want to use a username. What
you can do in EntityDb is make a lease for member entities where the entity id is the member id, the `Label`
is `Username`
and the `Value` is whatever username the member wants to use. If an attempt to commit a transaction is made that would
violate the uniqueness constraint, it will be rejected. (This is obnoxious behavior for the user, though, so the bank
should check before attempting to commit to see if the username is available and give immediate feedback to choose a
different username).
18 changes: 9 additions & 9 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project>
<Import Project="../Directory.Build.props" />
<Import Project="../Directory.Build.props"/>

<!--Build-->
<PropertyGroup>
<OutputType>Library</OutputType>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<!--Pack-->
<PropertyGroup>
<IsPackable>true</IsPackable>
Expand All @@ -26,13 +26,13 @@
</PropertyGroup>

<ItemGroup>
<None Include="..\..\ICON.png" Pack="true" PackagePath="\" />
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="\" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\ICON.png" Pack="true" PackagePath="\"/>
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="\"/>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion src/EntityDb.Abstractions/Annotations/IEntitiesAnnotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace EntityDb.Abstractions.Annotations;

/// <summary>
/// Represents data for multiple entities that have already been committed, along with relevant information not contained
/// Represents data for multiple entities that have already been committed, along with relevant information not
/// contained
/// in the data.
/// </summary>
/// <typeparam name="TData">The type of data.</typeparam>
Expand Down
15 changes: 10 additions & 5 deletions src/EntityDb.Abstractions/Entities/IEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,25 @@ public interface IEntityRepository<TEntity> : IDisposableResource
[Obsolete("Please use GetSnapshot(...) instead. This method will be removed at a later date.")]
[ExcludeFromCodeCoverage(Justification = "Obsolete")]
public Task<TEntity> GetCurrent(Id entityId, CancellationToken cancellationToken = default)
=> GetSnapshot(entityId, cancellationToken);
{
return GetSnapshot(entityId, cancellationToken);
}

/// <ignore />
[Obsolete("Please use GetSnapshot(...) instead. This method will be removed at a later date.")]
[ExcludeFromCodeCoverage(Justification = "Obsolete")]
Task<TEntity> GetAtVersion(Id entityId, VersionNumber lteVersionNumber, CancellationToken cancellationToken = default)
=> GetSnapshot(entityId + lteVersionNumber, cancellationToken);
Task<TEntity> GetAtVersion(Id entityId, VersionNumber lteVersionNumber,
CancellationToken cancellationToken = default)
{
return GetSnapshot(entityId + lteVersionNumber, cancellationToken);
}

/// <summary>
/// Returns the snapshot of a <typeparamref name="TEntity" /> for a given <see cref="Pointer"/>.
/// Returns the snapshot of a <typeparamref name="TEntity" /> for a given <see cref="Pointer" />.
/// </summary>
/// <param name="entityPointer">A pointer to the entity.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>The snapshot of a <typeparamref name="TEntity" /> for <paramref name="entityPointer"/>.</returns>
/// <returns>The snapshot of a <typeparamref name="TEntity" /> for <paramref name="entityPointer" />.</returns>
Task<TEntity> GetSnapshot(Pointer entityPointer, CancellationToken cancellationToken = default);

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions src/EntityDb.Abstractions/Projections/IProjectionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IProjectionRepository<TProjection> : IDisposableResource
/// The backing transaction repository.
/// </summary>
ITransactionRepository TransactionRepository { get; }

/// <summary>
/// The backing snapshot repository.
/// </summary>
Expand All @@ -29,14 +29,16 @@ public interface IProjectionRepository<TProjection> : IDisposableResource
[Obsolete("Please use GetSnapshot(...) instead. This method will be removed at a later date.")]
[ExcludeFromCodeCoverage(Justification = "Obsolete")]
public Task<TProjection> GetCurrent(Id projectionId, CancellationToken cancellationToken = default)
=> GetSnapshot(projectionId, cancellationToken);
{
return GetSnapshot(projectionId, cancellationToken);
}

/// <summary>
/// Returns the snapshot of a <typeparamref name="TProjection" /> for a given <see cref="Pointer"/>.
/// Returns the snapshot of a <typeparamref name="TProjection" /> for a given <see cref="Pointer" />.
/// </summary>
/// <param name="projectionPointer">A pointer to the projection.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>The snapshot of a <typeparamref name="TProjection" /> for <paramref name="projectionPointer"/>.</returns>
/// <returns>The snapshot of a <typeparamref name="TProjection" /> for <paramref name="projectionPointer" />.</returns>
Task<TProjection> GetSnapshot(Pointer projectionPointer, CancellationToken cancellationToken = default);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace EntityDb.Abstractions.Queries.FilterBuilders;
public interface IAgentSignatureFilterBuilder<TFilter> : IFilterBuilder<TFilter>
{
/// <summary>
/// Returns a <typeparamref name="TFilter" /> that only includes agentSignatures with any entity id which is contained in a set
/// Returns a <typeparamref name="TFilter" /> that only includes agentSignatures with any entity id which is contained
/// in a set
/// of entity ids.
/// </summary>
/// <param name="entityIds">The set of entity ids.</param>
Expand All @@ -22,7 +23,8 @@ public interface IAgentSignatureFilterBuilder<TFilter> : IFilterBuilder<TFilter>
TFilter EntityIdsIn(params Id[] entityIds);

/// <summary>
/// Returns a <typeparamref name="TFilter" /> that only includes agentSignatures whose type is contained in a set of agentSignature
/// Returns a <typeparamref name="TFilter" /> that only includes agentSignatures whose type is contained in a set of
/// agentSignature
/// types.
/// </summary>
/// <param name="agentSignatureTypes">The agentSignature types.</param>
Expand All @@ -33,7 +35,8 @@ public interface IAgentSignatureFilterBuilder<TFilter> : IFilterBuilder<TFilter>
TFilter AgentSignatureTypeIn(params Type[] agentSignatureTypes);

/// <summary>
/// Returns a <typeparamref name="TFilter" /> that only includes agentSignatures which do match a agentSignature expression.
/// Returns a <typeparamref name="TFilter" /> that only includes agentSignatures which do match a agentSignature
/// expression.
/// </summary>
/// <typeparam name="TAgentSignature">The type of agentSignature in the agentSignature expression.</typeparam>
/// <param name="agentSignatureExpression">The agentSignature expression.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace EntityDb.Abstractions.Queries.FilterBuilders;

/// <summary>
/// Builds a <typeparamref name="TFilter" /> for an object repository. Possible objects include: agentSignatures, commands,
/// Builds a <typeparamref name="TFilter" /> for an object repository. Possible objects include: agentSignatures,
/// commands,
/// facts, and leases.
/// </summary>
/// <typeparam name="TFilter">The type of filter used by the repository.</typeparam>
Expand Down
2 changes: 1 addition & 1 deletion src/EntityDb.Abstractions/Queries/IAgentSignatureQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IAgentSignatureQuery : IQuery
/// <param name="builder">The agentSignature filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(IAgentSignatureFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a agentSignature sort builder.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EntityDb.Abstractions/Queries/ICommandQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ICommandQuery : IQuery
/// <param name="builder">The command filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ICommandFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a command sort builder.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EntityDb.Abstractions/Queries/ILeaseQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ILeaseQuery : IQuery
/// <param name="builder">The lease filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ILeaseFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a lease sort builder.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EntityDb.Abstractions/Queries/ITagQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ITagQuery : IQuery
/// <param name="builder">The tag filter builder.</param>
/// <returns>A <typeparamref name="TFilter" /> built from <paramref name="builder" />.</returns>
TFilter GetFilter<TFilter>(ITagFilterBuilder<TFilter> builder);

/// <summary>
/// Returns a <typeparamref name="TSort" /> built from a tag sort builder.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ public interface IAgentSignatureSortBuilder<TSort> : ISortBuilder<TSort>
/// <param name="ascending">Pass <c>true</c> for ascending order or <c>false</c> for descending order.</param>
/// <param name="agentSignatureExpression">The agentSignature expression.</param>
/// <returns>A <typeparamref name="TSort" /> that orders agentSignatures by <paramref name="agentSignatureExpression" />.</returns>
TSort AgentSignatureProperty<TAgentSignature>(bool ascending, Expression<Func<TAgentSignature, object>> agentSignatureExpression);
TSort AgentSignatureProperty<TAgentSignature>(bool ascending,
Expression<Func<TAgentSignature, object>> agentSignatureExpression);
}
3 changes: 2 additions & 1 deletion src/EntityDb.Abstractions/Reducers/IReducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace EntityDb.Abstractions.Reducers;
public interface IReducer<TState>
{
/// <summary>
/// Returns a new <typeparamref name="TState"/> that incorporates this object into input <typeparamref name="TState"/>.
/// Returns a new <typeparamref name="TState" /> that incorporates this object into input
/// <typeparamref name="TState" />.
/// </summary>
/// <param name="state">The state to be reduced.</param>
/// <returns></returns>
Expand Down
14 changes: 10 additions & 4 deletions src/EntityDb.Abstractions/Snapshots/ISnapshotRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ namespace EntityDb.Abstractions.Snapshots;
/// <typeparam name="TSnapshot">The type of snapshot stored in the <see cref="ISnapshotRepository{TSnapshot}" />.</typeparam>
public interface ISnapshotRepository<TSnapshot> : IDisposableResource
{
/// <ignore/>
/// <ignore />
[Obsolete("Please use GetSnapshotOrDefault(...) instead. This method will be removed at a later date.")]
[ExcludeFromCodeCoverage(Justification = "Obsolete")]
public Task<TSnapshot?> GetSnapshot(Id snapshotId, CancellationToken cancellationToken = default)
=> GetSnapshotOrDefault(snapshotId, cancellationToken);
{
return GetSnapshotOrDefault(snapshotId, cancellationToken);
}

/// <summary>
/// Returns an exact version of snapshot of a <typeparamref name="TSnapshot" /> or <c>default(<typeparamref name="TSnapshot"/>)</c>.
/// Returns an exact version of snapshot of a <typeparamref name="TSnapshot" /> or
/// <c>default(<typeparamref name="TSnapshot" />)</c>.
/// </summary>
/// <param name="snapshotPointer">A pointer to a specific snapshot.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>An exact version of snapshot of a <typeparamref name="TSnapshot" /> or <c>default(<typeparamref name="TSnapshot"/>)</c>.</returns>
/// <returns>
/// An exact version of snapshot of a <typeparamref name="TSnapshot" /> or
/// <c>default(<typeparamref name="TSnapshot" />)</c>.
/// </returns>
Task<TSnapshot?> GetSnapshotOrDefault(Pointer snapshotPointer, CancellationToken cancellationToken = default);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public interface ISnapshotRepositoryFactory<TSnapshot> : IDisposableResource
/// <param name="snapshotSessionOptionsName">The agent's use case for the repository.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>A new instance of <see cref="ISnapshotRepository{TSnapshot}" />.</returns>
Task<ISnapshotRepository<TSnapshot>> CreateRepository(string snapshotSessionOptionsName, CancellationToken cancellationToken = default);
Task<ISnapshotRepository<TSnapshot>> CreateRepository(string snapshotSessionOptionsName,
CancellationToken cancellationToken = default);
}
Loading

0 comments on commit cd1f698

Please sign in to comment.