Accept typed Python CultNet sync responses in CultMesh

This commit is contained in:
Meta Vens 2026-06-14 04:26:45 +01:00
commit 27499e766c
4 changed files with 44 additions and 12 deletions

View file

@ -11,6 +11,8 @@ from cultnet_py import (
CultNetAppliedRecord,
CultNetMessage,
CultNetRawClient,
CultNetRawSnapshotResponse,
CultNetShardLogResponse,
apply_raw_snapshot as apply_cultnet_raw_snapshot,
apply_shard_log_response as apply_cultnet_shard_log_response,
document_delete,
@ -459,7 +461,7 @@ class CultMeshDatabase:
shard_id: str | None = None,
shard_epoch: int | None = None,
) -> list[CultNetAppliedRecord]:
response = client.fetch_snapshot(
response = client.fetch_snapshot_response(
schema_ids=schema_ids,
record_keys=record_keys,
shard_id=shard_id,
@ -476,7 +478,7 @@ class CultMeshDatabase:
after_sequence: int = 0,
limit: int | None = None,
) -> list[CultNetAppliedRecord]:
response = client.fetch_shard_log(
response = client.fetch_shard_log_response(
shard_id=shard_id,
shard_epoch=shard_epoch,
after_sequence=after_sequence,
@ -519,15 +521,23 @@ class CultMeshDatabase:
response["shardEpoch"] = self._latest_shard_epoch(shard_id) or 0
return response
def apply_snapshot_response(self, response: dict[str, Any]) -> list[CultNetAppliedRecord]:
previous = self._previous_values_for_snapshot_response(response)
applied = apply_cultnet_raw_snapshot(self.cache, self.documents, response)
def apply_snapshot_response(
self,
response: dict[str, Any] | CultNetRawSnapshotResponse,
) -> list[CultNetAppliedRecord]:
wire = response.to_wire() if isinstance(response, CultNetRawSnapshotResponse) else response
previous = self._previous_values_for_snapshot_response(wire)
applied = apply_cultnet_raw_snapshot(self.cache, self.documents, wire)
self._publish_applied_records(applied, previous)
return applied
def apply_shard_log_response(self, response: dict[str, Any]) -> list[CultNetAppliedRecord]:
previous = self._previous_values_for_shard_log_response(response)
applied = apply_cultnet_shard_log_response(self.cache, self.documents, response)
def apply_shard_log_response(
self,
response: dict[str, Any] | CultNetShardLogResponse,
) -> list[CultNetAppliedRecord]:
wire = response.to_wire() if isinstance(response, CultNetShardLogResponse) else response
previous = self._previous_values_for_shard_log_response(wire)
applied = apply_cultnet_shard_log_response(self.cache, self.documents, wire)
self._publish_applied_records(applied, previous)
return applied

View file

@ -8,6 +8,7 @@ from cultnet_py import (
CultNetAppliedRecord,
CultNetClientAuthorityScope,
CultNetRawClient,
CultNetShardLogResponse,
CultNetSimulationConsensusOptions,
CultNetSimulationObservationHub,
)
@ -76,7 +77,10 @@ class CultMeshGameSession:
self._predicted_keys.add((schema_id, key))
return CultMeshPrediction(key=key, schema_id=schema_id, document=document, value=value)
def apply_shard_log_response(self, response: dict[str, Any]) -> list[CultMeshSessionChange]:
def apply_shard_log_response(
self,
response: dict[str, Any] | CultNetShardLogResponse,
) -> list[CultMeshSessionChange]:
applied = self.node.database.apply_shard_log_response(response)
return self._reconcile_applied(applied)
@ -89,7 +93,7 @@ class CultMeshGameSession:
after_sequence: int = 0,
limit: int | None = None,
) -> list[CultMeshSessionChange]:
response = client.fetch_shard_log(
response = client.fetch_shard_log_response(
shard_id=shard_id,
shard_epoch=shard_epoch,
after_sequence=after_sequence,