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) # Python Tools for Visual Studio (PTVS)
__pycache__/ __pycache__/
*.pyc *.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 System.Linq.Expressions;
using Raven.Client.Documents; 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; } 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); 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); Ops.Session.Query<T>().FirstOrDefaultAsync(expression, ct);
public async Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) 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); 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); 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); 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); Ops.Delete(model);
} }
@@ -1,10 +1,10 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using Raven.Client.Documents; 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; } 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); Ops.Session.Query<T>().FirstOrDefaultAsync(expression, ct);
public async Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) 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); 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); 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); 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); Ops.Delete(model);
} }
@@ -1,10 +1,10 @@
using Raven.Client.Documents; using Raven.Client.Documents;
using System.Linq.Expressions; 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; } 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); 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); Ops.Session.Query<T>().FirstOrDefaultAsync(expression, ct);
public async Task<IList<T>> FindAll<T>(Expression<Func<T, bool>> expression, CancellationToken ct = default) 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); 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); 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); 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); Ops.Delete(model);
} }
@@ -1,8 +1,8 @@
using Rv = Raven.Client; 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) 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 Raven.Client.Documents.Session;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace zero.Raven; namespace Finch.Raven;
public static class RavenQueryableExtensions public static class RavenQueryableExtensions
{ {
@@ -49,7 +49,7 @@ public static class RavenQueryableExtensions
if (pageNumber <= 0 || pageSize <= 0) 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); return source.Skip((pageNumber - 1) * pageSize).Take(pageSize);
@@ -1,7 +1,7 @@
using FluentValidation; using FluentValidation;
using Raven.Client.Documents; using Raven.Client.Documents;
namespace zero.Raven; namespace Finch.Raven;
public static class ValidatorExtensions public static class ValidatorExtensions
{ {
@@ -9,12 +9,12 @@ public static class ValidatorExtensions
/// Check if this value is unique within a collection /// Check if this value is unique within a collection
/// </summary> /// </summary>
public static IRuleBuilderOptions<T, TProperty> Unique<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IRavenOperations ops) 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) => return ruleBuilder.MustAsync(async (entity, value, context, cancellation) =>
{ {
bool any = await ops.Session.Advanced.AsyncDocumentQuery<T>() 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) .WhereEquals(context.PropertyPath.ToPascalCaseId(), value)
.AnyAsync(cancellation); .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 /// Check if this value is at least set once to the expected value within a collection
/// </summary> /// </summary>
public static IRuleBuilderOptions<T, TProperty> ExpectAnyUnique<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, IRavenOperations ops, TProperty expectedValue) 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 ruleBuilder.MustAsync(async (entity, value, context, cancellation) =>
{ {
return await ops.Session.Advanced.AsyncDocumentQuery<T>() return await ops.Session.Advanced.AsyncDocumentQuery<T>()
.WhereNotEquals(nameof(ZeroIdEntity.Id), entity.Id) .WhereNotEquals(nameof(FinchIdEntity.Id), entity.Id)
.WhereEquals(context.PropertyPath.ToPascalCaseId(), expectedValue) .WhereEquals(context.PropertyPath.ToPascalCaseId(), expectedValue)
.AnyAsync(cancellation); .AnyAsync(cancellation);
}).WithMessage("@errors.forms.not_unique_alone"); }).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 /// Check if this reference exists and is an entity which can be referenced
/// </summary> /// </summary>
public static IRuleBuilderOptions<T, string> Exists<T>(this IRuleBuilder<T, string> ruleBuilder, IRavenOperations ops) 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); 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 /// Check if this reference exists and is an entity which can be referenced
/// </summary> /// </summary>
public static IRuleBuilderOptions<T, string> Exists<T, TCollection>(this IRuleBuilder<T, string> ruleBuilder, IRavenOperations ops) 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) => return ruleBuilder.MustAsync(async (entity, id, context, cancellation) =>
{ {
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<PackageId>zero.Raven</PackageId> <PackageId>Finch.Raven</PackageId>
<Version>1.0.0</Version> <Version>1.0.0</Version>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks> <TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<RootNamespace>zero.Raven</RootNamespace> <RootNamespace>Finch.Raven</RootNamespace>
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
@@ -17,7 +17,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\zero\zero.csproj" /> <ProjectReference Include="..\Finch\Finch.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -4,39 +4,39 @@ using Microsoft.Extensions.DependencyInjection;
using Raven.Client.Documents; using Raven.Client.Documents;
using Raven.Client.Documents.Indexes; using Raven.Client.Documents.Indexes;
using Raven.Client.Http; using Raven.Client.Http;
using zero.Identity; using Finch.Identity;
using zero.Media; using Finch.Media;
using zero.Numbers; 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; return builder;
} }
} }
internal class ZeroRavenModule : ZeroModule internal class FinchRavenModule : FinchModule
{ {
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{ {
services.AddSingleton<IRavenDocumentConventionsBuilder, RavenDocumentConventionsBuilder>(); services.AddSingleton<IRavenDocumentConventionsBuilder, RavenDocumentConventionsBuilder>();
services.AddSingleton<IDocumentStore>(CreateRavenStore); services.AddSingleton<IDocumentStore>(CreateRavenStore);
services.AddScoped<IZeroStore, ZeroStore>(); services.AddScoped<IFinchStore, FinchStore>();
services.AddScoped<IZeroTokenProvider, ZeroTokenProvider>(); services.AddScoped<IFinchTokenProvider, FinchTokenProvider>();
services.AddScoped<StoreContext>(); services.AddScoped<StoreContext>();
services.AddTransient<IRavenOperations, RavenOperations>(); services.AddTransient<IRavenOperations, RavenOperations>();
services.AddScoped<IInterceptors, Interceptors>(); services.AddScoped<IInterceptors, Interceptors>();
services.Replace<IZeroIdentityStoreDbProvider, RavenIdentityStoreDbProvider>(ServiceLifetime.Scoped); services.Replace<IFinchIdentityStoreDbProvider, RavenIdentityStoreDbProvider>(ServiceLifetime.Scoped);
services.Replace<IZeroMediaStoreDbProvider, RavenMediaStoreDbProvider>(ServiceLifetime.Scoped); services.Replace<IFinchMediaStoreDbProvider, RavenMediaStoreDbProvider>(ServiceLifetime.Scoped);
services.Replace<IZeroNumberStoreDbProvider, RavenNumberStoreDbProvider>(ServiceLifetime.Scoped); services.Replace<IFinchNumberStoreDbProvider, RavenNumberStoreDbProvider>(ServiceLifetime.Scoped);
services.AddOptions<FlavorOptions>(); services.AddOptions<FlavorOptions>();
services.AddOptions<RavenOptions>().Bind(configuration.GetSection("Zero:Raven")); services.AddOptions<RavenOptions>().Bind(configuration.GetSection("Finch:Raven"));
services.ConfigureOptions<ConfigureFlavorJsonOptions>(); services.ConfigureOptions<ConfigureFlavorJsonOptions>();
} }
@@ -45,7 +45,7 @@ internal class ZeroRavenModule : ZeroModule
/// </summary> /// </summary>
protected IDocumentStore CreateRavenStore(IServiceProvider services) protected IDocumentStore CreateRavenStore(IServiceProvider services)
{ {
IZeroOptions options = services.GetService<IZeroOptions>(); IFinchOptions options = services.GetService<IFinchOptions>();
RavenOptions ravenOptions = options.For<RavenOptions>(); RavenOptions ravenOptions = options.For<RavenOptions>();
IRavenDocumentConventionsBuilder conventionsBuilder = services.GetService<IRavenDocumentConventionsBuilder>(); IRavenDocumentConventionsBuilder conventionsBuilder = services.GetService<IRavenDocumentConventionsBuilder>();
@@ -68,7 +68,7 @@ internal class ZeroRavenModule : ZeroModule
IDocumentStore raven = store.Initialize(); IDocumentStore raven = store.Initialize();
// create all indexes // 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); IndexCreation.CreateIndexes(indexes, store, database: ravenOptions.Database);
@@ -4,18 +4,18 @@ using Raven.Client.Documents.Queries;
using Raven.Client.Documents.Session; using Raven.Client.Documents.Session;
using Raven.Client; 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; Options = options;
Raven = raven; Raven = raven;
//Database = null; //Database = null;
} }
protected IZeroOptions Options { get; set; } protected IFinchOptions Options { get; set; }
protected Dictionary<string, IAsyncDocumentSession> ScopedSessions { get; set; } = new(); protected Dictionary<string, IAsyncDocumentSession> ScopedSessions { get; set; } = new();
private const string NullDb = "__default__"; private const string NullDb = "__default__";
@@ -25,11 +25,11 @@ public class ZeroStore : IZeroStore
/// <inheritdoc /> /// <inheritdoc />
public IAsyncDocumentSession Session(ZeroSessionResolution resolution = ZeroSessionResolution.Reuse, SessionOptions options = null) public IAsyncDocumentSession Session(FinchSessionResolution resolution = FinchSessionResolution.Reuse, SessionOptions options = null)
{ {
options ??= new SessionOptions(); options ??= new SessionOptions();
if (resolution == ZeroSessionResolution.Create) if (resolution == FinchSessionResolution.Create)
{ {
return Raven.OpenAsyncSession(options); return Raven.OpenAsyncSession(options);
} }
@@ -75,14 +75,14 @@ public class ZeroStore : IZeroStore
} }
public enum ZeroSessionResolution public enum FinchSessionResolution
{ {
Reuse = 0, Reuse = 0,
Create = 1 Create = 1
} }
public interface IZeroStore public interface IFinchStore
{ {
/// <summary> /// <summary>
/// Get underlying raven document store /// Get underlying raven document store
@@ -92,7 +92,7 @@ public interface IZeroStore
/// <summary> /// <summary>
/// Use a specific session /// Use a specific session
/// </summary> /// </summary>
IAsyncDocumentSession Session(ZeroSessionResolution resolution = ZeroSessionResolution.Reuse, SessionOptions options = null); IAsyncDocumentSession Session(FinchSessionResolution resolution = FinchSessionResolution.Reuse, SessionOptions options = null);
/// <summary> /// <summary>
/// Purges a collection /// Purges a collection
@@ -4,15 +4,15 @@ using Raven.Client.Documents.Indexes.Spatial;
using Raven.Client.Documents.Operations.Attachments; using Raven.Client.Documents.Operations.Attachments;
using System.Linq.Expressions; 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() { } 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 Reduce { get => base.Reduce; set => base.Reduce = value; }
public new string OutputReduceToCollection { get => base.OutputReduceToCollection; set => base.OutputReduceToCollection = 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 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() { } protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { } public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractMultiMapIndexCreationTask<TReduceResult> // AbstractMultiMapIndexCreationTask<TReduceResult>
public new void AddMap<TSource>(Expression<Func<IEnumerable<TSource>, IEnumerable>> map) => base.AddMap(map); 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() { } protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { } public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractMultiMapIndexCreationTask<TReduceResult> // AbstractMultiMapIndexCreationTask<TReduceResult>
public new void AddMap<TSource>(Expression<Func<IEnumerable<TSource>, IEnumerable>> map) => base.AddMap(map); 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() { } protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { } public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractIndexCreationTask<TDocument, TReduceResult> // AbstractIndexCreationTask<TDocument, TReduceResult>
public new Expression<Func<IEnumerable<TDocument>, IEnumerable>> Map { get => base.Map; set => base.Map = value; } 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() { } protected virtual void Create() { }
public virtual void Setup(IZeroOptions options, IDocumentStore store) { } public virtual void Setup(IFinchOptions options, IDocumentStore store) { }
// AbstractIndexCreationTask // AbstractIndexCreationTask
public new IJsonObject AsJson(object doc) => base.AsJson(doc); 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()); IEnumerable<RavenIndexModifiersOptions.Modifier> modifiers = options.Indexes.Modifiers.GetAllForType(index.GetType());
foreach (RavenIndexModifiersOptions.Modifier modifier in modifiers) foreach (RavenIndexModifiersOptions.Modifier modifier in modifiers)
{ {
Action<IZeroIndexDefinition> action = modifier.Modify.Compile(); Action<IFinchIndexDefinition> action = modifier.Modify.Compile();
action.Invoke(index); action.Invoke(index);
} }
} }
@@ -1,18 +1,18 @@
using Raven.Client.Documents; using Raven.Client.Documents;
using Raven.Client.Documents.Indexes; 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 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() protected override void Create()
{ {
Map = items => items.Select(item => new ZeroTreeHierarchyIndexResult Map = items => items.Select(item => new FinchTreeHierarchyIndexResult
{ {
Id = item.Id, Id = item.Id,
Path = Recurse(item, x => LoadDocument<T>(x.ParentId)) Path = Recurse(item, x => LoadDocument<T>(x.ParentId))
@@ -1,6 +1,6 @@
using Raven.Client.Documents.Indexes; using Raven.Client.Documents.Indexes;
namespace zero.Raven; namespace Finch.Raven;
public static class RavenIndexExtensions 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 /> /// <inheritdoc />
public Type ModelType { get; protected set; } 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); public virtual Task<InterceptorResult<T>> Creating(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default);
/// <inheritdoc /> /// <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 /> /// <inheritdoc />
public virtual Task<InterceptorResult<T>> Updating(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default); public virtual Task<InterceptorResult<T>> Updating(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default);
/// <inheritdoc /> /// <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 /> /// <inheritdoc />
public virtual Task<InterceptorResult<T>> Deleting(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default); public virtual Task<InterceptorResult<T>> Deleting(InterceptorParameters args, T model) => Task.FromResult<InterceptorResult<T>>(default);
/// <inheritdoc /> /// <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 /> /// <inheritdoc />
public virtual Task Created(InterceptorParameters args, T model) => Task.CompletedTask; public virtual Task Created(InterceptorParameters args, T model) => Task.CompletedTask;
/// <inheritdoc /> /// <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 /> /// <inheritdoc />
public virtual Task Updated(InterceptorParameters args, T model) => Task.CompletedTask; public virtual Task Updated(InterceptorParameters args, T model) => Task.CompletedTask;
/// <inheritdoc /> /// <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 /> /// <inheritdoc />
public virtual Task Deleted(InterceptorParameters args, T model) => Task.CompletedTask; public virtual Task Deleted(InterceptorParameters args, T model) => Task.CompletedTask;
/// <inheritdoc /> /// <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) if (result == default)
{ {
return default; return default;
} }
return new InterceptorResult<ZeroIdEntity>() return new InterceptorResult<FinchIdEntity>()
{ {
Continue = result.Continue, Continue = result.Continue,
InterceptorHash = result.InterceptorHash, 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; public virtual bool CanHandle(InterceptorParameters args, Type modelType) => true;
/// <inheritdoc /> /// <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 /> /// <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 /> /// <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 /> /// <inheritdoc />
public virtual Task Created(InterceptorParameters args, ZeroIdEntity model) => Task.CompletedTask; public virtual Task Created(InterceptorParameters args, FinchIdEntity model) => Task.CompletedTask;
/// <inheritdoc /> /// <inheritdoc />
public virtual Task Updated(InterceptorParameters args, ZeroIdEntity model) => Task.CompletedTask; public virtual Task Updated(InterceptorParameters args, FinchIdEntity model) => Task.CompletedTask;
/// <inheritdoc /> /// <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> /// <summary>
/// Type of the associated model /// Type of the associated model
@@ -178,30 +178,30 @@ public interface IInterceptor
/// <summary> /// <summary>
/// Called after an entity has been stored but before the session has saved its changes /// Called after an entity has been stored but before the session has saved its changes
/// </summary> /// </summary>
Task Created(InterceptorParameters args, ZeroIdEntity model); Task Created(InterceptorParameters args, FinchIdEntity model);
/// <summary> /// <summary>
/// Called before an entity is stored and validated /// Called before an entity is stored and validated
/// </summary> /// </summary>
Task<InterceptorResult<ZeroIdEntity>> Creating(InterceptorParameters args, ZeroIdEntity model); Task<InterceptorResult<FinchIdEntity>> Creating(InterceptorParameters args, FinchIdEntity model);
/// <summary> /// <summary>
/// Called after an entity has been deleted but before the session has saved its changes /// Called after an entity has been deleted but before the session has saved its changes
/// </summary> /// </summary>
Task Deleted(InterceptorParameters args, ZeroIdEntity model); Task Deleted(InterceptorParameters args, FinchIdEntity model);
/// <summary> /// <summary>
/// Called before an entity is deleted /// Called before an entity is deleted
/// </summary> /// </summary>
Task<InterceptorResult<ZeroIdEntity>> Deleting(InterceptorParameters args, ZeroIdEntity model); Task<InterceptorResult<FinchIdEntity>> Deleting(InterceptorParameters args, FinchIdEntity model);
/// <summary> /// <summary>
/// Called after an entity has been updated but before the session has saved its changes /// Called after an entity has been updated but before the session has saved its changes
/// </summary> /// </summary>
Task Updated(InterceptorParameters args, ZeroIdEntity model); Task Updated(InterceptorParameters args, FinchIdEntity model);
/// <summary> /// <summary>
/// Called before an entity is stored and validated /// Called before an entity is stored and validated
/// </summary> /// </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; 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; } 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; } 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; } 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; 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; InterceptorHandler = interceptors;
Store = store; 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); 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); result.InterceptorHash = IdGenerator.Create(32);
InterceptorCache.Add(interceptor, parameters); InterceptorCache.Add(interceptor, parameters);
@@ -129,7 +129,7 @@ public class InterceptorInstruction<T> where T : ZeroIdEntity, new()
/// <summary> /// <summary>
/// Proxy for handling methods on an interceptor /// Proxy for handling methods on an interceptor
/// </summary> /// </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.Create => interceptor.Creating(parameters, Model),
InterceptorRunType.Update => interceptor.Updating(parameters, Model), InterceptorRunType.Update => interceptor.Updating(parameters, Model),
@@ -1,16 +1,16 @@
namespace zero.Raven; namespace Finch.Raven;
public class InterceptorParameters public class InterceptorParameters
{ {
/// <summary> /// <summary>
/// The current zero context /// The current finch context
/// </summary> /// </summary>
public IZeroContext Context { get; set; } public IFinchContext Context { get; set; }
/// <summary> /// <summary>
/// Raven document store /// Raven document store
/// </summary> /// </summary>
public IZeroStore Store { get; set; } public IFinchStore Store { get; set; }
/// <summary> /// <summary>
/// Access to other interceptor methods /// Access to other interceptor methods
@@ -1,4 +1,4 @@
namespace zero.Raven; namespace Finch.Raven;
public class InterceptorResult<T> public class InterceptorResult<T>
{ {
@@ -1,4 +1,4 @@
namespace zero.Raven; namespace Finch.Raven;
public enum InterceptorRunType public enum InterceptorRunType
{ {
@@ -1,19 +1,19 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace zero.Raven; namespace Finch.Raven;
public class Interceptors : IInterceptors 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 Lazy<IEnumerable<IInterceptor>> Registrations { get; set; }
protected ILogger<IInterceptor> Logger { 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; Context = context;
Store = store; Store = store;
@@ -23,13 +23,13 @@ public class Interceptors : IInterceptors
/// <inheritdoc /> /// <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 /> /// <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 /> /// <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> /// <summary>
/// Instruction which can run interceptors before and after a creating an entity /// Instruction which can run interceptors before and after a creating an entity
/// </summary> /// </summary>
InterceptorInstruction<T> ForCreate<T>(T model) where T : ZeroIdEntity, new(); InterceptorInstruction<T> ForCreate<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Instruction which can run interceptors before and after updating an entity /// Instruction which can run interceptors before and after updating an entity
/// </summary> /// </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> /// <summary>
/// Instruction which can run interceptors before and after deleting an entity /// Instruction which can run interceptors before and after deleting an entity
/// </summary> /// </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.Documents.Queries;
using Raven.Client; using Raven.Client;
namespace zero.Raven; namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations public partial class RavenOperations : IRavenOperations
{ {
/// <inheritdoc /> /// <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); => Delete<T>(model.Id);
/// <inheritdoc /> /// <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); T model = await Load<T>(id);
@@ -49,7 +49,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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 collectionName = Store.Raven.Conventions.FindCollectionName(typeof(T));
var operationQuery = new DeleteByQueryOperation(new IndexQuery() var operationQuery = new DeleteByQueryOperation(new IndexQuery()
@@ -1,14 +1,14 @@
namespace zero.Raven; namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations public partial class RavenOperations : IRavenOperations
{ {
/// <inheritdoc /> /// <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 /> /// <inheritdoc />
public virtual Task<TFlavor> Empty<T, TFlavor>(string flavorAlias = null) public virtual Task<TFlavor> Empty<T, TFlavor>(string flavorAlias = null)
where T : ZeroIdEntity, ISupportsFlavors, new() where T : FinchIdEntity, ISupportsFlavors, new()
where TFlavor : T, new() where TFlavor : T, new()
{ {
return Task.FromResult(Flavors.Construct<T, TFlavor>(flavorAlias)); return Task.FromResult(Flavors.Construct<T, TFlavor>(flavorAlias));
@@ -4,12 +4,12 @@ using Raven.Client.Documents.Linq;
using Raven.Client.Documents.Session; using Raven.Client.Documents.Session;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace zero.Raven; namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations public partial class RavenOperations : IRavenOperations
{ {
/// <inheritdoc /> /// <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()) if (id.IsNullOrWhiteSpace())
{ {
@@ -25,7 +25,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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(); ids = ids.Distinct().ToArray();
@@ -43,7 +43,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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(); ids = ids.Distinct().ToArray();
@@ -64,7 +64,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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; querySelector ??= x => x;
return await querySelector(Session.Query<T>()).AnyAsync(); return await querySelector(Session.Query<T>()).AnyAsync();
@@ -72,7 +72,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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); IRavenQueryable<T> queryable = Session.Query<T>().Statistics(out QueryStatistics statistics);
querySelector ??= x => x; querySelector ??= x => x;
@@ -84,7 +84,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task<Paged<T>> Load<T, TIndex>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) 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() where TIndex : AbstractCommonApiForIndexes, new()
{ {
IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Statistics(out QueryStatistics statistics); IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Statistics(out QueryStatistics statistics);
@@ -96,7 +96,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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>(); IRavenQueryable<T> queryable = Session.Query<T>();
querySelector ??= x => x; querySelector ??= x => x;
@@ -107,7 +107,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task<List<T>> Load<T, TIndex>(Func<IRavenQueryable<T>, IQueryable<T>> querySelector) 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() where TIndex : AbstractCommonApiForIndexes, new()
{ {
IRavenQueryable<T> queryable = Session.Query<T, TIndex>(); IRavenQueryable<T> queryable = Session.Query<T, TIndex>();
@@ -118,7 +118,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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(); return await Session.Query<T>().Where(predicate).ToListAsync();
} }
@@ -126,7 +126,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task<List<T>> Load<T, TIndex>(Expression<Func<T, bool>> predicate) 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() where TIndex : AbstractCommonApiForIndexes, new()
{ {
return await Session.Query<T, TIndex>().Where(predicate).ToListAsync(); return await Session.Query<T, TIndex>().Where(predicate).ToListAsync();
@@ -135,8 +135,8 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task<Paged<TProjection>> Load<T, TIndex, TProjection>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) 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 T : FinchIdEntity, new()
where TProjection : ZeroIdEntity, new() where TProjection : FinchIdEntity, new()
where TIndex : AbstractCommonApiForIndexes, new() where TIndex : AbstractCommonApiForIndexes, new()
{ {
IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Statistics(out QueryStatistics statistics); IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Statistics(out QueryStatistics statistics);
@@ -148,7 +148,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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(); List<T> items = new();
@@ -162,7 +162,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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>(); IRavenQueryable<T> query = Session.Query<T>();
IQueryable<T> queryable = query; IQueryable<T> queryable = query;
@@ -187,7 +187,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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); string changeVector = Session.Advanced.GetChangeVectorFor(model);
return IdGenerator.HashString(changeVector); return IdGenerator.HashString(changeVector);
@@ -3,12 +3,12 @@ using Raven.Client.Documents.Indexes;
using Raven.Client.Documents.Linq; using Raven.Client.Documents.Linq;
using Raven.Client.Documents.Session; using Raven.Client.Documents.Session;
namespace zero.Raven; namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations public partial class RavenOperations : IRavenOperations
{ {
/// <inheritdoc /> /// <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); return Task.FromResult(true);
} }
@@ -16,13 +16,13 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public async Task<T[]> GetHierarchy<T, TIndex>(string id) public async Task<T[]> GetHierarchy<T, TIndex>(string id)
where T : ZeroIdEntity, ISupportsTrees, new() where T : FinchIdEntity, ISupportsTrees, new()
where TIndex : ZeroTreeHierarchyIndex<T>, new() where TIndex : FinchTreeHierarchyIndex<T>, new()
{ {
ZeroTreeHierarchyIndexResult result = await Session.Query<ZeroTreeHierarchyIndexResult, TIndex>() FinchTreeHierarchyIndexResult result = await Session.Query<FinchTreeHierarchyIndexResult, TIndex>()
.ProjectInto<ZeroTreeHierarchyIndexResult>() .ProjectInto<FinchTreeHierarchyIndexResult>()
.Include<ZeroTreeHierarchyIndexResult, T>(x => x.Path) .Include<FinchTreeHierarchyIndexResult, T>(x => x.Path)
.Include<ZeroTreeHierarchyIndexResult, T>(x => x.Id) .Include<FinchTreeHierarchyIndexResult, T>(x => x.Id)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (result == null) if (result == null)
@@ -38,7 +38,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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); IRavenQueryable<T> queryable = Session.Query<T>().Where(x => x.ParentId == parentId).Statistics(out QueryStatistics statistics);
querySelector ??= x => x.OrderBy(x => x.Sort); querySelector ??= x => x.OrderBy(x => x.Sort);
@@ -50,7 +50,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public async Task<Paged<T>> LoadChildren<T, TIndex>(string parentId, int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) 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() where TIndex : AbstractCommonApiForIndexes, new()
{ {
IRavenQueryable<T> queryable = Session.Query<T, TIndex>().Where(x => x.ParentId == parentId).Statistics(out QueryStatistics statistics); 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 /> /// <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 model = await Load<T>(id);
T parent = await Load<T>(newParentId); T parent = await Load<T>(newParentId);
@@ -86,17 +86,17 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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 /> /// <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> /// <summary>
/// Copies an entity (with optional descendants) to a new location /// Copies an entity (with optional descendants) to a new location
/// </summary> /// </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 originalModel = await Load<T>(id);
T model = ObjectCopycat.Clone(originalModel); T model = ObjectCopycat.Clone(originalModel);
@@ -114,11 +114,11 @@ public partial class RavenOperations : IRavenOperations
model.Id = null; model.Id = null;
model.ParentId = parent?.Id; model.ParentId = parent?.Id;
if (model is ZeroEntity zeroEntity) if (model is FinchEntity finchEntity)
{ {
zeroEntity.IsActive = !isDescendant ? false : (originalModel as ZeroEntity).IsActive; finchEntity.IsActive = !isDescendant ? false : (originalModel as FinchEntity).IsActive;
zeroEntity.CreatedDate = DateTime.Now; finchEntity.CreatedDate = DateTime.Now;
zeroEntity.Hash = null; finchEntity.Hash = null;
} }
// check if new parent is allowed // check if new parent is allowed
@@ -145,7 +145,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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); List<T> pages = await GetDescendantsAndSelf(model);
@@ -162,7 +162,7 @@ public partial class RavenOperations : IRavenOperations
/// <summary> /// <summary>
/// Get an entity with all its descendants /// Get an entity with all its descendants
/// </summary> /// </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 }; List<T> items = new() { model };
@@ -1,18 +1,18 @@
using FluentValidation.Results; using FluentValidation.Results;
using Rv = Raven.Client; using Rv = Raven.Client;
namespace zero.Raven; namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations public partial class RavenOperations : IRavenOperations
{ {
/// <inheritdoc /> /// <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 /> /// <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 /> /// <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) if (model == null)
{ {
@@ -91,7 +91,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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); Dictionary<string, T> items = await Load<T>(sortedIds);
uint index = 10; uint index = 10;
@@ -114,7 +114,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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(); using var bulkInsert = Store.Raven.BulkInsert();
@@ -6,7 +6,7 @@ using Raven.Client.Documents.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Security.Claims; using System.Security.Claims;
namespace zero.Raven; namespace Finch.Raven;
public partial class RavenOperations : IRavenOperations public partial class RavenOperations : IRavenOperations
{ {
@@ -15,7 +15,7 @@ public partial class RavenOperations : IRavenOperations
protected record OperationOptions(bool IncludeInactive); protected record OperationOptions(bool IncludeInactive);
protected IZeroContext Context { get; private set; } protected IFinchContext Context { get; private set; }
protected IInterceptors Interceptors { 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 IServiceProvider Services { get; private set; }
protected IZeroStore Store { get; private set; } protected IFinchStore Store { get; private set; }
protected StoreInterceptorBlocker InterceptorBlocker { get; private set; } protected StoreInterceptorBlocker InterceptorBlocker { get; private set; }
@@ -39,7 +39,7 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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; IAsyncDocumentSession session = Session;
return await session.Advanced.DocumentStore.Conventions.GenerateDocumentIdAsync(session.Advanced.DocumentStore.Database, model); return await session.Advanced.DocumentStore.Conventions.GenerateDocumentIdAsync(session.Advanced.DocumentStore.Database, model);
@@ -54,33 +54,33 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <inheritdoc />
public T PrepareForSave<T>(T model) where T : ZeroIdEntity public T PrepareForSave<T>(T model) where T : FinchIdEntity
{ {
// set IDs // set IDs
AutoSetIds(model); AutoSetIds(model);
if (model is ZeroEntity zeroModel) if (model is FinchEntity finchModel)
{ {
// get current user // get current user
string userId = null; string userId = null;
//string userId = Context.BackofficeUser.FindFirstValue(Constants.Auth.Claims.UserId).Or(Constants.Auth.SystemUser); //string userId = Context.BackofficeUser.FindFirstValue(Constants.Auth.Claims.UserId).Or(Constants.Auth.SystemUser);
// set default properties // 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 // update name alias and last modified
zeroModel.Alias = Safenames.Alias(zeroModel.Name); finchModel.Alias = Safenames.Alias(finchModel.Name);
zeroModel.LastModifiedById = userId; finchModel.LastModifiedById = userId;
zeroModel.LastModifiedDate = DateTimeOffset.Now; finchModel.LastModifiedDate = DateTimeOffset.Now;
zeroModel.CreatedById ??= userId; finchModel.CreatedById ??= userId;
zeroModel.Hash ??= IdGenerator.Create(); finchModel.Hash ??= IdGenerator.Create();
} }
return model; return model;
@@ -88,9 +88,9 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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) if (validator == null)
{ {
@@ -109,10 +109,10 @@ public partial class RavenOperations : IRavenOperations
/// <inheritdoc /> /// <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; // 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> /// <summary>
/// Get new instance of an entity (with an optional flavor) /// Get new instance of an entity (with an optional flavor)
/// </summary> /// </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> /// <summary>
/// Get new instance of an entity with a specific flavor /// Get new instance of an entity with a specific flavor
/// </summary> /// </summary>
/// <param name="flavorAlias">Optional alias. If left out the default flavor is used (if configured)</param> /// <param name="flavorAlias">Optional alias. If left out the default flavor is used (if configured)</param>
Task<TFlavor> Empty<T, TFlavor>(string flavorAlias = null) Task<TFlavor> Empty<T, TFlavor>(string flavorAlias = null)
where T : ZeroIdEntity, ISupportsFlavors, new() where T : FinchIdEntity, ISupportsFlavors, new()
where TFlavor : T, new(); where TFlavor : T, new();
/// <summary> /// <summary>
/// Generate model Id by using configured document store conventions /// Generate model Id by using configured document store conventions
/// </summary> /// </summary>
Task<string> GenerateId<T>(T model) where T : ZeroIdEntity; Task<string> GenerateId<T>(T model) where T : FinchIdEntity;
/// <summary> /// <summary>
/// Generate values for all properties (incl. nested) which contain the [GenerateId] attribute /// Generate values for all properties (incl. nested) which contain the [GenerateId] attribute
@@ -164,88 +164,88 @@ public interface IRavenOperations
T AutoSetIds<T>(T model); T AutoSetIds<T>(T model);
/// <summary> /// <summary>
/// Automatically fill base properties of a ZeroEntity /// Automatically fill base properties of a FinchEntity
/// </summary> /// </summary>
T PrepareForSave<T>(T model) where T : ZeroIdEntity; T PrepareForSave<T>(T model) where T : FinchIdEntity;
/// <summary> /// <summary>
/// Check if any items exist in this collection (with optional query) /// Check if any items exist in this collection (with optional query)
/// </summary> /// </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> /// <summary>
/// Get an entity by Id /// Get an entity by Id
/// </summary> /// </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> /// <summary>
/// Get entities by ids /// Get entities by ids
/// </summary> /// </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> /// <summary>
/// Get entities by ids /// Get entities by ids
/// </summary> /// </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> /// <summary>
/// Get entities by query /// Get entities by query
/// </summary> /// </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> /// <summary>
/// Get entities by query (by using the specified index) /// Get entities by query (by using the specified index)
/// </summary> /// </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> /// <summary>
/// Get entities by query /// Get entities by query
/// </summary> /// </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> /// <summary>
/// Get entities by query (by using the specified index) /// Get entities by query (by using the specified index)
/// </summary> /// </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> /// <summary>
/// Get entities by query /// Get entities by query
/// </summary> /// </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> /// <summary>
/// Get entities by query (by using the specified index) /// Get entities by query (by using the specified index)
/// </summary> /// </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> /// <summary>
/// Get entities by query (by using the specified index) and project into a result /// Get entities by query (by using the specified index) and project into a result
/// </summary> /// </summary>
Task<Paged<TProjection>> Load<T, TIndex, TProjection>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default) Task<Paged<TProjection>> Load<T, TIndex, TProjection>(int pageNumber, int pageSize, Func<IRavenQueryable<T>, IQueryable<T>> querySelector = default)
where T : ZeroIdEntity, new() where T : FinchIdEntity, new()
where TProjection : ZeroIdEntity, new() where TProjection : FinchIdEntity, new()
where TIndex : AbstractCommonApiForIndexes, new(); where TIndex : AbstractCommonApiForIndexes, new();
/// <summary> /// <summary>
/// Get all entities from this collection. /// Get all entities from this collection.
/// Warning: Don't use this method for large collections. Stream the results instead. /// Warning: Don't use this method for large collections. Stream the results instead.
/// </summary> /// </summary>
Task<List<T>> LoadAll<T>() where T : ZeroIdEntity, new(); Task<List<T>> LoadAll<T>() where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Stream the collection /// Stream the collection
/// </summary> /// </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> /// <summary>
/// Get the change vector for a model /// Get the change vector for a model
/// </summary> /// </summary>
string GetChangeToken<T>(T model) where T : ZeroIdEntity, new(); string GetChangeToken<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Validates an entity /// Validates an entity
/// </summary> /// </summary>
Task<ValidationResult> Validate<T>(T model) where T : ZeroIdEntity, new(); Task<ValidationResult> Validate<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Do not run interceptors for create/update/delete operations while this disposable is active /// Do not run interceptors for create/update/delete operations while this disposable is active
@@ -255,73 +255,73 @@ public interface IRavenOperations
/// <summary> /// <summary>
/// Do only return the model when it is set to active or inactive entities are included with IncludeInactive() /// Do only return the model when it is set to active or inactive entities are included with IncludeInactive()
/// </summary> /// </summary>
T WhenActive<T>(T model) where T : ZeroIdEntity, new(); T WhenActive<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Creates an entity with an optional validator /// Creates an entity with an optional validator
/// </summary> /// </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> /// <summary>
/// Updates an entity with an optional validator /// Updates an entity with an optional validator
/// </summary> /// </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 /> /// <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> /// <summary>
/// Batch create entities /// Batch create entities
/// </summary> /// </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> /// <summary>
/// Deletes an entity /// Deletes an entity
/// </summary> /// </summary>
Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new(); Task<Result<T>> Delete<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Deletes an entity /// Deletes an entity
/// </summary> /// </summary>
Task<Result<T>> Delete<T>(string id) where T : ZeroIdEntity, new(); Task<Result<T>> Delete<T>(string id) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Deletes the whole collection /// Deletes the whole collection
/// </summary> /// </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> /// <summary>
/// Loads all children for an entity /// Loads all children for an entity
/// </summary> /// </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> /// <summary>
/// Get descendants by query (by using the specified index) /// Get descendants by query (by using the specified index)
/// </summary> /// </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> /// <summary>
/// Get tree hierarchy for an entity /// Get tree hierarchy for an entity
/// </summary> /// </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> /// <summary>
/// Move an entity to a new parent /// Move an entity to a new parent
/// </summary> /// </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> /// <summary>
/// Copies an entity to a new location /// Copies an entity to a new location
/// </summary> /// </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> /// <summary>
/// Copies an entity with descendants to a new location /// Copies an entity with descendants to a new location
/// </summary> /// </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> /// <summary>
/// Deletes an entity with all descendents /// Deletes an entity with all descendents
/// </summary> /// </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 Raven.Client.Documents.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace zero.Raven; namespace Finch.Raven;
public static class RavenOperationsExtensions public static class RavenOperationsExtensions
{ {
/// <summary> /// <summary>
/// Stream the collection /// Stream the collection
/// </summary> /// </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> /// <summary>
/// Deletes an entity by Id /// Deletes an entity by Id
/// </summary> /// </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> /// <summary>
/// Deletes entities by selector /// Deletes entities by selector
/// </summary> /// </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> /// <summary>
/// Deletes entities by Id /// Deletes entities by Id
/// </summary> /// </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> /// <summary>
/// Deletes entities /// Deletes entities
/// </summary> /// </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; int successCount = 0;
@@ -46,5 +46,5 @@ public static class RavenOperationsExtensions
/// <summary> /// <summary>
/// Deletes an entity by Id with all descendents /// Deletes an entity by Id with all descendents
/// </summary> /// </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 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; } public IInterceptors Interceptors { get; private set; }
@@ -15,7 +15,7 @@ public class StoreContext
public IMessageAggregator Messages { get; private set; } 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; Store = store;
Options = context.Options; Options = context.Options;
@@ -1,4 +1,4 @@
namespace zero.Raven; namespace Finch.Raven;
/// <summary> /// <summary>
/// This attribute will allow the usage of custom collection names for Raven collections /// 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 public static partial class RavenConstants
{ {
@@ -4,22 +4,22 @@ using System.Reflection;
using System.Text; using System.Text;
using Rv = Raven.Client; using Rv = Raven.Client;
namespace zero.Raven; namespace Finch.Raven;
public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
{ {
protected HashSet<Type> PolymorphTypes { get; private set; } = new(); 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 char IdentityPartsSeparator { get; set; } = '.';
protected IZeroOptions Options { get; private set; } protected IFinchOptions Options { get; private set; }
protected static ConcurrentDictionary<Type, string> CachedTypeCollectionNameMap = new(); protected static ConcurrentDictionary<Type, string> CachedTypeCollectionNameMap = new();
public RavenDocumentConventionsBuilder(IZeroOptions options) public RavenDocumentConventionsBuilder(IFinchOptions options)
{ {
Options = options; Options = options;
} }
@@ -32,7 +32,7 @@ public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
conventions.IdentityPartsSeparator = IdentityPartsSeparator; conventions.IdentityPartsSeparator = IdentityPartsSeparator;
conventions.TransformTypeCollectionNameToDocumentIdPrefix = TransformTypeCollectionNameToDocumentIdPrefix; conventions.TransformTypeCollectionNameToDocumentIdPrefix = TransformTypeCollectionNameToDocumentIdPrefix;
conventions.FindCollectionName = FindCollectionName; 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 // do not alter non-internal entities
if (!AcceptsZeroConventionsType.IsAssignableFrom(type)) if (!AcceptsFinchConventionsType.IsAssignableFrom(type))
{ {
return cache(DocumentConventions.DefaultGetCollectionName(type)); return cache(DocumentConventions.DefaultGetCollectionName(type));
} }
@@ -94,7 +94,7 @@ public class RavenDocumentConventionsBuilder : IRavenDocumentConventionsBuilder
} }
// use base interface if available // 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) if (interfaceBaseType != null)
{ {
@@ -1,7 +1,7 @@
using Raven.Client.Documents; using Raven.Client.Documents;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace zero.Raven; namespace Finch.Raven;
public class RavenOptions public class RavenOptions
{ {
@@ -23,9 +23,9 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
{ {
internal Type Type { get; set; } 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; Type = type;
CreateIndex = create; CreateIndex = create;
@@ -35,17 +35,17 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
public RavenIndexModifiersOptions Modifiers { get; private set; } = new(); 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())); base.Add(new Map(typeof(T), () => new T()));
} }
public void Add(Type indexType) 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)); base.Add(new Map(typeof(T), () => index));
} }
@@ -59,8 +59,8 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
} }
public void Replace<T, TReplaceWith>() public void Replace<T, TReplaceWith>()
where T : IZeroIndexDefinition, new() where T : IFinchIndexDefinition, new()
where TReplaceWith : IZeroIndexDefinition, new() where TReplaceWith : IFinchIndexDefinition, new()
{ {
Replace(typeof(T), typeof(TReplaceWith)); Replace(typeof(T), typeof(TReplaceWith));
} }
@@ -75,13 +75,13 @@ public class RavenIndexesOptions : List<RavenIndexesOptions.Map>
Add(replaceWith); Add(replaceWith);
} }
public IEnumerable<IZeroIndexDefinition> BuildAll(IZeroOptions options, IDocumentStore store) public IEnumerable<IFinchIndexDefinition> BuildAll(IFinchOptions options, IDocumentStore store)
{ {
RavenOptions ravenOptions = options.For<RavenOptions>(); RavenOptions ravenOptions = options.For<RavenOptions>();
foreach (Map map in this) foreach (Map map in this)
{ {
IZeroIndexDefinition index = map.CreateIndex.Compile().Invoke(); IFinchIndexDefinition index = map.CreateIndex.Compile().Invoke();
index.Setup(options, store); index.Setup(options, store);
index.RunModifiers(ravenOptions); index.RunModifiers(ravenOptions);
yield return index; yield return index;
@@ -96,10 +96,10 @@ public class RavenIndexModifiersOptions : List<RavenIndexModifiersOptions.Modifi
{ {
public Type Type { get; set; } 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() 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) public IEnumerable<Modifier> GetAllForType(Type type)
@@ -3,18 +3,18 @@ using Raven.Client.Documents.Session;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
namespace zero.Raven; namespace Finch.Raven;
public class ZeroTokenProvider : IZeroTokenProvider public class FinchTokenProvider : IFinchTokenProvider
{ {
readonly char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-".ToCharArray(); readonly char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-".ToCharArray();
readonly RandomNumberGenerator randonNumberGenerator; 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; Store = store;
randonNumberGenerator = RandomNumberGenerator.Create(); randonNumberGenerator = RandomNumberGenerator.Create();
@@ -246,7 +246,7 @@ public class ZeroTokenProvider : IZeroTokenProvider
} }
public interface IZeroTokenProvider public interface IFinchTokenProvider
{ {
/// <summary> /// <summary>
/// Generates a token for a <paramref name="key"/> with a specified <paramref name="expires"/> lifespan. /// 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.Security.Cryptography;
using System.Text; using System.Text;
namespace zero.Raven; namespace Finch.Raven;
/// <summary> /// <summary>
/// Replicates the Rfc6238AuthenticationService from ASP.NET Core internals as it isn't part of the public API /// 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")] [RavenCollection("Tokens")]
public class SecurityToken : ISupportsDbConventions public class SecurityToken : ISupportsDbConventions
+11 -11
View File
@@ -6,17 +6,17 @@ global using System.Linq;
global using System.Threading; global using System.Threading;
global using System.Threading.Tasks; global using System.Threading.Tasks;
global using zero.Utils; global using Finch.Utils;
global using zero.Configuration; global using Finch.Configuration;
global using zero.Extensions; global using Finch.Extensions;
global using zero.FileStorage; global using Finch.FileStorage;
global using zero.Models; global using Finch.Models;
global using zero.Modules; global using Finch.Modules;
global using zero.Rendering; global using Finch.Rendering;
global using zero.Validation; global using Finch.Validation;
global using zero.Localization; global using Finch.Localization;
global using zero.Context; global using Finch.Context;
global using zero.Communication; global using Finch.Communication;
global using Raven.Client.Documents; global using Raven.Client.Documents;
global using Raven.Client.Documents.Operations; global using Raven.Client.Documents.Operations;
@@ -2,9 +2,9 @@
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
using zero.Extensions; using Finch.Extensions;
namespace zero.Sqlite; namespace Finch.Sqlite;
public static class SqlExpressionExtensions public static class SqlExpressionExtensions
{ {
@@ -15,7 +15,7 @@ public static class SqlExpressionExtensions
if (pageNumber <= 0 || pageSize <= 0) 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); return source.Skip((pageNumber - 1) * pageSize).Take(pageSize);
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<PackageId>zero.Sqlite</PackageId> <PackageId>Finch.Sqlite</PackageId>
<Version>1.0.0</Version> <Version>1.0.0</Version>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks> <TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<RootNamespace>zero.Sqlite</RootNamespace> <RootNamespace>Finch.Sqlite</RootNamespace>
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
@@ -15,7 +15,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\zero\zero.csproj" /> <ProjectReference Include="..\Finch\Finch.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -2,19 +2,19 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
using zero.Models; using Finch.Models;
namespace zero.Sqlite; namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations public partial class DbOperations : IDbOperations
{ {
/// <inheritdoc /> /// <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); => Delete<T>(model.Id);
/// <inheritdoc /> /// <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); T model = await Load<T>(id);
@@ -5,16 +5,16 @@ using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
using ServiceStack.OrmLite.Dapper; using ServiceStack.OrmLite.Dapper;
using zero.Extensions; using Finch.Extensions;
using zero.Models; using Finch.Models;
using zero.Utils; using Finch.Utils;
namespace zero.Sqlite; namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations public partial class DbOperations : IDbOperations
{ {
/// <inheritdoc /> /// <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()) if (id.IsNullOrWhiteSpace())
{ {
@@ -30,7 +30,7 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc /> /// <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(); ids = ids.Distinct().ToArray();
@@ -48,7 +48,7 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc /> /// <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(); ids = ids.Distinct().ToArray();
@@ -69,35 +69,35 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc /> /// <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)); return await Db.ExistsAsync(querySelector ?? (x => true));
} }
/// <inheritdoc /> /// <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)); return await Db.SelectAsync(querySelector ?? (x => true));
} }
/// <inheritdoc /> /// <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); return await Db.SingleAsync(querySelector);
} }
/// <inheritdoc /> /// <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>())); return await Db.SelectAsync(querySelector(Db.From<T>()));
} }
/// <inheritdoc /> /// <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); return await Db.SelectAsync<T>(x => true);
} }
@@ -5,28 +5,28 @@ using System.Threading.Tasks;
using FluentValidation.Results; using FluentValidation.Results;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
using zero.Models; using Finch.Models;
using zero.Extensions; using Finch.Extensions;
namespace zero.Sqlite; namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations public partial class DbOperations : IDbOperations
{ {
/// <inheritdoc /> /// <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 /> /// <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 /> /// <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); bool update = !model.Id.IsNullOrEmpty() && await Any<T>(x => x.Id == model.Id);
return await Save(model, validate, update); return await Save(model, validate, update);
} }
/// <inheritdoc /> /// <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) if (model == null)
{ {
@@ -84,9 +84,9 @@ public partial class DbOperations : IDbOperations
await Db.SaveAsync(model); await Db.SaveAsync(model);
string action = update ? "Updated" : "Created"; 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 else
{ {
@@ -100,7 +100,7 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc /> /// <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>(); List<T> items = await LoadAll<T>();
@@ -8,17 +8,17 @@ using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
using zero.Communication; using Finch.Communication;
using zero.Context; using Finch.Context;
using zero.Models; using Finch.Models;
using zero.Utils; using Finch.Utils;
using zero.Validation; using Finch.Validation;
namespace zero.Sqlite; namespace Finch.Sqlite;
public partial class DbOperations : IDbOperations public partial class DbOperations : IDbOperations
{ {
protected IZeroContext Context { get; private set; } protected IFinchContext Context { get; private set; }
protected FlavorOptions Flavors { get; private set; } protected FlavorOptions Flavors { get; private set; }
@@ -43,14 +43,14 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc /> /// <inheritdoc />
public bool EnsureTableExists<T>() where T : ZeroIdEntity public bool EnsureTableExists<T>() where T : FinchIdEntity
{ {
return Db.CreateTableIfNotExists<T>(); return Db.CreateTableIfNotExists<T>();
} }
/// <inheritdoc /> /// <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)); return Task.FromResult(IdGenerator.Create(12));
} }
@@ -64,35 +64,35 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc /> /// <inheritdoc />
public T PrepareForSave<T>(T model) where T : ZeroIdEntity public T PrepareForSave<T>(T model) where T : FinchIdEntity
{ {
// set IDs // set IDs
AutoSetIds(model); AutoSetIds(model);
if (model is not ZeroEntity zeroModel) if (model is not FinchEntity finchModel)
{ {
return model; return model;
} }
// set default properties // 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 // update name alias and last modified
zeroModel.Alias = Safenames.Alias(zeroModel.Name); finchModel.Alias = Safenames.Alias(finchModel.Name);
zeroModel.LastModifiedDate = DateTimeOffset.Now; finchModel.LastModifiedDate = DateTimeOffset.Now;
zeroModel.Hash ??= IdGenerator.Create(); finchModel.Hash ??= IdGenerator.Create();
return model; return model;
} }
/// <inheritdoc /> /// <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) if (validator == null)
{ {
@@ -104,10 +104,10 @@ public partial class DbOperations : IDbOperations
/// <inheritdoc /> /// <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; // 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> /// <summary>
/// Create a table if not existing /// Create a table if not existing
/// </summary> /// </summary>
bool EnsureTableExists<T>() where T : ZeroIdEntity; bool EnsureTableExists<T>() where T : FinchIdEntity;
/// <summary> /// <summary>
/// Generate model Id by using configured document store conventions /// Generate model Id by using configured document store conventions
/// </summary> /// </summary>
Task<string> GenerateId<T>(T model) where T : ZeroIdEntity; Task<string> GenerateId<T>(T model) where T : FinchIdEntity;
/// <summary> /// <summary>
/// Do only return the model when it is set to active or inactive entities are included with IncludeInactive() /// Do only return the model when it is set to active or inactive entities are included with IncludeInactive()
/// </summary> /// </summary>
T WhenActive<T>(T model) where T : ZeroIdEntity, new(); T WhenActive<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Validates an entity /// Validates an entity
/// </summary> /// </summary>
Task<ValidationResult> Validate<T>(T model) where T : ZeroIdEntity, new(); Task<ValidationResult> Validate<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Generate values for all properties (incl. nested) which contain the [GenerateId] attribute /// Generate values for all properties (incl. nested) which contain the [GenerateId] attribute
@@ -140,78 +140,78 @@ public interface IDbOperations
T AutoSetIds<T>(T model); T AutoSetIds<T>(T model);
/// <summary> /// <summary>
/// Automatically fill base properties of a ZeroEntity /// Automatically fill base properties of a FinchEntity
/// </summary> /// </summary>
T PrepareForSave<T>(T model) where T : ZeroIdEntity; T PrepareForSave<T>(T model) where T : FinchIdEntity;
/// <summary> /// <summary>
/// Get an entity by Id /// Get an entity by Id
/// </summary> /// </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> /// <summary>
/// Get entities by ids /// Get entities by ids
/// </summary> /// </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> /// <summary>
/// Get entities by ids /// Get entities by ids
/// </summary> /// </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> /// <summary>
/// Check if any items exist in this collection (with optional query) /// Check if any items exist in this collection (with optional query)
/// </summary> /// </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> /// <summary>
/// Get entities by query /// Get entities by query
/// </summary> /// </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> /// <summary>
/// Find entity by query /// Find entity by query
/// </summary> /// </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> /// <summary>
/// Get entities by sql query /// Get entities by sql query
/// </summary> /// </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> /// <summary>
/// Get all entities from this collection. /// Get all entities from this collection.
/// Warning: Don't use this method for large collections. Stream the results instead. /// Warning: Don't use this method for large collections. Stream the results instead.
/// </summary> /// </summary>
Task<List<T>> LoadAll<T>() where T : ZeroIdEntity, new(); Task<List<T>> LoadAll<T>() where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Creates an entity with an optional validator /// Creates an entity with an optional validator
/// </summary> /// </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> /// <summary>
/// Updates an entity with an optional validator /// Updates an entity with an optional validator
/// </summary> /// </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> /// <summary>
/// Checks if an entity exists (via ID) and creates or updates it afterwards accordingly /// Checks if an entity exists (via ID) and creates or updates it afterwards accordingly
/// </summary> /// </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> /// <summary>
/// Updates sorting of all items in a collection based on the given enumerable /// Updates sorting of all items in a collection based on the given enumerable
/// </summary> /// </summary>
Task Sort<T>(IEnumerable<string> ids) where T : ZeroEntity, new(); Task Sort<T>(IEnumerable<string> ids) where T : FinchEntity, new();
/// <summary> /// <summary>
/// Deletes an entity /// Deletes an entity
/// </summary> /// </summary>
Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new(); Task<Result<T>> Delete<T>(T model) where T : FinchIdEntity, new();
/// <summary> /// <summary>
/// Deletes an entity /// Deletes an entity
/// </summary> /// </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;
using System.Data; using System.Data;
namespace zero.Sqlite; namespace Finch.Sqlite;
public class SqliteOptions public class SqliteOptions
{ {
@@ -4,22 +4,22 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using ServiceStack.Data; using ServiceStack.Data;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
using zero.Configuration; using Finch.Configuration;
using zero.Models; using Finch.Models;
using zero.Modules; 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; return builder;
} }
} }
internal class ZeroSqliteModule : ZeroModule internal class FinchSqliteModule : FinchModule
{ {
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{ {
@@ -29,14 +29,14 @@ internal class ZeroSqliteModule : ZeroModule
services.AddScoped<StoreContext>(); services.AddScoped<StoreContext>();
services.AddScoped<IEntityModifiedHandler, EmptyEntityModifiedHandler>(); services.AddScoped<IEntityModifiedHandler, EmptyEntityModifiedHandler>();
services.AddOptions<FlavorOptions>(); services.AddOptions<FlavorOptions>();
services.AddOptions<SqliteOptions>().Bind(configuration.GetSection("Zero:Sqlite")); services.AddOptions<SqliteOptions>().Bind(configuration.GetSection("Finch:Sqlite"));
services.ConfigureOptions<ConfigureFlavorJsonOptions>(); services.ConfigureOptions<ConfigureFlavorJsonOptions>();
} }
protected IDbConnectionFactory CreateDbConnectionFactory(IServiceProvider services) protected IDbConnectionFactory CreateDbConnectionFactory(IServiceProvider services)
{ {
IZeroOptions options = services.GetService<IZeroOptions>(); IFinchOptions options = services.GetService<IFinchOptions>();
SqliteOptions sqliteOptions = options.For<SqliteOptions>(); SqliteOptions sqliteOptions = options.For<SqliteOptions>();
return new OrmLiteConnectionFactory(sqliteOptions.ConnectionString, SqliteDialect.Provider); return new OrmLiteConnectionFactory(sqliteOptions.ConnectionString, SqliteDialect.Provider);
} }
@@ -45,7 +45,7 @@ internal class ZeroSqliteModule : ZeroModule
protected IDbConnection CreateDbConnection(IServiceProvider services) protected IDbConnection CreateDbConnection(IServiceProvider services)
{ {
IDbConnectionFactory factory = services.GetService<IDbConnectionFactory>(); IDbConnectionFactory factory = services.GetService<IDbConnectionFactory>();
IZeroOptions options = services.GetService<IZeroOptions>(); IFinchOptions options = services.GetService<IFinchOptions>();
SqliteOptions sqliteOptions = options.For<SqliteOptions>(); SqliteOptions sqliteOptions = options.For<SqliteOptions>();
IDbConnection db = factory.CreateDbConnection(); IDbConnection db = factory.CreateDbConnection();
db.Open(); db.Open();
+3 -3
View File
@@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275 VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1 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 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -1,12 +1,12 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
namespace zero; namespace Finch;
public static class ApplicationBuilderExtensions 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(); app.UseOutputCache();
if (app is WebApplication webApplication) if (app is WebApplication webApplication)
@@ -15,7 +15,7 @@ public static class ApplicationBuilderExtensions
webApplication.MapControllers(); webApplication.MapControllers();
} }
ZeroBuilder.Modules.Configure(app, null, app.ApplicationServices); FinchBuilder.Modules.Configure(app, null, app.ApplicationServices);
return app; return app;
} }
} }
@@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
using System.Reflection; using System.Reflection;
namespace zero.Assemblies; namespace Finch.Assemblies;
public class AssemblyDiscovery : IAssemblyDiscovery public class AssemblyDiscovery : IAssemblyDiscovery
{ {
@@ -1,6 +1,6 @@
using System.Reflection; using System.Reflection;
namespace zero.Assemblies; namespace Finch.Assemblies;
public class AssemblyDiscoveryContext 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; using Microsoft.Extensions.DependencyModel;
namespace zero.Assemblies; namespace Finch.Assemblies;
public interface IAssemblyDiscoveryRule public interface IAssemblyDiscoveryRule
{ {
@@ -1,9 +1,9 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; 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) 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; using Microsoft.Extensions.DependencyInjection;
namespace zero.Communication; namespace Finch.Communication;
public class HandlerHolder : IHandlerHolder public class HandlerHolder : IHandlerHolder
{ {
@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace zero.Communication; namespace Finch.Communication;
public class LazilyResolved<T> : Lazy<T> public class LazilyResolved<T> : Lazy<T>
{ {
@@ -1,5 +1,5 @@
 
namespace zero.Communication; namespace Finch.Communication;
public interface IMessage public interface IMessage
{ {
@@ -1,4 +1,4 @@
namespace zero.Communication; namespace Finch.Communication;
/// <summary> /// <summary>
/// Indicates a handler that can perform an action when a message of /// Indicates a handler that can perform an action when a message of
@@ -1,7 +1,7 @@
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq.Expressions; using System.Linq.Expressions;
namespace zero.Communication; namespace Finch.Communication;
public class MessageAggregator : IMessageAggregator public class MessageAggregator : IMessageAggregator
{ {
@@ -2,7 +2,7 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
namespace zero.Communication; namespace Finch.Communication;
internal class MessageSubscription<TMessage, TMessageHandler> : IMessageSubscription internal class MessageSubscription<TMessage, TMessageHandler> : IMessageSubscription
where TMessage : class, IMessage where TMessage : class, IMessage
@@ -2,21 +2,21 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; 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 int Order => -1000;
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) 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.ServiceProvider = svc;
opts.Version = "1.0.0-alpha.1"; opts.Version = "1.0.0-alpha.1";
opts.TokenExpiration = TimeSpan.FromHours(3); 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 Microsoft.Extensions.Options;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace zero.Configuration; namespace Finch.Configuration;
public class ZeroOptions : IZeroOptions public class FinchOptions : IFinchOptions
{ {
/// <inheritdoc /> /// <inheritdoc />
public string Version { get; set; } public string Version { get; set; }
@@ -41,7 +41,7 @@ public class ZeroOptions : IZeroOptions
} }
public interface IZeroOptions public interface IFinchOptions
{ {
/// <summary> /// <summary>
/// The currently active version /// The currently active version
@@ -1,21 +1,21 @@
using Microsoft.Extensions.DependencyInjection; 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 IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; private set; } = new List<IAssemblyDiscoveryRule>();
public IMvcBuilder Mvc { get; private set; } public IMvcBuilder Mvc { get; private set; }
public ZeroStartupOptions(IMvcBuilder mvc) public FinchStartupOptions(IMvcBuilder mvc)
{ {
Mvc = mvc; Mvc = mvc;
} }
} }
public interface IZeroStartupOptions public interface IFinchStartupOptions
{ {
IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; } IList<IAssemblyDiscoveryRule> AssemblyDiscoveryRules { get; }
@@ -0,0 +1,6 @@
namespace Finch.Configuration;
public interface IFinchCollectionOptions
{
}
@@ -1,6 +1,6 @@
using FluentValidation; using FluentValidation;
namespace zero.Configuration; namespace Finch.Configuration;
public abstract class OptionsType public abstract class OptionsType
{ {
@@ -3,18 +3,18 @@ using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Security.Claims; using System.Security.Claims;
namespace zero.Context; namespace Finch.Context;
public class ZeroContext : IZeroContext public class FinchContext : IFinchContext
{ {
/// <inheritdoc /> /// <inheritdoc />
public IZeroOptions Options { get; protected set; } public IFinchOptions Options { get; protected set; }
/// <inheritdoc /> /// <inheritdoc />
public IServiceProvider Services { get; private set; } public IServiceProvider Services { get; private set; }
protected ICultureResolver CultureResolver { 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; } protected IHandlerHolder Handler { get; private set; }
@@ -26,8 +26,8 @@ public class ZeroContext : IZeroContext
bool _resolved = false; bool _resolved = false;
public ZeroContext(IZeroOptions options, IHttpContextAccessor httpContextAccessor, ICultureResolver cultureResolver, public FinchContext(IFinchOptions options, IHttpContextAccessor httpContextAccessor, ICultureResolver cultureResolver,
ILogger<ZeroContext> logger, IHandlerHolder handler, IServiceProvider services) ILogger<FinchContext> logger, IHandlerHolder handler, IServiceProvider services)
{ {
Options = options; Options = options;
CultureResolver = cultureResolver; CultureResolver = cultureResolver;
@@ -68,12 +68,12 @@ public class ZeroContext : IZeroContext
public interface IZeroContext public interface IFinchContext
{ {
/// <summary> /// <summary>
/// Global zero options /// Global finch options
/// </summary> /// </summary>
IZeroOptions Options { get; } IFinchOptions Options { get; }
/// <summary> /// <summary>
/// Service container /// 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.Configuration;
using Microsoft.Extensions.DependencyInjection; 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) public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{ {
services.AddScoped<IZeroContext, ZeroContext>(); services.AddScoped<IFinchContext, FinchContext>();
services.AddHttpContextAccessor(); services.AddHttpContextAccessor();
} }
} }
@@ -1,4 +1,4 @@
namespace zero.Extensions; namespace Finch.Extensions;
public static class CharExtensions public static class CharExtensions
{ {
@@ -1,6 +1,6 @@
using System.Drawing; using System.Drawing;
namespace zero.Extensions; namespace Finch.Extensions;
public static class ColorExtensions public static class ColorExtensions
{ {
@@ -1,4 +1,4 @@
namespace zero.Extensions; namespace Finch.Extensions;
public static class DictionaryExtensions public static class DictionaryExtensions
{ {
@@ -1,4 +1,4 @@
namespace zero.Extensions; namespace Finch.Extensions;
public static class EnumerableExtensions public static class EnumerableExtensions
{ {
@@ -9,7 +9,7 @@ public static class EnumerableExtensions
if (pageNumber <= 0 || pageSize <= 0) 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); return source.Skip((pageNumber - 1) * pageSize).Take(pageSize);
@@ -1,7 +1,7 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Text; using System.Text;
namespace zero.Extensions; namespace Finch.Extensions;
public static class ExpressionExtensions public static class ExpressionExtensions
{ {
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
namespace zero.Extensions; namespace Finch.Extensions;
public static class HttpContextExtensions public static class HttpContextExtensions
{ {
@@ -1,4 +1,4 @@
namespace zero.Extensions; namespace Finch.Extensions;
public static class NumberExtensions public static class NumberExtensions
{ {
@@ -1,6 +1,6 @@
//using Newtonsoft.Json; //using Newtonsoft.Json;
//namespace zero.Extensions; //namespace Finch.Extensions;
//[Obsolete("we don't want this for every object (use a Utils class instead)")] //[Obsolete("we don't want this for every object (use a Utils class instead)")]
//public static class ObjectExtensions //public static class ObjectExtensions
@@ -1,4 +1,4 @@
namespace zero.Extensions; namespace Finch.Extensions;
public static class ResultExtensions public static class ResultExtensions
{ {
@@ -31,7 +31,7 @@ public static class ResultExtensions
public static Result AddError(this Result origin, string message) public static Result AddError(this Result origin, string message)
{ {
origin.IsSuccess = false; origin.IsSuccess = false;
origin.Errors.Add(new("__zero_no_field", message)); origin.Errors.Add(new("__finch_no_field", message));
return origin; return origin;
} }
@@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using System.Reflection; using System.Reflection;
namespace zero.Extensions; namespace Finch.Extensions;
public static class ServiceCollectionExtensions public static class ServiceCollectionExtensions
{ {
@@ -19,7 +19,7 @@ public static class ServiceCollectionExtensions
{ {
if (AssemblyDiscovery.Current == null) 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 // add implementations with generic service types
@@ -4,7 +4,7 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Html;
namespace zero.Extensions; namespace Finch.Extensions;
public static class StringExtensions public static class StringExtensions
{ {
@@ -1,4 +1,4 @@
namespace zero.FileStorage; namespace Finch.FileStorage;
public class FileResult public class FileResult
{ {
@@ -1,4 +1,4 @@
namespace zero.FileStorage; namespace Finch.FileStorage;
public enum FileSizeNotation public enum FileSizeNotation
{ {
@@ -1,4 +1,4 @@
namespace zero.FileStorage; namespace Finch.FileStorage;
public class FileSystemException : Exception 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.DependencyInjection;
using Microsoft.Extensions.Options; 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) public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{ {
services.AddScoped<IPaths>(factory => new Paths(factory.GetService<IWebHostEnvironment>())); 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 => services.AddSingleton<IWebRootFileSystem, WebRootFileSystem>(svc =>
@@ -1,4 +1,4 @@
namespace zero.FileStorage; namespace Finch.FileStorage;
public interface IFileMeta public interface IFileMeta
{ {
@@ -1,6 +1,6 @@
using System.IO; using System.IO;
namespace zero.FileStorage; namespace Finch.FileStorage;
public interface IFileSystem public interface IFileSystem
{ {
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.StaticFiles;
using System.IO; using System.IO;
using System.Text; using System.Text;
namespace zero.FileStorage; namespace Finch.FileStorage;
public class Paths : IPaths public class Paths : IPaths
{ {
@@ -1,6 +1,6 @@
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
namespace zero.FileStorage; namespace Finch.FileStorage;
public class PhysicalFileMeta : IFileMeta public class PhysicalFileMeta : IFileMeta
{ {
@@ -1,7 +1,7 @@
using Microsoft.Extensions.FileProviders.Physical; using Microsoft.Extensions.FileProviders.Physical;
using System.IO; using System.IO;
namespace zero.FileStorage; namespace Finch.FileStorage;
public class PhysicalFileSystem : IFileSystem public class PhysicalFileSystem : IFileSystem
{ {
@@ -1,4 +1,4 @@
namespace zero.FileStorage; namespace Finch.FileStorage;
public class WebRootFileSystem : PhysicalFileSystem, IWebRootFileSystem public class WebRootFileSystem : PhysicalFileSystem, IWebRootFileSystem
{ {
+2 -2
View File
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<PackageId>zero</PackageId> <PackageId>Finch</PackageId>
<Version>1.0.0</Version> <Version>1.0.0</Version>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks> <TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<RootNamespace>zero</RootNamespace> <RootNamespace>Finch</RootNamespace>
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>
</PropertyGroup> </PropertyGroup>
+37 -37
View File
@@ -2,42 +2,42 @@
using Microsoft.AspNetCore.Antiforgery; using Microsoft.AspNetCore.Antiforgery;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using zero.Logging; using Finch.Logging;
using zero.Mails; using Finch.Mails;
using zero.Metadata; using Finch.Metadata;
using zero.Mvc; using Finch.Mvc;
using zero.Numbers; using Finch.Numbers;
using zero.Routing; using Finch.Routing;
using zero.Security; 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 // 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 IServiceCollection Services { get; }
public virtual IMvcBuilder Mvc { 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 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; Services = services;
Mvc = services.AddMvc(); Mvc = services.AddMvc();
_configuration = configuration; _configuration = configuration;
// create startup options // create startup options
_startupOptions = new ZeroStartupOptions(Mvc); _startupOptions = new FinchStartupOptions(Mvc);
_startupOptions.AssemblyDiscoveryRules.Add(new ZeroAssemblyDiscoveryRule()); _startupOptions.AssemblyDiscoveryRules.Add(new FinchAssemblyDiscoveryRule());
setupAction?.Invoke(_startupOptions); 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.AddDataProtection();.PersistKeysToRegistry()
services.AddControllers(); services.AddControllers();
@@ -46,30 +46,30 @@ public class ZeroBuilder
Mvc.AddDataAnnotationsLocalization(); 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 // adds and discovers additional and built-in assemblies
new AssemblyDiscovery(Mvc).Execute(_startupOptions.AssemblyDiscoveryRules); new AssemblyDiscovery(Mvc).Execute(_startupOptions.AssemblyDiscoveryRules);
Modules.Add<ZeroLoggingModule>(); Modules.Add<FinchLoggingModule>();
Modules.Add<ZeroCommunicationModule>(); Modules.Add<FinchCommunicationModule>();
Modules.Add<ZeroMvcModule>(); Modules.Add<FinchMvcModule>();
Modules.Add<ZeroConfigurationModule>(); Modules.Add<FinchConfigurationModule>();
Modules.Add<ZeroValidationModule>(); Modules.Add<FinchValidationModule>();
Modules.Add<ZeroContextModule>(); Modules.Add<FinchContextModule>();
Modules.Add<ZeroFileStorageModule>(); Modules.Add<FinchFileStorageModule>();
//Modules.Add<ZeroIdentityModule>(); //Modules.Add<FinchIdentityModule>();
Modules.Add<ZeroLocalizationModule>(); Modules.Add<FinchLocalizationModule>();
Modules.Add<ZeroMailModule>(); Modules.Add<FinchMailModule>();
//Modules.Add<ZeroMapperModule>(); //Modules.Add<FinchMapperModule>();
Modules.Add<ZeroMediaModule>(); Modules.Add<FinchMediaModule>();
//Modules.Add<ZeroPageModule>(); //Modules.Add<FinchPageModule>();
Modules.Add<ZeroRenderingModule>(); Modules.Add<FinchRenderingModule>();
Modules.Add<ZeroNumberModule>(); Modules.Add<FinchNumberModule>();
Modules.Add<ZeroRoutingModule>(); Modules.Add<FinchRoutingModule>();
Modules.Add<ZeroMetadataModule>(); Modules.Add<FinchMetadataModule>();
Modules.Add<ZeroSecurityModule>(); Modules.Add<FinchSecurityModule>();
Modules.ConfigureServices(services, configuration); Modules.ConfigureServices(services, configuration);
@@ -81,14 +81,14 @@ public class ZeroBuilder
/// <summary> /// <summary>
/// Use specified options /// Use specified options
/// </summary> /// </summary>
public ZeroBuilder WithOptions(Action<ZeroOptions> configureOptions) public FinchBuilder WithOptions(Action<FinchOptions> configureOptions)
{ {
Services.Configure(configureOptions); Services.Configure(configureOptions);
return this; return this;
} }
public ZeroBuilder AddModule(IZeroModule module) public FinchBuilder AddModule(IFinchModule module)
{ {
module.ConfigureServices(Services, _configuration); module.ConfigureServices(Services, _configuration);
Modules.Add(module); 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(); T module = new();
module.ConfigureServices(Services, _configuration); module.ConfigureServices(Services, _configuration);
@@ -3,14 +3,14 @@
using ViteProxy; using ViteProxy;
#endif #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 #if DEBUG
builder.Services.AddViteProxy("Zero:Vite"); builder.Services.AddViteProxy("Finch:Vite");
#endif #endif
return builder; return builder;
} }
@@ -27,7 +27,7 @@ public static class ViteProxyApplicationBuilderExtensions
} }
} }
// internal class ZeroViteModule : ZeroModule // internal class FinchViteModule : FinchModule
// { // {
// public override int ConfigureOrder { get; } = -1; // public override int ConfigureOrder { get; } = -1;
// //
@@ -6,10 +6,10 @@ using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace zero.Frontend; namespace Finch.Frontend;
[HtmlTargetElement("app-vitescript", Attributes = "src", TagStructure = TagStructure.NormalOrSelfClosing)] [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] [HtmlAttributeNotBound]
[ViewContext] [ViewContext]
@@ -1,13 +1,13 @@
namespace zero.Identity; namespace Finch.Identity;
/// <summary> /// <summary>
/// Represents all the options you can use to configure the cookies middleware used by the identity system. /// Represents all the options you can use to configure the cookies middleware used by the identity system.
/// </summary> /// </summary>
public class ZeroIdentityConstants public class FinchIdentityConstants
{ {
public static class CookieNames 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 Application = CookiePrefix + ".app";
public static readonly string External = CookiePrefix + ".ext"; public static readonly string External = CookiePrefix + ".ext";
@@ -17,9 +17,9 @@ public class ZeroIdentityConstants
public static partial class Claims 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 UserId = ClaimPrefix + ".userid";
public static readonly string Username = ClaimPrefix + ".username"; public static readonly string Username = ClaimPrefix + ".username";
public static readonly string Name = ClaimPrefix + ".name"; public static readonly string Name = ClaimPrefix + ".name";
@@ -4,9 +4,9 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
namespace zero.Identity; namespace Finch.Identity;
public static class ZeroIdentityExtensions public static class FinchIdentityExtensions
{ {
// <summary> // <summary>
/// Adds the default identity system configuration for the specified User and Role types. /// 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> /// <typeparam name="TRole">The type representing a Role in the system.</typeparam>
/// <param name="services">The services available in the application.</param> /// <param name="services">The services available in the application.</param>
/// <returns>An <see cref="IdentityBuilder"/> for creating and configuring the identity system.</returns> /// <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)
where TUser : ZeroIdentityUser, new() where TUser : FinchIdentityUser, new()
where TRole : ZeroIdentityRole, new() => where TRole : FinchIdentityRole, new() =>
AddZeroIdentity<TUser, TRole>(services, null); AddFinchIdentity<TUser, TRole>(services, null);
/// <summary> /// <summary>
@@ -29,10 +29,10 @@ public static class ZeroIdentityExtensions
/// <param name="services">The services available in the application.</param> /// <param name="services">The services available in the application.</param>
/// <param name="setupAction">An action to configure the <see cref="IdentityOptions"/>.</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> /// <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) Action<IdentityOptions> setupAction)
where TUser : ZeroIdentityUser, new() where TUser : FinchIdentityUser, new()
where TRole : ZeroIdentityRole, new() where TRole : FinchIdentityRole, new()
{ {
// Services identity depends on // Services identity depends on
services services
@@ -53,7 +53,7 @@ public static class ZeroIdentityExtensions
o.SlidingExpiration = true; o.SlidingExpiration = true;
o.ExpireTimeSpan = TimeSpan.FromDays(90); o.ExpireTimeSpan = TimeSpan.FromDays(90);
o.Cookie.Name = ZeroIdentityConstants.CookieNames.Application; o.Cookie.Name = FinchIdentityConstants.CookieNames.Application;
o.Cookie.HttpOnly = true; o.Cookie.HttpOnly = true;
o.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest; o.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
o.Cookie.SameSite = SameSiteMode.Lax; o.Cookie.SameSite = SameSiteMode.Lax;
@@ -66,12 +66,12 @@ public static class ZeroIdentityExtensions
}) })
.AddCookie(IdentityConstants.ExternalScheme, o => .AddCookie(IdentityConstants.ExternalScheme, o =>
{ {
o.Cookie.Name = ZeroIdentityConstants.CookieNames.External; o.Cookie.Name = FinchIdentityConstants.CookieNames.External;
o.ExpireTimeSpan = TimeSpan.FromMinutes(5); o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
}) })
.AddCookie(IdentityConstants.TwoFactorRememberMeScheme, o => .AddCookie(IdentityConstants.TwoFactorRememberMeScheme, o =>
{ {
o.Cookie.Name = ZeroIdentityConstants.CookieNames.TwoFactorRememberMe; o.Cookie.Name = FinchIdentityConstants.CookieNames.TwoFactorRememberMe;
o.Events = new CookieAuthenticationEvents o.Events = new CookieAuthenticationEvents
{ {
OnValidatePrincipal = SecurityStampValidator.ValidateAsync<ITwoFactorSecurityStampValidator> OnValidatePrincipal = SecurityStampValidator.ValidateAsync<ITwoFactorSecurityStampValidator>
@@ -79,7 +79,7 @@ public static class ZeroIdentityExtensions
}) })
.AddCookie(IdentityConstants.TwoFactorUserIdScheme, o => .AddCookie(IdentityConstants.TwoFactorUserIdScheme, o =>
{ {
o.Cookie.Name = ZeroIdentityConstants.CookieNames.TwoFactorUserId; o.Cookie.Name = FinchIdentityConstants.CookieNames.TwoFactorUserId;
o.ExpireTimeSpan = TimeSpan.FromMinutes(5); o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
}); });
@@ -105,11 +105,11 @@ public static class ZeroIdentityExtensions
services.Configure<IdentityOptions>(opts => services.Configure<IdentityOptions>(opts =>
{ {
opts.ClaimsIdentity.UserIdClaimType = ZeroIdentityConstants.Claims.UserId; opts.ClaimsIdentity.UserIdClaimType = FinchIdentityConstants.Claims.UserId;
opts.ClaimsIdentity.UserNameClaimType = ZeroIdentityConstants.Claims.Username; opts.ClaimsIdentity.UserNameClaimType = FinchIdentityConstants.Claims.Username;
opts.ClaimsIdentity.RoleClaimType = ZeroIdentityConstants.Claims.Role; opts.ClaimsIdentity.RoleClaimType = FinchIdentityConstants.Claims.Role;
opts.ClaimsIdentity.SecurityStampClaimType = ZeroIdentityConstants.Claims.SecurityStamp; opts.ClaimsIdentity.SecurityStampClaimType = FinchIdentityConstants.Claims.SecurityStamp;
opts.ClaimsIdentity.EmailClaimType = ZeroIdentityConstants.Claims.Email; opts.ClaimsIdentity.EmailClaimType = FinchIdentityConstants.Claims.Email;
opts.Password.RequireDigit = false; opts.Password.RequireDigit = false;
opts.Password.RequireLowercase = false; opts.Password.RequireLowercase = false;
@@ -135,7 +135,7 @@ public static class ZeroIdentityExtensions
IdentityBuilder builder = new(typeof(TUser), typeof(TRole), services); IdentityBuilder builder = new(typeof(TUser), typeof(TRole), services);
builder.AddDefaultTokenProviders(); builder.AddDefaultTokenProviders();
builder.AddZeroIdentityStores(); builder.AddFinchIdentityStores();
return builder; return builder;
} }
@@ -147,7 +147,7 @@ public static class ZeroIdentityExtensions
/// <param name="services">The services available in the application.</param> /// <param name="services">The services available in the application.</param>
/// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param> /// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>The services.</returns> /// <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); => services.Configure(IdentityConstants.ApplicationScheme, configure);
/// <summary> /// <summary>
@@ -156,6 +156,6 @@ public static class ZeroIdentityExtensions
/// <param name="services">The services available in the application.</param> /// <param name="services">The services available in the application.</param>
/// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param> /// <param name="configure">An action to configure the <see cref="CookieAuthenticationOptions"/>.</param>
/// <returns>The services.</returns> /// <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); => services.Configure(IdentityConstants.ExternalScheme, configure);
} }
@@ -1,18 +1,18 @@
using System.Linq.Expressions; 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 Microsoft.AspNetCore.Identity;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNetCore.Mvc.ApplicationModels; 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>, IRoleStore<TRole>,
IRoleClaimStore<TRole> IRoleClaimStore<TRole>
where TRole : ZeroIdentityRole, new() where TRole : FinchIdentityRole, new()
{ {
protected IdentityErrorDescriber ErrorDescriber { get; private set; } 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; Db = db;
ErrorDescriber = describer ?? new IdentityErrorDescriber(); ErrorDescriber = describer ?? new IdentityErrorDescriber();
@@ -30,7 +30,7 @@ public class ZeroRoleStore<TRole> :
foreach (ResultError error in result.Errors) foreach (ResultError error in result.Errors)
{ {
string message = error.Message + "(key: " + error.Property + ")"; 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); return IdentityResult.Failed(errors);
@@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using System.Security.Claims; using System.Security.Claims;
namespace zero.Identity; namespace Finch.Identity;
public partial class ZeroUserStore<TUser> : public partial class FinchUserStore<TUser> :
IUserStore<TUser>, IUserStore<TUser>,
IUserEmailStore<TUser>, IUserEmailStore<TUser>,
IUserLockoutStore<TUser>, IUserLockoutStore<TUser>,
@@ -17,9 +17,9 @@ public partial class ZeroUserStore<TUser> :
IUserTwoFactorStore<TUser>, IUserTwoFactorStore<TUser>,
IUserTwoFactorRecoveryCodeStore<TUser>, IUserTwoFactorRecoveryCodeStore<TUser>,
IUserPhoneNumberStore<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; Db = db;
ErrorDescriber = describer ?? new IdentityErrorDescriber(); ErrorDescriber = describer ?? new IdentityErrorDescriber();
@@ -29,7 +29,7 @@ public partial class ZeroUserStore<TUser> :
protected IdentityErrorDescriber ErrorDescriber { get; private set; } protected IdentityErrorDescriber ErrorDescriber { get; private set; }
protected virtual IZeroIdentityStoreDbProvider Db { get; set; } protected virtual IFinchIdentityStoreDbProvider Db { get; set; }
private IdentityResult Fail(Result<TUser> result) private IdentityResult Fail(Result<TUser> result)
{ {
@@ -39,7 +39,7 @@ public partial class ZeroUserStore<TUser> :
foreach (ResultError error in result.Errors) foreach (ResultError error in result.Errors)
{ {
string message = error.Message + "(key: " + error.Property + ")"; 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); return IdentityResult.Failed(errors);
@@ -1,14 +1,14 @@
using Microsoft.AspNetCore.Identity; 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> IUserRoleStore<TUser>
where TUser : ZeroIdentityUser, new() where TUser : FinchIdentityUser, new()
where TRole : ZeroIdentityRole, new() where TRole : FinchIdentityRole, new()
{ {
public ZeroUserStore(IZeroIdentityStoreDbProvider db) : base(db) { } public FinchUserStore(IFinchIdentityStoreDbProvider db) : base(db) { }
/// <inheritdoc /> /// <inheritdoc />

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