import State from '../State' ; import Schema from '../Schema' ; import Field from '../Field' ; const applyField = ( Class , field , name ) => { if ( ! ( field instanceof Field ) ) { throw new Error ( 'Expected instance of Field.' ) ; } if ( ! Class . schema ) { Class . schema = new Schema ( ) ; } Class . schema = Class . schema . extend ( { [ name ] : field } ) ; } ; /** Represents a type that has a well-defined {@linkcode Schema}. */ export default class Validatable extends State { /** An instance of {@linkcode Schema} defining the properties necessary to construct an instance of the derived class. */ static schema : Schema ; } category param instance param flags { linkcode export const field = ( instance , flags = 0 ) : Function => { return ( target , fieldName ) => { const Class = target . constructor ; if ( ! ( Class . prototype instanceof Validatable ) ) { throw new Error ( "The '@field' decorator can only be used within 'Validatable' types." ) ; } instance . flags |= flags ; applyField ( Class , instance , fieldName ) ; } ; } ;