mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
add interface to generic pattern
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { Result } from 'neverthrow';
|
||||
import { ZodError} from 'zod';
|
||||
|
||||
// Define a type for the Result of repository operations
|
||||
export type RepositoryResult<T, E> = Result<T, Error | ZodError<E>>;
|
||||
|
||||
export abstract class IDexieRepository<T, R> {
|
||||
|
||||
abstract insert(document: T): Promise<RepositoryResult<number, T>>
|
||||
|
||||
abstract insertMany(documents: T[]): Promise<RepositoryResult<number[], ZodError<T>>>
|
||||
|
||||
abstract update(id: any, updatedDocument: Partial<T>) : Promise<RepositoryResult<number, T>>
|
||||
|
||||
abstract delete(id: any): Promise<RepositoryResult<void, T>>
|
||||
|
||||
abstract findById(id: any) : Promise<RepositoryResult<R, any>>
|
||||
|
||||
abstract find(filter: Partial<T>): Promise<RepositoryResult<R[], T[]>>
|
||||
|
||||
abstract findOne(filter: Partial<T>): Promise<RepositoryResult<T | undefined, T>>
|
||||
|
||||
abstract findAll(): Promise<RepositoryResult<T[], T>>
|
||||
|
||||
abstract count(filter?: Object): Promise<RepositoryResult<number, T>>
|
||||
}
|
||||
Reference in New Issue
Block a user