feat: add type-safe boundaries for analytics mock data with explicit … - #392
Merged
Lakes41 merged 1 commit intoAug 19, 2026
Conversation
…AnalyticsSummary type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extract analytics mock data into a dedicated, type-safe module that enforces shape validation at compile time. MOCK_ANALYTICS_SUMMARY is now explicitly typed as AnalyticsSummary with the satisfies keyword, ensuring that any shape changes are caught by TypeScript before runtime.
Changes
New Files
lib/api/analytics/types.ts: Focused module boundary with type re-exports and runtime type guards (isAnalyticsSummary, isResourceAccessCount)
lib/api/analytics/mock.ts: Analytics fixture data with explicit typing and type-safe accessor functions
lib/api/analytics/mock.test.ts: Comprehensive test coverage (16 tests) for type safety and data consistency
Modified Files
lib/api/mock.ts:
Added imports from ./analytics/mock module
Removed generateMockMemberGrowth() function and MOCK_ANALYTICS_SUMMARY definition
Updated MockAccessApi.analytics methods to use accessor functions (getMemberGrowth(), getResourceAccess())
What's Fixed
Type Safety
MOCK_ANALYTICS_SUMMARY is now explicitly typed as AnalyticsSummary
Uses as const satisfies AnalyticsSummary for compile-time shape checking
Accessor functions return explicit types: AnalyticsSummary['resourceAccess'], not any
Focused Boundaries
Analytics data isolated in dedicated lib/api/analytics/ module
Clear separation of concerns: types, mock data, and tests
Type guards enable runtime validation when parsing external data
Backward Compatibility
Re-exports preserve existing import paths
MOCK_ANALYTICS_SUMMARY still exported for direct access
No changes to mock data values—structure only
Testing
16 tests verify:
Mock structure (resourceAccess field presence and array type)
AnalyticsSummary shape (all required fields present with correct types)
Accessor functions (return correct data with proper types)
Type safety (compile-time type assignments validate shape)
Data consistency (monotonic growth, count relationships, non-negative values)
All tests pass runtime validation and compile with TypeScript satisfies checking.
How to Test
bash
npm test # Run analytics mock tests
npm run typecheck # Verify TypeScript compilation
npm run build # Full build verification
Related Issue
Fixes #385: Add focused type-safe boundaries for analytics mock data
Acceptance Criteria Met
✅ AnalyticsSummary interface defined with explicit field types
✅ MOCK_ANALYTICS_SUMMARY explicitly typed as AnalyticsSummary
✅ satisfies AnalyticsSummary used for compile-time shape checking
✅ resourceAccess typed as AnalyticsSummary['resourceAccess'] (not any)
✅ Access functions have typed return values (not any/unknown)
✅ Analytics mock extracted to focused module
✅ All existing consumers receive same data shape
✅ TypeScript compilation succeeds
✅ All tests pass
✅ Mock data values unchanged (structure only)