Relay Base Provider
Base application provider for AdonisJs
The base application provider extends the AdonisJs core to add features required by almost every micro service written at Relay.
Table of contents
Setup
Install it from npm
npm i @relayin/base-provider
and then register it to the list of providers
const providers = [
'@relayin/base-provider/build/providers/BaseProvider'
]
Validation rules
The base provider adds following validation rules to indicative
.
phone
Validates the user phone number as an Indian mobile number. This rule also mutates the phone number value by formatting it. This makes sure that all mobile numbers are properly formatted after validation.
const schema = {
phone_number: 'required|phone',
}
Helpers
The base provider also extends the Helpers
class of AdonisJs and adds following methods to it.
exec
Executes an async function by returning it's exception inline. The idea is highly inspired by go
style error handling.
This is how you usually handle errors.
let response
try {
response = await fn()
} catch (error) {
}
using the exec
function, you can make the process inline, as follows:
const [error, response] = await Helpers.exec(fn())
if (error) {
}
In order to get intellisense
for exec
function, you need to extend the Helpers
interface from the
following interface.
import { RelayHelpersContract } from '@relayin/base-provider'
interface Helpers extends HelpersContract, RelayHelpersContract {}
Change log
The change log can be found in the CHANGELOG.md file.
Contributing
Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.
Authors & License
[Harminder virk](https://github.com/Harminder virk) and contributors.
MIT License, see the included MIT file.