Move entity rehydration to domain layer, fix tempHp gap
All checks were successful
CI / check (push) Successful in 1m16s
CI / build-image (push) Has been skipped

Rehydration functions (reconstructing typed domain objects from untyped
JSON) lived in persistence adapters, duplicating domain validation.
Adding a field required updating both the domain type and a separate
adapter function — the adapter was missed for `level`, silently dropping
it on reload. Now adding a field only requires updating the domain type
and its co-located rehydration function.

- Add `rehydratePlayerCharacter` and `rehydrateCombatant` to domain
- Persistence adapters delegate to domain instead of reimplementing
- Add `tempHp` validation (was silently dropped during rehydration)
- Tighten initiative validation to integer-only
- Exhaustive domain tests (53 cases); adapter tests slimmed to round-trip
- Remove stale `jsinspect-plus` Knip ignoreDependencies entry

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-28 11:12:41 +01:00
parent f4fb69dbc7
commit 1de00e3d8e
12 changed files with 799 additions and 426 deletions

View File

@@ -4,8 +4,8 @@ import type {
PlayerCharacter,
UndoRedoState,
} from "@initiative/domain";
import { rehydratePlayerCharacter } from "@initiative/domain";
import { rehydrateEncounter } from "./encounter-storage.js";
import { rehydrateCharacter } from "./player-character-storage.js";
function rehydrateStack(raw: unknown[]): Encounter[] {
const result: Encounter[] = [];
@@ -21,7 +21,7 @@ function rehydrateStack(raw: unknown[]): Encounter[] {
function rehydrateCharacters(raw: unknown[]): PlayerCharacter[] {
const result: PlayerCharacter[] = [];
for (const entry of raw) {
const rehydrated = rehydrateCharacter(entry);
const rehydrated = rehydratePlayerCharacter(entry);
if (rehydrated !== null) {
result.push(rehydrated);
}