Skip to content

Pass the request context to filter handlers - #18

Merged
evoactivity merged 1 commit into
mainfrom
feat/filter-context
Aug 17, 2026
Merged

Pass the request context to filter handlers#18
evoactivity merged 1 commit into
mainfrom
feat/filter-context

Conversation

@evoactivity

Copy link
Copy Markdown
Owner

The gap

filter.custom handlers receive { Model, name } but not the request, so a filter that depends on the viewer (the current user's favourites, a role-scoped shortlist) cannot live in the resource declaration. The workaround is a declared no-op plus the real constraint in the controller, one filter split across two homes, the drift shape #10 existed to kill.

The change

FilterContext gains ctx?: HttpContext. applyFilters accepts and forwards it; the context helper passes its request; the low-level path leaves it undefined. Non-breaking: the parameter is additive and existing handlers ignore it.

mine: filter.custom((query, _value, { ctx }) => {
  query.where('author_id', ctx!.auth.user!.id)
})

Tests

Two unit tests drive applyFilters directly, context present and absent. The context-helper wiring is five lines passing a private field; its end-to-end proof lands immediately downstream in a functional filter[favourite] test over HTTP.

Unit 176 passed, example functional 62 passed, lint and typecheck clean.

Handlers already received { Model, name }; ctx joins it, carrying the
request when filtering runs inside one and staying undefined on the
low-level path. A filter can now depend on the viewer, the current
user's favourites being the motivating case downstream, without
splitting its constraint between the resource declaration and the
controller. filter.custom types the parameter; existing handlers are
unaffected.
@evoactivity evoactivity self-assigned this Aug 17, 2026
@evoactivity evoactivity added the enhancement New feature or request label Aug 17, 2026
@evoactivity
evoactivity merged commit 0d64fb5 into main Aug 17, 2026
4 checks passed
@evoactivity
evoactivity deleted the feat/filter-context branch August 17, 2026 16:25
@github-actions github-actions Bot mentioned this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant