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
feat: add routeSchema and routeConfig + switching context handling #4216
Conversation
Signed-off-by: Matteo Collina <hello@matteocollina.com>
b95ac6c
to
6aa3fff
Compare
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.
Should we make the exposed properties "read-only"?
Yes: any changes will not be processed by fastify.
What else should be exposed through the public API?
I think we should start small instead of adding unwanted stuff.
The initial request was to access the schema
only
lib/context.js
Outdated
return context.config | ||
} | ||
}, | ||
logLevel: { |
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.
Why this addition?
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 was playing a bit and might be beneficial to have some sort of single place where to look for specific settings of the route definition. I was thinking of a single read-only
approach but wanted to get your thoughts on this, as might/might-not have sense. wdyt?
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 would not say it is non-sense, it is just something nobody asked for so I would work on it in a separate PR if necessary instead of adding too much code on this one
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.
Has sense, let's keep it clean 👍
Done in 2c18837
Is this regressing on perf? |
One failing test I think we could target |
The failing test is non-related to the PR changes. It just need to rebase. |
@mcollina Specs
There is even an extremely small improvement within this branch. But no regression so far. Maybe someone else can double-check this? |
Can I have some help rebasing on |
# Conflicts: # fastify.js # package.json
I have merged the |
f22015c
to
aa5ed77
Compare
Done @climba03003, thanks for the rebase on |
test/router-options.test.js
Outdated
@@ -130,7 +87,8 @@ test('Should honor maxParamLength option', t => { | |||
}) | |||
}) | |||
|
|||
test('Should expose router options via getters on request and reply', t => { | |||
// TODO: fix once agreed on the new router options object | |||
test('Should expose router options via getters on request and reply', { todo: true }, t => { |
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.
revert
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.
Only question I have is there a number of "TODOS" added and usually I link those to issues if I can, especially things like "remove in v5".
(I'm also new to community here so wondering if it handled differently)
Hey! 🙂 |
Change has been done and pushed, @Eomm can you have a second look? 🙂 |
SWEET! I personally don't love TODOS in code getting merged (w/o an issue reference) as they fall into the nether and are (sometimes) important. Don't know if core maintainers have opinions... and don't want to create a problem where there might not be one 😄 |
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.
LGTM
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.
Last chores and then LGTM 👍🏽
docs/Reference/Reply.md
Outdated
@@ -84,7 +84,6 @@ object that exposes the following functions and properties: | |||
from Node core. | |||
- `.log` - The logger instance of the incoming request. | |||
- `.request` - The incoming request. | |||
- `.context` - Access the [Request's context](./Request.md) property. |
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.
we should kepp it right now
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.
Also done in f3be7b5
test/router-options.test.js
Outdated
t.equal(reply.context.config.url, '/test/:id') | ||
t.equal(reply.context.config.method, 'GET') |
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 would keep these two lines: they will fail when we will remove the context
option but till then we need to test it
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.
Sure, done in f3be7b5
Can you please include a benchmark? |
Node: 14 Node: 16 Node: 18 |
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.
lgtm
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Implements #4149
Description:
As stated in #4149, this PR introduces:
Context
object tight to the route through aSymbol
request
object with the signature ofrequest.routeContext
.Notes
major
version of Fastifyschema
config
logLevel
(which is also configurable)Open Questions
Checklist
npm run test
andnpm run benchmark
and the Code of conduct