feat: Improve delete API with clear hard delete option

- Single clear way to hard delete: { hard: true }
- Removed confusing soft: false option
- Soft delete remains the default behavior
- Clean, intuitive API: delete() for soft, delete(id, { hard: true }) for hard
- All delete features working: soft, hard, cascade
This commit is contained in:
David Snelling 2025-08-18 18:17:06 -07:00
parent 6b4b67a339
commit 4b4c66b935
10 changed files with 17 additions and 36 deletions

View file

@ -3376,17 +3376,19 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
id: string,
options: {
service?: string // The service that is deleting the data
soft?: boolean // Soft delete (mark as deleted, default: true)
hard?: boolean // Hard delete - completely removes from storage (default: false, soft delete is default)
cascade?: boolean // Delete related verbs (default: false)
force?: boolean // Force delete even if has relationships (default: false)
} = {}
): Promise<boolean> {
// Clear API: use 'hard: true' for hard delete, otherwise soft delete
const isHardDelete = options.hard === true
const opts = {
service: undefined,
soft: true, // Soft delete is default - preserves indexes
cascade: false,
force: false,
...options
service: options.service,
soft: !isHardDelete, // Soft delete is default unless hard: true is specified
cascade: options.cascade || false,
force: options.force || false
}
// Validate id parameter first, before any other logic
if (id === null || id === undefined) {