Pass the request context to filter handlers - #18
Merged
Conversation
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.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The gap
filter.customhandlers 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
FilterContextgainsctx?: HttpContext.applyFiltersaccepts 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.Tests
Two unit tests drive
applyFiltersdirectly, 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 functionalfilter[favourite]test over HTTP.Unit 176 passed, example functional 62 passed, lint and typecheck clean.