You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB

8 months ago
/**
* ============================================================================
* SECTION VALIDATOR
* ============================================================================
*/
import type { Section, AttrID } from '@/types';
import type { ValidationError } from '@/utils';
/**
* Validar sección en runtime
*/
export function validateSection(section: Section): ValidationError[] {
const errors: ValidationError[] = [];
// Validar que imageUrlTemplate tiene placeholders válidos
if (section.visualConfig.imageUrlTemplate) {
const template = section.visualConfig.imageUrlTemplate;
const placeholders = template.match(/\{[^}]+}/g) || [];
placeholders.forEach(placeholder => {
const cleanName = placeholder.slice(1, -1); // Remove { }
if (cleanName.startsWith('global.')) {
const attrName = cleanName.replace('global.', '');
const attrId = `at:${attrName}` as AttrID;
if (!section.visualConfig.globalAttributeDependencies?.includes(attrId)) {
errors.push({
sectionId: section.id,
message: `Placeholder ${placeholder} not in globalAttributeDependencies`,
severity: 'error'
});
}
}
});
}
return errors;
}

Powered by TurnKey Linux.