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:
98
src/lib/server/models/repository-version.ts
Normal file
98
src/lib/server/models/repository-version.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
export interface RepositoryVersionEntityProps {
|
||||
id: string;
|
||||
repository_id: string;
|
||||
tag: string;
|
||||
title: string | null;
|
||||
state: 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
total_snippets: number | null;
|
||||
indexed_at: number | null;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
export class RepositoryVersionEntity {
|
||||
id: string;
|
||||
repository_id: string;
|
||||
tag: string;
|
||||
title: string | null;
|
||||
state: 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
total_snippets: number | null;
|
||||
indexed_at: number | null;
|
||||
created_at: number;
|
||||
|
||||
constructor(props: RepositoryVersionEntityProps) {
|
||||
this.id = props.id;
|
||||
this.repository_id = props.repository_id;
|
||||
this.tag = props.tag;
|
||||
this.title = props.title;
|
||||
this.state = props.state;
|
||||
this.total_snippets = props.total_snippets;
|
||||
this.indexed_at = props.indexed_at;
|
||||
this.created_at = props.created_at;
|
||||
}
|
||||
}
|
||||
|
||||
export interface RepositoryVersionProps {
|
||||
id: string;
|
||||
repositoryId: string;
|
||||
tag: string;
|
||||
title: string | null;
|
||||
state: 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
totalSnippets: number;
|
||||
indexedAt: Date | null;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export class RepositoryVersion {
|
||||
id: string;
|
||||
repositoryId: string;
|
||||
tag: string;
|
||||
title: string | null;
|
||||
state: 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
totalSnippets: number;
|
||||
indexedAt: Date | null;
|
||||
createdAt: Date;
|
||||
|
||||
constructor(props: RepositoryVersionProps) {
|
||||
this.id = props.id;
|
||||
this.repositoryId = props.repositoryId;
|
||||
this.tag = props.tag;
|
||||
this.title = props.title;
|
||||
this.state = props.state;
|
||||
this.totalSnippets = props.totalSnippets;
|
||||
this.indexedAt = props.indexedAt;
|
||||
this.createdAt = props.createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
export interface RepositoryVersionDtoProps {
|
||||
id: string;
|
||||
repositoryId: string;
|
||||
tag: string;
|
||||
title: string | null;
|
||||
state: 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
totalSnippets: number;
|
||||
indexedAt: Date | null;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export class RepositoryVersionDto {
|
||||
id: string;
|
||||
repositoryId: string;
|
||||
tag: string;
|
||||
title: string | null;
|
||||
state: 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
totalSnippets: number;
|
||||
indexedAt: Date | null;
|
||||
createdAt: Date;
|
||||
|
||||
constructor(props: RepositoryVersionDtoProps) {
|
||||
this.id = props.id;
|
||||
this.repositoryId = props.repositoryId;
|
||||
this.tag = props.tag;
|
||||
this.title = props.title;
|
||||
this.state = props.state;
|
||||
this.totalSnippets = props.totalSnippets;
|
||||
this.indexedAt = props.indexedAt;
|
||||
this.createdAt = props.createdAt;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user