Comments (14)
Agreed - I've published 1.0.9 that compiles the validator before instantiation.
from fastest-validator-decorators.
Yes they have diverged and I won't be merging the changes in.
The schema is compiled https://github.com/tobydeh/fastest-validator-decorators/blob/master/src/index.ts#L41
Your Point3d example is correct, unfortunately we cant apply decorators to interfaces so you'll need to define Point3d as a class.
Hope that helps!
from fastest-validator-decorators.
You can open a pull request using the usual method, you don't need write access to this repo :)
from fastest-validator-decorators.
Hi, i fork your repo, and I've done a lot of changes, like support nested object, and transform function.
I will glad if we merge it to one repo.
https://github.com/yantrab/fastest-validator-decorators/blob/master/src/index.spec.ts
I also work on eslint for it.
Contact me by email if you want to, [email protected]
from fastest-validator-decorators.
So which package should one use!?
from fastest-validator-decorators.
Entirely up to you!
from fastest-validator-decorators.
Lol, they seem to have diverged with different updates, however FWIW, enum is not working in @yantrab package - but he seems to have added support for nested array, not that I need it (atm!)
I'm just trying to get into typescript, so in fastest-validator
I would compile a schema and then use this function to validate an object. The compilation step was an optimisation - does this package also do that?
Another question, so now you have to define your schemas as classes, then you build your class data to validate, I read that typescript can auto create constructors, but I'm trying to do:
@Schema()
class Event { ... }
const event = new Event(eventObject);
But Event
doesn't accept arguments, so we have to Object.assign
or set all properties manually?
EDIT:
Perhaps this is the pattern I should be following (from typescript website)
class Point {
x: number;
y: number;
}
interface Point3d extends Point {
z: number;
}
let point3d: Point3d = { x: 1, y: 2, z: 3 };
from fastest-validator-decorators.
So what is the best api / way to use this module?
You have to create an instance of the empty decorated class to get the compiled function, then to actually validate an object you have to apply the object data to the class - basically either using dot notation, I suppose perhaps spread notation (not sure) or object assign which I’m currently doing, but feels a bit clunky, as you then still have to call validate, I don’t suppose it would be possible to expose the validate method(s) directly on the class due to potential collision with schema property name?
If the validate were exposed in the schema instance you could just pass your object in one op?
from fastest-validator-decorators.
Just looking at the read me again, have i completely missed the section about the schema based utility class!!!?
from fastest-validator-decorators.
Yeah it does feel slightly clunky, the initial goal of the project was to provide getSchema() for use with Moleculer JS.
The idea was to define a class that could be used to type the Context object in an action handler and use getSchema() with the same class to set the action parameters.
The validate() and validateOrReject() functions were added later. I suppose that functionality could be added to the Schema decorator or SchemaBase class.
You didn't miss the section on the base utility class - I added it after you're previous comment :)
from fastest-validator-decorators.
Yes, much more pleasent! so when you declare the class, does the validator get compiled then, or is this happening each time we do new Schema(...)
?
from fastest-validator-decorators.
I've added a validate() method to SchemaBase - I'm hesitant to add any other properties because of possible collisions.
The fastest-validator schema is compiled when you instantiate the class using new.
from fastest-validator-decorators.
Yh personally if collisions are something, I’m not fussed, I’m using validate or throw method and I’m happy using that imported function on the class. Being able to construct using new is the real thumbs up. Thanks 🙏
from fastest-validator-decorators.
The fastest-validator schema is compiled when you instantiate the class using new.
I guess this isn't optimal in high performance scenrios - but not sure how you could support this and provide a pleasant api?
from fastest-validator-decorators.
Related Issues (14)
- Extend from SchemaBase prevents use of generics as argument HOT 1
- Docs: use of @Custom decorator HOT 2
- Extending a schema class mixes up properties HOT 3
- Error with Nested decorator HOT 1
- Async support
- Extending SchemaBase is not producing object with values HOT 6
- NestedArray Optionnel HOT 1
- "Nested" decorator on react enviroment (or front-end, webpack?) HOT 3
- Migration to 2 HOT 1
- Any way to support multi ? HOT 6
- Default values HOT 3
- Custom validation example HOT 3
- Instances of class decorated with "Schema" lose constructor name
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastest-validator-decorators.