https://github.com/fega/loy
Loy is a little helper for defining REST outputs
https://github.com/fega/loy
Last synced: about 2 months ago
JSON representation
Loy is a little helper for defining REST outputs
- Host: GitHub
- URL: https://github.com/fega/loy
- Owner: fega
- License: mit
- Created: 2018-11-23T18:52:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T17:12:15.000Z (about 3 years ago)
- Last Synced: 2025-10-18T06:46:25.527Z (3 months ago)
- Language: TypeScript
- Size: 1.04 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# loy
> Like Joi but for outputs
Loy is a little helper for defining REST outputs, Aimed to be used inside the [Moser web framework](https://github.com/fega/mongo-server).
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:
```javascript
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
```javascript
import {Give, Describe} from 'Joi'
const description= Describe(out)
```