/** * Base repository interface with common CRUD operations */ export interface BaseRepository { findById(id: ID): Promise; findMany(options?: FindManyOptions): Promise; create(data: CreateInput): Promise; update(id: ID, data: UpdateInput): Promise; delete(id: ID): Promise; count(options?: CountOptions): Promise; } /** * Generic find options interface */ export interface FindManyOptions { where?: Partial; orderBy?: Record; skip?: number; take?: number; include?: Record; } /** * Generic count options interface */ export interface CountOptions { where?: Partial; } /** * Create input type - excludes auto-generated fields */ export type CreateInput = Omit; /** * Update input type - excludes auto-generated fields and makes all optional */ export type UpdateInput = Partial>; /** * Repository error types */ export class RepositoryError extends Error { constructor( message: string, public readonly code: string, public readonly cause?: Error ) { super(message); this.name = "RepositoryError"; } } export class NotFoundError extends RepositoryError { constructor(entity: string, id: string | number) { super(`${entity} with id ${id} not found`, "NOT_FOUND"); } } export class ConflictError extends RepositoryError { constructor(message: string, cause?: Error) { super(message, "CONFLICT", cause); } } export class ValidationError extends RepositoryError { constructor(message: string, cause?: Error) { super(message, "VALIDATION_ERROR", cause); } }