Giter Site home page Giter Site logo

PR about fastest-validator-decorators HOT 14 CLOSED

amauryd avatar amauryd commented on July 18, 2024
PR

from fastest-validator-decorators.

Comments (14)

tobydeh avatar tobydeh commented on July 18, 2024 2

Agreed - I've published 1.0.9 that compiles the validator before instantiation.

from fastest-validator-decorators.

tobydeh avatar tobydeh commented on July 18, 2024 1

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.

tobydeh avatar tobydeh commented on July 18, 2024

You can open a pull request using the usual method, you don't need write access to this repo :)

from fastest-validator-decorators.

yantrab avatar yantrab commented on July 18, 2024

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.

ispyinternet avatar ispyinternet commented on July 18, 2024

So which package should one use!?

from fastest-validator-decorators.

tobydeh avatar tobydeh commented on July 18, 2024

Entirely up to you!

from fastest-validator-decorators.

ispyinternet avatar ispyinternet commented on July 18, 2024

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.

ispyinternet avatar ispyinternet commented on July 18, 2024

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.

ispyinternet avatar ispyinternet commented on July 18, 2024

Just looking at the read me again, have i completely missed the section about the schema based utility class!!!?

from fastest-validator-decorators.

tobydeh avatar tobydeh commented on July 18, 2024

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.

ispyinternet avatar ispyinternet commented on July 18, 2024

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.

tobydeh avatar tobydeh commented on July 18, 2024

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.

ispyinternet avatar ispyinternet commented on July 18, 2024

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.

ispyinternet avatar ispyinternet commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.