import * as _nestjs_common from '@nestjs/common'; import { NestModule, DynamicModule, MiddlewareConsumer, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common'; import { S as SoftDeleteModuleOptions, a as SoftDeleteModuleAsyncOptions, P as PrismaDmmfLike, b as SoftDeleteExtensionOptions } from './soft-delete-options.interface-DKjxJO9E.mjs'; export { R as RelationFilterOptions } from './soft-delete-options.interface-DKjxJO9E.mjs'; import { Prisma } from '@prisma/client/extension'; import { Reflector } from '@nestjs/core'; import { Observable } from 'rxjs'; declare class SoftDeleteModule implements NestModule { static forRoot(options: SoftDeleteModuleOptions): DynamicModule; static forRootAsync(options: SoftDeleteModuleAsyncOptions): DynamicModule; configure(consumer: MiddlewareConsumer): void; } interface CascadeHandlerOptions { cascade: Record; deletedAtField: string; deletedByField?: string | null; maxCascadeDepth: number; dmmf: PrismaDmmfLike; } type CascadeLifecycleRunner = (model: string, callback: (client: any) => Promise) => Promise; /** * Handles cascading soft-delete and restore operations by walking * the cascade graph defined in the module options and using Prisma * DMMF metadata to resolve foreign-key relationships. */ declare class CascadeHandler { private readonly cascade; private readonly deletedAtField; private readonly maxCascadeDepth; private readonly dmmf; private readonly fkCache; constructor(options: CascadeHandlerOptions); /** * Finds the primary key field name for a given model by inspecting the * Prisma DMMF datamodel. Falls back to 'id' if the model or PK is not found. */ findPrimaryKey(model: string): string; /** * Finds the foreign key field on the child model that references the parent model * by inspecting the Prisma DMMF datamodel. Results are cached for performance. * * @throws CascadeRelationNotFoundError if no relation from child to parent exists */ findForeignKey(parent: string, child: string): string; /** * Cascades a soft-delete from a parent record to all configured child models. * Recursively walks the cascade graph up to maxCascadeDepth. */ cascadeSoftDelete(prisma: any, parentModel: string, parentId: unknown, deletedAt: Date, depth: number, lifecycle?: CascadeLifecycleRunner): Promise; /** * Cascades a restore from a parent record to all configured child models. * Uses +/-1 second timestamp matching to find children that were soft-deleted * at approximately the same time as the parent. */ cascadeRestore(prisma: any, parentModel: string, parentId: unknown, deletedAt: Date, depth: number, lifecycle?: CascadeLifecycleRunner): Promise; } declare class SoftDeletedEvent { readonly model: string; readonly where: Record; readonly deletedAt: Date; readonly actorId: string | null; readonly count?: number | undefined; static readonly EVENT_NAME: "soft-delete.deleted"; constructor(model: string, where: Record, deletedAt: Date, actorId?: string | null, count?: number | undefined); } declare class RestoredEvent { readonly model: string; readonly where: Record; readonly actorId: string | null; readonly count?: number | undefined; static readonly EVENT_NAME: "soft-delete.restored"; constructor(model: string, where: Record, actorId?: string | null, count?: number | undefined); } declare class PurgedEvent { readonly model: string; readonly count: number; readonly olderThan: Date; static readonly EVENT_NAME: "soft-delete.purged"; constructor(model: string, count: number, olderThan: Date); } declare class SoftDeleteEventEmitter { private readonly eventEmitter; constructor(eventEmitter: any | null); get isEnabled(): boolean; emitSoftDeleted(event: SoftDeletedEvent): void; emitRestored(event: RestoredEvent): void; emitPurged(event: PurgedEvent): void; } declare class SoftDeleteService { private readonly options; private readonly prisma; private readonly cascadeHandler; private readonly eventEmitter; private readonly deletedAtField; private readonly deletedByField; constructor(options: SoftDeleteModuleOptions, prisma: any, cascadeHandler: CascadeHandler | null, eventEmitter: SoftDeleteEventEmitter | null); /** * Helper: get Prisma model delegate by name. * Converts model name (e.g. "User") to camelCase key (e.g. "user"). */ private getModelDelegate; private buildRestoreData; private buildDeletedWhere; private findPrimaryKey; private runLifecycle; /** * Restore a soft-deleted record by setting deletedAt (and optionally deletedBy) back to null. * If cascade is configured, cascade-restores child records as well. */ restore(model: string, where: Record): Promise; /** * Restore all soft-deleted records matching the given filter. * If cascade is configured, cascade-restores child records for each affected parent. */ restoreMany(model: string, options?: { where?: Record; }): Promise<{ count: number; }>; /** * Permanently delete a record, bypassing soft-delete logic. */ forceDelete(model: string, where: Record): Promise; /** * Permanently delete soft-deleted records older than the specified date. * Runs within skipSoftDelete context so the extension does not intercept the deleteMany. */ purge(model: string, options: { olderThan: Date; where?: Record; }): Promise<{ count: number; }>; /** * Execute a callback where all queries include soft-deleted records. */ withDeleted(callback: () => T | Promise): Promise; /** * Execute a callback where only soft-deleted records are returned. */ onlyDeleted(callback: () => T | Promise): Promise; } type SoftDeleteFilterMode = 'default' | 'withDeleted' | 'onlyDeleted'; interface SoftDeleteStore { filterMode: SoftDeleteFilterMode; skipSoftDelete: boolean; actorId?: string | null; withDeletedRelationPaths?: string[]; } declare class SoftDeleteContext { private static storage; /** * Runs a callback within the given soft-delete context store. * * Supports both synchronous and asynchronous callbacks. When the callback * returns a Promise (e.g. a Prisma query), the context is preserved * throughout the entire async chain — including inside Prisma extension * handlers whose internal Promise implementation may not propagate * AsyncLocalStorage context on its own. */ static run(store: SoftDeleteStore, callback: () => T): T; static getFilterMode(): SoftDeleteFilterMode; static isSkipped(): boolean; static getActorId(): string | null; static getWithDeletedRelationPaths(): string[]; static isWithDeletedRelationPath(path: string): boolean; } /** * Creates a Prisma client extension that intercepts delete operations * (converting them to soft-delete updates) and read operations * (injecting deletedAt filters based on the current context). */ declare function createPrismaSoftDeleteExtension(options: SoftDeleteExtensionOptions): ReturnType; declare const WithDeleted: () => _nestjs_common.CustomDecorator; declare const OnlyDeleted: () => _nestjs_common.CustomDecorator; declare const SkipSoftDelete: () => _nestjs_common.CustomDecorator; declare const WithDeletedRelations: (...paths: string[]) => _nestjs_common.CustomDecorator; declare class SoftDeleteFilterInterceptor implements NestInterceptor { private readonly reflector; constructor(reflector: Reflector); intercept(context: ExecutionContext, next: CallHandler): Observable; } declare class SoftDeleteFieldMissingError extends Error { constructor(model: string, field: string); } declare class CascadeRelationNotFoundError extends Error { constructor(parent: string, child: string); } declare class CascadeDmmfMissingError extends Error { constructor(); } declare class RelationDmmfMissingError extends Error { constructor(); } declare const SOFT_DELETE_MODULE_OPTIONS: unique symbol; declare const SOFT_DELETE_PRISMA_SERVICE: unique symbol; export { CascadeDmmfMissingError, CascadeRelationNotFoundError, OnlyDeleted, PrismaDmmfLike, PurgedEvent, RelationDmmfMissingError, RestoredEvent, SOFT_DELETE_MODULE_OPTIONS, SOFT_DELETE_PRISMA_SERVICE, SkipSoftDelete, SoftDeleteContext, SoftDeleteEventEmitter, SoftDeleteExtensionOptions, SoftDeleteFieldMissingError, SoftDeleteFilterInterceptor, type SoftDeleteFilterMode, SoftDeleteModule, SoftDeleteModuleAsyncOptions, SoftDeleteModuleOptions, SoftDeleteService, type SoftDeleteStore, SoftDeletedEvent, WithDeleted, WithDeletedRelations, createPrismaSoftDeleteExtension };