import * as path from 'path' ; import { TaskContext } from './task_context' ; import { checkMatchingMapping } from '../check_collector_integrity' ; import { readFileAsync } from '../utils' ; export function checkMatchingSchemasTask ( { roots } , throwOnDiff ) { return roots . map ( ( root ) => ( { task : async ( ) => { const fullPath = path . resolve ( process . cwd ( ) , root . config . output ) ; const opensearchMappingString = await readFileAsync ( fullPath , 'utf-8' ) ; const opensearchMapping = JSON . parse ( opensearchMappingString ) ; if ( root . parsedCollections ) { const differences = checkMatchingMapping ( root . parsedCollections , opensearchMapping ) ; root . opensearchMappingDiffs = Object . keys ( differences ) ; if ( root . opensearchMappingDiffs . length && throwOnDiff ) { throw Error ( `The following changes must be persisted in ${ fullPath } file. Use '--fix' to update.\n${ JSON . stringify ( differences , null , 2 ) }` ) ; } } } , title : `Checking in ${ root . config . root }` , } ) ) ; }