--- title: Normalizers tags: - frontend - data-transformation --- # Normalizers > [!info] File: `react_frontend/src/lib/normalizers.ts` ## Overview The backend returns Sequelize model instances serialized as JSON. Field naming is inconsistent (mix of camelCase from model definitions and snake_case from raw SQL). Normalizers transform backend responses into consistent frontend [[Types]]. ## Functions ### `normalizeMedia(media)` Handles field aliases: - `isLocal` / `is_local` → `isLocal` - `isSelected` / `is_selected` → `isSelected` - `isCustom` / `is_custom` → `isCustom` - `isFavorit` / `is_favorit` → `isFavorit` ### `normalizeCredit(credit)` Handles the `person` / `people` alias from Sequelize: - Backend may return `credit.person` or `credit.people` - Normalizes to `credit.people` ### `normalizeGenres(genres)` Handles two formats: - Array of strings (`["Action", "Drama"]`) - Array of objects (`[{ id: 28, name: "Action" }]`) - Normalizes to array of `Genre` objects ### `normalizeEntry(entry)` Full entry normalization — the main transformer: - Coerces TMDB IDs to numbers - Normalizes nested `entry_ids`, `entry_ratings`, `genres`, `networks` - Normalizes all `medias` via `normalizeMedia` - Normalizes all `entry_seens` - Normalizes all `seasons` ### `normalizeCollection(collection)` Handles field aliases: - `tmdbId` / `tmdb_id` → `tmdb_id` - `posterPath` / `poster_path` → `poster_path` - `backdropPath` / `backdrop_path` → `backdrop_path` - `isUserCollection` / `is_user_collection` → `isUserCollection` ## Why This Exists Sequelize model definitions use camelCase (`isLocal`, `tmdbId`) but some queries return snake_case. The frontend expects consistent snake_case for most fields. The normalizer layer ensures the frontend [[Types]] are always consistent regardless of backend response format.