mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 18:52:08 +01:00
- Implement repository pattern for data access layer - Add comprehensive service layer for business logic - Create scheduler management system with health monitoring - Add bounded buffer utility for memory management - Enhance security audit logging with retention policies
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
/**
|
|
* Base repository interface with common CRUD operations
|
|
*/
|
|
export interface BaseRepository<T, ID = string> {
|
|
findById(id: ID): Promise<T | null>;
|
|
findMany(options?: FindManyOptions<T>): Promise<T[]>;
|
|
create(data: CreateInput<T>): Promise<T>;
|
|
update(id: ID, data: UpdateInput<T>): Promise<T | null>;
|
|
delete(id: ID): Promise<boolean>;
|
|
count(options?: CountOptions<T>): Promise<number>;
|
|
}
|
|
|
|
/**
|
|
* Generic find options interface
|
|
*/
|
|
export interface FindManyOptions<T> {
|
|
where?: Partial<T>;
|
|
orderBy?: Record<keyof T, "asc" | "desc">;
|
|
skip?: number;
|
|
take?: number;
|
|
include?: Record<string, boolean>;
|
|
}
|
|
|
|
/**
|
|
* Generic count options interface
|
|
*/
|
|
export interface CountOptions<T> {
|
|
where?: Partial<T>;
|
|
}
|
|
|
|
/**
|
|
* Create input type - excludes auto-generated fields
|
|
*/
|
|
export type CreateInput<T> = Omit<T, "id" | "createdAt" | "updatedAt">;
|
|
|
|
/**
|
|
* Update input type - excludes auto-generated fields and makes all optional
|
|
*/
|
|
export type UpdateInput<T> = Partial<Omit<T, "id" | "createdAt" | "updatedAt">>;
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|