Skip to content

refactor(adf): replace patcher switch branches with operation handlers #12

@SmartBrandStrategies

Description

@SmartBrandStrategies

Linked feedback: ADX-007

Problem

patcher.ts relies on a large operation switch with repeated content-type checks and
index bounds logic in multiple branches, increasing maintenance overhead and error risk.

Evidence:

  • Main switch: packages/adf/src/patcher.ts:22
  • Repeated guards in add/replace/remove bullet paths: packages/adf/src/patcher.ts:49

Scope

  • Introduce handler map keyed by operation (PatchOperation['op']).
  • Extract shared helpers for:
    • section lookup
    • index bounds validation
    • list/map entry parsing/coercion
  • Keep immutable semantics and current error behavior.

Acceptance Criteria

  • Behavior parity across all patch operations and failure paths.
  • Duplicated guard logic is reduced materially in patcher implementation.
  • Existing patcher tests pass; new helper-focused edge-case tests added.

Test Plan

  • pnpm run test --filter @stackbilt/adf
  • Add tests for:
    • invalid index errors (list/map)
    • unsupported content-type errors
    • metric update on missing metric key

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:adfADF parser/bundler/patcher packagepriority:p2Nice to have this cycletype:refactorCode restructuring without behavior change

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions