express · Medium · cursor pagination
A production API needs a consumer page ownership repair at its service boundary. A search screen can request several pages for one query while the user changes the query. Late pages from the previous search currently append to the new result set.
Task
Implement the consumer page ownership contract used by the supplied HTTP adapter. Reduce request and response events into visible state where only the current search generation can commit rows.
Contract
Input is {events}. Events are search{id,query}, page{id,cursor,rows,nextCursor}, failure{id,message}. Return {query,rows,nextCursor,error}. A search starts a new generation and clears rows and errors.
Acceptance criteria
- Only events matching the latest search id may commit.
- Append pages in event order and deduplicate by row id.
- A current failure preserves committed rows and sets error.
- A stale failure changes nothing.
- 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