Files
initiative/specs/023-clear-encounter/data-model.md

1.7 KiB

Data Model: 023-clear-encounter

Entities

Encounter (existing — no schema changes)

The Encounter type is unchanged. The clear operation produces an encounter with:

Field Cleared Value Notes
combatants [] Empty readonly array
activeIndex 0 Reset to initial
roundNumber 1 Reset to initial

No new fields or types are added to the data model.

Events

EncounterCleared (new)

Field Type Description
type string Discriminant: "EncounterCleared"
combatantCount number Number of combatants that were removed

Minimal event shape — captures the count of cleared combatants for observability. No need to record the full pre-clear state (MVP baseline does not include undo).

State Transitions

clearEncounter(encounter: Encounter) → ClearEncounterSuccess | DomainError

Input:  Any Encounter with combatants.length > 0
Output: { encounter: { combatants: [], activeIndex: 0, roundNumber: 1 },
          events: [EncounterCleared] }

Error:  encounter.combatants.length === 0 → DomainError("encounter-already-empty")

Persistence Impact

  • saveEncounter(): No changes — already serializes any Encounter to JSON.
  • loadEncounter(): Must handle combatants: [] case by returning the empty encounter directly instead of routing through createEncounter() (which rejects empty combatant arrays).