cds-softdelete-plugin
A CAP plugin that turns DELETE into a flag on the record: annotated entities keep the row, record who deleted it and when, flag composition children with it, and drop out of reads.
A softdelete aspect adds isDeleted, deletedAt and deletedBy to an entity. On a service projection carrying @softdelete.enabled, DELETE becomes an UPDATE that sets the flag, composition children are flagged with their parent, and READ filters flagged rows out. Both parent and child projections need the annotation — the aspect on the persistence entity does not carry the behaviour into the service by itself.
Facts
Where it sits
Who is behind it
In the atlas: maintains 47, contributes to 47, wrote 10@miyasutamaintainer
Before choosing this
Conditions
LicenceSAP Developer License Agreement 3.2 CAP§ 1, 2, 3A cds-plugin is used with SAP CAP materials, or an artifact is explicitly identified as a CAP plugin or application.
- § 1 License. Productive customer applications are limited to SAP BTP or another SAP-licensed platform, and mass extraction to a non-SAP product is restricted except where solely required for SAP interoperability.
- § 2 Intellectual Property. The agreement retains SAP's rights in the covered materials and limits making APIs, tools or software available to third parties, while preserving ownership of customer applications subject to SAP's underlying rights.
- § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.
PracticalFunctional boundary
It changes what DELETE means for every client of the annotated projection, so anything that must actually remove a row — an erasure request, a retention job — has to go around it.
What it declares
Every artifact
- Type
- CDS plugin
- Origin
- Independently maintained
- Runtime
- Node.js
As a CDS plugin
- Declared for
- >=9
- Distributed through
- npm
Connections
CAP Java plugin for soft delete with a softdelete aspect
Deleting a record without removing it
Download
Install
npm add cds-softdelete-pluginDerived from the package name. No recipe recorded; the README has the configuration.
README
quoted from miyasuta/cds-softdelete-plugin under MIT, readcds-softdelete-plugin
A plugin for implementing soft delete functionality in SAP Cloud Application Programming Model (CAP) applications.
What It Does
This plugin automatically converts DELETE operations to soft deletes (marking records as deleted instead of removing them) and filters out soft-deleted records from READ operations. When a parent entity is deleted, its composition children are automatically soft-deleted as well.
Installation
npm install cds-softdelete-plugin
Quick Start
1. Add the softdelete aspect to your entities
// db/schema.cds
using { softdelete } from 'cds-softdelete-plugin';
entity Orders: softdelete {
key ID : UUID;
total : Decimal(9,2);
items : Composition of many OrderItems on items.order = $self;
}
entity OrderItems: softdelete {
key ID : UUID;
order : Association to Orders;
quantity : Integer;
}
The softdelete aspect adds these fields:
isDeleted(Boolean) - Deletion flagdeletedAt(DateTime) - Deletion timestampdeletedBy(String) - User who deleted the record
2. Enable soft delete in your service
Add @softdelete.enabled to every entity that should use soft delete:
// srv/order-service.cds
service OrderService {
@softdelete.enabled
entity Orders as projection on my.Orders;
@softdelete.enabled
entity OrderItems as projection on my.OrderItems;
}
Important: Both parent and child entities need @softdelete.enabled for cascade delete to work. The annotation is required because service projections do not automatically inherit aspect behavior.
How It Works
DELETE Operations
Delete operations are converted to updates that set isDeleted=true:
DELETE /Orders(123)
// Sets: isDeleted=true, deletedAt=<timestamp>, deletedBy=<user>
Composition children are automatically soft-deleted when the parent is deleted.
READ Operations
Soft-deleted records are automatically excluded from list queries:
GET /Orders
// Only returns records where isDeleted=false
Retrieving Deleted Data
Use isDeleted=true filter to access soft-deleted records:
GET /Orders?$filter=isDeleted eq true
Draft Support
Soft delete works in draft mode (Fiori Elements Object Page). Note that in draft edit mode, deleted items may remain visible until the draft is activated. This is expected behavior to ensure proper synchronization.
Limitations
- Draft Edit Mode: Deleted items remain visible in draft edit mode until the draft is activated
License
Links
History
Features 1
Notes
Added
- Physical deletion test case (DEL-09) to verify entities without @softdelete.enabled are physically deleted
Features 2, Changed 1
Notes
Added
- Navigation path deletion test cases (DEL-03-nav, DEL-05-nav, DEL-07-nav)
- Grandchild cascade deletion test cases (DEL-03-extended, DEL-05-extended)
Changed
- Improved test coverage for composition hierarchy deletion scenarios
Features 9, Other 4
Notes
First Major Release
This is the first stable release of cds-softdelete-plugin. The plugin is considered production-ready with comprehensive test coverage and well-defined behavior.
Features
- Automatic Soft Delete: DELETE operations are automatically converted to UPDATE operations that set
isDeleted=true,deletedAt, anddeletedBy - Automatic Filtering: READ operations automatically exclude soft-deleted records (where
isDeleted=false) - Cascade Delete: When a parent entity is deleted, all composition children are automatically soft-deleted recursively
- Draft Support: Full support for SAP Fiori Elements draft mode, including draft entity soft delete and proper synchronization on activation
- Key-Based Access: Direct access by key (e.g.,
Orders(ID)) returns records regardless ofisDeletedstatus, allowing access to deleted records - Explicit Filter Support: Users can explicitly query deleted records using
$filter=isDeleted eq true - Validation: Server startup validation ensures entities with
@softdelete.enabledhave all required fields (isDeleted,deletedAt,deletedBy) - Field Protection: All soft delete fields are protected with
@readonlyannotation to prevent direct user modification - Idempotent Operations: Deleting an already soft-deleted record succeeds without side effects (no timestamp updates)
Technical Details
- Test Coverage: 38 test cases covering all scenarios (100% coverage)
- Deletion operations (8 test cases)
- Active entity reads (16 test cases)
- Draft entity reads (7 test cases)
- Draft activation (2 test cases)
- Validation (2 test cases)
- Field protection (4 test cases)
- Specification: Comprehensive specification documentation in
docs/project/spec.md - Compatibility: Requires
@sap/cds >= 9
Known Behavior
- Draft Edit Mode: Deleted items remain visible in draft edit mode until the draft is activated (this is by design to ensure proper synchronization)
- Automatic Soft Delete: DELETE operations are automatically converted to UPDATE operations that set
Features 3, Fixes 1
Notes
Added
- Validation test cases for entity configuration
- Field protection test cases for readonly fields
- Comprehensive test specification documentation
Fixed
- Idempotency check for soft delete operations to prevent
deletedAtupdates on already deleted records
Features 2, Fixes 1
Notes
Added
- Plugin specification documentation
- Test specification documentation
Fixed
- Draft entity filtering limitation documented as expected behavior
Fixes 1
Notes
Fixed
- Prevent overwriting
deletedAt/deletedByon already soft-deleted records during cascade delete
- Prevent overwriting
Fixes 2
Notes
Fixed
- Exclude draft virtual keys from cascade soft delete
- Propagate parent
isDeletedstatus to children in key-based access
Features 2
Notes
Added
- Initial release with basic soft delete functionality
- Validation for entities with
@softdelete.enabled
Others providing
Compare all 2 on the Soft delete page →- cds-feature-softdeletecds-feature-softdeleteThe CAP Java counterpart to cds-softdelete-plugin: the same softdelete aspect, the same annotation, DELETE rewritten as a flag.independent, capCAP Java plugin for soft delete with a softdelete aspect
- cds-feature-softdeletecds-feature-softdeleteThe CAP Java counterpart to cds-softdelete-plugin: the same softdelete aspect, the same annotation, DELETE rewritten as a flag.independent, capCAP Java plugin for soft delete with a softdelete aspect
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
History in the atlas
- Entered unmapped because no capability fitted: change-tracking is history of changes, data-privacy is close to the opposite, and inventing an edge would have been worse than the gap. The capability now exists, so the edge is the honest one rather than the nearest one.
- First seen.
For your agent
- Ref
artifact:miyasuta-cds-softdelete-plugin- JSON
- /artifacts/miyasuta-cds-softdelete-plugin.json
- MCP
- Connecting an agent