express · Easy · request validation
A production API needs a normalized query options repair at its service boundary. A catalog screen receives available facet values after every search. The current state boundary keeps selections that no longer exist, so the UI announces filters that cannot affect the visible result.
Task
Implement the normalized query options contract used by the supplied HTTP adapter. Normalize the query, remove unavailable selections, preserve the order of surviving selections, and derive the active-filter count used by the supplied screen adapter.
Contract
Input is {query, selected, available}. Return {query, selected, activeCount}. Values are strings; matching is exact after trimming each selected value. Duplicate selections keep their first position.
Acceptance criteria
- Trim the query.
- Drop blank, duplicate, and unavailable selections.
- Keep the first-seen order.
- Set activeCount to selected.length plus one when query is non-empty.
- 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