mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { Result } from 'neverthrow';
|
|
import { ZodError} from 'zod';
|
|
import { IDBError } from './types';
|
|
import Dexie, { EntityTable, Table } from 'Dexie';
|
|
|
|
// Define a type for the Result of repository operations
|
|
export type RepositoryResult<T, E> = Result<T, IDBError<E>>;
|
|
export abstract class IDexieRepository<T, R, I = EntityTable<any, any>> {
|
|
|
|
abstract createTransaction(callback: (table: I) => Promise<void>): Promise<void>
|
|
abstract insert(document: T): Promise<RepositoryResult<number, T>>
|
|
|
|
abstract insertMany(documents: T[]): Promise<RepositoryResult<number[], 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 & ILocalModel<T, R, I> | undefined, T>>
|
|
|
|
abstract findAll(): Promise<RepositoryResult<T[], T>>
|
|
|
|
abstract count(filter?: Object): Promise<RepositoryResult<number, T>>
|
|
|
|
abstract clear(): Promise<Result<any, any>>
|
|
}
|
|
|
|
export abstract class ILocalModel<T, R, I = EntityTable<any, any>>{
|
|
abstract save() : Promise<RepositoryResult<number, T>>
|
|
abstract delete()
|
|
}
|