FileDatabase Refactor and normalization
Test cleanup
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
namespace DeepDrftContent.FileDatabase.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a key for entries in the file database system.
|
||||
/// Combines a string key with a media vault type for type-safe operations.
|
||||
/// </summary>
|
||||
/// <param name="Key">The string identifier for the entry</param>
|
||||
/// <param name="Type">The media vault type this entry belongs to</param>
|
||||
public record EntryKey(string Key, MediaVaultType Type);
|
||||
@@ -17,9 +17,9 @@ public interface IIndex
|
||||
public interface IEntryQueryable : IIndex
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all entry keys in this index
|
||||
/// Gets all entry IDs in this index
|
||||
/// </summary>
|
||||
IReadOnlyList<EntryKey> GetEntries();
|
||||
IReadOnlyList<string> GetEntries();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of entries in this index
|
||||
@@ -27,9 +27,9 @@ public interface IEntryQueryable : IIndex
|
||||
int GetEntriesSize();
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the index contains the specified entry key
|
||||
/// Checks if the index contains the specified entry ID
|
||||
/// </summary>
|
||||
bool HasEntry(EntryKey entryKey);
|
||||
bool HasEntry(string entryId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,7 +40,7 @@ public interface IDirectoryIndex : IEntryQueryable
|
||||
/// <summary>
|
||||
/// Adds an entry to the directory index
|
||||
/// </summary>
|
||||
void PutEntry(EntryKey entryKey);
|
||||
void PutEntry(string entryId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,10 +51,10 @@ public interface IVaultIndex : IEntryQueryable
|
||||
/// <summary>
|
||||
/// Gets metadata for a specific entry
|
||||
/// </summary>
|
||||
MetaData? GetEntry(EntryKey entryKey);
|
||||
MetaData? GetEntry(string entryId);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an entry with metadata to the vault index
|
||||
/// </summary>
|
||||
void PutEntry(EntryKey entryKey, MetaData metaData);
|
||||
void PutEntry(string entryId, MetaData metaData);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using DeepDrftContent.FileDatabase.Utils;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DeepDrftContent.FileDatabase.Models;
|
||||
|
||||
@@ -20,7 +21,7 @@ public abstract class IndexData
|
||||
/// </summary>
|
||||
public class DirectoryIndexData : IndexData
|
||||
{
|
||||
public List<EntryKey> Entries { get; set; } = new();
|
||||
public List<string> Entries { get; set; } = new();
|
||||
|
||||
public DirectoryIndexData(string indexKey) : base(indexKey) { }
|
||||
|
||||
@@ -39,7 +40,7 @@ public class DirectoryIndexData : IndexData
|
||||
/// </summary>
|
||||
public class VaultEntryData
|
||||
{
|
||||
public EntryKey Key { get; set; } = null!;
|
||||
public string Key { get; set; } = null!;
|
||||
public MetaData Value { get; set; } = null!;
|
||||
}
|
||||
|
||||
@@ -49,12 +50,22 @@ public class VaultEntryData
|
||||
public class VaultIndexData : IndexData
|
||||
{
|
||||
public List<VaultEntryData> Entries { get; set; } = new();
|
||||
public MediaVaultType VaultType { get; set; }
|
||||
|
||||
public VaultIndexData(string indexKey) : base(indexKey) { }
|
||||
public VaultIndexData(string indexKey) : base(indexKey)
|
||||
{
|
||||
VaultType = MediaVaultType.Media; // Default vault type for legacy compatibility
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public VaultIndexData(string indexKey, MediaVaultType vaultType) : base(indexKey)
|
||||
{
|
||||
VaultType = vaultType;
|
||||
}
|
||||
|
||||
public static VaultIndexData FromIndex(VaultIndex index)
|
||||
{
|
||||
var data = new VaultIndexData(index.GetKey())
|
||||
var data = new VaultIndexData(index.GetKey(), index.VaultType)
|
||||
{
|
||||
Entries = index.Entries.Select(kvp => new VaultEntryData { Key = kvp.Key, Value = kvp.Value }).ToList()
|
||||
};
|
||||
@@ -67,11 +78,11 @@ public class VaultIndexData : IndexData
|
||||
/// </summary>
|
||||
public class DirectoryIndex : IndexData, IDirectoryIndex
|
||||
{
|
||||
public StructuralSet<EntryKey> Entries { get; }
|
||||
public StructuralSet<string> Entries { get; }
|
||||
|
||||
public DirectoryIndex(DirectoryIndexData indexData) : base(indexData.IndexKey)
|
||||
{
|
||||
Entries = new StructuralSet<EntryKey>();
|
||||
Entries = new StructuralSet<string>();
|
||||
// Load entries from data
|
||||
foreach (var entry in indexData.Entries)
|
||||
{
|
||||
@@ -81,13 +92,13 @@ public class DirectoryIndex : IndexData, IDirectoryIndex
|
||||
|
||||
public string GetKey() => IndexKey;
|
||||
|
||||
public IReadOnlyList<EntryKey> GetEntries() => Entries.ToList().AsReadOnly();
|
||||
public IReadOnlyList<string> GetEntries() => Entries.ToList().AsReadOnly();
|
||||
|
||||
public int GetEntriesSize() => Entries.Size;
|
||||
|
||||
public bool HasEntry(EntryKey entryKey) => Entries.Has(entryKey);
|
||||
public bool HasEntry(string entryId) => Entries.Has(entryId);
|
||||
|
||||
public void PutEntry(EntryKey entryKey) => Entries.Add(entryKey);
|
||||
public void PutEntry(string entryId) => Entries.Add(entryId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,11 +106,13 @@ public class DirectoryIndex : IndexData, IDirectoryIndex
|
||||
/// </summary>
|
||||
public class VaultIndex : IndexData, IVaultIndex
|
||||
{
|
||||
public StructuralMap<EntryKey, MetaData> Entries { get; }
|
||||
public StructuralMap<string, MetaData> Entries { get; }
|
||||
public MediaVaultType VaultType { get; }
|
||||
|
||||
public VaultIndex(VaultIndexData indexData) : base(indexData.IndexKey)
|
||||
{
|
||||
Entries = new StructuralMap<EntryKey, MetaData>();
|
||||
Entries = new StructuralMap<string, MetaData>();
|
||||
VaultType = indexData.VaultType;
|
||||
// Load entries from data
|
||||
foreach (var entry in indexData.Entries)
|
||||
{
|
||||
@@ -109,13 +122,13 @@ public class VaultIndex : IndexData, IVaultIndex
|
||||
|
||||
public string GetKey() => IndexKey;
|
||||
|
||||
public IReadOnlyList<EntryKey> GetEntries() => Entries.Keys.ToList().AsReadOnly();
|
||||
public IReadOnlyList<string> GetEntries() => Entries.Keys.ToList().AsReadOnly();
|
||||
|
||||
public int GetEntriesSize() => Entries.Size;
|
||||
|
||||
public bool HasEntry(EntryKey entryKey) => Entries.Has(entryKey);
|
||||
public bool HasEntry(string entryId) => Entries.Has(entryId);
|
||||
|
||||
public MetaData? GetEntry(EntryKey entryKey) => Entries.Get(entryKey);
|
||||
public MetaData? GetEntry(string entryId) => Entries.Get(entryId);
|
||||
|
||||
public void PutEntry(EntryKey entryKey, MetaData metaData) => Entries.Set(entryKey, metaData);
|
||||
public void PutEntry(string entryId, MetaData metaData) => Entries.Set(entryId, metaData);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,16 @@ public static class MediaVaultTypeMap
|
||||
public static Type GetParamsType(MediaVaultType vaultType) => _registry.GetParamsType(vaultType);
|
||||
|
||||
public static Type GetMetaDataType(MediaVaultType vaultType) => _registry.GetMetaDataType(vaultType);
|
||||
|
||||
/// <summary>
|
||||
/// Get the vault type for a binary type (reverse mapping)
|
||||
/// </summary>
|
||||
public static MediaVaultType GetVaultType(Type binaryType) => _registry.GetVaultType(binaryType);
|
||||
|
||||
/// <summary>
|
||||
/// Get the vault type for a binary type using generics (reverse mapping)
|
||||
/// </summary>
|
||||
public static MediaVaultType GetVaultType<T>() where T : FileBinary => _registry.GetVaultType<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user