import { SanitationMetadata , ConstraintMetadata } from './interfaces' ; /**
 * Storage all metadatas of this library.
 */ export class MetadataStorage { private sanitationMetadataStore : Map < Function , SanitationMetadata [ ] > = new Map ( ) ; private constraintMetadatasStore : Map < Function , ConstraintMetadata [ ] > = new Map ( ) ; param metadata param type public addMetadata ( metadata , type ) ; public addMetadata ( metadata , type ) ; public addMetadata ( metadata , type ) { if ( ! this . sanitationMetadataStore . has ( metadata . target ) ) { this . sanitationMetadataStore . set ( metadata . target , [ ] ) ; } if ( ! this . constraintMetadatasStore . has ( metadata . target ) ) { this . constraintMetadatasStore . set ( metadata . target , [ ] ) ; } switch ( type ) { case 'sanitation' : this . sanitationMetadataStore . get ( metadata . target ) ! . push ( metadata as SanitationMetadata ) ; break ; case 'constraint' : this . constraintMetadatasStore . get ( metadata . target ) ! . push ( metadata as ConstraintMetadata ) ; try { ( metadata as ConstraintMetadata ) . instance = new ( metadata as ConstraintMetadata ) . target ( ) ; } catch { throw Error ( 'Error while registering decorator metadata, cannot create CustomSanitizer instance from received class definition.' ) ; } break ; } } param instanceConstructor getSanitizeMetadatasForClassInstance ( classInstance ) { const targetSanitationMetadata = this . sanitationMetadataStore . get ( ( classInstance as any ) [ '__proto__' ] ) || [ ] ; const parentSanitationMetadata = this . sanitationMetadataStore . get ( ( classInstance as any ) [ '__proto__' ] [ '__proto__' ] ) || [ ] ; return [ ... targetSanitationMetadata , ... parentSanitationMetadata ] ; } /**
     * Gets all sanitizator constraints for the given object.
     */ getSanitizeConstraintsForClassConstructor ( target ) { return this . constraintMetadatasStore . get ( target ) || [ ] ; } /**
     * Removes all the currently saved metadata about the classes.
     */ public reset ( ) { this . sanitationMetadataStore = new Map ( ) ; this . constraintMetadatasStore = new Map ( ) ; } }