node-machine / machinepack

Command-line tool for working with machinepacks and machines.
http://node-machine.org/implementing
14 stars 3 forks source link

custom `validate()` method not being used when running `mp exec`? #2

Open aars opened 9 years ago

aars commented 9 years ago

I have to define typeclass: '*', which apparently is not an issue when running through test-machinepack-mocha.

https://github.com/aars/machinepack-test-issue#machinepack-exec-oddity

aars commented 9 years ago

I believe this issue originates here: https://github.com/node-machine/machinepack-localmachinepacks/blob/master/machines/run-machine-interactive.js#L189

Where the typeSchema is only used for parsing and validation. I'm not sure how to elegantly solve this. My first guess would be to set typeSchema to '*' when inputDef.validate is defined and use that after rttc.parseHuman.

mikermcneil commented 8 years ago

Hey @aars, super late reply, sorry about that. For now, we've shifted away from working with the custom validate() function in the tooling other than the machine runtime, since it can't be statically analyzed. I think the way to do this is probably to have the validate function float on top of the exemplar. So you're right, in this case, you'd probably want to use a typeclass-style generic exemplar like *, {}, or === (keep in mind that, in the latter case, you'd be sending in a mutable reference).