Add typed CultNet operation dispatch
This commit is contained in:
parent
35d31ae908
commit
b0a876a220
13 changed files with 913 additions and 128 deletions
|
|
@ -82,6 +82,29 @@ namespace GameCult.Mesh
|
|||
public TResponse Value { get; }
|
||||
}
|
||||
|
||||
/// <summary>Correlated framework-level failure returned before a typed domain reply exists.</summary>
|
||||
public sealed class CultMeshRemoteOperationException : Exception
|
||||
{
|
||||
internal CultMeshRemoteOperationException(
|
||||
CultNetOperationResponseMessage envelope,
|
||||
CultNetOperationFailure failure)
|
||||
: base(failure?.Message ?? "CultMesh operation failed.")
|
||||
{
|
||||
Status = envelope?.Status ?? "error";
|
||||
Code = failure?.Code ?? "operation-error";
|
||||
Diagnostics = envelope?.Diagnostics ?? Array.Empty<string>();
|
||||
}
|
||||
|
||||
/// <summary>Gets the provider-authored failure status.</summary>
|
||||
public string Status { get; }
|
||||
|
||||
/// <summary>Gets the stable machine-readable failure code.</summary>
|
||||
public string Code { get; }
|
||||
|
||||
/// <summary>Gets provider diagnostics carried by the response.</summary>
|
||||
public IReadOnlyList<string> Diagnostics { get; }
|
||||
}
|
||||
|
||||
/// <summary>Owns one shared live document subscription until disposed.</summary>
|
||||
public sealed class CultMeshDocumentLease<TDocument> : IDisposable where TDocument : class
|
||||
{
|
||||
|
|
@ -408,6 +431,24 @@ namespace GameCult.Mesh
|
|||
if (!string.Equals(envelope.ServiceId, expectedService, StringComparison.Ordinal) ||
|
||||
!string.Equals(envelope.Operation, expectedOperation, StringComparison.Ordinal))
|
||||
throw new InvalidOperationException("CultMesh operation response did not match the requested service and operation.");
|
||||
if (string.Equals(envelope.PayloadSchema, CultNetOperationServer.FailureSchemaId, StringComparison.Ordinal))
|
||||
{
|
||||
if (!string.Equals(envelope.PayloadEncoding, "messagepack-base64", StringComparison.Ordinal))
|
||||
throw new InvalidOperationException(
|
||||
$"CultMesh operation failure returned unsupported payload encoding '{envelope.PayloadEncoding}'.");
|
||||
CultNetOperationFailure failure;
|
||||
try
|
||||
{
|
||||
failure = MessagePackSerializer.Deserialize<CultNetOperationFailure>(
|
||||
Convert.FromBase64String(envelope.Payload),
|
||||
CultNetSchemaMessageSerialization.Options);
|
||||
}
|
||||
catch (Exception error) when (error is FormatException || error is MessagePackSerializationException)
|
||||
{
|
||||
throw new InvalidOperationException("CultMesh operation failure payload was malformed.", error);
|
||||
}
|
||||
throw new CultMeshRemoteOperationException(envelope, failure);
|
||||
}
|
||||
if (!string.Equals(envelope.PayloadSchema, expectedResponseSchema, StringComparison.Ordinal))
|
||||
throw new InvalidOperationException(
|
||||
$"CultMesh operation returned payload schema '{envelope.PayloadSchema}', expected '{expectedResponseSchema}'.");
|
||||
|
|
|
|||
|
|
@ -34,13 +34,17 @@ wire, see [docs/typed-document-path.md](docs/typed-document-path.md).
|
|||
|
||||
## Eve / CultUI Surfaces
|
||||
|
||||
CultMesh includes the portable Eve/CultUI surface document contract and a fluent
|
||||
builder for daemon-published UI. The builder is deliberately shaped like the
|
||||
legacy CultUI/Unity properties panel API: compose menus and forms in readable
|
||||
imperative code, while the emitted document carries typed CultMesh operation
|
||||
bindings, state bindings, style tokens, and embedded surface slots.
|
||||
CultMesh supplies the typed state and operation binding descriptors used by Eve.
|
||||
The renderer-neutral `GameCult.Eve.Surface` package in the Eve repository owns
|
||||
the portable surface document and fluent builder. Add that package when a daemon
|
||||
publishes UI; do not add EveUnity to the provider. The emitted document carries
|
||||
typed CultMesh operation bindings, state bindings, style tokens, and embedded
|
||||
surface slots while remaining independent of any lowering runtime.
|
||||
|
||||
```csharp
|
||||
using GameCult.Eve.Surface;
|
||||
using GameCult.Mesh;
|
||||
|
||||
var menu = EveSurface.Create("aetheria.main_menu.root")
|
||||
.Provider("aetheria", "game.menu")
|
||||
.TitleSubtitle("AETHERIA", "TERMINUS")
|
||||
|
|
|
|||
|
|
@ -29,6 +29,58 @@ CultMesh document session. Other runtime lowerers must preserve the same
|
|||
boundary: they may reject or report unsupported capabilities, but they may not
|
||||
import provider internals.
|
||||
|
||||
## The Application-Owned Part
|
||||
|
||||
Install the renderer-neutral `GameCult.Eve.Surface` package in the provider.
|
||||
Do not install EveUnity or the browser lowerer there. A provider defines typed
|
||||
state, one typed operation transaction, and one Eve surface. CultNet envelope
|
||||
encoding is framework work:
|
||||
|
||||
```csharp
|
||||
using GameCult.Eve.Surface;
|
||||
using GameCult.Mesh;
|
||||
using GameCult.Networking;
|
||||
|
||||
using var operations = new CultNetOperationServer(schemaServer, "sample.counter-provider")
|
||||
.Register<IncrementRequest, IncrementReceipt>(
|
||||
"sample.counter",
|
||||
"sample.counter.increment",
|
||||
"sample.increment.v1",
|
||||
"gamecult.eve.command_receipt.v1",
|
||||
async command => await IncrementExactlyOnceAsync(
|
||||
command.IdempotencyKey,
|
||||
command.Value));
|
||||
|
||||
var route = new CultMeshRouteHint(CultMeshLocalityKind.Network, "cultmesh");
|
||||
var count = new CultMeshStateBindingDescriptor(
|
||||
"value",
|
||||
"sample.counter.count",
|
||||
"sample.counter_state:counter:main",
|
||||
"sample.counter_state.v1",
|
||||
route);
|
||||
var increment = CultMesh.OperationBinding(
|
||||
"sample.counter.increment",
|
||||
"Increment",
|
||||
"sample.increment.v1",
|
||||
route);
|
||||
|
||||
var surface = EveSurface.Create("sample.counter")
|
||||
.Provider("sample.counter-provider", "sample.daemon")
|
||||
.Title("CultMesh browser counter")
|
||||
.RootColumn("counter.root", root => root
|
||||
.Metric("counter.value", "Canonical count", "0", count)
|
||||
.Button("counter.increment", "Increment", increment))
|
||||
.Build();
|
||||
```
|
||||
|
||||
`schemaServer` is a transport-neutral CultNet server port. WebSocket, RUDP, and
|
||||
test transports attach the same dispatcher. The handler owns validation,
|
||||
idempotency, state mutation, and its durable receipt. `CultNetOperationServer`
|
||||
owns only route/schema checks and typed envelope serialization. The complete
|
||||
provider transaction is in
|
||||
[`samples/eve-browser-network/Program.cs`](../../../../samples/eve-browser-network/Program.cs);
|
||||
it contains no hand-written operation base64 or MessagePack dispatch switch.
|
||||
|
||||
## Multi-Runtime Checkpoint
|
||||
|
||||
Run the same provider and connect at least two lowerers. Both must report the
|
||||
|
|
|
|||
Loading…
Reference in a new issue