base.repository.ts•1.24 kB
/**
* Base repository interfaces
*/
/**
* Base repository interface for all repositories
*/
export interface IRepository<T, K> {
findById(id: K): Promise<T | null>;
findAll(): Promise<T[]>;
create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>): Promise<T>;
update(id: K, data: Partial<T>): Promise<T>;
delete(id: K): Promise<boolean>;
}
/**
* Search options for repositories
*/
export interface SearchOptions {
skip?: number;
take?: number;
orderBy?: Record<string, 'asc' | 'desc'>;
where?: Record<string, any>;
}
/**
* Search results with pagination metadata
*/
export interface SearchResult<T> {
items: T[];
total: number;
page: number;
limit: number;
totalPages: number;
hasNext: boolean;
hasPrevious: boolean;
}
/**
* Extended repository interface with search functionality
*/
export interface ISearchableRepository<T, K> extends IRepository<T, K> {
search(options: SearchOptions): Promise<SearchResult<T>>;
}
/**
* Transaction callback function type
*/
export type TransactionCallback<T> = (tx: any) => Promise<T>;
/**
* Repository interface with transaction support
*/
export interface ITransactionalRepository {
transaction<T>(callback: TransactionCallback<T>): Promise<T>;
}