Skip to content

Commit

Permalink
Merge pull request #6 from calebjenkins/dev/feature-07-meta-objects
Browse files Browse the repository at this point in the history
Update Dev WorkFlow - 1 push for 3 packages
  • Loading branch information
calebjenkins committed Jan 3, 2024
2 parents dcfea2b + dfcc151 commit 6490317
Show file tree
Hide file tree
Showing 22 changed files with 439 additions and 106 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ jobs:
if: ${{ steps.detect_develop.outcome == 'failure' }}

- name: Pack
run: dotnet pack --configuration Release /p:Version=${{steps.get_version.outputs.RELEASE_VERSION}}-ci-${GITHUB_RUN_NUMBER} --include-symbols --output .
#run: dotnet pack --configuration Release /p:Version=${{steps.get_version.outputs.RELEASE_VERSION}}-ci-${GITHUB_RUN_NUMBER} --include-symbols --output .
run: dotnet pack --configuration Release -p:Version=${{steps.get_version.outputs.RELEASE_VERSION}}-ci-${GITHUB_RUN_NUMBER} --include-symbols --output .
if: ${{ steps.detect_develop.outcome == 'success' }}


- name: Push to Nuget
# if: ${{ steps.detect_develop.outcome == 'success' }}
if: ${{ github.ref == 'refs/heads/develop' }}
# run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.FAKEAUTH_NUGET_KEY}}
run: dotnet nuget push Calebs.KeyValueRepo.${{steps.get_version.outputs.RELEASE_VERSION}}-ci-${GITHUB_RUN_NUMBER}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_KEY}}



