feat(core): add undelete API to reverse soft deletes#76
Merged
Conversation
Closes #60. The spec promises soft-delete recovery, but nothing implemented it — Stack/ScopedStack only exposed delete(). Adds: - StackRecordAdapter.undeleteRecord(id): Promise<StackRecord>, a dedicated adapter method (not routed through the generic updateRecord Partial<StackRecord> merge, which can't express "clear deletedAt" — every adapter treats an undefined field as "leave untouched," so there's no way to signal removal through it). Implemented in MemoryAdapter, record-adapter-sqljs, adapter-api (POST /records/:id/undelete), and wired through combineAdapters() and adapter-local's LocalAdapter. - Stack.undelete(id): idempotent (a non-deleted record returns unchanged), StackNotFoundError for missing/hard-deleted records. - ScopedStack.undelete(id): gated by requireDeletable, the same write-bit-or-delete-grant check as delete() — undelete is delete's inverse, so the same capability governs both directions. Hard delete's owner-only carve-out (#59) is untouched; it has no inverse. - migrateAll() now sweeps soft-deleted records too, so a record migrated while deleted comes back current on undelete instead of stranded on a stale schema. - Spec: §Deletion documents the API and idempotency contract; wire table gains the endpoint. Out of scope, per #60's own framing: version-bump-on-delete/undelete (tracked in #61, which hasn't landed — delete() doesn't bump version either yet, so undelete() stays symmetric with it) and the shared conformance-fixture framework (#52, doesn't exist in this repo yet; covered here with regular adapter-level tests instead).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #60.
The spec promises soft-delete recovery — it's half the stated purpose of record versioning — but nothing implements it.
Stack/ScopedStackexposedelete()and nothing else. #59 sharpened this from "missing polish" to a prerequisite: its trust model for the coarsewritebit ("anything a write-holder does, the owner can undo") is false for every deletion until this exists.What's added
StackRecordAdapter.undeleteRecord(id): Promise<StackRecord>— a dedicated adapter method, not routed through the genericupdateRecord(id, changes: Partial<StackRecord>)grab-bag. That contract can't express "cleardeletedAt": every adapter treats anundefinedfield in the patch as "leave untouched" (confirmed inrecord-adapter-sqljs, which checkschanges.deletedAt !== undefinedbefore including it in theUPDATE), so there's no way to signal removal through it. Implemented inMemoryAdapter,record-adapter-sqljs, andadapter-api(POST /records/:id/undelete), and wired throughcombineAdapters()andadapter-local'sLocalAdapter.Stack.undelete(id)— idempotent: undeleting a record that isn't deleted returns it unchanged, so a retried call after a network blip never fails. Missing record throwsStackNotFoundError; a hard-deleted record is simply missing, so it throws the same way.ScopedStack.undelete(id)— gated byrequireDeletable, the same write-bit-or-delete-grant check asdelete(). Undelete is the inverse of soft delete, so the same capability governs both directions — granting one without the other would be backwards. Hard delete's owner-only carve-out (Record-levelwritestays one bit — but everything it permits must be recoverable, and irreversible verbs get carved out #59, already merged) is untouched; it has no inverse.migrateAll()now sweeps soft-deleted records too (includeDeleted: true, unconditionally), so a record migrated while deleted comes back current on undelete instead of stranded on a stale schema.docs/spec.md§Deletion documents the API and idempotency contract; the wire endpoint table gainsPOST /records/:id/undelete;StackClient's method list gainsundelete.Out of scope (tracked separately, per #60's own framing)
delete()doesn't bumpversiontoday either, soundelete()stays symmetric with it until One versioning rule: every record mutation bumps version and snapshots full prior state (associations and permissions included) #61 lands both together.Test plan
packages/core(Stack.undelete,ScopedStack.undelete,migrateAllsweep),record-adapter-sqljs, andadapter-apipnpm -r build— cleanpnpm -r typecheck— clean across all 6 packagespnpm -r lint— cleanpnpm -r test— 348 tests passing workspace-wideprettier --checkon changed files — cleanRefs #60, #59, #61, #52, #47
Generated by Claude Code