New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@junaid1460/forms-annotations

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@junaid1460/forms-annotations

forms for node apps

latest
Source
npmnpm
Version
2.0.6
Version published
Weekly downloads
14
1300%
Maintainers
1
Weekly downloads
 
Created
Source

[Forms-Annotation] Beautiful code is what I seek.

NPM version


npm i @junaid1460/forms-annotations

Requirements

typescript 3 (es6)

Usage

import { Forms } from '.';


@Forms.Form
class ActionButton  {
    @Forms.Input().Validate(e => e.string().required())
    public action: string;
}
@Forms.Form
class AnotherForm  {

    @Forms.Input().Validate(e => e.string().required())
    public label?:  string;
}

// Customize
const RequiredText = () => Forms.Input().Validate(e => e.string().required())
@Forms.Form
class MyForm extends Forms.BaseForm<MyForm> {

    @RequiredText()
    name?: any

    @Forms.Input({dtype: "email"})
    @Forms.Validate(e => e.string().required())
    email: string

    @Forms.Select({
        options: [{
            value: "values",
            view_value: "sdfsdf"
        }, {
            value: "another",
            view_value: ""
        }]
    })
    options?: any

    @Forms.Branch<MyForm>({
        branch_key: "options",
        branches:() => ({
            values: ActionButton,
            another: AnotherForm
        })
    })
    test?: any

    @Forms.SubSchema({schema: AnotherForm})
    value: AnotherForm;
}


const data= new MyForm({
    email: 'junaid1460@gmail.com',
    name: "junaid",
    options: "values",
    test: {
        label: "My label"
    },
    value: {
        label: "Hello world"
    } 
})

console.log(data.validate().then(e => console.log(e)))
console.log(MyForm.getValidationSchema())
console.log(MyForm.getUISchema())
console.log(data)


/**

    example.ts:65
    internals.Object {isJoi: true, _currentJoi: module.exports.internals.Any, _type: "object", _settings: null, _baseType: undefined, …}
    example.ts:66
    Array(5) [Object, Object, Object, Object, Object]
    example.ts:67
    MyForm {email: "Test", name: "he", options: "values", test: Object, value: Object}
    example.ts:68
    (node:6365) UnhandledPromiseRejectionWarning: ValidationError: child "test" fails because [child "action" fails because ["action" is required]]
        at Object.exports.process (/Users/muhammadjunaid/loco/forms-annotations/node_modules/joi/lib/errors.js:203:19)
        at internals.Object._validateWithOptions (/Users/muhammadjunaid/loco/forms-annotations/node_modules/joi/lib/types/any/index.js:764:31)
        at internals.Object.validate (/Users/muhammadjunaid/loco/forms-annotations/node_modules/joi/lib/types/any/index.js:798:21)
        at validate.Promise (/Users/muhammadjunaid/loco/forms-annotations/src/index.ts:31:23)
        at new Promise (<anonymous>)
        at MyForm.validate (/Users/muhammadjunaid/loco/forms-annotations/src/index.ts:29:20)
        at Object.<anonymous> (/Users/muhammadjunaid/loco/forms-annotations/src/example.ts:65:18)
        at Module._compile (internal/modules/cjs/loader.js:773:14)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
        at Module.load (internal/modules/cjs/loader.js:653:32)
    warning.js:18

 */

Keywords

hapi

FAQs

Package last updated on 05 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts