|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Commands |
| 4 | + |
| 5 | +### Development |
| 6 | + |
| 7 | +- `pnpm dev` - Watch mode for playground file development |
| 8 | +- `pnpm test` - Run all tests |
| 9 | +- `pnpm test:watch` - Run tests in watch mode |
| 10 | +- `pnpm test:coverage` - Run tests with coverage report |
| 11 | + |
| 12 | +### Validation & Build |
| 13 | + |
| 14 | +- `pnpm lint` - Run ESLint |
| 15 | +- `pnpm lint:fix` - Run ESLint with auto-fix |
| 16 | +- `pnpm format` - Format code with Prettier |
| 17 | +- `pnpm format:check` - Check code formatting |
| 18 | +- `pnpm build` - Build distribution files (ESM, CJS, UMD) |
| 19 | +- `pnpm verify` - Full validation: format check, lint, test coverage, and build |
| 20 | + |
| 21 | +### Running Individual Tests |
| 22 | + |
| 23 | +To run a single test file: |
| 24 | + |
| 25 | +```bash |
| 26 | +pnpm vitest run src/user/getUserProfile.test.ts |
| 27 | +``` |
| 28 | + |
| 29 | +To run tests matching a pattern: |
| 30 | + |
| 31 | +```bash |
| 32 | +pnpm vitest run -t "getUserProfile" |
| 33 | +``` |
| 34 | + |
| 35 | +## Architecture |
| 36 | + |
| 37 | +This is a TypeScript library for the RetroAchievements API with a modular, domain-driven structure. Each API domain (user, game, achievement, etc.) is organized as a separate module with consistent patterns. |
| 38 | + |
| 39 | +### Key Architectural Patterns |
| 40 | + |
| 41 | +1. **Function Structure**: Every API function follows this exact pattern: |
| 42 | + |
| 43 | +```typescript |
| 44 | +export const getFunctionName = async ( |
| 45 | + authorization: AuthObject, |
| 46 | + payload: { |
| 47 | + /* typed parameters */ |
| 48 | + } |
| 49 | +): Promise<ReturnType> => { |
| 50 | + const url = buildRequestUrl(/* endpoint details */); |
| 51 | + const rawResponse = await call({ url }); |
| 52 | + return serializeProperties(rawResponse); |
| 53 | +}; |
| 54 | +``` |
| 55 | + |
| 56 | +2. **Module Organization**: Each domain directory contains: |
| 57 | + |
| 58 | + - Function implementations (e.g., `getUserProfile.ts`) |
| 59 | + - Tests with MSW mocks (e.g., `getUserProfile.test.ts`) |
| 60 | + - TypeScript models in `models/` subdirectory |
| 61 | + - Index file with barrel exports |
| 62 | + |
| 63 | +3. **Core Utilities** (in `src/utils/internal/`): |
| 64 | + |
| 65 | + - `call()` - HTTP client wrapper with error handling |
| 66 | + - `buildRequestUrl()` - Constructs API URLs with auth params |
| 67 | + - `serializeProperties()` - Transforms API responses (snake_case to camelCase, type coercion) |
| 68 | + |
| 69 | +4. **Testing Approach**: |
| 70 | + - All API calls are mocked using MSW (Mock Service Worker) |
| 71 | + - Tests verify both successful responses and error handling |
| 72 | + - Coverage requirements: 95% statements and lines |
| 73 | + |
| 74 | +### Important Conventions |
| 75 | + |
| 76 | +- All API functions require an `AuthObject` as the first parameter |
| 77 | +- Response properties are automatically converted from snake_case to camelCase |
| 78 | +- Numeric strings in responses are converted to numbers |
| 79 | +- ISO date strings are converted to Date objects |
| 80 | +- Every function must have comprehensive JSDoc comments with examples |
| 81 | +- Commit messages follow conventional commits format |
0 commit comments