CultMesh: AsSchemaAlias is gone; a catalog finds a handle by its type
F7 (operator, 2026-09-30): "Schema aliasing sounds like a really bad idea, I support retiring it." One CLR type owns a schema, so a handle never needs converting to another type for the same schema. - Delete AsSchemaAlias from the document and collection handles and their interfaces, with the MessagePack round-trip converters only it used. - The document and collection catalogs look a typed handle up by its type. The schema-name/version fallback existed only to find a handle of another type and alias it. - Tests: the MeshNoteAliasDocument fixture is deleted. Tests that used it for publication, sync, snapshot and prediction paths now use MeshNoteDocument; the one test that only checked alias refusal is deleted. Catalog tests check a type with no handle is not found. - public-api.md stops documenting aliasing; a stale comment in ReadDocumentFromSnapshotResponse that cited the fixture is trimmed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5b86bc9faf
commit
1e0455028c
5 changed files with 140 additions and 338 deletions
|
|
@ -2728,11 +2728,9 @@ namespace GameCult.Mesh
|
|||
// runtime does not recognize by any alias) its payload's own embedded schema stamp,
|
||||
// alias-matched against TDocument's descriptor. The parse step
|
||||
// (CultNetDocumentRegistry.TryReadSchemaVersion) is the one decode rule shared with
|
||||
// DecodeSnapshotDocuments; the match itself stays a direct alias-match against the caller's
|
||||
// own descriptor rather than a global "which registered type owns this schema string" lookup,
|
||||
// because that lookup is ambiguous when two document types alias the same schema id (as
|
||||
// MeshNoteDocument/MeshNoteAliasDocument do in tests/GameCult.Mesh.Tests). No re-filter of the
|
||||
// server's answer by schema alone, and no fallback that returns a record under the wrong key.
|
||||
// DecodeSnapshotDocuments; the match itself is a direct alias-match against the caller's own
|
||||
// descriptor. No re-filter of the server's answer by schema alone, and no fallback that
|
||||
// returns a record under the wrong key.
|
||||
private static TDocument ReadDocumentFromSnapshotResponse<TDocument>(
|
||||
CultNetSnapshotResponseRawMessage response,
|
||||
string schemaId,
|
||||
|
|
|
|||
|
|
@ -910,13 +910,10 @@ namespace GameCult.Mesh
|
|||
|
||||
/// <summary>Gets whether this handle can submit a client prediction for the underlying document value.</summary>
|
||||
bool CanSubmitPrediction { get; }
|
||||
|
||||
/// <summary>Creates a same-schema alias presentation for another CLR document type.</summary>
|
||||
CultMeshDocumentHandle<TAlias> AsSchemaAlias<TAlias>() where TAlias : class;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Typed reactive document handle with schema-aware alias conversion.
|
||||
/// Typed reactive document handle.
|
||||
/// </summary>
|
||||
public sealed class CultMeshDocumentHandle<TDocument> : ICultMeshDocumentHandle
|
||||
where TDocument : class
|
||||
|
|
@ -1117,39 +1114,6 @@ namespace GameCult.Mesh
|
|||
return ObserveAsync().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>Creates a same-schema alias presentation for another CLR document type.</summary>
|
||||
public CultMeshDocumentHandle<TAlias> AsSchemaAlias<TAlias>() where TAlias : class
|
||||
{
|
||||
var aliasDescriptor = CultDocumentRegistry.Shared.GetRequired<TAlias>();
|
||||
if (!string.Equals(Descriptor.SchemaName, aliasDescriptor.SchemaName, StringComparison.Ordinal) ||
|
||||
!string.Equals(Descriptor.SchemaVersion, aliasDescriptor.SchemaVersion, StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Document type {typeof(TAlias).FullName} uses schema '{aliasDescriptor.SchemaName}' " +
|
||||
$"version '{aliasDescriptor.SchemaVersion}', but handle '{DocumentId}' exposes " +
|
||||
$"schema '{SchemaName}' version '{SchemaVersion}'.");
|
||||
}
|
||||
|
||||
var aliasFeed = new CultMeshLiveFeed<CultMeshDocumentQueryParameters, TAlias>(
|
||||
DocumentId,
|
||||
async (parameters, context) => ConvertDocument<TDocument, TAlias>(
|
||||
await Feed.SnapshotAsync(parameters, context).ConfigureAwait(false)),
|
||||
(parameters, context) => Feed
|
||||
.Watch(parameters, context)
|
||||
.Select(ConvertDocument<TDocument, TAlias>),
|
||||
Sources,
|
||||
RouteHint);
|
||||
|
||||
Func<TAlias, Task>? replace = _replace == null
|
||||
? null
|
||||
: value => _replace(ConvertDocument<TAlias, TDocument>(value));
|
||||
Func<TAlias, Task>? submitPrediction = _submitPrediction == null
|
||||
? null
|
||||
: value => _submitPrediction(ConvertDocument<TAlias, TDocument>(value));
|
||||
|
||||
return new CultMeshDocumentHandle<TAlias>(aliasFeed.Bind(Context), replace, submitPrediction);
|
||||
}
|
||||
|
||||
internal static TDocumentValue CloneDocument<TDocumentValue>(TDocumentValue document)
|
||||
where TDocumentValue : class
|
||||
{
|
||||
|
|
@ -1216,19 +1180,6 @@ namespace GameCult.Mesh
|
|||
"field");
|
||||
}
|
||||
|
||||
internal static TTarget ConvertDocument<TSource, TTarget>(TSource document)
|
||||
where TSource : class
|
||||
where TTarget : class
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
if (document is TTarget alreadyTyped)
|
||||
{
|
||||
return alreadyTyped;
|
||||
}
|
||||
|
||||
var payload = CultDocumentMessagePackSerialization.SerializeUntyped(document, typeof(TSource));
|
||||
return (TTarget)CultDocumentMessagePackSerialization.DeserializeUntyped(typeof(TTarget), payload);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -1912,11 +1863,12 @@ namespace GameCult.Mesh
|
|||
$"CultMesh document catalog does not expose a document for schema '{schema}'.");
|
||||
}
|
||||
|
||||
/// <summary>Looks up a typed document handle by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Looks up a typed document handle by CLR type.</summary>
|
||||
public bool TryGetDocument<TDocument>(
|
||||
out CultMeshDocumentHandle<TDocument> document)
|
||||
where TDocument : class
|
||||
{
|
||||
// One type owns a schema, so the handle for TDocument's schema is the handle for TDocument.
|
||||
if (_documentsByType.TryGetValue(typeof(TDocument), out var untypedDocument) &&
|
||||
untypedDocument is CultMeshDocumentHandle<TDocument> typedDocument)
|
||||
{
|
||||
|
|
@ -1924,25 +1876,11 @@ namespace GameCult.Mesh
|
|||
return true;
|
||||
}
|
||||
|
||||
var descriptor = CultDocumentRegistry.Shared.GetRequired<TDocument>();
|
||||
if (_documentsBySchema.TryGetValue(descriptor.SchemaVersion, out var schemaDocument) ||
|
||||
_documentsBySchema.TryGetValue(descriptor.SchemaName, out schemaDocument!))
|
||||
{
|
||||
if (schemaDocument is CultMeshDocumentHandle<TDocument> schemaTypedDocument)
|
||||
{
|
||||
document = schemaTypedDocument;
|
||||
return true;
|
||||
}
|
||||
|
||||
document = schemaDocument.AsSchemaAlias<TDocument>();
|
||||
return true;
|
||||
}
|
||||
|
||||
document = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Looks up a typed document handle by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Looks up a typed document handle by CLR type.</summary>
|
||||
public CultMeshDocumentHandle<TDocument> Document<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
|
|
@ -1953,70 +1891,70 @@ namespace GameCult.Mesh
|
|||
$"CultMesh document catalog does not expose a document for {typeof(TDocument).FullName}.");
|
||||
}
|
||||
|
||||
/// <summary>Reads one typed document snapshot by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Reads one typed document snapshot by CLR type.</summary>
|
||||
public Task<TDocument> LatestAsync<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return Document<TDocument>().LatestAsync();
|
||||
}
|
||||
|
||||
/// <summary>Reads one typed document synchronously by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Reads one typed document synchronously by CLR type.</summary>
|
||||
public TDocument Latest<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return Document<TDocument>().Latest();
|
||||
}
|
||||
|
||||
/// <summary>Gets whether one typed document can be replaced by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Gets whether one typed document can be replaced by CLR type.</summary>
|
||||
public bool CanReplace<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return TryGetDocument<TDocument>(out var document) && document.CanReplace;
|
||||
}
|
||||
|
||||
/// <summary>Replaces one typed document by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Replaces one typed document by CLR type.</summary>
|
||||
public Task ReplaceAsync<TDocument>(TDocument value)
|
||||
where TDocument : class
|
||||
{
|
||||
return Document<TDocument>().ReplaceAsync(value);
|
||||
}
|
||||
|
||||
/// <summary>Gets whether one typed document can submit client predictions by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Gets whether one typed document can submit client predictions by CLR type.</summary>
|
||||
public bool CanSubmitPrediction<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return TryGetDocument<TDocument>(out var document) && document.CanSubmitPrediction;
|
||||
}
|
||||
|
||||
/// <summary>Submits a client prediction for one typed document by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Submits a client prediction for one typed document by CLR type.</summary>
|
||||
public Task SubmitPredictionAsync<TDocument>(TDocument value)
|
||||
where TDocument : class
|
||||
{
|
||||
return Document<TDocument>().SubmitPredictionAsync(value);
|
||||
}
|
||||
|
||||
/// <summary>Gets an explicit authoritative writer by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Gets an explicit authoritative writer by CLR type.</summary>
|
||||
public CultMeshDocumentWriter<TDocument> AuthoritativeWriter<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return Document<TDocument>().AuthoritativeWriter();
|
||||
}
|
||||
|
||||
/// <summary>Gets an explicit prediction writer by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Gets an explicit prediction writer by CLR type.</summary>
|
||||
public CultMeshDocumentWriter<TDocument> PredictionWriter<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return Document<TDocument>().PredictionWriter();
|
||||
}
|
||||
|
||||
/// <summary>Watches one typed document by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Watches one typed document by CLR type.</summary>
|
||||
public Observable<TDocument> Watch<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return Document<TDocument>().Watch();
|
||||
}
|
||||
|
||||
/// <summary>Subscribes to one typed document by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Subscribes to one typed document by CLR type.</summary>
|
||||
public IDisposable Watch<TDocument>(Action<TDocument> onNext)
|
||||
where TDocument : class
|
||||
{
|
||||
|
|
@ -2050,9 +1988,6 @@ namespace GameCult.Mesh
|
|||
|
||||
/// <summary>Gets typed state sources this collection handle depends on, when known.</summary>
|
||||
IReadOnlyList<CultMeshProjectionSource> Sources { get; }
|
||||
|
||||
/// <summary>Creates a same-schema alias presentation for another CLR document type.</summary>
|
||||
CultMeshCollectionHandle<TAlias> AsSchemaAlias<TAlias>() where TAlias : class;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -2118,11 +2053,12 @@ namespace GameCult.Mesh
|
|||
$"CultMesh collection catalog does not expose a collection for schema '{schema}'.");
|
||||
}
|
||||
|
||||
/// <summary>Looks up a typed collection handle by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Looks up a typed collection handle by CLR type.</summary>
|
||||
public bool TryGetCollection<TDocument>(
|
||||
out CultMeshCollectionHandle<TDocument> collection)
|
||||
where TDocument : class
|
||||
{
|
||||
// One type owns a schema, so the handle for TDocument's schema is the handle for TDocument.
|
||||
if (_collectionsByType.TryGetValue(typeof(TDocument), out var untypedCollection) &&
|
||||
untypedCollection is CultMeshCollectionHandle<TDocument> typedCollection)
|
||||
{
|
||||
|
|
@ -2130,26 +2066,11 @@ namespace GameCult.Mesh
|
|||
return true;
|
||||
}
|
||||
|
||||
var descriptor = CultDocumentRegistry.Shared.GetRequired<TDocument>();
|
||||
if (_collectionsBySchema.TryGetValue(descriptor.SchemaId, out var schemaCollection) ||
|
||||
_collectionsBySchema.TryGetValue(descriptor.SchemaVersion, out schemaCollection!) ||
|
||||
_collectionsBySchema.TryGetValue(descriptor.SchemaName, out schemaCollection!))
|
||||
{
|
||||
if (schemaCollection is CultMeshCollectionHandle<TDocument> schemaTypedCollection)
|
||||
{
|
||||
collection = schemaTypedCollection;
|
||||
return true;
|
||||
}
|
||||
|
||||
collection = schemaCollection.AsSchemaAlias<TDocument>();
|
||||
return true;
|
||||
}
|
||||
|
||||
collection = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Looks up a typed collection handle by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Looks up a typed collection handle by CLR type.</summary>
|
||||
public CultMeshCollectionHandle<TDocument> Collection<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
|
|
@ -2160,21 +2081,21 @@ namespace GameCult.Mesh
|
|||
$"CultMesh collection catalog does not expose a collection for {typeof(TDocument).FullName}.");
|
||||
}
|
||||
|
||||
/// <summary>Reads one typed collection snapshot by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Reads one typed collection snapshot by CLR type.</summary>
|
||||
public Task<IReadOnlyList<TDocument>> LatestAsync<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return Collection<TDocument>().LatestAsync();
|
||||
}
|
||||
|
||||
/// <summary>Watches one typed collection by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Watches one typed collection by CLR type.</summary>
|
||||
public Observable<CultMeshCollectionChange<TDocument>> WatchChanges<TDocument>()
|
||||
where TDocument : class
|
||||
{
|
||||
return Collection<TDocument>().WatchChanges();
|
||||
}
|
||||
|
||||
/// <summary>Subscribes to one typed collection by CLR type or same-schema alias.</summary>
|
||||
/// <summary>Subscribes to one typed collection by CLR type.</summary>
|
||||
public IDisposable WatchChanges<TDocument>(Action<CultMeshCollectionChange<TDocument>> onNext)
|
||||
where TDocument : class
|
||||
{
|
||||
|
|
@ -2246,7 +2167,7 @@ namespace GameCult.Mesh
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Typed reactive collection handle with schema-aware alias conversion.
|
||||
/// Typed reactive collection handle.
|
||||
/// </summary>
|
||||
public sealed class CultMeshCollectionHandle<TDocument> : ICultMeshCollectionHandle
|
||||
where TDocument : class
|
||||
|
|
@ -2313,49 +2234,6 @@ namespace GameCult.Mesh
|
|||
if (onNext == null) throw new ArgumentNullException(nameof(onNext));
|
||||
return WatchChanges().Subscribe(onNext);
|
||||
}
|
||||
|
||||
/// <summary>Creates a same-schema alias presentation for another CLR document type.</summary>
|
||||
public CultMeshCollectionHandle<TAlias> AsSchemaAlias<TAlias>() where TAlias : class
|
||||
{
|
||||
var aliasDescriptor = CultDocumentRegistry.Shared.GetRequired<TAlias>();
|
||||
if (!string.Equals(Descriptor.SchemaName, aliasDescriptor.SchemaName, StringComparison.Ordinal) ||
|
||||
!string.Equals(Descriptor.SchemaVersion, aliasDescriptor.SchemaVersion, StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Document type {typeof(TAlias).FullName} uses schema '{aliasDescriptor.SchemaName}' " +
|
||||
$"version '{aliasDescriptor.SchemaVersion}', but collection '{CollectionId}' exposes " +
|
||||
$"schema '{SchemaName}' version '{SchemaVersion}'.");
|
||||
}
|
||||
|
||||
return new CultMeshCollectionHandle<TAlias>(
|
||||
CollectionId,
|
||||
async () => (await LatestAsync().ConfigureAwait(false))
|
||||
.Select(ConvertDocument<TDocument, TAlias>)
|
||||
.ToArray(),
|
||||
() => WatchChanges().Select(change => new CultMeshCollectionChange<TAlias>(
|
||||
change.Kind,
|
||||
change.Key,
|
||||
change.SchemaId,
|
||||
change.Document == null ? null : ConvertDocument<TDocument, TAlias>(change.Document),
|
||||
change.PreviousDocument == null ? null : ConvertDocument<TDocument, TAlias>(change.PreviousDocument),
|
||||
change.Message)),
|
||||
Sources,
|
||||
RouteHint);
|
||||
}
|
||||
|
||||
private static TTarget ConvertDocument<TSource, TTarget>(TSource document)
|
||||
where TSource : class
|
||||
where TTarget : class
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
if (document is TTarget alreadyTyped)
|
||||
{
|
||||
return alreadyTyped;
|
||||
}
|
||||
|
||||
var payload = CultDocumentMessagePackSerialization.SerializeUntyped(document, typeof(TSource));
|
||||
return (TTarget)CultDocumentMessagePackSerialization.DeserializeUntyped(typeof(TTarget), payload);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -979,11 +979,11 @@ namespace GameCult.Mesh
|
|||
var canDeserializeWithBinding =
|
||||
binding != null &&
|
||||
typeof(TDocument).IsAssignableFrom(binding.DocumentType);
|
||||
var canDeserializeAsSchemaAlias =
|
||||
var canDeserializeByWireSchema =
|
||||
CultNetSchemaAliasMatching.Matches(record.SchemaId, descriptor) ||
|
||||
(binding != null && CultNetSchemaAliasMatching.Matches(binding.SchemaId, descriptor)) ||
|
||||
CultNetDocumentRegistry.PayloadMatchesSchema(record.Payload, descriptor);
|
||||
if (!canDeserializeWithBinding && !canDeserializeAsSchemaAlias)
|
||||
if (!canDeserializeWithBinding && !canDeserializeByWireSchema)
|
||||
continue;
|
||||
|
||||
if (!string.Equals(record.PayloadEncoding, "messagepack", StringComparison.Ordinal))
|
||||
|
|
|
|||
|
|
@ -173,28 +173,22 @@ portable machinery that makes it feel native.
|
|||
the normal shard log. Callers can bind a projected live feed, a local
|
||||
`CultCache` record, a distributed `CultNetDatabase` record, or a
|
||||
`CultMeshNode` record through the same surface instead of walking transport
|
||||
and projection layers themselves. Same-schema CLR aliases can be requested
|
||||
directly from node/database/snapshot surfaces; CultMesh resolves the canonical
|
||||
registered document by shared `[CultDocument(schemaName, schemaVersion)]`
|
||||
identity and uses the shared CultCache MessagePack codec for
|
||||
read/watch/replace/prediction conversion. `AsSchemaAlias<TAlias>()` remains
|
||||
available when a caller already has a handle and wants to project it.
|
||||
and projection layers themselves. One CLR type owns each
|
||||
`[CultDocument(schemaName, schemaVersion)]` schema; the registry refuses a
|
||||
second type for the same schema with `CultSchemaConflictException`.
|
||||
- `CultMeshDocumentCatalog` is the schema-aware lookup edge for a set of
|
||||
document handles. It indexes handles by CLR document type, schema name, and
|
||||
schema version, and resolves same-schema CLR aliases by delegating to
|
||||
`CultMeshDocumentHandle<TDocument>.AsSchemaAlias<TAlias>()`. Domain facades
|
||||
can expose `Document<T>()`, `DocumentBySchema(...)`, `LatestAsync<T>()`, and
|
||||
`Watch<T>()` without owning schema dictionaries or alias serializers. Mutable
|
||||
facades can also call `ReplaceAsync<T>(...)` or
|
||||
`SubmitPredictionAsync<T>(...)` directly on the catalog when they only need
|
||||
the schema-aliased operation and not the intermediate handle.
|
||||
document handles. It indexes handles by CLR document type, schema id, schema
|
||||
name, and schema version. Domain facades can expose `Document<T>()`,
|
||||
`DocumentBySchema(...)`, `LatestAsync<T>()`, and `Watch<T>()` without owning
|
||||
schema dictionaries. Mutable facades can also call `ReplaceAsync<T>(...)` or
|
||||
`SubmitPredictionAsync<T>(...)` directly on the catalog when they do not need
|
||||
the intermediate handle.
|
||||
- `CultMeshCollectionHandle<TDocument>` is the typed reactive edge for
|
||||
multi-record state. It exposes one `LatestAsync()` collection snapshot and a
|
||||
`WatchChanges()` stream while hiding whether the backing source is an
|
||||
in-process `CultCache`, a distributed `CultNetDatabase`, or a `CultMeshNode`.
|
||||
Collection handles can represent all records of a document type, a named
|
||||
document view, or an indexed value view, and they support the same
|
||||
same-schema CLR alias conversion as document handles.
|
||||
document view, or an indexed value view.
|
||||
- `CultMeshCollectionCatalog` is the collection sibling of
|
||||
`CultMeshDocumentCatalog`. It indexes typed collection handles by CLR
|
||||
document type, schema id, schema name, and schema version, then exposes
|
||||
|
|
@ -258,19 +252,17 @@ var objects = await visibleObjects.ExecuteAsync(viewportRequest);
|
|||
await movePilot.InvokeAsync(moveRequest, idempotencyKey);
|
||||
```
|
||||
|
||||
A single typed document can be surfaced the same way. The caller asks for the
|
||||
typed view it wants; if that type is a same-schema alias of the registered
|
||||
canonical document, CultMesh still opens the correct backing record:
|
||||
A single typed document can be surfaced the same way:
|
||||
|
||||
```csharp
|
||||
var stockForUi = CultMesh.Document<StationStockUiDocument>(
|
||||
var stockHandle = CultMesh.Document<StationStockDocument>(
|
||||
node,
|
||||
new CultRecordKey("station:starbridge:stock"),
|
||||
verse);
|
||||
|
||||
var stock = await stockForUi.LatestAsync();
|
||||
using var watch = stockForUi.Watch(RenderStock);
|
||||
await stockForUi.SetAsync(updatedStockFromUi);
|
||||
var stock = await stockHandle.LatestAsync();
|
||||
using var watch = stockHandle.Watch(RenderStock);
|
||||
await stockHandle.SetAsync(updatedStock);
|
||||
```
|
||||
|
||||
Projected or derived documents can use the same handle shape with explicit
|
||||
|
|
@ -291,8 +283,6 @@ var cockpit = CultMesh.Document(
|
|||
|
||||
var current = await cockpit.LatestAsync();
|
||||
using var subscription = cockpit.Watch(next => RenderCockpit(next));
|
||||
|
||||
var daemonAlias = cockpit.AsSchemaAlias<DaemonCockpitState>();
|
||||
```
|
||||
|
||||
Remote CultNet snapshots use the same document handle surface. The caller names
|
||||
|
|
@ -301,20 +291,18 @@ id, response filtering, raw MessagePack payload decode, route metadata, and
|
|||
polling watch fallback:
|
||||
|
||||
```csharp
|
||||
var remoteHealth = CultMesh.DocumentFromPeerSnapshot<DaemonHealthUiDocument>(
|
||||
var remoteHealth = CultMesh.DocumentFromPeerSnapshot<DaemonHealthDocument>(
|
||||
"cultnet://daemon.local:3075",
|
||||
"daemon:aetheria.health.v1",
|
||||
verse);
|
||||
|
||||
var uiHealth = await remoteHealth.LatestAsync();
|
||||
var health = await remoteHealth.LatestAsync();
|
||||
```
|
||||
|
||||
Snapshot requests are record-key-first so same logical documents can still be
|
||||
read when another runtime generated a different schema id for a compatible
|
||||
schema alias. The decode path prefers exact schema id matches when present and
|
||||
falls back to the requested record key. Ask for the runtime-facing alias type
|
||||
directly; `AsSchemaAlias<TAlias>()` is for adapting handles that were already
|
||||
constructed elsewhere.
|
||||
Snapshot requests are record-key-first so the same logical document can still be
|
||||
read when another runtime generated a different schema id for it. The decode
|
||||
path prefers exact schema id matches when present and falls back to the
|
||||
requested record key.
|
||||
|
||||
A domain facade can still collect existing handles into one schema-aware
|
||||
catalog when it is composing pre-built surfaces:
|
||||
|
|
@ -326,7 +314,7 @@ var documents = CultMesh.Documents(
|
|||
zoneContacts);
|
||||
|
||||
var refit = await documents.LatestAsync<StationRefitDocument>();
|
||||
var uiDocking = documents.Document<CurrentDockingUiDocument>();
|
||||
var docking = documents.Document<CurrentDockingDocument>();
|
||||
var bySchema = documents.DocumentBySchema("gamecult.aetheria.station_refit.v1");
|
||||
```
|
||||
|
||||
|
|
@ -341,11 +329,9 @@ var allies = CultMesh.CollectionByIndex<PlayerShipDocument>(
|
|||
var currentAllies = await allies.LatestAsync();
|
||||
using var changes = allies.WatchChanges(change => UpdateRoster(change));
|
||||
|
||||
var uiAllies = allies.AsSchemaAlias<PlayerShipUiDocument>();
|
||||
|
||||
var collections = CultMesh.Collections(allies);
|
||||
var uiRoster = await collections.LatestAsync<PlayerShipUiDocument>();
|
||||
using var uiRosterChanges = collections.WatchChanges<PlayerShipUiDocument>(RenderRoster);
|
||||
var roster = await collections.LatestAsync<PlayerShipDocument>();
|
||||
using var rosterChanges = collections.WatchChanges<PlayerShipDocument>(RenderRoster);
|
||||
```
|
||||
|
||||
```ts
|
||||
|
|
|
|||
Loading…
Reference in a new issue