Skip to content

refactor(json-difference): extract sentinel unwrap helper#95

Merged
lukascivil merged 5 commits intomasterfrom
refactor/adjustments-codebase
Apr 23, 2026
Merged

refactor(json-difference): extract sentinel unwrap helper#95
lukascivil merged 5 commits intomasterfrom
refactor/adjustments-codebase

Conversation

@lukascivil
Copy link
Copy Markdown
Owner

@lukascivil lukascivil commented Apr 23, 2026

Objective

The sentinel strings '@{}' and '@[]' were duplicated across three files (get-edited-paths.ts, get-paths-diff.ts, sanitize-delta.ts). This refactor extracts them into a single unwrap-sentinel helper to eliminate the duplication and make future sentinel changes easier to apply consistently.

What was done

  • Added libs/json-difference/src/helpers/unwrap-sentinel.ts with OBJECT_SENTINEL, ARRAY_SENTINEL constants and an unwrapSentinel function that maps sentinel values back to {} / []
  • Added unit tests for unwrapSentinel in libs/json-difference/src/helpers/unwrap-sentinel.spec.ts
  • Replaced inline sentinel comparisons in get-edited-paths.ts, get-paths-diff.ts, and sanitize-delta.ts with the new helper; sanitize-delta.ts now preserves the original tuple reference when no sentinel is present
  • Exported unwrap-sentinel from libs/json-difference/src/helpers/index.ts
  • Added tsconfig.spec.json reference to libs/json-difference/tsconfig.json
  • Added JSON fixture files (fixture/oldJson.json, fixture/newJson.json, fixture/delta.json) and a fixture-based integration test in get-diff.spec.ts that verifies the full diff output against a known snapshot

Test plan

  • Run yarn nx test json-difference — all tests should pass including the new fixture test
  • Run yarn nx lint json-difference — no warnings

@lukascivil lukascivil changed the title Refactor/adjustments codebase refactor(json-difference): extract sentinel unwrap helper Apr 23, 2026
@lukascivil lukascivil merged commit a412282 into master Apr 23, 2026
4 checks passed
@lukascivil lukascivil deleted the refactor/adjustments-codebase branch April 23, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant