Coder Social home page Coder Social logo

Comments (18)

KnisterPeter avatar KnisterPeter commented on June 12, 2024 1

@caiobiodere no need to say sorry 😃 We all are non native speakers. You're welcome.

Before start coding a rough scribble of pseudo code might help me to understand your requirements. Maybe what you try to achieve is already possible, not sure.
Please just explain it here in a few more sentences and a sketch.

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024 1

Instead I would propose to allow this to be a function. Then if the reponse is not matching it could be updated by that. Like this:

@Response(type: User, transform: (input) => input.user)
public async get(id: string, parameters: any) : User {}

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024 1

@caiobiodere I'll definitely build this this week I think.

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024 1

thanks mate! I think that's good enough regarding it also fixes my case :)

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024

Hi @caiobiodere,
I'm not sure if I understand what you are aiming at. What do you mean by 'return like a typescript class'?
Do you want to have the returned data wrapped in a class which is created based on the method which was called?

Would be nice to see some pseudocode you have in mind if you can write that down.

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024

@KnisterPeter yeah that's exactly what I meant sorry english is not one of my best things yet, still getting in there :) yes sure can do that give me a couple of days will figure out how to do that

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024

@KnisterPeter thanks for understanding mate!

getting into it, the idea behind all of this would be something similar to this:

type UserType {
   id?: number
}

class User: UserType {
   id?: number

    constructor(id: number) {
        this.id = id;
    }
}

@Headers('Accept: application/json')
@Get('/user/{id}', true)
@Response(type: User | User[], keyPath: "userObject" |  null) (the new decorator I mentioned before)
public async get(id: string, parameters: any) : User | User[] {}

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024

Hi @caiobiodere,
this looks nice. Can you explain a bit what you need the keyPath for? The type is pretty obvious.

In general I could think of adding this feature, I like it.

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024

Hi mate @KnisterPeter,
basically keyPath would be the path that it should extract the object to be wrapped from, lets say that we have a response like this:

{
  user: {
    id: 1
  }
}

I could use keyPath as "user" and tell the decorator to wrap into the User class from it, this would save a lot of scenarios I can tell that because most of the time API's are not in the way you really want them to be

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024

I like your idea better, do you want me to help with that? I really want this to be part of my current working project

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024

You can give it a try. I would accept a PR if you like.
But I'm as well a bit biased and have an idea how I would implement this. Lets see, maybe I like your idea as well. 😃

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024

Lets get this running, will be watching and forking this project from now on, do you have an idea of how much time would it take to you to get a first version of this done?

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024

if you think you can finish this in a couple of days I can wait mate, that would be no problem at all

from pretend.

caiobiodere avatar caiobiodere commented on June 12, 2024

@KnisterPeter hey mate I saw you started it already, how is it going do you have an estimated time?

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024

The PR could be reviewed by you, it's already done.
The tests should hold some examples.
Please give some feedback.

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024

@caiobiodere Any comments or thoughts? I'd like to make a release out of this.

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024

These are the docs in the README

from pretend.

KnisterPeter avatar KnisterPeter commented on June 12, 2024

Released in v3.1.0

from pretend.

Related Issues (11)

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.