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

fix: remove merge-deep from the validation #67

Merged
merged 1 commit into from
Jan 16, 2025
Merged

fix: remove merge-deep from the validation #67

merged 1 commit into from
Jan 16, 2025

Conversation

Megapixel99
Copy link
Collaborator

We used to use merge-deep to assign parameters to a new object; however, we can use structuredClone to do the same thing and remove the dependency on merge-deep. structuredClone only works on node 17+ but node 16 reached EOL in September 2023 per https://endoflife.date/nodejs and https://nodejs.org/en/blog/announcements/nodejs16-eol.

@Megapixel99
Copy link
Collaborator Author

Megapixel99 commented Oct 18, 2024

Ran the tests locally with all of the same versions as below (and 23), all of the tests passed (except for node 16).

Versions used to test:

  • v23.0.0 (passed)
  • v22.10.0 (passed)
  • v20.18.0 (passed)
  • v18.20.4 (passed)
  • v16.20.2 (failed)

@enov enov self-requested a review October 18, 2024 22:02
Copy link
Collaborator

@enov enov left a comment

Choose a reason for hiding this comment

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

Great PR! merge-deep is unnecessary nowadays and has some require magic conflicting with some js bundlers. I pulled the branch and tests against Node.js v18, v20, and v22 were successful.

@Megapixel99
Copy link
Collaborator Author

The tests are failing due to a newer version of path-to-regexp being used. I will install the newer version and update the tests

@Megapixel99
Copy link
Collaborator Author

The tests are failing due to a newer version of path-to-regexp being used. I will install the newer version and update the tests

I updated all of the dependencies and updated the tests, I can make the changes part of this PR or make a new PR with the changes to the tests. Aside from the changes to package.json and adding onto the tests (just to make sure I did not break anything) only two lines were changed to ensure the tests pass.

@@ -37,7 +36,7 @@ module.exports = function makeValidatorMiddleware (middleware, schema, opts) {
let validate

function makeValidator () {
const reqSchema = merge({}, BASE_REQ_SCHEMA)
const reqSchema = structuredClone(BASE_REQ_SCHEMA)
Copy link
Owner

Choose a reason for hiding this comment

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

I guess I just wonder if a more simple approach to this would be enough? I am not opposed to this, but since we are not doing this for the specific reason structuredClone is meant to serve I wonder if there are any unexpected consequences of this approach.

Copy link
Owner

@wesleytodd wesleytodd left a comment

Choose a reason for hiding this comment

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

Lets go with this for now and we can decide after the work to support v5 if it is good to keep.

@wesleytodd
Copy link
Owner

The tests are broken on main because [email protected] broke our regex handling. Going to merge this despite the tests not passing because I think it is a good change and then fix the remaining issues after.

@wesleytodd wesleytodd merged commit b56f6ee into main Jan 16, 2025
2 of 6 checks passed
@wesleytodd wesleytodd deleted the merge-deep branch January 16, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants