Files
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

35 lines
1.0 KiB
JavaScript

// @flow
import ValidationError from '../error/validation_error.js';
import getType from '../util/get_type.js';
import validate from './validate.js';
import type {ValidationOptions} from './validate.js';
export default function validateProjection(options: ValidationOptions): Array<ValidationError> {
const projection = options.value;
const styleSpec = options.styleSpec;
const projectionSpec = styleSpec.projection;
const style = options.style;
let errors = [];
const rootType = getType(projection);
if (rootType === 'object') {
for (const key in projection) {
errors = errors.concat(validate({
key,
value: projection[key],
valueSpec: projectionSpec[key],
style,
styleSpec
}));
}
} else if (rootType !== 'string') {
errors = errors.concat([new ValidationError('projection', projection, `object or string expected, ${rootType} found`)]);
}
return errors;
}