ai-functions
Version:
A powerful TypeScript library for building AI-powered applications with template literals and structured outputs
30 lines • 1.04 kB
JavaScript
export function validateSchema(schema) {
if (!schema || typeof schema !== 'object') {
throw new Error('Schema must be a valid object');
}
Object.entries(schema).forEach(([key, value]) => {
if (!key || typeof key !== 'string') {
throw new Error('Schema keys must be non-empty strings');
}
validateSchemaValue(value);
});
}
function validateSchemaValue(value) {
if (Array.isArray(value)) {
if (value.length === 0) {
throw new Error('Array schema values must not be empty');
}
value.forEach(item => {
if (typeof item !== 'string') {
throw new Error('Array schema values must contain only strings');
}
});
}
else if (typeof value === 'object' && value !== null) {
validateSchema(value);
}
else if (typeof value !== 'string') {
throw new Error('Schema values must be strings, arrays of strings, or nested objects');
}
}
//# sourceMappingURL=validation.js.map