refactor: introduce domain model classes and mapper layer

Replace ad-hoc inline row casting (snake_case → camelCase) spread across
services, routes, and the indexing pipeline with explicit model classes
(Repository, IndexingJob, RepositoryVersion, Snippet, SearchResult) and
dedicated mapper classes that own the DB → domain conversion.

- Add src/lib/server/models/ with typed model classes for all domain entities
- Add src/lib/server/mappers/ with mapper classes per entity
- Remove duplicated RawRow interfaces and inline map functions from
  job-queue, repository.service, indexing.pipeline, and all API routes
- Add dtoJsonResponse helper to standardise JSON responses via SvelteKit json()
- Add api-contract.integration.test.ts as a regression baseline

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Giancarmine Salucci
2026-03-25 14:29:49 +01:00
parent 7994254e23
commit 215cadf070
39 changed files with 1339 additions and 562 deletions

View File

@@ -0,0 +1,33 @@
import {
RepositoryVersion,
RepositoryVersionDto,
RepositoryVersionEntity
} from '$lib/server/models/repository-version.js';
export class RepositoryVersionMapper {
static fromEntity(entity: RepositoryVersionEntity): RepositoryVersion {
return new RepositoryVersion({
id: entity.id,
repositoryId: entity.repository_id,
tag: entity.tag,
title: entity.title,
state: entity.state,
totalSnippets: entity.total_snippets ?? 0,
indexedAt: entity.indexed_at != null ? new Date(entity.indexed_at * 1000) : null,
createdAt: new Date(entity.created_at * 1000)
});
}
static toDto(domain: RepositoryVersion): RepositoryVersionDto {
return new RepositoryVersionDto({
id: domain.id,
repositoryId: domain.repositoryId,
tag: domain.tag,
title: domain.title,
state: domain.state,
totalSnippets: domain.totalSnippets,
indexedAt: domain.indexedAt,
createdAt: domain.createdAt
});
}
}