import { AnnotationConfig } from '../types' ; export class ODataAnnotation { term : string ; string ? : string ; bool ? : boolean ; int ? : number ; permissions ? : string [ ] ; properties ? : string [ ] ; constructor ( annot ) { this . term = annot . term ; Object . assign ( this , annot ) ; } } export class ODataAnnotatable { annotations : ODataAnnotation [ ] ; constructor ( config ) { this . annotations = ( config . annotations || [ ] ) . map ( ( annot ) => new ODataAnnotation ( annot ) ) ; } param predicate returns findAnnotation ( predicate ) { return this . annotations . find ( predicate ) ; } param term returns annotatedValue < T > ( term ) { const reg = term instanceof RegExp ? term : new RegExp ( `^${ term }$` ) ; const annot = this . findAnnotation ( ( a ) => reg . test ( a . term ) ) ; if ( ! annot ) { return undefined ; } return ( annot . string || annot . bool || annot . int || annot . permissions || annot . properties ) as any ; } }