2.1.1 • Published 5 months ago
@payload-bites/soft-delete v2.1.1
Soft delete
Never lose your Payload documents again, soft delete is here to save the day.
https://github.com/user-attachments/assets/e8263a98-cb5b-447d-a6c5-b200091408c9
Compatibility table
| Payload version | Soft delete version |
|---|---|
| v3.23.0 or earlier | Incompatible |
| v3.24.0 to 3.38.0 | v1.x |
| v3.39.0 or later | v2.x |
Quick start
- Install the plugin:
pnpm add @payload-bites/soft-delete- Add the plugin to your
payload.config.ts:
// ...
import { softDeletePlugin } from "@payload-bites/soft-delete";
export default buildConfig({
// ...
plugins: [
// ...
softDeletePlugin({
collections: {
posts: {},
"posts-with-drafts": {
// ...
enableRestore: false,
enableHardDelete: false,
softDeleteAccess: (args) => args.req.user.role === "admin",
},
},
}),
],
});Defaults
For defaults, refer to defaults.ts.
Options
For options, refer to types.ts.
Querying
You can retrieve active or soft deleted documents by checking for the existence of the deletedAt field.
Local API
const result = await payload.find({
collection: "posts",
where: {
deletedAt: {
exists: false,
},
},
});REST API
import { stringify } from "qs-esm";
import type { Where } from "payload";
const query: Where = {
deletedAt: {
exists: false,
},
};
const getPosts = async () => {
const stringifiedQuery = stringify(
{
where: query,
},
{ addQueryPrefix: true },
);
const response = await fetch(
`http://localhost:3000/api/posts${stringifiedQuery}`,
);
};GraphQL API
query {
Posts(where: { deletedAt: { exists: false } }) {
docs {
title
}
}
}Caveats
- It is currently not possible to soft delete a draft document that has invalid fields (e.g. required) unless the document has a previously valid published version or you resolve the invalid fields.
Roadmap
- Add modal to hard delete.
- Enable/disable restore functionality per collection.
- Enable/disable hard delete functionality per collection.
- Schedule automatic deletion after certain number of days.
- Documentation (including API examples).
- Translations.
2.1.1
5 months ago
2.1.0
5 months ago
2.0.2
5 months ago
2.0.1
6 months ago
2.0.0
6 months ago
1.0.4
6 months ago
1.0.3
8 months ago
1.0.2
8 months ago
1.0.1
8 months ago
1.0.0
8 months ago
1.0.0-beta.11
8 months ago
1.0.0-beta.10
8 months ago
1.0.0-beta.9
8 months ago
1.0.0-beta.8
9 months ago
1.0.0-beta.7
9 months ago
1.0.0-beta.6
9 months ago
1.0.0-beta.5
9 months ago
1.0.0-beta.4
9 months ago
1.0.0-beta.3
9 months ago
1.0.0-beta.2
9 months ago
1.0.0-beta.1
9 months ago