-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[typescript] Use static middleware when calltime options exist but specify no middleware #20985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[typescript] Use static middleware when calltime options exist but specify no middleware #20985
Conversation
9c3a423
to
d88422b
Compare
d88422b
to
f102f02
Compare
I rebased all remaining changes here onto master, @joscha .
|
return staticMiddleware; | ||
} | ||
// default to replace behavior | ||
switch(strategy ?? "replace") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this become a signature change, i.e.: ..., strategy: "append" | "prepend" | "replace" = "append"
then the default is also visible for callers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Changed :-)
} | ||
return conf; | ||
throw new Error(`Unrecognized middleware merge strategy '${strategy}'`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you move this out because of the explicit return rule? Otherwise I think it was semantically easier to understand inside the switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It felt cleaner to me, because it made it obvious, that it is a last-resort for the function (actually in typescript it is unreachable anyway, because the switch completely covers all possible values of strategy)
Putting it into default
makes sense as well because it is concerned with invalid values for strategy
.
I can put it back into default:
if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer it for future readers/changes, to make sure noone puts code in between. It should immediately exit on an unknown value. If you're happy to move it back in, that would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I moved it back inside.
@macjohnny this one is ready, too |
This PR is a continuation of #20978 with more improvements following #20430.
I'll rebase once the other PR is merged. Currently this branch contains all changes from both PRs.
This is the main change in behaviour as discussed before in the other PR.
When the user calls a method with options that do not set a middleware, the existing static middleware should be used, to follow the spirit of merging the top-level fields of the options.
On the other hand the user can give an empty array to skip any middlewares for the call.
I added tests for both cases.
I included more refactoring in this PR.
I also noticed an error in the inversify variant. When no options are given, the static config should be used. Previously even empty options where used here.
Unfortunately it seems the inversify tests are broken and I guess inversify 6 is not compatible with typescript 4. Anyway I could not get them to work again and so I did not add a test here.
Another bug, that I found, is that
httpApi
was always taken from the static configuration and could not be overridden using options. I fixed that and added a test.I regenerated the samples after almost every change, to make them clearer.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)CC @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10)