@nestarc/soft-delete
Prisma soft-delete extension for NestJS. Automatically intercepts delete operations, filters deleted records from queries, and supports cascade soft-delete, bulk restore, purge, events, and relation-aware reads.
For the database rules and client boundary behind a production setup, read Prisma Soft Delete: Why deletedAt Alone Is Not Enough.
Current release
Current package version: 0.6.0
Version 0.6 adds first-class Prisma 7 support through Prisma Config, explicit generated-client output, and the PostgreSQL driver adapter. Prisma 5 and 6 remain in the peer range. Cascade and relation filters now require explicit DMMF metadata.
Features
- Automatic soft-delete:
deleteanddeleteManybecomeupdate/updateManysettingdeletedAt - Transparent query filtering:
findMany,findFirst,findUnique,count,aggregate,groupByall exclude soft-deleted rows by default - Opt-in relation filtering for to-many Prisma
includeandselecttrees - Cascade soft-delete and restore across related models
restore(),restoreMany(),forceDelete(), andpurge()operations onSoftDeleteService- Route-decorator control:
@WithDeleted(),@OnlyDeleted(),@SkipSoftDelete(),@WithDeletedRelations() - Optional actor tracking via
deletedByFieldandactorExtractor - Lifecycle events (
SoftDeletedEvent,RestoredEvent,PurgedEvent) via@nestjs/event-emitter - Testing utilities:
TestSoftDeleteModule,expectSoftDeleted,expectNotSoftDeleted,expectCascadeSoftDeleted - Standalone Prisma extension (
createPrismaSoftDeleteExtension) for use without NestJS - Global module — register once, use everywhere
Start Here
- Installation & Quick Start — supported versions and module setup
- Relation Filters — filter soft-deleted children in nested reads
- Cascade & Unique Constraints — cascade behavior and active-row uniqueness
- Restore, Force Delete & Purge — single and bulk recovery operations
- Upgrade to 0.6 — Prisma 7 and explicit DMMF migration notes
- v0.5 Upgrade & Resolved Issues — changes, fixes, and adoption checklist
- API Reference — generated TypeScript documentation
Installation
npm install @nestarc/soft-delete
# or
yarn add @nestarc/soft-delete
# or
pnpm add @nestarc/soft-deleteRequired peer dependencies (install if not already present):
npm install @nestjs/common @nestjs/core @prisma/client reflect-metadata rxjsFor direct PostgreSQL connections with Prisma 7:
npm install @prisma/adapter-pg pgOptional peer dependencies:
# For lifecycle events
npm install @nestjs/event-emitter
# For scheduled purge jobs
npm install @nestjs/scheduleSupported peer ranges are NestJS 10/11 and Prisma 5/6/7. Prisma 7 is the primary development and PostgreSQL E2E target. See the installation guide and Prisma 7 setup guide.