Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // src/utils/validation.js import { CoherentTypes, COHERENT_MARKER } from '../types/constants.js'; export const Validation = { validateCoherentObject, validateComponent, validateProps }; function validateCoherentObject(obj, context = 'render') { if (!obj || typeof obj !== 'object') { throw new Error(`${context}: Expected object, received ${typeof obj}`); } if (!obj[COHERENT_MARKER]) { throw new Error(`${context}: Object is not a valid Coherent object`); } if (!Object.values(CoherentTypes).includes(obj.type)) { throw new Error(`${context}: Invalid Coherent object type: ${obj.type}`); } return true; } function validateComponent(componentFunction) { if (typeof componentFunction !== 'function') { throw new Error('Component must be a function'); } return true; } function validateProps(props) { if (props && typeof props !== 'object') { throw new Error('Props must be an object'); } return true; } |