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(framework): add class-validator support #6840

Conversation

paulwer
Copy link
Contributor

@paulwer paulwer commented Nov 4, 2024

What changed? Why was the change needed?

Class Validator support for @novu/framework

Screenhots

Class validator peer dependency import failure message

 ⨯ Error: Tried to use a class-validator schema in @novu/framework without class-validator-jsonschema installed. Please install it by running `npm install class-validator-jsonschema`.
    at se (/Users/rifont/git/framework-next-turbo/.next/server/app/api/novu/route.js:411:77618)
    at async si.canHandle (/Users/rifont/git/framework-next-turbo/.next/server/app/api/novu/route.js:411:79403)
    at async sp (/Users/rifont/git/framework-next-turbo/.next/server/app/api/novu/route.js:411:81104)
    at async Object.discover (/Users/rifont/git/framework-next-turbo/.next/server/app/api/novu/route.js:505:10531)
    at async sl.addWorkflows (/Users/rifont/git/framework-next-turbo/.next/server/app/api/novu/route.js:501:8314)
    at async (/Users/rifont/git/framework-next-turbo/.next/server/app/api/novu/route.js:505:3508)
    at async te.do (/Users/rifont/git/framework-next-turbo/node_modules/.pnpm/[email protected][email protected][email protected]__utrvdij6okqvk6cvj3mqcl5cuy/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:17826)
    at async te.handle (/Users/rifont/git/framework-next-turbo/node_modules/.pnpm/[email protected][email protected][email protected]__utrvdij6okqvk6cvj3mqcl5cuy/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:18:22492)
    at async doRender (/Users/rifont/git/framework-next-turbo/node_modules/.pnpm/[email protected][email protected][email protected]__utrvdij6okqvk6cvj3mqcl5cuy/node_modules/next/dist/server/base-server.js:1455:42) {
  statusCode: 500,
  code: 'MissingDependencyError',
  data: [Array]
}
Expand for optional sections ### Related enterprise PR

Special notes for your reviewer

closes #6682

Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for novu-stg-vite-dashboard-poc ready!

Name Link
🔨 Latest commit 4140bda
🔍 Latest deploy log https://app.netlify.com/sites/novu-stg-vite-dashboard-poc/deploys/6732186e895c9600089386dc
😎 Deploy Preview https://deploy-preview-6840--novu-stg-vite-dashboard-poc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@paulwer paulwer changed the title feat: add class-validator support feat(framework): add class-validator support Nov 4, 2024
@paulwer
Copy link
Contributor Author

paulwer commented Nov 6, 2024

@rifont i marked you to may review this PR, as you have created the original validator implementation.
If there is anything I can provide, please reach out :)

@SokratisVidros
Copy link
Contributor

SokratisVidros commented Nov 6, 2024

@paulwer Thanks for submitting this PR. It coincides with an internal conversation about allowing contributors to bring their own validations, such as Zod, ClassValidator, etc...

Our dynamic require("x") pattern, along with peer dependencies, served us well so far, but as we moved our package to its ESM/CJS state, we noticed it caused some issues in some bundlers, such as Turbopack beta.

We expect to conclude our strategy by the end of this week, and the decision might also affect this PR. We would love to hear your opinions or suggestions on the matter.

@paulwer
Copy link
Contributor Author

paulwer commented Nov 6, 2024

Hi @SokratisVidros, thanks for the feedback. If the descision would be to only allow json-schema, i would like to encourage you to provide examples or mapper functions to be installed additionaly.

If I can support this in any way, please let me know :)

@SokratisVidros
Copy link
Contributor

SokratisVidros commented Nov 7, 2024

@paulwer White smoke! We are doubling down on ESM, making schema validation asynchronous so that we can use async imports. We expect this work to be merged by tomorrow. Then your PR will need some adjustments before merging.

We would love your feedback, PTAL #6879

Copy link
Collaborator

@rifont rifont left a comment

Choose a reason for hiding this comment

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

Awesome contribution @paulwer ! This will provide a strong basis for NestJS usage of the Framework.

I added some comments for your review, we will get this merged in and released ASAP.

@paulwer
Copy link
Contributor Author

paulwer commented Nov 8, 2024

@rifont any considderations for me regarding: #6428?

@rifont
Copy link
Collaborator

rifont commented Nov 8, 2024

@rifont any considderations for me regarding: #6428?

No, we can address support for class-validators in that PR later. Thanks for checking!

@paulwer
Copy link
Contributor Author

paulwer commented Nov 8, 2024

@rifont there is also a patch for the lib created, which we can try to use if there are any issues while building

…validator-support' into feat-package-class-validator-support
@rifont rifont changed the base branch from next to import-utils-refactor-schemas November 10, 2024 23:57
@paulwer
Copy link
Contributor Author

paulwer commented Nov 11, 2024

solid changes :)
I had reviewed it again and have nothing to complain <3

@paulwer
Copy link
Contributor Author

paulwer commented Nov 11, 2024

Not true, i have some minor suggestions :)

  1. add tests for enum support of class-validator/-transformer.

  2. You may also need to recheck anyOf/allOf etc.
    f.ex. https://stackoverflow.com/questions/75782271/how-to-validate-nested-array-of-multiple-types-using-class-validator

  3. add tests for validating array of objects should be added as a test (ValidateNested({ each }))

@rifont rifont deleted the branch novuhq:import-utils-refactor-schemas November 11, 2024 20:24
@rifont rifont closed this Nov 11, 2024
@rifont
Copy link
Collaborator

rifont commented Nov 11, 2024

Ahh, so evidently Github will automatically close a fork PR when deleting an upstream branch (which in the case of novuhq/novu, happens automatically after merging a PR).

@paulwer , do you have the capability to reopen the PR on your end? If not we can create a new PR with all the existing changes.

@paulwer
Copy link
Contributor Author

paulwer commented Nov 11, 2024

no worries, i created another pr with the latest changes :)

please check

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.

🚀 Feature: @novu/framework Integration with class-validator
3 participants