thenativeweb / node-cqrs-domain

Node-cqrs-domain is a node.js module based on nodeEventStore that. It can be very useful as domain component if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.
http://cqrs.js.org/pages/domain.html
MIT License
269 stars 57 forks source link

getInfo does not return the structure of defined commands #94

Closed alemhnan closed 7 years ago

alemhnan commented 7 years ago

This is more a feature request than a bug. I am wiring the commands into HTTP module using Swagger (with LoopBack). I would like to create one route for each command automatically and to specify as well the parameters needed.

Using getInfo, I can get the command names, but I do not have access to the parameters needed (or at least it does not seem so).

Is there a way to get that information at runtime? Otherwise, I will be happy to provide a PR (if you think that makes sense to have that). In such case could you point me the relevant codebase?

adrai commented 7 years ago

What do you mean by parameters? validation rules?

alemhnan commented 7 years ago

No sorry, my bad. I mean the inputs of the command. In your cqrs-sample, for createItem it will be id, command, and payload.text.

adrai commented 7 years ago

Do you mean this? https://github.com/adrai/cqrs-sample/blob/master/host/public/js/app.js#L202

alemhnan commented 7 years ago

As input yes. There you need to know a priori the structure of the command for every command in your system. What I would like is to have that structure (pretty much the json schemas defined in your command library I think) in the getInfo() method.

adrai commented 7 years ago

Probably I do not fully understand... Can you do a little example on what you would expect?

alemhnan commented 7 years ago

Sure, I'll provide a small example tomorrow morning.

alemhnan commented 7 years ago

The getInfo of your example returns this:

{ 
  name: 'createItem',
  version: 0,
  preConditions: [],
  preLoadConditions: []
}

Here I cannot inspect the payload structure. I would like something like this:

{ 
  name: 'createItem',
  version: 0,
  preConditions: [],
  preLoadConditions: [],
  payload: {
    type: "object",
    properties: {
      text: { type: "string" }
    },
    required: ["text"]
  }
}

Now with that information, I can programmatically feed another representation (like Swagger for instance). The end goal is to generate a swagger interface like this:

image

Hence I need the name of the command and the payload to pass along (and hopefully nothing more but I'm still working on it).

Does it make sense?

adrai commented 7 years ago

So basically a part (the payload) of the validationRule... The problem is, this is very specific... In theory a command does not need to have a property 'payload', it can be anything... the structure of the message is not strict

adrai commented 7 years ago

But on your specific implementation you can extend it on your own...

alemhnan commented 7 years ago

Ok, thanks for the answer. I'll look into it. Where do you suggest to look to extend for this use case?

adrai commented 7 years ago

directly after receiving the result of the getInfo function