Skip to content

sequenceCache.ts: Refactor sequence number invalidation into an explicit state machine #701

Description

@Kingsman-99

Description

src/sequenceCache.ts manages cached sequence numbers with invalidation flags scattered across several boolean variables. The state transitions between valid, invalidated, and refreshing are implicit and hard to trace. Converting to an explicit state machine (type CacheState = 'valid' | 'invalidated' | 'refreshing') makes transitions auditable.

Acceptance Criteria

  • A CacheState type union replaces the boolean flags
  • All state transitions go through a single transition(newState) function that validates the transition
  • Invalid transitions (e.g., valid to refreshing without first going through invalidated) throw a StateTransitionError
  • Unit tests pass

Context

  • Target file: src/sequenceCache.ts
  • The public API (getSequence, invalidate, refresh) must not change

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions