Skip to content
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: request and reply decorators can not be a reference type #5462

Merged
merged 8 commits into from May 20, 2024
Merged

Conversation

Eomm
Copy link
Member

@Eomm Eomm commented May 12, 2024

Implements #2598

This PR replaces the WARN message with an error when a reference type is used as a request or reply decorator, suggesting using a different API.

To use a reference type as a decorator without sharing values across requests, the user must use the getter/setter interface or the hook approach. Both methods are documented with examples.

This PR has been sponsored by Nearform

Checklist

@Eomm Eomm added v5.x Issue or pr related to Fastify v5 notable-change A change that should be explicitly outlined in release notes and migration guides labels May 12, 2024
@Eomm Eomm linked an issue May 12, 2024 that may be closed by this pull request
lib/decorate.js Outdated
if (typeof fn === 'object' && fn && !(typeof fn.getter === 'function' || typeof fn.setter === 'function')) {
FSTDEP006(name)
return encapsulatedDecorator(fn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just throw in this case and not clone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So are we removing the warning to replace it with an error while suggesting the user use the getter/setter interface?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@github-actions github-actions bot added documentation Improvements or additions to documentation typescript TypeScript related labels May 18, 2024
@Eomm Eomm changed the title feat: request and reply reference type encapsulated feat: request and reply block reference type May 18, 2024
@Eomm Eomm marked this pull request as ready for review May 18, 2024 08:11
Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

Can you update the PR title and description?

@Eomm Eomm changed the title feat: request and reply block reference type feat: request and reply decorators can not be a reference type May 20, 2024
@Eomm Eomm merged commit 30c95ed into main May 20, 2024
44 checks passed
@Eomm Eomm deleted the fully-enc branch May 20, 2024 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation notable-change A change that should be explicitly outlined in release notes and migration guides typescript TypeScript related v5.x Issue or pr related to Fastify v5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure that fastify Request is encapsulated
4 participants