Giter Club home page Giter Club logo

Comments (6)

RobinTail avatar RobinTail commented on July 28, 2024

@Isaac-Leonard , for me this method looks redundant, since you're connecting this db dependency in the same place where your handler is implemented, so you can use it directly within handler without passing it through the factory.

In case this entity somehow depends on incoming data or available for limited users, the existing method .addMiddleware() is designed for passing the desired entity to the options parameter of the handler.

Perhaps I'm missing something. Please let me know if these two solutions are not suitable for your case (with some more details). Thank you!

from express-zod-api.

Isaac-Leonard avatar Isaac-Leonard commented on July 28, 2024

Actually yeah you're right, I really should read the full documentation first before trying to add features.bThe only differences I would maybe make is to add the properties on options directly to the argument passed to handler instead of as a options property but really that doesn't make much of a difference and not requiring the createMiddleware boilerplate..

from express-zod-api.

Isaac-Leonard avatar Isaac-Leonard commented on July 28, 2024

Actually no
Looking at it more there is currently no typing on the options object.
Thats what My solution would add.
I've pushed my changes on my fork if you would like to look although they are a bit messy, its got tests demonstrating its typesafeness.
Currently it requires a breaking change as typescript can't infer types without it.
It currently allows for anything to be added to a dependancies object that gets passed to the final handler but only static data for now, making it dynamic such as creating individual db connections or authenticating users with a type safe user object being added to the result however should be doable.
The current options object is just typed as any.

from express-zod-api.

RobinTail avatar RobinTail commented on July 28, 2024

The current options object is just typed as any.

I'd recommend to check the type of your middleware's output and how you connect this middleware.

Usually it works this way (in a project, that utilizes express-zod-api):

image

from express-zod-api.

RobinTail avatar RobinTail commented on July 28, 2024

and not requiring the createMiddleware boilerplate..

I agree, that in some cases, especially for empty inputs, there may be some sort of shorthand for providing Endpoints with options easier. Need to think on it a little bit...

from express-zod-api.

RobinTail avatar RobinTail commented on July 28, 2024

@Isaac-Leonard , please check out PR #234.
Does it fulfill your needs?

from express-zod-api.

Related Issues (20)

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.