npm.io
0.1.0 • Published 8 years ago

sfn-validate-decorator

Licence
MIT
Version
0.1.0
Deps
3
Size
4 kB
Vulns
0
Weekly
0

sfn-validate-decorator

A decorator function for SFN controllers to validate inputs.

This package currently supports only HttpControllers, since WebSocket way to transmit data is somewhat different and cannot be tracked by the current version of SFN.

Install

npm i sfn-validate-decorator

Example

import { HttpController } from "sfn";
import { validate } from "sfn-validate-decorator";

export default class extends HttpController {
    @validate("req.body", {
        username: {
            type: "string",
            required: true,
            length: [3, 18]
        },
        password: {
            type: "string",
            required: true,
            length: [3, 18]
        }
    })
    async register() {
        // ...
    }
}

Keywords