@@ -30,7 +30,7 @@ import {
3030} from './validators/index.js' ;
3131import { SUPPORTED_VALIDATORS } from './Validation.js' ;
3232import type { Validation , Validator } from './Validation.js' ;
33- import { CidDocument } from '../document.js' ;
33+ import type { CidDocument } from '../document.js' ;
3434import type { Config } from '../config/Config.js' ;
3535
3636// MAIN VALIDATION
@@ -225,40 +225,42 @@ export function validateDocumentWithListDict(
225225
226226// Generates a document for output based on the validation results.
227227// sourceConfig is required to map the original column names in the error messages
228- export function makeValidationResultDocument (
228+ export const makeValidationResultDocument = (
229229 sourceConfig : Config . Options [ 'source' ] ,
230230 documentResult : Validation . DocumentResult ,
231- ) {
231+ ) : CidDocument => {
232232 let fieldNameMapping = sourceConfig . columns . reduce (
233233 ( memo , col ) => {
234234 return Object . assign ( memo , { [ col . alias ] : col . name } ) ;
235235 } ,
236236 { } as { [ key : string ] : string } ,
237237 ) ;
238238
239- return new CidDocument (
240- 'validationResult' ,
241- documentResult . results . map ( ( rowResult , rowIdx ) => {
242- // build an error message
243- let errorList = rowResult . errors . map ( ( error ) => {
244- // find the column name
245- let columnHumanName = fieldNameMapping [ error . column ] || error . column ;
246- return error . errors
247- . map ( ( { message } ) => `${ columnHumanName } ${ message } ;` )
248- . join ( '\n' ) ;
249- } ) ;
239+ const documentData : CidDocument [ "data" ] = documentResult . results . map ( ( rowResult , rowIdx ) => {
240+ // build an error message
241+ let errorList = rowResult . errors . map ( ( error ) => {
242+ // find the column name
243+ let columnHumanName = fieldNameMapping [ error . column ] || error . column ;
244+ return error . errors
245+ . map ( ( { message } ) => `${ columnHumanName } ${ message } ;` )
246+ . join ( '\n' ) ;
247+ } ) ;
250248
251- // combine with the row onject
252- return Object . assign (
253- {
254- // The row number should match the row number in the input document (row index 0 is row# 2)
255- row_number : rowIdx + 2 ,
256- // The error list should be an empty string (so that it'll be hidden if no errors are present)
257- // NOTE: the line-ending can be tricky
258- errors : errorList . join ( '\n' ) ,
259- } ,
260- rowResult . row ,
261- ) ;
262- } ) ,
263- ) ;
249+ // combine with the row onject
250+ return Object . assign (
251+ {
252+ // The row number should match the row number in the input document (row index 0 is row# 2)
253+ row_number : rowIdx + 2 ,
254+ // The error list should be an empty string (so that it'll be hidden if no errors are present)
255+ // NOTE: the line-ending can be tricky
256+ errors : errorList . join ( '\n' ) ,
257+ } ,
258+ rowResult . row ,
259+ ) ;
260+ } )
261+
262+ return {
263+ name : 'validationResult' ,
264+ data : documentData
265+ } ;
264266}
0 commit comments