Licence
MIT
Version
0.0.11
Deps
0
Size
31 kB
Vulns
0
Weekly
0
loy
Like Joi but for outputs
Loy is a little helper for defining REST outputs, Aimed to be used inside the Moser web framework.
Loy accomplish two missions:
- Define the REST output in order to generate documentation automatically.
- Restrict output fields based on user's permissions.
Usage
Define an output function:
import {Give} from 'Joi'
const out:(resource,user)=>{
return {
field1: Give(resource.field1, user)
.for('admin') // define the necessary user permission
.or('user') // alternative permission
// documentation:
.as('string')
.example('field example')
.description('field description')
// always finish with this:
.ok()
}
}
Moser will execute the function, and return the field only if the user have the permission.
to get the output definition
import {Give, Describe} from 'Joi'
const description= Describe(out)