Sort + filter query helpers per the documented grammar #192
Labels
No labels
area:auth
area:ci
area:db
area:infra
area:native
area:pwa
area:service
epic
feature
foundation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
james/carol#192
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Build reusable query-string parsing helpers for the sort and filter grammar documented in
docs/api-conventions.md§"Sort and filter grammar". No endpoint exercises sort or filter today; the helpers exist so feature tickets that need them opt in without re-litigating the grammar.The grammar (from
docs/api-conventions.md):?sort=<field>ascending,?sort=-<field>descending. Multiple comma-separated for tie-break:?sort=-created_at,name.?filter[<field>]=<value>equality. Multiple filters combine with AND.Unknown sort or filter keys must return
400 invalid_body.Scope
Add to
lib/api/query.ts(new file, alongsidepagination.ts):parseSort(searchParams, allowedFields: readonly string[])— returns either{ ok: true; sort: Array<{ field: string; dir: "asc" | "desc" }> }or{ ok: false }. Empty input → empty array, stillok.parseFilter(searchParams, allowedFields: readonly string[])— returns either{ ok: true; filter: Record<string, string> }or{ ok: false }. Empty input → empty object, stillok.zodschema helpers for typed integration in route handlers that want the result inferred.Pair each helper with focused unit tests covering: empty input, valid input, unknown field, malformed bracket syntax, repeated keys.
Document a minimal usage example in
docs/api-conventions.md(an aside inside the existing §"Sort and filter grammar", not a new section).Acceptance criteria
lib/api/query.tsexportsparseSortandparseFilterwith strict TypeScript types.tests/api/query.test.tscovers happy paths and rejection paths.docs/api-conventions.md§"Sort and filter grammar" carries a usage example.Out of scope
?filter[created_at][gt]=…), or full-text search. The current grammar is equality-only; richer forms get their own ADR or ticket if/when needed.Composes with
#179 (PR #190),
docs/api-conventions.md§"Sort and filter grammar".Part of
#176