An Open Source Application Generator
This project contains input validators for Magic. More specifically it contains the following slots.
All of the above slots takes an expression, or values, as its main input, and will throw exceptions if their input expression’s value(s), or its value, does not follow the rules specified by the validator. This makes them perfect fits for “intercepting” the input specified to an HTTP REST endpoint, to verify the input data conforms to some sort of predefined validator.
.foo number:int:11 validators.integer:x:@.foo/*/number min:int:5 max:int:10
Most validators requires some sort of argument(s), such as you can see above in the integer validator - However, some of these validators are without arguments, such as the email validator, that simply verifies the input is a valid email address. To use the [validators.regex] validator, you should probably learn regular expression. However, this is beyond the scope of this article.
You can use one invocation to any of the validators to validate multiple nodes, such as the following illustrates.
.arguments . no:5 . no:10 . // Throws .no:11 validators.integer:x:@.arguments/*/*/no min:5 max:10
First the above expression will be evaluated, then every resulting value will be validated, and if any of them are not validated according to the validtor’s arguments - Which for the above example is number between 5 and 10 - The validater will throw an exception, providing the invalid value, and the name of the last iterator (effectively being the argument name) to the caller. This allows you to use one single validator to validate multiple arguments, such as the above illustrates. This might be useful if you for instance have an endpoint accepting multiple address fields, and zip code is a mandatory argument, and it needs to be an integer.
The source code for this repository can be found at github.com/polterguy/magic.lambda.validators, and you can provide feedback, provide bug reports, etc at the same place.
This project is the copyright(c) 2020-2021 of Thomas Hansen firstname.lastname@example.org, and is licensed under the terms of the LGPL version 3, as published by the Free Software Foundation. See the enclosed LICENSE file for details.