mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +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>>
|
||||||
|
}
|
||||||
@@ -2,11 +2,12 @@ import { Result, ok, err } from 'neverthrow';
|
|||||||
import { EntityTable } from 'Dexie';
|
import { EntityTable } from 'Dexie';
|
||||||
import { ZodError, ZodObject, ZodSchema } from 'zod';
|
import { ZodError, ZodObject, ZodSchema } from 'zod';
|
||||||
import { Logger } from 'src/app/services/logger/main/service';
|
import { Logger } from 'src/app/services/logger/main/service';
|
||||||
|
import { IDexieRepository } from '../adapter'
|
||||||
|
|
||||||
// Define a type for the Result of repository operations
|
// Define a type for the Result of repository operations
|
||||||
type RepositoryResult<T, E> = Result<T, Error | ZodError<E>>;
|
type RepositoryResult<T, E> = Result<T, Error | ZodError<E>>;
|
||||||
|
|
||||||
export class DexieRepository<T, R> {
|
export class DexieRepository<T, R> implements IDexieRepository<T, R> {
|
||||||
private table: EntityTable<any, any>;
|
private table: EntityTable<any, any>;
|
||||||
private ZodSchema: ZodSchema<T>
|
private ZodSchema: ZodSchema<T>
|
||||||
private ZodPartialSchema: ZodSchema<T>
|
private ZodPartialSchema: ZodSchema<T>
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './adapter';
|
||||||
|
// export * from './types';
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// export type UpdatedModel = {
|
||||||
|
// matchedCount: number;
|
||||||
|
// modifiedCount: number;
|
||||||
|
// acknowledged: boolean;
|
||||||
|
// upsertedId: unknown | any;
|
||||||
|
// upsertedCount: number;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export type RemovedModel = {
|
||||||
|
// deletedCount: number;
|
||||||
|
// deleted: boolean;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export type CreatedModel = {
|
||||||
|
// id: string;
|
||||||
|
// created: boolean;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export type CreatedOrUpdateModel = {
|
||||||
|
// id: string;
|
||||||
|
// created: boolean;
|
||||||
|
// updated: boolean;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export enum DatabaseOperationEnum {
|
||||||
|
// EQUAL = 'equal',
|
||||||
|
// NOT_EQUAL = 'not_equal',
|
||||||
|
// NOT_CONTAINS = 'not_contains',
|
||||||
|
// CONTAINS = 'contains'
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export type DatabaseOperationCommand<T> = {
|
||||||
|
// property: keyof T;
|
||||||
|
// value: unknown[];
|
||||||
|
// command: DatabaseOperationEnum;
|
||||||
|
// };
|
||||||
Reference in New Issue
Block a user