Skip to content

feat: add type-safe boundaries for analytics mock data with explicit … - #392

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
onyemaechiezekiel9:feat/analytics-mock-type-safety
Aug 19, 2026
Merged

feat: add type-safe boundaries for analytics mock data with explicit …#392
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
onyemaechiezekiel9:feat/analytics-mock-type-safety

Conversation

@onyemaechiezekiel9

Copy link
Copy Markdown
Contributor

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)

@Lakes41
Lakes41 merged commit 61901f5 into Adamantine-guild:main Aug 19, 2026
1 check passed
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.

Add focused type-safe boundaries for analytics mock data

3 participants