import { RepositoryTransformOptions } from "../common"; import { Context } from "../shared-context"; import { FilterQuery as InternalFilterQuery, FindOptions, UpsertWithReplaceConfig } from "./index"; import { EntityClass } from "@mikro-orm/core"; import { IDmlEntity, InferTypeOf } from "../dml"; type EntityClassName = string; type EntityValues = { id: string; }[]; /** * Either infer the properties from a DML object or from a Mikro orm class prototype. */ export type InferRepositoryReturnType = T extends IDmlEntity ? InferTypeOf : EntityClass["prototype"]; export type PerformedActions = { created: Record; updated: Record; deleted: Record; }; /** * Data access layer (DAL) interface to implements for any repository service. * This layer helps to separate the business logic (service layer) from accessing the * ORM directly and allows to switch to another ORM without changing the business logic. */ interface BaseRepositoryService { transaction(task: (transactionManager: TManager) => Promise, context?: { isolationLevel?: string; transaction?: TManager; enableNestedTransactions?: boolean; }): Promise; getFreshManager(): TManager; getActiveManager(): TManager; serialize(data: any, options?: any): Promise; } export interface RepositoryService extends BaseRepositoryService { find(options?: FindOptions, context?: Context): Promise[]>; findAndCount(options?: FindOptions, context?: Context): Promise<[InferRepositoryReturnType[], number]>; create(data: any[], context?: Context): Promise[]>; update(data: { entity: any; update: any; }[], context?: Context): Promise[]>; delete(idsOrPKs: FindOptions["where"], context?: Context): Promise; /** * Soft delete entities and cascade to related entities if configured. * * @param idsOrFilter * @param context * * @returns [T[], Record] the second value being the map of the entity names and ids that were soft deleted */ softDelete(idsOrFilter: string | string[] | InternalFilterQuery | InternalFilterQuery[], context?: Context): Promise<[InferRepositoryReturnType[], Record]>; restore(idsOrFilter: string[] | InternalFilterQuery, context?: Context): Promise<[InferRepositoryReturnType[], Record]>; upsert(data: any[], context?: Context): Promise[]>; upsertWithReplace(data: any[], config?: UpsertWithReplaceConfig>, context?: Context): Promise<{ entities: InferRepositoryReturnType[]; performedActions: PerformedActions; }>; } export interface TreeRepositoryService extends BaseRepositoryService { find(options?: FindOptions, transformOptions?: RepositoryTransformOptions, context?: Context): Promise[]>; findAndCount(options?: FindOptions, transformOptions?: RepositoryTransformOptions, context?: Context): Promise<[InferRepositoryReturnType[], number]>; create(data: unknown[], context?: Context): Promise[]>; delete(ids: string[], context?: Context): Promise; } /** * @interface * * An object that is used to specify an entity's related entities that should be soft-deleted when the main entity is soft-deleted. */ export type SoftDeleteReturn = { /** * An array of strings, each being the ID attribute names of the entity's relations. */ returnLinkableKeys?: TReturnableLinkableKeys[]; }; /** * @interface * * An object that is used to specify an entity's related entities that should be restored when the main entity is restored. */ export type RestoreReturn = { /** * An array of strings, each being the ID attribute names of the entity's relations. */ returnLinkableKeys?: TReturnableLinkableKeys[]; }; export {}; //# sourceMappingURL=repository-service.d.ts.map