# run: dotnet nuget push Calebs.KeyValueRepo.${{steps.get_version.outputs.RELEASE_VERSION}}-ci-${GITHUB_RUN_NUMBER}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_KEY}}
run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_KEY}}
6 changes: 6 additions & 0 deletions KeyValueRepo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KeyValueRepoTests", "src\Ke
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KeyValueRepo.Benchmarks", "src\KeyValueRepo.Benchmarks\KeyValueRepo.Benchmarks.csproj", "{AC234450-6779-4916-92E6-DF39459273A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyValueSqlLiteRepoTests", "src\KeyValueSqlLiteRepoTests\KeyValueSqlLiteRepoTests.csproj", "{109EDB5F-5B9A-4FE8-AFFE-96713BC4E15F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -58,6 +60,10 @@ Global
{AC234450-6779-4916-92E6-DF39459273A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC234450-6779-4916-92E6-DF39459273A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC234450-6779-4916-92E6-DF39459273A3}.Release|Any CPU.Build.0 = Release|Any CPU
{109EDB5F-5B9A-4FE8-AFFE-96713BC4E15F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{109EDB5F-5B9A-4FE8-AFFE-96713BC4E15F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{109EDB5F-5B9A-4FE8-AFFE-96713BC4E15F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{109EDB5F-5B9A-4FE8-AFFE-96713BC4E15F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ The package `version` is defined in the `KeyValueRepo.csproj` file, using .NET S
- ✔ SQLite [Nuget Package](https://www.nuget.org/packages/Calebs.KeyValueRepo.SQLite/)
### Future Goals
---
- New Feature: KV Meta Objects
- In Progress: 0.3.0 - New Feature: KV Meta Objects
- In Progress: Seperate and publish base unit tests
- Considering: 0.4.0 - New Feature: Remove / RemoveAll methods
- New Repo: Azure Tables Implementation
- New Repo: Sql Server Implementation
- New Repo: Azure Tables Implementation
- New Repo: Azure CosmoDB Implementation
1 change: 0 additions & 1 deletion src/KeyValueRepo.Benchmarks/KeyValueRepo.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KeyValueRepo\KeyValueRepo.csproj" />
<ProjectReference Include="..\KeyValueSqlLiteRepo\KeyValueSqlLiteRepo.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/KeyValueRepo.Benchmarks/SQLiteBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task CleanUp()
{
var pathToFile = Repo?.AsKeyValueSqlLiteRepo().DatabaseFileName;

if (pathToFile.IsNotNullOrEmpty())
if (pathToFile.IsNotNullOrEmpty() && Repo != null)
{
await Repo.AsKeyValueSqlLiteRepo().ReleaseForCleanUp();
File.Delete(pathToFile.ValueOrEmpty());
Expand Down
11 changes: 5 additions & 6 deletions src/KeyValueRepo/IKeyValueRepo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Calebs.Data.KeyValueRepo;


public interface IKeyValueRepo
{
Task Update<T>(string key, T value) where T : class;
Task<T?> Get<T>(string key) where T : class;
Task<T?> Get<T>(int key) where T : class => Get<T>(key.ToString());
Task<IList<T>> GetAll<T>() where T : class;

Task Update<T>(string key, T value) where T : class;
Task Update<T>(int key, T value) where T : class => Update<T>(key.ToString(), value);
Task<MetaObject<T>?> GetMeta<T>(string key) where T : class;
Task<IList<MetaObject<T>>> GetHistory<T>(string key) where T : class;
Task<IList<MetaObject<T>>> GetMetaAll<T>() where T : class;
}
98 changes: 89 additions & 9 deletions src/KeyValueRepo/KeyValueInMemory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace Calebs.Data.KeyValueRepo;


public class KeyValueInMemory : IKeyValueRepo
{
// Note a lot of "await Task.Run(".. etc in here, since this is InMemory, Tasks/Await not really needed, but the interface is designed for networked databases where that is generally preffered.
Expand All @@ -14,11 +13,10 @@ public class KeyValueInMemory : IKeyValueRepo
{
if(_data[typeKey].ContainsKey(key))
{
T? data = _data[typeKey][key].FromJson<T>();
var data = _data[typeKey][key].FromJson<MetaObject<T>>()?.Value;
return await Task.FromResult<T?>(data);
}
}

return null;
}

Expand All @@ -34,24 +32,100 @@ public class KeyValueInMemory : IKeyValueRepo
{
if (_data[typeKey].ContainsKey(key))
{
T? data = _data[typeKey][key].FromJson<T>();
list.Add(data);
var data = _data[typeKey][key].FromJson<MetaObject<T>>().Value;
if (data != null)
{
list.Add(data);
}
}
}
}

return await Task.FromResult<IList<T>>(list);
}

public async Task<IList<MetaObject<T>>> GetMetaAll<T>() where T : class
{
string typeKey = typeof(T).ToString();
List<MetaObject<T>> list = new List<MetaObject<T>>();

if (_data.ContainsKey(typeKey))
{
var keys = _data[typeKey].Keys;
foreach (var key in keys)
{
if (_data[typeKey].ContainsKey(key))
{
var data = _data[typeKey][key].FromJson<MetaObject<T>>();
if (data != null)
{
list.Add(data);
}
}
}
}

return await Task.FromResult<IList<MetaObject<T>>>(list);
}

public async Task<IList<MetaObject<T>>> GetHistory<T>(string key) where T : class
{
string typeKey = typeof(T).ToString();

var list = new List<MetaObject<T>>();

if (_data.ContainsKey(typeKey))
{
var keys = _data[typeKey].Keys;
foreach (var k in keys)
{
if (_data[typeKey].ContainsKey(k))
{
var data = _data[typeKey][k].FromJson<MetaObject<T>>();
list.Add(data);
}
}
}

return await Task.FromResult<IList<MetaObject<T>>>(list);
}

public async Task<MetaObject<T>?> GetMeta<T>(string key) where T : class
{
string typeKey = typeof(T).ToString();

if (_data.ContainsKey(typeKey))
{
if (_data[typeKey].ContainsKey(key))
{
var data = _data[typeKey][key].FromJson<MetaObject<T>>();
return await Task.FromResult(data);
}
}
return null;
}

public async Task Update<T>(string key, T value) where T : class
{
var ident = Thread.CurrentPrincipal?.Identity?.Name ?? "";
var now = DateTime.Now;

string typeKey = typeof(T).ToString();
var mo = new MetaObject<T>()
{
Value = value,
CreatedBy = ident,
CreatedOn = now,
UpdatedBy = ident,
UpdatedOn = now
};

// Create type dictionary if does now exist
if (!_data.ContainsKey(typeKey))
{
var newDict = new Dictionary<string, string>();
newDict.Add(key, value.ToJson());
//newDict.Add(key, value.ToJson());
newDict.Add(key, mo.ToJson());

await Task.Run(() =>
{
Expand All @@ -64,14 +138,20 @@ public class KeyValueInMemory : IKeyValueRepo
{
await Task.Run(() =>
{
_data[typeKey].Add(key, value.ToJson());
// _data[typeKey].Add(key, value.ToJson());
_data[typeKey].Add(key, mo.ToJson());
});
}
else
{
await Task.Run(() =>
{
_data[typeKey][key] = value.ToJson();
var existingData = _data[typeKey][key].FromJson<MetaObject<T>>();
existingData.CreatedBy = mo.CreatedBy;
existingData.CreatedOn = mo.CreatedOn;
existingData.Value = mo.Value;
_data[typeKey][key] = existingData.ToJson();
});
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/KeyValueRepo/KeyValueRepo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<RootNamespace>Calebs.Data.KeyValueRepo</RootNamespace>
<AssemblyName>Calebs.KeyValueRepo</AssemblyName>
<Version>0.2.0</Version>
<Version>0.3.0</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Caleb Jenkins</Authors>
<Company>Caleb Jenkins</Company>
Expand All @@ -23,13 +23,12 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageId>Calebs.KeyValueRepo</PackageId>
<PackageIcon>KeyValueRepoLogo.png</PackageIcon>
<PackageIconUrl />
<Product>Calebs.KeyValueRepo</Product>
<Title>KeyValueRepo</Title>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Calebs.Extensions" Version="1.5.0-ci-62" />
<PackageReference Include="Calebs.Extensions" Version="1.5.0" />
<None Include="..\..\assets\logo\KeyValueRepoLogo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
Expand Down
9 changes: 9 additions & 0 deletions src/KeyValueRepo/KeyValueRepoExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Calebs.Data.KeyValueRepo;

public static class KeyValueRepoExtensions
{
public static Task<MetaObject<T>?> GetMeta<T>(this IKeyValueRepo repo, int key) where T : class => repo.GetMeta<T>(key.ToString());
public static Task<T?> Get<T>(this IKeyValueRepo repo, int key) where T : class => repo.Get<T>(key.ToString());
public static Task<IList<MetaObject<T>>?> GetHistory<T>(this IKeyValueRepo repo, int key) where T : class => repo.GetHistory<T>(key.ToString());

Check warning on line 7 in src/KeyValueRepo/KeyValueRepoExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in value of type 'Task<IList<MetaObject<T>>>' doesn't match target type 'Task<IList<MetaObject<T>>?>'.

Check warning on line 7 in src/KeyValueRepo/KeyValueRepoExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in value of type 'Task<IList<MetaObject<T>>>' doesn't match target type 'Task<IList<MetaObject<T>>?>'.
public static Task Update<T>(this IKeyValueRepo repo, int key, T value) where T : class => repo.Update<T>(key.ToString(), value);
}
9 changes: 9 additions & 0 deletions src/KeyValueRepo/MetaObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

public class MetaObject<T> where T : class
{
public string? CreatedBy { get; set; }
public DateTime CreatedOn { get; set; }
public string? UpdatedBy { get; init; }
public DateTime UpdatedOn { get; init; }
public T? Value { get; set; }
}
3 changes: 2 additions & 1 deletion src/KeyValueRepo/Usings.cs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
global using Calebs.Extensions;
global using Calebs.Extensions;
global using System.Security.Claims;

0 comments on commit 6490317

Please sign in to comment.