import { QueryConfig } from '../config' ; import { SpecQueryModel } from '../model' ; import { Property } from '../property' ; import { Wildcard } from '../wildcard' ; import { Schema } from '../schema' ; import { isValueQuery } from '../query/encoding' ; import { FIELD_CONSTRAINTS_BY_PROPERTY } from './field' ; import { VALUE_CONSTRAINTS_BY_PROPERTY } from './value' ; /**
 * Check all encoding constraints for a particular property and index tuple
 */ export function checkEncoding ( prop , wildcard , index , specM , schema , opt ) { const encodingConstraints = FIELD_CONSTRAINTS_BY_PROPERTY . get ( prop ) || [ ] ; const encQ = specM . getEncodingQueryByIndex ( index ) ; for ( const c of encodingConstraints ) { if ( c . strict ( ) || ! ! opt [ c . name ( ) ] ) { const satisfy = c . satisfy ( encQ , schema , specM . wildcardIndex . encodings [ index ] , opt ) ; if ( ! satisfy ) { const violatedConstraint = `(enc) ${ c . name ( ) }` ; if ( opt . verbose ) { console . log ( `${ violatedConstraint } failed with ${ specM . toShorthand ( ) } for ${ wildcard . name }` ) ; } return violatedConstraint ; } } } const valueContraints = VALUE_CONSTRAINTS_BY_PROPERTY . get ( prop ) || [ ] ; for ( const c of valueContraints ) { if ( ( c . strict ( ) || ! ! opt [ c . name ( ) ] ) && isValueQuery ( encQ ) ) { const satisfy = c . satisfy ( encQ , schema , specM . wildcardIndex . encodings [ index ] , opt ) ; if ( ! satisfy ) { const violatedConstraint = `(enc) ${ c . name ( ) }` ; if ( opt . verbose ) { console . log ( `${ violatedConstraint } failed with ${ specM . toShorthand ( ) } for ${ wildcard . name }` ) ; } return violatedConstraint ; } } } return null ; }