import { QueryConfig } from '../config' ; import { isEncodingNestedProp , Property } from '../property' ; import { PropIndex } from '../propindex' ; import { isWildcard , Wildcard } from '../wildcard' ; import { Schema } from '../schema' ; import { every } from '../util' ; import { EncodingQueryBase } from '../query/encoding' ; /**
 * Abstract interface for a constraint.
 */ export interface AbstractConstraint { name : string ; description : string ; properties : Property [ ] ; /**
     * Whether this constraint requires all specified properties types to be specific
     * in order to call satisfy function.
     */ allowWildcardForProperties : boolean ; /**
     * Whether this constraint is strict (not optional).
     */ strict : boolean ; } /**
 * Abstract model for a constraint.
 */ export class AbstractConstraintModel { protected constraint : AbstractConstraint ; constructor ( constraint ) { this . constraint = constraint ; } public name ( ) { return this . constraint . name ; } public description ( ) { return this . constraint . description ; } public properties ( ) { return this . constraint . properties ; } public strict ( ) { return this . constraint . strict ; } } /**
 * Collection of constraints for a single encoding mapping.
 */ /** A method for satisfying whether the provided encoding query satisfy the constraint. */ export interface EncodingConstraintChecker < E extends EncodingQueryBase > { ( encQ , schema , encWildcardIndex , opt ) : boolean ; } export class EncodingConstraintModel < E extends EncodingQueryBase > extends AbstractConstraintModel { constructor ( constraint ) { super ( constraint ) ; } public hasAllRequiredPropertiesSpecific ( encQ ) { return every ( this . constraint . properties , ( prop ) => { if ( isEncodingNestedProp ( prop ) ) { const parent = prop . parent ; const child = prop . child ; if ( ! encQ [ parent ] ) { return true ; } return ! isWildcard ( encQ [ parent ] [ child ] ) ; } if ( ! encQ [ prop ] ) { return true ; } return ! isWildcard ( encQ [ prop ] ) ; } ) ; } public satisfy ( encQ , schema , encWildcardIndex , opt ) { if ( ! this . constraint . allowWildcardForProperties ) { if ( ! this . hasAllRequiredPropertiesSpecific ( encQ ) ) { return true ; } } return ( this . constraint as EncodingConstraint < E > ) . satisfy ( encQ , schema , encWildcardIndex , opt ) ; } } /** Constraint for a single encoding mapping */ export interface EncodingConstraint < E extends EncodingQueryBase > extends AbstractConstraint { /** Method for checking if the encoding query satisfies this constraint. */ satisfy : EncodingConstraintChecker < E > ; }