Mutation→context merge primitive across the stack
The @client(merge=[context, ...]) decorator lets a mutation patch its
return value directly into the cached context bundle by matching the
mutation's Output type against each context-function's Output type
to identify the slot, then splicing server-side. Kernel runs
splice_slot on the response to apply locally — no refetch, no
invalidate-cascade.
Lands H14, H15, H16, M19, M20 from ISSUES.md.
Backends (Django + FastAPI):
_resolve_merges() in both executors walks @client(merge=...) targets,
resolves the per-context slot via types_match_for_merge, and emits
{context, slot, value, params?} entries on the response. Param
auto-scoping mirrors _resolve_invalidation's tier-1 logic.
Frontend kernel (mizan-base):
Response handler reads the merge[] array and applies splice_slot
for each entry — locates the cached context bundle by name+params,
overwrites the named slot with the new value, notifies subscribers.
Core (mizan-python):
@client decorator extended with merge= parameter. Schema export
threads merge metadata onto the OpenAPI x-mizan-functions entries.
Examples / fixtures:
fastapi-react-site harness exercises merge + Playwright spec covers
the end-to-end happy path (mutation → instant UI update without
network refetch). AFI fixture's rename_user function is the
canonical merge target.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -142,6 +142,58 @@ def current_user(request) -> UserOutput:
|
||||
)
|
||||
|
||||
|
||||
# ─── Merge protocol fixtures ────────────────────────────────────────────────
|
||||
|
||||
|
||||
class MorphGroupMeta(BaseModel):
|
||||
"""Group summary — narrower shape than MorphLayer. Listed alongside
|
||||
morph_layers so the server's slot resolver has to discriminate by
|
||||
return-type rather than by bundle order."""
|
||||
id: int
|
||||
label: str
|
||||
count: int
|
||||
|
||||
|
||||
class MorphLayer(BaseModel):
|
||||
id: int
|
||||
group_id: int
|
||||
label: str
|
||||
value: float
|
||||
|
||||
|
||||
_morph_groups: list[MorphGroupMeta] = [
|
||||
MorphGroupMeta(id=1, label="face", count=2),
|
||||
]
|
||||
|
||||
|
||||
_morph_layers: list[MorphLayer] = [
|
||||
MorphLayer(id=1, group_id=1, label="brow", value=0.0),
|
||||
MorphLayer(id=2, group_id=1, label="jaw", value=0.0),
|
||||
]
|
||||
|
||||
|
||||
@client(context="morphs")
|
||||
def morph_groups(request) -> list[MorphGroupMeta]:
|
||||
"""Summary-shape slot — server must route MorphLayer mutations away from here."""
|
||||
return list(_morph_groups)
|
||||
|
||||
|
||||
@client(context="morphs")
|
||||
def morph_layers(request) -> list[MorphLayer]:
|
||||
"""Detailed-shape slot — server routes MorphLayer mutations here."""
|
||||
return list(_morph_layers)
|
||||
|
||||
|
||||
@client(merge="morphs")
|
||||
def set_morph_value(request, id: int, value: float) -> MorphLayer:
|
||||
"""Mutation that returns the changed row; kernel splices into morph_layers."""
|
||||
for layer in _morph_layers:
|
||||
if layer.id == id:
|
||||
layer.value = value
|
||||
return layer
|
||||
raise ValueError(f"unknown morph layer id={id}")
|
||||
|
||||
|
||||
# ─── Registration ───────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -156,6 +208,9 @@ register(not_implemented_fn, "not_implemented_fn")
|
||||
register(buggy_fn, "buggy_fn")
|
||||
register(permission_check_fn, "permission_check_fn")
|
||||
register(current_user, "current_user")
|
||||
register(morph_groups, "morph_groups")
|
||||
register(morph_layers, "morph_layers")
|
||||
register(set_morph_value, "set_morph_value")
|
||||
|
||||
|
||||
# ─── App ────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user