Add synced snapshot endpoint facade

This commit is contained in:
Meta Vens 2026-06-27 18:37:56 +01:00
commit 07d4c4164a
2 changed files with 49 additions and 3 deletions

View file

@ -168,6 +168,46 @@ namespace GameCult.Mesh
public long ShardLogSequence => Snapshot.ShardLogSequence ?? 0L;
}
/// <summary>
/// Snapshot endpoint view with a local node sync policy already bound.
/// </summary>
public sealed class CultMeshSyncedSnapshotEndpoint
{
internal CultMeshSyncedSnapshotEndpoint(
CultMeshSnapshotEndpoint endpoint,
CultMeshNode node,
bool flush)
{
Endpoint = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
Node = node ?? throw new ArgumentNullException(nameof(node));
Flush = flush;
}
/// <summary>Gets the remote endpoint that provides snapshots.</summary>
public CultMeshSnapshotEndpoint Endpoint { get; }
/// <summary>Gets the local node snapshots are synced into.</summary>
public CultMeshNode Node { get; }
/// <summary>Gets whether each sync should flush the local node afterward.</summary>
public bool Flush { get; }
/// <summary>Creates a typed document handle that syncs into the local node before returning values.</summary>
public CultMeshDocumentHandle<TDocument> Document<TDocument>(
string recordKey,
string? documentId = null)
where TDocument : class
{
return Endpoint.SyncedDocument<TDocument>(Node, recordKey, documentId, Flush);
}
/// <summary>Creates a schema-aware catalog from typed endpoint bindings that sync into the local node before returning values.</summary>
public CultMeshDocumentCatalog Documents(params ICultMeshSnapshotDocumentBinding[] documents)
{
return Endpoint.SyncedDocuments(Node, Flush, documents);
}
}
/// <summary>
/// Typed snapshot surface for one remote CultNet endpoint.
/// </summary>
@ -209,6 +249,12 @@ namespace GameCult.Mesh
/// <summary>Gets the polling interval for watch fallback.</summary>
public TimeSpan PollInterval { get; }
/// <summary>Returns a view of this endpoint whose typed document handles sync into the supplied local node.</summary>
public CultMeshSyncedSnapshotEndpoint SyncTo(CultMeshNode node, bool flush = false)
{
return new CultMeshSyncedSnapshotEndpoint(this, node, flush);
}
/// <summary>Fetches one raw snapshot with this endpoint's configured request policy.</summary>
public Task<CultNetSnapshotResponseRawMessage> FetchSnapshotAsync(
IReadOnlyList<string>? schemaIds = null,

View file

@ -1230,7 +1230,8 @@ public sealed class CultMeshStreamingTests
Text = "snapshot-endpoint-synced",
Revision = 20
}, new CultRecordHandle<MeshNoteDocument>(key));
var syncedHandle = surface.SyncedDocument<MeshNoteAliasDocument>(node, key.Value);
var syncedEndpoint = surface.SyncTo(node);
var syncedHandle = syncedEndpoint.Document<MeshNoteAliasDocument>(key.Value);
var syncedLatest = await syncedHandle.LatestAsync();
await sourceCache.UpsertAsync(new MeshNoteDocument
{
@ -1238,8 +1239,7 @@ public sealed class CultMeshStreamingTests
Text = "snapshot-endpoint-catalog-synced",
Revision = 21
}, new CultRecordHandle<MeshNoteDocument>(key));
var syncedCatalog = surface.SyncedDocuments(
node,
var syncedCatalog = syncedEndpoint.Documents(
CultMesh.SnapshotDocument<MeshNoteDocument>(key.Value));
var syncedCatalogAlias = await syncedCatalog.LatestAsync<MeshNoteAliasDocument>();