Move entity rehydration to domain layer #20
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Entity rehydration (reconstructing typed domain objects from untyped JSON) currently lives in persistence adapters, duplicating validation logic that the domain already owns. This caused a bug where adding
leveltoPlayerCharacterrequired updating both the domain type and a separate rehydration function in the persistence layer — the persistence function was missed, silently dropping levels on reload. Moving rehydration to the domain ensures adding a field to a type and its rehydration function is the only change needed.Acceptance Criteria
rehydratePlayerCharacter(raw: unknown): PlayerCharacter | nullthat validates all fields (id, name, ac, maxHp, color, icon, level) and returns a typed instance or nullrehydrateCombatant(raw: unknown): Combatant | nullwith equivalent validation for combatant fieldsplayer-character-storage.tsdelegates torehydratePlayerCharacterinstead of reimplementing field checksencounter-storage.tsdelegates torehydrateCombatantinstead of reimplementing field checksvalidateImportBundleandrehydrateEncounterare unchanged — they validate bundle envelope / encounter shape in the adapter and delegate entity validation to domain rehydration functionsPlayerCharacterorCombatantrequires updating only the domain type and its rehydration function — persistence adapters stay in sync automatically