Index C# document catalogs by schema id

This commit is contained in:
Meta Vens 2026-06-27 22:16:26 +01:00
commit 26159f9cfa
2 changed files with 10 additions and 2 deletions

View file

@ -892,6 +892,9 @@ namespace GameCult.Mesh
/// <summary>Gets the stable CultCache schema version.</summary>
string SchemaVersion { get; }
/// <summary>Gets the content-derived schema identifier.</summary>
string SchemaId { get; }
/// <summary>Gets the preferred or observed route for document access.</summary>
CultMeshRouteHint RouteHint { get; }
@ -1577,6 +1580,8 @@ namespace GameCult.Mesh
foreach (var document in documentList)
{
byType[document.DocumentType] = document;
if (!string.IsNullOrWhiteSpace(document.SchemaId))
bySchema[document.SchemaId] = document;
if (!string.IsNullOrWhiteSpace(document.SchemaVersion))
bySchema[document.SchemaVersion] = document;
if (!string.IsNullOrWhiteSpace(document.SchemaName))
@ -1591,7 +1596,7 @@ namespace GameCult.Mesh
/// <summary>Gets the handles in this catalog.</summary>
public IReadOnlyList<ICultMeshDocumentHandle> Documents => _documents;
/// <summary>Looks up a document handle by shared schema name or schema version.</summary>
/// <summary>Looks up a document handle by schema id, shared schema name, or schema version.</summary>
public bool TryGetDocumentBySchema(
string schema,
out ICultMeshDocumentHandle document)
@ -1606,7 +1611,7 @@ namespace GameCult.Mesh
return false;
}
/// <summary>Looks up a document handle by shared schema name or schema version.</summary>
/// <summary>Looks up a document handle by schema id, shared schema name, or schema version.</summary>
public ICultMeshDocumentHandle DocumentBySchema(string schema)
{
if (TryGetDocumentBySchema(schema, out var document))

View file

@ -724,6 +724,9 @@ public sealed class CultMeshStreamingTests
catalog.TryGetDocumentBySchema("tests.mesh_note.v1", out var byVersion).Should().BeTrue();
byVersion.Should().BeSameAs(handle);
catalog.DocumentBySchema("tests.mesh_note").Should().BeSameAs(handle);
catalog.DocumentBySchema(CultDocumentRegistry.Shared.GetRequired<MeshNoteDocument>().SchemaId)
.Should()
.BeSameAs(handle);
catalog.TryGetDocument<MeshNoteAliasDocument>(out var alias).Should().BeTrue();
alias.DocumentId.Should().Be(handle.DocumentId);