You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Validation is a common requirement in modern applications, but the ecosystem is split between class-based (e.g., class-validator) and schema-based (e.g., Zod, Yup) libraries. Many frameworks hardwire a specific validation library, but this can be limiting and increase bundle size or dependencies.
For NexusDI, the goal is to provide a validation plugin system that is:
Agnostic: Works with any validation library via adapters (resolvers)
Extensible: New resolvers can be added as the ecosystem evolves
Minimal: No validation logic in the DI core—everything is opt-in via plugins
Declarative: Validation logic is close to business logic, easy to read and maintain
Proposed Features
Register a ValidationPlugin via the use() method, specifying a resolver (adapter) for your preferred validation library
Use a @Validate() decorator on method parameters or methods to trigger validation
On parameters: validates the argument before method execution
On methods: validates the return value after execution
For schema-based libraries (Zod, Yup, etc.), the schema is provided to the decorator
For class-based libraries (class-validator), the schema is inferred from the class metadata
Resolvers are provided in a subpath (e.g., @nexusdi/validation/resolvers)
Community or custom resolvers can be added for other libraries
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
[RFC] Validation Plugin System
Overview
Validation is a common requirement in modern applications, but the ecosystem is split between class-based (e.g., class-validator) and schema-based (e.g., Zod, Yup) libraries. Many frameworks hardwire a specific validation library, but this can be limiting and increase bundle size or dependencies.
For NexusDI, the goal is to provide a validation plugin system that is:
Proposed Features
ValidationPluginvia theuse()method, specifying a resolver (adapter) for your preferred validation library@Validate()decorator on method parameters or methods to trigger validation@nexusdi/validation/resolvers)Example Usage
API Design
@Validate(schema?)can be used on parameters (for input validation) or on methods (for return value validation)Extensibility
Open Questions
Call for Feedback
Beta Was this translation helpful? Give feedback.
All reactions