nestjs · Medium · optimistic concurrency
A production API needs a revision-safe asynchronous update repair at its service boundary. An editor saves drafts in the background. A slow confirmation for an older revision currently marks the latest text as saved, and an older failure can replace the current status.
Task
Implement the revision-safe asynchronous update contract used by the supplied HTTP adapter. Reduce edit, save, success and failure events into a truthful draft status.
Contract
Input is {events}. edit carries revision and text; save, success and failure carry revision. Return {text,revision,status,error}. Status is idle, dirty, saving, saved or failed.
Acceptance criteria
- Only the latest revision may become saved or failed.
- Saving an old revision does not change current status.
- Editing clears the previous error.
- Success must match both the current revision and latest save attempt.
- Return a deterministic JSON-serializable result for the HTTP adapter.
Constraints
- Do not mutate caller-owned input.
- Keep the supplied framework adapter and public contract unchanged.
- Add candidate tests for at least one boundary not covered by the public cases.
Editable files
src/repair.js— Task-specific state or service boundarytests/candidate.test.js— Candidate-authored regression