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

JSON schema validation is not working for commands #124

Closed tommiii closed 6 years ago

tommiii commented 6 years ago

I've noticed that the JSON schema validation is not working for commands, I tried to debug the your code but I din't find no one line of code where the JSON is actually validated. Should be automatic or do I need to enable some flag?

nanov commented 6 years ago

Did defined schemas? Are the names right? Could you supply a repository for test case?

tommiii commented 6 years ago

Schemas are defined with the same name of the commands. For the repository I could but it will take time.

nanov commented 6 years ago

Could you post the output of domain.getInfo(); after initilization ?

tommiii commented 6 years ago
{ contexts:
  [
    { name: 'tracking',
      aggregates: [
        { name: 'tracking',
          version: 0,
          commands: [
            { name: 'track',
              version: 0,
              preConditions: [
                { name: 'track',
                  description: 'User is authenticated',
                  priority: Infinity
                }
              ],
              preLoadConditions: []
            }
          ],
          events: [
            { name: 'tracked', version: 0
        }
          ],
          businessRules: [
            { name: 'aggregateValidationRule',
              description: 'Aggregate validation schema',
              priority: Infinity
            },
            { name: 'eventValidationRule',
              description: 'Event validation schema',
              priority: Infinity
            }
          ]
        }
      ]
    }
  ]
}
nanov commented 6 years ago

and after run something like that :

const cmd = domain.tree.getContext('tracking').aggregates[0].commands[0]; // tracking.tracking.track
console.log(!!cmd.validator);

Is the result true or false ? If it is false the problem is somewhere in your definitions ( are the schemas in .json files ? )

tommiii commented 6 years ago

Problem found. Seems a namespace issue. We organised the folders structure in this way:

So the library sees the .js file but no the .json . Is there a way for fix it without changing the structure?

alemhnan commented 6 years ago

Hello @adrai,

about this issue would be possible to extend the loader to correctly use the json files?

Apparently, they are rightly loaded (if they contain a wrong json I do get errors) but they are not actually used to validated the commands.

I think that the loader gets partially confused because they are not in the main directory.

adrai commented 6 years ago

is this still an issue? Can’t reproduce it.

alemhnan commented 6 years ago

Still an issue yep, will try to reproduce in a repo tomorrow and then will share

⁣Sent from BlueMail ​

On 25 Jul 2018, 21:03, at 21:03, Adriano Raiano notifications@github.com wrote:

is this still an issue? Can’t reproduce it.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/adrai/node-cqrs-domain/issues/124#issuecomment-407860603

alemhnan commented 6 years ago

Here you could find a test case: https://github.com/alemhnan/test-repo

I tried to move the json schema in various location but nothing worked. I suspect the actual error to be quite silly but I can't find anything wrong.

OrH commented 6 years ago

Hey @alemhnan , the issue in your test-repo is that you don't have a "title" property inside you json schema. Because of the way the current structure loader works (https://github.com/adrai/node-cqrs-domain/blob/master/lib/structure/structureLoader.js#L16-L18), you must have a matching title property. Adding it results in a validation error when running your test-repo.

Hope it helps =]

tommiii commented 6 years ago

Just tested, you're right. Problem solved, thanks. 🥇