rename zero to Finch

This commit is contained in:
2026-04-07 14:23:29 +02:00
parent 535894e774
commit 1bcf2b25b5
267 changed files with 1028 additions and 1045 deletions
-17
View File
@@ -260,20 +260,3 @@ paket-files/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Media folder + app_data
App_Data/
**/wwwroot/Media/
**/wwwroot/Uploads/
Temp/
**/Assets/**/app.*
**/Assets/**/setup.*
**/Assets/**/*.js
deps/*.dll
zero.Commerce/
zero.Stories/
zero.Forms/
zero.Backoffice.UI/package.json
zero.Backoffice.UI/package-lock.json
zero.Backoffice.UI/app/core/plugins.js
zero.Backoffice.UI/dist
@@ -1,10 +1,10 @@
using System.Linq.Expressions;
using Raven.Client.Documents;
using zero.Identity;
using Finch.Identity;
namespace zero.Raven;
namespace Finch.Raven;
public class RavenIdentityStoreDbProvider : IZeroIdentityStoreDbProvider
public class RavenIdentityStoreDbProvider : IFinchIdentityStoreDbProvider
{
protected IRavenOperations Ops { get; set; }
@@ -15,27 +15,27 @@ public class RavenIdentityStoreDbProvider : IZeroIdentityStoreDbProvider
}
public Task<T> Load<T>(string id, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<T> Load<T>(string id, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Load<T>(id);
public Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : ZeroEntity =>
public Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : FinchEntity =>
Ops.Session.Query<T>().FirstOrDefaultAsync(expression, ct);
public async Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default)
where T : ZeroEntity =>
where T : FinchEntity =>
await Ops.Session.Query<T>().Where(expression).ToListAsync(ct);
public Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Create(model);
public Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Update(model);
public Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Delete(model);
}
@@ -1,10 +1,10 @@
using System.Linq.Expressions;
using Raven.Client.Documents;
using zero.Media;
using Finch.Media;
namespace zero.Raven;
namespace Finch.Raven;
public class RavenMediaStoreDbProvider : IZeroMediaStoreDbProvider
public class RavenMediaStoreDbProvider : IFinchMediaStoreDbProvider
{
protected IRavenOperations Ops { get; set; }
@@ -15,23 +15,23 @@ public class RavenMediaStoreDbProvider : IZeroMediaStoreDbProvider
}
public Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : ZeroEntity =>
public Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : FinchEntity =>
Ops.Session.Query<T>().FirstOrDefaultAsync(expression, ct);
public async Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default)
where T : ZeroEntity =>
where T : FinchEntity =>
await Ops.Session.Query<T>().Where(expression).ToListAsync(ct);
public Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Create(model);
public Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Update(model);
public Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Delete(model);
}
@@ -1,10 +1,10 @@
using Raven.Client.Documents;
using System.Linq.Expressions;
using zero.Numbers;
using Finch.Numbers;
namespace zero.Raven;
namespace Finch.Raven;
public class RavenNumberStoreDbProvider : IZeroNumberStoreDbProvider
public class RavenNumberStoreDbProvider : IFinchNumberStoreDbProvider
{
protected IRavenOperations Ops { get; set; }
@@ -15,27 +15,27 @@ public class RavenNumberStoreDbProvider : IZeroNumberStoreDbProvider
}
public Task<T> Load<T>(string id, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<T> Load<T>(string id, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Load<T>(id);
public Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : ZeroEntity =>
public Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : FinchEntity =>
Ops.Session.Query<T>().FirstOrDefaultAsync(expression, ct);
public async Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default)
where T : ZeroEntity =>
where T : FinchEntity =>
await Ops.Session.Query<T>().Where(expression).ToListAsync(ct);
public Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Create(model);
public Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Update(model);
public Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new() =>
public Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : FinchEntity, new() =>
Ops.Delete(model);
}
@@ -1,8 +1,8 @@
using Rv = Raven.Client;
namespace zero.Raven;
namespace Finch.Raven;
public static class ZeroDocumentSessionExtensions
public static class FinchDocumentSessionExtensions
{
public static void SetCollection<T>(this IAsyncDocumentSession session, T model, string collectionName)
{
@@ -4,7 +4,7 @@ using Raven.Client.Documents.Queries;
using Raven.Client.Documents.Session;
using System.Linq.Expressions;
namespace zero.Raven;
namespace Finch.Raven;
public static class RavenQueryableExtensions
{
@@ -49,7 +49,7 @@ public static class RavenQueryableExtensions
if (pageNumber <= 0 || pageSize <= 0)
{
throw new NotSupportedException("Both pageNumber and pageSize must be greater than zero");
throw new NotSupportedException("Both pageNumber and pageSize must be greater than z_ero");
}
return source.Skip((pageNumber - 1) * pageSize).Take(pageSize);
@@ -1,7 +1,7 @@
using FluentValidation;
using Raven.Client.Documents;
namespace zero.Raven;
namespace Finch.Raven;
public static class ValidatorExtensions
{
@@ -9,12 +9,12 @@ public static class ValidatorExtensions
/// Check if this value is unique within a collection
/// </summary>
public static IRuleBuilderOptions<T, TProperty> Unique<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IRavenOperations ops)
where T : ZeroIdEntity
where T : FinchIdEntity
{
return ruleBuilder.MustAsync(async (entity, value, context, cancellation) =>
{
bool any = await ops.Session.Advanced.AsyncDocumentQuery<T>()
.WhereNotEquals(nameof(ZeroIdEntity.Id), entity.Id)
.WhereNotEquals(nameof(FinchIdEntity.Id), entity.Id)
.WhereEquals(context.PropertyPath.ToPascalCaseId(), value)
.AnyAsync(cancellation);
@@ -43,12 +43,12 @@ public static class ValidatorExtensions
/// Check if this value is at least set once to the expected value within a collection
/// </summary>
public static IRuleBuilderOptions<T, TProperty> ExpectAnyUnique<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IRavenOperations ops, TProperty expectedValue)
where T : ZeroIdEntity
where T : FinchIdEntity
{
return ruleBuilder.MustAsync(async (entity, value, context, cancellation) =>
{
return await ops.Session.Advanced.AsyncDocumentQuery<T>()
.WhereNotEquals(nameof(ZeroIdEntity.Id), entity.Id)
.WhereNotEquals(nameof(FinchIdEntity.Id), entity.Id)
.WhereEquals(context.PropertyPath.ToPascalCaseId(), expectedValue)
.AnyAsync(cancellation);
}).WithMessage("@errors.forms.not_unique_alone");
@@ -59,7 +59,7 @@ public static class ValidatorExtensions
/// Check if this reference exists and is an entity which can be referenced
/// </summary>
public static IRuleBuilderOptions<T, string> Exists<T>(this IRuleBuilder<T, string> ruleBuilder, IRavenOperations ops)
where T : ZeroIdEntity
where T : FinchIdEntity
{
return ruleBuilder.Exists<T, T>(ops);
}
@@ -69,7 +69,7 @@ public static class ValidatorExtensions
/// Check if this reference exists and is an entity which can be referenced
/// </summary>
public static IRuleBuilderOptions<T, string> Exists<T, TCollection>(this IRuleBuilder<T, string> ruleBuilder, IRavenOperations ops)
where TCollection : ZeroIdEntity
where TCollection : FinchIdEntity
{
return ruleBuilder.MustAsync(async (entity, id, context, cancellation) =>
{
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>zero.Raven</PackageId>
<PackageId>Finch.Raven</PackageId>
<Version>1.0.0</Version>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<RootNamespace>zero.Raven</RootNamespace>
<RootNamespace>Finch.Raven</RootNamespace>
<DebugType>embedded</DebugType>
</PropertyGroup>
@@ -17,7 +17,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\zero\zero.csproj" />
<ProjectReference Include="..\Finch\Finch.csproj" />
</ItemGroup>
</Project>
@@ -4,39 +4,39 @@ using Microsoft.Extensions.DependencyInjection;
using Raven.Client.Documents;
using Raven.Client.Documents.Indexes;
using Raven.Client.Http;
using zero.Identity;
using zero.Media;
using zero.Numbers;
using Finch.Identity;
using Finch.Media;
using Finch.Numbers;
namespace zero.Raven;
namespace Finch.Raven;
public static class ZeroBuilderExtensions
public static class FinchBuilderExtensions
{
public static ZeroBuilder AddRavenDb(this ZeroBuilder builder)
public static FinchBuilder AddRavenDb(this FinchBuilder builder)
{
builder.AddModule<ZeroRavenModule>();
builder.AddModule<FinchRavenModule>();
return builder;
}
}
internal class ZeroRavenModule : ZeroModule
internal class FinchRavenModule : FinchModule
{
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton<IRavenDocumentConventionsBuilder, RavenDocumentConventionsBuilder>();
services.AddSingleton<IDocumentStore>(CreateRavenStore);
services.AddScoped<IZeroStore, ZeroStore>();
services.AddScoped<IZeroTokenProvider, ZeroTokenProvider>();
services.AddScoped<IFinchStore, FinchStore>();
services.AddScoped<IFinchTokenProvider, FinchTokenProvider>();
services.AddScoped<StoreContext>();
services.AddTransient<IRavenOperations, RavenOperations>();
services.AddScoped<IInterceptors, Interceptors>();
services.Replace<IZeroIdentityStoreDbProvider, RavenIdentityStoreDbProvider>(ServiceLifetime.Scoped);
services.Replace<IZeroMediaStoreDbProvider, RavenMediaStoreDbProvider>(ServiceLifetime.Scoped);
services.Replace<IZeroNumberStoreDbProvider, RavenNumberStoreDbProvider>(ServiceLifetime.Scoped);
services.Replace<IFinchIdentityStoreDbProvider, RavenIdentityStoreDbProvider>(ServiceLifetime.Scoped);
services.Replace<IFinchMediaStoreDbProvider, RavenMediaStoreDbProvider>(ServiceLifetime.Scoped);
services.Replace<IFinchNumberStoreDbProvider, RavenNumberStoreDbProvider>(ServiceLifetime.Scoped);
services.AddOptions<FlavorOptions>();
services.AddOptions<RavenOptions>().Bind(configuration.GetSection("Zero:Raven"));
services.AddOptions<RavenOptions>().Bind(configuration.GetSection("Finch:Raven"));
services.ConfigureOptions<ConfigureFlavorJsonOptions>();
}
@@ -45,7 +45,7 @@ internal class ZeroRavenModule : ZeroModule
/// </summary>
protected IDocumentStore CreateRavenStore(IServiceProvider services)
{
IZeroOptions options = services.GetService<IZeroOptions>();
IFinchOptions options = services.GetService<IFinchOptions>();
RavenOptions ravenOptions = options.For<RavenOptions>();
IRavenDocumentConventionsBuilder conventionsBuilder = services.GetService<IRavenDocumentConventionsBuilder>();
@@ -68,7 +68,7 @@ internal class ZeroRavenModule : ZeroModule
IDocumentStore raven = store.Initialize();
// create all indexes
IEnumerable<IZeroIndexDefinition> indexes = ravenOptions.Indexes.BuildAll(options, store);
IEnumerable<IFinchIndexDefinition> indexes = ravenOptions.Indexes.BuildAll(options, store);
IndexCreation.CreateIndexes(indexes, store, database: ravenOptions.Database);
@@ -4,18 +4,18 @@ using Raven.Client.Documents.Queries;
using Raven.Client.Documents.Session;
using Raven.Client;
namespace zero.Raven;
namespace Finch.Raven;
public class ZeroStore : IZeroStore
public class FinchStore : IFinchStore
{
public ZeroStore(IDocumentStore raven, IZeroOptions options) : base()
public FinchStore(IDocumentStore raven, IFinchOptions options) : base()
{
Options = options;
Raven = raven;
//Database = null;
}
protected IZeroOptions Options { get; set; }
protected IFinchOptions Options { get; set; }
protected Dictionary<string, IAsyncDocumentSession> ScopedSessions { get; set; } = new();
private const string NullDb = "__default__";
@@ -25,11 +25,11 @@ public class ZeroStore : IZeroStore
/// <inheritdoc />
public IAsyncDocumentSession Session(ZeroSessionResolution resolution = ZeroSessionResolution.Reuse, SessionOptions options = null)
public IAsyncDocumentSession Session(FinchSessionResolution resolution = FinchSessionResolution.Reuse, SessionOptions options = null)
{
options ??= new SessionOptions();
if (resolution == ZeroSessionResolution.Create)
if (resolution == FinchSessionResolution.Create)
{
return Raven.OpenAsyncSession(options);
}
@@ -75,14 +75,14 @@ public class ZeroStore : IZeroStore
}
public enum ZeroSessionResolution
public enum FinchSessionResolution
{
Reuse = 0,
Create = 1
}
public interface IZeroStore
public interface IFinchStore
{
/// <summary>
/// Get underlying raven document store
@@ -92,7 +92,7 @@ public interface IZeroStore
/// <summary>
/// Use a specific session
/// </summary>
IAsyncDocumentSession Session(ZeroSessionResolution resolution = ZeroSessionResolution.Reuse, SessionOptions options = null);
IAsyncDocumentSession Session(FinchSessionResolution resolution = FinchSessionResolution.Reuse, SessionOptions options = null);
/// <summary>
/// Purges a collection
@@ -4,15 +4,15 @@ using Raven.Client.Documents.Indexes.Spatial;
using Raven.Client.Documents.Operations.Attachments;
using System.Linq.Expressions;
namespace zero.Raven;
namespace Finch.Raven;
public abstract class ZeroJavascriptIndex : AbstractJavaScriptIndexCreationTask, IZeroIndexDefinition
public abstract class FinchJavascriptIndex : AbstractJavaScriptIndexCreationTask, IFinchIndexDefinition
{
public ZeroJavascriptIndex() { Create(); }
public FinchJavascriptIndex() { Create(); }
protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { }
public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
public new string Reduce { get => base.Reduce; set => base.Reduce = value; }
public new string OutputReduceToCollection { get => base.OutputReduceToCollection; set => base.OutputReduceToCollection = value; }
@@ -44,12 +44,12 @@ public abstract class ZeroJavascriptIndex : AbstractJavaScriptIndexCreationTask,
public new T? TryConvert<T>(object value) where T : struct => base.TryConvert<T>(value);
}
public abstract class ZeroMultiMapIndex : AbstractMultiMapIndexCreationTask<object>, IZeroIndexDefinition
public abstract class FinchMultiMapIndex : AbstractMultiMapIndexCreationTask<object>, IFinchIndexDefinition
{
public ZeroMultiMapIndex() { Create(); }
public FinchMultiMapIndex() { Create(); }
protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { }
public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractMultiMapIndexCreationTask<TReduceResult>
public new void AddMap<TSource>(Expression<Func<IEnumerable<TSource>, IEnumerable>> map) => base.AddMap(map);
@@ -111,12 +111,12 @@ public abstract class ZeroMultiMapIndex : AbstractMultiMapIndexCreationTask<obje
}
public abstract class ZeroMultiMapIndex<TReduceResult> : AbstractMultiMapIndexCreationTask<TReduceResult>, IZeroIndexDefinition
public abstract class FinchMultiMapIndex<TReduceResult> : AbstractMultiMapIndexCreationTask<TReduceResult>, IFinchIndexDefinition
{
public ZeroMultiMapIndex() { Create(); }
public FinchMultiMapIndex() { Create(); }
protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { }
public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractMultiMapIndexCreationTask<TReduceResult>
public new void AddMap<TSource>(Expression<Func<IEnumerable<TSource>, IEnumerable>> map) => base.AddMap(map);
@@ -178,12 +178,12 @@ public abstract class ZeroMultiMapIndex<TReduceResult> : AbstractMultiMapIndexCr
}
public abstract class ZeroIndex<TDocument, TReduceResult> : AbstractIndexCreationTask<TDocument, TReduceResult>, IZeroIndexDefinition
public abstract class FinchIndex<TDocument, TReduceResult> : AbstractIndexCreationTask<TDocument, TReduceResult>, IFinchIndexDefinition
{
public ZeroIndex() { Create(); }
public FinchIndex() { Create(); }
protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { }
public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractIndexCreationTask<TDocument, TReduceResult>
public new Expression<Func<IEnumerable<TDocument>, IEnumerable>> Map { get => base.Map; set => base.Map = value; }
@@ -244,17 +244,17 @@ public abstract class ZeroIndex<TDocument, TReduceResult> : AbstractIndexCreatio
}
public abstract class ZeroIndex<TDocument> : ZeroIndex<TDocument, TDocument>
public abstract class FinchIndex<TDocument> : FinchIndex<TDocument, TDocument>
{
}
public abstract class ZeroIndex : AbstractIndexCreationTask, IZeroIndexDefinition
public abstract class FinchIndex : AbstractIndexCreationTask, IFinchIndexDefinition
{
public ZeroIndex() { Create(); }
public FinchIndex() { Create(); }
protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { }
public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractIndexCreationTask
public new IJsonObject AsJson(object doc) => base.AsJson(doc);
@@ -282,7 +282,7 @@ public abstract class ZeroIndex : AbstractIndexCreationTask, IZeroIndexDefinitio
}
public interface IZeroIndexDefinition : IAbstractIndexCreationTask
public interface IFinchIndexDefinition : IAbstractIndexCreationTask
{
void Setup(IZeroOptions options, IDocumentStore store);
void Setup(IFinchOptions options, IDocumentStore store);
}
@@ -1,14 +1,14 @@
namespace zero.Raven;
namespace Finch.Raven;
public static class ZeroIndexExtensions
public static class FinchIndexExtensions
{
internal static void RunModifiers<T>(this T index, RavenOptions options) where T : IZeroIndexDefinition
internal static void RunModifiers<T>(this T index, RavenOptions options) where T : IFinchIndexDefinition
{
IEnumerable<RavenIndexModifiersOptions.Modifier> modifiers = options.Indexes.Modifiers.GetAllForType(index.GetType());
foreach (RavenIndexModifiersOptions.Modifier modifier in modifiers)
{
Action<IZeroIndexDefinition> action = modifier.Modify.Compile();
Action<IFinchIndexDefinition> action = modifier.Modify.Compile();
action.Invoke(index);
}
}
@@ -1,18 +1,18 @@
using Raven.Client.Documents;
using Raven.Client.Documents.Indexes;
namespace zero.Raven;
namespace Finch.Raven;
public class ZeroTreeHierarchyIndexResult : ZeroIdEntity, ISupportsDbConventions
public class FinchTreeHierarchyIndexResult : FinchIdEntity, ISupportsDbConventions
{
public List<string> Path { get; set; } = new List<string>();
}
public abstract class ZeroTreeHierarchyIndex<T> : ZeroIndex<T, ZeroTreeHierarchyIndexResult> where T : ZeroIdEntity, ISupportsTrees
public abstract class FinchTreeHierarchyIndex<T> : FinchIndex<T, FinchTreeHierarchyIndexResult> where T : FinchIdEntity, ISupportsTrees
{
protected override void Create()
{
Map = items => items.Select(item => new ZeroTreeHierarchyIndexResult
Map = items => items.Select(item => new FinchTreeHierarchyIndexResult
{
Id = item.Id,
Path = Recurse(item, x => LoadDocument<T>(x.ParentId))
@@ -1,6 +1,6 @@
using Raven.Client.Documents.Indexes;
namespace zero.Raven;
namespace Finch.Raven;
public static class RavenIndexExtensions
{
@@ -1,7 +1,7 @@
namespace zero.Raven;
namespace Finch.Raven;
public abstract partial class Interceptor<T> : Interceptor, IInterceptor<T> where T : ZeroIdEntity
public abstract partial class Interceptor<T> : Interceptor, IInterceptor<T> where T : FinchIdEntity
{
/// <inheritdoc />
public Type ModelType { get; protected set; }
@@ -22,51 +22,51 @@ public abstract partial class Interceptor<T> : Interceptor, IInterceptor<T> wher
public virtual Task<InterceptorResult<T>> Creating(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default);
/// <inheritdoc />
public sealed override async Task<InterceptorResult<ZeroIdEntity>> Creating(InterceptorParameters args, ZeroIdEntity model) => Convert(await Creating(args, model as T));
public sealed override async Task<InterceptorResult<FinchIdEntity>> Creating(InterceptorParameters args, FinchIdEntity model) => Convert(await Creating(args, model as T));
/// <inheritdoc />
public virtual Task<InterceptorResult<T>> Updating(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default);
/// <inheritdoc />
public sealed override async Task<InterceptorResult<ZeroIdEntity>> Updating(InterceptorParameters args, ZeroIdEntity model) => Convert(await Updating(args, model as T));
public sealed override async Task<InterceptorResult<FinchIdEntity>> Updating(InterceptorParameters args, FinchIdEntity model) => Convert(await Updating(args, model as T));
/// <inheritdoc />
public virtual Task<InterceptorResult<T>> Deleting(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default);
/// <inheritdoc />
public sealed override async Task<InterceptorResult<ZeroIdEntity>> Deleting(InterceptorParameters args, ZeroIdEntity model) => Convert(await Deleting(args, model as T));
public sealed override async Task<InterceptorResult<FinchIdEntity>> Deleting(InterceptorParameters args, FinchIdEntity model) => Convert(await Deleting(args, model as T));
/// <inheritdoc />
public virtual Task Created(InterceptorParameters args, T model) => Task.CompletedTask;
/// <inheritdoc />
public sealed override Task Created(InterceptorParameters args, ZeroIdEntity model) => Created(args, model as T);
public sealed override Task Created(InterceptorParameters args, FinchIdEntity model) => Created(args, model as T);
/// <inheritdoc />
public virtual Task Updated(InterceptorParameters args, T model) => Task.CompletedTask;
/// <inheritdoc />
public sealed override Task Updated(InterceptorParameters args, ZeroIdEntity model) => Updated(args, model as T);
public sealed override Task Updated(InterceptorParameters args, FinchIdEntity model) => Updated(args, model as T);
/// <inheritdoc />
public virtual Task Deleted(InterceptorParameters args, T model) => Task.CompletedTask;
/// <inheritdoc />
public sealed override Task Deleted(InterceptorParameters args, ZeroIdEntity model) => Deleted(args, model as T);
public sealed override Task Deleted(InterceptorParameters args, FinchIdEntity model) => Deleted(args, model as T);
InterceptorResult<ZeroIdEntity> Convert(InterceptorResult<T> result)
InterceptorResult<FinchIdEntity> Convert(InterceptorResult<T> result)
{
if (result == default)
{
return default;
}
return new InterceptorResult<ZeroIdEntity>()
return new InterceptorResult<FinchIdEntity>()
{
Continue = result.Continue,
InterceptorHash = result.InterceptorHash,
Result = result.Result != null ? result.Result.ConvertTo<ZeroIdEntity>(result.Result.Model) : null
Result = result.Result != null ? result.Result.ConvertTo<FinchIdEntity>(result.Result.Model) : null
};
}
}
@@ -95,26 +95,26 @@ public abstract partial class Interceptor : IInterceptor
public virtual bool CanHandle(InterceptorParameters args, Type modelType) => true;
/// <inheritdoc />
public virtual Task<InterceptorResult<ZeroIdEntity>> Creating(InterceptorParameters args, ZeroIdEntity model) => Task.FromResult<InterceptorResult<ZeroIdEntity>>(default);
public virtual Task<InterceptorResult<FinchIdEntity>> Creating(InterceptorParameters args, FinchIdEntity model) => Task.FromResult<InterceptorResult<FinchIdEntity>>(default);
/// <inheritdoc />
public virtual Task<InterceptorResult<ZeroIdEntity>> Updating(InterceptorParameters args, ZeroIdEntity model) => Task.FromResult<InterceptorResult<ZeroIdEntity>>(default);
public virtual Task<InterceptorResult<FinchIdEntity>> Updating(InterceptorParameters args, FinchIdEntity model) => Task.FromResult<InterceptorResult<FinchIdEntity>>(default);
/// <inheritdoc />
public virtual Task<InterceptorResult<ZeroIdEntity>> Deleting(InterceptorParameters args, ZeroIdEntity model) => Task.FromResult<InterceptorResult<ZeroIdEntity>>(default);
public virtual Task<InterceptorResult<FinchIdEntity>> Deleting(InterceptorParameters args, FinchIdEntity model) => Task.FromResult<InterceptorResult<FinchIdEntity>>(default);
/// <inheritdoc />
public virtual Task Created(InterceptorParameters args, ZeroIdEntity model) => Task.CompletedTask;
public virtual Task Created(InterceptorParameters args, FinchIdEntity model) => Task.CompletedTask;
/// <inheritdoc />
public virtual Task Updated(InterceptorParameters args, ZeroIdEntity model) => Task.CompletedTask;
public virtual Task Updated(InterceptorParameters args, FinchIdEntity model) => Task.CompletedTask;
/// <inheritdoc />
public virtual Task Deleted(InterceptorParameters args, ZeroIdEntity model) => Task.CompletedTask;
public virtual Task Deleted(InterceptorParameters args, FinchIdEntity model) => Task.CompletedTask;
}
public interface IInterceptor<T> : IInterceptor where T : ZeroIdEntity
public interface IInterceptor<T> : IInterceptor where T : FinchIdEntity
{
/// <summary>
/// Type of the associated model
@@ -178,30 +178,30 @@ public interface IInterceptor
/// <summary>
/// Called after an entity has been stored but before the session has saved its changes
/// </summary>
Task Created(InterceptorParameters args, ZeroIdEntity model);
Task Created(InterceptorParameters args, FinchIdEntity model);
/// <summary>
/// Called before an entity is stored and validated
/// </summary>
Task<InterceptorResult<ZeroIdEntity>> Creating(InterceptorParameters args, ZeroIdEntity model);
Task<InterceptorResult<FinchIdEntity>> Creating(InterceptorParameters args, FinchIdEntity model);
/// <summary>
/// Called after an entity has been deleted but before the session has saved its changes
/// </summary>
Task Deleted(InterceptorParameters args, ZeroIdEntity model);
Task Deleted(InterceptorParameters args, FinchIdEntity model);
/// <summary>
/// Called before an entity is deleted
/// </summary>
Task<InterceptorResult<ZeroIdEntity>> Deleting(InterceptorParameters args, ZeroIdEntity model);
Task<InterceptorResult<FinchIdEntity>> Deleting(InterceptorParameters args, FinchIdEntity model);
/// <summary>
/// Called after an entity has been updated but before the session has saved its changes
/// </summary>
Task Updated(InterceptorParameters args, ZeroIdEntity model);
Task Updated(InterceptorParameters args, FinchIdEntity model);
/// <summary>
/// Called before an entity is stored and validated
/// </summary>
Task<InterceptorResult<ZeroIdEntity>> Updating(InterceptorParameters args, ZeroIdEntity model);
Task<InterceptorResult<FinchIdEntity>> Updating(InterceptorParameters args, FinchIdEntity model);
}
@@ -1,8 +1,8 @@
using Microsoft.Extensions.Logging;
namespace zero.Raven;
namespace Finch.Raven;
public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
public class InterceptorInstruction<T> where T : FinchIdEntity, new()
{
public Guid Guid { get; private set; }
@@ -16,9 +16,9 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
public Result<T> Result { get; private set; }
protected IZeroContext Context { get; private set; }
protected IFinchContext Context { get; private set; }
protected IZeroStore Store { get; private set; }
protected IFinchStore Store { get; private set; }
protected Lazy<IEnumerable<IInterceptor>> Interceptors { get; private set; }
@@ -31,7 +31,7 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
protected Func<IInterceptor, bool> InterceptorFilter { get; private set; } = x => true;
internal InterceptorInstruction(IInterceptors interceptors, IZeroStore store, IZeroContext context, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger, InterceptorRunType runtype, T model, T previousModel = null)
internal InterceptorInstruction(IInterceptors interceptors, IFinchStore store, IFinchContext context, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger, InterceptorRunType runtype, T model, T previousModel = null)
{
InterceptorHandler = interceptors;
Store = store;
@@ -83,7 +83,7 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
Logger.LogDebug("Run interceptor {interceptor} for {type}:{operation}", interceptor.Name, ModelType, Runtype);
InterceptorResult<ZeroIdEntity> result = (await HandleBefore(interceptor, parameters)) ?? new();
InterceptorResult<FinchIdEntity> result = (await HandleBefore(interceptor, parameters)) ?? new();
result.InterceptorHash = IdGenerator.Create(32);
InterceptorCache.Add(interceptor, parameters);
@@ -129,7 +129,7 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
/// <summary>
/// Proxy for handling methods on an interceptor
/// </summary>
protected Task<InterceptorResult<ZeroIdEntity>> HandleBefore(IInterceptor interceptor, InterceptorParameters parameters) => Runtype switch
protected Task<InterceptorResult<FinchIdEntity>> HandleBefore(IInterceptor interceptor, InterceptorParameters parameters) => Runtype switch
{
InterceptorRunType.Create => interceptor.Creating(parameters, Model),
InterceptorRunType.Update => interceptor.Updating(parameters, Model),
@@ -1,16 +1,16 @@
namespace zero.Raven;
namespace Finch.Raven;
public class InterceptorParameters
{
/// <summary>
/// The current zero context
/// The current finch context
/// </summary>
public IZeroContext Context { get; set; }
public IFinchContext Context { get; set; }
/// <summary>
/// Raven document store
/// </summary>
public IZeroStore Store { get; set; }
public IFinchStore Store { get; set; }
/// <summary>
/// Access to other interceptor methods
@@ -1,4 +1,4 @@
namespace zero.Raven;
namespace Finch.Raven;
public class InterceptorResult<T>
{
@@ -1,4 +1,4 @@
namespace zero.Raven;
namespace Finch.Raven;
public enum InterceptorRunType
{
@@ -1,19 +1,19 @@
using Microsoft.Extensions.Logging;
namespace zero.Raven;
namespace Finch.Raven;
public class Interceptors : IInterceptors
{
protected IZeroContext Context { get; set; }
protected IFinchContext Context { get; set; }
protected IZeroStore Store { get; set; }
protected IFinchStore Store { get; set; }
protected Lazy<IEnumerable<IInterceptor>> Registrations { get; set; }
protected ILogger<IInterceptor> Logger { get; set; }
public Interceptors(IZeroContext context, IZeroStore store, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger)
public Interceptors(IFinchContext context, IFinchStore store, Lazy<IEnumerable<IInterceptor>> registrations, ILogger<IInterceptor> logger)
{
Context = context;
Store = store;
@@ -23,13 +23,13 @@ public class Interceptors : IInterceptors
/// <inheritdoc />
public InterceptorInstruction<T> ForCreate<T>(T model) where T : ZeroIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Create, model);
public InterceptorInstruction<T> ForCreate<T>(T model) where T : FinchIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Create, model);
/// <inheritdoc />
public InterceptorInstruction<T> ForUpdate<T>(T model, T previousModel = null) where T : ZeroIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Update, model, previousModel);
public InterceptorInstruction<T> ForUpdate<T>(T model, T previousModel = null) where T : FinchIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Update, model, previousModel);
/// <inheritdoc />
public InterceptorInstruction<T> ForDelete<T>(T model) where T : ZeroIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Delete, model);
public InterceptorInstruction<T> ForDelete<T>(T model) where T : FinchIdEntity, new() => new(this, Store, Context, Registrations, Logger, InterceptorRunType.Delete, model);
}
@@ -38,15 +38,15 @@ public interface IInterceptors
/// <summary>
/// Instruction which can run interceptors before and after a creating an entity
/// </summary>
InterceptorInstruction<T> ForCreate<T>(T model) where T : ZeroIdEntity, new();
InterceptorInstruction<T> ForCreate<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Instruction which can run interceptors before and after updating an entity
/// </summary>
InterceptorInstruction<T> ForUpdate<T>(T model, T previousModel = null) where T : ZeroIdEntity, new();
InterceptorInstruction<T> ForUpdate<T>(T model, T previousModel = null) where T : FinchIdEntity, new();
/// <summary>
/// Instruction which can run interceptors before and after deleting an entity
/// </summary>
InterceptorInstruction<T> ForDelete<T>(T model) where T : ZeroIdEntity, new();
InterceptorInstruction<T> ForDelete<T>(T model) where T : FinchIdEntity, new();
}
@@ -2,17 +2,17 @@
using Raven.Client.Documents.Queries;
using Raven.Client;
namespace zero.Raven;
namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations
{
/// <inheritdoc />
public virtual Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new()
public virtual Task<Result<T>> Delete<T>(T model) where T : FinchIdEntity, new()
=> Delete<T>(model.Id);
/// <inheritdoc />
public virtual async Task<Result<T>> Delete<T>(string id) where T : ZeroIdEntity, new()
public virtual async Task<Result<T>> Delete<T>(string id) where T : FinchIdEntity, new()
{
T model = await Load<T>(id);
@@ -49,7 +49,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task Purge<T>(string querySuffix = null, Parameters parameters = null) where T : ZeroIdEntity, new()
public virtual async Task Purge<T>(string querySuffix = null, Parameters parameters = null) where T : FinchIdEntity, new()
{
var collectionName = Store.Raven.Conventions.FindCollectionName(typeof(T));
var operationQuery = new DeleteByQueryOperation(new IndexQuery()
@@ -1,14 +1,14 @@
namespace zero.Raven;
namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations
{
/// <inheritdoc />
public virtual Task<T> Empty<T>(string flavorAlias = null) where T : ZeroIdEntity, ISupportsFlavors, new() => Empty<T, T>(flavorAlias);
public virtual Task<T> Empty<T>(string flavorAlias = null) where T : FinchIdEntity, ISupportsFlavors, new() => Empty<T, T>(flavorAlias);
/// <inheritdoc />
public virtual Task<TFlavor> Empty<T, TFlavor>(string flavorAlias = null)
where T : ZeroIdEntity, ISupportsFlavors, new()
where T : FinchIdEntity, ISupportsFlavors, new()
where TFlavor : T, new()
{
return Task.FromResult(Flavors.Construct<T, TFlavor>(flavorAlias));
@@ -4,12 +4,12 @@ using Raven.Client.Documents.Linq;
using Raven.Client.Documents.Session;
using System.Linq.Expressions;
namespace zero.Raven;
namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations
{
/// <inheritdoc />
public virtual async Task<T> Load<T>(string id, string changeVector = null) where T : ZeroIdEntity, new()
public virtual async Task<T> Load<T>(string id, string changeVector = null) where T : FinchIdEntity, new()
{
if (id.IsNullOrWhiteSpace())
{
@@ -25,7 +25,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new()
public virtual async Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : FinchIdEntity, new()
{
ids = ids.Distinct().ToArray();
@@ -43,7 +43,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new()
public virtual async Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : FinchIdEntity, new()
{
ids = ids.Distinct().ToArray();
@@ -64,7 +64,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<bool> Any<T>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : ZeroIdEntity, new()
public virtual async Task<bool> Any<T>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : FinchIdEntity, new()
{
querySelector ??= x => x;
return await querySelector(Session.Query<T>()).AnyAsync();
@@ -72,7 +72,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<Paged<T>> Load<T>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : ZeroIdEntity, new()
public virtual async Task<Paged<T>> Load<T>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : FinchIdEntity, new()
{
IRavenQueryable<T> queryable = Session.Query<T>().Statistics(out QueryStatistics statistics);
querySelector ??= x => x;
@@ -84,7 +84,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<Paged<T>> Load<T, TIndex>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default)
where T : ZeroIdEntity, new()
where T : FinchIdEntity, new()
where TIndex : AbstractCommonApiForIndexes, new()
{
IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Statistics(out QueryStatistics statistics);
@@ -96,7 +96,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<List<T>> Load<T>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector) where T : ZeroIdEntity, new()
public virtual async Task<List<T>> Load<T>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector) where T : FinchIdEntity, new()
{
IRavenQueryable<T> queryable = Session.Query<T>();
querySelector ??= x => x;
@@ -107,7 +107,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<List<T>> Load<T, TIndex>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector)
where T : ZeroIdEntity, new()
where T : FinchIdEntity, new()
where TIndex : AbstractCommonApiForIndexes, new()
{
IRavenQueryable<T> queryable = Session.Query<T, TIndex>();
@@ -118,7 +118,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<List<T>> Load<T>(Expression<Func<T, bool>> predicate) where T : ZeroIdEntity, new()
public virtual async Task<List<T>> Load<T>(Expression<Func<T, bool>> predicate) where T : FinchIdEntity, new()
{
return await Session.Query<T>().Where(predicate).ToListAsync();
}
@@ -126,7 +126,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<List<T>> Load<T, TIndex>(Expression<Func<T, bool>> predicate)
where T : ZeroIdEntity, new()
where T : FinchIdEntity, new()
where TIndex : AbstractCommonApiForIndexes, new()
{
return await Session.Query<T, TIndex>().Where(predicate).ToListAsync();
@@ -135,8 +135,8 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<Paged<TProjection>> Load<T, TIndex, TProjection>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default)
where T : ZeroIdEntity, new()
where TProjection : ZeroIdEntity, new()
where T : FinchIdEntity, new()
where TProjection : FinchIdEntity, new()
where TIndex : AbstractCommonApiForIndexes, new()
{
IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Statistics(out QueryStatistics statistics);
@@ -148,7 +148,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<List<T>> LoadAll<T>() where T : ZeroIdEntity, new()
public virtual async Task<List<T>> LoadAll<T>() where T : FinchIdEntity, new()
{
List<T> items = new();
@@ -162,7 +162,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async IAsyncEnumerable<T> Stream<T>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : ZeroIdEntity, new()
public virtual async IAsyncEnumerable<T> Stream<T>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : FinchIdEntity, new()
{
IRavenQueryable<T> query = Session.Query<T>();
IQueryable<T> queryable = query;
@@ -187,7 +187,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual string GetChangeToken<T>(T model) where T : ZeroIdEntity, new()
public virtual string GetChangeToken<T>(T model) where T : FinchIdEntity, new()
{
string changeVector = Session.Advanced.GetChangeVectorFor(model);
return IdGenerator.HashString(changeVector);
@@ -3,12 +3,12 @@ using Raven.Client.Documents.Indexes;
using Raven.Client.Documents.Linq;
using Raven.Client.Documents.Session;
namespace zero.Raven;
namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations
{
/// <inheritdoc />
public virtual Task<bool> IsAllowedAsChild<T>(T model, string parentId) where T : ZeroIdEntity, ISupportsTrees, new()
public virtual Task<bool> IsAllowedAsChild<T>(T model, string parentId) where T : FinchIdEntity, ISupportsTrees, new()
{
return Task.FromResult(true);
}
@@ -16,13 +16,13 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<T[]> GetHierarchy<T, TIndex>(string id)
where T : ZeroIdEntity, ISupportsTrees, new()
where TIndex : ZeroTreeHierarchyIndex<T>, new()
where T : FinchIdEntity, ISupportsTrees, new()
where TIndex : FinchTreeHierarchyIndex<T>, new()
{
ZeroTreeHierarchyIndexResult result = await Session.Query<ZeroTreeHierarchyIndexResult, TIndex>()
.ProjectInto<ZeroTreeHierarchyIndexResult>()
.Include<ZeroTreeHierarchyIndexResult, T>(x => x.Path)
.Include<ZeroTreeHierarchyIndexResult, T>(x => x.Id)
FinchTreeHierarchyIndexResult result = await Session.Query<FinchTreeHierarchyIndexResult, TIndex>()
.ProjectInto<FinchTreeHierarchyIndexResult>()
.Include<FinchTreeHierarchyIndexResult, T>(x => x.Path)
.Include<FinchTreeHierarchyIndexResult, T>(x => x.Id)
.FirstOrDefaultAsync(x => x.Id == id);
if (result == null)
@@ -38,7 +38,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<Paged<T>> LoadChildren<T>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : ZeroIdEntity, ISupportsTrees, new()
public async Task<Paged<T>> LoadChildren<T>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : FinchIdEntity, ISupportsTrees, new()
{
IRavenQueryable<T> queryable = Session.Query<T>().Where(x => x.ParentId == parentId).Statistics(out QueryStatistics statistics);
querySelector ??= x => x.OrderBy(x => x.Sort);
@@ -50,7 +50,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<Paged<T>> LoadChildren<T, TIndex>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default)
where T : ZeroIdEntity, ISupportsTrees, new()
where T : FinchIdEntity, ISupportsTrees, new()
where TIndex : AbstractCommonApiForIndexes, new()
{
IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Where(x => x.ParentId == parentId).Statistics(out QueryStatistics statistics);
@@ -64,7 +64,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<Result<T>> Move<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : ZeroIdEntity, ISupportsTrees, new()
public async Task<Result<T>> Move<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : FinchIdEntity, ISupportsTrees, new()
{
T model = await Load<T>(id);
T parent = await Load<T>(newParentId);
@@ -86,17 +86,17 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public Task<Result<T>> Copy<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : ZeroIdEntity, ISupportsTrees, new() => Copy<T>(id, newParentId, false, isParentAllowed);
public Task<Result<T>> Copy<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : FinchIdEntity, ISupportsTrees, new() => Copy<T>(id, newParentId, false, isParentAllowed);
/// <inheritdoc />
public Task<Result<T>> CopyWithDescendants<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : ZeroIdEntity, ISupportsTrees, new() => Copy<T>(id, newParentId, true, isParentAllowed);
public Task<Result<T>> CopyWithDescendants<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : FinchIdEntity, ISupportsTrees, new() => Copy<T>(id, newParentId, true, isParentAllowed);
/// <summary>
/// Copies an entity (with optional descendants) to a new location
/// </summary>
protected async Task<Result<T>> Copy<T>(string id, string newParentId, bool includeDescendants, Func<T, string, Task<bool>> isParentAllowed = null, bool isDescendant = false) where T : ZeroIdEntity, ISupportsTrees, new()
protected async Task<Result<T>> Copy<T>(string id, string newParentId, bool includeDescendants, Func<T, string, Task<bool>> isParentAllowed = null, bool isDescendant = false) where T : FinchIdEntity, ISupportsTrees, new()
{
T originalModel = await Load<T>(id);
T model = ObjectCopycat.Clone(originalModel);
@@ -114,11 +114,11 @@ public partial class RavenOperations : IRavenOperations
model.Id = null;
model.ParentId = parent?.Id;
if (model is ZeroEntity zeroEntity)
if (model is FinchEntity finchEntity)
{
zeroEntity.IsActive = !isDescendant ? false : (originalModel as ZeroEntity).IsActive;
zeroEntity.CreatedDate = DateTime.Now;
zeroEntity.Hash = null;
finchEntity.IsActive = !isDescendant ? false : (originalModel as FinchEntity).IsActive;
finchEntity.CreatedDate = DateTime.Now;
finchEntity.Hash = null;
}
// check if new parent is allowed
@@ -145,7 +145,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<Result<string[]>> DeleteWithDescendants<T>(T model) where T : ZeroIdEntity, ISupportsTrees, new()
public async Task<Result<string[]>> DeleteWithDescendants<T>(T model) where T : FinchIdEntity, ISupportsTrees, new()
{
List<T> pages = await GetDescendantsAndSelf(model);
@@ -162,7 +162,7 @@ public partial class RavenOperations : IRavenOperations
/// <summary>
/// Get an entity with all its descendants
/// </summary>
async Task<List<T>> GetDescendantsAndSelf<T>(T model) where T : ZeroIdEntity, ISupportsTrees, new()
async Task<List<T>> GetDescendantsAndSelf<T>(T model) where T : FinchIdEntity, ISupportsTrees, new()
{
List<T> items = new() { model };
@@ -1,18 +1,18 @@
using FluentValidation.Results;
using Rv = Raven.Client;
namespace zero.Raven;
namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations
{
/// <inheritdoc />
public virtual Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : ZeroIdEntity, new() => Save(model, validate, onAfterStore);
public virtual Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : FinchIdEntity, new() => Save(model, validate, onAfterStore);
/// <inheritdoc />
public virtual Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : ZeroIdEntity, new() => Save(model, validate, onAfterStore, true);
public virtual Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : FinchIdEntity, new() => Save(model, validate, onAfterStore, true);
/// <inheritdoc />
protected virtual async Task<Result<T>> Save<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null, bool update = false) where T : ZeroIdEntity, new()
protected virtual async Task<Result<T>> Save<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null, bool update = false) where T : FinchIdEntity, new()
{
if (model == null)
{
@@ -91,7 +91,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<Result<IOrderedEnumerable<T>>> Sort<T>(string[] sortedIds) where T : ZeroIdEntity, ISupportsSorting, new()
public async Task<Result<IOrderedEnumerable<T>>> Sort<T>(string[] sortedIds) where T : FinchIdEntity, ISupportsSorting, new()
{
Dictionary<string, T> items = await Load<T>(sortedIds);
uint index = 10;
@@ -114,7 +114,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual async Task<Result<IEnumerable<T>>> CreateAll<T>(IEnumerable<T> models) where T : ZeroIdEntity, new()
public virtual async Task<Result<IEnumerable<T>>> CreateAll<T>(IEnumerable<T> models) where T : FinchIdEntity, new()
{
using var bulkInsert = Store.Raven.BulkInsert();
@@ -6,7 +6,7 @@ using Raven.Client.Documents.Linq;
using System.Linq.Expressions;
using System.Security.Claims;
namespace zero.Raven;
namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations
{
@@ -15,7 +15,7 @@ public partial class RavenOperations : IRavenOperations
protected record OperationOptions(bool IncludeInactive);
protected IZeroContext Context { get; private set; }
protected IFinchContext Context { get; private set; }
protected IInterceptors Interceptors { get; private set; }
@@ -23,7 +23,7 @@ public partial class RavenOperations : IRavenOperations
protected IServiceProvider Services { get; private set; }
protected IZeroStore Store { get; private set; }
protected IFinchStore Store { get; private set; }
protected StoreInterceptorBlocker InterceptorBlocker { get; private set; }
@@ -39,7 +39,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<string> GenerateId<T>(T model) where T : ZeroIdEntity
public async Task<string> GenerateId<T>(T model) where T : FinchIdEntity
{
IAsyncDocumentSession session = Session;
return await session.Advanced.DocumentStore.Conventions.GenerateDocumentIdAsync(session.Advanced.DocumentStore.Database, model);
@@ -54,33 +54,33 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public T PrepareForSave<T>(T model) where T : ZeroIdEntity
public T PrepareForSave<T>(T model) where T : FinchIdEntity
{
// set IDs
AutoSetIds(model);
if (model is ZeroEntity zeroModel)
if (model is FinchEntity finchModel)
{
// get current user
string userId = null;
//string userId = Context.BackofficeUser.FindFirstValue(Constants.Auth.Claims.UserId).Or(Constants.Auth.SystemUser);
// set default properties
if (zeroModel.CreatedDate == default)
if (finchModel.CreatedDate == default)
{
zeroModel.CreatedDate = DateTimeOffset.Now;
finchModel.CreatedDate = DateTimeOffset.Now;
}
if (zeroModel.CreatedById.IsNullOrEmpty())
if (finchModel.CreatedById.IsNullOrEmpty())
{
zeroModel.CreatedById = userId;
finchModel.CreatedById = userId;
}
// update name alias and last modified
zeroModel.Alias = Safenames.Alias(zeroModel.Name);
zeroModel.LastModifiedById = userId;
zeroModel.LastModifiedDate = DateTimeOffset.Now;
zeroModel.CreatedById ??= userId;
zeroModel.Hash ??= IdGenerator.Create();
finchModel.Alias = Safenames.Alias(finchModel.Name);
finchModel.LastModifiedById = userId;
finchModel.LastModifiedDate = DateTimeOffset.Now;
finchModel.CreatedById ??= userId;
finchModel.Hash ??= IdGenerator.Create();
}
return model;
@@ -88,9 +88,9 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public async Task<ValidationResult> Validate<T>(T model) where T : ZeroIdEntity, new()
public async Task<ValidationResult> Validate<T>(T model) where T : FinchIdEntity, new()
{
IZeroMergedValidator<T> validator = Services.GetService<IZeroMergedValidator<T>>();
IFinchMergedValidator<T> validator = Services.GetService<IFinchMergedValidator<T>>();
if (validator == null)
{
@@ -109,10 +109,10 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc />
public virtual T WhenActive<T>(T model) where T : ZeroIdEntity, new()
public virtual T WhenActive<T>(T model) where T : FinchIdEntity, new()
{
return model; // TODO should we really use this? I tried to get data in a custom backend but couldn't because of this
//return model != null && (model is not ZeroEntity || (model as ZeroEntity).IsActive) && (model is not ISupportsSoftDelete || !(model as ISupportsSoftDelete).IsDeleted) ? model : default;
//return model != null && (model is not FinchEntity || (model as FinchEntity).IsActive) && (model is not ISupportsSoftDelete || !(model as ISupportsSoftDelete).IsDeleted) ? model : default;
}
}
@@ -143,20 +143,20 @@ public interface IRavenOperations
/// <summary>
/// Get new instance of an entity (with an optional flavor)
/// </summary>
Task<T> Empty<T>(string flavorAlias = null) where T : ZeroIdEntity, ISupportsFlavors, new();
Task<T> Empty<T>(string flavorAlias = null) where T : FinchIdEntity, ISupportsFlavors, new();
/// <summary>
/// Get new instance of an entity with a specific flavor
/// </summary>
/// <param name="flavorAlias">Optional alias. If left out the default flavor is used (if configured)</param>
Task<TFlavor> Empty<T, TFlavor>(string flavorAlias = null)
where T : ZeroIdEntity, ISupportsFlavors, new()
where T : FinchIdEntity, ISupportsFlavors, new()
where TFlavor : T, new();
/// <summary>
/// Generate model Id by using configured document store conventions
/// </summary>
Task<string> GenerateId<T>(T model) where T : ZeroIdEntity;
Task<string> GenerateId<T>(T model) where T : FinchIdEntity;
/// <summary>
/// Generate values for all properties (incl. nested) which contain the [GenerateId] attribute
@@ -164,88 +164,88 @@ public interface IRavenOperations
T AutoSetIds<T>(T model);
/// <summary>
/// Automatically fill base properties of a ZeroEntity
/// Automatically fill base properties of a FinchEntity
/// </summary>
T PrepareForSave<T>(T model) where T : ZeroIdEntity;
T PrepareForSave<T>(T model) where T : FinchIdEntity;
/// <summary>
/// Check if any items exist in this collection (with optional query)
/// </summary>
Task<bool> Any<T>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : ZeroIdEntity, new();
Task<bool> Any<T>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : FinchIdEntity, new();
/// <summary>
/// Get an entity by Id
/// </summary>
Task<T> Load<T>(string id, string changeVector = null) where T : ZeroIdEntity, new();
Task<T> Load<T>(string id, string changeVector = null) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by ids
/// </summary>
Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new();
Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by ids
/// </summary>
Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new();
Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by query
/// </summary>
Task<Paged<T>> Load<T>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> expression = default) where T : ZeroIdEntity, new();
Task<Paged<T>> Load<T>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> expression = default) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by query (by using the specified index)
/// </summary>
Task<Paged<T>> Load<T, TIndex>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> expression = default) where T : ZeroIdEntity, new() where TIndex : AbstractCommonApiForIndexes, new();
Task<Paged<T>> Load<T, TIndex>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> expression = default) where T : FinchIdEntity, new() where TIndex : AbstractCommonApiForIndexes, new();
/// <summary>
/// Get entities by query
/// </summary>
Task<List<T>> Load<T>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : ZeroIdEntity, new();
Task<List<T>> Load<T>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by query (by using the specified index)
/// </summary>
Task<List<T>> Load<T, TIndex>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : ZeroIdEntity, new() where TIndex : AbstractCommonApiForIndexes, new();
Task<List<T>> Load<T, TIndex>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : FinchIdEntity, new() where TIndex : AbstractCommonApiForIndexes, new();
/// <summary>
/// Get entities by query
/// </summary>
Task<List<T>> Load<T>(Expression<Func<T, bool>> predicate) where T : ZeroIdEntity, new();
Task<List<T>> Load<T>(Expression<Func<T, bool>> predicate) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by query (by using the specified index)
/// </summary>
Task<List<T>> Load<T, TIndex>(Expression<Func<T, bool>> predicate) where T : ZeroIdEntity, new() where TIndex : AbstractCommonApiForIndexes, new();
Task<List<T>> Load<T, TIndex>(Expression<Func<T, bool>> predicate) where T : FinchIdEntity, new() where TIndex : AbstractCommonApiForIndexes, new();
/// <summary>
/// Get entities by query (by using the specified index) and project into a result
/// </summary>
Task<Paged<TProjection>> Load<T, TIndex, TProjection>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default)
where T : ZeroIdEntity, new()
where TProjection : ZeroIdEntity, new()
where T : FinchIdEntity, new()
where TProjection : FinchIdEntity, new()
where TIndex : AbstractCommonApiForIndexes, new();
/// <summary>
/// Get all entities from this collection.
/// Warning: Don't use this method for large collections. Stream the results instead.
/// </summary>
Task<List<T>> LoadAll<T>() where T : ZeroIdEntity, new();
Task<List<T>> LoadAll<T>() where T : FinchIdEntity, new();
/// <summary>
/// Stream the collection
/// </summary>
IAsyncEnumerable<T> Stream<T>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : ZeroIdEntity, new();
IAsyncEnumerable<T> Stream<T>(Func<IRavenQueryable<T>, IQueryable<T>> expression) where T : FinchIdEntity, new();
/// <summary>
/// Get the change vector for a model
/// </summary>
string GetChangeToken<T>(T model) where T : ZeroIdEntity, new();
string GetChangeToken<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Validates an entity
/// </summary>
Task<ValidationResult> Validate<T>(T model) where T : ZeroIdEntity, new();
Task<ValidationResult> Validate<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Do not run interceptors for create/update/delete operations while this disposable is active
@@ -255,73 +255,73 @@ public interface IRavenOperations
/// <summary>
/// Do only return the model when it is set to active or inactive entities are included with IncludeInactive()
/// </summary>
T WhenActive<T>(T model) where T : ZeroIdEntity, new();
T WhenActive<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Creates an entity with an optional validator
/// </summary>
Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : ZeroIdEntity, new();
Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : FinchIdEntity, new();
/// <summary>
/// Updates an entity with an optional validator
/// </summary>
Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : ZeroIdEntity, new();
Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null, Action<IAsyncDocumentSession> onAfterStore = null) where T : FinchIdEntity, new();
/// <inheritdoc />
Task<Result<IOrderedEnumerable<T>>> Sort<T>(string[] sortedIds) where T : ZeroIdEntity, ISupportsSorting, new();
Task<Result<IOrderedEnumerable<T>>> Sort<T>(string[] sortedIds) where T : FinchIdEntity, ISupportsSorting, new();
/// <summary>
/// Batch create entities
/// </summary>
Task<Result<IEnumerable<T>>> CreateAll<T>(IEnumerable<T> models) where T : ZeroIdEntity, new();
Task<Result<IEnumerable<T>>> CreateAll<T>(IEnumerable<T> models) where T : FinchIdEntity, new();
/// <summary>
/// Deletes an entity
/// </summary>
Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new();
Task<Result<T>> Delete<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Deletes an entity
/// </summary>
Task<Result<T>> Delete<T>(string id) where T : ZeroIdEntity, new();
Task<Result<T>> Delete<T>(string id) where T : FinchIdEntity, new();
/// <summary>
/// Deletes the whole collection
/// </summary>
Task Purge<T>(string querySuffix = null, Parameters parameters = null) where T : ZeroIdEntity, new();
Task Purge<T>(string querySuffix = null, Parameters parameters = null) where T : FinchIdEntity, new();
/// <summary>
/// Loads all children for an entity
/// </summary>
Task<Paged<T>> LoadChildren<T>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : ZeroIdEntity, ISupportsTrees, new();
Task<Paged<T>> LoadChildren<T>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : FinchIdEntity, ISupportsTrees, new();
/// <summary>
/// Get descendants by query (by using the specified index)
/// </summary>
Task<Paged<T>> LoadChildren<T, TIndex>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : ZeroIdEntity, ISupportsTrees, new() where TIndex : AbstractCommonApiForIndexes, new();
Task<Paged<T>> LoadChildren<T, TIndex>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) where T : FinchIdEntity, ISupportsTrees, new() where TIndex : AbstractCommonApiForIndexes, new();
/// <summary>
/// Get tree hierarchy for an entity
/// </summary>
Task<T[]> GetHierarchy<T, TIndex>(string id) where T : ZeroIdEntity, ISupportsTrees, new() where TIndex : ZeroTreeHierarchyIndex<T>, new();
Task<T[]> GetHierarchy<T, TIndex>(string id) where T : FinchIdEntity, ISupportsTrees, new() where TIndex : FinchTreeHierarchyIndex<T>, new();
/// <summary>
/// Move an entity to a new parent
/// </summary>
Task<Result<T>> Move<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : ZeroIdEntity, ISupportsTrees, new();
Task<Result<T>> Move<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : FinchIdEntity, ISupportsTrees, new();
/// <summary>
/// Copies an entity to a new location
/// </summary>
Task<Result<T>> Copy<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : ZeroIdEntity, ISupportsTrees, new();
Task<Result<T>> Copy<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : FinchIdEntity, ISupportsTrees, new();
/// <summary>
/// Copies an entity with descendants to a new location
/// </summary>
Task<Result<T>> CopyWithDescendants<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : ZeroIdEntity, ISupportsTrees, new();
Task<Result<T>> CopyWithDescendants<T>(string id, string newParentId, Func<T, string, Task<bool>> isParentAllowed = null) where T : FinchIdEntity, ISupportsTrees, new();
/// <summary>
/// Deletes an entity with all descendents
/// </summary>
Task<Result<string[]>> DeleteWithDescendants<T>(T model) where T : ZeroIdEntity, ISupportsTrees, new();
Task<Result<string[]>> DeleteWithDescendants<T>(T model) where T : FinchIdEntity, ISupportsTrees, new();
}
@@ -1,36 +1,36 @@
using Raven.Client.Documents.Linq;
using System.Linq.Expressions;
namespace zero.Raven;
namespace Finch.Raven;
public static class RavenOperationsExtensions
{
/// <summary>
/// Stream the collection
/// </summary>
public static IAsyncEnumerable<T> Stream<T>(this IRavenOperations ops) where T : ZeroIdEntity, new() => ops.Stream<T>(null);
public static IAsyncEnumerable<T> Stream<T>(this IRavenOperations ops) where T : FinchIdEntity, new() => ops.Stream<T>(null);
/// <summary>
/// Deletes an entity by Id
/// </summary>
public static async Task<Result<T>> Delete<T>(this IRavenOperations ops, string id) where T : ZeroIdEntity, new() => await ops.Delete(await ops.Load<T>(id));
public static async Task<Result<T>> Delete<T>(this IRavenOperations ops, string id) where T : FinchIdEntity, new() => await ops.Delete(await ops.Load<T>(id));
/// <summary>
/// Deletes entities by selector
/// </summary>
public static async Task<int> Delete<T>(this IRavenOperations ops, Expression<Func<T, bool>> predicate) where T : ZeroIdEntity, new() => await ops.Delete(await ops.Load<T>(predicate));
public static async Task<int> Delete<T>(this IRavenOperations ops, Expression<Func<T, bool>> predicate) where T : FinchIdEntity, new() => await ops.Delete(await ops.Load<T>(predicate));
/// <summary>
/// Deletes entities by Id
/// </summary>
public static async Task<int> Delete<T>(this IRavenOperations ops, IEnumerable<string> ids) where T : ZeroIdEntity, new() => await ops.Delete((await ops.Load<T>(ids)).Select(x => x.Value));
public static async Task<int> Delete<T>(this IRavenOperations ops, IEnumerable<string> ids) where T : FinchIdEntity, new() => await ops.Delete((await ops.Load<T>(ids)).Select(x => x.Value));
/// <summary>
/// Deletes entities
/// </summary>
public static async Task<int> Delete<T>(this IRavenOperations ops, IEnumerable<T> models) where T : ZeroIdEntity, new()
public static async Task<int> Delete<T>(this IRavenOperations ops, IEnumerable<T> models) where T : FinchIdEntity, new()
{
int successCount = 0;
@@ -46,5 +46,5 @@ public static class RavenOperationsExtensions
/// <summary>
/// Deletes an entity by Id with all descendents
/// </summary>
public static async Task<Result<string[]>> DeleteWithDescendants<T>(this IRavenOperations ops, string id) where T : ZeroIdEntity, ISupportsTrees, new() => await ops.DeleteWithDescendants(await ops.Load<T>(id));
public static async Task<Result<string[]>> DeleteWithDescendants<T>(this IRavenOperations ops, string id) where T : FinchIdEntity, ISupportsTrees, new() => await ops.DeleteWithDescendants(await ops.Load<T>(id));
}
@@ -1,12 +1,12 @@
namespace zero.Raven;
namespace Finch.Raven;
public class StoreContext
{
public IZeroStore Store { get; private set; }
public IFinchStore Store { get; private set; }
public IZeroContext Context { get; private set; }
public IFinchContext Context { get; private set; }
public IZeroOptions Options { get; private set; }
public IFinchOptions Options { get; private set; }
public IInterceptors Interceptors { get; private set; }
@@ -15,7 +15,7 @@ public class StoreContext
public IMessageAggregator Messages { get; private set; }
public StoreContext(IZeroContext context, IZeroStore store, IInterceptors interceptors, IServiceProvider serviceProvider, IMessageAggregator messages)
public StoreContext(IFinchContext context, IFinchStore store, IInterceptors interceptors, IServiceProvider serviceProvider, IMessageAggregator messages)
{
Store = store;
Options = context.Options;
@@ -1,4 +1,4 @@
namespace zero.Raven;
namespace Finch.Raven;
/// <summary>
/// This attribute will allow the usage of custom collection names for Raven collections
@@ -1,4 +1,4 @@
namespace zero.Raven;
namespace Finch.Raven;
public static partial class RavenConstants
{
@@ -4,22 +4,22 @@ using System.Reflection;
using System.Text;
using Rv = Raven.Client;
namespace zero.Raven;
namespace Finch.Raven;
public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
{
protected HashSet<Type> PolymorphTypes { get; private set; } = new();
protected Type AcceptsZeroConventionsType { get; set; } = typeof(ISupportsDbConventions);
protected Type AcceptsFinchConventionsType { get; set; } = typeof(ISupportsDbConventions);
protected char IdentityPartsSeparator { get; set; } = '.';
protected IZeroOptions Options { get; private set; }
protected IFinchOptions Options { get; private set; }
protected static ConcurrentDictionary<Type, string> CachedTypeCollectionNameMap = new();
public RavenDocumentConventionsBuilder(IZeroOptions options)
public RavenDocumentConventionsBuilder(IFinchOptions options)
{
Options = options;
}
@@ -32,7 +32,7 @@ public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
conventions.IdentityPartsSeparator = IdentityPartsSeparator;
conventions.TransformTypeCollectionNameToDocumentIdPrefix = TransformTypeCollectionNameToDocumentIdPrefix;
conventions.FindCollectionName = FindCollectionName;
conventions.RegisterAsyncIdConvention<ZeroIdEntity>((_, entity) => GetDocumentId(conventions, entity));
conventions.RegisterAsyncIdConvention<FinchIdEntity>((_, entity) => GetDocumentId(conventions, entity));
}
@@ -80,7 +80,7 @@ public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
}
// do not alter non-internal entities
if (!AcceptsZeroConventionsType.IsAssignableFrom(type))
if (!AcceptsFinchConventionsType.IsAssignableFrom(type))
{
return cache(DocumentConventions.DefaultGetCollectionName(type));
}
@@ -94,7 +94,7 @@ public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
}
// use base interface if available
Type interfaceBaseType = type.GetInterfaces().FirstOrDefault(x => x.IsInterface && AcceptsZeroConventionsType.IsAssignableFrom(x) && x.Name != AcceptsZeroConventionsType.Name);
Type interfaceBaseType = type.GetInterfaces().FirstOrDefault(x => x.IsInterface && AcceptsFinchConventionsType.IsAssignableFrom(x) && x.Name != AcceptsFinchConventionsType.Name);
if (interfaceBaseType != null)
{
@@ -1,7 +1,7 @@
using Raven.Client.Documents;
using System.Linq.Expressions;
namespace zero.Raven;
namespace Finch.Raven;
public class RavenOptions
{
@@ -23,9 +23,9 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
{
internal Type Type { get; set; }
internal Expression<Func<IZeroIndexDefinition>> CreateIndex { get; set; }
internal Expression<Func<IFinchIndexDefinition>> CreateIndex { get; set; }
internal Map(Type type, Expression<Func<IZeroIndexDefinition>> create)
internal Map(Type type, Expression<Func<IFinchIndexDefinition>> create)
{
Type = type;
CreateIndex = create;
@@ -35,17 +35,17 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
public RavenIndexModifiersOptions Modifiers { get; private set; } = new();
public void Add<T>() where T : IZeroIndexDefinition, new()
public void Add<T>() where T : IFinchIndexDefinition, new()
{
base.Add(new Map(typeof(T), () => new T()));
}
public void Add(Type indexType)
{
base.Add(new Map(indexType, () => (IZeroIndexDefinition)Activator.CreateInstance(indexType)));
base.Add(new Map(indexType, () => (IFinchIndexDefinition)Activator.CreateInstance(indexType)));
}
public void Add<T>(T index) where T : IZeroIndexDefinition
public void Add<T>(T index) where T : IFinchIndexDefinition
{
base.Add(new Map(typeof(T), () => index));
}
@@ -59,8 +59,8 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
}
public void Replace<T, TReplaceWith>()
where T : IZeroIndexDefinition, new()
where TReplaceWith : IZeroIndexDefinition, new()
where T : IFinchIndexDefinition, new()
where TReplaceWith : IFinchIndexDefinition, new()
{
Replace(typeof(T), typeof(TReplaceWith));
}
@@ -75,13 +75,13 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
Add(replaceWith);
}
public IEnumerable<IZeroIndexDefinition> BuildAll(IZeroOptions options, IDocumentStore store)
public IEnumerable<IFinchIndexDefinition> BuildAll(IFinchOptions options, IDocumentStore store)
{
RavenOptions ravenOptions = options.For<RavenOptions>();
foreach (Map map in this)
{
IZeroIndexDefinition index = map.CreateIndex.Compile().Invoke();
IFinchIndexDefinition index = map.CreateIndex.Compile().Invoke();
index.Setup(options, store);
index.RunModifiers(ravenOptions);
yield return index;
@@ -96,10 +96,10 @@ public class RavenIndexModifiersOptions : List<RavenIndexModifiersOptions.Modifi
{
public Type Type { get; set; }
public Expression<Action<IZeroIndexDefinition>> Modify { get; set; }
public Expression<Action<IFinchIndexDefinition>> Modify { get; set; }
}
public void Add<T>(Action<T> modify) where T : IZeroIndexDefinition, new()
public void Add<T>(Action<T> modify) where T : IFinchIndexDefinition, new()
{
Add(new()
{
@@ -109,7 +109,7 @@ public class RavenIndexModifiersOptions : List<RavenIndexModifiersOptions.Modifi
}
public IEnumerable<Modifier> GetAllForType<T>() where T : IZeroIndexDefinition, new() => GetAllForType(typeof(T));
public IEnumerable<Modifier> GetAllForType<T>() where T : IFinchIndexDefinition, new() => GetAllForType(typeof(T));
public IEnumerable<Modifier> GetAllForType(Type type)
@@ -3,18 +3,18 @@ using Raven.Client.Documents.Session;
using System.Security.Cryptography;
using System.Text;
namespace zero.Raven;
namespace Finch.Raven;
public class ZeroTokenProvider : IZeroTokenProvider
public class FinchTokenProvider : IFinchTokenProvider
{
readonly char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-".ToCharArray();
readonly RandomNumberGenerator randonNumberGenerator;
protected IZeroStore Store { get; private set; }
protected IFinchStore Store { get; private set; }
public ZeroTokenProvider(IZeroStore store)
public FinchTokenProvider(IFinchStore store)
{
Store = store;
randonNumberGenerator = RandomNumberGenerator.Create();
@@ -246,7 +246,7 @@ public class ZeroTokenProvider : IZeroTokenProvider
}
public interface IZeroTokenProvider
public interface IFinchTokenProvider
{
/// <summary>
/// Generates a token for a <paramref name="key"/> with a specified <paramref name="expires"/> lifespan.
@@ -3,7 +3,7 @@ using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace zero.Raven;
namespace Finch.Raven;
/// <summary>
/// Replicates the Rfc6238AuthenticationService from ASP.NET Core internals as it isn't part of the public API
@@ -1,4 +1,4 @@
namespace zero.Raven;
namespace Finch.Raven;
[RavenCollection("Tokens")]
public class SecurityToken : ISupportsDbConventions
+11 -11
View File
@@ -6,17 +6,17 @@ global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using zero.Utils;
global using zero.Configuration;
global using zero.Extensions;
global using zero.FileStorage;
global using zero.Models;
global using zero.Modules;
global using zero.Rendering;
global using zero.Validation;
global using zero.Localization;
global using zero.Context;
global using zero.Communication;
global using Finch.Utils;
global using Finch.Configuration;
global using Finch.Extensions;
global using Finch.FileStorage;
global using Finch.Models;
global using Finch.Modules;
global using Finch.Rendering;
global using Finch.Validation;
global using Finch.Localization;
global using Finch.Context;
global using Finch.Communication;
global using Raven.Client.Documents;
global using Raven.Client.Documents.Operations;
@@ -2,9 +2,9 @@
using System.Linq;
using System.Linq.Expressions;
using ServiceStack.OrmLite;
using zero.Extensions;
using Finch.Extensions;
namespace zero.Sqlite;
namespace Finch.Sqlite;
public static class SqlExpressionExtensions
{
@@ -15,7 +15,7 @@ public static class SqlExpressionExtensions
if (pageNumber <= 0 || pageSize <= 0)
{
throw new NotSupportedException("Both pageNumber and pageSize must be greater than zero");
throw new NotSupportedException("Both pageNumber and pageSize must be greater than z_ero");
}
return source.Skip((pageNumber - 1) * pageSize).Take(pageSize);
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>zero.Sqlite</PackageId>
<PackageId>Finch.Sqlite</PackageId>
<Version>1.0.0</Version>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<RootNamespace>zero.Sqlite</RootNamespace>
<RootNamespace>Finch.Sqlite</RootNamespace>
<DebugType>embedded</DebugType>
</PropertyGroup>
@@ -15,7 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\zero\zero.csproj" />
<ProjectReference Include="..\Finch\Finch.csproj" />
</ItemGroup>
</Project>
@@ -2,19 +2,19 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ServiceStack.OrmLite;
using zero.Models;
using Finch.Models;
namespace zero.Sqlite;
namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations
{
/// <inheritdoc />
public virtual Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new()
public virtual Task<Result<T>> Delete<T>(T model) where T : FinchIdEntity, new()
=> Delete<T>(model.Id);
/// <inheritdoc />
public virtual async Task<Result<T>> Delete<T>(string id) where T : ZeroIdEntity, new()
public virtual async Task<Result<T>> Delete<T>(string id) where T : FinchIdEntity, new()
{
T model = await Load<T>(id);
@@ -5,16 +5,16 @@ using System.Linq.Expressions;
using System.Threading.Tasks;
using ServiceStack.OrmLite;
using ServiceStack.OrmLite.Dapper;
using zero.Extensions;
using zero.Models;
using zero.Utils;
using Finch.Extensions;
using Finch.Models;
using Finch.Utils;
namespace zero.Sqlite;
namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations
{
/// <inheritdoc />
public virtual async Task<T> Load<T>(string id, string changeVector = null) where T : ZeroIdEntity, new()
public virtual async Task<T> Load<T>(string id, string changeVector = null) where T : FinchIdEntity, new()
{
if (id.IsNullOrWhiteSpace())
{
@@ -30,7 +30,7 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc />
public virtual async Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new()
public virtual async Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : FinchIdEntity, new()
{
ids = ids.Distinct().ToArray();
@@ -48,7 +48,7 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc />
public virtual async Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new()
public virtual async Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : FinchIdEntity, new()
{
ids = ids.Distinct().ToArray();
@@ -69,35 +69,35 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc />
public virtual async Task<bool> Any<T>(Expression<Func<T, bool>> querySelector = null) where T : ZeroIdEntity, new()
public virtual async Task<bool> Any<T>(Expression<Func<T, bool>> querySelector = null) where T : FinchIdEntity, new()
{
return await Db.ExistsAsync(querySelector ?? (x => true));
}
/// <inheritdoc />
public virtual async Task<List<T>> Load<T>(Expression<Func<T, bool>> querySelector) where T : ZeroIdEntity, new()
public virtual async Task<List<T>> Load<T>(Expression<Func<T, bool>> querySelector) where T : FinchIdEntity, new()
{
return await Db.SelectAsync(querySelector ?? (x => true));
}
/// <inheritdoc />
public virtual async Task<T> Find<T>(Expression<Func<T, bool>> querySelector) where T : ZeroIdEntity, new()
public virtual async Task<T> Find<T>(Expression<Func<T, bool>> querySelector) where T : FinchIdEntity, new()
{
return await Db.SingleAsync(querySelector);
}
/// <inheritdoc />
public virtual async Task<List<T>> LoadBySql<T>(Func<SqlExpression<T>, SqlExpression<T>> querySelector) where T : ZeroIdEntity, new()
public virtual async Task<List<T>> LoadBySql<T>(Func<SqlExpression<T>, SqlExpression<T>> querySelector) where T : FinchIdEntity, new()
{
return await Db.SelectAsync(querySelector(Db.From<T>()));
}
/// <inheritdoc />
public virtual async Task<List<T>> LoadAll<T>() where T : ZeroIdEntity, new()
public virtual async Task<List<T>> LoadAll<T>() where T : FinchIdEntity, new()
{
return await Db.SelectAsync<T>(x => true);
}
@@ -5,28 +5,28 @@ using System.Threading.Tasks;
using FluentValidation.Results;
using Microsoft.Extensions.Logging;
using ServiceStack.OrmLite;
using zero.Models;
using zero.Extensions;
using Finch.Models;
using Finch.Extensions;
namespace zero.Sqlite;
namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations
{
/// <inheritdoc />
public virtual Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : ZeroIdEntity, new() => Save(model, validate);
public virtual Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : FinchIdEntity, new() => Save(model, validate);
/// <inheritdoc />
public virtual Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : ZeroIdEntity, new() => Save(model, validate, true);
public virtual Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : FinchIdEntity, new() => Save(model, validate, true);
/// <inheritdoc />
public virtual async Task<Result<T>> CreateOrUpdate<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : ZeroIdEntity, new()
public virtual async Task<Result<T>> CreateOrUpdate<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : FinchIdEntity, new()
{
bool update = !model.Id.IsNullOrEmpty() && await Any<T>(x => x.Id == model.Id);
return await Save(model, validate, update);
}
/// <inheritdoc />
protected virtual async Task<Result<T>> Save<T>(T model, Func<T, Task<ValidationResult>> validate = null, bool update = false) where T : ZeroIdEntity, new()
protected virtual async Task<Result<T>> Save<T>(T model, Func<T, Task<ValidationResult>> validate = null, bool update = false) where T : FinchIdEntity, new()
{
if (model == null)
{
@@ -84,9 +84,9 @@ public partial class DbOperations : IDbOperations
await Db.SaveAsync(model);
string action = update ? "Updated" : "Created";
if (model is ZeroEntity zeroEntity)
if (model is FinchEntity finchEntity)
{
Logger.LogInformation(action + " {id} with name {name}", model.Id, zeroEntity.Name);
Logger.LogInformation(action + " {id} with name {name}", model.Id, finchEntity.Name);
}
else
{
@@ -100,7 +100,7 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc />
public virtual async Task Sort<T>(IEnumerable<string> ids) where T : ZeroEntity, new()
public virtual async Task Sort<T>(IEnumerable<string> ids) where T : FinchEntity, new()
{
List<T> items = await LoadAll<T>();
@@ -8,17 +8,17 @@ using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using ServiceStack.OrmLite;
using zero.Communication;
using zero.Context;
using zero.Models;
using zero.Utils;
using zero.Validation;
using Finch.Communication;
using Finch.Context;
using Finch.Models;
using Finch.Utils;
using Finch.Validation;
namespace zero.Sqlite;
namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations
{
protected IZeroContext Context { get; private set; }
protected IFinchContext Context { get; private set; }
protected FlavorOptions Flavors { get; private set; }
@@ -43,14 +43,14 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc />
public bool EnsureTableExists<T>() where T : ZeroIdEntity
public bool EnsureTableExists<T>() where T : FinchIdEntity
{
return Db.CreateTableIfNotExists<T>();
}
/// <inheritdoc />
public Task<string> GenerateId<T>(T model) where T : ZeroIdEntity
public Task<string> GenerateId<T>(T model) where T : FinchIdEntity
{
return Task.FromResult(IdGenerator.Create(12));
}
@@ -64,35 +64,35 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc />
public T PrepareForSave<T>(T model) where T : ZeroIdEntity
public T PrepareForSave<T>(T model) where T : FinchIdEntity
{
// set IDs
AutoSetIds(model);
if (model is not ZeroEntity zeroModel)
if (model is not FinchEntity finchModel)
{
return model;
}
// set default properties
if (zeroModel.CreatedDate == default)
if (finchModel.CreatedDate == default)
{
zeroModel.CreatedDate = DateTimeOffset.Now;
finchModel.CreatedDate = DateTimeOffset.Now;
}
// update name alias and last modified
zeroModel.Alias = Safenames.Alias(zeroModel.Name);
zeroModel.LastModifiedDate = DateTimeOffset.Now;
zeroModel.Hash ??= IdGenerator.Create();
finchModel.Alias = Safenames.Alias(finchModel.Name);
finchModel.LastModifiedDate = DateTimeOffset.Now;
finchModel.Hash ??= IdGenerator.Create();
return model;
}
/// <inheritdoc />
public async Task<ValidationResult> Validate<T>(T model) where T : ZeroIdEntity, new()
public async Task<ValidationResult> Validate<T>(T model) where T : FinchIdEntity, new()
{
IZeroMergedValidator<T> validator = Services.GetService<IZeroMergedValidator<T>>();
IFinchMergedValidator<T> validator = Services.GetService<IFinchMergedValidator<T>>();
if (validator == null)
{
@@ -104,10 +104,10 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc />
public virtual T WhenActive<T>(T model) where T : ZeroIdEntity, new()
public virtual T WhenActive<T>(T model) where T : FinchIdEntity, new()
{
return model; // TODO should we really use this? I tried to get data in a custom backend but couldn't because of this
//return model != null && (model is not ZeroEntity || (model as ZeroEntity).IsActive) && (model is not ISupportsSoftDelete || !(model as ISupportsSoftDelete).IsDeleted) ? model : default;
//return model != null && (model is not FinchEntity || (model as FinchEntity).IsActive) && (model is not ISupportsSoftDelete || !(model as ISupportsSoftDelete).IsDeleted) ? model : default;
}
}
@@ -117,22 +117,22 @@ public interface IDbOperations
/// <summary>
/// Create a table if not existing
/// </summary>
bool EnsureTableExists<T>() where T : ZeroIdEntity;
bool EnsureTableExists<T>() where T : FinchIdEntity;
/// <summary>
/// Generate model Id by using configured document store conventions
/// </summary>
Task<string> GenerateId<T>(T model) where T : ZeroIdEntity;
Task<string> GenerateId<T>(T model) where T : FinchIdEntity;
/// <summary>
/// Do only return the model when it is set to active or inactive entities are included with IncludeInactive()
/// </summary>
T WhenActive<T>(T model) where T : ZeroIdEntity, new();
T WhenActive<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Validates an entity
/// </summary>
Task<ValidationResult> Validate<T>(T model) where T : ZeroIdEntity, new();
Task<ValidationResult> Validate<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Generate values for all properties (incl. nested) which contain the [GenerateId] attribute
@@ -140,78 +140,78 @@ public interface IDbOperations
T AutoSetIds<T>(T model);
/// <summary>
/// Automatically fill base properties of a ZeroEntity
/// Automatically fill base properties of a FinchEntity
/// </summary>
T PrepareForSave<T>(T model) where T : ZeroIdEntity;
T PrepareForSave<T>(T model) where T : FinchIdEntity;
/// <summary>
/// Get an entity by Id
/// </summary>
Task<T> Load<T>(string id, string changeVector = null) where T : ZeroIdEntity, new();
Task<T> Load<T>(string id, string changeVector = null) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by ids
/// </summary>
Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new();
Task<Dictionary<string, T>> Load<T>(IEnumerable<string> ids) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by ids
/// </summary>
Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : ZeroIdEntity, new();
Task<List<T>> LoadAsList<T>(IEnumerable<string> ids) where T : FinchIdEntity, new();
/// <summary>
/// Check if any items exist in this collection (with optional query)
/// </summary>
Task<bool> Any<T>(Expression<Func<T, bool>> querySelector = null) where T : ZeroIdEntity, new();
Task<bool> Any<T>(Expression<Func<T, bool>> querySelector = null) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by query
/// </summary>
Task<List<T>> Load<T>(Expression<Func<T, bool>> querySelector) where T : ZeroIdEntity, new();
Task<List<T>> Load<T>(Expression<Func<T, bool>> querySelector) where T : FinchIdEntity, new();
/// <summary>
/// Find entity by query
/// </summary>
Task<T> Find<T>(Expression<Func<T, bool>> querySelector) where T : ZeroIdEntity, new();
Task<T> Find<T>(Expression<Func<T, bool>> querySelector) where T : FinchIdEntity, new();
/// <summary>
/// Get entities by sql query
/// </summary>
Task<List<T>> LoadBySql<T>(Func<SqlExpression<T>, SqlExpression<T>> querySelector) where T : ZeroIdEntity, new();
Task<List<T>> LoadBySql<T>(Func<SqlExpression<T>, SqlExpression<T>> querySelector) where T : FinchIdEntity, new();
/// <summary>
/// Get all entities from this collection.
/// Warning: Don't use this method for large collections. Stream the results instead.
/// </summary>
Task<List<T>> LoadAll<T>() where T : ZeroIdEntity, new();
Task<List<T>> LoadAll<T>() where T : FinchIdEntity, new();
/// <summary>
/// Creates an entity with an optional validator
/// </summary>
Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : ZeroIdEntity, new();
Task<Result<T>> Create<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : FinchIdEntity, new();
/// <summary>
/// Updates an entity with an optional validator
/// </summary>
Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : ZeroIdEntity, new();
Task<Result<T>> Update<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : FinchIdEntity, new();
/// <summary>
/// Checks if an entity exists (via ID) and creates or updates it afterwards accordingly
/// </summary>
Task<Result<T>> CreateOrUpdate<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : ZeroIdEntity, new();
Task<Result<T>> CreateOrUpdate<T>(T model, Func<T, Task<ValidationResult>> validate = null) where T : FinchIdEntity, new();
/// <summary>
/// Updates sorting of all items in a collection based on the given enumerable
/// </summary>
Task Sort<T>(IEnumerable<string> ids) where T : ZeroEntity, new();
Task Sort<T>(IEnumerable<string> ids) where T : FinchEntity, new();
/// <summary>
/// Deletes an entity
/// </summary>
Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new();
Task<Result<T>> Delete<T>(T model) where T : FinchIdEntity, new();
/// <summary>
/// Deletes an entity
/// </summary>
Task<Result<T>> Delete<T>(string id) where T : ZeroIdEntity, new();
Task<Result<T>> Delete<T>(string id) where T : FinchIdEntity, new();
}
@@ -0,0 +1,21 @@
using System.Threading.Tasks;
using Finch.Communication;
using Finch.Models;
namespace Finch.Sqlite;
public interface IEntityModifiedHandler : IHandler
{
Task Saved<T>(T model, bool update) where T : FinchIdEntity, new() => update ? Updated(model) : Created(model);
Task Created<T>(T model) where T : FinchIdEntity, new();
Task Updated<T>(T model) where T : FinchIdEntity, new();
Task Deleted<T>(T model) where T : FinchIdEntity, new();
}
public class EmptyEntityModifiedHandler : IEntityModifiedHandler
{
public Task Created<T>(T model) where T : FinchIdEntity, new() => Task.CompletedTask;
public Task Updated<T>(T model) where T : FinchIdEntity, new() => Task.CompletedTask;
public Task Deleted<T>(T model) where T : FinchIdEntity, new() => Task.CompletedTask;
}
+26
View File
@@ -0,0 +1,26 @@
using System;
using Finch.Communication;
using Finch.Configuration;
using Finch.Context;
namespace Finch.Sqlite;
public class StoreContext
{
public IFinchContext Context { get; private set; }
public IFinchOptions Options { get; private set; }
public IServiceProvider Services { get; private set; }
public IMessageAggregator Messages { get; private set; }
public StoreContext(IFinchContext context, IServiceProvider serviceProvider, IMessageAggregator messages)
{
Options = context.Options;
Context = context;
Services = serviceProvider;
Messages = messages;
}
}
@@ -1,7 +1,7 @@
using System;
using System.Data;
namespace zero.Sqlite;
namespace Finch.Sqlite;
public class SqliteOptions
{
@@ -4,22 +4,22 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack.Data;
using ServiceStack.OrmLite;
using zero.Configuration;
using zero.Models;
using zero.Modules;
using Finch.Configuration;
using Finch.Models;
using Finch.Modules;
namespace zero.Sqlite;
namespace Finch.Sqlite;
public static class ZeroBuilderExtensions
public static class FinchBuilderExtensions
{
public static ZeroBuilder AddSqlite(this ZeroBuilder builder)
public static FinchBuilder AddSqlite(this FinchBuilder builder)
{
builder.AddModule<ZeroSqliteModule>();
builder.AddModule<FinchSqliteModule>();
return builder;
}
}
internal class ZeroSqliteModule : ZeroModule
internal class FinchSqliteModule : FinchModule
{
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
@@ -29,14 +29,14 @@ internal class ZeroSqliteModule : ZeroModule
services.AddScoped<StoreContext>();
services.AddScoped<IEntityModifiedHandler, EmptyEntityModifiedHandler>();
services.AddOptions<FlavorOptions>();
services.AddOptions<SqliteOptions>().Bind(configuration.GetSection("Zero:Sqlite"));
services.AddOptions<SqliteOptions>().Bind(configuration.GetSection("Finch:Sqlite"));
services.ConfigureOptions<ConfigureFlavorJsonOptions>();
}
protected IDbConnectionFactory CreateDbConnectionFactory(IServiceProvider services)
{
IZeroOptions options = services.GetService<IZeroOptions>();
IFinchOptions options = services.GetService<IFinchOptions>();
SqliteOptions sqliteOptions = options.For<SqliteOptions>();
return new OrmLiteConnectionFactory(sqliteOptions.ConnectionString, SqliteDialect.Provider);
}
@@ -45,7 +45,7 @@ internal class ZeroSqliteModule : ZeroModule
protected IDbConnection CreateDbConnection(IServiceProvider services)
{
IDbConnectionFactory factory = services.GetService<IDbConnectionFactory>();
IZeroOptions options = services.GetService<IZeroOptions>();
IFinchOptions options = services.GetService<IFinchOptions>();
SqliteOptions sqliteOptions = options.For<SqliteOptions>();
IDbConnection db = factory.CreateDbConnection();
db.Open();
+3 -3
View File
@@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "zero", "zero\zero.csproj", "{33CD6E46-CD81-42C3-9019-C0EAD557EE99}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Finch", "Finch\Finch.csproj", "{33CD6E46-CD81-42C3-9019-C0EAD557EE99}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "zero.Raven", "zero.Raven\zero.Raven.csproj", "{DC79D7EA-FAA1-4701-9C36-8295CD1C45D0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Finch.Raven", "Finch.Raven\Finch.Raven.csproj", "{DC79D7EA-FAA1-4701-9C36-8295CD1C45D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zero.Sqlite", "zero.Sqlite\zero.Sqlite.csproj", "{A57D88BC-952F-4311-B474-26FBF0FA957E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Finch.Sqlite", "Finch.Sqlite\Finch.Sqlite.csproj", "{A57D88BC-952F-4311-B474-26FBF0FA957E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Builder;
namespace zero;
namespace Finch;
public static class ApplicationBuilderExtensions
{
public static IApplicationBuilder UseZero(this IApplicationBuilder app)
public static IApplicationBuilder UseFinch(this IApplicationBuilder app)
{
app.UseMiddleware<ZeroContextMiddleware>();
app.UseMiddleware<FinchContextMiddleware>();
app.UseOutputCache();
if (app is WebApplication webApplication)
@@ -15,7 +15,7 @@ public static class ApplicationBuilderExtensions
webApplication.MapControllers();
}
ZeroBuilder.Modules.Configure(app, null, app.ApplicationServices);
FinchBuilder.Modules.Configure(app, null, app.ApplicationServices);
return app;
}
}
@@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyModel;
using System.Reflection;
namespace zero.Assemblies;
namespace Finch.Assemblies;
public class AssemblyDiscovery : IAssemblyDiscovery
{
@@ -1,6 +1,6 @@
using System.Reflection;
namespace zero.Assemblies;
namespace Finch.Assemblies;
public class AssemblyDiscoveryContext
{
@@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyModel;
namespace Finch.Assemblies;
public class FinchAssemblyDiscoveryRule : IAssemblyDiscoveryRule
{
const string FinchPrefix = "Finch.";
/// <inheritdoc />
public bool IsValid(RuntimeLibrary library, AssemblyDiscoveryContext context)
{
StringComparison casing = StringComparison.OrdinalIgnoreCase;
// TODO we need to auto-add assemblies and discover their types which have implementations of IFinchPlugin
return library.Name.StartsWith(FinchPrefix, casing) || (context.HasEntryAssembly && library.Name.Contains(context.EntryAssemblyName, casing));
}
}
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyModel;
namespace zero.Assemblies;
namespace Finch.Assemblies;
public interface IAssemblyDiscoveryRule
{
@@ -1,9 +1,9 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace zero.Communication;
namespace Finch.Communication;
internal class ZeroCommunicationModule : ZeroModule
internal class FinchCommunicationModule : FinchModule
{
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
+5
View File
@@ -0,0 +1,5 @@
namespace Finch.Communication;
public interface IHandler
{
}
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
namespace zero.Communication;
namespace Finch.Communication;
public class HandlerHolder : IHandlerHolder
{
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
namespace zero.Communication;
namespace Finch.Communication;
public class LazilyResolved<T> : Lazy<T>
{
@@ -1,5 +1,5 @@

namespace zero.Communication;
namespace Finch.Communication;
public interface IMessage
{
@@ -1,4 +1,4 @@
namespace zero.Communication;
namespace Finch.Communication;
/// <summary>
/// Indicates a handler that can perform an action when a message of
@@ -1,7 +1,7 @@
using System.Collections.Concurrent;
using System.Linq.Expressions;
namespace zero.Communication;
namespace Finch.Communication;
public class MessageAggregator : IMessageAggregator
{
@@ -2,7 +2,7 @@
using System.Linq.Expressions;
using System.Reflection;
namespace zero.Communication;
namespace Finch.Communication;
internal class MessageSubscription<TMessage, TMessageHandler> : IMessageSubscription
where TMessage : class, IMessage
@@ -2,21 +2,21 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace zero.Configuration;
namespace Finch.Configuration;
internal class ZeroConfigurationModule : ZeroModule
internal class FinchConfigurationModule : FinchModule
{
public override int Order => -1000;
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddOptions<ZeroOptions>().Configure<IServiceProvider>((opts, svc) =>
services.AddOptions<FinchOptions>().Configure<IServiceProvider>((opts, svc) =>
{
opts.ServiceProvider = svc;
opts.Version = "1.0.0-alpha.1";
opts.TokenExpiration = TimeSpan.FromHours(3);
}).Bind(configuration.GetSection("Zero"));
}).Bind(configuration.GetSection("Finch"));
services.AddTransient<IZeroOptions, ZeroOptions>(factory => factory.GetService<IOptions<ZeroOptions>>().Value);
services.AddTransient<IFinchOptions, FinchOptions>(factory => factory.GetService<IOptions<FinchOptions>>().Value);
}
}
@@ -2,9 +2,9 @@
using Microsoft.Extensions.Options;
using System.Collections.Concurrent;
namespace zero.Configuration;
namespace Finch.Configuration;
public class ZeroOptions : IZeroOptions
public class FinchOptions : IFinchOptions
{
/// <inheritdoc />
public string Version { get; set; }
@@ -41,7 +41,7 @@ public class ZeroOptions : IZeroOptions
}
public interface IZeroOptions
public interface IFinchOptions
{
/// <summary>
/// The currently active version
@@ -1,21 +1,21 @@
using Microsoft.Extensions.DependencyInjection;
namespace zero.Configuration;
namespace Finch.Configuration;
public class ZeroStartupOptions : IZeroStartupOptions
public class FinchStartupOptions : IFinchStartupOptions
{
public IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; private set; } = new List<IAssemblyDiscoveryRule>();
public IMvcBuilder Mvc { get; private set; }
public ZeroStartupOptions(IMvcBuilder mvc)
public FinchStartupOptions(IMvcBuilder mvc)
{
Mvc = mvc;
}
}
public interface IZeroStartupOptions
public interface IFinchStartupOptions
{
IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; }
@@ -0,0 +1,6 @@
namespace Finch.Configuration;
public interface IFinchCollectionOptions
{
}
@@ -1,6 +1,6 @@
using FluentValidation;
namespace zero.Configuration;
namespace Finch.Configuration;
public abstract class OptionsType
{
@@ -3,18 +3,18 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Security.Claims;
namespace zero.Context;
namespace Finch.Context;
public class ZeroContext : IZeroContext
public class FinchContext : IFinchContext
{
/// <inheritdoc />
public IZeroOptions Options { get; protected set; }
public IFinchOptions Options { get; protected set; }
/// <inheritdoc />
public IServiceProvider Services { get; private set; }
protected ICultureResolver CultureResolver { get; private set; }
protected ILogger<ZeroContext> Logger { get; private set; }
protected ILogger<FinchContext> Logger { get; private set; }
protected IHandlerHolder Handler { get; private set; }
@@ -26,8 +26,8 @@ public class ZeroContext : IZeroContext
bool _resolved = false;
public ZeroContext(IZeroOptions options, IHttpContextAccessor httpContextAccessor, ICultureResolver cultureResolver,
ILogger<ZeroContext> logger, IHandlerHolder handler, IServiceProvider services)
public FinchContext(IFinchOptions options, IHttpContextAccessor httpContextAccessor, ICultureResolver cultureResolver,
ILogger<FinchContext> logger, IHandlerHolder handler, IServiceProvider services)
{
Options = options;
CultureResolver = cultureResolver;
@@ -68,12 +68,12 @@ public class ZeroContext : IZeroContext
public interface IZeroContext
public interface IFinchContext
{
/// <summary>
/// Global zero options
/// Global finch options
/// </summary>
IZeroOptions Options { get; }
IFinchOptions Options { get; }
/// <summary>
/// Service container
+20
View File
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Http;
namespace Finch.Context
{
public class FinchContextMiddleware
{
RequestDelegate _next;
public FinchContextMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext, IFinchContext finchContext)
{
await finchContext.Resolve(httpContext);
await _next(httpContext);
}
}
}
@@ -1,13 +1,13 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace zero.Context;
namespace Finch.Context;
internal class ZeroContextModule : ZeroModule
internal class FinchContextModule : FinchModule
{
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IZeroContext, ZeroContext>();
services.AddScoped<IFinchContext, FinchContext>();
services.AddHttpContextAccessor();
}
}
@@ -1,4 +1,4 @@
namespace zero.Extensions;
namespace Finch.Extensions;
public static class CharExtensions
{
@@ -1,6 +1,6 @@
using System.Drawing;
namespace zero.Extensions;
namespace Finch.Extensions;
public static class ColorExtensions
{
@@ -1,4 +1,4 @@
namespace zero.Extensions;
namespace Finch.Extensions;
public static class DictionaryExtensions
{
@@ -1,4 +1,4 @@
namespace zero.Extensions;
namespace Finch.Extensions;
public static class EnumerableExtensions
{
@@ -9,7 +9,7 @@ public static class EnumerableExtensions
if (pageNumber <= 0 || pageSize <= 0)
{
throw new NotSupportedException("Both pageNumber and pageSize must be greater than zero");
throw new NotSupportedException("Both pageNumber and pageSize must be greater than z_ero");
}
return source.Skip((pageNumber - 1) * pageSize).Take(pageSize);
@@ -1,7 +1,7 @@
using System.Linq.Expressions;
using System.Text;
namespace zero.Extensions;
namespace Finch.Extensions;
public static class ExpressionExtensions
{
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http;
namespace zero.Extensions;
namespace Finch.Extensions;
public static class HttpContextExtensions
{
@@ -1,4 +1,4 @@
namespace zero.Extensions;
namespace Finch.Extensions;
public static class NumberExtensions
{
@@ -1,6 +1,6 @@
//using Newtonsoft.Json;
//namespace zero.Extensions;
//namespace Finch.Extensions;
//[Obsolete("we don't want this for every object (use a Utils class instead)")]
//public static class ObjectExtensions
@@ -1,4 +1,4 @@
namespace zero.Extensions;
namespace Finch.Extensions;
public static class ResultExtensions
{
@@ -31,7 +31,7 @@ public static class ResultExtensions
public static Result AddError(this Result origin, string message)
{
origin.IsSuccess = false;
origin.Errors.Add(new("__zero_no_field", message));
origin.Errors.Add(new("__finch_no_field", message));
return origin;
}
@@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using System.Reflection;
namespace zero.Extensions;
namespace Finch.Extensions;
public static class ServiceCollectionExtensions
{
@@ -19,7 +19,7 @@ public static class ServiceCollectionExtensions
{
if (AssemblyDiscovery.Current == null)
{
throw new Exception("services.AddAll() can only be run after mvcBuilder.AddZero()");
throw new Exception("services.AddAll() can only be run after mvcBuilder.AddFinch()");
}
// add implementations with generic service types
@@ -4,7 +4,7 @@ using System.Text;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Html;
namespace zero.Extensions;
namespace Finch.Extensions;
public static class StringExtensions
{
@@ -1,4 +1,4 @@
namespace zero.FileStorage;
namespace Finch.FileStorage;
public class FileResult
{
@@ -1,4 +1,4 @@
namespace zero.FileStorage;
namespace Finch.FileStorage;
public enum FileSizeNotation
{
@@ -1,4 +1,4 @@
namespace zero.FileStorage;
namespace Finch.FileStorage;
public class FileSystemException : Exception
{
+6
View File
@@ -0,0 +1,6 @@
namespace Finch.FileStorage;
public class FileSystemOptions
{
public string FinchAssetsPath { get; set; }
}
@@ -3,17 +3,17 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace zero.FileStorage;
namespace Finch.FileStorage;
internal class ZeroFileStorageModule : ZeroModule
internal class FinchFileStorageModule : FinchModule
{
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IPaths>(factory => new Paths(factory.GetService<IWebHostEnvironment>()));
services.AddOptions<FileSystemOptions>().Bind(configuration.GetSection("Zero:FileSystem")).Configure(opts =>
services.AddOptions<FileSystemOptions>().Bind(configuration.GetSection("Finch:FileSystem")).Configure(opts =>
{
opts.ZeroAssetsPath = "zero";
opts.FinchAssetsPath = "finch";
});
services.AddSingleton<IWebRootFileSystem, WebRootFileSystem>(svc =>
@@ -1,4 +1,4 @@
namespace zero.FileStorage;
namespace Finch.FileStorage;
public interface IFileMeta
{
@@ -1,6 +1,6 @@
using System.IO;
namespace zero.FileStorage;
namespace Finch.FileStorage;
public interface IFileSystem
{
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.StaticFiles;
using System.IO;
using System.Text;
namespace zero.FileStorage;
namespace Finch.FileStorage;
public class Paths : IPaths
{
@@ -1,6 +1,6 @@
using Microsoft.Extensions.FileProviders;
namespace zero.FileStorage;
namespace Finch.FileStorage;
public class PhysicalFileMeta : IFileMeta
{
@@ -1,7 +1,7 @@
using Microsoft.Extensions.FileProviders.Physical;
using System.IO;
namespace zero.FileStorage;
namespace Finch.FileStorage;
public class PhysicalFileSystem : IFileSystem
{
@@ -1,4 +1,4 @@
namespace zero.FileStorage;
namespace Finch.FileStorage;
public class WebRootFileSystem : PhysicalFileSystem, IWebRootFileSystem
{
+2 -2
View File
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>zero</PackageId>
<PackageId>Finch</PackageId>
<Version>1.0.0</Version>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<RootNamespace>zero</RootNamespace>
<RootNamespace>Finch</RootNamespace>
<DebugType>embedded</DebugType>
</PropertyGroup>
+37 -37
View File
@@ -2,42 +2,42 @@
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using zero.Logging;
using zero.Mails;
using zero.Metadata;
using zero.Mvc;
using zero.Numbers;
using zero.Routing;
using zero.Security;
using Finch.Logging;
using Finch.Mails;
using Finch.Metadata;
using Finch.Mvc;
using Finch.Numbers;
using Finch.Routing;
using Finch.Security;
namespace zero;
namespace Finch;
// TODO maybe use a middleware like Hangfire does: https://github.com/HangfireIO/Hangfire/blob/master/src/Hangfire.AspNetCore/HangfireEndpointRouteBuilderExtensions.cs
public class ZeroBuilder
public class FinchBuilder
{
public virtual IServiceCollection Services { get; }
public virtual IMvcBuilder Mvc { get; }
internal static ZeroModuleCollection Modules { get; private set; } = new();
internal static FinchModuleCollection Modules { get; private set; } = new();
readonly IConfiguration _configuration;
readonly IZeroStartupOptions _startupOptions;
readonly IFinchStartupOptions _startupOptions;
public ZeroBuilder(IServiceCollection services, IConfiguration configuration, Action<IZeroStartupOptions> setupAction)
public FinchBuilder(IServiceCollection services, IConfiguration configuration, Action<IFinchStartupOptions> setupAction)
{
Services = services;
Mvc = services.AddMvc();
_configuration = configuration;
// create startup options
_startupOptions = new ZeroStartupOptions(Mvc);
_startupOptions.AssemblyDiscoveryRules.Add(new ZeroAssemblyDiscoveryRule());
_startupOptions = new FinchStartupOptions(Mvc);
_startupOptions.AssemblyDiscoveryRules.Add(new FinchAssemblyDiscoveryRule());
setupAction?.Invoke(_startupOptions);
//string appName = configuration.GetValue<string>("Zero:AppName").Or("zero-app");
//string appName = configuration.GetValue<string>("Finch:AppName").Or("finch-app");
//services.AddDataProtection();.PersistKeysToRegistry()
services.AddControllers();
@@ -46,30 +46,30 @@ public class ZeroBuilder
Mvc.AddDataAnnotationsLocalization();
services.Configure<AntiforgeryOptions>(opts => opts.Cookie.Name = "zero.antiforgery");
services.Configure<AntiforgeryOptions>(opts => opts.Cookie.Name = "finch.antiforgery");
// adds and discovers additional and built-in assemblies
new AssemblyDiscovery(Mvc).Execute(_startupOptions.AssemblyDiscoveryRules);
Modules.Add<ZeroLoggingModule>();
Modules.Add<ZeroCommunicationModule>();
Modules.Add<ZeroMvcModule>();
Modules.Add<ZeroConfigurationModule>();
Modules.Add<ZeroValidationModule>();
Modules.Add<ZeroContextModule>();
Modules.Add<ZeroFileStorageModule>();
//Modules.Add<ZeroIdentityModule>();
Modules.Add<ZeroLocalizationModule>();
Modules.Add<ZeroMailModule>();
//Modules.Add<ZeroMapperModule>();
Modules.Add<ZeroMediaModule>();
//Modules.Add<ZeroPageModule>();
Modules.Add<ZeroRenderingModule>();
Modules.Add<ZeroNumberModule>();
Modules.Add<ZeroRoutingModule>();
Modules.Add<ZeroMetadataModule>();
Modules.Add<ZeroSecurityModule>();
Modules.Add<FinchLoggingModule>();
Modules.Add<FinchCommunicationModule>();
Modules.Add<FinchMvcModule>();
Modules.Add<FinchConfigurationModule>();
Modules.Add<FinchValidationModule>();
Modules.Add<FinchContextModule>();
Modules.Add<FinchFileStorageModule>();
//Modules.Add<FinchIdentityModule>();
Modules.Add<FinchLocalizationModule>();
Modules.Add<FinchMailModule>();
//Modules.Add<FinchMapperModule>();
Modules.Add<FinchMediaModule>();
//Modules.Add<FinchPageModule>();
Modules.Add<FinchRenderingModule>();
Modules.Add<FinchNumberModule>();
Modules.Add<FinchRoutingModule>();
Modules.Add<FinchMetadataModule>();
Modules.Add<FinchSecurityModule>();
Modules.ConfigureServices(services, configuration);
@@ -81,14 +81,14 @@ public class ZeroBuilder
/// <summary>
/// Use specified options
/// </summary>
public ZeroBuilder WithOptions(Action<ZeroOptions> configureOptions)
public FinchBuilder WithOptions(Action<FinchOptions> configureOptions)
{
Services.Configure(configureOptions);
return this;
}
public ZeroBuilder AddModule(IZeroModule module)
public FinchBuilder AddModule(IFinchModule module)
{
module.ConfigureServices(Services, _configuration);
Modules.Add(module);
@@ -96,7 +96,7 @@ public class ZeroBuilder
}
public ZeroBuilder AddModule<T>() where T : class, IZeroModule, new()
public FinchBuilder AddModule<T>() where T : class, IFinchModule, new()
{
T module = new();
module.ConfigureServices(Services, _configuration);
@@ -3,14 +3,14 @@
using ViteProxy;
#endif
namespace zero.Frontend;
namespace Finch.Frontend;
public static class ZeroBuilderExtensions
public static class FinchBuilderExtensions
{
public static ZeroBuilder AddVite(this ZeroBuilder builder)
public static FinchBuilder AddVite(this FinchBuilder builder)
{
#if DEBUG
builder.Services.AddViteProxy("Zero:Vite");
builder.Services.AddViteProxy("Finch:Vite");
#endif
return builder;
}
@@ -27,7 +27,7 @@ public static class ViteProxyApplicationBuilderExtensions
}
}
// internal class ZeroViteModule : ZeroModule
// internal class FinchViteModule : FinchModule
// {
// public override int ConfigureOrder { get; } = -1;
//
@@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
namespace zero.Frontend;
namespace Finch.Frontend;
[HtmlTargetElement("app-vitescript", Attributes = "src", TagStructure = TagStructure.NormalOrSelfClosing)]
public class ViteScriptTagHelper(IWebHostEnvironment env, IZeroOptions options) : TagHelper
public class ViteScriptTagHelper(IWebHostEnvironment env, IFinchOptions options) : TagHelper
{
[HtmlAttributeNotBound]
[ViewContext]
@@ -1,13 +1,13 @@
namespace zero.Identity;
namespace Finch.Identity;
/// <summary>
/// Represents all the options you can use to configure the cookies middleware used by the identity system.
/// </summary>
public class ZeroIdentityConstants
public class FinchIdentityConstants
{
public static class CookieNames
{
private const string CookiePrefix = "zero.id";
private const string CookiePrefix = "Finch.id";
public static readonly string Application = CookiePrefix + ".app";
public static readonly string External = CookiePrefix + ".ext";
@@ -17,9 +17,9 @@ public class ZeroIdentityConstants
public static partial class Claims
{
private const string ClaimPrefix = "zero.claim";
private const string ClaimPrefix = "Finch.claim";
public static readonly string IsZero = ClaimPrefix + ".iszero";
public static readonly string IsFinch = ClaimPrefix + ".isfinch";
public static readonly string UserId = ClaimPrefix + ".userid";
public static readonly string Username = ClaimPrefix + ".username";
public static readonly string Name = ClaimPrefix + ".name";
@@ -4,9 +4,9 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace zero.Identity;
namespace Finch.Identity;
public static class ZeroIdentityExtensions
public static class FinchIdentityExtensions
{
// <summary>
/// Adds the default identity system configuration for the specified User and Role types.
@@ -15,10 +15,10 @@ public static class ZeroIdentityExtensions
/// <typeparam name="TRole">The type representing a Role in the system.</typeparam>
/// <param name="services">The services available in the application.</param>
/// <returns>An <see cref="IdentityBuilder"/> for creating and configuring the identity system.</returns>
public static IdentityBuilder AddZeroIdentity<TUser, TRole>(this IServiceCollection services)
where TUser : ZeroIdentityUser, new()
where TRole : ZeroIdentityRole, new() =>
AddZeroIdentity<TUser, TRole>(services, null);
public static IdentityBuilder AddFinchIdentity<TUser, TRole>(this IServiceCollection services)
where TUser : FinchIdentityUser, new()
where TRole : FinchIdentityRole, new() =>
AddFinchIdentity<TUser, TRole>(services, null);
/// <summary>
@@ -29,10 +29,10 @@ public static class ZeroIdentityExtensions
/// <param name="services">The services available in the application.</param>
/// <param name="setupAction">An action to configure the <see cref="IdentityOptions"/>.</param>
/// <returns>An <see cref="IdentityBuilder"/> for creating and configuring the identity system.</returns>
public static IdentityBuilder AddZeroIdentity<TUser, TRole>(this IServiceCollection services,
public static IdentityBuilder AddFinchIdentity<TUser, TRole>(this IServiceCollection services,
Action<IdentityOptions> setupAction)
where TUser : ZeroIdentityUser, new()
where TRole : ZeroIdentityRole, new()
where TUser : FinchIdentityUser, new()
where TRole : FinchIdentityRole, new()
{
// Services identity depends on
services
@@ -53,7 +53,7 @@ public static class ZeroIdentityExtensions
o.SlidingExpiration = true;
o.ExpireTimeSpan = TimeSpan.FromDays(90);
o.Cookie.Name = ZeroIdentityConstants.CookieNames.Application;
o.Cookie.Name = FinchIdentityConstants.CookieNames.Application;
o.Cookie.HttpOnly = true;
o.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
o.Cookie.SameSite = SameSiteMode.Lax;
@@ -66,12 +66,12 @@ public static class ZeroIdentityExtensions
})
.AddCookie(IdentityConstants.ExternalScheme, o =>
{
o.Cookie.Name = ZeroIdentityConstants.CookieNames.External;
o.Cookie.Name = FinchIdentityConstants.CookieNames.External;
o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
})
.AddCookie(IdentityConstants.TwoFactorRememberMeScheme, o =>
{
o.Cookie.Name = ZeroIdentityConstants.CookieNames.TwoFactorRememberMe;
o.Cookie.Name = FinchIdentityConstants.CookieNames.TwoFactorRememberMe;
o.Events = new CookieAuthenticationEvents
{
OnValidatePrincipal = SecurityStampValidator.ValidateAsync<ITwoFactorSecurityStampValidator>
@@ -79,7 +79,7 @@ public static class ZeroIdentityExtensions
})
.AddCookie(IdentityConstants.TwoFactorUserIdScheme, o =>
{
o.Cookie.Name = ZeroIdentityConstants.CookieNames.TwoFactorUserId;
o.Cookie.Name = FinchIdentityConstants.CookieNames.TwoFactorUserId;
o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
});
@@ -105,11 +105,11 @@ public static class ZeroIdentityExtensions
services.Configure<IdentityOptions>(opts =>
{
opts.ClaimsIdentity.UserIdClaimType = ZeroIdentityConstants.Claims.UserId;
opts.ClaimsIdentity.UserNameClaimType = ZeroIdentityConstants.Claims.Username;
opts.ClaimsIdentity.RoleClaimType = ZeroIdentityConstants.Claims.Role;
opts.ClaimsIdentity.SecurityStampClaimType = ZeroIdentityConstants.Claims.SecurityStamp;
opts.ClaimsIdentity.EmailClaimType = ZeroIdentityConstants.Claims.Email;
opts.ClaimsIdentity.UserIdClaimType = FinchIdentityConstants.Claims.UserId;
opts.ClaimsIdentity.UserNameClaimType = FinchIdentityConstants.Claims.Username;
opts.ClaimsIdentity.RoleClaimType = FinchIdentityConstants.Claims.Role;
opts.ClaimsIdentity.SecurityStampClaimType = FinchIdentityConstants.Claims.SecurityStamp;
opts.ClaimsIdentity.EmailClaimType = FinchIdentityConstants.Claims.Email;
opts.Password.RequireDigit = false;
opts.Password.RequireLowercase = false;
@@ -135,7 +135,7 @@ public static class ZeroIdentityExtensions
IdentityBuilder builder = new(typeof(TUser), typeof(TRole), services);
builder.AddDefaultTokenProviders();
builder.AddZeroIdentityStores();
builder.AddFinchIdentityStores();
return builder;
}
@@ -147,7 +147,7 @@ public static class ZeroIdentityExtensions
/// <param name="services">The services available in the application.</param>
/// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>The services.</returns>
public static IServiceCollection ConfigureZeroApplicationCookie(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
public static IServiceCollection ConfigureFinchApplicationCookie(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
=> services.Configure(IdentityConstants.ApplicationScheme, configure);
/// <summary>
@@ -156,6 +156,6 @@ public static class ZeroIdentityExtensions
/// <param name="services">The services available in the application.</param>
/// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>The services.</returns>
public static IServiceCollection ConfigureZeroExternalCookie(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
public static IServiceCollection ConfigureFinchExternalCookie(this IServiceCollection services, Action<CookieAuthenticationOptions> configure)
=> services.Configure(IdentityConstants.ExternalScheme, configure);
}
@@ -1,18 +1,18 @@
using System.Linq.Expressions;
namespace zero.Identity;
namespace Finch.Identity;
public interface IZeroIdentityStoreDbProvider
public interface IFinchIdentityStoreDbProvider
{
Task<T> Load<T>(string id, CancellationToken ct = default) where T : ZeroEntity, new();
Task<T> Load<T>(string id, CancellationToken ct = default) where T : FinchEntity, new();
Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : ZeroEntity;
Task<T> Find<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : FinchEntity;
Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : ZeroEntity;
Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) where T : FinchEntity;
Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new();
Task<Result<T>> Create<T>(T model, CancellationToken ct = default) where T : FinchEntity, new();
Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new();
Task<Result<T>> Update<T>(T model, CancellationToken ct = default) where T : FinchEntity, new();
Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : ZeroEntity, new();
Task<Result<T>> Delete<T>(T model, CancellationToken ct = default) where T : FinchEntity, new();
}
@@ -1,21 +1,21 @@
using Microsoft.AspNetCore.Identity;
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using zero.Identity;
using Finch.Identity;
namespace zero.Identity;
namespace Finch.Identity;
public class ZeroRoleStore<TRole> :
public class FinchRoleStore<TRole> :
IRoleStore<TRole>,
IRoleClaimStore<TRole>
where TRole : ZeroIdentityRole, new()
where TRole : FinchIdentityRole, new()
{
protected IdentityErrorDescriber ErrorDescriber { get; private set; }
protected virtual IZeroIdentityStoreDbProvider Db { get; set; }
protected virtual IFinchIdentityStoreDbProvider Db { get; set; }
public ZeroRoleStore(IZeroIdentityStoreDbProvider db, IdentityErrorDescriber describer = null)
public FinchRoleStore(IFinchIdentityStoreDbProvider db, IdentityErrorDescriber describer = null)
{
Db = db;
ErrorDescriber = describer ?? new IdentityErrorDescriber();
@@ -30,7 +30,7 @@ public class ZeroRoleStore<TRole> :
foreach (ResultError error in result.Errors)
{
string message = error.Message + "(key: " + error.Property + ")";
errors[index++] = new() { Code = "zero/raven/500", Description = message };
errors[index++] = new() { Code = "finch/raven/500", Description = message };
}
return IdentityResult.Failed(errors);
@@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Identity;
using System.Security.Claims;
namespace zero.Identity;
namespace Finch.Identity;
public partial class ZeroUserStore<TUser> :
public partial class FinchUserStore<TUser> :
IUserStore<TUser>,
IUserEmailStore<TUser>,
IUserLockoutStore<TUser>,
@@ -17,9 +17,9 @@ public partial class ZeroUserStore<TUser> :
IUserTwoFactorStore<TUser>,
IUserTwoFactorRecoveryCodeStore<TUser>,
IUserPhoneNumberStore<TUser>
where TUser : ZeroIdentityUser, new()
where TUser : FinchIdentityUser, new()
{
public ZeroUserStore(IZeroIdentityStoreDbProvider db, IdentityErrorDescriber describer = null)
public FinchUserStore(IFinchIdentityStoreDbProvider db, IdentityErrorDescriber describer = null)
{
Db = db;
ErrorDescriber = describer ?? new IdentityErrorDescriber();
@@ -29,7 +29,7 @@ public partial class ZeroUserStore<TUser> :
protected IdentityErrorDescriber ErrorDescriber { get; private set; }
protected virtual IZeroIdentityStoreDbProvider Db { get; set; }
protected virtual IFinchIdentityStoreDbProvider Db { get; set; }
private IdentityResult Fail(Result<TUser> result)
{
@@ -39,7 +39,7 @@ public partial class ZeroUserStore<TUser> :
foreach (ResultError error in result.Errors)
{
string message = error.Message + "(key: " + error.Property + ")";
errors[index++] = new() { Code = "zero/raven/500", Description = message };
errors[index++] = new() { Code = "finch/raven/500", Description = message };
}
return IdentityResult.Failed(errors);
@@ -1,14 +1,14 @@
using Microsoft.AspNetCore.Identity;
using zero.Identity;
using Finch.Identity;
namespace zero.Identity;
namespace Finch.Identity;
public partial class ZeroUserStore<TUser, TRole> : ZeroUserStore<TUser>,
public partial class FinchUserStore<TUser, TRole> : FinchUserStore<TUser>,
IUserRoleStore<TUser>
where TUser : ZeroIdentityUser, new()
where TRole : ZeroIdentityRole, new()
where TUser : FinchIdentityUser, new()
where TRole : FinchIdentityRole, new()
{
public ZeroUserStore(IZeroIdentityStoreDbProvider db) : base(db) { }
public FinchUserStore(IFinchIdentityStoreDbProvider db) : base(db) { }
/// <inheritdoc />

Some files were not shown because too many files have changed in this diff Show More