- Audited undoRedo utility: completely unused (no imports found) - Only type exports remain (WithUndoRedo) but also unused - Previously removed from Library Store in Action 4.1.2.5 - Safe to remove (Action 4.6.1.10) - Audited stateNormalization utility: only used in outdated test - Only createEmptyNormalized used in stores.test.ts - Tests check obsolete Library Store structure (items/favorites) - Library Store migrated to React Query in Action 4.1.2.6 - Safe to remove after updating test file (Action 4.6.1.12) - Created audit documentation: - apps/web/src/docs/UNDOREDO_UTILITY_AUDIT.md - apps/web/src/docs/STATENORMALIZATION_UTILITY_AUDIT.md - Actions 4.6.1.9 and 4.6.1.11 complete
3 KiB
3 KiB
StateNormalization Utility Audit
Date: 2025-01-27
Action: 4.6.1.11
Status: ✅ Complete
Summary
The stateNormalization utility (apps/web/src/utils/stateNormalization.ts) is only used in an outdated test file that tests obsolete Library Store functionality. The Library Store no longer uses normalized state structure (migrated to React Query in Action 4.1.2.6).
Usage Analysis
Imports
- ✅ One import found:
apps/web/src/test/stores.test.ts(line 7)- Imports
createEmptyNormalizedfunction - Used in tests for Library Store (lines 158-159)
- Tests are outdated - they test
state.itemsandstate.favoriteswhich no longer exist
- Imports
Functions Exported
normalize<T>()- Normalize array to normalized statedenormalize<T>()- Convert normalized state back to arrayaddToNormalized<T>()- Add item to normalized stateupdateInNormalized<T>()- Update item in normalized stateremoveFromNormalized<T>()- Remove item from normalized statereplaceNormalized<T>()- Replace all itemsmergeNormalized<T>()- Merge items into normalized stategetById<T>()- Get item by IDgetByIds<T>()- Get multiple items by IDshasId<T>()- Check if item existsgetCount<T>()- Get count of itemscreateEmptyNormalized<T>()- Create empty normalized statereorderNormalized<T>()- Reorder items
Only createEmptyNormalized is used, and only in outdated tests.
Other "normalize" Matches
The grep found many other "normalize" functions, but they are different utilities:
normalizeId()/normalizeObjectIds()- ID normalization (different utility, still used)normalizeUrl()- URL normalization (different utility, still used)normalizeDate()- Date normalization (different utility, still used)normalizeError()- Error normalization (different utility, still used)normalizeEndpoint()- API endpoint normalization (different utility, still used)
These are not related to stateNormalization.ts.
Historical Context
- Previously used by Library Store to normalize
itemsandfavoritesarrays into{ byId, allIds }structure - Removed in Action 4.1.2.6 when Library Store domain data was migrated to React Query
- React Query handles data fetching and caching, making normalization unnecessary
Current State
The Library Store now only contains UI state (filters):
export interface LibraryState {
filters: {
type?: string;
search?: string;
};
}
Domain data (items, favorites) is managed by React Query hooks.
Recommendation
✅ Safe to remove - The utility is only used in outdated tests. However:
- Option A (Recommended): Update
apps/web/src/test/stores.test.tsto remove outdated Library Store tests, then delete the utility - Option B: Delete the utility and fix the test file (it will fail, but tests are already outdated)
Next Steps
- Action 4.6.1.12: Remove stateNormalization if unused ✅ (confirmed unused, but test file needs update)