Data Validation and Transformation
Validation
Just like with authorization rules, we can validate data using functions. For example:
where validateBook
is a JavaScript function in validators.js
, defined as:
Transformation
Let's say that we want every book's title to be in uppercase automatically on every read, we can pass a function to @onRead
directive on the Book
model
transformBook
is a JavaScript function defined in transformers.js
as:
The result of the transformation is then returned to the user, or passed to the next @onRead
. The same composition mechanism applies to other types of directives that take function arguments, i.e. onWrite
, onLogin
, and onDelete
.