amauryd / fastest-validator-decorators Goto Github PK
View Code? Open in Web Editor NEWTypescript decorators for the fastest-validator library
License: MIT License
Typescript decorators for the fastest-validator library
License: MIT License
Hello, is there a way to use multi from fastest-validator ? (search return nothing, so I think no) .
fastest-validator: 1.12.0
When I follow the example to extend SchemaBase to use the constructor get a new object, the property values are always undefined, (except any properties that are on the original object but not in the schema - they remain untouched).
i.e.
@Schema()
class Entity extends SchemaBase { // BTW I think the docs have a typo, const should be class
@Email()
email: string;
}
const entity = new Entity({ email: '[email protected]' });
console.log(entity); // Entity { email: undefined }
I put some console.logs into the src at https://github.com/AmauryD/fastest-validator-decorators/blob/master/src/index.ts#L148 and can confirm at this point the object has all the values. But somewhere they are getting lost.
The constructor signature of the class SchemaBase prevents to use generics in some cases.
class DAO<T extends Model> {
private _klass;
constructor(klass: {new (): T}) {
this._klass = klass;
}
}
const dao = new DAO(User) // TypeScript compiler complains here!
When following the migration guide and using the same helper function, get the error:
Obj is missing complied validation method
Hi, thanks for you great job.
i wont to make PR, but i can't push new brunch .
can you add me write access to do it?
Hello.
First of all, thank you for making a good module.
My React project is using this module well.
There is a bug when using the "Nested" decorator, as the title suggests.
I don't know exactly what kind of environment it is.
Below is a reproduced code and box link.
Please check it and reflect it.
https://codesandbox.io/s/fastest-validator-decorators-test-bhm7tf
I added this line and solved it.
For now I don't know if this issue comes from the original package (fastest-validator) or the port to TypeScript decorators. Need investigation.
Hello,
I made a pull request #25 to support async validation introduced in fastest-validator library.
In order not to break semver, i added a custom decorator @AsyncSchema that behaves the same than @Schema.
Also, should we use the library "fastest-validator" as peerDependency instead of dependency ?
Hello !
When extending an annotated class, the resulting schemas contain properties of both classes which get mixed up. An example:
import { getSchema, Schema, String } from 'fastest-validator-decorators';
@Schema()
export class Parent {
@String()
a!: string;
}
@Schema()
export class Child extends Parent {
@String()
b!: string;
}
console.log(getSchema(Parent));
console.log(getSchema(Child));
Produces:
{
a: { empty: false, type: 'string' },
'$$strict': false,
b: { empty: false, type: 'string' }
}
{
a: { empty: false, type: 'string' },
'$$strict': false,
b: { empty: false, type: 'string' }
}
whereas one would expect
{
a: { empty: false, type: 'string' },
'$$strict': false,
}
{
a: { empty: false, type: 'string' },
'$$strict': false,
b: { empty: false, type: 'string' }
}
Versions used:
Thank you for your time !
The documentation for @Custom
decorator is missing. We can find it in this #8 (comment)
Hi there,
I struggle to implement custom validation on a property of type array. I want to check the items of the array (if there is any) are all instances of a given class. I tried passing custom validation function based on the fastest-validator documentation. The following snippet gives you the idea of what I need.
Did someone achieve it?
Thanks for your help.
I have used Nested as below:
`@Schema(true)
class Entity {
@Email()
email: string
}
@Schema(true)
export class CreateBannerInput {
@nested()
prop: Entity
}`
But I received an error, I don't know why, please help me !!!
✖ Cannot read property 'prototype' of undefined
✖ TypeError: Cannot read property 'prototype' of undefined
at getSchema (/Users/Projects/xxx/node_modules/fastest-validator-decorators/dist/index.js:39:59)
First of all, thank you for this project, it is very useful. I like to put validation directly into my schemas. 🤟
Unfortunately I was not able to make it work with default values. Following your example, this class bellow does not compile with strict mode enabled.
@Schema()
class Entity extends SchemaBase {
@String({ min: 4, max: 8, trim: true })
prop1: string; // <= ERROR: Property 'prop1' has no initializer and is not definitely assigned in the constructor
}
When I set a default value directly in the property definition (what I would like to do actually) all passed values at the instantiation time are ignored.
@Schema()
class Entity extends SchemaBase {
@String({ min: 4, max: 8, trim: true })
prop1 = "0000";
}
const entity = new Entity({ prop1: "1234" });
console.log(entity); // print -> {prop1: "0000"}
In the case I disable the strict mode (I would prefer to keep it enabled) and try to define a default value inside the decorator (expecting to use the fastest-validator
feature), it does not work neither. This time it is the default value which is ignored.
@Schema()
class Entity extends SchemaBase {
@String({ min: 4, max: 8, trim: true, default: "0000" })
prop1: string;
}
const entity1 = new Entity({ prop1: "1234" });
console.log(entity1); // print -> {prop1: "1234"}
const entity2 = new Entity({});
console.log(entity2); // print -> {}
Do I do something wrong? Is there a solution?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.