memphis icon indicating copy to clipboard operation
memphis copied to clipboard

Feature: schemaverse schema introspection/autogenerated types for typescritpt.

Open damngamerz opened this issue 2 years ago • 12 comments

Current behavior

This would be a nice to have feature. Atm we have to explicitly define type in typescript on the consumer/producer side attached to station. For eg:

  // this part could be automated and schemaverse should implicitly tell us the type of messageData.
  type JsonMessage = {
    id: string;
  }
  consumer.on('message', (message: Message) => {
    const messageData = message.getData();
    const jsonMessage: JsonMessage = JSON.parse(messageData.toString());
    console.log(jsonMessage);
    message.ack();
  });

type JsonMessage could be automated here.

Suggested solution

One of the solution could be: We have introspection on the schemas defined in schemaverse. We can then generate attached schema of a particular station to typescript types on the fly. So both the consumer and producer have typesafety for the message being sent to the station. For eg:

  consumer.on('message', (message: Message) => {
    const messageData = message.getData();
    // do something with messageData
    console.log(messageData);
    message.ack();
  });

We should implicitly know that messageData would be of type/shape.

{
    id: string;
}

Additional context

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

Contributing Docs

  • [X] I agree to follow this project's Contribution Docs

damngamerz avatar Jan 25 '23 09:01 damngamerz

Thanks @damngamerz ! It added to the near backlog and will be handled soon.

yanivbh1 avatar Feb 13 '23 11:02 yanivbh1

Apologies for the late response, @damngamerz. Somehow missed.

yanivbh1 avatar Feb 13 '23 11:02 yanivbh1

@yanivbh1 No problem. Glad to hear this is being taken forward. <3 This would make memphis very seamless to work with, if implemented correctly. I can say this would be a USP to memphis and i would prefer it to use over anything else out there. Kudos guys :+1:

damngamerz avatar Feb 13 '23 11:02 damngamerz

@Big-Vi Would you like to work on that together?

yanivbh1 avatar Sep 08 '23 06:09 yanivbh1

Would love to see this! I usually had to implement a wrapper around the client to have a similar effect

hoffnung8493 avatar Sep 08 '23 06:09 hoffnung8493

@Big-Vi Would you like to work on that together?

Yep. I can take a look.

Big-Vi avatar Sep 08 '23 07:09 Big-Vi

This would be huge. Thank you for taking this forward. Atm we created a package to share types between our microservices. Solving this one would make it obsolete. :heart: Please don't hesitate to ask for input :tada:

damngamerz avatar Sep 08 '23 10:09 damngamerz

This would be huge. Thank you for taking this forward. Atm we created a package to share types between our microservices. Solving this one would make it obsolete. ❤️ Please don't hesitate to ask for input 🎉

Thanks @damngamerz. 🙂

Big-Vi avatar Sep 10 '23 01:09 Big-Vi

How are you @Big-Vi ? Did you manage to work on it?

yanivbh1 avatar Sep 21 '23 20:09 yanivbh1

Not yet. I'm working on other issue. I'll work on this next.

Big-Vi avatar Sep 23 '23 02:09 Big-Vi

@yanivbh1 I'm busy lately. I'll come back and start contributing again once i find the time. Meanwhile if somebody wants to work on this, they can go for it.

Big-Vi avatar Oct 20 '23 03:10 Big-Vi

Thank you @Big-Vi, that is completely understood. We will do our best to prioritize it for the next release.

yanivbh1 avatar Oct 20 '23 10:10 yanivbh1