@nestbolt/soft-delete
Installation
Install @nestbolt/soft-delete and its required and optional peer dependencies.
Install the Package
Install @nestbolt/soft-delete using your preferred package manager:
npm install @nestbolt/soft-deleteyarn add @nestbolt/soft-deletepnpm add @nestbolt/soft-deletePeer Dependencies
The following packages are required peer dependencies. In a typical NestJS project, most of these are already installed:
| Package | Required Version | Purpose |
|---|---|---|
@nestjs/common | ^10.0.0 || ^11.0.0 | NestJS core decorators and utilities |
@nestjs/core | ^10.0.0 || ^11.0.0 | NestJS application core (ModuleRef for optional event emitter resolution) |
typeorm | ^0.3.0 | ORM used for the underlying repositories and subscribers |
reflect-metadata | ^0.1.13 || ^0.2.0 | Metadata reflection for the @SoftDeletable() decorator |
Install any missing peer dependencies:
npm install @nestjs/common @nestjs/core typeorm reflect-metadataDatabase Setup
@nestbolt/soft-delete does not ship its own table -- it operates on a column you add to each soft-deletable entity. Add a nullable timestamp column called deleted_at (or whatever you configure):
@Column({ name: "deleted_at", type: "datetime", nullable: true, default: null })
deletedAt!: Date | null;The package never reads or writes created_at / updated_at -- only the deleted-at column it's configured for.
Optional Dependencies
Event Emitter (Soft-Delete Lifecycle Events)
Required if you want to listen to soft-delete.deleted, soft-delete.restored, and soft-delete.force-deleted events.
npm install @nestjs/event-emitterSupported versions: ^2.0.0 || ^3.0.0
You also need to register the EventEmitterModule in your application:
import { EventEmitterModule } from "@nestjs/event-emitter";
@Module({
imports: [
EventEmitterModule.forRoot(),
// ... other imports
],
})
export class AppModule {}If @nestjs/event-emitter is not installed or EventEmitterModule is not registered, the package works normally but no events are emitted. The event emitter is resolved lazily and treated as fully optional.
Verifying the Installation
After installing, verify everything is wired correctly by importing the module in your root AppModule:
import { Module } from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { SoftDeleteModule } from "@nestbolt/soft-delete";
@Module({
imports: [
TypeOrmModule.forRoot({
type: "postgres",
// ... your database config
autoLoadEntities: true,
synchronize: true, // development only
}),
SoftDeleteModule.forRoot(),
],
})
export class AppModule {}If the application starts without errors and you see SoftDeleteService initialized in the logs, the installation is complete. Continue to the Quick Start guide to soft-delete your first record.