medic/kujua-sentinel — pull request #50 by mandric (2014-02-05 02:30:07+00:00)
Title: added support for async/custom validations kujua-lite/issues/411

added callback parameter to `lib.validation.validate()` returning errors
as array in callback, empty array if no errors (since there was a test
for that). updated tests.

added `extra_validations` object to allow for custom validation function
in `lib/validation.js`.

Modified registrations transition to support async/custom validations in
addition to the synchronous Pupil validations.

Validation settings may consist of Pupil.js rules and custom rules.
These cannot be combined as part of the same rule.

Not OK:
rule: "regex(\d{5}) && unique('patient_id')"

OK:
rule: "regex(\d{5}) && max(11111)"

If for example you want to validate that patient_id is 5 numbers and it
is unique (or some other custom validation) you need to define two
validation configs/separate rules in your settings. Example validation
settings:

[
{
property: "patient_id",
rule: "regex(\d{5})",
message: "Patient ID must be 5 numbers."
},
{
property: "patient_id",
rule: "unique('patient_id')",
message: "Patient ID must be unique."
}
]

Opened issue on Pupil repo for future reference:
https://github.com/Dragory/Pupil.js/issues/5

Modified `pupil.validator` to ignore when a validation function does not exist in
its library.

Exported lexer and parser modules from Pupil to allow for parsing rules
for custom/async validations.

TODO finish custom `unique` validation function and add some tests
around it.