Skip to content

Refactor: consolidate duplicate code, fix coverage, update docs#323

Merged
avoidwork merged 5 commits intomasterfrom
audit2
Apr 19, 2026
Merged

Refactor: consolidate duplicate code, fix coverage, update docs#323
avoidwork merged 5 commits intomasterfrom
audit2

Conversation

@avoidwork
Copy link
Copy Markdown
Owner

Summary

  • DRY refactor: Extract #freezeResult(), #fromCache(), #toCache() helpers; consolidate #getIndexKeys + #getIndexKeysForWhere#getIndexKeysFrom() (212 lines removed, -50% duplicate code)
  • Coverage fix: Add test for clear()set() state transition achieving 100% line coverage
  • Docs: Update AGENTS.md with internal helpers, test strategy, and refactoring patterns; sync API.md and TECHNICAL_DOCUMENTATION.md

Changes

src/haro.js (-293, +188)

  • #freezeResult(result) - Centralizes all Object.freeze() returns (10+ methods)
  • #fromCache(cached) - Unified cache-read clone/freeze pattern for search()/where()
  • #toCache(cacheKey, records) - Unified cache-write for search()/where()
  • #getIndexKeysFrom(arg, source, getValueFn) - Consolidates index key generation with getter callback
  • Removed #getIndexKeys and #getIndexKeysForWhere (duplicated logic)

tests/unit/crud.test.js (+1 test)

  • clear()set() on same store triggers lazy index recreation branch

src/constants.js (no change, 100% coverage maintained)

docs/

  • AGENTS.md: Added internal helpers, immutable mode rules, caching, indexing, batch ops, test strategy, refactoring patterns
  • API.md: Removed clone()/freeze()/merge() from public API; added Internal Helper Methods section
  • TECHNICAL_DOCUMENTATION.md: Added helper methods, updated Immutability Model and cache protection docs

coverage.txt

  • Line: 99.73% → 100.00%
  • Branch: 97.50% → 97.86%
  • Functions: 97.62% → 97.62%

Testing

  • 231 tests pass, 0 failures

Commits (4)

  1. 4dba4f5 — DRY refactoring helpers and consolidate getIndexKeys
  2. dfd268f — Coverage fix: test clear() → set() index recreation
  3. e6eadd2 — AGENTS.md expansion with helpers, patterns, strategy
  4. 2bdf030 — API and technical docs update

Extract #freezeResult(), #fromCache(), and #toCache() private helpers to eliminate
repeated Object.freeze return patterns across 10+ methods. Consolidate #getIndexKeys
and #getIndexKeysForWhere into a single parametrized #getIndexKeysFrom method
(2 methods → 1, removing 62 lines of duplicate code).
Add 'should recreate index after clear on same store' test to achieve
100% line coverage across haro.js.
- Remove clone(), freeze(), merge() from public API (all are private)
- Add Internal Helper Methods section documenting #freezeResult, #fromCache,
  #toCache, #getIndexKeysFrom
- Update Immutability Model to reference centralized #freezeResult()
- Update cache mutation protection to reference #fromCache/#toCache
- Clarify internal vs public utility methods
@avoidwork avoidwork merged commit fa19e05 into master Apr 19, 2026
4 checks passed
@avoidwork avoidwork deleted the audit2 branch April 19, 2026 17:44
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